comp.lang.ada
 help / color / mirror / Atom feed
* [Spark] Proving GCD
@ 2017-03-16 20:27 Frédéric Praca
  2017-03-17  9:33 ` Frédéric PRACA
  0 siblings, 1 reply; 10+ messages in thread
From: Frédéric Praca @ 2017-03-16 20:27 UTC (permalink / raw)


Hi guys,


^ permalink raw reply	[flat|nested] 10+ messages in thread
* [Spark] Proving GCD
@ 2017-03-16 20:31 Frédéric Praca
  2017-03-17  1:20 ` Brian Kolden
  2017-04-05 23:52 ` moy
  0 siblings, 2 replies; 10+ messages in thread
From: Frédéric Praca @ 2017-03-16 20:31 UTC (permalink / raw)


Hi guys,
sorry for the first message, I clicked on the wrong button :D

I'm trying to train myself on Spark and I tried to see if a simple 
function like GCD could be proved.

I created the following :

GCD_Package is

   pragma SPARK_Mode;
   pragma Assertion_Policy(Check);
   
   function gcd (A : Natural; B : Positive) return Natural
     with
       Global => null,
       Depends => (gcd'Result => (A,B)),
       Post => gcd'Result <= A and A mod gcd'Result = 0 and B mod
       gcd'Result = 0 ;

end GCD_Package;

package body GCD_Package is

   pragma SPARK_Mode;

   function gcd (A : Natural; B : Positive) return Natural is
      Value : Natural;
      Temp : Natural; Local_B : Natural := B;
      Local_A : Natural := A;
   begin
      if A = 0 then
         value := B;
      else
         while Local_B > 0 loop
            pragma Loop_Variant (Decreases => Local_B);
            Temp := Local_B;
            Local_B := Local_A mod Local_B;
            Local_A := Temp;
         end loop;
         value := Local_A;
      end if;
      
      return value;
   end Gcd;

end GCD_Package;

The answer is always "postcondition might fail" and I don't know what to 
do. 
Do you have an idea on how to discharge all VCs and thus prove this code ?

Thanks
Fred


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2017-04-05 23:52 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-16 20:27 [Spark] Proving GCD Frédéric Praca
2017-03-17  9:33 ` Frédéric PRACA
2017-03-17 13:00   ` Phil Thornley
2017-03-17 13:24     ` Frédéric PRACA
2017-03-17 13:28       ` Frédéric PRACA
2017-03-17 17:16         ` Phil Thornley
  -- strict thread matches above, loose matches on Subject: below --
2017-03-16 20:31 Frédéric Praca
2017-03-17  1:20 ` Brian Kolden
2017-03-17  9:07   ` Frédéric PRACA
2017-04-05 23:52 ` moy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox