# Frama-C-discuss mailing list archives

This page gathers the archives of the old Frama-C-discuss archives, that was hosted by Inria's gforge before its demise at the end of 2020. To search for mails newer than September 2020, please visit the page of the new mailing list on Renater.

• From: Arthur.CLAVIERE at student.isae-supaero.fr (CLAVIERE Arthur)
• Date: Mon, 19 Jun 2017 13:36:09 +0200

```I want to prove the correctness of a simple function which adds two 3-by-3 matrices. Using wp plug-in, I can prove the assign clause but I can't prove the ensures clause (I use the real model for computing weakest preconditions). Did I forget a precondition, is it a known problem ?

Regards,

Arthur

/*@
requires \valid(A[0]+(0..2)) && \valid(A[1]+(0..2)) && \valid(A[2]+(0..2)) && \valid(B[0]+(0..2)) && \valid(B[1]+(0..2)) && \valid(B[2]+(0..2)) && \valid(result[0]+(0..2)) && \valid(result[1]+(0..2)) && \valid(result[2]+(0..2));
requires \separated(A[0]+(0..2), A[1]+(0..2), A[2]+(0..2), B[0]+(0..2), B[1]+(0..2), B[2]+(0..2), result[0]+(0..2), result[1]+(0..2), result[2]+(0..2));
assigns result[0][0..2], result[1][0..2], result[2][0..2];
ensures \forall integer p, q; 0 <= p <= 2 && 0 <= q <=2 ==> result[p][q] == A[p][q] + B[p][q];
@*/
void matrix_addition(float A[3][3], float B[3][3], float result[3][3]){
Â Â  Â
Â Â  Â /*@
Â Â  Â loop assigns i, result[0][0..2], result[1][0..2], result[2][0..2];
Â Â  Â loop invariant 0 <= i <= 3;
Â Â  Â loop invariant \forall integer k; 0 <= k < i ==> result[k][0] == A[k][0] + B[k][0] && result[k][1] == A[k][1] + B[k][1] && result[k][2] == A[k][2] + B[k][2];
Â Â  Â loop variant 2-i;
Â Â  Â @*/
Â Â  Â for (int i=0; i<3; i++){
Â Â  Â Â Â  Â
Â Â  Â Â Â  Â /*@
Â Â  Â Â Â  Â loop assigns j, result[i][0..2];
Â Â  Â Â Â  Â loop invariant 0 <= j <= 3;
Â Â  Â Â Â  Â loop invariant \forall integer n; 0 <= n < j ==> result[i][n] == A[i][n] + B[i][n];
Â Â  Â Â Â  Â loop variant 2-j;
Â Â  Â Â Â  Â @*/
Â Â  Â Â Â  Â for (int j=0; j<3; j++){
Â Â  Â Â Â  Â Â Â  Â
Â Â  Â Â Â  Â Â Â  Â result[i][j] = A[i][j] + B[i][j];
Â Â  Â Â Â  Â Â Â  Â //@ assert result[i][j] == A[i][j] + B[i][j];
Â Â  Â Â Â  Â }
Â Â  Â Â Â  Â
Â Â  Â }
Â Â  Â
}

--
Â Â
Arthur CLAVIÃˆRE