-
1
-
2
-
3
-
4
-
5
-
6
-
7
-
8
-
9
-
10
-
11
-
12
-
13
-
14
-
15
-
16
-
17
-
18
-
19
-
20
-
21
-
22
-
23
-
24
-
25
-
26
-
27
-
28
-
29
-
30
-
31
-
32
-
33
-
34
-
35
-
36
-
37
-
38
-
39
-
40
-
41
-
42
-
43
-
44
-
45
-
46
-
47
-
48
-
49
-
50
-
51
-
52
-
53
-
54
-
55
-
56
-
57
-
58
-
59
-
60
-
61
-
62
-
63
-
64
-
65
-
66
-
67
-
68
-
69
-
70
-
71
-
72
-
73
-
74
-
75
-
76
-
77
-
78
import CaseStudies.Velvet.Std
set_option loom.semantics.termination "total"
set_option loom.semantics.choice "demonic"
method lsb (i : ℕ) return (j : ℕ)
require 0 < i
ensures 0 < j ∧ j ≤ i
do
if 0 < i ∧ 2 ∣ i then
let res ← lsb (i / 2)
return 2 * res
else
return 1
prove_correct lsb
by loom_solve
lemma lsb_add (i : ℕ) (hi : 0 < i) :
let j := lsb i |>.extract
let k := lsb (i + j) |>.extract
2 * j ≤ k := by
by_cases h : 0 < i ∧ 2 ∣ i
· have := lsb_add (i / 2) (by grind)
simp at this
have : (lsb i).extract = 2 * (lsb (i / 2)).extract := by sorry
simp [this]
grind
· have : (lsb i).extract = 1 := by sorry
simp [this]
grind
method GCD (a : Nat) (b : Nat) return (res : Nat)
require a > 0
ensures res > 0
do
if b = 0 then
return a
else
let remainder := a % b
let result ← GCD b remainder
return result
termination_by b
decreasing_by
apply Nat.mod_lt
grind
attribute [solverHint] Nat.mod_lt
prove_correct GCD
termination_by b
decreasing_by all_goals(
apply Nat.mod_lt
grind
)
by
loom_solve
method Minimum (a: Int) (b: Int) return (minValue: Int)
ensures minValue ≤ a
ensures minValue ≤ b
ensures minValue = a ∨ minValue = b
do
if a ≤ b then
assert a - 1 ≤ b
return a
else
return b
prove_correct Minimum by
loom_solve