diff --git a/content/conception_formelle/99-DM_framac/TD-TP.tex b/content/conception_formelle/99-DM_framac/TD-TP.tex index e6405c5..4459200 100644 --- a/content/conception_formelle/99-DM_framac/TD-TP.tex +++ b/content/conception_formelle/99-DM_framac/TD-TP.tex @@ -318,6 +318,9 @@ int abs2(int n) /*@ loop assign i, min, max; */ + while ( i < n ) + { + // ... \end{lstlisting} \end{solutionorbox} @@ -343,7 +346,14 @@ int max_dist(int *tab, unsigned int n) \begin{solutionorbox} - METTEZ VOTRE RÉPONSE ICI. + Cette fonction incorrecte prend en paramètre deux éléments -- un tableau et un entier positif -- et en retrourne un -- un entier. C'est exactement la même chose que pour notre fonction correcte. Le contrat s'écrirait alors comme ci-dessous pour Frama-C : + \begin{lstlisting} + \*@ + require 0 < n <= UINT_MAX; + require \valid(tab+(0..n-1)); + ensures \result >= 0; + *\ + \end{lstlisting} \end{solutionorbox} \part Donnez une postcondition vérifiée par la fonction correcte qui n’est pas vérifiée par celle-ci. @@ -351,7 +361,7 @@ int max_dist(int *tab, unsigned int n) \begin{solutionorbox} - METTEZ VOTRE RÉPONSE ICI. + \end{solutionorbox} diff --git a/content/conception_formelle/99-DM_framac/code/abs.h b/content/conception_formelle/99-DM_framac/code/abs.h index ad03ed3..46bcd79 100644 --- a/content/conception_formelle/99-DM_framac/code/abs.h +++ b/content/conception_formelle/99-DM_framac/code/abs.h @@ -6,16 +6,20 @@ /*@ logic integer abs(integer n) = 0 max >= tab[j] >= min); + loop invariant I4: \exists integer j; ( 0 < j < i ==> max == tab[j]); + loop invariant I5: \exists integer j; ( 0 < j < i ==> min == tab[j]); + loop variant n - i; + */ while (i < n) { if (tab[i] < min) @@ -14,4 +24,4 @@ int max_dist(int *tab, unsigned int n) i++; } return max - min; -} \ No newline at end of file +} diff --git a/content/conception_formelle/99-DM_framac/code/max_dist.h b/content/conception_formelle/99-DM_framac/code/max_dist.h index aed8cb1..eaeeb93 100644 --- a/content/conception_formelle/99-DM_framac/code/max_dist.h +++ b/content/conception_formelle/99-DM_framac/code/max_dist.h @@ -1,6 +1,10 @@ #include #include "abs.h" -/*@ ensures \forall integer a,b; 0 <= a < b < n ==> \result >= abs(tab[a]-tab[b]); +/*@ + requires 0 < n < UINT_MAX; + requires \valid_read(tab+(0..n-1)); + terminates \true; + ensures \forall integer a,b; 0 <= a < b < n ==> \result >= abs(tab[a]-tab[b]); */ -int max_dist(int *tab, unsigned int n); \ No newline at end of file +int max_dist(int *tab, unsigned int n);