|
2 | 2 | Tests around the special case of well-founded recursion on Nat. |
3 | 3 | -/ |
4 | 4 |
|
| 5 | +set_option warn.sorry false |
| 6 | + |
5 | 7 | namespace T1 |
6 | 8 |
|
7 | 9 | def foo : List α → Nat |
@@ -69,3 +71,59 @@ example : foo (x::xs) = 1 + foo xs := by (fail_if_success rfl); simp [foo] |
69 | 71 | example : foo (x::y::z::xs) = 1+ (1 + ( 1+ foo xs)) := by (fail_if_success rfl); simp [foo] |
70 | 72 |
|
71 | 73 | 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