Skip to content
This repository was archived by the owner on Jul 24, 2024. It is now read-only.

Commit d9dc30e

Browse files
committed
feat(algebra/free): turn free_magma.lift into an equivalence (#6672)
This will be convenient for some work I have in mind and is more consistent with the pattern used elsewhere, such as: - [`free_algebra.lift`](https://leanprover-community.github.io/mathlib_docs/algebra/free_algebra.html#free_algebra.lift) - [`monoid_algebra.lift`](https://leanprover-community.github.io/mathlib_docs/algebra/monoid_algebra.html#monoid_algebra.lift) - [`universal_enveloping.lift`](https://leanprover-community.github.io/mathlib_docs/algebra/lie/universal_enveloping.html#universal_enveloping_algebra.lift) - ...
1 parent ae77628 commit d9dc30e

File tree

1 file changed

+26
-15
lines changed

1 file changed

+26
-15
lines changed

src/algebra/free.lean

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Authors: Kenny Lau
66
import data.equiv.basic
77
import control.applicative
88
import control.traversable.basic
9+
import algebra.group.hom
910

1011
/-!
1112
# Free constructions
@@ -19,6 +20,7 @@ import control.traversable.basic
1920
(i.e. nonempty lists), with traversable instance and decidable equality.
2021
* `free_semigroup_free_magma α`: isomorphism between `magma.free_semigroup (free_magma α)` and
2122
`free_semigroup α`.
23+
* `free_magma.lift`: the universal property of the free magma, expressing its adjointness.
2224
-/
2325

2426
universes u v l
@@ -63,30 +65,38 @@ attribute [elab_as_eliminator] rec_on' free_add_magma.rec_on'
6365
end free_magma
6466

6567
/-- Lifts a function `α → β` to a magma homomorphism `free_magma α → β` given a magma `β`. -/
66-
def free_magma.lift {α : Type u} {β : Type v} [has_mul β] (f : α → β) : free_magma α → β
68+
def free_magma.lift_aux {α : Type u} {β : Type v} [has_mul β] (f : α → β) : free_magma α → β
6769
| (free_magma.of x) := f x
68-
| (x * y) := x.lift * y.lift
70+
| (x * y) := x.lift_aux * y.lift_aux
6971

7072
/-- Lifts a function `α → β` to an additive magma homomorphism `free_add_magma α → β` given
7173
an additive magma `β`. -/
72-
def free_add_magma.lift {α : Type u} {β : Type v} [has_add β] (f : α → β) : free_add_magma α → β
74+
def free_add_magma.lift_aux {α : Type u} {β : Type v} [has_add β] (f : α → β) : free_add_magma α → β
7375
| (free_add_magma.of x) := f x
74-
| (x + y) := x.lift + y.lift
76+
| (x + y) := x.lift_aux + y.lift_aux
7577

76-
attribute [to_additive free_add_magma.lift] free_magma.lift
78+
attribute [to_additive free_add_magma.lift_aux] free_magma.lift_aux
7779

7880
namespace free_magma
7981

8082
variables {α : Type u} {β : Type v} [has_mul β] (f : α → β)
8183

82-
@[simp, to_additive] lemma lift_of (x) : lift f (of x) = f x := rfl
83-
@[simp, to_additive] lemma lift_mul (x y) : lift f (x * y) = lift f x * lift f y := rfl
84-
8584
@[to_additive]
86-
theorem lift_unique (f : free_magma α → β) (hf : ∀ x y, f (x * y) = f x * f y) :
87-
f = lift (f ∘ of) :=
85+
theorem lift_aux_unique (F : mul_hom (free_magma α) β) : ⇑F = lift_aux (F ∘ of) :=
8886
funext $ λ x, free_magma.rec_on x (λ x, rfl) $ λ x y ih1 ih2,
89-
(hf x y).trans $ congr (congr_arg _ ih1) ih2
87+
(F.map_mul x y).trans $ congr (congr_arg _ ih1) ih2
88+
89+
/-- The universal property of the free magma expressing its adjointness. -/
90+
@[to_additive "The universal property of the free additive magma expressing its adjointness."]
91+
def lift : (α → β) ≃ mul_hom (free_magma α) β :=
92+
{ to_fun := λ f,
93+
{ to_fun := lift_aux f,
94+
map_mul' := λ x y, rfl, },
95+
inv_fun := λ F, F ∘ of,
96+
left_inv := λ f, by { ext, simp only [lift_aux, mul_hom.coe_mk, function.comp_app], },
97+
right_inv := λ F, by { ext, rw [mul_hom.coe_mk, lift_aux_unique], } }
98+
99+
@[simp, to_additive] lemma lift_of (x) : lift f (of x) = f x := rfl
90100

91101
end free_magma
92102

@@ -569,12 +579,13 @@ end free_semigroup
569579
`add_magma.free_add_semigroup (free_add_magma α)` and `free_add_semigroup α`."]
570580
def free_semigroup_free_magma (α : Type u) :
571581
magma.free_semigroup (free_magma α) ≃ free_semigroup α :=
572-
{ to_fun := magma.free_semigroup.lift (free_magma.lift free_semigroup.of) (free_magma.lift_mul _),
573-
inv_fun := free_semigroup.lift (magma.free_semigroup.of ∘ free_magma.of),
574-
left_inv := λ x, magma.free_semigroup.induction_on x $ λ p, by rw magma.free_semigroup.lift_of;
582+
{ to_fun :=
583+
magma.free_semigroup.lift (free_magma.lift free_semigroup.of) (free_magma.lift _).map_mul,
584+
inv_fun := free_semigroup.lift (magma.free_semigroup.of ∘ free_magma.of),
585+
left_inv := λ x, magma.free_semigroup.induction_on x $ λ p, by rw magma.free_semigroup.lift_of;
575586
exact free_magma.rec_on' p
576587
(λ x, by rw [free_magma.lift_of, free_semigroup.lift_of])
577-
(λ x y ihx ihy, by rw [free_magma.lift_mul, free_semigroup.lift_mul, ihx, ihy,
588+
(λ x y ihx ihy, by rw [mul_hom.map_mul, free_semigroup.lift_mul, ihx, ihy,
578589
magma.free_semigroup.of_mul]),
579590
right_inv := λ x, free_semigroup.rec_on x
580591
(λ x, by rw [free_semigroup.lift_of, magma.free_semigroup.lift_of, free_magma.lift_of])

0 commit comments

Comments
 (0)