Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Why3
why3
Commits
ceab2013
Commit
ceab2013
authored
May 27, 2011
by
MARCHE Claude
Browse files
factorial example
parent
1c3c58f4
Changes
1
Hide whitespace changes
Inline
Side-by-side
examples/programs/fact.mlw
0 → 100644
View file @
ceab2013
theory Fact "Factorial"
use export int.Int
logic fact int : int
axiom fact0: fact 0 = 1
axiom factn: forall n:int. n >= 1 -> fact n = fact (n-1) * n
end
module FactImperative
use import Fact
use import int.Int
use import module ref.Ref
let fact_imp (x:int) : int =
{ x >= 0 }
let y = ref 0 in
let r = ref 1 in
while !y < x do
invariant { 0 <= !y <= x and !r = fact !y }
y := !y + 1;
r := !r * !y
done;
!r
{ result = fact x }
end
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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