Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
why3
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
125
Issues
125
List
Boards
Labels
Service Desk
Milestones
Merge Requests
15
Merge Requests
15
Operations
Operations
Incidents
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Why3
why3
Commits
5f67db56
Commit
5f67db56
authored
Apr 08, 2011
by
Jean-Christophe Filliâtre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fibonacci: documentation
parent
e424e301
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
0 deletions
+13
-0
examples/programs/fibonacci.mlw
examples/programs/fibonacci.mlw
+13
-0
No files found.
examples/programs/fibonacci.mlw
View file @
5f67db56
...
...
@@ -86,6 +86,11 @@ module FibonacciLogarithmic
logic m1110 : t = {| a11 = 1; a12 = 1;
a21 = 1; a22 = 0 |}
(* computes ((1 1) (1 0))^n in O(log(n)) time
since it is a matrix of the shape ((a+b b) (b a)),
we only return the pair (a, b) *)
let rec logfib n =
{ n >= 0 }
if n = 0 then
...
...
@@ -101,6 +106,14 @@ module FibonacciLogarithmic
{ let a, b = result in
power m1110 n = {| a11 = a+b; a12 = b; a21 = b; a22 = a |} }
(* by induction, we easily prove that
(1 1)^n = (F(n+1) F(n) )
(1 0) (F(n) F(n-1))
thus, we can compute F(n) in O(log(n)) using funtion logfib above
*)
logic p (n:int) =
let p = power m1110 n in
isfib (n+1) p.a11 and isfib n p.a21
...
...
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