Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
W
why3
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Nils Fitinghoff
why3
Commits
05648746
Commit
05648746
authored
Jun 28, 2018
by
Claude Marché
Browse files
Options
Downloads
Patches
Plain Diff
New very simple example: Nistonacci numbers
parent
30f8256a
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
examples/nistonacci.mlw
+65
-0
65 additions, 0 deletions
examples/nistonacci.mlw
with
65 additions
and
0 deletions
examples/nistonacci.mlw
0 → 100644
+
65
−
0
View file @
05648746
(** {1 Nistonacci numbers}
The simple "Nistonacci numbers" example, originally designed by
K. Rustan M. Leino for the SSAS workshop (Sound Static Analysis
for Security, NIST, Gaithersburg, MD, USA, June 27-28, 2018) *)
use int.Int
(** {2 Specification}
new in Why3 1.0: (pure) program function that goes into the logic
(no need for axioms anymore to define such a function)
*)
let rec ghost function nist(n:int) : int
requires { n >= 0 }
variant { n }
= if n < 2 then n else nist (n-2) + 2 * nist (n-1)
(** {2 Implementation} *)
use ref.Ref
let rec nistonacci (n:int) : int
requires { n >= 0 }
variant { n }
ensures { result = nist n }
= let x = ref 0 in
let y = ref 1 in
for i=0 to n-1 do
invariant { !x = nist i }
invariant { !y = nist (i+1) }
let tmp = !x in
x := !y;
y := tmp + 2 * !y
done;
!x
(** {2 A general lemma on Nistonacci numbers}
That lemma function is used to prove the lemma `forall n. nist(n) >=
n` by induction on `n`
*)
(*** (new in Why3 1.0: markdown in comments !) *)
let rec lemma nist_ge_n (n:int)
requires { n >= 0 }
variant { n }
ensures { nist(n) >= n }
= if n >= 2 then begin
(** recursive call on `n-1`, acts as using the induction
hypothesis on `n-1` *)
nist_ge_n (n-1);
(** let's also use induction hypothesis on `n-2` *)
nist_ge_n (n-2)
end
(** test: this can be proved by instantiating the previous lemma *)
goal test : nist 42 >= 17
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment