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?`.
37 lines
629 B
Text
37 lines
629 B
Text
import Lean
|
|
|
|
open Lean
|
|
open Lean.Meta
|
|
def tst (declName : Name) : MetaM Unit := do
|
|
IO.println (← getUnfoldEqnFor? declName)
|
|
|
|
mutual
|
|
def g (i j : Nat) : Nat :=
|
|
if i < 5 then 0 else
|
|
match j with
|
|
| Nat.zero => 1
|
|
| Nat.succ j => h i j
|
|
def h (i j : Nat) : Nat :=
|
|
match j with
|
|
| 0 => g i 0
|
|
| Nat.succ j => g i j
|
|
end
|
|
termination_by
|
|
g i j => (i + j, 0)
|
|
h i j => (i + j, 1)
|
|
decreasing_by
|
|
simp_wf
|
|
first
|
|
| apply Prod.Lex.left
|
|
apply Nat.lt_succ_self
|
|
| apply Prod.Lex.right
|
|
decide
|
|
|
|
#eval tst ``g
|
|
#check g._eq_1
|
|
#check g._eq_2
|
|
#check g._unfold
|
|
#eval tst ``h
|
|
#check h._eq_1
|
|
#check h._eq_2
|
|
#check h._unfold
|