Commit 45bab2b 1 parent 7bfa8f6 commit 45bab2b Copy full SHA for 45bab2b
File tree 1 file changed +29
-1
lines changed
1 file changed +29
-1
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,31 @@ def f91 (n : Nat) : Option Nat :=
4
4
else f91 (n + 11 ) >>= f91
5
5
partial_fixpoint
6
6
7
+ section partial_correctness
8
+
9
+ -- #check f91.partial_correctness
10
+
11
+ theorem f91_partial_spec (n r : Nat) :
12
+ f91 n = some r → r = if n > 100 then n - 10 else 91 := by
13
+ apply f91.partial_correctness
14
+ intro f91 ih n r h
15
+ split at *
16
+ · simp_all
17
+ · simp only [Option.bind_eq_bind, Option.bind_eq_some] at h
18
+ obtain ⟨r', hr1, hr2⟩ := h
19
+ replace hr1 := ih _ _ hr1
20
+ replace hr2 := ih _ _ hr2
21
+ clear ih
22
+ subst hr1
23
+ subst hr2
24
+ split
25
+ · simp; omega
26
+ · simp
27
+
28
+ end partial_correctness
29
+
30
+ section total_correctness
31
+
7
32
theorem f91_spec_high (n : Nat) (h : 100 < n) : f91 n = some (n - 10 ) := by
8
33
unfold f91; simp [*]
9
34
@@ -21,7 +46,10 @@ theorem f91_spec_low (n : Nat) (h₂ : n ≤ 100) : f91 n = some 91 := by
21
46
· simp [*, f91]
22
47
· exact f91_spec_low (n + 1 ) (by omega)
23
48
24
- theorem f91_spec (n : Nat) : f91 n = some (if n ≤ 100 then 91 else n - 10 ) := by
49
+ theorem f91_spec (n : Nat) :
50
+ f91 n = some (if n ≤ 100 then 91 else n - 10 ) := by
25
51
by_cases h100 : n ≤ 100
26
52
· simp [f91_spec_low, *]
27
53
· simp [f91_spec_high, Nat.lt_of_not_le ‹_›, *]
54
+
55
+ end total_correctness
You can’t perform that action at this time.
0 commit comments