until around 7fe6881 the way to define well-founded recursions was to
specify a `WellFoundedRelation` on the argument explicitly. This was
rather low-level, for example one had to predict the packing of multiple
arguments into `PProd`s, the packing of mutual functions into `PSum`s,
and the cliques that were calculated.
Then the current `termination_by` syntax was introduced, where you
specify the termination argument at a higher level (one clause per
functions, unpacked arguments), and the `WellFoundedRelation` is found
using type class resolution.
The old syntax was kept around as `termination_by'`. This is not used
anywhere in the lean, std, mathlib or the theorem-proving-in-lean
repositories,
and three occurrences I found in the wild can do without
In particular, it should be possible to express anything that the old
syntax
supported also with the new one, possibly requiring a helper type with a
suitable instance, or the following generic wrapper that now lives in
std
```
def wrap {α : Sort u} {r : α → α → Prop} (h : WellFounded r) (x : α) : {x : α // Acc r x}
```
Since the old syntax is unused, has an unhelpful name and relies on
internals, this removes the support. Now is a good time before the
refactoring that's planned in #2921.
The test suite was updated without particular surprises.
The parametric `terminationHint` parser is gone, which means we can
match on syntax more easily now, in `expandDecreasingBy?`.
61 lines
924 B
Text
61 lines
924 B
Text
namespace Ex1
|
|
|
|
mutual
|
|
def h (c : Nat) (x : Nat) := match g c x c c with
|
|
| 0 => 1
|
|
| r => r + 2
|
|
def g (c : Nat) (t : Nat) (a b : Nat) : Nat := match t with
|
|
| (n+1) => match g c n a b with
|
|
| 0 => 0
|
|
| m => match g c (n - m) a b with
|
|
| 0 => 0
|
|
| m + 1 => g c m a b
|
|
| 0 => f c 0
|
|
def f (c : Nat) (x : Nat) := match h c x with
|
|
| 0 => 1
|
|
| r => f c r
|
|
end
|
|
termination_by
|
|
g x a b => 0
|
|
f c x => 0
|
|
h c x => 0
|
|
decreasing_by sorry
|
|
|
|
attribute [simp] g
|
|
attribute [simp] h
|
|
attribute [simp] f
|
|
|
|
#check g._eq_1
|
|
#check g._eq_2
|
|
|
|
#check h._eq_1
|
|
|
|
#check f._eq_1
|
|
|
|
end Ex1
|
|
|
|
namespace Ex2
|
|
|
|
def g (t : Nat) : Nat := match t with
|
|
| (n+1) => match g n with
|
|
| 0 => 0
|
|
| m + 1 => match g (n - m) with
|
|
| 0 => 0
|
|
| m + 1 => g n
|
|
| 0 => 0
|
|
decreasing_by sorry
|
|
|
|
theorem ex1 : g 0 = 0 := by
|
|
rw [g]
|
|
|
|
#check g._eq_1
|
|
#check g._eq_2
|
|
|
|
theorem ex2 : g 0 = 0 := by
|
|
unfold g
|
|
simp
|
|
|
|
#check g._unfold
|
|
|
|
|
|
end Ex2
|