Skip to content

Commit e1506cd

Browse files
committed
More tests
1 parent 1a3901a commit e1506cd

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

tests/lean/run/wfrec-nat.lean

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
Tests around the special case of well-founded recursion on Nat.
33
-/
44

5+
set_option warn.sorry false
6+
57
namespace T1
68

79
def foo : List α → Nat
@@ -69,3 +71,59 @@ example : foo (x::xs) = 1 + foo xs := by (fail_if_success rfl); simp [foo]
6971
example : foo (x::y::z::xs) = 1+ (1 + ( 1+ foo xs)) := by (fail_if_success rfl); simp [foo]
7072

7173
end T3
74+
75+
-- Defeq between similar functions
76+
77+
namespace T4
78+
79+
def foo (b : Bool) : Nat → Nat
80+
| 0 => 0
81+
| n+1 => 1 + foo b n
82+
termination_by n => n
83+
84+
def bar (b : Bool) : Nat → Nat
85+
| 0 => 0
86+
| n+1 => cond b 1 2 + bar b n
87+
termination_by n => n
88+
89+
def baz : Nat → Nat
90+
| 0 => 0
91+
| n+1 => 1 + baz n
92+
termination_by n => n
93+
94+
example : foo true n = bar true n := rfl
95+
example : foo true n = baz n := rfl
96+
example : bar true n = baz n := rfl
97+
98+
end T4
99+
100+
-- For comparison: with wfrec
101+
102+
namespace T4wfrec
103+
104+
def foo (b : Bool) : Nat → Nat
105+
| 0 => 0
106+
| n+1 => 1 + foo b n
107+
termination_by n => (n, 0)
108+
109+
def bar (b : Bool) : Nat → Nat
110+
| 0 => 0
111+
| n+1 => cond b 1 2 + bar b n
112+
termination_by n => (n, 0)
113+
114+
def baz : Nat → Nat
115+
| 0 => 0
116+
| n+1 => 1 + baz n
117+
termination_by n => (n, 0)
118+
119+
example : foo true n = bar true n := by (fail_if_success rfl); sorry
120+
example : foo true n = baz n := by (fail_if_success rfl); sorry
121+
example : bar true n = baz n := by (fail_if_success rfl); sorry
122+
123+
unseal foo bar baz
124+
125+
example : foo true n = bar true n := rfl
126+
example : foo true n = baz n := rfl
127+
example : bar true n = baz n := rfl
128+
129+
end T4wfrec

0 commit comments

Comments
 (0)