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
119
Issues
119
List
Boards
Labels
Service Desk
Milestones
Merge Requests
16
Merge Requests
16
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
3df75dcf
Commit
3df75dcf
authored
Feb 28, 2014
by
Jean-Christophe Filliâtre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
new example binary_gcd
parent
ac92aef1
Changes
2
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
701 additions
and
41 deletions
+701
-41
examples/gcd.mlw
examples/gcd.mlw
+39
-0
examples/gcd/why3session.xml
examples/gcd/why3session.xml
+662
-41
No files found.
examples/gcd.mlw
View file @
3df75dcf
...
...
@@ -43,3 +43,42 @@ module EuclideanAlgorithmIterative
!u
end
module BinaryGcd
use import int.Int
use import int.Lex2
use import number.Parity
use import number.Gcd
use import int.ComputerDivision
lemma even1: forall n: int. 0 <= n -> even n <-> n = 2 * div n 2
lemma odd1: forall n: int. 0 <= n -> not (even n) <-> n = 2 * div n 2 + 1
lemma div_nonneg: forall n: int. 0 <= n -> 0 <= div n 2
lemma gcd_even_even: forall u v: int. 0 <= v -> 0 <= u ->
gcd (2 * u) (2 * v) = 2 * gcd u v
lemma gcd_even_odd: forall u v: int. 0 <= v -> 0 <= u ->
gcd (2 * u) (2 * v + 1) = gcd u (2 * v + 1)
lemma gcd_even_odd2: forall u v: int. 0 <= v -> 0 <= u ->
even u -> odd v -> gcd u v = gcd (div u 2) v
lemma odd_odd_div2: forall u v: int. 0 <= v -> 0 <= u ->
div ((2*u+1) - (2*v+1)) 2 = u - v
lemma gcd_odd_odd: forall u v: int. 0 <= v -> 0 <= u ->
gcd (2 * u + 1) (2 * v + 1) = gcd (u - v) (2 * v + 1)
lemma gcd_odd_odd2: forall u v: int. 0 <= v -> 0 <= u ->
odd u -> odd v -> gcd u v = gcd (div (u - v) 2) v
let rec binary_gcd (u v: int) : int
variant { (v, u) with lex }
requires { u >= 0 /\ v >= 0 }
ensures { result = gcd u v }
=
if v > u then binary_gcd v u else
if v = 0 then u else
if even u then if even v then 2 * binary_gcd (div u 2) (div v 2)
else binary_gcd (div u 2) v
else if even v then binary_gcd u (div v 2)
else binary_gcd (div (u - v) 2) v
end
examples/gcd/why3session.xml
View file @
3df75dcf
This diff is collapsed.
Click to expand it.
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