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.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Frama-c-discuss] extended_Euclide



Hi,
You actually missed several details.

First, there is warning: wp complains about the missing verification of runtime errors.
You can run Value Analysis, or use -wp-rte to check that. In both cases, the absence of arithmetic overflows can be tricky to prove (complex linear arithmetic involved here). Validity of pointers p and q are easier to verify.

However, even if the program is RTE free, it is actually incorrect w.r.t to the bezout property if pointers p and q overlap.
This is why WP can not finish the proof. Consider either:
1. using a less general memory model (-wp-model +ref)
2. adding a \separated(p,q) to the requirements, and adding loop assigns or loop invariant on the values of pointers p and q

For instance:

/*@
  @	requires x >= 0 && y >= 0 && \separated(p,q);
  @	behavior bezoutProperty:
  @		ensures (*p)*x + (*q)*y == \result;
*/
int extended_Euclid(int x, int y, int* p, int* q) 
{
	int a = 1, b = 0, c = 0, d = 1;
	/*@
	  @	loop invariant x >= 0 && y >= 0;
	  @     loop invariant p == \at(p,Pre) && q == \at(q,Pre);
	  @	for bezoutProperty: loop invariant 
	  @			a*\at(x, Pre) + b*\at(y, Pre) == x
	  @		 && c*\at(x, Pre) + d*\at(y, Pre) == y;
	  @	loop variant y;	
	*/
	while(y > 0)
	{
		int r = x % y;
		int q = x / y;
		int ta = a, tb = b;
		x = y; y = r;
		a = c; b = d;
		c = ta - c * q; d = tb - d * q;
	}	
	*p = a; *q = b;
	return x;
}


Le 23 mai 2014 ? 09:50, MAXIM GAINA <maxim.gaina at studenti.unipr.it> a ?crit :

> Good morning.
> 
> While training on Frama-C in a Semanthics class, I tried the example shown on page 41 of ACSL handbook (http://frama-c.com/download/acsl-implementation-Neon-20140301.pdf), which exemplifies a possible implementation of Extended Euclide Algorithm. However, I was not able to proof any relevant property: am I missing something?
> 
> The code is attached. I am using Frama-C Neon on a 64-bit Fedora 20. I used Alt-Ergo (Native) as theorem proover, having enabled both RTE and Invariants. The Bezout property could not be proved in the contract (orange ball) but is partially proved before the while loop, inside the function (green/red ball).
> 
> Waiting for an answer, I offer my best regards
> 
> <extended_Euclid.c>_______________________________________________
> Frama-c-discuss mailing list
> Frama-c-discuss at lists.gforge.inria.fr
> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/frama-c-discuss

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gforge.inria.fr/pipermail/frama-c-discuss/attachments/20140523/57fc453d/attachment.html>