lean4-htt/tests/lean/run/mutwf3.lean
2022-02-18 10:40:32 -08:00

61 lines
1.3 KiB
Text
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

namespace Ex1
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
termination_by'
invImage
(fun
| PSum.inl ⟨n, _, _⟩ => (n, 2)
| PSum.inr <| PSum.inl ⟨_, n, _⟩ => (n, 1)
| PSum.inr <| PSum.inr ⟨_, _, n⟩ => (n, 0))
(Prod.lex sizeOfWFRel sizeOfWFRel)
decreasing_by
simp [invImage, InvImage, Prod.lex, sizeOfWFRel, measure, Nat.lt_wfRel, WellFoundedRelation.rel]
first
| apply Prod.Lex.left
apply Nat.lt_succ_self
| apply Prod.Lex.right
decide
#eval f 5 'a' 'b'
#print f
#print g
#print h
#print f._unary._mutual
end Ex1
namespace Ex2
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
termination_by'
invImage
(fun
| PSum.inl ⟨n, _, _⟩ => (n, 2)
| PSum.inr <| PSum.inl ⟨_, n, _⟩ => (n, 1)
| PSum.inr <| PSum.inr ⟨_, _, n⟩ => (n, 0))
(Prod.lex sizeOfWFRel sizeOfWFRel)
#print f._unary._mutual
end Ex2