Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Why3
why3
Commits
b9d879d9
Commit
b9d879d9
authored
Apr 01, 2016
by
Jean-Christophe Filliâtre
Browse files
mccarthy: much nicer with a let function
parent
110f252f
Changes
3
Hide whitespace changes
Inline
Side-by-side
examples/mccarthy.mlw
View file @
b9d879d9
...
...
@@ -7,7 +7,8 @@ module McCarthy91
(* traditional recursive implementation *)
let rec f91 (n:int) : int variant { 101-n }
let rec function f91 (n:int) : int
variant { 101-n }
ensures { result = if n <= 100 then 91 else n - 10 }
= if n <= 100 then
f91 (f91 (n + 11))
...
...
@@ -20,13 +21,11 @@ module McCarthy91
use import ref.Ref
use import int.Iter
function f (x: int) : int = if x <= 100 then 91 else x-10
let f91_nonrec (n0: int) ensures { result = f n0 }
let f91_nonrec (n0: int) ensures { result = f91 n0 }
= let e = ref 1 in
let n = ref n0 in
while !e > 0 do
invariant { !e >= 0 /\ iter f !e !n = f n0 }
invariant { !e >= 0 /\ iter f
91
!e !n = f
91
n0 }
variant { 101 - !n + 10 * !e, !e }
if !n > 100 then begin
n := !n - 10;
...
...
examples/mccarthy/why3session.xml
View file @
b9d879d9
...
...
@@ -2,9 +2,10 @@
<!DOCTYPE why3session PUBLIC "-//Why3//proof session v5//EN"
"http://why3.lri.fr/why3session.dtd">
<why3session
shape_version=
"4"
>
<prover
id=
"4"
name=
"Alt-Ergo"
version=
"0.99.1"
timelimit=
"5"
memlimit=
"1000"
/>
<prover
id=
"0"
name=
"Alt-Ergo"
version=
"1.01"
timelimit=
"5"
steplimit=
"1"
memlimit=
"1000"
/>
<prover
id=
"4"
name=
"Alt-Ergo"
version=
"0.99.1"
timelimit=
"5"
steplimit=
"1"
memlimit=
"1000"
/>
<file
name=
"../mccarthy.mlw"
expanded=
"true"
>
<theory
name=
"McCarthy91"
sum=
"
dfd70d690529e1a36626f39ca1116ffb
"
expanded=
"true"
>
<theory
name=
"McCarthy91"
sum=
"
38080f0fd49f8f0d571a189eec9df3af
"
expanded=
"true"
>
<goal
name=
"VC f91"
expl=
"VC for f91"
expanded=
"true"
>
<transf
name=
"split_goal_wp"
expanded=
"true"
>
<goal
name=
"VC f91.1"
expl=
"1. variant decrease"
>
...
...
@@ -14,7 +15,10 @@
<proof
prover=
"4"
><result
status=
"valid"
time=
"0.01"
steps=
"3"
/></proof>
</goal>
<goal
name=
"VC f91.3"
expl=
"3. postcondition"
>
<proof
prover=
"4"
><result
status=
"valid"
time=
"0.01"
steps=
"8"
/></proof>
<proof
prover=
"4"
><result
status=
"valid"
time=
"0.01"
steps=
"6"
/></proof>
</goal>
<goal
name=
"VC f91.4"
expl=
"4. postcondition"
>
<proof
prover=
"0"
><result
status=
"valid"
time=
"0.00"
steps=
"2"
/></proof>
</goal>
</transf>
</goal>
...
...
@@ -24,13 +28,13 @@
<proof
prover=
"4"
><result
status=
"valid"
time=
"0.01"
steps=
"2"
/></proof>
</goal>
<goal
name=
"VC f91_nonrec.2"
expl=
"2. loop invariant preservation"
>
<proof
prover=
"4"
><result
status=
"valid"
time=
"0.03"
steps=
"
4
6"
/></proof>
<proof
prover=
"4"
><result
status=
"valid"
time=
"0.03"
steps=
"6
1
"
/></proof>
</goal>
<goal
name=
"VC f91_nonrec.3"
expl=
"3. loop variant decrease"
>
<proof
prover=
"4"
><result
status=
"valid"
time=
"0.01"
steps=
"6"
/></proof>
</goal>
<goal
name=
"VC f91_nonrec.4"
expl=
"4. loop invariant preservation"
>
<proof
prover=
"4"
><result
status=
"valid"
time=
"
1.32
"
steps=
"
222
"
/></proof>
<proof
prover=
"4"
><result
status=
"valid"
time=
"
0.03
"
steps=
"
47
"
/></proof>
</goal>
<goal
name=
"VC f91_nonrec.5"
expl=
"5. loop variant decrease"
>
<proof
prover=
"4"
><result
status=
"valid"
time=
"0.01"
steps=
"6"
/></proof>
...
...
examples/mccarthy/why3shapes.gz
View file @
b9d879d9
No preview for this file type
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment