Last active
August 29, 2015 14:01
-
-
Save nkavanagh/bc0f718a34e70bee6387 to your computer and use it in GitHub Desktop.
Revisions
-
nkavanagh revised this gist
May 28, 2014 . 1 changed file with 15 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -20,4 +20,19 @@ method testFib() assert 3 == fib(4); assert 55 == fib(10); assert 987 == fib(16); } method ifib(n: int) returns (f2: int) ensures f2 == fib(n); { var i: int := 0; var f1: int := 0; f2 := 0; while (i < n) invariant 0 <= i <= n; { f1 := f2; f2 := f1+f2; i := i + 1; } } -
nkavanagh created this gist
May 28, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,23 @@ function method fibn(n: int, f1: int, f2: int): int requires n >= 0; decreases n; { if n > 1 then fibn(n-1, f2, f1+f2) else f2 } function method fib(n: int): int requires n >= 0; decreases n; { if n == 0 then n else fibn(n, 0, 1) } method testFib() { assert 0 == fib(0); assert 1 == fib(1); assert 2 == fib(3); assert 3 == fib(4); assert 55 == fib(10); assert 987 == fib(16); }