gcd_bezout: this is ghost code

parent 43b684d0
......@@ -12,19 +12,20 @@ module GcdBezout
requires { x >= 0 /\ y >= 0 }
ensures { result = gcd x y }
ensures { exists a b:int. a*x+b*y = result }
= let x = ref x in let y = ref y in
=
let x = ref x in let y = ref y in
'Pre:
let a = ref 1 in let b = ref 0 in
let c = ref 0 in let d = ref 1 in
let ghost a = ref 1 in let ghost b = ref 0 in
let ghost c = ref 0 in let ghost d = ref 1 in
while (!y > 0) do
invariant { !x >= 0 /\ !y >= 0 }
invariant { gcd !x !y = gcd (at !x 'Pre) (at !y 'Pre) }
invariant { !a * (at !x 'Pre) + !b * (at !y 'Pre) = !x }
invariant { !c * (at !x 'Pre) + !d * (at !y 'Pre) = !y }
variant { !y }
let r = mod !x !y in let q = div !x !y in
let r = mod !x !y in let ghost q = div !x !y in
x := !y; y := r;
let ta = !a in let tb = !b in
let ghost ta = !a in let ghost tb = !b in
a := !c; b := !d;
c := ta - !c * q; d := tb - !d * q
done;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment