lean4-htt/tests/lean/run/lcnfInliningIssue.lean
Kyle Miller 45fccc5906
feat: custom eliminators for induction and cases tactics, and beautiful eliminators for Nat (#3629)
Replaces `@[eliminator]` with two attributes `@[induction_eliminator]`
and `@[cases_eliminator]` for defining custom eliminators for the
`induction` and `cases` tactics, respectively.

Adds `Nat.recAux` and `Nat.casesAuxOn`, which are eliminators that are
defeq to `Nat.rec` and `Nat.casesOn`, but these use `0` and `n + 1`
rather than `Nat.zero` and `Nat.succ n`.

For example, using `induction` to prove that the factorial function is
positive now has the following goal states (thanks also to #3616 for the
goal state after unfolding).
```lean
example : 0 < fact x := by
  induction x with
  | zero => decide
  | succ x ih =>
    /-
    x : Nat
    ih : 0 < fact x
    ⊢ 0 < fact (x + 1)
    -/
    unfold fact
    /-
    ...
    ⊢ 0 < (x + 1) * fact x
    -/
    simpa using ih
```

Thanks to @adamtopaz for initial work on splitting the `@[eliminator]`
attribute.
2024-03-09 15:31:51 +00:00

34 lines
913 B
Text

namespace MWE
inductive Id {A : Type u} : A → A → Type u
| refl {a : A} : Id a a
attribute [induction_eliminator] Id.casesOn
infix:50 (priority := high) " = " => Id
def symm {A : Type u} {a b : A} (p : a = b) : b = a :=
by { induction p; exact Id.refl }
def map {A : Type u} {B : Type v} {a b : A} (f : A → B) (p : a = b) : f a = f b :=
by { induction p; apply Id.refl }
def transport {A : Type u} (B : A → Type v) {a b : A} (p : a = b) : B a → B b :=
by { induction p; exact id }
def boolToUniverse : Bool → Type
| true => Unit
| false => Empty
def ffNeqTt : false = true → Empty :=
λ p => transport boolToUniverse (symm p) ()
def isZero : Nat → Bool
| Nat.zero => true
| Nat.succ _ => false
set_option pp.funBinderTypes true
set_option pp.letVarTypes true
set_option trace.Compiler.result true
def succNeqZero (n : Nat) : Nat.succ n = 0 → Empty :=
λ h => ffNeqTt (map isZero h)