Skip to content

Commit

Permalink
chore(algebra/order/group/defs): split file (#17787)
Browse files Browse the repository at this point in the history
Splits:
* algebra/order/group/defs.lean
* algebra/group/with_one.lean
* algebra/order/monoid/with_zero.lean

This will get us unstuck on the mathlib4 port, moving some of the files (about algebraic morphisms and equivalences) that are currently waiting for fixes in Lean 4 off the critical path.



Co-authored-by: Scott Morrison <scott.morrison@gmail.com>
  • Loading branch information
semorrison and semorrison committed Dec 2, 2022
1 parent 1c9ea25 commit 4bcba0d
Show file tree
Hide file tree
Showing 17 changed files with 293 additions and 174 deletions.
2 changes: 1 addition & 1 deletion counterexamples/linear_order_with_pos_mul_pos_eq_zero.lean
Expand Up @@ -5,7 +5,7 @@ Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin, Damiano Testa, Kevin Buzzard
-/
import algebra.order.monoid.defs
import algebra.order.monoid.with_zero
import algebra.order.monoid.with_zero.defs

/-!
An example of a `linear_ordered_comm_monoid_with_zero` in which the product of two positive
Expand Down
2 changes: 1 addition & 1 deletion src/algebra/category/Mon/adjunctions.lean
Expand Up @@ -5,7 +5,7 @@ Authors: Julian Kuelshammer
-/
import algebra.category.Mon.basic
import algebra.category.Semigroup.basic
import algebra.group.with_one
import algebra.group.with_one.basic
import algebra.free_monoid.basic

/-!
Expand Down
1 change: 1 addition & 0 deletions src/algebra/free.lean
Expand Up @@ -4,6 +4,7 @@ Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau
-/
import algebra.hom.group
import algebra.hom.equiv.basic
import control.applicative
import control.traversable.basic
import logic.equiv.defs
Expand Down
2 changes: 1 addition & 1 deletion src/algebra/group/default.lean
Expand Up @@ -5,7 +5,7 @@ Authors: Jeremy Avigad, Leonardo de Moura, Michael Howes
-/
import algebra.group.conj
import algebra.group.type_tags
import algebra.group.with_one
import algebra.group.with_one.basic
import algebra.hom.units

/-!
Expand Down
123 changes: 123 additions & 0 deletions src/algebra/group/with_one/basic.lean
@@ -0,0 +1,123 @@
/-
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Johan Commelin
-/
import algebra.group.with_one.defs
import algebra.hom.equiv.basic

/-!
# More operations on `with_one` and `with_zero`
This file defines various bundled morphisms on `with_one` and `with_zero`
that were not available in `algebra/group/with_one/defs`.
## Main definitions
* `with_one.lift`, `with_zero.lift`
* `with_one.map`, `with_zero.map`
-/

universes u v w
variables {α : Type u} {β : Type v} {γ : Type w}

namespace with_one

section
-- workaround: we make `with_one`/`with_zero` irreducible for this definition, otherwise `simps`
-- will unfold it in the statement of the lemma it generates.
local attribute [irreducible] with_one with_zero
/-- `coe` as a bundled morphism -/
@[to_additive "`coe` as a bundled morphism", simps apply]
def coe_mul_hom [has_mul α] : α →ₙ* (with_one α) :=
{ to_fun := coe, map_mul' := λ x y, rfl }

end

section lift

local attribute [semireducible] with_one with_zero

variables [has_mul α] [mul_one_class β]

/-- Lift a semigroup homomorphism `f` to a bundled monoid homorphism. -/
@[to_additive "Lift an add_semigroup homomorphism `f` to a bundled add_monoid homorphism."]
def lift : (α →ₙ* β) ≃ (with_one α →* β) :=
{ to_fun := λ f,
{ to_fun := λ x, option.cases_on x 1 f,
map_one' := rfl,
map_mul' := λ x y,
with_one.cases_on x (by { rw one_mul, exact (one_mul _).symm }) $ λ x,
with_one.cases_on y (by { rw mul_one, exact (mul_one _).symm }) $ λ y,
f.map_mul x y },
inv_fun := λ F, F.to_mul_hom.comp coe_mul_hom,
left_inv := λ f, mul_hom.ext $ λ x, rfl,
right_inv := λ F, monoid_hom.ext $ λ x, with_one.cases_on x F.map_one.symm $ λ x, rfl }

variables (f : α →ₙ* β)

@[simp, to_additive]
lemma lift_coe (x : α) : lift f x = f x := rfl

@[simp, to_additive]
lemma lift_one : lift f 1 = 1 := rfl

@[to_additive]
theorem lift_unique (f : with_one α →* β) : f = lift (f.to_mul_hom.comp coe_mul_hom) :=
(lift.apply_symm_apply f).symm

end lift

section map

variables [has_mul α] [has_mul β] [has_mul γ]

/-- Given a multiplicative map from `α → β` returns a monoid homomorphism
from `with_one α` to `with_one β` -/
@[to_additive "Given an additive map from `α → β` returns an add_monoid homomorphism
from `with_zero α` to `with_zero β`"]
def map (f : α →ₙ* β) : with_one α →* with_one β :=
lift (coe_mul_hom.comp f)

@[simp, to_additive] lemma map_coe (f : α →ₙ* β) (a : α) : map f (a : with_one α) = f a :=
lift_coe _ _

@[simp, to_additive]
lemma map_id : map (mul_hom.id α) = monoid_hom.id (with_one α) :=
by { ext, induction x using with_one.cases_on; refl }

@[to_additive]
lemma map_map (f : α →ₙ* β) (g : β →ₙ* γ) (x) :
map g (map f x) = map (g.comp f) x :=
by { induction x using with_one.cases_on; refl }

@[simp, to_additive]
lemma map_comp (f : α →ₙ* β) (g : β →ₙ* γ) :
map (g.comp f) = (map g).comp (map f) :=
monoid_hom.ext $ λ x, (map_map f g x).symm

/-- A version of `equiv.option_congr` for `with_one`. -/
@[to_additive "A version of `equiv.option_congr` for `with_zero`.", simps apply]
def _root_.mul_equiv.with_one_congr (e : α ≃* β) : with_one α ≃* with_one β :=
{ to_fun := map e.to_mul_hom,
inv_fun := map e.symm.to_mul_hom,
left_inv := λ x, (map_map _ _ _).trans $ by induction x using with_one.cases_on; { simp },
right_inv := λ x, (map_map _ _ _).trans $ by induction x using with_one.cases_on; { simp },
.. map e.to_mul_hom }

@[simp]
lemma _root_.mul_equiv.with_one_congr_refl : (mul_equiv.refl α).with_one_congr = mul_equiv.refl _ :=
mul_equiv.to_monoid_hom_injective map_id

@[simp]
lemma _root_.mul_equiv.with_one_congr_symm (e : α ≃* β) :
e.with_one_congr.symm = e.symm.with_one_congr := rfl

@[simp]
lemma _root_.mul_equiv.with_one_congr_trans (e₁ : α ≃* β) (e₂ : β ≃* γ) :
e₁.with_one_congr.trans e₂.with_one_congr = (e₁.trans e₂).with_one_congr :=
mul_equiv.to_monoid_hom_injective (map_comp _ _).symm

end map

end with_one
Expand Up @@ -4,8 +4,6 @@ Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Johan Commelin
-/
import order.with_bot
import algebra.hom.equiv.basic
import algebra.group_with_zero.units.basic
import algebra.ring.defs

/-!
Expand Down Expand Up @@ -134,103 +132,8 @@ instance [comm_semigroup α] : comm_monoid (with_one α) :=
{ mul_comm := (option.lift_or_get_comm _).1,
..with_one.monoid }

section
-- workaround: we make `with_one`/`with_zero` irreducible for this definition, otherwise `simps`
-- will unfold it in the statement of the lemma it generates.
local attribute [irreducible] with_one with_zero
/-- `coe` as a bundled morphism -/
@[to_additive "`coe` as a bundled morphism", simps apply]
def coe_mul_hom [has_mul α] : α →ₙ* (with_one α) :=
{ to_fun := coe, map_mul' := λ x y, rfl }

end

section lift

variables [has_mul α] [mul_one_class β]

/-- Lift a semigroup homomorphism `f` to a bundled monoid homorphism. -/
@[to_additive "Lift an add_semigroup homomorphism `f` to a bundled add_monoid homorphism."]
def lift : (α →ₙ* β) ≃ (with_one α →* β) :=
{ to_fun := λ f,
{ to_fun := λ x, option.cases_on x 1 f,
map_one' := rfl,
map_mul' := λ x y,
with_one.cases_on x (by { rw one_mul, exact (one_mul _).symm }) $ λ x,
with_one.cases_on y (by { rw mul_one, exact (mul_one _).symm }) $ λ y,
f.map_mul x y },
inv_fun := λ F, F.to_mul_hom.comp coe_mul_hom,
left_inv := λ f, mul_hom.ext $ λ x, rfl,
right_inv := λ F, monoid_hom.ext $ λ x, with_one.cases_on x F.map_one.symm $ λ x, rfl }

variables (f : α →ₙ* β)

@[simp, to_additive]
lemma lift_coe (x : α) : lift f x = f x := rfl

@[simp, to_additive]
lemma lift_one : lift f 1 = 1 := rfl

@[to_additive]
theorem lift_unique (f : with_one α →* β) : f = lift (f.to_mul_hom.comp coe_mul_hom) :=
(lift.apply_symm_apply f).symm

end lift

attribute [irreducible] with_one

section map

variables [has_mul α] [has_mul β] [has_mul γ]

/-- Given a multiplicative map from `α → β` returns a monoid homomorphism
from `with_one α` to `with_one β` -/
@[to_additive "Given an additive map from `α → β` returns an add_monoid homomorphism
from `with_zero α` to `with_zero β`"]
def map (f : α →ₙ* β) : with_one α →* with_one β :=
lift (coe_mul_hom.comp f)

@[simp, to_additive] lemma map_coe (f : α →ₙ* β) (a : α) : map f (a : with_one α) = f a :=
lift_coe _ _

@[simp, to_additive]
lemma map_id : map (mul_hom.id α) = monoid_hom.id (with_one α) :=
by { ext, induction x using with_one.cases_on; refl }

@[to_additive]
lemma map_map (f : α →ₙ* β) (g : β →ₙ* γ) (x) :
map g (map f x) = map (g.comp f) x :=
by { induction x using with_one.cases_on; refl }

@[simp, to_additive]
lemma map_comp (f : α →ₙ* β) (g : β →ₙ* γ) :
map (g.comp f) = (map g).comp (map f) :=
monoid_hom.ext $ λ x, (map_map f g x).symm

/-- A version of `equiv.option_congr` for `with_one`. -/
@[to_additive "A version of `equiv.option_congr` for `with_zero`.", simps apply]
def _root_.mul_equiv.with_one_congr (e : α ≃* β) : with_one α ≃* with_one β :=
{ to_fun := map e.to_mul_hom,
inv_fun := map e.symm.to_mul_hom,
left_inv := λ x, (map_map _ _ _).trans $ by induction x using with_one.cases_on; { simp },
right_inv := λ x, (map_map _ _ _).trans $ by induction x using with_one.cases_on; { simp },
.. map e.to_mul_hom }

@[simp]
lemma _root_.mul_equiv.with_one_congr_refl : (mul_equiv.refl α).with_one_congr = mul_equiv.refl _ :=
mul_equiv.to_monoid_hom_injective map_id

@[simp]
lemma _root_.mul_equiv.with_one_congr_symm (e : α ≃* β) :
e.with_one_congr.symm = e.symm.with_one_congr := rfl

@[simp]
lemma _root_.mul_equiv.with_one_congr_trans (e₁ : α ≃* β) (e₂ : β ≃* γ) :
e₁.with_one_congr.trans e₂.with_one_congr = (e₁.trans e₂).with_one_congr :=
mul_equiv.to_monoid_hom_injective (map_comp _ _).symm

end map

@[simp, norm_cast, to_additive]
lemma coe_mul [has_mul α] (a b : α) : ((a * b : α) : with_one α) = a * b := rfl

Expand Down Expand Up @@ -441,14 +344,6 @@ instance [semiring α] : semiring (with_zero α) :=
..with_zero.mul_zero_class,
..with_zero.monoid_with_zero }

/-- Any group is isomorphic to the units of itself adjoined with `0`. -/
def units_with_zero_equiv [group α] : (with_zero α)ˣ ≃* α :=
{ to_fun := λ a, unzero a.ne_zero,
inv_fun := λ a, units.mk0 a coe_ne_zero,
left_inv := λ _, units.ext $ by simpa only [coe_unzero],
right_inv := λ _, rfl,
map_mul' := λ _ _, coe_inj.mp $ by simpa only [coe_unzero, coe_mul] }

attribute [irreducible] with_zero

end with_zero
27 changes: 27 additions & 0 deletions src/algebra/group/with_one/units.lean
@@ -0,0 +1,27 @@
/-
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Johan Commelin
-/
import algebra.group.with_one.basic
import algebra.group_with_zero.units.basic

/-!
# Isomorphism between a group and the units of itself adjoined with `0`
## Notes
This is here to keep `algebra.group_with_zero.units.basic` out of the import requirements of
`algebra.order.field.defs`.
-/

namespace with_zero

/-- Any group is isomorphic to the units of itself adjoined with `0`. -/
def units_with_zero_equiv {α : Type*} [group α] : (with_zero α)ˣ ≃* α :=
{ to_fun := λ a, unzero a.ne_zero,
inv_fun := λ a, units.mk0 a coe_ne_zero,
left_inv := λ _, units.ext $ by simpa only [coe_unzero],
right_inv := λ _, rfl,
map_mul' := λ _ _, coe_inj.mp $ by simpa only [coe_unzero, coe_mul] }

end with_zero
3 changes: 3 additions & 0 deletions src/algebra/order/field/defs.lean
Expand Up @@ -42,3 +42,6 @@ class linear_ordered_field (α : Type*) extends linear_ordered_comm_ring α, fie
instance linear_ordered_field.to_linear_ordered_semifield [linear_ordered_field α] :
linear_ordered_semifield α :=
{ ..linear_ordered_ring.to_linear_ordered_semiring, ..‹linear_ordered_field α› }

-- Guard against import creep.
assert_not_exists monoid_hom
2 changes: 1 addition & 1 deletion src/algebra/order/group/abs.lean
Expand Up @@ -4,7 +4,7 @@ Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura, Mario Carneiro, Johannes Hölzl
-/
import algebra.abs
import algebra.order.group.defs
import algebra.order.group.order_iso
import order.min_max

/-!
Expand Down

0 comments on commit 4bcba0d

Please sign in to comment.