Skip to content

Commit 45bab2b

Browse files
committed
test: expand f91 test
1 parent 7bfa8f6 commit 45bab2b

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

tests/lean/run/partial_fixpoint_f91.lean

+29-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,31 @@ def f91 (n : Nat) : Option Nat :=
44
else f91 (n + 11) >>= f91
55
partial_fixpoint
66

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+
732
theorem f91_spec_high (n : Nat) (h : 100 < n) : f91 n = some (n - 10) := by
833
unfold f91; simp [*]
934

@@ -21,7 +46,10 @@ theorem f91_spec_low (n : Nat) (h₂ : n ≤ 100) : f91 n = some 91 := by
2146
· simp [*, f91]
2247
· exact f91_spec_low (n + 1) (by omega)
2348

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
2551
by_cases h100 : n ≤ 100
2652
· simp [f91_spec_low, *]
2753
· simp [f91_spec_high, Nat.lt_of_not_le ‹_›, *]
54+
55+
end total_correctness

0 commit comments

Comments
 (0)