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?`.
105 lines
1.7 KiB
Text
105 lines
1.7 KiB
Text
mutual
|
||
inductive Even : Nat → Prop
|
||
| base : Even 0
|
||
| step : Odd n → Even (n+1)
|
||
inductive Odd : Nat → Prop
|
||
| step : Even n → Odd (n+1)
|
||
end
|
||
termination_by _ n => n -- Error
|
||
|
||
mutual
|
||
def f (n : Nat) :=
|
||
if n == 0 then 0 else f (n / 2) + 1
|
||
termination_by _ => n -- Error
|
||
end
|
||
|
||
mutual
|
||
def f (n : Nat) :=
|
||
if n == 0 then 0 else f (n / 2) + 1
|
||
end
|
||
termination_by n => n -- Error
|
||
|
||
|
||
def g' (n : Nat) :=
|
||
match n with
|
||
| 0 => 1
|
||
| n+1 => g' n * 3
|
||
termination_by
|
||
h' n => n -- Error
|
||
|
||
def g' (n : Nat) :=
|
||
match n with
|
||
| 0 => 1
|
||
| n+1 => g' n * 3
|
||
termination_by
|
||
g' n => n
|
||
_ n => n -- Error
|
||
|
||
mutual
|
||
def isEven : Nat → Bool
|
||
| 0 => true
|
||
| n+1 => isOdd n
|
||
def isOdd : Nat → Bool
|
||
| 0 => false
|
||
| n+1 => isEven n
|
||
end
|
||
termination_by
|
||
isEven x => x -- Error
|
||
|
||
mutual
|
||
def isEven : Nat → Bool
|
||
| 0 => true
|
||
| n+1 => isOdd n
|
||
def isOdd : Nat → Bool
|
||
| 0 => false
|
||
| n+1 => isEven n
|
||
end
|
||
termination_by
|
||
isEven x => x
|
||
isOd x => x -- Error
|
||
|
||
mutual
|
||
def isEven : Nat → Bool
|
||
| 0 => true
|
||
| n+1 => isOdd n
|
||
def isOdd : Nat → Bool
|
||
| 0 => false
|
||
| n+1 => isEven n
|
||
end
|
||
termination_by
|
||
isEven x => x
|
||
isEven y => y -- Error
|
||
|
||
mutual
|
||
def isEven : Nat → Bool
|
||
| 0 => true
|
||
| n+1 => isOdd n
|
||
def isOdd : Nat → Bool
|
||
| 0 => false
|
||
| n+1 => isEven n
|
||
end
|
||
termination_by
|
||
isEven x => x
|
||
_ x => x
|
||
_ x => x + 1 -- Error
|
||
|
||
|
||
namespace Test
|
||
mutual
|
||
def f : Nat → α → α → α
|
||
| 0, a, b => a
|
||
| n+1, a, b => g n a b |>.1
|
||
|
||
def g : Nat → α → α → (α × α)
|
||
| 0, a, b => (a, b)
|
||
| n+1, a, b => (h n a b, a)
|
||
|
||
def h : Nat → α → α → α
|
||
| 0, a, b => b
|
||
| n+1, a, b => f n a b
|
||
end
|
||
termination_by
|
||
f n => n -- Error
|
||
g n => n
|
||
|
||
end Test
|