Skip to content

Commit 46b048d

Browse files
chore: add induction_eliminator and cases_eliminator for free objects (#14135)
Namely, for * `FreeMagma` / `FreeAddMagma` * `FreeSemigroup` / `FreeAddSemigroup` * `FreeMonoid` / `FreeAddMonoid` * `FreeCommRing` * `FreeAlgebra` Split from #12605 Co-authored-by: negiizhao <[email protected]>
1 parent b35f338 commit 46b048d

File tree

8 files changed

+20
-17
lines changed

8 files changed

+20
-17
lines changed

Mathlib/Algebra/Free.lean

+5-4
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ attribute [nolint simpNF] FreeAddMagma.add.injEq
7272
attribute [nolint simpNF] FreeMagma.mul.injEq
7373

7474
/-- Recursor for `FreeMagma` using `x * y` instead of `FreeMagma.mul x y`. -/
75-
@[to_additive (attr := elab_as_elim) "Recursor for `FreeAddMagma` using `x + y` instead of
76-
`FreeAddMagma.add x y`."]
75+
@[to_additive (attr := elab_as_elim, induction_eliminator)
76+
"Recursor for `FreeAddMagma` using `x + y` instead of `FreeAddMagma.add x y`."]
7777
def recOnMul {C : FreeMagma α → Sort l} (x) (ih1 : ∀ x, C (of x))
7878
(ih2 : ∀ x y, C x → C y → C (x * y)) : C x :=
7979
FreeMagma.recOn x ih1 ih2
@@ -394,7 +394,7 @@ def of : α →ₙ* AssocQuotient α where toFun := Quot.mk _; map_mul' _x _y :=
394394
@[to_additive]
395395
instance [Inhabited α] : Inhabited (AssocQuotient α) := ⟨of default⟩
396396

397-
@[to_additive (attr := elab_as_elim)]
397+
@[to_additive (attr := elab_as_elim, induction_eliminator)]
398398
protected theorem induction_on {C : AssocQuotient α → Prop} (x : AssocQuotient α)
399399
(ih : ∀ x, C (of x)) : C x := Quot.induction_on x ih
400400
#align magma.assoc_quotient.induction_on Magma.AssocQuotient.induction_on
@@ -517,7 +517,8 @@ theorem length_of (x : α) : (of x).length = 1 := rfl
517517
instance [Inhabited α] : Inhabited (FreeSemigroup α) := ⟨of default⟩
518518

519519
/-- Recursor for free semigroup using `of` and `*`. -/
520-
@[to_additive (attr := elab_as_elim) "Recursor for free additive semigroup using `of` and `+`."]
520+
@[to_additive (attr := elab_as_elim, induction_eliminator)
521+
"Recursor for free additive semigroup using `of` and `+`."]
521522
protected def recOnMul {C : FreeSemigroup α → Sort l} (x) (ih1 : ∀ x, C (of x))
522523
(ih2 : ∀ x y, C (of x) → C y → C (of x * y)) : C x :=
523524
FreeSemigroup.recOn x fun f s ↦

Mathlib/Algebra/FreeAlgebra.lean

+2-2
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@ namespace FreeAlgebra
563563
If `C` holds for the `algebraMap` of `r : R` into `FreeAlgebra R X`, the `ι` of `x : X`, and is
564564
preserved under addition and muliplication, then it holds for all of `FreeAlgebra R X`.
565565
-/
566-
@[elab_as_elim]
566+
@[elab_as_elim, induction_eliminator]
567567
theorem induction {C : FreeAlgebra R X → Prop}
568568
(h_grade0 : ∀ r, C (algebraMap R (FreeAlgebra R X) r)) (h_grade1 : ∀ x, C (ι R x))
569569
(h_mul : ∀ a b, C a → C b → C (a * b)) (h_add : ∀ a b, C a → C b → C (a + b))
@@ -591,7 +591,7 @@ theorem induction {C : FreeAlgebra R X → Prop}
591591
theorem adjoin_range_ι : Algebra.adjoin R (Set.range (ι R : X → FreeAlgebra R X)) = ⊤ := by
592592
set S := Algebra.adjoin R (Set.range (ι R : X → FreeAlgebra R X))
593593
refine top_unique fun x hx => ?_; clear hx
594-
induction x using FreeAlgebra.induction with
594+
induction x with
595595
| h_grade0 => exact S.algebraMap_mem _
596596
| h_add x y hx hy => exact S.add_mem hx hy
597597
| h_mul x y hx hy => exact S.mul_mem hx hy

Mathlib/Algebra/FreeMonoid/Basic.lean

+6-4
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,9 @@ theorem of_injective : Function.Injective (@of α) := List.singleton_injective
151151
#align free_add_monoid.of_injective FreeAddMonoid.of_injective
152152

153153
/-- Recursor for `FreeMonoid` using `1` and `FreeMonoid.of x * xs` instead of `[]` and `x :: xs`. -/
154-
@[to_additive (attr := elab_as_elim) "Recursor for `FreeAddMonoid` using `0` and
155-
`FreeAddMonoid.of x + xs` instead of `[]` and `x :: xs`."]
154+
@[to_additive (attr := elab_as_elim, induction_eliminator)
155+
"Recursor for `FreeAddMonoid` using `0` and
156+
FreeAddMonoid.of x + xs` instead of `[]` and `x :: xs`."]
156157
-- Porting note: change from `List.recOn` to `List.rec` since only the latter is computable
157158
def recOn {C : FreeMonoid α → Sort*} (xs : FreeMonoid α) (h0 : C 1)
158159
(ih : ∀ x xs, C xs → C (of x * xs)) : C xs := List.rec h0 ih xs
@@ -174,8 +175,9 @@ theorem recOn_of_mul {C : FreeMonoid α → Sort*} (x : α) (xs : FreeMonoid α)
174175

175176
/-- A version of `List.cases_on` for `FreeMonoid` using `1` and `FreeMonoid.of x * xs` instead of
176177
`[]` and `x :: xs`. -/
177-
@[to_additive (attr := elab_as_elim) "A version of `List.casesOn` for `FreeAddMonoid` using `0` and
178-
`FreeAddMonoid.of x + xs` instead of `[]` and `x :: xs`."]
178+
@[to_additive (attr := elab_as_elim, cases_eliminator)
179+
"A version of `List.casesOn` for `FreeAddMonoid` using `0` and
180+
`FreeAddMonoid.of x + xs` instead of `[]` and `x :: xs`."]
179181
def casesOn {C : FreeMonoid α → Sort*} (xs : FreeMonoid α) (h0 : C 1)
180182
(ih : ∀ x xs, C (of x * xs)) : C xs := List.casesOn xs h0 ih
181183
#align free_monoid.cases_on FreeMonoid.casesOn

Mathlib/Algebra/Group/Submonoid/Membership.lean

+1-1
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ theorem closure_induction_left {s : Set M} {p : (m : M) → m ∈ closure s →
419419
p x h := by
420420
simp_rw [closure_eq_mrange] at h
421421
obtain ⟨l, rfl⟩ := h
422-
induction' l using FreeMonoid.recOn with x y ih
422+
induction' l with x y ih
423423
· exact one
424424
· simp only [map_mul, FreeMonoid.lift_eval_of]
425425
refine mul_left _ x.prop (FreeMonoid.lift Subtype.val y) _ (ih ?_)

Mathlib/GroupTheory/Coprod/Basic.lean

+2-2
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ theorem induction_on' {C : M ∗ N → Prop} (m : M ∗ N)
191191
(inl_mul : ∀ m x, C x → C (inl m * x))
192192
(inr_mul : ∀ n x, C x → C (inr n * x)) : C m := by
193193
rcases mk_surjective m with ⟨x, rfl⟩
194-
induction x using FreeMonoid.recOn with
194+
induction x with
195195
| h0 => exact one
196196
| ih x xs ih =>
197197
cases x with
@@ -573,7 +573,7 @@ theorem mk_of_inv_mul : ∀ x : G ⊕ H, mk (of (x.map Inv.inv Inv.inv)) * mk (o
573573
theorem con_mul_left_inv (x : FreeMonoid (G ⊕ H)) :
574574
coprodCon G H (ofList (x.toList.map (Sum.map Inv.inv Inv.inv)).reverse * x) 1 := by
575575
rw [← mk_eq_mk, map_mul, map_one]
576-
induction x using FreeMonoid.recOn with
576+
induction x with
577577
| h0 => simp [map_one mk] -- TODO: fails without `[map_one mk]`
578578
| ih x xs ihx =>
579579
simp only [toList_of_mul, map_cons, reverse_cons, ofList_append, map_mul, ihx, ofList_singleton]

Mathlib/GroupTheory/FreeGroup/Basic.lean

+1-1
Original file line numberDiff line numberDiff line change
@@ -1027,7 +1027,7 @@ instance : Monad FreeGroup.{u} where
10271027
map {_α} {_β} {f} := map f
10281028
bind {_α} {_β} {x} {f} := lift f x
10291029

1030-
@[to_additive (attr := elab_as_elim)]
1030+
@[to_additive (attr := elab_as_elim, induction_eliminator)]
10311031
protected theorem induction_on {C : FreeGroup α → Prop} (z : FreeGroup α) (C1 : C 1)
10321032
(Cp : ∀ x, C <| pure x) (Ci : ∀ x, C (pure x) → C (pure x)⁻¹)
10331033
(Cm : ∀ x y, C x → C y → C (x * y)) : C z :=

Mathlib/RingTheory/FreeCommRing.lean

+2-2
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ lemma of_cons (a : α) (m : Multiset α) : (FreeAbelianGroup.of (Multiplicative.
9595
rw [← Multiset.singleton_add, ofAdd_add,
9696
of, FreeAbelianGroup.of_mul_of]
9797

98-
@[elab_as_elim]
98+
@[elab_as_elim, induction_eliminator]
9999
protected theorem induction_on {C : FreeCommRing α → Prop} (z : FreeCommRing α) (hn1 : C (-1))
100100
(hb : ∀ b, C (of b)) (ha : ∀ x y, C x → C y → C (x + y)) (hm : ∀ x y, C x → C y → C (x * y)) :
101101
C z :=
@@ -360,7 +360,7 @@ protected theorem coe_mul (x y : FreeRing α) : ↑(x * y) = (x : FreeCommRing
360360
variable (α)
361361

362362
protected theorem coe_surjective : Surjective ((↑) : FreeRing α → FreeCommRing α) := fun x => by
363-
induction x using FreeCommRing.induction_on with
363+
induction x with
364364
| hn1 =>
365365
use -1
366366
rfl

Mathlib/RingTheory/FreeRing.lean

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ theorem of_injective : Function.Injective (of : α → FreeRing α) :=
5656
FreeAbelianGroup.of_injective.comp FreeMonoid.of_injective
5757
#align free_ring.of_injective FreeRing.of_injective
5858

59-
@[elab_as_elim]
59+
@[elab_as_elim, induction_eliminator]
6060
protected theorem induction_on {C : FreeRing α → Prop} (z : FreeRing α) (hn1 : C (-1))
6161
(hb : ∀ b, C (of b)) (ha : ∀ x y, C x → C y → C (x + y)) (hm : ∀ x y, C x → C y → C (x * y)) :
6262
C z :=

0 commit comments

Comments
 (0)