This introduces the `ArgsPacker` module and abstraction, to replace the exising `PackDomain`/`PackMutual` code. The motivation was that we now have more uses besides `Fix.lean` (`GuessLex` and `FunInd`), and the code was spread in various places. The goals are * consistent function naming withing the the `PSigma` handling, the `PSum` handling, and the combined interface * avoid taking a type apart just based on the `PSigma`/`PSum` nesting, to be robust in case the user happens to be using `PSigma`/`PSum` somewhere. Therefore, always pass an `arity` or `numFuncs` or `varNames` around. * keep all the `PSigma`/`PSum` encoding logic contained within one module (`ArgsPacker`), and keep that module independent of its users (so no `EqnInfos` visible here). * pick good variable names when matching on a packed argument * the unary function now is either called `fun1._unary` or `fun1._mutual`, never `fun1._unary._mutual`. This file has less heavy dependencies than `PackMutual` had, so build parallelism is improved as well.
77 lines
1.4 KiB
Text
77 lines
1.4 KiB
Text
namespace Ex1
|
||
mutual
|
||
def f : Nat → α → α → α
|
||
| 0, a, b => a
|
||
| n, a, b => g a n b |>.1
|
||
termination_by n _ _ => (n, 2)
|
||
decreasing_by
|
||
simp_wf
|
||
apply Prod.Lex.right
|
||
decide
|
||
|
||
def g : α → Nat → α → (α × α)
|
||
| a, 0, b => (a, b)
|
||
| a, n, b => (h a b n, a)
|
||
termination_by _ n _ => (n, 1)
|
||
decreasing_by
|
||
simp_wf
|
||
apply Prod.Lex.right
|
||
decide
|
||
|
||
def h : α → α → Nat → α
|
||
| _a, b, 0 => b
|
||
| a, b, n+1 => f n a b
|
||
termination_by _ _ n => (n, 0)
|
||
decreasing_by
|
||
simp_wf
|
||
apply Prod.Lex.left
|
||
apply Nat.lt_succ_self
|
||
end
|
||
|
||
#eval f 5 'a' 'b'
|
||
#print f
|
||
#print g
|
||
#print h
|
||
#print f._mutual
|
||
end Ex1
|
||
|
||
namespace Ex2
|
||
mutual
|
||
def f : Nat → α → α → α
|
||
| 0, a, b => a
|
||
| n, a, b => g a n b |>.1
|
||
termination_by n _ _ => (n, 2)
|
||
|
||
def g : α → Nat → α → (α × α)
|
||
| a, 0, b => (a, b)
|
||
| a, n, b => (h a b n, a)
|
||
termination_by _ n _ => (n, 1)
|
||
|
||
def h : α → α → Nat → α
|
||
| a, b, 0 => b
|
||
| a, b, n+1 => f n a b
|
||
termination_by _ _ n => (n, 0)
|
||
end
|
||
|
||
#print f._mutual
|
||
|
||
end Ex2
|
||
|
||
namespace Ex3
|
||
mutual
|
||
def f : Nat → α → α → α
|
||
| 0, a, b => a
|
||
| n, a, b => g a n b |>.1
|
||
|
||
def g : α → Nat → α → (α × α)
|
||
| a, 0, b => (a, b)
|
||
| a, n, b => (h a b n, a)
|
||
|
||
def h : α → α → Nat → α
|
||
| a, b, 0 => b
|
||
| a, b, n+1 => f n a b
|
||
end
|
||
|
||
#print f._mutual
|
||
|
||
end Ex3
|