source stringlengths 17 118 | lean4 stringlengths 0 335k |
|---|---|
.lake/packages/mathlib/Mathlib/Algebra/Group/MinimalAxioms.lean | import Mathlib.Algebra.Group.Defs
/-!
# Minimal Axioms for a Group
This file defines constructors to define a group structure on a Type, while proving only three
equalities.
## Main Definitions
* `Group.ofLeftAxioms`: Define a group structure on a Type by proving `∀ a, 1 * a = a` and
`∀ a, a⁻¹ * a = 1` and associativity.
* `Group.ofRightAxioms`: Define a group structure on a Type by proving `∀ a, a * 1 = a` and
`∀ a, a * a⁻¹ = 1` and associativity.
-/
assert_not_exists MonoidWithZero DenselyOrdered
universe u
/-- Define a `Group` structure on a Type by proving `∀ a, 1 * a = a` and
`∀ a, a⁻¹ * a = 1`.
Note that this uses the default definitions for `npow`, `zpow` and `div`.
See note [reducible non-instances]. -/
@[to_additive
/-- Define an `AddGroup` structure on a Type by proving `∀ a, 0 + a = a` and
`∀ a, -a + a = 0`.
Note that this uses the default definitions for `nsmul`, `zsmul` and `sub`.
See note [reducible non-instances]. -/]
abbrev Group.ofLeftAxioms {G : Type u} [Mul G] [Inv G] [One G]
(assoc : ∀ a b c : G, (a * b) * c = a * (b * c))
(one_mul : ∀ a : G, 1 * a = a)
(inv_mul_cancel : ∀ a : G, a⁻¹ * a = 1) : Group G :=
{ mul_assoc := assoc,
one_mul := one_mul,
inv_mul_cancel := inv_mul_cancel,
mul_one := fun a => by
have mul_inv_cancel : ∀ a : G, a * a⁻¹ = 1 := fun a =>
calc a * a⁻¹ = 1 * (a * a⁻¹) := (one_mul _).symm
_ = ((a * a⁻¹)⁻¹ * (a * a⁻¹)) * (a * a⁻¹) := by
rw [inv_mul_cancel]
_ = (a * a⁻¹)⁻¹ * (a * ((a⁻¹ * a) * a⁻¹)) := by
simp only [assoc]
_ = 1 := by
rw [inv_mul_cancel, one_mul, inv_mul_cancel]
rw [← inv_mul_cancel a, ← assoc, mul_inv_cancel a, one_mul] }
/-- Define a `Group` structure on a Type by proving `∀ a, a * 1 = a` and
`∀ a, a * a⁻¹ = 1`.
Note that this uses the default definitions for `npow`, `zpow` and `div`.
See note [reducible non-instances]. -/
@[to_additive
/-- Define an `AddGroup` structure on a Type by proving `∀ a, a + 0 = a` and
`∀ a, a + -a = 0`.
Note that this uses the default definitions for `nsmul`, `zsmul` and `sub`.
See note [reducible non-instances]. -/]
abbrev Group.ofRightAxioms {G : Type u} [Mul G] [Inv G] [One G]
(assoc : ∀ a b c : G, (a * b) * c = a * (b * c))
(mul_one : ∀ a : G, a * 1 = a)
(mul_inv_cancel : ∀ a : G, a * a⁻¹ = 1) : Group G :=
have inv_mul_cancel : ∀ a : G, a⁻¹ * a = 1 := fun a =>
calc a⁻¹ * a = (a⁻¹ * a) * 1 := (mul_one _).symm
_ = (a⁻¹ * a) * ((a⁻¹ * a) * (a⁻¹ * a)⁻¹) := by
rw [mul_inv_cancel]
_ = ((a⁻¹ * (a * a⁻¹)) * a) * (a⁻¹ * a)⁻¹ := by
simp only [assoc]
_ = 1 := by
rw [mul_inv_cancel, mul_one, mul_inv_cancel]
{ mul_assoc := assoc,
mul_one := mul_one,
inv_mul_cancel := inv_mul_cancel,
one_mul := fun a => by
rw [← mul_inv_cancel a, assoc, inv_mul_cancel, mul_one] } |
.lake/packages/mathlib/Mathlib/Algebra/Group/NatPowAssoc.lean | import Mathlib.Algebra.Group.Pi.Basic
import Mathlib.Algebra.Group.Prod
import Mathlib.Algebra.Ring.Int.Defs
import Mathlib.Data.Nat.Cast.Basic
/-!
# Typeclasses for power-associative structures
In this file we define power-associativity for algebraic structures with a multiplication operation.
The class is a Prop-valued mixin named `NatPowAssoc`.
## Results
- `npow_add` a defining property: `x ^ (k + n) = x ^ k * x ^ n`
- `npow_one` a defining property: `x ^ 1 = x`
- `npow_assoc` strictly positive powers of an element have associative multiplication.
- `npow_comm` `x ^ m * x ^ n = x ^ n * x ^ m` for strictly positive `m` and `n`.
- `npow_mul` `x ^ (m * n) = (x ^ m) ^ n` for strictly positive `m` and `n`.
- `npow_eq_pow` monoid exponentiation coincides with semigroup exponentiation.
## Instances
We also produce the following instances:
- `NatPowAssoc` for Monoids, Pi types and products.
## TODO
* to_additive?
-/
assert_not_exists DenselyOrdered
variable {M : Type*}
/-- A mixin for power-associative multiplication. -/
class NatPowAssoc (M : Type*) [MulOneClass M] [Pow M ℕ] : Prop where
/-- Multiplication is power-associative. -/
protected npow_add : ∀ (k n : ℕ) (x : M), x ^ (k + n) = x ^ k * x ^ n
/-- Exponent zero is one. -/
protected npow_zero : ∀ (x : M), x ^ 0 = 1
/-- Exponent one is identity. -/
protected npow_one : ∀ (x : M), x ^ 1 = x
section MulOneClass
variable [MulOneClass M] [Pow M ℕ] [NatPowAssoc M]
theorem npow_add (k n : ℕ) (x : M) : x ^ (k + n) = x ^ k * x ^ n :=
NatPowAssoc.npow_add k n x
@[simp]
theorem npow_zero (x : M) : x ^ 0 = 1 :=
NatPowAssoc.npow_zero x
@[simp]
theorem npow_one (x : M) : x ^ 1 = x :=
NatPowAssoc.npow_one x
theorem npow_mul_assoc (k m n : ℕ) (x : M) :
(x ^ k * x ^ m) * x ^ n = x ^ k * (x ^ m * x ^ n) := by
simp only [← npow_add, add_assoc]
theorem npow_mul_comm (m n : ℕ) (x : M) :
x ^ m * x ^ n = x ^ n * x ^ m := by simp only [← npow_add, add_comm]
theorem npow_mul (x : M) (m n : ℕ) : x ^ (m * n) = (x ^ m) ^ n := by
induction n with
| zero => rw [npow_zero, Nat.mul_zero, npow_zero]
| succ n ih => rw [mul_add, npow_add, ih, mul_one, npow_add, npow_one]
theorem npow_mul' (x : M) (m n : ℕ) : x ^ (m * n) = (x ^ n) ^ m := by
rw [mul_comm]
exact npow_mul x n m
end MulOneClass
section Neg
theorem neg_npow_assoc {R : Type*} [NonAssocRing R] [Pow R ℕ] [NatPowAssoc R] (a b : R) (k : ℕ) :
(-1) ^ k * a * b = (-1) ^ k * (a * b) := by
induction k with
| zero => simp only [npow_zero, one_mul]
| succ k ih =>
rw [npow_add, npow_one, ← neg_mul_comm, mul_one]
simp only [neg_mul, ih]
end Neg
instance Pi.instNatPowAssoc {ι : Type*} {α : ι → Type*} [∀ i, MulOneClass <| α i] [∀ i, Pow (α i) ℕ]
[∀ i, NatPowAssoc <| α i] : NatPowAssoc (∀ i, α i) where
npow_add _ _ _ := by ext; simp [npow_add]
npow_zero _ := by ext; simp
npow_one _ := by ext; simp
instance Prod.instNatPowAssoc {N : Type*} [MulOneClass M] [Pow M ℕ] [NatPowAssoc M] [MulOneClass N]
[Pow N ℕ] [NatPowAssoc N] : NatPowAssoc (M × N) where
npow_add _ _ _ := by ext <;> simp [npow_add]
npow_zero _ := by ext <;> simp
npow_one _ := by ext <;> simp
section Monoid
variable [Monoid M]
instance Monoid.PowAssoc : NatPowAssoc M where
npow_add _ _ _ := pow_add _ _ _
npow_zero _ := pow_zero _
npow_one _ := pow_one _
@[simp, norm_cast]
theorem Nat.cast_npow (R : Type*) [NonAssocSemiring R] [Pow R ℕ] [NatPowAssoc R] (n m : ℕ) :
(↑(n ^ m) : R) = (↑n : R) ^ m := by
induction m with
| zero => simp only [pow_zero, Nat.cast_one, npow_zero]
| succ m ih => rw [npow_add, npow_add, Nat.cast_mul, ih, npow_one, npow_one]
@[simp, norm_cast]
theorem Int.cast_npow (R : Type*) [NonAssocRing R] [Pow R ℕ] [NatPowAssoc R]
(n : ℤ) : ∀ (m : ℕ), @Int.cast R NonAssocRing.toIntCast (n ^ m) = (n : R) ^ m
| 0 => by
rw [pow_zero, npow_zero, Int.cast_one]
| m + 1 => by
rw [npow_add, npow_one, Int.cast_mul, Int.cast_npow R n m, npow_add, npow_one]
end Monoid |
.lake/packages/mathlib/Mathlib/Algebra/Group/ForwardDiff.lean | import Mathlib.Algebra.BigOperators.Pi
import Mathlib.Algebra.Group.AddChar
import Mathlib.Algebra.Module.Submodule.LinearMap
import Mathlib.Data.Nat.Choose.Sum
import Mathlib.Tactic.Abel
import Mathlib.Algebra.GroupWithZero.Action.Pi
import Mathlib.Algebra.Polynomial.Basic
import Mathlib.Algebra.Polynomial.Degree.Definitions
import Mathlib.Algebra.Polynomial.Eval.Degree
/-!
# Forward difference operators and Newton series
We define the forward difference operator, sending `f` to the function `x ↦ f (x + h) - f x` for
a given `h` (for any additive semigroup, taking values in an abelian group). The notation `Δ_[h]` is
defined for this operator, scoped in namespace `fwdDiff`.
We prove two key formulae about this operator:
* `shift_eq_sum_fwdDiff_iter`: the **Gregory-Newton formula**, expressing `f (y + n • h)` as a
linear combination of forward differences of `f` at `y`, for `n ∈ ℕ`;
* `fwdDiff_iter_eq_sum_shift`: formula expressing the `n`-th forward difference of `f` at `y` as
a linear combination of `f (y + k • h)` for `0 ≤ k ≤ n`.
We also prove some auxiliary results about iterated forward differences of the function
`n ↦ n.choose k`.
-/
open Finset Nat Function Polynomial
variable {M G : Type*} [AddCommMonoid M] [AddCommGroup G] (h : M)
/--
Forward difference operator, `fwdDiff h f n = f (n + h) - f n`. The notation `Δ_[h]` for this
operator is available in the `fwdDiff` namespace.
-/
def fwdDiff (h : M) (f : M → G) : M → G := fun n ↦ f (n + h) - f n
@[inherit_doc] scoped[fwdDiff] notation "Δ_[" h "]" => fwdDiff h
open fwdDiff
@[simp] lemma fwdDiff_add (h : M) (f g : M → G) :
Δ_[h] (f + g) = Δ_[h] f + Δ_[h] g :=
add_sub_add_comm ..
@[simp] lemma fwdDiff_const (g : G) : Δ_[h] (fun _ ↦ g : M → G) = fun _ ↦ 0 :=
funext fun _ ↦ sub_self g
section smul
lemma fwdDiff_smul {R : Type} [Ring R] [Module R G] (f : M → R) (g : M → G) :
Δ_[h] (f • g) = Δ_[h] f • g + f • Δ_[h] g + Δ_[h] f • Δ_[h] g := by
ext y
simp only [fwdDiff, Pi.smul_apply', Pi.add_apply, smul_sub, sub_smul]
abel
-- Note `fwdDiff_const_smul` is more general than `fwdDiff_smul` since it allows `R` to be a
-- semiring, rather than a ring; in particular `R = ℕ` is allowed.
@[simp] lemma fwdDiff_const_smul {R : Type*} [Monoid R] [DistribMulAction R G] (r : R) (f : M → G) :
Δ_[h] (r • f) = r • Δ_[h] f :=
funext fun _ ↦ (smul_sub ..).symm
@[simp] lemma fwdDiff_smul_const {R : Type} [Ring R] [Module R G] (f : M → R) (g : G) :
Δ_[h] (fun y ↦ f y • g) = Δ_[h] f • fun _ ↦ g := by
ext y
simp only [fwdDiff, Pi.smul_apply', sub_smul]
end smul
namespace fwdDiff_aux
/-!
## Forward-difference and shift operators as linear endomorphisms
This section contains versions of the forward-difference operator and the shift operator bundled as
`ℤ`-linear endomorphisms. These are useful for certain proofs; but they are slightly annoying to
use, as the source and target types of the maps have to be specified each time, and various
coercions need to be un-wound when the operators are applied, so we also provide the un-bundled
version.
-/
variable (M G) in
/-- Linear-endomorphism version of the forward difference operator. -/
@[simps]
def fwdDiffₗ : Module.End ℤ (M → G) where
toFun := fwdDiff h
map_add' := fwdDiff_add h
map_smul' := fwdDiff_const_smul h
lemma coe_fwdDiffₗ : ↑(fwdDiffₗ M G h) = fwdDiff h := rfl
lemma coe_fwdDiffₗ_pow (n : ℕ) : ↑(fwdDiffₗ M G h ^ n) = (fwdDiff h)^[n] := by
ext; rw [Module.End.pow_apply, coe_fwdDiffₗ]
variable (M G) in
/-- Linear-endomorphism version of the shift-by-1 operator. -/
def shiftₗ : Module.End ℤ (M → G) := fwdDiffₗ M G h + 1
lemma shiftₗ_apply (f : M → G) (y : M) : shiftₗ M G h f y = f (y + h) := by simp [shiftₗ, fwdDiff]
lemma shiftₗ_pow_apply (f : M → G) (k : ℕ) (y : M) : (shiftₗ M G h ^ k) f y = f (y + k • h) := by
induction k generalizing f with
| zero => simp
| succ k IH => simp [pow_add, IH (shiftₗ M G h f), shiftₗ_apply, add_assoc, add_nsmul]
end fwdDiff_aux
open fwdDiff_aux
@[simp] lemma fwdDiff_finset_sum {α : Type*} (s : Finset α) (f : α → M → G) :
Δ_[h] (∑ k ∈ s, f k) = ∑ k ∈ s, Δ_[h] (f k) :=
map_sum (fwdDiffₗ M G h) f s
@[simp] lemma fwdDiff_iter_add (f g : M → G) (n : ℕ) :
Δ_[h]^[n] (f + g) = Δ_[h]^[n] f + Δ_[h]^[n] g := by
simpa only [coe_fwdDiffₗ_pow] using map_add (fwdDiffₗ M G h ^ n) f g
@[simp] lemma fwdDiff_iter_const_smul {R : Type*} [Monoid R] [DistribMulAction R G]
(r : R) (f : M → G) (n : ℕ) : Δ_[h]^[n] (r • f) = r • Δ_[h]^[n] f := by
induction n generalizing f with
| zero => simp only [iterate_zero, id_eq]
| succ n IH => simp only [iterate_succ_apply, fwdDiff_const_smul, IH]
@[simp] lemma fwdDiff_iter_finset_sum {α : Type*} (s : Finset α) (f : α → M → G) (n : ℕ) :
Δ_[h]^[n] (∑ k ∈ s, f k) = ∑ k ∈ s, Δ_[h]^[n] (f k) := by
simpa only [coe_fwdDiffₗ_pow] using map_sum (fwdDiffₗ M G h ^ n) f s
section newton_formulae
/--
Express the `n`-th forward difference of `f` at `y` in terms of the values `f (y + k)`, for
`0 ≤ k ≤ n`.
-/
theorem fwdDiff_iter_eq_sum_shift (f : M → G) (n : ℕ) (y : M) :
Δ_[h]^[n] f y = ∑ k ∈ range (n + 1), ((-1 : ℤ) ^ (n - k) * n.choose k) • f (y + k • h) := by
-- rewrite in terms of `(shiftₗ - 1) ^ n`
have : fwdDiffₗ M G h = shiftₗ M G h - 1 := by simp only [shiftₗ, add_sub_cancel_right]
rw [← coe_fwdDiffₗ, this, ← Module.End.pow_apply]
-- use binomial theorem `Commute.add_pow` to expand this
have : Commute (shiftₗ M G h) (-1) := (Commute.one_right _).neg_right
convert congr_fun (LinearMap.congr_fun (this.add_pow n) f) y using 3
· simp only [sub_eq_add_neg]
· rw [LinearMap.sum_apply, sum_apply]
congr 1 with k
have : ((-1) ^ (n - k) * n.choose k : Module.End ℤ (M → G))
= ↑((-1) ^ (n - k) * n.choose k : ℤ) := by norm_cast
rw [mul_assoc, Module.End.mul_apply, this, Module.End.intCast_apply, LinearMap.map_smul,
Pi.smul_apply, shiftₗ_pow_apply]
lemma fwdDiff_iter_comp_add (f : M → G) (m : M) (n : ℕ) (y : M) :
Δ_[h]^[n] (fun r ↦ f (r + m)) y = (Δ_[h]^[n] f) (y + m) := by
simp [fwdDiff_iter_eq_sum_shift, add_right_comm]
lemma fwdDiff_comp_add (f : M → G) (m : M) (y : M) :
Δ_[h] (fun r ↦ f (r + m)) y = (Δ_[h] f) (y + m) :=
fwdDiff_iter_comp_add h f m 1 y
/--
**Gregory-Newton formula** expressing `f (y + n • h)` in terms of the iterated forward differences
of `f` at `y`.
-/
theorem shift_eq_sum_fwdDiff_iter (f : M → G) (n : ℕ) (y : M) :
f (y + n • h) = ∑ k ∈ range (n + 1), n.choose k • Δ_[h]^[k] f y := by
convert congr_fun (LinearMap.congr_fun
((Commute.one_right (fwdDiffₗ M G h)).add_pow n) f) y using 1
· rw [← shiftₗ_pow_apply h f, shiftₗ]
· simp [Module.End.pow_apply, coe_fwdDiffₗ]
end newton_formulae
section choose
lemma fwdDiff_choose (j : ℕ) : Δ_[1] (fun x ↦ x.choose (j + 1) : ℕ → ℤ) = fun x ↦ x.choose j := by
ext n
simp only [fwdDiff, choose_succ_succ' n j, cast_add, add_sub_cancel_right]
lemma fwdDiff_iter_choose (j k : ℕ) :
Δ_[1]^[k] (fun x ↦ x.choose (k + j) : ℕ → ℤ) = fun x ↦ x.choose j := by
induction k generalizing j with
| zero => simp only [zero_add, iterate_zero, id_eq]
| succ k IH =>
simp only [iterate_succ_apply', add_assoc, add_comm 1 j, IH, fwdDiff_choose]
lemma fwdDiff_iter_choose_zero (m n : ℕ) :
Δ_[1]^[n] (fun x ↦ x.choose m : ℕ → ℤ) 0 = if n = m then 1 else 0 := by
rcases lt_trichotomy m n with hmn | rfl | hnm
· rcases Nat.exists_eq_add_of_lt hmn with ⟨k, rfl⟩
simp_rw [hmn.ne', if_false, (by ring : m + k + 1 = k + 1 + m), iterate_add_apply,
add_zero m ▸ fwdDiff_iter_choose 0 m, choose_zero_right, iterate_one, cast_one, fwdDiff_const,
fwdDiff_iter_eq_sum_shift, smul_zero, sum_const_zero]
· simp only [if_true, add_zero m ▸ fwdDiff_iter_choose 0 m, choose_zero_right, cast_one]
· rcases Nat.exists_eq_add_of_lt hnm with ⟨k, rfl⟩
simp_rw [hnm.ne, if_false, add_assoc n k 1, fwdDiff_iter_choose, choose_zero_succ, cast_zero]
end choose
lemma fwdDiff_addChar_eq {M R : Type*} [AddCommMonoid M] [Ring R]
(φ : AddChar M R) (x h : M) (n : ℕ) : Δ_[h]^[n] φ x = (φ h - 1) ^ n * φ x := by
induction n generalizing x with
| zero => simp
| succ n IH =>
simp only [pow_succ, iterate_succ_apply', fwdDiff, IH, ← mul_sub, mul_assoc]
rw [sub_mul, ← AddChar.map_add_eq_mul, add_comm h x, one_mul]
/-!
## Forward differences of polynomials
We prove formulae about the forward difference operator applied to polynomials:
* `fwdDiff_iter_pow_eq_zero_of_lt` :
The `n`-th forward difference of the function `x ↦ x^j` is zero if `j < n`;
* `fwdDiff_iter_eq_factorial` :
The `n`-th forward difference of the function `x ↦ x^n` is the constant function `n!`;
* `fwdDiff_iter_sum_mul_pow_eq_zero` :
The `n`-th forward difference of a polynomial of degree `< n` is zero (formulated using explicit
sums over `range n`.
-/
variable {R : Type*} [CommRing R]
/--
The `n`-th forward difference of the function `x ↦ x^j` is zero if `j < n`.
-/
theorem fwdDiff_iter_pow_eq_zero_of_lt {j n : ℕ} (h : j < n) :
Δ_[1]^[n] (fun (r : R) ↦ r ^ j) = 0 := by
induction n generalizing j with
| zero => aesop
| succ n ih =>
have : (Δ_[1] fun (r : R) ↦ r ^ j) = ∑ i ∈ range j, j.choose i • fun r ↦ r ^ i := by
ext x
simp [nsmul_eq_mul, fwdDiff, add_pow, sum_range_succ, mul_comm]
rw [iterate_succ_apply, this, fwdDiff_iter_finset_sum]
exact sum_eq_zero fun i hi ↦ by
rw [fwdDiff_iter_const_smul, ih (by have := mem_range.1 hi; cutsat), nsmul_zero]
/--
The `n`-th forward difference of `x ↦ x^n` is the constant function `n!`.
-/
theorem fwdDiff_iter_eq_factorial {n : ℕ} :
Δ_[1]^[n] (fun (r : R) ↦ r ^ n) = n ! := by
induction n with
| zero => aesop
| succ n IH =>
have : (Δ_[1] fun (r : R) ↦ r ^ (n + 1)) =
∑ i ∈ range (n + 1), (n + 1).choose i • fun r ↦ r ^ i := by
ext x
simp [nsmul_eq_mul, fwdDiff, add_pow, sum_range_succ, mul_comm]
simp_rw [iterate_succ_apply, this, fwdDiff_iter_finset_sum, fwdDiff_iter_const_smul,
sum_range_succ]
simpa [IH, factorial_succ] using sum_eq_zero fun i hi ↦ by
rw [fwdDiff_iter_pow_eq_zero_of_lt (by have := mem_range.1 hi; cutsat), mul_zero]
theorem Polynomial.fwdDiff_iter_degree_eq_factorial (P : R[X]) :
Δ_[1]^[P.natDegree] P.eval = P.leadingCoeff • P.natDegree ! := funext fun x ↦ by
simp_rw [P.eval_eq_sum_range, ← sum_apply _ _ (fun i x ↦ P.coeff i * x ^ i),
fwdDiff_iter_finset_sum, ← smul_eq_mul, ← Pi.smul_def, fwdDiff_iter_const_smul, Pi.smul_apply]
rw [sum_apply, sum_range_succ, sum_eq_zero (fun i hi ↦ ?_), zero_add,
fwdDiff_iter_eq_factorial, leadingCoeff, Pi.smul_apply]
rw [fwdDiff_iter_pow_eq_zero_of_lt (mem_range.mp hi), smul_zero, Pi.zero_apply]
theorem Polynomial.fwdDiff_iter_eq_zero_of_degree_lt {P : R[X]} {n : ℕ} (hP : P.natDegree < n) :
Δ_[1]^[n] P.eval = 0 := funext fun x ↦ by
obtain ⟨j, rfl⟩ := Nat.exists_eq_add_of_lt hP
rw [add_assoc, add_comm, Function.iterate_add_apply, Function.iterate_succ_apply,
P.fwdDiff_iter_degree_eq_factorial, Pi.smul_def]
simp [fwdDiff_iter_eq_sum_shift]
theorem Polynomial.fwdDiff_iter_degree_add_one_eq_zero (P : R[X]) :
Δ_[1]^[P.natDegree + 1] P.eval = 0 := by
have hP : P.natDegree < P.natDegree + 1 := Nat.lt_succ_self P.natDegree
exact Polynomial.fwdDiff_iter_eq_zero_of_degree_lt hP
/--
The `n`-th forward difference of a polynomial of degree `< n` is zero (formulated using explicit
sums over `range n`.
-/
theorem fwdDiff_iter_sum_mul_pow_eq_zero {n : ℕ} (P : ℕ → R) :
Δ_[1]^[n] (fun r : R ↦ ∑ k ∈ range n, P k * r ^ k) = 0 := by
simp_rw [← sum_apply _ _ (fun i x ↦ P i * x ^ i), fwdDiff_iter_finset_sum, sum_fn, ← smul_eq_mul,
← Pi.smul_def, fwdDiff_iter_const_smul, ← sum_fn]
exact sum_eq_zero fun i hi ↦ smul_eq_zero_of_right _ <| fwdDiff_iter_pow_eq_zero_of_lt
<| mem_range.mp hi |
.lake/packages/mathlib/Mathlib/Algebra/Group/AddChar.lean | import Mathlib.Algebra.BigOperators.Pi
import Mathlib.Algebra.BigOperators.Ring.Finset
import Mathlib.Algebra.Group.Subgroup.Ker
import Mathlib.Algebra.Group.TransferInstance
import Mathlib.Algebra.Group.Units.Equiv
import Mathlib.Algebra.Ring.Regular
/-!
# Characters from additive to multiplicative monoids
Let `A` be an additive monoid, and `M` a multiplicative one. An *additive character* of `A` with
values in `M` is simply a map `A → M` which intertwines the addition operation on `A` with the
multiplicative operation on `M`.
We define these objects, using the namespace `AddChar`, and show that if `A` is a commutative group
under addition, then the additive characters are also a group (written multiplicatively). Note that
we do not need `M` to be a group here.
We also include some constructions specific to the case when `A = R` is a ring; then we define
`mulShift ψ r`, where `ψ : AddChar R M` and `r : R`, to be the character defined by
`x ↦ ψ (r * x)`.
For more refined results of a number-theoretic nature (primitive characters, Gauss sums, etc)
see `Mathlib/NumberTheory/LegendreSymbol/AddCharacter.lean`.
## Implementation notes
Due to their role as the dual of an additive group, additive characters must themselves be an
additive group. This contrasts to their pointwise operations which make them a multiplicative group.
We simply define both the additive and multiplicative group structures and prove them equal.
For more information on this design decision, see the following zulip thread:
https://leanprover.zulipchat.com/#narrow/stream/116395-maths/topic/Additive.20characters
## Tags
additive character
-/
/-!
### Definitions related to and results on additive characters
-/
open Function Multiplicative
open Finset hiding card
open Fintype (card)
section AddCharDef
-- The domain of our additive characters
variable (A : Type*) [AddMonoid A]
-- The target
variable (M : Type*) [Monoid M]
/-- `AddChar A M` is the type of maps `A → M`, for `A` an additive monoid and `M` a multiplicative
monoid, which intertwine addition in `A` with multiplication in `M`.
We only put the typeclasses needed for the definition, although in practice we are usually
interested in much more specific cases (e.g. when `A` is a group and `M` a commutative ring).
-/
structure AddChar where
/-- The underlying function.
Do not use this function directly. Instead use the coercion coming from the `FunLike`
instance. -/
toFun : A → M
/-- The function maps `0` to `1`.
Do not use this directly. Instead use `AddChar.map_zero_eq_one`. -/
map_zero_eq_one' : toFun 0 = 1
/-- The function maps addition in `A` to multiplication in `M`.
Do not use this directly. Instead use `AddChar.map_add_eq_mul`. -/
map_add_eq_mul' : ∀ a b : A, toFun (a + b) = toFun a * toFun b
end AddCharDef
namespace AddChar
section Basic
-- results which don't require commutativity or inverses
variable {A B M N : Type*} [AddMonoid A] [AddMonoid B] [Monoid M] [Monoid N] {ψ : AddChar A M}
/-- Define coercion to a function. -/
instance instFunLike : FunLike (AddChar A M) A M where
coe := AddChar.toFun
coe_injective' φ ψ h := by cases φ; cases ψ; congr
initialize_simps_projections AddChar (toFun → apply) -- needs to come after FunLike instance
@[ext] lemma ext (f g : AddChar A M) (h : ∀ x : A, f x = g x) : f = g :=
DFunLike.ext f g h
@[simp] lemma coe_mk (f : A → M)
(map_zero_eq_one' : f 0 = 1) (map_add_eq_mul' : ∀ a b : A, f (a + b) = f a * f b) :
AddChar.mk f map_zero_eq_one' map_add_eq_mul' = f := by
rfl
/-- An additive character maps `0` to `1`. -/
@[simp] lemma map_zero_eq_one (ψ : AddChar A M) : ψ 0 = 1 := ψ.map_zero_eq_one'
/-- An additive character maps sums to products. -/
lemma map_add_eq_mul (ψ : AddChar A M) (x y : A) : ψ (x + y) = ψ x * ψ y := ψ.map_add_eq_mul' x y
/-- Interpret an additive character as a monoid homomorphism. -/
def toMonoidHom (φ : AddChar A M) : Multiplicative A →* M where
toFun := φ.toFun
map_one' := φ.map_zero_eq_one'
map_mul' := φ.map_add_eq_mul'
-- this instance was a bad idea and conflicted with `instFunLike` above
@[simp] lemma toMonoidHom_apply (ψ : AddChar A M) (a : Multiplicative A) :
ψ.toMonoidHom a = ψ a.toAdd :=
rfl
/-- An additive character maps multiples by natural numbers to powers. -/
lemma map_nsmul_eq_pow (ψ : AddChar A M) (n : ℕ) (x : A) : ψ (n • x) = ψ x ^ n :=
ψ.toMonoidHom.map_pow x n
/-- Additive characters `A → M` are the same thing as monoid homomorphisms from `Multiplicative A`
to `M`. -/
def toMonoidHomEquiv : AddChar A M ≃ (Multiplicative A →* M) where
toFun φ := φ.toMonoidHom
invFun f :=
{ toFun := f.toFun
map_zero_eq_one' := f.map_one'
map_add_eq_mul' := f.map_mul' }
@[simp, norm_cast] lemma coe_toMonoidHomEquiv (ψ : AddChar A M) :
⇑(toMonoidHomEquiv ψ) = ψ ∘ Multiplicative.toAdd := rfl
@[simp, norm_cast] lemma coe_toMonoidHomEquiv_symm (ψ : Multiplicative A →* M) :
⇑(toMonoidHomEquiv.symm ψ) = ψ ∘ Multiplicative.ofAdd := rfl
@[simp] lemma toMonoidHomEquiv_apply (ψ : AddChar A M) (a : Multiplicative A) :
toMonoidHomEquiv ψ a = ψ a.toAdd := rfl
@[simp] lemma toMonoidHomEquiv_symm_apply (ψ : Multiplicative A →* M) (a : A) :
toMonoidHomEquiv.symm ψ a = ψ (Multiplicative.ofAdd a) := rfl
/-- Interpret an additive character as a monoid homomorphism. -/
def toAddMonoidHom (φ : AddChar A M) : A →+ Additive M where
toFun := φ.toFun
map_zero' := φ.map_zero_eq_one'
map_add' := φ.map_add_eq_mul'
@[simp] lemma coe_toAddMonoidHom (ψ : AddChar A M) : ⇑ψ.toAddMonoidHom = Additive.ofMul ∘ ψ := rfl
@[simp] lemma toAddMonoidHom_apply (ψ : AddChar A M) (a : A) :
ψ.toAddMonoidHom a = Additive.ofMul (ψ a) := rfl
/-- Additive characters `A → M` are the same thing as additive homomorphisms from `A` to
`Additive M`. -/
def toAddMonoidHomEquiv : AddChar A M ≃ (A →+ Additive M) where
toFun φ := φ.toAddMonoidHom
invFun f :=
{ toFun := f.toFun
map_zero_eq_one' := f.map_zero'
map_add_eq_mul' := f.map_add' }
@[simp, norm_cast]
lemma coe_toAddMonoidHomEquiv (ψ : AddChar A M) :
⇑(toAddMonoidHomEquiv ψ) = Additive.ofMul ∘ ψ := rfl
@[simp, norm_cast] lemma coe_toAddMonoidHomEquiv_symm (ψ : A →+ Additive M) :
⇑(toAddMonoidHomEquiv.symm ψ) = Additive.toMul ∘ ψ := rfl
@[simp] lemma toAddMonoidHomEquiv_apply (ψ : AddChar A M) (a : A) :
toAddMonoidHomEquiv ψ a = Additive.ofMul (ψ a) := rfl
@[simp] lemma toAddMonoidHomEquiv_symm_apply (ψ : A →+ Additive M) (a : A) :
toAddMonoidHomEquiv.symm ψ a = (ψ a).toMul := rfl
/-- The trivial additive character (sending everything to `1`). -/
instance instOne : One (AddChar A M) := toMonoidHomEquiv.one
/-- The trivial additive character (sending everything to `1`). -/
instance instZero : Zero (AddChar A M) := ⟨1⟩
@[simp, norm_cast] lemma coe_one : ⇑(1 : AddChar A M) = 1 := rfl
@[simp, norm_cast] lemma coe_zero : ⇑(0 : AddChar A M) = 1 := rfl
@[simp] lemma one_apply (a : A) : (1 : AddChar A M) a = 1 := rfl
@[simp] lemma zero_apply (a : A) : (0 : AddChar A M) a = 1 := rfl
lemma one_eq_zero : (1 : AddChar A M) = (0 : AddChar A M) := rfl
@[simp, norm_cast] lemma coe_eq_one : ⇑ψ = 1 ↔ ψ = 0 := by rw [← coe_zero, DFunLike.coe_fn_eq]
@[simp] lemma toMonoidHomEquiv_zero : toMonoidHomEquiv (0 : AddChar A M) = 1 := rfl
@[simp] lemma toMonoidHomEquiv_symm_one :
toMonoidHomEquiv.symm (1 : Multiplicative A →* M) = 0 := rfl
@[simp] lemma toAddMonoidHomEquiv_zero : toAddMonoidHomEquiv (0 : AddChar A M) = 0 := rfl
@[simp] lemma toAddMonoidHomEquiv_symm_zero :
toAddMonoidHomEquiv.symm (0 : A →+ Additive M) = 0 := rfl
instance instInhabited : Inhabited (AddChar A M) := ⟨1⟩
/-- Composing a `MonoidHom` with an `AddChar` yields another `AddChar`. -/
def _root_.MonoidHom.compAddChar {N : Type*} [Monoid N] (f : M →* N) (φ : AddChar A M) :
AddChar A N := toMonoidHomEquiv.symm (f.comp φ.toMonoidHom)
@[simp, norm_cast]
lemma _root_.MonoidHom.coe_compAddChar {N : Type*} [Monoid N] (f : M →* N) (φ : AddChar A M) :
f.compAddChar φ = f ∘ φ :=
rfl
@[simp, norm_cast]
lemma _root_.MonoidHom.compAddChar_apply (f : M →* N) (φ : AddChar A M) : f.compAddChar φ = f ∘ φ :=
rfl
lemma _root_.MonoidHom.compAddChar_injective_left (ψ : AddChar A M) (hψ : Surjective ψ) :
Injective fun f : M →* N ↦ f.compAddChar ψ := by
rintro f g h; rw [DFunLike.ext'_iff] at h ⊢; exact hψ.injective_comp_right h
lemma _root_.MonoidHom.compAddChar_injective_right (f : M →* N) (hf : Injective f) :
Injective fun ψ : AddChar B M ↦ f.compAddChar ψ := by
rintro ψ χ h; rw [DFunLike.ext'_iff] at h ⊢; exact hf.comp_left h
/-- Composing an `AddChar` with an `AddMonoidHom` yields another `AddChar`. -/
def compAddMonoidHom (φ : AddChar B M) (f : A →+ B) : AddChar A M :=
toAddMonoidHomEquiv.symm (φ.toAddMonoidHom.comp f)
@[simp, norm_cast]
lemma coe_compAddMonoidHom (φ : AddChar B M) (f : A →+ B) : φ.compAddMonoidHom f = φ ∘ f := rfl
@[simp] lemma compAddMonoidHom_apply (ψ : AddChar B M) (f : A →+ B)
(a : A) : ψ.compAddMonoidHom f a = ψ (f a) := rfl
lemma compAddMonoidHom_injective_left (f : A →+ B) (hf : Surjective f) :
Injective fun ψ : AddChar B M ↦ ψ.compAddMonoidHom f := by
rintro ψ χ h; rw [DFunLike.ext'_iff] at h ⊢; exact hf.injective_comp_right h
lemma compAddMonoidHom_injective_right (ψ : AddChar B M) (hψ : Injective ψ) :
Injective fun f : A →+ B ↦ ψ.compAddMonoidHom f := by
rintro f g h
rw [DFunLike.ext'_iff] at h ⊢; exact hψ.comp_left h
lemma eq_one_iff : ψ = 1 ↔ ∀ x, ψ x = 1 := DFunLike.ext_iff
lemma eq_zero_iff : ψ = 0 ↔ ∀ x, ψ x = 1 := DFunLike.ext_iff
lemma ne_one_iff : ψ ≠ 1 ↔ ∃ x, ψ x ≠ 1 := DFunLike.ne_iff
lemma ne_zero_iff : ψ ≠ 0 ↔ ∃ x, ψ x ≠ 1 := DFunLike.ne_iff
noncomputable instance : DecidableEq (AddChar A M) := Classical.decEq _
end Basic
section toCommMonoid
variable {ι A M : Type*} [AddMonoid A] [CommMonoid M]
/-- When `M` is commutative, `AddChar A M` is a commutative monoid. -/
instance instCommMonoid : CommMonoid (AddChar A M) := toMonoidHomEquiv.commMonoid
/-- When `M` is commutative, `AddChar A M` is an additive commutative monoid. -/
instance instAddCommMonoid : AddCommMonoid (AddChar A M) := Additive.addCommMonoid
@[simp, norm_cast] lemma coe_mul (ψ χ : AddChar A M) : ⇑(ψ * χ) = ψ * χ := rfl
@[simp, norm_cast] lemma coe_add (ψ χ : AddChar A M) : ⇑(ψ + χ) = ψ * χ := rfl
@[simp, norm_cast] lemma coe_pow (ψ : AddChar A M) (n : ℕ) : ⇑(ψ ^ n) = ψ ^ n := rfl
@[simp, norm_cast] lemma coe_nsmul (n : ℕ) (ψ : AddChar A M) : ⇑(n • ψ) = ψ ^ n := rfl
@[simp, norm_cast]
lemma coe_prod (s : Finset ι) (ψ : ι → AddChar A M) : ∏ i ∈ s, ψ i = ∏ i ∈ s, ⇑(ψ i) := by
induction s using Finset.cons_induction <;> simp [*]
@[simp, norm_cast]
lemma coe_sum (s : Finset ι) (ψ : ι → AddChar A M) : ∑ i ∈ s, ψ i = ∏ i ∈ s, ⇑(ψ i) := by
induction s using Finset.cons_induction <;> simp [*]
@[simp] lemma mul_apply (ψ φ : AddChar A M) (a : A) : (ψ * φ) a = ψ a * φ a := rfl
@[simp] lemma add_apply (ψ φ : AddChar A M) (a : A) : (ψ + φ) a = ψ a * φ a := rfl
@[simp] lemma pow_apply (ψ : AddChar A M) (n : ℕ) (a : A) : (ψ ^ n) a = (ψ a) ^ n := rfl
@[simp] lemma nsmul_apply (ψ : AddChar A M) (n : ℕ) (a : A) : (n • ψ) a = (ψ a) ^ n := rfl
lemma prod_apply (s : Finset ι) (ψ : ι → AddChar A M) (a : A) :
(∏ i ∈ s, ψ i) a = ∏ i ∈ s, ψ i a := by rw [coe_prod, Finset.prod_apply]
lemma sum_apply (s : Finset ι) (ψ : ι → AddChar A M) (a : A) :
(∑ i ∈ s, ψ i) a = ∏ i ∈ s, ψ i a := by rw [coe_sum, Finset.prod_apply]
lemma mul_eq_add (ψ χ : AddChar A M) : ψ * χ = ψ + χ := rfl
lemma pow_eq_nsmul (ψ : AddChar A M) (n : ℕ) : ψ ^ n = n • ψ := rfl
lemma prod_eq_sum (s : Finset ι) (ψ : ι → AddChar A M) : ∏ i ∈ s, ψ i = ∑ i ∈ s, ψ i := rfl
@[simp] lemma toMonoidHomEquiv_add (ψ φ : AddChar A M) :
toMonoidHomEquiv (ψ + φ) = toMonoidHomEquiv ψ * toMonoidHomEquiv φ := rfl
@[simp] lemma toMonoidHomEquiv_symm_mul (ψ φ : Multiplicative A →* M) :
toMonoidHomEquiv.symm (ψ * φ) = toMonoidHomEquiv.symm ψ + toMonoidHomEquiv.symm φ := rfl
/-- The natural equivalence to `(Multiplicative A →* M)` is a monoid isomorphism. -/
def toMonoidHomMulEquiv : AddChar A M ≃* (Multiplicative A →* M) :=
{ toMonoidHomEquiv with map_mul' := fun φ ψ ↦ by rfl }
/-- Additive characters `A → M` are the same thing as additive homomorphisms from `A` to
`Additive M`. -/
def toAddMonoidAddEquiv : Additive (AddChar A M) ≃+ (A →+ Additive M) :=
{ toAddMonoidHomEquiv with map_add' := fun φ ψ ↦ by rfl }
/-- The double dual embedding. -/
def doubleDualEmb : A →+ AddChar (AddChar A M) M where
toFun a := { toFun := fun ψ ↦ ψ a
map_zero_eq_one' := by simp
map_add_eq_mul' := by simp }
map_zero' := by ext; simp
map_add' _ _ := by ext; simp [map_add_eq_mul]
@[simp] lemma doubleDualEmb_apply (a : A) (ψ : AddChar A M) : doubleDualEmb a ψ = ψ a := rfl
end toCommMonoid
section CommSemiring
variable {A R : Type*} [AddGroup A] [Fintype A] [CommSemiring R] [IsDomain R]
{ψ : AddChar A R}
lemma sum_eq_ite (ψ : AddChar A R) [Decidable (ψ = 0)] :
∑ a, ψ a = if ψ = 0 then ↑(card A) else 0 := by
split_ifs with h
· simp [h]
obtain ⟨x, hx⟩ := ne_one_iff.1 h
refine eq_zero_of_mul_eq_self_left hx ?_
rw [Finset.mul_sum]
exact Fintype.sum_equiv (Equiv.addLeft x) _ _ fun y ↦ (map_add_eq_mul ..).symm
variable [CharZero R]
lemma sum_eq_zero_iff_ne_zero : ∑ x, ψ x = 0 ↔ ψ ≠ 0 := by
classical
rw [sum_eq_ite, Ne.ite_eq_right_iff]; exact Nat.cast_ne_zero.2 Fintype.card_ne_zero
lemma sum_ne_zero_iff_eq_zero : ∑ x, ψ x ≠ 0 ↔ ψ = 0 := sum_eq_zero_iff_ne_zero.not_left
end CommSemiring
/-!
## Additive characters of additive abelian groups
-/
section fromAddCommGroup
variable {A M : Type*} [AddCommGroup A] [CommMonoid M]
/-- The additive characters on a commutative additive group form a commutative group.
Note that the inverse is defined using negation on the domain; we do not assume `M` has an
inversion operation for the definition (but see `AddChar.map_neg_eq_inv` below). -/
instance instCommGroup : CommGroup (AddChar A M) :=
{ instCommMonoid with
inv := fun ψ ↦ ψ.compAddMonoidHom negAddMonoidHom
inv_mul_cancel := fun ψ ↦ by ext1 x; simp [negAddMonoidHom, ← map_add_eq_mul]}
/-- The additive characters on a commutative additive group form a commutative group. -/
instance : AddCommGroup (AddChar A M) := Additive.addCommGroup
@[simp] lemma inv_apply (ψ : AddChar A M) (a : A) : ψ⁻¹ a = ψ (-a) := rfl
@[simp] lemma neg_apply (ψ : AddChar A M) (a : A) : (-ψ) a = ψ (-a) := rfl
lemma div_apply (ψ χ : AddChar A M) (a : A) : (ψ / χ) a = ψ a * χ (-a) := rfl
lemma sub_apply (ψ χ : AddChar A M) (a : A) : (ψ - χ) a = ψ a * χ (-a) := rfl
end fromAddCommGroup
section fromAddGrouptoCommMonoid
/-- The values of an additive character on an additive group are units. -/
lemma val_isUnit {A M} [AddGroup A] [Monoid M] (φ : AddChar A M) (a : A) : IsUnit (φ a) :=
IsUnit.map φ.toMonoidHom <| Group.isUnit (Multiplicative.ofAdd a)
end fromAddGrouptoCommMonoid
section fromAddGrouptoDivisionMonoid
variable {A M : Type*} [AddGroup A] [DivisionMonoid M]
/-- An additive character maps negatives to inverses (when defined) -/
lemma map_neg_eq_inv (ψ : AddChar A M) (a : A) : ψ (-a) = (ψ a)⁻¹ := by
apply eq_inv_of_mul_eq_one_left
simp only [← map_add_eq_mul, neg_add_cancel, map_zero_eq_one]
/-- An additive character maps integer scalar multiples to integer powers. -/
lemma map_zsmul_eq_zpow (ψ : AddChar A M) (n : ℤ) (a : A) : ψ (n • a) = (ψ a) ^ n :=
ψ.toMonoidHom.map_zpow a n
end fromAddGrouptoDivisionMonoid
section fromAddCommGrouptoDivisionCommMonoid
variable {A M : Type*} [AddCommGroup A] [DivisionCommMonoid M]
lemma inv_apply' (ψ : AddChar A M) (a : A) : ψ⁻¹ a = (ψ a)⁻¹ := by rw [inv_apply, map_neg_eq_inv]
lemma neg_apply' (ψ : AddChar A M) (a : A) : (-ψ) a = (ψ a)⁻¹ := map_neg_eq_inv _ _
lemma div_apply' (ψ χ : AddChar A M) (a : A) : (ψ / χ) a = ψ a / χ a := by
rw [div_apply, map_neg_eq_inv, div_eq_mul_inv]
lemma sub_apply' (ψ χ : AddChar A M) (a : A) : (ψ - χ) a = ψ a / χ a := by
rw [sub_apply, map_neg_eq_inv, div_eq_mul_inv]
@[simp] lemma zsmul_apply (n : ℤ) (ψ : AddChar A M) (a : A) : (n • ψ) a = ψ a ^ n := by
cases n <;> simp [-neg_apply, neg_apply']
@[simp] lemma zpow_apply (ψ : AddChar A M) (n : ℤ) (a : A) : (ψ ^ n) a = ψ a ^ n := zsmul_apply ..
lemma map_sub_eq_div (ψ : AddChar A M) (a b : A) : ψ (a - b) = ψ a / ψ b :=
ψ.toMonoidHom.map_div _ _
lemma injective_iff {ψ : AddChar A M} : Injective ψ ↔ ∀ ⦃x⦄, ψ x = 1 → x = 0 :=
ψ.toMonoidHom.ker_eq_bot_iff.symm.trans eq_bot_iff
end fromAddCommGrouptoDivisionCommMonoid
section MonoidWithZero
variable {A M₀ : Type*} [AddGroup A] [MonoidWithZero M₀] [Nontrivial M₀]
@[simp] lemma coe_ne_zero (ψ : AddChar A M₀) : (ψ : A → M₀) ≠ 0 :=
ne_iff.2 ⟨0, fun h ↦ by simpa only [h, Pi.zero_apply, zero_ne_one] using map_zero_eq_one ψ⟩
end MonoidWithZero
/-!
## Additive characters of rings
-/
section Ring
-- The domain and target of our additive characters. Now we restrict to a ring in the domain.
variable {R M : Type*} [Ring R] [CommMonoid M]
/-- Define the multiplicative shift of an additive character.
This satisfies `mulShift ψ a x = ψ (a * x)`. -/
def mulShift (ψ : AddChar R M) (r : R) : AddChar R M :=
ψ.compAddMonoidHom (AddMonoidHom.mulLeft r)
@[simp] lemma mulShift_apply {ψ : AddChar R M} {r : R} {x : R} : mulShift ψ r x = ψ (r * x) :=
rfl
/-- `ψ⁻¹ = mulShift ψ (-1))`. -/
theorem inv_mulShift (ψ : AddChar R M) : ψ⁻¹ = mulShift ψ (-1) := by
ext
rw [inv_apply, mulShift_apply, neg_mul, one_mul]
/-- If `n` is a natural number, then `mulShift ψ n x = (ψ x) ^ n`. -/
theorem mulShift_spec' (ψ : AddChar R M) (n : ℕ) (x : R) : mulShift ψ n x = ψ x ^ n := by
rw [mulShift_apply, ← nsmul_eq_mul, map_nsmul_eq_pow]
/-- If `n` is a natural number, then `ψ ^ n = mulShift ψ n`. -/
theorem pow_mulShift (ψ : AddChar R M) (n : ℕ) : ψ ^ n = mulShift ψ n := by
ext x
rw [pow_apply, ← mulShift_spec']
/-- The product of `mulShift ψ r` and `mulShift ψ s` is `mulShift ψ (r + s)`. -/
theorem mulShift_mul (ψ : AddChar R M) (r s : R) :
mulShift ψ r * mulShift ψ s = mulShift ψ (r + s) := by
ext
rw [mulShift_apply, right_distrib, map_add_eq_mul]; norm_cast
lemma mulShift_mulShift (ψ : AddChar R M) (r s : R) :
mulShift (mulShift ψ r) s = mulShift ψ (r * s) := by
ext
simp only [mulShift_apply, mul_assoc]
/-- `mulShift ψ 0` is the trivial character. -/
@[simp]
theorem mulShift_zero (ψ : AddChar R M) : mulShift ψ 0 = 1 := by
ext; rw [mulShift_apply, zero_mul, map_zero_eq_one, one_apply]
@[simp]
lemma mulShift_one (ψ : AddChar R M) : mulShift ψ 1 = ψ := by
ext; rw [mulShift_apply, one_mul]
lemma mulShift_unit_eq_one_iff (ψ : AddChar R M) {u : R} (hu : IsUnit u) :
ψ.mulShift u = 1 ↔ ψ = 1 := by
refine ⟨fun h ↦ ?_, ?_⟩
· ext1 y
rw [show y = u * (hu.unit⁻¹ * y) by rw [← mul_assoc, IsUnit.mul_val_inv, one_mul]]
simpa only [mulShift_apply] using DFunLike.ext_iff.mp h (hu.unit⁻¹ * y)
· solve_by_elim
end Ring
end AddChar |
.lake/packages/mathlib/Mathlib/Algebra/Group/UniqueProds/VectorSpace.lean | import Mathlib.Algebra.Group.UniqueProds.Basic
import Mathlib.LinearAlgebra.Basis.VectorSpace
/-!
# A `ℚ`-vector space has `TwoUniqueSums`.
-/
variable {G : Type*}
/-- Any `ℚ`-vector space has `TwoUniqueSums`, because it is isomorphic to some
`(Basis.ofVectorSpaceIndex ℚ G) →₀ ℚ` by choosing a basis, and `ℚ` already has
`TwoUniqueSums` because it's ordered. -/
instance [AddCommGroup G] [Module ℚ G] : TwoUniqueSums G :=
TwoUniqueSums.of_injective_addHom _ (Module.Basis.ofVectorSpace ℚ G).repr.injective inferInstance |
.lake/packages/mathlib/Mathlib/Algebra/Group/UniqueProds/Basic.lean | import Mathlib.Algebra.Group.Equiv.Opposite
import Mathlib.Algebra.Group.Finsupp
import Mathlib.Algebra.Group.Pi.Lemmas
import Mathlib.Algebra.Group.Pointwise.Finset.Basic
import Mathlib.Algebra.Group.TypeTags.Basic
import Mathlib.Algebra.Group.ULift
import Mathlib.Data.DFinsupp.Defs
/-!
# Unique products and related notions
A group `G` has *unique products* if for any two non-empty finite subsets `A, B ⊆ G`, there is an
element `g ∈ A * B` that can be written uniquely as a product of an element of `A` and an element
of `B`. We call the formalization this property `UniqueProds`. Since the condition requires no
property of the group operation, we define it for a Type simply satisfying `Mul`. We also
introduce the analogous "additive" companion, `UniqueSums`, and link the two so that `to_additive`
converts `UniqueProds` into `UniqueSums`.
A common way of *proving* that a group satisfies the `UniqueProds/Sums` property is by assuming
the existence of some kind of ordering on the group that is well-behaved with respect to the
group operation and showing that minima/maxima are the "unique products/sums".
However, the order is just a convenience and is not part of the `UniqueProds/Sums` setup.
Here you can see several examples of Types that have `UniqueSums/Prods`
(`inferInstance` uses `Covariant.to_uniqueProds_left` and `Covariant.to_uniqueSums_left`).
```lean
import Mathlib.Data.Real.Basic
import Mathlib.Data.PNat.Basic
import Mathlib.Algebra.Group.UniqueProds.Basic
example : UniqueSums ℕ := inferInstance
example : UniqueSums ℕ+ := inferInstance
example : UniqueSums ℤ := inferInstance
example : UniqueSums ℚ := inferInstance
example : UniqueSums ℝ := inferInstance
example : UniqueProds ℕ+ := inferInstance
```
## Use in `(Add)MonoidAlgebra`s
`UniqueProds/Sums` allow to decouple certain arguments about `(Add)MonoidAlgebra`s into an argument
about the grading type and then a generic statement of the form "look at the coefficient of the
'unique product/sum'".
The file `Algebra/MonoidAlgebra/NoZeroDivisors` contains several examples of this use.
-/
assert_not_exists Cardinal Subsemiring Algebra Submodule StarModule FreeMonoid IsOrderedMonoid
open Finset
/-- Let `G` be a Type with multiplication, let `A B : Finset G` be finite subsets and
let `a0 b0 : G` be two elements. `UniqueMul A B a0 b0` asserts `a0 * b0` can be written in at
most one way as a product of an element of `A` and an element of `B`. -/
@[to_additive
/-- Let `G` be a Type with addition, let `A B : Finset G` be finite subsets and
let `a0 b0 : G` be two elements. `UniqueAdd A B a0 b0` asserts `a0 + b0` can be written in at
most one way as a sum of an element from `A` and an element from `B`. -/]
def UniqueMul {G} [Mul G] (A B : Finset G) (a0 b0 : G) : Prop :=
∀ ⦃a b⦄, a ∈ A → b ∈ B → a * b = a0 * b0 → a = a0 ∧ b = b0
namespace UniqueMul
variable {G H : Type*} [Mul G] [Mul H] {A B : Finset G} {a0 b0 : G}
@[to_additive]
theorem mono {A' B' : Finset G} (hA : A ⊆ A') (hB : B ⊆ B') (h : UniqueMul A' B' a0 b0) :
UniqueMul A B a0 b0 := fun _ _ ha hb he ↦ h (hA ha) (hB hb) he
@[to_additive (attr := nontriviality, simp)]
theorem of_subsingleton [Subsingleton G] : UniqueMul A B a0 b0 := by
simp [UniqueMul, eq_iff_true_of_subsingleton]
@[to_additive of_card_le_one]
theorem of_card_le_one (hA : A.Nonempty) (hB : B.Nonempty) (hA1 : #A ≤ 1) (hB1 : #B ≤ 1) :
∃ a ∈ A, ∃ b ∈ B, UniqueMul A B a b := by
rw [Finset.card_le_one_iff] at hA1 hB1
obtain ⟨a, ha⟩ := hA; obtain ⟨b, hb⟩ := hB
exact ⟨a, ha, b, hb, fun _ _ ha' hb' _ ↦ ⟨hA1 ha' ha, hB1 hb' hb⟩⟩
@[to_additive]
theorem mt (h : UniqueMul A B a0 b0) :
∀ ⦃a b⦄, a ∈ A → b ∈ B → a ≠ a0 ∨ b ≠ b0 → a * b ≠ a0 * b0 := fun _ _ ha hb k ↦ by
contrapose! k
exact h ha hb k
@[to_additive]
theorem subsingleton (h : UniqueMul A B a0 b0) :
Subsingleton { ab : G × G // ab.1 ∈ A ∧ ab.2 ∈ B ∧ ab.1 * ab.2 = a0 * b0 } :=
⟨fun ⟨⟨_a, _b⟩, ha, hb, ab⟩ ⟨⟨_a', _b'⟩, ha', hb', ab'⟩ ↦
Subtype.ext <|
Prod.ext ((h ha hb ab).1.trans (h ha' hb' ab').1.symm) <|
(h ha hb ab).2.trans (h ha' hb' ab').2.symm⟩
@[to_additive]
theorem set_subsingleton (h : UniqueMul A B a0 b0) :
Set.Subsingleton { ab : G × G | ab.1 ∈ A ∧ ab.2 ∈ B ∧ ab.1 * ab.2 = a0 * b0 } := by
rintro ⟨x1, y1⟩ (hx : x1 ∈ A ∧ y1 ∈ B ∧ x1 * y1 = a0 * b0) ⟨x2, y2⟩
(hy : x2 ∈ A ∧ y2 ∈ B ∧ x2 * y2 = a0 * b0)
rcases h hx.1 hx.2.1 hx.2.2 with ⟨rfl, rfl⟩
rcases h hy.1 hy.2.1 hy.2.2 with ⟨rfl, rfl⟩
rfl
@[to_additive]
theorem iff_existsUnique (aA : a0 ∈ A) (bB : b0 ∈ B) :
UniqueMul A B a0 b0 ↔ ∃! ab, ab ∈ A ×ˢ B ∧ ab.1 * ab.2 = a0 * b0 :=
⟨fun _ ↦ ⟨(a0, b0), ⟨Finset.mk_mem_product aA bB, rfl⟩, by simpa⟩,
fun h ↦ h.elim
(by
rintro ⟨x1, x2⟩ _ J x y hx hy l
rcases Prod.mk_inj.mp (J (a0, b0) ⟨Finset.mk_mem_product aA bB, rfl⟩) with ⟨rfl, rfl⟩
exact Prod.mk_inj.mp (J (x, y) ⟨Finset.mk_mem_product hx hy, l⟩))⟩
open Finset in
@[to_additive iff_card_le_one]
theorem iff_card_le_one [DecidableEq G] (ha0 : a0 ∈ A) (hb0 : b0 ∈ B) :
UniqueMul A B a0 b0 ↔ #{p ∈ A ×ˢ B | p.1 * p.2 = a0 * b0} ≤ 1 := by
simp_rw [card_le_one_iff, mem_filter, mem_product]
refine ⟨fun h p1 p2 ⟨⟨ha1, hb1⟩, he1⟩ ⟨⟨ha2, hb2⟩, he2⟩ ↦ ?_, fun h a b ha hb he ↦ ?_⟩
· have h1 := h ha1 hb1 he1; have h2 := h ha2 hb2 he2
grind
· exact Prod.ext_iff.1 (@h (a, b) (a0, b0) ⟨⟨ha, hb⟩, he⟩ ⟨⟨ha0, hb0⟩, rfl⟩)
@[to_additive]
theorem exists_iff_exists_existsUnique :
(∃ a0 b0 : G, a0 ∈ A ∧ b0 ∈ B ∧ UniqueMul A B a0 b0) ↔
∃ g : G, ∃! ab, ab ∈ A ×ˢ B ∧ ab.1 * ab.2 = g :=
⟨fun ⟨_, _, hA, hB, h⟩ ↦ ⟨_, (iff_existsUnique hA hB).mp h⟩, fun ⟨g, h⟩ ↦ by
have h' := h
rcases h' with ⟨⟨a, b⟩, ⟨hab, rfl, -⟩, -⟩
obtain ⟨ha, hb⟩ := Finset.mem_product.mp hab
exact ⟨a, b, ha, hb, (iff_existsUnique ha hb).mpr h⟩⟩
/-- `UniqueMul` is preserved by inverse images under injective, multiplicative maps. -/
@[to_additive /-- `UniqueAdd` is preserved by inverse images under injective, additive maps. -/]
theorem mulHom_preimage (f : G →ₙ* H) (hf : Function.Injective f) (a0 b0 : G) {A B : Finset H}
(u : UniqueMul A B (f a0) (f b0)) :
UniqueMul (A.preimage f hf.injOn) (B.preimage f hf.injOn) a0 b0 := by
intro a b ha hb ab
simp only [← hf.eq_iff, map_mul] at ab ⊢
exact u (Finset.mem_preimage.mp ha) (Finset.mem_preimage.mp hb) ab
@[to_additive] theorem of_mulHom_image [DecidableEq H] (f : G →ₙ* H)
(hf : ∀ ⦃a b c d : G⦄, a * b = c * d → f a = f c ∧ f b = f d → a = c ∧ b = d)
(h : UniqueMul (A.image f) (B.image f) (f a0) (f b0)) : UniqueMul A B a0 b0 :=
fun a b ha hb ab ↦ hf ab
(h (Finset.mem_image_of_mem f ha) (Finset.mem_image_of_mem f hb) <| by simp_rw [← map_mul, ab])
/-- `Unique_Mul` is preserved under multiplicative maps that are injective.
See `UniqueMul.mulHom_map_iff` for a version with swapped bundling. -/
@[to_additive
/-- `UniqueAdd` is preserved under additive maps that are injective.
See `UniqueAdd.addHom_map_iff` for a version with swapped bundling. -/]
theorem mulHom_image_iff [DecidableEq H] (f : G →ₙ* H) (hf : Function.Injective f) :
UniqueMul (A.image f) (B.image f) (f a0) (f b0) ↔ UniqueMul A B a0 b0 :=
⟨of_mulHom_image f fun _ _ _ _ _ ↦ .imp (hf ·) (hf ·), fun h _ _ ↦ by
simp_rw [Finset.mem_image]
rintro ⟨a, aA, rfl⟩ ⟨b, bB, rfl⟩ ab
simp_rw [← map_mul, hf.eq_iff] at ab ⊢
exact h aA bB ab⟩
/-- `UniqueMul` is preserved under embeddings that are multiplicative.
See `UniqueMul.mulHom_image_iff` for a version with swapped bundling. -/
@[to_additive
/-- `UniqueAdd` is preserved under embeddings that are additive.
See `UniqueAdd.addHom_image_iff` for a version with swapped bundling. -/]
theorem mulHom_map_iff (f : G ↪ H) (mul : ∀ x y, f (x * y) = f x * f y) :
UniqueMul (A.map f) (B.map f) (f a0) (f b0) ↔ UniqueMul A B a0 b0 := by
classical simp_rw [← mulHom_image_iff ⟨f, mul⟩ f.2, Finset.map_eq_image]; rfl
section Opposites
open Finset MulOpposite
@[to_additive]
theorem of_mulOpposite
(h : UniqueMul (B.map ⟨_, op_injective⟩) (A.map ⟨_, op_injective⟩) (op b0) (op a0)) :
UniqueMul A B a0 b0 := fun a b aA bB ab ↦ by
simpa [and_comm] using h (mem_map_of_mem _ bB) (mem_map_of_mem _ aA) (congr_arg op ab)
@[to_additive]
theorem to_mulOpposite (h : UniqueMul A B a0 b0) :
UniqueMul (B.map ⟨_, op_injective⟩) (A.map ⟨_, op_injective⟩) (op b0) (op a0) :=
of_mulOpposite (by simp_rw [map_map]; exact (mulHom_map_iff _ fun _ _ ↦ by rfl).mpr h)
@[to_additive]
theorem iff_mulOpposite :
UniqueMul (B.map ⟨_, op_injective⟩) (A.map ⟨_, op_injective⟩) (op b0) (op a0) ↔
UniqueMul A B a0 b0 :=
⟨of_mulOpposite, to_mulOpposite⟩
end Opposites
open Finset in
@[to_additive]
theorem of_image_filter [DecidableEq H]
(f : G →ₙ* H) {A B : Finset G} {aG bG : G} {aH bH : H} (hae : f aG = aH) (hbe : f bG = bH)
(huH : UniqueMul (A.image f) (B.image f) aH bH)
(huG : UniqueMul {a ∈ A | f a = aH} {b ∈ B | f b = bH} aG bG) :
UniqueMul A B aG bG := fun a b ha hb he ↦ by
specialize huH (mem_image_of_mem _ ha) (mem_image_of_mem _ hb)
rw [← map_mul, he, map_mul, hae, hbe] at huH
refine huG ?_ ?_ he <;> rw [mem_filter]
exacts [⟨ha, (huH rfl).1⟩, ⟨hb, (huH rfl).2⟩]
end UniqueMul
/-- Let `G` be a Type with addition. `UniqueSums G` asserts that any two non-empty
finite subsets of `G` have the `UniqueAdd` property, with respect to some element of their
sum `A + B`. -/
class UniqueSums (G) [Add G] : Prop where
/-- For `A B` two nonempty finite sets, there always exist `a0 ∈ A, b0 ∈ B` such that
`UniqueAdd A B a0 b0` -/
uniqueAdd_of_nonempty :
∀ {A B : Finset G}, A.Nonempty → B.Nonempty → ∃ a0 ∈ A, ∃ b0 ∈ B, UniqueAdd A B a0 b0
/-- Let `G` be a Type with multiplication. `UniqueProds G` asserts that any two non-empty
finite subsets of `G` have the `UniqueMul` property, with respect to some element of their
product `A * B`. -/
class UniqueProds (G) [Mul G] : Prop where
/-- For `A B` two nonempty finite sets, there always exist `a0 ∈ A, b0 ∈ B` such that
`UniqueMul A B a0 b0` -/
uniqueMul_of_nonempty :
∀ {A B : Finset G}, A.Nonempty → B.Nonempty → ∃ a0 ∈ A, ∃ b0 ∈ B, UniqueMul A B a0 b0
attribute [to_additive] UniqueProds
/-- Let `G` be a Type with addition. `TwoUniqueSums G` asserts that any two non-empty
finite subsets of `G`, at least one of which is not a singleton, possesses at least two pairs
of elements satisfying the `UniqueAdd` property. -/
class TwoUniqueSums (G) [Add G] : Prop where
/-- For `A B` two finite sets whose product has cardinality at least 2,
we can find at least two unique pairs. -/
uniqueAdd_of_one_lt_card : ∀ {A B : Finset G}, 1 < #A * #B →
∃ p1 ∈ A ×ˢ B, ∃ p2 ∈ A ×ˢ B, p1 ≠ p2 ∧ UniqueAdd A B p1.1 p1.2 ∧ UniqueAdd A B p2.1 p2.2
/-- Let `G` be a Type with multiplication. `TwoUniqueProds G` asserts that any two non-empty
finite subsets of `G`, at least one of which is not a singleton, possesses at least two pairs
of elements satisfying the `UniqueMul` property. -/
class TwoUniqueProds (G) [Mul G] : Prop where
/-- For `A B` two finite sets whose product has cardinality at least 2,
we can find at least two unique pairs. -/
uniqueMul_of_one_lt_card : ∀ {A B : Finset G}, 1 < #A * #B →
∃ p1 ∈ A ×ˢ B, ∃ p2 ∈ A ×ˢ B, p1 ≠ p2 ∧ UniqueMul A B p1.1 p1.2 ∧ UniqueMul A B p2.1 p2.2
attribute [to_additive] TwoUniqueProds
@[to_additive]
lemma uniqueMul_of_twoUniqueMul {G} [Mul G] {A B : Finset G} (h : 1 < #A * #B →
∃ p1 ∈ A ×ˢ B, ∃ p2 ∈ A ×ˢ B, p1 ≠ p2 ∧ UniqueMul A B p1.1 p1.2 ∧ UniqueMul A B p2.1 p2.2)
(hA : A.Nonempty) (hB : B.Nonempty) : ∃ a ∈ A, ∃ b ∈ B, UniqueMul A B a b := by
set_option push_neg.use_distrib true in by_cases! hc : #A ≤ 1 ∧ #B ≤ 1
· exact UniqueMul.of_card_le_one hA hB hc.1 hc.2
rw [← Finset.card_pos] at hA hB
obtain ⟨p, hp, _, _, _, hu, _⟩ := h (Nat.one_lt_mul_iff.mpr ⟨hA, hB, hc⟩)
rw [Finset.mem_product] at hp
exact ⟨p.1, hp.1, p.2, hp.2, hu⟩
@[to_additive] instance TwoUniqueProds.toUniqueProds (G) [Mul G] [TwoUniqueProds G] :
UniqueProds G where
uniqueMul_of_nonempty := uniqueMul_of_twoUniqueMul uniqueMul_of_one_lt_card
namespace Multiplicative
instance {M} [Add M] [UniqueSums M] : UniqueProds (Multiplicative M) where
uniqueMul_of_nonempty := UniqueSums.uniqueAdd_of_nonempty (G := M)
instance {M} [Add M] [TwoUniqueSums M] : TwoUniqueProds (Multiplicative M) where
uniqueMul_of_one_lt_card := TwoUniqueSums.uniqueAdd_of_one_lt_card (G := M)
end Multiplicative
namespace Additive
instance {M} [Mul M] [UniqueProds M] : UniqueSums (Additive M) where
uniqueAdd_of_nonempty := UniqueProds.uniqueMul_of_nonempty (G := M)
instance {M} [Mul M] [TwoUniqueProds M] : TwoUniqueSums (Additive M) where
uniqueAdd_of_one_lt_card := TwoUniqueProds.uniqueMul_of_one_lt_card (G := M)
end Additive
universe u v
variable (G : Type u) (H : Type v) [Mul G] [Mul H]
private abbrev I : Bool → Type max u v := Bool.rec (ULift.{v} G) (ULift.{u} H)
@[to_additive] private instance : ∀ b, Mul (I G H b) := Bool.rec ULift.mul ULift.mul
@[to_additive] private def Prod.upMulHom : G × H →ₙ* ∀ b, I G H b :=
⟨fun x ↦ Bool.rec ⟨x.1⟩ ⟨x.2⟩, fun x y ↦ by ext (_ | _) <;> rfl⟩
@[to_additive] private def downMulHom : ULift G →ₙ* G := ⟨ULift.down, fun _ _ ↦ rfl⟩
variable {G H}
namespace UniqueProds
open Finset
@[to_additive] theorem of_mulHom (f : H →ₙ* G)
(hf : ∀ ⦃a b c d : H⦄, a * b = c * d → f a = f c ∧ f b = f d → a = c ∧ b = d)
[UniqueProds G] : UniqueProds H where
uniqueMul_of_nonempty {A B} A0 B0 := by
classical
obtain ⟨a0, ha0, b0, hb0, h⟩ := uniqueMul_of_nonempty (A0.image f) (B0.image f)
obtain ⟨a', ha', rfl⟩ := mem_image.mp ha0
obtain ⟨b', hb', rfl⟩ := mem_image.mp hb0
exact ⟨a', ha', b', hb', UniqueMul.of_mulHom_image f hf h⟩
@[to_additive]
theorem of_injective_mulHom (f : H →ₙ* G) (hf : Function.Injective f) (_ : UniqueProds G) :
UniqueProds H := of_mulHom f (fun _ _ _ _ _ ↦ .imp (hf ·) (hf ·))
/-- `UniqueProd` is preserved under multiplicative equivalences. -/
@[to_additive /-- `UniqueSums` is preserved under additive equivalences. -/]
theorem _root_.MulEquiv.uniqueProds_iff (f : G ≃* H) : UniqueProds G ↔ UniqueProds H :=
⟨of_injective_mulHom f.symm f.symm.injective, of_injective_mulHom f f.injective⟩
open Finset MulOpposite in
@[to_additive]
theorem of_mulOpposite (h : UniqueProds Gᵐᵒᵖ) : UniqueProds G where
uniqueMul_of_nonempty hA hB :=
let f : G ↪ Gᵐᵒᵖ := ⟨op, op_injective⟩
let ⟨y, yB, x, xA, hxy⟩ := h.uniqueMul_of_nonempty (hB.map (f := f)) (hA.map (f := f))
⟨unop x, (mem_map' _).mp xA, unop y, (mem_map' _).mp yB, hxy.of_mulOpposite⟩
@[to_additive] instance [h : UniqueProds G] : UniqueProds Gᵐᵒᵖ :=
of_mulOpposite <| (MulEquiv.opOp G).uniqueProds_iff.mp h
@[to_additive] private theorem toIsLeftCancelMul [UniqueProds G] : IsLeftCancelMul G where
mul_left_cancel a b1 b2 he := by
classical
have := mem_insert_self b1 {b2}
obtain ⟨a, ha, b, hb, hu⟩ := uniqueMul_of_nonempty ⟨a, mem_singleton_self a⟩ ⟨b1, this⟩
cases mem_singleton.mp ha
simp_rw [mem_insert, mem_singleton] at hb
obtain rfl | rfl := hb
· exact (hu ha (mem_insert_of_mem <| mem_singleton_self b2) he.symm).2.symm
· exact (hu ha this he).2
open MulOpposite in
@[to_additive] theorem toIsCancelMul [UniqueProds G] : IsCancelMul G where
mul_left_cancel := toIsLeftCancelMul.mul_left_cancel
mul_right_cancel _ _ _ h :=
op_injective <| toIsLeftCancelMul.mul_left_cancel _ <| unop_injective h
/-! Two theorems in [Andrzej Strojnowski, *A note on u.p. groups*][Strojnowski1980] -/
/-- `UniqueProds G` says that for any two nonempty `Finset`s `A` and `B` in `G`, `A × B`
contains a unique pair with the `UniqueMul` property. Strojnowski showed that if `G` is
a group, then we only need to check this when `A = B`.
Here we generalize the result to cancellative semigroups.
Non-cancellative counterexample: the AddMonoid {0,1} with 1+1=1. -/
@[to_additive] theorem of_same {G} [Semigroup G] [IsCancelMul G]
(h : ∀ {A : Finset G}, A.Nonempty → ∃ a1 ∈ A, ∃ a2 ∈ A, UniqueMul A A a1 a2) :
UniqueProds G where
uniqueMul_of_nonempty {A B} hA hB := by
classical
obtain ⟨g1, h1, g2, h2, hu⟩ := h (hB.mul hA)
obtain ⟨b1, hb1, a1, ha1, rfl⟩ := mem_mul.mp h1
obtain ⟨b2, hb2, a2, ha2, rfl⟩ := mem_mul.mp h2
refine ⟨a1, ha1, b2, hb2, fun a b ha hb he => ?_⟩
specialize hu (mul_mem_mul hb1 ha) (mul_mem_mul hb ha2) _
· rw [mul_assoc b1, ← mul_assoc a, he, mul_assoc a1, ← mul_assoc b1]
exact ⟨mul_left_cancel hu.1, mul_right_cancel hu.2⟩
/-- If a group has `UniqueProds`, then it actually has `TwoUniqueProds`.
For an example of a semigroup `G` embeddable into a group that has `UniqueProds`
but not `TwoUniqueProds`, see Example 10.13 in
[J. Okniński, *Semigroup Algebras*][Okninski1991]. -/
@[to_additive] theorem toTwoUniqueProds_of_group {G}
[Group G] [UniqueProds G] : TwoUniqueProds G where
uniqueMul_of_one_lt_card {A B} hc := by
simp_rw [Nat.one_lt_mul_iff, card_pos] at hc
obtain ⟨a, ha, b, hb, hu⟩ := uniqueMul_of_nonempty hc.1 hc.2.1
let C := A.map ⟨_, mul_right_injective a⁻¹⟩ -- C = a⁻¹A
let D := B.map ⟨_, mul_left_injective b⁻¹⟩ -- D = Bb⁻¹
have hcard : 1 < #C ∨ 1 < #D := by simp_rw [C, D, card_map]; exact hc.2.2
have hC : 1 ∈ C := mem_map.mpr ⟨a, ha, inv_mul_cancel a⟩
have hD : 1 ∈ D := mem_map.mpr ⟨b, hb, mul_inv_cancel b⟩
suffices ∃ c ∈ C, ∃ d ∈ D, (c ≠ 1 ∨ d ≠ 1) ∧ UniqueMul C D c d by
simp_rw [mem_product]
obtain ⟨c, hc, d, hd, hne, hu'⟩ := this
obtain ⟨a0, ha0, rfl⟩ := mem_map.mp hc
obtain ⟨b0, hb0, rfl⟩ := mem_map.mp hd
refine ⟨(_, _), ⟨ha0, hb0⟩, (a, b), ⟨ha, hb⟩, ?_, fun a' b' ha' hb' he => ?_, hu⟩
· simp_rw [Function.Embedding.coeFn_mk, Ne, inv_mul_eq_one, mul_inv_eq_one] at hne
rwa [Ne, Prod.mk_inj, not_and_or, eq_comm]
specialize hu' (mem_map_of_mem _ ha') (mem_map_of_mem _ hb')
simp_rw [Function.Embedding.coeFn_mk, mul_left_cancel_iff, mul_right_cancel_iff] at hu'
rw [mul_assoc, ← mul_assoc a', he, mul_assoc, mul_assoc] at hu'
exact hu' rfl
classical
let _ := Finset.mul (α := G) -- E = D⁻¹C, F = DC⁻¹
have := uniqueMul_of_nonempty (A := D.image (·⁻¹) * C) (B := D * C.image (·⁻¹)) ?_ ?_
· obtain ⟨e, he, f, hf, hu⟩ := this
clear_value C D
simp only [UniqueMul, mem_mul, mem_image] at he hf hu
obtain ⟨_, ⟨d1, hd1, rfl⟩, c1, hc1, rfl⟩ := he
obtain ⟨d2, hd2, _, ⟨c2, hc2, rfl⟩, rfl⟩ := hf
by_cases! h12 : c1 ≠ 1 ∨ d2 ≠ 1
· refine ⟨c1, hc1, d2, hd2, h12, fun c3 d3 hc3 hd3 he => ?_⟩
specialize hu ⟨_, ⟨_, hd1, rfl⟩, _, hc3, rfl⟩ ⟨_, hd3, _, ⟨_, hc2, rfl⟩, rfl⟩
rw [mul_left_cancel_iff, mul_right_cancel_iff,
mul_assoc, ← mul_assoc c3, he, mul_assoc, mul_assoc] at hu; exact hu rfl
obtain ⟨rfl, rfl⟩ := h12
by_cases! h21 : c2 ≠ 1 ∨ d1 ≠ 1
· refine ⟨c2, hc2, d1, hd1, h21, fun c4 d4 hc4 hd4 he => ?_⟩
specialize hu ⟨_, ⟨_, hd4, rfl⟩, _, hC, rfl⟩ ⟨_, hD, _, ⟨_, hc4, rfl⟩, rfl⟩
simpa only [mul_one, one_mul, ← mul_inv_rev, he, true_imp_iff, inv_inj, and_comm] using hu
obtain ⟨rfl, rfl⟩ := h21
rcases hcard with hC | hD
· obtain ⟨c, hc, hc1⟩ := exists_mem_ne hC 1
refine (hc1 ?_).elim
simpa using hu ⟨_, ⟨_, hD, rfl⟩, _, hc, rfl⟩ ⟨_, hD, _, ⟨_, hc, rfl⟩, rfl⟩
· obtain ⟨d, hd, hd1⟩ := exists_mem_ne hD 1
refine (hd1 ?_).elim
simpa using hu ⟨_, ⟨_, hd, rfl⟩, _, hC, rfl⟩ ⟨_, hd, _, ⟨_, hC, rfl⟩, rfl⟩
all_goals apply_rules [Nonempty.mul, Nonempty.image, Finset.Nonempty.map, hc.1, hc.2.1]
open UniqueMul in
@[to_additive] instance instForall {ι} (G : ι → Type*) [∀ i, Mul (G i)] [∀ i, UniqueProds (G i)] :
UniqueProds (∀ i, G i) where
uniqueMul_of_nonempty {A} := by
classical
let _ := isWellFounded_ssubset (α := ∀ i, G i) -- why need this?
apply IsWellFounded.induction (· ⊂ ·) A; intro A ihA B hA
apply IsWellFounded.induction (· ⊂ ·) B; intro B ihB hB
set_option push_neg.use_distrib true in by_cases! hc : #A ≤ 1 ∧ #B ≤ 1
· exact of_card_le_one hA hB hc.1 hc.2
obtain ⟨i, hc⟩ := exists_or.mpr (hc.imp exists_of_one_lt_card_pi exists_of_one_lt_card_pi)
obtain ⟨ai, hA, bi, hB, hi⟩ := uniqueMul_of_nonempty (hA.image (· i)) (hB.image (· i))
rw [mem_image, ← filter_nonempty_iff] at hA hB
let A' := {a ∈ A | a i = ai}; let B' := {b ∈ B | b i = bi}
obtain ⟨a0, ha0, b0, hb0, hu⟩ : ∃ a0 ∈ A', ∃ b0 ∈ B', UniqueMul A' B' a0 b0 := by
rcases hc with hc | hc; · exact ihA A' (hc.2 ai) hA hB
by_cases hA' : A' = A
· rw [hA']
exact ihB B' (hc.2 bi) hB
· exact ihA A' ((A.filter_subset _).ssubset_of_ne hA') hA hB
rw [mem_filter] at ha0 hb0
exact ⟨a0, ha0.1, b0, hb0.1, of_image_filter (Pi.evalMulHom G i) ha0.2 hb0.2 hi hu⟩
open ULift in
@[to_additive] instance _root_.Prod.instUniqueProds [UniqueProds G] [UniqueProds H] :
UniqueProds (G × H) := by
have : ∀ b, UniqueProds (I G H b) := Bool.rec ?_ ?_
· exact of_injective_mulHom (downMulHom H) down_injective ‹_›
· refine of_injective_mulHom (Prod.upMulHom G H) (fun x y he => Prod.ext ?_ ?_)
(UniqueProds.instForall <| I G H) <;> apply up_injective
exacts [congr_fun he false, congr_fun he true]
· exact of_injective_mulHom (downMulHom G) down_injective ‹_›
end UniqueProds
instance {ι} (G : ι → Type*) [∀ i, AddZeroClass (G i)] [∀ i, UniqueSums (G i)] :
UniqueSums (Π₀ i, G i) :=
UniqueSums.of_injective_addHom
DFinsupp.coeFnAddMonoidHom.toAddHom DFunLike.coe_injective inferInstance
instance {ι G} [AddZeroClass G] [UniqueSums G] : UniqueSums (ι →₀ G) :=
UniqueSums.of_injective_addHom
Finsupp.coeFnAddHom.toAddHom DFunLike.coe_injective inferInstance
namespace TwoUniqueProds
open Finset
@[to_additive] theorem of_mulHom (f : H →ₙ* G)
(hf : ∀ ⦃a b c d : H⦄, a * b = c * d → f a = f c ∧ f b = f d → a = c ∧ b = d)
[TwoUniqueProds G] : TwoUniqueProds H where
uniqueMul_of_one_lt_card {A B} hc := by
classical
obtain hc' | hc' := lt_or_ge 1 (#(A.image f) * #(B.image f))
· obtain ⟨⟨a1, b1⟩, h1, ⟨a2, b2⟩, h2, hne, hu1, hu2⟩ := uniqueMul_of_one_lt_card hc'
simp_rw [mem_product, mem_image] at h1 h2 ⊢
obtain ⟨⟨a1, ha1, rfl⟩, b1, hb1, rfl⟩ := h1
obtain ⟨⟨a2, ha2, rfl⟩, b2, hb2, rfl⟩ := h2
exact ⟨(a1, b1), ⟨ha1, hb1⟩, (a2, b2), ⟨ha2, hb2⟩, mt (congr_arg (Prod.map f f)) hne,
UniqueMul.of_mulHom_image f hf hu1, UniqueMul.of_mulHom_image f hf hu2⟩
rw [← card_product] at hc hc'
obtain ⟨p1, h1, p2, h2, hne⟩ := one_lt_card_iff_nontrivial.mp hc
refine ⟨p1, h1, p2, h2, hne, ?_⟩
cases mem_product.mp h1; cases mem_product.mp h2
constructor <;> refine UniqueMul.of_mulHom_image f hf
((UniqueMul.iff_card_le_one ?_ ?_).mpr <| (card_filter_le _ _).trans hc') <;>
apply mem_image_of_mem <;> assumption
@[to_additive]
theorem of_injective_mulHom (f : H →ₙ* G) (hf : Function.Injective f)
(_ : TwoUniqueProds G) : TwoUniqueProds H :=
of_mulHom f (fun _ _ _ _ _ ↦ .imp (hf ·) (hf ·))
/-- `TwoUniqueProd` is preserved under multiplicative equivalences. -/
@[to_additive /-- `TwoUniqueSums` is preserved under additive equivalences. -/]
theorem _root_.MulEquiv.twoUniqueProds_iff (f : G ≃* H) : TwoUniqueProds G ↔ TwoUniqueProds H :=
⟨of_injective_mulHom f.symm f.symm.injective, of_injective_mulHom f f.injective⟩
@[to_additive]
instance instForall {ι} (G : ι → Type*) [∀ i, Mul (G i)] [∀ i, TwoUniqueProds (G i)] :
TwoUniqueProds (∀ i, G i) where
uniqueMul_of_one_lt_card {A} := by
classical
let _ := isWellFounded_ssubset (α := ∀ i, G i) -- why need this?
apply IsWellFounded.induction (· ⊂ ·) A; intro A ihA B
apply IsWellFounded.induction (· ⊂ ·) B; intro B ihB hc
obtain ⟨hA, hB, hc⟩ := Nat.one_lt_mul_iff.mp hc
rw [card_pos] at hA hB
obtain ⟨i, hc⟩ := exists_or.mpr (hc.imp exists_of_one_lt_card_pi exists_of_one_lt_card_pi)
obtain ⟨p1, h1, p2, h2, hne, hi1, hi2⟩ := uniqueMul_of_one_lt_card (Nat.one_lt_mul_iff.mpr
⟨card_pos.2 (hA.image _), card_pos.2 (hB.image _), hc.imp And.left And.left⟩)
simp_rw [mem_product, mem_image, ← filter_nonempty_iff] at h1 h2
replace h1 := uniqueMul_of_twoUniqueMul ?_ h1.1 h1.2
on_goal 1 => replace h2 := uniqueMul_of_twoUniqueMul ?_ h2.1 h2.2
· obtain ⟨a1, ha1, b1, hb1, hu1⟩ := h1
obtain ⟨a2, ha2, b2, hb2, hu2⟩ := h2
rw [mem_filter] at ha1 hb1 ha2 hb2
simp_rw [mem_product]
refine ⟨(a1, b1), ⟨ha1.1, hb1.1⟩, (a2, b2), ⟨ha2.1, hb2.1⟩, ?_,
UniqueMul.of_image_filter (Pi.evalMulHom G i) ha1.2 hb1.2 hi1 hu1,
UniqueMul.of_image_filter (Pi.evalMulHom G i) ha2.2 hb2.2 hi2 hu2⟩
grind
all_goals rcases hc with hc | hc; · exact ihA _ (hc.2 _)
· by_cases hA : {a ∈ A | a i = p2.1} = A
· rw [hA]
exact ihB _ (hc.2 _)
· exact ihA _ ((A.filter_subset _).ssubset_of_ne hA)
· by_cases hA : {a ∈ A | a i = p1.1} = A
· rw [hA]
exact ihB _ (hc.2 _)
· exact ihA _ ((A.filter_subset _).ssubset_of_ne hA)
open ULift in
@[to_additive]
instance _root_.Prod.instTwoUniqueProds [TwoUniqueProds G] [TwoUniqueProds H] :
TwoUniqueProds (G × H) := by
have : ∀ b, TwoUniqueProds (I G H b) := Bool.rec ?_ ?_
· exact of_injective_mulHom (downMulHom H) down_injective ‹_›
· refine of_injective_mulHom (Prod.upMulHom G H) (fun x y he ↦ Prod.ext ?_ ?_)
(TwoUniqueProds.instForall <| I G H) <;> apply up_injective
exacts [congr_fun he false, congr_fun he true]
· exact of_injective_mulHom (downMulHom G) down_injective ‹_›
open MulOpposite in
@[to_additive]
theorem of_mulOpposite (h : TwoUniqueProds Gᵐᵒᵖ) : TwoUniqueProds G where
uniqueMul_of_one_lt_card hc := by
let f : G ↪ Gᵐᵒᵖ := ⟨op, op_injective⟩
rw [← card_map f, ← card_map f, mul_comm] at hc
obtain ⟨p1, h1, p2, h2, hne, hu1, hu2⟩ := h.uniqueMul_of_one_lt_card hc
simp_rw [mem_product] at h1 h2 ⊢
refine ⟨(_, _), ⟨?_, ?_⟩, (_, _), ⟨?_, ?_⟩, ?_, hu1.of_mulOpposite, hu2.of_mulOpposite⟩
pick_goal 5
· contrapose! hne; rw [Prod.ext_iff] at hne ⊢
exact ⟨unop_injective hne.2, unop_injective hne.1⟩
all_goals apply (mem_map' f).mp
exacts [h1.2, h1.1, h2.2, h2.1]
@[to_additive] instance [h : TwoUniqueProds G] : TwoUniqueProds Gᵐᵒᵖ :=
of_mulOpposite <| (MulEquiv.opOp G).twoUniqueProds_iff.mp h
-- see Note [lower instance priority]
/-- This instance asserts that if `G` has a right-cancellative multiplication, a linear order, and
multiplication is strictly monotone w.r.t. the second argument, then `G` has `TwoUniqueProds`. -/
@[to_additive
/-- This instance asserts that if `G` has a right-cancellative addition, a linear order,
and addition is strictly monotone w.r.t. the second argument, then `G` has `TwoUniqueSums`. -/]
instance (priority := 100) of_covariant_right [IsRightCancelMul G]
[LinearOrder G] [MulLeftStrictMono G] :
TwoUniqueProds G where
uniqueMul_of_one_lt_card {A B} hc := by
obtain ⟨hA, hB, -⟩ := Nat.one_lt_mul_iff.mp hc
rw [card_pos] at hA hB
rw [← card_product] at hc
obtain ⟨a0, ha0, b0, hb0, he0⟩ := mem_mul.mp (max'_mem _ <| hA.mul hB)
obtain ⟨a1, ha1, b1, hb1, he1⟩ := mem_mul.mp (min'_mem _ <| hA.mul hB)
have : UniqueMul A B a0 b0 := by
intro a b ha hb he
obtain hl | rfl | hl := lt_trichotomy b b0
· exact ((he0 ▸ he ▸ mul_lt_mul_left' hl a).not_ge <| le_max' _ _ <| mul_mem_mul ha hb0).elim
· exact ⟨mul_right_cancel he, rfl⟩
· exact ((he0 ▸ mul_lt_mul_left' hl a0).not_ge <| le_max' _ _ <| mul_mem_mul ha0 hb).elim
refine ⟨_, mk_mem_product ha0 hb0, _, mk_mem_product ha1 hb1, fun he ↦ ?_, this, ?_⟩
· rw [Prod.mk_inj] at he; rw [he.1, he.2, he1] at he0
obtain ⟨⟨a2, b2⟩, h2, hne⟩ := exists_mem_ne hc (a0, b0)
rw [mem_product] at h2
refine (min'_lt_max' _ (mul_mem_mul ha0 hb0) (mul_mem_mul h2.1 h2.2) fun he ↦ hne ?_).ne he0
exact Prod.ext_iff.mpr (this h2.1 h2.2 he.symm)
· intro a b ha hb he
obtain hl | rfl | hl := lt_trichotomy b b1
· exact ((he1 ▸ mul_lt_mul_left' hl a1).not_ge <| min'_le _ _ <| mul_mem_mul ha1 hb).elim
· exact ⟨mul_right_cancel he, rfl⟩
· exact ((he1 ▸ he ▸ mul_lt_mul_left' hl a).not_ge <| min'_le _ _ <| mul_mem_mul ha hb1).elim
open MulOpposite in
-- see Note [lower instance priority]
/-- This instance asserts that if `G` has a left-cancellative multiplication, a linear order, and
multiplication is strictly monotone w.r.t. the first argument, then `G` has `TwoUniqueProds`. -/
@[to_additive
/-- This instance asserts that if `G` has a left-cancellative addition, a linear order, and
addition is strictly monotone w.r.t. the first argument, then `G` has `TwoUniqueSums`. -/]
instance (priority := 100) of_covariant_left [IsLeftCancelMul G]
[LinearOrder G] [MulRightStrictMono G] :
TwoUniqueProds G :=
let _ := LinearOrder.lift' (unop : Gᵐᵒᵖ → G) unop_injective
let _ : MulLeftStrictMono Gᵐᵒᵖ :=
{ elim := fun _ _ _ bc ↦ mul_lt_mul_right' (α := G) bc (unop _) }
of_mulOpposite of_covariant_right
end TwoUniqueProds
instance {ι} (G : ι → Type*) [∀ i, AddZeroClass (G i)] [∀ i, TwoUniqueSums (G i)] :
TwoUniqueSums (Π₀ i, G i) :=
TwoUniqueSums.of_injective_addHom
DFinsupp.coeFnAddMonoidHom.toAddHom DFunLike.coe_injective inferInstance
instance {ι G} [AddZeroClass G] [TwoUniqueSums G] : TwoUniqueSums (ι →₀ G) :=
TwoUniqueSums.of_injective_addHom
Finsupp.coeFnAddHom.toAddHom DFunLike.coe_injective inferInstance |
.lake/packages/mathlib/Mathlib/Algebra/Group/Fin/Tuple.lean | import Mathlib.Algebra.Group.Basic
import Mathlib.Algebra.Notation.Pi.Basic
import Mathlib.Data.Fin.VecNotation
/-!
# Algebraic properties of tuples
-/
namespace Fin
variable {n : ℕ} {α : Fin (n + 1) → Type*}
@[to_additive (attr := simp)]
lemma insertNth_one_right [∀ j, One (α j)] (i : Fin (n + 1)) (x : α i) :
i.insertNth x 1 = Pi.mulSingle i x :=
insertNth_eq_iff.2 <| by unfold removeNth; simp [succAbove_ne, Pi.one_def]
@[to_additive (attr := simp)]
lemma insertNth_mul [∀ j, Mul (α j)] (i : Fin (n + 1)) (x y : α i) (p q : ∀ j, α (i.succAbove j)) :
i.insertNth (x * y) (p * q) = i.insertNth x p * i.insertNth y q :=
insertNth_binop (fun _ ↦ (· * ·)) i x y p q
@[to_additive (attr := simp)]
lemma insertNth_div [∀ j, Div (α j)] (i : Fin (n + 1)) (x y : α i) (p q : ∀ j, α (i.succAbove j)) :
i.insertNth (x / y) (p / q) = i.insertNth x p / i.insertNth y q :=
insertNth_binop (fun _ ↦ (· / ·)) i x y p q
@[to_additive (attr := simp)]
lemma insertNth_div_same [∀ j, Group (α j)] (i : Fin (n + 1)) (x y : α i)
(p : ∀ j, α (i.succAbove j)) : i.insertNth x p / i.insertNth y p = Pi.mulSingle i (x / y) := by
simp_rw [← insertNth_div, ← insertNth_one_right, Pi.div_def, div_self', Pi.one_def]
end Fin
namespace Matrix
variable {α M : Type*} {n : ℕ}
section SMul
variable [SMul M α]
@[simp] lemma smul_empty (x : M) (v : Fin 0 → α) : x • v = ![] := empty_eq _
@[simp] lemma smul_cons (x : M) (y : α) (v : Fin n → α) :
x • vecCons y v = vecCons (x • y) (x • v) := by ext i; refine i.cases ?_ ?_ <;> simp
end SMul
section Add
variable [Add α]
@[simp] lemma empty_add_empty (v w : Fin 0 → α) : v + w = ![] := empty_eq _
@[simp] lemma cons_add (x : α) (v : Fin n → α) (w : Fin n.succ → α) :
vecCons x v + w = vecCons (x + vecHead w) (v + vecTail w) := by
ext i; refine i.cases ?_ ?_ <;> simp [vecHead, vecTail]
@[simp] lemma add_cons (v : Fin n.succ → α) (y : α) (w : Fin n → α) :
v + vecCons y w = vecCons (vecHead v + y) (vecTail v + w) := by
ext i; refine i.cases ?_ ?_ <;> simp [vecHead, vecTail]
lemma cons_add_cons (x : α) (v : Fin n → α) (y : α) (w : Fin n → α) :
vecCons x v + vecCons y w = vecCons (x + y) (v + w) := by simp
@[simp] lemma head_add (a b : Fin n.succ → α) : vecHead (a + b) = vecHead a + vecHead b := rfl
@[simp] lemma tail_add (a b : Fin n.succ → α) : vecTail (a + b) = vecTail a + vecTail b := rfl
end Add
section Sub
variable [Sub α]
@[simp] lemma empty_sub_empty (v w : Fin 0 → α) : v - w = ![] := empty_eq _
@[simp] lemma cons_sub (x : α) (v : Fin n → α) (w : Fin n.succ → α) :
vecCons x v - w = vecCons (x - vecHead w) (v - vecTail w) := by
ext i; refine i.cases ?_ ?_ <;> simp [vecHead, vecTail]
@[simp] lemma sub_cons (v : Fin n.succ → α) (y : α) (w : Fin n → α) :
v - vecCons y w = vecCons (vecHead v - y) (vecTail v - w) := by
ext i; refine i.cases ?_ ?_ <;> simp [vecHead, vecTail]
lemma cons_sub_cons (x : α) (v : Fin n → α) (y : α) (w : Fin n → α) :
vecCons x v - vecCons y w = vecCons (x - y) (v - w) := by simp
@[simp] lemma head_sub (a b : Fin n.succ → α) : vecHead (a - b) = vecHead a - vecHead b := rfl
@[simp] lemma tail_sub (a b : Fin n.succ → α) : vecTail (a - b) = vecTail a - vecTail b := rfl
end Sub
section Zero
variable [Zero α]
@[simp] lemma zero_empty : (0 : Fin 0 → α) = ![] := empty_eq _
@[simp] lemma cons_zero_zero : vecCons (0 : α) (0 : Fin n → α) = 0 := by
ext i; exact i.cases rfl (by simp)
@[simp] lemma head_zero : vecHead (0 : Fin n.succ → α) = 0 := rfl
@[simp] lemma tail_zero : vecTail (0 : Fin n.succ → α) = 0 := rfl
@[simp] lemma cons_eq_zero_iff {v : Fin n → α} {x : α} : vecCons x v = 0 ↔ x = 0 ∧ v = 0 where
mp h := ⟨congr_fun h 0, by convert congr_arg vecTail h⟩
mpr := fun ⟨hx, hv⟩ ↦ by simp [hx, hv]
lemma cons_nonzero_iff {v : Fin n → α} {x : α} : vecCons x v ≠ 0 ↔ x ≠ 0 ∨ v ≠ 0 where
mp h := not_and_or.mp (h ∘ cons_eq_zero_iff.mpr)
mpr h := mt cons_eq_zero_iff.mp (not_and_or.mpr h)
end Zero
section Neg
variable [Neg α]
@[simp] lemma neg_empty (v : Fin 0 → α) : -v = ![] := empty_eq _
@[simp] lemma neg_cons (x : α) (v : Fin n → α) : -vecCons x v = vecCons (-x) (-v) := by
ext i; refine i.cases ?_ ?_ <;> simp
@[simp] lemma head_neg (a : Fin n.succ → α) : vecHead (-a) = -vecHead a := rfl
@[simp] lemma tail_neg (a : Fin n.succ → α) : vecTail (-a) = -vecTail a := rfl
end Neg
end Matrix |
.lake/packages/mathlib/Mathlib/Algebra/Group/Fin/Basic.lean | import Mathlib.Algebra.Group.Basic
import Mathlib.Algebra.NeZero
import Mathlib.Data.Nat.Cast.Defs
import Mathlib.Data.Fin.Rev
/-!
# Fin is a group
This file contains the additive and multiplicative monoid instances on `Fin n`.
See note [foundational algebra order theory].
-/
assert_not_exists IsOrderedMonoid MonoidWithZero
open Nat
namespace Fin
variable {n : ℕ}
/-! ### Instances -/
instance addCommSemigroup (n : ℕ) : AddCommSemigroup (Fin n) where
add_assoc := by simp [add_def, Nat.add_assoc]
add_comm := by simp [add_def, Nat.add_comm]
instance addCommMonoid (n : ℕ) [NeZero n] : AddCommMonoid (Fin n) where
zero_add := Fin.zero_add
add_zero := Fin.add_zero
nsmul := nsmulRec
__ := Fin.addCommSemigroup n
/--
This is not a global instance, but can introduced locally using `open Fin.NatCast in ...`.
This is not an instance because the `binop%` elaborator assumes that
there are no non-trivial coercion loops,
but this instance would introduce a coercion from `Nat` to `Fin n` and back.
Non-trivial loops lead to undesirable and counterintuitive elaboration behavior.
For example, for `x : Fin k` and `n : Nat`,
it causes `x < n` to be elaborated as `x < ↑n` rather than `↑x < n`,
silently introducing wraparound arithmetic.
-/
def instAddMonoidWithOne (n) [NeZero n] : AddMonoidWithOne (Fin n) where
__ := inferInstanceAs (AddCommMonoid (Fin n))
natCast i := Fin.ofNat n i
natCast_zero := rfl
natCast_succ _ := Fin.ext (add_mod _ _ _)
namespace NatCast
attribute [scoped instance] Fin.instAddMonoidWithOne
end NatCast
instance addCommGroup (n : ℕ) [NeZero n] : AddCommGroup (Fin n) where
__ := addCommMonoid n
__ := neg n
neg_add_cancel := fun ⟨a, ha⟩ ↦
Fin.ext <| (Nat.mod_add_mod _ _ _).trans <| by
rw [Fin.val_zero, Nat.sub_add_cancel, Nat.mod_self]
exact le_of_lt ha
sub := Fin.sub
sub_eq_add_neg := fun ⟨a, ha⟩ ⟨b, hb⟩ ↦
Fin.ext <| by simp [Fin.sub_def, Fin.neg_def, Fin.add_def, Nat.add_comm]
zsmul := zsmulRec
/-- Note this is more general than `Fin.addCommGroup` as it applies (vacuously) to `Fin 0` too. -/
instance instInvolutiveNeg (n : ℕ) : InvolutiveNeg (Fin n) where
neg_neg := Nat.casesOn n finZeroElim fun _i ↦ neg_neg
/-- Note this is more general than `Fin.addCommGroup` as it applies (vacuously) to `Fin 0` too. -/
instance instIsCancelAdd (n : ℕ) : IsCancelAdd (Fin n) where
add_left_cancel := Nat.casesOn n finZeroElim fun _i _ _ _ ↦ add_left_cancel
add_right_cancel := Nat.casesOn n finZeroElim fun _i _ _ _ ↦ add_right_cancel
/-- Note this is more general than `Fin.addCommGroup` as it applies (vacuously) to `Fin 0` too. -/
instance instAddLeftCancelSemigroup (n : ℕ) : AddLeftCancelSemigroup (Fin n) :=
{ Fin.addCommSemigroup n, Fin.instIsCancelAdd n with }
/-- Note this is more general than `Fin.addCommGroup` as it applies (vacuously) to `Fin 0` too. -/
instance instAddRightCancelSemigroup (n : ℕ) : AddRightCancelSemigroup (Fin n) :=
{ Fin.addCommSemigroup n, Fin.instIsCancelAdd n with }
/-! ### Miscellaneous lemmas -/
open scoped Fin.NatCast Fin.IntCast in
/-- Variant of `Fin.intCast_def` with `Nat.cast` on the RHS. -/
theorem intCast_def' {n : Nat} [NeZero n] (x : Int) :
(x : Fin n) = if 0 ≤ x then ↑x.natAbs else -↑x.natAbs :=
Fin.intCast_def _
lemma coe_sub_one (a : Fin (n + 1)) : ↑(a - 1) = if a = 0 then n else a - 1 := by
cases n
· simp
split_ifs with h
· simp [h]
rw [sub_eq_add_neg, val_add_eq_ite, coe_neg_one, if_pos, Nat.add_comm, Nat.add_sub_add_left]
conv_rhs => rw [Nat.add_comm]
rw [Nat.add_le_add_iff_left, Nat.one_le_iff_ne_zero]
rwa [Fin.ext_iff] at h
@[simp]
lemma lt_sub_iff {n : ℕ} {a b : Fin n} : a < a - b ↔ a < b := by
rcases n with - | n
· exact a.elim0
constructor
· contrapose!
intro h
obtain ⟨l, hl⟩ := Nat.exists_eq_add_of_le (Fin.not_lt.mp h)
simpa only [Fin.not_lt, le_iff_val_le_val, sub_def, hl, ← Nat.add_assoc, Nat.add_mod_left,
Nat.mod_eq_of_lt, Nat.sub_add_cancel b.is_lt.le] using
(le_trans (mod_le _ _) (le_add_left _ _))
· intro h
rw [lt_iff_val_lt_val, sub_def]
simp only
obtain ⟨k, hk⟩ := Nat.exists_eq_add_of_lt b.is_lt
have : n + 1 - b = k + 1 := by
simp_rw [hk, Nat.add_assoc, Nat.add_sub_cancel_left]
-- simp_rw because, otherwise, rw tries to rewrite inside `b : Fin (n + 1)`
rw [this, Nat.mod_eq_of_lt (hk.ge.trans_lt' ?_), Nat.lt_add_left_iff_pos] <;>
omega
@[simp]
lemma sub_le_iff {n : ℕ} {a b : Fin n} : a - b ≤ a ↔ b ≤ a := by
rw [← not_iff_not, Fin.not_le, Fin.not_le, lt_sub_iff]
@[simp]
lemma lt_one_iff {n : ℕ} (x : Fin (n + 2)) : x < 1 ↔ x = 0 := by
simp [lt_iff_val_lt_val]
lemma lt_sub_one_iff {k : Fin (n + 2)} : k < k - 1 ↔ k = 0 := by
simp
@[simp] lemma le_sub_one_iff {k : Fin (n + 1)} : k ≤ k - 1 ↔ k = 0 := by
cases n
· simp [fin_one_eq_zero k]
simp only [le_def]
rw [← lt_sub_one_iff, le_iff_lt_or_eq, val_fin_lt, val_inj, lt_sub_one_iff, or_iff_left_iff_imp,
eq_comm, sub_eq_iff_eq_add]
simp
lemma sub_one_lt_iff {k : Fin (n + 1)} : k - 1 < k ↔ 0 < k :=
not_iff_not.1 <| by simp only [lt_def, not_lt, val_fin_le, le_sub_one_iff, le_zero_iff]
@[simp] lemma neg_last (n : ℕ) : -Fin.last n = 1 := by simp [neg_eq_iff_add_eq_zero]
open Fin.NatCast in
lemma neg_natCast_eq_one (n : ℕ) : -(n : Fin (n + 1)) = 1 := by
simp only [natCast_eq_last, neg_last]
lemma rev_add (a b : Fin n) : rev (a + b) = rev a - b := by
cases n
· exact a.elim0
rw [← last_sub, ← last_sub, sub_add_eq_sub_sub]
lemma rev_sub (a b : Fin n) : rev (a - b) = rev a + b := by
rw [rev_eq_iff, rev_add, rev_rev]
lemma lt_add_one_of_succ_lt {n : ℕ} [NeZero n] {a : Fin n} (ha : a + 1 < n) : a < a + 1 := by
rw [lt_def, val_add, coe_ofNat_eq_mod, Nat.add_mod_mod, Nat.mod_eq_of_lt ha]
cutsat
lemma add_lt_left_iff {n : ℕ} {a b : Fin n} : a + b < a ↔ rev b < a := by
rw [← rev_lt_rev, Iff.comm, ← rev_lt_rev, rev_add, lt_sub_iff, rev_rev]
end Fin |
.lake/packages/mathlib/Mathlib/Algebra/Group/Hom/Instances.lean | import Mathlib.Algebra.Group.Hom.Basic
import Mathlib.Algebra.Group.InjSurj
import Mathlib.Algebra.Group.Pi.Basic
import Mathlib.Tactic.FastInstance
/-!
# Instances on spaces of monoid and group morphisms
We endow the space of monoid morphisms `M →* N` with a `CommMonoid` structure when the target is
commutative, through pointwise multiplication, and with a `CommGroup` structure when the target
is a commutative group. We also prove the same instances for additive situations.
Since these structures permit morphisms of morphisms, we also provide some composition-like
operations.
Finally, we provide the `Ring` structure on `AddMonoid.End`.
-/
assert_not_exists AddMonoidWithOne Ring
universe uM uN uP uQ
variable {M : Type uM} {N : Type uN} {P : Type uP} {Q : Type uQ}
instance ZeroHom.instNatSMul [Zero M] [AddMonoid N] : SMul ℕ (ZeroHom M N) where
smul a f :=
{ toFun := a • f
map_zero' := by simp }
instance AddMonoidHom.instNatSMul [AddZeroClass M] [AddCommMonoid N] : SMul ℕ (M →+ N) where
smul a f :=
{ toFun := a • f
map_zero' := by simp
map_add' x y := by simp [nsmul_add] }
@[to_additive existing ZeroHom.instNatSMul]
instance OneHom.instPow [One M] [Monoid N] : Pow (OneHom M N) ℕ where
pow f n :=
{ toFun := f ^ n
map_one' := by simp }
@[to_additive existing AddMonoidHom.instNatSMul]
instance MonoidHom.instPow [MulOneClass M] [CommMonoid N] : Pow (M →* N) ℕ where
pow f n :=
{ toFun := f ^ n
map_one' := by simp
map_mul' x y := by simp [mul_pow] }
@[to_additive (attr := simp)]
lemma OneHom.pow_apply [One M] [Monoid N] (f : OneHom M N) (n : ℕ) (x : M) :
(f ^ n) x = f x ^ n :=
rfl
@[to_additive (attr := simp)]
lemma MonoidHom.pow_apply [MulOneClass M] [CommMonoid N] (f : M →* N) (n : ℕ) (x : M) :
(f ^ n) x = f x ^ n :=
rfl
/-- `OneHom M N` is a `Monoid` if `N` is. -/
@[to_additive /-- `ZeroHom M N` is an `AddMonoid` if `N` is. -/]
instance OneHom.instMonoid [One M] [Monoid N] : Monoid (OneHom M N) :=
fast_instance%
DFunLike.coe_injective.monoid DFunLike.coe rfl (fun _ _ => rfl) (fun _ _ => rfl)
/-- `OneHom M N` is a `CommMonoid` if `N` is commutative. -/
@[to_additive /-- `ZeroHom M N` is an `AddCommMonoid` if `N` is commutative. -/]
instance OneHom.instCommMonoid [One M] [CommMonoid N] : CommMonoid (OneHom M N) :=
fast_instance%
DFunLike.coe_injective.commMonoid DFunLike.coe rfl (fun _ _ => rfl) (fun _ _ => rfl)
/-- `(M →* N)` is a `CommMonoid` if `N` is commutative. -/
@[to_additive /-- `(M →+ N)` is an `AddCommMonoid` if `N` is commutative. -/]
instance MonoidHom.instCommMonoid [MulOneClass M] [CommMonoid N] : CommMonoid (M →* N) :=
fast_instance%
DFunLike.coe_injective.commMonoid DFunLike.coe rfl (fun _ _ => rfl) (fun _ _ => rfl)
instance ZeroHom.instIntSMul [Zero M] [AddGroup N] : SMul ℤ (ZeroHom M N) where
smul a f :=
{ toFun := a • f
map_zero' := by simp [zsmul_zero] }
instance AddMonoidHom.instIntSMul [AddZeroClass M] [AddCommGroup N] : SMul ℤ (M →+ N) where
smul a f :=
{ toFun := a • f
map_zero' := by simp [zsmul_zero]
map_add' x y := by simp [zsmul_add] }
@[to_additive existing ZeroHom.instIntSMul]
instance OneHom.instIntPow [One M] [Group N] : Pow (OneHom M N) ℤ where
pow f n :=
{ toFun := f ^ n
map_one' := by simp }
@[to_additive existing AddMonoidHom.instIntSMul]
instance MonoidHom.instIntPow [MulOneClass M] [CommGroup N] : Pow (M →* N) ℤ where
pow f n :=
{ toFun := f ^ n
map_one' := by simp
map_mul' x y := by simp [mul_zpow] }
@[to_additive (attr := simp)]
lemma OneHom.zpow_apply [One M] [Group N] (f : OneHom M N) (z : ℤ) (x : M) :
(f ^ z) x = f x ^ z :=
rfl
@[to_additive (attr := simp)]
lemma MonoidHom.zpow_apply [MulOneClass M] [CommGroup N] (f : M →* N) (z : ℤ) (x : M) :
(f ^ z) x = f x ^ z :=
rfl
/-- If `G` is a group, then so is `OneHom M G`. -/
@[to_additive /-- If `G` is an additive group, then so is `ZeroHom M G`. -/]
instance OneHom.instGroup [One M] [Group N] : Group (OneHom M N) :=
fast_instance%
DFunLike.coe_injective.group DFunLike.coe
rfl (fun _ _ => rfl) (fun _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl)
/-- If `G` is a commutative group, then so is `OneHom M G`. -/
@[to_additive /-- If `G` is an additive commutative group, then so is `ZeroHom M G`. -/]
instance OneHom.instCommGroup [One M] [CommGroup N] : CommGroup (OneHom M N) :=
fast_instance%
DFunLike.coe_injective.commGroup DFunLike.coe
rfl (fun _ _ => rfl) (fun _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl)
/-- If `G` is a commutative group, then `M →* G` is a commutative group too. -/
@[to_additive /-- If `G` is an additive commutative group, then `M →+ G` is an additive commutative
group too. -/]
instance MonoidHom.instCommGroup [MulOneClass M] [CommGroup N] : CommGroup (M →* N) :=
fast_instance%
DFunLike.coe_injective.commGroup DFunLike.coe
rfl (fun _ _ => rfl) (fun _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl)
@[to_additive]
instance [One M] [MulOneClass N] [IsLeftCancelMul N] : IsLeftCancelMul (OneHom M N) :=
DFunLike.coe_injective.isLeftCancelMul _ fun _ _ => rfl
@[to_additive]
instance [MulOneClass M] [CommMonoid N] [IsLeftCancelMul N] : IsLeftCancelMul (M →* N) :=
DFunLike.coe_injective.isLeftCancelMul _ fun _ _ => rfl
@[to_additive]
instance [One M] [MulOneClass N] [IsRightCancelMul N] : IsRightCancelMul (OneHom M N) :=
DFunLike.coe_injective.isRightCancelMul _ fun _ _ => rfl
@[to_additive]
instance [MulOneClass M] [CommMonoid N] [IsRightCancelMul N] : IsRightCancelMul (M →* N) :=
DFunLike.coe_injective.isRightCancelMul _ fun _ _ => rfl
@[to_additive]
instance [One M] [MulOneClass N] [IsCancelMul N] : IsCancelMul (OneHom M N) where
@[to_additive]
instance [MulOneClass M] [CommMonoid N] [IsCancelMul N] : IsCancelMul (M →* N) where
section End
instance AddMonoid.End.instAddCommMonoid [AddCommMonoid M] : AddCommMonoid (AddMonoid.End M) :=
AddMonoidHom.instAddCommMonoid
@[simp]
theorem AddMonoid.End.zero_apply [AddCommMonoid M] (m : M) : (0 : AddMonoid.End M) m = 0 :=
rfl
-- Note: `@[simp]` omitted because `(1 : AddMonoid.End M) = id` by `AddMonoid.End.coe_one`
theorem AddMonoid.End.one_apply [AddZeroClass M] (m : M) : (1 : AddMonoid.End M) m = m :=
rfl
instance AddMonoid.End.instAddCommGroup [AddCommGroup M] : AddCommGroup (AddMonoid.End M) :=
AddMonoidHom.instAddCommGroup
instance AddMonoid.End.instIntCast [AddCommGroup M] : IntCast (AddMonoid.End M) :=
{ intCast := fun z => z • (1 : AddMonoid.End M) }
/-- See also `AddMonoid.End.intCast_def`. -/
@[simp]
theorem AddMonoid.End.intCast_apply [AddCommGroup M] (z : ℤ) (m : M) :
(↑z : AddMonoid.End M) m = z • m :=
rfl
end End
/-!
### Morphisms of morphisms
The structures above permit morphisms that themselves produce morphisms, provided the codomain
is commutative.
-/
namespace MonoidHom
@[to_additive]
theorem ext_iff₂ {_ : MulOneClass M} {_ : MulOneClass N} {_ : CommMonoid P} {f g : M →* N →* P} :
f = g ↔ ∀ x y, f x y = g x y :=
DFunLike.ext_iff.trans <| forall_congr' fun _ => DFunLike.ext_iff
/-- `flip` arguments of `f : M →* N →* P` -/
@[to_additive /-- `flip` arguments of `f : M →+ N →+ P` -/]
def flip {mM : MulOneClass M} {mN : MulOneClass N} {mP : CommMonoid P} (f : M →* N →* P) :
N →* M →* P where
toFun y :=
{ toFun := fun x => f x y,
map_one' := by simp [f.map_one, one_apply],
map_mul' := fun x₁ x₂ => by simp [f.map_mul, mul_apply] }
map_one' := ext fun x => (f x).map_one
map_mul' y₁ y₂ := ext fun x => (f x).map_mul y₁ y₂
@[to_additive (attr := simp)]
theorem flip_apply {_ : MulOneClass M} {_ : MulOneClass N} {_ : CommMonoid P} (f : M →* N →* P)
(x : M) (y : N) : f.flip y x = f x y :=
rfl
@[to_additive]
theorem map_one₂ {_ : MulOneClass M} {_ : MulOneClass N} {_ : CommMonoid P} (f : M →* N →* P)
(n : N) : f 1 n = 1 :=
(flip f n).map_one
@[to_additive]
theorem map_mul₂ {_ : MulOneClass M} {_ : MulOneClass N} {_ : CommMonoid P} (f : M →* N →* P)
(m₁ m₂ : M) (n : N) : f (m₁ * m₂) n = f m₁ n * f m₂ n :=
(flip f n).map_mul _ _
@[to_additive]
theorem map_inv₂ {_ : Group M} {_ : MulOneClass N} {_ : CommGroup P} (f : M →* N →* P) (m : M)
(n : N) : f m⁻¹ n = (f m n)⁻¹ :=
(flip f n).map_inv _
@[to_additive]
theorem map_div₂ {_ : Group M} {_ : MulOneClass N} {_ : CommGroup P} (f : M →* N →* P)
(m₁ m₂ : M) (n : N) : f (m₁ / m₂) n = f m₁ n / f m₂ n :=
(flip f n).map_div _ _
/-- Evaluation of a `MonoidHom` at a point as a monoid homomorphism. See also `MonoidHom.apply`
for the evaluation of any function at a point. -/
@[to_additive (attr := simps!)
/-- Evaluation of an `AddMonoidHom` at a point as an additive monoid homomorphism.
See also `AddMonoidHom.apply` for the evaluation of any function at a point. -/]
def eval [MulOneClass M] [CommMonoid N] : M →* (M →* N) →* N :=
(MonoidHom.id (M →* N)).flip
/-- The expression `fun g m ↦ g (f m)` as a `MonoidHom`.
Equivalently, `(fun g ↦ MonoidHom.comp g f)` as a `MonoidHom`. -/
@[to_additive (attr := simps!)
/-- The expression `fun g m ↦ g (f m)` as an `AddMonoidHom`.
Equivalently, `(fun g ↦ AddMonoidHom.comp g f)` as an `AddMonoidHom`.
This also exists in a `LinearMap` version, `LinearMap.lcomp`. -/]
def compHom' [MulOneClass M] [MulOneClass N] [CommMonoid P] (f : M →* N) : (N →* P) →* M →* P :=
flip <| eval.comp f
/-- Composition of monoid morphisms (`MonoidHom.comp`) as a monoid morphism.
Note that unlike `MonoidHom.comp_hom'` this requires commutativity of `N`. -/
@[to_additive (attr := simps)
/-- Composition of additive monoid morphisms (`AddMonoidHom.comp`) as an additive
monoid morphism.
Note that unlike `AddMonoidHom.comp_hom'` this requires commutativity of `N`.
This also exists in a `LinearMap` version, `LinearMap.llcomp`. -/]
def compHom [MulOneClass M] [CommMonoid N] [CommMonoid P] :
(N →* P) →* (M →* N) →* M →* P where
toFun g := { toFun := g.comp, map_one' := comp_one g, map_mul' := comp_mul g }
map_one' := by
ext1 f
exact one_comp f
map_mul' g₁ g₂ := by
ext1 f
exact mul_comp g₁ g₂ f
/-- Flipping arguments of monoid morphisms (`MonoidHom.flip`) as a monoid morphism. -/
@[to_additive (attr := simps)
/-- Flipping arguments of additive monoid morphisms (`AddMonoidHom.flip`)
as an additive monoid morphism. -/]
def flipHom {_ : MulOneClass M} {_ : MulOneClass N} {_ : CommMonoid P} :
(M →* N →* P) →* N →* M →* P where
toFun := MonoidHom.flip
map_one' := rfl
map_mul' _ _ := rfl
/-- The expression `fun m q ↦ f m (g q)` as a `MonoidHom`.
Note that the expression `fun q n ↦ f (g q) n` is simply `MonoidHom.comp`. -/
@[to_additive
/-- The expression `fun m q ↦ f m (g q)` as an `AddMonoidHom`.
Note that the expression `fun q n ↦ f (g q) n` is simply `AddMonoidHom.comp`.
This also exists as a `LinearMap` version, `LinearMap.compl₂` -/]
def compl₂ [MulOneClass M] [MulOneClass N] [CommMonoid P] [MulOneClass Q] (f : M →* N →* P)
(g : Q →* N) : M →* Q →* P :=
(compHom' g).comp f
@[to_additive (attr := simp)]
theorem compl₂_apply [MulOneClass M] [MulOneClass N] [CommMonoid P] [MulOneClass Q]
(f : M →* N →* P) (g : Q →* N) (m : M) (q : Q) : (compl₂ f g) m q = f m (g q) :=
rfl
/-- The expression `fun m n ↦ g (f m n)` as a `MonoidHom`. -/
@[to_additive
/-- The expression `fun m n ↦ g (f m n)` as an `AddMonoidHom`.
This also exists as a `LinearMap` version, `LinearMap.compr₂` -/]
def compr₂ [MulOneClass M] [MulOneClass N] [CommMonoid P] [CommMonoid Q] (f : M →* N →* P)
(g : P →* Q) : M →* N →* Q :=
(compHom g).comp f
@[to_additive (attr := simp)]
theorem compr₂_apply [MulOneClass M] [MulOneClass N] [CommMonoid P] [CommMonoid Q] (f : M →* N →* P)
(g : P →* Q) (m : M) (n : N) : (compr₂ f g) m n = g (f m n) :=
rfl
end MonoidHom |
.lake/packages/mathlib/Mathlib/Algebra/Group/Hom/Basic.lean | import Mathlib.Algebra.Group.Basic
import Mathlib.Algebra.Group.Hom.Defs
/-!
# Additional lemmas about monoid and group homomorphisms
-/
-- `NeZero` cannot be additivised, hence its theory should be developed outside of the
-- `Algebra.Group` folder.
assert_not_imported Mathlib.Algebra.NeZero
variable {α M N P : Type*}
-- monoids
variable {G : Type*} {H : Type*}
-- groups
variable {F : Type*}
section CommMonoid
variable [CommMonoid α]
/-- The `n`th power map on a commutative monoid for a natural `n`, considered as a morphism of
monoids. -/
@[to_additive (attr := simps) /-- Multiplication by a natural `n` on a commutative additive monoid,
considered as a morphism of additive monoids. -/]
def powMonoidHom (n : ℕ) : α →* α where
toFun := (· ^ n)
map_one' := one_pow _
map_mul' a b := mul_pow a b n
end CommMonoid
section DivisionCommMonoid
variable [DivisionCommMonoid α]
/-- The `n`-th power map (for an integer `n`) on a commutative group, considered as a group
homomorphism. -/
@[to_additive (attr := simps) /-- Multiplication by an integer `n` on a commutative additive group,
considered as an additive group homomorphism. -/]
def zpowGroupHom (n : ℤ) : α →* α where
toFun := (· ^ n)
map_one' := one_zpow n
map_mul' a b := mul_zpow a b n
/-- Inversion on a commutative group, considered as a monoid homomorphism. -/
@[to_additive /-- Negation on a commutative additive group, considered as an additive monoid
homomorphism. -/]
def invMonoidHom : α →* α where
toFun := Inv.inv
map_one' := inv_one
map_mul' := mul_inv
@[simp]
theorem coe_invMonoidHom : (invMonoidHom : α → α) = Inv.inv := rfl
@[simp]
theorem invMonoidHom_apply (a : α) : invMonoidHom a = a⁻¹ := rfl
end DivisionCommMonoid
namespace OneHom
/-- Given two one-preserving morphisms `f`, `g`,
`f * g` is the one-preserving morphism sending `x` to `f x * g x`. -/
@[to_additive /-- Given two zero-preserving morphisms `f`, `g`,
`f + g` is the zero-preserving morphism sending `x` to `f x + g x`. -/]
instance [One M] [MulOneClass N] : Mul (OneHom M N) where
mul f g :=
{ toFun m := f m * g m
map_one' := by simp}
@[to_additive (attr := norm_cast)]
theorem coe_mul {M N} [One M] [MulOneClass N] (f g : OneHom M N) : ⇑(f * g) = ⇑f * ⇑g := rfl
@[to_additive (attr := simp)]
theorem mul_apply {M N} [One M] [MulOneClass N] (f g : OneHom M N) (x : M) :
(f * g) x = f x * g x := rfl
@[to_additive]
theorem mul_comp [One M] [One N] [MulOneClass P] (g₁ g₂ : OneHom N P) (f : OneHom M N) :
(g₁ * g₂).comp f = g₁.comp f * g₂.comp f := rfl
/-- Given a one-preserving morphism `f`,
`f⁻¹` is the one-preserving morphism sending `x` to `(f x)⁻¹`. -/
@[to_additive /-- Given a zero-preserving morphism `f`,
`-f` is the zero-preserving morphism sending `x` to `-f x`. -/]
instance [One M] [InvOneClass N] : Inv (OneHom M N) where
inv f :=
{ toFun m := (f m)⁻¹
map_one' := by simp}
@[to_additive (attr := norm_cast)]
theorem coe_inv {M N} [One M] [InvOneClass N] (f : OneHom M N) : ⇑(f⁻¹) = (⇑f)⁻¹ := rfl
@[to_additive (attr := simp)]
theorem inv_apply {M N} [One M] [InvOneClass N] (f : OneHom M N) (x : M) :
f⁻¹ x = (f x)⁻¹ := rfl
@[to_additive]
theorem inv_comp [One M] [One N] [InvOneClass P] (g : OneHom N P) (f : OneHom M N) :
(g⁻¹).comp f = (g.comp f)⁻¹ := rfl
/-- Given two one-preserving morphisms `f`, `g`,
`f / g` is the one-preserving morphism sending `x` to `f x / g x`. -/
@[to_additive /-- Given two zero-preserving morphisms `f`, `g`,
`f - g` is the additive morphism sending `x` to `f x - g x`. -/]
instance [One M] [DivisionMonoid N] : Div (OneHom M N) where
div f g :=
{ toFun m := f m / g m
map_one' := by simp }
@[to_additive (attr := norm_cast)]
theorem coe_div {M N} [One M] [DivisionMonoid N] (f g : OneHom M N) : ⇑(f / g) = ⇑f / ⇑g := rfl
@[to_additive (attr := simp)]
theorem div_apply {M N} [One M] [DivisionMonoid N] (f g : OneHom M N) (x : M) :
(f / g) x = f x / g x := rfl
@[to_additive]
theorem div_comp [One M] [One N] [DivisionMonoid P] (g₁ g₂ : OneHom N P) (f : OneHom M N) :
(g₁ / g₂).comp f = g₁.comp f / g₂.comp f := rfl
end OneHom
namespace MulHom
/-- Given two mul morphisms `f`, `g` to a commutative semigroup, `f * g` is the mul morphism
sending `x` to `f x * g x`. -/
@[to_additive /-- Given two additive morphisms `f`, `g` to an additive commutative semigroup,
`f + g` is the additive morphism sending `x` to `f x + g x`. -/]
instance [Mul M] [CommSemigroup N] : Mul (M →ₙ* N) :=
⟨fun f g =>
{ toFun := fun m => f m * g m,
map_mul' := fun x y => by
show f (x * y) * g (x * y) = f x * g x * (f y * g y)
rw [f.map_mul, g.map_mul, ← mul_assoc, ← mul_assoc, mul_right_comm (f x)] }⟩
@[to_additive (attr := simp)]
theorem mul_apply {M N} [Mul M] [CommSemigroup N] (f g : M →ₙ* N) (x : M) :
(f * g) x = f x * g x := rfl
@[to_additive]
theorem mul_comp [Mul M] [Mul N] [CommSemigroup P] (g₁ g₂ : N →ₙ* P) (f : M →ₙ* N) :
(g₁ * g₂).comp f = g₁.comp f * g₂.comp f := rfl
@[to_additive]
theorem comp_mul [Mul M] [CommSemigroup N] [CommSemigroup P] (g : N →ₙ* P) (f₁ f₂ : M →ₙ* N) :
g.comp (f₁ * f₂) = g.comp f₁ * g.comp f₂ := by
ext
simp only [mul_apply, Function.comp_apply, map_mul, coe_comp]
end MulHom
namespace MonoidHom
section Group
variable [Group G]
/-- A homomorphism from a group to a monoid is injective iff its kernel is trivial.
For the iff statement on the triviality of the kernel, see `injective_iff_map_eq_one'`. -/
@[to_additive
/-- A homomorphism from an additive group to an additive monoid is injective iff
its kernel is trivial. For the iff statement on the triviality of the kernel,
see `injective_iff_map_eq_zero'`. -/]
theorem _root_.injective_iff_map_eq_one {G H} [Group G] [MulOneClass H]
[FunLike F G H] [MonoidHomClass F G H]
(f : F) : Function.Injective f ↔ ∀ a, f a = 1 → a = 1 :=
⟨fun h _ => (map_eq_one_iff f h).mp, fun h x y hxy =>
mul_inv_eq_one.1 <| h _ <| by rw [map_mul, hxy, ← map_mul, mul_inv_cancel, map_one]⟩
/-- A homomorphism from a group to a monoid is injective iff its kernel is trivial,
stated as an iff on the triviality of the kernel.
For the implication, see `injective_iff_map_eq_one`. -/
@[to_additive
/-- A homomorphism from an additive group to an additive monoid is injective iff its
kernel is trivial, stated as an iff on the triviality of the kernel. For the implication, see
`injective_iff_map_eq_zero`. -/]
theorem _root_.injective_iff_map_eq_one' {G H} [Group G] [MulOneClass H]
[FunLike F G H] [MonoidHomClass F G H]
(f : F) : Function.Injective f ↔ ∀ a, f a = 1 ↔ a = 1 :=
(injective_iff_map_eq_one f).trans <|
forall_congr' fun _ => ⟨fun h => ⟨h, fun H => H.symm ▸ map_one f⟩, Iff.mp⟩
/-- Makes a group homomorphism from a proof that the map preserves right division
`fun x y => x * y⁻¹`. See also `MonoidHom.of_map_div` for a version using `fun x y => x / y`.
-/
@[to_additive
/-- Makes an additive group homomorphism from a proof that the map preserves
the operation `fun a b => a + -b`. See also `AddMonoidHom.ofMapSub` for a version using
`fun a b => a - b`. -/]
def ofMapMulInv {H : Type*} [Group H] (f : G → H)
(map_div : ∀ a b : G, f (a * b⁻¹) = f a * (f b)⁻¹) : G →* H :=
(mk' f) fun x y =>
calc
f (x * y) = f x * (f <| 1 * 1⁻¹ * y⁻¹)⁻¹ := by
{ simp only [one_mul, inv_one, ← map_div, inv_inv] }
_ = f x * f y := by
{ simp only [map_div]
simp only [mul_inv_cancel, one_mul, inv_inv] }
@[to_additive (attr := simp)]
theorem coe_of_map_mul_inv {H : Type*} [Group H] (f : G → H)
(map_div : ∀ a b : G, f (a * b⁻¹) = f a * (f b)⁻¹) : ↑(ofMapMulInv f map_div) = f :=
rfl
/-- Define a morphism of additive groups given a map which respects ratios. -/
@[to_additive /-- Define a morphism of additive groups given a map which respects difference. -/]
def ofMapDiv {H : Type*} [Group H] (f : G → H) (hf : ∀ x y, f (x / y) = f x / f y) : G →* H :=
ofMapMulInv f (by simpa only [div_eq_mul_inv] using hf)
@[to_additive (attr := simp)]
theorem coe_of_map_div {H : Type*} [Group H] (f : G → H) (hf : ∀ x y, f (x / y) = f x / f y) :
↑(ofMapDiv f hf) = f := rfl
end Group
section Mul
variable [MulOneClass M] [CommMonoid N]
/-- Given two monoid morphisms `f`, `g` to a commutative monoid, `f * g` is the monoid morphism
sending `x` to `f x * g x`. -/
@[to_additive]
instance mul : Mul (M →* N) :=
⟨fun f g =>
{ toFun := fun m => f m * g m,
map_one' := by simp,
map_mul' := fun x y => by
rw [f.map_mul, g.map_mul, ← mul_assoc, ← mul_assoc, mul_right_comm (f x)] }⟩
/-- Given two additive monoid morphisms `f`, `g` to an additive commutative monoid,
`f + g` is the additive monoid morphism sending `x` to `f x + g x`. -/
add_decl_doc AddMonoidHom.add
@[to_additive (attr := simp)] lemma mul_apply (f g : M →* N) (x : M) : (f * g) x = f x * g x := rfl
@[to_additive]
lemma mul_comp [MulOneClass P] (g₁ g₂ : M →* N) (f : P →* M) :
(g₁ * g₂).comp f = g₁.comp f * g₂.comp f := rfl
@[to_additive]
lemma comp_mul [CommMonoid P] (g : N →* P) (f₁ f₂ : M →* N) :
g.comp (f₁ * f₂) = g.comp f₁ * g.comp f₂ := by
ext; simp only [mul_apply, Function.comp_apply, map_mul, coe_comp]
end Mul
section InvDiv
variable [MulOneClass M] [MulOneClass N] [CommGroup G] [CommGroup H]
/-- If `f` is a monoid homomorphism to a commutative group, then `f⁻¹` is the homomorphism sending
`x` to `(f x)⁻¹`. -/
@[to_additive /-- If `f` is an additive monoid homomorphism to an additive commutative group,
then `-f` is the homomorphism sending `x` to `-(f x)`. -/]
instance : Inv (M →* G) where
inv f := mk' (fun g ↦ (f g)⁻¹) fun a b ↦ by simp_rw [← mul_inv, f.map_mul]
@[to_additive (attr := simp)] lemma inv_apply (f : M →* G) (x : M) : f⁻¹ x = (f x)⁻¹ := rfl
@[to_additive (attr := simp)]
theorem inv_comp (φ : N →* G) (ψ : M →* N) : φ⁻¹.comp ψ = (φ.comp ψ)⁻¹ := rfl
@[to_additive (attr := simp)]
theorem comp_inv (φ : G →* H) (ψ : M →* G) : φ.comp ψ⁻¹ = (φ.comp ψ)⁻¹ := by
ext
simp only [Function.comp_apply, inv_apply, map_inv, coe_comp]
/-- If `f` and `g` are monoid homomorphisms to a commutative group, then `f / g` is the homomorphism
sending `x` to `(f x) / (g x)`. -/
@[to_additive /-- If `f` and `g` are monoid homomorphisms to an additive commutative group,
then `f - g` is the homomorphism sending `x` to `(f x) - (g x)`. -/]
instance : Div (M →* G) where
div f g := mk' (fun x ↦ f x / g x) fun a b ↦ by
simp [div_eq_mul_inv, mul_assoc, mul_left_comm, mul_comm]
@[to_additive (attr := simp)] lemma div_apply (f g : M →* G) (x : M) : (f / g) x = f x / g x := rfl
@[to_additive (attr := simp)]
lemma div_comp (f g : N →* G) (h : M →* N) : (f / g).comp h = f.comp h / g.comp h := rfl
@[to_additive (attr := simp)]
lemma comp_div (f : G →* H) (g h : M →* G) : f.comp (g / h) = f.comp g / f.comp h := by
ext; simp only [Function.comp_apply, div_apply, map_div, coe_comp]
end InvDiv
/-- If `H` is commutative and `G →* H` is injective, then `G` is commutative. -/
def commGroupOfInjective [Group G] [CommGroup H] (f : G →* H) (hf : Function.Injective f) :
CommGroup G :=
⟨by simp_rw [← hf.eq_iff, map_mul, mul_comm, implies_true]⟩
/-- If `G` is commutative and `G →* H` is surjective, then `H` is commutative. -/
def commGroupOfSurjective [CommGroup G] [Group H] (f : G →* H) (hf : Function.Surjective f) :
CommGroup H :=
⟨by simp_rw [hf.forall₂, ← map_mul, mul_comm, implies_true]⟩
end MonoidHom |
.lake/packages/mathlib/Mathlib/Algebra/Group/Hom/End.lean | import Mathlib.Algebra.Group.Hom.Instances
import Mathlib.Algebra.Ring.Defs
/-!
# Instances on spaces of monoid and group morphisms
This file does two things involving `AddMonoid.End` and `Ring`.
They are separate, and if someone would like to split this file in two that may be helpful.
* We provide the `Ring` structure on `AddMonoid.End`.
* Results about `AddMonoid.End R` when `R` is a ring.
-/
universe uM
variable {M : Type uM}
namespace AddMonoid.End
instance instAddMonoidWithOne (M) [AddCommMonoid M] : AddMonoidWithOne (AddMonoid.End M) where
natCast n := n • (1 : AddMonoid.End M)
natCast_zero := AddMonoid.nsmul_zero _
natCast_succ n := AddMonoid.nsmul_succ n 1
/-- See also `AddMonoid.End.natCast_def`. -/
@[simp]
lemma natCast_apply [AddCommMonoid M] (n : ℕ) (m : M) : (↑n : AddMonoid.End M) m = n • m := rfl
@[simp] lemma ofNat_apply [AddCommMonoid M] (n : ℕ) [n.AtLeastTwo] (m : M) :
(ofNat(n) : AddMonoid.End M) m = n • m := rfl
instance instSemiring [AddCommMonoid M] : Semiring (AddMonoid.End M) :=
{ AddMonoid.End.instMonoid M,
AddMonoidHom.instAddCommMonoid,
AddMonoid.End.instAddMonoidWithOne M with
zero_mul := fun _ => AddMonoidHom.ext fun _ => rfl,
mul_zero := fun _ => AddMonoidHom.ext fun _ => AddMonoidHom.map_zero _,
left_distrib := fun _ _ _ => AddMonoidHom.ext fun _ => AddMonoidHom.map_add _ _ _,
right_distrib := fun _ _ _ => AddMonoidHom.ext fun _ => rfl }
instance instRing [AddCommGroup M] : Ring (AddMonoid.End M) :=
{ AddMonoid.End.instSemiring, AddMonoid.End.instAddCommGroup with
intCast := fun z => z • (1 : AddMonoid.End M),
intCast_ofNat := natCast_zsmul _,
intCast_negSucc := negSucc_zsmul _ }
end AddMonoid.End |
.lake/packages/mathlib/Mathlib/Algebra/Group/Hom/Defs.lean | import Mathlib.Algebra.Group.Defs
import Mathlib.Algebra.Notation.Pi.Defs
import Mathlib.Data.FunLike.Basic
import Mathlib.Logic.Function.Iterate
/-!
# Monoid and group homomorphisms
This file defines the bundled structures for monoid and group homomorphisms. Namely, we define
`MonoidHom` (resp., `AddMonoidHom`) to be bundled homomorphisms between multiplicative (resp.,
additive) monoids or groups.
We also define coercion to a function, and usual operations: composition, identity homomorphism,
pointwise multiplication and pointwise inversion.
This file also defines the lesser-used (and notation-less) homomorphism types which are used as
building blocks for other homomorphisms:
* `ZeroHom`
* `OneHom`
* `AddHom`
* `MulHom`
## Notation
* `→+`: Bundled `AddMonoid` homs. Also use for `AddGroup` homs.
* `→*`: Bundled `Monoid` homs. Also use for `Group` homs.
* `→ₙ+`: Bundled `AddSemigroup` homs.
* `→ₙ*`: Bundled `Semigroup` homs.
## Implementation notes
There's a coercion from bundled homs to fun, and the canonical
notation is to use the bundled hom as a function via this coercion.
There is no `GroupHom` -- the idea is that `MonoidHom` is used.
The constructor for `MonoidHom` needs a proof of `map_one` as well
as `map_mul`; a separate constructor `MonoidHom.mk'` will construct
group homs (i.e. monoid homs between groups) given only a proof
that multiplication is preserved,
Implicit `{}` brackets are often used instead of type class `[]` brackets. This is done when the
instances can be inferred because they are implicit arguments to the type `MonoidHom`. When they
can be inferred from the type it is faster to use this method than to use type class inference.
Historically this file also included definitions of unbundled homomorphism classes; they were
deprecated and moved to `Deprecated/Group`.
## Tags
MonoidHom, AddMonoidHom
-/
open Function
variable {ι α β M N P : Type*}
-- monoids
variable {G : Type*} {H : Type*}
-- groups
variable {F : Type*}
-- homs
section Zero
/-- `ZeroHom M N` is the type of functions `M → N` that preserve zero.
When possible, instead of parametrizing results over `(f : ZeroHom M N)`,
you should parametrize over `(F : Type*) [ZeroHomClass F M N] (f : F)`.
When you extend this structure, make sure to also extend `ZeroHomClass`.
-/
structure ZeroHom (M : Type*) (N : Type*) [Zero M] [Zero N] where
/-- The underlying function -/
protected toFun : M → N
/-- The proposition that the function preserves 0 -/
protected map_zero' : toFun 0 = 0
/-- `ZeroHomClass F M N` states that `F` is a type of zero-preserving homomorphisms.
You should extend this typeclass when you extend `ZeroHom`.
-/
class ZeroHomClass (F : Type*) (M N : outParam Type*) [Zero M] [Zero N] [FunLike F M N] :
Prop where
/-- The proposition that the function preserves 0 -/
map_zero : ∀ f : F, f 0 = 0
-- Instances and lemmas are defined below through `@[to_additive]`.
end Zero
section Add
/-- `M →ₙ+ N` is the type of functions `M → N` that preserve addition. The `ₙ` in the notation
stands for "non-unital" because it is intended to match the notation for `NonUnitalAlgHom` and
`NonUnitalRingHom`, so a `AddHom` is a non-unital additive monoid hom.
When possible, instead of parametrizing results over `(f : AddHom M N)`,
you should parametrize over `(F : Type*) [AddHomClass F M N] (f : F)`.
When you extend this structure, make sure to extend `AddHomClass`.
-/
structure AddHom (M : Type*) (N : Type*) [Add M] [Add N] where
/-- The underlying function -/
protected toFun : M → N
/-- The proposition that the function preserves addition -/
protected map_add' : ∀ x y, toFun (x + y) = toFun x + toFun y
/-- `M →ₙ+ N` denotes the type of addition-preserving maps from `M` to `N`. -/
infixr:25 " →ₙ+ " => AddHom
/-- `AddHomClass F M N` states that `F` is a type of addition-preserving homomorphisms.
You should declare an instance of this typeclass when you extend `AddHom`.
-/
class AddHomClass (F : Type*) (M N : outParam Type*) [Add M] [Add N] [FunLike F M N] : Prop where
/-- The proposition that the function preserves addition -/
map_add : ∀ (f : F) (x y : M), f (x + y) = f x + f y
-- Instances and lemmas are defined below through `@[to_additive]`.
end Add
section add_zero
/-- `M →+ N` is the type of functions `M → N` that preserve the `AddZero` structure.
`AddMonoidHom` is also used for group homomorphisms.
When possible, instead of parametrizing results over `(f : M →+ N)`,
you should parametrize over `(F : Type*) [AddMonoidHomClass F M N] (f : F)`.
When you extend this structure, make sure to extend `AddMonoidHomClass`.
-/
structure AddMonoidHom (M : Type*) (N : Type*) [AddZero M] [AddZero N]
extends ZeroHom M N, AddHom M N
attribute [nolint docBlame] AddMonoidHom.toAddHom
attribute [nolint docBlame] AddMonoidHom.toZeroHom
/-- `M →+ N` denotes the type of additive monoid homomorphisms from `M` to `N`. -/
infixr:25 " →+ " => AddMonoidHom
/-- `AddMonoidHomClass F M N` states that `F` is a type of `AddZero`-preserving
homomorphisms.
You should also extend this typeclass when you extend `AddMonoidHom`.
-/
class AddMonoidHomClass (F : Type*) (M N : outParam Type*)
[AddZero M] [AddZero N] [FunLike F M N] : Prop
extends AddHomClass F M N, ZeroHomClass F M N
-- Instances and lemmas are defined below through `@[to_additive]`.
end add_zero
section One
variable [One M] [One N]
/-- `OneHom M N` is the type of functions `M → N` that preserve one.
When possible, instead of parametrizing results over `(f : OneHom M N)`,
you should parametrize over `(F : Type*) [OneHomClass F M N] (f : F)`.
When you extend this structure, make sure to also extend `OneHomClass`.
-/
@[to_additive]
structure OneHom (M : Type*) (N : Type*) [One M] [One N] where
/-- The underlying function -/
protected toFun : M → N
/-- The proposition that the function preserves 1 -/
protected map_one' : toFun 1 = 1
/-- `OneHomClass F M N` states that `F` is a type of one-preserving homomorphisms.
You should extend this typeclass when you extend `OneHom`.
-/
@[to_additive]
class OneHomClass (F : Type*) (M N : outParam Type*) [One M] [One N] [FunLike F M N] : Prop where
/-- The proposition that the function preserves 1 -/
map_one : ∀ f : F, f 1 = 1
@[to_additive]
instance OneHom.funLike : FunLike (OneHom M N) M N where
coe := OneHom.toFun
coe_injective' f g h := by cases f; cases g; congr
@[to_additive]
instance OneHom.oneHomClass : OneHomClass (OneHom M N) M N where
map_one := OneHom.map_one'
library_note2 «hom simp lemma priority»
/--
The hom class hierarchy allows for a single lemma, such as `map_one`, to apply to a large variety
of morphism types, so long as they have an instance of `OneHomClass`. For example, this applies to
to `MonoidHom`, `RingHom`, `AlgHom`, `StarAlgHom`, as well as their `Equiv` variants, etc. However,
precisely because these lemmas are so widely applicable, they keys in the `simp` discrimination tree
are necessarily highly non-specific. For example, the key for `map_one` is
`@DFunLike.coe _ _ _ _ _ 1`.
Consequently, whenever lean sees `⇑f 1`, for some `f : F`, it will attempt to synthesize a
`OneHomClass F ?A ?B` instance. If no such instance exists, then Lean will need to traverse (almost)
the entirety of the `FunLike` hierarchy in order to determine this because so many classes have a
`OneHomClass` instance (in fact, this problem is likely worse for `ZeroHomClass`). This can lead to
a significant performance hit when `map_one` fails to apply.
To avoid this problem, we mark these widely applicable simp lemmas with key discimination tree keys
with `mid` priority in order to ensure that they are not tried first.
We do not use `low`, to allow bundled morphisms to unfold themselves with `low` priority such that
the generic morphism lemmas are applied first. For instance, we might have
```lean
def fooMonoidHom : M →* N where
toFun := foo; map_one' := sorry; map_mul' := sorry
@[simp low] lemma fooMonoidHom_apply (x : M) : fooMonoidHom x = foo x := rfl
```
As `map_mul` is tagged `simp mid`, this means that it still fires before `fooMonoidHom_apply`, which
is the behavior we desire.
-/
variable [FunLike F M N]
/-- See note [hom simp lemma priority] -/
@[to_additive (attr := simp mid, grind =)]
theorem map_one [OneHomClass F M N] (f : F) : f 1 = 1 :=
OneHomClass.map_one f
@[to_additive] lemma map_comp_one [OneHomClass F M N] (f : F) : f ∘ (1 : ι → M) = 1 := by simp
/-- In principle this could be an instance, but in practice it causes performance issues. -/
@[to_additive]
theorem Subsingleton.of_oneHomClass [Subsingleton M] [OneHomClass F M N] :
Subsingleton F where
allEq f g := DFunLike.ext _ _ fun x ↦ by simp [Subsingleton.elim x 1]
@[to_additive] instance [Subsingleton M] : Subsingleton (OneHom M N) := .of_oneHomClass
@[to_additive]
theorem map_eq_one_iff [OneHomClass F M N] (f : F) (hf : Function.Injective f)
{x : M} :
f x = 1 ↔ x = 1 := hf.eq_iff' (map_one f)
@[to_additive]
theorem map_ne_one_iff {R S F : Type*} [One R] [One S] [FunLike F R S] [OneHomClass F R S] (f : F)
(hf : Function.Injective f) {x : R} : f x ≠ 1 ↔ x ≠ 1 := (map_eq_one_iff f hf).not
@[to_additive]
theorem ne_one_of_map {R S F : Type*} [One R] [One S] [FunLike F R S] [OneHomClass F R S]
{f : F} {x : R} (hx : f x ≠ 1) : x ≠ 1 := ne_of_apply_ne f <| (by rwa [(map_one f)])
/-- Turn an element of a type `F` satisfying `OneHomClass F M N` into an actual
`OneHom`. This is declared as the default coercion from `F` to `OneHom M N`. -/
@[to_additive (attr := coe)
/-- Turn an element of a type `F` satisfying `ZeroHomClass F M N` into an actual
`ZeroHom`. This is declared as the default coercion from `F` to `ZeroHom M N`. -/]
def OneHomClass.toOneHom [OneHomClass F M N] (f : F) : OneHom M N where
toFun := f
map_one' := map_one f
/-- Any type satisfying `OneHomClass` can be cast into `OneHom` via `OneHomClass.toOneHom`. -/
@[to_additive /-- Any type satisfying `ZeroHomClass` can be cast into `ZeroHom` via
`ZeroHomClass.toZeroHom`. -/]
instance [OneHomClass F M N] : CoeTC F (OneHom M N) :=
⟨OneHomClass.toOneHom⟩
@[to_additive (attr := simp)]
theorem OneHom.coe_coe [OneHomClass F M N] (f : F) :
((f : OneHom M N) : M → N) = f := rfl
end One
section Mul
variable [Mul M] [Mul N]
/-- `M →ₙ* N` is the type of functions `M → N` that preserve multiplication. The `ₙ` in the notation
stands for "non-unital" because it is intended to match the notation for `NonUnitalAlgHom` and
`NonUnitalRingHom`, so a `MulHom` is a non-unital monoid hom.
When possible, instead of parametrizing results over `(f : M →ₙ* N)`,
you should parametrize over `(F : Type*) [MulHomClass F M N] (f : F)`.
When you extend this structure, make sure to extend `MulHomClass`.
-/
@[to_additive]
structure MulHom (M : Type*) (N : Type*) [Mul M] [Mul N] where
/-- The underlying function -/
protected toFun : M → N
/-- The proposition that the function preserves multiplication -/
protected map_mul' : ∀ x y, toFun (x * y) = toFun x * toFun y
/-- `M →ₙ* N` denotes the type of multiplication-preserving maps from `M` to `N`. -/
infixr:25 " →ₙ* " => MulHom
/-- `MulHomClass F M N` states that `F` is a type of multiplication-preserving homomorphisms.
You should declare an instance of this typeclass when you extend `MulHom`.
-/
@[to_additive]
class MulHomClass (F : Type*) (M N : outParam Type*) [Mul M] [Mul N] [FunLike F M N] : Prop where
/-- The proposition that the function preserves multiplication -/
map_mul : ∀ (f : F) (x y : M), f (x * y) = f x * f y
@[to_additive]
instance MulHom.funLike : FunLike (M →ₙ* N) M N where
coe := MulHom.toFun
coe_injective' f g h := by cases f; cases g; congr
/-- `MulHom` is a type of multiplication-preserving homomorphisms -/
@[to_additive /-- `AddHom` is a type of addition-preserving homomorphisms -/]
instance MulHom.mulHomClass : MulHomClass (M →ₙ* N) M N where
map_mul := MulHom.map_mul'
variable [FunLike F M N]
/-- See note [hom simp lemma priority] -/
@[to_additive (attr := simp mid, grind =)]
theorem map_mul [MulHomClass F M N] (f : F) (x y : M) : f (x * y) = f x * f y :=
MulHomClass.map_mul f x y
@[to_additive (attr := simp)]
lemma map_comp_mul [MulHomClass F M N] (f : F) (g h : ι → M) : f ∘ (g * h) = f ∘ g * f ∘ h := by
ext; simp
/-- Turn an element of a type `F` satisfying `MulHomClass F M N` into an actual
`MulHom`. This is declared as the default coercion from `F` to `M →ₙ* N`. -/
@[to_additive (attr := coe)
/-- Turn an element of a type `F` satisfying `AddHomClass F M N` into an actual
`AddHom`. This is declared as the default coercion from `F` to `M →ₙ+ N`. -/]
def MulHomClass.toMulHom [MulHomClass F M N] (f : F) : M →ₙ* N where
toFun := f
map_mul' := map_mul f
/-- Any type satisfying `MulHomClass` can be cast into `MulHom` via `MulHomClass.toMulHom`. -/
@[to_additive /-- Any type satisfying `AddHomClass` can be cast into `AddHom` via
`AddHomClass.toAddHom`. -/]
instance [MulHomClass F M N] : CoeTC F (M →ₙ* N) :=
⟨MulHomClass.toMulHom⟩
@[to_additive (attr := simp)]
theorem MulHom.coe_coe [MulHomClass F M N] (f : F) : ((f : MulHom M N) : M → N) = f := rfl
end Mul
section mul_one
variable [MulOne M] [MulOne N]
/-- `M →* N` is the type of functions `M → N` that preserve the `MulOne` structure.
`MonoidHom` is used for both monoid and group homomorphisms.
When possible, instead of parametrizing results over `(f : M →* N)`,
you should parametrize over `(F : Type*) [MonoidHomClass F M N] (f : F)`.
When you extend this structure, make sure to extend `MonoidHomClass`.
-/
@[to_additive]
structure MonoidHom (M : Type*) (N : Type*) [MulOne M] [MulOne N]
extends OneHom M N, M →ₙ* N
attribute [nolint docBlame] MonoidHom.toMulHom
attribute [nolint docBlame] MonoidHom.toOneHom
/-- `M →* N` denotes the type of monoid homomorphisms from `M` to `N`. -/
infixr:25 " →* " => MonoidHom
/-- `MonoidHomClass F M N` states that `F` is a type of `Monoid`-preserving homomorphisms.
You should also extend this typeclass when you extend `MonoidHom`. -/
@[to_additive]
class MonoidHomClass (F : Type*) (M N : outParam Type*) [MulOne M] [MulOne N]
[FunLike F M N] : Prop
extends MulHomClass F M N, OneHomClass F M N
@[to_additive]
instance MonoidHom.instFunLike : FunLike (M →* N) M N where
coe f := f.toFun
coe_injective' f g h := by
cases f
cases g
congr
apply DFunLike.coe_injective'
exact h
@[to_additive]
instance MonoidHom.instMonoidHomClass : MonoidHomClass (M →* N) M N where
map_mul := MonoidHom.map_mul'
map_one f := f.toOneHom.map_one'
@[to_additive] instance [Subsingleton M] : Subsingleton (M →* N) := .of_oneHomClass
variable [FunLike F M N]
/-- Turn an element of a type `F` satisfying `MonoidHomClass F M N` into an actual
`MonoidHom`. This is declared as the default coercion from `F` to `M →* N`. -/
@[to_additive (attr := coe)
/-- Turn an element of a type `F` satisfying `AddMonoidHomClass F M N` into an
actual `MonoidHom`. This is declared as the default coercion from `F` to `M →+ N`. -/]
def MonoidHomClass.toMonoidHom [MonoidHomClass F M N] (f : F) : M →* N :=
{ (f : M →ₙ* N), (f : OneHom M N) with }
/-- Any type satisfying `MonoidHomClass` can be cast into `MonoidHom` via
`MonoidHomClass.toMonoidHom`. -/
@[to_additive /-- Any type satisfying `AddMonoidHomClass` can be cast into `AddMonoidHom` via
`AddMonoidHomClass.toAddMonoidHom`. -/]
instance [MonoidHomClass F M N] : CoeTC F (M →* N) :=
⟨MonoidHomClass.toMonoidHom⟩
@[to_additive (attr := simp)]
theorem MonoidHom.coe_coe [MonoidHomClass F M N] (f : F) : ((f : M →* N) : M → N) = f := rfl
@[to_additive]
theorem map_mul_eq_one [MonoidHomClass F M N] (f : F) {a b : M} (h : a * b = 1) :
f a * f b = 1 := by
rw [← map_mul, h, map_one]
variable [FunLike F G H]
@[to_additive]
theorem map_div' [DivInvMonoid G] [DivInvMonoid H] [MulHomClass F G H]
(f : F) (hf : ∀ a, f a⁻¹ = (f a)⁻¹) (a b : G) : f (a / b) = f a / f b := by
grind [div_eq_mul_inv]
@[to_additive]
lemma map_comp_div' [DivInvMonoid G] [DivInvMonoid H] [MulHomClass F G H] (f : F)
(hf : ∀ a, f a⁻¹ = (f a)⁻¹) (g h : ι → G) : f ∘ (g / h) = f ∘ g / f ∘ h := by
ext; simp [map_div' f hf]
/-- Group homomorphisms preserve inverse.
See note [hom simp lemma priority] -/
@[to_additive (attr := simp mid, grind =) /-- Additive group homomorphisms preserve negation. -/]
theorem map_inv [Group G] [DivisionMonoid H] [MonoidHomClass F G H]
(f : F) (a : G) : f a⁻¹ = (f a)⁻¹ :=
eq_inv_of_mul_eq_one_left <| map_mul_eq_one f <| inv_mul_cancel _
@[to_additive (attr := simp)]
lemma map_comp_inv [Group G] [DivisionMonoid H] [MonoidHomClass F G H] (f : F) (g : ι → G) :
f ∘ g⁻¹ = (f ∘ g)⁻¹ := by ext; simp
/-- Group homomorphisms preserve division. -/
@[to_additive /-- Additive group homomorphisms preserve subtraction. -/]
theorem map_mul_inv [Group G] [DivisionMonoid H] [MonoidHomClass F G H] (f : F) (a b : G) :
f (a * b⁻¹) = f a * (f b)⁻¹ := by rw [map_mul, map_inv]
@[to_additive]
lemma map_comp_mul_inv [Group G] [DivisionMonoid H] [MonoidHomClass F G H] (f : F) (g h : ι → G) :
f ∘ (g * h⁻¹) = f ∘ g * (f ∘ h)⁻¹ := by simp
/-- Group homomorphisms preserve division.
See note [hom simp lemma priority] -/
@[to_additive (attr := simp mid, grind =) /-- Additive group homomorphisms preserve subtraction. -/]
theorem map_div [Group G] [DivisionMonoid H] [MonoidHomClass F G H] (f : F) :
∀ a b, f (a / b) = f a / f b := map_div' _ <| map_inv f
@[to_additive (attr := simp)]
lemma map_comp_div [Group G] [DivisionMonoid H] [MonoidHomClass F G H] (f : F) (g h : ι → G) :
f ∘ (g / h) = f ∘ g / f ∘ h := by ext; simp
/-- See note [hom simp lemma priority] -/
@[to_additive (attr := simp mid, grind =) (reorder := 9 10)]
theorem map_pow [Monoid G] [Monoid H] [MonoidHomClass F G H] (f : F) (a : G) :
∀ n : ℕ, f (a ^ n) = f a ^ n
| 0 => by rw [pow_zero, pow_zero, map_one]
| n + 1 => by rw [pow_succ, pow_succ, map_mul, map_pow f a n]
@[to_additive (attr := simp)]
lemma map_comp_pow [Monoid G] [Monoid H] [MonoidHomClass F G H] (f : F) (g : ι → G) (n : ℕ) :
f ∘ (g ^ n) = f ∘ g ^ n := by ext; simp
@[to_additive]
theorem map_zpow' [DivInvMonoid G] [DivInvMonoid H] [MonoidHomClass F G H]
(f : F) (hf : ∀ x : G, f x⁻¹ = (f x)⁻¹) (a : G) : ∀ n : ℤ, f (a ^ n) = f a ^ n
| (n : ℕ) => by rw [zpow_natCast, map_pow, zpow_natCast]
| Int.negSucc n => by rw [zpow_negSucc, hf, map_pow, ← zpow_negSucc]
@[to_additive (attr := simp)]
lemma map_comp_zpow' [DivInvMonoid G] [DivInvMonoid H] [MonoidHomClass F G H] (f : F)
(hf : ∀ x : G, f x⁻¹ = (f x)⁻¹) (g : ι → G) (n : ℤ) : f ∘ (g ^ n) = f ∘ g ^ n := by
ext; simp [map_zpow' f hf]
/-- Group homomorphisms preserve integer power.
See note [hom simp lemma priority] -/
@[to_additive (attr := simp mid, grind =) (reorder := 9 10)
/-- Additive group homomorphisms preserve integer scaling. -/]
theorem map_zpow [Group G] [DivisionMonoid H] [MonoidHomClass F G H]
(f : F) (g : G) (n : ℤ) : f (g ^ n) = f g ^ n := map_zpow' f (map_inv f) g n
@[to_additive]
lemma map_comp_zpow [Group G] [DivisionMonoid H] [MonoidHomClass F G H] (f : F) (g : ι → G)
(n : ℤ) : f ∘ (g ^ n) = f ∘ g ^ n := by simp
end mul_one
/-- If the codomain of an injective monoid homomorphism is torsion free,
then so is the domain. -/
@[to_additive /-- If the codomain of an injective additive monoid homomorphism is torsion free,
then so is the domain. -/]
theorem Function.Injective.isMulTorsionFree [Monoid M] [Monoid N] [IsMulTorsionFree N]
(f : M →* N) (hf : Function.Injective f) : IsMulTorsionFree M where
pow_left_injective n hn x y hxy := hf <| IsMulTorsionFree.pow_left_injective hn <| by
simpa using congrArg f hxy
-- completely uninteresting lemmas about coercion to function, that all homs need
section Coes
/-! Bundled morphisms can be down-cast to weaker bundlings -/
attribute [coe] MonoidHom.toOneHom
attribute [coe] AddMonoidHom.toZeroHom
/-- `MonoidHom` down-cast to a `OneHom`, forgetting the multiplicative property. -/
@[to_additive /-- `AddMonoidHom` down-cast to a `ZeroHom`, forgetting the additive property -/]
instance MonoidHom.coeToOneHom [MulOne M] [MulOne N] : Coe (M →* N) (OneHom M N) :=
⟨MonoidHom.toOneHom⟩
attribute [coe] MonoidHom.toMulHom
attribute [coe] AddMonoidHom.toAddHom
/-- `MonoidHom` down-cast to a `MulHom`, forgetting the 1-preserving property. -/
@[to_additive /-- `AddMonoidHom` down-cast to an `AddHom`, forgetting the 0-preserving property. -/]
instance MonoidHom.coeToMulHom [MulOne M] [MulOne N] : Coe (M →* N) (M →ₙ* N) :=
⟨MonoidHom.toMulHom⟩
-- these must come after the coe_toFun definitions
initialize_simps_projections ZeroHom (toFun → apply)
initialize_simps_projections AddHom (toFun → apply)
initialize_simps_projections AddMonoidHom (toFun → apply)
initialize_simps_projections OneHom (toFun → apply)
initialize_simps_projections MulHom (toFun → apply)
initialize_simps_projections MonoidHom (toFun → apply)
@[to_additive (attr := simp)]
theorem OneHom.coe_mk [One M] [One N] (f : M → N) (h1) : (OneHom.mk f h1 : M → N) = f := rfl
@[to_additive (attr := simp)]
theorem OneHom.toFun_eq_coe [One M] [One N] (f : OneHom M N) : f.toFun = f := rfl
@[to_additive (attr := simp)]
theorem MulHom.coe_mk [Mul M] [Mul N] (f : M → N) (hmul) : (MulHom.mk f hmul : M → N) = f := rfl
@[to_additive (attr := simp)]
theorem MulHom.toFun_eq_coe [Mul M] [Mul N] (f : M →ₙ* N) : f.toFun = f := rfl
@[to_additive (attr := simp)]
theorem MonoidHom.coe_mk [MulOne M] [MulOne N] (f hmul) :
(MonoidHom.mk f hmul : M → N) = f := rfl
@[to_additive (attr := simp)]
theorem MonoidHom.toOneHom_coe [MulOne M] [MulOne N] (f : M →* N) :
(f.toOneHom : M → N) = f := rfl
@[to_additive (attr := simp)]
theorem MonoidHom.toMulHom_coe [MulOne M] [MulOne N] (f : M →* N) :
f.toMulHom.toFun = f := rfl
@[to_additive]
theorem MonoidHom.toFun_eq_coe [MulOne M] [MulOne N] (f : M →* N) : f.toFun = f := rfl
@[to_additive (attr := ext)]
theorem OneHom.ext [One M] [One N] ⦃f g : OneHom M N⦄ (h : ∀ x, f x = g x) : f = g :=
DFunLike.ext _ _ h
@[to_additive (attr := ext)]
theorem MulHom.ext [Mul M] [Mul N] ⦃f g : M →ₙ* N⦄ (h : ∀ x, f x = g x) : f = g :=
DFunLike.ext _ _ h
@[to_additive (attr := ext)]
theorem MonoidHom.ext [MulOne M] [MulOne N] ⦃f g : M →* N⦄ (h : ∀ x, f x = g x) : f = g :=
DFunLike.ext _ _ h
namespace MonoidHom
variable [Group G]
variable [MulOneClass M]
/-- Makes a group homomorphism from a proof that the map preserves multiplication. -/
@[to_additive (attr := simps -fullyApplied)
/-- Makes an additive group homomorphism from a proof that the map preserves addition. -/]
def mk' (f : M → G) (map_mul : ∀ a b : M, f (a * b) = f a * f b) : M →* G where
toFun := f
map_mul' := map_mul
map_one' := by rw [← mul_right_cancel_iff, ← map_mul _ 1, one_mul, one_mul]
end MonoidHom
@[to_additive (attr := simp)]
theorem OneHom.mk_coe [One M] [One N] (f : OneHom M N) (h1) : OneHom.mk f h1 = f :=
OneHom.ext fun _ => rfl
@[to_additive (attr := simp)]
theorem MulHom.mk_coe [Mul M] [Mul N] (f : M →ₙ* N) (hmul) : MulHom.mk f hmul = f :=
MulHom.ext fun _ => rfl
@[to_additive (attr := simp)]
theorem MonoidHom.mk_coe [MulOne M] [MulOne N] (f : M →* N) (hmul) :
MonoidHom.mk f hmul = f := MonoidHom.ext fun _ => rfl
end Coes
/-- Copy of a `OneHom` with a new `toFun` equal to the old one. Useful to fix definitional
equalities. -/
@[to_additive
/-- Copy of a `ZeroHom` with a new `toFun` equal to the old one. Useful to fix
definitional equalities. -/]
protected def OneHom.copy [One M] [One N] (f : OneHom M N) (f' : M → N) (h : f' = f) :
OneHom M N where
toFun := f'
map_one' := h.symm ▸ f.map_one'
@[to_additive (attr := simp)]
theorem OneHom.coe_copy {_ : One M} {_ : One N} (f : OneHom M N) (f' : M → N) (h : f' = f) :
(f.copy f' h) = f' :=
rfl
@[to_additive]
theorem OneHom.coe_copy_eq {_ : One M} {_ : One N} (f : OneHom M N) (f' : M → N) (h : f' = f) :
f.copy f' h = f :=
DFunLike.ext' h
/-- Copy of a `MulHom` with a new `toFun` equal to the old one. Useful to fix definitional
equalities. -/
@[to_additive
/-- Copy of an `AddHom` with a new `toFun` equal to the old one. Useful to fix
definitional equalities. -/]
protected def MulHom.copy [Mul M] [Mul N] (f : M →ₙ* N) (f' : M → N) (h : f' = f) :
M →ₙ* N where
toFun := f'
map_mul' := h.symm ▸ f.map_mul'
@[to_additive (attr := simp)]
theorem MulHom.coe_copy {_ : Mul M} {_ : Mul N} (f : M →ₙ* N) (f' : M → N) (h : f' = f) :
(f.copy f' h) = f' :=
rfl
@[to_additive]
theorem MulHom.coe_copy_eq {_ : Mul M} {_ : Mul N} (f : M →ₙ* N) (f' : M → N) (h : f' = f) :
f.copy f' h = f :=
DFunLike.ext' h
/-- Copy of a `MonoidHom` with a new `toFun` equal to the old one. Useful to fix
definitional equalities. -/
@[to_additive
/-- Copy of an `AddMonoidHom` with a new `toFun` equal to the old one. Useful to fix
definitional equalities. -/]
protected def MonoidHom.copy [MulOne M] [MulOne N] (f : M →* N) (f' : M → N)
(h : f' = f) : M →* N :=
{ f.toOneHom.copy f' h, f.toMulHom.copy f' h with }
@[to_additive (attr := simp)]
theorem MonoidHom.coe_copy {_ : MulOne M} {_ : MulOne N} (f : M →* N) (f' : M → N)
(h : f' = f) : (f.copy f' h) = f' :=
rfl
@[to_additive]
theorem MonoidHom.copy_eq {_ : MulOne M} {_ : MulOne N} (f : M →* N) (f' : M → N)
(h : f' = f) : f.copy f' h = f :=
DFunLike.ext' h
@[to_additive]
protected theorem OneHom.map_one [One M] [One N] (f : OneHom M N) : f 1 = 1 :=
f.map_one'
/-- If `f` is a monoid homomorphism then `f 1 = 1`. -/
@[to_additive /-- If `f` is an additive monoid homomorphism then `f 0 = 0`. -/]
protected theorem MonoidHom.map_one [MulOne M] [MulOne N] (f : M →* N) : f 1 = 1 :=
f.map_one'
@[to_additive]
protected theorem MulHom.map_mul [Mul M] [Mul N] (f : M →ₙ* N) (a b : M) : f (a * b) = f a * f b :=
f.map_mul' a b
/-- If `f` is a monoid homomorphism then `f (a * b) = f a * f b`. -/
@[to_additive /-- If `f` is an additive monoid homomorphism then `f (a + b) = f a + f b`. -/]
protected theorem MonoidHom.map_mul [MulOne M] [MulOne N] (f : M →* N) (a b : M) :
f (a * b) = f a * f b := f.map_mul' a b
namespace MonoidHom
variable [MulOne M] [MulOne N] [FunLike F M N] [MonoidHomClass F M N]
/-- Given a monoid homomorphism `f : M →* N` and an element `x : M`, if `x` has a right inverse,
then `f x` has a right inverse too. For elements invertible on both sides see `IsUnit.map`. -/
@[to_additive
/-- Given an AddMonoid homomorphism `f : M →+ N` and an element `x : M`, if `x` has
a right inverse, then `f x` has a right inverse too. -/]
theorem map_exists_right_inv (f : F) {x : M} (hx : ∃ y, x * y = 1) : ∃ y, f x * y = 1 :=
let ⟨y, hy⟩ := hx
⟨f y, map_mul_eq_one f hy⟩
/-- Given a monoid homomorphism `f : M →* N` and an element `x : M`, if `x` has a left inverse,
then `f x` has a left inverse too. For elements invertible on both sides see `IsUnit.map`. -/
@[to_additive
/-- Given an AddMonoid homomorphism `f : M →+ N` and an element `x : M`, if `x` has
a left inverse, then `f x` has a left inverse too. For elements invertible on both sides see
`IsAddUnit.map`. -/]
theorem map_exists_left_inv (f : F) {x : M} (hx : ∃ y, y * x = 1) : ∃ y, y * f x = 1 :=
let ⟨y, hy⟩ := hx
⟨f y, map_mul_eq_one f hy⟩
end MonoidHom
/-- The identity map from a type with 1 to itself. -/
@[to_additive (attr := simps) /-- The identity map from a type with zero to itself. -/]
def OneHom.id (M : Type*) [One M] : OneHom M M where
toFun x := x
map_one' := rfl
/-- The identity map from a type with multiplication to itself. -/
@[to_additive (attr := simps) /-- The identity map from a type with addition to itself. -/]
def MulHom.id (M : Type*) [Mul M] : M →ₙ* M where
toFun x := x
map_mul' _ _ := rfl
/-- The identity map from a monoid to itself. -/
@[to_additive (attr := simps) /-- The identity map from an additive monoid to itself. -/]
def MonoidHom.id (M : Type*) [MulOne M] : M →* M where
toFun x := x
map_one' := rfl
map_mul' _ _ := rfl
@[to_additive (attr := simp)]
lemma OneHom.coe_id {M : Type*} [One M] : (OneHom.id M : M → M) = _root_.id := rfl
@[to_additive (attr := simp)]
lemma MulHom.coe_id {M : Type*} [Mul M] : (MulHom.id M : M → M) = _root_.id := rfl
@[to_additive (attr := simp)]
lemma MonoidHom.coe_id {M : Type*} [MulOne M] : (MonoidHom.id M : M → M) = _root_.id := rfl
/-- Composition of `OneHom`s as a `OneHom`. -/
@[to_additive /-- Composition of `ZeroHom`s as a `ZeroHom`. -/]
def OneHom.comp [One M] [One N] [One P] (hnp : OneHom N P) (hmn : OneHom M N) : OneHom M P where
toFun := hnp ∘ hmn
map_one' := by simp
/-- Composition of `MulHom`s as a `MulHom`. -/
@[to_additive /-- Composition of `AddHom`s as an `AddHom`. -/]
def MulHom.comp [Mul M] [Mul N] [Mul P] (hnp : N →ₙ* P) (hmn : M →ₙ* N) : M →ₙ* P where
toFun := hnp ∘ hmn
map_mul' x y := by simp
/-- Composition of monoid morphisms as a monoid morphism. -/
@[to_additive /-- Composition of additive monoid morphisms as an additive monoid morphism. -/]
def MonoidHom.comp [MulOne M] [MulOne N] [MulOne P] (hnp : N →* P) (hmn : M →* N) :
M →* P where
toFun := hnp ∘ hmn
map_one' := by simp
map_mul' := by simp
@[to_additive (attr := simp)]
theorem OneHom.coe_comp [One M] [One N] [One P] (g : OneHom N P) (f : OneHom M N) :
↑(g.comp f) = g ∘ f := rfl
@[to_additive (attr := simp)]
theorem MulHom.coe_comp [Mul M] [Mul N] [Mul P] (g : N →ₙ* P) (f : M →ₙ* N) :
↑(g.comp f) = g ∘ f := rfl
@[to_additive (attr := simp)]
theorem MonoidHom.coe_comp [MulOne M] [MulOne N] [MulOne P]
(g : N →* P) (f : M →* N) : ↑(g.comp f) = g ∘ f := rfl
@[to_additive]
theorem OneHom.comp_apply [One M] [One N] [One P] (g : OneHom N P) (f : OneHom M N) (x : M) :
g.comp f x = g (f x) := rfl
@[to_additive]
theorem MulHom.comp_apply [Mul M] [Mul N] [Mul P] (g : N →ₙ* P) (f : M →ₙ* N) (x : M) :
g.comp f x = g (f x) := rfl
@[to_additive]
theorem MonoidHom.comp_apply [MulOne M] [MulOne N] [MulOne P]
(g : N →* P) (f : M →* N) (x : M) : g.comp f x = g (f x) := rfl
/-- Composition of monoid homomorphisms is associative. -/
@[to_additive /-- Composition of additive monoid homomorphisms is associative. -/]
theorem OneHom.comp_assoc {Q : Type*} [One M] [One N] [One P] [One Q]
(f : OneHom M N) (g : OneHom N P) (h : OneHom P Q) :
(h.comp g).comp f = h.comp (g.comp f) := rfl
@[to_additive]
theorem MulHom.comp_assoc {Q : Type*} [Mul M] [Mul N] [Mul P] [Mul Q]
(f : M →ₙ* N) (g : N →ₙ* P) (h : P →ₙ* Q) : (h.comp g).comp f = h.comp (g.comp f) := rfl
@[to_additive]
theorem MonoidHom.comp_assoc {Q : Type*} [MulOne M] [MulOne N] [MulOne P]
[MulOne Q] (f : M →* N) (g : N →* P) (h : P →* Q) :
(h.comp g).comp f = h.comp (g.comp f) := rfl
@[to_additive]
theorem OneHom.cancel_right [One M] [One N] [One P] {g₁ g₂ : OneHom N P} {f : OneHom M N}
(hf : Function.Surjective f) : g₁.comp f = g₂.comp f ↔ g₁ = g₂ :=
⟨fun h => OneHom.ext <| hf.forall.2 (DFunLike.ext_iff.1 h), fun h => h ▸ rfl⟩
@[to_additive]
theorem MulHom.cancel_right [Mul M] [Mul N] [Mul P] {g₁ g₂ : N →ₙ* P} {f : M →ₙ* N}
(hf : Function.Surjective f) : g₁.comp f = g₂.comp f ↔ g₁ = g₂ :=
⟨fun h => MulHom.ext <| hf.forall.2 (DFunLike.ext_iff.1 h), fun h => h ▸ rfl⟩
@[to_additive]
theorem MonoidHom.cancel_right [MulOne M] [MulOne N] [MulOne P]
{g₁ g₂ : N →* P} {f : M →* N} (hf : Function.Surjective f) :
g₁.comp f = g₂.comp f ↔ g₁ = g₂ :=
⟨fun h => MonoidHom.ext <| hf.forall.2 (DFunLike.ext_iff.1 h), fun h => h ▸ rfl⟩
@[to_additive]
theorem OneHom.cancel_left [One M] [One N] [One P] {g : OneHom N P} {f₁ f₂ : OneHom M N}
(hg : Function.Injective g) : g.comp f₁ = g.comp f₂ ↔ f₁ = f₂ :=
⟨fun h => OneHom.ext fun x => hg <| by rw [← OneHom.comp_apply, h, OneHom.comp_apply],
fun h => h ▸ rfl⟩
@[to_additive]
theorem MulHom.cancel_left [Mul M] [Mul N] [Mul P] {g : N →ₙ* P} {f₁ f₂ : M →ₙ* N}
(hg : Function.Injective g) : g.comp f₁ = g.comp f₂ ↔ f₁ = f₂ :=
⟨fun h => MulHom.ext fun x => hg <| by rw [← MulHom.comp_apply, h, MulHom.comp_apply],
fun h => h ▸ rfl⟩
@[to_additive]
theorem MonoidHom.cancel_left [MulOne M] [MulOne N] [MulOne P]
{g : N →* P} {f₁ f₂ : M →* N} (hg : Function.Injective g) : g.comp f₁ = g.comp f₂ ↔ f₁ = f₂ :=
⟨fun h => MonoidHom.ext fun x => hg <| by rw [← MonoidHom.comp_apply, h, MonoidHom.comp_apply],
fun h => h ▸ rfl⟩
section
@[to_additive]
theorem MonoidHom.toOneHom_injective [MulOne M] [MulOne N] :
Function.Injective (MonoidHom.toOneHom : (M →* N) → OneHom M N) :=
Function.Injective.of_comp (f := DFunLike.coe) DFunLike.coe_injective
@[to_additive]
theorem MonoidHom.toMulHom_injective [MulOne M] [MulOne N] :
Function.Injective (MonoidHom.toMulHom : (M →* N) → M →ₙ* N) :=
Function.Injective.of_comp (f := DFunLike.coe) DFunLike.coe_injective
end
@[to_additive (attr := simp)]
theorem OneHom.comp_id [One M] [One N] (f : OneHom M N) : f.comp (OneHom.id M) = f :=
OneHom.ext fun _ => rfl
@[to_additive (attr := simp)]
theorem MulHom.comp_id [Mul M] [Mul N] (f : M →ₙ* N) : f.comp (MulHom.id M) = f :=
MulHom.ext fun _ => rfl
@[to_additive (attr := simp)]
theorem MonoidHom.comp_id [MulOne M] [MulOne N] (f : M →* N) :
f.comp (MonoidHom.id M) = f := MonoidHom.ext fun _ => rfl
@[to_additive (attr := simp)]
theorem OneHom.id_comp [One M] [One N] (f : OneHom M N) : (OneHom.id N).comp f = f :=
OneHom.ext fun _ => rfl
@[to_additive (attr := simp)]
theorem MulHom.id_comp [Mul M] [Mul N] (f : M →ₙ* N) : (MulHom.id N).comp f = f :=
MulHom.ext fun _ => rfl
@[to_additive (attr := simp)]
theorem MonoidHom.id_comp [MulOne M] [MulOne N] (f : M →* N) :
(MonoidHom.id N).comp f = f := MonoidHom.ext fun _ => rfl
@[to_additive]
protected theorem MonoidHom.map_pow [Monoid M] [Monoid N] (f : M →* N) (a : M) (n : ℕ) :
f (a ^ n) = f a ^ n := map_pow f a n
@[to_additive]
protected theorem MonoidHom.map_zpow' [DivInvMonoid M] [DivInvMonoid N] (f : M →* N)
(hf : ∀ x, f x⁻¹ = (f x)⁻¹) (a : M) (n : ℤ) :
f (a ^ n) = f a ^ n := map_zpow' f hf a n
/-- Makes a `OneHom` inverse from the bijective inverse of a `OneHom` -/
@[to_additive (attr := simps)
/-- Make a `ZeroHom` inverse from the bijective inverse of a `ZeroHom` -/]
def OneHom.inverse [One M] [One N] (f : OneHom M N) (g : N → M) (h₁ : Function.LeftInverse g f) :
OneHom N M :=
{ toFun := g,
map_one' := by rw [← f.map_one, h₁] }
/-- Makes a multiplicative inverse from a bijection which preserves multiplication. -/
@[to_additive (attr := simps)
/-- Makes an additive inverse from a bijection which preserves addition. -/]
def MulHom.inverse [Mul M] [Mul N] (f : M →ₙ* N) (g : N → M)
(h₁ : Function.LeftInverse g f)
(h₂ : Function.RightInverse g f) : N →ₙ* M where
toFun := g
map_mul' x y :=
calc
g (x * y) = g (f (g x) * f (g y)) := by rw [h₂ x, h₂ y]
_ = g (f (g x * g y)) := by rw [f.map_mul]
_ = g x * g y := h₁ _
/-- If `M` and `N` have multiplications, `f : M →ₙ* N` is a surjective multiplicative map,
and `M` is commutative, then `N` is commutative. -/
@[to_additive
/-- If `M` and `N` have additions, `f : M →ₙ+ N` is a surjective additive map,
and `M` is commutative, then `N` is commutative. -/]
theorem Function.Surjective.mul_comm [Mul M] [Mul N] {f : M →ₙ* N}
(is_surj : Function.Surjective f) (is_comm : Std.Commutative (· * · : M → M → M)) :
Std.Commutative (· * · : N → N → N) where
comm := fun a b ↦ by
obtain ⟨a', ha'⟩ := is_surj a
obtain ⟨b', hb'⟩ := is_surj b
simp only [← ha', ← hb', ← map_mul]
rw [is_comm.comm]
/-- The inverse of a bijective `MonoidHom` is a `MonoidHom`. -/
@[to_additive (attr := simps)
/-- The inverse of a bijective `AddMonoidHom` is an `AddMonoidHom`. -/]
def MonoidHom.inverse {A B : Type*} [Monoid A] [Monoid B] (f : A →* B) (g : B → A)
(h₁ : Function.LeftInverse g f) (h₂ : Function.RightInverse g f) : B →* A :=
{ (f : OneHom A B).inverse g h₁,
(f : A →ₙ* B).inverse g h₁ h₂ with toFun := g }
section End
namespace Monoid
variable (M) [MulOne M]
/-- The monoid of endomorphisms. -/
@[to_additive /-- The monoid of endomorphisms. -/, to_additive_dont_translate]
protected def End := M →* M
namespace End
@[to_additive]
instance instFunLike : FunLike (Monoid.End M) M M := MonoidHom.instFunLike
@[to_additive]
instance instMonoidHomClass : MonoidHomClass (Monoid.End M) M M := MonoidHom.instMonoidHomClass
@[to_additive instOne]
instance instOne : One (Monoid.End M) where one := .id _
@[to_additive instMul]
instance instMul : Mul (Monoid.End M) where mul := .comp
@[to_additive instMonoid]
instance instMonoid : Monoid (Monoid.End M) where
mul := MonoidHom.comp
one := MonoidHom.id M
mul_assoc _ _ _ := MonoidHom.comp_assoc _ _ _
mul_one := MonoidHom.comp_id
one_mul := MonoidHom.id_comp
npow n f := (npowRec n f).copy f^[n] <| by induction n <;> simp [npowRec, *] <;> rfl
npow_succ _ _ := DFunLike.coe_injective <| Function.iterate_succ _ _
@[to_additive]
instance : Inhabited (Monoid.End M) := ⟨1⟩
@[to_additive (attr := simp, norm_cast) coe_pow]
lemma coe_pow (f : Monoid.End M) (n : ℕ) : (↑(f ^ n) : M → M) = f^[n] := rfl
@[to_additive (attr := simp) coe_one]
theorem coe_one : ((1 : Monoid.End M) : M → M) = id := rfl
@[to_additive (attr := simp) coe_mul]
theorem coe_mul (f g) : ((f * g : Monoid.End M) : M → M) = f ∘ g := rfl
end End
end Monoid
end End
/-- `1` is the homomorphism sending all elements to `1`. -/
@[to_additive /-- `0` is the homomorphism sending all elements to `0`. -/]
instance [One M] [One N] : One (OneHom M N) := ⟨⟨fun _ => 1, rfl⟩⟩
/-- `1` is the multiplicative homomorphism sending all elements to `1`. -/
@[to_additive /-- `0` is the additive homomorphism sending all elements to `0` -/]
instance [Mul M] [MulOneClass N] : One (M →ₙ* N) :=
⟨⟨fun _ => 1, fun _ _ => (one_mul 1).symm⟩⟩
/-- `1` is the monoid homomorphism sending all elements to `1`. -/
@[to_additive /-- `0` is the additive monoid homomorphism sending all elements to `0`. -/]
instance [MulOne M] [MulOneClass N] : One (M →* N) :=
⟨⟨⟨fun _ => 1, rfl⟩, fun _ _ => (one_mul 1).symm⟩⟩
@[to_additive (attr := simp)]
theorem OneHom.one_apply [One M] [One N] (x : M) : (1 : OneHom M N) x = 1 := rfl
@[to_additive (attr := simp)]
theorem MonoidHom.one_apply [MulOne M] [MulOneClass N] (x : M) : (1 : M →* N) x = 1 := rfl
@[to_additive (attr := simp)]
theorem OneHom.one_comp [One M] [One N] [One P] (f : OneHom M N) :
(1 : OneHom N P).comp f = 1 := rfl
@[to_additive (attr := simp)]
theorem OneHom.comp_one [One M] [One N] [One P] (f : OneHom N P) : f.comp (1 : OneHom M N) = 1 := by
ext
simp only [OneHom.map_one, OneHom.coe_comp, Function.comp_apply, OneHom.one_apply]
@[to_additive]
instance [One M] [One N] : Inhabited (OneHom M N) := ⟨1⟩
@[to_additive]
instance [Mul M] [MulOneClass N] : Inhabited (M →ₙ* N) := ⟨1⟩
@[to_additive]
instance [MulOne M] [MulOneClass N] : Inhabited (M →* N) := ⟨1⟩
namespace MonoidHom
@[to_additive (attr := simp)]
theorem one_comp [MulOne M] [MulOne N] [MulOneClass P] (f : M →* N) :
(1 : N →* P).comp f = 1 := rfl
@[to_additive (attr := simp)]
theorem comp_one [MulOne M] [MulOneClass N] [MulOneClass P] (f : N →* P) :
f.comp (1 : M →* N) = 1 := by
ext
simp only [map_one, coe_comp, Function.comp_apply, one_apply]
/-- Group homomorphisms preserve inverse. -/
@[to_additive /-- Additive group homomorphisms preserve negation. -/]
protected theorem map_inv [Group α] [DivisionMonoid β] (f : α →* β) (a : α) : f a⁻¹ = (f a)⁻¹ :=
map_inv f _
/-- Group homomorphisms preserve integer power. -/
@[to_additive /-- Additive group homomorphisms preserve integer scaling. -/]
protected theorem map_zpow [Group α] [DivisionMonoid β] (f : α →* β) (g : α) (n : ℤ) :
f (g ^ n) = f g ^ n := map_zpow f g n
/-- Group homomorphisms preserve division. -/
@[to_additive /-- Additive group homomorphisms preserve subtraction. -/]
protected theorem map_div [Group α] [DivisionMonoid β] (f : α →* β) (g h : α) :
f (g / h) = f g / f h := map_div f g h
/-- Group homomorphisms preserve division. -/
@[to_additive /-- Additive group homomorphisms preserve subtraction. -/]
protected theorem map_mul_inv [Group α] [DivisionMonoid β] (f : α →* β) (g h : α) :
f (g * h⁻¹) = f g * (f h)⁻¹ := by simp
end MonoidHom
@[to_additive (attr := simp)]
lemma iterate_map_mul {M F : Type*} [Mul M] [FunLike F M M] [MulHomClass F M M]
(f : F) (n : ℕ) (x y : M) :
f^[n] (x * y) = f^[n] x * f^[n] y :=
Function.Semiconj₂.iterate (map_mul f) n x y
@[to_additive (attr := simp)]
lemma iterate_map_one {M F : Type*} [One M] [FunLike F M M] [OneHomClass F M M]
(f : F) (n : ℕ) :
f^[n] 1 = 1 :=
iterate_fixed (map_one f) n
@[to_additive (attr := simp)]
lemma iterate_map_inv {M F : Type*} [Group M] [FunLike F M M] [MonoidHomClass F M M]
(f : F) (n : ℕ) (x : M) :
f^[n] x⁻¹ = (f^[n] x)⁻¹ :=
Commute.iterate_left (map_inv f) n x
@[to_additive (attr := simp)]
lemma iterate_map_div {M F : Type*} [Group M] [FunLike F M M] [MonoidHomClass F M M]
(f : F) (n : ℕ) (x y : M) :
f^[n] (x / y) = f^[n] x / f^[n] y :=
Semiconj₂.iterate (map_div f) n x y
@[to_additive (attr := simp)]
lemma iterate_map_pow {M F : Type*} [Monoid M] [FunLike F M M] [MonoidHomClass F M M]
(f : F) (n : ℕ) (x : M) (k : ℕ) :
f^[n] (x ^ k) = f^[n] x ^ k :=
Commute.iterate_left (map_pow f · k) n x
@[to_additive (attr := simp)]
lemma iterate_map_zpow {M F : Type*} [Group M] [FunLike F M M] [MonoidHomClass F M M]
(f : F) (n : ℕ) (x : M) (k : ℤ) :
f^[n] (x ^ k) = f^[n] x ^ k :=
Commute.iterate_left (map_zpow f · k) n x |
.lake/packages/mathlib/Mathlib/Algebra/Group/Hom/CompTypeclasses.lean | import Mathlib.Logic.Function.CompTypeclasses
import Mathlib.Algebra.Group.Hom.Defs
/-!
# Propositional typeclasses on several monoid homs
This file contains typeclasses used in the definition of equivariant maps,
in the spirit what was initially developed by Frédéric Dupuis and Heather Macbeth for linear maps.
However, we do not expect that all maps should be guessed automatically,
as it happens for linear maps.
If `φ`, `ψ`… are monoid homs and `M`, `N`… are monoids, we add two instances:
* `MonoidHom.CompTriple φ ψ χ`, which expresses that `ψ.comp φ = χ`
* `MonoidHom.IsId φ`, which expresses that `φ = id`
Some basic lemmas are proved:
* `MonoidHom.CompTriple.comp` asserts `MonoidHom.CompTriple φ ψ (ψ.comp φ)`
* `MonoidHom.CompTriple.id_comp` asserts `MonoidHom.CompTriple φ ψ ψ`
in the presence of `MonoidHom.IsId φ`
* its variant `MonoidHom.CompTriple.comp_id`
TODO :
* align with RingHomCompTriple
* probably rename MonoidHom.CompTriple as MonoidHomCompTriple
(or, on the opposite, rename RingHomCompTriple as RingHom.CompTriple)
* does one need AddHom.CompTriple ?
-/
section MonoidHomCompTriple
namespace MonoidHom
/-- Class of composing triples -/
class CompTriple {M N P : Type*} [Monoid M] [Monoid N] [Monoid P]
(φ : M →* N) (ψ : N →* P) (χ : outParam (M →* P)) : Prop where
/-- The maps form a commuting triangle -/
comp_eq : ψ.comp φ = χ
attribute [simp] CompTriple.comp_eq
namespace CompTriple
variable {M N P : Type*} [Monoid M] [Monoid N] [Monoid P]
/-- Class of Id maps -/
class IsId (σ : M →* M) : Prop where
eq_id : σ = MonoidHom.id M
instance instIsId {M : Type*} [Monoid M] : IsId (MonoidHom.id M) where
eq_id := rfl
instance {σ : M →* M} [h : _root_.CompTriple.IsId σ] : IsId σ where
eq_id := by ext; exact congr_fun h.eq_id _
instance instComp_id {N P : Type*} [Monoid N] [Monoid P]
{φ : N →* N} [IsId φ] {ψ : N →* P} :
CompTriple φ ψ ψ where
comp_eq := by simp only [IsId.eq_id, MonoidHom.comp_id]
instance instId_comp {M N : Type*} [Monoid M] [Monoid N]
{φ : M →* N} {ψ : N →* N} [IsId ψ] :
CompTriple φ ψ φ where
comp_eq := by simp only [IsId.eq_id, MonoidHom.id_comp]
lemma comp_inv {φ : M →* N} {ψ : N →* M} (h : Function.RightInverse φ ψ)
{χ : M →* M} [IsId χ] :
CompTriple φ ψ χ where
comp_eq := by simp only [IsId.eq_id, ← DFunLike.coe_fn_eq, coe_comp, h.id, coe_id]
instance instRootCompTriple {φ : M →* N} {ψ : N →* P} {χ : M →* P} [κ : CompTriple φ ψ χ] :
_root_.CompTriple φ ψ χ where
comp_eq := by rw [← MonoidHom.coe_comp, κ.comp_eq]
/-- `φ`, `ψ` and `ψ.comp φ` form a `MonoidHom.CompTriple`
(to be used with care, because no simplification is done) -/
theorem comp {φ : M →* N} {ψ : N →* P} :
CompTriple φ ψ (ψ.comp φ) where
comp_eq := rfl
lemma comp_apply
{φ : M →* N} {ψ : N →* P} {χ : M →* P} (h : CompTriple φ ψ χ) (x : M) :
ψ (φ x) = χ x := by
rw [← h.comp_eq, MonoidHom.comp_apply]
theorem comp_assoc {Q : Type*} [Monoid Q]
{φ₁ : M →* N} {φ₂ : N →* P} {φ₁₂ : M →* P}
(κ : CompTriple φ₁ φ₂ φ₁₂)
{φ₃ : P →* Q} {φ₂₃ : N →* Q} (κ' : CompTriple φ₂ φ₃ φ₂₃)
{φ₁₂₃ : M →* Q} :
CompTriple φ₁ φ₂₃ φ₁₂₃ ↔ CompTriple φ₁₂ φ₃ φ₁₂₃ := by
constructor <;>
· rintro ⟨h⟩
exact ⟨by simp only [← κ.comp_eq, ← h, ← κ'.comp_eq, MonoidHom.comp_assoc]⟩
end MonoidHom.CompTriple
end MonoidHomCompTriple |
.lake/packages/mathlib/Mathlib/Algebra/Group/Irreducible/Lemmas.lean | import Mathlib.Algebra.Group.Commute.Units
import Mathlib.Algebra.Group.Even
import Mathlib.Algebra.Group.Irreducible.Defs
import Mathlib.Algebra.Group.Units.Equiv
/-!
# More lemmas about irreducible elements
-/
assert_not_exists MonoidWithZero IsOrderedMonoid Multiset
variable {F M N : Type*}
section Monoid
variable [Monoid M] [Monoid N] {f : F} {x y : M}
@[to_additive]
lemma not_irreducible_pow : ∀ {n : ℕ}, n ≠ 1 → ¬ Irreducible (x ^ n)
| 0, _ => by simp
| n + 2, _ => by
intro ⟨h₁, h₂⟩
have := h₂ (pow_succ _ _)
rw [isUnit_pow_iff n.succ_ne_zero, or_self] at this
exact h₁ (this.pow _)
@[to_additive]
lemma irreducible_units_mul (u : Mˣ) : Irreducible (u * y) ↔ Irreducible y := by
simp only [irreducible_iff, Units.isUnit_units_mul, and_congr_right_iff]
refine fun _ => ⟨fun h A B HAB => ?_, fun h A B HAB => ?_⟩
· rw [← u.isUnit_units_mul]
apply h
rw [mul_assoc, ← HAB]
· rw [← u⁻¹.isUnit_units_mul]
apply h
rw [mul_assoc, ← HAB, Units.inv_mul_cancel_left]
@[to_additive]
lemma irreducible_isUnit_mul (h : IsUnit x) : Irreducible (x * y) ↔ Irreducible y :=
let ⟨x, ha⟩ := h
ha ▸ irreducible_units_mul x
@[to_additive]
lemma irreducible_mul_units (u : Mˣ) : Irreducible (y * u) ↔ Irreducible y := by
simp only [irreducible_iff, Units.isUnit_mul_units, and_congr_right_iff]
refine fun _ => ⟨fun h A B HAB => ?_, fun h A B HAB => ?_⟩
· rw [← u.isUnit_mul_units B]
apply h
rw [← mul_assoc, ← HAB]
· rw [← u⁻¹.isUnit_mul_units B]
apply h
rw [← mul_assoc, ← HAB, Units.mul_inv_cancel_right]
@[to_additive]
lemma irreducible_mul_isUnit (h : IsUnit x) : Irreducible (y * x) ↔ Irreducible y :=
let ⟨x, hx⟩ := h
hx ▸ irreducible_mul_units x
@[to_additive]
lemma irreducible_mul_iff :
Irreducible (x * y) ↔ Irreducible x ∧ IsUnit y ∨ Irreducible y ∧ IsUnit x := by
constructor
· refine fun h => Or.imp (fun h' => ⟨?_, h'⟩) (fun h' => ⟨?_, h'⟩) (h.isUnit_or_isUnit rfl).symm
· rwa [irreducible_mul_isUnit h'] at h
· rwa [irreducible_isUnit_mul h'] at h
· rintro (⟨ha, hb⟩ | ⟨hb, ha⟩)
· rwa [irreducible_mul_isUnit hb]
· rwa [irreducible_isUnit_mul ha]
section MulEquivClass
variable [EquivLike F M N] [MulEquivClass F M N] (f : F)
@[to_additive]
lemma MulEquiv.irreducible_iff : Irreducible (f x) ↔ Irreducible x := by
simp [_root_.irreducible_iff, (EquivLike.surjective f).forall, ← map_mul, -isUnit_map_iff]
/-- Irreducibility is preserved by multiplicative equivalences.
Note that surjective + local hom is not enough. Consider the additive monoids `M = ℕ ⊕ ℕ`, `N = ℕ`,
with x surjective local (additive) hom `f : M →+ N` sending `(m, n)` to `2m + n`.
It is local because the only add unit in `N` is `0`, with preimage `{(0, 0)}` also an add unit.
Then `x = (1, 0)` is irreducible in `M`, but `f x = 2 = 1 + 1` is not irreducible in `N`. -/
@[to_additive /-- Irreducibility is preserved by additive equivalences. -/]
alias ⟨_, Irreducible.map⟩ := MulEquiv.irreducible_iff
end MulEquivClass
lemma Irreducible.of_map [FunLike F M N] [MonoidHomClass F M N] [IsLocalHom f]
(hfx : Irreducible (f x)) : Irreducible x where
not_isUnit hu := hfx.not_isUnit <| hu.map f
isUnit_or_isUnit := by
rintro p q rfl; exact (hfx.isUnit_or_isUnit <| map_mul f p q).imp (.of_map f _) (.of_map f _)
@[to_additive]
lemma Irreducible.not_isSquare (ha : Irreducible x) : ¬IsSquare x := by
rw [isSquare_iff_exists_sq]
rintro ⟨y, rfl⟩
exact not_irreducible_pow (by decide) ha
@[to_additive]
lemma IsSquare.not_irreducible (ha : IsSquare x) : ¬Irreducible x := fun h => h.not_isSquare ha
end Monoid |
.lake/packages/mathlib/Mathlib/Algebra/Group/Irreducible/Defs.lean | import Mathlib.Algebra.Group.Units.Defs
import Mathlib.Logic.Basic
/-!
# Irreducible elements in a monoid
This file defines irreducible elements of a monoid (`Irreducible`), as non-units that can't be
written as the product of two non-units. This generalises irreducible elements of a ring.
We also define the additive variant (`AddIrreducible`).
In decomposition monoids (e.g., `ℕ`, `ℤ`), this predicate is equivalent to `Prime`
(see `irreducible_iff_prime`), however this is not true in general.
-/
assert_not_exists MonoidWithZero IsOrderedMonoid Multiset
variable {M : Type*}
/-- `AddIrreducible p` states that `p` is not an additive unit and cannot be written as a sum of
additive non-units. -/
structure AddIrreducible [AddMonoid M] (p : M) : Prop where
/-- An irreducible element is not an additive unit. -/
not_isAddUnit : ¬IsAddUnit p
/-- If an irreducible element can be written as a sum, then one term is an additive unit. -/
isAddUnit_or_isAddUnit ⦃a b⦄ : p = a + b → IsAddUnit a ∨ IsAddUnit b
section Monoid
variable [Monoid M] {p q a b : M}
/-- `Irreducible p` states that `p` is non-unit and only factors into units.
We explicitly avoid stating that `p` is non-zero, this would require a semiring. Assuming only a
monoid allows us to reuse irreducible for associated elements. -/
@[to_additive]
structure Irreducible (p : M) : Prop where
/-- An irreducible element is not a unit. -/
not_isUnit : ¬IsUnit p
/-- If an irreducible element factors, then one factor is a unit. -/
isUnit_or_isUnit ⦃a b : M⦄ : p = a * b → IsUnit a ∨ IsUnit b
namespace Irreducible
end Irreducible
@[to_additive] lemma irreducible_iff :
Irreducible p ↔ ¬IsUnit p ∧ ∀ ⦃a b⦄, p = a * b → IsUnit a ∨ IsUnit b where
mp hp := ⟨hp.not_isUnit, hp.isUnit_or_isUnit⟩
mpr hp := ⟨hp.1, hp.2⟩
@[to_additive (attr := simp)]
lemma not_irreducible_one : ¬Irreducible (1 : M) := by simp [irreducible_iff]
@[to_additive]
lemma Irreducible.ne_one (hp : Irreducible p) : p ≠ 1 := by rintro rfl; exact not_irreducible_one hp
@[to_additive]
lemma of_irreducible_mul : Irreducible (a * b) → IsUnit a ∨ IsUnit b | ⟨_, h⟩ => h rfl
@[to_additive]
lemma irreducible_or_factor (hp : ¬IsUnit p) :
Irreducible p ∨ ∃ a b, ¬IsUnit a ∧ ¬IsUnit b ∧ p = a * b := by
simpa [irreducible_iff, hp, and_rotate] using em (∀ a b, p = a * b → IsUnit a ∨ IsUnit b)
@[to_additive]
lemma Irreducible.eq_one_or_eq_one [Subsingleton Mˣ] (hab : Irreducible (a * b)) :
a = 1 ∨ b = 1 := by simpa using hab.isUnit_or_isUnit rfl
end Monoid |
.lake/packages/mathlib/Mathlib/Algebra/Group/Invertible/Basic.lean | import Mathlib.Algebra.Group.Commute.Units
import Mathlib.Algebra.Group.Invertible.Defs
import Mathlib.Algebra.Group.Hom.Defs
import Mathlib.Logic.Equiv.Defs
/-!
# Theorems about invertible elements
-/
assert_not_exists MonoidWithZero DenselyOrdered
universe u
variable {α : Type u}
/-- An `Invertible` element is a unit. -/
@[simps]
def unitOfInvertible [Monoid α] (a : α) [Invertible a] : αˣ where
val := a
inv := ⅟a
val_inv := by simp
inv_val := by simp
theorem isUnit_of_invertible [Monoid α] (a : α) [Invertible a] : IsUnit a :=
⟨unitOfInvertible a, rfl⟩
/-- Units are invertible in their associated monoid. -/
instance Units.invertible [Monoid α] (u : αˣ) :
Invertible (u : α) where
invOf := ↑u⁻¹
invOf_mul_self := u.inv_mul
mul_invOf_self := u.mul_inv
@[simp]
theorem invOf_units [Monoid α] (u : αˣ) [Invertible (u : α)] : ⅟(u : α) = ↑u⁻¹ :=
invOf_eq_right_inv u.mul_inv
theorem IsUnit.nonempty_invertible [Monoid α] {a : α} (h : IsUnit a) : Nonempty (Invertible a) :=
let ⟨x, hx⟩ := h
⟨x.invertible.copy _ hx.symm⟩
/-- Convert `IsUnit` to `Invertible` using `Classical.choice`.
Prefer `casesI h.nonempty_invertible` over `letI := h.invertible` if you want to avoid choice. -/
noncomputable def IsUnit.invertible [Monoid α] {a : α} (h : IsUnit a) : Invertible a :=
Classical.choice h.nonempty_invertible
@[simp]
theorem nonempty_invertible_iff_isUnit [Monoid α] (a : α) : Nonempty (Invertible a) ↔ IsUnit a :=
⟨Nonempty.rec <| @isUnit_of_invertible _ _ _, IsUnit.nonempty_invertible⟩
theorem Commute.invOf_right [Monoid α] {a b : α} [Invertible b] (h : Commute a b) :
Commute a (⅟b) :=
calc
a * ⅟b = ⅟b * (b * a * ⅟b) := by simp [mul_assoc]
_ = ⅟b * (a * b * ⅟b) := by rw [h.eq]
_ = ⅟b * a := by simp [mul_assoc]
theorem Commute.invOf_left [Monoid α] {a b : α} [Invertible b] (h : Commute b a) :
Commute (⅟b) a :=
calc
⅟b * a = ⅟b * (a * b * ⅟b) := by simp [mul_assoc]
_ = ⅟b * (b * a * ⅟b) := by rw [h.eq]
_ = a * ⅟b := by simp [mul_assoc]
theorem commute_invOf {M : Type*} [One M] [Mul M] (m : M) [Invertible m] : Commute m (⅟m) :=
calc
m * ⅟m = 1 := mul_invOf_self m
_ = ⅟m * m := (invOf_mul_self m).symm
section Monoid
variable [Monoid α]
/-- This is the `Invertible` version of `Units.isUnit_units_mul` -/
abbrev invertibleOfInvertibleMul (a b : α) [Invertible a] [Invertible (a * b)] : Invertible b where
invOf := ⅟(a * b) * a
invOf_mul_self := by rw [mul_assoc, invOf_mul_self]
mul_invOf_self := by
rw [← (isUnit_of_invertible a).mul_right_inj, ← mul_assoc, ← mul_assoc, mul_invOf_self, mul_one,
one_mul]
/-- This is the `Invertible` version of `Units.isUnit_mul_units` -/
abbrev invertibleOfMulInvertible (a b : α) [Invertible (a * b)] [Invertible b] : Invertible a where
invOf := b * ⅟(a * b)
invOf_mul_self := by
rw [← (isUnit_of_invertible b).mul_left_inj, mul_assoc, mul_assoc, invOf_mul_self, mul_one,
one_mul]
mul_invOf_self := by rw [← mul_assoc, mul_invOf_self]
/-- `invertibleOfInvertibleMul` and `invertibleMul` as an equivalence. -/
@[simps apply symm_apply]
def Invertible.mulLeft {a : α} (_ : Invertible a) (b : α) : Invertible b ≃ Invertible (a * b) where
toFun _ := invertibleMul a b
invFun _ := invertibleOfInvertibleMul a _
left_inv _ := Subsingleton.elim _ _
right_inv _ := Subsingleton.elim _ _
/-- `invertibleOfMulInvertible` and `invertibleMul` as an equivalence. -/
@[simps apply symm_apply]
def Invertible.mulRight (a : α) {b : α} (_ : Invertible b) : Invertible a ≃ Invertible (a * b) where
toFun _ := invertibleMul a b
invFun _ := invertibleOfMulInvertible _ b
left_inv _ := Subsingleton.elim _ _
right_inv _ := Subsingleton.elim _ _
instance invertiblePow (m : α) [Invertible m] (n : ℕ) : Invertible (m ^ n) where
invOf := ⅟m ^ n
invOf_mul_self := by rw [← (commute_invOf m).symm.mul_pow, invOf_mul_self, one_pow]
mul_invOf_self := by rw [← (commute_invOf m).mul_pow, mul_invOf_self, one_pow]
lemma invOf_pow (m : α) [Invertible m] (n : ℕ) [Invertible (m ^ n)] : ⅟(m ^ n) = ⅟m ^ n :=
@invertible_unique _ _ _ _ _ (invertiblePow m n) rfl
/-- If `x ^ n = 1` then `x` has an inverse, `x^(n - 1)`. -/
def invertibleOfPowEqOne (x : α) (n : ℕ) (hx : x ^ n = 1) (hn : n ≠ 0) : Invertible x :=
(Units.ofPowEqOne x n hx hn).invertible
end Monoid
/-- Monoid homs preserve invertibility. -/
def Invertible.map {R : Type*} {S : Type*} {F : Type*} [MulOneClass R] [MulOneClass S]
[FunLike F R S] [MonoidHomClass F R S] (f : F) (r : R) [Invertible r] :
Invertible (f r) where
invOf := f (⅟r)
invOf_mul_self := by rw [← map_mul, invOf_mul_self, map_one]
mul_invOf_self := by rw [← map_mul, mul_invOf_self, map_one]
/-- Note that the `Invertible (f r)` argument can be satisfied by using `letI := Invertible.map f r`
before applying this lemma. -/
theorem map_invOf {R : Type*} {S : Type*} {F : Type*} [MulOneClass R] [Monoid S]
[FunLike F R S] [MonoidHomClass F R S] (f : F) (r : R)
[Invertible r] [ifr : Invertible (f r)] :
f (⅟r) = ⅟(f r) :=
have h : ifr = Invertible.map f r := Subsingleton.elim _ _
by subst h; rfl
/-- If a function `f : R → S` has a left-inverse that is a monoid hom,
then `r : R` is invertible if `f r` is.
The inverse is computed as `g (⅟(f r))` -/
@[simps! -isSimp]
def Invertible.ofLeftInverse {R : Type*} {S : Type*} {G : Type*} [MulOneClass R] [MulOneClass S]
[FunLike G S R] [MonoidHomClass G S R] (f : R → S) (g : G) (r : R)
(h : Function.LeftInverse g f) [Invertible (f r)] : Invertible r :=
(Invertible.map g (f r)).copy _ (h r).symm
/-- Invertibility on either side of a monoid hom with a left-inverse is equivalent. -/
@[simps]
def invertibleEquivOfLeftInverse {R : Type*} {S : Type*} {F G : Type*} [Monoid R] [Monoid S]
[FunLike F R S] [MonoidHomClass F R S] [FunLike G S R] [MonoidHomClass G S R]
(f : F) (g : G) (r : R) (h : Function.LeftInverse g f) : Invertible (f r) ≃ Invertible r where
toFun _ := Invertible.ofLeftInverse f _ _ h
invFun _ := Invertible.map f _
left_inv _ := Subsingleton.elim _ _
right_inv _ := Subsingleton.elim _ _ |
.lake/packages/mathlib/Mathlib/Algebra/Group/Invertible/Defs.lean | import Mathlib.Algebra.Group.Defs
/-!
# Invertible elements
This file defines a typeclass `Invertible a` for elements `a` with a two-sided
multiplicative inverse.
The intent of the typeclass is to provide a way to write e.g. `⅟2` in a ring
like `ℤ[1/2]` where some inverses exist but there is no general `⁻¹` operator;
or to specify that a field has characteristic `≠ 2`.
It is the `Type`-valued analogue to the `Prop`-valued `IsUnit`.
For constructions of the invertible element given a characteristic, see
`Algebra/CharP/Invertible` and other lemmas in that file.
## Notation
* `⅟a` is `Invertible.invOf a`, the inverse of `a`
## Implementation notes
The `Invertible` class lives in `Type`, not `Prop`, to make computation easier.
If multiplication is associative, `Invertible` is a subsingleton anyway.
The `simp` normal form tries to normalize `⅟a` to `a ⁻¹`. Otherwise, it pushes
`⅟` inside the expression as much as possible.
Since `Invertible a` is not a `Prop` (but it is a `Subsingleton`), we have to be careful about
coherence issues: we should avoid having multiple non-defeq instances for `Invertible a` in the
same context. This file plays it safe and uses `def` rather than `instance` for most definitions,
users can choose which instances to use at the point of use.
For example, here's how you can use an `Invertible 1` instance:
```lean
variable {α : Type*} [Monoid α]
def something_that_needs_inverses (x : α) [Invertible x] := sorry
section
attribute [local instance] invertibleOne
def something_one := something_that_needs_inverses 1
end
```
### Typeclass search vs. unification for `simp` lemmas
Note that since typeclass search searches the local context first, an instance argument like
`[Invertible a]` might sometimes be filled by a different term than the one we'd find by
unification (i.e., the one that's used as an implicit argument to `⅟`).
This can cause issues with `simp`. Therefore, some lemmas are duplicated, with the `@[simp]`
versions using unification and the user-facing ones using typeclass search.
Since unification can make backwards rewriting (e.g. `rw [← mylemma]`) impractical, we still want
the instance-argument versions; therefore the user-facing versions retain the instance arguments
and the original lemma name, whereas the `@[simp]`/unification ones acquire a `'` at the end of
their name.
We modify this file according to the above pattern only as needed; therefore, most `@[simp]` lemmas
here are not part of such a duplicate pair. This is not (yet) intended as a permanent solution.
See Zulip: [https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/Invertible.201.20simps/near/320558233]
## Tags
invertible, inverse element, invOf, a half, one half, a third, one third, ½, ⅓
-/
assert_not_exists MonoidWithZero DenselyOrdered
universe u
variable {α : Type u}
/-- `Invertible a` gives a two-sided multiplicative inverse of `a`. -/
class Invertible [Mul α] [One α] (a : α) : Type u where
/-- The inverse of an `Invertible` element -/
invOf : α
/-- `invOf a` is a left inverse of `a` -/
invOf_mul_self : invOf * a = 1
/-- `invOf a` is a right inverse of `a` -/
mul_invOf_self : a * invOf = 1
/-- The inverse of an `Invertible` element -/
-- This notation has the same precedence as `Inv.inv`.
prefix:max "⅟" => Invertible.invOf
@[simp]
theorem invOf_mul_self' [Mul α] [One α] (a : α) {_ : Invertible a} : ⅟a * a = 1 :=
Invertible.invOf_mul_self
theorem invOf_mul_self [Mul α] [One α] (a : α) [Invertible a] : ⅟a * a = 1 := invOf_mul_self' _
@[simp]
theorem mul_invOf_self' [Mul α] [One α] (a : α) {_ : Invertible a} : a * ⅟a = 1 :=
Invertible.mul_invOf_self
theorem mul_invOf_self [Mul α] [One α] (a : α) [Invertible a] : a * ⅟a = 1 := mul_invOf_self' _
@[simp]
theorem invOf_mul_cancel_left' [Monoid α] (a b : α) {_ : Invertible a} : ⅟a * (a * b) = b := by
rw [← mul_assoc, invOf_mul_self, one_mul]
example {G} [Group G] (a b : G) : a⁻¹ * (a * b) = b := inv_mul_cancel_left a b
theorem invOf_mul_cancel_left [Monoid α] (a b : α) [Invertible a] : ⅟a * (a * b) = b :=
invOf_mul_cancel_left' _ _
@[simp]
theorem mul_invOf_cancel_left' [Monoid α] (a b : α) {_ : Invertible a} : a * (⅟a * b) = b := by
rw [← mul_assoc, mul_invOf_self, one_mul]
example {G} [Group G] (a b : G) : a * (a⁻¹ * b) = b := mul_inv_cancel_left a b
theorem mul_invOf_cancel_left [Monoid α] (a b : α) [Invertible a] : a * (⅟a * b) = b :=
mul_invOf_cancel_left' a b
@[simp]
theorem invOf_mul_cancel_right' [Monoid α] (a b : α) {_ : Invertible b} : a * ⅟b * b = a := by
simp [mul_assoc]
example {G} [Group G] (a b : G) : a * b⁻¹ * b = a := inv_mul_cancel_right a b
theorem invOf_mul_cancel_right [Monoid α] (a b : α) [Invertible b] : a * ⅟b * b = a :=
invOf_mul_cancel_right' _ _
@[simp]
theorem mul_invOf_cancel_right' [Monoid α] (a b : α) {_ : Invertible b} : a * b * ⅟b = a := by
simp [mul_assoc]
example {G} [Group G] (a b : G) : a * b * b⁻¹ = a := mul_inv_cancel_right a b
theorem mul_invOf_cancel_right [Monoid α] (a b : α) [Invertible b] : a * b * ⅟b = a :=
mul_invOf_cancel_right' _ _
theorem invOf_eq_right_inv [Monoid α] {a b : α} [Invertible a] (hac : a * b = 1) : ⅟a = b :=
left_inv_eq_right_inv (invOf_mul_self _) hac
theorem invOf_eq_left_inv [Monoid α] {a b : α} [Invertible a] (hac : b * a = 1) : ⅟a = b :=
(left_inv_eq_right_inv hac (mul_invOf_self _)).symm
theorem invertible_unique {α : Type u} [Monoid α] (a b : α) [Invertible a] [Invertible b]
(h : a = b) : ⅟a = ⅟b := by
apply invOf_eq_right_inv
rw [h, mul_invOf_self]
instance Invertible.subsingleton [Monoid α] (a : α) : Subsingleton (Invertible a) :=
⟨fun ⟨b, hba, hab⟩ ⟨c, _, hac⟩ => by
congr
exact left_inv_eq_right_inv hba hac⟩
/-- If `a` is invertible and `a = b`, then `⅟a = ⅟b`. -/
@[congr]
theorem Invertible.congr [Monoid α] (a b : α) [Invertible a] [Invertible b] (h : a = b) :
⅟a = ⅟b :=
invertible_unique a b h
/-- If `r` is invertible and `s = r` and `si = ⅟r`, then `s` is invertible with `⅟s = si`. -/
def Invertible.copy' [MulOneClass α] {r : α} (hr : Invertible r) (s : α) (si : α) (hs : s = r)
(hsi : si = ⅟r) : Invertible s where
invOf := si
invOf_mul_self := by rw [hs, hsi, invOf_mul_self]
mul_invOf_self := by rw [hs, hsi, mul_invOf_self]
/-- If `r` is invertible and `s = r`, then `s` is invertible. -/
abbrev Invertible.copy [MulOneClass α] {r : α} (hr : Invertible r) (s : α) (hs : s = r) :
Invertible s :=
hr.copy' _ _ hs rfl
/-- Each element of a group is invertible. -/
def invertibleOfGroup [Group α] (a : α) : Invertible a :=
⟨a⁻¹, inv_mul_cancel a, mul_inv_cancel a⟩
@[simp]
theorem invOf_eq_group_inv [Group α] (a : α) [Invertible a] : ⅟a = a⁻¹ :=
invOf_eq_right_inv (mul_inv_cancel a)
/-- `1` is the inverse of itself -/
def invertibleOne [Monoid α] : Invertible (1 : α) :=
⟨1, mul_one _, one_mul _⟩
@[simp]
theorem invOf_one' [Monoid α] {_ : Invertible (1 : α)} : ⅟(1 : α) = 1 :=
invOf_eq_right_inv (mul_one _)
theorem invOf_one [Monoid α] [Invertible (1 : α)] : ⅟(1 : α) = 1 := invOf_one'
/-- `a` is the inverse of `⅟a`. -/
instance invertibleInvOf [One α] [Mul α] {a : α} [Invertible a] : Invertible (⅟a) :=
⟨a, mul_invOf_self a, invOf_mul_self a⟩
@[simp]
theorem invOf_invOf [Monoid α] (a : α) [Invertible a] [Invertible (⅟a)] : ⅟(⅟a) = a :=
invOf_eq_right_inv (invOf_mul_self _)
@[simp]
theorem invOf_inj [Monoid α] {a b : α} [Invertible a] [Invertible b] : ⅟a = ⅟b ↔ a = b :=
⟨invertible_unique _ _, invertible_unique _ _⟩
/-- `⅟b * ⅟a` is the inverse of `a * b` -/
def invertibleMul [Monoid α] (a b : α) [Invertible a] [Invertible b] : Invertible (a * b) :=
⟨⅟b * ⅟a, by simp [← mul_assoc], by simp [← mul_assoc]⟩
@[simp]
theorem invOf_mul [Monoid α] (a b : α) [Invertible a] [Invertible b] [Invertible (a * b)] :
⅟(a * b) = ⅟b * ⅟a :=
invOf_eq_right_inv (by simp [← mul_assoc])
/-- A copy of `invertibleMul` for dot notation. -/
abbrev Invertible.mul [Monoid α] {a b : α} (_ : Invertible a) (_ : Invertible b) :
Invertible (a * b) :=
invertibleMul _ _
section
variable [Monoid α] {a b c : α} [Invertible c]
variable (c) in
theorem mul_left_inj_of_invertible : a * c = b * c ↔ a = b :=
⟨fun h => by simpa using congr_arg (· * ⅟c) h, congr_arg (· * _)⟩
variable (c) in
theorem mul_right_inj_of_invertible : c * a = c * b ↔ a = b :=
⟨fun h => by simpa using congr_arg (⅟c * ·) h, congr_arg (_ * ·)⟩
theorem invOf_mul_eq_iff_eq_mul_left : ⅟c * a = b ↔ a = c * b := by
rw [← mul_right_inj_of_invertible (c := c), mul_invOf_cancel_left]
theorem mul_left_eq_iff_eq_invOf_mul : c * a = b ↔ a = ⅟c * b := by
rw [← mul_right_inj_of_invertible (c := ⅟c), invOf_mul_cancel_left]
theorem mul_invOf_eq_iff_eq_mul_right : a * ⅟c = b ↔ a = b * c := by
rw [← mul_left_inj_of_invertible (c := c), invOf_mul_cancel_right]
theorem mul_right_eq_iff_eq_mul_invOf : a * c = b ↔ a = b * ⅟c := by
rw [← mul_left_inj_of_invertible (c := ⅟c), mul_invOf_cancel_right]
end |
.lake/packages/mathlib/Mathlib/Algebra/Group/Equiv/Finite.lean | import Mathlib.Algebra.Group.Equiv.Defs
import Mathlib.Data.Fintype.Defs
/-!
# Finite types with addition/multiplications
This file contains basic results and instances for finite types that have an
addition/multiplication operator.
## Main results
* `Fintype.decidableEqMulEquivFintype`: `MulEquiv`s on finite types have decidable equality
-/
assert_not_exists MonoidWithZero MulAction
open Function
open Nat
universe u v
variable {α β γ : Type*}
namespace Fintype
section BundledHoms
@[to_additive]
instance decidableEqMulEquivFintype {α β : Type*} [DecidableEq β] [Fintype α] [Mul α] [Mul β] :
DecidableEq (α ≃* β) :=
fun a b => decidable_of_iff ((a : α → β) = b) (Injective.eq_iff DFunLike.coe_injective)
end BundledHoms
end Fintype |
.lake/packages/mathlib/Mathlib/Algebra/Group/Equiv/Opposite.lean | import Mathlib.Algebra.Group.Equiv.Basic
import Mathlib.Algebra.Group.Opposite
/-!
# Group isomorphism between a group and its opposite
-/
variable {α : Type*}
namespace MulOpposite
/-- The function `MulOpposite.op` is an additive equivalence. -/
@[simps! -fullyApplied +simpRhs apply symm_apply]
def opAddEquiv [Add α] : α ≃+ αᵐᵒᵖ where
toEquiv := opEquiv
map_add' _ _ := rfl
@[simp] lemma opAddEquiv_toEquiv [Add α] : ((opAddEquiv : α ≃+ αᵐᵒᵖ) : α ≃ αᵐᵒᵖ) = opEquiv := rfl
end MulOpposite
namespace AddOpposite
/-- The function `AddOpposite.op` is a multiplicative equivalence. -/
@[simps! -fullyApplied +simpRhs]
def opMulEquiv [Mul α] : α ≃* αᵃᵒᵖ where
toEquiv := opEquiv
map_mul' _ _ := rfl
@[simp] lemma opMulEquiv_toEquiv [Mul α] : ((opMulEquiv : α ≃* αᵃᵒᵖ) : α ≃ αᵃᵒᵖ) = opEquiv := rfl
end AddOpposite
open MulOpposite
/-- Inversion on a group is a `MulEquiv` to the opposite group. When `G` is commutative, there is
`MulEquiv.inv`. -/
@[to_additive (attr := simps! -fullyApplied +simpRhs)
/-- Negation on an additive group is an `AddEquiv` to the opposite group. When `G`
is commutative, there is `AddEquiv.inv`. -/]
def MulEquiv.inv' (G : Type*) [DivisionMonoid G] : G ≃* Gᵐᵒᵖ :=
{ (Equiv.inv G).trans opEquiv with map_mul' x y := unop_injective <| mul_inv_rev x y }
/-- A semigroup homomorphism `f : M →ₙ* N` such that `f x` commutes with `f y` for all `x, y`
defines a semigroup homomorphism to `Nᵐᵒᵖ`. -/
@[to_additive (attr := simps -fullyApplied)
/-- An additive semigroup homomorphism `f : AddHom M N` such that `f x` additively
commutes with `f y` for all `x, y` defines an additive semigroup homomorphism to `Sᵃᵒᵖ`. -/]
def MulHom.toOpposite {M N : Type*} [Mul M] [Mul N] (f : M →ₙ* N)
(hf : ∀ x y, Commute (f x) (f y)) : M →ₙ* Nᵐᵒᵖ where
toFun := op ∘ f
map_mul' x y := by simp [(hf x y).eq]
/-- A semigroup homomorphism `f : M →ₙ* N` such that `f x` commutes with `f y` for all `x, y`
defines a semigroup homomorphism from `Mᵐᵒᵖ`. -/
@[to_additive (attr := simps -fullyApplied)
/-- An additive semigroup homomorphism `f : AddHom M N` such that `f x` additively
commutes with `f y` for all `x`, `y` defines an additive semigroup homomorphism from `Mᵃᵒᵖ`. -/]
def MulHom.fromOpposite {M N : Type*} [Mul M] [Mul N] (f : M →ₙ* N)
(hf : ∀ x y, Commute (f x) (f y)) : Mᵐᵒᵖ →ₙ* N where
toFun := f ∘ MulOpposite.unop
map_mul' _ _ := (f.map_mul _ _).trans (hf _ _).eq
/-- A monoid homomorphism `f : M →* N` such that `f x` commutes with `f y` for all `x, y` defines
a monoid homomorphism to `Nᵐᵒᵖ`. -/
@[to_additive (attr := simps -fullyApplied)
/-- An additive monoid homomorphism `f : M →+ N` such that `f x` additively commutes
with `f y` for all `x, y` defines an additive monoid homomorphism to `Sᵃᵒᵖ`. -/]
def MonoidHom.toOpposite {M N : Type*} [MulOneClass M] [MulOneClass N] (f : M →* N)
(hf : ∀ x y, Commute (f x) (f y)) : M →* Nᵐᵒᵖ where
toFun := op ∘ f
map_one' := congrArg op f.map_one
map_mul' x y := by simp [(hf x y).eq]
/-- A monoid homomorphism `f : M →* N` such that `f x` commutes with `f y` for all `x, y` defines
a monoid homomorphism from `Mᵐᵒᵖ`. -/
@[to_additive (attr := simps -fullyApplied)
/-- An additive monoid homomorphism `f : M →+ N` such that `f x` additively commutes
with `f y` for all `x`, `y` defines an additive monoid homomorphism from `Mᵃᵒᵖ`. -/]
def MonoidHom.fromOpposite {M N : Type*} [MulOneClass M] [MulOneClass N] (f : M →* N)
(hf : ∀ x y, Commute (f x) (f y)) : Mᵐᵒᵖ →* N where
toFun := f ∘ MulOpposite.unop
map_one' := f.map_one
map_mul' _ _ := (f.map_mul _ _).trans (hf _ _).eq
/-- A semigroup homomorphism `M →ₙ* N` can equivalently be viewed as a semigroup homomorphism
`Mᵐᵒᵖ →ₙ* Nᵐᵒᵖ`. This is the action of the (fully faithful) `ᵐᵒᵖ`-functor on morphisms. -/
@[to_additive (attr := simps)
/-- An additive semigroup homomorphism `AddHom M N` can equivalently be viewed as an additive
semigroup homomorphism `AddHom Mᵃᵒᵖ Nᵃᵒᵖ`. This is the action of the (fully faithful)`ᵃᵒᵖ`-functor
on morphisms. -/]
def MulHom.op {M N} [Mul M] [Mul N] : (M →ₙ* N) ≃ (Mᵐᵒᵖ →ₙ* Nᵐᵒᵖ) where
toFun f :=
{ toFun := MulOpposite.op ∘ f ∘ unop,
map_mul' x y := unop_injective (f.map_mul y.unop x.unop) }
invFun f :=
{ toFun := unop ∘ f ∘ MulOpposite.op,
map_mul' x y := congrArg unop (f.map_mul (MulOpposite.op y) (MulOpposite.op x)) }
/-- The 'unopposite' of a semigroup homomorphism `Mᵐᵒᵖ →ₙ* Nᵐᵒᵖ`. Inverse to `MulHom.op`. -/
@[to_additive (attr := simp) /-- The 'unopposite' of an additive semigroup homomorphism
`Mᵃᵒᵖ →ₙ+ Nᵃᵒᵖ`. Inverse to `AddHom.op`. -/]
def MulHom.unop {M N} [Mul M] [Mul N] : (Mᵐᵒᵖ →ₙ* Nᵐᵒᵖ) ≃ (M →ₙ* N) :=
MulHom.op.symm
/-- An additive semigroup homomorphism `AddHom M N` can equivalently be viewed as an additive
homomorphism `AddHom Mᵐᵒᵖ Nᵐᵒᵖ`. This is the action of the (fully faithful) `ᵐᵒᵖ`-functor on
morphisms. -/
@[simps]
def AddHom.mulOp {M N} [Add M] [Add N] : AddHom M N ≃ AddHom Mᵐᵒᵖ Nᵐᵒᵖ where
toFun f :=
{ toFun := MulOpposite.op ∘ f ∘ MulOpposite.unop,
map_add' x y := unop_injective (f.map_add x.unop y.unop) }
invFun f :=
{ toFun := MulOpposite.unop ∘ f ∘ MulOpposite.op,
map_add' :=
fun x y => congrArg MulOpposite.unop (f.map_add (MulOpposite.op x) (MulOpposite.op y)) }
/-- The 'unopposite' of an additive semigroup hom `αᵐᵒᵖ →+ βᵐᵒᵖ`. Inverse to
`AddHom.mul_op`. -/
@[simp]
def AddHom.mulUnop {α β} [Add α] [Add β] : AddHom αᵐᵒᵖ βᵐᵒᵖ ≃ AddHom α β :=
AddHom.mulOp.symm
/-- A monoid homomorphism `M →* N` can equivalently be viewed as a monoid homomorphism
`Mᵐᵒᵖ →* Nᵐᵒᵖ`. This is the action of the (fully faithful) `ᵐᵒᵖ`-functor on morphisms. -/
@[to_additive (attr := simps)
/-- An additive monoid homomorphism `M →+ N` can equivalently be viewed as an additive monoid
homomorphism `Mᵃᵒᵖ →+ Nᵃᵒᵖ`. This is the action of the (fully faithful)
`ᵃᵒᵖ`-functor on morphisms. -/]
def MonoidHom.op {M N} [MulOneClass M] [MulOneClass N] : (M →* N) ≃ (Mᵐᵒᵖ →* Nᵐᵒᵖ) where
toFun f :=
{ toFun := MulOpposite.op ∘ f ∘ unop, map_one' := congrArg MulOpposite.op f.map_one,
map_mul' x y := unop_injective (f.map_mul y.unop x.unop) }
invFun f :=
{ toFun := unop ∘ f ∘ MulOpposite.op, map_one' := congrArg unop f.map_one,
map_mul' x y := congrArg unop (f.map_mul (MulOpposite.op y) (MulOpposite.op x)) }
/-- The 'unopposite' of a monoid homomorphism `Mᵐᵒᵖ →* Nᵐᵒᵖ`. Inverse to `MonoidHom.op`. -/
@[to_additive (attr := simp) /-- The 'unopposite' of an additive monoid homomorphism
`Mᵃᵒᵖ →+ Nᵃᵒᵖ`. Inverse to `AddMonoidHom.op`. -/]
def MonoidHom.unop {M N} [MulOneClass M] [MulOneClass N] : (Mᵐᵒᵖ →* Nᵐᵒᵖ) ≃ (M →* N) :=
MonoidHom.op.symm
/-- A monoid is isomorphic to the opposite of its opposite. -/
@[to_additive (attr := simps!)
/-- A additive monoid is isomorphic to the opposite of its opposite. -/]
def MulEquiv.opOp (M : Type*) [Mul M] : M ≃* Mᵐᵒᵖᵐᵒᵖ where
__ := MulOpposite.opEquiv.trans MulOpposite.opEquiv
map_mul' _ _ := rfl
/-- An additive homomorphism `M →+ N` can equivalently be viewed as an additive homomorphism
`Mᵐᵒᵖ →+ Nᵐᵒᵖ`. This is the action of the (fully faithful) `ᵐᵒᵖ`-functor on morphisms. -/
@[simps]
def AddMonoidHom.mulOp {M N} [AddZeroClass M] [AddZeroClass N] : (M →+ N) ≃ (Mᵐᵒᵖ →+ Nᵐᵒᵖ) where
toFun f :=
{ toFun := MulOpposite.op ∘ f ∘ MulOpposite.unop, map_zero' := unop_injective f.map_zero,
map_add' x y := unop_injective (f.map_add x.unop y.unop) }
invFun f :=
{ toFun := MulOpposite.unop ∘ f ∘ MulOpposite.op,
map_zero' := congrArg MulOpposite.unop f.map_zero,
map_add' :=
fun x y => congrArg MulOpposite.unop (f.map_add (MulOpposite.op x) (MulOpposite.op y)) }
/-- The 'unopposite' of an additive monoid hom `αᵐᵒᵖ →+ βᵐᵒᵖ`. Inverse to
`AddMonoidHom.mul_op`. -/
@[simp]
def AddMonoidHom.mulUnop {α β} [AddZeroClass α] [AddZeroClass β] : (αᵐᵒᵖ →+ βᵐᵒᵖ) ≃ (α →+ β) :=
AddMonoidHom.mulOp.symm
/-- An iso `α ≃+ β` can equivalently be viewed as an iso `αᵐᵒᵖ ≃+ βᵐᵒᵖ`. -/
@[simps]
def AddEquiv.mulOp {α β} [Add α] [Add β] : α ≃+ β ≃ (αᵐᵒᵖ ≃+ βᵐᵒᵖ) where
toFun f := opAddEquiv.symm.trans (f.trans opAddEquiv)
invFun f := opAddEquiv.trans (f.trans opAddEquiv.symm)
/-- The 'unopposite' of an iso `αᵐᵒᵖ ≃+ βᵐᵒᵖ`. Inverse to `AddEquiv.mul_op`. -/
@[simp]
def AddEquiv.mulUnop {α β} [Add α] [Add β] : αᵐᵒᵖ ≃+ βᵐᵒᵖ ≃ (α ≃+ β) :=
AddEquiv.mulOp.symm
/-- An iso `α ≃* β` can equivalently be viewed as an iso `αᵐᵒᵖ ≃* βᵐᵒᵖ`. -/
@[to_additive (attr := simps)
/-- An iso `α ≃+ β` can equivalently be viewed as an iso `αᵃᵒᵖ ≃+ βᵃᵒᵖ`. -/]
def MulEquiv.op {α β} [Mul α] [Mul β] : α ≃* β ≃ (αᵐᵒᵖ ≃* βᵐᵒᵖ) where
toFun f :=
{ toFun := MulOpposite.op ∘ f ∘ unop, invFun := MulOpposite.op ∘ f.symm ∘ unop,
left_inv x := unop_injective (f.symm_apply_apply x.unop),
right_inv x := unop_injective (f.apply_symm_apply x.unop),
map_mul' x y := unop_injective (map_mul f y.unop x.unop) }
invFun f :=
{ toFun := unop ∘ f ∘ MulOpposite.op, invFun := unop ∘ f.symm ∘ MulOpposite.op,
left_inv x := by simp,
right_inv x := by simp,
map_mul' x y := congr_arg unop (map_mul f (MulOpposite.op y) (MulOpposite.op x)) }
/-- The 'unopposite' of an iso `αᵐᵒᵖ ≃* βᵐᵒᵖ`. Inverse to `MulEquiv.op`. -/
@[to_additive (attr := simp)
/-- The 'unopposite' of an iso `αᵃᵒᵖ ≃+ βᵃᵒᵖ`. Inverse to `AddEquiv.op`. -/]
def MulEquiv.unop {α β} [Mul α] [Mul β] : αᵐᵒᵖ ≃* βᵐᵒᵖ ≃ (α ≃* β) := MulEquiv.op.symm
section Ext
/-- This ext lemma changes equalities on `αᵐᵒᵖ →+ β` to equalities on `α →+ β`.
This is useful because there are often ext lemmas for specific `α`s that will apply
to an equality of `α →+ β` such as `Finsupp.addHom_ext'`. -/
@[ext]
lemma AddMonoidHom.mul_op_ext {α β} [AddZeroClass α] [AddZeroClass β] (f g : αᵐᵒᵖ →+ β)
(h :
f.comp (opAddEquiv : α ≃+ αᵐᵒᵖ).toAddMonoidHom =
g.comp (opAddEquiv : α ≃+ αᵐᵒᵖ).toAddMonoidHom) :
f = g :=
AddMonoidHom.ext <| MulOpposite.rec' fun x => (DFunLike.congr_fun h :) x
end Ext |
.lake/packages/mathlib/Mathlib/Algebra/Group/Equiv/Basic.lean | import Mathlib.Algebra.Group.Equiv.Defs
import Mathlib.Algebra.Group.Hom.Basic
import Mathlib.Logic.Equiv.Basic
import Mathlib.Tactic.Spread
/-!
# Multiplicative and additive equivs
This file contains basic results on `MulEquiv` and `AddEquiv`.
## Tags
Equiv, MulEquiv, AddEquiv
-/
assert_not_exists Fintype
open Function
variable {F α β M M₁ M₂ M₃ N N₁ N₂ N₃ P Q G H : Type*}
namespace EmbeddingLike
variable [One M] [One N] [FunLike F M N] [EmbeddingLike F M N] [OneHomClass F M N]
end EmbeddingLike
variable [EquivLike F α β]
@[to_additive]
theorem MulEquivClass.toMulEquiv_injective [Mul α] [Mul β] [MulEquivClass F α β] :
Function.Injective ((↑) : F → α ≃* β) :=
fun _ _ e ↦ DFunLike.ext _ _ fun a ↦ congr_arg (fun e : α ≃* β ↦ e.toFun a) e
namespace MulEquiv
section Mul
variable [Mul M] [Mul N] [Mul P]
section unique
/-- The `MulEquiv` between two monoids with a unique element. -/
@[to_additive /-- The `AddEquiv` between two `AddMonoid`s with a unique element. -/]
def ofUnique {M N} [Unique M] [Unique N] [Mul M] [Mul N] : M ≃* N :=
{ Equiv.ofUnique M N with map_mul' := fun _ _ => Subsingleton.elim _ _ }
/-- There is a unique monoid homomorphism between two monoids with a unique element. -/
@[to_additive /-- There is a unique additive monoid homomorphism between two additive monoids with
a unique element. -/]
instance {M N} [Unique M] [Unique N] [Mul M] [Mul N] : Unique (M ≃* N) where
default := ofUnique
uniq _ := ext fun _ => Subsingleton.elim _ _
end unique
end Mul
/-!
## Monoids
-/
/-- A multiplicative analogue of `Equiv.arrowCongr`,
where the equivalence between the targets is multiplicative.
-/
@[to_additive (attr := simps apply) /-- An additive analogue of `Equiv.arrowCongr`,
where the equivalence between the targets is additive. -/]
def arrowCongr {M N P Q : Type*} [Mul P] [Mul Q] (f : M ≃ N) (g : P ≃* Q) :
(M → P) ≃* (N → Q) where
toFun h n := g (h (f.symm n))
invFun k m := g.symm (k (f m))
left_inv h := by ext; simp
right_inv k := by ext; simp
map_mul' h k := by ext; simp
section monoidHomCongrEquiv
variable [MulOneClass M] [MulOneClass M₁] [MulOneClass M₂] [MulOneClass M₃]
[Monoid N] [Monoid N₁] [Monoid N₂] [Monoid N₃]
/-- The equivalence `(M₁ →* N) ≃ (M₂ →* N)` obtained by postcomposition with
a multiplicative equivalence `e : M₁ ≃* M₂`. -/
@[to_additive (attr := simps)
/-- The equivalence `(M₁ →+ N) ≃ (M₂ →+ N)` obtained by postcomposition with
an additive equivalence `e : M₁ ≃+ M₂`. -/]
def monoidHomCongrLeftEquiv (e : M₁ ≃* M₂) : (M₁ →* N) ≃ (M₂ →* N) where
toFun f := f.comp e.symm.toMonoidHom
invFun f := f.comp e.toMonoidHom
left_inv f := by ext; simp
right_inv f := by ext; simp
/-- The equivalence `(M →* N₁) ≃ (M →* N₂)` obtained by postcomposition with
a multiplicative equivalence `e : N₁ ≃* N₂`. -/
@[to_additive (attr := simps)
/-- The equivalence `(M →+ N₁) ≃ (M →+ N₂)` obtained by postcomposition with
an additive equivalence `e : N₁ ≃+ N₂`. -/]
def monoidHomCongrRightEquiv (e : N₁ ≃* N₂) : (M →* N₁) ≃ (M →* N₂) where
toFun := e.toMonoidHom.comp
invFun := e.symm.toMonoidHom.comp
left_inv f := by ext; simp
right_inv f := by ext; simp
@[to_additive (attr := simp)]
lemma monoidHomCongrLeftEquiv_refl : monoidHomCongrLeftEquiv (.refl M) = .refl (M →* N) := rfl
@[to_additive (attr := simp)]
lemma monoidHomCongrRightEquiv_refl : monoidHomCongrRightEquiv (.refl N) = .refl (M →* N) := rfl
@[to_additive (attr := simp)]
lemma symm_monoidHomCongrLeftEquiv (e : M₁ ≃* M₂) :
(monoidHomCongrLeftEquiv e).symm = monoidHomCongrLeftEquiv (N := N) e.symm := rfl
@[to_additive (attr := simp)]
lemma symm_monoidHomCongrRightEquiv (e : N₁ ≃* N₂) :
(monoidHomCongrRightEquiv e).symm = monoidHomCongrRightEquiv (M := M) e.symm := rfl
@[to_additive (attr := simp)]
lemma monoidHomCongrLeftEquiv_trans (e₁₂ : M₁ ≃* M₂) (e₂₃ : M₂ ≃* M₃) :
monoidHomCongrLeftEquiv (N := N) (e₁₂.trans e₂₃) =
(monoidHomCongrLeftEquiv e₁₂).trans (monoidHomCongrLeftEquiv e₂₃) := rfl
@[to_additive (attr := simp)]
lemma monoidHomCongrRightEquiv_trans (e₁₂ : N₁ ≃* N₂) (e₂₃ : N₂ ≃* N₃) :
monoidHomCongrRightEquiv (M := M) (e₁₂.trans e₂₃) =
(monoidHomCongrRightEquiv e₁₂).trans (monoidHomCongrRightEquiv e₂₃) := rfl
end monoidHomCongrEquiv
section monoidHomCongr
variable [MulOneClass M] [MulOneClass M₁] [MulOneClass M₂] [MulOneClass M₃]
[CommMonoid N] [CommMonoid N₁] [CommMonoid N₂] [CommMonoid N₃]
/-- The isomorphism `(M₁ →* N) ≃* (M₂ →* N)` obtained by postcomposition with
a multiplicative equivalence `e : M₁ ≃* M₂`. -/
@[to_additive (attr := simps! apply)
/-- The isomorphism `(M₁ →+ N) ≃+ (M₂ →+ N)` obtained by postcomposition with
an additive equivalence `e : M₁ ≃+ M₂`. -/]
def monoidHomCongrLeft (e : M₁ ≃* M₂) : (M₁ →* N) ≃* (M₂ →* N) where
__ := e.monoidHomCongrLeftEquiv
map_mul' f g := by ext; simp
/-- The isomorphism `(M →* N₁) ≃* (M →* N₂)` obtained by postcomposition with
a multiplicative equivalence `e : N₁ ≃* N₂`. -/
@[to_additive (attr := simps! apply)
/-- The isomorphism `(M →+ N₁) ≃+ (M →+ N₂)` obtained by postcomposition with
an additive equivalence `e : N₁ ≃+ N₂`. -/]
def monoidHomCongrRight (e : N₁ ≃* N₂) : (M →* N₁) ≃* (M →* N₂) where
__ := e.monoidHomCongrRightEquiv
map_mul' f g := by ext; simp
@[to_additive (attr := simp)]
lemma monoidHomCongrLeft_refl : monoidHomCongrLeft (.refl M) = .refl (M →* N) := rfl
@[to_additive (attr := simp)]
lemma monoidHomCongrRight_refl : monoidHomCongrRight (.refl N) = .refl (M →* N) := rfl
@[to_additive (attr := simp)]
lemma symm_monoidHomCongrLeft (e : M₁ ≃* M₂) :
(monoidHomCongrLeft e).symm = monoidHomCongrLeft (N := N) e.symm := rfl
@[to_additive (attr := simp)]
lemma symm_monoidHomCongrRight (e : N₁ ≃* N₂) :
(monoidHomCongrRight e).symm = monoidHomCongrRight (M := M) e.symm := rfl
@[to_additive (attr := simp)]
lemma monoidHomCongrLeft_trans (e₁₂ : M₁ ≃* M₂) (e₂₃ : M₂ ≃* M₃) :
monoidHomCongrLeft (N := N) (e₁₂.trans e₂₃) =
(monoidHomCongrLeft e₁₂).trans (monoidHomCongrLeft e₂₃) := rfl
@[to_additive (attr := simp)]
lemma monoidHomCongrRight_trans (e₁₂ : N₁ ≃* N₂) (e₂₃ : N₂ ≃* N₃) :
monoidHomCongrRight (M := M) (e₁₂.trans e₂₃) =
(monoidHomCongrRight e₁₂).trans (monoidHomCongrRight e₂₃) := rfl
end monoidHomCongr
/-- A multiplicative analogue of `Equiv.arrowCongr`,
for multiplicative maps from a monoid to a commutative monoid.
-/
@[to_additive (attr := deprecated MulEquiv.monoidHomCongrLeft (since := "2025-08-12"))
/-- An additive analogue of `Equiv.arrowCongr`,
for additive maps from an additive monoid to a commutative additive monoid. -/]
def monoidHomCongr {M N P Q} [MulOneClass M] [MulOneClass N] [CommMonoid P] [CommMonoid Q]
(f : M ≃* N) (g : P ≃* Q) : (M →* P) ≃* (N →* Q) :=
f.monoidHomCongrLeft.trans g.monoidHomCongrRight
/-- A family of multiplicative equivalences `Π j, (Ms j ≃* Ns j)` generates a
multiplicative equivalence between `Π j, Ms j` and `Π j, Ns j`.
This is the `MulEquiv` version of `Equiv.piCongrRight`, and the dependent version of
`MulEquiv.arrowCongr`.
-/
@[to_additive (attr := simps apply)
/-- A family of additive equivalences `Π j, (Ms j ≃+ Ns j)`
generates an additive equivalence between `Π j, Ms j` and `Π j, Ns j`.
This is the `AddEquiv` version of `Equiv.piCongrRight`, and the dependent version of
`AddEquiv.arrowCongr`. -/]
def piCongrRight {η : Type*} {Ms Ns : η → Type*} [∀ j, Mul (Ms j)] [∀ j, Mul (Ns j)]
(es : ∀ j, Ms j ≃* Ns j) : (∀ j, Ms j) ≃* ∀ j, Ns j :=
{ Equiv.piCongrRight fun j => (es j).toEquiv with
toFun := fun x j => es j (x j),
invFun := fun x j => (es j).symm (x j),
map_mul' := fun x y => funext fun j => map_mul (es j) (x j) (y j) }
@[to_additive (attr := simp)]
theorem piCongrRight_refl {η : Type*} {Ms : η → Type*} [∀ j, Mul (Ms j)] :
(piCongrRight fun j => MulEquiv.refl (Ms j)) = MulEquiv.refl _ := rfl
@[to_additive (attr := simp)]
theorem piCongrRight_symm {η : Type*} {Ms Ns : η → Type*} [∀ j, Mul (Ms j)] [∀ j, Mul (Ns j)]
(es : ∀ j, Ms j ≃* Ns j) : (piCongrRight es).symm = piCongrRight fun i => (es i).symm := rfl
@[to_additive (attr := simp)]
theorem piCongrRight_trans {η : Type*} {Ms Ns Ps : η → Type*} [∀ j, Mul (Ms j)]
[∀ j, Mul (Ns j)] [∀ j, Mul (Ps j)] (es : ∀ j, Ms j ≃* Ns j) (fs : ∀ j, Ns j ≃* Ps j) :
(piCongrRight es).trans (piCongrRight fs) = piCongrRight fun i => (es i).trans (fs i) := rfl
/-- A family indexed by a type with a unique element
is `MulEquiv` to the element at the single index. -/
@[to_additive (attr := simps!)
/-- A family indexed by a type with a unique element
is `AddEquiv` to the element at the single index. -/]
def piUnique {ι : Type*} (M : ι → Type*) [∀ j, Mul (M j)] [Unique ι] :
(∀ j, M j) ≃* M default :=
{ Equiv.piUnique M with map_mul' := fun _ _ => Pi.mul_apply _ _ _ }
end MulEquiv
namespace MonoidHom
variable {M N₁ N₂ : Type*} [Monoid M] [CommMonoid N₁] [CommMonoid N₂]
/-- The equivalence `(β →* γ) ≃ (α →* γ)` obtained by precomposition with
a multiplicative equivalence `e : α ≃* β`. -/
@[to_additive (attr := simps -isSimp,
deprecated MulEquiv.monoidHomCongrLeftEquiv (since := "2025-08-12"))
/-- The equivalence `(β →+ γ) ≃ (α →+ γ)` obtained by precomposition with
an additive equivalence `e : α ≃+ β`. -/]
def precompEquiv {α β : Type*} [Monoid α] [Monoid β] (e : α ≃* β) (γ : Type*) [Monoid γ] :
(β →* γ) ≃ (α →* γ) where
toFun f := f.comp e
invFun g := g.comp e.symm
left_inv _ := by ext; simp
right_inv _ := by ext; simp
/-- The equivalence `(γ →* α) ≃ (γ →* β)` obtained by postcomposition with
a multiplicative equivalence `e : α ≃* β`. -/
@[to_additive (attr := simps -isSimp,
deprecated MulEquiv.monoidHomCongrRightEquiv (since := "2025-08-12"))
/-- The equivalence `(γ →+ α) ≃ (γ →+ β)` obtained by postcomposition with
an additive equivalence `e : α ≃+ β`. -/]
def postcompEquiv {α β : Type*} [Monoid α] [Monoid β] (e : α ≃* β) (γ : Type*) [Monoid γ] :
(γ →* α) ≃ (γ →* β) where
toFun f := e.toMonoidHom.comp f
invFun g := e.symm.toMonoidHom.comp g
left_inv _ := by ext; simp
right_inv _ := by ext; simp
end MonoidHom
namespace Equiv
section InvolutiveInv
variable (G) [InvolutiveInv G]
/-- Inversion on a `Group` or `GroupWithZero` is a permutation of the underlying type. -/
@[to_additive (attr := simps! -fullyApplied apply)
/-- Negation on an `AddGroup` is a permutation of the underlying type. -/]
protected def inv : Perm G :=
inv_involutive.toPerm _
variable {G}
@[to_additive (attr := simp)]
theorem inv_symm : (Equiv.inv G).symm = Equiv.inv G := rfl
end InvolutiveInv
end Equiv |
.lake/packages/mathlib/Mathlib/Algebra/Group/Equiv/Defs.lean | import Mathlib.Algebra.Group.Hom.Defs
import Mathlib.Logic.Equiv.Defs
/-!
# Multiplicative and additive equivs
In this file we define two extensions of `Equiv` called `AddEquiv` and `MulEquiv`, which are
datatypes representing isomorphisms of `AddMonoid`s/`AddGroup`s and `Monoid`s/`Group`s.
## Main definitions
* `≃*` (`MulEquiv`), `≃+` (`AddEquiv`): bundled equivalences that preserve multiplication/addition
(and are therefore monoid and group isomorphisms).
* `MulEquivClass`, `AddEquivClass`: classes for types containing bundled equivalences that
preserve multiplication/addition.
## Notation
* ``infix ` ≃* `:25 := MulEquiv``
* ``infix ` ≃+ `:25 := AddEquiv``
The extended equivs all have coercions to functions, and the coercions are the canonical
notation when treating the isomorphisms as maps.
## Tags
Equiv, MulEquiv, AddEquiv
-/
open Function
variable {F α β M N P G H : Type*}
namespace EmbeddingLike
variable [One M] [One N] [FunLike F M N] [EmbeddingLike F M N] [OneHomClass F M N]
@[to_additive (attr := simp)]
theorem map_eq_one_iff {f : F} {x : M} :
f x = 1 ↔ x = 1 :=
_root_.map_eq_one_iff f (EmbeddingLike.injective f)
@[to_additive]
theorem map_ne_one_iff {f : F} {x : M} :
f x ≠ 1 ↔ x ≠ 1 :=
map_eq_one_iff.not
end EmbeddingLike
/-- `AddEquiv α β` is the type of an equiv `α ≃ β` which preserves addition. -/
structure AddEquiv (A B : Type*) [Add A] [Add B] extends A ≃ B, AddHom A B
/-- `AddEquivClass F A B` states that `F` is a type of addition-preserving morphisms.
You should extend this class when you extend `AddEquiv`. -/
class AddEquivClass (F : Type*) (A B : outParam Type*) [Add A] [Add B] [EquivLike F A B] :
Prop where
/-- Preserves addition. -/
map_add : ∀ (f : F) (a b), f (a + b) = f a + f b
/-- The `Equiv` underlying an `AddEquiv`. -/
add_decl_doc AddEquiv.toEquiv
/-- The `AddHom` underlying an `AddEquiv`. -/
add_decl_doc AddEquiv.toAddHom
/-- `MulEquiv α β` is the type of an equiv `α ≃ β` which preserves multiplication. -/
@[to_additive]
structure MulEquiv (M N : Type*) [Mul M] [Mul N] extends M ≃ N, M →ₙ* N
/-- The `Equiv` underlying a `MulEquiv`. -/
add_decl_doc MulEquiv.toEquiv
/-- The `MulHom` underlying a `MulEquiv`. -/
add_decl_doc MulEquiv.toMulHom
/-- Notation for a `MulEquiv`. -/
infixl:25 " ≃* " => MulEquiv
/-- Notation for an `AddEquiv`. -/
infixl:25 " ≃+ " => AddEquiv
@[to_additive]
lemma MulEquiv.toEquiv_injective {α β : Type*} [Mul α] [Mul β] :
Function.Injective (toEquiv : (α ≃* β) → (α ≃ β))
| ⟨_, _⟩, ⟨_, _⟩, rfl => rfl
/-- `MulEquivClass F A B` states that `F` is a type of multiplication-preserving morphisms.
You should extend this class when you extend `MulEquiv`. -/
-- TODO: make this a synonym for MulHomClass?
@[to_additive]
class MulEquivClass (F : Type*) (A B : outParam Type*) [Mul A] [Mul B] [EquivLike F A B] :
Prop where
/-- Preserves multiplication. -/
map_mul : ∀ (f : F) (a b), f (a * b) = f a * f b
@[to_additive]
alias MulEquivClass.map_eq_one_iff := EmbeddingLike.map_eq_one_iff
@[to_additive]
alias MulEquivClass.map_ne_one_iff := EmbeddingLike.map_ne_one_iff
namespace MulEquivClass
variable (F)
variable [EquivLike F M N]
-- See note [lower instance priority]
@[to_additive]
instance (priority := 100) instMulHomClass (F : Type*)
[Mul M] [Mul N] [EquivLike F M N] [h : MulEquivClass F M N] : MulHomClass F M N :=
{ h with }
-- See note [lower instance priority]
@[to_additive]
instance (priority := 100) instMonoidHomClass
[MulOneClass M] [MulOneClass N] [MulEquivClass F M N] :
MonoidHomClass F M N :=
{ MulEquivClass.instMulHomClass F with
map_one := fun e =>
calc
e 1 = e 1 * 1 := (mul_one _).symm
_ = e 1 * e (EquivLike.inv e (1 : N) : M) :=
congr_arg _ (EquivLike.right_inv e 1).symm
_ = e (EquivLike.inv e (1 : N)) := by rw [← map_mul, one_mul]
_ = 1 := EquivLike.right_inv e 1 }
end MulEquivClass
variable [EquivLike F α β]
/-- Turn an element of a type `F` satisfying `MulEquivClass F α β` into an actual
`MulEquiv`. This is declared as the default coercion from `F` to `α ≃* β`. -/
@[to_additive (attr := coe)
/-- Turn an element of a type `F` satisfying `AddEquivClass F α β` into an actual
`AddEquiv`. This is declared as the default coercion from `F` to `α ≃+ β`. -/]
def MulEquivClass.toMulEquiv [Mul α] [Mul β] [MulEquivClass F α β] (f : F) : α ≃* β :=
{ (f : α ≃ β), (f : α →ₙ* β) with }
/-- Any type satisfying `MulEquivClass` can be cast into `MulEquiv` via
`MulEquivClass.toMulEquiv`. -/
@[to_additive /-- Any type satisfying `AddEquivClass` can be cast into `AddEquiv` via
`AddEquivClass.toAddEquiv`. -/]
instance [Mul α] [Mul β] [MulEquivClass F α β] : CoeTC F (α ≃* β) :=
⟨MulEquivClass.toMulEquiv⟩
namespace MulEquiv
section Mul
variable [Mul M] [Mul N] [Mul P]
section coe
@[to_additive]
instance : EquivLike (M ≃* N) M N where
coe f := f.toFun
inv f := f.invFun
left_inv f := f.left_inv
right_inv f := f.right_inv
coe_injective' f g h₁ h₂ := by
cases f
cases g
congr
apply Equiv.coe_fn_injective h₁
@[to_additive] -- shortcut instance that doesn't generate any subgoals
instance : CoeFun (M ≃* N) fun _ ↦ M → N where
coe f := f
@[to_additive]
instance : MulEquivClass (M ≃* N) M N where
map_mul f := f.map_mul'
/-- Two multiplicative isomorphisms agree if they are defined by the
same underlying function. -/
@[to_additive (attr := ext)
/-- Two additive isomorphisms agree if they are defined by the same underlying function. -/]
theorem ext {f g : MulEquiv M N} (h : ∀ x, f x = g x) : f = g :=
DFunLike.ext f g h
@[to_additive]
protected theorem congr_arg {f : MulEquiv M N} {x x' : M} : x = x' → f x = f x' :=
DFunLike.congr_arg f
@[to_additive]
protected theorem congr_fun {f g : MulEquiv M N} (h : f = g) (x : M) : f x = g x :=
DFunLike.congr_fun h x
@[to_additive (attr := simp)]
theorem coe_mk (f : M ≃ N) (hf : ∀ x y, f (x * y) = f x * f y) : (mk f hf : M → N) = f := rfl
@[to_additive (attr := simp)]
theorem mk_coe (e : M ≃* N) (e' h₁ h₂ h₃) : (⟨⟨e, e', h₁, h₂⟩, h₃⟩ : M ≃* N) = e :=
ext fun _ => rfl
@[to_additive (attr := simp)]
theorem toEquiv_eq_coe (f : M ≃* N) : f.toEquiv = f :=
rfl
/-- The `simp`-normal form to turn something into a `MulHom` is via `MulHomClass.toMulHom`. -/
@[to_additive (attr := simp)]
theorem toMulHom_eq_coe (f : M ≃* N) : f.toMulHom = ↑f :=
rfl
@[to_additive]
theorem toFun_eq_coe (f : M ≃* N) : f.toFun = f := rfl
/-- `simp`-normal form of `toFun_eq_coe`. -/
@[to_additive (attr := simp)]
theorem coe_toEquiv (f : M ≃* N) : ⇑(f : M ≃ N) = f := rfl
@[to_additive (attr := simp)]
theorem coe_toMulHom {f : M ≃* N} : (f.toMulHom : M → N) = f := rfl
/-- Makes a multiplicative isomorphism from a bijection which preserves multiplication. -/
@[to_additive /-- Makes an additive isomorphism from a bijection which preserves addition. -/]
def mk' (f : M ≃ N) (h : ∀ x y, f (x * y) = f x * f y) : M ≃* N := ⟨f, h⟩
end coe
section map
/-- A multiplicative isomorphism preserves multiplication. -/
@[to_additive /-- An additive isomorphism preserves addition. -/]
protected theorem map_mul (f : M ≃* N) : ∀ x y, f (x * y) = f x * f y :=
map_mul f
end map
section bijective
@[to_additive]
protected theorem bijective (e : M ≃* N) : Function.Bijective e :=
EquivLike.bijective e
@[to_additive]
protected theorem injective (e : M ≃* N) : Function.Injective e :=
EquivLike.injective e
@[to_additive]
protected theorem surjective (e : M ≃* N) : Function.Surjective e :=
EquivLike.surjective e
@[to_additive]
theorem apply_eq_iff_eq (e : M ≃* N) {x y : M} : e x = e y ↔ x = y :=
e.injective.eq_iff
end bijective
section refl
/-- The identity map is a multiplicative isomorphism. -/
@[to_additive (attr := refl) /-- The identity map is an additive isomorphism. -/]
def refl (M : Type*) [Mul M] : M ≃* M :=
{ Equiv.refl _ with map_mul' := fun _ _ => rfl }
@[to_additive]
instance : Inhabited (M ≃* M) := ⟨refl M⟩
@[to_additive (attr := simp)]
theorem coe_refl : ↑(refl M) = id := rfl
@[to_additive (attr := simp)]
theorem refl_apply (m : M) : refl M m = m := rfl
end refl
section symm
/-- An alias for `h.symm.map_mul`. Introduced to fix the issue in
https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/!4.234183.20.60simps.60.20maximum.20recursion.20depth
-/
@[to_additive]
lemma symm_map_mul {M N : Type*} [Mul M] [Mul N] (h : M ≃* N) (x y : N) :
h.symm (x * y) = h.symm x * h.symm y :=
map_mul (h.toMulHom.inverse h.toEquiv.symm h.left_inv h.right_inv) x y
/-- The inverse of an isomorphism is an isomorphism. -/
@[to_additive (attr := symm) /-- The inverse of an isomorphism is an isomorphism. -/]
def symm {M N : Type*} [Mul M] [Mul N] (h : M ≃* N) : N ≃* M :=
⟨h.toEquiv.symm, h.symm_map_mul⟩
@[to_additive]
theorem invFun_eq_symm {f : M ≃* N} : f.invFun = f.symm := rfl
/-- `simp`-normal form of `invFun_eq_symm`. -/
@[to_additive (attr := simp)]
theorem coe_toEquiv_symm (f : M ≃* N) : ((f : M ≃ N).symm : N → M) = f.symm := rfl
@[to_additive (attr := simp)]
theorem equivLike_inv_eq_symm (f : M ≃* N) : EquivLike.inv f = f.symm := rfl
@[to_additive (attr := simp)]
theorem toEquiv_symm (f : M ≃* N) : (f.symm : N ≃ M) = (f : M ≃ N).symm := rfl
@[to_additive (attr := simp)]
theorem symm_symm (f : M ≃* N) : f.symm.symm = f := rfl
@[to_additive]
theorem symm_bijective : Function.Bijective (symm : (M ≃* N) → N ≃* M) :=
Function.bijective_iff_has_inverse.mpr ⟨_, symm_symm, symm_symm⟩
@[to_additive (attr := simp)]
theorem mk_coe' (e : M ≃* N) (f h₁ h₂ h₃) : (MulEquiv.mk ⟨f, e, h₁, h₂⟩ h₃ : N ≃* M) = e.symm :=
symm_bijective.injective <| ext fun _ => rfl
@[to_additive (attr := simp)]
theorem symm_mk (f : M ≃ N) (h) :
(MulEquiv.mk f h).symm = ⟨f.symm, (MulEquiv.mk f h).symm_map_mul⟩ := rfl
@[to_additive (attr := simp)]
theorem refl_symm : (refl M).symm = refl M := rfl
/-- `e.symm` is a right inverse of `e`, written as `e (e.symm y) = y`. -/
@[to_additive (attr := simp)
/-- `e.symm` is a right inverse of `e`, written as `e (e.symm y) = y`. -/]
theorem apply_symm_apply (e : M ≃* N) (y : N) : e (e.symm y) = y :=
e.toEquiv.apply_symm_apply y
/-- `e.symm` is a left inverse of `e`, written as `e.symm (e y) = y`. -/
@[to_additive (attr := simp)
/-- `e.symm` is a left inverse of `e`, written as `e.symm (e y) = y`. -/]
theorem symm_apply_apply (e : M ≃* N) (x : M) : e.symm (e x) = x :=
e.toEquiv.symm_apply_apply x
@[to_additive (attr := simp)]
theorem symm_comp_self (e : M ≃* N) : e.symm ∘ e = id :=
funext e.symm_apply_apply
@[to_additive (attr := simp)]
theorem self_comp_symm (e : M ≃* N) : e ∘ e.symm = id :=
funext e.apply_symm_apply
@[to_additive]
theorem apply_eq_iff_symm_apply (e : M ≃* N) {x : M} {y : N} : e x = y ↔ x = e.symm y :=
e.toEquiv.apply_eq_iff_eq_symm_apply
@[to_additive]
theorem symm_apply_eq (e : M ≃* N) {x y} : e.symm x = y ↔ x = e y :=
e.toEquiv.symm_apply_eq
@[to_additive]
theorem eq_symm_apply (e : M ≃* N) {x y} : y = e.symm x ↔ e y = x :=
e.toEquiv.eq_symm_apply
@[to_additive]
theorem eq_comp_symm {α : Type*} (e : M ≃* N) (f : N → α) (g : M → α) :
f = g ∘ e.symm ↔ f ∘ e = g :=
e.toEquiv.eq_comp_symm f g
@[to_additive]
theorem comp_symm_eq {α : Type*} (e : M ≃* N) (f : N → α) (g : M → α) :
g ∘ e.symm = f ↔ g = f ∘ e :=
e.toEquiv.comp_symm_eq f g
@[to_additive]
theorem eq_symm_comp {α : Type*} (e : M ≃* N) (f : α → M) (g : α → N) :
f = e.symm ∘ g ↔ e ∘ f = g :=
e.toEquiv.eq_symm_comp f g
@[to_additive]
theorem symm_comp_eq {α : Type*} (e : M ≃* N) (f : α → M) (g : α → N) :
e.symm ∘ g = f ↔ g = e ∘ f :=
e.toEquiv.symm_comp_eq f g
@[to_additive (attr := simp)]
theorem _root_.MulEquivClass.apply_coe_symm_apply {α β} [Mul α] [Mul β] {F} [EquivLike F α β]
[MulEquivClass F α β] (e : F) (x : β) :
e ((e : α ≃* β).symm x) = x :=
(e : α ≃* β).right_inv x
@[to_additive (attr := simp)]
theorem _root_.MulEquivClass.coe_symm_apply_apply {α β} [Mul α] [Mul β] {F} [EquivLike F α β]
[MulEquivClass F α β] (e : F) (x : α) :
(e : α ≃* β).symm (e x) = x :=
(e : α ≃* β).left_inv x
end symm
section simps
-- we don't hyperlink the note in the additive version, since that breaks syntax highlighting
-- in the whole file.
/-- See Note [custom simps projection] -/
@[to_additive /-- See Note [custom simps projection] -/]
def Simps.symm_apply (e : M ≃* N) : N → M :=
e.symm
initialize_simps_projections AddEquiv (toFun → apply, invFun → symm_apply)
initialize_simps_projections MulEquiv (toFun → apply, invFun → symm_apply)
end simps
section trans
/-- Transitivity of multiplication-preserving isomorphisms -/
@[to_additive (attr := trans) /-- Transitivity of addition-preserving isomorphisms -/]
def trans (h1 : M ≃* N) (h2 : N ≃* P) : M ≃* P :=
{ h1.toEquiv.trans h2.toEquiv with
map_mul' := fun x y => show h2 (h1 (x * y)) = h2 (h1 x) * h2 (h1 y) by
rw [map_mul, map_mul] }
@[to_additive (attr := simp)]
theorem coe_trans (e₁ : M ≃* N) (e₂ : N ≃* P) : ↑(e₁.trans e₂) = e₂ ∘ e₁ := rfl
@[to_additive (attr := simp)]
theorem trans_apply (e₁ : M ≃* N) (e₂ : N ≃* P) (m : M) : e₁.trans e₂ m = e₂ (e₁ m) := rfl
@[to_additive (attr := simp)]
theorem symm_trans_apply (e₁ : M ≃* N) (e₂ : N ≃* P) (p : P) :
(e₁.trans e₂).symm p = e₁.symm (e₂.symm p) := rfl
@[to_additive (attr := simp)]
theorem symm_trans_self (e : M ≃* N) : e.symm.trans e = refl N :=
DFunLike.ext _ _ e.apply_symm_apply
@[to_additive (attr := simp)]
theorem self_trans_symm (e : M ≃* N) : e.trans e.symm = refl M :=
DFunLike.ext _ _ e.symm_apply_apply
end trans
/-- `MulEquiv.symm` defines an equivalence between `α ≃* β` and `β ≃* α`. -/
@[to_additive (attr := simps!)
/-- `AddEquiv.symm` defines an equivalence between `α ≃+ β` and `β ≃+ α` -/]
def symmEquiv (P Q : Type*) [Mul P] [Mul Q] : (P ≃* Q) ≃ (Q ≃* P) where
toFun := .symm
invFun := .symm
end Mul
/-- `Equiv.cast (congrArg _ h)` as a `MulEquiv`.
Note that unlike `Equiv.cast`, this takes an equality of indices rather than an equality of types,
to avoid having to deal with an equality of the algebraic structure itself. -/
@[to_additive (attr := simps!) /-- `Equiv.cast (congrArg _ h)` as an `AddEquiv`.
Note that unlike `Equiv.cast`, this takes an equality of indices rather than an equality of types,
to avoid having to deal with an equality of the algebraic structure itself. -/]
protected def cast {ι : Type*} {M : ι → Type*} [∀ i, Mul (M i)] {i j : ι} (h : i = j) :
M i ≃* M j where
toEquiv := Equiv.cast (congrArg _ h)
map_mul' _ _ := by cases h; rfl
/-!
### Monoids
-/
section MulOneClass
variable [MulOneClass M] [MulOneClass N] [MulOneClass P]
@[to_additive (attr := simp)]
theorem coe_monoidHom_refl : (refl M : M →* M) = MonoidHom.id M := rfl
@[to_additive (attr := simp)]
lemma coe_monoidHom_trans (e₁ : M ≃* N) (e₂ : N ≃* P) :
(e₁.trans e₂ : M →* P) = (e₂ : N →* P).comp ↑e₁ := rfl
@[to_additive (attr := simp)]
lemma coe_monoidHom_comp_coe_monoidHom_symm (e : M ≃* N) :
(e : M →* N).comp e.symm = MonoidHom.id _ := by ext; simp
@[to_additive (attr := simp)]
lemma coe_monoidHom_symm_comp_coe_monoidHom (e : M ≃* N) :
(e.symm : N →* M).comp e = MonoidHom.id _ := by ext; simp
@[to_additive]
lemma comp_left_injective (e : M ≃* N) : Injective fun f : N →* P ↦ f.comp (e : M →* N) :=
LeftInverse.injective (g := fun f ↦ f.comp e.symm) fun f ↦ by simp [MonoidHom.comp_assoc]
@[to_additive]
lemma comp_right_injective (e : M ≃* N) : Injective fun f : P →* M ↦ (e : M →* N).comp f :=
LeftInverse.injective (g := (e.symm : N →* M).comp) fun f ↦ by simp [← MonoidHom.comp_assoc]
/-- A multiplicative isomorphism of monoids sends `1` to `1` (and is hence a monoid isomorphism). -/
@[to_additive
/-- An additive isomorphism of additive monoids sends `0` to `0`
(and is hence an additive monoid isomorphism). -/]
protected theorem map_one (h : M ≃* N) : h 1 = 1 := map_one h
@[to_additive]
protected theorem map_eq_one_iff (h : M ≃* N) {x : M} : h x = 1 ↔ x = 1 :=
EmbeddingLike.map_eq_one_iff
@[to_additive]
theorem map_ne_one_iff (h : M ≃* N) {x : M} : h x ≠ 1 ↔ x ≠ 1 :=
EmbeddingLike.map_ne_one_iff
/-- A bijective `Semigroup` homomorphism is an isomorphism -/
@[to_additive (attr := simps! apply)
/-- A bijective `AddSemigroup` homomorphism is an isomorphism -/]
noncomputable def ofBijective {M N F} [Mul M] [Mul N] [FunLike F M N] [MulHomClass F M N]
(f : F) (hf : Bijective f) : M ≃* N :=
{ Equiv.ofBijective f hf with map_mul' := map_mul f }
@[to_additive (attr := simp)]
theorem ofBijective_apply_symm_apply {n : N} (f : M →* N) (hf : Bijective f) :
f ((ofBijective f hf).symm n) = n := (ofBijective f hf).apply_symm_apply n
/-- Extract the forward direction of a multiplicative equivalence
as a multiplication-preserving function.
-/
@[to_additive /-- Extract the forward direction of an additive equivalence
as an addition-preserving function. -/]
def toMonoidHom (h : M ≃* N) : M →* N :=
{ h with map_one' := h.map_one }
@[to_additive (attr := simp)]
theorem coe_toMonoidHom (e : M ≃* N) : ⇑e.toMonoidHom = e := rfl
@[to_additive (attr := simp)]
theorem toMonoidHom_eq_coe (f : M ≃* N) : f.toMonoidHom = (f : M →* N) :=
rfl
@[to_additive]
theorem toMonoidHom_injective : Injective (toMonoidHom : M ≃* N → M →* N) :=
Injective.of_comp (f := DFunLike.coe) DFunLike.coe_injective
end MulOneClass
/-!
### Groups
-/
/-- A multiplicative equivalence of groups preserves inversion. -/
@[to_additive /-- An additive equivalence of additive groups preserves negation. -/]
protected theorem map_inv [Group G] [DivisionMonoid H] (h : G ≃* H) (x : G) :
h x⁻¹ = (h x)⁻¹ :=
map_inv h x
/-- A multiplicative equivalence of groups preserves division. -/
@[to_additive /-- An additive equivalence of additive groups preserves subtractions. -/]
protected theorem map_div [Group G] [DivisionMonoid H] (h : G ≃* H) (x y : G) :
h (x / y) = h x / h y :=
map_div h x y
end MulEquiv
/-- Given a pair of multiplicative homomorphisms `f`, `g` such that `g.comp f = id` and
`f.comp g = id`, returns a multiplicative equivalence with `toFun = f` and `invFun = g`. This
constructor is useful if the underlying type(s) have specialized `ext` lemmas for multiplicative
homomorphisms. -/
@[to_additive (attr := simps -fullyApplied)
/-- Given a pair of additive homomorphisms `f`, `g` such that `g.comp f = id` and
`f.comp g = id`, returns an additive equivalence with `toFun = f` and `invFun = g`. This
constructor is useful if the underlying type(s) have specialized `ext` lemmas for additive
homomorphisms. -/]
def MulHom.toMulEquiv [Mul M] [Mul N] (f : M →ₙ* N) (g : N →ₙ* M) (h₁ : g.comp f = MulHom.id _)
(h₂ : f.comp g = MulHom.id _) : M ≃* N where
toFun := f
invFun := g
left_inv := DFunLike.congr_fun h₁
right_inv := DFunLike.congr_fun h₂
map_mul' := f.map_mul
/-- Given a pair of monoid homomorphisms `f`, `g` such that `g.comp f = id` and `f.comp g = id`,
returns a multiplicative equivalence with `toFun = f` and `invFun = g`. This constructor is
useful if the underlying type(s) have specialized `ext` lemmas for monoid homomorphisms. -/
@[to_additive (attr := simps -fullyApplied)
/-- Given a pair of additive monoid homomorphisms `f`, `g` such that `g.comp f = id`
and `f.comp g = id`, returns an additive equivalence with `toFun = f` and `invFun = g`. This
constructor is useful if the underlying type(s) have specialized `ext` lemmas for additive
monoid homomorphisms. -/]
def MonoidHom.toMulEquiv [MulOneClass M] [MulOneClass N] (f : M →* N) (g : N →* M)
(h₁ : g.comp f = MonoidHom.id _) (h₂ : f.comp g = MonoidHom.id _) : M ≃* N where
toFun := f
invFun := g
left_inv := DFunLike.congr_fun h₁
right_inv := DFunLike.congr_fun h₂
map_mul' := f.map_mul |
.lake/packages/mathlib/Mathlib/Algebra/Group/Equiv/TypeTags.lean | import Mathlib.Algebra.Group.TypeTags.Hom
import Mathlib.Algebra.Group.Equiv.Defs
import Mathlib.Algebra.Notation.Prod
import Mathlib.Tactic.Spread
/-!
# Additive and multiplicative equivalences associated to `Multiplicative` and `Additive`.
-/
assert_not_exists Finite Fintype
variable {ι G H : Type*}
/-- Reinterpret `G ≃+ H` as `Multiplicative G ≃* Multiplicative H`. -/
@[simps]
def AddEquiv.toMultiplicative [AddZeroClass G] [AddZeroClass H] :
G ≃+ H ≃ (Multiplicative G ≃* Multiplicative H) where
toFun f :=
{ toFun := AddMonoidHom.toMultiplicative f.toAddMonoidHom
invFun := AddMonoidHom.toMultiplicative f.symm.toAddMonoidHom
left_inv := f.left_inv
right_inv := f.right_inv
map_mul' := map_add f }
invFun f :=
{ toFun := AddMonoidHom.toMultiplicative.symm f.toMonoidHom
invFun := AddMonoidHom.toMultiplicative.symm f.symm.toMonoidHom
left_inv := f.left_inv
right_inv := f.right_inv
map_add' := map_mul f }
/-- Reinterpret `G ≃* H` as `Additive G ≃+ Additive H`. -/
@[simps]
def MulEquiv.toAdditive [MulOneClass G] [MulOneClass H] :
G ≃* H ≃ (Additive G ≃+ Additive H) where
toFun f :=
{ toFun := MonoidHom.toAdditive f.toMonoidHom
invFun := MonoidHom.toAdditive f.symm.toMonoidHom
left_inv := f.left_inv
right_inv := f.right_inv
map_add' := map_mul f }
invFun f :=
{ toFun := MonoidHom.toAdditive.symm f.toAddMonoidHom
invFun := MonoidHom.toAdditive.symm f.symm.toAddMonoidHom
left_inv := f.left_inv
right_inv := f.right_inv
map_mul' := map_add f }
/-- Reinterpret `Additive G ≃+ H` as `G ≃* Multiplicative H`. -/
@[simps]
def AddEquiv.toMultiplicativeRight [MulOneClass G] [AddZeroClass H] :
Additive G ≃+ H ≃ (G ≃* Multiplicative H) where
toFun f :=
{ toFun := f.toAddMonoidHom.toMultiplicativeRight
invFun := f.symm.toAddMonoidHom.toMultiplicativeLeft
left_inv := f.left_inv
right_inv := f.right_inv
map_mul' := map_add f }
invFun f :=
{ toFun := f.toMonoidHom.toAdditiveLeft
invFun := f.symm.toMonoidHom.toAdditiveRight
left_inv := f.left_inv
right_inv := f.right_inv
map_add' := map_mul f }
@[deprecated (since := "2025-09-19")]
alias AddEquiv.toMultiplicative' := AddEquiv.toMultiplicativeRight
/-- Reinterpret `G ≃* Multiplicative H` as `Additive G ≃+ H`. -/
abbrev MulEquiv.toAdditiveLeft [MulOneClass G] [AddZeroClass H] :
G ≃* Multiplicative H ≃ (Additive G ≃+ H) :=
AddEquiv.toMultiplicativeRight.symm
@[deprecated (since := "2025-09-19")] alias MulEquiv.toAdditive' := MulEquiv.toAdditiveLeft
/-- Reinterpret `G ≃+ Additive H` as `Multiplicative G ≃* H`. -/
@[simps]
def AddEquiv.toMultiplicativeLeft [AddZeroClass G] [MulOneClass H] :
G ≃+ Additive H ≃ (Multiplicative G ≃* H) where
toFun f :=
{ toFun := f.toAddMonoidHom.toMultiplicativeLeft
invFun := f.symm.toAddMonoidHom.toMultiplicativeRight
left_inv := f.left_inv
right_inv := f.right_inv
map_mul' := map_add f }
invFun f :=
{ toFun := f.toMonoidHom.toAdditiveRight
invFun := f.symm.toMonoidHom.toAdditiveLeft
left_inv := f.left_inv
right_inv := f.right_inv
map_add' := map_mul f }
@[deprecated (since := "2025-09-19")]
alias AddEquiv.toMultiplicative'' := AddEquiv.toMultiplicativeLeft
/-- Reinterpret `Multiplicative G ≃* H` as `G ≃+ Additive H` as. -/
abbrev MulEquiv.toAdditiveRight [AddZeroClass G] [MulOneClass H] :
Multiplicative G ≃* H ≃ (G ≃+ Additive H) :=
AddEquiv.toMultiplicativeLeft.symm
@[deprecated (since := "2025-09-19")] alias MulEquiv.toAdditive'' := MulEquiv.toAdditiveRight
/-- The multiplicative version of an additivized monoid is mul-equivalent to itself. -/
@[simps! apply symm_apply]
def MulEquiv.toMultiplicative_toAdditive [MulOneClass G] :
Multiplicative (Additive G) ≃* G :=
AddEquiv.toMultiplicativeLeft <| MulEquiv.toAdditive (.refl _)
/-- The additive version of an multiplicativized additive monoid is add-equivalent to itself. -/
@[simps! apply symm_apply]
def AddEquiv.toAdditive_toMultiplicative [AddZeroClass G] :
Additive (Multiplicative G) ≃+ G :=
MulEquiv.toAdditiveLeft <| AddEquiv.toMultiplicative (.refl _)
/-- Multiplicative equivalence between multiplicative endomorphisms of a `MulOneClass` `M`
and additive endomorphisms of `Additive M`. -/
@[simps!] def monoidEndToAdditive (M : Type*) [MulOneClass M] :
Monoid.End M ≃* AddMonoid.End (Additive M) :=
{ MonoidHom.toAdditive with
map_mul' := fun _ _ => rfl }
/-- Multiplicative equivalence between additive endomorphisms of an `AddZeroClass` `A`
and multiplicative endomorphisms of `Multiplicative A`. -/
@[simps!] def addMonoidEndToMultiplicative (A : Type*) [AddZeroClass A] :
AddMonoid.End A ≃* Monoid.End (Multiplicative A) :=
{ AddMonoidHom.toMultiplicative with
map_mul' := fun _ _ => rfl }
/-- `Multiplicative (∀ i : ι, K i)` is equivalent to `∀ i : ι, Multiplicative (K i)`. -/
@[simps]
def MulEquiv.piMultiplicative (K : ι → Type*) [∀ i, Add (K i)] :
Multiplicative (∀ i : ι, K i) ≃* (∀ i : ι, Multiplicative (K i)) where
toFun x := fun i ↦ Multiplicative.ofAdd <| x.toAdd i
invFun x := Multiplicative.ofAdd fun i ↦ (x i).toAdd
map_mul' _ _ := rfl
variable (ι) (G) in
/-- `Multiplicative (ι → G)` is equivalent to `ι → Multiplicative G`. -/
abbrev MulEquiv.funMultiplicative [Add G] :
Multiplicative (ι → G) ≃* (ι → Multiplicative G) :=
MulEquiv.piMultiplicative fun _ ↦ G
/-- `Additive (∀ i : ι, K i)` is equivalent to `∀ i : ι, Additive (K i)`. -/
@[simps]
def AddEquiv.piAdditive (K : ι → Type*) [∀ i, Mul (K i)] :
Additive (∀ i : ι, K i) ≃+ (∀ i : ι, Additive (K i)) where
toFun x := fun i ↦ Additive.ofMul <| x.toMul i
invFun x := Additive.ofMul fun i ↦ (x i).toMul
map_add' _ _ := rfl
variable (ι) (G) in
/-- `Additive (ι → G)` is equivalent to `ι → Additive G`. -/
abbrev AddEquiv.funAdditive [Mul G] :
Additive (ι → G) ≃+ (ι → Additive G) :=
AddEquiv.piAdditive fun _ ↦ G
section
variable (G) (H)
/-- `Additive (Multiplicative G)` is just `G`. -/
@[simps!]
def AddEquiv.additiveMultiplicative [AddZeroClass G] : Additive (Multiplicative G) ≃+ G :=
MulEquiv.toAdditiveLeft (MulEquiv.refl (Multiplicative G))
/-- `Multiplicative (Additive H)` is just `H`. -/
@[simps!]
def MulEquiv.multiplicativeAdditive [MulOneClass H] : Multiplicative (Additive H) ≃* H :=
AddEquiv.toMultiplicativeLeft (AddEquiv.refl (Additive H))
/-- `Multiplicative (G × H)` is equivalent to `Multiplicative G × Multiplicative H`. -/
@[simps]
def MulEquiv.prodMultiplicative [Add G] [Add H] :
Multiplicative (G × H) ≃* Multiplicative G × Multiplicative H where
toFun x := (Multiplicative.ofAdd x.toAdd.1,
Multiplicative.ofAdd x.toAdd.2)
invFun := fun (x, y) ↦ Multiplicative.ofAdd (x.toAdd, y.toAdd)
map_mul' _ _ := rfl
/-- `Additive (G × H)` is equivalent to `Additive G × Additive H`. -/
@[simps]
def AddEquiv.prodAdditive [Mul G] [Mul H] :
Additive (G × H) ≃+ Additive G × Additive H where
toFun x := (Additive.ofMul x.toMul.1,
Additive.ofMul x.toMul.2)
invFun := fun (x, y) ↦ Additive.ofMul (x.toMul, y.toMul)
map_add' _ _ := rfl
end
section End
variable {M : Type*}
/-- `Monoid.End M` is equivalent to `AddMonoid.End (Additive M)`. -/
@[simps! apply]
def MulEquiv.Monoid.End [Monoid M] : Monoid.End M ≃* AddMonoid.End (Additive M) where
__ := MonoidHom.toAdditive
map_mul' := fun _ _ ↦ rfl
/-- `AddMonoid.End M` is equivalent to `Monoid.End (Multiplicative M)`. -/
@[simps! apply]
def MulEquiv.AddMonoid.End [AddMonoid M] :
AddMonoid.End M ≃* _root_.Monoid.End (Multiplicative M) where
__ := AddMonoidHom.toMultiplicative
map_mul' := fun _ _ ↦ rfl
end End |
.lake/packages/mathlib/Mathlib/Algebra/Group/Nat/Defs.lean | import Mathlib.Algebra.Group.Defs
/-!
# The natural numbers form a monoid
This file contains the additive and multiplicative monoid instances on the natural numbers.
See note [foundational algebra order theory].
-/
assert_not_exists MonoidWithZero DenselyOrdered
namespace Nat
/-! ### Instances -/
instance instMulOneClass : MulOneClass ℕ where
one_mul := Nat.one_mul
mul_one := Nat.mul_one
instance instAddCancelCommMonoid : AddCancelCommMonoid ℕ where
add := Nat.add
add_assoc := Nat.add_assoc
zero := Nat.zero
zero_add := Nat.zero_add
add_zero := Nat.add_zero
add_comm := Nat.add_comm
nsmul m n := m * n
nsmul_zero := Nat.zero_mul
nsmul_succ := succ_mul
add_left_cancel _ _ _ := Nat.add_left_cancel
instance instCommMonoid : CommMonoid ℕ where
mul := Nat.mul
mul_assoc := Nat.mul_assoc
one := Nat.succ Nat.zero
one_mul := Nat.one_mul
mul_one := Nat.mul_one
mul_comm := Nat.mul_comm
npow m n := n ^ m
npow_zero := Nat.pow_zero
npow_succ _ _ := rfl
/-!
### Extra instances to short-circuit type class resolution
These also prevent non-computable instances being used to construct these instances non-computably.
-/
set_option linter.style.commandStart false
instance instAddCommMonoid : AddCommMonoid ℕ := by infer_instance
instance instAddMonoid : AddMonoid ℕ := by infer_instance
instance instMonoid : Monoid ℕ := by infer_instance
instance instCommSemigroup : CommSemigroup ℕ := by infer_instance
instance instSemigroup : Semigroup ℕ := by infer_instance
instance instAddCommSemigroup : AddCommSemigroup ℕ := by infer_instance
instance instAddSemigroup : AddSemigroup ℕ := by infer_instance
instance instOne : One ℕ := inferInstance
instance instIsAddTorsionFree : IsAddTorsionFree ℕ where
nsmul_right_injective _n hn _x _y hxy := Nat.mul_left_cancel (Nat.pos_of_ne_zero hn) hxy
set_option linter.style.commandStart true
/-! ### Miscellaneous lemmas -/
-- We set the simp priority slightly lower than default; later more general lemmas will replace it.
@[simp 900] protected lemma nsmul_eq_mul (m n : ℕ) : m • n = m * n := rfl
end Nat |
.lake/packages/mathlib/Mathlib/Algebra/Group/Nat/Even.lean | import Mathlib.Algebra.Group.Even
import Mathlib.Algebra.Group.Nat.Defs
import Mathlib.Data.Nat.Sqrt
/-!
# `IsSquare` and `Even` for natural numbers
-/
assert_not_exists MonoidWithZero DenselyOrdered
namespace Nat
/-! #### Parity -/
variable {m n : ℕ}
@[grind =]
lemma even_iff : Even n ↔ n % 2 = 0 where
mp := fun ⟨m, hm⟩ ↦ by simp [← Nat.two_mul, hm]
mpr h := ⟨n / 2, by grind⟩
instance : DecidablePred (Even : ℕ → Prop) := fun _ ↦ decidable_of_iff _ even_iff.symm
/-- `IsSquare` can be decided on `ℕ` by checking against the square root. -/
instance : DecidablePred (IsSquare : ℕ → Prop) :=
fun m ↦ decidable_of_iff' (Nat.sqrt m * Nat.sqrt m = m) <| by
simp_rw [← Nat.exists_mul_self m, IsSquare, eq_comm]
lemma not_even_iff : ¬ Even n ↔ n % 2 = 1 := by grind
@[simp] lemma two_dvd_ne_zero : ¬2 ∣ n ↔ n % 2 = 1 := by grind
@[simp] lemma not_even_one : ¬Even 1 := by grind
@[parity_simps, grind =] lemma even_add : Even (m + n) ↔ (Even m ↔ Even n) := by grind
@[parity_simps] lemma even_add_one : Even (n + 1) ↔ ¬Even n := by grind
lemma succ_mod_two_eq_zero_iff : (m + 1) % 2 = 0 ↔ m % 2 = 1 := by cutsat
lemma succ_mod_two_eq_one_iff : (m + 1) % 2 = 1 ↔ m % 2 = 0 := by cutsat
lemma two_not_dvd_two_mul_add_one (n : ℕ) : ¬2 ∣ 2 * n + 1 := by cutsat
lemma two_not_dvd_two_mul_sub_one {n} : 0 < n → ¬2 ∣ 2 * n - 1 := by cutsat
@[parity_simps] lemma even_sub (h : n ≤ m) : Even (m - n) ↔ (Even m ↔ Even n) := by grind
@[parity_simps, grind =] lemma even_mul : Even (m * n) ↔ Even m ∨ Even n := by
rcases mod_two_eq_zero_or_one m with h₁ | h₁ <;> rcases mod_two_eq_zero_or_one n with h₂ | h₂ <;>
simp [even_iff, h₁, h₂, Nat.mul_mod]
/-- If `m` and `n` are natural numbers, then the natural number `m^n` is even
if and only if `m` is even and `n` is positive. -/
@[parity_simps, grind =] lemma even_pow : Even (m ^ n) ↔ Even m ∧ n ≠ 0 := by
induction n with grind
lemma even_pow' (h : n ≠ 0) : Even (m ^ n) ↔ Even m := by grind
lemma even_mul_succ_self (n : ℕ) : Even (n * (n + 1)) := by grind
lemma even_mul_pred_self (n : ℕ) : Even (n * (n - 1)) := by grind
lemma two_mul_div_two_of_even : Even n → 2 * (n / 2) = n := fun h ↦
Nat.mul_div_cancel_left' ((even_iff_exists_two_nsmul _).1 h)
lemma div_two_mul_two_of_even : Even n → n / 2 * 2 = n :=
fun h ↦ Nat.div_mul_cancel ((even_iff_exists_two_nsmul _).1 h)
theorem one_lt_of_ne_zero_of_even (h0 : n ≠ 0) (hn : Even n) : 1 < n := by grind
theorem add_one_lt_of_even (hn : Even n) (hm : Even m) (hnm : n < m) :
n + 1 < m := by grind
-- Here are examples of how `parity_simps` can be used with `Nat`.
example (m n : ℕ) (h : Even m) : ¬Even (n + 3) ↔ Even (m ^ 2 + m + n) := by simp [*, parity_simps]
example : ¬Even 25394535 := by decide
end Nat |
.lake/packages/mathlib/Mathlib/Algebra/Group/Nat/TypeTags.lean | import Mathlib.Algebra.Group.Nat.Defs
import Mathlib.Algebra.Group.TypeTags.Basic
/-!
# Lemmas about `Multiplicative ℕ`
-/
assert_not_exists MonoidWithZero DenselyOrdered
open Multiplicative
namespace Nat
lemma toAdd_pow (a : Multiplicative ℕ) (b : ℕ) : (a ^ b).toAdd = a.toAdd * b := mul_comm _ _
@[simp] lemma ofAdd_mul (a b : ℕ) : ofAdd (a * b) = ofAdd a ^ b := (toAdd_pow _ _).symm
end Nat |
.lake/packages/mathlib/Mathlib/Algebra/Group/Nat/Range.lean | import Mathlib.Algebra.Group.Embedding
import Mathlib.Algebra.Group.Nat.Defs
import Mathlib.Data.Finset.Image
/-!
# `Finset.range` and addition of natural numbers
-/
assert_not_exists MonoidWithZero MulAction IsOrderedMonoid
variable {α β γ : Type*}
namespace Finset
theorem disjoint_range_addLeftEmbedding (a : ℕ) (s : Finset ℕ) :
Disjoint (range a) (map (addLeftEmbedding a) s) := by
simp_rw [disjoint_left, mem_map, mem_range, addLeftEmbedding_apply]
rintro _ h ⟨l, -, rfl⟩
cutsat
theorem disjoint_range_addRightEmbedding (a : ℕ) (s : Finset ℕ) :
Disjoint (range a) (map (addRightEmbedding a) s) := by
rw [← addLeftEmbedding_eq_addRightEmbedding]
apply disjoint_range_addLeftEmbedding
theorem range_add (a b : ℕ) : range (a + b) = range a ∪ (range b).map (addLeftEmbedding a) := by
rw [← val_inj, union_val]
exact Multiset.range_add_eq_union a b
end Finset |
.lake/packages/mathlib/Mathlib/Algebra/Group/Nat/Units.lean | import Mathlib.Algebra.Group.Nat.Defs
import Mathlib.Algebra.Group.Units.Defs
import Mathlib.Logic.Unique
/-!
# The unit of the natural numbers
-/
assert_not_exists MonoidWithZero DenselyOrdered
namespace Nat
/-! #### Units -/
lemma units_eq_one (u : ℕˣ) : u = 1 := Units.ext <| Nat.eq_one_of_dvd_one ⟨u.inv, u.val_inv.symm⟩
lemma addUnits_eq_zero (u : AddUnits ℕ) : u = 0 :=
AddUnits.ext <| (Nat.eq_zero_of_add_eq_zero u.val_neg).1
instance unique_units : Unique ℕˣ where
default := 1
uniq := Nat.units_eq_one
instance unique_addUnits : Unique (AddUnits ℕ) where
default := 0
uniq := Nat.addUnits_eq_zero
/-- Alias of `isUnit_iff_eq_one` for discoverability. -/
protected lemma isUnit_iff {n : ℕ} : IsUnit n ↔ n = 1 := isUnit_iff_eq_one
/-- Alias of `isAddUnit_iff_eq_zero` for discoverability. -/
protected lemma isAddUnit_iff {n : ℕ} : IsAddUnit n ↔ n = 0 := isAddUnit_iff_eq_zero
end Nat |
.lake/packages/mathlib/Mathlib/Algebra/Group/Nat/Hom.lean | import Mathlib.Algebra.Group.Nat.Defs
import Mathlib.Algebra.Group.TypeTags.Hom
import Mathlib.Tactic.Spread
/-!
# Extensionality of monoid homs from `ℕ`
-/
assert_not_exists IsOrderedMonoid MonoidWithZero
open Additive Multiplicative
variable {M : Type*}
section AddMonoidHomClass
variable {A B F : Type*} [FunLike F ℕ A]
lemma ext_nat' [AddZeroClass A] [AddMonoidHomClass F ℕ A] (f g : F) (h : f 1 = g 1) : f = g :=
DFunLike.ext f g <| by
intro n
induction n with
| zero => simp_rw [map_zero f, map_zero g]
| succ n ihn =>
simp [h, ihn]
@[ext]
lemma AddMonoidHom.ext_nat [AddZeroClass A] {f g : ℕ →+ A} : f 1 = g 1 → f = g :=
ext_nat' f g
end AddMonoidHomClass
section AddMonoid
variable [AddMonoid M]
variable (M) in
/-- Additive homomorphisms from `ℕ` are defined by the image of `1`. -/
def multiplesHom : M ≃ (ℕ →+ M) where
toFun x :=
{ toFun := fun n ↦ n • x
map_zero' := zero_nsmul x
map_add' := fun _ _ ↦ add_nsmul _ _ _ }
invFun f := f 1
left_inv := one_nsmul
right_inv f := AddMonoidHom.ext_nat <| one_nsmul (f 1)
@[simp] lemma multiplesHom_apply (x : M) (n : ℕ) : multiplesHom M x n = n • x := rfl
@[simp] lemma multiplesHom_symm_apply (f : ℕ →+ M) : (multiplesHom M).symm f = f 1 := rfl
lemma AddMonoidHom.apply_nat (f : ℕ →+ M) (n : ℕ) : f n = n • f 1 := by
rw [← multiplesHom_symm_apply, ← multiplesHom_apply, Equiv.apply_symm_apply]
end AddMonoid
section Monoid
variable [Monoid M]
variable (M) in
/-- Monoid homomorphisms from `Multiplicative ℕ` are defined by the image
of `Multiplicative.ofAdd 1`. -/
def powersHom : M ≃ (Multiplicative ℕ →* M) :=
Additive.ofMul.trans <| (multiplesHom _).trans <| AddMonoidHom.toMultiplicativeLeft
@[simp] lemma powersHom_apply (x : M) (n : Multiplicative ℕ) :
powersHom M x n = x ^ n.toAdd := rfl
@[simp] lemma powersHom_symm_apply (f : Multiplicative ℕ →* M) :
(powersHom M).symm f = f (Multiplicative.ofAdd 1) := rfl
lemma MonoidHom.apply_mnat (f : Multiplicative ℕ →* M) (n : Multiplicative ℕ) :
f n = f (Multiplicative.ofAdd 1) ^ n.toAdd := by
rw [← powersHom_symm_apply, ← powersHom_apply, Equiv.apply_symm_apply]
@[ext]
lemma MonoidHom.ext_mnat ⦃f g : Multiplicative ℕ →* M⦄
(h : f (Multiplicative.ofAdd 1) = g (Multiplicative.ofAdd 1)) : f = g :=
MonoidHom.ext fun n ↦ by rw [f.apply_mnat, g.apply_mnat, h]
end Monoid
section AddCommMonoid
variable [AddCommMonoid M]
variable (M) in
/-- If `M` is commutative, `multiplesHom` is an additive equivalence. -/
def multiplesAddHom : M ≃+ (ℕ →+ M) where
__ := multiplesHom M
map_add' a b := AddMonoidHom.ext fun n ↦ by simp [nsmul_add]
@[simp] lemma multiplesAddHom_apply (x : M) (n : ℕ) : multiplesAddHom M x n = n • x := rfl
@[simp] lemma multiplesAddHom_symm_apply (f : ℕ →+ M) : (multiplesAddHom M).symm f = f 1 := rfl
end AddCommMonoid
section CommMonoid
variable [CommMonoid M]
variable (M) in
/-- If `M` is commutative, `powersHom` is a multiplicative equivalence. -/
def powersMulHom : M ≃* (Multiplicative ℕ →* M) where
__ := powersHom M
map_mul' a b := MonoidHom.ext fun n ↦ by simp [mul_pow]
@[simp]
lemma powersMulHom_apply (x : M) (n : Multiplicative ℕ) : powersMulHom M x n = x ^ n.toAdd := rfl
@[simp]
lemma powersMulHom_symm_apply (f : Multiplicative ℕ →* M) : (powersMulHom M).symm f = f (ofAdd 1) :=
rfl
end CommMonoid |
.lake/packages/mathlib/Mathlib/Algebra/Group/Submonoid/Finite.lean | import Mathlib.Algebra.Group.Submonoid.Operations
import Mathlib.Data.Fintype.Basic
/-!
# Submonoids
This file provides some results on multiplicative and additive submonoids in the finite context.
-/
namespace Submonoid
section Pi
variable {η : Type*} {f : η → Type*} [∀ i, MulOneClass (f i)]
variable {S : Type*} [SetLike S (Π i, f i)] [SubmonoidClass S (Π i, f i)]
open Set
@[to_additive]
theorem pi_mem_of_mulSingle_mem_aux [DecidableEq η] (I : Finset η) {H : S} (x : Π i, f i)
(h1 : ∀ i, i ∉ I → x i = 1) (h2 : ∀ i, i ∈ I → Pi.mulSingle i (x i) ∈ H) : x ∈ H := by
induction I using Finset.induction_on generalizing x with
| empty =>
have : x = 1 := funext fun i => h1 i (Finset.notMem_empty i)
exact this ▸ one_mem H
| insert i I hnotMem ih =>
have : x = Function.update x i 1 * Pi.mulSingle i (x i) := by
ext j
by_cases heq : j = i
· subst heq
simp
· simp [heq]
rw [this]
clear this
apply mul_mem (ih _ _ _) (by simp [h2]) <;> clear ih <;> intro j hj
· by_cases heq : j = i
· subst heq
simp
· simpa [heq] using h1 j (by simpa [heq] using hj)
· have : j ≠ i := fun h => h ▸ hnotMem <| hj
simp only [ne_eq, this, not_false_eq_true, Function.update_of_ne]
exact h2 _ (Finset.mem_insert_of_mem hj)
@[to_additive]
theorem pi_mem_of_mulSingle_mem [Finite η] [DecidableEq η] {H : S} (x : Π i, f i)
(h : ∀ i, Pi.mulSingle i (x i) ∈ H) : x ∈ H := by
cases nonempty_fintype η
exact pi_mem_of_mulSingle_mem_aux Finset.univ x (by simp) fun i _ => h i
/-- For finite index types, the `Submonoid.pi` is generated by the embeddings of the monoids. -/
@[to_additive /-- For finite index types, the `Submonoid.pi` is generated by the embeddings of the
additive monoids. -/]
theorem pi_le_iff [Finite η] [DecidableEq η] {H : Π i, Submonoid (f i)} {J : Submonoid (Π i, f i)} :
pi univ H ≤ J ↔ ∀ i : η, map (MonoidHom.mulSingle f i) (H i) ≤ J :=
⟨fun h i _ ⟨x, hx, H⟩ => h <| by simpa [← H],
fun h x hx => pi_mem_of_mulSingle_mem x fun i => h i (mem_map_of_mem _ (hx i trivial))⟩
@[to_additive]
theorem closure_pi [Finite η] {s : Π i, Set (f i)} (hs : ∀ i, 1 ∈ s i) :
closure (univ.pi fun i => s i) = pi univ fun i => closure (s i) :=
le_antisymm
(closure_le.2 <| pi_subset_pi_iff.2 <| .inl fun _ _ => subset_closure)
(by
classical
exact pi_le_iff.mpr fun i => map_le_of_le_comap _ <| closure_le.2 fun _x hx =>
subset_closure <| mem_univ_pi.mpr fun j => by
by_cases H : j = i
· subst H
simpa
· simpa [H] using hs _)
end Pi
end Submonoid |
.lake/packages/mathlib/Mathlib/Algebra/Group/Submonoid/MulOpposite.lean | import Mathlib.Algebra.Group.Opposite
import Mathlib.Algebra.Group.Submonoid.Basic
/-!
# Submonoid of opposite monoids
For every monoid `M`, we construct an equivalence between submonoids of `M` and that of `Mᵐᵒᵖ`.
-/
assert_not_exists MonoidWithZero
variable {ι : Sort*} {M : Type*} [MulOneClass M]
namespace Submonoid
/-- Pull a submonoid back to an opposite submonoid along `MulOpposite.unop` -/
@[to_additive (attr := simps) /-- Pull an additive submonoid back to an opposite submonoid along
`AddOpposite.unop` -/]
protected def op (x : Submonoid M) : Submonoid Mᵐᵒᵖ where
carrier := MulOpposite.unop ⁻¹' x
mul_mem' ha hb := x.mul_mem hb ha
one_mem' := Submonoid.one_mem' _
@[to_additive (attr := simp)]
theorem mem_op {x : Mᵐᵒᵖ} {S : Submonoid M} : x ∈ S.op ↔ x.unop ∈ S := Iff.rfl
/-- Pull an opposite submonoid back to a submonoid along `MulOpposite.op` -/
@[to_additive (attr := simps) /-- Pull an opposite additive submonoid back to a submonoid along
`AddOpposite.op` -/]
protected def unop (x : Submonoid Mᵐᵒᵖ) : Submonoid M where
carrier := MulOpposite.op ⁻¹' x
mul_mem' ha hb := x.mul_mem hb ha
one_mem' := Submonoid.one_mem' _
@[to_additive (attr := simp)]
theorem mem_unop {x : M} {S : Submonoid Mᵐᵒᵖ} : x ∈ S.unop ↔ MulOpposite.op x ∈ S := Iff.rfl
@[to_additive (attr := simp)]
theorem unop_op (S : Submonoid M) : S.op.unop = S := rfl
@[to_additive (attr := simp)]
theorem op_unop (S : Submonoid Mᵐᵒᵖ) : S.unop.op = S := rfl
/-! ### Lattice results -/
@[to_additive]
theorem op_le_iff {S₁ : Submonoid M} {S₂ : Submonoid Mᵐᵒᵖ} : S₁.op ≤ S₂ ↔ S₁ ≤ S₂.unop :=
MulOpposite.op_surjective.forall
@[to_additive]
theorem le_op_iff {S₁ : Submonoid Mᵐᵒᵖ} {S₂ : Submonoid M} : S₁ ≤ S₂.op ↔ S₁.unop ≤ S₂ :=
MulOpposite.op_surjective.forall
@[to_additive (attr := simp)]
theorem op_le_op_iff {S₁ S₂ : Submonoid M} : S₁.op ≤ S₂.op ↔ S₁ ≤ S₂ :=
MulOpposite.op_surjective.forall
@[to_additive (attr := simp)]
theorem unop_le_unop_iff {S₁ S₂ : Submonoid Mᵐᵒᵖ} : S₁.unop ≤ S₂.unop ↔ S₁ ≤ S₂ :=
MulOpposite.unop_surjective.forall
/-- A submonoid `H` of `G` determines a submonoid `H.op` of the opposite group `Gᵐᵒᵖ`. -/
@[to_additive (attr := simps) /-- A additive submonoid `H` of `G` determines an additive submonoid
`H.op` of the opposite group `Gᵐᵒᵖ`. -/]
def opEquiv : Submonoid M ≃o Submonoid Mᵐᵒᵖ where
toFun := Submonoid.op
invFun := Submonoid.unop
left_inv := unop_op
right_inv := op_unop
map_rel_iff' := op_le_op_iff
@[to_additive]
theorem op_injective : (@Submonoid.op M _).Injective := opEquiv.injective
@[to_additive]
theorem unop_injective : (@Submonoid.unop M _).Injective := opEquiv.symm.injective
@[to_additive (attr := simp)]
theorem op_inj {S T : Submonoid M} : S.op = T.op ↔ S = T := opEquiv.eq_iff_eq
@[to_additive (attr := simp)]
theorem unop_inj {S T : Submonoid Mᵐᵒᵖ} : S.unop = T.unop ↔ S = T := opEquiv.symm.eq_iff_eq
@[to_additive (attr := simp)]
theorem op_bot : (⊥ : Submonoid M).op = ⊥ := opEquiv.map_bot
@[to_additive (attr := simp)]
theorem op_eq_bot {S : Submonoid M} : S.op = ⊥ ↔ S = ⊥ := op_injective.eq_iff' op_bot
@[to_additive (attr := simp)]
theorem unop_bot : (⊥ : Submonoid Mᵐᵒᵖ).unop = ⊥ := opEquiv.symm.map_bot
@[to_additive (attr := simp)]
theorem unop_eq_bot {S : Submonoid Mᵐᵒᵖ} : S.unop = ⊥ ↔ S = ⊥ := unop_injective.eq_iff' unop_bot
@[to_additive (attr := simp)]
theorem op_top : (⊤ : Submonoid M).op = ⊤ := rfl
@[to_additive (attr := simp)]
theorem op_eq_top {S : Submonoid M} : S.op = ⊤ ↔ S = ⊤ := op_injective.eq_iff' op_top
@[to_additive (attr := simp)]
theorem unop_top : (⊤ : Submonoid Mᵐᵒᵖ).unop = ⊤ := rfl
@[to_additive (attr := simp)]
theorem unop_eq_top {S : Submonoid Mᵐᵒᵖ} : S.unop = ⊤ ↔ S = ⊤ := unop_injective.eq_iff' unop_top
@[to_additive]
theorem op_sup (S₁ S₂ : Submonoid M) : (S₁ ⊔ S₂).op = S₁.op ⊔ S₂.op :=
opEquiv.map_sup _ _
@[to_additive]
theorem unop_sup (S₁ S₂ : Submonoid Mᵐᵒᵖ) : (S₁ ⊔ S₂).unop = S₁.unop ⊔ S₂.unop :=
opEquiv.symm.map_sup _ _
@[to_additive]
theorem op_inf (S₁ S₂ : Submonoid M) : (S₁ ⊓ S₂).op = S₁.op ⊓ S₂.op := rfl
@[to_additive]
theorem unop_inf (S₁ S₂ : Submonoid Mᵐᵒᵖ) : (S₁ ⊓ S₂).unop = S₁.unop ⊓ S₂.unop := rfl
@[to_additive]
theorem op_sSup (S : Set (Submonoid M)) : (sSup S).op = sSup (.unop ⁻¹' S) :=
opEquiv.map_sSup_eq_sSup_symm_preimage _
@[to_additive]
theorem unop_sSup (S : Set (Submonoid Mᵐᵒᵖ)) : (sSup S).unop = sSup (.op ⁻¹' S) :=
opEquiv.symm.map_sSup_eq_sSup_symm_preimage _
@[to_additive]
theorem op_sInf (S : Set (Submonoid M)) : (sInf S).op = sInf (.unop ⁻¹' S) :=
opEquiv.map_sInf_eq_sInf_symm_preimage _
@[to_additive]
theorem unop_sInf (S : Set (Submonoid Mᵐᵒᵖ)) : (sInf S).unop = sInf (.op ⁻¹' S) :=
opEquiv.symm.map_sInf_eq_sInf_symm_preimage _
@[to_additive]
theorem op_iSup (S : ι → Submonoid M) : (iSup S).op = ⨆ i, (S i).op := opEquiv.map_iSup _
@[to_additive]
theorem unop_iSup (S : ι → Submonoid Mᵐᵒᵖ) : (iSup S).unop = ⨆ i, (S i).unop :=
opEquiv.symm.map_iSup _
@[to_additive]
theorem op_iInf (S : ι → Submonoid M) : (iInf S).op = ⨅ i, (S i).op := opEquiv.map_iInf _
@[to_additive]
theorem unop_iInf (S : ι → Submonoid Mᵐᵒᵖ) : (iInf S).unop = ⨅ i, (S i).unop :=
opEquiv.symm.map_iInf _
@[to_additive]
theorem op_closure (s : Set M) : (closure s).op = closure (MulOpposite.unop ⁻¹' s) := by
simp_rw [closure, op_sInf, Set.preimage_setOf_eq, Submonoid.coe_unop]
congr with a
exact MulOpposite.unop_surjective.forall
@[to_additive]
theorem unop_closure (s : Set Mᵐᵒᵖ) : (closure s).unop = closure (MulOpposite.op ⁻¹' s) := by
rw [← op_inj, op_unop, op_closure]
simp_rw [Set.preimage_preimage, MulOpposite.op_unop, Set.preimage_id']
/-- Bijection between a submonoid `H` and its opposite. -/
@[to_additive (attr := simps!) /-- Bijection between an additive submonoid `H` and its opposite. -/]
def equivOp (H : Submonoid M) : H ≃ H.op :=
MulOpposite.opEquiv.subtypeEquiv fun _ => Iff.rfl
end Submonoid |
.lake/packages/mathlib/Mathlib/Algebra/Group/Submonoid/Pointwise.lean | import Mathlib.Algebra.Group.Action.Pointwise.Set.Basic
import Mathlib.Algebra.Group.Submonoid.Membership
import Mathlib.Algebra.Order.BigOperators.Group.List
import Mathlib.Order.WellFoundedSet
/-!
# Pointwise instances on `Submonoid`s and `AddSubmonoid`s
This file provides:
* `Submonoid.inv`
* `AddSubmonoid.neg`
and the actions
* `Submonoid.pointwiseMulAction`
* `AddSubmonoid.pointwiseAddAction`
which matches the action of `Set.mulActionSet`.
## Implementation notes
Most of the lemmas in this file are direct copies of lemmas from
`Mathlib/Algebra/Group/Pointwise/Set/Basic.lean` and
`Mathlib/Algebra/Group/Action/Pointwise/Set/Basic.lean`.
While the statements of these lemmas are defeq, we repeat them here due to them not being
syntactically equal. Before adding new lemmas here, consider if they would also apply to the action
on `Set`s.
-/
assert_not_exists GroupWithZero
open Set Pointwise
variable {α G M R A S : Type*}
variable [Monoid M] [AddMonoid A]
@[to_additive (attr := simp, norm_cast)]
lemma coe_mul_coe [SetLike S M] [SubmonoidClass S M] (H : S) : H * H = (H : Set M) := by
aesop (add simp mem_mul)
@[to_additive (attr := simp)]
lemma coe_set_pow [SetLike S M] [SubmonoidClass S M] :
∀ {n} (_ : n ≠ 0) (H : S), (H ^ n : Set M) = H
| 1, _, H => by simp
| n + 2, _, H => by rw [pow_succ, coe_set_pow n.succ_ne_zero, coe_mul_coe]
/-! Some lemmas about pointwise multiplication and submonoids. Ideally we put these in
`GroupTheory.Submonoid.Basic`, but currently we cannot because that file is imported by this. -/
namespace Submonoid
variable {s t u : Set M}
@[to_additive]
theorem mul_subset {S : Submonoid M} (hs : s ⊆ S) (ht : t ⊆ S) : s * t ⊆ S :=
mul_subset_iff.2 fun _x hx _y hy ↦ mul_mem (hs hx) (ht hy)
@[to_additive]
theorem mul_subset_closure (hs : s ⊆ u) (ht : t ⊆ u) : s * t ⊆ Submonoid.closure u :=
mul_subset (Subset.trans hs Submonoid.subset_closure) (Subset.trans ht Submonoid.subset_closure)
@[to_additive]
theorem coe_mul_self_eq (s : Submonoid M) : (s : Set M) * s = s := by
simp
@[to_additive]
theorem closure_mul_le (S T : Set M) : closure (S * T) ≤ closure S ⊔ closure T :=
sInf_le fun _x ⟨_s, hs, _t, ht, hx⟩ => hx ▸
(closure S ⊔ closure T).mul_mem (SetLike.le_def.mp le_sup_left <| subset_closure hs)
(SetLike.le_def.mp le_sup_right <| subset_closure ht)
@[to_additive]
lemma closure_pow_le : ∀ {n}, n ≠ 0 → closure (s ^ n) ≤ closure s
| 1, _ => by simp
| n + 2, _ =>
calc
closure (s ^ (n + 2))
_ = closure (s ^ (n + 1) * s) := by rw [pow_succ]
_ ≤ closure (s ^ (n + 1)) ⊔ closure s := closure_mul_le ..
_ ≤ closure s ⊔ closure s := by gcongr ?_ ⊔ _; exact closure_pow_le n.succ_ne_zero
_ = closure s := sup_idem _
@[to_additive]
lemma closure_pow {n : ℕ} (hs : 1 ∈ s) (hn : n ≠ 0) : closure (s ^ n) = closure s :=
(closure_pow_le hn).antisymm <| by gcongr; exact subset_pow hs hn
@[to_additive]
theorem sup_eq_closure_mul (H K : Submonoid M) : H ⊔ K = closure ((H : Set M) * (K : Set M)) :=
le_antisymm
(sup_le (fun h hh => subset_closure ⟨h, hh, 1, K.one_mem, mul_one h⟩) fun k hk =>
subset_closure ⟨1, H.one_mem, k, hk, one_mul k⟩)
((closure_mul_le _ _).trans <| by rw [closure_eq, closure_eq])
@[to_additive]
theorem coe_sup {N : Type*} [CommMonoid N] (H K : Submonoid N) :
↑(H ⊔ K) = (H * K : Set N) := by
ext x
simp [mem_sup, Set.mem_mul]
@[to_additive]
theorem pow_smul_mem_closure_smul {N : Type*} [CommMonoid N] [MulAction M N] [IsScalarTower M N N]
(r : M) (s : Set N) {x : N} (hx : x ∈ closure s) : ∃ n : ℕ, r ^ n • x ∈ closure (r • s) := by
induction hx using closure_induction with
| mem x hx => exact ⟨1, subset_closure ⟨_, hx, by rw [pow_one]⟩⟩
| one => exact ⟨0, by simp⟩
| mul x y _ _ hx hy =>
obtain ⟨⟨nx, hx⟩, ⟨ny, hy⟩⟩ := And.intro hx hy
use ny + nx
rw [pow_add, mul_smul, ← smul_mul_assoc, mul_comm, ← smul_mul_assoc]
exact mul_mem hy hx
variable [Group G]
/-- The submonoid with every element inverted. -/
@[to_additive /-- The additive submonoid with every element negated. -/]
protected def inv : Inv (Submonoid G) where
inv S :=
{ carrier := (S : Set G)⁻¹
mul_mem' := fun ha hb => by rw [mem_inv, mul_inv_rev]; exact mul_mem hb ha
one_mem' := mem_inv.2 <| by rw [inv_one]; exact S.one_mem' }
scoped[Pointwise] attribute [instance] Submonoid.inv AddSubmonoid.neg
@[to_additive (attr := simp)]
theorem coe_inv (S : Submonoid G) : ↑S⁻¹ = (S : Set G)⁻¹ :=
rfl
@[to_additive (attr := simp)]
theorem mem_inv {g : G} {S : Submonoid G} : g ∈ S⁻¹ ↔ g⁻¹ ∈ S :=
Iff.rfl
/-- Inversion is involutive on submonoids. -/
@[to_additive /-- Inversion is involutive on additive submonoids. -/]
def involutiveInv : InvolutiveInv (Submonoid G) :=
SetLike.coe_injective.involutiveInv _ fun _ => rfl
scoped[Pointwise] attribute [instance] Submonoid.involutiveInv AddSubmonoid.involutiveNeg
@[to_additive (attr := simp)]
theorem inv_le_inv (S T : Submonoid G) : S⁻¹ ≤ T⁻¹ ↔ S ≤ T :=
SetLike.coe_subset_coe.symm.trans Set.inv_subset_inv
@[to_additive]
theorem inv_le (S T : Submonoid G) : S⁻¹ ≤ T ↔ S ≤ T⁻¹ :=
SetLike.coe_subset_coe.symm.trans Set.inv_subset
/-- Pointwise inversion of submonoids as an order isomorphism. -/
@[to_additive (attr := simps!)
/-- Pointwise negation of additive submonoids as an order isomorphism -/]
def invOrderIso : Submonoid G ≃o Submonoid G where
toEquiv := Equiv.inv _
map_rel_iff' := inv_le_inv _ _
@[to_additive]
theorem closure_inv (s : Set G) : closure s⁻¹ = (closure s)⁻¹ := by
apply le_antisymm
· rw [closure_le, coe_inv, ← Set.inv_subset, inv_inv]
exact subset_closure
· rw [inv_le, closure_le, coe_inv, ← Set.inv_subset]
exact subset_closure
@[to_additive]
lemma mem_closure_inv (s : Set G) (x : G) : x ∈ closure s⁻¹ ↔ x⁻¹ ∈ closure s := by
rw [closure_inv, mem_inv]
@[to_additive (attr := simp)]
theorem inv_inf (S T : Submonoid G) : (S ⊓ T)⁻¹ = S⁻¹ ⊓ T⁻¹ :=
SetLike.coe_injective Set.inter_inv
@[to_additive (attr := simp)]
theorem inv_sup (S T : Submonoid G) : (S ⊔ T)⁻¹ = S⁻¹ ⊔ T⁻¹ :=
(invOrderIso : Submonoid G ≃o Submonoid G).map_sup S T
@[to_additive (attr := simp)]
theorem inv_bot : (⊥ : Submonoid G)⁻¹ = ⊥ :=
SetLike.coe_injective <| (Set.inv_singleton 1).trans <| congr_arg _ inv_one
@[to_additive (attr := simp)]
theorem inv_top : (⊤ : Submonoid G)⁻¹ = ⊤ :=
SetLike.coe_injective <| Set.inv_univ
@[to_additive (attr := simp)]
theorem inv_iInf {ι : Sort*} (S : ι → Submonoid G) : (⨅ i, S i)⁻¹ = ⨅ i, (S i)⁻¹ :=
(invOrderIso : Submonoid G ≃o Submonoid G).map_iInf _
@[to_additive (attr := simp)]
theorem inv_iSup {ι : Sort*} (S : ι → Submonoid G) : (⨆ i, S i)⁻¹ = ⨆ i, (S i)⁻¹ :=
(invOrderIso : Submonoid G ≃o Submonoid G).map_iSup _
end Submonoid
namespace Submonoid
section Monoid
variable [Monoid α] [MulDistribMulAction α M]
-- todo: add `to_additive`?
/-- The action on a submonoid corresponding to applying the action to every element.
This is available as an instance in the `Pointwise` locale. -/
protected def pointwiseMulAction : MulAction α (Submonoid M) where
smul a S := S.map (MulDistribMulAction.toMonoidEnd _ M a)
one_smul S := by
change S.map _ = S
simpa only [map_one] using S.map_id
mul_smul _ _ S :=
(congr_arg (fun f : Monoid.End M => S.map f) (MonoidHom.map_mul _ _ _)).trans
(S.map_map _ _).symm
scoped[Pointwise] attribute [instance] Submonoid.pointwiseMulAction
@[simp, norm_cast]
theorem coe_pointwise_smul (a : α) (S : Submonoid M) : ↑(a • S) = a • (S : Set M) :=
rfl
theorem smul_mem_pointwise_smul (m : M) (a : α) (S : Submonoid M) : m ∈ S → a • m ∈ a • S :=
(Set.smul_mem_smul_set : _ → _ ∈ a • (S : Set M))
instance : CovariantClass α (Submonoid M) HSMul.hSMul LE.le :=
⟨fun _ _ => image_mono⟩
theorem mem_smul_pointwise_iff_exists (m : M) (a : α) (S : Submonoid M) :
m ∈ a • S ↔ ∃ s : M, s ∈ S ∧ a • s = m :=
(Set.mem_smul_set : m ∈ a • (S : Set M) ↔ _)
@[simp]
theorem smul_bot (a : α) : a • (⊥ : Submonoid M) = ⊥ :=
map_bot _
theorem smul_sup (a : α) (S T : Submonoid M) : a • (S ⊔ T) = a • S ⊔ a • T :=
map_sup _ _ _
theorem smul_closure (a : α) (s : Set M) : a • closure s = closure (a • s) :=
MonoidHom.map_mclosure _ _
lemma pointwise_isCentralScalar [MulDistribMulAction αᵐᵒᵖ M] [IsCentralScalar α M] :
IsCentralScalar α (Submonoid M) :=
⟨fun _ S => (congr_arg fun f : Monoid.End M => S.map f) <| MonoidHom.ext <| op_smul_eq_smul _⟩
scoped[Pointwise] attribute [instance] Submonoid.pointwise_isCentralScalar
end Monoid
section Group
variable [Group α] [MulDistribMulAction α M]
@[simp]
theorem smul_mem_pointwise_smul_iff {a : α} {S : Submonoid M} {x : M} : a • x ∈ a • S ↔ x ∈ S :=
smul_mem_smul_set_iff
theorem mem_pointwise_smul_iff_inv_smul_mem {a : α} {S : Submonoid M} {x : M} :
x ∈ a • S ↔ a⁻¹ • x ∈ S :=
mem_smul_set_iff_inv_smul_mem
theorem mem_inv_pointwise_smul_iff {a : α} {S : Submonoid M} {x : M} : x ∈ a⁻¹ • S ↔ a • x ∈ S :=
mem_inv_smul_set_iff
@[simp]
theorem pointwise_smul_le_pointwise_smul_iff {a : α} {S T : Submonoid M} : a • S ≤ a • T ↔ S ≤ T :=
smul_set_subset_smul_set_iff
theorem pointwise_smul_subset_iff {a : α} {S T : Submonoid M} : a • S ≤ T ↔ S ≤ a⁻¹ • T :=
smul_set_subset_iff_subset_inv_smul_set
theorem subset_pointwise_smul_iff {a : α} {S T : Submonoid M} : S ≤ a • T ↔ a⁻¹ • S ≤ T :=
subset_smul_set_iff
end Group
end Submonoid
namespace Set.IsPWO
variable [CommMonoid α] [PartialOrder α] [IsOrderedCancelMonoid α] {s : Set α}
@[to_additive]
theorem submonoid_closure (hpos : ∀ x : α, x ∈ s → 1 ≤ x) (h : s.IsPWO) :
IsPWO (Submonoid.closure s : Set α) := by
rw [Submonoid.closure_eq_image_prod]
refine (h.partiallyWellOrderedOn_sublistForall₂ (· ≤ ·)).image_of_monotone_on ?_
exact fun l1 _ l2 hl2 h12 => h12.prod_le_prod' fun x hx => hpos x <| hl2 x hx
end Set.IsPWO |
.lake/packages/mathlib/Mathlib/Algebra/Group/Submonoid/Basic.lean | import Mathlib.Algebra.Group.Hom.Defs
import Mathlib.Algebra.Group.Submonoid.Defs
import Mathlib.Algebra.Group.Subsemigroup.Basic
import Mathlib.Algebra.Group.Units.Defs
/-!
# Submonoids: `CompleteLattice` structure
This file defines a `CompleteLattice` structure on `Submonoid`s, define the closure of a set as the
minimal submonoid that includes this set, and prove a few results about extending properties from a
dense set (i.e. a set with `closure s = ⊤`) to the whole monoid, see `Submonoid.dense_induction` and
`MonoidHom.ofClosureEqTopLeft`/`MonoidHom.ofClosureEqTopRight`.
## Main definitions
For each of the following definitions in the `Submonoid` namespace, there is a corresponding
definition in the `AddSubmonoid` namespace.
* `Submonoid.copy` : copy of a submonoid with `carrier` replaced by a set that is equal but possibly
not definitionally equal to the carrier of the original `Submonoid`.
* `Submonoid.closure` : monoid closure of a set, i.e., the least submonoid that includes the set.
* `Submonoid.gi` : `closure : Set M → Submonoid M` and coercion `coe : Submonoid M → Set M`
form a `GaloisInsertion`;
* `MonoidHom.eqLocus`: the submonoid of elements `x : M` such that `f x = g x`;
* `MonoidHom.ofClosureEqTopRight`: if a map `f : M → N` between two monoids satisfies
`f 1 = 1` and `f (x * y) = f x * f y` for `y` from some dense set `s`, then `f` is a monoid
homomorphism. E.g., if `f : ℕ → M` satisfies `f 0 = 0` and `f (x + 1) = f x + f 1`, then `f` is
an additive monoid homomorphism.
## Implementation notes
Submonoid inclusion is denoted `≤` rather than `⊆`, although `∈` is defined as
membership of a submonoid's underlying set.
Note that `Submonoid M` does not actually require `Monoid M`, instead requiring only the weaker
`MulOneClass M`.
This file is designed to have very few dependencies. In particular, it should not use natural
numbers. `Submonoid` is implemented by extending `Subsemigroup` requiring `one_mem'`.
## Tags
submonoid, submonoids
-/
assert_not_exists MonoidWithZero
variable {M : Type*} {N : Type*}
variable {A : Type*}
section NonAssoc
variable [MulOneClass M] {s : Set M}
variable [AddZeroClass A] {t : Set A}
namespace Submonoid
variable (S : Submonoid M)
@[to_additive]
instance : InfSet (Submonoid M) :=
⟨fun s =>
{ carrier := ⋂ t ∈ s, ↑t
one_mem' := Set.mem_biInter fun i _ => i.one_mem
mul_mem' := fun hx hy =>
Set.mem_biInter fun i h =>
i.mul_mem (by apply Set.mem_iInter₂.1 hx i h) (by apply Set.mem_iInter₂.1 hy i h) }⟩
@[to_additive (attr := simp, norm_cast)]
theorem coe_sInf (S : Set (Submonoid M)) : ((sInf S : Submonoid M) : Set M) = ⋂ s ∈ S, ↑s :=
rfl
@[to_additive]
theorem mem_sInf {S : Set (Submonoid M)} {x : M} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p :=
Set.mem_iInter₂
@[to_additive]
theorem mem_iInf {ι : Sort*} {S : ι → Submonoid M} {x : M} : (x ∈ ⨅ i, S i) ↔ ∀ i, x ∈ S i := by
simp only [iInf, mem_sInf, Set.forall_mem_range]
@[to_additive (attr := simp, norm_cast)]
theorem coe_iInf {ι : Sort*} {S : ι → Submonoid M} : (↑(⨅ i, S i) : Set M) = ⋂ i, S i := by
simp only [iInf, coe_sInf, Set.biInter_range]
/-- Submonoids of a monoid form a complete lattice. -/
@[to_additive /-- The `AddSubmonoid`s of an `AddMonoid` form a complete lattice. -/]
instance : CompleteLattice (Submonoid M) :=
{ (completeLatticeOfInf (Submonoid M)) fun _ =>
IsGLB.of_image (f := (SetLike.coe : Submonoid M → Set M))
(@fun S T => show (S : Set M) ≤ T ↔ S ≤ T from SetLike.coe_subset_coe)
isGLB_biInf with
le := (· ≤ ·)
lt := (· < ·)
bot := ⊥
bot_le := fun S _ hx => (mem_bot.1 hx).symm ▸ S.one_mem
top := ⊤
le_top := fun _ x _ => mem_top x
inf := (· ⊓ ·)
sInf := InfSet.sInf
le_inf := fun _ _ _ ha hb _ hx => ⟨ha hx, hb hx⟩
inf_le_left := fun _ _ _ => And.left
inf_le_right := fun _ _ _ => And.right }
/-- The `Submonoid` generated by a set. -/
@[to_additive /-- The `AddSubmonoid` generated by a set -/]
def closure (s : Set M) : Submonoid M :=
sInf { S | s ⊆ S }
@[to_additive]
theorem mem_closure {x : M} : x ∈ closure s ↔ ∀ S : Submonoid M, s ⊆ S → x ∈ S :=
mem_sInf
/-- The submonoid generated by a set includes the set. -/
@[to_additive (attr := simp, aesop safe 20 (rule_sets := [SetLike]))
/-- The `AddSubmonoid` generated by a set includes the set. -/]
theorem subset_closure : s ⊆ closure s := fun _ hx => mem_closure.2 fun _ hS => hS hx
@[to_additive (attr := aesop 80% (rule_sets := [SetLike]))]
theorem mem_closure_of_mem {s : Set M} {x : M} (hx : x ∈ s) : x ∈ closure s := subset_closure hx
@[to_additive]
theorem notMem_of_notMem_closure {P : M} (hP : P ∉ closure s) : P ∉ s := fun h =>
hP (subset_closure h)
@[deprecated (since := "2025-05-23")]
alias _root_.AddSubmonoid.not_mem_of_not_mem_closure := AddSubmonoid.notMem_of_notMem_closure
@[to_additive existing, deprecated (since := "2025-05-23")]
alias not_mem_of_not_mem_closure := notMem_of_notMem_closure
variable {S}
open Set
/-- A submonoid `S` includes `closure s` if and only if it includes `s`. -/
@[to_additive (attr := simp)
/-- An additive submonoid `S` includes `closure s` if and only if it includes `s`. -/]
theorem closure_le : closure s ≤ S ↔ s ⊆ S :=
⟨Subset.trans subset_closure, fun h => sInf_le h⟩
/-- Submonoid closure of a set is monotone in its argument: if `s ⊆ t`,
then `closure s ≤ closure t`. -/
@[to_additive (attr := gcongr)
/-- Additive submonoid closure of a set is monotone in its argument: if `s ⊆ t`,
then `closure s ≤ closure t`. -/]
theorem closure_mono ⦃s t : Set M⦄ (h : s ⊆ t) : closure s ≤ closure t :=
closure_le.2 <| Subset.trans h subset_closure
@[to_additive]
theorem closure_eq_of_le (h₁ : s ⊆ S) (h₂ : S ≤ closure s) : closure s = S :=
le_antisymm (closure_le.2 h₁) h₂
variable (S)
/-- An induction principle for closure membership. If `p` holds for `1` and all elements of `s`, and
is preserved under multiplication, then `p` holds for all elements of the closure of `s`. -/
@[to_additive (attr := elab_as_elim)
/-- An induction principle for additive closure membership. If `p` holds for `0` and all
elements of `s`, and is preserved under addition, then `p` holds for all elements of the
additive closure of `s`. -/]
theorem closure_induction {s : Set M} {motive : (x : M) → x ∈ closure s → Prop}
(mem : ∀ (x) (h : x ∈ s), motive x (subset_closure h)) (one : motive 1 (one_mem _))
(mul : ∀ x y hx hy, motive x hx → motive y hy → motive (x * y) (mul_mem hx hy)) {x}
(hx : x ∈ closure s) : motive x hx :=
let S : Submonoid M :=
{ carrier := { x | ∃ hx, motive x hx }
one_mem' := ⟨_, one⟩
mul_mem' := fun ⟨_, hpx⟩ ⟨_, hpy⟩ ↦ ⟨_, mul _ _ _ _ hpx hpy⟩ }
closure_le (S := S) |>.mpr (fun y hy ↦ ⟨subset_closure hy, mem y hy⟩) hx |>.elim fun _ ↦ id
/-- An induction principle for closure membership for predicates with two arguments. -/
@[to_additive (attr := elab_as_elim)
/-- An induction principle for additive closure membership for predicates with two arguments. -/]
theorem closure_induction₂ {motive : (x y : M) → x ∈ closure s → y ∈ closure s → Prop}
(mem : ∀ (x) (y) (hx : x ∈ s) (hy : y ∈ s), motive x y (subset_closure hx) (subset_closure hy))
(one_left : ∀ x hx, motive 1 x (one_mem _) hx) (one_right : ∀ x hx, motive x 1 hx (one_mem _))
(mul_left : ∀ x y z hx hy hz,
motive x z hx hz → motive y z hy hz → motive (x * y) z (mul_mem hx hy) hz)
(mul_right : ∀ x y z hx hy hz,
motive z x hz hx → motive z y hz hy → motive z (x * y) hz (mul_mem hx hy))
{x y : M} (hx : x ∈ closure s) (hy : y ∈ closure s) : motive x y hx hy := by
induction hy using closure_induction with
| mem z hz => induction hx using closure_induction with
| mem _ h => exact mem _ _ h hz
| one => exact one_left _ (subset_closure hz)
| mul _ _ _ _ h₁ h₂ => exact mul_left _ _ _ _ _ _ h₁ h₂
| one => exact one_right x hx
| mul _ _ _ _ h₁ h₂ => exact mul_right _ _ _ _ _ hx h₁ h₂
/-- If `s` is a dense set in a monoid `M`, `Submonoid.closure s = ⊤`, then in order to prove that
some predicate `p` holds for all `x : M` it suffices to verify `p x` for `x ∈ s`, verify `p 1`,
and verify that `p x` and `p y` imply `p (x * y)`. -/
@[to_additive (attr := elab_as_elim)
/-- If `s` is a dense set in an additive monoid `M`, `AddSubmonoid.closure s = ⊤`, then in
order to prove that some predicate `p` holds for all `x : M` it suffices to verify `p x` for
`x ∈ s`, verify `p 0`, and verify that `p x` and `p y` imply `p (x + y)`. -/]
theorem dense_induction {motive : M → Prop} (s : Set M) (closure : closure s = ⊤)
(mem : ∀ x ∈ s, motive x) (one : motive 1) (mul : ∀ x y, motive x → motive y → motive (x * y))
(x : M) : motive x := by
induction closure.symm ▸ mem_top x using closure_induction with
| mem _ h => exact mem _ h
| one => exact one
| mul _ _ _ _ h₁ h₂ => exact mul _ _ h₁ h₂
/- The argument `s : Set M` is explicit in `Submonoid.dense_induction` because the type of the
induction variable, namely `x : M`, does not reference `x`. Making `s` explicit allows the user
to apply the induction principle while deferring the proof of `closure s = ⊤` without creating
metavariables, as in the following example. -/
example {p : M → Prop} (s : Set M) (closure : closure s = ⊤) (mem : ∀ x ∈ s, p x)
(one : p 1) (mul : ∀ x y, p x → p y → p (x * y)) (x : M) : p x := by
induction x using dense_induction s with
| closure => exact closure
| mem x hx => exact mem x hx
| one => exact one
| mul _ _ h₁ h₂ => exact mul _ _ h₁ h₂
/-- The `Submonoid.closure` of a set is the union of `{1}` and its `Subsemigroup.closure`. -/
lemma closure_eq_one_union (s : Set M) :
closure s = {(1 : M)} ∪ (Subsemigroup.closure s : Set M) := by
apply le_antisymm
· intro x hx
induction hx using closure_induction with
| mem x hx => exact Or.inr <| Subsemigroup.subset_closure hx
| one => exact Or.inl <| by simp
| mul x hx y hy hx hy =>
simp only [singleton_union, mem_insert_iff, SetLike.mem_coe] at hx hy
obtain ⟨(rfl | hx), (rfl | hy)⟩ := And.intro hx hy
all_goals simp_all
exact Or.inr <| mul_mem hx hy
· rintro x (hx | hx)
· exact (show x = 1 by simpa using hx) ▸ one_mem (closure s)
· exact Subsemigroup.closure_le.mpr subset_closure hx
variable (M)
/-- `closure` forms a Galois insertion with the coercion to set. -/
@[to_additive /-- `closure` forms a Galois insertion with the coercion to set. -/]
protected def gi : GaloisInsertion (@closure M _) SetLike.coe where
choice s _ := closure s
gc _ _ := closure_le
le_l_u _ := subset_closure
choice_eq _ _ := rfl
variable {M}
/-- Closure of a submonoid `S` equals `S`. -/
@[to_additive (attr := simp) /-- Additive closure of an additive submonoid `S` equals `S` -/]
theorem closure_eq : closure (S : Set M) = S :=
(Submonoid.gi M).l_u_eq S
@[to_additive (attr := simp)]
theorem closure_empty : closure (∅ : Set M) = ⊥ :=
(Submonoid.gi M).gc.l_bot
@[to_additive (attr := simp)]
theorem closure_univ : closure (univ : Set M) = ⊤ :=
@coe_top M _ ▸ closure_eq ⊤
@[to_additive]
theorem closure_union (s t : Set M) : closure (s ∪ t) = closure s ⊔ closure t :=
(Submonoid.gi M).gc.l_sup
@[to_additive]
theorem sup_eq_closure (N N' : Submonoid M) : N ⊔ N' = closure ((N : Set M) ∪ (N' : Set M)) := by
simp_rw [closure_union, closure_eq]
@[to_additive]
theorem closure_iUnion {ι} (s : ι → Set M) : closure (⋃ i, s i) = ⨆ i, closure (s i) :=
(Submonoid.gi M).gc.l_iSup
@[to_additive]
theorem closure_singleton_le_iff_mem (m : M) (p : Submonoid M) : closure {m} ≤ p ↔ m ∈ p := by
rw [closure_le, singleton_subset_iff, SetLike.mem_coe]
@[to_additive (attr := simp)]
theorem closure_insert_one (s : Set M) : closure (insert 1 s) = closure s := by
rw [insert_eq, closure_union, sup_eq_right, closure_singleton_le_iff_mem]
apply one_mem
@[to_additive]
theorem mem_iSup {ι : Sort*} (p : ι → Submonoid M) {m : M} :
(m ∈ ⨆ i, p i) ↔ ∀ N, (∀ i, p i ≤ N) → m ∈ N := by
rw [← closure_singleton_le_iff_mem, le_iSup_iff]
simp only [closure_singleton_le_iff_mem]
@[to_additive]
theorem iSup_eq_closure {ι : Sort*} (p : ι → Submonoid M) :
⨆ i, p i = Submonoid.closure (⋃ i, (p i : Set M)) := by
simp_rw [Submonoid.closure_iUnion, Submonoid.closure_eq]
@[to_additive]
theorem disjoint_def {p₁ p₂ : Submonoid M} :
Disjoint p₁ p₂ ↔ ∀ {x : M}, x ∈ p₁ → x ∈ p₂ → x = 1 := by
simp_rw [disjoint_iff_inf_le, SetLike.le_def, mem_inf, and_imp, mem_bot]
@[to_additive]
theorem disjoint_def' {p₁ p₂ : Submonoid M} :
Disjoint p₁ p₂ ↔ ∀ {x y : M}, x ∈ p₁ → y ∈ p₂ → x = y → x = 1 :=
disjoint_def.trans ⟨fun h _ _ hx hy hxy => h hx <| hxy.symm ▸ hy, fun h _ hx hx' => h hx hx' rfl⟩
variable {t : Set M}
@[to_additive] -- this must not be a simp-lemma as the conclusion applies to `hts`, causing loops
lemma closure_sdiff_eq_closure (hts : t ⊆ closure (s \ t)) : closure (s \ t) = closure s := by
refine (closure_mono Set.diff_subset).antisymm <| closure_le.mpr <| fun x hxs ↦ ?_
by_cases hxt : x ∈ t
· exact hts hxt
· rw [SetLike.mem_coe, Submonoid.mem_closure]
exact fun N hN ↦ hN <| Set.mem_diff_of_mem hxs hxt
@[to_additive (attr := simp)]
lemma closure_sdiff_singleton_one (s : Set M) : closure (s \ {1}) = closure s :=
closure_sdiff_eq_closure <| by simp [one_mem]
end Submonoid
namespace MonoidHom
variable [MulOneClass N]
open Submonoid
/-- If two monoid homomorphisms are equal on a set, then they are equal on its submonoid closure. -/
@[to_additive
/-- If two monoid homomorphisms are equal on a set, then they are equal on its submonoid
closure. -/]
theorem eqOn_closureM {f g : M →* N} {s : Set M} (h : Set.EqOn f g s) : Set.EqOn f g (closure s) :=
show closure s ≤ f.eqLocusM g from closure_le.2 h
@[to_additive]
theorem eq_of_eqOn_denseM {s : Set M} (hs : closure s = ⊤) {f g : M →* N} (h : s.EqOn f g) :
f = g :=
eq_of_eqOn_topM <| hs ▸ eqOn_closureM h
end MonoidHom
end NonAssoc
section Assoc
variable [Monoid M] [Monoid N] {s : Set M}
section IsUnit
/-- The submonoid consisting of the units of a monoid -/
@[to_additive /-- The additive submonoid consisting of the additive units of an additive monoid -/]
def IsUnit.submonoid (M : Type*) [Monoid M] : Submonoid M where
carrier := setOf IsUnit
one_mem' := by simp only [isUnit_one, Set.mem_setOf_eq]
mul_mem' := by
intro a b ha hb
rw [Set.mem_setOf_eq] at *
exact IsUnit.mul ha hb
@[to_additive]
theorem IsUnit.mem_submonoid_iff {M : Type*} [Monoid M] (a : M) :
a ∈ IsUnit.submonoid M ↔ IsUnit a := by
change a ∈ setOf IsUnit ↔ IsUnit a
rw [Set.mem_setOf_eq]
end IsUnit
namespace MonoidHom
open Submonoid
/-- Let `s` be a subset of a monoid `M` such that the closure of `s` is the whole monoid.
Then `MonoidHom.ofClosureEqTopLeft` defines a monoid homomorphism from `M` asking for
a proof of `f (x * y) = f x * f y` only for `x ∈ s`. -/
@[to_additive
/-- Let `s` be a subset of an additive monoid `M` such that the closure of `s` is
the whole monoid. Then `AddMonoidHom.ofClosureEqTopLeft` defines an additive monoid
homomorphism from `M` asking for a proof of `f (x + y) = f x + f y` only for `x ∈ s`. -/]
def ofClosureMEqTopLeft {M N} [Monoid M] [Monoid N] {s : Set M} (f : M → N) (hs : closure s = ⊤)
(h1 : f 1 = 1) (hmul : ∀ x ∈ s, ∀ (y), f (x * y) = f x * f y) :
M →* N where
toFun := f
map_one' := h1
map_mul' x :=
dense_induction (motive := _) _ hs hmul fun y => by rw [one_mul, h1, one_mul]
(fun a b ha hb y => by rw [mul_assoc, ha, ha, hb, mul_assoc]) x
@[to_additive (attr := simp, norm_cast)]
theorem coe_ofClosureMEqTopLeft (f : M → N) (hs : closure s = ⊤) (h1 hmul) :
⇑(ofClosureMEqTopLeft f hs h1 hmul) = f :=
rfl
/-- Let `s` be a subset of a monoid `M` such that the closure of `s` is the whole monoid.
Then `MonoidHom.ofClosureEqTopRight` defines a monoid homomorphism from `M` asking for
a proof of `f (x * y) = f x * f y` only for `y ∈ s`. -/
@[to_additive
/-- Let `s` be a subset of an additive monoid `M` such that the closure of `s` is
the whole monoid. Then `AddMonoidHom.ofClosureEqTopRight` defines an additive monoid
homomorphism from `M` asking for a proof of `f (x + y) = f x + f y` only for `y ∈ s`. -/]
def ofClosureMEqTopRight {M N} [Monoid M] [Monoid N] {s : Set M} (f : M → N) (hs : closure s = ⊤)
(h1 : f 1 = 1) (hmul : ∀ (x), ∀ y ∈ s, f (x * y) = f x * f y) :
M →* N where
toFun := f
map_one' := h1
map_mul' x y :=
dense_induction _ hs (fun y hy x => hmul x y hy) (by simp [h1])
(fun y₁ y₂ (h₁ : ∀ _, f _ = f _ * f _) (h₂ : ∀ _, f _ = f _ * f _) x => by
simp [← mul_assoc, h₁, h₂]) y x
@[to_additive (attr := simp, norm_cast)]
theorem coe_ofClosureMEqTopRight (f : M → N) (hs : closure s = ⊤) (h1 hmul) :
⇑(ofClosureMEqTopRight f hs h1 hmul) = f :=
rfl
end MonoidHom
end Assoc |
.lake/packages/mathlib/Mathlib/Algebra/Group/Submonoid/Operations.lean | import Mathlib.Algebra.Group.Action.Faithful
import Mathlib.Algebra.Group.Nat.Defs
import Mathlib.Algebra.Group.Pi.Lemmas
import Mathlib.Algebra.Group.Prod
import Mathlib.Algebra.Group.Submonoid.Basic
import Mathlib.Algebra.Group.Submonoid.MulAction
import Mathlib.Algebra.Group.TypeTags.Basic
/-!
# Operations on `Submonoid`s
In this file we define various operations on `Submonoid`s and `MonoidHom`s.
## Main definitions
### Conversion between multiplicative and additive definitions
* `Submonoid.toAddSubmonoid`, `Submonoid.toAddSubmonoid'`, `AddSubmonoid.toSubmonoid`,
`AddSubmonoid.toSubmonoid'`: convert between multiplicative and additive submonoids of `M`,
`Multiplicative M`, and `Additive M`. These are stated as `OrderIso`s.
### (Commutative) monoid structure on a submonoid
* `Submonoid.toMonoid`, `Submonoid.toCommMonoid`: a submonoid inherits a (commutative) monoid
structure.
### Group actions by submonoids
* `Submonoid.MulAction`, `Submonoid.DistribMulAction`: a submonoid inherits (distributive)
multiplicative actions.
### Operations on submonoids
* `Submonoid.comap`: preimage of a submonoid under a monoid homomorphism as a submonoid of the
domain;
* `Submonoid.map`: image of a submonoid under a monoid homomorphism as a submonoid of the codomain;
* `Submonoid.prod`: product of two submonoids `s : Submonoid M` and `t : Submonoid N` as a submonoid
of `M × N`;
### Monoid homomorphisms between submonoid
* `Submonoid.subtype`: embedding of a submonoid into the ambient monoid.
* `Submonoid.inclusion`: given two submonoids `S`, `T` such that `S ≤ T`, `S.inclusion T` is the
inclusion of `S` into `T` as a monoid homomorphism;
* `MulEquiv.submonoidCongr`: converts a proof of `S = T` into a monoid isomorphism between `S`
and `T`.
* `Submonoid.prodEquiv`: monoid isomorphism between `s.prod t` and `s × t`;
### Operations on `MonoidHom`s
* `MonoidHom.mrange`: range of a monoid homomorphism as a submonoid of the codomain;
* `MonoidHom.mker`: kernel of a monoid homomorphism as a submonoid of the domain;
* `MonoidHom.restrict`: restrict a monoid homomorphism to a submonoid;
* `MonoidHom.codRestrict`: restrict the codomain of a monoid homomorphism to a submonoid;
* `MonoidHom.mrangeRestrict`: restrict a monoid homomorphism to its range;
## Tags
submonoid, range, product, map, comap
-/
assert_not_exists MonoidWithZero
open Function
variable {M N P : Type*} [MulOneClass M] [MulOneClass N] [MulOneClass P] (S : Submonoid M)
/-!
### Conversion to/from `Additive`/`Multiplicative`
-/
section
/-- Submonoids of monoid `M` are isomorphic to additive submonoids of `Additive M`. -/
@[simps]
def Submonoid.toAddSubmonoid : Submonoid M ≃o AddSubmonoid (Additive M) where
toFun S :=
{ carrier := Additive.toMul ⁻¹' S
zero_mem' := S.one_mem'
add_mem' := fun ha hb => S.mul_mem' ha hb }
invFun S :=
{ carrier := Additive.ofMul ⁻¹' S
one_mem' := S.zero_mem'
mul_mem' := fun ha hb => S.add_mem' ha hb}
left_inv x := by cases x; rfl
right_inv x := by cases x; rfl
map_rel_iff' := Iff.rfl
/-- Additive submonoids of an additive monoid `Additive M` are isomorphic to submonoids of `M`. -/
abbrev AddSubmonoid.toSubmonoid' : AddSubmonoid (Additive M) ≃o Submonoid M :=
Submonoid.toAddSubmonoid.symm
theorem Submonoid.toAddSubmonoid_closure (S : Set M) :
Submonoid.toAddSubmonoid (Submonoid.closure S)
= AddSubmonoid.closure (Additive.toMul ⁻¹' S) :=
le_antisymm
(Submonoid.toAddSubmonoid.le_symm_apply.1 <|
Submonoid.closure_le.2 (AddSubmonoid.subset_closure (M := Additive M)))
(AddSubmonoid.closure_le.2 <| Submonoid.subset_closure (M := M))
theorem AddSubmonoid.toSubmonoid'_closure (S : Set (Additive M)) :
AddSubmonoid.toSubmonoid' (AddSubmonoid.closure S)
= Submonoid.closure (Additive.ofMul ⁻¹' S) :=
le_antisymm
(AddSubmonoid.toSubmonoid'.le_symm_apply.1 <|
AddSubmonoid.closure_le.2 (Submonoid.subset_closure (M := M)))
(Submonoid.closure_le.2 <| AddSubmonoid.subset_closure (M := Additive M))
end
section
variable {A : Type*} [AddZeroClass A]
/-- Additive submonoids of an additive monoid `A` are isomorphic to
multiplicative submonoids of `Multiplicative A`. -/
@[simps]
def AddSubmonoid.toSubmonoid : AddSubmonoid A ≃o Submonoid (Multiplicative A) where
toFun S :=
{ carrier := Multiplicative.toAdd ⁻¹' S
one_mem' := S.zero_mem'
mul_mem' := fun ha hb => S.add_mem' ha hb }
invFun S :=
{ carrier := Multiplicative.ofAdd ⁻¹' S
zero_mem' := S.one_mem'
add_mem' := fun ha hb => S.mul_mem' ha hb}
left_inv x := by cases x; rfl
right_inv x := by cases x; rfl
map_rel_iff' := Iff.rfl
/-- Submonoids of a monoid `Multiplicative A` are isomorphic to additive submonoids of `A`. -/
abbrev Submonoid.toAddSubmonoid' : Submonoid (Multiplicative A) ≃o AddSubmonoid A :=
AddSubmonoid.toSubmonoid.symm
theorem AddSubmonoid.toSubmonoid_closure (S : Set A) :
(AddSubmonoid.toSubmonoid) (AddSubmonoid.closure S)
= Submonoid.closure (Multiplicative.toAdd ⁻¹' S) :=
le_antisymm
(AddSubmonoid.toSubmonoid.to_galoisConnection.l_le <|
AddSubmonoid.closure_le.2 <| Submonoid.subset_closure (M := Multiplicative A))
(Submonoid.closure_le.2 <| AddSubmonoid.subset_closure (M := A))
theorem Submonoid.toAddSubmonoid'_closure (S : Set (Multiplicative A)) :
Submonoid.toAddSubmonoid' (Submonoid.closure S)
= AddSubmonoid.closure (Multiplicative.ofAdd ⁻¹' S) :=
le_antisymm
(Submonoid.toAddSubmonoid'.to_galoisConnection.l_le <|
Submonoid.closure_le.2 <| AddSubmonoid.subset_closure (M := A))
(AddSubmonoid.closure_le.2 <| Submonoid.subset_closure (M := Multiplicative A))
end
namespace Submonoid
variable {F : Type*} [FunLike F M N] [mc : MonoidHomClass F M N]
open Set
/-!
### `comap` and `map`
-/
/-- The preimage of a submonoid along a monoid homomorphism is a submonoid. -/
@[to_additive
/-- The preimage of an `AddSubmonoid` along an `AddMonoid` homomorphism is an `AddSubmonoid`. -/]
def comap (f : F) (S : Submonoid N) :
Submonoid M where
carrier := f ⁻¹' S
one_mem' := show f 1 ∈ S by rw [map_one]; exact S.one_mem
mul_mem' ha hb := show f (_ * _) ∈ S by rw [map_mul]; exact S.mul_mem ha hb
@[to_additive (attr := simp)]
theorem coe_comap (S : Submonoid N) (f : F) : (S.comap f : Set M) = f ⁻¹' S :=
rfl
@[to_additive (attr := simp)]
theorem mem_comap {S : Submonoid N} {f : F} {x : M} : x ∈ S.comap f ↔ f x ∈ S :=
Iff.rfl
@[to_additive]
theorem comap_comap (S : Submonoid P) (g : N →* P) (f : M →* N) :
(S.comap g).comap f = S.comap (g.comp f) :=
rfl
@[to_additive (attr := simp)]
theorem comap_id (S : Submonoid P) : S.comap (MonoidHom.id P) = S :=
ext (by simp)
/-- The image of a submonoid along a monoid homomorphism is a submonoid. -/
@[to_additive
/-- The image of an `AddSubmonoid` along an `AddMonoid` homomorphism is an `AddSubmonoid`. -/]
def map (f : F) (S : Submonoid M) :
Submonoid N where
carrier := f '' S
one_mem' := ⟨1, S.one_mem, map_one f⟩
mul_mem' := by
rintro _ _ ⟨x, hx, rfl⟩ ⟨y, hy, rfl⟩
exact ⟨x * y, S.mul_mem hx hy, by rw [map_mul]⟩
@[to_additive (attr := simp)]
theorem coe_map (f : F) (S : Submonoid M) : (S.map f : Set N) = f '' S :=
rfl
@[to_additive (attr := simp)]
theorem map_coe_toMonoidHom (f : F) (S : Submonoid M) : S.map (f : M →* N) = S.map f :=
rfl
@[to_additive (attr := simp)]
theorem map_coe_toMulEquiv {F} [EquivLike F M N] [MulEquivClass F M N] (f : F) (S : Submonoid M) :
S.map (f : M ≃* N) = S.map f :=
rfl
@[to_additive (attr := simp)]
theorem mem_map {f : F} {S : Submonoid M} {y : N} : y ∈ S.map f ↔ ∃ x ∈ S, f x = y := Iff.rfl
@[to_additive]
theorem mem_map_of_mem (f : F) {S : Submonoid M} {x : M} (hx : x ∈ S) : f x ∈ S.map f :=
mem_image_of_mem f hx
@[to_additive]
theorem apply_coe_mem_map (f : F) (S : Submonoid M) (x : S) : f x ∈ S.map f :=
mem_map_of_mem f x.2
@[to_additive]
theorem map_map (g : N →* P) (f : M →* N) : (S.map f).map g = S.map (g.comp f) :=
SetLike.coe_injective <| image_image _ _ _
-- The simpNF linter says that the LHS can be simplified via `Submonoid.mem_map`.
-- However this is a higher priority lemma.
-- It seems the side condition `hf` is not applied by `simpNF`.
-- https://github.com/leanprover/std4/issues/207
@[to_additive (attr := simp 1100, nolint simpNF)]
theorem mem_map_iff_mem {f : F} (hf : Function.Injective f) {S : Submonoid M} {x : M} :
f x ∈ S.map f ↔ x ∈ S :=
hf.mem_set_image
@[to_additive]
theorem map_le_iff_le_comap {f : F} {S : Submonoid M} {T : Submonoid N} :
S.map f ≤ T ↔ S ≤ T.comap f :=
image_subset_iff
@[to_additive]
theorem gc_map_comap (f : F) : GaloisConnection (map f) (comap f) := fun _ _ => map_le_iff_le_comap
@[to_additive]
theorem map_le_of_le_comap {T : Submonoid N} {f : F} : S ≤ T.comap f → S.map f ≤ T :=
(gc_map_comap f).l_le
@[to_additive]
theorem le_comap_of_map_le {T : Submonoid N} {f : F} : S.map f ≤ T → S ≤ T.comap f :=
(gc_map_comap f).le_u
@[to_additive]
theorem le_comap_map {f : F} : S ≤ (S.map f).comap f :=
(gc_map_comap f).le_u_l _
@[to_additive]
theorem map_comap_le {S : Submonoid N} {f : F} : (S.comap f).map f ≤ S :=
(gc_map_comap f).l_u_le _
@[to_additive]
theorem monotone_map {f : F} : Monotone (map f) :=
(gc_map_comap f).monotone_l
@[to_additive]
theorem monotone_comap {f : F} : Monotone (comap f) :=
(gc_map_comap f).monotone_u
@[to_additive (attr := simp)]
theorem map_comap_map {f : F} : ((S.map f).comap f).map f = S.map f :=
(gc_map_comap f).l_u_l_eq_l _
@[to_additive (attr := simp)]
theorem comap_map_comap {S : Submonoid N} {f : F} : ((S.comap f).map f).comap f = S.comap f :=
(gc_map_comap f).u_l_u_eq_u _
@[to_additive]
theorem map_sup (S T : Submonoid M) (f : F) : (S ⊔ T).map f = S.map f ⊔ T.map f :=
(gc_map_comap f : GaloisConnection (map f) (comap f)).l_sup
@[to_additive]
theorem map_iSup {ι : Sort*} (f : F) (s : ι → Submonoid M) : (iSup s).map f = ⨆ i, (s i).map f :=
(gc_map_comap f : GaloisConnection (map f) (comap f)).l_iSup
@[to_additive]
theorem map_inf (S T : Submonoid M) (f : F) (hf : Function.Injective f) :
(S ⊓ T).map f = S.map f ⊓ T.map f := SetLike.coe_injective (Set.image_inter hf)
@[to_additive]
theorem map_iInf {ι : Sort*} [Nonempty ι] (f : F) (hf : Function.Injective f)
(s : ι → Submonoid M) : (iInf s).map f = ⨅ i, (s i).map f := by
apply SetLike.coe_injective
simpa using (Set.injOn_of_injective hf).image_iInter_eq (s := SetLike.coe ∘ s)
@[to_additive]
theorem comap_inf (S T : Submonoid N) (f : F) : (S ⊓ T).comap f = S.comap f ⊓ T.comap f :=
(gc_map_comap f : GaloisConnection (map f) (comap f)).u_inf
@[to_additive]
theorem comap_iInf {ι : Sort*} (f : F) (s : ι → Submonoid N) :
(iInf s).comap f = ⨅ i, (s i).comap f :=
(gc_map_comap f : GaloisConnection (map f) (comap f)).u_iInf
@[to_additive (attr := simp)]
theorem map_bot (f : F) : (⊥ : Submonoid M).map f = ⊥ :=
(gc_map_comap f).l_bot
@[to_additive]
lemma disjoint_map {f : F} (hf : Function.Injective f) {H K : Submonoid M} (h : Disjoint H K) :
Disjoint (H.map f) (K.map f) := by
rw [disjoint_iff, ← map_inf _ _ f hf, disjoint_iff.mp h, map_bot]
@[to_additive (attr := simp)]
theorem comap_top (f : F) : (⊤ : Submonoid N).comap f = ⊤ :=
(gc_map_comap f).u_top
@[to_additive (attr := simp)]
theorem map_id (S : Submonoid M) : S.map (MonoidHom.id M) = S :=
ext fun _ => ⟨fun ⟨_, h, rfl⟩ => h, fun h => ⟨_, h, rfl⟩⟩
section GaloisCoinsertion
variable {ι : Type*} {f : F}
/-- `map f` and `comap f` form a `GaloisCoinsertion` when `f` is injective. -/
@[to_additive /-- `map f` and `comap f` form a `GaloisCoinsertion` when `f` is injective. -/]
def gciMapComap (hf : Function.Injective f) : GaloisCoinsertion (map f) (comap f) :=
(gc_map_comap f).toGaloisCoinsertion fun S x => by simp [mem_comap, mem_map, hf.eq_iff]
variable (hf : Function.Injective f)
include hf
@[to_additive]
theorem comap_map_eq_of_injective (S : Submonoid M) : (S.map f).comap f = S :=
(gciMapComap hf).u_l_eq _
@[to_additive]
theorem comap_surjective_of_injective : Function.Surjective (comap f) :=
(gciMapComap hf).u_surjective
@[to_additive]
theorem map_injective_of_injective : Function.Injective (map f) :=
(gciMapComap hf).l_injective
@[to_additive]
theorem comap_inf_map_of_injective (S T : Submonoid M) : (S.map f ⊓ T.map f).comap f = S ⊓ T :=
(gciMapComap hf).u_inf_l _ _
@[to_additive]
theorem comap_iInf_map_of_injective (S : ι → Submonoid M) : (⨅ i, (S i).map f).comap f = iInf S :=
(gciMapComap hf).u_iInf_l _
@[to_additive]
theorem comap_sup_map_of_injective (S T : Submonoid M) : (S.map f ⊔ T.map f).comap f = S ⊔ T :=
(gciMapComap hf).u_sup_l _ _
@[to_additive]
theorem comap_iSup_map_of_injective (S : ι → Submonoid M) : (⨆ i, (S i).map f).comap f = iSup S :=
(gciMapComap hf).u_iSup_l _
@[to_additive]
theorem map_le_map_iff_of_injective {S T : Submonoid M} : S.map f ≤ T.map f ↔ S ≤ T :=
(gciMapComap hf).l_le_l_iff
@[to_additive]
theorem map_strictMono_of_injective : StrictMono (map f) :=
(gciMapComap hf).strictMono_l
end GaloisCoinsertion
section GaloisInsertion
variable {ι : Type*} {f : F}
/-- `map f` and `comap f` form a `GaloisInsertion` when `f` is surjective. -/
@[to_additive /-- `map f` and `comap f` form a `GaloisInsertion` when `f` is surjective. -/]
def giMapComap (hf : Function.Surjective f) : GaloisInsertion (map f) (comap f) :=
(gc_map_comap f).toGaloisInsertion fun S x h =>
let ⟨y, hy⟩ := hf x
mem_map.2 ⟨y, by simp [hy, h]⟩
variable (hf : Function.Surjective f)
include hf
@[to_additive]
theorem map_comap_eq_of_surjective (S : Submonoid N) : (S.comap f).map f = S :=
(giMapComap hf).l_u_eq _
@[to_additive]
theorem map_surjective_of_surjective : Function.Surjective (map f) :=
(giMapComap hf).l_surjective
@[to_additive]
theorem comap_injective_of_surjective : Function.Injective (comap f) :=
(giMapComap hf).u_injective
@[to_additive]
theorem map_inf_comap_of_surjective (S T : Submonoid N) : (S.comap f ⊓ T.comap f).map f = S ⊓ T :=
(giMapComap hf).l_inf_u _ _
@[to_additive]
theorem map_iInf_comap_of_surjective (S : ι → Submonoid N) : (⨅ i, (S i).comap f).map f = iInf S :=
(giMapComap hf).l_iInf_u _
@[to_additive]
theorem map_sup_comap_of_surjective (S T : Submonoid N) : (S.comap f ⊔ T.comap f).map f = S ⊔ T :=
(giMapComap hf).l_sup_u _ _
@[to_additive]
theorem map_iSup_comap_of_surjective (S : ι → Submonoid N) : (⨆ i, (S i).comap f).map f = iSup S :=
(giMapComap hf).l_iSup_u _
@[to_additive]
theorem comap_le_comap_iff_of_surjective {S T : Submonoid N} : S.comap f ≤ T.comap f ↔ S ≤ T :=
(giMapComap hf).u_le_u_iff
@[to_additive]
theorem comap_strictMono_of_surjective : StrictMono (comap f) :=
(giMapComap hf).strictMono_u
end GaloisInsertion
variable {M : Type*} [MulOneClass M] (S : Submonoid M)
/-- The top submonoid is isomorphic to the monoid. -/
@[to_additive (attr := simps)
/-- The top additive submonoid is isomorphic to the additive monoid. -/]
def topEquiv : (⊤ : Submonoid M) ≃* M where
toFun x := x
invFun x := ⟨x, mem_top x⟩
left_inv x := x.eta _
map_mul' _ _ := rfl
@[to_additive (attr := simp)]
theorem topEquiv_toMonoidHom : ((topEquiv : _ ≃* M) : _ →* M) = (⊤ : Submonoid M).subtype :=
rfl
/-- A subgroup is isomorphic to its image under an injective function. If you have an isomorphism,
use `MulEquiv.submonoidMap` for better definitional equalities. -/
@[to_additive /-- An additive subgroup is isomorphic to its image under an injective function. If
you have an isomorphism, use `AddEquiv.addSubmonoidMap` for better definitional equalities. -/]
noncomputable def equivMapOfInjective (f : M →* N) (hf : Function.Injective f) : S ≃* S.map f :=
{ Equiv.Set.image f S hf with map_mul' := fun _ _ => Subtype.ext (f.map_mul _ _) }
@[to_additive (attr := simp)]
theorem coe_equivMapOfInjective_apply (f : M →* N) (hf : Function.Injective f) (x : S) :
(equivMapOfInjective S f hf x : N) = f x :=
rfl
@[to_additive (attr := simp)]
theorem closure_closure_coe_preimage {s : Set M} : closure (((↑) : closure s → M) ⁻¹' s) = ⊤ :=
eq_top_iff.2 fun x _ ↦ Subtype.recOn x fun _ hx' ↦
closure_induction (fun _ h ↦ subset_closure h) (one_mem _) (fun _ _ _ _ ↦ mul_mem) hx'
/-- Given submonoids `s`, `t` of monoids `M`, `N` respectively, `s × t` as a submonoid
of `M × N`. -/
@[to_additive prod
/-- Given `AddSubmonoid`s `s`, `t` of `AddMonoid`s `A`, `B` respectively, `s × t`
as an `AddSubmonoid` of `A × B`. -/]
def prod (s : Submonoid M) (t : Submonoid N) :
Submonoid (M × N) where
carrier := s ×ˢ t
one_mem' := ⟨s.one_mem, t.one_mem⟩
mul_mem' hp hq := ⟨s.mul_mem hp.1 hq.1, t.mul_mem hp.2 hq.2⟩
@[to_additive (attr := norm_cast) coe_prod]
theorem coe_prod (s : Submonoid M) (t : Submonoid N) :
(s.prod t : Set (M × N)) = (s : Set M) ×ˢ (t : Set N) :=
rfl
@[to_additive mem_prod]
theorem mem_prod {s : Submonoid M} {t : Submonoid N} {p : M × N} :
p ∈ s.prod t ↔ p.1 ∈ s ∧ p.2 ∈ t :=
Iff.rfl
@[to_additive prod_mono]
theorem prod_mono {s₁ s₂ : Submonoid M} {t₁ t₂ : Submonoid N} (hs : s₁ ≤ s₂) (ht : t₁ ≤ t₂) :
s₁.prod t₁ ≤ s₂.prod t₂ :=
Set.prod_mono hs ht
@[to_additive prod_top]
theorem prod_top (s : Submonoid M) : s.prod (⊤ : Submonoid N) = s.comap (MonoidHom.fst M N) :=
ext fun x => by simp [mem_prod, MonoidHom.coe_fst]
@[to_additive top_prod]
theorem top_prod (s : Submonoid N) : (⊤ : Submonoid M).prod s = s.comap (MonoidHom.snd M N) :=
ext fun x => by simp [mem_prod, MonoidHom.coe_snd]
@[to_additive (attr := simp) top_prod_top]
theorem top_prod_top : (⊤ : Submonoid M).prod (⊤ : Submonoid N) = ⊤ :=
(top_prod _).trans <| comap_top _
@[to_additive bot_prod_bot]
theorem bot_prod_bot : (⊥ : Submonoid M).prod (⊥ : Submonoid N) = ⊥ :=
SetLike.coe_injective <| by simp [coe_prod]
/-- The product of submonoids is isomorphic to their product as monoids. -/
@[to_additive prodEquiv
/-- The product of additive submonoids is isomorphic to their product as additive monoids. -/]
def prodEquiv (s : Submonoid M) (t : Submonoid N) : s.prod t ≃* s × t :=
{ (Equiv.Set.prod (s : Set M) (t : Set N)) with
map_mul' := fun _ _ => rfl }
open MonoidHom
@[to_additive]
theorem map_inl (s : Submonoid M) : s.map (inl M N) = s.prod ⊥ :=
ext fun p =>
⟨fun ⟨_, hx, hp⟩ => hp ▸ ⟨hx, Set.mem_singleton 1⟩, fun ⟨hps, hp1⟩ =>
⟨p.1, hps, Prod.ext rfl <| (Set.eq_of_mem_singleton hp1).symm⟩⟩
@[to_additive]
theorem map_inr (s : Submonoid N) : s.map (inr M N) = prod ⊥ s :=
ext fun p =>
⟨fun ⟨_, hx, hp⟩ => hp ▸ ⟨Set.mem_singleton 1, hx⟩, fun ⟨hp1, hps⟩ =>
⟨p.2, hps, Prod.ext (Set.eq_of_mem_singleton hp1).symm rfl⟩⟩
@[to_additive (attr := simp) prod_bot_sup_bot_prod]
theorem prod_bot_sup_bot_prod (s : Submonoid M) (t : Submonoid N) :
(prod s ⊥) ⊔ (prod ⊥ t) = prod s t :=
(le_antisymm (sup_le (prod_mono (le_refl s) bot_le) (prod_mono bot_le (le_refl t))))
fun p hp => Prod.fst_mul_snd p ▸ mul_mem
((le_sup_left : prod s ⊥ ≤ prod s ⊥ ⊔ prod ⊥ t) ⟨hp.1, Set.mem_singleton 1⟩)
((le_sup_right : prod ⊥ t ≤ prod s ⊥ ⊔ prod ⊥ t) ⟨Set.mem_singleton 1, hp.2⟩)
@[to_additive]
theorem mem_map_equiv {f : M ≃* N} {K : Submonoid M} {x : N} :
x ∈ K.map f.toMonoidHom ↔ f.symm x ∈ K :=
Set.mem_image_equiv
@[to_additive]
theorem map_equiv_eq_comap_symm (f : M ≃* N) (K : Submonoid M) :
K.map f = K.comap f.symm :=
SetLike.coe_injective (f.toEquiv.image_eq_preimage_symm K)
@[to_additive]
theorem comap_equiv_eq_map_symm (f : N ≃* M) (K : Submonoid M) :
K.comap f = K.map f.symm :=
(map_equiv_eq_comap_symm f.symm K).symm
@[to_additive (attr := simp)]
theorem map_equiv_top (f : M ≃* N) : (⊤ : Submonoid M).map f = ⊤ :=
SetLike.coe_injective <| Set.image_univ.trans f.surjective.range_eq
@[to_additive le_prod_iff]
theorem le_prod_iff {s : Submonoid M} {t : Submonoid N} {u : Submonoid (M × N)} :
u ≤ s.prod t ↔ u.map (fst M N) ≤ s ∧ u.map (snd M N) ≤ t := by
constructor
· intro h
constructor
· rintro x ⟨⟨y1, y2⟩, ⟨hy1, rfl⟩⟩
exact (h hy1).1
· rintro x ⟨⟨y1, y2⟩, ⟨hy1, rfl⟩⟩
exact (h hy1).2
· rintro ⟨hH, hK⟩ ⟨x1, x2⟩ h
exact ⟨hH ⟨_, h, rfl⟩, hK ⟨_, h, rfl⟩⟩
@[to_additive prod_le_iff]
theorem prod_le_iff {s : Submonoid M} {t : Submonoid N} {u : Submonoid (M × N)} :
s.prod t ≤ u ↔ s.map (inl M N) ≤ u ∧ t.map (inr M N) ≤ u := by
constructor
· intro h
constructor
· rintro _ ⟨x, hx, rfl⟩
apply h
exact ⟨hx, Submonoid.one_mem _⟩
· rintro _ ⟨x, hx, rfl⟩
apply h
exact ⟨Submonoid.one_mem _, hx⟩
· rintro ⟨hH, hK⟩ ⟨x1, x2⟩ ⟨h1, h2⟩
have h1' : inl M N x1 ∈ u := by
apply hH
simpa using h1
have h2' : inr M N x2 ∈ u := by
apply hK
simpa using h2
simpa using Submonoid.mul_mem _ h1' h2'
@[to_additive closure_prod]
theorem closure_prod {s : Set M} {t : Set N} (hs : 1 ∈ s) (ht : 1 ∈ t) :
closure (s ×ˢ t) = (closure s).prod (closure t) :=
le_antisymm
(closure_le.2 <| Set.prod_subset_prod_iff.2 <| .inl ⟨subset_closure, subset_closure⟩)
(prod_le_iff.2 ⟨
map_le_of_le_comap _ <| closure_le.2 fun _x hx => subset_closure ⟨hx, ht⟩,
map_le_of_le_comap _ <| closure_le.2 fun _y hy => subset_closure ⟨hs, hy⟩⟩)
@[to_additive (attr := simp) closure_prod_zero]
lemma closure_prod_one (s : Set M) : closure (s ×ˢ ({1} : Set N)) = (closure s).prod ⊥ :=
le_antisymm
(closure_le.2 <| Set.prod_subset_prod_iff.2 <| .inl ⟨subset_closure, .rfl⟩)
(prod_le_iff.2 ⟨
map_le_of_le_comap _ <| closure_le.2 fun _x hx => subset_closure ⟨hx, rfl⟩,
by simp⟩)
@[to_additive (attr := simp) closure_zero_prod]
lemma closure_one_prod (t : Set N) : closure (({1} : Set M) ×ˢ t) = .prod ⊥ (closure t) :=
le_antisymm
(closure_le.2 <| Set.prod_subset_prod_iff.2 <| .inl ⟨.rfl, subset_closure⟩)
(prod_le_iff.2 ⟨by simp,
map_le_of_le_comap _ <| closure_le.2 fun _y hy => subset_closure ⟨rfl, hy⟩⟩)
end Submonoid
namespace MonoidHom
variable {F : Type*} [FunLike F M N] [mc : MonoidHomClass F M N]
open Submonoid
library_note2 «range copy pattern» /--
For many categories (monoids, modules, rings, ...) the set-theoretic image of a morphism `f` is
a subobject of the codomain. When this is the case, it is useful to define the range of a morphism
in such a way that the underlying carrier set of the range subobject is definitionally
`Set.range f`. In particular this means that the types `↥(Set.range f)` and `↥f.range` are
interchangeable without proof obligations.
A convenient candidate definition for range which is mathematically correct is `map ⊤ f`, just as
`Set.range` could have been defined as `f '' Set.univ`. However, this lacks the desired definitional
convenience, in that it both does not match `Set.range`, and that it introduces a redundant `x ∈ ⊤`
term which clutters proofs. In such a case one may resort to the `copy`
pattern. A `copy` function converts the definitional problem for the carrier set of a subobject
into a one-off propositional proof obligation which one discharges while writing the definition of
the definitionally convenient range (the parameter `hs` in the example below).
A good example is the case of a morphism of monoids. A convenient definition for
`MonoidHom.mrange` would be `(⊤ : Submonoid M).map f`. However since this lacks the required
definitional convenience, we first define `Submonoid.copy` as follows:
```lean
protected def copy (S : Submonoid M) (s : Set M) (hs : s = S) : Submonoid M :=
{ carrier := s,
one_mem' := hs.symm ▸ S.one_mem',
mul_mem' := hs.symm ▸ S.mul_mem' }
```
and then finally define:
```lean
def mrange (f : M →* N) : Submonoid N :=
((⊤ : Submonoid M).map f).copy (Set.range f) Set.image_univ.symm
```
-/
/-- The range of a monoid homomorphism is a submonoid. See Note [range copy pattern]. -/
@[to_additive /-- The range of an `AddMonoidHom` is an `AddSubmonoid`. -/]
def mrange (f : F) : Submonoid N :=
((⊤ : Submonoid M).map f).copy (Set.range f) Set.image_univ.symm
@[to_additive (attr := simp)]
theorem coe_mrange (f : F) : (mrange f : Set N) = Set.range f :=
rfl
@[to_additive (attr := simp)]
theorem mem_mrange {f : F} {y : N} : y ∈ mrange f ↔ ∃ x, f x = y :=
Iff.rfl
@[to_additive]
lemma mrange_comp {O : Type*} [MulOneClass O] (f : N →* O) (g : M →* N) :
mrange (f.comp g) = (mrange g).map f := SetLike.coe_injective <| Set.range_comp f _
@[to_additive]
theorem mrange_eq_map (f : F) : mrange f = (⊤ : Submonoid M).map f :=
Submonoid.copy_eq _
@[to_additive (attr := simp)]
theorem mrange_id : mrange (MonoidHom.id M) = ⊤ := by
simp [mrange_eq_map]
@[to_additive]
theorem map_mrange (g : N →* P) (f : M →* N) : (mrange f).map g = mrange (comp g f) := by
simpa only [mrange_eq_map] using (⊤ : Submonoid M).map_map g f
@[to_additive]
theorem mrange_eq_top {f : F} : mrange f = (⊤ : Submonoid N) ↔ Surjective f :=
SetLike.ext'_iff.trans <| Iff.trans (by rw [coe_mrange, coe_top]) Set.range_eq_univ
/-- The range of a surjective monoid hom is the whole of the codomain. -/
@[to_additive (attr := simp)
/-- The range of a surjective `AddMonoid` hom is the whole of the codomain. -/]
theorem mrange_eq_top_of_surjective (f : F) (hf : Function.Surjective f) :
mrange f = (⊤ : Submonoid N) :=
mrange_eq_top.2 hf
@[to_additive]
theorem mclosure_preimage_le (f : F) (s : Set N) : closure (f ⁻¹' s) ≤ (closure s).comap f :=
closure_le.2 fun _ hx => SetLike.mem_coe.2 <| mem_comap.2 <| subset_closure hx
/-- The image under a monoid hom of the submonoid generated by a set equals the submonoid generated
by the image of the set. -/
@[to_additive
/-- The image under an `AddMonoid` hom of the `AddSubmonoid` generated by a set equals
the `AddSubmonoid` generated by the image of the set. -/]
theorem map_mclosure (f : F) (s : Set M) : (closure s).map f = closure (f '' s) :=
Set.image_preimage.l_comm_of_u_comm (gc_map_comap f) (Submonoid.gi N).gc (Submonoid.gi M).gc
fun _ ↦ rfl
@[to_additive (attr := simp)]
theorem mclosure_range (f : F) : closure (Set.range f) = mrange f := by
rw [← Set.image_univ, ← map_mclosure, mrange_eq_map, closure_univ]
/-- Restriction of a monoid hom to a submonoid of the domain. -/
@[to_additive /-- Restriction of an `AddMonoid` hom to an `AddSubmonoid` of the domain. -/]
def restrict {N S : Type*} [MulOneClass N] [SetLike S M] [SubmonoidClass S M] (f : M →* N)
(s : S) : s →* N :=
f.comp (SubmonoidClass.subtype _)
@[to_additive (attr := simp)]
theorem restrict_apply {N S : Type*} [MulOneClass N] [SetLike S M] [SubmonoidClass S M]
(f : M →* N) (s : S) (x : s) : f.restrict s x = f x :=
rfl
@[to_additive (attr := simp)]
theorem restrict_mrange (f : M →* N) : mrange (f.restrict S) = S.map f := by
simp [SetLike.ext_iff]
/-- Restriction of a monoid hom to a submonoid of the codomain. -/
@[to_additive (attr := simps apply)
/-- Restriction of an `AddMonoid` hom to an `AddSubmonoid` of the codomain. -/]
def codRestrict {S} [SetLike S N] [SubmonoidClass S N] (f : M →* N) (s : S) (h : ∀ x, f x ∈ s) :
M →* s where
toFun n := ⟨f n, h n⟩
map_one' := Subtype.eq f.map_one
map_mul' x y := Subtype.eq (f.map_mul x y)
@[to_additive (attr := simp)]
lemma injective_codRestrict {S} [SetLike S N] [SubmonoidClass S N] (f : M →* N) (s : S)
(h : ∀ x, f x ∈ s) : Function.Injective (f.codRestrict s h) ↔ Function.Injective f :=
⟨fun H _ _ hxy ↦ H <| Subtype.eq hxy, fun H _ _ hxy ↦ H (congr_arg Subtype.val hxy)⟩
/-- Restriction of a monoid hom to its range interpreted as a submonoid. -/
@[to_additive /-- Restriction of an `AddMonoid` hom to its range interpreted as a submonoid. -/]
def mrangeRestrict {N} [MulOneClass N] (f : M →* N) : M →* (mrange f) :=
(f.codRestrict (mrange f)) fun x => ⟨x, rfl⟩
@[to_additive (attr := simp)]
theorem coe_mrangeRestrict {N} [MulOneClass N] (f : M →* N) (x : M) :
(f.mrangeRestrict x : N) = f x :=
rfl
@[to_additive]
theorem mrangeRestrict_surjective (f : M →* N) : Function.Surjective f.mrangeRestrict :=
fun ⟨_, ⟨x, rfl⟩⟩ => ⟨x, rfl⟩
/-- The multiplicative kernel of a monoid hom is the submonoid of elements `x : G` such
that `f x = 1`. -/
@[to_additive
/-- The additive kernel of an `AddMonoid` hom is the `AddSubmonoid` of elements such that
`f x = 0`. -/]
def mker (f : F) : Submonoid M :=
(⊥ : Submonoid N).comap f
@[to_additive (attr := simp)]
theorem mem_mker {f : F} {x : M} : x ∈ mker f ↔ f x = 1 :=
Iff.rfl
@[to_additive]
theorem coe_mker (f : F) : (mker f : Set M) = (f : M → N) ⁻¹' {1} :=
rfl
@[to_additive]
instance decidableMemMker [DecidableEq N] (f : F) : DecidablePred (· ∈ mker f) := fun x =>
decidable_of_iff (f x = 1) mem_mker
@[to_additive]
theorem comap_mker (g : N →* P) (f : M →* N) : (mker g).comap f = mker (comp g f) :=
rfl
@[to_additive (attr := simp)]
theorem comap_bot' (f : F) : (⊥ : Submonoid N).comap f = mker f :=
rfl
@[to_additive (attr := simp)]
theorem restrict_mker (f : M →* N) : mker (f.restrict S) = (MonoidHom.mker f).comap S.subtype :=
rfl
@[to_additive]
theorem mrangeRestrict_mker (f : M →* N) : mker (mrangeRestrict f) = mker f := by
ext x
change (⟨f x, _⟩ : mrange f) = ⟨1, _⟩ ↔ f x = 1
simp
@[to_additive (attr := simp)]
theorem mker_one : mker (1 : M →* N) = ⊤ := by
ext
simp [mem_mker]
@[to_additive prod_map_comap_prod']
theorem prod_map_comap_prod' {M' : Type*} {N' : Type*} [MulOneClass M'] [MulOneClass N']
(f : M →* N) (g : M' →* N') (S : Submonoid N) (S' : Submonoid N') :
(S.prod S').comap (prodMap f g) = (S.comap f).prod (S'.comap g) :=
SetLike.coe_injective <| Set.preimage_prod_map_prod f g _ _
@[to_additive mker_prod_map]
theorem mker_prod_map {M' : Type*} {N' : Type*} [MulOneClass M'] [MulOneClass N'] (f : M →* N)
(g : M' →* N') : mker (prodMap f g) = (mker f).prod (mker g) := by
rw [← comap_bot', ← comap_bot', ← comap_bot', ← prod_map_comap_prod', bot_prod_bot]
@[to_additive (attr := simp)]
theorem mker_inl : mker (inl M N) = ⊥ := by
ext x
simp [mem_mker]
@[to_additive (attr := simp)]
theorem mker_inr : mker (inr M N) = ⊥ := by
ext x
simp [mem_mker]
@[to_additive (attr := simp)]
lemma mker_fst : mker (fst M N) = .prod ⊥ ⊤ := SetLike.ext fun _ => (iff_of_eq (and_true _)).symm
@[to_additive (attr := simp)]
lemma mker_snd : mker (snd M N) = .prod ⊤ ⊥ := SetLike.ext fun _ => (iff_of_eq (true_and _)).symm
/-- The `MonoidHom` from the preimage of a submonoid to itself. -/
@[to_additive (attr := simps)
/-- The `AddMonoidHom` from the preimage of an additive submonoid to itself. -/]
def submonoidComap (f : M →* N) (N' : Submonoid N) :
N'.comap f →* N' where
toFun x := ⟨f x, x.2⟩
map_one' := Subtype.eq f.map_one
map_mul' x y := Subtype.eq (f.map_mul x y)
@[to_additive]
lemma submonoidComap_surjective_of_surjective (f : M →* N) (N' : Submonoid N) (hf : Surjective f) :
Surjective (f.submonoidComap N') := fun y ↦ by
obtain ⟨x, hx⟩ := hf y
use ⟨x, mem_comap.mpr (hx ▸ y.2)⟩
apply Subtype.val_injective
simp [hx]
/-- The `MonoidHom` from a submonoid to its image.
See `MulEquiv.SubmonoidMap` for a variant for `MulEquiv`s. -/
@[to_additive (attr := simps)
/-- The `AddMonoidHom` from an additive submonoid to its image. See `AddEquiv.AddSubmonoidMap`
for a variant for `AddEquiv`s. -/]
def submonoidMap (f : M →* N) (M' : Submonoid M) : M' →* M'.map f where
toFun x := ⟨f x, ⟨x, x.2, rfl⟩⟩
map_one' := Subtype.eq <| f.map_one
map_mul' x y := Subtype.eq <| f.map_mul x y
@[to_additive]
theorem submonoidMap_surjective (f : M →* N) (M' : Submonoid M) :
Function.Surjective (f.submonoidMap M') := by
rintro ⟨_, x, hx, rfl⟩
exact ⟨⟨x, hx⟩, rfl⟩
end MonoidHom
namespace Submonoid
@[to_additive]
lemma surjOn_iff_le_map {f : M →* N} {H : Submonoid M} {K : Submonoid N} :
Set.SurjOn f H K ↔ K ≤ H.map f :=
Iff.rfl
open MonoidHom
@[to_additive]
theorem mrange_inl : mrange (inl M N) = prod ⊤ ⊥ := by simpa only [mrange_eq_map] using map_inl ⊤
@[to_additive]
theorem mrange_inr : mrange (inr M N) = prod ⊥ ⊤ := by simpa only [mrange_eq_map] using map_inr ⊤
@[to_additive]
theorem mrange_inl' : mrange (inl M N) = comap (snd M N) ⊥ :=
mrange_inl.trans (top_prod _)
@[to_additive]
theorem mrange_inr' : mrange (inr M N) = comap (fst M N) ⊥ :=
mrange_inr.trans (prod_top _)
@[to_additive (attr := simp)]
theorem mrange_fst : mrange (fst M N) = ⊤ :=
mrange_eq_top_of_surjective (fst M N) <| @Prod.fst_surjective _ _ ⟨1⟩
@[to_additive (attr := simp)]
theorem mrange_snd : mrange (snd M N) = ⊤ :=
mrange_eq_top_of_surjective (snd M N) <| @Prod.snd_surjective _ _ ⟨1⟩
@[to_additive prod_eq_bot_iff]
theorem prod_eq_bot_iff {s : Submonoid M} {t : Submonoid N} : s.prod t = ⊥ ↔ s = ⊥ ∧ t = ⊥ := by
simp only [eq_bot_iff, prod_le_iff, (gc_map_comap _).le_iff_le, comap_bot', mker_inl, mker_inr]
@[to_additive prod_eq_top_iff]
theorem prod_eq_top_iff {s : Submonoid M} {t : Submonoid N} : s.prod t = ⊤ ↔ s = ⊤ ∧ t = ⊤ := by
simp only [eq_top_iff, le_prod_iff, ← mrange_eq_map, mrange_fst, mrange_snd]
@[to_additive (attr := simp)]
theorem mrange_inl_sup_mrange_inr : mrange (inl M N) ⊔ mrange (inr M N) = ⊤ := by
simp only [mrange_inl, mrange_inr, prod_bot_sup_bot_prod, top_prod_top]
/-- The monoid hom associated to an inclusion of submonoids. -/
@[to_additive
/-- The `AddMonoid` hom associated to an inclusion of submonoids. -/]
def inclusion {S T : Submonoid M} (h : S ≤ T) : S →* T :=
S.subtype.codRestrict _ fun x => h x.2
@[to_additive (attr := simp)]
theorem coe_inclusion {S T : Submonoid M} (h : S ≤ T) (a : S) : (inclusion h a : M) = a :=
Set.coe_inclusion h a
@[to_additive]
theorem inclusion_injective {S T : Submonoid M} (h : S ≤ T) : Function.Injective <| inclusion h :=
Set.inclusion_injective h
@[to_additive (attr := simp)]
lemma inclusion_inj {S T : Submonoid M} (h : S ≤ T) {x y : S} :
inclusion h x = inclusion h y ↔ x = y :=
(inclusion_injective h).eq_iff
@[to_additive (attr := simp)]
theorem subtype_comp_inclusion {S T : Submonoid M} (h : S ≤ T) :
T.subtype.comp (inclusion h) = S.subtype :=
rfl
@[to_additive (attr := simp)]
theorem mrange_subtype (s : Submonoid M) : mrange s.subtype = s :=
SetLike.coe_injective <| (coe_mrange _).trans <| Subtype.range_coe
@[to_additive]
theorem eq_top_iff' : S = ⊤ ↔ ∀ x : M, x ∈ S :=
eq_top_iff.trans ⟨fun h m => h <| mem_top m, fun h m _ => h m⟩
@[to_additive]
theorem eq_bot_iff_forall : S = ⊥ ↔ ∀ x ∈ S, x = (1 : M) :=
SetLike.ext_iff.trans <| by simp +contextual [iff_def, S.one_mem]
@[to_additive]
theorem eq_bot_of_subsingleton [Subsingleton S] : S = ⊥ := by
rw [eq_bot_iff_forall]
intro y hy
simpa using congr_arg ((↑) : S → M) <| Subsingleton.elim (⟨y, hy⟩ : S) 1
@[to_additive]
theorem nontrivial_iff_exists_ne_one (S : Submonoid M) : Nontrivial S ↔ ∃ x ∈ S, x ≠ (1 : M) :=
calc
Nontrivial S ↔ ∃ x : S, x ≠ 1 := nontrivial_iff_exists_ne 1
_ ↔ ∃ (x : _) (hx : x ∈ S), (⟨x, hx⟩ : S) ≠ ⟨1, S.one_mem⟩ := Subtype.exists
_ ↔ ∃ x ∈ S, x ≠ (1 : M) := by simp [Ne]
/-- A submonoid is either the trivial submonoid or nontrivial. -/
@[to_additive /-- An additive submonoid is either the trivial additive submonoid or nontrivial. -/]
theorem bot_or_nontrivial (S : Submonoid M) : S = ⊥ ∨ Nontrivial S := by
simp only [eq_bot_iff_forall, nontrivial_iff_exists_ne_one, ← not_forall, ← Classical.not_imp,
Classical.em]
/-- A submonoid is either the trivial submonoid or contains a nonzero element. -/
@[to_additive
/-- An additive submonoid is either the trivial additive submonoid or contains a nonzero
element. -/]
theorem bot_or_exists_ne_one (S : Submonoid M) : S = ⊥ ∨ ∃ x ∈ S, x ≠ (1 : M) :=
S.bot_or_nontrivial.imp_right S.nontrivial_iff_exists_ne_one.mp
@[to_additive]
lemma codisjoint_map {F : Type*} [FunLike F M N] [MonoidHomClass F M N] {f : F}
(hf : Function.Surjective f) {H K : Submonoid M} (h : Codisjoint H K) :
Codisjoint (H.map f) (K.map f) := by
rw [codisjoint_iff, ← map_sup, codisjoint_iff.mp h, ← MonoidHom.mrange_eq_map,
mrange_eq_top_of_surjective _ hf]
section Pi
variable {ι : Type*} {M : ι → Type*} [∀ i, MulOneClass (M i)]
/-- A version of `Set.pi` for submonoids. Given an index set `I` and a family of submodules
`s : Π i, Submonoid f i`, `pi I s` is the submonoid of dependent functions `f : Π i, f i` such that
`f i` belongs to `Pi I s` whenever `i ∈ I`. -/
@[to_additive /-- A version of `Set.pi` for `AddSubmonoid`s. Given an index set `I` and a family
of submodules `s : Π i, AddSubmonoid f i`, `pi I s` is the `AddSubmonoid` of dependent functions
`f : Π i, f i` such that `f i` belongs to `pi I s` whenever `i ∈ I`. -/]
def pi (I : Set ι) (S : ∀ i, Submonoid (M i)) : Submonoid (∀ i, M i) where
carrier := I.pi fun i => (S i).carrier
one_mem' i _ := (S i).one_mem
mul_mem' hp hq i hI := (S i).mul_mem (hp i hI) (hq i hI)
@[to_additive]
theorem coe_pi (I : Set ι) (S : ∀ i, Submonoid (M i)) :
(pi I S : Set (∀ i, M i)) = Set.pi I fun i => (S i : Set (M i)) :=
rfl
@[to_additive]
theorem mem_pi (I : Set ι) {S : ∀ i, Submonoid (M i)} {p : ∀ i, M i} :
p ∈ Submonoid.pi I S ↔ ∀ i, i ∈ I → p i ∈ S i :=
Iff.rfl
@[to_additive]
theorem pi_top (I : Set ι) : (pi I fun i => (⊤ : Submonoid (M i))) = ⊤ :=
ext fun x => by simp [mem_pi]
@[to_additive]
theorem pi_empty (H : ∀ i, Submonoid (M i)) : pi ∅ H = ⊤ :=
ext fun x => by simp [mem_pi]
@[to_additive]
theorem pi_bot : (pi Set.univ fun i => (⊥ : Submonoid (M i))) = ⊥ :=
ext fun x => by simp [mem_pi, funext_iff]
@[to_additive]
theorem le_pi_iff {I : Set ι} {S : ∀ i, Submonoid (M i)} {J : Submonoid (∀ i, M i)} :
J ≤ pi I S ↔ ∀ i ∈ I, J ≤ comap (Pi.evalMonoidHom M i) (S i) :=
Set.subset_pi_iff
@[to_additive (attr := simp)]
theorem mulSingle_mem_pi [DecidableEq ι] {I : Set ι} {S : ∀ i, Submonoid (M i)} (i : ι) (x : M i) :
Pi.mulSingle i x ∈ pi I S ↔ i ∈ I → x ∈ S i :=
Set.update_mem_pi_iff_of_mem (one_mem (pi I _))
@[to_additive]
theorem pi_eq_bot_iff (S : ∀ i, Submonoid (M i)) : pi Set.univ S = ⊥ ↔ ∀ i, S i = ⊥ := by
simp_rw [SetLike.ext'_iff]
exact Set.univ_pi_eq_singleton_iff
@[to_additive]
theorem le_comap_mulSingle_pi [DecidableEq ι] (S : ∀ i, Submonoid (M i)) {I i} :
S i ≤ comap (MonoidHom.mulSingle M i) (pi I S) :=
fun x hx => by simp [hx]
@[to_additive]
theorem iSup_map_mulSingle_le [DecidableEq ι] {I : Set ι} {S : ∀ i, Submonoid (M i)} :
⨆ i, map (MonoidHom.mulSingle M i) (S i) ≤ pi I S :=
iSup_le fun _ => map_le_iff_le_comap.mpr (le_comap_mulSingle_pi _)
end Pi
end Submonoid
namespace MulEquiv
variable {S} {T : Submonoid M}
/-- Makes the identity isomorphism from a proof that two submonoids of a multiplicative
monoid are equal. -/
@[to_additive
/-- Makes the identity additive isomorphism from a proof two submonoids of an additive monoid are
equal. -/]
def submonoidCongr (h : S = T) : S ≃* T :=
{ Equiv.setCongr <| congr_arg _ h with map_mul' := fun _ _ => rfl }
-- this name is primed so that the version to `f.range` instead of `f.mrange` can be unprimed.
/-- A monoid homomorphism `f : M →* N` with a left-inverse `g : N → M` defines a multiplicative
equivalence between `M` and `f.mrange`.
This is a bidirectional version of `MonoidHom.mrange_restrict`. -/
@[to_additive (attr := simps +simpRhs)
/-- An additive monoid homomorphism `f : M →+ N` with a left-inverse `g : N → M` defines an
additive equivalence between `M` and `f.mrange`. This is a bidirectional version of
`AddMonoidHom.mrange_restrict`. -/]
def ofLeftInverse' (f : M →* N) {g : N → M} (h : Function.LeftInverse g f) :
M ≃* MonoidHom.mrange f :=
{ f.mrangeRestrict with
toFun := f.mrangeRestrict
invFun := g ∘ (MonoidHom.mrange f).subtype
left_inv := h
right_inv := fun x =>
Subtype.ext <|
let ⟨x', hx'⟩ := MonoidHom.mem_mrange.mp x.2
show f (g x) = x by rw [← hx', h x'] }
/-- A `MulEquiv` `φ` between two monoids `M` and `N` induces a `MulEquiv` between
a submonoid `S ≤ M` and the submonoid `φ(S) ≤ N`.
See `MonoidHom.submonoidMap` for a variant for `MonoidHom`s. -/
@[to_additive
/-- An `AddEquiv` `φ` between two additive monoids `M` and `N` induces an `AddEquiv`
between a submonoid `S ≤ M` and the submonoid `φ(S) ≤ N`. See
`AddMonoidHom.addSubmonoidMap` for a variant for `AddMonoidHom`s. -/]
def submonoidMap (e : M ≃* N) (S : Submonoid M) : S ≃* S.map e :=
{ (e : M ≃ N).image S with map_mul' := fun _ _ => Subtype.ext (map_mul e _ _) }
@[to_additive (attr := simp)]
theorem coe_submonoidMap_apply (e : M ≃* N) (S : Submonoid M) (g : S) :
((submonoidMap e S g : S.map (e : M →* N)) : N) = e g :=
rfl
@[to_additive (attr := simp)]
theorem submonoidMap_symm_apply (e : M ≃* N) (S : Submonoid M) (g : S.map (e : M →* N)) :
(e.submonoidMap S).symm g = ⟨e.symm g, SetLike.mem_coe.1 <| Set.mem_image_equiv.1 g.2⟩ :=
rfl
@[deprecated (since := "2025-08-20")]
alias _root_.AddEquiv.add_submonoid_map_symm_apply := AddEquiv.addSubmonoidMap_symm_apply
end MulEquiv
@[to_additive (attr := simp)]
theorem Submonoid.equivMapOfInjective_coe_mulEquiv (e : M ≃* N) :
S.equivMapOfInjective (e : M →* N) (EquivLike.injective e) = e.submonoidMap S := by
ext
rfl
@[to_additive]
instance Submonoid.faithfulSMul {M' α : Type*} [MulOneClass M'] [SMul M' α] {S : Submonoid M'}
[FaithfulSMul M' α] : FaithfulSMul S α :=
⟨fun h => Subtype.ext <| eq_of_smul_eq_smul h⟩
section Units
namespace Submonoid
/-- The multiplicative equivalence between the type of units of `M` and the submonoid of unit
elements of `M`. -/
@[to_additive (attr := simps!) /-- The additive equivalence between the type of additive units of
`M` and the additive submonoid whose elements are the additive units of `M`. -/]
noncomputable def unitsTypeEquivIsUnitSubmonoid [Monoid M] : Mˣ ≃* IsUnit.submonoid M where
toFun x := ⟨x, Units.isUnit x⟩
invFun x := x.prop.unit
left_inv _ := IsUnit.unit_of_val_units _
right_inv x := by simp_rw [IsUnit.unit_spec]
map_mul' x y := by simp_rw [Units.val_mul]; rfl
end Submonoid
end Units
open AddSubmonoid Set
namespace Nat
@[simp] lemma addSubmonoidClosure_one : closure ({1} : Set ℕ) = ⊤ := by
refine (eq_top_iff' _).2 <| Nat.rec (zero_mem _) ?_
simp_rw [Nat.succ_eq_add_one]
exact fun n hn ↦ AddSubmonoid.add_mem _ hn <| subset_closure <| Set.mem_singleton _
@[deprecated (since := "2025-08-14")] alias addSubmonoid_closure_one := addSubmonoidClosure_one
end Nat
namespace Submonoid
variable {F : Type*} [FunLike F M N] [mc : MonoidHomClass F M N]
@[to_additive]
theorem map_comap_eq (f : F) (S : Submonoid N) : (S.comap f).map f = S ⊓ MonoidHom.mrange f :=
SetLike.coe_injective Set.image_preimage_eq_inter_range
@[to_additive]
theorem map_comap_eq_self {f : F} {S : Submonoid N} (h : S ≤ MonoidHom.mrange f) :
(S.comap f).map f = S := by
simpa only [inf_of_le_left h] using map_comap_eq f S
@[to_additive]
theorem map_comap_eq_self_of_surjective {f : F} (h : Function.Surjective f) {S : Submonoid N} :
map f (comap f S) = S :=
map_comap_eq_self (MonoidHom.mrange_eq_top_of_surjective _ h ▸ le_top)
end Submonoid |
.lake/packages/mathlib/Mathlib/Algebra/Group/Submonoid/DistribMulAction.lean | import Mathlib.Algebra.Group.Submonoid.MulAction
import Mathlib.Algebra.GroupWithZero.Action.Defs
/-!
# Distributive actions by submonoids
-/
assert_not_exists RelIso Ring
namespace Submonoid
variable {M α : Type*} [Monoid M]
variable {S : Type*} [SetLike S M] (s : S) [SubmonoidClass S M]
instance (priority := low) [AddMonoid α] [DistribMulAction M α] : DistribMulAction s α where
smul_zero r := smul_zero (r : M)
smul_add r := smul_add (r : M)
/-- The action by a submonoid is the action by the underlying monoid. -/
instance distribMulAction [AddMonoid α] [DistribMulAction M α] (S : Submonoid M) :
DistribMulAction S α :=
inferInstance
instance (priority := low) [Monoid α] [MulDistribMulAction M α] : MulDistribMulAction s α where
smul_mul r := smul_mul' (r : M)
smul_one r := smul_one (r : M)
/-- The action by a submonoid is the action by the underlying monoid. -/
instance mulDistribMulAction [Monoid α] [MulDistribMulAction M α] (S : Submonoid M) :
MulDistribMulAction S α :=
inferInstance
end Submonoid |
.lake/packages/mathlib/Mathlib/Algebra/Group/Submonoid/Defs.lean | import Mathlib.Algebra.Group.Hom.Defs
import Mathlib.Algebra.Group.Subsemigroup.Defs
import Mathlib.Tactic.FastInstance
import Mathlib.Data.Set.Insert
/-!
# Submonoids: definition
This file defines bundled multiplicative and additive submonoids. We also define
a `CompleteLattice` structure on `Submonoid`s, define the closure of a set as the minimal submonoid
that includes this set, and prove a few results about extending properties from a dense set (i.e.
a set with `closure s = ⊤`) to the whole monoid, see `Submonoid.dense_induction` and
`MonoidHom.ofClosureEqTopLeft`/`MonoidHom.ofClosureEqTopRight`.
## Main definitions
* `Submonoid M`: the type of bundled submonoids of a monoid `M`; the underlying set is given in
the `carrier` field of the structure, and should be accessed through coercion as in `(S : Set M)`.
* `AddSubmonoid M` : the type of bundled submonoids of an additive monoid `M`.
For each of the following definitions in the `Submonoid` namespace, there is a corresponding
definition in the `AddSubmonoid` namespace.
* `Submonoid.copy` : copy of a submonoid with `carrier` replaced by a set that is equal but possibly
not definitionally equal to the carrier of the original `Submonoid`.
* `MonoidHom.eqLocusM`: the submonoid of elements `x : M` such that `f x = g x`;
## Implementation notes
Submonoid inclusion is denoted `≤` rather than `⊆`, although `∈` is defined as
membership of a submonoid's underlying set.
Note that `Submonoid M` does not actually require `Monoid M`, instead requiring only the weaker
`MulOneClass M`.
This file is designed to have very few dependencies. In particular, it should not use natural
numbers. `Submonoid` is implemented by extending `Subsemigroup` requiring `one_mem'`.
## Tags
submonoid, submonoids
-/
assert_not_exists RelIso CompleteLattice MonoidWithZero
variable {M : Type*} {N : Type*}
section NonAssoc
variable [MulOneClass M] {s : Set M}
/-- `OneMemClass S M` says `S` is a type of subsets `s ≤ M`, such that `1 ∈ s` for all `s`. -/
class OneMemClass (S : Type*) (M : outParam Type*) [One M] [SetLike S M] : Prop where
/-- By definition, if we have `OneMemClass S M`, we have `1 ∈ s` for all `s : S`. -/
one_mem : ∀ s : S, (1 : M) ∈ s
export OneMemClass (one_mem)
/-- `ZeroMemClass S M` says `S` is a type of subsets `s ≤ M`, such that `0 ∈ s` for all `s`. -/
class ZeroMemClass (S : Type*) (M : outParam Type*) [Zero M] [SetLike S M] : Prop where
/-- By definition, if we have `ZeroMemClass S M`, we have `0 ∈ s` for all `s : S`. -/
zero_mem : ∀ s : S, (0 : M) ∈ s
export ZeroMemClass (zero_mem)
attribute [to_additive] OneMemClass
attribute [simp, aesop safe (rule_sets := [SetLike])] one_mem zero_mem
section
/-- A submonoid of a monoid `M` is a subset containing 1 and closed under multiplication. -/
structure Submonoid (M : Type*) [MulOneClass M] extends Subsemigroup M where
/-- A submonoid contains `1`. -/
one_mem' : (1 : M) ∈ carrier
end
/-- A submonoid of a monoid `M` can be considered as a subsemigroup of that monoid. -/
add_decl_doc Submonoid.toSubsemigroup
/-- `SubmonoidClass S M` says `S` is a type of subsets `s ≤ M` that contain `1`
and are closed under `(*)` -/
class SubmonoidClass (S : Type*) (M : outParam Type*) [MulOneClass M] [SetLike S M] : Prop
extends MulMemClass S M, OneMemClass S M
section
/-- An additive submonoid of an additive monoid `M` is a subset containing 0 and
closed under addition. -/
structure AddSubmonoid (M : Type*) [AddZeroClass M] extends AddSubsemigroup M where
/-- An additive submonoid contains `0`. -/
zero_mem' : (0 : M) ∈ carrier
end
/-- An additive submonoid of an additive monoid `M` can be considered as an
additive subsemigroup of that additive monoid. -/
add_decl_doc AddSubmonoid.toAddSubsemigroup
/-- `AddSubmonoidClass S M` says `S` is a type of subsets `s ≤ M` that contain `0`
and are closed under `(+)` -/
class AddSubmonoidClass (S : Type*) (M : outParam Type*) [AddZeroClass M] [SetLike S M] : Prop
extends AddMemClass S M, ZeroMemClass S M
attribute [to_additive] Submonoid SubmonoidClass
@[to_additive (attr := aesop 90% (rule_sets := [SetLike]))]
theorem pow_mem {M A} [Monoid M] [SetLike A M] [SubmonoidClass A M] {S : A} {x : M}
(hx : x ∈ S) : ∀ n : ℕ, x ^ n ∈ S
| 0 => by
rw [pow_zero]
exact OneMemClass.one_mem S
| n + 1 => by
rw [pow_succ]
exact mul_mem (pow_mem hx n) hx
namespace Submonoid
@[to_additive]
instance : SetLike (Submonoid M) M where
coe s := s.carrier
coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h
initialize_simps_projections Submonoid (carrier → coe, as_prefix coe)
initialize_simps_projections AddSubmonoid (carrier → coe, as_prefix coe)
/-- The actual `Submonoid` obtained from an element of a `SubmonoidClass` -/
@[to_additive (attr := simps) /-- The actual `AddSubmonoid` obtained from an element of a
`AddSubmonoidClass` -/]
def ofClass {S M : Type*} [Monoid M] [SetLike S M] [SubmonoidClass S M] (s : S) : Submonoid M :=
⟨⟨s, MulMemClass.mul_mem⟩, OneMemClass.one_mem s⟩
@[to_additive]
instance (priority := 100) : CanLift (Set M) (Submonoid M) (↑)
(fun s ↦ 1 ∈ s ∧ ∀ {x y}, x ∈ s → y ∈ s → x * y ∈ s) where
prf s h := ⟨{ carrier := s, one_mem' := h.1, mul_mem' := h.2 }, rfl⟩
@[to_additive]
instance : SubmonoidClass (Submonoid M) M where
one_mem := Submonoid.one_mem'
mul_mem {s} := s.mul_mem'
@[to_additive (attr := simp)]
theorem mem_toSubsemigroup {s : Submonoid M} {x : M} : x ∈ s.toSubsemigroup ↔ x ∈ s :=
Iff.rfl
@[to_additive]
theorem mem_carrier {s : Submonoid M} {x : M} : x ∈ s.carrier ↔ x ∈ s :=
Iff.rfl
@[to_additive (attr := simp)]
theorem mem_mk {s : Subsemigroup M} {x : M} (h_one) : x ∈ mk s h_one ↔ x ∈ s :=
Iff.rfl
@[to_additive (attr := simp)]
theorem coe_set_mk {s : Subsemigroup M} (h_one) : (mk s h_one : Set M) = s :=
rfl
@[to_additive (attr := simp)]
theorem mk_le_mk {s t : Subsemigroup M} (h_one) (h_one') : mk s h_one ≤ mk t h_one' ↔ s ≤ t :=
Iff.rfl
/-- Two submonoids are equal if they have the same elements. -/
@[to_additive (attr := ext) /-- Two `AddSubmonoid`s are equal if they have the same elements. -/]
theorem ext {S T : Submonoid M} (h : ∀ x, x ∈ S ↔ x ∈ T) : S = T :=
SetLike.ext h
/-- Copy a submonoid replacing `carrier` with a set that is equal to it. -/
@[to_additive /-- Copy an additive submonoid replacing `carrier` with a set that is equal to it. -/]
protected def copy (S : Submonoid M) (s : Set M) (hs : s = S) : Submonoid M where
carrier := s
one_mem' := show 1 ∈ s from hs.symm ▸ S.one_mem'
mul_mem' := hs.symm ▸ S.mul_mem'
variable {S : Submonoid M}
@[to_additive (attr := simp, norm_cast)]
theorem coe_copy {s : Set M} (hs : s = S) : (S.copy s hs : Set M) = s :=
rfl
@[to_additive]
theorem copy_eq {s : Set M} (hs : s = S) : S.copy s hs = S :=
SetLike.coe_injective hs
variable (S)
/-- A submonoid contains the monoid's 1. -/
@[to_additive /-- An `AddSubmonoid` contains the monoid's 0. -/]
protected theorem one_mem : (1 : M) ∈ S :=
one_mem S
/-- A submonoid is closed under multiplication. -/
@[to_additive /-- An `AddSubmonoid` is closed under addition. -/]
protected theorem mul_mem {x y : M} : x ∈ S → y ∈ S → x * y ∈ S :=
mul_mem
/-- The submonoid `M` of the monoid `M`. -/
@[to_additive /-- The additive submonoid `M` of the `AddMonoid M`. -/]
instance : Top (Submonoid M) :=
⟨{ carrier := Set.univ
one_mem' := Set.mem_univ 1
mul_mem' := fun _ _ => Set.mem_univ _ }⟩
/-- The trivial submonoid `{1}` of a monoid `M`. -/
@[to_additive /-- The trivial `AddSubmonoid` `{0}` of an `AddMonoid` `M`. -/]
instance : Bot (Submonoid M) :=
⟨{ carrier := {1}
one_mem' := Set.mem_singleton 1
mul_mem' := fun ha hb => by
simp only [Set.mem_singleton_iff] at *
rw [ha, hb, mul_one] }⟩
@[to_additive]
instance : Inhabited (Submonoid M) :=
⟨⊥⟩
@[to_additive (attr := simp)]
theorem mem_bot {x : M} : x ∈ (⊥ : Submonoid M) ↔ x = 1 :=
Set.mem_singleton_iff
@[to_additive (attr := simp)]
theorem mem_top (x : M) : x ∈ (⊤ : Submonoid M) :=
Set.mem_univ x
@[to_additive (attr := simp, norm_cast)]
theorem coe_top : ((⊤ : Submonoid M) : Set M) = Set.univ :=
rfl
@[to_additive (attr := simp, norm_cast)]
theorem coe_bot : ((⊥ : Submonoid M) : Set M) = {1} :=
rfl
/-- The inf of two submonoids is their intersection. -/
@[to_additive /-- The inf of two `AddSubmonoid`s is their intersection. -/]
instance : Min (Submonoid M) :=
⟨fun S₁ S₂ =>
{ carrier := S₁ ∩ S₂
one_mem' := ⟨S₁.one_mem, S₂.one_mem⟩
mul_mem' := fun ⟨hx, hx'⟩ ⟨hy, hy'⟩ => ⟨S₁.mul_mem hx hy, S₂.mul_mem hx' hy'⟩ }⟩
@[to_additive (attr := simp, norm_cast)]
theorem coe_inf (p p' : Submonoid M) : ((p ⊓ p' : Submonoid M) : Set M) = (p : Set M) ∩ p' :=
rfl
@[to_additive (attr := simp)]
theorem mem_inf {p p' : Submonoid M} {x : M} : x ∈ p ⊓ p' ↔ x ∈ p ∧ x ∈ p' :=
Iff.rfl
@[to_additive (attr := simp)]
theorem subsingleton_iff : Subsingleton (Submonoid M) ↔ Subsingleton M :=
⟨fun _ =>
⟨fun x y =>
have : ∀ i : M, i = 1 := fun i =>
mem_bot.mp <| Subsingleton.elim (⊤ : Submonoid M) ⊥ ▸ mem_top i
(this x).trans (this y).symm⟩,
fun _ =>
⟨fun x y => Submonoid.ext fun i => Subsingleton.elim 1 i ▸ by simp⟩⟩
@[to_additive (attr := simp)]
theorem nontrivial_iff : Nontrivial (Submonoid M) ↔ Nontrivial M :=
not_iff_not.mp
((not_nontrivial_iff_subsingleton.trans subsingleton_iff).trans
not_nontrivial_iff_subsingleton.symm)
@[to_additive]
instance [Subsingleton M] : Unique (Submonoid M) :=
⟨⟨⊥⟩, fun a => @Subsingleton.elim _ (subsingleton_iff.mpr ‹_›) a _⟩
@[to_additive]
instance [Nontrivial M] : Nontrivial (Submonoid M) :=
nontrivial_iff.mpr ‹_›
end Submonoid
namespace MonoidHom
variable [MulOneClass N]
open Submonoid
/-- The submonoid of elements `x : M` such that `f x = g x` -/
@[to_additive /-- The additive submonoid of elements `x : M` such that `f x = g x` -/]
def eqLocusM (f g : M →* N) : Submonoid M where
carrier := { x | f x = g x }
one_mem' := by rw [Set.mem_setOf_eq, f.map_one, g.map_one]
mul_mem' (hx : _ = _) (hy : _ = _) := by simp [*]
@[to_additive (attr := simp)]
theorem mem_eqLocusM {f g : M →* N} {x : M} : x ∈ f.eqLocusM g ↔ f x = g x := Iff.rfl
@[to_additive (attr := simp)]
theorem eqLocusM_same (f : M →* N) : f.eqLocusM f = ⊤ :=
SetLike.ext fun _ => eq_self_iff_true _
@[to_additive]
theorem eq_of_eqOn_topM {f g : M →* N} (h : Set.EqOn f g (⊤ : Submonoid M)) : f = g :=
ext fun _ => h trivial
end MonoidHom
end NonAssoc
namespace OneMemClass
variable {A M₁ : Type*} [SetLike A M₁] [One M₁] [hA : OneMemClass A M₁] (S' : A)
/-- A submonoid of a monoid inherits a 1. -/
@[to_additive /-- An `AddSubmonoid` of an `AddMonoid` inherits a zero. -/]
instance one : One S' :=
⟨⟨1, OneMemClass.one_mem S'⟩⟩
@[to_additive (attr := simp, norm_cast)]
theorem coe_one : ((1 : S') : M₁) = 1 :=
rfl
variable {S'}
@[to_additive (attr := simp, norm_cast)]
theorem coe_eq_one {x : S'} : (↑x : M₁) = 1 ↔ x = 1 :=
(Subtype.ext_iff.symm : (x : M₁) = (1 : S') ↔ x = 1)
variable (S')
@[to_additive]
theorem one_def : (1 : S') = ⟨1, OneMemClass.one_mem S'⟩ :=
rfl
end OneMemClass
variable {A : Type*} [MulOneClass M] [SetLike A M] [hA : SubmonoidClass A M] (S' : A)
/-- An `AddSubmonoid` of an `AddMonoid` inherits a scalar multiplication. -/
instance AddSubmonoidClass.nSMul {M} [AddMonoid M] {A : Type*} [SetLike A M]
[AddSubmonoidClass A M] (S : A) : SMul ℕ S :=
⟨fun n a => ⟨n • a.1, nsmul_mem a.2 n⟩⟩
namespace SubmonoidClass
/-- A submonoid of a monoid inherits a power operator. -/
instance nPow {M} [Monoid M] {A : Type*} [SetLike A M] [SubmonoidClass A M] (S : A) : Pow S ℕ :=
⟨fun a n => ⟨a.1 ^ n, pow_mem a.2 n⟩⟩
attribute [to_additive existing nSMul] nPow
@[to_additive (attr := simp, norm_cast)]
theorem coe_pow {M} [Monoid M] {A : Type*} [SetLike A M] [SubmonoidClass A M] {S : A} (x : S)
(n : ℕ) : ↑(x ^ n) = (x : M) ^ n :=
rfl
@[to_additive (attr := simp)]
theorem mk_pow {M} [Monoid M] {A : Type*} [SetLike A M] [SubmonoidClass A M] {S : A} (x : M)
(hx : x ∈ S) (n : ℕ) : (⟨x, hx⟩ : S) ^ n = ⟨x ^ n, pow_mem hx n⟩ :=
rfl
-- Prefer subclasses of `Monoid` over subclasses of `SubmonoidClass`.
/-- A submonoid of a unital magma inherits a unital magma structure. -/
@[to_additive
/-- An `AddSubmonoid` of a unital additive magma inherits a unital additive magma structure. -/]
instance (priority := 75) toMulOneClass {M : Type*} [MulOneClass M] {A : Type*} [SetLike A M]
[SubmonoidClass A M] (S : A) : MulOneClass S := fast_instance%
Subtype.coe_injective.mulOneClass Subtype.val rfl (fun _ _ => rfl)
-- Prefer subclasses of `Monoid` over subclasses of `SubmonoidClass`.
/-- A submonoid of a monoid inherits a monoid structure. -/
@[to_additive /-- An `AddSubmonoid` of an `AddMonoid` inherits an `AddMonoid` structure. -/]
instance (priority := 75) toMonoid {M : Type*} [Monoid M] {A : Type*} [SetLike A M]
[SubmonoidClass A M] (S : A) : Monoid S := fast_instance%
Subtype.coe_injective.monoid Subtype.val rfl (fun _ _ => rfl) (fun _ _ => rfl)
-- Prefer subclasses of `Monoid` over subclasses of `SubmonoidClass`.
/-- A submonoid of a `CommMonoid` is a `CommMonoid`. -/
@[to_additive /-- An `AddSubmonoid` of an `AddCommMonoid` is an `AddCommMonoid`. -/]
instance (priority := 75) toCommMonoid {M} [CommMonoid M] {A : Type*} [SetLike A M]
[SubmonoidClass A M] (S : A) : CommMonoid S := fast_instance%
Subtype.coe_injective.commMonoid Subtype.val rfl (fun _ _ => rfl) fun _ _ => rfl
/-- The natural monoid hom from a submonoid of monoid `M` to `M`. -/
@[to_additive /-- The natural monoid hom from an `AddSubmonoid` of `AddMonoid` `M` to `M`. -/]
def subtype : S' →* M where
toFun := Subtype.val; map_one' := rfl; map_mul' _ _ := by simp
variable {S'} in
@[to_additive (attr := simp)]
lemma subtype_apply (x : S') :
SubmonoidClass.subtype S' x = x := rfl
@[to_additive]
lemma subtype_injective :
Function.Injective (SubmonoidClass.subtype S') :=
Subtype.coe_injective
@[to_additive (attr := simp)]
theorem coe_subtype : (SubmonoidClass.subtype S' : S' → M) = Subtype.val :=
rfl
end SubmonoidClass
namespace Submonoid
variable {M : Type*} [MulOneClass M] (S : Submonoid M)
/-- A submonoid of a monoid inherits a multiplication. -/
@[to_additive /-- An `AddSubmonoid` of an `AddMonoid` inherits an addition. -/]
instance mul : Mul S :=
⟨fun a b => ⟨a.1 * b.1, S.mul_mem a.2 b.2⟩⟩
/-- A submonoid of a monoid inherits a 1. -/
@[to_additive /-- An `AddSubmonoid` of an `AddMonoid` inherits a zero. -/]
instance one : One S :=
⟨⟨_, S.one_mem⟩⟩
@[to_additive (attr := simp, norm_cast)]
theorem coe_mul (x y : S) : (↑(x * y) : M) = ↑x * ↑y :=
rfl
@[to_additive (attr := simp, norm_cast)]
theorem coe_one : ((1 : S) : M) = 1 :=
rfl
@[to_additive (attr := simp)]
lemma mk_eq_one {a : M} {ha} : (⟨a, ha⟩ : S) = 1 ↔ a = 1 := by simp [← SetLike.coe_eq_coe]
@[to_additive (attr := simp)]
theorem mk_mul_mk (x y : M) (hx : x ∈ S) (hy : y ∈ S) :
(⟨x, hx⟩ : S) * ⟨y, hy⟩ = ⟨x * y, S.mul_mem hx hy⟩ :=
rfl
@[to_additive]
theorem mul_def (x y : S) : x * y = ⟨x * y, S.mul_mem x.2 y.2⟩ :=
rfl
@[to_additive]
theorem one_def : (1 : S) = ⟨1, S.one_mem⟩ :=
rfl
/-- A submonoid of a unital magma inherits a unital magma structure. -/
@[to_additive
/-- An `AddSubmonoid` of a unital additive magma inherits a unital additive magma structure. -/]
instance toMulOneClass {M : Type*} [MulOneClass M] (S : Submonoid M) :
MulOneClass S := fast_instance%
Subtype.coe_injective.mulOneClass Subtype.val rfl fun _ _ => rfl
@[to_additive]
protected theorem pow_mem {M : Type*} [Monoid M] (S : Submonoid M) {x : M} (hx : x ∈ S) (n : ℕ) :
x ^ n ∈ S :=
pow_mem hx n
/-- A submonoid of a monoid inherits a monoid structure. -/
@[to_additive /-- An `AddSubmonoid` of an `AddMonoid` inherits an `AddMonoid` structure. -/]
instance toMonoid {M : Type*} [Monoid M] (S : Submonoid M) : Monoid S := fast_instance%
Subtype.coe_injective.monoid Subtype.val rfl (fun _ _ => rfl) fun _ _ => rfl
/-- A submonoid of a `CommMonoid` is a `CommMonoid`. -/
@[to_additive /-- An `AddSubmonoid` of an `AddCommMonoid` is an `AddCommMonoid`. -/]
instance toCommMonoid {M} [CommMonoid M] (S : Submonoid M) : CommMonoid S := fast_instance%
Subtype.coe_injective.commMonoid Subtype.val rfl (fun _ _ => rfl) fun _ _ => rfl
/-- The natural monoid hom from a submonoid of monoid `M` to `M`. -/
@[to_additive /-- The natural monoid hom from an `AddSubmonoid` of `AddMonoid` `M` to `M`. -/]
def subtype : S →* M where
toFun := Subtype.val; map_one' := rfl; map_mul' _ _ := by simp
@[to_additive (attr := simp)]
lemma subtype_apply {s : Submonoid M} (x : s) :
s.subtype x = x := rfl
@[to_additive]
lemma subtype_injective (s : Submonoid M) :
Function.Injective s.subtype :=
Subtype.coe_injective
@[to_additive (attr := simp)]
theorem coe_subtype : ⇑S.subtype = Subtype.val :=
rfl
end Submonoid |
.lake/packages/mathlib/Mathlib/Algebra/Group/Submonoid/Finsupp.lean | import Mathlib.Algebra.BigOperators.Finsupp.Basic
/-! # Connection between `Submonoid.closure` and `Finsupp.prod` -/
assert_not_exists Field
namespace Submonoid
variable {M : Type*} [CommMonoid M] {ι : Type*} (f : ι → M) (x : M)
@[to_additive]
theorem exists_finsupp_of_mem_closure_range (hx : x ∈ closure (Set.range f)) :
∃ a : ι →₀ ℕ, x = a.prod (f · ^ ·) := by
classical
induction hx using closure_induction with
| mem x h => obtain ⟨i, rfl⟩ := h; exact ⟨Finsupp.single i 1, by simp⟩
| one => use 0; simp
| mul x y hx hy hx' hy' =>
obtain ⟨⟨v, rfl⟩, w, rfl⟩ := And.intro hx' hy'
use v + w
rw [Finsupp.prod_add_index]
· simp
· simp [pow_add]
@[to_additive]
theorem exists_of_mem_closure_range [Fintype ι] (hx : x ∈ closure (Set.range f)) :
∃ a : ι → ℕ, x = ∏ i, f i ^ a i := by
obtain ⟨a, rfl⟩ := exists_finsupp_of_mem_closure_range f x hx
exact ⟨a, by simp⟩
variable {f x}
@[to_additive]
theorem mem_closure_range_iff :
x ∈ closure (Set.range f) ↔ ∃ a : ι →₀ ℕ, x = a.prod (f · ^ ·) := by
refine ⟨exists_finsupp_of_mem_closure_range f x, ?_⟩
rintro ⟨a, rfl⟩
exact prod_mem _ fun i hi ↦ pow_mem (subset_closure (Set.mem_range_self i)) _
@[to_additive]
theorem mem_closure_range_iff_of_fintype [Fintype ι] :
x ∈ closure (Set.range f) ↔ ∃ a : ι → ℕ, x = ∏ i, f i ^ a i := by
rw [Finsupp.equivFunOnFinite.symm.exists_congr_left, mem_closure_range_iff]
simp
@[to_additive]
theorem mem_closure_iff_of_fintype {s : Set M} [Fintype s] :
x ∈ closure s ↔ ∃ a : s → ℕ, x = ∏ i : s, i.1 ^ a i := by
conv_lhs => rw [← Subtype.range_coe (s := s)]
exact mem_closure_range_iff_of_fintype
/-- A variant of `Submonoid.mem_closure_finset` using `s` as the index type. -/
@[to_additive /-- A variant of `AddSubmonoid.mem_closure_finset` using `s` as the index type. -/]
theorem mem_closure_finset' {s : Finset M} :
x ∈ closure s ↔ ∃ a : s → ℕ, x = ∏ i : s, i.1 ^ a i :=
mem_closure_iff_of_fintype
end Submonoid |
.lake/packages/mathlib/Mathlib/Algebra/Group/Submonoid/Membership.lean | import Mathlib.Algebra.BigOperators.Group.Multiset.Defs
import Mathlib.Algebra.FreeMonoid.Basic
import Mathlib.Algebra.Group.Idempotent
import Mathlib.Algebra.Group.Nat.Hom
import Mathlib.Algebra.Group.Submonoid.MulOpposite
import Mathlib.Algebra.Group.Submonoid.Operations
import Mathlib.Data.Fintype.EquivFin
import Mathlib.Data.Int.Basic
/-!
# Submonoids: membership criteria
In this file we prove various facts about membership in a submonoid:
* `mem_iSup_of_directed`, `coe_iSup_of_directed`, `mem_sSup_of_directedOn`,
`coe_sSup_of_directedOn`: the supremum of a directed collection of submonoid is their union.
* `sup_eq_range`, `mem_sup`: supremum of two submonoids `S`, `T` of a commutative monoid is the set
of products;
* `closure_singleton_eq`, `mem_closure_singleton`, `mem_closure_pair`: the multiplicative (resp.,
additive) closure of `{x}` consists of powers (resp., natural multiples) of `x`, and a similar
result holds for the closure of `{x, y}`.
We also define `Submonoid.powers` and `AddSubmonoid.multiples`, the submonoids
generated by a single element.
## Tags
submonoid, submonoids
-/
assert_not_exists MonoidWithZero
variable {M A B : Type*}
section Assoc
variable [Monoid M] [SetLike B M] [SubmonoidClass B M] {S : B}
end Assoc
section NonAssoc
variable [MulOneClass M]
open Function Set
namespace Submonoid
@[to_additive]
theorem mem_biSup_of_directedOn {ι} {p : ι → Prop} {K : ι → Submonoid M} {i : ι} (hp : p i)
(hK : DirectedOn ((· ≤ ·) on K) {i | p i})
{x : M} : x ∈ (⨆ i, ⨆ (_h : p i), K i) ↔ ∃ i, p i ∧ x ∈ K i := by
refine ⟨?_, fun ⟨i, hi', hi⟩ ↦ ?_⟩
· suffices x ∈ closure (⋃ i, ⋃ (_ : p i), (K i : Set M)) → ∃ i, p i ∧ x ∈ K i by
simpa only [closure_iUnion, closure_eq (K _)] using this
refine fun hx ↦ closure_induction (fun _ ↦ ?_) ?_ ?_ hx
· simp
· exact ⟨i, hp, (K i).one_mem⟩
· rintro x y _ _ ⟨i, hip, hi⟩ ⟨j, hjp, hj⟩
rcases hK i hip j hjp with ⟨k, hk, hki, hkj⟩
exact ⟨k, hk, mul_mem (hki hi) (hkj hj)⟩
· apply le_iSup (fun i ↦ ⨆ (_ : p i), K i) i
simp [hi, hi']
-- TODO: this section can be generalized to `[SubmonoidClass B M] [CompleteLattice B]`
-- such that `CompleteLattice.LE` coincides with `SetLike.LE`
@[to_additive]
theorem mem_iSup_of_directed {ι} [hι : Nonempty ι] {S : ι → Submonoid M} (hS : Directed (· ≤ ·) S)
{x : M} : (x ∈ ⨆ i, S i) ↔ ∃ i, x ∈ S i := by
have : iSup S = ⨆ i : PLift ι, ⨆ (_ : True), S i.down := by simp [iSup_plift_down]
rw [this, mem_biSup_of_directedOn trivial]
· simp
· simp only [setOf_true]
rw [directedOn_onFun_iff, Set.image_univ, ← directedOn_range]
-- `Directed.mono_comp` and much of the Set API requires `Type u` instead of `Sort u`
intro i
simp only [PLift.exists]
intro j
refine (hS i.down j.down).imp ?_
simp
· exact PLift.up hι.some
@[to_additive (attr := simp)]
theorem mem_iSup_prop {p : Prop} {S : p → Submonoid M} {x : M} :
x ∈ ⨆ (h : p), S h ↔ x = 1 ∨ ∃ (h : p), x ∈ S h := by
by_cases h : p <;>
simp +contextual [h]
@[to_additive]
theorem coe_iSup_of_directed {ι} [Nonempty ι] {S : ι → Submonoid M} (hS : Directed (· ≤ ·) S) :
((⨆ i, S i : Submonoid M) : Set M) = ⋃ i, S i :=
Set.ext fun x ↦ by simp [mem_iSup_of_directed hS]
@[to_additive]
theorem mem_sSup_of_directedOn {S : Set (Submonoid M)} (Sne : S.Nonempty)
(hS : DirectedOn (· ≤ ·) S) {x : M} : x ∈ sSup S ↔ ∃ s ∈ S, x ∈ s := by
haveI : Nonempty S := Sne.to_subtype
simp [sSup_eq_iSup', mem_iSup_of_directed hS.directed_val]
@[to_additive]
theorem coe_sSup_of_directedOn {S : Set (Submonoid M)} (Sne : S.Nonempty)
(hS : DirectedOn (· ≤ ·) S) : (↑(sSup S) : Set M) = ⋃ s ∈ S, ↑s :=
Set.ext fun x => by simp [mem_sSup_of_directedOn Sne hS]
@[to_additive]
theorem mem_sup_left {S T : Submonoid M} : ∀ {x : M}, x ∈ S → x ∈ S ⊔ T := by
rw [← SetLike.le_def]
exact le_sup_left
@[to_additive]
theorem mem_sup_right {S T : Submonoid M} : ∀ {x : M}, x ∈ T → x ∈ S ⊔ T := by
rw [← SetLike.le_def]
exact le_sup_right
@[to_additive]
theorem mul_mem_sup {S T : Submonoid M} {x y : M} (hx : x ∈ S) (hy : y ∈ T) : x * y ∈ S ⊔ T :=
(S ⊔ T).mul_mem (mem_sup_left hx) (mem_sup_right hy)
@[to_additive]
theorem mem_iSup_of_mem {ι : Sort*} {S : ι → Submonoid M} (i : ι) :
∀ {x : M}, x ∈ S i → x ∈ iSup S := by
rw [← SetLike.le_def]
exact le_iSup _ _
@[to_additive]
theorem mem_sSup_of_mem {S : Set (Submonoid M)} {s : Submonoid M} (hs : s ∈ S) :
∀ {x : M}, x ∈ s → x ∈ sSup S := by
rw [← SetLike.le_def]
exact le_sSup hs
/-- An induction principle for elements of `⨆ i, S i`.
If `C` holds for `1` and all elements of `S i` for all `i`, and is preserved under multiplication,
then it holds for all elements of the supremum of `S`. -/
@[to_additive (attr := elab_as_elim)
/-- An induction principle for elements of `⨆ i, S i`.
If `C` holds for `0` and all elements of `S i` for all `i`, and is preserved under addition,
then it holds for all elements of the supremum of `S`. -/]
theorem iSup_induction {ι : Sort*} (S : ι → Submonoid M) {motive : M → Prop} {x : M}
(hx : x ∈ ⨆ i, S i) (mem : ∀ (i), ∀ x ∈ S i, motive x) (one : motive 1)
(mul : ∀ x y, motive x → motive y → motive (x * y)) : motive x := by
rw [iSup_eq_closure] at hx
refine closure_induction (fun x hx => ?_) one (fun _ _ _ _ ↦ mul _ _) hx
obtain ⟨i, hi⟩ := Set.mem_iUnion.mp hx
exact mem _ _ hi
/-- A dependent version of `Submonoid.iSup_induction`. -/
@[to_additive (attr := elab_as_elim) /-- A dependent version of `AddSubmonoid.iSup_induction`. -/]
theorem iSup_induction' {ι : Sort*} (S : ι → Submonoid M) {motive : ∀ x, (x ∈ ⨆ i, S i) → Prop}
(mem : ∀ (i), ∀ (x) (hxS : x ∈ S i), motive x (mem_iSup_of_mem i hxS))
(one : motive 1 (one_mem _))
(mul : ∀ x y hx hy, motive x hx → motive y hy → motive (x * y) (mul_mem ‹_› ‹_›)) {x : M}
(hx : x ∈ ⨆ i, S i) : motive x hx := by
refine Exists.elim (?_ : ∃ Hx, motive x Hx) fun (hx : x ∈ ⨆ i, S i) (hc : motive x hx) => hc
refine @iSup_induction _ _ ι S (fun m => ∃ hm, motive m hm) _ hx (fun i x hx => ?_) ?_
fun x y => ?_
· exact ⟨_, mem _ _ hx⟩
· exact ⟨_, one⟩
· rintro ⟨_, Cx⟩ ⟨_, Cy⟩
exact ⟨_, mul _ _ _ _ Cx Cy⟩
end Submonoid
end NonAssoc
namespace FreeMonoid
variable {α : Type*}
open Submonoid
@[to_additive]
theorem closure_range_of : closure (Set.range <| @of α) = ⊤ :=
eq_top_iff.2 fun x _ =>
FreeMonoid.recOn x (one_mem _) fun _x _xs hxs =>
mul_mem (subset_closure <| Set.mem_range_self _) hxs
end FreeMonoid
namespace Submonoid
variable [Monoid M] {a : M}
open MonoidHom
theorem closure_singleton_eq (x : M) : closure ({x} : Set M) = mrange (powersHom M x) :=
closure_eq_of_le (Set.singleton_subset_iff.2 ⟨Multiplicative.ofAdd 1, pow_one x⟩) fun _ ⟨_, hn⟩ =>
hn ▸ pow_mem (subset_closure <| Set.mem_singleton _) _
/-- The submonoid generated by an element of a monoid equals the set of natural number powers of
the element. -/
theorem mem_closure_singleton {x y : M} : y ∈ closure ({x} : Set M) ↔ ∃ n : ℕ, x ^ n = y := by
rw [closure_singleton_eq, mem_mrange]; rfl
theorem mem_closure_singleton_self {y : M} : y ∈ closure ({y} : Set M) :=
mem_closure_singleton.2 ⟨1, pow_one y⟩
theorem closure_singleton_one : closure ({1} : Set M) = ⊥ := by
simp [eq_bot_iff_forall, mem_closure_singleton]
section Submonoid
variable {S : Submonoid M} [Fintype S]
open Fintype
/- curly brackets `{}` are used here instead of instance brackets `[]` because
the instance in a goal is often not the same as the one inferred by type class inference. -/
@[to_additive]
theorem card_bot {_ : Fintype (⊥ : Submonoid M)} : card (⊥ : Submonoid M) = 1 :=
card_eq_one_iff.2
⟨⟨(1 : M), Set.mem_singleton 1⟩, fun ⟨_y, hy⟩ => Subtype.eq <| mem_bot.1 hy⟩
@[to_additive]
theorem eq_bot_of_card_le (h : card S ≤ 1) : S = ⊥ :=
let _ := card_le_one_iff_subsingleton.mp h
eq_bot_of_subsingleton S
@[to_additive]
theorem eq_bot_of_card_eq (h : card S = 1) : S = ⊥ :=
S.eq_bot_of_card_le (le_of_eq h)
@[to_additive card_le_one_iff_eq_bot]
theorem card_le_one_iff_eq_bot : card S ≤ 1 ↔ S = ⊥ :=
⟨fun h =>
(eq_bot_iff_forall _).2 fun x hx => by
simpa [Subtype.ext_iff] using card_le_one_iff.1 h ⟨x, hx⟩ 1,
fun h => by simp [h]⟩
@[to_additive]
lemma eq_bot_iff_card : S = ⊥ ↔ card S = 1 :=
⟨by rintro rfl; exact card_bot, eq_bot_of_card_eq⟩
end Submonoid
@[to_additive]
theorem _root_.FreeMonoid.mrange_lift {α} (f : α → M) :
mrange (FreeMonoid.lift f) = closure (Set.range f) := by
rw [mrange_eq_map, ← FreeMonoid.closure_range_of, map_mclosure, ← Set.range_comp,
FreeMonoid.lift_comp_of]
@[to_additive]
theorem closure_eq_mrange (s : Set M) : closure s = mrange (FreeMonoid.lift ((↑) : s → M)) := by
rw [FreeMonoid.mrange_lift, Subtype.range_coe]
@[to_additive]
theorem closure_eq_image_prod (s : Set M) :
(closure s : Set M) = List.prod '' { l : List M | ∀ x ∈ l, x ∈ s } := by
rw [closure_eq_mrange, coe_mrange, ← Set.range_list_map_coe, ← Set.range_comp]
exact congrArg _ (funext <| FreeMonoid.lift_apply _)
@[to_additive]
theorem exists_list_of_mem_closure {s : Set M} {x : M} (hx : x ∈ closure s) :
∃ l : List M, (∀ y ∈ l, y ∈ s) ∧ l.prod = x := by
rwa [← SetLike.mem_coe, closure_eq_image_prod, Set.mem_image] at hx
@[to_additive]
theorem exists_multiset_of_mem_closure {M : Type*} [CommMonoid M] {s : Set M} {x : M}
(hx : x ∈ closure s) : ∃ l : Multiset M, (∀ y ∈ l, y ∈ s) ∧ l.prod = x := by
obtain ⟨l, h1, h2⟩ := exists_list_of_mem_closure hx
exact ⟨l, h1, (Multiset.prod_coe l).trans h2⟩
@[to_additive (attr := elab_as_elim)]
theorem closure_induction_left
{s : Set M} {motive : (m : M) → m ∈ closure s → Prop} (one : motive 1 (one_mem _))
(mul_left : ∀ x (hx : x ∈ s), ∀ y hy,
motive y hy → motive (x * y) (mul_mem (subset_closure hx) hy))
{x : M} (h : x ∈ closure s) : motive x h := by
simp_rw [closure_eq_mrange] at h
obtain ⟨l, rfl⟩ := h
induction l using FreeMonoid.inductionOn' with
| one => exact one
| mul_of x y ih =>
simp only [map_mul, FreeMonoid.lift_eval_of]
refine mul_left _ x.prop (FreeMonoid.lift Subtype.val y) _ (ih ?_)
simp only [closure_eq_mrange, mem_mrange, exists_apply_eq_apply]
@[to_additive (attr := elab_as_elim)]
theorem induction_of_closure_eq_top_left {s : Set M} {motive : M → Prop} (hs : closure s = ⊤)
(x : M) (one : motive 1) (mul_left : ∀ x ∈ s, ∀ y, motive y → motive (x * y)) : motive x := by
have : x ∈ closure s := by simp [hs]
induction this using closure_induction_left with
| one => exact one
| mul_left x hx y _ ih => exact mul_left x hx y ih
@[to_additive (attr := elab_as_elim)]
theorem closure_induction_right
{s : Set M} {motive : (m : M) → m ∈ closure s → Prop} (one : motive 1 (one_mem _))
(mul_right : ∀ x hx, ∀ y (hy : y ∈ s),
motive x hx → motive (x * y) (mul_mem hx (subset_closure hy)))
{x : M} (h : x ∈ closure s) : motive x h :=
closure_induction_left (s := MulOpposite.unop ⁻¹' s)
(motive := fun m hm => motive m.unop <| by rwa [← op_closure] at hm)
one (fun _x hx _y _ => mul_right _ _ _ hx) (by rwa [← op_closure])
@[to_additive (attr := elab_as_elim)]
theorem induction_of_closure_eq_top_right {s : Set M} {motive : M → Prop} (hs : closure s = ⊤)
(x : M) (one : motive 1) (mul_right : ∀ x, ∀ y ∈ s, motive x → motive (x * y)) : motive x := by
have : x ∈ closure s := by simp [hs]
induction this using closure_induction_right with
| one => exact one
| mul_right x _ y hy ih => exact mul_right x y hy ih
/-- The submonoid generated by an element. -/
def powers (n : M) : Submonoid M :=
Submonoid.copy (mrange (powersHom M n)) (Set.range (n ^ · : ℕ → M)) <|
Set.ext fun n => exists_congr fun i => by simp; rfl
theorem mem_powers (n : M) : n ∈ powers n :=
⟨1, pow_one _⟩
theorem coe_powers (x : M) : ↑(powers x) = Set.range fun n : ℕ => x ^ n :=
rfl
theorem mem_powers_iff (x z : M) : x ∈ powers z ↔ ∃ n : ℕ, z ^ n = x :=
Iff.rfl
noncomputable instance decidableMemPowers : DecidablePred (· ∈ Submonoid.powers a) :=
Classical.decPred _
-- TODO the following instance should follow from a more general principle
-- See also https://github.com/leanprover-community/mathlib4/issues/2417
noncomputable instance fintypePowers [Fintype M] : Fintype (powers a) :=
inferInstanceAs <| Fintype {y // y ∈ powers a}
theorem powers_eq_closure (n : M) : powers n = closure {n} := by
ext
exact mem_closure_singleton.symm
lemma powers_le {n : M} {P : Submonoid M} : powers n ≤ P ↔ n ∈ P := by simp [powers_eq_closure]
lemma powers_one : powers (1 : M) = ⊥ := bot_unique <| powers_le.2 <| one_mem _
theorem _root_.IsIdempotentElem.coe_powers {a : M} (ha : IsIdempotentElem a) :
(Submonoid.powers a : Set M) = {1, a} :=
let S : Submonoid M :=
{ carrier := {1, a},
mul_mem' := by
rintro _ _ (rfl | rfl) (rfl | rfl)
· rw [one_mul]; exact .inl rfl
· rw [one_mul]; exact .inr rfl
· rw [mul_one]; exact .inr rfl
· rw [ha]; exact .inr rfl
one_mem' := .inl rfl }
suffices Submonoid.powers a = S from congr_arg _ this
le_antisymm (Submonoid.powers_le.mpr <| .inr rfl)
(by rintro _ (rfl | rfl); exacts [one_mem _, Submonoid.mem_powers _])
/-- The submonoid generated by an element is a group if that element has finite order. -/
abbrev groupPowers {x : M} {n : ℕ} (hpos : 0 < n) (hx : x ^ n = 1) : Group (powers x) where
inv x := x ^ (n - 1)
inv_mul_cancel y := Subtype.ext <| by
obtain ⟨_, k, rfl⟩ := y
simp only [coe_one, coe_mul, SubmonoidClass.coe_pow]
rw [← pow_succ, Nat.sub_add_cancel hpos, ← pow_mul, mul_comm, pow_mul, hx, one_pow]
zpow z x := x ^ z.natMod n
zpow_zero' z := by simp only [Int.natMod, Int.zero_emod, Int.toNat_zero, pow_zero]
zpow_neg' m x := Subtype.ext <| by
obtain ⟨_, k, rfl⟩ := x
simp only [← pow_mul, Int.natMod, SubmonoidClass.coe_pow]
rw [Int.negSucc_eq, ← Int.natCast_succ, ← Int.add_mul_emod_self_right (b := (m + 1 : ℕ))]
nth_rw 1 [← mul_one ((m + 1 : ℕ) : ℤ)]
rw [← sub_eq_neg_add, ← Int.mul_sub, ← Int.natCast_pred_of_pos hpos]; norm_cast
simp only [Int.toNat_natCast]
rw [mul_comm, pow_mul, ← pow_eq_pow_mod _ hx, mul_comm k, mul_assoc, pow_mul _ (_ % _),
← pow_eq_pow_mod _ hx, pow_mul, pow_mul]
zpow_succ' m x := Subtype.ext <| by
obtain ⟨_, k, rfl⟩ := x
simp only [← pow_mul, Int.natMod, SubmonoidClass.coe_pow, coe_mul]
norm_cast
iterate 2 rw [Int.toNat_natCast, mul_comm, pow_mul, ← pow_eq_pow_mod _ hx]
rw [← pow_mul _ m, mul_comm, pow_mul, ← pow_succ, ← pow_mul, mul_comm, pow_mul]
/-- Exponentiation map from natural numbers to powers. -/
@[simps!]
def pow (n : M) (m : ℕ) : powers n :=
(powersHom M n).mrangeRestrict (Multiplicative.ofAdd m)
theorem pow_apply (n : M) (m : ℕ) : Submonoid.pow n m = ⟨n ^ m, m, rfl⟩ :=
rfl
/-- Logarithms from powers to natural numbers. -/
def log [DecidableEq M] {n : M} (p : powers n) : ℕ :=
Nat.find <| (mem_powers_iff p.val n).mp p.prop
@[simp]
theorem pow_log_eq_self [DecidableEq M] {n : M} (p : powers n) : pow n (log p) = p :=
Subtype.ext <| Nat.find_spec p.prop
theorem pow_right_injective_iff_pow_injective {n : M} :
(Function.Injective fun m : ℕ => n ^ m) ↔ Function.Injective (pow n) :=
Subtype.coe_injective.of_comp_iff (pow n)
@[simp]
theorem log_pow_eq_self [DecidableEq M] {n : M} (h : Function.Injective fun m : ℕ => n ^ m)
(m : ℕ) : log (pow n m) = m :=
pow_right_injective_iff_pow_injective.mp h <| pow_log_eq_self _
/-- The exponentiation map is an isomorphism from the additive monoid on natural numbers to powers
when it is injective. The inverse is given by the logarithms. -/
@[simps]
def powLogEquiv [DecidableEq M] {n : M} (h : Function.Injective fun m : ℕ => n ^ m) :
Multiplicative ℕ ≃* powers n where
toFun m := pow n m.toAdd
invFun m := Multiplicative.ofAdd (log m)
left_inv := log_pow_eq_self h
right_inv := pow_log_eq_self
map_mul' _ _ := by simp only [pow, map_mul, ofAdd_add, toAdd_mul]
theorem log_mul [DecidableEq M] {n : M} (h : Function.Injective fun m : ℕ => n ^ m)
(x y : powers (n : M)) : log (x * y) = log x + log y :=
map_mul (powLogEquiv h).symm x y
theorem log_pow_int_eq_self {x : ℤ} (h : 1 < x.natAbs) (m : ℕ) : log (pow x m) = m :=
(powLogEquiv (Int.pow_right_injective h)).symm_apply_apply _
@[simp]
theorem map_powers {N : Type*} {F : Type*} [Monoid N] [FunLike F M N] [MonoidHomClass F M N]
(f : F) (m : M) :
(powers m).map f = powers (f m) := by
simp only [powers_eq_closure, map_mclosure f, Set.image_singleton]
end Submonoid
@[to_additive]
theorem IsScalarTower.of_mclosure_eq_top {N α} [Monoid M] [MulAction M N] [SMul N α] [MulAction M α]
{s : Set M} (htop : Submonoid.closure s = ⊤)
(hs : ∀ x ∈ s, ∀ (y : N) (z : α), (x • y) • z = x • y • z) : IsScalarTower M N α := by
refine ⟨fun x => Submonoid.induction_of_closure_eq_top_left htop x ?_ ?_⟩
· intro y z
rw [one_smul, one_smul]
· clear x
intro x hx x' hx' y z
rw [mul_smul, mul_smul, hs x hx, hx']
@[to_additive]
theorem SMulCommClass.of_mclosure_eq_top {N α} [Monoid M] [SMul N α] [MulAction M α] {s : Set M}
(htop : Submonoid.closure s = ⊤) (hs : ∀ x ∈ s, ∀ (y : N) (z : α), x • y • z = y • x • z) :
SMulCommClass M N α := by
refine ⟨fun x => Submonoid.induction_of_closure_eq_top_left htop x ?_ ?_⟩
· intro y z
rw [one_smul, one_smul]
· clear x
intro x hx x' hx' y z
rw [mul_smul, mul_smul, hx', hs x hx]
namespace Submonoid
variable {N : Type*} [CommMonoid N]
open MonoidHom
@[to_additive]
theorem sup_eq_range (s t : Submonoid N) : s ⊔ t = mrange (s.subtype.coprod t.subtype) := by
rw [mrange_eq_map, ← mrange_inl_sup_mrange_inr, map_sup, map_mrange, coprod_comp_inl, map_mrange,
coprod_comp_inr, mrange_subtype, mrange_subtype]
@[to_additive]
theorem mem_sup {s t : Submonoid N} {x : N} : x ∈ s ⊔ t ↔ ∃ y ∈ s, ∃ z ∈ t, y * z = x := by
simp only [sup_eq_range, mem_mrange, coprod_apply, coe_subtype, Prod.exists,
Subtype.exists, exists_prop]
end Submonoid
namespace AddSubmonoid
variable [AddMonoid A]
open Set
theorem closure_singleton_eq (x : A) :
closure ({x} : Set A) = AddMonoidHom.mrange (multiplesHom A x) :=
closure_eq_of_le (Set.singleton_subset_iff.2 ⟨1, one_nsmul x⟩) fun _ ⟨_n, hn⟩ =>
hn ▸ nsmul_mem (subset_closure <| Set.mem_singleton _) _
/-- The `AddSubmonoid` generated by an element of an `AddMonoid` equals the set of
natural number multiples of the element. -/
theorem mem_closure_singleton {x y : A} : y ∈ closure ({x} : Set A) ↔ ∃ n : ℕ, n • x = y := by
rw [closure_singleton_eq, AddMonoidHom.mem_mrange]; rfl
theorem closure_singleton_zero : closure ({0} : Set A) = ⊥ := by
simp [eq_bot_iff_forall, mem_closure_singleton, nsmul_zero]
/-- The additive submonoid generated by an element. -/
def multiples (x : A) : AddSubmonoid A :=
AddSubmonoid.copy (AddMonoidHom.mrange (multiplesHom A x)) (Set.range (fun i => i • x : ℕ → A)) <|
Set.ext fun n => exists_congr fun i => by simp
attribute [to_additive existing] Submonoid.powers
attribute [to_additive (attr := simp)] Submonoid.mem_powers
attribute [to_additive (attr := norm_cast)] Submonoid.coe_powers
attribute [to_additive] Submonoid.mem_powers_iff
attribute [to_additive] Submonoid.decidableMemPowers
attribute [to_additive] Submonoid.fintypePowers
attribute [to_additive] Submonoid.powers_eq_closure
attribute [to_additive] Submonoid.powers_le
attribute [to_additive (attr := simp)] Submonoid.powers_one
attribute [to_additive /-- The additive submonoid generated by an element is
an additive group if that element has finite order. -/] Submonoid.groupPowers
end AddSubmonoid
namespace Submonoid
/-- An element is in the closure of a two-element set if it is a linear combination of those two
elements. -/
@[to_additive
/-- An element is in the closure of a two-element set if it is a linear combination of
those two elements. -/]
theorem mem_closure_pair {A : Type*} [CommMonoid A] (a b c : A) :
c ∈ Submonoid.closure ({a, b} : Set A) ↔ ∃ m n : ℕ, a ^ m * b ^ n = c := by
rw [← Set.singleton_union, Submonoid.closure_union, mem_sup]
simp_rw [mem_closure_singleton, exists_exists_eq_and]
end Submonoid
section mul_add
theorem ofMul_image_powers_eq_multiples_ofMul [Monoid M] {x : M} :
Additive.ofMul '' (Submonoid.powers x : Set M) = AddSubmonoid.multiples (Additive.ofMul x) := by
ext
exact Set.mem_image_iff_of_inverse (congrFun rfl) (congrFun rfl)
theorem ofAdd_image_multiples_eq_powers_ofAdd [AddMonoid A] {x : A} :
Multiplicative.ofAdd '' (AddSubmonoid.multiples x : Set A) =
Submonoid.powers (Multiplicative.ofAdd x) := by
symm
rw [Equiv.eq_image_iff_symm_image_eq]
exact ofMul_image_powers_eq_multiples_ofMul
end mul_add |
.lake/packages/mathlib/Mathlib/Algebra/Group/Submonoid/BigOperators.lean | import Mathlib.Algebra.Group.Submonoid.Basic
import Mathlib.Algebra.Group.Support
import Mathlib.Data.Finset.NoncommProd
/-!
# Submonoids: membership criteria for products and sums
In this file we prove various facts about membership in a submonoid:
* `list_prod_mem`, `multiset_prod_mem`, `prod_mem`: if each element of a collection belongs
to a multiplicative submonoid, then so does their product;
* `list_sum_mem`, `multiset_sum_mem`, `sum_mem`: if each element of a collection belongs
to an additive submonoid, then so does their sum;
## Tags
submonoid, submonoids
-/
-- We don't need ordered structures to establish basic membership facts for submonoids
assert_not_exists IsOrderedRing
variable {M A B : Type*}
section SubmonoidClass
variable [Monoid M] [SetLike B M] [SubmonoidClass B M] {x : M} {S : B}
namespace SubmonoidClass
@[to_additive (attr := norm_cast, simp)]
theorem coe_list_prod (l : List S) : (l.prod : M) = (l.map (↑)).prod :=
map_list_prod (SubmonoidClass.subtype S : _ →* M) l
@[to_additive (attr := norm_cast, simp)]
theorem coe_multiset_prod {M} [CommMonoid M] [SetLike B M] [SubmonoidClass B M] (m : Multiset S) :
(m.prod : M) = (m.map (↑)).prod :=
(SubmonoidClass.subtype S : _ →* M).map_multiset_prod m
@[to_additive (attr := norm_cast, simp)]
theorem coe_finset_prod {ι M} [CommMonoid M] [SetLike B M] [SubmonoidClass B M] (f : ι → S)
(s : Finset ι) : ↑(∏ i ∈ s, f i) = (∏ i ∈ s, f i : M) :=
map_prod (SubmonoidClass.subtype S) f s
end SubmonoidClass
open SubmonoidClass
/-- Product of a list of elements in a submonoid is in the submonoid. -/
@[to_additive /-- Sum of a list of elements in an `AddSubmonoid` is in the `AddSubmonoid`. -/]
theorem list_prod_mem {l : List M} (hl : ∀ x ∈ l, x ∈ S) : l.prod ∈ S := by
lift l to List S using hl
rw [← coe_list_prod]
exact l.prod.coe_prop
/-- Product of a multiset of elements in a submonoid of a `CommMonoid` is in the submonoid. -/
@[to_additive
/-- Sum of a multiset of elements in an `AddSubmonoid` of an `AddCommMonoid` is
in the `AddSubmonoid`. -/]
theorem multiset_prod_mem {M} [CommMonoid M] [SetLike B M] [SubmonoidClass B M] (m : Multiset M)
(hm : ∀ a ∈ m, a ∈ S) : m.prod ∈ S := by
lift m to Multiset S using hm
rw [← coe_multiset_prod]
exact m.prod.coe_prop
/-- Product of elements of a submonoid of a `CommMonoid` indexed by a `Finset` is in the
submonoid. -/
@[to_additive
/-- Sum of elements in an `AddSubmonoid` of an `AddCommMonoid` indexed by a `Finset`
is in the `AddSubmonoid`. -/]
theorem prod_mem {M : Type*} [CommMonoid M] [SetLike B M] [SubmonoidClass B M] {ι : Type*}
{t : Finset ι} {f : ι → M} (h : ∀ c ∈ t, f c ∈ S) : (∏ c ∈ t, f c) ∈ S :=
multiset_prod_mem (t.1.map f) fun _x hx =>
let ⟨i, hi, hix⟩ := Multiset.mem_map.1 hx
hix ▸ h i hi
end SubmonoidClass
namespace Submonoid
section Monoid
variable [Monoid M] {x : M} (s : Submonoid M)
@[to_additive (attr := norm_cast)]
theorem coe_list_prod (l : List s) : (l.prod : M) = (l.map (↑)).prod :=
map_list_prod s.subtype l
@[to_additive (attr := norm_cast)]
theorem coe_multiset_prod {M} [CommMonoid M] (S : Submonoid M) (m : Multiset S) :
(m.prod : M) = (m.map (↑)).prod :=
S.subtype.map_multiset_prod m
@[to_additive (attr := norm_cast)]
theorem coe_finset_prod {ι M} [CommMonoid M] (S : Submonoid M) (f : ι → S) (s : Finset ι) :
↑(∏ i ∈ s, f i) = (∏ i ∈ s, f i : M) :=
map_prod S.subtype f s
/-- Product of a list of elements in a submonoid is in the submonoid. -/
@[to_additive /-- Sum of a list of elements in an `AddSubmonoid` is in the `AddSubmonoid`. -/]
theorem list_prod_mem {l : List M} (hl : ∀ x ∈ l, x ∈ s) : l.prod ∈ s := _root_.list_prod_mem hl
/-- Product of a multiset of elements in a submonoid of a `CommMonoid` is in the submonoid. -/
@[to_additive
/-- Sum of a multiset of elements in an `AddSubmonoid` of an `AddCommMonoid` is
in the `AddSubmonoid`. -/]
theorem multiset_prod_mem {M} [CommMonoid M] (S : Submonoid M) (m : Multiset M)
(hm : ∀ a ∈ m, a ∈ S) : m.prod ∈ S := _root_.multiset_prod_mem m hm
@[to_additive]
theorem multiset_noncommProd_mem (S : Submonoid M) (m : Multiset M) (comm) (h : ∀ x ∈ m, x ∈ S) :
m.noncommProd comm ∈ S := by
induction m using Quotient.inductionOn with | h l => ?_
simp only [Multiset.quot_mk_to_coe, Multiset.noncommProd_coe]
exact Submonoid.list_prod_mem _ h
/-- Product of elements of a submonoid of a `CommMonoid` indexed by a `Finset` is in the
submonoid. -/
@[to_additive
/-- Sum of elements in an `AddSubmonoid` of an `AddCommMonoid` indexed by a `Finset`
is in the `AddSubmonoid`. -/]
theorem prod_mem {M : Type*} [CommMonoid M] (S : Submonoid M) {ι : Type*} {t : Finset ι}
{f : ι → M} (h : ∀ c ∈ t, f c ∈ S) : (∏ c ∈ t, f c) ∈ S :=
S.multiset_prod_mem (t.1.map f) fun _ hx =>
let ⟨i, hi, hix⟩ := Multiset.mem_map.1 hx
hix ▸ h i hi
@[to_additive]
theorem noncommProd_mem (S : Submonoid M) {ι : Type*} (t : Finset ι) (f : ι → M) (comm)
(h : ∀ c ∈ t, f c ∈ S) : t.noncommProd f comm ∈ S := by
apply multiset_noncommProd_mem
intro y
rw [Multiset.mem_map]
rintro ⟨x, ⟨hx, rfl⟩⟩
exact h x hx
end Monoid
section CommMonoid
variable [CommMonoid M] {x : M}
@[to_additive]
lemma mem_closure_iff_exists_finset_subset {s : Set M} :
x ∈ closure s ↔
∃ (f : M → ℕ) (t : Finset M), ↑t ⊆ s ∧ f.support ⊆ t ∧ ∏ a ∈ t, a ^ f a = x where
mp hx := by
classical
induction hx using closure_induction with
| one => exact ⟨0, ∅, by simp⟩
| mem x hx =>
simp only at hx
exact ⟨Pi.single x 1, {x}, by simp [hx, Pi.single_apply]⟩
| mul x y _ _ hx hy =>
obtain ⟨f, t, hts, hf, rfl⟩ := hx
obtain ⟨g, u, hus, hg, rfl⟩ := hy
refine ⟨f + g, t ∪ u, mod_cast Set.union_subset hts hus,
(Function.support_add _ _).trans <| mod_cast Set.union_subset_union hf hg, ?_⟩
simp only [Pi.add_apply, pow_add, Finset.prod_mul_distrib]
congr 1 <;> symm
· refine Finset.prod_subset Finset.subset_union_left ?_
simp +contextual [Function.support_subset_iff'.1 hf]
· refine Finset.prod_subset Finset.subset_union_right ?_
simp +contextual [Function.support_subset_iff'.1 hg]
mpr := by
rintro ⟨n, t, hts, -, rfl⟩; exact prod_mem _ fun x hx ↦ pow_mem (subset_closure <| hts hx) _
@[to_additive]
lemma mem_closure_finset {s : Finset M} :
x ∈ closure s ↔ ∃ f : M → ℕ, f.support ⊆ s ∧ ∏ a ∈ s, a ^ f a = x where
mp := by
rw [mem_closure_iff_exists_finset_subset]
rintro ⟨f, t, hts, hf, rfl⟩
refine ⟨f, hf.trans hts, .symm <| Finset.prod_subset hts ?_⟩
simp +contextual [Function.support_subset_iff'.1 hf]
mpr := by rintro ⟨n, -, rfl⟩; exact prod_mem _ fun x hx ↦ pow_mem (subset_closure hx) _
end CommMonoid
end Submonoid |
.lake/packages/mathlib/Mathlib/Algebra/Group/Submonoid/Units.lean | import Mathlib.Algebra.Group.Submonoid.Operations
import Mathlib.Algebra.Group.Submonoid.Pointwise
import Mathlib.Algebra.Group.Subgroup.Lattice
/-!
# Submonoid of units
Given a submonoid `S` of a monoid `M`, we define the subgroup `S.units` as the units of `S` as a
subgroup of `Mˣ`. That is to say, `S.units` contains all members of `S` which have a
two-sided inverse within `S`, as terms of type `Mˣ`.
We also define, for subgroups `S` of `Mˣ`, `S.ofUnits`, which is `S` considered as a submonoid
of `M`. `Submonoid.units` and `Subgroup.ofUnits` form a Galois coinsertion.
We also make the equivalent additive definitions.
## Implementation details
There are a number of other constructions which are multiplicatively equivalent to `S.units` but
which have a different type.
| Definition | Type |
|----------------------|---------------|
| `S.units` | `Subgroup Mˣ` |
| `Sˣ` | `Type u` |
| `IsUnit.submonoid S` | `Submonoid S` |
| `S.units.ofUnits` | `Submonoid M` |
All of these are distinct from `S.leftInv`, which is the submonoid of `M` which contains
every member of `M` with a right inverse in `S`.
-/
variable {M : Type*} [Monoid M]
open Units
open Pointwise in
/-- The units of `S`, packaged as a subgroup of `Mˣ`. -/
@[to_additive /-- The additive units of `S`, packaged as an additive subgroup of `AddUnits M`. -/]
def Submonoid.units (S : Submonoid M) : Subgroup Mˣ where
toSubmonoid := S.comap (coeHom M) ⊓ (S.comap (coeHom M))⁻¹
inv_mem' ha := ⟨ha.2, ha.1⟩
/-- A subgroup of units represented as a submonoid of `M`. -/
@[to_additive
/-- A additive subgroup of additive units represented as a additive submonoid of `M`. -/]
def Subgroup.ofUnits (S : Subgroup Mˣ) : Submonoid M := S.toSubmonoid.map (coeHom M)
@[to_additive]
lemma Submonoid.units_mono : Monotone (Submonoid.units (M := M)) :=
fun _ _ hST _ ⟨h₁, h₂⟩ => ⟨hST h₁, hST h₂⟩
@[to_additive (attr := simp)]
lemma Submonoid.ofUnits_units_le (S : Submonoid M) : S.units.ofUnits ≤ S :=
fun _ ⟨_, hm, he⟩ => he ▸ hm.1
@[to_additive]
lemma Subgroup.ofUnits_mono : Monotone (Subgroup.ofUnits (M := M)) :=
fun _ _ hST _ ⟨x, hx, hy⟩ => ⟨x, hST hx, hy⟩
@[to_additive (attr := simp)]
lemma Subgroup.units_ofUnits_eq (S : Subgroup Mˣ) : S.ofUnits.units = S :=
Subgroup.ext (fun _ =>
⟨fun ⟨⟨_, hm, he⟩, _⟩ => (Units.ext he) ▸ hm, fun hm => ⟨⟨_, hm, rfl⟩, _, S.inv_mem hm, rfl⟩⟩)
/-- A Galois coinsertion exists between the coercion from a subgroup of units to a submonoid and
the reduction from a submonoid to its unit group. -/
@[to_additive /-- A Galois coinsertion exists between the coercion from a additive subgroup of
additive units to a additive submonoid and the reduction from a additive submonoid to its unit
group. -/]
def ofUnits_units_gci : GaloisCoinsertion (Subgroup.ofUnits (M := M)) (Submonoid.units) :=
GaloisCoinsertion.monotoneIntro Submonoid.units_mono Subgroup.ofUnits_mono
Submonoid.ofUnits_units_le Subgroup.units_ofUnits_eq
@[to_additive]
lemma ofUnits_units_gc : GaloisConnection (Subgroup.ofUnits (M := M)) (Submonoid.units) :=
ofUnits_units_gci.gc
@[to_additive]
lemma ofUnits_le_iff_le_units (S : Submonoid M) (H : Subgroup Mˣ) :
H.ofUnits ≤ S ↔ H ≤ S.units := ofUnits_units_gc _ _
namespace Submonoid
section Units
@[to_additive]
lemma mem_units_iff (S : Submonoid M) (x : Mˣ) : x ∈ S.units ↔
((x : M) ∈ S ∧ ((x⁻¹ : Mˣ) : M) ∈ S) := Iff.rfl
@[to_additive]
lemma mem_units_of_val_mem_inv_val_mem (S : Submonoid M) {x : Mˣ} (h₁ : (x : M) ∈ S)
(h₂ : ((x⁻¹ : Mˣ) : M) ∈ S) : x ∈ S.units := ⟨h₁, h₂⟩
@[to_additive]
lemma val_mem_of_mem_units (S : Submonoid M) {x : Mˣ} (h : x ∈ S.units) : (x : M) ∈ S := h.1
@[to_additive]
lemma inv_val_mem_of_mem_units (S : Submonoid M) {x : Mˣ} (h : x ∈ S.units) :
((x⁻¹ : Mˣ) : M) ∈ S := h.2
@[to_additive]
lemma coe_inv_val_mul_coe_val (S : Submonoid M) {x : Sˣ} :
((x⁻¹ : Sˣ) : M) * ((x : Sˣ) : M) = 1 := DFunLike.congr_arg S.subtype x.inv_mul
@[to_additive]
lemma coe_val_mul_coe_inv_val (S : Submonoid M) {x : Sˣ} :
((x : Sˣ) : M) * ((x⁻¹ : Sˣ) : M) = 1 := DFunLike.congr_arg S.subtype x.mul_inv
@[to_additive]
lemma mk_inv_mul_mk_eq_one (S : Submonoid M) {x : Mˣ} (h : x ∈ S.units) :
(⟨_, h.2⟩ : S) * ⟨_, h.1⟩ = 1 := Subtype.ext x.inv_mul
@[to_additive]
lemma mk_mul_mk_inv_eq_one (S : Submonoid M) {x : Mˣ} (h : x ∈ S.units) :
(⟨_, h.1⟩ : S) * ⟨_, h.2⟩ = 1 := Subtype.ext x.mul_inv
@[to_additive]
lemma mul_mem_units (S : Submonoid M) {x y : Mˣ} (h₁ : x ∈ S.units) (h₂ : y ∈ S.units) :
x * y ∈ S.units := mul_mem h₁ h₂
@[to_additive]
lemma inv_mem_units (S : Submonoid M) {x : Mˣ} (h : x ∈ S.units) : x⁻¹ ∈ S.units := inv_mem h
@[to_additive]
lemma inv_mem_units_iff (S : Submonoid M) {x : Mˣ} : x⁻¹ ∈ S.units ↔ x ∈ S.units := inv_mem_iff
/-- The equivalence between the subgroup of units of `S` and the type of units of `S`. -/
@[to_additive /-- The equivalence between the additive subgroup of additive units of
`S` and the type of additive units of `S`. -/]
def unitsEquivUnitsType (S : Submonoid M) : S.units ≃* Sˣ where
toFun := fun ⟨_, h⟩ => ⟨⟨_, h.1⟩, ⟨_, h.2⟩, S.mk_mul_mk_inv_eq_one h, S.mk_inv_mul_mk_eq_one h⟩
invFun := fun x => ⟨⟨_, _, S.coe_val_mul_coe_inv_val, S.coe_inv_val_mul_coe_val⟩, ⟨x.1.2, x.2.2⟩⟩
map_mul' := fun _ _ => rfl
@[to_additive (attr := simp)]
lemma units_top : (⊤ : Submonoid M).units = ⊤ := ofUnits_units_gc.u_top
@[to_additive]
lemma units_inf (S T : Submonoid M) : (S ⊓ T).units = S.units ⊓ T.units :=
ofUnits_units_gc.u_inf
@[to_additive]
lemma units_sInf {s : Set (Submonoid M)} : (sInf s).units = ⨅ S ∈ s, S.units :=
ofUnits_units_gc.u_sInf
@[to_additive]
lemma units_iInf {ι : Sort*} (f : ι → Submonoid M) : (iInf f).units = ⨅ (i : ι), (f i).units :=
ofUnits_units_gc.u_iInf
@[to_additive]
lemma units_iInf₂ {ι : Sort*} {κ : ι → Sort*} (f : (i : ι) → κ i → Submonoid M) :
(⨅ (i : ι), ⨅ (j : κ i), f i j).units = ⨅ (i : ι), ⨅ (j : κ i), (f i j).units :=
ofUnits_units_gc.u_iInf₂
@[to_additive (attr := simp)]
lemma units_bot : (⊥ : Submonoid M).units = ⊥ := ofUnits_units_gci.u_bot
@[to_additive]
lemma units_surjective : Function.Surjective (units (M := M)) :=
ofUnits_units_gci.u_surjective
@[to_additive]
lemma units_left_inverse :
Function.LeftInverse (units (M := M)) (Subgroup.ofUnits (M := M)) :=
ofUnits_units_gci.u_l_leftInverse
/-- The equivalence between the subgroup of units of `S` and the submonoid of unit
elements of `S`. -/
@[to_additive /-- The equivalence between the additive subgroup of additive units of
`S` and the additive submonoid of additive unit elements of `S`. -/]
noncomputable def unitsEquivIsUnitSubmonoid (S : Submonoid M) : S.units ≃* IsUnit.submonoid S :=
S.unitsEquivUnitsType.trans unitsTypeEquivIsUnitSubmonoid
end Units
end Submonoid
namespace Subgroup
@[to_additive]
lemma mem_ofUnits_iff (S : Subgroup Mˣ) (x : M) : x ∈ S.ofUnits ↔ ∃ y ∈ S, y = x := Iff.rfl
@[to_additive]
lemma mem_ofUnits (S : Subgroup Mˣ) {x : M} {y : Mˣ} (h₁ : y ∈ S) (h₂ : y = x) : x ∈ S.ofUnits :=
⟨_, h₁, h₂⟩
@[to_additive]
lemma exists_mem_ofUnits_val_eq (S : Subgroup Mˣ) {x : M} (h : x ∈ S.ofUnits) :
∃ y ∈ S, y = x := h
@[to_additive]
lemma mem_of_mem_val_ofUnits (S : Subgroup Mˣ) {y : Mˣ} (hy : (y : M) ∈ S.ofUnits) : y ∈ S :=
match hy with
| ⟨_, hm, he⟩ => (Units.ext he) ▸ hm
@[to_additive]
lemma isUnit_of_mem_ofUnits (S : Subgroup Mˣ) {x : M} (hx : x ∈ S.ofUnits) : IsUnit x :=
match hx with
| ⟨_, _, h⟩ => ⟨_, h⟩
/-- Given some `x : M` which is a member of the submonoid of unit elements corresponding to a
subgroup of units, produce a unit of `M` whose coercion is equal to `x`. -/
@[to_additive /-- Given some `x : M` which is a member of the additive submonoid of additive unit
elements corresponding to a subgroup of units, produce a unit of `M` whose coercion is equal to
`x`. -/]
noncomputable def unit_of_mem_ofUnits (S : Subgroup Mˣ) {x : M} (h : x ∈ S.ofUnits) : Mˣ :=
(Classical.choose h).copy x (Classical.choose_spec h).2.symm _ rfl
@[to_additive]
lemma unit_of_mem_ofUnits_spec_eq_of_val_mem (S : Subgroup Mˣ) {x : Mˣ} (h : (x : M) ∈ S.ofUnits) :
S.unit_of_mem_ofUnits h = x := Units.ext rfl
@[to_additive]
lemma unit_of_mem_ofUnits_spec_val_eq_of_mem (S : Subgroup Mˣ) {x : M} (h : x ∈ S.ofUnits) :
S.unit_of_mem_ofUnits h = x := rfl
@[to_additive]
lemma unit_of_mem_ofUnits_spec_mem (S : Subgroup Mˣ) {x : M} {h : x ∈ S.ofUnits} :
S.unit_of_mem_ofUnits h ∈ S := S.mem_of_mem_val_ofUnits h
@[to_additive]
lemma unit_eq_unit_of_mem_ofUnits (S : Subgroup Mˣ) {x : M} (h₁ : IsUnit x)
(h₂ : x ∈ S.ofUnits) : h₁.unit = S.unit_of_mem_ofUnits h₂ := Units.ext rfl
@[to_additive]
lemma unit_mem_of_mem_ofUnits (S : Subgroup Mˣ) {x : M} {h₁ : IsUnit x}
(h₂ : x ∈ S.ofUnits) : h₁.unit ∈ S :=
S.unit_eq_unit_of_mem_ofUnits h₁ h₂ ▸ (S.unit_of_mem_ofUnits_spec_mem)
@[to_additive]
lemma mem_ofUnits_of_isUnit_of_unit_mem (S : Subgroup Mˣ) {x : M} (h₁ : IsUnit x)
(h₂ : h₁.unit ∈ S) : x ∈ S.ofUnits := S.mem_ofUnits h₂ h₁.unit_spec
@[to_additive]
lemma mem_ofUnits_iff_exists_isUnit (S : Subgroup Mˣ) (x : M) :
x ∈ S.ofUnits ↔ ∃ h : IsUnit x, h.unit ∈ S :=
⟨fun h => ⟨S.isUnit_of_mem_ofUnits h, S.unit_mem_of_mem_ofUnits h⟩,
fun ⟨hm, he⟩ => S.mem_ofUnits_of_isUnit_of_unit_mem hm he⟩
/-- The equivalence between the coercion of a subgroup `S` of `Mˣ` to a submonoid of `M` and
the subgroup itself as a type. -/
@[to_additive /-- The equivalence between the coercion of an additive subgroup `S` of
`Mˣ` to an additive submonoid of `M` and the additive subgroup itself as a type. -/]
noncomputable def ofUnitsEquivType (S : Subgroup Mˣ) : S.ofUnits ≃* S where
toFun := fun x => ⟨S.unit_of_mem_ofUnits x.2, S.unit_of_mem_ofUnits_spec_mem⟩
invFun := fun x => ⟨x.1, ⟨x.1, x.2, rfl⟩⟩
map_mul' := fun _ _ => Subtype.ext (Units.ext rfl)
@[to_additive (attr := simp)]
lemma ofUnits_bot : (⊥ : Subgroup Mˣ).ofUnits = ⊥ := ofUnits_units_gc.l_bot
@[to_additive]
lemma ofUnits_inf (S T : Subgroup Mˣ) : (S ⊔ T).ofUnits = S.ofUnits ⊔ T.ofUnits :=
ofUnits_units_gc.l_sup
@[to_additive]
lemma ofUnits_sSup (s : Set (Subgroup Mˣ)) : (sSup s).ofUnits = ⨆ S ∈ s, S.ofUnits :=
ofUnits_units_gc.l_sSup
@[to_additive]
lemma ofUnits_iSup {ι : Sort*} {f : ι → Subgroup Mˣ} :
(iSup f).ofUnits = ⨆ (i : ι), (f i).ofUnits := ofUnits_units_gc.l_iSup
@[to_additive]
lemma ofUnits_iSup₂ {ι : Sort*} {κ : ι → Sort*} (f : (i : ι) → κ i → Subgroup Mˣ) :
(⨆ (i : ι), ⨆ (j : κ i), f i j).ofUnits = ⨆ (i : ι), ⨆ (j : κ i), (f i j).ofUnits :=
ofUnits_units_gc.l_iSup₂
@[to_additive]
lemma ofUnits_injective : Function.Injective (ofUnits (M := M)) :=
ofUnits_units_gci.l_injective
@[to_additive (attr := simp)]
lemma ofUnits_sup_units (S T : Subgroup Mˣ) : (S.ofUnits ⊔ T.ofUnits).units = S ⊔ T :=
ofUnits_units_gci.u_sup_l _ _
@[to_additive (attr := simp)]
lemma ofUnits_inf_units (S T : Subgroup Mˣ) : (S.ofUnits ⊓ T.ofUnits).units = S ⊓ T :=
ofUnits_units_gci.u_inf_l _ _
@[to_additive]
lemma ofUnits_right_inverse :
Function.RightInverse (ofUnits (M := M)) (Submonoid.units (M := M)) :=
ofUnits_units_gci.u_l_leftInverse
@[to_additive]
lemma ofUnits_strictMono : StrictMono (ofUnits (M := M)) := ofUnits_units_gci.strictMono_l
lemma ofUnits_le_ofUnits_iff {S T : Subgroup Mˣ} : S.ofUnits ≤ T.ofUnits ↔ S ≤ T :=
ofUnits_units_gci.l_le_l_iff
/-- The equivalence between the top subgroup of `Mˣ` coerced to a submonoid `M` and the
units of `M`. -/
@[to_additive /-- The equivalence between the additive subgroup of additive units of
`S` and the additive submonoid of additive unit elements of `S`. -/]
noncomputable def ofUnitsTopEquiv : (⊤ : Subgroup Mˣ).ofUnits ≃* Mˣ :=
(⊤ : Subgroup Mˣ).ofUnitsEquivType.trans topEquiv
variable {G : Type*} [Group G]
@[to_additive]
lemma mem_units_iff_val_mem (H : Subgroup G) (x : Gˣ) : x ∈ H.units ↔ (x : G) ∈ H := by
simp_rw [Submonoid.mem_units_iff, mem_toSubmonoid, val_inv_eq_inv_val, inv_mem_iff, and_self]
@[to_additive]
lemma mem_ofUnits_iff_toUnits_mem (H : Subgroup Gˣ) (x : G) : x ∈ H.ofUnits ↔ (toUnits x) ∈ H := by
simp_rw [mem_ofUnits_iff, toUnits.surjective.exists, val_toUnits_apply, exists_eq_right]
@[to_additive (attr := simp)]
lemma mem_iff_toUnits_mem_units (H : Subgroup G) (x : G) : toUnits x ∈ H.units ↔ x ∈ H := by
simp_rw [mem_units_iff_val_mem, val_toUnits_apply]
@[to_additive (attr := simp)]
lemma val_mem_ofUnits_iff_mem (H : Subgroup Gˣ) (x : Gˣ) : (x : G) ∈ H.ofUnits ↔ x ∈ H := by
simp_rw [mem_ofUnits_iff_toUnits_mem, toUnits_val_apply]
/-- The equivalence between the greatest subgroup of units contained within `T` and `T` itself. -/
@[to_additive /-- The equivalence between the greatest subgroup of additive units
contained within `T` and `T` itself. -/]
def unitsEquivSelf (H : Subgroup G) : H.units ≃* H :=
H.unitsEquivUnitsType.trans (toUnits (G := H)).symm
end Subgroup |
.lake/packages/mathlib/Mathlib/Algebra/Group/Submonoid/MulAction.lean | import Mathlib.Algebra.Group.Submonoid.Defs
import Mathlib.Algebra.Group.Action.Defs
/-!
# Actions by `Submonoid`s
These instances transfer the action by an element `m : M` of a monoid `M` written as `m • a` onto
the action by an element `s : S` of a submonoid `S : Submonoid M` such that `s • a = (s : M) • a`.
These instances work particularly well in conjunction with `Monoid.toMulAction`, enabling
`s • m` as an alias for `↑s * m`.
-/
assert_not_exists RelIso
namespace Submonoid
variable {M' : Type*} {α β : Type*}
section SetLike
variable {S' : Type*} [SetLike S' M'] (s : S')
@[to_additive]
instance (priority := low) [SMul M' α] : SMul s α where
smul m a := (m : M') • a
section MulOneClass
variable [MulOneClass M']
@[to_additive]
instance (priority := low) [SMul M' β] [SMul α β] [SMulCommClass M' α β] : SMulCommClass s α β :=
⟨fun a _ _ => smul_comm (a : M') _ _⟩
@[to_additive]
instance (priority := low) [SMul α β] [SMul M' β] [SMulCommClass α M' β] : SMulCommClass α s β :=
⟨fun a s => smul_comm a (s : M')⟩
@[to_additive]
instance (priority := low) [SMul α β] [SMul M' α] [SMul M' β] [IsScalarTower M' α β] :
IsScalarTower s α β :=
⟨fun a => smul_assoc (a : M')⟩
end MulOneClass
variable [Monoid M'] [SubmonoidClass S' M']
@[to_additive]
instance (priority := low) [MulAction M' α] : MulAction s α where
one_smul := one_smul M'
mul_smul m₁ m₂ := mul_smul (m₁ : M') m₂
end SetLike
section MulOneClass
variable [MulOneClass M']
@[to_additive]
instance smul [SMul M' α] (S : Submonoid M') : SMul S α :=
inferInstance
@[to_additive]
instance smulCommClass_left [SMul M' β] [SMul α β] [SMulCommClass M' α β]
(S : Submonoid M') : SMulCommClass S α β :=
inferInstance
@[to_additive]
instance smulCommClass_right [SMul α β] [SMul M' β] [SMulCommClass α M' β]
(S : Submonoid M') : SMulCommClass α S β :=
inferInstance
/-- Note that this provides `IsScalarTower S M' M'` which is needed by `SMulMulAssoc`. -/
@[to_additive]
instance isScalarTower [SMul α β] [SMul M' α] [SMul M' β] [IsScalarTower M' α β]
(S : Submonoid M') :
IsScalarTower S α β :=
inferInstance
section SMul
variable [SMul M' α] {S : Submonoid M'}
@[to_additive] lemma smul_def (g : S) (a : α) : g • a = (g : M') • a := rfl
@[to_additive (attr := simp)]
lemma mk_smul (g : M') (hg : g ∈ S) (a : α) : (⟨g, hg⟩ : S) • a = g • a := rfl
end SMul
end MulOneClass
variable [Monoid M']
/-- The action by a submonoid is the action by the underlying monoid. -/
@[to_additive
/-- The additive action by an `AddSubmonoid` is the action by the underlying `AddMonoid`. -/]
instance mulAction [MulAction M' α] (S : Submonoid M') : MulAction S α :=
inferInstance
example {S : Submonoid M'} : IsScalarTower S M' M' := by infer_instance
end Submonoid |
.lake/packages/mathlib/Mathlib/Algebra/Group/Units/Opposite.lean | import Mathlib.Algebra.Group.Equiv.Defs
import Mathlib.Algebra.Group.Opposite
import Mathlib.Algebra.Group.Units.Defs
/-!
# Units in multiplicative and additive opposites
-/
assert_not_exists MonoidWithZero DenselyOrdered
variable {α : Type*}
open MulOpposite
/-- The units of the opposites are equivalent to the opposites of the units. -/
@[to_additive
/-- The additive units of the additive opposites are equivalent to the additive opposites
of the additive units. -/]
def Units.opEquiv {M} [Monoid M] : Mᵐᵒᵖˣ ≃* Mˣᵐᵒᵖ where
toFun u := op ⟨unop u, unop ↑u⁻¹, op_injective u.4, op_injective u.3⟩
invFun := MulOpposite.rec' fun u => ⟨op ↑u, op ↑u⁻¹, unop_injective <| u.4, unop_injective u.3⟩
map_mul' _ _ := unop_injective <| Units.ext <| rfl
@[to_additive (attr := simp)]
theorem Units.coe_unop_opEquiv {M} [Monoid M] (u : Mᵐᵒᵖˣ) :
((Units.opEquiv u).unop : M) = unop (u : Mᵐᵒᵖ) :=
rfl
@[to_additive (attr := simp)]
theorem Units.coe_opEquiv_symm {M} [Monoid M] (u : Mˣᵐᵒᵖ) :
(Units.opEquiv.symm u : Mᵐᵒᵖ) = op (u.unop : M) :=
rfl
@[to_additive]
nonrec theorem IsUnit.op {M} [Monoid M] {m : M} (h : IsUnit m) : IsUnit (op m) :=
let ⟨u, hu⟩ := h
hu ▸ ⟨Units.opEquiv.symm (op u), rfl⟩
@[to_additive]
nonrec theorem IsUnit.unop {M} [Monoid M] {m : Mᵐᵒᵖ} (h : IsUnit m) : IsUnit (unop m) :=
let ⟨u, hu⟩ := h
hu ▸ ⟨unop (Units.opEquiv u), rfl⟩
@[to_additive (attr := simp)]
theorem isUnit_op {M} [Monoid M] {m : M} : IsUnit (op m) ↔ IsUnit m :=
⟨IsUnit.unop, IsUnit.op⟩
@[to_additive (attr := simp)]
theorem isUnit_unop {M} [Monoid M] {m : Mᵐᵒᵖ} : IsUnit (unop m) ↔ IsUnit m :=
⟨IsUnit.op, IsUnit.unop⟩ |
.lake/packages/mathlib/Mathlib/Algebra/Group/Units/Basic.lean | import Mathlib.Algebra.Group.Basic
import Mathlib.Algebra.Group.Commute.Defs
import Mathlib.Algebra.Group.Units.Defs
import Mathlib.Logic.Unique
import Mathlib.Tactic.Nontriviality
import Mathlib.Tactic.Lift
import Mathlib.Tactic.Subsingleton
/-!
# Units (i.e., invertible elements) of a monoid
An element of a `Monoid` is a unit if it has a two-sided inverse.
This file contains the basic lemmas on units in a monoid, especially focusing on singleton types
and unique types.
## TODO
The results here should be used to golf the basic `Group` lemmas.
-/
assert_not_exists Multiplicative MonoidWithZero DenselyOrdered
open Function
universe u
variable {α : Type u}
section HasElem
@[to_additive]
theorem unique_one {α : Type*} [Unique α] [One α] : default = (1 : α) :=
Unique.default_eq 1
end HasElem
namespace Units
section Monoid
variable [Monoid α]
variable (b c : αˣ) {u : αˣ}
@[to_additive (attr := simp)]
theorem mul_inv_cancel_right (a : α) (b : αˣ) : a * b * ↑b⁻¹ = a := by
rw [mul_assoc, mul_inv, mul_one]
@[to_additive (attr := simp)]
theorem inv_mul_cancel_right (a : α) (b : αˣ) : a * ↑b⁻¹ * b = a := by
rw [mul_assoc, inv_mul, mul_one]
@[to_additive (attr := simp)]
theorem mul_right_inj (a : αˣ) {b c : α} : (a : α) * b = a * c ↔ b = c :=
⟨fun h => by simpa only [inv_mul_cancel_left] using congr_arg (fun x : α => ↑(a⁻¹ : αˣ) * x) h,
congr_arg _⟩
@[to_additive (attr := simp)]
theorem mul_left_inj (a : αˣ) {b c : α} : b * a = c * a ↔ b = c :=
⟨fun h => by simpa only [mul_inv_cancel_right] using congr_arg (fun x : α => x * ↑(a⁻¹ : αˣ)) h,
congr_arg (· * a.val)⟩
@[to_additive]
theorem eq_mul_inv_iff_mul_eq {a b : α} : a = b * ↑c⁻¹ ↔ a * c = b :=
⟨fun h => by rw [h, inv_mul_cancel_right], fun h => by rw [← h, mul_inv_cancel_right]⟩
@[to_additive]
theorem eq_inv_mul_iff_mul_eq {a c : α} : a = ↑b⁻¹ * c ↔ ↑b * a = c :=
⟨fun h => by rw [h, mul_inv_cancel_left], fun h => by rw [← h, inv_mul_cancel_left]⟩
@[to_additive]
theorem mul_inv_eq_iff_eq_mul {a c : α} : a * ↑b⁻¹ = c ↔ a = c * b :=
⟨fun h => by rw [← h, inv_mul_cancel_right], fun h => by rw [h, mul_inv_cancel_right]⟩
@[to_additive]
protected theorem inv_eq_of_mul_eq_one_left {a : α} (h : a * u = 1) : ↑u⁻¹ = a :=
calc
↑u⁻¹ = 1 * ↑u⁻¹ := by rw [one_mul]
_ = a := by rw [← h, mul_inv_cancel_right]
@[to_additive]
protected theorem inv_eq_of_mul_eq_one_right {a : α} (h : ↑u * a = 1) : ↑u⁻¹ = a :=
calc
↑u⁻¹ = ↑u⁻¹ * 1 := by rw [mul_one]
_ = a := by rw [← h, inv_mul_cancel_left]
@[to_additive]
protected theorem eq_inv_of_mul_eq_one_left {a : α} (h : ↑u * a = 1) : a = ↑u⁻¹ :=
(Units.inv_eq_of_mul_eq_one_right h).symm
@[to_additive]
protected theorem eq_inv_of_mul_eq_one_right {a : α} (h : a * u = 1) : a = ↑u⁻¹ :=
(Units.inv_eq_of_mul_eq_one_left h).symm
@[to_additive (attr := simp)]
theorem mul_inv_eq_one {a : α} : a * ↑u⁻¹ = 1 ↔ a = u :=
⟨inv_inv u ▸ Units.eq_inv_of_mul_eq_one_right, fun h => mul_inv_of_eq h.symm⟩
@[to_additive (attr := simp)]
theorem inv_mul_eq_one {a : α} : ↑u⁻¹ * a = 1 ↔ ↑u = a :=
⟨inv_inv u ▸ Units.inv_eq_of_mul_eq_one_right, inv_mul_of_eq⟩
@[to_additive]
theorem mul_eq_one_iff_eq_inv {a : α} : a * u = 1 ↔ a = ↑u⁻¹ := by rw [← mul_inv_eq_one, inv_inv]
@[to_additive]
theorem mul_eq_one_iff_inv_eq {a : α} : ↑u * a = 1 ↔ ↑u⁻¹ = a := by rw [← inv_mul_eq_one, inv_inv]
@[to_additive]
theorem inv_unique {u₁ u₂ : αˣ} (h : (↑u₁ : α) = ↑u₂) : (↑u₁⁻¹ : α) = ↑u₂⁻¹ :=
Units.inv_eq_of_mul_eq_one_right <| by rw [h, u₂.mul_inv]
end Monoid
section CommMonoid
variable [CommMonoid α] (a c : α) (b d : αˣ)
@[to_additive]
theorem mul_inv_eq_mul_inv_iff : a * b⁻¹ = c * d⁻¹ ↔ a * d = c * b := by
rw [mul_comm c, Units.mul_inv_eq_iff_eq_mul, mul_assoc, Units.eq_inv_mul_iff_mul_eq, mul_comm]
@[to_additive]
theorem inv_mul_eq_inv_mul_iff : b⁻¹ * a = d⁻¹ * c ↔ a * d = c * b := by
rw [mul_comm, mul_comm _ c, mul_inv_eq_mul_inv_iff]
end CommMonoid
end Units
section Monoid
variable [Monoid α]
@[simp]
theorem divp_left_inj (u : αˣ) {a b : α} : a /ₚ u = b /ₚ u ↔ a = b :=
Units.mul_left_inj _
theorem divp_eq_iff_mul_eq {x : α} {u : αˣ} {y : α} : x /ₚ u = y ↔ y * u = x :=
u.mul_left_inj.symm.trans <| by rw [divp_mul_cancel]; exact ⟨Eq.symm, Eq.symm⟩
theorem eq_divp_iff_mul_eq {x : α} {u : αˣ} {y : α} : x = y /ₚ u ↔ x * u = y := by
rw [eq_comm, divp_eq_iff_mul_eq]
theorem divp_eq_one_iff_eq {a : α} {u : αˣ} : a /ₚ u = 1 ↔ a = u :=
(Units.mul_left_inj u).symm.trans <| by rw [divp_mul_cancel, one_mul]
theorem inv_eq_one_divp' (u : αˣ) : ((1 / u : αˣ) : α) = 1 /ₚ u := by
rw [one_div, one_divp]
end Monoid
namespace LeftCancelMonoid
variable [LeftCancelMonoid α] [Subsingleton αˣ] {a b : α}
@[to_additive]
protected theorem eq_one_of_mul_right (h : a * b = 1) : a = 1 :=
congr_arg Units.inv <| Subsingleton.elim (Units.mk _ _ (by
rw [← mul_left_cancel_iff (a := a), ← mul_assoc, h, one_mul, mul_one]) h) 1
@[to_additive]
protected theorem eq_one_of_mul_left (h : a * b = 1) : b = 1 := by
rwa [LeftCancelMonoid.eq_one_of_mul_right h, one_mul] at h
@[to_additive (attr := simp)]
protected theorem mul_eq_one : a * b = 1 ↔ a = 1 ∧ b = 1 :=
⟨fun h => ⟨LeftCancelMonoid.eq_one_of_mul_right h, LeftCancelMonoid.eq_one_of_mul_left h⟩, by
rintro ⟨rfl, rfl⟩
exact mul_one _⟩
@[to_additive]
protected theorem mul_ne_one : a * b ≠ 1 ↔ a ≠ 1 ∨ b ≠ 1 := by rw [not_iff_comm]; simp
end LeftCancelMonoid
namespace RightCancelMonoid
variable [RightCancelMonoid α] [Subsingleton αˣ] {a b : α}
@[to_additive]
protected theorem eq_one_of_mul_right (h : a * b = 1) : a = 1 :=
congr_arg Units.inv <| Subsingleton.elim (Units.mk _ _ (by
rw [← mul_right_cancel_iff (a := b), mul_assoc, h, one_mul, mul_one]) h) 1
@[to_additive]
protected theorem eq_one_of_mul_left (h : a * b = 1) : b = 1 := by
rwa [RightCancelMonoid.eq_one_of_mul_right h, one_mul] at h
@[to_additive (attr := simp)]
protected theorem mul_eq_one : a * b = 1 ↔ a = 1 ∧ b = 1 :=
⟨fun h => ⟨RightCancelMonoid.eq_one_of_mul_right h, RightCancelMonoid.eq_one_of_mul_left h⟩, by
rintro ⟨rfl, rfl⟩
exact mul_one _⟩
@[to_additive]
protected theorem mul_ne_one : a * b ≠ 1 ↔ a ≠ 1 ∨ b ≠ 1 := by rw [not_iff_comm]; simp
end RightCancelMonoid
section CancelMonoid
variable [CancelMonoid α] [Subsingleton αˣ] {a b : α}
@[to_additive]
theorem eq_one_of_mul_right' (h : a * b = 1) : a = 1 := LeftCancelMonoid.eq_one_of_mul_right h
@[to_additive]
theorem eq_one_of_mul_left' (h : a * b = 1) : b = 1 := LeftCancelMonoid.eq_one_of_mul_left h
@[to_additive]
theorem mul_eq_one' : a * b = 1 ↔ a = 1 ∧ b = 1 := LeftCancelMonoid.mul_eq_one
@[to_additive]
theorem mul_ne_one' : a * b ≠ 1 ↔ a ≠ 1 ∨ b ≠ 1 := LeftCancelMonoid.mul_ne_one
end CancelMonoid
section CommMonoid
variable [CommMonoid α]
theorem divp_mul_eq_mul_divp (x y : α) (u : αˣ) : x /ₚ u * y = x * y /ₚ u := by
rw [divp, divp, mul_right_comm]
theorem divp_eq_divp_iff {x y : α} {ux uy : αˣ} : x /ₚ ux = y /ₚ uy ↔ x * uy = y * ux := by
rw [divp_eq_iff_mul_eq, divp_mul_eq_mul_divp, divp_eq_iff_mul_eq]
theorem divp_mul_divp (x y : α) (ux uy : αˣ) : x /ₚ ux * (y /ₚ uy) = x * y /ₚ (ux * uy) := by
rw [divp_mul_eq_mul_divp, ← divp_assoc, divp_divp_eq_divp_mul]
variable [Subsingleton αˣ] {a b : α}
@[to_additive]
theorem eq_one_of_mul_right (h : a * b = 1) : a = 1 :=
congr_arg Units.inv <| Subsingleton.elim (Units.mk _ _ (by rwa [mul_comm]) h) 1
@[to_additive]
theorem eq_one_of_mul_left (h : a * b = 1) : b = 1 :=
congr_arg Units.inv <| Subsingleton.elim (Units.mk _ _ h <| by rwa [mul_comm]) 1
@[to_additive (attr := simp)]
theorem mul_eq_one : a * b = 1 ↔ a = 1 ∧ b = 1 :=
⟨fun h => ⟨eq_one_of_mul_right h, eq_one_of_mul_left h⟩, by
rintro ⟨rfl, rfl⟩
exact mul_one _⟩
@[to_additive] theorem mul_ne_one : a * b ≠ 1 ↔ a ≠ 1 ∨ b ≠ 1 := by rw [not_iff_comm]; simp
end CommMonoid
/-!
### `IsUnit` predicate
-/
section IsUnit
variable {M : Type*}
@[to_additive (attr := nontriviality)]
theorem isUnit_of_subsingleton [Monoid M] [Subsingleton M] (a : M) : IsUnit a :=
⟨⟨a, a, by subsingleton, by subsingleton⟩, rfl⟩
@[to_additive]
instance [Monoid M] : CanLift M Mˣ Units.val IsUnit :=
{ prf := fun _ ↦ id }
/-- A subsingleton `Monoid` has a unique unit. -/
@[to_additive /-- A subsingleton `AddMonoid` has a unique additive unit. -/]
instance [Monoid M] [Subsingleton M] : Unique Mˣ where
uniq _ := Units.val_eq_one.mp (by subsingleton)
section Monoid
variable [Monoid M]
theorem units_eq_one [Subsingleton Mˣ] (u : Mˣ) : u = 1 := by subsingleton
end Monoid
namespace IsUnit
section Monoid
variable [Monoid M] {a b c : M}
@[to_additive]
theorem mul_left_inj (h : IsUnit a) : b * a = c * a ↔ b = c :=
let ⟨u, hu⟩ := h
hu ▸ u.mul_left_inj
@[to_additive]
theorem mul_right_inj (h : IsUnit a) : a * b = a * c ↔ b = c :=
let ⟨u, hu⟩ := h
hu ▸ u.mul_right_inj
@[to_additive]
protected theorem mul_left_cancel (h : IsUnit a) : a * b = a * c → b = c :=
h.mul_right_inj.1
@[to_additive]
protected theorem mul_right_cancel (h : IsUnit b) : a * b = c * b → a = c :=
h.mul_left_inj.1
@[to_additive]
theorem mul_eq_right (h : IsUnit b) : a * b = b ↔ a = 1 := calc
a * b = b ↔ a * b = 1 * b := by rw [one_mul]
_ ↔ a = 1 := by rw [h.mul_left_inj]
@[to_additive]
theorem mul_eq_left (h : IsUnit a) : a * b = a ↔ b = 1 := calc
a * b = a ↔ a * b = a * 1 := by rw [mul_one]
_ ↔ b = 1 := by rw [h.mul_right_inj]
@[to_additive]
protected theorem mul_right_injective (h : IsUnit a) : Injective (a * ·) :=
fun _ _ => h.mul_left_cancel
@[to_additive]
protected theorem mul_left_injective (h : IsUnit b) : Injective (· * b) :=
fun _ _ => h.mul_right_cancel
@[to_additive]
theorem isUnit_iff_mulLeft_bijective {a : M} :
IsUnit a ↔ Function.Bijective (a * ·) :=
⟨fun h ↦ ⟨h.mul_right_injective, fun y ↦ ⟨h.unit⁻¹ * y, by simp [← mul_assoc]⟩⟩, fun h ↦
⟨⟨a, _, (h.2 1).choose_spec, h.1
(by simpa [mul_assoc] using congr_arg (· * a) (h.2 1).choose_spec)⟩, rfl⟩⟩
@[to_additive]
theorem isUnit_iff_mulRight_bijective {a : M} :
IsUnit a ↔ Function.Bijective (· * a) :=
⟨fun h ↦ ⟨h.mul_left_injective, fun y ↦ ⟨y * h.unit⁻¹, by simp [mul_assoc]⟩⟩,
fun h ↦ ⟨⟨a, _, h.1 (by simpa [mul_assoc] using congr_arg (a * ·) (h.2 1).choose_spec),
(h.2 1).choose_spec⟩, rfl⟩⟩
end Monoid
section DivisionMonoid
variable [DivisionMonoid α] {a b c : α}
@[to_additive (attr := simp)]
protected lemma mul_inv_cancel_right (h : IsUnit b) (a : α) : a * b * b⁻¹ = a :=
h.unit'.mul_inv_cancel_right _
@[to_additive (attr := simp)]
protected lemma inv_mul_cancel_right (h : IsUnit b) (a : α) : a * b⁻¹ * b = a :=
h.unit'.inv_mul_cancel_right _
@[to_additive]
protected lemma eq_mul_inv_iff_mul_eq (h : IsUnit c) : a = b * c⁻¹ ↔ a * c = b :=
h.unit'.eq_mul_inv_iff_mul_eq
@[to_additive]
protected lemma eq_inv_mul_iff_mul_eq (h : IsUnit b) : a = b⁻¹ * c ↔ b * a = c :=
h.unit'.eq_inv_mul_iff_mul_eq
@[to_additive]
protected lemma inv_mul_eq_iff_eq_mul (h : IsUnit a) : a⁻¹ * b = c ↔ b = a * c :=
h.unit'.inv_mul_eq_iff_eq_mul
@[to_additive]
protected lemma mul_inv_eq_iff_eq_mul (h : IsUnit b) : a * b⁻¹ = c ↔ a = c * b :=
h.unit'.mul_inv_eq_iff_eq_mul
@[to_additive]
protected lemma mul_inv_eq_one (h : IsUnit b) : a * b⁻¹ = 1 ↔ a = b :=
@Units.mul_inv_eq_one _ _ h.unit' _
@[to_additive]
protected lemma inv_mul_eq_one (h : IsUnit a) : a⁻¹ * b = 1 ↔ a = b :=
@Units.inv_mul_eq_one _ _ h.unit' _
@[to_additive]
protected lemma mul_eq_one_iff_eq_inv (h : IsUnit b) : a * b = 1 ↔ a = b⁻¹ :=
@Units.mul_eq_one_iff_eq_inv _ _ h.unit' _
@[to_additive]
protected lemma mul_eq_one_iff_inv_eq (h : IsUnit a) : a * b = 1 ↔ a⁻¹ = b :=
@Units.mul_eq_one_iff_inv_eq _ _ h.unit' _
@[to_additive (attr := simp)]
protected lemma div_mul_cancel (h : IsUnit b) (a : α) : a / b * b = a := by
rw [div_eq_mul_inv, h.inv_mul_cancel_right]
@[to_additive (attr := simp)]
protected lemma mul_div_cancel_right (h : IsUnit b) (a : α) : a * b / b = a := by
rw [div_eq_mul_inv, h.mul_inv_cancel_right]
@[to_additive]
protected lemma mul_one_div_cancel (h : IsUnit a) : a * (1 / a) = 1 := by simp [h]
@[to_additive]
protected lemma one_div_mul_cancel (h : IsUnit a) : 1 / a * a = 1 := by simp [h]
@[to_additive]
protected lemma div_left_inj (h : IsUnit c) : a / c = b / c ↔ a = b := by
simp only [div_eq_mul_inv]
exact Units.mul_left_inj h.inv.unit'
@[to_additive]
protected lemma div_eq_iff (h : IsUnit b) : a / b = c ↔ a = c * b := by
rw [div_eq_mul_inv, h.mul_inv_eq_iff_eq_mul]
@[to_additive]
protected lemma eq_div_iff (h : IsUnit c) : a = b / c ↔ a * c = b := by
rw [div_eq_mul_inv, h.eq_mul_inv_iff_mul_eq]
@[to_additive]
protected lemma div_eq_of_eq_mul (h : IsUnit b) : a = c * b → a / b = c :=
h.div_eq_iff.2
@[to_additive]
protected lemma eq_div_of_mul_eq (h : IsUnit c) : a * c = b → a = b / c :=
h.eq_div_iff.2
@[to_additive]
protected lemma div_eq_one_iff_eq (h : IsUnit b) : a / b = 1 ↔ a = b :=
⟨eq_of_div_eq_one, fun hab => hab.symm ▸ h.div_self⟩
@[to_additive]
protected lemma div_mul_left (h : IsUnit b) : b / (a * b) = 1 / a := by
rw [h.div_mul_cancel_right, one_div]
@[to_additive]
protected lemma mul_mul_div (a : α) (h : IsUnit b) : a * b * (1 / b) = a := by simp [h]
end DivisionMonoid
section DivisionCommMonoid
variable [DivisionCommMonoid α] {a b c d : α}
@[to_additive]
protected lemma div_mul_right (h : IsUnit a) (b : α) : a / (a * b) = 1 / b := by
rw [mul_comm, h.div_mul_left]
@[to_additive]
protected lemma mul_div_cancel_left (h : IsUnit a) (b : α) : a * b / a = b := by
rw [mul_comm, h.mul_div_cancel_right]
@[to_additive]
protected lemma mul_div_cancel (h : IsUnit a) (b : α) : a * (b / a) = b := by
rw [mul_comm, h.div_mul_cancel]
@[to_additive]
protected lemma mul_eq_mul_of_div_eq_div (hb : IsUnit b) (hd : IsUnit d)
(a c : α) (h : a / b = c / d) : a * d = c * b := by
rw [← mul_one a, ← hb.div_self, ← mul_comm_div, h, div_mul_eq_mul_div, hd.div_mul_cancel]
@[to_additive]
protected lemma div_eq_div_iff (hb : IsUnit b) (hd : IsUnit d) :
a / b = c / d ↔ a * d = c * b := by
rw [← (hb.mul hd).mul_left_inj, ← mul_assoc, hb.div_mul_cancel, ← mul_assoc, mul_right_comm,
hd.div_mul_cancel]
@[to_additive]
protected lemma mul_inv_eq_mul_inv_iff (hb : IsUnit b) (hd : IsUnit d) :
a * b⁻¹ = c * d⁻¹ ↔ a * d = c * b := by
rw [← div_eq_mul_inv, ← div_eq_mul_inv, hb.div_eq_div_iff hd]
@[to_additive]
protected lemma inv_mul_eq_inv_mul_iff (hb : IsUnit b) (hd : IsUnit d) :
b⁻¹ * a = d⁻¹ * c ↔ a * d = c * b := by
rw [← div_eq_inv_mul, ← div_eq_inv_mul, hb.div_eq_div_iff hd]
@[to_additive]
protected lemma div_div_cancel (h : IsUnit a) : a / (a / b) = b := by
rw [div_div_eq_mul_div, h.mul_div_cancel_left]
@[to_additive]
protected lemma div_div_cancel_left (h : IsUnit a) : a / b / a = b⁻¹ := by
rw [div_eq_mul_inv, div_eq_mul_inv, mul_right_comm, h.mul_inv_cancel, one_mul]
end DivisionCommMonoid
end IsUnit
-- namespace
end IsUnit |
.lake/packages/mathlib/Mathlib/Algebra/Group/Units/Defs.lean | import Mathlib.Algebra.Group.Commute.Defs
/-!
# Units (i.e., invertible elements) of a monoid
An element of a `Monoid` is a unit if it has a two-sided inverse.
## Main declarations
* `Units M`: the group of units (i.e., invertible elements) of a monoid.
* `IsUnit x`: a predicate asserting that `x` is a unit (i.e., invertible element) of a monoid.
For both declarations, there is an additive counterpart: `AddUnits` and `IsAddUnit`.
See also `Prime`, `Associated`, and `Irreducible` in `Mathlib/Algebra/Associated.lean`.
## Notation
We provide `Mˣ` as notation for `Units M`,
resembling the notation $R^{\times}$ for the units of a ring, which is common in mathematics.
## TODO
The results here should be used to golf the basic `Group` lemmas.
-/
assert_not_exists Multiplicative MonoidWithZero DenselyOrdered
open Function
universe u
variable {α : Type u}
/-- Units of a `Monoid`, bundled version. Notation: `αˣ`.
An element of a `Monoid` is a unit if it has a two-sided inverse.
This version bundles the inverse element so that it can be computed.
For a predicate see `IsUnit`. -/
structure Units (α : Type u) [Monoid α] where
/-- The underlying value in the base `Monoid`. -/
val : α
/-- The inverse value of `val` in the base `Monoid`. -/
inv : α
/-- `inv` is the right inverse of `val` in the base `Monoid`. -/
val_inv : val * inv = 1
/-- `inv` is the left inverse of `val` in the base `Monoid`. -/
inv_val : inv * val = 1
attribute [coe] Units.val
@[inherit_doc]
postfix:1024 "ˣ" => Units
-- We don't provide notation for the additive version, because its use is somewhat rare.
/-- Units of an `AddMonoid`, bundled version.
An element of an `AddMonoid` is a unit if it has a two-sided additive inverse.
This version bundles the inverse element so that it can be computed.
For a predicate see `isAddUnit`. -/
structure AddUnits (α : Type u) [AddMonoid α] where
/-- The underlying value in the base `AddMonoid`. -/
val : α
/-- The additive inverse value of `val` in the base `AddMonoid`. -/
neg : α
/-- `neg` is the right additive inverse of `val` in the base `AddMonoid`. -/
val_neg : val + neg = 0
/-- `neg` is the left additive inverse of `val` in the base `AddMonoid`. -/
neg_val : neg + val = 0
attribute [to_additive] Units
attribute [coe] AddUnits.val
namespace Units
section Monoid
variable [Monoid α]
/-- A unit can be interpreted as a term in the base `Monoid`. -/
@[to_additive /-- An additive unit can be interpreted as a term in the base `AddMonoid`. -/]
instance : CoeHead αˣ α :=
⟨val⟩
/-- The inverse of a unit in a `Monoid`. -/
@[to_additive /-- The additive inverse of an additive unit in an `AddMonoid`. -/]
instance instInv : Inv αˣ :=
⟨fun u => ⟨u.2, u.1, u.4, u.3⟩⟩
attribute [instance] AddUnits.instNeg
/-- See Note [custom simps projection] -/
@[to_additive
/-- See Note [custom simps projection] -/]
def Simps.val_inv (u : αˣ) : α := ↑(u⁻¹)
initialize_simps_projections Units (as_prefix val, val_inv → null, inv → val_inv, as_prefix val_inv)
initialize_simps_projections AddUnits
(as_prefix val, val_neg → null, neg → val_neg, as_prefix val_neg)
@[to_additive]
theorem val_mk (a : α) (b h₁ h₂) : ↑(Units.mk a b h₁ h₂) = a :=
rfl
@[to_additive]
theorem val_injective : Function.Injective (val : αˣ → α)
| ⟨v, i₁, vi₁, iv₁⟩, ⟨v', i₂, vi₂, iv₂⟩, e => by
simp only at e; subst v'; congr
simpa only [iv₂, vi₁, one_mul, mul_one] using mul_assoc i₂ v i₁
@[to_additive (attr := ext)]
theorem ext {u v : αˣ} (huv : u.val = v.val) : u = v := val_injective huv
@[to_additive (attr := norm_cast)]
theorem val_inj {a b : αˣ} : (a : α) = b ↔ a = b :=
val_injective.eq_iff
@[to_additive (attr := deprecated val_inj (since := "2025-06-21"))] alias eq_iff := val_inj
/-- Units have decidable equality if the base `Monoid` has decidable equality. -/
@[to_additive /-- Additive units have decidable equality
if the base `AddMonoid` has decidable equality. -/]
instance [DecidableEq α] : DecidableEq αˣ := fun _ _ => decidable_of_iff' _ Units.ext_iff
@[to_additive (attr := simp)]
theorem mk_val (u : αˣ) (y h₁ h₂) : mk (u : α) y h₁ h₂ = u :=
ext rfl
/-- Copy a unit, adjusting definition equalities. -/
@[to_additive (attr := simps) /-- Copy an `AddUnit`, adjusting definitional equalities. -/]
def copy (u : αˣ) (val : α) (hv : val = u) (inv : α) (hi : inv = ↑u⁻¹) : αˣ :=
{ val, inv, inv_val := hv.symm ▸ hi.symm ▸ u.inv_val, val_inv := hv.symm ▸ hi.symm ▸ u.val_inv }
@[to_additive]
theorem copy_eq (u : αˣ) (val hv inv hi) : u.copy val hv inv hi = u :=
ext hv
/-- Units of a monoid have an induced multiplication. -/
@[to_additive /-- Additive units of an additive monoid have an induced addition. -/]
instance : Mul αˣ where
mul u₁ u₂ :=
⟨u₁.val * u₂.val, u₂.inv * u₁.inv,
by rw [mul_assoc, ← mul_assoc u₂.val, val_inv, one_mul, val_inv],
by rw [mul_assoc, ← mul_assoc u₁.inv, inv_val, one_mul, inv_val]⟩
/-- Units of a monoid have a unit -/
@[to_additive /-- Additive units of an additive monoid have a zero. -/]
instance : One αˣ where
one := ⟨1, 1, one_mul 1, one_mul 1⟩
/-- Units of a monoid have a multiplication and multiplicative identity. -/
@[to_additive
/-- Additive units of an additive monoid have an addition and an additive identity. -/]
instance instMulOneClass : MulOneClass αˣ where
one_mul u := ext <| one_mul (u : α)
mul_one u := ext <| mul_one (u : α)
/-- Units of a monoid are inhabited because `1` is a unit. -/
@[to_additive
/-- Additive units of an additive monoid are inhabited because `0` is an additive unit. -/]
instance : Inhabited αˣ :=
⟨1⟩
/-- Units of a monoid have a representation of the base value in the `Monoid`. -/
@[to_additive /-- Additive units of an additive monoid have a representation of the base value in
the `AddMonoid`. -/]
instance [Repr α] : Repr αˣ :=
⟨reprPrec ∘ val⟩
variable (a b : αˣ) {u : αˣ}
@[to_additive (attr := simp, norm_cast)]
theorem val_mul : (↑(a * b) : α) = a * b :=
rfl
@[to_additive (attr := simp, norm_cast)]
theorem val_one : ((1 : αˣ) : α) = 1 :=
rfl
@[to_additive (attr := simp, norm_cast)]
theorem val_eq_one {a : αˣ} : (a : α) = 1 ↔ a = 1 := by rw [← Units.val_one, val_inj]
@[to_additive (attr := simp)]
theorem inv_mk (x y : α) (h₁ h₂) : (mk x y h₁ h₂)⁻¹ = mk y x h₂ h₁ :=
rfl
@[to_additive (attr := simp)]
theorem inv_eq_val_inv : a.inv = ((a⁻¹ : αˣ) : α) :=
rfl
@[to_additive (attr := simp)]
theorem inv_mul : (↑a⁻¹ * a : α) = 1 :=
inv_val _
@[to_additive (attr := simp)]
theorem mul_inv : (a * ↑a⁻¹ : α) = 1 :=
val_inv _
@[to_additive] lemma commute_coe_inv : Commute (a : α) ↑a⁻¹ := by
rw [Commute, SemiconjBy, inv_mul, mul_inv]
@[to_additive] lemma commute_inv_coe : Commute ↑a⁻¹ (a : α) := a.commute_coe_inv.symm
@[to_additive]
theorem inv_mul_of_eq {a : α} (h : ↑u = a) : ↑u⁻¹ * a = 1 := by rw [← h, u.inv_mul]
@[to_additive]
theorem mul_inv_of_eq {a : α} (h : ↑u = a) : a * ↑u⁻¹ = 1 := by rw [← h, u.mul_inv]
@[to_additive (attr := simp)]
theorem mul_inv_cancel_left (a : αˣ) (b : α) : (a : α) * (↑a⁻¹ * b) = b := by
rw [← mul_assoc, mul_inv, one_mul]
@[to_additive (attr := simp)]
theorem inv_mul_cancel_left (a : αˣ) (b : α) : (↑a⁻¹ : α) * (a * b) = b := by
rw [← mul_assoc, inv_mul, one_mul]
@[to_additive]
theorem inv_mul_eq_iff_eq_mul {b c : α} : ↑a⁻¹ * b = c ↔ b = a * c :=
⟨fun h => by rw [← h, mul_inv_cancel_left], fun h => by rw [h, inv_mul_cancel_left]⟩
@[to_additive]
instance instMonoid : Monoid αˣ :=
{ (inferInstance : MulOneClass αˣ) with
mul_assoc := fun _ _ _ => ext <| mul_assoc _ _ _,
npow := fun n a ↦
{ val := a ^ n
inv := a⁻¹ ^ n
val_inv := by rw [← a.commute_coe_inv.mul_pow]; simp
inv_val := by rw [← a.commute_inv_coe.mul_pow]; simp }
npow_zero := fun a ↦ by ext; simp
npow_succ := fun n a ↦ by ext; simp [pow_succ] }
/-- Units of a monoid have division -/
@[to_additive /-- Additive units of an additive monoid have subtraction. -/]
instance : Div αˣ where
div := fun a b ↦
{ val := a * b⁻¹
inv := b * a⁻¹
val_inv := by rw [mul_assoc, inv_mul_cancel_left, mul_inv]
inv_val := by rw [mul_assoc, inv_mul_cancel_left, mul_inv] }
/-- Units of a monoid form a `DivInvMonoid`. -/
@[to_additive /-- Additive units of an additive monoid form a `SubNegMonoid`. -/]
instance instDivInvMonoid : DivInvMonoid αˣ where
zpow := fun n a ↦ match n, a with
| Int.ofNat n, a => a ^ n
| Int.negSucc n, a => (a ^ n.succ)⁻¹
zpow_zero' := fun a ↦ by simp
zpow_succ' := fun n a ↦ by simp [pow_succ]
zpow_neg' := fun n a ↦ by simp
/-- Units of a monoid form a group. -/
@[to_additive /-- Additive units of an additive monoid form an additive group. -/]
instance instGroup : Group αˣ where
inv_mul_cancel := fun u => ext u.inv_val
/-- Units of a commutative monoid form a commutative group. -/
@[to_additive /-- Additive units of an additive commutative monoid form
an additive commutative group. -/]
instance instCommGroupUnits {α} [CommMonoid α] : CommGroup αˣ where
mul_comm := fun _ _ => ext <| mul_comm _ _
@[to_additive (attr := simp, norm_cast)]
lemma val_pow_eq_pow_val (n : ℕ) : ↑(a ^ n) = (a ^ n : α) := rfl
@[to_additive (attr := simp, norm_cast)]
lemma inv_pow_eq_pow_inv (n : ℕ) : ↑(a ^ n)⁻¹ = (a⁻¹ ^ n : α) := rfl
end Monoid
section DivisionMonoid
variable [DivisionMonoid α]
@[to_additive (attr := simp, norm_cast)] lemma val_inv_eq_inv_val (u : αˣ) : ↑u⁻¹ = (u⁻¹ : α) :=
Eq.symm <| inv_eq_of_mul_eq_one_right u.mul_inv
@[to_additive (attr := simp, norm_cast)]
lemma val_div_eq_div_val : ∀ u₁ u₂ : αˣ, ↑(u₁ / u₂) = (u₁ / u₂ : α) := by simp [div_eq_mul_inv]
end DivisionMonoid
end Units
/-- For `a, b` in a `CommMonoid` such that `a * b = 1`, makes a unit out of `a`. -/
@[to_additive
/-- For `a, b` in an `AddCommMonoid` such that `a + b = 0`, makes an addUnit out of `a`. -/]
def Units.mkOfMulEqOne [CommMonoid α] (a b : α) (hab : a * b = 1) : αˣ :=
⟨a, b, hab, (mul_comm b a).trans hab⟩
@[to_additive (attr := simp)]
theorem Units.val_mkOfMulEqOne [CommMonoid α] {a b : α} (h : a * b = 1) :
(Units.mkOfMulEqOne a b h : α) = a :=
rfl
section Monoid
variable [Monoid α] {a : α}
/-- Partial division, denoted `a /ₚ u`. It is defined when the
second argument is invertible, and unlike the division operator
in `DivisionRing` it is not totalized at zero. -/
def divp (a : α) (u : Units α) : α :=
a * (u⁻¹ : αˣ)
@[inherit_doc]
infixl:70 " /ₚ " => divp
@[simp]
theorem divp_self (u : αˣ) : (u : α) /ₚ u = 1 :=
Units.mul_inv _
@[simp]
theorem divp_one (a : α) : a /ₚ 1 = a :=
mul_one _
theorem divp_assoc (a b : α) (u : αˣ) : a * b /ₚ u = a * (b /ₚ u) :=
mul_assoc _ _ _
@[deprecated divp_assoc (since := "2025-08-25")]
theorem divp_assoc' (x y : α) (u : αˣ) : x * (y /ₚ u) = x * y /ₚ u :=
(divp_assoc _ _ _).symm
@[simp]
theorem divp_inv (u : αˣ) : a /ₚ u⁻¹ = a * u :=
rfl
@[simp]
theorem divp_mul_cancel (a : α) (u : αˣ) : a /ₚ u * u = a :=
(mul_assoc _ _ _).trans <| by rw [Units.inv_mul, mul_one]
@[simp]
theorem mul_divp_cancel (a : α) (u : αˣ) : a * u /ₚ u = a :=
(mul_assoc _ _ _).trans <| by rw [Units.mul_inv, mul_one]
theorem divp_divp_eq_divp_mul (x : α) (u₁ u₂ : αˣ) : x /ₚ u₁ /ₚ u₂ = x /ₚ (u₂ * u₁) := by
simp only [divp, mul_inv_rev, Units.val_mul, mul_assoc]
@[simp]
theorem one_divp (u : αˣ) : 1 /ₚ u = ↑u⁻¹ :=
one_mul _
theorem inv_eq_one_divp (u : αˣ) : ↑u⁻¹ = 1 /ₚ u := by rw [one_divp]
theorem val_div_eq_divp (u₁ u₂ : αˣ) : ↑(u₁ / u₂) = ↑u₁ /ₚ u₂ := by
rw [divp, division_def, Units.val_mul]
end Monoid
/-!
### `IsUnit` predicate
-/
section IsUnit
variable {M : Type*} {N : Type*}
/-- An element `a : M` of a `Monoid` is a unit if it has a two-sided inverse.
The actual definition says that `a` is equal to some `u : Mˣ`, where
`Mˣ` is a bundled version of `IsUnit`. -/
@[to_additive /-- An element `a : M` of an `AddMonoid` is an `AddUnit` if it has a two-sided
additive inverse. The actual definition says that `a` is equal to some `u : AddUnits M`,
where `AddUnits M` is a bundled version of `IsAddUnit`. -/]
def IsUnit [Monoid M] (a : M) : Prop :=
∃ u : Mˣ, (u : M) = a
/-- See `isUnit_iff_exists_and_exists` for a similar lemma with two existentials. -/
@[to_additive
/-- See `isAddUnit_iff_exists_and_exists` for a similar lemma with two existentials. -/]
lemma isUnit_iff_exists [Monoid M] {x : M} : IsUnit x ↔ ∃ b, x * b = 1 ∧ b * x = 1 := by
refine ⟨fun ⟨u, hu⟩ => ?_, fun ⟨b, h1b, h2b⟩ => ⟨⟨x, b, h1b, h2b⟩, rfl⟩⟩
subst x
exact ⟨u.inv, u.val_inv, u.inv_val⟩
/-- See `isUnit_iff_exists` for a similar lemma with one existential. -/
@[to_additive /-- See `isAddUnit_iff_exists` for a similar lemma with one existential. -/]
theorem isUnit_iff_exists_and_exists [Monoid M] {a : M} :
IsUnit a ↔ (∃ b, a * b = 1) ∧ (∃ c, c * a = 1) :=
isUnit_iff_exists.trans
⟨fun ⟨b, hba, hab⟩ => ⟨⟨b, hba⟩, ⟨b, hab⟩⟩,
fun ⟨⟨b, hb⟩, ⟨_, hc⟩⟩ => ⟨b, hb, left_inv_eq_right_inv hc hb ▸ hc⟩⟩
@[to_additive (attr := simp)]
protected theorem Units.isUnit [Monoid M] (u : Mˣ) : IsUnit (u : M) :=
⟨u, rfl⟩
@[to_additive (attr := simp, grind ←)]
theorem isUnit_one [Monoid M] : IsUnit (1 : M) :=
⟨1, rfl⟩
@[to_additive]
theorem IsUnit.of_mul_eq_one [CommMonoid M] {a : M} (b : M) (h : a * b = 1) : IsUnit a :=
⟨.mkOfMulEqOne a b h, rfl⟩
@[deprecated (since := "2025-11-05")] alias isUnit_of_mul_eq_one := IsUnit.of_mul_eq_one
@[to_additive]
theorem IsUnit.of_mul_eq_one_right [CommMonoid M] {b : M} (a : M) (h : a * b = 1) : IsUnit b :=
.of_mul_eq_one a <| mul_comm a b ▸ h
@[deprecated (since := "2025-11-05")] alias isUnit_of_mul_eq_one_right := IsUnit.of_mul_eq_one_right
section Monoid
variable [Monoid M] {a b : M}
@[to_additive IsAddUnit.exists_neg]
lemma IsUnit.exists_right_inv (h : IsUnit a) : ∃ b, a * b = 1 := by
rcases h with ⟨⟨a, b, hab, _⟩, rfl⟩
exact ⟨b, hab⟩
@[to_additive IsAddUnit.exists_neg']
lemma IsUnit.exists_left_inv {a : M} (h : IsUnit a) : ∃ b, b * a = 1 := by
rcases h with ⟨⟨a, b, _, hba⟩, rfl⟩
exact ⟨b, hba⟩
@[to_additive] lemma IsUnit.mul : IsUnit a → IsUnit b → IsUnit (a * b) := by
rintro ⟨x, rfl⟩ ⟨y, rfl⟩; exact ⟨x * y, rfl⟩
@[to_additive] lemma IsUnit.pow (n : ℕ) : IsUnit a → IsUnit (a ^ n) := by
rintro ⟨u, rfl⟩; exact ⟨u ^ n, rfl⟩
@[to_additive (attr := simp)]
lemma isUnit_iff_eq_one [Subsingleton Mˣ] {x : M} : IsUnit x ↔ x = 1 :=
⟨fun ⟨u, hu⟩ ↦ by rw [← hu, Subsingleton.elim u 1, Units.val_one], fun h ↦ h ▸ isUnit_one⟩
end Monoid
@[to_additive]
theorem isUnit_iff_exists_inv [CommMonoid M] {a : M} : IsUnit a ↔ ∃ b, a * b = 1 :=
⟨fun h => h.exists_right_inv, fun ⟨b, hab⟩ => .of_mul_eq_one b hab⟩
@[to_additive]
theorem isUnit_iff_exists_inv' [CommMonoid M] {a : M} : IsUnit a ↔ ∃ b, b * a = 1 := by
simp [isUnit_iff_exists_inv, mul_comm]
/-- Multiplication by a `u : Mˣ` on the right doesn't affect `IsUnit`. -/
@[to_additive (attr := simp)
/-- Addition of a `u : AddUnits M` on the right doesn't affect `IsAddUnit`. -/]
theorem Units.isUnit_mul_units [Monoid M] (a : M) (u : Mˣ) : IsUnit (a * u) ↔ IsUnit a :=
Iff.intro
(fun ⟨v, hv⟩ => by
have : IsUnit (a * ↑u * ↑u⁻¹) := by exists v * u⁻¹; rw [← hv, Units.val_mul]
rwa [mul_assoc, Units.mul_inv, mul_one] at this)
fun v => v.mul u.isUnit
/-- Multiplication by a `u : Mˣ` on the left doesn't affect `IsUnit`. -/
@[to_additive (attr := simp)
/-- Addition of a `u : AddUnits M` on the left doesn't affect `IsAddUnit`. -/]
theorem Units.isUnit_units_mul {M : Type*} [Monoid M] (u : Mˣ) (a : M) :
IsUnit (↑u * a) ↔ IsUnit a :=
Iff.intro
(fun ⟨v, hv⟩ => by
have : IsUnit (↑u⁻¹ * (↑u * a)) := by exists u⁻¹ * v; rw [← hv, Units.val_mul]
rwa [← mul_assoc, Units.inv_mul, one_mul] at this)
u.isUnit.mul
@[to_additive]
theorem isUnit_of_mul_isUnit_left [CommMonoid M] {x y : M} (hu : IsUnit (x * y)) : IsUnit x :=
let ⟨z, hz⟩ := isUnit_iff_exists_inv.1 hu
isUnit_iff_exists_inv.2 ⟨y * z, by rwa [← mul_assoc]⟩
@[to_additive]
theorem isUnit_of_mul_isUnit_right [CommMonoid M] {x y : M} (hu : IsUnit (x * y)) : IsUnit y :=
@isUnit_of_mul_isUnit_left _ _ y x <| by rwa [mul_comm]
namespace IsUnit
@[to_additive (attr := simp, grind =)]
theorem mul_iff [CommMonoid M] {x y : M} : IsUnit (x * y) ↔ IsUnit x ∧ IsUnit y :=
⟨fun h => ⟨isUnit_of_mul_isUnit_left h, isUnit_of_mul_isUnit_right h⟩,
fun h => IsUnit.mul h.1 h.2⟩
section Monoid
variable [Monoid M] {a b : M}
/-- The element of the group of units, corresponding to an element of a monoid which is a unit. When
`α` is a `DivisionMonoid`, use `IsUnit.unit'` instead. -/
@[to_additive /-- The element of the additive group of additive units, corresponding to an element
of an additive monoid which is an additive unit. When `α` is a `SubtractionMonoid`, use
`IsAddUnit.addUnit'` instead. -/]
protected noncomputable def unit (h : IsUnit a) : Mˣ :=
(Classical.choose h).copy a (Classical.choose_spec h).symm _ rfl
@[to_additive (attr := simp)]
theorem unit_of_val_units {a : Mˣ} (h : IsUnit (a : M)) : h.unit = a :=
Units.ext rfl
@[to_additive (attr := simp)]
theorem unit_spec (h : IsUnit a) : ↑h.unit = a :=
rfl
@[to_additive (attr := simp)]
theorem unit_one (h : IsUnit (1 : M)) : h.unit = 1 :=
Units.ext rfl
@[to_additive]
theorem unit_mul (ha : IsUnit a) (hb : IsUnit b) : (ha.mul hb).unit = ha.unit * hb.unit :=
Units.ext rfl
@[to_additive]
theorem unit_pow (h : IsUnit a) (n : ℕ) : (h.pow n).unit = h.unit ^ n :=
Units.ext rfl
@[to_additive (attr := simp)]
theorem val_inv_mul (h : IsUnit a) : ↑h.unit⁻¹ * a = 1 :=
Units.mul_inv _
@[to_additive (attr := simp)]
theorem mul_val_inv (h : IsUnit a) : a * ↑h.unit⁻¹ = 1 := by
rw [← h.unit.mul_inv]; congr
/-- `IsUnit x` is decidable if we can decide if `x` comes from `Mˣ`. -/
@[to_additive /-- `IsAddUnit x` is decidable if we can decide if `x` comes from `AddUnits M`. -/]
instance (x : M) [h : Decidable (∃ u : Mˣ, ↑u = x)] : Decidable (IsUnit x) :=
h
end Monoid
section DivisionMonoid
variable [DivisionMonoid α] {a b c : α}
@[to_additive (attr := simp)]
protected theorem inv_mul_cancel : IsUnit a → a⁻¹ * a = 1 := by
rintro ⟨u, rfl⟩
rw [← Units.val_inv_eq_inv_val, Units.inv_mul]
@[to_additive (attr := simp)]
protected theorem mul_inv_cancel : IsUnit a → a * a⁻¹ = 1 := by
rintro ⟨u, rfl⟩
rw [← Units.val_inv_eq_inv_val, Units.mul_inv]
/-- The element of the group of units, corresponding to an element of a monoid which is a unit. As
opposed to `IsUnit.unit`, the inverse is computable and comes from the inversion on `α`. This is
useful to transfer properties of inversion in `Units α` to `α`. See also `toUnits`. -/
@[to_additive (attr := simps val)
/-- The element of the additive group of additive units, corresponding to an element of
an additive monoid which is an additive unit. As opposed to `IsAddUnit.addUnit`, the negation is
computable and comes from the negation on `α`. This is useful to transfer properties of negation
in `AddUnits α` to `α`. See also `toAddUnits`. -/]
def unit' (h : IsUnit a) : αˣ := ⟨a, a⁻¹, h.mul_inv_cancel, h.inv_mul_cancel⟩
@[to_additive] lemma val_inv_unit' (h : IsUnit a) : ↑(h.unit'⁻¹) = a⁻¹ := rfl
@[to_additive (attr := simp)]
protected lemma mul_inv_cancel_left (h : IsUnit a) : ∀ b, a * (a⁻¹ * b) = b :=
h.unit'.mul_inv_cancel_left
@[to_additive (attr := simp)]
protected lemma inv_mul_cancel_left (h : IsUnit a) : ∀ b, a⁻¹ * (a * b) = b :=
h.unit'.inv_mul_cancel_left
@[to_additive]
protected lemma div_self (h : IsUnit a) : a / a = 1 := by rw [div_eq_mul_inv, h.mul_inv_cancel]
@[to_additive]
lemma inv (h : IsUnit a) : IsUnit a⁻¹ := by
obtain ⟨u, hu⟩ := h
rw [← hu, ← Units.val_inv_eq_inv_val]
exact Units.isUnit _
@[to_additive]
lemma unit_inv (h : IsUnit a) : h.inv.unit = h.unit⁻¹ :=
Units.ext h.unit.val_inv_eq_inv_val.symm
@[to_additive]
lemma div (ha : IsUnit a) (hb : IsUnit b) : IsUnit (a / b) := by
rw [div_eq_mul_inv]; exact ha.mul hb.inv
@[to_additive]
lemma unit_div (ha : IsUnit a) (hb : IsUnit b) : (ha.div hb).unit = ha.unit / hb.unit :=
Units.ext (ha.unit.val_div_eq_div_val hb.unit).symm
@[to_additive]
protected lemma div_mul_cancel_right (h : IsUnit b) (a : α) : b / (a * b) = a⁻¹ := by
rw [div_eq_mul_inv, mul_inv_rev, h.mul_inv_cancel_left]
@[to_additive]
protected lemma mul_div_mul_right (h : IsUnit c) (a b : α) : a * c / (b * c) = a / b := by
simp only [div_eq_mul_inv, mul_inv_rev, mul_assoc, h.mul_inv_cancel_left]
end DivisionMonoid
section DivisionCommMonoid
variable [DivisionCommMonoid α] {a c : α}
@[to_additive]
protected lemma div_mul_cancel_left (h : IsUnit a) (b : α) : a / (a * b) = b⁻¹ := by
rw [mul_comm, h.div_mul_cancel_right]
@[to_additive]
protected lemma mul_div_mul_left (h : IsUnit c) (a b : α) : c * a / (c * b) = a / b := by
rw [mul_comm c, mul_comm c, h.mul_div_mul_right]
end DivisionCommMonoid
end IsUnit
lemma divp_eq_div [DivisionMonoid α] (a : α) (u : αˣ) : a /ₚ u = a / u := by
rw [div_eq_mul_inv, divp, u.val_inv_eq_inv_val]
@[to_additive]
lemma Group.isUnit [Group α] (a : α) : IsUnit a :=
⟨⟨a, a⁻¹, mul_inv_cancel _, inv_mul_cancel _⟩, rfl⟩
-- namespace
end IsUnit
-- section
section NoncomputableDefs
variable {M : Type*}
/-- Constructs an inv operation for a `Monoid` consisting only of units. -/
noncomputable def invOfIsUnit [Monoid M] (h : ∀ a : M, IsUnit a) : Inv M where
inv := fun a => ↑(h a).unit⁻¹
/-- Constructs a `Group` structure on a `Monoid` consisting only of units. -/
noncomputable def groupOfIsUnit [hM : Monoid M] (h : ∀ a : M, IsUnit a) : Group M :=
{ hM with
toInv := invOfIsUnit h,
inv_mul_cancel := fun a => by
change ↑(h a).unit⁻¹ * a = 1
rw [Units.inv_mul_eq_iff_eq_mul, (h a).unit_spec, mul_one] }
/-- Constructs a `CommGroup` structure on a `CommMonoid` consisting only of units. -/
noncomputable def commGroupOfIsUnit [hM : CommMonoid M] (h : ∀ a : M, IsUnit a) : CommGroup M :=
{ hM with
toInv := invOfIsUnit h,
inv_mul_cancel := fun a => by
change ↑(h a).unit⁻¹ * a = 1
rw [Units.inv_mul_eq_iff_eq_mul, (h a).unit_spec, mul_one] }
end NoncomputableDefs |
.lake/packages/mathlib/Mathlib/Algebra/Group/Units/Equiv.lean | import Mathlib.Algebra.Group.Equiv.Basic
import Mathlib.Algebra.Group.Units.Hom
/-!
# Multiplicative and additive equivalence acting on units.
-/
assert_not_exists MonoidWithZero DenselyOrdered
variable {F α M N G : Type*}
/-- A group is isomorphic to its group of units. -/
@[to_additive (attr := simps apply_val symm_apply)
/-- An additive group is isomorphic to its group of additive units -/]
def toUnits [Group G] : G ≃* Gˣ where
toFun x := ⟨x, x⁻¹, mul_inv_cancel _, inv_mul_cancel _⟩
invFun x := x
map_mul' _ _ := Units.ext rfl
@[to_additive (attr := simp)]
lemma toUnits_val_apply {G : Type*} [Group G] (x : Gˣ) : toUnits (x : G) = x := by
simp_rw [MulEquiv.apply_eq_iff_symm_apply, toUnits_symm_apply]
namespace Units
variable [Monoid M] [Monoid N]
/-- A multiplicative equivalence of monoids defines a multiplicative equivalence
of their groups of units. -/
def mapEquiv (h : M ≃* N) : Mˣ ≃* Nˣ :=
{ map h.toMonoidHom with
invFun := map h.symm.toMonoidHom,
left_inv := fun u => ext <| h.left_inv u,
right_inv := fun u => ext <| h.right_inv u }
@[simp]
theorem mapEquiv_symm (h : M ≃* N) : (mapEquiv h).symm = mapEquiv h.symm :=
rfl
@[simp]
theorem coe_mapEquiv (h : M ≃* N) (x : Mˣ) : (mapEquiv h x : N) = h x :=
rfl
/-- Left multiplication by a unit of a monoid is a permutation of the underlying type. -/
@[to_additive (attr := simps -fullyApplied apply)
/-- Left addition of an additive unit is a permutation of the underlying type. -/]
def mulLeft (u : Mˣ) : Equiv.Perm M where
toFun x := u * x
invFun x := u⁻¹ * x
left_inv := u.inv_mul_cancel_left
right_inv := u.mul_inv_cancel_left
@[to_additive (attr := simp)]
theorem mulLeft_symm (u : Mˣ) : u.mulLeft.symm = u⁻¹.mulLeft :=
Equiv.ext fun _ => rfl
@[to_additive]
theorem mulLeft_bijective (a : Mˣ) : Function.Bijective ((a * ·) : M → M) :=
(mulLeft a).bijective
/-- Right multiplication by a unit of a monoid is a permutation of the underlying type. -/
@[to_additive (attr := simps -fullyApplied apply)
/-- Right addition of an additive unit is a permutation of the underlying type. -/]
def mulRight (u : Mˣ) : Equiv.Perm M where
toFun x := x * u
invFun x := x * ↑u⁻¹
left_inv x := mul_inv_cancel_right x u
right_inv x := inv_mul_cancel_right x u
@[to_additive (attr := simp)]
theorem mulRight_symm (u : Mˣ) : u.mulRight.symm = u⁻¹.mulRight :=
Equiv.ext fun _ => rfl
@[to_additive]
theorem mulRight_bijective (a : Mˣ) : Function.Bijective ((· * a) : M → M) :=
(mulRight a).bijective
end Units
namespace Equiv
section Group
variable [Group G]
/-- Left multiplication in a `Group` is a permutation of the underlying type. -/
@[to_additive /-- Left addition in an `AddGroup` is a permutation of the underlying type. -/]
protected def mulLeft (a : G) : Perm G :=
(toUnits a).mulLeft
@[to_additive (attr := simp)]
theorem coe_mulLeft (a : G) : ⇑(Equiv.mulLeft a) = (a * ·) :=
rfl
/-- Extra simp lemma that `dsimp` can use. `simp` will never use this. -/
@[to_additive (attr := simp)
/-- Extra simp lemma that `dsimp` can use. `simp` will never use this. -/]
theorem mulLeft_symm_apply (a : G) : ((Equiv.mulLeft a).symm : G → G) = (a⁻¹ * ·) :=
rfl
@[to_additive (attr := simp)]
theorem mulLeft_symm (a : G) : (Equiv.mulLeft a).symm = Equiv.mulLeft a⁻¹ :=
ext fun _ => rfl
@[to_additive]
theorem _root_.Group.mulLeft_bijective (a : G) : Function.Bijective (a * ·) :=
(Equiv.mulLeft a).bijective
/-- Right multiplication in a `Group` is a permutation of the underlying type. -/
@[to_additive /-- Right addition in an `AddGroup` is a permutation of the underlying type. -/]
protected def mulRight (a : G) : Perm G :=
(toUnits a).mulRight
@[to_additive (attr := simp)]
theorem coe_mulRight (a : G) : ⇑(Equiv.mulRight a) = fun x => x * a :=
rfl
@[to_additive (attr := simp)]
theorem mulRight_symm (a : G) : (Equiv.mulRight a).symm = Equiv.mulRight a⁻¹ :=
ext fun _ => rfl
/-- Extra simp lemma that `dsimp` can use. `simp` will never use this. -/
@[to_additive (attr := simp)
/-- Extra simp lemma that `dsimp` can use. `simp` will never use this. -/]
theorem mulRight_symm_apply (a : G) : ((Equiv.mulRight a).symm : G → G) = fun x => x * a⁻¹ :=
rfl
@[to_additive]
theorem _root_.Group.mulRight_bijective (a : G) : Function.Bijective (· * a) :=
(Equiv.mulRight a).bijective
/-- A version of `Equiv.mulLeft a b⁻¹` that is defeq to `a / b`. -/
@[to_additive (attr := simps) /-- A version of `Equiv.addLeft a (-b)` that is defeq to `a - b`. -/]
protected def divLeft (a : G) : G ≃ G where
toFun b := a / b
invFun b := b⁻¹ * a
left_inv b := by simp [div_eq_mul_inv]
right_inv b := by simp [div_eq_mul_inv]
@[to_additive]
theorem divLeft_eq_inv_trans_mulLeft (a : G) :
Equiv.divLeft a = (Equiv.inv G).trans (Equiv.mulLeft a) :=
ext fun _ => div_eq_mul_inv _ _
/-- A version of `Equiv.mulRight a⁻¹ b` that is defeq to `b / a`. -/
@[to_additive (attr := simps) /-- A version of `Equiv.addRight (-a) b` that is defeq to `b - a`. -/]
protected def divRight (a : G) : G ≃ G where
toFun b := b / a
invFun b := b * a
left_inv b := by simp [div_eq_mul_inv]
right_inv b := by simp [div_eq_mul_inv]
@[to_additive]
theorem divRight_eq_mulRight_inv (a : G) : Equiv.divRight a = Equiv.mulRight a⁻¹ :=
ext fun _ => div_eq_mul_inv _ _
end Group
section CommGroup
variable [CommGroup G]
@[to_additive]
lemma symm_divLeft (a : G) : (Equiv.divLeft a).symm = Equiv.divLeft a :=
ext fun _ ↦ inv_mul_eq_div _ _
@[to_additive (attr := simp)]
lemma divLeft_involutive (a : G) : Function.Involutive (Equiv.divLeft a) :=
fun _ ↦ div_div_cancel ..
end CommGroup
end Equiv
variable (α) in
/-- The `αˣ` type is equivalent to a subtype of `α × α`. -/
@[simps]
def unitsEquivProdSubtype [Monoid α] : αˣ ≃ {p : α × α // p.1 * p.2 = 1 ∧ p.2 * p.1 = 1} where
toFun u := ⟨(u, ↑u⁻¹), u.val_inv, u.inv_val⟩
invFun p := Units.mk (p : α × α).1 (p : α × α).2 p.prop.1 p.prop.2
/-- In a `DivisionCommMonoid`, `Equiv.inv` is a `MulEquiv`. There is a variant of this
`MulEquiv.inv' G : G ≃* Gᵐᵒᵖ` for the non-commutative case. -/
@[to_additive (attr := simps apply)
/-- When the `AddGroup` is commutative, `Equiv.neg` is an `AddEquiv`. -/]
def MulEquiv.inv (G : Type*) [DivisionCommMonoid G] : G ≃* G :=
{ Equiv.inv G with toFun := Inv.inv, invFun := Inv.inv, map_mul' := mul_inv }
@[to_additive (attr := simp)]
theorem MulEquiv.inv_symm (G : Type*) [DivisionCommMonoid G] :
(MulEquiv.inv G).symm = MulEquiv.inv G :=
rfl
section EquivLike
variable [Monoid M] [Monoid N] [EquivLike F M N] [MulEquivClass F M N] (f : F) {x : M}
-- Higher priority to take over the non-additivisable `isUnit_map_iff`
@[to_additive (attr := simp high)]
lemma MulEquiv.isUnit_map : IsUnit (f x) ↔ IsUnit x where
mp hx := by
simpa using hx.map <| MonoidHom.mk ⟨EquivLike.inv f, EquivLike.injective f <| by simp⟩
fun x y ↦ EquivLike.injective f <| by simp
mpr := .map f
@[instance] theorem isLocalHom_equiv : IsLocalHom f where map_nonunit := by simp
end EquivLike |
.lake/packages/mathlib/Mathlib/Algebra/Group/Units/Hom.lean | import Mathlib.Algebra.Group.Equiv.Defs
import Mathlib.Algebra.Group.Hom.Basic
import Mathlib.Algebra.Group.Units.Basic
/-!
# Monoid homomorphisms and units
This file allows to lift monoid homomorphisms to group homomorphisms of their units subgroups. It
also contains unrelated results about `Units` that depend on `MonoidHom`.
## Main declarations
* `Units.map`: Turn a homomorphism from `α` to `β` monoids into a homomorphism from `αˣ` to `βˣ`.
* `MonoidHom.toHomUnits`: Turn a homomorphism from a group `α` to `β` into a homomorphism from
`α` to `βˣ`.
* `IsLocalHom`: A predicate on monoid maps, requiring that it maps
nonunits to nonunits. For the local rings, that is, applied to their
multiplicative monoids, this means that the image of the unique
maximal ideal is again contained in the unique maximal ideal. This
is developed earlier, and in the generality of monoids, as it allows
its use in non-local-ring related contexts, but it does have the
strange consequence that it does not require local rings, or even rings.
## TODO
The results that don't mention homomorphisms should be proved (earlier?) in a different file and be
used to golf the basic `Group` lemmas.
Add a `@[to_additive]` version of `IsLocalHom`.
-/
assert_not_exists MonoidWithZero DenselyOrdered
open Function
universe u v w
section MonoidHomClass
/-- If two homomorphisms from a division monoid to a monoid are equal at a unit `x`, then they are
equal at `x⁻¹`. -/
@[to_additive
/-- If two homomorphisms from a subtraction monoid to an additive monoid are equal at an
additive unit `x`, then they are equal at `-x`. -/]
theorem IsUnit.eq_on_inv {F G N} [DivisionMonoid G] [Monoid N] [FunLike F G N]
[MonoidHomClass F G N] {x : G} (hx : IsUnit x) (f g : F) (h : f x = g x) : f x⁻¹ = g x⁻¹ :=
left_inv_eq_right_inv (map_mul_eq_one f hx.inv_mul_cancel)
(h.symm ▸ map_mul_eq_one g (hx.mul_inv_cancel))
/-- If two homomorphism from a group to a monoid are equal at `x`, then they are equal at `x⁻¹`. -/
@[to_additive
/-- If two homomorphism from an additive group to an additive monoid are equal at `x`,
then they are equal at `-x`. -/]
theorem eq_on_inv {F G M} [Group G] [Monoid M] [FunLike F G M] [MonoidHomClass F G M]
(f g : F) {x : G} (h : f x = g x) : f x⁻¹ = g x⁻¹ :=
(Group.isUnit x).eq_on_inv f g h
end MonoidHomClass
namespace Units
variable {α : Type*} {M : Type u} {N : Type v} {P : Type w} [Monoid M] [Monoid N] [Monoid P]
/-- The group homomorphism on units induced by a `MonoidHom`. -/
@[to_additive /-- The additive homomorphism on `AddUnit`s induced by an `AddMonoidHom`. -/]
def map (f : M →* N) : Mˣ →* Nˣ :=
MonoidHom.mk'
(fun u => ⟨f u.val, f u.inv,
by rw [← f.map_mul, u.val_inv, f.map_one],
by rw [← f.map_mul, u.inv_val, f.map_one]⟩)
fun x y => ext (f.map_mul x y)
@[to_additive (attr := simp)]
theorem coe_map (f : M →* N) (x : Mˣ) : ↑(map f x) = f x := rfl
@[to_additive (attr := simp)]
theorem coe_map_inv (f : M →* N) (u : Mˣ) : ↑(map f u)⁻¹ = f ↑u⁻¹ := rfl
@[to_additive (attr := simp)]
lemma map_mk (f : M →* N) (val inv : M) (val_inv inv_val) :
map f (mk val inv val_inv inv_val) = mk (f val) (f inv)
(by rw [← f.map_mul, val_inv, f.map_one]) (by rw [← f.map_mul, inv_val, f.map_one]) := rfl
@[to_additive (attr := simp)]
theorem map_comp (f : M →* N) (g : N →* P) : map (g.comp f) = (map g).comp (map f) := rfl
@[to_additive]
lemma map_injective {f : M →* N} (hf : Function.Injective f) :
Function.Injective (map f) := fun _ _ e => ext (hf (congr_arg val e))
variable (M)
@[to_additive (attr := simp)]
theorem map_id : map (MonoidHom.id M) = MonoidHom.id Mˣ := by ext; rfl
/-- Coercion `Mˣ → M` as a monoid homomorphism. -/
@[to_additive /-- Coercion `AddUnits M → M` as an AddMonoid homomorphism. -/]
def coeHom : Mˣ →* M where
toFun := Units.val; map_one' := val_one; map_mul' := val_mul
variable {M}
@[to_additive (attr := simp)]
theorem coeHom_apply (x : Mˣ) : coeHom M x = ↑x := rfl
@[to_additive]
theorem coeHom_injective : Function.Injective (coeHom M) := Units.val_injective
section DivisionMonoid
variable [DivisionMonoid α]
@[to_additive (attr := simp, norm_cast)]
theorem val_zpow_eq_zpow_val : ∀ (u : αˣ) (n : ℤ), ((u ^ n : αˣ) : α) = (u : α) ^ n :=
(Units.coeHom α).map_zpow
@[to_additive (attr := simp)]
theorem _root_.map_units_inv {F : Type*} [FunLike F M α] [MonoidHomClass F M α]
(f : F) (u : Units M) :
f ↑u⁻¹ = (f u)⁻¹ := ((f : M →* α).comp (Units.coeHom M)).map_inv u
end DivisionMonoid
/-- If a map `g : M → Nˣ` agrees with a homomorphism `f : M →* N`, then
this map is a monoid homomorphism too. -/
@[to_additive
/-- If a map `g : M → AddUnits N` agrees with a homomorphism `f : M →+ N`, then this map
is an AddMonoid homomorphism too. -/]
def liftRight (f : M →* N) (g : M → Nˣ) (h : ∀ x, ↑(g x) = f x) : M →* Nˣ where
toFun := g
map_one' := by ext; rw [h 1]; exact f.map_one
map_mul' x y := Units.ext <| by simp only [h, val_mul, f.map_mul]
@[to_additive (attr := simp)]
theorem coe_liftRight {f : M →* N} {g : M → Nˣ} (h : ∀ x, ↑(g x) = f x) (x) :
(liftRight f g h x : N) = f x := h x
@[to_additive (attr := simp)]
theorem mul_liftRight_inv {f : M →* N} {g : M → Nˣ} (h : ∀ x, ↑(g x) = f x) (x) :
f x * ↑(liftRight f g h x)⁻¹ = 1 := by
rw [Units.mul_inv_eq_iff_eq_mul, one_mul, coe_liftRight]
@[to_additive (attr := simp)]
theorem liftRight_inv_mul {f : M →* N} {g : M → Nˣ} (h : ∀ x, ↑(g x) = f x) (x) :
↑(liftRight f g h x)⁻¹ * f x = 1 := by
rw [Units.inv_mul_eq_iff_eq_mul, mul_one, coe_liftRight]
end Units
namespace MonoidHom
variable {G M : Type*} [Group G]
section Monoid
variable [Monoid M]
/-- If `f` is a homomorphism from a group `G` to a monoid `M`,
then its image lies in the units of `M`,
and `f.toHomUnits` is the corresponding monoid homomorphism from `G` to `Mˣ`. -/
@[to_additive
/-- If `f` is a homomorphism from an additive group `G` to an additive monoid `M`,
then its image lies in the `AddUnits` of `M`,
and `f.toHomUnits` is the corresponding homomorphism from `G` to `AddUnits M`. -/]
def toHomUnits (f : G →* M) : G →* Mˣ :=
Units.liftRight f (fun g => ⟨f g, f g⁻¹, map_mul_eq_one f (mul_inv_cancel _),
map_mul_eq_one f (inv_mul_cancel _)⟩)
fun _ => rfl
@[to_additive (attr := simp)]
theorem coe_toHomUnits (f : G →* M) (g : G) : (f.toHomUnits g : M) = f g := rfl
end Monoid
variable [CommMonoid M]
@[simp] lemma toHomUnits_mul (f g : G →* M) : (f * g).toHomUnits = f.toHomUnits * g.toHomUnits := by
ext; rfl
/-- `MonoidHom.toHomUnits` as a `MulEquiv`. -/
@[simps] def toHomUnitsMulEquiv : (G →* M) ≃* (G →* Mˣ) where
toFun := toHomUnits
invFun f := (Units.coeHom _).comp f
map_mul' := by simp
end MonoidHom
namespace IsUnit
variable {F G M N : Type*} [FunLike F M N] [FunLike G N M]
section Monoid
variable [Monoid M] [Monoid N]
@[to_additive]
theorem map [MonoidHomClass F M N] (f : F) {x : M} (h : IsUnit x) : IsUnit (f x) := by
rcases h with ⟨y, rfl⟩; exact (Units.map (f : M →* N) y).isUnit
@[to_additive]
theorem of_leftInverse [MonoidHomClass G N M] {f : F} {x : M} (g : G)
(hfg : Function.LeftInverse g f) (h : IsUnit (f x)) : IsUnit x := by
simpa only [hfg x] using h.map g
/-- Prefer `IsLocalHom.of_leftInverse`, but we can't get rid of this because of `ToAdditive`. -/
@[to_additive]
theorem _root_.isUnit_map_of_leftInverse [MonoidHomClass F M N] [MonoidHomClass G N M]
{f : F} {x : M} (g : G) (hfg : Function.LeftInverse g f) :
IsUnit (f x) ↔ IsUnit x := ⟨of_leftInverse g hfg, map _⟩
/-- If a homomorphism `f : M →* N` sends each element to an `IsUnit`, then it can be lifted
to `f : M →* Nˣ`. See also `Units.liftRight` for a computable version. -/
@[to_additive
/-- If a homomorphism `f : M →+ N` sends each element to an `IsAddUnit`, then it can be
lifted to `f : M →+ AddUnits N`. See also `AddUnits.liftRight` for a computable version. -/]
noncomputable def liftRight (f : M →* N) (hf : ∀ x, IsUnit (f x)) : M →* Nˣ :=
(Units.liftRight f fun x => (hf x).unit) fun _ => rfl
@[to_additive]
theorem coe_liftRight (f : M →* N) (hf : ∀ x, IsUnit (f x)) (x) :
(IsUnit.liftRight f hf x : N) = f x := rfl
@[to_additive (attr := simp)]
theorem mul_liftRight_inv (f : M →* N) (h : ∀ x, IsUnit (f x)) (x) :
f x * ↑(IsUnit.liftRight f h x)⁻¹ = 1 := Units.mul_liftRight_inv (by intro; rfl) x
@[to_additive (attr := simp)]
theorem liftRight_inv_mul (f : M →* N) (h : ∀ x, IsUnit (f x)) (x) :
↑(IsUnit.liftRight f h x)⁻¹ * f x = 1 := Units.liftRight_inv_mul (by intro; rfl) x
end Monoid
end IsUnit
section IsLocalHom
variable {G R S T F : Type*}
variable [Monoid R] [Monoid S] [Monoid T] [FunLike F R S]
/-- A map `f` between monoids is *local* if any `a` in the domain is a unit
whenever `f a` is a unit. See `IsLocalRing.local_hom_TFAE` for other equivalent
definitions in the local ring case - from where this concept originates, but it is useful in
other contexts, so we allow this generalisation in mathlib. -/
class IsLocalHom (f : F) : Prop where
/-- A local homomorphism `f : R ⟶ S` will send nonunits of `R` to nonunits of `S`. -/
map_nonunit : ∀ a, IsUnit (f a) → IsUnit a
theorem IsUnit.of_map (f : F) [IsLocalHom f] (a : R) (h : IsUnit (f a)) : IsUnit a :=
IsLocalHom.map_nonunit a h
-- TODO : remove alias, change the parenthesis of `f` and `a`
alias isUnit_of_map_unit := IsUnit.of_map
variable [MonoidHomClass F R S]
@[simp]
theorem isUnit_map_iff (f : F) [IsLocalHom f] (a : R) : IsUnit (f a) ↔ IsUnit a :=
⟨IsLocalHom.map_nonunit a, IsUnit.map f⟩
theorem isLocalHom_of_leftInverse [FunLike G S R] [MonoidHomClass G S R]
{f : F} (g : G) (hfg : Function.LeftInverse g f) : IsLocalHom f where
map_nonunit a ha := by rwa [isUnit_map_of_leftInverse g hfg] at ha
@[instance]
theorem MonoidHom.isLocalHom_comp (g : S →* T) (f : R →* S) [IsLocalHom g]
[IsLocalHom f] : IsLocalHom (g.comp f) where
map_nonunit a := IsLocalHom.map_nonunit a ∘ IsLocalHom.map_nonunit (f := g) (f a)
-- see note [lower instance priority]
@[instance 100]
theorem isLocalHom_toMonoidHom (f : F) [IsLocalHom f] :
IsLocalHom (f : R →* S) :=
⟨IsLocalHom.map_nonunit (f := f)⟩
theorem MonoidHom.isLocalHom_of_comp (f : R →* S) (g : S →* T) [IsLocalHom (g.comp f)] :
IsLocalHom f :=
⟨fun _ ha => (isUnit_map_iff (g.comp f) _).mp (ha.map g)⟩
end IsLocalHom |
.lake/packages/mathlib/Mathlib/Algebra/Group/Pi/Lemmas.lean | import Mathlib.Algebra.Group.Commute.Defs
import Mathlib.Algebra.Group.Hom.Instances
import Mathlib.Algebra.Group.Pi.Basic
import Mathlib.Algebra.Group.Torsion
import Mathlib.Data.Set.Piecewise
import Mathlib.Logic.Pairwise
/-!
# Extra lemmas about products of monoids and groups
This file proves lemmas about the instances defined in `Algebra.Group.Pi.Basic` that require more
imports.
-/
assert_not_exists AddMonoidWithOne MonoidWithZero
universe u v w
variable {ι α : Type*}
variable {I : Type u}
variable {f : I → Type v} {M : ι → Type*}
variable (i : I)
@[to_additive (attr := simp)]
theorem Set.range_one {α β : Type*} [One β] [Nonempty α] : Set.range (1 : α → β) = {1} :=
range_const
@[to_additive]
theorem Set.preimage_one {α β : Type*} [One β] (s : Set β) [Decidable ((1 : β) ∈ s)] :
(1 : α → β) ⁻¹' s = if (1 : β) ∈ s then Set.univ else ∅ :=
Set.preimage_const 1 s
namespace Pi
@[to_additive]
instance instIsMulTorsionFree [∀ i, Monoid (M i)] [∀ i, IsMulTorsionFree (M i)] :
IsMulTorsionFree (∀ i, M i) where
pow_left_injective n hn a b hab := by ext i; exact pow_left_injective hn <| congr_fun hab i
variable {α β : Type*} [Preorder α] [Preorder β]
@[to_additive] lemma one_mono [One β] : Monotone (1 : α → β) := monotone_const
@[to_additive] lemma one_anti [One β] : Antitone (1 : α → β) := antitone_const
end Pi
namespace MulHom
@[to_additive]
theorem coe_mul {M N} {_ : Mul M} {_ : CommSemigroup N} (f g : M →ₙ* N) : (f * g : M → N) =
fun x => f x * g x := rfl
end MulHom
section MulHom
/-- A family of MulHom's `f a : γ →ₙ* β a` defines a MulHom `Pi.mulHom f : γ →ₙ* Π a, β a`
given by `Pi.mulHom f x b = f b x`. -/
@[to_additive (attr := simps)
/-- A family of AddHom's `f a : γ → β a` defines an AddHom `Pi.addHom f : γ → Π a, β a` given by
`Pi.addHom f x b = f b x`. -/]
def Pi.mulHom {γ : Type w} [∀ i, Mul (f i)] [Mul γ] (g : ∀ i, γ →ₙ* f i) : γ →ₙ* ∀ i, f i where
toFun x i := g i x
map_mul' x y := funext fun i => (g i).map_mul x y
@[to_additive]
theorem Pi.mulHom_injective {γ : Type w} [Nonempty I] [∀ i, Mul (f i)] [Mul γ] (g : ∀ i, γ →ₙ* f i)
(hg : ∀ i, Function.Injective (g i)) : Function.Injective (Pi.mulHom g) := fun _ _ h =>
let ⟨i⟩ := ‹Nonempty I›
hg i ((funext_iff.mp h :) i)
/-- A family of monoid homomorphisms `f a : γ →* β a` defines a monoid homomorphism
`Pi.monoidHom f : γ →* Π a, β a` given by `Pi.monoidHom f x b = f b x`. -/
@[to_additive (attr := simps)
/-- A family of additive monoid homomorphisms `f a : γ →+ β a` defines a monoid homomorphism
`Pi.addMonoidHom f : γ →+ Π a, β a` given by `Pi.addMonoidHom f x b = f b x`. -/]
def Pi.monoidHom {γ : Type w} [∀ i, MulOneClass (f i)] [MulOneClass γ] (g : ∀ i, γ →* f i) :
γ →* ∀ i, f i :=
{ Pi.mulHom fun i => (g i).toMulHom with
toFun := fun x i => g i x
map_one' := funext fun i => (g i).map_one }
@[to_additive]
theorem Pi.monoidHom_injective {γ : Type w} [Nonempty I] [∀ i, MulOneClass (f i)] [MulOneClass γ]
(g : ∀ i, γ →* f i) (hg : ∀ i, Function.Injective (g i)) :
Function.Injective (Pi.monoidHom g) :=
Pi.mulHom_injective (fun i => (g i).toMulHom) hg
variable (f)
variable [(i : I) → Mul (f i)]
/-- Evaluation of functions into an indexed collection of semigroups at a point is a semigroup
homomorphism.
This is `Function.eval i` as a `MulHom`. -/
@[to_additive (attr := simps)
/-- Evaluation of functions into an indexed collection of additive semigroups at a point is an
additive semigroup homomorphism. This is `Function.eval i` as an `AddHom`. -/]
def Pi.evalMulHom (i : I) : (∀ i, f i) →ₙ* f i where
toFun g := g i
map_mul' _ _ := Pi.mul_apply _ _ i
/-- `Function.const` as a `MulHom`. -/
@[to_additive (attr := simps) /-- `Function.const` as an `AddHom`. -/]
def Pi.constMulHom (α β : Type*) [Mul β] :
β →ₙ* α → β where
toFun := Function.const α
map_mul' _ _ := rfl
/-- Coercion of a `MulHom` into a function is itself a `MulHom`.
See also `MulHom.eval`. -/
@[to_additive (attr := simps) /-- Coercion of an `AddHom` into a function is itself an `AddHom`.
See also `AddHom.eval`. -/]
def MulHom.coeFn (α β : Type*) [Mul α] [CommSemigroup β] :
(α →ₙ* β) →ₙ* α → β where
toFun g := g
map_mul' _ _ := rfl
/-- Semigroup homomorphism between the function spaces `I → α` and `I → β`, induced by a semigroup
homomorphism `f` between `α` and `β`. -/
@[to_additive (attr := simps) /-- Additive semigroup homomorphism between the function spaces
`I → α` and `I → β`, induced by an additive semigroup homomorphism `f` between `α` and `β` -/]
protected def MulHom.compLeft {α β : Type*} [Mul α] [Mul β] (f : α →ₙ* β) (I : Type*) :
(I → α) →ₙ* I → β where
toFun h := f ∘ h
map_mul' _ _ := by ext; simp
end MulHom
section MonoidHom
variable (f)
variable [(i : I) → MulOneClass (f i)]
/-- Evaluation of functions into an indexed collection of monoids at a point is a monoid
homomorphism.
This is `Function.eval i` as a `MonoidHom`. -/
@[to_additive (attr := simps) /-- Evaluation of functions into an indexed collection of additive
monoids at a point is an additive monoid homomorphism. This is `Function.eval i` as an
`AddMonoidHom`. -/]
def Pi.evalMonoidHom (i : I) : (∀ i, f i) →* f i where
toFun g := g i
map_one' := Pi.one_apply i
map_mul' _ _ := Pi.mul_apply _ _ i
@[simp, norm_cast]
lemma Pi.coe_evalMonoidHom (i : I) : ⇑(evalMonoidHom f i) = Function.eval i := rfl
/-- `Function.const` as a `MonoidHom`. -/
@[to_additive (attr := simps) /-- `Function.const` as an `AddMonoidHom`. -/]
def Pi.constMonoidHom (α β : Type*) [MulOneClass β] : β →* α → β where
toFun := Function.const α
map_one' := rfl
map_mul' _ _ := rfl
/-- Coercion of a `MonoidHom` into a function is itself a `MonoidHom`.
See also `MonoidHom.eval`. -/
@[to_additive (attr := simps) /-- Coercion of an `AddMonoidHom` into a function is itself
an `AddMonoidHom`.
See also `AddMonoidHom.eval`. -/]
def MonoidHom.coeFn (α β : Type*) [MulOneClass α] [CommMonoid β] : (α →* β) →* α → β where
toFun g := g
map_one' := rfl
map_mul' _ _ := rfl
/-- Monoid homomorphism between the function spaces `I → α` and `I → β`, induced by a monoid
homomorphism `f` between `α` and `β`. -/
@[to_additive (attr := simps)
/-- Additive monoid homomorphism between the function spaces `I → α` and `I → β`, induced by an
additive monoid homomorphism `f` between `α` and `β` -/]
protected def MonoidHom.compLeft {α β : Type*} [MulOneClass α] [MulOneClass β] (f : α →* β)
(I : Type*) : (I → α) →* I → β where
toFun h := f ∘ h
map_one' := by ext; simp
map_mul' _ _ := by ext; simp
end MonoidHom
section Single
variable [DecidableEq I]
open Pi
variable (f) in
/-- The one-preserving homomorphism including a single value
into a dependent family of values, as functions supported at a point.
This is the `OneHom` version of `Pi.mulSingle`. -/
@[to_additive
/-- The zero-preserving homomorphism including a single value into a dependent family of values,
as functions supported at a point.
This is the `ZeroHom` version of `Pi.single`. -/]
nonrec def OneHom.mulSingle [∀ i, One <| f i] (i : I) : OneHom (f i) (∀ i, f i) where
toFun := mulSingle i
map_one' := mulSingle_one i
@[to_additive (attr := simp)]
theorem OneHom.mulSingle_apply [∀ i, One <| f i] (i : I) (x : f i) :
mulSingle f i x = Pi.mulSingle i x := rfl
@[to_additive (attr := simp, norm_cast)]
theorem OneHom.coe_mulSingle [∀ i, One <| f i] (i : I) :
mulSingle f i = Pi.mulSingle (M := f) i := rfl
variable (f) in
/-- The monoid homomorphism including a single monoid into a dependent family of additive monoids,
as functions supported at a point.
This is the `MonoidHom` version of `Pi.mulSingle`. -/
@[to_additive
/-- The additive monoid homomorphism including a single additive monoid into a dependent family
of additive monoids, as functions supported at a point.
This is the `AddMonoidHom` version of `Pi.single`. -/]
def MonoidHom.mulSingle [∀ i, MulOneClass <| f i] (i : I) : f i →* ∀ i, f i :=
{ OneHom.mulSingle f i with map_mul' := mulSingle_op₂ (fun _ => (· * ·)) (fun _ => one_mul _) _ }
@[to_additive (attr := simp)]
theorem MonoidHom.mulSingle_apply [∀ i, MulOneClass <| f i] (i : I) (x : f i) :
mulSingle f i x = Pi.mulSingle i x :=
rfl
@[to_additive (attr := simp, norm_cast)]
theorem MonoidHom.coe_mulSingle [∀ i, MulOneClass <| f i] (i : I) :
mulSingle f i = Pi.mulSingle (M := f) i := rfl
@[to_additive]
theorem Pi.mulSingle_sup [∀ i, SemilatticeSup (f i)] [∀ i, One (f i)] (i : I) (x y : f i) :
Pi.mulSingle i (x ⊔ y) = Pi.mulSingle i x ⊔ Pi.mulSingle i y :=
Function.update_sup _ _ _ _
@[to_additive]
theorem Pi.mulSingle_inf [∀ i, SemilatticeInf (f i)] [∀ i, One (f i)] (i : I) (x y : f i) :
Pi.mulSingle i (x ⊓ y) = Pi.mulSingle i x ⊓ Pi.mulSingle i y :=
Function.update_inf _ _ _ _
@[to_additive]
theorem Pi.mulSingle_mul [∀ i, MulOneClass <| f i] (i : I) (x y : f i) :
mulSingle i (x * y) = mulSingle i x * mulSingle i y :=
(MonoidHom.mulSingle f i).map_mul x y
@[to_additive]
theorem Pi.mulSingle_inv [∀ i, Group <| f i] (i : I) (x : f i) :
mulSingle i x⁻¹ = (mulSingle i x)⁻¹ :=
(MonoidHom.mulSingle f i).map_inv x
@[to_additive]
theorem Pi.mulSingle_div [∀ i, Group <| f i] (i : I) (x y : f i) :
mulSingle i (x / y) = mulSingle i x / mulSingle i y :=
(MonoidHom.mulSingle f i).map_div x y
@[to_additive]
theorem Pi.mulSingle_pow [∀ i, Monoid (f i)] (i : I) (x : f i) (n : ℕ) :
mulSingle i (x ^ n) = mulSingle i x ^ n :=
(MonoidHom.mulSingle f i).map_pow x n
@[to_additive]
theorem Pi.mulSingle_zpow [∀ i, Group (f i)] (i : I) (x : f i) (n : ℤ) :
mulSingle i (x ^ n) = mulSingle i x ^ n :=
(MonoidHom.mulSingle f i).map_zpow x n
/-- The injection into a pi group at different indices commutes.
For injections of commuting elements at the same index, see `Commute.map` -/
@[to_additive
/-- The injection into an additive pi group at different indices commutes.
For injections of commuting elements at the same index, see `AddCommute.map` -/]
theorem Pi.mulSingle_commute [∀ i, MulOneClass <| f i] :
Pairwise fun i j => ∀ (x : f i) (y : f j), Commute (mulSingle i x) (mulSingle j y) := by
intro i j hij x y; ext k
by_cases i = k <;> simp_all
/-- The injection into a pi group with the same values commutes. -/
@[to_additive /-- The injection into an additive pi group with the same values commutes. -/]
theorem Pi.mulSingle_apply_commute [∀ i, MulOneClass <| f i] (x : ∀ i, f i) (i j : I) :
Commute (mulSingle i (x i)) (mulSingle j (x j)) := by
obtain rfl | hij := Decidable.eq_or_ne i j
· rfl
· exact Pi.mulSingle_commute hij _ _
@[to_additive]
theorem Pi.update_eq_div_mul_mulSingle [∀ i, Group <| f i] (g : ∀ i : I, f i) (x : f i) :
Function.update g i x = g / mulSingle i (g i) * mulSingle i x := by
ext j
rcases eq_or_ne i j with (rfl | h)
· simp
· simp [Function.update_of_ne h.symm, h]
@[to_additive]
theorem Pi.mulSingle_mul_mulSingle_eq_mulSingle_mul_mulSingle {M : Type*} [CommMonoid M]
{k l m n : I} {u v : M} (hu : u ≠ 1) (hv : v ≠ 1) :
(mulSingle k u : I → M) * mulSingle l v = mulSingle m u * mulSingle n v ↔
k = m ∧ l = n ∨ u = v ∧ k = n ∧ l = m ∨ u * v = 1 ∧ k = l ∧ m = n := by
refine ⟨fun h ↦ ?_, ?_⟩
· have hk := congr_fun h k
have hl := congr_fun h l
have hm := congr_fun h m
have hn := congr_fun h n
simp only [mul_apply, mulSingle_apply] at hk hl hm hn
grind [mul_one, one_mul]
· aesop (add simp [mulSingle_apply])
end Single
section
variable [∀ i, Mul <| f i]
@[to_additive]
theorem SemiconjBy.pi {x y z : ∀ i, f i} (h : ∀ i, SemiconjBy (x i) (y i) (z i)) :
SemiconjBy x y z :=
funext h
@[to_additive]
theorem Pi.semiconjBy_iff {x y z : ∀ i, f i} :
SemiconjBy x y z ↔ ∀ i, SemiconjBy (x i) (y i) (z i) := funext_iff
@[to_additive]
theorem Commute.pi {x y : ∀ i, f i} (h : ∀ i, Commute (x i) (y i)) : Commute x y := SemiconjBy.pi h
@[to_additive]
theorem Pi.commute_iff {x y : ∀ i, f i} : Commute x y ↔ ∀ i, Commute (x i) (y i) := semiconjBy_iff
end
namespace Function
@[to_additive (attr := simp)]
theorem update_one [∀ i, One (f i)] [DecidableEq I] (i : I) : update (1 : ∀ i, f i) i 1 = 1 :=
update_eq_self i (1 : (a : I) → f a)
@[to_additive]
theorem update_mul [∀ i, Mul (f i)] [DecidableEq I] (f₁ f₂ : ∀ i, f i) (i : I) (x₁ : f i)
(x₂ : f i) : update (f₁ * f₂) i (x₁ * x₂) = update f₁ i x₁ * update f₂ i x₂ :=
funext fun j => (apply_update₂ (fun _ => (· * ·)) f₁ f₂ i x₁ x₂ j).symm
@[to_additive]
theorem update_inv [∀ i, Inv (f i)] [DecidableEq I] (f₁ : ∀ i, f i) (i : I) (x₁ : f i) :
update f₁⁻¹ i x₁⁻¹ = (update f₁ i x₁)⁻¹ :=
funext fun j => (apply_update (fun _ => Inv.inv) f₁ i x₁ j).symm
@[to_additive]
theorem update_div [∀ i, Div (f i)] [DecidableEq I] (f₁ f₂ : ∀ i, f i) (i : I) (x₁ : f i)
(x₂ : f i) : update (f₁ / f₂) i (x₁ / x₂) = update f₁ i x₁ / update f₂ i x₂ :=
funext fun j => (apply_update₂ (fun _ => (· / ·)) f₁ f₂ i x₁ x₂ j).symm
variable [One α] [Nonempty ι] {a : α}
@[to_additive (attr := simp)]
theorem const_eq_one : const ι a = 1 ↔ a = 1 :=
@const_inj _ _ _ _ 1
@[to_additive]
theorem const_ne_one : const ι a ≠ 1 ↔ a ≠ 1 :=
Iff.not const_eq_one
end Function
section Piecewise
@[to_additive]
theorem Set.piecewise_mul [∀ i, Mul (f i)] (s : Set I) [∀ i, Decidable (i ∈ s)]
(f₁ f₂ g₁ g₂ : ∀ i, f i) :
s.piecewise (f₁ * f₂) (g₁ * g₂) = s.piecewise f₁ g₁ * s.piecewise f₂ g₂ :=
s.piecewise_op₂ f₁ _ _ _ fun _ => (· * ·)
@[to_additive]
theorem Set.piecewise_inv [∀ i, Inv (f i)] (s : Set I) [∀ i, Decidable (i ∈ s)] (f₁ g₁ : ∀ i, f i) :
s.piecewise f₁⁻¹ g₁⁻¹ = (s.piecewise f₁ g₁)⁻¹ :=
s.piecewise_op f₁ g₁ fun _ x => x⁻¹
@[to_additive]
theorem Set.piecewise_div [∀ i, Div (f i)] (s : Set I) [∀ i, Decidable (i ∈ s)]
(f₁ f₂ g₁ g₂ : ∀ i, f i) :
s.piecewise (f₁ / f₂) (g₁ / g₂) = s.piecewise f₁ g₁ / s.piecewise f₂ g₂ :=
s.piecewise_op₂ f₁ _ _ _ fun _ => (· / ·)
end Piecewise
section Extend
variable {η : Type v} (R : Type w) (s : ι → η)
/-- `Function.extend s f 1` as a bundled hom. -/
@[to_additive (attr := simps) Function.ExtendByZero.hom
/-- `Function.extend s f 0` as a bundled hom. -/]
noncomputable def Function.ExtendByOne.hom [MulOneClass R] :
(ι → R) →* η → R where
toFun f := Function.extend s f 1
map_one' := Function.extend_one s
map_mul' f g := by simpa using Function.extend_mul s f g 1 1
end Extend
namespace Pi
variable [DecidableEq I] [∀ i, Preorder (f i)] [∀ i, One (f i)]
@[to_additive]
theorem mulSingle_mono : Monotone (Pi.mulSingle i : f i → ∀ i, f i) :=
Function.update_mono
@[to_additive]
theorem mulSingle_strictMono : StrictMono (Pi.mulSingle i : f i → ∀ i, f i) :=
Function.update_strictMono
@[to_additive]
lemma mulSingle_comp_equiv {m n : Type*} [DecidableEq n] [DecidableEq m] [One α] (σ : n ≃ m)
(i : m) (x : α) : Pi.mulSingle i x ∘ σ = Pi.mulSingle (σ.symm i) x := by
ext x
aesop (add simp Pi.mulSingle_apply)
end Pi
namespace Sigma
variable {α : Type*} {β : α → Type*} {γ : ∀ a, β a → Type*}
@[to_additive (attr := simp)]
theorem curry_one [∀ a b, One (γ a b)] : Sigma.curry (1 : (i : Σ a, β a) → γ i.1 i.2) = 1 :=
rfl
@[to_additive (attr := simp)]
theorem uncurry_one [∀ a b, One (γ a b)] : Sigma.uncurry (1 : ∀ a b, γ a b) = 1 :=
rfl
@[to_additive (attr := simp)]
theorem curry_mul [∀ a b, Mul (γ a b)] (x y : (i : Σ a, β a) → γ i.1 i.2) :
Sigma.curry (x * y) = Sigma.curry x * Sigma.curry y :=
rfl
@[to_additive (attr := simp)]
theorem uncurry_mul [∀ a b, Mul (γ a b)] (x y : ∀ a b, γ a b) :
Sigma.uncurry (x * y) = Sigma.uncurry x * Sigma.uncurry y :=
rfl
@[to_additive (attr := simp)]
theorem curry_inv [∀ a b, Inv (γ a b)] (x : (i : Σ a, β a) → γ i.1 i.2) :
Sigma.curry (x⁻¹) = (Sigma.curry x)⁻¹ :=
rfl
@[to_additive (attr := simp)]
theorem uncurry_inv [∀ a b, Inv (γ a b)] (x : ∀ a b, γ a b) :
Sigma.uncurry (x⁻¹) = (Sigma.uncurry x)⁻¹ :=
rfl
@[to_additive (attr := simp)]
theorem curry_mulSingle [DecidableEq α] [∀ a, DecidableEq (β a)] [∀ a b, One (γ a b)]
(i : Σ a, β a) (x : γ i.1 i.2) :
Sigma.curry (Pi.mulSingle i x) = Pi.mulSingle i.1 (Pi.mulSingle i.2 x) := by
simp only [Pi.mulSingle, Sigma.curry_update, Sigma.curry_one, Pi.one_apply]
@[to_additive (attr := simp)]
theorem uncurry_mulSingle_mulSingle [DecidableEq α] [∀ a, DecidableEq (β a)] [∀ a b, One (γ a b)]
(a : α) (b : β a) (x : γ a b) :
Sigma.uncurry (Pi.mulSingle a (Pi.mulSingle b x)) = Pi.mulSingle (Sigma.mk a b) x := by
rw [← curry_mulSingle ⟨a, b⟩, uncurry_curry]
end Sigma |
.lake/packages/mathlib/Mathlib/Algebra/Group/Pi/Basic.lean | import Mathlib.Algebra.Group.Defs
import Mathlib.Algebra.Notation.Pi.Basic
import Mathlib.Data.Sum.Basic
import Mathlib.Logic.Unique
import Mathlib.Tactic.Spread
/-!
# Instances and theorems on pi types
This file provides instances for the typeclass defined in `Algebra.Group.Defs`. More sophisticated
instances are defined in `Algebra.Group.Pi.Lemmas` files elsewhere.
## Porting note
This file relied on the `pi_instance` tactic, which was not available at the time of porting. The
comment `--pi_instance` is inserted before all fields which were previously derived by
`pi_instance`. See this Zulip discussion:
[https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/not.20porting.20pi_instance]
-/
-- We enforce to only import `Algebra.Group.Defs` and basic logic
assert_not_exists Set.range MonoidHom MonoidWithZero DenselyOrdered
universe u v₁ v₂ v₃
variable {I : Type u}
-- The indexing type
variable {α β γ : Type*}
-- The families of types already equipped with instances
variable {f : I → Type v₁} {g : I → Type v₂} {h : I → Type v₃}
variable (x y : ∀ i, f i) (i : I)
namespace Pi
@[to_additive]
instance semigroup [∀ i, Semigroup (f i)] : Semigroup (∀ i, f i) where
mul_assoc := by intros; ext; exact mul_assoc _ _ _
@[to_additive]
instance commSemigroup [∀ i, CommSemigroup (f i)] : CommSemigroup (∀ i, f i) where
mul_comm := by intros; ext; exact mul_comm _ _
@[to_additive]
instance mulOneClass [∀ i, MulOneClass (f i)] : MulOneClass (∀ i, f i) where
one_mul := by intros; ext; exact one_mul _
mul_one := by intros; ext; exact mul_one _
@[to_additive]
instance invOneClass [∀ i, InvOneClass (f i)] : InvOneClass (∀ i, f i) where
inv_one := by ext; exact inv_one
@[to_additive]
instance monoid [∀ i, Monoid (f i)] : Monoid (∀ i, f i) where
__ := semigroup
__ := mulOneClass
npow := fun n x i => x i ^ n
npow_zero := by intros; ext; exact Monoid.npow_zero _
npow_succ := by intros; ext; exact Monoid.npow_succ _ _
@[to_additive]
instance commMonoid [∀ i, CommMonoid (f i)] : CommMonoid (∀ i, f i) :=
{ monoid, commSemigroup with }
@[to_additive Pi.subNegMonoid]
instance divInvMonoid [∀ i, DivInvMonoid (f i)] : DivInvMonoid (∀ i, f i) where
zpow := fun z x i => x i ^ z
div_eq_mul_inv := by intros; ext; exact div_eq_mul_inv _ _
zpow_zero' := by intros; ext; exact DivInvMonoid.zpow_zero' _
zpow_succ' := by intros; ext; exact DivInvMonoid.zpow_succ' _ _
zpow_neg' := by intros; ext; exact DivInvMonoid.zpow_neg' _ _
@[to_additive]
instance divInvOneMonoid [∀ i, DivInvOneMonoid (f i)] : DivInvOneMonoid (∀ i, f i) where
inv_one := by ext; exact inv_one
@[to_additive]
instance involutiveInv [∀ i, InvolutiveInv (f i)] : InvolutiveInv (∀ i, f i) where
inv_inv := by intros; ext; exact inv_inv _
@[to_additive]
instance divisionMonoid [∀ i, DivisionMonoid (f i)] : DivisionMonoid (∀ i, f i) where
__ := divInvMonoid
__ := involutiveInv
mul_inv_rev := by intros; ext; exact mul_inv_rev _ _
inv_eq_of_mul := by intro _ _ h; ext; exact DivisionMonoid.inv_eq_of_mul _ _ (congrFun h _)
@[to_additive instSubtractionCommMonoid]
instance divisionCommMonoid [∀ i, DivisionCommMonoid (f i)] : DivisionCommMonoid (∀ i, f i) :=
{ divisionMonoid, commSemigroup with }
@[to_additive]
instance group [∀ i, Group (f i)] : Group (∀ i, f i) where
inv_mul_cancel := by intros; ext; exact inv_mul_cancel _
@[to_additive]
instance commGroup [∀ i, CommGroup (f i)] : CommGroup (∀ i, f i) := { group, commMonoid with }
@[to_additive] instance instIsLeftCancelMul [∀ i, Mul (f i)] [∀ i, IsLeftCancelMul (f i)] :
IsLeftCancelMul (∀ i, f i) where
mul_left_cancel _ _ _ h := funext fun _ ↦ mul_left_cancel (congr_fun h _)
@[to_additive] instance instIsRightCancelMul [∀ i, Mul (f i)] [∀ i, IsRightCancelMul (f i)] :
IsRightCancelMul (∀ i, f i) where
mul_right_cancel _ _ _ h := funext fun _ ↦ mul_right_cancel (congr_fun h _)
@[to_additive] instance instIsCancelMul [∀ i, Mul (f i)] [∀ i, IsCancelMul (f i)] :
IsCancelMul (∀ i, f i) where
@[to_additive]
instance leftCancelSemigroup [∀ i, LeftCancelSemigroup (f i)] : LeftCancelSemigroup (∀ i, f i) :=
{ semigroup with mul_left_cancel := fun _ _ _ => mul_left_cancel }
@[to_additive]
instance rightCancelSemigroup [∀ i, RightCancelSemigroup (f i)] : RightCancelSemigroup (∀ i, f i) :=
{ semigroup with mul_right_cancel := fun _ _ _ => mul_right_cancel }
@[to_additive]
instance leftCancelMonoid [∀ i, LeftCancelMonoid (f i)] : LeftCancelMonoid (∀ i, f i) :=
{ leftCancelSemigroup, monoid with }
@[to_additive]
instance rightCancelMonoid [∀ i, RightCancelMonoid (f i)] : RightCancelMonoid (∀ i, f i) :=
{ rightCancelSemigroup, monoid with }
@[to_additive]
instance cancelMonoid [∀ i, CancelMonoid (f i)] : CancelMonoid (∀ i, f i) :=
{ leftCancelMonoid, rightCancelMonoid with }
@[to_additive]
instance cancelCommMonoid [∀ i, CancelCommMonoid (f i)] : CancelCommMonoid (∀ i, f i) :=
{ leftCancelMonoid, commMonoid with }
end Pi
namespace Function
section Extend
@[to_additive]
theorem extend_one [One γ] (f : α → β) : Function.extend f (1 : α → γ) (1 : β → γ) = 1 :=
funext fun _ => by apply ite_self
@[to_additive]
theorem extend_mul [Mul γ] (f : α → β) (g₁ g₂ : α → γ) (e₁ e₂ : β → γ) :
Function.extend f (g₁ * g₂) (e₁ * e₂) = Function.extend f g₁ e₁ * Function.extend f g₂ e₂ := by
classical
funext x
simp [Function.extend_def, apply_dite₂]
@[to_additive]
theorem extend_inv [Inv γ] (f : α → β) (g : α → γ) (e : β → γ) :
Function.extend f g⁻¹ e⁻¹ = (Function.extend f g e)⁻¹ := by
classical
funext x
simp [Function.extend_def, apply_dite Inv.inv]
@[to_additive]
theorem extend_div [Div γ] (f : α → β) (g₁ g₂ : α → γ) (e₁ e₂ : β → γ) :
Function.extend f (g₁ / g₂) (e₁ / e₂) = Function.extend f g₁ e₁ / Function.extend f g₂ e₂ := by
classical
funext x
simp [Function.extend_def, apply_dite₂]
end Extend
lemma comp_eq_const_iff (b : β) (f : α → β) {g : β → γ} (hg : Injective g) :
g ∘ f = Function.const _ (g b) ↔ f = Function.const _ b :=
hg.comp_left.eq_iff' rfl
@[to_additive]
lemma comp_eq_one_iff [One β] [One γ] (f : α → β) {g : β → γ} (hg : Injective g) (hg0 : g 1 = 1) :
g ∘ f = 1 ↔ f = 1 := by
simpa [hg0, const_one] using comp_eq_const_iff 1 f hg
@[to_additive]
lemma comp_ne_one_iff [One β] [One γ] (f : α → β) {g : β → γ} (hg : Injective g) (hg0 : g 1 = 1) :
g ∘ f ≠ 1 ↔ f ≠ 1 :=
(comp_eq_one_iff f hg hg0).ne
end Function
/-- If the one function is surjective, the codomain is trivial. -/
@[to_additive /-- If the zero function is surjective, the codomain is trivial. -/]
def uniqueOfSurjectiveOne (α : Type*) {β : Type*} [One β] (h : Function.Surjective (1 : α → β)) :
Unique β :=
h.uniqueOfSurjectiveConst α (1 : β)
@[to_additive]
theorem Subsingleton.pi_mulSingle_eq {α : Type*} [DecidableEq I] [Subsingleton I] [One α]
(i : I) (x : α) : Pi.mulSingle i x = fun _ => x :=
funext fun j => by rw [Subsingleton.elim j i, Pi.mulSingle_eq_same]
namespace Sum
variable (a a' : α → γ) (b b' : β → γ)
@[to_additive (attr := simp)]
theorem elim_one_one [One γ] : Sum.elim (1 : α → γ) (1 : β → γ) = 1 :=
Sum.elim_const_const 1
@[to_additive (attr := simp)]
theorem elim_mulSingle_one [DecidableEq α] [DecidableEq β] [One γ] (i : α) (c : γ) :
Sum.elim (Pi.mulSingle i c) (1 : β → γ) = Pi.mulSingle (Sum.inl i) c := by
simp only [Pi.mulSingle, Sum.elim_update_left, elim_one_one]
@[to_additive (attr := simp)]
theorem elim_one_mulSingle [DecidableEq α] [DecidableEq β] [One γ] (i : β) (c : γ) :
Sum.elim (1 : α → γ) (Pi.mulSingle i c) = Pi.mulSingle (Sum.inr i) c := by
simp only [Pi.mulSingle, Sum.elim_update_right, elim_one_one]
@[to_additive]
theorem elim_inv_inv [Inv γ] : Sum.elim a⁻¹ b⁻¹ = (Sum.elim a b)⁻¹ :=
(Sum.comp_elim Inv.inv a b).symm
@[to_additive]
theorem elim_mul_mul [Mul γ] : Sum.elim (a * a') (b * b') = Sum.elim a b * Sum.elim a' b' := by
ext x
cases x <;> rfl
@[to_additive]
theorem elim_div_div [Div γ] : Sum.elim (a / a') (b / b') = Sum.elim a b / Sum.elim a' b' := by
ext x
cases x <;> rfl
end Sum |
.lake/packages/mathlib/Mathlib/Algebra/Group/Pi/Units.lean | import Mathlib.Algebra.Group.Equiv.Defs
import Mathlib.Algebra.Group.Pi.Basic
import Mathlib.Algebra.Group.Units.Defs
import Mathlib.Util.Delaborators
/-! # Units in pi types -/
variable {ι : Type*} {M : ι → Type*} [∀ i, Monoid (M i)] {x : Π i, M i}
open Units in
/-- The monoid equivalence between units of a product,
and the product of the units of each monoid. -/
@[to_additive (attr := simps)
/-- The additive-monoid equivalence between (additive) units of a product,
and the product of the (additive) units of each monoid. -/]
def MulEquiv.piUnits : (Π i, M i)ˣ ≃* Π i, (M i)ˣ where
toFun f i := ⟨f.val i, f.inv i, congr_fun f.val_inv i, congr_fun f.inv_val i⟩
invFun f := ⟨(val <| f ·), (inv <| f ·), funext (val_inv <| f ·), funext (inv_val <| f ·)⟩
map_mul' _ _ := rfl
@[to_additive]
lemma Pi.isUnit_iff :
IsUnit x ↔ ∀ i, IsUnit (x i) := by
simp_rw [isUnit_iff_exists, funext_iff, ← forall_and]
exact Classical.skolem (p := fun i y ↦ x i * y = 1 ∧ y * x i = 1).symm
@[to_additive]
alias ⟨IsUnit.apply, _⟩ := Pi.isUnit_iff
@[to_additive]
lemma IsUnit.val_inv_apply (hx : IsUnit x) (i : ι) : (hx.unit⁻¹).1 i = (hx.apply i).unit⁻¹ := by
rw [← Units.inv_eq_val_inv, ← MulEquiv.val_inv_piUnits_apply]; congr; ext; rfl |
.lake/packages/mathlib/Mathlib/Algebra/Group/Int/Defs.lean | import Mathlib.Algebra.Group.Defs
/-!
# The integers form a group
This file contains the additive group and multiplicative monoid instances on the integers.
See note [foundational algebra order theory].
-/
assert_not_exists Ring DenselyOrdered
open Nat
namespace Int
/-! ### Instances -/
instance instCommMonoid : CommMonoid ℤ where
mul_comm := Int.mul_comm
mul_one := Int.mul_one
one_mul := Int.one_mul
npow n x := x ^ n
npow_zero _ := rfl
npow_succ _ _ := rfl
mul_assoc := Int.mul_assoc
instance instAddCommGroup : AddCommGroup ℤ where
add_comm := Int.add_comm
add_assoc := Int.add_assoc
add_zero := Int.add_zero
zero_add := Int.zero_add
neg_add_cancel := Int.add_left_neg
nsmul := (·*·)
nsmul_zero := Int.zero_mul
nsmul_succ n x :=
show (n + 1 : ℤ) * x = n * x + x
by rw [Int.add_mul, Int.one_mul]
zsmul := (·*·)
zsmul_zero' := Int.zero_mul
zsmul_succ' m n := by
simp only [natCast_succ, Int.add_mul, Int.add_comm, Int.one_mul]
zsmul_neg' m n := by simp only [negSucc_eq, natCast_succ, Int.neg_mul]
sub_eq_add_neg _ _ := Int.sub_eq_add_neg
/-!
### Extra instances to short-circuit type class resolution
These also prevent non-computable instances like `Int.instNormedCommRing` being used to construct
these instances non-computably.
-/
set_option linter.style.commandStart false
instance instAddCommMonoid : AddCommMonoid ℤ := by infer_instance
instance instAddMonoid : AddMonoid ℤ := by infer_instance
instance instMonoid : Monoid ℤ := by infer_instance
instance instCommSemigroup : CommSemigroup ℤ := by infer_instance
instance instSemigroup : Semigroup ℤ := by infer_instance
instance instAddGroup : AddGroup ℤ := by infer_instance
instance instAddCommSemigroup : AddCommSemigroup ℤ := by infer_instance
instance instAddSemigroup : AddSemigroup ℤ := by infer_instance
-- This lemma is higher priority than later `_root_.nsmul_eq_mul` so that the `simpNF` is happy
@[simp high] protected lemma nsmul_eq_mul (n : ℕ) (a : ℤ) : n • a = n * a := rfl
-- This lemma is higher priority than later `_root_.zsmul_eq_mul` so that the `simpNF` is happy
@[simp high] protected lemma zsmul_eq_mul (n a : ℤ) : n • a = n * a := rfl
end Int
-- TODO: Do we really need this lemma? This is just `smul_eq_mul`
lemma zsmul_int_int (a b : ℤ) : a • b = a * b := rfl
lemma zsmul_int_one (n : ℤ) : n • (1 : ℤ) = n := mul_one _ |
.lake/packages/mathlib/Mathlib/Algebra/Group/Int/Even.lean | import Mathlib.Algebra.Group.Int.Defs
import Mathlib.Algebra.Group.Nat.Even
import Mathlib.Data.Int.Sqrt
/-!
# Parity of integers
-/
open Nat
namespace Int
/-! #### Parity -/
variable {m n : ℤ}
@[simp] lemma emod_two_ne_one : ¬n % 2 = 1 ↔ n % 2 = 0 := by grind
@[simp] lemma one_emod_two : (1 : Int) % 2 = 1 := rfl
-- `EuclideanDomain.mod_eq_zero` uses (2 ∣ n) as normal form
@[local simp] lemma emod_two_ne_zero : ¬n % 2 = 0 ↔ n % 2 = 1 := by grind
@[grind =]
lemma even_iff : Even n ↔ n % 2 = 0 where
mp := fun ⟨m, hm⟩ ↦ by simp [← Int.two_mul, hm]
mpr h := ⟨n / 2, by grind⟩
lemma not_even_iff : ¬Even n ↔ n % 2 = 1 := by grind
@[simp] lemma two_dvd_ne_zero : ¬2 ∣ n ↔ n % 2 = 1 := by grind
instance : DecidablePred (Even : ℤ → Prop) := fun _ ↦ decidable_of_iff _ even_iff.symm
/-- `IsSquare` can be decided on `ℤ` by checking against the square root. -/
instance : DecidablePred (IsSquare : ℤ → Prop) :=
fun m ↦ decidable_of_iff' (sqrt m * sqrt m = m) <| by
simp_rw [← exists_mul_self m, IsSquare, eq_comm]
@[simp] lemma not_even_one : ¬Even (1 : ℤ) := by simp [even_iff]
@[parity_simps] lemma even_add : Even (m + n) ↔ (Even m ↔ Even n) := by grind
lemma two_not_dvd_two_mul_add_one (n : ℤ) : ¬2 ∣ 2 * n + 1 := by grind
@[parity_simps]
lemma even_sub : Even (m - n) ↔ (Even m ↔ Even n) := by grind
@[parity_simps] lemma even_add_one : Even (n + 1) ↔ ¬Even n := by grind
@[parity_simps] lemma even_sub_one : Even (n - 1) ↔ ¬Even n := by grind
@[parity_simps, grind =] lemma even_mul : Even (m * n) ↔ Even m ∨ Even n := by
rcases emod_two_eq_zero_or_one m with h₁ | h₁ <;>
rcases emod_two_eq_zero_or_one n with h₂ | h₂ <;>
simp [even_iff, h₁, h₂, Int.mul_emod]
@[parity_simps, grind =] lemma even_pow {n : ℕ} : Even (m ^ n) ↔ Even m ∧ n ≠ 0 := by
induction n with grind
lemma even_pow' {n : ℕ} (h : n ≠ 0) : Even (m ^ n) ↔ Even m := by grind
@[simp, norm_cast, grind =]
lemma even_coe_nat (n : ℕ) : Even (n : ℤ) ↔ Even n := by
rw_mod_cast [even_iff, Nat.even_iff]
lemma two_mul_ediv_two_of_even : Even n → 2 * (n / 2) = n := by grind
lemma ediv_two_mul_two_of_even : Even n → n / 2 * 2 = n := by grind
-- Here are examples of how `parity_simps` can be used with `Int`.
example (m n : ℤ) (h : Even m) : ¬Even (n + 3) ↔ Even (m ^ 2 + m + n) := by
simp +decide [*, parity_simps]
example : ¬Even (25394535 : ℤ) := by decide
@[simp]
theorem isSquare_sign_iff {z : ℤ} : IsSquare z.sign ↔ 0 ≤ z := by
induction z using Int.induction_on with
| zero => simpa using ⟨0, by simp⟩
| succ => norm_cast; simp
| pred =>
rw [sign_eq_neg_one_of_neg (by cutsat), ← neg_add', Int.neg_nonneg]
norm_cast
simp only [reduceNeg, le_zero_eq, Nat.add_eq_zero, succ_ne_self, and_false, iff_false]
rintro ⟨a | a, ⟨⟩⟩
end Int |
.lake/packages/mathlib/Mathlib/Algebra/Group/Int/TypeTags.lean | import Mathlib.Algebra.Group.Int.Defs
import Mathlib.Algebra.Group.TypeTags.Basic
/-!
# Lemmas about `Multiplicative ℤ`.
-/
open Nat
namespace Int
section Multiplicative
open Multiplicative
lemma toAdd_pow (a : Multiplicative ℤ) (b : ℕ) : (a ^ b).toAdd = a.toAdd * b := mul_comm _ _
lemma toAdd_zpow (a : Multiplicative ℤ) (b : ℤ) : (a ^ b).toAdd = a.toAdd * b := mul_comm _ _
@[simp] lemma ofAdd_mul (a b : ℤ) : ofAdd (a * b) = ofAdd a ^ b := (toAdd_zpow ..).symm
end Multiplicative
end Int |
.lake/packages/mathlib/Mathlib/Algebra/Group/Int/Units.lean | import Mathlib.Tactic.Tauto
import Mathlib.Algebra.Group.Int.Defs
import Mathlib.Algebra.Group.Basic
import Mathlib.Algebra.Group.Nat.Units
/-!
# Units in the integers
-/
open Nat
namespace Int
/-! #### Units -/
variable {u v : ℤ}
lemma units_natAbs (u : ℤˣ) : natAbs u = 1 :=
Units.ext_iff.1 <|
Nat.units_eq_one
⟨natAbs u, natAbs ↑u⁻¹, by rw [← natAbs_mul, Units.mul_inv]; rfl, by
rw [← natAbs_mul, Units.inv_mul]; rfl⟩
@[simp] lemma natAbs_of_isUnit (hu : IsUnit u) : natAbs u = 1 := units_natAbs hu.unit
lemma isUnit_eq_one_or (hu : IsUnit u) : u = 1 ∨ u = -1 := by
simpa only [natAbs_of_isUnit hu] using natAbs_eq u
lemma isUnit_ne_iff_eq_neg (hu : IsUnit u) (hv : IsUnit v) : u ≠ v ↔ u = -v := by
obtain rfl | rfl := isUnit_eq_one_or hu <;> obtain rfl | rfl := isUnit_eq_one_or hv <;> decide
lemma isUnit_eq_or_eq_neg (hu : IsUnit u) (hv : IsUnit v) : u = v ∨ u = -v :=
or_iff_not_imp_left.2 (isUnit_ne_iff_eq_neg hu hv).1
lemma isUnit_iff : IsUnit u ↔ u = 1 ∨ u = -1 := by
refine ⟨fun h ↦ isUnit_eq_one_or h, fun h ↦ ?_⟩
rcases h with (rfl | rfl)
· exact isUnit_one
· exact ⟨⟨-1, -1, by decide, by decide⟩, rfl⟩
lemma eq_one_or_neg_one_of_mul_eq_one (h : u * v = 1) : u = 1 ∨ u = -1 :=
isUnit_iff.1 (.of_mul_eq_one v h)
lemma eq_one_or_neg_one_of_mul_eq_one' (h : u * v = 1) : u = 1 ∧ v = 1 ∨ u = -1 ∧ v = -1 := by
have h' : v * u = 1 := mul_comm u v ▸ h
obtain rfl | rfl := eq_one_or_neg_one_of_mul_eq_one h <;>
obtain rfl | rfl := eq_one_or_neg_one_of_mul_eq_one h' <;> tauto
lemma eq_of_mul_eq_one (h : u * v = 1) : u = v :=
(eq_one_or_neg_one_of_mul_eq_one' h).elim
(and_imp.2 (·.trans ·.symm)) (and_imp.2 (·.trans ·.symm))
lemma mul_eq_one_iff_eq_one_or_neg_one : u * v = 1 ↔ u = 1 ∧ v = 1 ∨ u = -1 ∧ v = -1 := by
refine ⟨eq_one_or_neg_one_of_mul_eq_one', fun h ↦ Or.elim h (fun H ↦ ?_) fun H ↦ ?_⟩ <;>
obtain ⟨rfl, rfl⟩ := H <;> rfl
lemma eq_one_or_neg_one_of_mul_eq_neg_one' (h : u * v = -1) : u = 1 ∧ v = -1 ∨ u = -1 ∧ v = 1 := by
obtain rfl | rfl := isUnit_eq_one_or (IsUnit.mul_iff.mp (Int.isUnit_iff.mpr (Or.inr h))).1
· exact Or.inl ⟨rfl, one_mul v ▸ h⟩
· simpa [Int.neg_mul] using h
lemma mul_eq_neg_one_iff_eq_one_or_neg_one : u * v = -1 ↔ u = 1 ∧ v = -1 ∨ u = -1 ∧ v = 1 := by
refine ⟨eq_one_or_neg_one_of_mul_eq_neg_one', fun h ↦ Or.elim h (fun H ↦ ?_) fun H ↦ ?_⟩ <;>
obtain ⟨rfl, rfl⟩ := H <;> rfl
lemma isUnit_iff_natAbs_eq : IsUnit u ↔ u.natAbs = 1 := by simp [natAbs_eq_iff, isUnit_iff]
alias ⟨IsUnit.natAbs_eq, _⟩ := isUnit_iff_natAbs_eq
@[norm_cast]
lemma ofNat_isUnit {n : ℕ} : IsUnit (n : ℤ) ↔ IsUnit n := by simp [isUnit_iff_natAbs_eq]
lemma isUnit_mul_self (hu : IsUnit u) : u * u = 1 :=
(isUnit_eq_one_or hu).elim (fun h ↦ h.symm ▸ rfl) fun h ↦ h.symm ▸ rfl
lemma isUnit_add_isUnit_eq_isUnit_add_isUnit {a b c d : ℤ} (ha : IsUnit a) (hb : IsUnit b)
(hc : IsUnit c) (hd : IsUnit d) : a + b = c + d ↔ a = c ∧ b = d ∨ a = d ∧ b = c := by
rw [isUnit_iff] at ha hb hc hd
cutsat
lemma eq_one_or_neg_one_of_mul_eq_neg_one (h : u * v = -1) : u = 1 ∨ u = -1 :=
Or.elim (eq_one_or_neg_one_of_mul_eq_neg_one' h) (fun H => Or.inl H.1) fun H => Or.inr H.1
end Int |
.lake/packages/mathlib/Mathlib/Algebra/Group/Action/Sum.lean | import Mathlib.Algebra.Group.Action.Faithful
/-!
# Sum instances for additive and multiplicative actions
This file defines instances for additive and multiplicative actions on the binary `Sum` type.
## See also
* `Mathlib/Algebra/Group/Action/Option.lean`
* `Mathlib/Algebra/Group/Action/Pi.lean`
* `Mathlib/Algebra/Group/Action/Prod.lean`
* `Mathlib/Algebra/Group/Action/Sigma.lean`
-/
assert_not_exists MonoidWithZero
variable {M N α β : Type*}
namespace Sum
section SMul
variable [SMul M α] [SMul M β] [SMul N α] [SMul N β] (a : M) (b : α) (c : β)
(x : α ⊕ β)
@[to_additive]
instance instSMul : SMul M (α ⊕ β) :=
⟨fun a => Sum.map (a • ·) (a • ·)⟩
@[to_additive]
theorem smul_def : a • x = x.map (a • ·) (a • ·) :=
rfl
@[to_additive (attr := simp)]
theorem smul_inl : a • (inl b : α ⊕ β) = inl (a • b) :=
rfl
@[to_additive (attr := simp)]
theorem smul_inr : a • (inr c : α ⊕ β) = inr (a • c) :=
rfl
@[to_additive (attr := simp)]
theorem smul_swap : (a • x).swap = a • x.swap := by cases x <;> rfl
instance [SMul M N] [IsScalarTower M N α] [IsScalarTower M N β] : IsScalarTower M N (α ⊕ β) :=
⟨fun a b x => by
cases x
exacts [congr_arg inl (smul_assoc _ _ _), congr_arg inr (smul_assoc _ _ _)]⟩
@[to_additive]
instance [SMulCommClass M N α] [SMulCommClass M N β] : SMulCommClass M N (α ⊕ β) :=
⟨fun a b x => by
cases x
exacts [congr_arg inl (smul_comm _ _ _), congr_arg inr (smul_comm _ _ _)]⟩
@[to_additive]
instance [SMul Mᵐᵒᵖ α] [SMul Mᵐᵒᵖ β] [IsCentralScalar M α] [IsCentralScalar M β] :
IsCentralScalar M (α ⊕ β) :=
⟨fun a x => by
cases x
exacts [congr_arg inl (op_smul_eq_smul _ _), congr_arg inr (op_smul_eq_smul _ _)]⟩
@[to_additive]
instance FaithfulSMulLeft [FaithfulSMul M α] : FaithfulSMul M (α ⊕ β) :=
⟨fun h => eq_of_smul_eq_smul fun a : α => by injection h (inl a)⟩
@[to_additive]
instance FaithfulSMulRight [FaithfulSMul M β] : FaithfulSMul M (α ⊕ β) :=
⟨fun h => eq_of_smul_eq_smul fun b : β => by injection h (inr b)⟩
end SMul
@[to_additive]
instance {m : Monoid M} [MulAction M α] [MulAction M β] :
MulAction M (α ⊕ β) where
mul_smul a b x := by
cases x
exacts [congr_arg inl (mul_smul _ _ _), congr_arg inr (mul_smul _ _ _)]
one_smul x := by
cases x
exacts [congr_arg inl (one_smul _ _), congr_arg inr (one_smul _ _)]
end Sum |
.lake/packages/mathlib/Mathlib/Algebra/Group/Action/Opposite.lean | import Mathlib.Algebra.Group.Action.Defs
import Mathlib.Algebra.Group.Opposite
/-!
# Scalar actions on and by `Mᵐᵒᵖ`
This file defines the actions on the opposite type `SMul R Mᵐᵒᵖ`, and actions by the opposite
type, `SMul Rᵐᵒᵖ M`.
Note that `MulOpposite.smul` is provided in an earlier file as it is needed to
provide the `AddMonoid.nsmul` and `AddCommGroup.zsmul` fields.
## Notation
With `open scoped RightActions`, this provides:
* `r •> m` as an alias for `r • m`
* `m <• r` as an alias for `MulOpposite.op r • m`
* `v +ᵥ> p` as an alias for `v +ᵥ p`
* `p <+ᵥ v` as an alias for `AddOpposite.op v +ᵥ p`
-/
assert_not_exists MonoidWithZero Units FaithfulSMul MonoidHom
variable {M N α β : Type*}
/-!
### Actions _on_ the opposite type
Actions on the opposite type just act on the underlying type.
-/
namespace MulOpposite
@[to_additive]
instance instMulAction [Monoid M] [MulAction M α] : MulAction M αᵐᵒᵖ where
one_smul _ := unop_injective <| one_smul _ _
mul_smul _ _ _ := unop_injective <| mul_smul _ _ _
@[to_additive]
instance instIsScalarTower [SMul M N] [SMul M α] [SMul N α] [IsScalarTower M N α] :
IsScalarTower M N αᵐᵒᵖ where
smul_assoc _ _ _ := unop_injective <| smul_assoc _ _ _
@[to_additive]
instance instSMulCommClass [SMul M α] [SMul N α] [SMulCommClass M N α] :
SMulCommClass M N αᵐᵒᵖ where
smul_comm _ _ _ := unop_injective <| smul_comm _ _ _
@[to_additive]
instance instIsCentralScalar [SMul M α] [SMul Mᵐᵒᵖ α] [IsCentralScalar M α] :
IsCentralScalar M αᵐᵒᵖ where
op_smul_eq_smul _ _ := unop_injective <| op_smul_eq_smul _ _
@[to_additive]
lemma op_smul_eq_op_smul_op [SMul M α] [SMul Mᵐᵒᵖ α] [IsCentralScalar M α] (r : M) (a : α) :
op (r • a) = op r • op a := (op_smul_eq_smul r (op a)).symm
@[to_additive]
lemma unop_smul_eq_unop_smul_unop [SMul M α] [SMul Mᵐᵒᵖ α] [IsCentralScalar M α] (r : Mᵐᵒᵖ)
(a : αᵐᵒᵖ) : unop (r • a) = unop r • unop a := (unop_smul_eq_smul r (unop a)).symm
end MulOpposite
/-!
### Right actions
In this section we establish `SMul αᵐᵒᵖ β` as the canonical spelling of right scalar multiplication
of `β` by `α`, and provide convenient notations.
-/
namespace RightActions
/-- With `open scoped RightActions`, an alternative symbol for left actions, `r • m`.
In lemma names this is still called `smul`. -/
scoped notation3:74 r:75 " •> " m:74 => r • m
/-- With `open scoped RightActions`, a shorthand for right actions, `op r • m`.
In lemma names this is still called `op_smul`. -/
scoped notation3:73 m:73 " <• " r:74 => MulOpposite.op r • m
/-- With `open scoped RightActions`, an alternative symbol for left actions, `r • m`.
In lemma names this is still called `vadd`. -/
scoped notation3:74 r:75 " +ᵥ> " m:74 => r +ᵥ m
/-- With `open scoped RightActions`, a shorthand for right actions, `op r +ᵥ m`.
In lemma names this is still called `op_vadd`. -/
scoped notation3:73 m:73 " <+ᵥ " r:74 => AddOpposite.op r +ᵥ m
section examples
variable [SMul α β] [SMul αᵐᵒᵖ β] [VAdd α β] [VAdd αᵃᵒᵖ β] {a a₁ a₂ a₃ a₄ : α} {b : β}
-- Left and right actions are just notation around the general `•` and `+ᵥ` notations
example : a •> b = a • b := rfl
example : b <• a = MulOpposite.op a • b := rfl
example : a +ᵥ> b = a +ᵥ b := rfl
example : b <+ᵥ a = AddOpposite.op a +ᵥ b := rfl
-- Left actions right-associate, right actions left-associate
example : a₁ •> a₂ •> b = a₁ •> (a₂ •> b) := rfl
example : b <• a₂ <• a₁ = (b <• a₂) <• a₁ := rfl
example : a₁ +ᵥ> a₂ +ᵥ> b = a₁ +ᵥ> (a₂ +ᵥ> b) := rfl
example : b <+ᵥ a₂ <+ᵥ a₁ = (b <+ᵥ a₂) <+ᵥ a₁ := rfl
-- When left and right actions coexist, they associate to the left
example : a₁ •> b <• a₂ = (a₁ •> b) <• a₂ := rfl
example : a₁ •> a₂ •> b <• a₃ <• a₄ = ((a₁ •> (a₂ •> b)) <• a₃) <• a₄ := rfl
example : a₁ +ᵥ> b <+ᵥ a₂ = (a₁ +ᵥ> b) <+ᵥ a₂ := rfl
example : a₁ +ᵥ> a₂ +ᵥ> b <+ᵥ a₃ <+ᵥ a₄ = ((a₁ +ᵥ> (a₂ +ᵥ> b)) <+ᵥ a₃) <+ᵥ a₄ := rfl
end examples
end RightActions
section
variable [Monoid α] [MulAction αᵐᵒᵖ β]
open scoped RightActions
@[to_additive]
lemma op_smul_op_smul (b : β) (a₁ a₂ : α) : b <• a₁ <• a₂ = b <• (a₁ * a₂) := smul_smul _ _ _
@[to_additive]
lemma op_smul_mul (b : β) (a₁ a₂ : α) : b <• (a₁ * a₂) = b <• a₁ <• a₂ := mul_smul _ _ _
end
/-! ### Actions _by_ the opposite type (right actions) -/
open MulOpposite
@[to_additive]
instance Semigroup.opposite_smulCommClass [Semigroup α] : SMulCommClass αᵐᵒᵖ α α where
smul_comm _ _ _ := mul_assoc _ _ _
@[to_additive]
instance Semigroup.opposite_smulCommClass' [Semigroup α] : SMulCommClass α αᵐᵒᵖ α :=
SMulCommClass.symm _ _ _
@[to_additive]
instance CommSemigroup.isCentralScalar [CommSemigroup α] : IsCentralScalar α α where
op_smul_eq_smul _ _ := mul_comm _ _
/-- Like `Monoid.toMulAction`, but multiplies on the right. -/
@[to_additive /-- Like `AddMonoid.toAddAction`, but adds on the right. -/]
instance Monoid.toOppositeMulAction [Monoid α] : MulAction αᵐᵒᵖ α where
one_smul := mul_one
mul_smul _ _ _ := (mul_assoc _ _ _).symm
@[to_additive]
instance IsScalarTower.opposite_mid {M N} [Mul N] [SMul M N] [SMulCommClass M N N] :
IsScalarTower M Nᵐᵒᵖ N where
smul_assoc _ _ _ := mul_smul_comm _ _ _
@[to_additive]
instance SMulCommClass.opposite_mid {M N} [Mul N] [SMul M N] [IsScalarTower M N N] :
SMulCommClass M Nᵐᵒᵖ N where
smul_comm x y z := by
induction y using MulOpposite.rec'
simp only [smul_mul_assoc, MulOpposite.smul_eq_mul_unop]
-- The above instance does not create an unwanted diamond, the two paths to
-- `MulAction αᵐᵒᵖ αᵐᵒᵖ` are defeq.
example [Monoid α] : Monoid.toMulAction αᵐᵒᵖ = MulOpposite.instMulAction := by
with_reducible_and_instances rfl |
.lake/packages/mathlib/Mathlib/Algebra/Group/Action/Option.lean | import Mathlib.Algebra.Group.Action.Faithful
/-!
# Option instances for additive and multiplicative actions
This file defines instances for additive and multiplicative actions on `Option` type. Scalar
multiplication is defined by `a • some b = some (a • b)` and `a • none = none`.
## See also
* `Mathlib/Algebra/Group/Action/Pi.lean`
* `Mathlib/Algebra/Group/Action/Sigma.lean`
* `Mathlib/Algebra/Group/Action/Sum.lean`
-/
assert_not_exists MonoidWithZero
variable {M N α : Type*}
namespace Option
section SMul
variable [SMul M α] [SMul N α] (a : M) (b : α) (x : Option α)
@[to_additive Option.VAdd]
instance : SMul M (Option α) :=
⟨fun a => Option.map <| (a • ·)⟩
@[to_additive]
theorem smul_def : a • x = x.map (a • ·) :=
rfl
@[to_additive (attr := simp)]
theorem smul_none : a • (none : Option α) = none :=
rfl
@[to_additive (attr := simp)]
theorem smul_some : a • some b = some (a • b) :=
rfl
@[to_additive]
instance instIsScalarTowerOfSMul [SMul M N] [IsScalarTower M N α] : IsScalarTower M N (Option α) :=
⟨fun a b x => by
cases x
exacts [rfl, congr_arg some (smul_assoc _ _ _)]⟩
@[to_additive]
instance [SMulCommClass M N α] : SMulCommClass M N (Option α) :=
⟨fun _ _ => Function.Commute.option_map <| smul_comm _ _⟩
@[to_additive]
instance [SMul Mᵐᵒᵖ α] [IsCentralScalar M α] : IsCentralScalar M (Option α) :=
⟨fun a x => by
cases x
exacts [rfl, congr_arg some (op_smul_eq_smul _ _)]⟩
@[to_additive]
instance [FaithfulSMul M α] : FaithfulSMul M (Option α) :=
⟨fun h => eq_of_smul_eq_smul fun b : α => by injection h (some b)⟩
end SMul
instance [Monoid M] [MulAction M α] :
MulAction M (Option α) where
one_smul b := by
cases b
exacts [rfl, congr_arg some (one_smul _ _)]
mul_smul a₁ a₂ b := by
cases b
exacts [rfl, congr_arg some (mul_smul _ _ _)]
end Option |
.lake/packages/mathlib/Mathlib/Algebra/Group/Action/Faithful.lean | import Mathlib.Algebra.Group.Action.Defs
/-!
# Faithful group actions
This file provides typeclasses for faithful actions.
## Notation
- `a • b` is used as notation for `SMul.smul a b`.
- `a +ᵥ b` is used as notation for `VAdd.vadd a b`.
## Implementation details
This file should avoid depending on other parts of `GroupTheory`, to avoid import cycles.
More sophisticated lemmas belong in `GroupTheory.GroupAction`.
## Tags
group action
-/
assert_not_exists MonoidWithZero
open Function (Injective Surjective)
variable {M G α : Type*}
/-! ### Faithful actions -/
/-- Typeclass for faithful actions. -/
class FaithfulVAdd (G : Type*) (P : Type*) [VAdd G P] : Prop where
/-- Two elements `g₁` and `g₂` are equal whenever they act in the same way on all points. -/
eq_of_vadd_eq_vadd : ∀ {g₁ g₂ : G}, (∀ p : P, g₁ +ᵥ p = g₂ +ᵥ p) → g₁ = g₂
/-- Typeclass for faithful actions. -/
@[to_additive]
class FaithfulSMul (M : Type*) (α : Type*) [SMul M α] : Prop where
/-- Two elements `m₁` and `m₂` are equal whenever they act in the same way on all points. -/
eq_of_smul_eq_smul : ∀ {m₁ m₂ : M}, (∀ a : α, m₁ • a = m₂ • a) → m₁ = m₂
export FaithfulSMul (eq_of_smul_eq_smul)
export FaithfulVAdd (eq_of_vadd_eq_vadd)
@[to_additive]
lemma smul_left_injective' [SMul M α] [FaithfulSMul M α] : Injective ((· • ·) : M → α → α) :=
fun _ _ h ↦ FaithfulSMul.eq_of_smul_eq_smul (congr_fun h)
/-- `Monoid.toMulAction` is faithful on cancellative monoids. -/
@[to_additive /-- `AddMonoid.toAddAction` is faithful on additive cancellative monoids. -/]
instance RightCancelMonoid.faithfulSMul [RightCancelMonoid α] : FaithfulSMul α α :=
⟨fun h ↦ mul_right_cancel (h 1)⟩
/-- `Monoid.toOppositeMulAction` is faithful on cancellative monoids. -/
@[to_additive /-- `AddMonoid.toOppositeAddAction` is faithful on additive cancellative monoids. -/]
instance LeftCancelMonoid.to_faithfulSMul_mulOpposite [LeftCancelMonoid α] : FaithfulSMul αᵐᵒᵖ α :=
⟨fun h ↦ MulOpposite.unop_injective <| mul_left_cancel (h 1)⟩
@[deprecated (since := "2025-09-15")]
alias LefttCancelMonoid.to_faithfulSMul_mulOpposite := LeftCancelMonoid.to_faithfulSMul_mulOpposite
instance (R : Type*) [MulOneClass R] : FaithfulSMul R R := ⟨fun {r₁ r₂} h ↦ by simpa using h 1⟩
lemma faithfulSMul_iff_injective_smul_one (R A : Type*)
[MulOneClass A] [SMul R A] [IsScalarTower R A A] :
FaithfulSMul R A ↔ Injective (fun r : R ↦ r • (1 : A)) := by
refine ⟨fun ⟨h⟩ {r₁ r₂} hr ↦ h fun a ↦ ?_, fun h ↦ ⟨fun {r₁ r₂} hr ↦ h ?_⟩⟩
· simp only at hr
rw [← one_mul a, ← smul_mul_assoc, ← smul_mul_assoc, hr]
· simpa using hr 1
/--
Let `Q / P / N / M` be a tower. If `Q / N / M`, `Q / P / M` and `Q / P / N` are
scalar towers, then `P / N / M` is also a scalar tower.
-/
@[to_additive] lemma IsScalarTower.to₁₂₃ (M N P Q)
[SMul M N] [SMul M P] [SMul M Q] [SMul N P] [SMul N Q] [SMul P Q] [FaithfulSMul P Q]
[IsScalarTower M N Q] [IsScalarTower M P Q] [IsScalarTower N P Q] : IsScalarTower M N P where
smul_assoc m n p := by simp_rw [← (smul_left_injective' (α := Q)).eq_iff, smul_assoc] |
.lake/packages/mathlib/Mathlib/Algebra/Group/Action/TransferInstance.lean | import Mathlib.Algebra.Group.Action.Defs
import Mathlib.Algebra.Group.Equiv.Defs
import Mathlib.Algebra.Group.TransferInstance
import Mathlib.Algebra.Group.InjSurj
import Mathlib.Data.Fintype.Basic
/-!
# Transfer algebraic structures across `Equiv`s
This continues the pattern set in `Mathlib/Algebra/Group/TransferInstance.lean`.
-/
assert_not_exists MonoidWithZero
namespace Equiv
variable {M N O α β : Type*}
variable (M) [Monoid M] in
/-- Transfer `MulAction` across an `Equiv` -/
@[to_additive /-- Transfer `AddAction` across an `Equiv` -/]
protected abbrev mulAction (e : α ≃ β) [MulAction M β] : MulAction M α where
__ := e.smul M
one_smul := by simp [smul_def]
mul_smul := by simp [smul_def, mul_smul]
variable (M N) [SMul M β] [SMul N β] in
/-- Transfer `SMulCommClass` across an `Equiv` -/
@[to_additive /-- Transfer `VAddCommClass` across an `Equiv` -/]
protected lemma smulCommClass (e : α ≃ β) [SMulCommClass M N β] :
letI := e.smul M
letI := e.smul N
SMulCommClass M N α :=
letI := e.smul M
letI := e.smul N
{ smul_comm := by simp [smul_def, smul_comm] }
variable (M N) [SMul M N] [SMul M β] [SMul N β] in
/-- Transfer `IsScalarTower` across an `Equiv` -/
@[to_additive /-- Transfer `VAddAssocClass` across an `Equiv` -/]
protected lemma isScalarTower (e : α ≃ β) [IsScalarTower M N β] :
letI := e.smul M
letI := e.smul N
IsScalarTower M N α :=
letI := e.smul M
letI := e.smul N
{ smul_assoc := by simp [smul_def, smul_assoc] }
variable (M) [SMul M β] [SMul Mᵐᵒᵖ β] in
/-- Transfer `IsCentralScalar` across an `Equiv` -/
@[to_additive /-- Transfer `IsCentralVAdd` across an `Equiv` -/]
protected lemma isCentralScalar (e : α ≃ β) [IsCentralScalar M β] :
letI := e.smul M
letI := e.smul Mᵐᵒᵖ
IsCentralScalar M α :=
letI := e.smul M
letI := e.smul Mᵐᵒᵖ
{ op_smul_eq_smul := by simp [smul_def, op_smul_eq_smul] }
variable (M) [Monoid M] [Monoid O] in
/-- Transfer `MulDistribMulAction` across an `Equiv` -/
protected abbrev mulDistribMulAction (e : N ≃ O) [MulDistribMulAction M O] :
letI := e.monoid
MulDistribMulAction M N :=
letI := e.monoid
{ e.mulAction M with
smul_one := by simp [one_def, smul_def, smul_one]
smul_mul := by simp [mul_def, smul_def, smul_mul'] }
end Equiv |
.lake/packages/mathlib/Mathlib/Algebra/Group/Action/Sigma.lean | import Mathlib.Algebra.Group.Action.Faithful
import Mathlib.Data.Sigma.Basic
/-!
# Sigma instances for additive and multiplicative actions
This file defines instances for arbitrary sum of additive and multiplicative actions.
## See also
* `Mathlib/Algebra/Group/Action/Option.lean`
* `Mathlib/Algebra/Group/Action/Pi.lean`
* `Mathlib/Algebra/Group/Action/Prod.lean`
* `Mathlib/Algebra/Group/Action/Sum.lean`
-/
assert_not_exists MonoidWithZero
variable {ι : Type*} {M N : Type*} {α : ι → Type*}
namespace Sigma
section SMul
variable [∀ i, SMul M (α i)] [∀ i, SMul N (α i)] (a : M) (i : ι) (b : α i) (x : Σ i, α i)
@[to_additive Sigma.VAdd]
instance : SMul M (Σ i, α i) :=
⟨fun a => (Sigma.map id) fun _ => (a • ·)⟩
@[to_additive]
theorem smul_def : a • x = x.map id fun _ => (a • ·) :=
rfl
@[to_additive (attr := simp)]
theorem smul_mk : a • mk i b = ⟨i, a • b⟩ :=
rfl
@[to_additive]
instance instIsScalarTowerOfSMul [SMul M N] [∀ i, IsScalarTower M N (α i)] :
IsScalarTower M N (Σ i, α i) :=
⟨fun a b x => by
cases x
rw [smul_mk, smul_mk, smul_mk, smul_assoc]⟩
@[to_additive]
instance [∀ i, SMulCommClass M N (α i)] : SMulCommClass M N (Σ i, α i) :=
⟨fun a b x => by
cases x
rw [smul_mk, smul_mk, smul_mk, smul_mk, smul_comm]⟩
@[to_additive]
instance [∀ i, SMul Mᵐᵒᵖ (α i)] [∀ i, IsCentralScalar M (α i)] : IsCentralScalar M (Σ i, α i) :=
⟨fun a x => by
cases x
rw [smul_mk, smul_mk, op_smul_eq_smul]⟩
/-- This is not an instance because `i` becomes a metavariable. -/
@[to_additive /-- This is not an instance because `i` becomes a metavariable. -/]
protected theorem FaithfulSMul' [FaithfulSMul M (α i)] : FaithfulSMul M (Σ i, α i) :=
⟨fun h => eq_of_smul_eq_smul fun a : α i => heq_iff_eq.1 (Sigma.ext_iff.1 <| h <| mk i a).2⟩
@[to_additive]
instance [Nonempty ι] [∀ i, FaithfulSMul M (α i)] : FaithfulSMul M (Σ i, α i) :=
(Nonempty.elim ‹_›) fun i => Sigma.FaithfulSMul' i
end SMul
@[to_additive]
instance {m : Monoid M} [∀ i, MulAction M (α i)] :
MulAction M (Σ i, α i) where
mul_smul a b x := by
cases x
rw [smul_mk, smul_mk, smul_mk, mul_smul]
one_smul x := by
cases x
rw [smul_mk, one_smul]
end Sigma |
.lake/packages/mathlib/Mathlib/Algebra/Group/Action/Prod.lean | import Mathlib.Algebra.Group.Action.Faithful
import Mathlib.Algebra.Group.Action.Hom
import Mathlib.Algebra.Group.Prod
/-!
# Prod instances for additive and multiplicative actions
This file defines instances for binary product of additive and multiplicative actions and provides
scalar multiplication as a homomorphism from `α × β` to `β`.
## Main declarations
* `smulMulHom`/`smulMonoidHom`: Scalar multiplication bundled as a multiplicative/monoid
homomorphism.
## See also
* `Mathlib/Algebra/Group/Action/Option.lean`
* `Mathlib/Algebra/Group/Action/Pi.lean`
* `Mathlib/Algebra/Group/Action/Sigma.lean`
* `Mathlib/Algebra/Group/Action/Sum.lean`
## Porting notes
The `to_additive` attribute can be used to generate both the `smul` and `vadd` lemmas
from the corresponding `pow` lemmas, as explained on zulip here:
https://leanprover.zulipchat.com/#narrow/near/316087838
This was not done as part of the port in order to stay as close as possible to the mathlib3 code.
-/
assert_not_exists MonoidWithZero
variable {M N P E α β : Type*}
namespace Prod
section
variable [SMul M α] [SMul M β] [SMul N α] [SMul N β] (a : M) (x : α × β)
@[to_additive]
instance isScalarTower [SMul M N] [IsScalarTower M N α] [IsScalarTower M N β] :
IsScalarTower M N (α × β) where
smul_assoc _ _ _ := by ext <;> exact smul_assoc ..
@[to_additive]
instance smulCommClass [SMulCommClass M N α] [SMulCommClass M N β] : SMulCommClass M N (α × β) where
smul_comm _ _ _ := by ext <;> exact smul_comm ..
@[to_additive]
instance isCentralScalar [SMul Mᵐᵒᵖ α] [SMul Mᵐᵒᵖ β] [IsCentralScalar M α] [IsCentralScalar M β] :
IsCentralScalar M (α × β) where
op_smul_eq_smul _ _ := Prod.ext (op_smul_eq_smul _ _) (op_smul_eq_smul _ _)
@[to_additive]
instance faithfulSMulLeft [FaithfulSMul M α] [Nonempty β] : FaithfulSMul M (α × β) where
eq_of_smul_eq_smul h :=
let ⟨b⟩ := ‹Nonempty β›
eq_of_smul_eq_smul fun a : α => by injection h (a, b)
@[to_additive]
instance faithfulSMulRight [Nonempty α] [FaithfulSMul M β] : FaithfulSMul M (α × β) where
eq_of_smul_eq_smul h :=
let ⟨a⟩ := ‹Nonempty α›
eq_of_smul_eq_smul fun b : β => by injection h (a, b)
end
@[to_additive]
instance smulCommClassBoth [Mul N] [Mul P] [SMul M N] [SMul M P] [SMulCommClass M N N]
[SMulCommClass M P P] : SMulCommClass M (N × P) (N × P) where
smul_comm c x y := by simp [smul_def, mul_def, mul_smul_comm]
instance isScalarTowerBoth [Mul N] [Mul P] [SMul M N] [SMul M P] [IsScalarTower M N N]
[IsScalarTower M P P] : IsScalarTower M (N × P) (N × P) where
smul_assoc c x y := by simp [smul_def, mul_def, smul_mul_assoc]
@[to_additive]
instance mulAction [Monoid M] [MulAction M α] [MulAction M β] : MulAction M (α × β) where
mul_smul _ _ _ := by ext <;> exact mul_smul ..
one_smul _ := by ext <;> exact one_smul ..
end Prod
/-! ### Scalar multiplication as a homomorphism -/
section BundledSMul
/-- Scalar multiplication as a multiplicative homomorphism. -/
@[simps]
def smulMulHom [Monoid α] [Mul β] [MulAction α β] [IsScalarTower α β β] [SMulCommClass α β β] :
α × β →ₙ* β where
toFun a := a.1 • a.2
map_mul' _ _ := (smul_mul_smul_comm _ _ _ _).symm
/-- Scalar multiplication as a monoid homomorphism. -/
@[simps]
def smulMonoidHom [Monoid α] [MulOneClass β] [MulAction α β] [IsScalarTower α β β]
[SMulCommClass α β β] : α × β →* β :=
{ smulMulHom with map_one' := one_smul _ _ }
end BundledSMul
section Action_by_Prod
variable (M N α) [Monoid M] [Monoid N]
/-- Construct a `MulAction` by a product monoid from `MulAction`s by the factors.
This is not an instance to avoid diamonds for example when `α := M × N`. -/
@[to_additive AddAction.prodOfVAddCommClass
/-- Construct an `AddAction` by a product monoid from `AddAction`s by the factors.
This is not an instance to avoid diamonds for example when `α := M × N`. -/]
abbrev MulAction.prodOfSMulCommClass [MulAction M α] [MulAction N α] [SMulCommClass M N α] :
MulAction (M × N) α where
smul mn a := mn.1 • mn.2 • a
one_smul a := (one_smul M _).trans (one_smul N a)
mul_smul x y a := by
change (x.1 * y.1) • (x.2 * y.2) • a = x.1 • x.2 • y.1 • y.2 • a
rw [mul_smul, mul_smul, smul_comm y.1 x.2]
/-- A `MulAction` by a product monoid is equivalent to commuting `MulAction`s by the factors. -/
@[to_additive AddAction.prodEquiv
/-- An `AddAction` by a product monoid is equivalent to commuting `AddAction`s by the factors. -/]
def MulAction.prodEquiv :
MulAction (M × N) α ≃ Σ' (_ : MulAction M α) (_ : MulAction N α), SMulCommClass M N α where
toFun _ :=
letI instM := MulAction.compHom α (.inl M N)
letI instN := MulAction.compHom α (.inr M N)
⟨instM, instN,
{ smul_comm := fun m n a ↦ by
change (m, (1 : N)) • ((1 : M), n) • a = ((1 : M), n) • (m, (1 : N)) • a
simp_rw [smul_smul, Prod.mk_mul_mk, mul_one, one_mul] }⟩
invFun _insts :=
letI := _insts.1; letI := _insts.2.1; have := _insts.2.2
MulAction.prodOfSMulCommClass M N α
left_inv := by
rintro ⟨-, hsmul⟩; dsimp only; ext ⟨m, n⟩ a
change (m, (1 : N)) • ((1 : M), n) • a = _
rw [← hsmul, Prod.mk_mul_mk, mul_one, one_mul]; rfl
right_inv := by
rintro ⟨hM, hN, -⟩
dsimp only; congr 1
· ext m a; (conv_rhs => rw [← hN.one_smul a]); rfl
congr 1
· funext; congr; ext m a; (conv_rhs => rw [← hN.one_smul a]); rfl
· ext n a; (conv_rhs => rw [← hM.one_smul (SMul.smul n a)]); rfl
· exact proof_irrel_heq ..
end Action_by_Prod |
.lake/packages/mathlib/Mathlib/Algebra/Group/Action/Pi.lean | import Mathlib.Algebra.Group.Action.Faithful
import Mathlib.Algebra.Group.Pi.Basic
import Mathlib.Data.Set.Piecewise
/-!
# Pi instances for multiplicative actions
This file defines instances for `MulAction` and related structures on `Pi` types.
## See also
* `Mathlib/Algebra/Group/Action/Option.lean`
* `Mathlib/Algebra/Group/Action/Prod.lean`
* `Mathlib/Algebra/Group/Action/Sigma.lean`
* `Mathlib/Algebra/Group/Action/Sum.lean`
-/
assert_not_exists MonoidWithZero
variable {ι M N : Type*} {α β γ : ι → Type*} (i : ι)
namespace Pi
@[to_additive]
instance smul' [∀ i, SMul (α i) (β i)] : SMul (∀ i, α i) (∀ i, β i) where smul s x i := s i • x i
@[to_additive]
lemma smul_def' [∀ i, SMul (α i) (β i)] (s : ∀ i, α i) (x : ∀ i, β i) : s • x = fun i ↦ s i • x i :=
rfl
@[to_additive (attr := simp)]
lemma smul_apply' [∀ i, SMul (α i) (β i)] (s : ∀ i, α i) (x : ∀ i, β i) : (s • x) i = s i • x i :=
rfl
@[to_additive]
instance isScalarTower [SMul M N] [∀ i, SMul N (α i)] [∀ i, SMul M (α i)]
[∀ i, IsScalarTower M N (α i)] : IsScalarTower M N (∀ i, α i) where
smul_assoc x y z := funext fun i ↦ smul_assoc x y (z i)
@[to_additive]
instance isScalarTower' [∀ i, SMul M (α i)] [∀ i, SMul (α i) (β i)] [∀ i, SMul M (β i)]
[∀ i, IsScalarTower M (α i) (β i)] : IsScalarTower M (∀ i, α i) (∀ i, β i) where
smul_assoc x y z := funext fun i ↦ smul_assoc x (y i) (z i)
@[to_additive]
instance isScalarTower'' [∀ i, SMul (α i) (β i)] [∀ i, SMul (β i) (γ i)] [∀ i, SMul (α i) (γ i)]
[∀ i, IsScalarTower (α i) (β i) (γ i)] : IsScalarTower (∀ i, α i) (∀ i, β i) (∀ i, γ i) where
smul_assoc x y z := funext fun i ↦ smul_assoc (x i) (y i) (z i)
@[to_additive]
instance smulCommClass [∀ i, SMul M (α i)] [∀ i, SMul N (α i)] [∀ i, SMulCommClass M N (α i)] :
SMulCommClass M N (∀ i, α i) where
smul_comm x y z := funext fun i ↦ smul_comm x y (z i)
@[to_additive]
instance smulCommClass' [∀ i, SMul M (β i)] [∀ i, SMul (α i) (β i)]
[∀ i, SMulCommClass M (α i) (β i)] : SMulCommClass M (∀ i, α i) (∀ i, β i) :=
⟨fun x y z => funext fun i ↦ smul_comm x (y i) (z i)⟩
@[to_additive]
instance smulCommClass'' [∀ i, SMul (β i) (γ i)] [∀ i, SMul (α i) (γ i)]
[∀ i, SMulCommClass (α i) (β i) (γ i)] : SMulCommClass (∀ i, α i) (∀ i, β i) (∀ i, γ i) where
smul_comm x y z := funext fun i ↦ smul_comm (x i) (y i) (z i)
@[to_additive]
instance isCentralScalar [∀ i, SMul M (α i)] [∀ i, SMul Mᵐᵒᵖ (α i)] [∀ i, IsCentralScalar M (α i)] :
IsCentralScalar M (∀ i, α i) where
op_smul_eq_smul _ _ := funext fun _ ↦ op_smul_eq_smul _ _
/-- If `α i` has a faithful scalar action for a given `i`, then so does `Π i, α i`. This is
not an instance as `i` cannot be inferred. -/
@[to_additive
/-- If `α i` has a faithful additive action for a given `i`, then
so does `Π i, α i`. This is not an instance as `i` cannot be inferred -/]
lemma faithfulSMul_at [∀ i, SMul M (α i)] [∀ i, Nonempty (α i)] (i : ι) [FaithfulSMul M (α i)] :
FaithfulSMul M (∀ i, α i) where
eq_of_smul_eq_smul h := eq_of_smul_eq_smul fun a : α i => by
classical
simpa using
congr_fun (h <| Function.update (fun j => Classical.choice (‹∀ i, Nonempty (α i)› j)) i a) i
@[to_additive]
instance faithfulSMul [Nonempty ι] [∀ i, SMul M (α i)] [∀ i, Nonempty (α i)]
[∀ i, FaithfulSMul M (α i)] : FaithfulSMul M (∀ i, α i) :=
let ⟨i⟩ := ‹Nonempty ι›
faithfulSMul_at i
@[to_additive]
instance mulAction (M) {m : Monoid M} [∀ i, MulAction M (α i)] : @MulAction M (∀ i, α i) m where
mul_smul _ _ _ := funext fun _ ↦ mul_smul _ _ _
one_smul _ := funext fun _ ↦ one_smul _ _
@[to_additive]
instance mulAction' {m : ∀ i, Monoid (α i)} [∀ i, MulAction (α i) (β i)] :
@MulAction (∀ i, α i) (∀ i, β i)
(@Pi.monoid ι α m) where
mul_smul _ _ _ := funext fun _ ↦ mul_smul _ _ _
one_smul _ := funext fun _ ↦ one_smul _ _
end Pi
namespace Function
/-- Non-dependent version of `Pi.smul`. Lean gets confused by the dependent instance if this
is not present. -/
@[to_additive
/-- Non-dependent version of `Pi.vadd`. Lean gets confused by the dependent instance
if this is not present. -/]
instance hasSMul {α : Type*} [SMul M α] : SMul M (ι → α) := Pi.instSMul
/-- Non-dependent version of `Pi.smulCommClass`. Lean gets confused by the dependent instance if
this is not present. -/
@[to_additive
/-- Non-dependent version of `Pi.vaddCommClass`. Lean gets confused by the dependent
instance if this is not present. -/]
instance smulCommClass {α : Type*} [SMul M α] [SMul N α] [SMulCommClass M N α] :
SMulCommClass M N (ι → α) := Pi.smulCommClass
@[to_additive]
lemma update_smul [∀ i, SMul M (α i)] [DecidableEq ι] (c : M) (f₁ : ∀ i, α i)
(i : ι) (x₁ : α i) : update (c • f₁) i (c • x₁) = c • update f₁ i x₁ :=
funext fun j => (apply_update (β := α) (fun _ ↦ (c • ·)) f₁ i x₁ j).symm
@[to_additive]
lemma extend_smul {M α β : Type*} [SMul M β] (r : M) (f : ι → α) (g : ι → β) (e : α → β) :
extend f (r • g) (r • e) = r • extend f g e := by
funext x
classical
simp only [extend_def, Pi.smul_apply]
split_ifs <;> rfl
end Function
namespace Set
@[to_additive]
lemma piecewise_smul [∀ i, SMul M (α i)] (s : Set ι) [∀ i, Decidable (i ∈ s)]
(c : M) (f₁ g₁ : ∀ i, α i) : s.piecewise (c • f₁) (c • g₁) = c • s.piecewise f₁ g₁ :=
s.piecewise_op (δ' := α) f₁ _ fun _ ↦ (c • ·)
end Set |
.lake/packages/mathlib/Mathlib/Algebra/Group/Action/Basic.lean | import Mathlib.Algebra.Group.Action.Units
import Mathlib.Algebra.Group.Invertible.Basic
import Mathlib.Algebra.Group.Pi.Basic
import Mathlib.Logic.Embedding.Basic
/-!
# More lemmas about group actions
This file contains lemmas about group actions that require more imports than
`Mathlib/Algebra/Group/Action/Defs.lean` offers.
-/
assert_not_exists MonoidWithZero Equiv.Perm.permGroup
variable {G M A B α β : Type*}
section MulAction
section Group
variable [Group α] [MulAction α β]
/-- Given an action of a group `α` on `β`, each `g : α` defines a permutation of `β`. -/
@[to_additive (attr := simps)]
def MulAction.toPerm (a : α) : Equiv.Perm β :=
⟨fun x => a • x, fun x => a⁻¹ • x, inv_smul_smul a, smul_inv_smul a⟩
/-- Given an action of an additive group `α` on `β`, each `g : α` defines a permutation of `β`. -/
add_decl_doc AddAction.toPerm
/-- `MulAction.toPerm` is injective on faithful actions. -/
@[to_additive /-- `AddAction.toPerm` is injective on faithful actions. -/]
lemma MulAction.toPerm_injective [FaithfulSMul α β] :
Function.Injective (MulAction.toPerm : α → Equiv.Perm β) :=
(show Function.Injective (Equiv.toFun ∘ MulAction.toPerm) from smul_left_injective').of_comp
@[to_additive]
protected lemma MulAction.bijective (g : α) : Function.Bijective (g • · : β → β) :=
(MulAction.toPerm g).bijective
@[to_additive]
protected lemma MulAction.injective (g : α) : Function.Injective (g • · : β → β) :=
(MulAction.bijective g).injective
@[to_additive]
protected lemma MulAction.surjective (g : α) : Function.Surjective (g • · : β → β) :=
(MulAction.bijective g).surjective
@[to_additive]
lemma smul_left_cancel (g : α) {x y : β} (h : g • x = g • y) : x = y := MulAction.injective g h
@[to_additive (attr := simp)]
lemma smul_left_cancel_iff (g : α) {x y : β} : g • x = g • y ↔ x = y :=
(MulAction.injective g).eq_iff
@[to_additive]
lemma smul_eq_iff_eq_inv_smul (g : α) {x y : β} : g • x = y ↔ x = g⁻¹ • y :=
(MulAction.toPerm g).apply_eq_iff_eq_symm_apply
@[to_additive]
lemma isCancelSMul_iff_eq_one_of_smul_eq :
IsCancelSMul α β ↔ (∀ (g : α) (x : β), g • x = x → g = 1) := by
refine ⟨fun H _ _ ↦ IsCancelSMul.eq_one_of_smul, fun H ↦ ⟨fun g h x ↦ ?_⟩⟩
rw [smul_eq_iff_eq_inv_smul, eq_comm, ← mul_smul, ← inv_mul_eq_one (G := α)]
exact H (g⁻¹ * h) x
end Group
section Monoid
variable [Monoid α] [MulAction α β] (c : α) (x y : β) [Invertible c]
@[simp] lemma invOf_smul_smul : ⅟c • c • x = x := inv_smul_smul (unitOfInvertible c) _
@[simp] lemma smul_invOf_smul : c • (⅟c • x) = x := smul_inv_smul (unitOfInvertible c) _
variable {c x y}
lemma invOf_smul_eq_iff : ⅟c • x = y ↔ x = c • y := inv_smul_eq_iff (g := unitOfInvertible c)
lemma smul_eq_iff_eq_invOf_smul : c • x = y ↔ x = ⅟c • y :=
smul_eq_iff_eq_inv_smul (g := unitOfInvertible c)
end Monoid
end MulAction
section Arrow
variable {G A B : Type*} [DivisionMonoid G] [MulAction G A]
/-- If `G` acts on `A`, then it acts also on `A → B`, by `(g • F) a = F (g⁻¹ • a)`. -/
@[to_additive (attr := simps) arrowAddAction
/-- If `G` acts on `A`, then it acts also on `A → B`, by `(g +ᵥ F) a = F (g⁻¹ +ᵥ a)` -/]
def arrowAction : MulAction G (A → B) where
smul g F a := F (g⁻¹ • a)
one_smul f := by
change (fun x => f ((1 : G)⁻¹ • x)) = f
simp only [inv_one, one_smul]
mul_smul x y f := by
change (fun a => f ((x*y)⁻¹ • a)) = (fun a => f (y⁻¹ • x⁻¹ • a))
simp only [mul_smul, mul_inv_rev]
attribute [local instance] arrowAction
variable [Monoid M]
/-- When `M` is a monoid, `ArrowAction` is additionally a `MulDistribMulAction`. -/
def arrowMulDistribMulAction : MulDistribMulAction G (A → M) where
smul_one _ := rfl
smul_mul _ _ _ := rfl
end Arrow
namespace IsUnit
variable [Monoid α] [MulAction α β]
@[to_additive]
theorem smul_bijective {m : α} (hm : IsUnit m) :
Function.Bijective (fun (a : β) ↦ m • a) := by
lift m to αˣ using hm
exact MulAction.bijective m
@[to_additive]
lemma smul_left_cancel {a : α} (ha : IsUnit a) {x y : β} : a • x = a • y ↔ x = y :=
let ⟨u, hu⟩ := ha
hu ▸ smul_left_cancel_iff u
end IsUnit
section SMul
variable [Group α] [Monoid β] [MulAction α β] [SMulCommClass α β β] [IsScalarTower α β β]
@[simp] lemma isUnit_smul_iff (g : α) (m : β) : IsUnit (g • m) ↔ IsUnit m :=
⟨fun h => inv_smul_smul g m ▸ h.smul g⁻¹, IsUnit.smul g⟩
end SMul
namespace MulAction
variable [Monoid M] [MulAction M α]
variable (M α) in
/-- Embedding of `α` into functions `M → α` induced by a multiplicative action of `M` on `α`. -/
@[to_additive
/-- Embedding of `α` into functions `M → α` induced by an additive action of `M` on `α`. -/]
def toFun : α ↪ M → α :=
⟨fun y x ↦ x • y, fun y₁ y₂ H ↦ one_smul M y₁ ▸ one_smul M y₂ ▸ by convert congr_fun H 1⟩
@[to_additive (attr := simp)]
lemma toFun_apply (x : M) (y : α) : MulAction.toFun M α y x = x • y := rfl
end MulAction
section MulDistribMulAction
variable [Monoid M] [Monoid A] [MulDistribMulAction M A]
/-- Pullback a multiplicative distributive multiplicative action along an injective monoid
homomorphism. -/
-- See note [reducible non-instances]
protected abbrev Function.Injective.mulDistribMulAction [Monoid B] [SMul M B] (f : B →* A)
(hf : Injective f) (smul : ∀ (c : M) (x), f (c • x) = c • f x) : MulDistribMulAction M B where
__ := hf.mulAction f smul
smul_mul c x y := hf <| by simp only [smul, f.map_mul, smul_mul']
smul_one c := hf <| by simp only [smul, f.map_one, smul_one]
/-- Pushforward a multiplicative distributive multiplicative action along a surjective monoid
homomorphism. -/
-- See note [reducible non-instances]
protected abbrev Function.Surjective.mulDistribMulAction [Monoid B] [SMul M B] (f : A →* B)
(hf : Surjective f) (smul : ∀ (c : M) (x), f (c • x) = c • f x) : MulDistribMulAction M B where
__ := hf.mulAction f smul
smul_mul c := by simp only [hf.forall, smul_mul', ← smul, ← f.map_mul, implies_true]
smul_one c := by rw [← f.map_one, ← smul, smul_one]
variable (A) in
/-- Scalar multiplication by `r` as a `MonoidHom`. -/
@[simps] def MulDistribMulAction.toMonoidHom (r : M) : A →* A where
toFun := (r • ·)
map_one' := smul_one r
map_mul' := smul_mul' r
@[simp] lemma smul_pow' (r : M) (x : A) (n : ℕ) : r • x ^ n = (r • x) ^ n :=
(MulDistribMulAction.toMonoidHom _ _).map_pow _ _
variable (M A) in
/-- Each element of the monoid defines a monoid homomorphism. -/
@[simps]
def MulDistribMulAction.toMonoidEnd : M →* Monoid.End A where
toFun := MulDistribMulAction.toMonoidHom A
map_one' := MonoidHom.ext <| one_smul M
map_mul' x y := MonoidHom.ext <| mul_smul x y
end MulDistribMulAction
section MulDistribMulAction
variable [Monoid M] [Group A] [MulDistribMulAction M A]
@[simp] lemma smul_inv' (r : M) (x : A) : r • x⁻¹ = (r • x)⁻¹ :=
(MulDistribMulAction.toMonoidHom A r).map_inv x
lemma smul_div' (r : M) (x y : A) : r • (x / y) = r • x / r • y :=
map_div (MulDistribMulAction.toMonoidHom A r) x y
lemma smul_zpow' (r : M) (x : A) (z : ℤ) : r • (x ^ z) = (r • x) ^ z :=
map_zpow (MulDistribMulAction.toMonoidHom A r) x z
end MulDistribMulAction |
.lake/packages/mathlib/Mathlib/Algebra/Group/Action/End.lean | import Mathlib.Algebra.Group.Action.Basic
import Mathlib.Algebra.Group.Action.Hom
import Mathlib.Algebra.Group.End
/-!
# Interaction between actions and endomorphisms/automorphisms
This file provides two things:
* The tautological actions by endomorphisms/automorphisms on their base type.
* An action by a monoid/group on a type is the same as a hom from the monoid/group to
endomorphisms/automorphisms of the type.
## Tags
monoid action, group action
-/
assert_not_exists MonoidWithZero
open Function (Injective Surjective)
variable {G M N A α : Type*}
/-! ### Tautological actions -/
/-! #### Tautological action by `Function.End` -/
namespace Function.End
/-- The tautological action by `Function.End α` on `α`.
This is generalized to bundled endomorphisms by:
* `Equiv.Perm.applyMulAction`
* `AddMonoid.End.applyDistribMulAction`
* `AddMonoid.End.applyModule`
* `AddAut.applyDistribMulAction`
* `MulAut.applyMulDistribMulAction`
* `LinearEquiv.applyDistribMulAction`
* `LinearMap.applyModule`
* `RingHom.applyMulSemiringAction`
* `RingAut.applyMulSemiringAction`
* `AlgEquiv.applyMulSemiringAction`
* `RelHom.applyMulAction`
* `RelEmbedding.applyMulAction`
* `RelIso.applyMulAction`
-/
instance applyMulAction : MulAction (Function.End α) α where
smul := (· <| ·)
one_smul _ := rfl
mul_smul _ _ _ := rfl
/-- The tautological additive action by `Additive (Function.End α)` on `α`. -/
instance applyAddAction : AddAction (Additive (Function.End α)) α := inferInstance
@[simp] lemma smul_def (f : Function.End α) (a : α) : f • a = f a := rfl
--TODO - This statement should be somethting like `toFun (f * g) = toFun f ∘ toFun g`
lemma mul_def (f g : Function.End α) : (f * g) = f ∘ g := rfl
--TODO - This statement should be somethting like `toFun 1 = id`
lemma one_def : (1 : Function.End α) = id := rfl
/-- `Function.End.applyMulAction` is faithful. -/
instance apply_FaithfulSMul : FaithfulSMul (Function.End α) α where eq_of_smul_eq_smul := funext
end Function.End
/-! #### Tautological action by `Equiv.Perm` -/
namespace Equiv.Perm
/-- The tautological action by `Equiv.Perm α` on `α`.
This generalizes `Function.End.applyMulAction`. -/
instance applyMulAction (α : Type*) : MulAction (Perm α) α where
smul f a := f a
one_smul _ := rfl
mul_smul _ _ _ := rfl
@[simp]
protected lemma smul_def {α : Type*} (f : Perm α) (a : α) : f • a = f a := rfl
/-- `Equiv.Perm.applyMulAction` is faithful. -/
instance applyFaithfulSMul (α : Type*) : FaithfulSMul (Perm α) α := ⟨Equiv.ext⟩
/-- The permutation group of `α` acts transitively on `α`. -/
instance : MulAction.IsPretransitive (Perm α) α := by
rw [MulAction.isPretransitive_iff]
classical
intro x y
use Equiv.swap x y
simp
end Equiv.Perm
/-! #### Tautological action by `MulAut` -/
namespace MulAut
variable [Monoid M]
/-- The tautological action by `MulAut M` on `M`. -/
instance applyMulAction : MulAction (MulAut M) M where
smul := (· <| ·)
one_smul _ := rfl
mul_smul _ _ _ := rfl
/-- The tautological action by `MulAut M` on `M`.
This generalizes `Function.End.applyMulAction`. -/
instance applyMulDistribMulAction : MulDistribMulAction (MulAut M) M where
smul := (· <| ·)
one_smul _ := rfl
mul_smul _ _ _ := rfl
smul_one := map_one
smul_mul := map_mul
@[simp] protected lemma smul_def (f : MulAut M) (a : M) : f • a = f a := rfl
/-- `MulAut.applyDistribMulAction` is faithful. -/
instance apply_faithfulSMul : FaithfulSMul (MulAut M) M where eq_of_smul_eq_smul := MulEquiv.ext
end MulAut
/-! #### Tautological action by `AddAut` -/
namespace AddAut
variable [AddMonoid M]
/-- The tautological action by `AddAut M` on `M`. -/
instance applyMulAction : MulAction (AddAut M) M where
smul := (· <| ·)
one_smul _ := rfl
mul_smul _ _ _ := rfl
@[simp] protected lemma smul_def (f : AddAut M) (a : M) : f • a = f a := rfl
/-- `AddAut.applyDistribMulAction` is faithful. -/
instance apply_faithfulSMul : FaithfulSMul (AddAut M) M where eq_of_smul_eq_smul := AddEquiv.ext
end AddAut
/-! ### Converting actions to and from homs to the monoid/group of endomorphisms/automorphisms -/
section Monoid
variable [Monoid M]
/-- The monoid hom representing a monoid action.
When `M` is a group, see `MulAction.toPermHom`. -/
def MulAction.toEndHom [MulAction M α] : M →* Function.End α where
toFun := (· • ·)
map_one' := funext (one_smul M)
map_mul' x y := funext (mul_smul x y)
/-- The monoid action induced by a monoid hom to `Function.End α`
See note [reducible non-instances]. -/
abbrev MulAction.ofEndHom (f : M →* Function.End α) : MulAction M α := .compHom α f
end Monoid
section AddMonoid
variable [AddMonoid M]
/-- The additive monoid hom representing an additive monoid action.
When `M` is a group, see `AddAction.toPermHom`. -/
def AddAction.toEndHom [AddAction M α] : M →+ Additive (Function.End α) :=
MulAction.toEndHom.toAdditiveRight
/-- The additive action induced by a hom to `Additive (Function.End α)`
See note [reducible non-instances]. -/
abbrev AddAction.ofEndHom (f : M →+ Additive (Function.End α)) : AddAction M α := .compHom α f
end AddMonoid
section Group
variable (G α) [Group G] [MulAction G α]
/-- Given an action of a group `G` on a set `α`, each `g : G` defines a permutation of `α`. -/
@[simps]
def MulAction.toPermHom : G →* Equiv.Perm α where
toFun := MulAction.toPerm
map_one' := Equiv.ext <| one_smul G
map_mul' u₁ u₂ := Equiv.ext <| mul_smul (u₁ : G) u₂
end Group
section AddGroup
variable (G α) [AddGroup G] [AddAction G α]
/-- Given an action of an additive group `G` on a set `α`, each `g : G` defines a permutation of
`α`. -/
@[simps!]
def AddAction.toPermHom : G →+ Additive (Equiv.Perm α) := (MulAction.toPermHom ..).toAdditiveRight
end AddGroup
section MulDistribMulAction
variable (M) [Group G] [Monoid M] [MulDistribMulAction G M]
/-- Each element of the group defines a multiplicative monoid isomorphism.
This is a stronger version of `MulAction.toPerm`. -/
@[simps +simpRhs]
def MulDistribMulAction.toMulEquiv (x : G) : M ≃* M :=
{ MulDistribMulAction.toMonoidHom M x, MulAction.toPermHom G M x with }
variable (G) in
/-- Each element of the group defines a multiplicative monoid isomorphism.
This is a stronger version of `MulAction.toPermHom`. -/
@[simps]
def MulDistribMulAction.toMulAut : G →* MulAut M where
toFun := MulDistribMulAction.toMulEquiv M
map_one' := MulEquiv.ext (one_smul _)
map_mul' _ _ := MulEquiv.ext (mul_smul _ _)
end MulDistribMulAction
section Arrow
variable [Group G] [MulAction G A] [Monoid M]
attribute [local instance] arrowMulDistribMulAction
/-- Given groups `G H` with `G` acting on `A`, `G` acts by
multiplicative automorphisms on `A → H`. -/
@[simps!] def mulAutArrow : G →* MulAut (A → M) := MulDistribMulAction.toMulAut _ _
end Arrow |
.lake/packages/mathlib/Mathlib/Algebra/Group/Action/Defs.lean | import Mathlib.Algebra.Group.Commute.Defs
import Mathlib.Algebra.Opposites
import Mathlib.Tactic.Spread
/-!
# Definitions of group actions
This file defines a hierarchy of group action type-classes on top of the previously defined
notation classes `SMul` and its additive version `VAdd`:
* `MulAction M α` and its additive version `AddAction G P` are typeclasses used for
actions of multiplicative and additive monoids and groups; they extend notation classes
`SMul` and `VAdd` that are defined in `Algebra.Group.Defs`;
* `DistribMulAction M A` is a typeclass for an action of a multiplicative monoid on
an additive monoid such that `a • (b + c) = a • b + a • c` and `a • 0 = 0`.
The hierarchy is extended further by `Module`, defined elsewhere.
Also provided are typeclasses regarding the interaction of different group actions,
* `SMulCommClass M N α` and its additive version `VAddCommClass M N α`;
* `IsScalarTower M N α` and its additive version `VAddAssocClass M N α`;
* `IsCentralScalar M α` and its additive version `IsCentralVAdd M N α`.
## Notation
- `a • b` is used as notation for `SMul.smul a b`.
- `a +ᵥ b` is used as notation for `VAdd.vadd a b`.
## Implementation details
This file should avoid depending on other parts of `GroupTheory`, to avoid import cycles.
More sophisticated lemmas belong in `GroupTheory.GroupAction`.
## Tags
group action
-/
assert_not_exists MonoidWithZero
open Function (Injective Surjective)
variable {M N G H α β γ δ : Type*}
attribute [to_additive Add.toVAdd /-- See also `AddMonoid.toAddAction` -/] instSMulOfMul
-- see Note [lower instance priority]
/-- See also `Monoid.toMulAction` and `MulZeroClass.toSMulWithZero`. -/
@[deprecated instSMulOfMul (since := "2025-10-18")]
def Mul.toSMul (α : Type*) [Mul α] : SMul α α := ⟨(· * ·)⟩
/-- Like `Mul.toSMul`, but multiplies on the right.
See also `Monoid.toOppositeMulAction` and `MonoidWithZero.toOppositeMulActionWithZero`. -/
@[to_additive /-- Like `Add.toVAdd`, but adds on the right.
See also `AddMonoid.toOppositeAddAction`. -/]
instance (priority := 910) Mul.toSMulMulOpposite (α : Type*) [Mul α] : SMul αᵐᵒᵖ α where
smul a b := b * a.unop
@[to_additive (attr := simp)]
lemma smul_eq_mul {α : Type*} [Mul α] (a b : α) : a • b = a * b := rfl
@[to_additive]
lemma op_smul_eq_mul {α : Type*} [Mul α] (a b : α) : MulOpposite.op a • b = b * a := rfl
@[to_additive (attr := simp)]
lemma MulOpposite.smul_eq_mul_unop [Mul α] (a : αᵐᵒᵖ) (b : α) : a • b = b * a.unop := rfl
/--
Type class for additive monoid actions on types, with notation `g +ᵥ p`.
The `AddAction G P` typeclass says that the additive monoid `G` acts additively on a type `P`.
More precisely this means that the action satisfies the two axioms `0 +ᵥ p = p` and
`(g₁ + g₂) +ᵥ p = g₁ +ᵥ (g₂ +ᵥ p)`. A mathematician might simply say that the additive monoid `G`
acts on `P`.
For example, if `A` is an additive group and `X` is a type, if a mathematician says
say "let `A` act on the set `X`" they will usually mean `[AddAction A X]`.
-/
class AddAction (G : Type*) (P : Type*) [AddMonoid G] extends VAdd G P where
/-- Zero is a neutral element for `+ᵥ` -/
protected zero_vadd : ∀ p : P, (0 : G) +ᵥ p = p
/-- Associativity of `+` and `+ᵥ` -/
add_vadd : ∀ (g₁ g₂ : G) (p : P), (g₁ + g₂) +ᵥ p = g₁ +ᵥ g₂ +ᵥ p
/--
Type class for monoid actions on types, with notation `g • p`.
The `MulAction G P` typeclass says that the monoid `G` acts multiplicatively on a type `P`.
More precisely this means that the action satisfies the two axioms `1 • p = p` and
`(g₁ * g₂) • p = g₁ • (g₂ • p)`. A mathematician might simply say that the monoid `G`
acts on `P`.
For example, if `G` is a group and `X` is a type, if a mathematician says
say "let `G` act on the set `X`" they will probably mean `[AddAction G X]`.
-/
@[to_additive (attr := ext)]
class MulAction (α : Type*) (β : Type*) [Monoid α] extends SMul α β where
/-- One is the neutral element for `•` -/
protected one_smul : ∀ b : β, (1 : α) • b = b
/-- Associativity of `•` and `*` -/
mul_smul : ∀ (x y : α) (b : β), (x * y) • b = x • y • b
/-! ### Scalar tower and commuting actions -/
/-- A typeclass mixin saying that two additive actions on the same space commute. -/
class VAddCommClass (M N α : Type*) [VAdd M α] [VAdd N α] : Prop where
/-- `+ᵥ` is left commutative -/
vadd_comm : ∀ (m : M) (n : N) (a : α), m +ᵥ (n +ᵥ a) = n +ᵥ (m +ᵥ a)
/-- A typeclass mixin saying that two multiplicative actions on the same space commute. -/
@[to_additive]
class SMulCommClass (M N α : Type*) [SMul M α] [SMul N α] : Prop where
/-- `•` is left commutative -/
smul_comm : ∀ (m : M) (n : N) (a : α), m • n • a = n • m • a
export MulAction (mul_smul)
export AddAction (add_vadd)
export SMulCommClass (smul_comm)
export VAddCommClass (vadd_comm)
library_note2 «bundled maps over different rings» /--
Frequently, we find ourselves wanting to express a bilinear map `M →ₗ[R] N →ₗ[R] P` or an
equivalence between maps `(M →ₗ[R] N) ≃ₗ[R] (M' →ₗ[R] N')` where the maps have an associated ring
`R`. Unfortunately, using definitions like these requires that `R` satisfy `CommSemiring R`, and
not just `Semiring R`. Using `M →ₗ[R] N →+ P` and `(M →ₗ[R] N) ≃+ (M' →ₗ[R] N')` avoids this
problem, but throws away structure that is useful for when we _do_ have a commutative (semi)ring.
To avoid making this compromise, we instead state these definitions as `M →ₗ[R] N →ₗ[S] P` or
`(M →ₗ[R] N) ≃ₗ[S] (M' →ₗ[R] N')` and require `SMulCommClass S R` on the appropriate modules. When
the caller has `CommSemiring R`, they can set `S = R` and `smulCommClass_self` will populate the
instance. If the caller only has `Semiring R` they can still set either `R = ℕ` or `S = ℕ`, and
`AddCommMonoid.nat_smulCommClass` or `AddCommMonoid.nat_smulCommClass'` will populate
the typeclass, which is still sufficient to recover a `≃+` or `→+` structure.
An example of where this is used is `LinearMap.prod_equiv`.
-/
/-- Commutativity of actions is a symmetric relation. This lemma can't be an instance because this
would cause a loop in the instance search graph. -/
@[to_additive]
lemma SMulCommClass.symm (M N α : Type*) [SMul M α] [SMul N α] [SMulCommClass M N α] :
SMulCommClass N M α where smul_comm a' a b := (smul_comm a a' b).symm
/-- Commutativity of additive actions is a symmetric relation. This lemma can't be an instance
because this would cause a loop in the instance search graph. -/
add_decl_doc VAddCommClass.symm
@[to_additive]
lemma Function.Injective.smulCommClass [SMul M α] [SMul N α] [SMul M β] [SMul N β]
[SMulCommClass M N β] {f : α → β} (hf : Injective f) (h₁ : ∀ (c : M) x, f (c • x) = c • f x)
(h₂ : ∀ (c : N) x, f (c • x) = c • f x) : SMulCommClass M N α where
smul_comm c₁ c₂ x := hf <| by simp only [h₁, h₂, smul_comm c₁ c₂ (f x)]
@[to_additive]
lemma Function.Surjective.smulCommClass [SMul M α] [SMul N α] [SMul M β] [SMul N β]
[SMulCommClass M N α] {f : α → β} (hf : Surjective f) (h₁ : ∀ (c : M) x, f (c • x) = c • f x)
(h₂ : ∀ (c : N) x, f (c • x) = c • f x) : SMulCommClass M N β where
smul_comm c₁ c₂ := hf.forall.2 fun x ↦ by simp only [← h₁, ← h₂, smul_comm c₁ c₂ x]
@[to_additive]
instance smulCommClass_self (M α : Type*) [CommMonoid M] [MulAction M α] : SMulCommClass M M α where
smul_comm a a' b := by rw [← mul_smul, mul_comm, mul_smul]
/-- An instance of `VAddAssocClass M N α` states that the additive action of `M` on `α` is
determined by the additive actions of `M` on `N` and `N` on `α`. -/
class VAddAssocClass (M N α : Type*) [VAdd M N] [VAdd N α] [VAdd M α] : Prop where
/-- Associativity of `+ᵥ` -/
vadd_assoc : ∀ (x : M) (y : N) (z : α), (x +ᵥ y) +ᵥ z = x +ᵥ y +ᵥ z
/-- An instance of `IsScalarTower M N α` states that the multiplicative
action of `M` on `α` is determined by the multiplicative actions of `M` on `N`
and `N` on `α`. -/
@[to_additive]
class IsScalarTower (M N α : Type*) [SMul M N] [SMul N α] [SMul M α] : Prop where
/-- Associativity of `•` -/
smul_assoc : ∀ (x : M) (y : N) (z : α), (x • y) • z = x • y • z
@[to_additive (attr := simp)]
lemma smul_assoc {M N} [SMul M N] [SMul N α] [SMul M α] [IsScalarTower M N α] (x : M) (y : N)
(z : α) : (x • y) • z = x • y • z := IsScalarTower.smul_assoc x y z
@[to_additive]
instance Semigroup.isScalarTower [Semigroup α] : IsScalarTower α α α := ⟨mul_assoc⟩
/-- An instance of `SMulDistribClass G R S` states that the multiplicative
action of `G` on `S` is determined by the multiplicative actions of `G` on `R`
and `R` on `S`.
This is similar to `IsScalarTower` except that the action of `G` distributes
over the action of `R` on `S`.
E.g. if `M/L/K` is a tower of galois extensions then `SMulDistribClass Gal(M/K) L M`. -/
class SMulDistribClass (G R S : Type*) [SMul G R] [SMul G S] [SMul R S] : Prop where
smul_distrib_smul (g : G) (r : R) (s : S) : g • r • s = (g • r) • (g • s)
export SMulDistribClass (smul_distrib_smul)
/-- A typeclass indicating that the right (aka `AddOpposite`) and left actions by `M` on `α` are
equal, that is that `M` acts centrally on `α`. This can be thought of as a version of commutativity
for `+ᵥ`. -/
class IsCentralVAdd (M α : Type*) [VAdd M α] [VAdd Mᵃᵒᵖ α] : Prop where
/-- The right and left actions of `M` on `α` are equal. -/
op_vadd_eq_vadd : ∀ (m : M) (a : α), AddOpposite.op m +ᵥ a = m +ᵥ a
/-- A typeclass indicating that the right (aka `MulOpposite`) and left actions by `M` on `α` are
equal, that is that `M` acts centrally on `α`. This can be thought of as a version of commutativity
for `•`. -/
@[to_additive]
class IsCentralScalar (M α : Type*) [SMul M α] [SMul Mᵐᵒᵖ α] : Prop where
/-- The right and left actions of `M` on `α` are equal. -/
op_smul_eq_smul : ∀ (m : M) (a : α), MulOpposite.op m • a = m • a
@[to_additive]
lemma IsCentralScalar.unop_smul_eq_smul {M α : Type*} [SMul M α] [SMul Mᵐᵒᵖ α]
[IsCentralScalar M α] (m : Mᵐᵒᵖ) (a : α) : MulOpposite.unop m • a = m • a := by
induction m; exact (IsCentralScalar.op_smul_eq_smul _ a).symm
export IsCentralVAdd (op_vadd_eq_vadd unop_vadd_eq_vadd)
export IsCentralScalar (op_smul_eq_smul unop_smul_eq_smul)
attribute [simp] IsCentralScalar.op_smul_eq_smul
-- these instances are very low priority, as there is usually a faster way to find these instances
@[to_additive]
instance (priority := 50) SMulCommClass.op_left [SMul M α] [SMul Mᵐᵒᵖ α] [IsCentralScalar M α]
[SMul N α] [SMulCommClass M N α] : SMulCommClass Mᵐᵒᵖ N α :=
⟨fun m n a ↦ by rw [← unop_smul_eq_smul m (n • a), ← unop_smul_eq_smul m a, smul_comm]⟩
@[to_additive]
instance (priority := 50) SMulCommClass.op_right [SMul M α] [SMul N α] [SMul Nᵐᵒᵖ α]
[IsCentralScalar N α] [SMulCommClass M N α] : SMulCommClass M Nᵐᵒᵖ α :=
⟨fun m n a ↦ by rw [← unop_smul_eq_smul n (m • a), ← unop_smul_eq_smul n a, smul_comm]⟩
@[to_additive]
instance (priority := 50) IsScalarTower.op_left [SMul M α] [SMul Mᵐᵒᵖ α] [IsCentralScalar M α]
[SMul M N] [SMul Mᵐᵒᵖ N] [IsCentralScalar M N] [SMul N α] [IsScalarTower M N α] :
IsScalarTower Mᵐᵒᵖ N α where
smul_assoc m n a := by rw [← unop_smul_eq_smul m (n • a), ← unop_smul_eq_smul m n, smul_assoc]
@[to_additive]
instance (priority := 50) IsScalarTower.op_right [SMul M α] [SMul M N] [SMul N α]
[SMul Nᵐᵒᵖ α] [IsCentralScalar N α] [IsScalarTower M N α] : IsScalarTower M Nᵐᵒᵖ α where
smul_assoc m n a := by
rw [← unop_smul_eq_smul n a, ← unop_smul_eq_smul (m • n) a, MulOpposite.unop_smul, smul_assoc]
namespace SMul
variable [SMul M α]
/-- Auxiliary definition for `SMul.comp`, `MulAction.compHom`,
`DistribMulAction.compHom`, `Module.compHom`, etc. -/
@[to_additive (attr := simp) /-- Auxiliary definition for `VAdd.comp`, `AddAction.compHom`, etc. -/]
def comp.smul (g : N → M) (n : N) (a : α) : α := g n • a
variable (α)
/-- An action of `M` on `α` and a function `N → M` induces an action of `N` on `α`. -/
-- See note [reducible non-instances]
-- Since this is reducible, we make sure to go via
-- `SMul.comp.smul` to prevent typeclass inference unfolding too far
@[to_additive /-- An additive action of `M` on `α` and a function `N → M` induces an additive
action of `N` on `α`. -/]
abbrev comp (g : N → M) : SMul N α where smul := SMul.comp.smul g
variable {α}
/-- Given a tower of scalar actions `M → α → β`, if we use `SMul.comp`
to pull back both of `M`'s actions by a map `g : N → M`, then we obtain a new
tower of scalar actions `N → α → β`.
This cannot be an instance because it can cause infinite loops whenever the `SMul` arguments
are still metavariables. -/
@[to_additive
/-- Given a tower of additive actions `M → α → β`, if we use `SMul.comp` to pull back both of
`M`'s actions by a map `g : N → M`, then we obtain a new tower of scalar actions `N → α → β`.
This cannot be an instance because it can cause infinite loops whenever the `SMul` arguments
are still metavariables. -/]
lemma comp.isScalarTower [SMul M β] [SMul α β] [IsScalarTower M α β] (g : N → M) : by
haveI := comp α g; haveI := comp β g; exact IsScalarTower N α β where
__ := comp α g
__ := comp β g
smul_assoc n := smul_assoc (g n)
/-- This cannot be an instance because it can cause infinite loops whenever the `SMul` arguments
are still metavariables. -/
@[to_additive
/-- This cannot be an instance because it can cause infinite loops whenever the `VAdd` arguments
are still metavariables. -/]
lemma comp.smulCommClass [SMul β α] [SMulCommClass M β α] (g : N → M) :
haveI := comp α g
SMulCommClass N β α where
__ := comp α g
smul_comm n := smul_comm (g n)
/-- This cannot be an instance because it can cause infinite loops whenever the `SMul` arguments
are still metavariables. -/
@[to_additive
/-- This cannot be an instance because it can cause infinite loops whenever the `VAdd` arguments
are still metavariables. -/]
lemma comp.smulCommClass' [SMul β α] [SMulCommClass β M α] (g : N → M) :
haveI := comp α g
SMulCommClass β N α where
__ := comp α g
smul_comm _ n := smul_comm _ (g n)
end SMul
section
/-- Note that the `SMulCommClass α β β` typeclass argument is usually satisfied by `Algebra α β`. -/
@[to_additive]
lemma mul_smul_comm [Mul β] [SMul α β] [SMulCommClass α β β] (s : α) (x y : β) :
x * s • y = s • (x * y) := (smul_comm s x y).symm
/-- Note that the `IsScalarTower α β β` typeclass argument is usually satisfied by `Algebra α β`. -/
@[to_additive]
lemma smul_mul_assoc [Mul β] [SMul α β] [IsScalarTower α β β] (r : α) (x y : β) :
r • x * y = r • (x * y) := smul_assoc r x y
/-- Note that the `IsScalarTower α β β` typeclass argument is usually satisfied by `Algebra α β`. -/
@[to_additive]
lemma smul_div_assoc [DivInvMonoid β] [SMul α β] [IsScalarTower α β β] (r : α) (x y : β) :
r • x / y = r • (x / y) := by simp [div_eq_mul_inv, smul_mul_assoc]
@[to_additive]
lemma smul_smul_smul_comm [SMul α β] [SMul α γ] [SMul β δ] [SMul α δ] [SMul γ δ]
[IsScalarTower α β δ] [IsScalarTower α γ δ] [SMulCommClass β γ δ] (a : α) (b : β) (c : γ)
(d : δ) : (a • b) • c • d = (a • c) • b • d := by rw [smul_assoc, smul_assoc, smul_comm b]
/-- Note that the `IsScalarTower α β β` and `SMulCommClass α β β` typeclass arguments are usually
satisfied by `Algebra α β`. -/
@[to_additive]
lemma smul_mul_smul_comm [Mul α] [Mul β] [SMul α β] [IsScalarTower α β β]
[IsScalarTower α α β] [SMulCommClass α β β] (a : α) (b : β) (c : α) (d : β) :
(a • b) * (c • d) = (a * c) • (b * d) := by
have : SMulCommClass β α β := .symm ..; exact smul_smul_smul_comm a b c d
@[to_additive]
alias smul_mul_smul := smul_mul_smul_comm
/-- Note that the `IsScalarTower α β β` and `SMulCommClass α β β` typeclass arguments are usually
satisfied by `Algebra α β`. -/
@[to_additive]
lemma mul_smul_mul_comm [Mul α] [Mul β] [SMul α β] [IsScalarTower α β β]
[IsScalarTower α α β] [SMulCommClass α β β] (a b : α) (c d : β) :
(a * b) • (c * d) = (a • c) * (b • d) := smul_smul_smul_comm a b c d
variable [SMul M α]
@[to_additive]
lemma Commute.smul_right [Mul α] [SMulCommClass M α α] [IsScalarTower M α α] {a b : α}
(h : Commute a b) (r : M) : Commute a (r • b) :=
(mul_smul_comm _ _ _).trans ((congr_arg _ h).trans <| (smul_mul_assoc _ _ _).symm)
@[to_additive]
lemma Commute.smul_left [Mul α] [SMulCommClass M α α] [IsScalarTower M α α] {a b : α}
(h : Commute a b) (r : M) : Commute (r • a) b := (h.symm.smul_right r).symm
end
section
variable [Monoid M] [MulAction M α] {a : M}
@[to_additive]
lemma smul_smul (a₁ a₂ : M) (b : α) : a₁ • a₂ • b = (a₁ * a₂) • b := (mul_smul _ _ _).symm
variable (M)
@[to_additive (attr := simp)]
lemma one_smul (b : α) : (1 : M) • b = b := MulAction.one_smul _
/-- `SMul` version of `one_mul_eq_id` -/
@[to_additive /-- `VAdd` version of `zero_add_eq_id` -/]
lemma one_smul_eq_id : (((1 : M) • ·) : α → α) = id := funext <| one_smul _
/-- `SMul` version of `comp_mul_left` -/
@[to_additive /-- `VAdd` version of `comp_add_left` -/]
lemma comp_smul_left (a₁ a₂ : M) : (a₁ • ·) ∘ (a₂ • ·) = (((a₁ * a₂) • ·) : α → α) :=
funext fun _ ↦ (mul_smul _ _ _).symm
variable {M}
@[to_additive (attr := simp)]
theorem smul_iterate (a : M) : ∀ n : ℕ, (a • · : α → α)^[n] = (a ^ n • ·)
| 0 => by simp [funext_iff]
| n + 1 => by ext; simp [smul_iterate, pow_succ, smul_smul]
@[to_additive]
lemma smul_iterate_apply (a : M) (n : ℕ) (x : α) : (a • ·)^[n] x = a ^ n • x := by
rw [smul_iterate]
/-- Pullback a multiplicative action along an injective map respecting `•`.
See note [reducible non-instances]. -/
@[to_additive
/-- Pullback an additive action along an injective map respecting `+ᵥ`. -/]
protected abbrev Function.Injective.mulAction [SMul M β] (f : β → α) (hf : Injective f)
(smul : ∀ (c : M) (x), f (c • x) = c • f x) : MulAction M β where
one_smul x := hf <| (smul _ _).trans <| one_smul _ (f x)
mul_smul c₁ c₂ x := hf <| by simp only [smul, mul_smul]
/-- Pushforward a multiplicative action along a surjective map respecting `•`.
See note [reducible non-instances]. -/
@[to_additive
/-- Pushforward an additive action along a surjective map respecting `+ᵥ`. -/]
protected abbrev Function.Surjective.mulAction [SMul M β] (f : α → β) (hf : Surjective f)
(smul : ∀ (c : M) (x), f (c • x) = c • f x) : MulAction M β where
one_smul := by simp [hf.forall, ← smul]
mul_smul := by simp [hf.forall, ← smul, mul_smul]
section
variable (M)
/-- The regular action of a monoid on itself by left multiplication.
This is promoted to a module by `Semiring.toModule`. -/
-- see Note [lower instance priority]
@[to_additive
/-- The regular action of a monoid on itself by left addition.
This is promoted to an `AddTorsor` by `addGroup_is_addTorsor`. -/]
instance (priority := 910) Monoid.toMulAction : MulAction M M where
smul := (· * ·)
one_smul := one_mul
mul_smul := mul_assoc
@[to_additive]
instance IsScalarTower.left : IsScalarTower M M α where
smul_assoc x y z := mul_smul x y z
variable {M}
section Monoid
variable [Monoid N] [MulAction M N] [IsScalarTower M N N] [SMulCommClass M N N]
lemma smul_pow (r : M) (x : N) : ∀ n, (r • x) ^ n = r ^ n • x ^ n
| 0 => by simp
| n + 1 => by rw [pow_succ', smul_pow _ _ n, smul_mul_smul_comm, ← pow_succ', ← pow_succ']
end Monoid
section Group
variable [Group G] [MulAction G α] {g : G} {a b : α}
@[to_additive (attr := simp)]
lemma inv_smul_smul (g : G) (a : α) : g⁻¹ • g • a = a := by rw [smul_smul, inv_mul_cancel, one_smul]
@[to_additive (attr := simp)]
lemma smul_inv_smul (g : G) (a : α) : g • g⁻¹ • a = a := by rw [smul_smul, mul_inv_cancel, one_smul]
@[to_additive] lemma inv_smul_eq_iff : g⁻¹ • a = b ↔ a = g • b :=
⟨fun h ↦ by rw [← h, smul_inv_smul], fun h ↦ by rw [h, inv_smul_smul]⟩
@[to_additive] lemma eq_inv_smul_iff : a = g⁻¹ • b ↔ g • a = b :=
⟨fun h ↦ by rw [h, smul_inv_smul], fun h ↦ by rw [← h, inv_smul_smul]⟩
section Mul
variable [Mul H] [MulAction G H] [SMulCommClass G H H] [IsScalarTower G H H] {a b : H}
@[simp] lemma Commute.smul_right_iff : Commute a (g • b) ↔ Commute a b :=
⟨fun h ↦ inv_smul_smul g b ▸ h.smul_right g⁻¹, fun h ↦ h.smul_right g⟩
@[simp] lemma Commute.smul_left_iff : Commute (g • a) b ↔ Commute a b := by
rw [Commute.symm_iff, Commute.smul_right_iff, Commute.symm_iff]
end Mul
variable [Group H] [MulAction G H] [SMulCommClass G H H] [IsScalarTower G H H]
lemma smul_inv (g : G) (a : H) : (g • a)⁻¹ = g⁻¹ • a⁻¹ :=
inv_eq_of_mul_eq_one_right <| by rw [smul_mul_smul_comm, mul_inv_cancel, mul_inv_cancel, one_smul]
lemma smul_zpow (g : G) (a : H) (n : ℤ) : (g • a) ^ n = g ^ n • a ^ n := by
cases n <;> simp [smul_pow, smul_inv]
end Group
end
lemma SMulCommClass.of_commMonoid
(A B G : Type*) [CommMonoid G] [SMul A G] [SMul B G]
[IsScalarTower A G G] [IsScalarTower B G G] :
SMulCommClass A B G where
smul_comm r s x := by
rw [← one_smul G (s • x), ← smul_assoc, ← one_smul G x, ← smul_assoc s 1 x,
smul_comm, smul_assoc, one_smul, smul_assoc, one_smul]
lemma IsScalarTower.of_commMonoid (R₁ R : Type*)
[Monoid R₁] [CommMonoid R] [MulAction R₁ R] [SMulCommClass R₁ R R] : IsScalarTower R₁ R R where
smul_assoc x₁ y z := by rw [smul_eq_mul, mul_comm, ← smul_eq_mul, ← smul_comm, smul_eq_mul,
mul_comm, ← smul_eq_mul]
lemma isScalarTower_iff_smulCommClass_of_commMonoid (R₁ R : Type*)
[Monoid R₁] [CommMonoid R] [MulAction R₁ R] :
SMulCommClass R₁ R R ↔ IsScalarTower R₁ R R :=
⟨fun _ ↦ IsScalarTower.of_commMonoid R₁ R, fun _ ↦ SMulCommClass.of_commMonoid R₁ R R⟩
end
section CompatibleScalar
@[to_additive]
lemma smul_one_smul {M} (N) [Monoid N] [SMul M N] [MulAction N α] [SMul M α]
[IsScalarTower M N α] (x : M) (y : α) : (x • (1 : N)) • y = x • y := by
rw [smul_assoc, one_smul]
@[to_additive (attr := simp)]
lemma smul_one_mul {M N} [MulOneClass N] [SMul M N] [IsScalarTower M N N] (x : M) (y : N) :
x • (1 : N) * y = x • y := by rw [smul_mul_assoc, one_mul]
@[to_additive (attr := simp)]
lemma mul_smul_one {M N} [MulOneClass N] [SMul M N] [SMulCommClass M N N] (x : M) (y : N) :
y * x • (1 : N) = x • y := by rw [← smul_eq_mul, ← smul_comm, smul_eq_mul, mul_one]
@[to_additive]
lemma IsScalarTower.of_smul_one_mul {M N} [Monoid N] [SMul M N]
(h : ∀ (x : M) (y : N), x • (1 : N) * y = x • y) : IsScalarTower M N N :=
⟨fun x y z ↦ by rw [← h, smul_eq_mul, mul_assoc, h, smul_eq_mul]⟩
@[to_additive]
lemma SMulCommClass.of_mul_smul_one {M N} [Monoid N] [SMul M N]
(H : ∀ (x : M) (y : N), y * x • (1 : N) = x • y) : SMulCommClass M N N :=
⟨fun x y z ↦ by rw [← H x z, smul_eq_mul, ← H, smul_eq_mul, mul_assoc]⟩
/--
Let `Q / P / N / M` be a tower. If `P / N / M`, `Q / P / M` and `Q / P / N` are
scalar towers, then `Q / N / M` is also a scalar tower.
-/
@[to_additive] lemma IsScalarTower.to₁₂₄ (M N P Q)
[SMul M N] [SMul M P] [SMul M Q] [SMul N P] [SMul N Q] [Monoid P] [MulAction P Q]
[IsScalarTower M N P] [IsScalarTower M P Q] [IsScalarTower N P Q] : IsScalarTower M N Q where
smul_assoc m n q := by rw [← smul_one_smul P, smul_assoc m, smul_assoc, smul_one_smul]
/--
Let `Q / P / N / M` be a tower. If `P / N / M`, `Q / N / M` and `Q / P / N` are
scalar towers, then `Q / P / M` is also a scalar tower.
-/
@[to_additive] lemma IsScalarTower.to₁₃₄ (M N P Q)
[SMul M N] [SMul M P] [SMul M Q] [SMul P Q] [Monoid N] [MulAction N P] [MulAction N Q]
[IsScalarTower M N P] [IsScalarTower M N Q] [IsScalarTower N P Q] : IsScalarTower M P Q where
smul_assoc m p q := by rw [← smul_one_smul N m, smul_assoc, smul_one_smul]
/--
Let `Q / P / N / M` be a tower. If `P / N / M`, `Q / N / M` and `Q / P / M` are
scalar towers, then `Q / P / N` is also a scalar tower.
-/
@[to_additive] lemma IsScalarTower.to₂₃₄ (M N P Q)
[SMul M N] [SMul M P] [SMul M Q] [SMul P Q] [Monoid N] [MulAction N P] [MulAction N Q]
[IsScalarTower M N P] [IsScalarTower M N Q] [IsScalarTower M P Q]
(h : Function.Surjective fun m : M ↦ m • (1 : N)) : IsScalarTower N P Q where
smul_assoc n p q := by obtain ⟨m, rfl⟩ := h n; simp_rw [smul_one_smul, smul_assoc]
end CompatibleScalar
/-- Typeclass for multiplicative actions on multiplicative structures.
The key axiom here is `smul_mul : g • (x * y) = (g • x) * (g • y)`.
If `G` is a group (with group law multiplication) and `Γ` is its automorphism
group then there is a natural instance of `MulDistribMulAction Γ G`.
The axiom is also satisfied by a Galois group $Gal(L/K)$ acting on the field `L`,
but here you can use the even stronger class `MulSemiringAction`, which captures
how the action plays with both multiplication and addition. -/
@[ext]
class MulDistribMulAction (M N : Type*) [Monoid M] [Monoid N] extends MulAction M N where
/-- Distributivity of `•` across `*` -/
smul_mul : ∀ (r : M) (x y : N), r • (x * y) = r • x * r • y
/-- Multiplying `1` by a scalar gives `1` -/
smul_one : ∀ r : M, r • (1 : N) = 1
export MulDistribMulAction (smul_one)
section MulDistribMulAction
variable [Monoid M] [Monoid N] [MulDistribMulAction M N]
lemma smul_mul' (a : M) (b₁ b₂ : N) : a • (b₁ * b₂) = a • b₁ * a • b₂ :=
MulDistribMulAction.smul_mul ..
end MulDistribMulAction
section IsCancelSMul
variable (G P : Type*)
/-- A vector addition is left-cancellative if it is pointwise injective on the left. -/
class IsLeftCancelVAdd [VAdd G P] : Prop where
protected left_cancel' : ∀ (a : G) (b c : P), a +ᵥ b = a +ᵥ c → b = c
/-- A scalar multiplication is left-cancellative if it is pointwise injective on the left. -/
@[to_additive]
class IsLeftCancelSMul [SMul G P] : Prop where
protected left_cancel' : ∀ (a : G) (b c : P), a • b = a • c → b = c
@[to_additive]
lemma IsLeftCancelSMul.left_cancel {G P} [SMul G P] [IsLeftCancelSMul G P] (a : G) (b c : P) :
a • b = a • c → b = c := IsLeftCancelSMul.left_cancel' a b c
@[to_additive]
instance [LeftCancelMonoid G] : IsLeftCancelSMul G G where
left_cancel' := IsLeftCancelMul.mul_left_cancel
/-- A vector addition is cancellative if it is pointwise injective on the left and right.
A group action is cancellative in this sense if and only if it is **free**.
See `isCancelVAdd_iff_eq_zero_of_vadd_eq` for a more familiar condition. -/
class IsCancelVAdd [VAdd G P] : Prop extends IsLeftCancelVAdd G P where
protected right_cancel' : ∀ (a b : G) (c : P), a +ᵥ c = b +ᵥ c → a = b
/-- A scalar multiplication is cancellative if it is pointwise injective on the left and right.
A group action is cancellative in this sense if and only if it is **free**.
See `isCancelSMul_iff_eq_one_of_smul_eq` for a more familiar condition. -/
@[to_additive]
class IsCancelSMul [SMul G P] : Prop extends IsLeftCancelSMul G P where
protected right_cancel' : ∀ (a b : G) (c : P), a • c = b • c → a = b
@[to_additive]
lemma IsCancelSMul.left_cancel {G P} [SMul G P] [IsCancelSMul G P] (a : G) (b c : P) :
a • b = a • c → b = c := IsLeftCancelSMul.left_cancel' a b c
@[to_additive]
lemma IsCancelSMul.right_cancel {G P} [SMul G P] [IsCancelSMul G P] (a b : G) (c : P) :
a • c = b • c → a = b := IsCancelSMul.right_cancel' a b c
@[to_additive]
lemma IsCancelSMul.eq_one_of_smul {G P} [Monoid G] [MulAction G P] [IsCancelSMul G P] {g : G}
{x : P} (h : g • x = x) : g = 1 :=
IsCancelSMul.right_cancel g 1 x ((one_smul G x).symm ▸ h)
@[to_additive]
instance [CancelMonoid G] : IsCancelSMul G G where
left_cancel' := IsLeftCancelMul.mul_left_cancel
right_cancel' _ _ _ := mul_right_cancel
@[to_additive]
instance [Group G] [MulAction G P] : IsLeftCancelSMul G P where
left_cancel' a b c h := by rw [← inv_smul_smul a b, h, inv_smul_smul]
end IsCancelSMul |
.lake/packages/mathlib/Mathlib/Algebra/Group/Action/Equidecomp.lean | import Mathlib.Algebra.Group.Action.Defs
import Mathlib.Logic.Equiv.PartialEquiv
import Mathlib.Algebra.Group.Pointwise.Finset.Basic
/-!
# Equidecompositions
This file develops the basic theory of equidecompositions.
## Main Definitions
Let `G` be a group acting on a space `X`, and `A B : Set X`.
An *equidecomposition* of `A` and `B` is typically defined as a finite partition of `A` together
with a finite list of elements of `G` of the same size such that applying each element to the
matching piece of the partition yields a partition of `B`.
This yields a bijection `f : A ≃ B` where, given `a : A`, `f a = γ • a` for `γ : G` the group
element for `a`'s piece of the partition. Reversing this is easy, and so we get an equivalent
(up to the choice of group elements) definition: an *Equidecomposition* of `A` and `B` is a
bijection `f : A ≃ B` such that for some `S : Finset G`, `f a ∈ S • a` for all `a`.
We take this as our definition as it is easier to work with. It is implemented as an element
`PartialEquiv X X` with source `A` and target `B`.
## Implementation Notes
* Equidecompositions are implemented as elements of `PartialEquiv X X` together with a
`Finset` of elements of the acting group and a proof that every point in the source is moved
by an element in the finset.
* The requirement that `G` be a group is relaxed where possible.
* We introduce a non-standard predicate, `IsDecompOn`, to state that a function satisfies the main
combinatorial property of equidecompositions, even if it is not injective or surjective.
## TODO
* Prove that if two sets equidecompose into subsets of each other, they are equidecomposable
(Schroeder-Bernstein type theorem)
* Define equidecomposability into subsets as a preorder on sets and
prove that its induced equivalence relation is equidecomposability.
* Prove the definition of equidecomposition used here is equivalent to the more familiar one
using partitions.
-/
variable {X G : Type*} {A B C : Set X}
open Function Set Pointwise PartialEquiv
namespace Equidecomp
section SMul
variable [SMul G X]
/-- Let `G` act on a space `X` and `A : Set X`. We say `f : X → X` is a decomposition on `A`
as witnessed by some `S : Finset G` if for all `a ∈ A`, the value `f a` can be obtained
by applying some element of `S` to `a` instead.
More familiarly, the restriction of `f` to `A` is the result of partitioning `A` into finitely many
pieces, then applying a single element of `G` to each piece. -/
def IsDecompOn (f : X → X) (A : Set X) (S : Finset G) : Prop := ∀ a ∈ A, ∃ g ∈ S, f a = g • a
variable (X G)
/-- Let `G` act on a space `X`. An `Equidecomposition` with respect to `X` and `G` is a partial
bijection `f : PartialEquiv X X` with the property that for some set `elements : Finset G`,
(which we record), for each `a ∈ f.source`, `f a` can be obtained by applying some `g ∈ elements`
instead. We call `f` an equidecomposition of `f.source` with `f.target`.
More familiarly, `f` is the result of partitioning `f.source` into finitely many pieces,
then applying a single element of `G` to each to get a partition of `f.target`.
-/
structure _root_.Equidecomp extends PartialEquiv X X where
isDecompOn' : ∃ S : Finset G, IsDecompOn toFun source S
variable {X G}
/-- Note that `Equidecomp X G` is not `FunLike`. -/
instance : CoeFun (Equidecomp X G) fun _ => X → X := ⟨fun f => f.toFun⟩
/-- A finite set of group elements witnessing that `f` is an equidecomposition. -/
noncomputable
def witness (f : Equidecomp X G) : Finset G := f.isDecompOn'.choose
theorem isDecompOn (f : Equidecomp X G) : IsDecompOn f f.source f.witness :=
f.isDecompOn'.choose_spec
theorem apply_mem_target {f : Equidecomp X G} {x : X} (h : x ∈ f.source) :
f x ∈ f.target := by simp [h]
theorem toPartialEquiv_injective : Injective <| toPartialEquiv (X := X) (G := G) := by
intro ⟨_, _, _⟩ _ _
congr
theorem IsDecompOn.mono {f f' : X → X} {A A' : Set X} {S : Finset G} (h : IsDecompOn f A S)
(hA' : A' ⊆ A) (hf' : EqOn f f' A') : IsDecompOn f' A' S := by
intro a ha
rw [← hf' ha]
exact h a (hA' ha)
/-- The restriction of an equidecomposition as an equidecomposition. -/
@[simps!]
def restr (f : Equidecomp X G) (A : Set X) : Equidecomp X G where
toPartialEquiv := f.toPartialEquiv.restr A
isDecompOn' := ⟨f.witness,
f.isDecompOn.mono (source_restr_subset_source _ _) fun _ ↦ congrFun rfl⟩
@[simp]
theorem toPartialEquiv_restr (f : Equidecomp X G) (A : Set X) :
(f.restr A).toPartialEquiv = f.toPartialEquiv.restr A := rfl
theorem source_restr (f : Equidecomp X G) {A : Set X} (hA : A ⊆ f.source) :
(f.restr A).source = A := by rw [restr_source, inter_eq_self_of_subset_right hA]
theorem restr_of_source_subset {f : Equidecomp X G} {A : Set X} (hA : f.source ⊆ A) :
f.restr A = f := by
apply toPartialEquiv_injective
rw [toPartialEquiv_restr, PartialEquiv.restr_eq_of_source_subset hA]
@[simp]
theorem restr_univ (f : Equidecomp X G) : f.restr univ = f :=
restr_of_source_subset <| subset_univ _
end SMul
section Monoid
variable [Monoid G] [MulAction G X]
variable (X G)
/-- The identity function is an equidecomposition of the space with itself. -/
@[simps toPartialEquiv]
def refl : Equidecomp X G where
toPartialEquiv := .refl _
isDecompOn' := ⟨{1}, by simp [IsDecompOn]⟩
variable {X} {G}
open scoped Classical in
theorem IsDecompOn.comp' {g f : X → X} {B A : Set X} {T S : Finset G}
(hg : IsDecompOn g B T) (hf : IsDecompOn f A S) :
IsDecompOn (g ∘ f) (A ∩ f ⁻¹' B) (T * S) := by
intro _ ⟨aA, aB⟩
rcases hf _ aA with ⟨γ, γ_mem, hγ⟩
rcases hg _ aB with ⟨δ, δ_mem, hδ⟩
use δ * γ, Finset.mul_mem_mul δ_mem γ_mem
rwa [mul_smul, ← hγ]
open scoped Classical in
theorem IsDecompOn.comp {g f : X → X} {B A : Set X} {T S : Finset G}
(hg : IsDecompOn g B T) (hf : IsDecompOn f A S) (h : MapsTo f A B) :
IsDecompOn (g ∘ f) A (T * S) := by
rw [left_eq_inter.mpr h]
exact hg.comp' hf
/-- The composition of two equidecompositions as an equidecomposition. -/
@[simps toPartialEquiv, trans]
noncomputable def trans (f g : Equidecomp X G) : Equidecomp X G where
toPartialEquiv := f.toPartialEquiv.trans g.toPartialEquiv
isDecompOn' := by classical exact ⟨g.witness * f.witness, g.isDecompOn.comp' f.isDecompOn⟩
end Monoid
section Group
variable [Group G] [MulAction G X]
open scoped Classical in
theorem IsDecompOn.of_leftInvOn {f g : X → X} {A : Set X} {S : Finset G}
(hf : IsDecompOn f A S) (h : LeftInvOn g f A) : IsDecompOn g (f '' A) S⁻¹ := by
rintro _ ⟨a, ha, rfl⟩
rcases hf a ha with ⟨γ, γ_mem, hγ⟩
use γ⁻¹, Finset.inv_mem_inv γ_mem
rw [hγ, inv_smul_smul, ← hγ, h ha]
/-- The inverse function of an equidecomposition as an equidecomposition. -/
@[symm, simps toPartialEquiv]
noncomputable def symm (f : Equidecomp X G) : Equidecomp X G where
toPartialEquiv := f.toPartialEquiv.symm
isDecompOn' := by classical exact ⟨f.witness⁻¹, by
convert f.isDecompOn.of_leftInvOn f.leftInvOn
rw [image_source_eq_target, symm_source]⟩
theorem map_target {f : Equidecomp X G} {x : X} (h : x ∈ f.target) :
f.symm x ∈ f.source := f.toPartialEquiv.map_target h
theorem left_inv {f : Equidecomp X G} {x : X} (h : x ∈ f.source) :
f.toPartialEquiv.symm (f x) = x := by simp [h]
theorem right_inv {f : Equidecomp X G} {x : X} (h : x ∈ f.target) :
f (f.toPartialEquiv.symm x) = x := by simp [h]
@[simp]
theorem symm_symm (f : Equidecomp X G) : f.symm.symm = f := rfl
theorem symm_involutive : Function.Involutive (symm : Equidecomp X G → _) := symm_symm
theorem symm_bijective : Function.Bijective (symm : Equidecomp X G → _) := symm_involutive.bijective
@[simp]
theorem refl_symm : (refl X G).symm = refl X G := rfl
@[simp]
theorem restr_refl_symm (A : Set X) :
((Equidecomp.refl X G).restr A).symm = (Equidecomp.refl X G).restr A := rfl
end Group
end Equidecomp |
.lake/packages/mathlib/Mathlib/Algebra/Group/Action/Pretransitive.lean | import Mathlib.Algebra.Group.Action.TypeTags
/-!
# Pretransitive group actions
This file defines a typeclass for pretransitive group actions.
## Notation
- `a • b` is used as notation for `SMul.smul a b`.
- `a +ᵥ b` is used as notation for `VAdd.vadd a b`.
## Implementation details
This file should avoid depending on other parts of `GroupTheory`, to avoid import cycles.
More sophisticated lemmas belong in `GroupTheory.GroupAction`.
## Tags
group action
-/
assert_not_exists MonoidWithZero
open Function (Injective Surjective)
variable {M G α β : Type*}
/-!
### (Pre)transitive action
`M` acts pretransitively on `α` if for any `x y` there is `g` such that `g • x = y` (or `g +ᵥ x = y`
for an additive action). A transitive action should furthermore have `α` nonempty.
In this section we define typeclasses `MulAction.IsPretransitive` and
`AddAction.IsPretransitive` and provide `MulAction.exists_smul_eq`/`AddAction.exists_vadd_eq`,
`MulAction.surjective_smul`/`AddAction.surjective_vadd` as public interface to access this
property. We do not provide typeclasses `*Action.IsTransitive`; users should assume
`[MulAction.IsPretransitive M α] [Nonempty α]` instead.
-/
/-- `M` acts pretransitively on `α` if for any `x y` there is `g` such that `g +ᵥ x = y`.
A transitive action should furthermore have `α` nonempty. -/
class AddAction.IsPretransitive (M α : Type*) [VAdd M α] : Prop where
/-- There is `g` such that `g +ᵥ x = y`. -/
exists_vadd_eq : ∀ x y : α, ∃ g : M, g +ᵥ x = y
/-- `M` acts pretransitively on `α` if for any `x y` there is `g` such that `g • x = y`.
A transitive action should furthermore have `α` nonempty. -/
@[to_additive (attr := mk_iff)]
class MulAction.IsPretransitive (M α : Type*) [SMul M α] : Prop where
/-- There is `g` such that `g • x = y`. -/
exists_smul_eq : ∀ x y : α, ∃ g : M, g • x = y
@[to_additive]
instance MulAction.instIsPretransitiveOfSubsingleton
{M α : Type*} [Monoid M] [MulAction M α] [Subsingleton α] :
MulAction.IsPretransitive M α where
exists_smul_eq x y := ⟨1, by
simp only [one_smul, Subsingleton.elim x y] ⟩
namespace MulAction
variable (M) [SMul M α] [IsPretransitive M α]
@[to_additive]
lemma exists_smul_eq (x y : α) : ∃ m : M, m • x = y := IsPretransitive.exists_smul_eq x y
@[to_additive]
lemma surjective_smul (x : α) : Surjective fun c : M ↦ c • x := exists_smul_eq M x
/-- The left regular action of a group on itself is transitive. -/
@[to_additive /-- The regular action of a group on itself is transitive. -/]
instance Regular.isPretransitive [Group G] : IsPretransitive G G :=
⟨fun x y ↦ ⟨y * x⁻¹, inv_mul_cancel_right _ _⟩⟩
/-- The right regular action of a group on itself is transitive. -/
@[to_additive /-- The right regular action of an additive group on itself is transitive. -/]
instance Regular.isPretransitive_mulOpposite [Group G] : IsPretransitive Gᵐᵒᵖ G :=
⟨fun x y ↦ ⟨.op (x⁻¹ * y), mul_inv_cancel_left _ _⟩⟩
end MulAction
namespace MulAction
@[to_additive]
lemma IsPretransitive.of_smul_eq {M N α : Type*} [SMul M α] [SMul N α] [IsPretransitive M α]
(f : M → N) (hf : ∀ {c : M} {x : α}, f c • x = c • x) : IsPretransitive N α where
exists_smul_eq x y := (exists_smul_eq x y).elim fun m h ↦ ⟨f m, hf.trans h⟩
end MulAction
section CompatibleScalar
@[to_additive]
lemma MulAction.IsPretransitive.of_isScalarTower (M : Type*) {N α : Type*} [Monoid N] [SMul M N]
[MulAction N α] [SMul M α] [IsScalarTower M N α] [IsPretransitive M α] : IsPretransitive N α :=
of_smul_eq (fun x : M ↦ x • 1) (smul_one_smul N _ _)
end CompatibleScalar
/-! ### `Additive`, `Multiplicative` -/
section
open Additive Multiplicative
instance Additive.addAction_isPretransitive [Monoid α] [MulAction α β]
[MulAction.IsPretransitive α β] : AddAction.IsPretransitive (Additive α) β :=
⟨@MulAction.exists_smul_eq α _ _ _⟩
instance Multiplicative.mulAction_isPretransitive [AddMonoid α] [AddAction α β]
[AddAction.IsPretransitive α β] : MulAction.IsPretransitive (Multiplicative α) β :=
⟨@AddAction.exists_vadd_eq α _ _ _⟩
end |
.lake/packages/mathlib/Mathlib/Algebra/Group/Action/TypeTags.lean | import Mathlib.Algebra.Group.Action.Defs
import Mathlib.Algebra.Group.TypeTags.Basic
/-!
# Additive and Multiplicative for group actions
## Tags
group action
-/
assert_not_exists MonoidWithZero MonoidHom
open Function (Injective Surjective)
variable {M α β γ : Type*}
section
open Additive Multiplicative
instance Additive.vadd [SMul α β] : VAdd (Additive α) β where vadd a := (a.toMul • ·)
instance Multiplicative.smul [VAdd α β] : SMul (Multiplicative α) β where smul a := (a.toAdd +ᵥ ·)
@[simp] lemma toMul_smul [SMul α β] (a : Additive α) (b : β) : (a.toMul : α) • b = a +ᵥ b := rfl
@[simp] lemma ofMul_vadd [SMul α β] (a : α) (b : β) : ofMul a +ᵥ b = a • b := rfl
@[simp] lemma toAdd_vadd [VAdd α β] (a : Multiplicative α) (b : β) : (a.toAdd : α) +ᵥ b = a • b :=
rfl
@[simp] lemma ofAdd_smul [VAdd α β] (a : α) (b : β) : ofAdd a • b = a +ᵥ b := rfl
instance Additive.addAction [Monoid α] [MulAction α β] : AddAction (Additive α) β where
zero_vadd := MulAction.one_smul
add_vadd := MulAction.mul_smul (α := α)
instance Multiplicative.mulAction [AddMonoid α] [AddAction α β] :
MulAction (Multiplicative α) β where
one_smul := AddAction.zero_vadd
mul_smul := AddAction.add_vadd (G := α)
instance Additive.vaddCommClass [SMul α γ] [SMul β γ] [SMulCommClass α β γ] :
VAddCommClass (Additive α) (Additive β) γ :=
⟨@smul_comm α β _ _ _ _⟩
instance Multiplicative.smulCommClass [VAdd α γ] [VAdd β γ] [VAddCommClass α β γ] :
SMulCommClass (Multiplicative α) (Multiplicative β) γ :=
⟨@vadd_comm α β _ _ _ _⟩
end |
.lake/packages/mathlib/Mathlib/Algebra/Group/Action/Units.lean | import Mathlib.Algebra.Group.Action.Faithful
import Mathlib.Algebra.Group.Basic
import Mathlib.Algebra.Group.Units.Defs
/-! # Group actions on and by `Mˣ`
This file provides the action of a unit on a type `α`, `SMul Mˣ α`, in the presence of
`SMul M α`, with the obvious definition stated in `Units.smul_def`. This definition preserves
`MulAction` and `DistribMulAction` structures too.
Additionally, a `MulAction G M` for some group `G` satisfying some additional properties admits a
`MulAction G Mˣ` structure, again with the obvious definition stated in `Units.coe_smul`.
These instances use a primed name.
The results are repeated for `AddUnits` and `VAdd` where relevant.
-/
assert_not_exists MonoidWithZero
variable {G H M N α : Type*}
namespace Units
@[to_additive] instance [Monoid M] [SMul M α] : SMul Mˣ α where smul m a := (m : M) • a
@[to_additive] lemma smul_def [Monoid M] [SMul M α] (m : Mˣ) (a : α) : m • a = (m : M) • a := rfl
@[to_additive, simp]
lemma smul_mk_apply {M α : Type*} [Monoid M] [SMul M α] (m n : M) (h₁) (h₂) (a : α) :
(⟨m, n, h₁, h₂⟩ : Mˣ) • a = m • a := rfl
@[simp]
lemma smul_isUnit [Monoid M] [SMul M α] {m : M} (hm : IsUnit m) (a : α) : hm.unit • a = m • a := rfl
@[to_additive]
lemma _root_.IsUnit.inv_smul [Monoid α] {a : α} (h : IsUnit a) : h.unit⁻¹ • a = 1 := h.val_inv_mul
@[to_additive]
instance [Monoid M] [SMul M α] [FaithfulSMul M α] : FaithfulSMul Mˣ α where
eq_of_smul_eq_smul h := Units.ext <| eq_of_smul_eq_smul h
@[to_additive]
instance instMulAction [Monoid M] [MulAction M α] : MulAction Mˣ α where
one_smul := one_smul M
mul_smul m n := mul_smul (m : M) n
@[to_additive]
instance smulCommClass_left [Monoid M] [SMul M α] [SMul N α] [SMulCommClass M N α] :
SMulCommClass Mˣ N α where smul_comm m n := smul_comm (m : M) n
@[to_additive]
instance smulCommClass_right [Monoid N] [SMul M α] [SMul N α] [SMulCommClass M N α] :
SMulCommClass M Nˣ α where smul_comm m n := smul_comm m (n : N)
@[to_additive]
instance [Monoid M] [SMul M N] [SMul M α] [SMul N α] [IsScalarTower M N α] :
IsScalarTower Mˣ N α where smul_assoc m n := smul_assoc (m : M) n
/-! ### Action of a group `G` on units of `M` -/
/-- If an action `G` associates and commutes with multiplication on `M`, then it lifts to an
action on `Mˣ`. Notably, this provides `MulAction Mˣ Nˣ` under suitable conditions. -/
@[to_additive]
instance mulAction' [Group G] [Monoid M] [MulAction G M] [SMulCommClass G M M]
[IsScalarTower G M M] : MulAction G Mˣ where
smul g m :=
⟨g • (m : M), (g⁻¹ • ((m⁻¹ : Mˣ) : M)),
by rw [smul_mul_smul_comm, Units.mul_inv, mul_inv_cancel, one_smul],
by rw [smul_mul_smul_comm, Units.inv_mul, inv_mul_cancel, one_smul]⟩
one_smul _ := Units.ext <| one_smul _ _
mul_smul _ _ _ := Units.ext <| mul_smul _ _ _
/-- This is not the usual `smul_eq_mul` because `mulAction'` creates a diamond.
Discussed [on Zulip](https://leanprover.zulipchat.com/#narrow/channel/113488-general/topic/units.2Emul_action'.20diamond/near/246400399). -/
@[simp]
lemma smul_eq_mul {M} [CommMonoid M] (u₁ u₂ : Mˣ) :
u₁ • u₂ = u₁ * u₂ := by
fail_if_success rfl -- there is an instance diamond here
ext
rfl
@[to_additive (attr := simp)]
lemma val_smul [Group G] [Monoid M] [MulAction G M] [SMulCommClass G M M] [IsScalarTower G M M]
(g : G) (m : Mˣ) : ↑(g • m) = g • (m : M) := rfl
/-- Note that this lemma exists more generally as the global `smul_inv` -/
@[to_additive (attr := simp)]
lemma smul_inv [Group G] [Monoid M] [MulAction G M] [SMulCommClass G M M] [IsScalarTower G M M]
(g : G) (m : Mˣ) : (g • m)⁻¹ = g⁻¹ • m⁻¹ := ext rfl
/-- Transfer `SMulCommClass G H M` to `SMulCommClass G H Mˣ`. -/
@[to_additive /-- Transfer `VAddCommClass G H M` to `VAddCommClass G H (AddUnits M)`. -/]
instance smulCommClass' [Group G] [Group H] [Monoid M] [MulAction G M] [SMulCommClass G M M]
[MulAction H M] [SMulCommClass H M M] [IsScalarTower G M M] [IsScalarTower H M M]
[SMulCommClass G H M] :
SMulCommClass G H Mˣ where smul_comm g h m := Units.ext <| smul_comm g h (m : M)
/-- Transfer `IsScalarTower G H M` to `IsScalarTower G H Mˣ`. -/
@[to_additive /-- Transfer `VAddAssocClass G H M` to `VAddAssocClass G H (AddUnits M)`. -/]
instance isScalarTower' [SMul G H] [Group G] [Group H] [Monoid M] [MulAction G M]
[SMulCommClass G M M] [MulAction H M] [SMulCommClass H M M] [IsScalarTower G M M]
[IsScalarTower H M M] [IsScalarTower G H M] :
IsScalarTower G H Mˣ where smul_assoc g h m := Units.ext <| smul_assoc g h (m : M)
/-- Transfer `IsScalarTower G M α` to `IsScalarTower G Mˣ α`. -/
@[to_additive /-- Transfer `VAddAssocClass G M α` to `VAddAssocClass G (AddUnits M) α`. -/]
instance isScalarTower'_left [Group G] [Monoid M] [MulAction G M] [SMul M α] [SMul G α]
[SMulCommClass G M M] [IsScalarTower G M M] [IsScalarTower G M α] :
IsScalarTower G Mˣ α where smul_assoc g m := smul_assoc g (m : M)
-- Just to prove this transfers a particularly useful instance.
example [Monoid M] [Monoid N] [MulAction M N] [SMulCommClass M N N] [IsScalarTower M N N] :
MulAction Mˣ Nˣ := Units.mulAction'
end Units
@[to_additive]
lemma IsUnit.smul [Group G] [Monoid M] [MulAction G M] [SMulCommClass G M M] [IsScalarTower G M M]
{m : M} (g : G) (h : IsUnit m) : IsUnit (g • m) :=
let ⟨u, hu⟩ := h
hu ▸ ⟨g • u, Units.val_smul _ _⟩ |
.lake/packages/mathlib/Mathlib/Algebra/Group/Action/Hom.lean | import Mathlib.Algebra.Group.Action.Pretransitive
import Mathlib.Algebra.Group.Hom.Defs
/-!
# Homomorphisms and group actions
-/
assert_not_exists MonoidWithZero
open Function (Injective Surjective)
variable {M N α : Type*}
section
variable [Monoid M] [MulAction M α]
/-- Push forward the action of `R` on `M` along a compatible surjective map `f : R →* S`.
See also `Function.Surjective.distribMulActionLeft` and `Function.Surjective.moduleLeft`.
-/
@[to_additive
/-- Push forward the action of `R` on `M` along a compatible surjective map `f : R →+ S`. -/]
abbrev Function.Surjective.mulActionLeft {R S M : Type*} [Monoid R] [MulAction R M] [Monoid S]
[SMul S M] (f : R →* S) (hf : Surjective f) (hsmul : ∀ (c) (x : M), f c • x = c • x) :
MulAction S M where
one_smul b := by rw [← f.map_one, hsmul, one_smul]
mul_smul := hf.forall₂.mpr fun a b x ↦ by simp only [← f.map_mul, hsmul, mul_smul]
namespace MulAction
variable (α)
/-- A multiplicative action of `M` on `α` and a monoid homomorphism `N → M` induce
a multiplicative action of `N` on `α`.
See note [reducible non-instances]. -/
@[to_additive]
abbrev compHom [Monoid N] (g : N →* M) : MulAction N α where
smul := SMul.comp.smul g
one_smul _ := by simpa [(· • ·)] using MulAction.one_smul ..
mul_smul _ _ _ := by simpa [(· • ·)] using MulAction.mul_smul ..
/-- An additive action of `M` on `α` and an additive monoid homomorphism `N → M` induce
an additive action of `N` on `α`.
See note [reducible non-instances]. -/
add_decl_doc AddAction.compHom
@[to_additive]
lemma compHom_smul_def
{E F G : Type*} [Monoid E] [Monoid F] [MulAction F G] (f : E →* F) (a : E) (x : G) :
letI : MulAction E G := MulAction.compHom _ f
a • x = (f a) • x := rfl
/-- If an action is transitive, then composing this action with a surjective homomorphism gives
again a transitive action. -/
@[to_additive]
lemma isPretransitive_compHom {E F G : Type*} [Monoid E] [Monoid F] [MulAction F G]
[IsPretransitive F G] {f : E →* F} (hf : Surjective f) :
letI : MulAction E G := MulAction.compHom _ f
IsPretransitive E G := by
let _ : MulAction E G := MulAction.compHom _ f
refine ⟨fun x y ↦ ?_⟩
obtain ⟨m, rfl⟩ : ∃ m : F, m • x = y := exists_smul_eq F x y
obtain ⟨e, rfl⟩ : ∃ e, f e = m := hf m
exact ⟨e, rfl⟩
@[to_additive]
lemma IsPretransitive.of_compHom {M N α : Type*} [Monoid M] [Monoid N] [MulAction N α]
(f : M →* N) [h : letI := compHom α f; IsPretransitive M α] : IsPretransitive N α :=
letI := compHom α f; h.of_smul_eq f rfl
end MulAction
end
section CompatibleScalar
/-- If the multiplicative action of `M` on `N` is compatible with multiplication on `N`, then
`fun x ↦ x • 1` is a monoid homomorphism from `M` to `N`. -/
@[to_additive (attr := simps)
/-- If the additive action of `M` on `N` is compatible with addition on `N`, then
`fun x ↦ x +ᵥ 0` is an additive monoid homomorphism from `M` to `N`. -/]
def MonoidHom.smulOneHom {M N} [Monoid M] [MulOneClass N] [MulAction M N] [IsScalarTower M N N] :
M →* N where
toFun x := x • (1 : N)
map_one' := one_smul _ _
map_mul' x y := by rw [smul_one_mul, smul_smul]
/-- A monoid homomorphism between two monoids M and N can be equivalently specified by a
multiplicative action of M on N that is compatible with the multiplication on N. -/
@[to_additive
/-- A monoid homomorphism between two additive monoids M and N can be equivalently
specified by an additive action of M on N that is compatible with the addition on N. -/]
def monoidHomEquivMulActionIsScalarTower (M N) [Monoid M] [Monoid N] :
(M →* N) ≃ {_inst : MulAction M N // IsScalarTower M N N} where
toFun f := ⟨MulAction.compHom N f, SMul.comp.isScalarTower _⟩
invFun := fun ⟨_, _⟩ ↦ MonoidHom.smulOneHom
left_inv f := MonoidHom.ext fun m ↦ mul_one (f m)
right_inv := fun ⟨_, _⟩ ↦ Subtype.ext <| MulAction.ext <| funext₂ <| smul_one_smul N
end CompatibleScalar |
.lake/packages/mathlib/Mathlib/Algebra/Group/Action/Pointwise/Finset.lean | import Mathlib.Algebra.Group.Action.Pi
import Mathlib.Algebra.Group.Action.Pointwise.Set.Basic
import Mathlib.Algebra.Group.Pointwise.Finset.Scalar
import Mathlib.Algebra.Group.Pointwise.Finset.Basic
/-!
# Pointwise actions of finsets
-/
-- TODO
-- assert_not_exists MonoidWithZero
assert_not_exists Cardinal
open Function MulOpposite
open scoped Pointwise
variable {F α β γ : Type*}
namespace Finset
/-! ### Instances -/
section Instances
variable [DecidableEq γ]
@[to_additive]
instance smulCommClass_finset [SMul α γ] [SMul β γ] [SMulCommClass α β γ] :
SMulCommClass α β (Finset γ) :=
⟨fun _ _ => Commute.finset_image <| smul_comm _ _⟩
@[to_additive]
instance smulCommClass_finset' [SMul α γ] [SMul β γ] [SMulCommClass α β γ] :
SMulCommClass α (Finset β) (Finset γ) :=
⟨fun a s t => coe_injective <| by simp only [coe_smul_finset, coe_smul, smul_comm]⟩
@[to_additive]
instance smulCommClass_finset'' [SMul α γ] [SMul β γ] [SMulCommClass α β γ] :
SMulCommClass (Finset α) β (Finset γ) :=
haveI := SMulCommClass.symm α β γ
SMulCommClass.symm _ _ _
@[to_additive]
instance smulCommClass [SMul α γ] [SMul β γ] [SMulCommClass α β γ] :
SMulCommClass (Finset α) (Finset β) (Finset γ) :=
⟨fun s t u => coe_injective <| by simp_rw [coe_smul, smul_comm]⟩
@[to_additive]
instance isScalarTower [SMul α β] [SMul α γ] [SMul β γ] [IsScalarTower α β γ] :
IsScalarTower α β (Finset γ) :=
⟨fun a b s => by simp only [← image_smul, image_image, smul_assoc, Function.comp_def]⟩
variable [DecidableEq β]
@[to_additive]
instance isScalarTower' [SMul α β] [SMul α γ] [SMul β γ] [IsScalarTower α β γ] :
IsScalarTower α (Finset β) (Finset γ) :=
⟨fun a s t => coe_injective <| by simp only [coe_smul_finset, coe_smul, smul_assoc]⟩
@[to_additive]
instance isScalarTower'' [SMul α β] [SMul α γ] [SMul β γ] [IsScalarTower α β γ] :
IsScalarTower (Finset α) (Finset β) (Finset γ) :=
⟨fun a s t => coe_injective <| by simp only [coe_smul, smul_assoc]⟩
@[to_additive]
instance isCentralScalar [SMul α β] [SMul αᵐᵒᵖ β] [IsCentralScalar α β] :
IsCentralScalar α (Finset β) :=
⟨fun a s => coe_injective <| by simp only [coe_smul_finset, op_smul_eq_smul]⟩
/-- A multiplicative action of a monoid `α` on a type `β` gives a multiplicative action of
`Finset α` on `Finset β`. -/
@[to_additive
/-- An additive action of an additive monoid `α` on a type `β` gives an additive action
of `Finset α` on `Finset β` -/]
protected def mulAction [DecidableEq α] [Monoid α] [MulAction α β] :
MulAction (Finset α) (Finset β) where
mul_smul _ _ _ := image₂_assoc mul_smul
one_smul s := image₂_singleton_left.trans <| by simp_rw [one_smul, image_id']
/-- A multiplicative action of a monoid on a type `β` gives a multiplicative action on `Finset β`.
-/
@[to_additive
/-- An additive action of an additive monoid on a type `β` gives an additive action
on `Finset β`. -/]
protected def mulActionFinset [Monoid α] [MulAction α β] : MulAction α (Finset β) :=
coe_injective.mulAction _ coe_smul_finset
scoped[Pointwise]
attribute [instance]
Finset.mulActionFinset Finset.addActionFinset Finset.mulAction Finset.addAction
end Instances
section Mul
variable [Mul α] [DecidableEq α] {s t u : Finset α} {a : α}
open scoped RightActions in
@[to_additive] lemma mul_singleton (a : α) : s * {a} = s <• a := image₂_singleton_right
@[to_additive] lemma singleton_mul (a : α) : {a} * s = a • s := image₂_singleton_left
@[to_additive] lemma smul_finset_subset_mul : a ∈ s → a • t ⊆ s * t := image_subset_image₂_right
@[to_additive]
theorem op_smul_finset_subset_mul : a ∈ t → op a • s ⊆ s * t :=
image_subset_image₂_left
@[to_additive (attr := simp)]
theorem biUnion_op_smul_finset (s t : Finset α) : (t.biUnion fun a => op a • s) = s * t :=
biUnion_image_right
@[to_additive]
theorem mul_subset_iff_left : s * t ⊆ u ↔ ∀ a ∈ s, a • t ⊆ u :=
image₂_subset_iff_left
@[to_additive]
theorem mul_subset_iff_right : s * t ⊆ u ↔ ∀ b ∈ t, op b • s ⊆ u :=
image₂_subset_iff_right
end Mul
section Semigroup
variable [Semigroup α] [DecidableEq α]
@[to_additive]
theorem op_smul_finset_mul_eq_mul_smul_finset (a : α) (s : Finset α) (t : Finset α) :
op a • s * t = s * a • t :=
op_smul_finset_smul_eq_smul_smul_finset _ _ _ fun _ _ _ => mul_assoc _ _ _
end Semigroup
section IsLeftCancelMul
variable [Mul α] [IsLeftCancelMul α] [DecidableEq α] {s t : Finset α} {a : α}
@[to_additive]
theorem pairwiseDisjoint_smul_iff {s : Set α} {t : Finset α} :
s.PairwiseDisjoint (· • t) ↔ (s ×ˢ t : Set (α × α)).InjOn fun p => p.1 * p.2 := by
simp_rw [← pairwiseDisjoint_coe, coe_smul_finset, Set.pairwiseDisjoint_smul_iff]
end IsLeftCancelMul
@[to_additive]
theorem image_smul_distrib [DecidableEq α] [DecidableEq β] [Mul α] [Mul β] [FunLike F α β]
[MulHomClass F α β] (f : F) (a : α) (s : Finset α) : (a • s).image f = f a • s.image f :=
image_comm <| map_mul _ _
section Group
variable [DecidableEq β] [Group α] [MulAction α β] {s t : Finset β} {a : α} {b : β}
@[to_additive (attr := simp)]
theorem smul_mem_smul_finset_iff (a : α) : a • b ∈ a • s ↔ b ∈ s :=
(MulAction.injective _).mem_finset_image
@[to_additive (attr := simp)]
lemma mul_mem_smul_finset_iff [DecidableEq α] (a : α) {b : α} {s : Finset α} :
a * b ∈ a • s ↔ b ∈ s := smul_mem_smul_finset_iff _
@[to_additive]
theorem inv_smul_mem_iff : a⁻¹ • b ∈ s ↔ b ∈ a • s := by
rw [← smul_mem_smul_finset_iff a, smul_inv_smul]
@[to_additive]
theorem mem_inv_smul_finset_iff : b ∈ a⁻¹ • s ↔ a • b ∈ s := by
rw [← smul_mem_smul_finset_iff a, smul_inv_smul]
@[to_additive (attr := simp)]
theorem smul_finset_subset_smul_finset_iff : a • s ⊆ a • t ↔ s ⊆ t :=
image_subset_image_iff <| MulAction.injective _
@[to_additive]
theorem smul_finset_subset_iff : a • s ⊆ t ↔ s ⊆ a⁻¹ • t := by
simp_rw [← coe_subset]
push_cast
exact Set.smul_set_subset_iff_subset_inv_smul_set
@[to_additive]
theorem subset_smul_finset_iff : s ⊆ a • t ↔ a⁻¹ • s ⊆ t := by
simp_rw [← coe_subset]
push_cast
exact Set.subset_smul_set_iff
@[to_additive]
theorem smul_finset_inter : a • (s ∩ t) = a • s ∩ a • t :=
image_inter _ _ <| MulAction.injective a
@[to_additive]
theorem smul_finset_sdiff : a • (s \ t) = a • s \ a • t :=
image_sdiff _ _ <| MulAction.injective a
open scoped symmDiff in
@[to_additive]
theorem smul_finset_symmDiff : a • s ∆ t = (a • s) ∆ (a • t) :=
image_symmDiff _ _ <| MulAction.injective a
@[to_additive (attr := simp)]
theorem smul_finset_univ [Fintype β] : a • (univ : Finset β) = univ :=
image_univ_of_surjective <| MulAction.surjective a
@[to_additive (attr := simp)]
theorem smul_univ [Fintype β] {s : Finset α} (hs : s.Nonempty) : s • (univ : Finset β) = univ :=
coe_injective <| by
push_cast
exact Set.smul_univ hs
@[to_additive (attr := simp)]
theorem card_smul_finset (a : α) (s : Finset β) : (a • s).card = s.card :=
card_image_of_injective _ <| MulAction.injective _
/-- If the left cosets of `t` by elements of `s` are disjoint (but not necessarily distinct!), then
the size of `t` divides the size of `s • t`. -/
@[to_additive /-- If the left cosets of `t` by elements of `s` are disjoint (but not necessarily
distinct!), then the size of `t` divides the size of `s +ᵥ t`. -/]
theorem card_dvd_card_smul_right {s : Finset α} :
((· • t) '' (s : Set α)).PairwiseDisjoint id → t.card ∣ (s • t).card :=
card_dvd_card_image₂_right fun _ _ => MulAction.injective _
variable [DecidableEq α]
/-- If the right cosets of `s` by elements of `t` are disjoint (but not necessarily distinct!), then
the size of `s` divides the size of `s * t`. -/
@[to_additive /-- If the right cosets of `s` by elements of `t` are disjoint (but not necessarily
distinct!), then the size of `s` divides the size of `s + t`. -/]
theorem card_dvd_card_mul_left {s t : Finset α} :
((fun b => s.image fun a => a * b) '' (t : Set α)).PairwiseDisjoint id →
s.card ∣ (s * t).card :=
card_dvd_card_image₂_left fun _ _ => mul_left_injective _
/-- If the left cosets of `t` by elements of `s` are disjoint (but not necessarily distinct!), then
the size of `t` divides the size of `s * t`. -/
@[to_additive /-- If the left cosets of `t` by elements of `s` are disjoint (but not necessarily
distinct!), then the size of `t` divides the size of `s + t`. -/]
theorem card_dvd_card_mul_right {s t : Finset α} :
((· • t) '' (s : Set α)).PairwiseDisjoint id → t.card ∣ (s * t).card :=
card_dvd_card_image₂_right fun _ _ => mul_right_injective _
@[to_additive (attr := simp)]
lemma inv_smul_finset_distrib (a : α) (s : Finset α) : (a • s)⁻¹ = op a⁻¹ • s⁻¹ := by
ext; simp [← inv_smul_mem_iff]
@[to_additive (attr := simp)]
lemma inv_op_smul_finset_distrib (a : α) (s : Finset α) : (op a • s)⁻¹ = a⁻¹ • s⁻¹ := by
ext; simp [← inv_smul_mem_iff]
end Group
end Finset
namespace Fintype
variable {ι : Type*} {α β : ι → Type*} [Fintype ι] [DecidableEq ι] [∀ i, DecidableEq (β i)]
@[to_additive]
lemma piFinset_smul [∀ i, SMul (α i) (β i)] (s : ∀ i, Finset (α i)) (t : ∀ i, Finset (β i)) :
piFinset (fun i ↦ s i • t i) = piFinset s • piFinset t := piFinset_image₂ _ _ _
@[to_additive]
lemma piFinset_smul_finset [∀ i, SMul (α i) (β i)] (a : ∀ i, α i) (s : ∀ i, Finset (β i)) :
piFinset (fun i ↦ a i • s i) = a • piFinset s := piFinset_image _ _
-- Note: We don't currently state `piFinset_vsub` because there's no
-- `[∀ i, VSub (β i) (α i)] → VSub (∀ i, β i) (∀ i, α i)` instance
end Fintype
instance Nat.decidablePred_mem_vadd_set {s : Set ℕ} [DecidablePred (· ∈ s)] (a : ℕ) :
DecidablePred (· ∈ a +ᵥ s) :=
fun n ↦ decidable_of_iff' (a ≤ n ∧ n - a ∈ s) <| by
simp only [Set.mem_vadd_set, vadd_eq_add]; aesop |
.lake/packages/mathlib/Mathlib/Algebra/Group/Action/Pointwise/Set/Finite.lean | import Mathlib.Algebra.Group.Action.Basic
import Mathlib.Algebra.Group.Pointwise.Set.Scalar
import Mathlib.Data.Set.Finite.Basic
/-! # Finiteness lemmas for pointwise operations on sets -/
open scoped Pointwise
namespace Set
variable {G α : Type*} [Group G] [MulAction G α] {a : G} {s : Set α}
@[to_additive (attr := simp)]
lemma finite_smul_set : (a • s).Finite ↔ s.Finite := finite_image_iff (MulAction.injective _).injOn
@[to_additive (attr := simp)]
lemma infinite_smul_set : (a • s).Infinite ↔ s.Infinite :=
infinite_image_iff (MulAction.injective _).injOn
@[to_additive] alias ⟨Finite.of_smul_set, _⟩ := finite_smul_set
@[to_additive] alias ⟨_, Infinite.smul_set⟩ := infinite_smul_set
end Set |
.lake/packages/mathlib/Mathlib/Algebra/Group/Action/Pointwise/Set/Basic.lean | import Mathlib.Algebra.Group.Action.Basic
import Mathlib.Algebra.Group.Action.Opposite
import Mathlib.Algebra.Group.Pointwise.Set.Scalar
import Mathlib.Algebra.Group.Units.Equiv
import Mathlib.Data.Set.Lattice.Image
import Mathlib.Data.Set.Pairwise.Basic
import Mathlib.Algebra.Group.Pointwise.Set.Basic
/-!
# Pointwise actions on sets
This file proves that several kinds of actions of a type `α` on another type `β` transfer to actions
of `α`/`Set α` on `Set β`.
## Implementation notes
* We put all instances in the scope `Pointwise`, so that these instances are not available by
default. Note that we do not mark them as reducible (as argued by note [reducible non-instances])
since we expect the scope to be open whenever the instances are actually used (and making the
instances reducible changes the behavior of `simp`.
-/
assert_not_exists MonoidWithZero IsOrderedMonoid
open Function MulOpposite
open scoped Pointwise
variable {F α β γ : Type*}
namespace Set
/-! ### Translation/scaling of sets -/
@[to_additive vadd_set_prod]
lemma smul_set_prod {M α : Type*} [SMul M α] [SMul M β] (c : M) (s : Set α) (t : Set β) :
c • (s ×ˢ t) = (c • s) ×ˢ (c • t) :=
prodMap_image_prod (c • ·) (c • ·) s t
@[to_additive]
lemma smul_set_pi {G ι : Type*} {α : ι → Type*} [Group G] [∀ i, MulAction G (α i)]
(c : G) (I : Set ι) (s : ∀ i, Set (α i)) : c • I.pi s = I.pi (c • s) :=
smul_set_pi_of_surjective c I s fun _ _ ↦ (MulAction.bijective c).surjective
@[to_additive]
lemma smul_set_pi_of_isUnit {M ι : Type*} {α : ι → Type*} [Monoid M] [∀ i, MulAction M (α i)]
{c : M} (hc : IsUnit c) (I : Set ι) (s : ∀ i, Set (α i)) : c • I.pi s = I.pi (c • s) := by
lift c to Mˣ using hc
exact smul_set_pi c I s
section Mul
variable {ι : Sort*} {κ : ι → Sort*} [Mul α] {s s₁ s₂ t t₁ t₂ u : Set α} {a b : α}
@[to_additive] lemma smul_set_subset_mul : a ∈ s → a • t ⊆ s * t := image_subset_image2_right
open scoped RightActions in
@[to_additive] lemma op_smul_set_subset_mul : a ∈ t → s <• a ⊆ s * t := image_subset_image2_left
@[to_additive]
theorem image_op_smul : (op '' s) • t = t * s := by
rw [← image2_smul, ← image2_mul, image2_image_left, image2_swap]
rfl
@[to_additive (attr := simp)]
theorem iUnion_op_smul_set (s t : Set α) : ⋃ a ∈ t, MulOpposite.op a • s = s * t :=
iUnion_image_right _
@[to_additive]
theorem mul_subset_iff_left : s * t ⊆ u ↔ ∀ a ∈ s, a • t ⊆ u :=
image2_subset_iff_left
@[to_additive]
theorem mul_subset_iff_right : s * t ⊆ u ↔ ∀ b ∈ t, op b • s ⊆ u :=
image2_subset_iff_right
@[to_additive] lemma pair_mul (a b : α) (s : Set α) : {a, b} * s = a • s ∪ b • s := by
rw [insert_eq, union_mul, singleton_mul, singleton_mul]; rfl
open scoped RightActions
@[to_additive] lemma mul_pair (s : Set α) (a b : α) : s * {a, b} = s <• a ∪ s <• b := by
rw [insert_eq, mul_union, mul_singleton, mul_singleton]; rfl
@[to_additive] lemma range_mul {ι : Sort*} (a : α) (f : ι → α) :
range (fun i ↦ a * f i) = a • range f := range_smul a f
end Mul
@[to_additive]
lemma image_smul_distrib [Mul α] [Mul β] [FunLike F α β] [MulHomClass F α β]
(f : F) (a : α) (s : Set α) :
f '' (a • s) = f a • f '' s :=
image_comm <| map_mul _ _
open scoped RightActions in
@[to_additive]
lemma image_op_smul_distrib [Mul α] [Mul β] [FunLike F α β] [MulHomClass F α β]
(f : F) (a : α) (s : Set α) : f '' (s <• a) = f '' s <• f a := image_comm fun _ ↦ map_mul ..
section Semigroup
variable [Semigroup α]
@[to_additive]
lemma op_smul_set_mul_eq_mul_smul_set (a : α) (s : Set α) (t : Set α) :
op a • s * t = s * a • t :=
op_smul_set_smul_eq_smul_smul_set _ _ _ fun _ _ _ => mul_assoc _ _ _
end Semigroup
section IsLeftCancelMul
variable [Mul α] [IsLeftCancelMul α] {s t : Set α}
@[to_additive]
theorem pairwiseDisjoint_smul_iff :
s.PairwiseDisjoint (· • t) ↔ (s ×ˢ t).InjOn fun p ↦ p.1 * p.2 :=
pairwiseDisjoint_image_right_iff fun _ _ ↦ mul_right_injective _
end IsLeftCancelMul
@[to_additive]
instance smulCommClass_set [SMul α γ] [SMul β γ] [SMulCommClass α β γ] :
SMulCommClass α β (Set γ) :=
⟨fun _ _ ↦ Commute.set_image <| smul_comm _ _⟩
@[to_additive]
instance smulCommClass_set' [SMul α γ] [SMul β γ] [SMulCommClass α β γ] :
SMulCommClass α (Set β) (Set γ) :=
⟨fun _ _ _ ↦ image_image2_distrib_right <| smul_comm _⟩
@[to_additive]
instance smulCommClass_set'' [SMul α γ] [SMul β γ] [SMulCommClass α β γ] :
SMulCommClass (Set α) β (Set γ) :=
haveI := SMulCommClass.symm α β γ
SMulCommClass.symm _ _ _
@[to_additive]
instance smulCommClass [SMul α γ] [SMul β γ] [SMulCommClass α β γ] :
SMulCommClass (Set α) (Set β) (Set γ) :=
⟨fun _ _ _ ↦ image2_left_comm smul_comm⟩
@[to_additive]
instance isScalarTower [SMul α β] [SMul α γ] [SMul β γ] [IsScalarTower α β γ] :
IsScalarTower α β (Set γ) where
smul_assoc a b T := by simp only [← image_smul, image_image, smul_assoc]
@[to_additive]
instance isScalarTower' [SMul α β] [SMul α γ] [SMul β γ] [IsScalarTower α β γ] :
IsScalarTower α (Set β) (Set γ) :=
⟨fun _ _ _ ↦ image2_image_left_comm <| smul_assoc _⟩
@[to_additive]
instance isScalarTower'' [SMul α β] [SMul α γ] [SMul β γ] [IsScalarTower α β γ] :
IsScalarTower (Set α) (Set β) (Set γ) where
smul_assoc _ _ _ := image2_assoc smul_assoc
@[to_additive]
instance isCentralScalar [SMul α β] [SMul αᵐᵒᵖ β] [IsCentralScalar α β] :
IsCentralScalar α (Set β) :=
⟨fun _ S ↦ (congr_arg fun f ↦ f '' S) <| funext fun _ ↦ op_smul_eq_smul _ _⟩
/-- A multiplicative action of a monoid `α` on a type `β` gives a multiplicative action of `Set α`
on `Set β`. -/
@[to_additive
/-- An additive action of an additive monoid `α` on a type `β` gives an additive action of `Set α`
on `Set β` -/]
protected noncomputable def mulAction [Monoid α] [MulAction α β] : MulAction (Set α) (Set β) where
mul_smul _ _ _ := image2_assoc mul_smul
one_smul s := image2_singleton_left.trans <| by simp_rw [one_smul, image_id']
/-- A multiplicative action of a monoid on a type `β` gives a multiplicative action on `Set β`. -/
@[to_additive
/-- An additive action of an additive monoid on a type `β` gives an additive action on `Set β`. -/]
protected def mulActionSet [Monoid α] [MulAction α β] : MulAction α (Set β) where
mul_smul _ _ _ := by simp only [← image_smul, image_image, ← mul_smul]
one_smul _ := by simp only [← image_smul, one_smul, image_id']
scoped[Pointwise] attribute [instance] Set.mulActionSet Set.addActionSet Set.mulAction Set.addAction
section Group
variable [Group α] [MulAction α β] {s t A B : Set β} {a b : α} {x : β}
@[to_additive (attr := simp)]
theorem smul_mem_smul_set_iff : a • x ∈ a • s ↔ x ∈ s :=
(MulAction.injective _).mem_set_image
@[to_additive]
theorem mem_smul_set_iff_inv_smul_mem : x ∈ a • A ↔ a⁻¹ • x ∈ A :=
show x ∈ MulAction.toPerm a '' A ↔ _ from mem_image_equiv
@[to_additive]
theorem mem_inv_smul_set_iff : x ∈ a⁻¹ • A ↔ a • x ∈ A := by
simp only [← image_smul, mem_image, inv_smul_eq_iff, exists_eq_right]
@[to_additive (attr := simp)]
lemma mem_smul_set_inv {s : Set α} : a ∈ b • s⁻¹ ↔ b ∈ a • s := by
simp [mem_smul_set_iff_inv_smul_mem]
@[to_additive]
theorem preimage_smul (a : α) (t : Set β) : (fun x ↦ a • x) ⁻¹' t = a⁻¹ • t :=
((MulAction.toPerm a).image_symm_eq_preimage _).symm
@[to_additive]
theorem preimage_smul_inv (a : α) (t : Set β) : (fun x ↦ a⁻¹ • x) ⁻¹' t = a • t :=
preimage_smul (toUnits a)⁻¹ t
@[to_additive (attr := simp)]
theorem smul_set_subset_smul_set_iff : a • A ⊆ a • B ↔ A ⊆ B :=
image_subset_image_iff <| MulAction.injective _
@[to_additive]
theorem smul_set_subset_iff_subset_inv_smul_set : a • A ⊆ B ↔ A ⊆ a⁻¹ • B := by
refine image_subset_iff.trans ?_
congr! 1
exact ((MulAction.toPerm _).image_symm_eq_preimage _).symm
@[to_additive]
theorem subset_smul_set_iff : A ⊆ a • B ↔ a⁻¹ • A ⊆ B := by
refine (image_subset_iff.trans ?_ ).symm; congr! 1;
exact ((MulAction.toPerm _).image_eq_preimage_symm _).symm
@[to_additive]
theorem smul_set_inter : a • (s ∩ t) = a • s ∩ a • t :=
image_inter <| MulAction.injective a
@[to_additive]
theorem smul_set_iInter {ι : Sort*}
(a : α) (t : ι → Set β) : (a • ⋂ i, t i) = ⋂ i, a • t i :=
image_iInter (MulAction.bijective a) t
@[to_additive]
theorem smul_set_sdiff : a • (s \ t) = a • s \ a • t :=
image_diff (MulAction.injective a) _ _
open scoped symmDiff in
@[to_additive]
theorem smul_set_symmDiff : a • s ∆ t = (a • s) ∆ (a • t) :=
image_symmDiff (MulAction.injective a) _ _
@[to_additive (attr := simp)]
theorem smul_set_univ : a • (univ : Set β) = univ :=
image_univ_of_surjective <| MulAction.surjective a
@[to_additive (attr := simp)]
theorem smul_univ {s : Set α} (hs : s.Nonempty) : s • (univ : Set β) = univ :=
let ⟨a, ha⟩ := hs
eq_univ_of_forall fun b ↦ ⟨a, ha, a⁻¹ • b, trivial, smul_inv_smul _ _⟩
@[to_additive]
theorem smul_set_compl : a • sᶜ = (a • s)ᶜ := by
simp_rw [Set.compl_eq_univ_diff, smul_set_sdiff, smul_set_univ]
@[to_additive]
theorem smul_inter_ne_empty_iff {s t : Set α} {x : α} :
x • s ∩ t ≠ ∅ ↔ ∃ a b, (a ∈ t ∧ b ∈ s) ∧ a * b⁻¹ = x := by
rw [← nonempty_iff_ne_empty]
constructor
· rintro ⟨a, h, ha⟩
obtain ⟨b, hb, rfl⟩ := mem_smul_set.mp h
exact ⟨x • b, b, ⟨ha, hb⟩, by simp⟩
· rintro ⟨a, b, ⟨ha, hb⟩, rfl⟩
exact ⟨a, mem_inter (mem_smul_set.mpr ⟨b, hb, by simp⟩) ha⟩
@[to_additive]
theorem smul_inter_ne_empty_iff' {s t : Set α} {x : α} :
x • s ∩ t ≠ ∅ ↔ ∃ a b, (a ∈ t ∧ b ∈ s) ∧ a / b = x := by
simp_rw [smul_inter_ne_empty_iff, div_eq_mul_inv]
@[to_additive]
theorem op_smul_inter_ne_empty_iff {s t : Set α} {x : αᵐᵒᵖ} :
x • s ∩ t ≠ ∅ ↔ ∃ a b, (a ∈ s ∧ b ∈ t) ∧ a⁻¹ * b = MulOpposite.unop x := by
rw [← nonempty_iff_ne_empty]
constructor
· rintro ⟨a, h, ha⟩
obtain ⟨b, hb, rfl⟩ := mem_smul_set.mp h
exact ⟨b, x • b, ⟨hb, ha⟩, by simp⟩
· rintro ⟨a, b, ⟨ha, hb⟩, H⟩
have : MulOpposite.op (a⁻¹ * b) = x := congr_arg MulOpposite.op H
exact ⟨b, mem_inter (mem_smul_set.mpr ⟨a, ha, by simp [← this]⟩) hb⟩
@[to_additive (attr := simp)]
theorem iUnion_inv_smul : ⋃ g : α, g⁻¹ • s = ⋃ g : α, g • s :=
(Function.Surjective.iSup_congr _ inv_surjective) fun _ ↦ rfl
@[to_additive]
theorem iUnion_smul_eq_setOf_exists {s : Set β} : ⋃ g : α, g • s = { a | ∃ g : α, g • a ∈ s } := by
simp_rw [← iUnion_setOf, ← iUnion_inv_smul, ← preimage_smul, preimage]
@[to_additive (attr := simp)]
lemma inv_smul_set_distrib (a : α) (s : Set α) : (a • s)⁻¹ = op a⁻¹ • s⁻¹ := by
ext; simp [mem_smul_set_iff_inv_smul_mem]
@[to_additive (attr := simp)]
lemma inv_op_smul_set_distrib (a : α) (s : Set α) : (op a • s)⁻¹ = a⁻¹ • s⁻¹ := by
ext; simp [mem_smul_set_iff_inv_smul_mem]
@[to_additive (attr := simp)]
lemma disjoint_smul_set : Disjoint (a • s) (a • t) ↔ Disjoint s t :=
disjoint_image_iff <| MulAction.injective _
@[to_additive]
lemma disjoint_smul_set_left : Disjoint (a • s) t ↔ Disjoint s (a⁻¹ • t) := by
simpa using disjoint_smul_set (a := a) (t := a⁻¹ • t)
@[to_additive]
lemma disjoint_smul_set_right : Disjoint s (a • t) ↔ Disjoint (a⁻¹ • s) t := by
simpa using disjoint_smul_set (a := a) (s := a⁻¹ • s)
/-- Any intersection of translates of two sets `s` and `t` can be covered by a single translate of
`(s⁻¹ * s) ∩ (t⁻¹ * t)`.
This is useful to show that the intersection of approximate subgroups is an approximate subgroup. -/
@[to_additive
/-- Any intersection of translates of two sets `s` and `t` can be covered by a single translate of
`(-s + s) ∩ (-t + t)`.
This is useful to show that the intersection of approximate subgroups is an approximate subgroup.
-/]
lemma exists_smul_inter_smul_subset_smul_inv_mul_inter_inv_mul (s t : Set α) (a b : α) :
∃ z : α, a • s ∩ b • t ⊆ z • ((s⁻¹ * s) ∩ (t⁻¹ * t)) := by
obtain hAB | ⟨z, hzA, hzB⟩ := (a • s ∩ b • t).eq_empty_or_nonempty
· exact ⟨1, by simp [hAB]⟩
refine ⟨z, ?_⟩
calc
a • s ∩ b • t ⊆ (z • s⁻¹) * s ∩ ((z • t⁻¹) * t) := by
gcongr <;> apply smul_set_subset_mul <;> simpa
_ = z • ((s⁻¹ * s) ∩ (t⁻¹ * t)) := by simp_rw [Set.smul_set_inter, smul_mul_assoc]
end Group
section Monoid
variable [Monoid α] [MulAction α β] {s : Set β} {a : α} {b : β}
@[simp] lemma mem_invOf_smul_set [Invertible a] : b ∈ ⅟a • s ↔ a • b ∈ s :=
mem_inv_smul_set_iff (a := unitOfInvertible a)
end Monoid
section Group
variable [Group α] [CommGroup β] [FunLike F α β] [MonoidHomClass F α β]
@[to_additive]
lemma smul_graphOn (x : α × β) (s : Set α) (f : F) :
x • s.graphOn f = (x.1 • s).graphOn fun a ↦ x.2 / f x.1 * f a := by
ext ⟨a, b⟩
simp [mem_smul_set_iff_inv_smul_mem, inv_mul_eq_iff_eq_mul, mul_left_comm _ _⁻¹,
eq_inv_mul_iff_mul_eq, ← mul_div_right_comm, div_eq_iff_eq_mul, mul_comm b]
@[to_additive]
lemma smul_graphOn_univ (x : α × β) (f : F) :
x • univ.graphOn f = univ.graphOn fun a ↦ x.2 / f x.1 * f a := by simp [smul_graphOn]
end Group
section CommGroup
variable [CommGroup α]
@[to_additive] lemma smul_div_smul_comm (a : α) (s : Set α) (b : α) (t : Set α) :
a • s / b • t = (a / b) • (s / t) := by
simp_rw [← image_smul, smul_eq_mul, ← singleton_mul, mul_div_mul_comm _ s,
singleton_div_singleton]
end CommGroup
end Set |
.lake/packages/mathlib/Mathlib/Algebra/Group/Commute/Basic.lean | import Mathlib.Algebra.Group.Commute.Defs
import Mathlib.Algebra.Group.Semiconj.Basic
/-!
# Additional lemmas about commuting pairs of elements in monoids
-/
assert_not_exists MonoidWithZero DenselyOrdered
variable {G : Type*}
section Semigroup
variable [Semigroup G] {a b c : G}
open Function
@[to_additive]
lemma SemiconjBy.function_semiconj_mul_left (h : SemiconjBy a b c) :
Semiconj (a * ·) (b * ·) (c * ·) := fun j ↦ by simp only [← mul_assoc, h.eq]
@[to_additive]
lemma Commute.function_commute_mul_left (h : Commute a b) : Function.Commute (a * ·) (b * ·) :=
SemiconjBy.function_semiconj_mul_left h
@[to_additive]
lemma SemiconjBy.function_semiconj_mul_right_swap (h : SemiconjBy a b c) :
Function.Semiconj (· * a) (· * c) (· * b) := fun j ↦ by simp only [mul_assoc, ← h.eq]
@[to_additive]
lemma Commute.function_commute_mul_right (h : Commute a b) : Function.Commute (· * a) (· * b) :=
SemiconjBy.function_semiconj_mul_right_swap h
end Semigroup
namespace Commute
section DivisionMonoid
variable [DivisionMonoid G] {a b c d : G}
@[to_additive]
protected theorem inv_inv : Commute a b → Commute a⁻¹ b⁻¹ :=
SemiconjBy.inv_inv_symm
@[to_additive (attr := simp)]
theorem inv_inv_iff : Commute a⁻¹ b⁻¹ ↔ Commute a b :=
SemiconjBy.inv_inv_symm_iff
@[to_additive]
protected theorem div_mul_div_comm (hbd : Commute b d) (hbc : Commute b⁻¹ c) :
a / b * (c / d) = a * c / (b * d) := by
simp_rw [div_eq_mul_inv, mul_inv_rev, hbd.inv_inv.symm.eq, hbc.mul_mul_mul_comm]
@[to_additive]
protected theorem mul_div_mul_comm (hcd : Commute c d) (hbc : Commute b c⁻¹) :
a * b / (c * d) = a / c * (b / d) :=
(hcd.div_mul_div_comm hbc.symm).symm
@[to_additive]
protected theorem div_div_div_comm (hbc : Commute b c) (hbd : Commute b⁻¹ d) (hcd : Commute c⁻¹ d) :
a / b / (c / d) = a / c / (b / d) := by
simp_rw [div_eq_mul_inv, mul_inv_rev, inv_inv, hbd.symm.eq, hcd.symm.eq,
hbc.inv_inv.mul_mul_mul_comm]
end DivisionMonoid
section Group
variable [Group G] {a b : G}
@[to_additive (attr := simp)]
lemma inv_left_iff : Commute a⁻¹ b ↔ Commute a b := SemiconjBy.inv_symm_left_iff
@[to_additive] alias ⟨_, inv_left⟩ := inv_left_iff
@[to_additive (attr := simp)]
lemma inv_right_iff : Commute a b⁻¹ ↔ Commute a b := SemiconjBy.inv_right_iff
@[to_additive] alias ⟨_, inv_right⟩ := inv_right_iff
@[to_additive]
protected lemma inv_mul_cancel (h : Commute a b) : a⁻¹ * b * a = b := by
rw [h.inv_left.eq, inv_mul_cancel_right]
@[to_additive]
lemma inv_mul_cancel_assoc (h : Commute a b) : a⁻¹ * (b * a) = b := by
rw [← mul_assoc, h.inv_mul_cancel]
@[to_additive (attr := simp)]
protected theorem conj_iff (h : G) : Commute (h * a * h⁻¹) (h * b * h⁻¹) ↔ Commute a b :=
SemiconjBy.conj_iff
@[to_additive]
protected theorem conj (comm : Commute a b) (h : G) : Commute (h * a * h⁻¹) (h * b * h⁻¹) :=
(Commute.conj_iff h).mpr comm
@[to_additive (attr := simp)]
lemma zpow_right (h : Commute a b) (m : ℤ) : Commute a (b ^ m) := SemiconjBy.zpow_right h m
@[to_additive (attr := simp)]
lemma zpow_left (h : Commute a b) (m : ℤ) : Commute (a ^ m) b := (h.symm.zpow_right m).symm
@[to_additive] lemma zpow_zpow (h : Commute a b) (m n : ℤ) : Commute (a ^ m) (b ^ n) :=
(h.zpow_left m).zpow_right n
variable (a) (m n : ℤ)
@[to_additive] lemma self_zpow : Commute a (a ^ n) := (Commute.refl a).zpow_right n
@[to_additive] lemma zpow_self : Commute (a ^ n) a := (Commute.refl a).zpow_left n
@[to_additive] lemma zpow_zpow_self : Commute (a ^ m) (a ^ n) := (Commute.refl a).zpow_zpow m n
end Group
end Commute
section Group
variable [Group G]
@[to_additive] lemma pow_inv_comm (a : G) (m n : ℕ) : a⁻¹ ^ m * a ^ n = a ^ n * a⁻¹ ^ m :=
(Commute.refl a).inv_left.pow_pow _ _
end Group |
.lake/packages/mathlib/Mathlib/Algebra/Group/Commute/Defs.lean | import Mathlib.Algebra.Group.Semiconj.Defs
/-!
# Commuting pairs of elements in monoids
We define the predicate `Commute a b := a * b = b * a` and provide some operations on terms
`(h : Commute a b)`. E.g., if `a`, `b`, and c are elements of a semiring, and that
`hb : Commute a b` and `hc : Commute a c`. Then `hb.pow_left 5` proves `Commute (a ^ 5) b` and
`(hb.pow_right 2).add_right (hb.mul_right hc)` proves `Commute a (b ^ 2 + b * c)`.
Lean does not immediately recognise these terms as equations, so for rewriting we need syntax like
`rw [(hb.pow_left 5).eq]` rather than just `rw [hb.pow_left 5]`.
This file defines only a few operations (`mul_left`, `inv_right`, etc). Other operations
(`pow_right`, field inverse etc) are in the files that define corresponding notions.
## Implementation details
Most of the proofs come from the properties of `SemiconjBy`.
-/
assert_not_exists MonoidWithZero DenselyOrdered
variable {G M S : Type*}
/-- Two elements commute if `a * b = b * a`. -/
@[to_additive /-- Two elements additively commute if `a + b = b + a` -/]
def Commute [Mul S] (a b : S) : Prop :=
SemiconjBy a b b
/--
Two elements `a` and `b` commute if `a * b = b * a`.
-/
@[to_additive]
theorem commute_iff_eq [Mul S] (a b : S) : Commute a b ↔ a * b = b * a := Iff.rfl
namespace Commute
section Mul
variable [Mul S]
/-- Equality behind `Commute a b`; useful for rewriting. -/
@[to_additive /-- Equality behind `AddCommute a b`; useful for rewriting. -/]
protected theorem eq {a b : S} (h : Commute a b) : a * b = b * a :=
h
/-- Any element commutes with itself. -/
@[to_additive (attr := refl, simp) /-- Any element commutes with itself. -/]
protected theorem refl (a : S) : Commute a a :=
Eq.refl (a * a)
/-- If `a` commutes with `b`, then `b` commutes with `a`. -/
@[to_additive (attr := symm) /-- If `a` commutes with `b`, then `b` commutes with `a`. -/]
protected theorem symm {a b : S} (h : Commute a b) : Commute b a :=
Eq.symm h
@[to_additive]
protected theorem semiconjBy {a b : S} (h : Commute a b) : SemiconjBy a b b :=
h
@[to_additive]
protected theorem symm_iff {a b : S} : Commute a b ↔ Commute b a :=
⟨Commute.symm, Commute.symm⟩
@[to_additive]
instance : IsRefl S Commute :=
⟨Commute.refl⟩
-- This instance is useful for `Finset.noncommProd`
@[to_additive]
instance on_isRefl {f : G → S} : IsRefl G fun a b => Commute (f a) (f b) :=
⟨fun _ => Commute.refl _⟩
end Mul
section Semigroup
variable [Semigroup S] {a b c : S}
/-- If `a` commutes with both `b` and `c`, then it commutes with their product. -/
@[to_additive (attr := simp)
/-- If `a` commutes with both `b` and `c`, then it commutes with their sum. -/]
theorem mul_right (hab : Commute a b) (hac : Commute a c) : Commute a (b * c) :=
SemiconjBy.mul_right hab hac
/-- If both `a` and `b` commute with `c`, then their product commutes with `c`. -/
@[to_additive (attr := simp)
/-- If both `a` and `b` commute with `c`, then their product commutes with `c`. -/]
theorem mul_left (hac : Commute a c) (hbc : Commute b c) : Commute (a * b) c :=
SemiconjBy.mul_left hac hbc
@[to_additive]
protected theorem right_comm (h : Commute b c) (a : S) : a * b * c = a * c * b := by
simp only [mul_assoc, h.eq]
@[to_additive]
protected theorem left_comm (h : Commute a b) (c) : a * (b * c) = b * (a * c) := by
simp only [← mul_assoc, h.eq]
@[to_additive]
protected theorem mul_mul_mul_comm (hbc : Commute b c) (a d : S) :
a * b * (c * d) = a * c * (b * d) := by simp only [hbc.left_comm, mul_assoc]
end Semigroup
@[to_additive]
protected theorem all [CommMagma S] (a b : S) : Commute a b :=
mul_comm a b
section MulOneClass
variable [MulOneClass M]
@[to_additive (attr := simp)]
theorem one_right (a : M) : Commute a 1 :=
SemiconjBy.one_right a
@[to_additive (attr := simp)]
theorem one_left (a : M) : Commute 1 a :=
SemiconjBy.one_left a
end MulOneClass
section Monoid
variable [Monoid M] {a b : M}
@[to_additive (attr := simp)]
theorem pow_right (h : Commute a b) (n : ℕ) : Commute a (b ^ n) :=
SemiconjBy.pow_right h n
@[to_additive (attr := simp)]
theorem pow_left (h : Commute a b) (n : ℕ) : Commute (a ^ n) b :=
(h.symm.pow_right n).symm
-- todo: should nat power be called `nsmul` here?
@[to_additive]
theorem pow_pow (h : Commute a b) (m n : ℕ) : Commute (a ^ m) (b ^ n) := by
simp [h]
@[to_additive]
theorem self_pow (a : M) (n : ℕ) : Commute a (a ^ n) :=
(Commute.refl a).pow_right n
@[to_additive]
theorem pow_self (a : M) (n : ℕ) : Commute (a ^ n) a :=
(Commute.refl a).pow_left n
@[to_additive]
theorem pow_pow_self (a : M) (m n : ℕ) : Commute (a ^ m) (a ^ n) :=
(Commute.refl a).pow_pow m n
@[to_additive] lemma mul_pow (h : Commute a b) : ∀ n, (a * b) ^ n = a ^ n * b ^ n
| 0 => by rw [pow_zero, pow_zero, pow_zero, one_mul]
| n + 1 => by simp only [pow_succ', h.mul_pow n, ← mul_assoc, (h.pow_left n).right_comm]
end Monoid
section DivisionMonoid
variable [DivisionMonoid G] {a b : G}
@[to_additive]
protected theorem mul_inv (hab : Commute a b) : (a * b)⁻¹ = a⁻¹ * b⁻¹ := by rw [hab.eq, mul_inv_rev]
@[to_additive]
protected theorem inv (hab : Commute a b) : (a * b)⁻¹ = a⁻¹ * b⁻¹ := by rw [hab.eq, mul_inv_rev]
@[to_additive AddCommute.zsmul_add]
protected lemma mul_zpow (h : Commute a b) : ∀ n : ℤ, (a * b) ^ n = a ^ n * b ^ n
| (n : ℕ) => by simp [zpow_natCast, h.mul_pow n]
| .negSucc n => by simp [h.mul_pow, (h.pow_pow _ _).eq, mul_inv_rev]
end DivisionMonoid
section Group
variable [Group G] {a b : G}
@[to_additive]
protected theorem mul_inv_cancel (h : Commute a b) : a * b * a⁻¹ = b := by
rw [h.eq, mul_inv_cancel_right]
@[to_additive]
theorem mul_inv_cancel_assoc (h : Commute a b) : a * (b * a⁻¹) = b := by
rw [← mul_assoc, h.mul_inv_cancel]
end Group
end Commute |
.lake/packages/mathlib/Mathlib/Algebra/Group/Commute/Units.lean | import Mathlib.Algebra.Group.Commute.Defs
import Mathlib.Algebra.Group.Semiconj.Units
/-!
# Lemmas about commuting pairs of elements involving units.
-/
assert_not_exists MonoidWithZero DenselyOrdered
variable {M : Type*}
section Monoid
variable [Monoid M] {n : ℕ} {a b : M} {u u₁ u₂ : Mˣ}
namespace Commute
@[to_additive]
theorem units_inv_right : Commute a u → Commute a ↑u⁻¹ :=
SemiconjBy.units_inv_right
@[to_additive (attr := simp)]
theorem units_inv_right_iff : Commute a ↑u⁻¹ ↔ Commute a u :=
SemiconjBy.units_inv_right_iff
@[to_additive]
theorem units_inv_left : Commute (↑u) a → Commute (↑u⁻¹) a :=
SemiconjBy.units_inv_symm_left
@[to_additive (attr := simp)]
theorem units_inv_left_iff : Commute (↑u⁻¹) a ↔ Commute (↑u) a :=
SemiconjBy.units_inv_symm_left_iff
@[to_additive]
theorem units_val : Commute u₁ u₂ → Commute (u₁ : M) u₂ :=
SemiconjBy.units_val
@[to_additive]
theorem units_of_val : Commute (u₁ : M) u₂ → Commute u₁ u₂ :=
SemiconjBy.units_of_val
@[to_additive (attr := simp)]
theorem units_val_iff : Commute (u₁ : M) u₂ ↔ Commute u₁ u₂ :=
SemiconjBy.units_val_iff
end Commute
/-- If the product of two commuting elements is a unit, then the left multiplier is a unit. -/
@[to_additive /-- If the sum of two commuting elements is an additive unit, then the left summand is
an additive unit. -/]
def Units.leftOfMul (u : Mˣ) (a b : M) (hu : a * b = u) (hc : Commute a b) : Mˣ where
val := a
inv := b * ↑u⁻¹
val_inv := by rw [← mul_assoc, hu, u.mul_inv]
inv_val := by
have : Commute a u := hu ▸ (Commute.refl _).mul_right hc
rw [← this.units_inv_right.right_comm, ← hc.eq, hu, u.mul_inv]
/-- If the product of two commuting elements is a unit, then the right multiplier is a unit. -/
@[to_additive /-- If the sum of two commuting elements is an additive unit, then the right summand
is an additive unit. -/]
def Units.rightOfMul (u : Mˣ) (a b : M) (hu : a * b = u) (hc : Commute a b) : Mˣ :=
u.leftOfMul b a (hc.eq ▸ hu) hc.symm
@[to_additive]
theorem Commute.isUnit_mul_iff (h : Commute a b) : IsUnit (a * b) ↔ IsUnit a ∧ IsUnit b :=
⟨fun ⟨u, hu⟩ => ⟨(u.leftOfMul a b hu.symm h).isUnit, (u.rightOfMul a b hu.symm h).isUnit⟩,
fun H => H.1.mul H.2⟩
@[to_additive (attr := simp)]
theorem isUnit_mul_self_iff : IsUnit (a * a) ↔ IsUnit a :=
(Commute.refl a).isUnit_mul_iff.trans and_self_iff
@[to_additive (attr := simp)]
lemma Commute.units_zpow_right (h : Commute a u) (m : ℤ) : Commute a ↑(u ^ m) :=
SemiconjBy.units_zpow_right h m
@[to_additive (attr := simp)]
lemma Commute.units_zpow_left (h : Commute ↑u a) (m : ℤ) : Commute ↑(u ^ m) a :=
(h.symm.units_zpow_right m).symm
/-- If a natural power of `x` is a unit, then `x` is a unit. -/
@[to_additive
/-- If a natural multiple of `x` is an additive unit, then `x` is an additive unit. -/]
def Units.ofPow (u : Mˣ) (x : M) {n : ℕ} (hn : n ≠ 0) (hu : x ^ n = u) : Mˣ :=
u.leftOfMul x (x ^ (n - 1))
(by rwa [← _root_.pow_succ', Nat.sub_add_cancel (Nat.succ_le_of_lt <| Nat.pos_of_ne_zero hn)])
(Commute.self_pow _ _)
@[to_additive (attr := simp)] lemma isUnit_pow_iff (hn : n ≠ 0) : IsUnit (a ^ n) ↔ IsUnit a :=
⟨fun ⟨u, hu⟩ ↦ (u.ofPow a hn hu.symm).isUnit, IsUnit.pow n⟩
@[to_additive]
lemma isUnit_pow_succ_iff : IsUnit (a ^ (n + 1)) ↔ IsUnit a := isUnit_pow_iff n.succ_ne_zero
lemma isUnit_pow_iff_of_not_isUnit (hx : ¬ IsUnit a) {n : ℕ} :
IsUnit (a ^ n) ↔ n = 0 := by
rcases n with (_ | n) <;>
simp [hx]
/-- If `a ^ n = 1`, `n ≠ 0`, then `a` is a unit. -/
@[to_additive (attr := simps!) /-- If `n • x = 0`, `n ≠ 0`, then `x` is an additive unit. -/]
def Units.ofPowEqOne (a : M) (n : ℕ) (ha : a ^ n = 1) (hn : n ≠ 0) : Mˣ := Units.ofPow 1 a hn ha
@[to_additive (attr := simp)]
lemma Units.pow_ofPowEqOne (ha : a ^ n = 1) (hn : n ≠ 0) :
Units.ofPowEqOne _ n ha hn ^ n = 1 := Units.ext <| by simp [ha]
@[to_additive]
lemma IsUnit.of_pow_eq_one (ha : a ^ n = 1) (hn : n ≠ 0) : IsUnit a :=
(Units.ofPowEqOne _ n ha hn).isUnit
@[to_additive]
lemma _root_.Units.commute_iff_inv_mul_cancel {u : Mˣ} {a : M} :
Commute ↑u a ↔ ↑u⁻¹ * a * u = a := by
rw [mul_assoc, Units.inv_mul_eq_iff_eq_mul, eq_comm, Commute, SemiconjBy]
@[to_additive]
lemma _root_.Units.commute_iff_inv_mul_cancel_assoc {u : Mˣ} {a : M} :
Commute ↑u a ↔ ↑u⁻¹ * (a * u) = a := by
rw [u.commute_iff_inv_mul_cancel, mul_assoc]
@[to_additive]
lemma _root_.Units.commute_iff_mul_inv_cancel {u : Mˣ} {a : M} :
Commute ↑u a ↔ ↑u * a * ↑u⁻¹ = a := by
rw [Units.mul_inv_eq_iff_eq_mul, Commute, SemiconjBy]
@[to_additive]
lemma _root_.Units.commute_iff_mul_inv_cancel_assoc {u : Mˣ} {a : M} :
Commute ↑u a ↔ ↑u * (a * ↑u⁻¹) = a := by
rw [u.commute_iff_mul_inv_cancel, mul_assoc]
end Monoid
namespace Commute
variable [DivisionMonoid M] {a b c d : M}
@[to_additive]
lemma div_eq_div_iff_of_isUnit (hbd : Commute b d) (hb : IsUnit b) (hd : IsUnit d) :
a / b = c / d ↔ a * d = c * b := by
rw [← (hb.mul hd).mul_left_inj, ← mul_assoc, hb.div_mul_cancel, ← mul_assoc, hbd.right_comm,
hd.div_mul_cancel]
@[to_additive]
lemma mul_inv_eq_mul_inv_iff_of_isUnit (hbd : Commute b d) (hb : IsUnit b) (hd : IsUnit d) :
a * b⁻¹ = c * d⁻¹ ↔ a * d = c * b := by
rw [← div_eq_mul_inv, ← div_eq_mul_inv, hbd.div_eq_div_iff_of_isUnit hb hd]
@[to_additive]
lemma inv_mul_eq_inv_mul_iff_of_isUnit (hbd : Commute b d) (hb : IsUnit b) (hd : IsUnit d) :
b⁻¹ * a = d⁻¹ * c ↔ d * a = b * c := by
rw [← (hd.mul hb).mul_right_inj, ← mul_assoc, mul_assoc d, hb.mul_inv_cancel, mul_one,
← mul_assoc, mul_assoc d, hbd.symm.left_comm, hd.mul_inv_cancel, mul_one]
end Commute |
.lake/packages/mathlib/Mathlib/Algebra/Group/Commute/Hom.lean | import Mathlib.Algebra.Group.Commute.Defs
import Mathlib.Algebra.Group.Hom.Defs
/-!
# Multiplicative homomorphisms respect semiconjugation and commutation.
-/
assert_not_exists MonoidWithZero DenselyOrdered
section Commute
variable {F M N : Type*} [Mul M] [Mul N] {a x y : M} [FunLike F M N]
@[to_additive (attr := simp)]
protected theorem SemiconjBy.map [MulHomClass F M N] (h : SemiconjBy a x y) (f : F) :
SemiconjBy (f a) (f x) (f y) := by simpa only [SemiconjBy, map_mul] using congr_arg f h
@[to_additive (attr := simp)]
protected theorem Commute.map [MulHomClass F M N] (h : Commute x y) (f : F) : Commute (f x) (f y) :=
SemiconjBy.map h f
@[to_additive]
protected theorem SemiconjBy.of_map [MulHomClass F M N] {f : F} (hf : Function.Injective f)
(h : SemiconjBy (f a) (f x) (f y)) : SemiconjBy a x y :=
hf (by simpa only [SemiconjBy, map_mul] using h)
@[to_additive]
theorem Commute.of_map [MulHomClass F M N] {f : F} (hf : Function.Injective f)
(h : Commute (f x) (f y)) : Commute x y :=
hf (by simpa only [map_mul] using h.eq)
@[to_additive]
theorem semiconjBy_map_iff [MulHomClass F M N] {f : F} (hf : Function.Injective f) {x y : M} :
SemiconjBy (f a) (f x) (f y) ↔ SemiconjBy a x y :=
⟨.of_map hf, (.map · f)⟩
@[to_additive]
theorem commute_map_iff [MulHomClass F M N] {f : F} (hf : Function.Injective f) {x y : M} :
Commute (f x) (f y) ↔ Commute x y :=
⟨.of_map hf, (.map · f)⟩
end Commute |
.lake/packages/mathlib/Mathlib/Algebra/Group/Semiconj/Basic.lean | import Mathlib.Algebra.Group.Semiconj.Defs
import Mathlib.Algebra.Group.Basic
/-!
# Lemmas about semiconjugate elements of a group
-/
assert_not_exists MonoidWithZero DenselyOrdered
namespace SemiconjBy
variable {G : Type*}
section DivisionMonoid
variable [DivisionMonoid G] {a x y : G}
@[to_additive (attr := simp)]
theorem inv_inv_symm_iff : SemiconjBy a⁻¹ x⁻¹ y⁻¹ ↔ SemiconjBy a y x := by
simp_rw [SemiconjBy, ← mul_inv_rev, inv_inj, eq_comm]
@[to_additive] alias ⟨_, inv_inv_symm⟩ := inv_inv_symm_iff
end DivisionMonoid
section Group
variable [Group G] {a x y : G}
@[to_additive (attr := simp)] lemma inv_symm_left_iff : SemiconjBy a⁻¹ y x ↔ SemiconjBy a x y := by
simp_rw [SemiconjBy, eq_mul_inv_iff_mul_eq, mul_assoc, inv_mul_eq_iff_eq_mul, eq_comm]
@[to_additive] alias ⟨_, inv_symm_left⟩ := inv_symm_left_iff
@[to_additive (attr := simp)] lemma inv_right_iff : SemiconjBy a x⁻¹ y⁻¹ ↔ SemiconjBy a x y := by
rw [← inv_symm_left_iff, inv_inv_symm_iff]
@[to_additive] alias ⟨_, inv_right⟩ := inv_right_iff
@[to_additive (attr := simp)] lemma zpow_right (h : SemiconjBy a x y) :
∀ m : ℤ, SemiconjBy a (x ^ m) (y ^ m)
| (n : ℕ) => by simp [zpow_natCast, h.pow_right n]
| .negSucc n => by
simp only [zpow_negSucc, inv_right_iff]
apply pow_right h
variable (a) in
@[to_additive] lemma eq_one_iff (h : SemiconjBy a x y) : x = 1 ↔ y = 1 := by
rw [← conj_eq_one_iff (a := a) (b := x), h.eq, mul_inv_cancel_right]
end Group
end SemiconjBy |
.lake/packages/mathlib/Mathlib/Algebra/Group/Semiconj/Defs.lean | -- Some proofs and docs came from mathlib3 `src/algebra/commute.lean` (c) Neil Strickland
import Mathlib.Algebra.Group.Defs
import Mathlib.Order.Defs.Unbundled
/-!
# Semiconjugate elements of a semigroup
## Main definitions
We say that `x` is semiconjugate to `y` by `a` (`SemiconjBy a x y`), if `a * x = y * a`.
In this file we provide operations on `SemiconjBy _ _ _`.
In the names of these operations, we treat `a` as the “left” argument, and both `x` and `y` as
“right” arguments. This way most names in this file agree with the names of the corresponding lemmas
for `Commute a b = SemiconjBy a b b`. As a side effect, some lemmas have only `_right` version.
Lean does not immediately recognise these terms as equations, so for rewriting we need syntax like
`rw [(h.pow_right 5).eq]` rather than just `rw [h.pow_right 5]`.
This file provides only basic operations (`mul_left`, `mul_right`, `inv_right` etc). Other
operations (`pow_right`, field inverse etc) are in the files that define corresponding notions.
-/
assert_not_exists MonoidWithZero DenselyOrdered
variable {S M G : Type*}
/-- `x` is semiconjugate to `y` by `a`, if `a * x = y * a`. -/
@[to_additive /-- `x` is additive semiconjugate to `y` by `a` if `a + x = y + a` -/]
def SemiconjBy [Mul M] (a x y : M) : Prop :=
a * x = y * a
namespace SemiconjBy
/-- Equality behind `SemiconjBy a x y`; useful for rewriting. -/
@[to_additive /-- Equality behind `AddSemiconjBy a x y`; useful for rewriting. -/]
protected theorem eq [Mul S] {a x y : S} (h : SemiconjBy a x y) : a * x = y * a :=
h
section Semigroup
variable [Semigroup S] {a b x y z x' y' : S}
/-- If `a` semiconjugates `x` to `y` and `x'` to `y'`,
then it semiconjugates `x * x'` to `y * y'`. -/
@[to_additive (attr := simp) /-- If `a` semiconjugates `x` to `y` and `x'` to `y'`,
then it semiconjugates `x + x'` to `y + y'`. -/]
theorem mul_right (h : SemiconjBy a x y) (h' : SemiconjBy a x' y') :
SemiconjBy a (x * x') (y * y') := by
unfold SemiconjBy
-- TODO this could be done using `assoc_rw` if/when this is ported to mathlib4
rw [← mul_assoc, h.eq, mul_assoc, h'.eq, ← mul_assoc]
/-- If `b` semiconjugates `x` to `y` and `a` semiconjugates `y` to `z`, then `a * b`
semiconjugates `x` to `z`. -/
@[to_additive /-- If `b` semiconjugates `x` to `y` and `a` semiconjugates `y` to `z`, then `a + b`
semiconjugates `x` to `z`. -/]
theorem mul_left (ha : SemiconjBy a y z) (hb : SemiconjBy b x y) : SemiconjBy (a * b) x z := by
unfold SemiconjBy
rw [mul_assoc, hb.eq, ← mul_assoc, ha.eq, mul_assoc]
/-- The relation “there exists an element that semiconjugates `a` to `b`” on a semigroup
is transitive. -/
@[to_additive /-- The relation “there exists an element that semiconjugates `a` to `b`” on an
additive semigroup is transitive. -/]
protected theorem transitive : Transitive fun a b : S ↦ ∃ c, SemiconjBy c a b
| _, _, _, ⟨x, hx⟩, ⟨y, hy⟩ => ⟨y * x, hy.mul_left hx⟩
end Semigroup
section MulOneClass
variable [MulOneClass M]
/-- Any element semiconjugates `1` to `1`. -/
@[to_additive (attr := simp) /-- Any element semiconjugates `0` to `0`. -/]
theorem one_right (a : M) : SemiconjBy a 1 1 := by rw [SemiconjBy, mul_one, one_mul]
/-- One semiconjugates any element to itself. -/
@[to_additive (attr := simp) /-- Zero semiconjugates any element to itself. -/]
theorem one_left (x : M) : SemiconjBy 1 x x :=
Eq.symm <| one_right x
/-- The relation “there exists an element that semiconjugates `a` to `b`” on a monoid (or, more
generally, on `MulOneClass` type) is reflexive. -/
@[to_additive /-- The relation “there exists an element that semiconjugates `a` to `b`” on an
additive monoid (or, more generally, on an `AddZeroClass` type) is reflexive. -/]
protected theorem reflexive : Reflexive fun a b : M ↦ ∃ c, SemiconjBy c a b
| a => ⟨1, one_left a⟩
end MulOneClass
section Monoid
variable [Monoid M]
@[to_additive (attr := simp)]
theorem pow_right {a x y : M} (h : SemiconjBy a x y) (n : ℕ) : SemiconjBy a (x ^ n) (y ^ n) := by
induction n with
| zero =>
rw [pow_zero, pow_zero]
exact SemiconjBy.one_right _
| succ n ih =>
rw [pow_succ, pow_succ]
exact ih.mul_right h
end Monoid
section Group
variable [Group G]
/-- `a` semiconjugates `x` to `a * x * a⁻¹`. -/
@[to_additive /-- `a` semiconjugates `x` to `a + x + -a`. -/]
theorem conj_mk (a x : G) : SemiconjBy a x (a * x * a⁻¹) := by
unfold SemiconjBy; rw [mul_assoc, inv_mul_cancel, mul_one]
@[to_additive (attr := simp)]
theorem conj_iff {a x y b : G} :
SemiconjBy (b * a * b⁻¹) (b * x * b⁻¹) (b * y * b⁻¹) ↔ SemiconjBy a x y := by
unfold SemiconjBy
simp only [← mul_assoc, inv_mul_cancel_right]
repeat rw [mul_assoc]
rw [mul_left_cancel_iff, ← mul_assoc, ← mul_assoc, mul_right_cancel_iff]
end Group
end SemiconjBy
@[to_additive (attr := simp)]
theorem semiconjBy_iff_eq [CancelCommMonoid M] {a x y : M} : SemiconjBy a x y ↔ x = y :=
⟨fun h => mul_left_cancel (h.trans (mul_comm _ _)), fun h => by rw [h, SemiconjBy, mul_comm]⟩ |
.lake/packages/mathlib/Mathlib/Algebra/Group/Semiconj/Units.lean | -- Some proofs and docs came from mathlib3 `src/algebra/commute.lean` (c) Neil Strickland
import Mathlib.Algebra.Group.Semiconj.Defs
import Mathlib.Algebra.Group.Units.Basic
/-!
# Semiconjugate elements of a semigroup
## Main definitions
We say that `x` is semiconjugate to `y` by `a` (`SemiconjBy a x y`), if `a * x = y * a`.
In this file we provide operations on `SemiconjBy _ _ _`.
In the names of these operations, we treat `a` as the “left” argument, and both `x` and `y` as
“right” arguments. This way most names in this file agree with the names of the corresponding lemmas
for `Commute a b = SemiconjBy a b b`. As a side effect, some lemmas have only `_right` version.
Lean does not immediately recognise these terms as equations, so for rewriting we need syntax like
`rw [(h.pow_right 5).eq]` rather than just `rw [h.pow_right 5]`.
This file provides only basic operations (`mul_left`, `mul_right`, `inv_right` etc). Other
operations (`pow_right`, field inverse etc) are in the files that define corresponding notions.
-/
assert_not_exists MonoidWithZero DenselyOrdered
open scoped Int
variable {M : Type*}
namespace SemiconjBy
section Monoid
variable [Monoid M]
/-- If `a` semiconjugates a unit `x` to a unit `y`, then it semiconjugates `x⁻¹` to `y⁻¹`. -/
@[to_additive /-- If `a` semiconjugates an additive unit `x` to an additive unit `y`, then it
semiconjugates `-x` to `-y`. -/]
theorem units_inv_right {a : M} {x y : Mˣ} (h : SemiconjBy a x y) : SemiconjBy a ↑x⁻¹ ↑y⁻¹ :=
calc a * ↑x⁻¹
_ = ↑y⁻¹ * (y * a) * ↑x⁻¹ := by rw [Units.inv_mul_cancel_left]
_ = ↑y⁻¹ * a := by rw [← h.eq, mul_assoc, Units.mul_inv_cancel_right]
@[to_additive (attr := simp)]
theorem units_inv_right_iff {a : M} {x y : Mˣ} : SemiconjBy a ↑x⁻¹ ↑y⁻¹ ↔ SemiconjBy a x y :=
⟨units_inv_right, units_inv_right⟩
/-- If a unit `a` semiconjugates `x` to `y`, then `a⁻¹` semiconjugates `y` to `x`. -/
@[to_additive /-- If an additive unit `a` semiconjugates `x` to `y`, then `-a` semiconjugates `y` to
`x`. -/]
theorem units_inv_symm_left {a : Mˣ} {x y : M} (h : SemiconjBy (↑a) x y) : SemiconjBy (↑a⁻¹) y x :=
calc
↑a⁻¹ * y = ↑a⁻¹ * (y * a * ↑a⁻¹) := by rw [Units.mul_inv_cancel_right]
_ = x * ↑a⁻¹ := by rw [← h.eq, ← mul_assoc, Units.inv_mul_cancel_left]
@[to_additive (attr := simp)]
theorem units_inv_symm_left_iff {a : Mˣ} {x y : M} : SemiconjBy (↑a⁻¹) y x ↔ SemiconjBy (↑a) x y :=
⟨units_inv_symm_left, units_inv_symm_left⟩
@[to_additive]
theorem units_val {a x y : Mˣ} (h : SemiconjBy a x y) : SemiconjBy (a : M) x y :=
congr_arg Units.val h
@[to_additive]
theorem units_of_val {a x y : Mˣ} (h : SemiconjBy (a : M) x y) : SemiconjBy a x y :=
Units.ext h
@[to_additive (attr := simp)]
theorem units_val_iff {a x y : Mˣ} : SemiconjBy (a : M) x y ↔ SemiconjBy a x y :=
⟨units_of_val, units_val⟩
@[to_additive (attr := simp)]
lemma units_zpow_right {a : M} {x y : Mˣ} (h : SemiconjBy a x y) :
∀ m : ℤ, SemiconjBy a ↑(x ^ m) ↑(y ^ m)
| (n : ℕ) => by simp only [zpow_natCast, Units.val_pow_eq_pow_val, h, pow_right]
| -[n+1] => by simp only [zpow_negSucc, Units.val_pow_eq_pow_val, units_inv_right, h, pow_right]
end Monoid
end SemiconjBy
namespace Units
variable [Monoid M]
/-- `a` semiconjugates `x` to `a * x * a⁻¹`. -/
@[to_additive /-- `a` semiconjugates `x` to `a + x + -a`. -/]
lemma mk_semiconjBy (u : Mˣ) (x : M) : SemiconjBy (↑u) x (u * x * ↑u⁻¹) := by
unfold SemiconjBy; rw [Units.inv_mul_cancel_right]
lemma conj_pow (u : Mˣ) (x : M) (n : ℕ) :
((↑u : M) * x * (↑u⁻¹ : M)) ^ n = (u : M) * x ^ n * (↑u⁻¹ : M) :=
eq_divp_iff_mul_eq.2 ((u.mk_semiconjBy x).pow_right n).eq.symm
lemma conj_pow' (u : Mˣ) (x : M) (n : ℕ) :
((↑u⁻¹ : M) * x * (u : M)) ^ n = (↑u⁻¹ : M) * x ^ n * (u : M) := u⁻¹.conj_pow x n
end Units |
.lake/packages/mathlib/Mathlib/Algebra/Group/Subgroup/Finite.lean | import Mathlib.Algebra.Group.Subgroup.Basic
import Mathlib.Algebra.Group.Submonoid.BigOperators
import Mathlib.Algebra.Group.Submonoid.Finite
import Mathlib.Data.Finite.Card
import Mathlib.Data.Set.Finite.Range
/-!
# Subgroups
This file provides some result on multiplicative and additive subgroups in the finite context.
## Tags
subgroup, subgroups
-/
assert_not_exists Field
variable {G : Type*} [Group G]
variable {A : Type*} [AddGroup A]
namespace Subgroup
@[to_additive]
instance (K : Subgroup G) [DecidablePred (· ∈ K)] [Fintype G] : Fintype K :=
show Fintype { g : G // g ∈ K } from inferInstance
@[to_additive]
instance (K : Subgroup G) [Finite G] : Finite K :=
Subtype.finite
end Subgroup
/-!
### Conversion to/from `Additive`/`Multiplicative`
-/
namespace Subgroup
variable (H K : Subgroup G)
/-- Product of a list of elements in a subgroup is in the subgroup. -/
@[to_additive /-- Sum of a list of elements in an `AddSubgroup` is in the `AddSubgroup`. -/]
protected theorem list_prod_mem {l : List G} : (∀ x ∈ l, x ∈ K) → l.prod ∈ K :=
list_prod_mem
/-- Product of a multiset of elements in a subgroup of a `CommGroup` is in the subgroup. -/
@[to_additive /-- Sum of a multiset of elements in an `AddSubgroup` of an `AddCommGroup` is in
the `AddSubgroup`. -/]
protected theorem multiset_prod_mem {G} [CommGroup G] (K : Subgroup G) (g : Multiset G) :
(∀ a ∈ g, a ∈ K) → g.prod ∈ K :=
multiset_prod_mem g
@[to_additive]
theorem multiset_noncommProd_mem (K : Subgroup G) (g : Multiset G) (comm) :
(∀ a ∈ g, a ∈ K) → g.noncommProd comm ∈ K :=
K.toSubmonoid.multiset_noncommProd_mem g comm
/-- Product of elements of a subgroup of a `CommGroup` indexed by a `Finset` is in the
subgroup. -/
@[to_additive /-- Sum of elements in an `AddSubgroup` of an `AddCommGroup` indexed by a `Finset`
is in the `AddSubgroup`. -/]
protected theorem prod_mem {G : Type*} [CommGroup G] (K : Subgroup G) {ι : Type*} {t : Finset ι}
{f : ι → G} (h : ∀ c ∈ t, f c ∈ K) : (∏ c ∈ t, f c) ∈ K :=
prod_mem h
@[to_additive]
theorem noncommProd_mem (K : Subgroup G) {ι : Type*} {t : Finset ι} {f : ι → G} (comm) :
(∀ c ∈ t, f c ∈ K) → t.noncommProd f comm ∈ K :=
K.toSubmonoid.noncommProd_mem t f comm
@[to_additive (attr := simp 1100, norm_cast)]
theorem val_list_prod (l : List H) : (l.prod : G) = (l.map Subtype.val).prod :=
SubmonoidClass.coe_list_prod l
@[to_additive (attr := simp 1100, norm_cast)]
theorem val_multiset_prod {G} [CommGroup G] (H : Subgroup G) (m : Multiset H) :
(m.prod : G) = (m.map Subtype.val).prod :=
SubmonoidClass.coe_multiset_prod m
@[to_additive (attr := simp 1100, norm_cast)]
theorem val_finset_prod {ι G} [CommGroup G] (H : Subgroup G) (f : ι → H) (s : Finset ι) :
↑(∏ i ∈ s, f i) = (∏ i ∈ s, f i : G) :=
SubmonoidClass.coe_finset_prod f s
@[to_additive]
instance fintypeBot : Fintype (⊥ : Subgroup G) :=
⟨{1}, by
rintro ⟨x, ⟨hx⟩⟩
exact Finset.mem_singleton_self _⟩
@[to_additive]
theorem card_bot : Nat.card (⊥ : Subgroup G) = 1 := by simp
@[to_additive]
theorem card_top : Nat.card (⊤ : Subgroup G) = Nat.card G :=
Nat.card_congr Subgroup.topEquiv.toEquiv
@[to_additive]
theorem eq_of_le_of_card_ge {H K : Subgroup G} [Finite K] (hle : H ≤ K)
(hcard : Nat.card K ≤ Nat.card H) :
H = K :=
SetLike.coe_injective <| Set.Finite.eq_of_subset_of_card_le (Set.toFinite _) hle hcard
@[to_additive]
theorem eq_top_of_le_card [Finite G] (h : Nat.card G ≤ Nat.card H) : H = ⊤ :=
eq_of_le_of_card_ge le_top (Nat.card_congr (Equiv.Set.univ G) ▸ h)
@[to_additive]
theorem eq_top_of_card_eq [Finite H] (h : Nat.card H = Nat.card G) : H = ⊤ := by
have : Finite G := Nat.finite_of_card_ne_zero (h ▸ Nat.card_pos.ne')
exact eq_top_of_le_card _ (Nat.le_of_eq h.symm)
@[to_additive (attr := simp)]
theorem card_eq_iff_eq_top [Finite H] : Nat.card H = Nat.card G ↔ H = ⊤ :=
Iff.intro (eq_top_of_card_eq H) (fun h ↦ by simpa only [h] using card_top)
@[to_additive]
theorem eq_bot_of_card_le [Finite H] (h : Nat.card H ≤ 1) : H = ⊥ :=
let _ := Finite.card_le_one_iff_subsingleton.mp h
eq_bot_of_subsingleton H
@[to_additive]
theorem eq_bot_of_card_eq (h : Nat.card H = 1) : H = ⊥ :=
let _ := (Nat.card_eq_one_iff_unique.mp h).1
eq_bot_of_subsingleton H
@[to_additive card_le_one_iff_eq_bot]
theorem card_le_one_iff_eq_bot [Finite H] : Nat.card H ≤ 1 ↔ H = ⊥ :=
⟨H.eq_bot_of_card_le, fun h => by simp [h]⟩
@[to_additive] lemma eq_bot_iff_card : H = ⊥ ↔ Nat.card H = 1 :=
⟨by rintro rfl; exact card_bot, eq_bot_of_card_eq _⟩
@[to_additive one_lt_card_iff_ne_bot]
theorem one_lt_card_iff_ne_bot [Finite H] : 1 < Nat.card H ↔ H ≠ ⊥ :=
lt_iff_not_ge.trans H.card_le_one_iff_eq_bot.not
@[to_additive]
theorem card_le_card_group [Finite G] : Nat.card H ≤ Nat.card G :=
Nat.card_le_card_of_injective _ Subtype.coe_injective
@[to_additive]
theorem card_le_of_le {H K : Subgroup G} [Finite K] (h : H ≤ K) : Nat.card H ≤ Nat.card K :=
Nat.card_le_card_of_injective _ (Subgroup.inclusion_injective h)
@[to_additive]
theorem card_map_of_injective {H : Type*} [Group H] {K : Subgroup G} {f : G →* H}
(hf : Function.Injective f) :
Nat.card (map f K) = Nat.card K := by
apply Nat.card_image_of_injective hf
@[to_additive]
theorem card_subtype (K : Subgroup G) (L : Subgroup K) :
Nat.card (map K.subtype L) = Nat.card L :=
card_map_of_injective K.subtype_injective
end Subgroup
namespace Subgroup
section Pi
open Set
variable {η : Type*} {f : η → Type*} [∀ i, Group (f i)]
@[to_additive (attr := deprecated Submonoid.pi_mem_of_mulSingle_mem_aux (since := "2025-10-08"))]
theorem pi_mem_of_mulSingle_mem_aux [DecidableEq η] (I : Finset η) {H : Subgroup (∀ i, f i)}
(x : ∀ i, f i) (h1 : ∀ i, i ∉ I → x i = 1) (h2 : ∀ i, i ∈ I → Pi.mulSingle i (x i) ∈ H) :
x ∈ H :=
Submonoid.pi_mem_of_mulSingle_mem_aux I x h1 h2
@[to_additive]
theorem pi_mem_of_mulSingle_mem [Finite η] [DecidableEq η] {H : Subgroup (∀ i, f i)} (x : ∀ i, f i)
(h : ∀ i, Pi.mulSingle i (x i) ∈ H) : x ∈ H :=
Submonoid.pi_mem_of_mulSingle_mem x h
/-- For finite index types, the `Subgroup.pi` is generated by the embeddings of the groups. -/
@[to_additive /-- For finite index types, the `Subgroup.pi` is generated by the embeddings of the
additive groups. -/]
theorem pi_le_iff [DecidableEq η] [Finite η] {H : ∀ i, Subgroup (f i)} {J : Subgroup (∀ i, f i)} :
pi univ H ≤ J ↔ ∀ i : η, map (MonoidHom.mulSingle f i) (H i) ≤ J :=
Submonoid.pi_le_iff
@[to_additive]
theorem closure_pi [Finite η] {s : Π i, Set (f i)} (hs : ∀ i, 1 ∈ s i) :
closure (univ.pi fun i => s i) = pi univ fun i => closure (s i) :=
le_antisymm
((closure_le _).2 <| pi_subset_pi_iff.2 <| .inl fun _ _ => subset_closure)
(by
classical
exact pi_le_iff.mpr fun i => (gc_map_comap _).l_le <| (closure_le _).2 fun _x hx =>
subset_closure <| mem_univ_pi.mpr fun j => by
by_cases H : j = i
· subst H
simpa
· simpa [H] using hs _)
end Pi
section Normalizer
theorem mem_normalizer_fintype {S : Set G} [Finite S] {x : G} (h : ∀ n, n ∈ S → x * n * x⁻¹ ∈ S) :
x ∈ Subgroup.setNormalizer S := by
haveI := Classical.propDecidable; cases nonempty_fintype S
exact fun n =>
⟨h n, fun h₁ =>
have heq : (fun n => x * n * x⁻¹) '' S = S :=
Set.eq_of_subset_of_card_le (fun n ⟨y, hy⟩ => hy.2 ▸ h y hy.1)
(by rw [Set.card_image_of_injective S conj_injective])
have : x * n * x⁻¹ ∈ (fun n => x * n * x⁻¹) '' S := heq.symm ▸ h₁
let ⟨y, hy⟩ := this
conj_injective hy.2 ▸ hy.1⟩
end Normalizer
end Subgroup
namespace MonoidHom
variable {N : Type*} [Group N]
open Subgroup
@[to_additive]
instance decidableMemRange (f : G →* N) [Fintype G] [DecidableEq N] : DecidablePred (· ∈ f.range) :=
fun _ => Fintype.decidableExistsFintype
-- this instance can't go just after the definition of `mrange` because `Fintype` is
-- not imported at that stage
/-- The range of a finite monoid under a monoid homomorphism is finite.
Note: this instance can form a diamond with `Subtype.fintype` in the
presence of `Fintype N`. -/
@[to_additive /-- The range of a finite additive monoid under an additive monoid homomorphism is
finite.
Note: this instance can form a diamond with `Subtype.fintype` or `Subgroup.fintype` in the presence
of `Fintype N`. -/]
instance fintypeMrange {M N : Type*} [Monoid M] [Monoid N] [Fintype M] [DecidableEq N]
(f : M →* N) : Fintype (mrange f) :=
Set.fintypeRange f
/-- The range of a finite group under a group homomorphism is finite.
Note: this instance can form a diamond with `Subtype.fintype` or `Subgroup.fintype` in the
presence of `Fintype N`. -/
@[to_additive
/-- The range of a finite additive group under an additive group homomorphism is finite.
Note: this instance can form a diamond with `Subtype.fintype` or `Subgroup.fintype` in the
presence of `Fintype N`. -/]
instance fintypeRange [Fintype G] [DecidableEq N] (f : G →* N) : Fintype (range f) :=
Set.fintypeRange f
lemma _root_.Fintype.card_coeSort_mrange {M N : Type*} [Monoid M] [Monoid N] [Fintype M]
[DecidableEq N] {f : M →* N} (hf : Function.Injective f) :
Fintype.card (mrange f) = Fintype.card M :=
Set.card_range_of_injective hf
lemma _root_.Fintype.card_coeSort_range [Fintype G] [DecidableEq N] {f : G →* N}
(hf : Function.Injective f) :
Fintype.card (range f) = Fintype.card G :=
Set.card_range_of_injective hf
end MonoidHom |
.lake/packages/mathlib/Mathlib/Algebra/Group/Subgroup/MulOpposite.lean | import Mathlib.Algebra.Group.Subgroup.Defs
import Mathlib.Algebra.Group.Submonoid.MulOpposite
/-!
# Mul-opposite subgroups
## Tags
subgroup, subgroups
-/
variable {ι : Sort*} {G : Type*} [Group G]
namespace Subgroup
/-- Pull a subgroup back to an opposite subgroup along `MulOpposite.unop` -/
@[to_additive (attr := simps)
/-- Pull an additive subgroup back to an opposite additive subgroup along `AddOpposite.unop` -/]
protected def op (H : Subgroup G) : Subgroup Gᵐᵒᵖ where
carrier := MulOpposite.unop ⁻¹' (H : Set G)
one_mem' := H.one_mem
mul_mem' ha hb := H.mul_mem hb ha
inv_mem' := H.inv_mem
@[to_additive (attr := simp)]
theorem mem_op {x : Gᵐᵒᵖ} {S : Subgroup G} : x ∈ S.op ↔ x.unop ∈ S := Iff.rfl
@[to_additive (attr := simp)] lemma op_toSubmonoid (H : Subgroup G) :
H.op.toSubmonoid = H.toSubmonoid.op :=
rfl
/-- Pull an opposite subgroup back to a subgroup along `MulOpposite.op` -/
@[to_additive (attr := simps)
/-- Pull an opposite additive subgroup back to an additive subgroup along `AddOpposite.op` -/]
protected def unop (H : Subgroup Gᵐᵒᵖ) : Subgroup G where
carrier := MulOpposite.op ⁻¹' (H : Set Gᵐᵒᵖ)
one_mem' := H.one_mem
mul_mem' := fun ha hb => H.mul_mem hb ha
inv_mem' := H.inv_mem
@[to_additive (attr := simp)]
theorem mem_unop {x : G} {S : Subgroup Gᵐᵒᵖ} : x ∈ S.unop ↔ MulOpposite.op x ∈ S := Iff.rfl
@[to_additive (attr := simp)] lemma unop_toSubmonoid (H : Subgroup Gᵐᵒᵖ) :
H.unop.toSubmonoid = H.toSubmonoid.unop :=
rfl
@[to_additive (attr := simp)]
theorem unop_op (S : Subgroup G) : S.op.unop = S := rfl
@[to_additive (attr := simp)]
theorem op_unop (S : Subgroup Gᵐᵒᵖ) : S.unop.op = S := rfl
/-! ### Lattice results -/
@[to_additive]
theorem op_le_iff {S₁ : Subgroup G} {S₂ : Subgroup Gᵐᵒᵖ} : S₁.op ≤ S₂ ↔ S₁ ≤ S₂.unop :=
MulOpposite.op_surjective.forall
@[to_additive]
theorem le_op_iff {S₁ : Subgroup Gᵐᵒᵖ} {S₂ : Subgroup G} : S₁ ≤ S₂.op ↔ S₁.unop ≤ S₂ :=
MulOpposite.op_surjective.forall
@[to_additive (attr := simp)]
theorem op_le_op_iff {S₁ S₂ : Subgroup G} : S₁.op ≤ S₂.op ↔ S₁ ≤ S₂ :=
MulOpposite.op_surjective.forall
@[to_additive (attr := simp)]
theorem unop_le_unop_iff {S₁ S₂ : Subgroup Gᵐᵒᵖ} : S₁.unop ≤ S₂.unop ↔ S₁ ≤ S₂ :=
MulOpposite.unop_surjective.forall
/-- A subgroup `H` of `G` determines a subgroup `H.op` of the opposite group `Gᵐᵒᵖ`. -/
@[to_additive (attr := simps) /-- An additive subgroup `H` of `G` determines an additive subgroup
`H.op` of the opposite additive group `Gᵃᵒᵖ`. -/]
def opEquiv : Subgroup G ≃o Subgroup Gᵐᵒᵖ where
toFun := Subgroup.op
invFun := Subgroup.unop
left_inv := unop_op
right_inv := op_unop
map_rel_iff' := op_le_op_iff
@[to_additive]
theorem op_injective : (@Subgroup.op G _).Injective := opEquiv.injective
@[to_additive]
theorem unop_injective : (@Subgroup.unop G _).Injective := opEquiv.symm.injective
@[to_additive (attr := simp)]
theorem op_inj {S T : Subgroup G} : S.op = T.op ↔ S = T := opEquiv.eq_iff_eq
@[to_additive (attr := simp)]
theorem unop_inj {S T : Subgroup Gᵐᵒᵖ} : S.unop = T.unop ↔ S = T := opEquiv.symm.eq_iff_eq
/-- Bijection between a subgroup `H` and its opposite. -/
@[to_additive (attr := simps!) /-- Bijection between an additive subgroup `H` and its opposite. -/]
def equivOp (H : Subgroup G) : H ≃ H.op :=
MulOpposite.opEquiv.subtypeEquiv fun _ => Iff.rfl
@[to_additive]
theorem op_normalizer (H : Subgroup G) : H.normalizer.op = H.op.normalizer := by
ext x
simp [mem_normalizer_iff', iff_comm]
@[to_additive]
theorem unop_normalizer (H : Subgroup Gᵐᵒᵖ) : H.normalizer.unop = H.unop.normalizer := by
rw [← op_inj, op_unop, op_normalizer, op_unop]
end Subgroup |
.lake/packages/mathlib/Mathlib/Algebra/Group/Subgroup/Pointwise.lean | import Mathlib.Algebra.Group.Action.End
import Mathlib.Algebra.Group.Pointwise.Set.Lattice
import Mathlib.Algebra.Group.Subgroup.MulOppositeLemmas
import Mathlib.Algebra.Group.Submonoid.Pointwise
import Mathlib.GroupTheory.GroupAction.ConjAct
/-! # Pointwise instances on `Subgroup` and `AddSubgroup`s
This file provides the actions
* `Subgroup.pointwiseMulAction`
* `AddSubgroup.pointwiseMulAction`
which matches the action of `Set.mulActionSet`.
These actions are available in the `Pointwise` locale.
## Implementation notes
The pointwise section of this file is almost identical to
the file `Mathlib/Algebra/Group/Submonoid/Pointwise.lean`.
Where possible, try to keep them in sync.
-/
assert_not_exists GroupWithZero
open Set
open Pointwise
variable {α G A S : Type*}
@[to_additive (attr := simp, norm_cast)]
theorem inv_coe_set [InvolutiveInv G] [SetLike S G] [InvMemClass S G] {H : S} : (H : Set G)⁻¹ = H :=
Set.ext fun _ => inv_mem_iff
@[to_additive (attr := simp)]
lemma smul_coe_set [Group G] [SetLike S G] [SubgroupClass S G] {s : S} {a : G} (ha : a ∈ s) :
a • (s : Set G) = s := by
ext; simp [Set.mem_smul_set_iff_inv_smul_mem, mul_mem_cancel_left, ha]
@[norm_cast, to_additive]
lemma coe_set_eq_one [Group G] {s : Subgroup G} : (s : Set G) = 1 ↔ s = ⊥ :=
(SetLike.ext'_iff.trans (by rfl)).symm
@[to_additive (attr := simp)]
lemma op_smul_coe_set [Group G] [SetLike S G] [SubgroupClass S G] {s : S} {a : G} (ha : a ∈ s) :
MulOpposite.op a • (s : Set G) = s := by
ext; simp [Set.mem_smul_set_iff_inv_smul_mem, mul_mem_cancel_right, ha]
@[to_additive (attr := simp, norm_cast)]
lemma coe_div_coe [SetLike S G] [DivisionMonoid G] [SubgroupClass S G] (H : S) :
H / H = (H : Set G) := by simp [div_eq_mul_inv]
variable [Group G] [AddGroup A] {s : Set G}
namespace Set
open Subgroup
@[to_additive (attr := simp)]
lemma mul_subgroupClosure (hs : s.Nonempty) : s * closure s = closure s := by
rw [← smul_eq_mul, ← Set.iUnion_smul_set]
have h a (ha : a ∈ s) : a • (closure s : Set G) = closure s :=
smul_coe_set <| subset_closure ha
simp +contextual [h, hs]
open scoped RightActions in
@[to_additive (attr := simp)]
lemma subgroupClosure_mul (hs : s.Nonempty) : closure s * s = closure s := by
rw [← Set.iUnion_op_smul_set]
have h a (ha : a ∈ s) : (closure s : Set G) <• a = closure s :=
op_smul_coe_set <| subset_closure ha
simp +contextual [h, hs]
@[to_additive (attr := simp)]
lemma pow_mul_subgroupClosure (hs : s.Nonempty) : ∀ n, s ^ n * closure s = closure s
| 0 => by simp
| n + 1 => by rw [pow_succ, mul_assoc, mul_subgroupClosure hs, pow_mul_subgroupClosure hs]
@[to_additive (attr := simp)]
lemma subgroupClosure_mul_pow (hs : s.Nonempty) : ∀ n, closure s * s ^ n = closure s
| 0 => by simp
| n + 1 => by rw [pow_succ', ← mul_assoc, subgroupClosure_mul hs, subgroupClosure_mul_pow hs]
end Set
namespace Subgroup
@[to_additive (attr := simp)]
theorem inv_subset_closure (S : Set G) : S⁻¹ ⊆ closure S := fun s hs => by
rw [SetLike.mem_coe, ← Subgroup.inv_mem_iff]
exact subset_closure (mem_inv.mp hs)
@[to_additive]
theorem closure_toSubmonoid (S : Set G) :
(closure S).toSubmonoid = Submonoid.closure (S ∪ S⁻¹) := by
refine le_antisymm (fun x hx => ?_) (Submonoid.closure_le.2 ?_)
· refine
closure_induction
(fun x hx => Submonoid.closure_mono subset_union_left (Submonoid.subset_closure hx))
(Submonoid.one_mem _) (fun x y _ _ hx hy => Submonoid.mul_mem _ hx hy) (fun x _ hx => ?_) hx
rwa [← Submonoid.mem_closure_inv, Set.union_inv, inv_inv, Set.union_comm]
· simp only [true_and, coe_toSubmonoid, union_subset_iff, subset_closure, inv_subset_closure]
@[to_additive]
lemma toSubmonoid_zpowers (g : G) :
(Subgroup.zpowers g).toSubmonoid = Submonoid.powers g ⊔ Submonoid.powers g⁻¹ := by
rw [zpowers_eq_closure, closure_toSubmonoid, Submonoid.closure_union,
Submonoid.powers_eq_closure, Submonoid.powers_eq_closure, Set.inv_singleton]
@[to_additive]
lemma _root_.Submonoid.powers_le_zpowers (g : G) :
Submonoid.powers g ≤ (Subgroup.zpowers g).toSubmonoid := by
rw [toSubmonoid_zpowers]
exact le_sup_left
/-- For subgroups generated by a single element, see the simpler `zpow_induction_left`. -/
@[to_additive (attr := elab_as_elim)
/-- For additive subgroups generated by a single element, see the simpler
`zsmul_induction_left`. -/]
theorem closure_induction_left {p : (x : G) → x ∈ closure s → Prop} (one : p 1 (one_mem _))
(mul_left : ∀ x (hx : x ∈ s), ∀ (y) hy, p y hy → p (x * y) (mul_mem (subset_closure hx) hy))
(inv_mul_cancel : ∀ x (hx : x ∈ s), ∀ (y) hy, p y hy →
p (x⁻¹ * y) (mul_mem (inv_mem (subset_closure hx)) hy))
{x : G} (h : x ∈ closure s) : p x h := by
revert h
simp_rw [← mem_toSubmonoid, closure_toSubmonoid] at *
intro h
induction h using Submonoid.closure_induction_left with
| one => exact one
| mul_left x hx y hy ih =>
cases hx with
| inl hx => exact mul_left _ hx _ hy ih
| inr hx => simpa only [inv_inv] using inv_mul_cancel _ hx _ hy ih
/-- For subgroups generated by a single element, see the simpler `zpow_induction_right`. -/
@[to_additive (attr := elab_as_elim)
/-- For additive subgroups generated by a single element, see the simpler
`zsmul_induction_right`. -/]
theorem closure_induction_right {p : (x : G) → x ∈ closure s → Prop} (one : p 1 (one_mem _))
(mul_right : ∀ (x) hx, ∀ y (hy : y ∈ s), p x hx → p (x * y) (mul_mem hx (subset_closure hy)))
(mul_inv_cancel : ∀ (x) hx, ∀ y (hy : y ∈ s), p x hx →
p (x * y⁻¹) (mul_mem hx (inv_mem (subset_closure hy))))
{x : G} (h : x ∈ closure s) : p x h :=
closure_induction_left (s := MulOpposite.unop ⁻¹' s)
(p := fun m hm => p m.unop <| by rwa [← op_closure] at hm)
one
(fun _x hx _y _ => mul_right _ _ _ hx)
(fun _x hx _y _ => mul_inv_cancel _ _ _ hx)
(by rwa [← op_closure])
@[to_additive (attr := simp)]
theorem closure_inv (s : Set G) : closure s⁻¹ = closure s := by
simp only [← toSubmonoid_inj, closure_toSubmonoid, inv_inv, union_comm]
@[to_additive (attr := simp)]
lemma closure_singleton_inv (x : G) : closure {x⁻¹} = closure {x} := by
rw [← Set.inv_singleton, closure_inv]
/-- An induction principle for closure membership. If `p` holds for `1` and all elements of
`k` and their inverse, and is preserved under multiplication, then `p` holds for all elements of
the closure of `k`. -/
@[to_additive (attr := elab_as_elim)
/-- An induction principle for additive closure membership. If `p` holds for `0` and all
elements of `k` and their negation, and is preserved under addition, then `p` holds for all
elements of the additive closure of `k`. -/]
theorem closure_induction'' {p : (g : G) → g ∈ closure s → Prop}
(mem : ∀ x (hx : x ∈ s), p x (subset_closure hx))
(inv_mem : ∀ x (hx : x ∈ s), p x⁻¹ (inv_mem (subset_closure hx)))
(one : p 1 (one_mem _))
(mul : ∀ x y hx hy, p x hx → p y hy → p (x * y) (mul_mem hx hy))
{x} (h : x ∈ closure s) : p x h :=
closure_induction_left one (fun x hx y _ hy => mul x y _ _ (mem x hx) hy)
(fun x hx y _ => mul x⁻¹ y _ _ <| inv_mem x hx) h
/-- An induction principle for elements of `⨆ i, S i`.
If `C` holds for `1` and all elements of `S i` for all `i`, and is preserved under multiplication,
then it holds for all elements of the supremum of `S`. -/
@[to_additive (attr := elab_as_elim) /-- An induction principle for elements of `⨆ i, S i`.
If `C` holds for `0` and all elements of `S i` for all `i`, and is preserved under addition,
then it holds for all elements of the supremum of `S`. -/]
theorem iSup_induction {ι : Sort*} (S : ι → Subgroup G) {C : G → Prop} {x : G} (hx : x ∈ ⨆ i, S i)
(mem : ∀ (i), ∀ x ∈ S i, C x) (one : C 1) (mul : ∀ x y, C x → C y → C (x * y)) : C x := by
rw [iSup_eq_closure] at hx
induction hx using closure_induction'' with
| one => exact one
| mem x hx =>
obtain ⟨i, hi⟩ := Set.mem_iUnion.mp hx
exact mem _ _ hi
| inv_mem x hx =>
obtain ⟨i, hi⟩ := Set.mem_iUnion.mp hx
exact mem _ _ (inv_mem hi)
| mul x y _ _ ihx ihy => exact mul x y ihx ihy
/-- A dependent version of `Subgroup.iSup_induction`. -/
@[to_additive (attr := elab_as_elim) /-- A dependent version of `AddSubgroup.iSup_induction`. -/]
theorem iSup_induction' {ι : Sort*} (S : ι → Subgroup G) {C : ∀ x, (x ∈ ⨆ i, S i) → Prop}
(hp : ∀ (i), ∀ x (hx : x ∈ S i), C x (mem_iSup_of_mem i hx)) (h1 : C 1 (one_mem _))
(hmul : ∀ x y hx hy, C x hx → C y hy → C (x * y) (mul_mem ‹_› ‹_›)) {x : G}
(hx : x ∈ ⨆ i, S i) : C x hx := by
suffices ∃ h, C x h from this.snd
refine iSup_induction S (C := fun x => ∃ h, C x h) hx (fun i x hx => ?_) ?_ fun x y => ?_
· exact ⟨_, hp i _ hx⟩
· exact ⟨_, h1⟩
· rintro ⟨_, Cx⟩ ⟨_, Cy⟩
exact ⟨_, hmul _ _ _ _ Cx Cy⟩
@[to_additive]
theorem closure_mul_le (S T : Set G) : closure (S * T) ≤ closure S ⊔ closure T :=
sInf_le fun _x ⟨_s, hs, _t, ht, hx⟩ => hx ▸
(closure S ⊔ closure T).mul_mem (SetLike.le_def.mp le_sup_left <| subset_closure hs)
(SetLike.le_def.mp le_sup_right <| subset_closure ht)
@[to_additive]
lemma closure_pow_le : ∀ {n}, n ≠ 0 → closure (s ^ n) ≤ closure s
| 1, _ => by simp
| n + 2, _ =>
calc
closure (s ^ (n + 2))
_ = closure (s ^ (n + 1) * s) := by rw [pow_succ]
_ ≤ closure (s ^ (n + 1)) ⊔ closure s := closure_mul_le ..
_ ≤ closure s ⊔ closure s := by gcongr ?_ ⊔ _; exact closure_pow_le n.succ_ne_zero
_ = closure s := sup_idem _
@[to_additive]
lemma closure_pow {n : ℕ} (hs : 1 ∈ s) (hn : n ≠ 0) : closure (s ^ n) = closure s :=
(closure_pow_le hn).antisymm <| by gcongr; exact subset_pow hs hn
@[to_additive]
theorem sup_eq_closure_mul (H K : Subgroup G) : H ⊔ K = closure ((H : Set G) * (K : Set G)) :=
le_antisymm
(sup_le (fun h hh => subset_closure ⟨h, hh, 1, K.one_mem, mul_one h⟩) fun k hk =>
subset_closure ⟨1, H.one_mem, k, hk, one_mul k⟩)
((closure_mul_le _ _).trans <| by rw [closure_eq, closure_eq])
@[to_additive]
theorem set_mul_normalizer_comm (S : Set G) (N : Subgroup G) (hLE : S ⊆ N.normalizer) :
S * N = N * S := by
rw [← iUnion_mul_left_image, ← iUnion_mul_right_image]
simp only [image_mul_left, image_mul_right, Set.preimage]
congr! 5 with s hs x
exact (mem_normalizer_iff'.mp (inv_mem (hLE hs)) x).symm
@[to_additive]
theorem set_mul_normal_comm (S : Set G) (N : Subgroup G) [hN : N.Normal] :
S * (N : Set G) = (N : Set G) * S := set_mul_normalizer_comm S N subset_normalizer_of_normal
/-- The carrier of `H ⊔ N` is just `↑H * ↑N` (pointwise set product)
when `H` is a subgroup of the normalizer of `N` in `G`. -/
@[to_additive /-- The carrier of `H ⊔ N` is just `↑H + ↑N` (pointwise set addition)
when `H` is a subgroup of the normalizer of `N` in `G`. -/]
theorem coe_mul_of_left_le_normalizer_right (H N : Subgroup G) (hLE : H ≤ N.normalizer) :
(↑(H ⊔ N) : Set G) = H * N := by
rw [sup_eq_closure_mul]
refine Set.Subset.antisymm (fun x hx => ?_) subset_closure
induction hx using closure_induction'' with
| one => exact ⟨1, one_mem _, 1, one_mem _, mul_one 1⟩
| mem _ hx => exact hx
| inv_mem x hx =>
obtain ⟨x, hx, y, hy, rfl⟩ := hx
simpa only [mul_inv_rev, mul_assoc, inv_inv, inv_mul_cancel_left]
using mul_mem_mul (inv_mem hx) ((mem_normalizer_iff.mp (hLE hx) y⁻¹).mp (inv_mem hy))
| mul x' x' _ _ hx hx' =>
obtain ⟨x, hx, y, hy, rfl⟩ := hx
obtain ⟨x', hx', y', hy', rfl⟩ := hx'
refine ⟨x * x', mul_mem hx hx', x'⁻¹ * y * x' * y', mul_mem ?_ hy', ?_⟩
· exact (mem_normalizer_iff''.mp (hLE hx') y).mp hy
· simp only [mul_assoc, mul_inv_cancel_left]
/-- The carrier of `N ⊔ H` is just `↑N * ↑H` (pointwise set product) when
`H` is a subgroup of the normalizer of `N` in `G`. -/
@[to_additive /-- The carrier of `N ⊔ H` is just `↑N + ↑H` (pointwise set addition)
when `H` is a subgroup of the normalizer of `N` in `G`. -/]
theorem coe_mul_of_right_le_normalizer_left (N H : Subgroup G) (hLE : H ≤ N.normalizer) :
(↑(N ⊔ H) : Set G) = N * H := by
rw [← set_mul_normalizer_comm _ _ hLE, sup_comm, coe_mul_of_left_le_normalizer_right _ _ hLE]
/-- The carrier of `H ⊔ N` is just `↑H * ↑N` (pointwise set product) when `N` is normal. -/
@[to_additive /-- The carrier of `H ⊔ N` is just `↑H + ↑N` (pointwise set addition)
when `N` is normal. -/]
theorem mul_normal (H N : Subgroup G) [hN : N.Normal] : (↑(H ⊔ N) : Set G) = H * N :=
coe_mul_of_left_le_normalizer_right H N le_normalizer_of_normal
/-- The carrier of `N ⊔ H` is just `↑N * ↑H` (pointwise set product) when `N` is normal. -/
@[to_additive /-- The carrier of `N ⊔ H` is just `↑N + ↑H` (pointwise set addition)
when `N` is normal. -/]
theorem normal_mul (N H : Subgroup G) [N.Normal] : (↑(N ⊔ H) : Set G) = N * H :=
coe_mul_of_right_le_normalizer_left N H le_normalizer_of_normal
@[to_additive]
theorem mul_inf_assoc (A B C : Subgroup G) (h : A ≤ C) :
(A : Set G) * ↑(B ⊓ C) = (A : Set G) * (B : Set G) ∩ C := by
ext
simp only [coe_inf, Set.mem_mul, Set.mem_inter_iff]
constructor
· rintro ⟨y, hy, z, ⟨hzB, hzC⟩, rfl⟩
refine ⟨?_, mul_mem (h hy) hzC⟩
exact ⟨y, hy, z, hzB, rfl⟩
rintro ⟨⟨y, hy, z, hz, rfl⟩, hyz⟩
refine ⟨y, hy, z, ⟨hz, ?_⟩, rfl⟩
suffices y⁻¹ * (y * z) ∈ C by simpa
exact mul_mem (inv_mem (h hy)) hyz
@[to_additive]
theorem inf_mul_assoc (A B C : Subgroup G) (h : C ≤ A) :
((A ⊓ B : Subgroup G) : Set G) * C = (A : Set G) ∩ (↑B * ↑C) := by
ext
simp only [coe_inf, Set.mem_mul, Set.mem_inter_iff]
constructor
· rintro ⟨y, ⟨hyA, hyB⟩, z, hz, rfl⟩
refine ⟨A.mul_mem hyA (h hz), ?_⟩
exact ⟨y, hyB, z, hz, rfl⟩
rintro ⟨hyz, y, hy, z, hz, rfl⟩
refine ⟨y, ⟨?_, hy⟩, z, hz, rfl⟩
suffices y * z * z⁻¹ ∈ A by simpa
exact mul_mem hyz (inv_mem (h hz))
@[to_additive]
instance sup_normal (H K : Subgroup G) [hH : H.Normal] [hK : K.Normal] : (H ⊔ K).Normal where
conj_mem n hmem g := by
rw [← SetLike.mem_coe, normal_mul] at hmem ⊢
rcases hmem with ⟨h, hh, k, hk, rfl⟩
refine ⟨g * h * g⁻¹, hH.conj_mem h hh g, g * k * g⁻¹, hK.conj_mem k hk g, ?_⟩
simp only [mul_assoc, inv_mul_cancel_left]
@[to_additive]
theorem smul_mem_of_mem_closure_of_mem {X : Type*} [MulAction G X] {s : Set G} {t : Set X}
(hs : ∀ g ∈ s, g⁻¹ ∈ s) (hst : ∀ᵉ (g ∈ s) (x ∈ t), g • x ∈ t) {g : G}
(hg : g ∈ Subgroup.closure s) {x : X} (hx : x ∈ t) : g • x ∈ t := by
induction hg using Subgroup.closure_induction'' generalizing x with
| one => simpa
| mem g' hg' => exact hst g' hg' x hx
| inv_mem g' hg' => exact hst g'⁻¹ (hs g' hg') x hx
| mul _ _ _ _ h₁ h₂ => rw [mul_smul]; exact h₁ (h₂ hx)
@[to_additive]
theorem smul_opposite_image_mul_preimage' (g : G) (h : Gᵐᵒᵖ) (s : Set G) :
(fun y => h • y) '' ((g * ·) ⁻¹' s) = (g * ·) ⁻¹' ((fun y => h • y) '' s) := by
simp [preimage_preimage, mul_assoc]
-- TODO: deprecate?
@[to_additive]
theorem smul_opposite_image_mul_preimage {H : Subgroup G} (g : G) (h : H.op) (s : Set G) :
(fun y => h • y) '' ((g * ·) ⁻¹' s) = (g * ·) ⁻¹' ((fun y => h • y) '' s) :=
smul_opposite_image_mul_preimage' g h s
/-! ### Pointwise action -/
section Monoid
variable [Monoid α] [MulDistribMulAction α G]
/-- The action on a subgroup corresponding to applying the action to every element.
This is available as an instance in the `Pointwise` locale. -/
protected def pointwiseMulAction : MulAction α (Subgroup G) where
smul a S := S.map (MulDistribMulAction.toMonoidEnd _ _ a)
one_smul S := by
change S.map _ = S
simpa only [map_one] using S.map_id
mul_smul _ _ S :=
(congr_arg (fun f : Monoid.End G => S.map f) (MonoidHom.map_mul _ _ _)).trans
(S.map_map _ _).symm
scoped[Pointwise] attribute [instance] Subgroup.pointwiseMulAction
theorem pointwise_smul_def {a : α} (S : Subgroup G) :
a • S = S.map (MulDistribMulAction.toMonoidEnd _ _ a) :=
rfl
@[simp, norm_cast]
theorem coe_pointwise_smul (a : α) (S : Subgroup G) : ↑(a • S) = a • (S : Set G) :=
rfl
@[simp]
theorem pointwise_smul_toSubmonoid (a : α) (S : Subgroup G) :
(a • S).toSubmonoid = a • S.toSubmonoid :=
rfl
theorem smul_mem_pointwise_smul (m : G) (a : α) (S : Subgroup G) : m ∈ S → a • m ∈ a • S :=
(Set.smul_mem_smul_set : _ → _ ∈ a • (S : Set G))
instance : CovariantClass α (Subgroup G) HSMul.hSMul LE.le :=
⟨fun _ _ => image_mono⟩
theorem mem_smul_pointwise_iff_exists (m : G) (a : α) (S : Subgroup G) :
m ∈ a • S ↔ ∃ s : G, s ∈ S ∧ a • s = m :=
(Set.mem_smul_set : m ∈ a • (S : Set G) ↔ _)
@[simp]
theorem smul_bot (a : α) : a • (⊥ : Subgroup G) = ⊥ :=
map_bot _
theorem smul_sup (a : α) (S T : Subgroup G) : a • (S ⊔ T) = a • S ⊔ a • T :=
map_sup _ _ _
theorem smul_closure (a : α) (s : Set G) : a • closure s = closure (a • s) :=
MonoidHom.map_closure _ _
instance pointwise_isCentralScalar [MulDistribMulAction αᵐᵒᵖ G] [IsCentralScalar α G] :
IsCentralScalar α (Subgroup G) :=
⟨fun _ S => (congr_arg fun f => S.map f) <| MonoidHom.ext <| op_smul_eq_smul _⟩
theorem conj_smul_le_of_le {P H : Subgroup G} (hP : P ≤ H) (h : H) :
MulAut.conj (h : G) • P ≤ H := by
rintro - ⟨g, hg, rfl⟩
exact H.mul_mem (H.mul_mem h.2 (hP hg)) (H.inv_mem h.2)
theorem conj_smul_subgroupOf {P H : Subgroup G} (hP : P ≤ H) (h : H) :
MulAut.conj h • P.subgroupOf H = (MulAut.conj (h : G) • P).subgroupOf H := by
refine le_antisymm ?_ ?_
· rintro - ⟨g, hg, rfl⟩
exact ⟨g, hg, rfl⟩
· rintro p ⟨g, hg, hp⟩
exact ⟨⟨g, hP hg⟩, hg, Subtype.ext hp⟩
end Monoid
section Group
variable [Group α] [MulDistribMulAction α G]
@[simp]
theorem smul_mem_pointwise_smul_iff {a : α} {S : Subgroup G} {x : G} : a • x ∈ a • S ↔ x ∈ S :=
smul_mem_smul_set_iff
theorem mem_pointwise_smul_iff_inv_smul_mem {a : α} {S : Subgroup G} {x : G} :
x ∈ a • S ↔ a⁻¹ • x ∈ S :=
mem_smul_set_iff_inv_smul_mem
theorem mem_inv_pointwise_smul_iff {a : α} {S : Subgroup G} {x : G} : x ∈ a⁻¹ • S ↔ a • x ∈ S :=
mem_inv_smul_set_iff
@[simp]
theorem pointwise_smul_le_pointwise_smul_iff {a : α} {S T : Subgroup G} : a • S ≤ a • T ↔ S ≤ T :=
smul_set_subset_smul_set_iff
theorem pointwise_smul_subset_iff {a : α} {S T : Subgroup G} : a • S ≤ T ↔ S ≤ a⁻¹ • T :=
smul_set_subset_iff_subset_inv_smul_set
theorem subset_pointwise_smul_iff {a : α} {S T : Subgroup G} : S ≤ a • T ↔ a⁻¹ • S ≤ T :=
subset_smul_set_iff
@[simp]
theorem smul_inf (a : α) (S T : Subgroup G) : a • (S ⊓ T) = a • S ⊓ a • T := by
simp [SetLike.ext_iff, mem_pointwise_smul_iff_inv_smul_mem]
/-- Applying a `MulDistribMulAction` results in an isomorphic subgroup -/
@[simps!]
def equivSMul (a : α) (H : Subgroup G) : H ≃* (a • H : Subgroup G) :=
(MulDistribMulAction.toMulEquiv G a).subgroupMap H
theorem subgroup_mul_singleton {H : Subgroup G} {h : G} (hh : h ∈ H) : (H : Set G) * {h} = H := by
simp [preimage, mul_mem_cancel_right (inv_mem hh)]
theorem singleton_mul_subgroup {H : Subgroup G} {h : G} (hh : h ∈ H) : {h} * (H : Set G) = H := by
simp [preimage, mul_mem_cancel_left (inv_mem hh)]
theorem Normal.conjAct {H : Subgroup G} (hH : H.Normal) (g : ConjAct G) : g • H = H :=
have : ∀ g : ConjAct G, g • H ≤ H :=
fun _ => map_le_iff_le_comap.2 fun _ h => hH.conj_mem _ h _
(this g).antisymm <| (smul_inv_smul g H).symm.trans_le (map_mono <| this _)
@[simp]
theorem Normal.conj_smul_eq_self (g : G) (H : Subgroup G) [h : Normal H] : MulAut.conj g • H = H :=
h.conjAct g
theorem Normal.of_conjugate_fixed {H : Subgroup G} (h : ∀ g : G, (MulAut.conj g) • H = H) :
H.Normal := by
constructor
intro n hn g
rw [← h g, Subgroup.mem_pointwise_smul_iff_inv_smul_mem, ← map_inv, MulAut.smul_def,
MulAut.conj_apply, inv_inv, mul_assoc, mul_assoc, inv_mul_cancel, mul_one,
← mul_assoc, inv_mul_cancel, one_mul]
exact hn
theorem normalCore_eq_iInf_conjAct (H : Subgroup G) :
H.normalCore = ⨅ (g : ConjAct G), g • H := by
ext g
simp only [Subgroup.normalCore, Subgroup.mem_iInf, Subgroup.mem_pointwise_smul_iff_inv_smul_mem]
refine ⟨fun h x ↦ h x⁻¹, fun h x ↦ ?_⟩
simpa only [ConjAct.toConjAct_inv, inv_inv] using h x⁻¹
end Group
end Subgroup |
.lake/packages/mathlib/Mathlib/Algebra/Group/Subgroup/Order.lean | import Mathlib.Algebra.Group.Subgroup.Basic
import Mathlib.Algebra.Group.Subsemigroup.Operations
import Mathlib.Algebra.Order.Group.Unbundled.Abs
import Mathlib.Algebra.Order.Monoid.Basic
import Mathlib.Order.Atoms
/-!
# Facts about ordered structures and ordered instances on subgroups
-/
open Subgroup
@[to_additive (attr := simp)]
theorem mabs_mem_iff {S G} [Group G] [LinearOrder G] {_ : SetLike S G}
[InvMemClass S G] {H : S} {x : G} : |x|ₘ ∈ H ↔ x ∈ H := by
cases mabs_choice x <;> simp [*]
section ModularLattice
variable {C : Type*} [CommGroup C]
@[to_additive]
instance : IsModularLattice (Subgroup C) :=
⟨fun {x} y z xz a ha => by
rw [mem_inf, mem_sup] at ha
rcases ha with ⟨⟨b, hb, c, hc, rfl⟩, haz⟩
rw [mem_sup]
exact ⟨b, hb, c, mem_inf.2 ⟨hc, (mul_mem_cancel_left (xz hb)).1 haz⟩, rfl⟩⟩
end ModularLattice
section Coatom
namespace Subgroup
variable {G : Type*} [Group G] (H : Subgroup G)
/-- In a group that satisfies the normalizer condition, every maximal subgroup is normal -/
theorem NormalizerCondition.normal_of_coatom (hnc : NormalizerCondition G) (hmax : IsCoatom H) :
H.Normal :=
normalizer_eq_top_iff.mp (hmax.2 _ (hnc H (lt_top_iff_ne_top.mpr hmax.1)))
@[simp]
theorem isCoatom_comap {H : Type*} [Group H] (f : G ≃* H) {K : Subgroup H} :
IsCoatom (Subgroup.comap (f : G →* H) K) ↔ IsCoatom K :=
OrderIso.isCoatom_iff (f.comapSubgroup) K
@[simp]
theorem isCoatom_map (f : G ≃* H) {K : Subgroup G} :
IsCoatom (Subgroup.map (f : G →* H) K) ↔ IsCoatom K :=
OrderIso.isCoatom_iff (f.mapSubgroup) K
lemma isCoatom_comap_of_surjective
{H : Type*} [Group H] {φ : G →* H} (hφ : Function.Surjective φ)
{M : Subgroup H} (hM : IsCoatom M) : IsCoatom (M.comap φ) := by
refine And.imp (fun hM ↦ ?_) (fun hM ↦ ?_) hM
· rwa [← (comap_injective hφ).ne_iff, comap_top] at hM
· intro K hK
specialize hM (K.map φ)
rw [← comap_lt_comap_of_surjective hφ, ← (comap_injective hφ).eq_iff] at hM
rw [comap_map_eq_self ((M.ker_le_comap φ).trans hK.le), comap_top] at hM
exact hM hK
end Subgroup
end Coatom
namespace Subgroup
variable {G : Type*}
/-- A subgroup of an ordered group is an ordered group. -/
@[to_additive /-- An `AddSubgroup` of an `AddOrderedCommGroup` is an `AddOrderedCommGroup`. -/]
instance toIsOrderedMonoid [CommGroup G] [PartialOrder G] [IsOrderedMonoid G] (H : Subgroup G) :
IsOrderedMonoid H :=
Function.Injective.isOrderedMonoid Subtype.val (fun _ _ => rfl) .rfl
end Subgroup
@[to_additive]
lemma Subsemigroup.strictMono_topEquiv {G : Type*} [CommMonoid G] [PartialOrder G] :
StrictMono (topEquiv (M := G)) := fun _ _ ↦ id
@[to_additive]
lemma MulEquiv.strictMono_subsemigroupCongr {G : Type*}
[CommMonoid G] [PartialOrder G] {S T : Subsemigroup G}
(h : S = T) : StrictMono (subsemigroupCongr h) := fun _ _ ↦ id
@[to_additive]
lemma MulEquiv.strictMono_symm {G G' : Type*} [CommMonoid G] [LinearOrder G]
[CommMonoid G'] [PartialOrder G'] {e : G ≃* G'} (he : StrictMono e) : StrictMono e.symm := by
intro
simp [← he.lt_iff_lt] |
.lake/packages/mathlib/Mathlib/Algebra/Group/Subgroup/Map.lean | import Mathlib.Algebra.Group.Subgroup.Lattice
import Mathlib.Algebra.Group.TypeTags.Hom
/-!
# `map` and `comap` for subgroups
We prove results about images and preimages of subgroups under group homomorphisms. The bundled
subgroups use bundled monoid homomorphisms.
Special thanks goes to Amelia Livingston and Yury Kudryashov for their help and inspiration.
## Main definitions
Notation used here:
- `G N` are `Group`s
- `H` is a `Subgroup` of `G`
- `x` is an element of type `G` or type `A`
- `f g : N →* G` are group homomorphisms
- `s k` are sets of elements of type `G`
Definitions in the file:
* `Subgroup.comap H f` : the preimage of a subgroup `H` along the group homomorphism `f` is also a
subgroup
* `Subgroup.map f H` : the image of a subgroup `H` along the group homomorphism `f` is also a
subgroup
## Implementation notes
Subgroup inclusion is denoted `≤` rather than `⊆`, although `∈` is defined as
membership of a subgroup's underlying set.
## Tags
subgroup, subgroups
-/
assert_not_exists IsOrderedMonoid Multiset Ring
open Function
open scoped Int
variable {G G' G'' : Type*} [Group G] [Group G'] [Group G'']
variable {A : Type*} [AddGroup A]
namespace Subgroup
variable (H K : Subgroup G) {k : Set G}
open Set
variable {N : Type*} [Group N] {P : Type*} [Group P]
/-- The preimage of a subgroup along a monoid homomorphism is a subgroup. -/
@[to_additive
/-- The preimage of an `AddSubgroup` along an `AddMonoid` homomorphism
is an `AddSubgroup`. -/]
def comap {N : Type*} [Group N] (f : G →* N) (H : Subgroup N) : Subgroup G :=
{ H.toSubmonoid.comap f with
carrier := f ⁻¹' H
inv_mem' := fun {a} ha => show f a⁻¹ ∈ H by rw [f.map_inv]; exact H.inv_mem ha }
@[to_additive (attr := simp)]
theorem coe_comap (K : Subgroup N) (f : G →* N) : (K.comap f : Set G) = f ⁻¹' K :=
rfl
@[to_additive (attr := simp)]
theorem mem_comap {K : Subgroup N} {f : G →* N} {x : G} : x ∈ K.comap f ↔ f x ∈ K :=
Iff.rfl
@[to_additive]
theorem comap_mono {f : G →* N} {K K' : Subgroup N} : K ≤ K' → comap f K ≤ comap f K' :=
preimage_mono
@[to_additive]
theorem comap_comap (K : Subgroup P) (g : N →* P) (f : G →* N) :
(K.comap g).comap f = K.comap (g.comp f) :=
rfl
@[to_additive (attr := simp)]
theorem comap_id (K : Subgroup N) : K.comap (MonoidHom.id _) = K := by
ext
rfl
@[simp]
theorem toAddSubgroup_comap {G₂ : Type*} [Group G₂] (f : G →* G₂) (s : Subgroup G₂) :
s.toAddSubgroup.comap (MonoidHom.toAdditive f) = Subgroup.toAddSubgroup (s.comap f) := rfl
@[simp]
theorem _root_.AddSubgroup.toSubgroup_comap {A A₂ : Type*} [AddGroup A] [AddGroup A₂]
(f : A →+ A₂) (s : AddSubgroup A₂) :
s.toSubgroup.comap (AddMonoidHom.toMultiplicative f) = AddSubgroup.toSubgroup (s.comap f) := rfl
/-- The image of a subgroup along a monoid homomorphism is a subgroup. -/
@[to_additive
/-- The image of an `AddSubgroup` along an `AddMonoid` homomorphism
is an `AddSubgroup`. -/]
def map (f : G →* N) (H : Subgroup G) : Subgroup N :=
{ H.toSubmonoid.map f with
carrier := f '' H
inv_mem' := by
rintro _ ⟨x, hx, rfl⟩
exact ⟨x⁻¹, H.inv_mem hx, f.map_inv x⟩ }
@[to_additive (attr := simp)]
theorem coe_map (f : G →* N) (K : Subgroup G) : (K.map f : Set N) = f '' K :=
rfl
@[to_additive (attr := simp)]
theorem map_toSubmonoid (f : G →* G') (K : Subgroup G) :
(Subgroup.map f K).toSubmonoid = Submonoid.map f K.toSubmonoid := rfl
@[to_additive (attr := simp)]
theorem mem_map {f : G →* N} {K : Subgroup G} {y : N} : y ∈ K.map f ↔ ∃ x ∈ K, f x = y := Iff.rfl
@[to_additive]
theorem mem_map_of_mem (f : G →* N) {K : Subgroup G} {x : G} (hx : x ∈ K) : f x ∈ K.map f :=
mem_image_of_mem f hx
@[to_additive]
theorem apply_coe_mem_map (f : G →* N) (K : Subgroup G) (x : K) : f x ∈ K.map f :=
mem_map_of_mem f x.prop
@[to_additive (attr := gcongr)]
theorem map_mono {f : G →* N} {K K' : Subgroup G} : K ≤ K' → map f K ≤ map f K' :=
image_mono
@[to_additive (attr := simp)]
theorem map_id : K.map (MonoidHom.id G) = K :=
SetLike.coe_injective <| image_id _
@[to_additive]
theorem map_map (g : N →* P) (f : G →* N) : (K.map f).map g = K.map (g.comp f) :=
SetLike.coe_injective <| image_image _ _ _
@[to_additive (attr := simp)]
theorem map_one_eq_bot : K.map (1 : G →* N) = ⊥ :=
eq_bot_iff.mpr <| by
rintro x ⟨y, _, rfl⟩
simp
@[to_additive]
theorem mem_map_equiv {f : G ≃* N} {K : Subgroup G} {x : N} :
x ∈ K.map f.toMonoidHom ↔ f.symm x ∈ K :=
Set.mem_image_equiv
-- The simpNF linter says that the LHS can be simplified via `Subgroup.mem_map`.
-- However this is a higher priority lemma.
-- It seems the side condition `hf` is not applied by `simpNF`.
-- https://github.com/leanprover/std4/issues/207
@[to_additive (attr := simp 1100, nolint simpNF)]
theorem mem_map_iff_mem {f : G →* N} (hf : Function.Injective f) {K : Subgroup G} {x : G} :
f x ∈ K.map f ↔ x ∈ K :=
hf.mem_set_image
@[to_additive]
theorem map_equiv_eq_comap_symm' (f : G ≃* N) (K : Subgroup G) :
K.map f.toMonoidHom = K.comap f.symm.toMonoidHom :=
SetLike.coe_injective (f.toEquiv.image_eq_preimage_symm K)
@[to_additive]
theorem map_equiv_eq_comap_symm (f : G ≃* N) (K : Subgroup G) :
K.map f = K.comap (G := N) f.symm :=
map_equiv_eq_comap_symm' _ _
@[to_additive]
theorem comap_equiv_eq_map_symm (f : N ≃* G) (K : Subgroup G) :
K.comap (G := N) f = K.map f.symm :=
(map_equiv_eq_comap_symm f.symm K).symm
@[to_additive]
theorem comap_equiv_eq_map_symm' (f : N ≃* G) (K : Subgroup G) :
K.comap f.toMonoidHom = K.map f.symm.toMonoidHom :=
(map_equiv_eq_comap_symm f.symm K).symm
@[to_additive]
theorem map_symm_eq_iff_map_eq {H : Subgroup N} {e : G ≃* N} :
H.map ↑e.symm = K ↔ K.map ↑e = H := by
constructor <;> rintro rfl
· rw [map_map, ← MulEquiv.coe_monoidHom_trans, MulEquiv.symm_trans_self,
MulEquiv.coe_monoidHom_refl, map_id]
· rw [map_map, ← MulEquiv.coe_monoidHom_trans, MulEquiv.self_trans_symm,
MulEquiv.coe_monoidHom_refl, map_id]
@[to_additive]
theorem map_le_iff_le_comap {f : G →* N} {K : Subgroup G} {H : Subgroup N} :
K.map f ≤ H ↔ K ≤ H.comap f :=
image_subset_iff
@[to_additive]
theorem gc_map_comap (f : G →* N) : GaloisConnection (map f) (comap f) := fun _ _ =>
map_le_iff_le_comap
@[to_additive]
theorem map_sup (H K : Subgroup G) (f : G →* N) : (H ⊔ K).map f = H.map f ⊔ K.map f :=
(gc_map_comap f).l_sup
@[to_additive]
theorem map_iSup {ι : Sort*} (f : G →* N) (s : ι → Subgroup G) :
(iSup s).map f = ⨆ i, (s i).map f :=
(gc_map_comap f).l_iSup
@[to_additive]
theorem map_inf (H K : Subgroup G) (f : G →* N) (hf : Function.Injective f) :
(H ⊓ K).map f = H.map f ⊓ K.map f := SetLike.coe_injective (Set.image_inter hf)
@[to_additive]
theorem map_iInf {ι : Sort*} [Nonempty ι] (f : G →* N) (hf : Function.Injective f)
(s : ι → Subgroup G) : (iInf s).map f = ⨅ i, (s i).map f := by
apply SetLike.coe_injective
simpa using (Set.injOn_of_injective hf).image_iInter_eq (s := SetLike.coe ∘ s)
@[to_additive]
theorem comap_sup_comap_le (H K : Subgroup N) (f : G →* N) :
comap f H ⊔ comap f K ≤ comap f (H ⊔ K) :=
Monotone.le_map_sup (fun _ _ => comap_mono) H K
@[to_additive]
theorem iSup_comap_le {ι : Sort*} (f : G →* N) (s : ι → Subgroup N) :
⨆ i, (s i).comap f ≤ (iSup s).comap f :=
Monotone.le_map_iSup fun _ _ => comap_mono
@[to_additive]
theorem comap_inf (H K : Subgroup N) (f : G →* N) : (H ⊓ K).comap f = H.comap f ⊓ K.comap f :=
(gc_map_comap f).u_inf
@[to_additive]
theorem comap_iInf {ι : Sort*} (f : G →* N) (s : ι → Subgroup N) :
(iInf s).comap f = ⨅ i, (s i).comap f :=
(gc_map_comap f).u_iInf
@[to_additive]
theorem map_inf_le (H K : Subgroup G) (f : G →* N) : map f (H ⊓ K) ≤ map f H ⊓ map f K :=
le_inf (map_mono inf_le_left) (map_mono inf_le_right)
@[to_additive]
theorem map_inf_eq (H K : Subgroup G) (f : G →* N) (hf : Function.Injective f) :
map f (H ⊓ K) = map f H ⊓ map f K := by
rw [← SetLike.coe_set_eq]
simp [Set.image_inter hf]
@[to_additive (attr := simp)]
theorem map_bot (f : G →* N) : (⊥ : Subgroup G).map f = ⊥ :=
(gc_map_comap f).l_bot
@[to_additive]
lemma disjoint_map {f : G →* N} (hf : Function.Injective f) {H K : Subgroup G} (h : Disjoint H K) :
Disjoint (H.map f) (K.map f) := by
rw [disjoint_iff, ← map_inf _ _ f hf, disjoint_iff.mp h, map_bot]
@[to_additive]
theorem map_top_of_surjective (f : G →* N) (h : Function.Surjective f) : Subgroup.map f ⊤ = ⊤ := by
rw [eq_top_iff]
intro x _
obtain ⟨y, hy⟩ := h x
exact ⟨y, trivial, hy⟩
@[to_additive]
lemma codisjoint_map {f : G →* N} (hf : Function.Surjective f)
{H K : Subgroup G} (h : Codisjoint H K) : Codisjoint (H.map f) (K.map f) := by
rw [codisjoint_iff, ← map_sup, codisjoint_iff.mp h, map_top_of_surjective _ hf]
@[to_additive (attr := simp)]
lemma map_equiv_top {F : Type*} [EquivLike F G N] [MulEquivClass F G N] (f : F) :
map (f : G →* N) ⊤ = ⊤ :=
map_top_of_surjective _ (EquivLike.surjective f)
@[to_additive (attr := simp)]
theorem comap_top (f : G →* N) : (⊤ : Subgroup N).comap f = ⊤ :=
(gc_map_comap f).u_top
/-- For any subgroups `H` and `K`, view `H ⊓ K` as a subgroup of `K`. -/
@[to_additive /-- For any subgroups `H` and `K`, view `H ⊓ K` as a subgroup of `K`. -/]
def subgroupOf (H K : Subgroup G) : Subgroup K :=
H.comap K.subtype
/-- If `H ≤ K`, then `H` as a subgroup of `K` is isomorphic to `H`. -/
@[to_additive (attr := simps)
/-- If `H ≤ K`, then `H` as a subgroup of `K` is isomorphic to `H`. -/]
def subgroupOfEquivOfLe {G : Type*} [Group G] {H K : Subgroup G} (h : H ≤ K) :
H.subgroupOf K ≃* H where
toFun g := ⟨g.1, g.2⟩
invFun g := ⟨⟨g.1, h g.2⟩, g.2⟩
map_mul' _g _h := rfl
@[to_additive (attr := simp)]
theorem comap_subtype (H K : Subgroup G) : H.comap K.subtype = H.subgroupOf K :=
rfl
@[to_additive (attr := simp)]
theorem comap_inclusion_subgroupOf {K₁ K₂ : Subgroup G} (h : K₁ ≤ K₂) (H : Subgroup G) :
(H.subgroupOf K₂).comap (inclusion h) = H.subgroupOf K₁ :=
rfl
@[to_additive]
theorem coe_subgroupOf (H K : Subgroup G) : (H.subgroupOf K : Set K) = K.subtype ⁻¹' H :=
rfl
@[to_additive]
theorem mem_subgroupOf {H K : Subgroup G} {h : K} : h ∈ H.subgroupOf K ↔ (h : G) ∈ H :=
Iff.rfl
-- TODO(kmill): use `K ⊓ H` order for RHS to match `Subtype.image_preimage_coe`
@[to_additive (attr := simp)]
theorem subgroupOf_map_subtype (H K : Subgroup G) : (H.subgroupOf K).map K.subtype = H ⊓ K :=
SetLike.ext' <| by refine Subtype.image_preimage_coe _ _ |>.trans ?_; apply Set.inter_comm
@[to_additive]
theorem map_subgroupOf_eq_of_le {H K : Subgroup G} (h : H ≤ K) :
(H.subgroupOf K).map K.subtype = H := by
rwa [subgroupOf_map_subtype, inf_eq_left]
@[to_additive (attr := simp)]
theorem bot_subgroupOf : (⊥ : Subgroup G).subgroupOf H = ⊥ :=
Eq.symm (Subgroup.ext fun _g => Subtype.ext_iff)
@[to_additive (attr := simp)]
theorem top_subgroupOf : (⊤ : Subgroup G).subgroupOf H = ⊤ :=
rfl
@[to_additive]
theorem subgroupOf_bot_eq_bot : H.subgroupOf ⊥ = ⊥ :=
Subsingleton.elim _ _
@[to_additive]
theorem subgroupOf_bot_eq_top : H.subgroupOf ⊥ = ⊤ :=
Subsingleton.elim _ _
@[to_additive (attr := simp)]
theorem subgroupOf_self : H.subgroupOf H = ⊤ :=
top_unique fun g _hg => g.2
@[to_additive (attr := simp)]
theorem subgroupOf_inj {H₁ H₂ K : Subgroup G} :
H₁.subgroupOf K = H₂.subgroupOf K ↔ H₁ ⊓ K = H₂ ⊓ K := by
simpa only [SetLike.ext_iff, mem_inf, mem_subgroupOf, and_congr_left_iff] using Subtype.forall
@[to_additive (attr := simp)]
theorem inf_subgroupOf_right (H K : Subgroup G) : (H ⊓ K).subgroupOf K = H.subgroupOf K :=
subgroupOf_inj.2 (inf_right_idem _ _)
@[to_additive (attr := simp)]
theorem inf_subgroupOf_left (H K : Subgroup G) : (K ⊓ H).subgroupOf K = H.subgroupOf K := by
rw [inf_comm, inf_subgroupOf_right]
@[to_additive (attr := simp)]
theorem subgroupOf_eq_bot {H K : Subgroup G} : H.subgroupOf K = ⊥ ↔ Disjoint H K := by
rw [disjoint_iff, ← bot_subgroupOf, subgroupOf_inj, bot_inf_eq]
@[to_additive (attr := simp)]
theorem subgroupOf_eq_top {H K : Subgroup G} : H.subgroupOf K = ⊤ ↔ K ≤ H := by
rw [← top_subgroupOf, subgroupOf_inj, top_inf_eq, inf_eq_right]
variable (H : Subgroup G)
@[to_additive]
instance map_isMulCommutative (f : G →* G') [IsMulCommutative H] : IsMulCommutative (H.map f) :=
⟨⟨by
rintro ⟨-, a, ha, rfl⟩ ⟨-, b, hb, rfl⟩
rw [Subtype.ext_iff, coe_mul, coe_mul, Subtype.coe_mk, Subtype.coe_mk, ← map_mul, ← map_mul]
exact congr_arg f (Subtype.ext_iff.mp (mul_comm (⟨a, ha⟩ : H) ⟨b, hb⟩))⟩⟩
@[to_additive]
theorem comap_injective_isMulCommutative {f : G' →* G} (hf : Injective f) [IsMulCommutative H] :
IsMulCommutative (H.comap f) :=
⟨⟨fun a b =>
Subtype.ext
(by
have := mul_comm (⟨f a, a.2⟩ : H) (⟨f b, b.2⟩ : H)
rwa [Subtype.ext_iff, coe_mul, coe_mul, coe_mk, coe_mk, ← map_mul, ← map_mul,
hf.eq_iff] at this)⟩⟩
@[to_additive]
instance subgroupOf_isMulCommutative [IsMulCommutative H] : IsMulCommutative (H.subgroupOf K) :=
H.comap_injective_isMulCommutative Subtype.coe_injective
end Subgroup
namespace MulEquiv
variable {H : Type*} [Group H]
/--
An isomorphism of groups gives an order isomorphism between the lattices of subgroups,
defined by sending subgroups to their inverse images.
See also `MulEquiv.mapSubgroup` which maps subgroups to their forward images.
-/
@[to_additive (attr := simps)
/-- An isomorphism of groups gives an order isomorphism between the lattices of subgroups,
defined by sending subgroups to their inverse images.
See also `AddEquiv.mapAddSubgroup` which maps subgroups to their forward images. -/]
def comapSubgroup (f : G ≃* H) : Subgroup H ≃o Subgroup G where
toFun := Subgroup.comap f
invFun := Subgroup.comap f.symm
left_inv sg := by simp [Subgroup.comap_comap]
right_inv sh := by simp [Subgroup.comap_comap]
map_rel_iff' {sg1 sg2} :=
⟨fun h => by simpa [Subgroup.comap_comap] using
Subgroup.comap_mono (f := (f.symm : H →* G)) h, Subgroup.comap_mono⟩
@[to_additive (attr := simp, norm_cast)]
lemma coe_comapSubgroup (e : G ≃* H) : comapSubgroup e = Subgroup.comap e.toMonoidHom := rfl
@[to_additive (attr := simp)]
lemma symm_comapSubgroup (e : G ≃* H) : (comapSubgroup e).symm = comapSubgroup e.symm := rfl
/--
An isomorphism of groups gives an order isomorphism between the lattices of subgroups,
defined by sending subgroups to their forward images.
See also `MulEquiv.comapSubgroup` which maps subgroups to their inverse images.
-/
@[to_additive (attr := simps)
/-- An isomorphism of groups gives an order isomorphism between the lattices of subgroups,
defined by sending subgroups to their forward images.
See also `AddEquiv.comapAddSubgroup` which maps subgroups to their inverse images. -/]
def mapSubgroup {H : Type*} [Group H] (f : G ≃* H) : Subgroup G ≃o Subgroup H where
toFun := Subgroup.map f
invFun := Subgroup.map f.symm
left_inv sg := by simp [Subgroup.map_map]
right_inv sh := by simp [Subgroup.map_map]
map_rel_iff' {sg1 sg2} :=
⟨fun h => by simpa [Subgroup.map_map] using
Subgroup.map_mono (f := (f.symm : H →* G)) h, Subgroup.map_mono⟩
@[to_additive (attr := simp, norm_cast)]
lemma coe_mapSubgroup (e : G ≃* H) : mapSubgroup e = Subgroup.map e.toMonoidHom := rfl
@[to_additive (attr := simp)]
lemma symm_mapSubgroup (e : G ≃* H) : (mapSubgroup e).symm = mapSubgroup e.symm := rfl
end MulEquiv
namespace Subgroup
open MonoidHom
variable {N : Type*} [Group N] (f : G →* N)
@[to_additive (attr := simp, norm_cast)]
lemma comap_toSubmonoid (e : G ≃* N) (s : Subgroup N) :
(s.comap e).toSubmonoid = s.toSubmonoid.comap e.toMonoidHom := rfl
@[to_additive]
theorem map_comap_le (H : Subgroup N) : map f (comap f H) ≤ H :=
(gc_map_comap f).l_u_le _
@[to_additive]
theorem le_comap_map (H : Subgroup G) : H ≤ comap f (map f H) :=
(gc_map_comap f).le_u_l _
@[to_additive]
theorem map_eq_comap_of_inverse {f : G →* N} {g : N →* G} (hl : Function.LeftInverse g f)
(hr : Function.RightInverse g f) (H : Subgroup G) : map f H = comap g H :=
SetLike.ext' <| by rw [coe_map, coe_comap, Set.image_eq_preimage_of_inverse hl hr]
/-- A subgroup is isomorphic to its image under an injective function. If you have an isomorphism,
use `MulEquiv.subgroupMap` for better definitional equalities. -/
@[to_additive
/-- An additive subgroup is isomorphic to its image under an injective function. If you
have an isomorphism, use `AddEquiv.addSubgroupMap` for better definitional equalities. -/]
noncomputable def equivMapOfInjective (H : Subgroup G) (f : G →* N) (hf : Function.Injective f) :
H ≃* H.map f :=
{ Equiv.Set.image f H hf with map_mul' := fun _ _ => Subtype.ext (f.map_mul _ _) }
@[to_additive (attr := simp)]
theorem coe_equivMapOfInjective_apply (H : Subgroup G) (f : G →* N) (hf : Function.Injective f)
(h : H) : (equivMapOfInjective H f hf h : N) = f h :=
rfl
end Subgroup
variable {N : Type*} [Group N]
namespace MonoidHom
/-- The `MonoidHom` from the preimage of a subgroup to itself. -/
@[to_additive (attr := simps!) /-- the `AddMonoidHom` from the preimage of an
additive subgroup to itself. -/]
def subgroupComap (f : G →* G') (H' : Subgroup G') : H'.comap f →* H' :=
f.submonoidComap H'.toSubmonoid
@[to_additive]
lemma subgroupComap_surjective_of_surjective (f : G →* G') (H' : Subgroup G') (hf : Surjective f) :
Surjective (f.subgroupComap H') :=
f.submonoidComap_surjective_of_surjective H'.toSubmonoid hf
/-- The `MonoidHom` from a subgroup to its image. -/
@[to_additive (attr := simps!) /-- the `AddMonoidHom` from an additive subgroup to its image -/]
def subgroupMap (f : G →* G') (H : Subgroup G) : H →* H.map f :=
f.submonoidMap H.toSubmonoid
@[to_additive]
theorem subgroupMap_surjective (f : G →* G') (H : Subgroup G) :
Function.Surjective (f.subgroupMap H) :=
f.submonoidMap_surjective H.toSubmonoid
end MonoidHom
namespace MulEquiv
variable {H K : Subgroup G}
/-- Makes the identity isomorphism from a proof two subgroups of a multiplicative
group are equal. -/
@[to_additive
/-- Makes the identity additive isomorphism from a proof
two subgroups of an additive group are equal. -/]
def subgroupCongr (h : H = K) : H ≃* K :=
{ Equiv.setCongr <| congr_arg _ h with map_mul' := fun _ _ => rfl }
@[to_additive (attr := simp)]
lemma subgroupCongr_apply (h : H = K) (x) :
(MulEquiv.subgroupCongr h x : G) = x := rfl
@[to_additive (attr := simp)]
lemma subgroupCongr_symm_apply (h : H = K) (x) :
((MulEquiv.subgroupCongr h).symm x : G) = x := rfl
/-- A subgroup is isomorphic to its image under an isomorphism. If you only have an injective map,
use `Subgroup.equivMapOfInjective`. -/
@[to_additive
/-- An additive subgroup is isomorphic to its image under an isomorphism. If you only
have an injective map, use `AddSubgroup.equivMapOfInjective`. -/]
def subgroupMap (e : G ≃* G') (H : Subgroup G) : H ≃* H.map (e : G →* G') :=
MulEquiv.submonoidMap (e : G ≃* G') H.toSubmonoid
@[to_additive (attr := simp)]
theorem coe_subgroupMap_apply (e : G ≃* G') (H : Subgroup G) (g : H) :
((subgroupMap e H g : H.map (e : G →* G')) : G') = e g :=
rfl
@[to_additive (attr := simp)]
theorem subgroupMap_symm_apply (e : G ≃* G') (H : Subgroup G) (g : H.map (e : G →* G')) :
(e.subgroupMap H).symm g = ⟨e.symm g, SetLike.mem_coe.1 <| Set.mem_image_equiv.1 g.2⟩ :=
rfl
end MulEquiv
namespace MonoidHom
open Subgroup
@[to_additive]
theorem closure_preimage_le (f : G →* N) (s : Set N) : closure (f ⁻¹' s) ≤ (closure s).comap f :=
(closure_le _).2 fun x hx => by rw [SetLike.mem_coe, mem_comap]; exact subset_closure hx
/-- The image under a monoid homomorphism of the subgroup generated by a set equals the subgroup
generated by the image of the set. -/
@[to_additive
/-- The image under an `AddMonoid` hom of the `AddSubgroup` generated by a set equals
the `AddSubgroup` generated by the image of the set. -/]
theorem map_closure (f : G →* N) (s : Set G) : (closure s).map f = closure (f '' s) :=
Set.image_preimage.l_comm_of_u_comm (gc_map_comap f) (Subgroup.gi N).gc (Subgroup.gi G).gc
fun _ ↦ rfl
end MonoidHom
namespace Subgroup
@[to_additive]
lemma surjOn_iff_le_map {f : G →* N} {H : Subgroup G} {K : Subgroup N} :
Set.SurjOn f H K ↔ K ≤ H.map f :=
Iff.rfl
@[to_additive (attr := simp)]
theorem equivMapOfInjective_coe_mulEquiv (H : Subgroup G) (e : G ≃* G') :
H.equivMapOfInjective (e : G →* G') (EquivLike.injective e) = e.subgroupMap H := by
ext
rfl
end Subgroup |
.lake/packages/mathlib/Mathlib/Algebra/Group/Subgroup/Actions.lean | import Mathlib.Algebra.Group.Submonoid.DistribMulAction
import Mathlib.GroupTheory.Subgroup.Center
/-!
# Actions by `Subgroup`s
These are just copies of the definitions about `Submonoid` starting from `Submonoid.mulAction`.
## Tags
subgroup, subgroups
-/
namespace Subgroup
variable {G α β : Type*} [Group G]
section MulAction
variable [MulAction G α] {S : Subgroup G}
/-- The action by a subgroup is the action by the underlying group. -/
@[to_additive
/-- The additive action by an add_subgroup is the action by the underlying `AddGroup`. -/]
instance instMulAction : MulAction S α := inferInstanceAs (MulAction S.toSubmonoid α)
@[to_additive] lemma smul_def (g : S) (m : α) : g • m = (g : G) • m := rfl
@[to_additive (attr := simp)]
lemma mk_smul (g : G) (hg : g ∈ S) (a : α) : (⟨g, hg⟩ : S) • a = g • a := rfl
end MulAction
@[to_additive]
instance smulCommClass_left [MulAction G β] [SMul α β] [SMulCommClass G α β] (S : Subgroup G) :
SMulCommClass S α β :=
S.toSubmonoid.smulCommClass_left
@[to_additive]
instance smulCommClass_right [SMul α β] [MulAction G β] [SMulCommClass α G β] (S : Subgroup G) :
SMulCommClass α S β :=
S.toSubmonoid.smulCommClass_right
/-- Note that this provides `IsScalarTower S G G` which is needed by `smul_mul_assoc`. -/
@[to_additive]
instance [SMul α β] [MulAction G α] [MulAction G β] [IsScalarTower G α β] (S : Subgroup G) :
IsScalarTower S α β :=
inferInstanceAs (IsScalarTower S.toSubmonoid α β)
@[to_additive]
instance [MulAction G α] [FaithfulSMul G α] (S : Subgroup G) : FaithfulSMul S α :=
inferInstanceAs (FaithfulSMul S.toSubmonoid α)
/-- The action by a subgroup is the action by the underlying group. -/
instance [AddMonoid α] [DistribMulAction G α] (S : Subgroup G) : DistribMulAction S α :=
inferInstanceAs (DistribMulAction S.toSubmonoid α)
/-- The action by a subgroup is the action by the underlying group. -/
instance [Monoid α] [MulDistribMulAction G α] (S : Subgroup G) : MulDistribMulAction S α :=
inferInstanceAs (MulDistribMulAction S.toSubmonoid α)
/-- The center of a group acts commutatively on that group. -/
instance center.smulCommClass_left : SMulCommClass (center G) G G :=
Submonoid.center.smulCommClass_left
/-- The center of a group acts commutatively on that group. -/
instance center.smulCommClass_right : SMulCommClass G (center G) G :=
Submonoid.center.smulCommClass_right
end Subgroup |
.lake/packages/mathlib/Mathlib/Algebra/Group/Subgroup/Basic.lean | import Mathlib.Algebra.Group.Conj
import Mathlib.Algebra.Group.Pi.Lemmas
import Mathlib.Algebra.Group.Subgroup.Ker
import Mathlib.Algebra.Group.Torsion
/-!
# Basic results on subgroups
We prove basic results on the definitions of subgroups. The bundled subgroups use bundled monoid
homomorphisms.
Special thanks goes to Amelia Livingston and Yury Kudryashov for their help and inspiration.
## Main definitions
Notation used here:
- `G N` are `Group`s
- `A` is an `AddGroup`
- `H K` are `Subgroup`s of `G` or `AddSubgroup`s of `A`
- `x` is an element of type `G` or type `A`
- `f g : N →* G` are group homomorphisms
- `s k` are sets of elements of type `G`
Definitions in the file:
* `Subgroup.prod H K` : the product of subgroups `H`, `K` of groups `G`, `N` respectively, `H × K`
is a subgroup of `G × N`
## Implementation notes
Subgroup inclusion is denoted `≤` rather than `⊆`, although `∈` is defined as
membership of a subgroup's underlying set.
## Tags
subgroup, subgroups
-/
assert_not_exists IsOrderedMonoid Multiset Ring
open Function
open scoped Int
variable {G G' G'' : Type*} [Group G] [Group G'] [Group G'']
variable {A : Type*} [AddGroup A]
section SubgroupClass
variable {M S : Type*} [DivInvMonoid M] [SetLike S M] [hSM : SubgroupClass S M] {H K : S}
variable [SetLike S G] [SubgroupClass S G]
@[to_additive]
theorem div_mem_comm_iff {a b : G} : a / b ∈ H ↔ b / a ∈ H :=
inv_div b a ▸ inv_mem_iff
end SubgroupClass
namespace Subgroup
variable (H K : Subgroup G)
@[to_additive]
protected theorem div_mem_comm_iff {a b : G} : a / b ∈ H ↔ b / a ∈ H :=
div_mem_comm_iff
variable {k : Set G}
open Set
variable {N : Type*} [Group N] {P : Type*} [Group P]
/-- Given `Subgroup`s `H`, `K` of groups `G`, `N` respectively, `H × K` as a subgroup of `G × N`. -/
@[to_additive prod
/-- Given `AddSubgroup`s `H`, `K` of `AddGroup`s `A`, `B` respectively, `H × K`
as an `AddSubgroup` of `A × B`. -/]
def prod (H : Subgroup G) (K : Subgroup N) : Subgroup (G × N) :=
{ Submonoid.prod H.toSubmonoid K.toSubmonoid with
inv_mem' := fun hx => ⟨H.inv_mem' hx.1, K.inv_mem' hx.2⟩ }
@[to_additive (attr := norm_cast) coe_prod]
theorem coe_prod (H : Subgroup G) (K : Subgroup N) :
(H.prod K : Set (G × N)) = (H : Set G) ×ˢ (K : Set N) :=
rfl
@[to_additive mem_prod]
theorem mem_prod {H : Subgroup G} {K : Subgroup N} {p : G × N} : p ∈ H.prod K ↔ p.1 ∈ H ∧ p.2 ∈ K :=
Iff.rfl
open scoped Relator in
@[to_additive prod_mono]
theorem prod_mono : ((· ≤ ·) ⇒ (· ≤ ·) ⇒ (· ≤ ·)) (@prod G _ N _) (@prod G _ N _) :=
fun _s _s' hs _t _t' ht => Set.prod_mono hs ht
@[to_additive prod_mono_right]
theorem prod_mono_right (K : Subgroup G) : Monotone fun t : Subgroup N => K.prod t :=
prod_mono (le_refl K)
@[to_additive prod_mono_left]
theorem prod_mono_left (H : Subgroup N) : Monotone fun K : Subgroup G => K.prod H := fun _ _ hs =>
prod_mono hs (le_refl H)
@[to_additive prod_top]
theorem prod_top (K : Subgroup G) : K.prod (⊤ : Subgroup N) = K.comap (MonoidHom.fst G N) :=
ext fun x => by simp [mem_prod, MonoidHom.coe_fst]
@[to_additive top_prod]
theorem top_prod (H : Subgroup N) : (⊤ : Subgroup G).prod H = H.comap (MonoidHom.snd G N) :=
ext fun x => by simp [mem_prod, MonoidHom.coe_snd]
@[to_additive (attr := simp) top_prod_top]
theorem top_prod_top : (⊤ : Subgroup G).prod (⊤ : Subgroup N) = ⊤ :=
(top_prod _).trans <| comap_top _
@[to_additive (attr := simp) bot_prod_bot]
theorem bot_prod_bot : (⊥ : Subgroup G).prod (⊥ : Subgroup N) = ⊥ :=
SetLike.coe_injective <| by simp [coe_prod]
@[to_additive le_prod_iff]
theorem le_prod_iff {H : Subgroup G} {K : Subgroup N} {J : Subgroup (G × N)} :
J ≤ H.prod K ↔ map (MonoidHom.fst G N) J ≤ H ∧ map (MonoidHom.snd G N) J ≤ K := by
simpa only [← Subgroup.toSubmonoid_le] using Submonoid.le_prod_iff
@[to_additive prod_le_iff]
theorem prod_le_iff {H : Subgroup G} {K : Subgroup N} {J : Subgroup (G × N)} :
H.prod K ≤ J ↔ map (MonoidHom.inl G N) H ≤ J ∧ map (MonoidHom.inr G N) K ≤ J := by
simpa only [← Subgroup.toSubmonoid_le] using Submonoid.prod_le_iff
@[to_additive (attr := simp) prod_eq_bot_iff]
theorem prod_eq_bot_iff {H : Subgroup G} {K : Subgroup N} : H.prod K = ⊥ ↔ H = ⊥ ∧ K = ⊥ := by
simpa only [← Subgroup.toSubmonoid_inj] using Submonoid.prod_eq_bot_iff
@[to_additive closure_prod]
theorem closure_prod {s : Set G} {t : Set N} (hs : 1 ∈ s) (ht : 1 ∈ t) :
closure (s ×ˢ t) = (closure s).prod (closure t) :=
le_antisymm
(closure_le _ |>.2 <| Set.prod_subset_prod_iff.2 <| .inl ⟨subset_closure, subset_closure⟩)
(prod_le_iff.2 ⟨
map_le_iff_le_comap.2 <| closure_le _ |>.2 fun _x hx => subset_closure ⟨hx, ht⟩,
map_le_iff_le_comap.2 <| closure_le _ |>.2 fun _y hy => subset_closure ⟨hs, hy⟩⟩)
/-- Product of subgroups is isomorphic to their product as groups. -/
@[to_additive prodEquiv
/-- Product of additive subgroups is isomorphic to their product
as additive groups -/]
def prodEquiv (H : Subgroup G) (K : Subgroup N) : H.prod K ≃* H × K :=
{ Equiv.Set.prod (H : Set G) (K : Set N) with map_mul' := fun _ _ => rfl }
section Pi
variable {η : Type*} {f : η → Type*}
variable [∀ i, Group (f i)]
/-- A version of `Set.pi` for subgroups. Given an index set `I` and a family of submodules
`s : Π i, Subgroup f i`, `pi I s` is the subgroup of dependent functions `f : Π i, f i` such that
`f i` belongs to `pi I s` whenever `i ∈ I`. -/
@[to_additive
/-- A version of `Set.pi` for `AddSubgroup`s. Given an index set `I` and a family
of submodules `s : Π i, AddSubgroup f i`, `pi I s` is the `AddSubgroup` of dependent functions
`f : Π i, f i` such that `f i` belongs to `pi I s` whenever `i ∈ I`. -/]
def pi (I : Set η) (H : ∀ i, Subgroup (f i)) : Subgroup (∀ i, f i) :=
{ Submonoid.pi I fun i => (H i).toSubmonoid with
inv_mem' := fun hp i hI => (H i).inv_mem (hp i hI) }
@[to_additive]
theorem coe_pi (I : Set η) (H : ∀ i, Subgroup (f i)) :
(pi I H : Set (∀ i, f i)) = Set.pi I fun i => (H i : Set (f i)) :=
rfl
@[to_additive]
theorem mem_pi (I : Set η) {H : ∀ i, Subgroup (f i)} {p : ∀ i, f i} :
p ∈ pi I H ↔ ∀ i : η, i ∈ I → p i ∈ H i :=
Iff.rfl
@[to_additive]
theorem pi_top (I : Set η) : (pi I fun i => (⊤ : Subgroup (f i))) = ⊤ :=
ext fun x => by simp [mem_pi]
@[to_additive]
theorem pi_empty (H : ∀ i, Subgroup (f i)) : pi ∅ H = ⊤ :=
ext fun x => by simp [mem_pi]
@[to_additive]
theorem pi_bot : (pi Set.univ fun i => (⊥ : Subgroup (f i))) = ⊥ :=
ext fun x => by simp [mem_pi, funext_iff]
@[to_additive]
theorem le_pi_iff {I : Set η} {H : ∀ i, Subgroup (f i)} {J : Subgroup (∀ i, f i)} :
J ≤ pi I H ↔ ∀ i ∈ I, J ≤ comap (Pi.evalMonoidHom f i) (H i) :=
Set.subset_pi_iff
@[to_additive (attr := simp)]
theorem mulSingle_mem_pi [DecidableEq η] {I : Set η} {H : ∀ i, Subgroup (f i)} (i : η) (x : f i) :
Pi.mulSingle i x ∈ pi I H ↔ i ∈ I → x ∈ H i :=
Set.update_mem_pi_iff_of_mem (one_mem (pi I H))
@[to_additive]
theorem pi_eq_bot_iff (H : ∀ i, Subgroup (f i)) : pi Set.univ H = ⊥ ↔ ∀ i, H i = ⊥ := by
simp_rw [SetLike.ext'_iff]
exact Set.univ_pi_eq_singleton_iff
end Pi
instance instIsMulTorsionFree [IsMulTorsionFree G] : IsMulTorsionFree H where
pow_left_injective n hn a b := by
have := pow_left_injective hn (M := G) (a₁ := a) (a₂ := b)
dsimp at *
norm_cast at this
end Subgroup
namespace Subgroup
variable {H K : Subgroup G}
variable (H)
/-- A subgroup is characteristic if it is fixed by all automorphisms.
Several equivalent conditions are provided by lemmas of the form `Characteristic.iff...` -/
structure Characteristic : Prop where
/-- `H` is fixed by all automorphisms -/
fixed : ∀ ϕ : G ≃* G, H.comap ϕ.toMonoidHom = H
attribute [class] Characteristic
instance (priority := 100) normal_of_characteristic [h : H.Characteristic] : H.Normal :=
⟨fun a ha b => (SetLike.ext_iff.mp (h.fixed (MulAut.conj b)) a).mpr ha⟩
end Subgroup
namespace AddSubgroup
variable (H : AddSubgroup A)
/-- An `AddSubgroup` is characteristic if it is fixed by all automorphisms.
Several equivalent conditions are provided by lemmas of the form `Characteristic.iff...` -/
structure Characteristic : Prop where
/-- `H` is fixed by all automorphisms -/
fixed : ∀ ϕ : A ≃+ A, H.comap ϕ.toAddMonoidHom = H
attribute [to_additive] Subgroup.Characteristic
attribute [class] Characteristic
instance (priority := 100) normal_of_characteristic [h : H.Characteristic] : H.Normal :=
⟨fun a ha b => (SetLike.ext_iff.mp (h.fixed (AddAut.conj b)) a).mpr ha⟩
end AddSubgroup
namespace Subgroup
variable {H K : Subgroup G}
@[to_additive]
theorem characteristic_iff_comap_eq : H.Characteristic ↔ ∀ ϕ : G ≃* G, H.comap ϕ.toMonoidHom = H :=
⟨Characteristic.fixed, Characteristic.mk⟩
@[to_additive]
theorem characteristic_iff_comap_le : H.Characteristic ↔ ∀ ϕ : G ≃* G, H.comap ϕ.toMonoidHom ≤ H :=
characteristic_iff_comap_eq.trans
⟨fun h ϕ => le_of_eq (h ϕ), fun h ϕ =>
le_antisymm (h ϕ) fun g hg => h ϕ.symm ((congr_arg (· ∈ H) (ϕ.symm_apply_apply g)).mpr hg)⟩
@[to_additive]
theorem characteristic_iff_le_comap : H.Characteristic ↔ ∀ ϕ : G ≃* G, H ≤ H.comap ϕ.toMonoidHom :=
characteristic_iff_comap_eq.trans
⟨fun h ϕ => ge_of_eq (h ϕ), fun h ϕ =>
le_antisymm (fun g hg => (congr_arg (· ∈ H) (ϕ.symm_apply_apply g)).mp (h ϕ.symm hg)) (h ϕ)⟩
@[to_additive]
theorem characteristic_iff_map_eq : H.Characteristic ↔ ∀ ϕ : G ≃* G, H.map ϕ.toMonoidHom = H := by
simp_rw [map_equiv_eq_comap_symm']
exact characteristic_iff_comap_eq.trans ⟨fun h ϕ => h ϕ.symm, fun h ϕ => h ϕ.symm⟩
@[to_additive]
theorem characteristic_iff_map_le : H.Characteristic ↔ ∀ ϕ : G ≃* G, H.map ϕ.toMonoidHom ≤ H := by
simp_rw [map_equiv_eq_comap_symm']
exact characteristic_iff_comap_le.trans ⟨fun h ϕ => h ϕ.symm, fun h ϕ => h ϕ.symm⟩
@[to_additive]
theorem characteristic_iff_le_map : H.Characteristic ↔ ∀ ϕ : G ≃* G, H ≤ H.map ϕ.toMonoidHom := by
simp_rw [map_equiv_eq_comap_symm']
exact characteristic_iff_le_comap.trans ⟨fun h ϕ => h ϕ.symm, fun h ϕ => h ϕ.symm⟩
@[to_additive]
instance botCharacteristic : Characteristic (⊥ : Subgroup G) :=
characteristic_iff_le_map.mpr fun _ϕ => bot_le
@[to_additive]
instance topCharacteristic : Characteristic (⊤ : Subgroup G) :=
characteristic_iff_map_le.mpr fun _ϕ => le_top
variable (H)
section Normalizer
variable {H}
@[to_additive]
theorem normalizer_eq_top_iff : H.normalizer = ⊤ ↔ H.Normal :=
eq_top_iff.trans
⟨fun h => ⟨fun a ha b => (h (mem_top b) a).mp ha⟩, fun h a _ha b =>
⟨fun hb => h.conj_mem b hb a, fun hb => by rwa [h.mem_comm_iff, inv_mul_cancel_left] at hb⟩⟩
variable (H) in
@[to_additive]
theorem normalizer_eq_top [h : H.Normal] : H.normalizer = ⊤ :=
normalizer_eq_top_iff.mpr h
variable {N : Type*} [Group N]
/-- The preimage of the normalizer is contained in the normalizer of the preimage. -/
@[to_additive /-- The preimage of the normalizer is contained in the normalizer of the preimage. -/]
theorem le_normalizer_comap (f : N →* G) :
H.normalizer.comap f ≤ (H.comap f).normalizer := fun x => by
simp only [mem_normalizer_iff, mem_comap]
intro h n
simp [h (f n)]
/-- The image of the normalizer is contained in the normalizer of the image. -/
@[to_additive /-- The image of the normalizer is contained in the normalizer of the image. -/]
theorem le_normalizer_map (f : G →* N) : H.normalizer.map f ≤ (H.map f).normalizer := fun _ => by
simp only [and_imp, mem_map, exists_imp, mem_normalizer_iff]
rintro x hx rfl n
constructor
· rintro ⟨y, hy, rfl⟩
use x * y * x⁻¹, (hx y).1 hy
simp
· rintro ⟨y, hyH, hy⟩
use x⁻¹ * y * x
rw [hx]
simp [hy, hyH, mul_assoc]
@[to_additive]
theorem comap_normalizer_eq_of_le_range {f : N →* G} (h : H ≤ f.range) :
comap f H.normalizer = (comap f H).normalizer := by
apply le_antisymm (le_normalizer_comap f)
rw [← map_le_iff_le_comap]
apply (le_normalizer_map f).trans
rw [map_comap_eq_self h]
@[to_additive]
theorem subgroupOf_normalizer_eq {H N : Subgroup G} (h : H ≤ N) :
H.normalizer.subgroupOf N = (H.subgroupOf N).normalizer :=
comap_normalizer_eq_of_le_range (h.trans_eq N.range_subtype.symm)
@[to_additive]
theorem normal_subgroupOf_iff_le_normalizer (h : H ≤ K) :
(H.subgroupOf K).Normal ↔ K ≤ H.normalizer := by
rw [← subgroupOf_eq_top, subgroupOf_normalizer_eq h, normalizer_eq_top_iff]
@[to_additive]
theorem normal_subgroupOf_iff_le_normalizer_inf :
(H.subgroupOf K).Normal ↔ K ≤ (H ⊓ K).normalizer :=
inf_subgroupOf_right H K ▸ normal_subgroupOf_iff_le_normalizer inf_le_right
@[to_additive]
instance (priority := 100) normal_in_normalizer : (H.subgroupOf H.normalizer).Normal :=
(normal_subgroupOf_iff_le_normalizer H.le_normalizer).mpr le_rfl
@[to_additive]
theorem le_normalizer_of_normal_subgroupOf [hK : (H.subgroupOf K).Normal] (HK : H ≤ K) :
K ≤ H.normalizer :=
(normal_subgroupOf_iff_le_normalizer HK).mp hK
@[to_additive]
theorem subset_normalizer_of_normal {S : Set G} [hH : H.Normal] : S ⊆ H.normalizer :=
(@normalizer_eq_top _ _ H hH) ▸ le_top
@[to_additive]
theorem le_normalizer_of_normal [H.Normal] : K ≤ H.normalizer := subset_normalizer_of_normal
@[to_additive]
theorem inf_normalizer_le_normalizer_inf : H.normalizer ⊓ K.normalizer ≤ (H ⊓ K).normalizer :=
fun _ h g ↦ and_congr (h.1 g) (h.2 g)
variable (G) in
/-- Every proper subgroup `H` of `G` is a proper normal subgroup of the normalizer of `H` in `G`. -/
def _root_.NormalizerCondition :=
∀ H : Subgroup G, H < ⊤ → H < normalizer H
/-- Alternative phrasing of the normalizer condition: Only the full group is self-normalizing.
This may be easier to work with, as it avoids inequalities and negations. -/
theorem _root_.normalizerCondition_iff_only_full_group_self_normalizing :
NormalizerCondition G ↔ ∀ H : Subgroup G, H.normalizer = H → H = ⊤ := by
apply forall_congr'; intro H
simp only [lt_iff_le_and_ne, le_normalizer, le_top, Ne]
tauto
variable (H)
end Normalizer
end Subgroup
namespace Group
variable {s : Set G}
/-- Given a set `s`, `conjugatesOfSet s` is the set of all conjugates of
the elements of `s`. -/
def conjugatesOfSet (s : Set G) : Set G :=
⋃ a ∈ s, conjugatesOf a
theorem mem_conjugatesOfSet_iff {x : G} : x ∈ conjugatesOfSet s ↔ ∃ a ∈ s, IsConj a x := by
rw [conjugatesOfSet, Set.mem_iUnion₂]
simp only [conjugatesOf, isConj_iff, Set.mem_setOf_eq, exists_prop]
theorem subset_conjugatesOfSet : s ⊆ conjugatesOfSet s := fun (x : G) (h : x ∈ s) =>
mem_conjugatesOfSet_iff.2 ⟨x, h, IsConj.refl _⟩
theorem conjugatesOfSet_mono {s t : Set G} (h : s ⊆ t) : conjugatesOfSet s ⊆ conjugatesOfSet t :=
Set.biUnion_subset_biUnion_left h
theorem conjugates_subset_normal {N : Subgroup G} [tn : N.Normal] {a : G} (h : a ∈ N) :
conjugatesOf a ⊆ N := by
rintro a hc
obtain ⟨c, rfl⟩ := isConj_iff.1 hc
exact tn.conj_mem a h c
theorem conjugatesOfSet_subset {s : Set G} {N : Subgroup G} [N.Normal] (h : s ⊆ N) :
conjugatesOfSet s ⊆ N :=
Set.iUnion₂_subset fun _x H => conjugates_subset_normal (h H)
/-- The set of conjugates of `s` is closed under conjugation. -/
theorem conj_mem_conjugatesOfSet {x c : G} :
x ∈ conjugatesOfSet s → c * x * c⁻¹ ∈ conjugatesOfSet s := fun H => by
rcases mem_conjugatesOfSet_iff.1 H with ⟨a, h₁, h₂⟩
exact mem_conjugatesOfSet_iff.2 ⟨a, h₁, h₂.trans (isConj_iff.2 ⟨c, rfl⟩)⟩
end Group
namespace Subgroup
open Group
variable {s : Set G}
/-- The normal closure of a set `s` is the subgroup closure of all the conjugates of
elements of `s`. It is the smallest normal subgroup containing `s`. -/
def normalClosure (s : Set G) : Subgroup G :=
closure (conjugatesOfSet s)
theorem conjugatesOfSet_subset_normalClosure : conjugatesOfSet s ⊆ normalClosure s :=
subset_closure
theorem subset_normalClosure : s ⊆ normalClosure s :=
Set.Subset.trans subset_conjugatesOfSet conjugatesOfSet_subset_normalClosure
theorem le_normalClosure {H : Subgroup G} : H ≤ normalClosure ↑H := fun _ h =>
subset_normalClosure h
/-- The normal closure of `s` is a normal subgroup. -/
instance normalClosure_normal : (normalClosure s).Normal :=
⟨fun n h g => by
refine Subgroup.closure_induction (fun x hx => ?_) ?_ (fun x y _ _ ihx ihy => ?_)
(fun x _ ihx => ?_) h
· exact conjugatesOfSet_subset_normalClosure (conj_mem_conjugatesOfSet hx)
· simp
· rw [← conj_mul]
exact mul_mem ihx ihy
· rw [← conj_inv]
exact inv_mem ihx⟩
/-- The normal closure of `s` is the smallest normal subgroup containing `s`. -/
theorem normalClosure_le_normal {N : Subgroup G} [N.Normal] (h : s ⊆ N) : normalClosure s ≤ N := by
intro a w
refine closure_induction (fun x hx => ?_) ?_ (fun x y _ _ ihx ihy => ?_) (fun x _ ihx => ?_) w
· exact conjugatesOfSet_subset h hx
· exact one_mem _
· exact mul_mem ihx ihy
· exact inv_mem ihx
theorem normalClosure_subset_iff {N : Subgroup G} [N.Normal] : s ⊆ N ↔ normalClosure s ≤ N :=
⟨normalClosure_le_normal, Set.Subset.trans subset_normalClosure⟩
@[gcongr]
theorem normalClosure_mono {s t : Set G} (h : s ⊆ t) : normalClosure s ≤ normalClosure t :=
normalClosure_le_normal (Set.Subset.trans h subset_normalClosure)
theorem normalClosure_eq_iInf :
normalClosure s = ⨅ (N : Subgroup G) (_ : Normal N) (_ : s ⊆ N), N :=
le_antisymm (le_iInf fun _ => le_iInf fun _ => le_iInf normalClosure_le_normal)
(iInf_le_of_le (normalClosure s)
(iInf_le_of_le (by infer_instance) (iInf_le_of_le subset_normalClosure le_rfl)))
@[simp]
theorem normalClosure_eq_self (H : Subgroup G) [H.Normal] : normalClosure ↑H = H :=
le_antisymm (normalClosure_le_normal rfl.subset) le_normalClosure
theorem normalClosure_idempotent : normalClosure ↑(normalClosure s) = normalClosure s :=
normalClosure_eq_self _
theorem closure_le_normalClosure {s : Set G} : closure s ≤ normalClosure s := by
simp only [subset_normalClosure, closure_le]
@[simp]
theorem normalClosure_closure_eq_normalClosure {s : Set G} :
normalClosure ↑(closure s) = normalClosure s :=
le_antisymm (normalClosure_le_normal closure_le_normalClosure) (normalClosure_mono subset_closure)
/-- The normal core of a subgroup `H` is the largest normal subgroup of `G` contained in `H`,
as shown by `Subgroup.normalCore_eq_iSup`. -/
def normalCore (H : Subgroup G) : Subgroup G where
carrier := { a : G | ∀ b : G, b * a * b⁻¹ ∈ H }
one_mem' a := by rw [mul_one, mul_inv_cancel]; exact H.one_mem
inv_mem' {_} h b := (congr_arg (· ∈ H) conj_inv).mp (H.inv_mem (h b))
mul_mem' {_ _} ha hb c := (congr_arg (· ∈ H) conj_mul).mp (H.mul_mem (ha c) (hb c))
theorem normalCore_le (H : Subgroup G) : H.normalCore ≤ H := fun a h => by
rw [← mul_one a, ← inv_one, ← one_mul a]
exact h 1
instance normalCore_normal (H : Subgroup G) : H.normalCore.Normal :=
⟨fun a h b c => by
rw [mul_assoc, mul_assoc, ← mul_inv_rev, ← mul_assoc, ← mul_assoc]; exact h (c * b)⟩
theorem normal_le_normalCore {H : Subgroup G} {N : Subgroup G} [hN : N.Normal] :
N ≤ H.normalCore ↔ N ≤ H :=
⟨ge_trans H.normalCore_le, fun h_le n hn g => h_le (hN.conj_mem n hn g)⟩
theorem normalCore_mono {H K : Subgroup G} (h : H ≤ K) : H.normalCore ≤ K.normalCore :=
normal_le_normalCore.mpr (H.normalCore_le.trans h)
theorem normalCore_eq_iSup (H : Subgroup G) :
H.normalCore = ⨆ (N : Subgroup G) (_ : Normal N) (_ : N ≤ H), N :=
le_antisymm
(le_iSup_of_le H.normalCore
(le_iSup_of_le H.normalCore_normal (le_iSup_of_le H.normalCore_le le_rfl)))
(iSup_le fun _ => iSup_le fun _ => iSup_le normal_le_normalCore.mpr)
@[simp]
theorem normalCore_eq_self (H : Subgroup G) [H.Normal] : H.normalCore = H :=
le_antisymm H.normalCore_le (normal_le_normalCore.mpr le_rfl)
theorem normalCore_idempotent (H : Subgroup G) : H.normalCore.normalCore = H.normalCore :=
H.normalCore.normalCore_eq_self
end Subgroup
namespace MonoidHom
variable {N : Type*} {P : Type*} [Group N] [Group P] (K : Subgroup G)
open Subgroup
section Ker
variable {M : Type*} [MulOneClass M]
@[to_additive prodMap_comap_prod]
theorem prodMap_comap_prod {G' : Type*} {N' : Type*} [Group G'] [Group N'] (f : G →* N)
(g : G' →* N') (S : Subgroup N) (S' : Subgroup N') :
(S.prod S').comap (prodMap f g) = (S.comap f).prod (S'.comap g) :=
SetLike.coe_injective <| Set.preimage_prod_map_prod f g _ _
@[to_additive ker_prodMap]
theorem ker_prodMap {G' : Type*} {N' : Type*} [Group G'] [Group N'] (f : G →* N) (g : G' →* N') :
(prodMap f g).ker = f.ker.prod g.ker := by
rw [← comap_bot, ← comap_bot, ← comap_bot, ← prodMap_comap_prod, bot_prod_bot]
@[to_additive (attr := simp)]
lemma ker_fst : ker (fst G G') = .prod ⊥ ⊤ := SetLike.ext fun _ => (iff_of_eq (and_true _)).symm
@[to_additive (attr := simp)]
lemma ker_snd : ker (snd G G') = .prod ⊤ ⊥ := SetLike.ext fun _ => (iff_of_eq (true_and _)).symm
end Ker
end MonoidHom
namespace Subgroup
variable {N : Type*} [Group N] (H : Subgroup G)
@[to_additive]
theorem Normal.map {H : Subgroup G} (h : H.Normal) (f : G →* N) (hf : Function.Surjective f) :
(H.map f).Normal := by
rw [← normalizer_eq_top_iff, ← top_le_iff, ← f.range_eq_top_of_surjective hf, f.range_eq_map,
← H.normalizer_eq_top]
exact le_normalizer_map _
end Subgroup
namespace Subgroup
open MonoidHom
variable {N : Type*} [Group N] (f : G →* N)
/-- The preimage of the normalizer is equal to the normalizer of the preimage of a surjective
function. -/
@[to_additive
/-- The preimage of the normalizer is equal to the normalizer of the preimage of
a surjective function. -/]
theorem comap_normalizer_eq_of_surjective (H : Subgroup G) {f : N →* G}
(hf : Function.Surjective f) : H.normalizer.comap f = (H.comap f).normalizer :=
comap_normalizer_eq_of_le_range fun x _ ↦ hf x
/-- The image of the normalizer is equal to the normalizer of the image of an isomorphism. -/
@[to_additive
/-- The image of the normalizer is equal to the normalizer of the image of an
isomorphism. -/]
theorem map_equiv_normalizer_eq (H : Subgroup G) (f : G ≃* N) :
H.normalizer.map f.toMonoidHom = (H.map f.toMonoidHom).normalizer := by
ext x
simp only [mem_normalizer_iff, mem_map_equiv]
rw [f.toEquiv.forall_congr]
intro
simp
/-- The image of the normalizer is equal to the normalizer of the image of a bijective
function. -/
@[to_additive
/-- The image of the normalizer is equal to the normalizer of the image of a bijective
function. -/]
theorem map_normalizer_eq_of_bijective (H : Subgroup G) {f : G →* N} (hf : Function.Bijective f) :
H.normalizer.map f = (H.map f).normalizer :=
map_equiv_normalizer_eq H (MulEquiv.ofBijective f hf)
end Subgroup
namespace MonoidHom
variable {G₁ G₂ G₃ : Type*} [Group G₁] [Group G₂] [Group G₃]
variable (f : G₁ →* G₂) (f_inv : G₂ → G₁)
/-- Auxiliary definition used to define `liftOfRightInverse` -/
@[to_additive /-- Auxiliary definition used to define `liftOfRightInverse` -/]
def liftOfRightInverseAux (hf : Function.RightInverse f_inv f) (g : G₁ →* G₃) (hg : f.ker ≤ g.ker) :
G₂ →* G₃ where
toFun b := g (f_inv b)
map_one' := hg (hf 1)
map_mul' := by
intro x y
rw [← g.map_mul, ← mul_inv_eq_one, ← g.map_inv, ← g.map_mul, ← g.mem_ker]
apply hg
rw [f.mem_ker, f.map_mul, f.map_inv, mul_inv_eq_one, f.map_mul]
simp only [hf _]
@[to_additive (attr := simp)]
theorem liftOfRightInverseAux_comp_apply (hf : Function.RightInverse f_inv f) (g : G₁ →* G₃)
(hg : f.ker ≤ g.ker) (x : G₁) : (f.liftOfRightInverseAux f_inv hf g hg) (f x) = g x := by
dsimp [liftOfRightInverseAux]
rw [← mul_inv_eq_one, ← g.map_inv, ← g.map_mul, ← g.mem_ker]
apply hg
rw [f.mem_ker, f.map_mul, f.map_inv, mul_inv_eq_one]
simp only [hf _]
/-- `liftOfRightInverse f hf g hg` is the unique group homomorphism `φ`
* such that `φ.comp f = g` (`MonoidHom.liftOfRightInverse_comp`),
* where `f : G₁ →+* G₂` has a RightInverse `f_inv` (`hf`),
* and `g : G₂ →+* G₃` satisfies `hg : f.ker ≤ g.ker`.
See `MonoidHom.eq_liftOfRightInverse` for the uniqueness lemma.
```
G₁.
| \
f | \ g
| \
v \⌟
G₂----> G₃
∃!φ
```
-/
@[to_additive
/-- `liftOfRightInverse f f_inv hf g hg` is the unique additive group homomorphism `φ`
* such that `φ.comp f = g` (`AddMonoidHom.liftOfRightInverse_comp`),
* where `f : G₁ →+ G₂` has a RightInverse `f_inv` (`hf`),
* and `g : G₂ →+ G₃` satisfies `hg : f.ker ≤ g.ker`.
See `AddMonoidHom.eq_liftOfRightInverse` for the uniqueness lemma.
```
G₁.
| \
f | \ g
| \
v \⌟
G₂----> G₃
∃!φ
``` -/]
def liftOfRightInverse (hf : Function.RightInverse f_inv f) :
{ g : G₁ →* G₃ // f.ker ≤ g.ker } ≃ (G₂ →* G₃) where
toFun g := f.liftOfRightInverseAux f_inv hf g.1 g.2
invFun φ := ⟨φ.comp f, fun x hx ↦ mem_ker.mpr <| by simp [mem_ker.mp hx]⟩
left_inv g := by
ext
simp only [comp_apply, liftOfRightInverseAux_comp_apply]
right_inv φ := by
ext b
simp [liftOfRightInverseAux, hf b]
/-- A non-computable version of `MonoidHom.liftOfRightInverse` for when no computable right
inverse is available, that uses `Function.surjInv`. -/
@[to_additive (attr := simp)
/-- A non-computable version of `AddMonoidHom.liftOfRightInverse` for when no
computable right inverse is available. -/]
noncomputable abbrev liftOfSurjective (hf : Function.Surjective f) :
{ g : G₁ →* G₃ // f.ker ≤ g.ker } ≃ (G₂ →* G₃) :=
f.liftOfRightInverse (Function.surjInv hf) (Function.rightInverse_surjInv hf)
@[to_additive (attr := simp)]
theorem liftOfRightInverse_comp_apply (hf : Function.RightInverse f_inv f)
(g : { g : G₁ →* G₃ // f.ker ≤ g.ker }) (x : G₁) :
(f.liftOfRightInverse f_inv hf g) (f x) = g.1 x :=
f.liftOfRightInverseAux_comp_apply f_inv hf g.1 g.2 x
@[to_additive (attr := simp)]
theorem liftOfRightInverse_comp (hf : Function.RightInverse f_inv f)
(g : { g : G₁ →* G₃ // f.ker ≤ g.ker }) : (f.liftOfRightInverse f_inv hf g).comp f = g :=
MonoidHom.ext <| f.liftOfRightInverse_comp_apply f_inv hf g
@[to_additive]
theorem eq_liftOfRightInverse (hf : Function.RightInverse f_inv f) (g : G₁ →* G₃)
(hg : f.ker ≤ g.ker) (h : G₂ →* G₃) (hh : h.comp f = g) :
h = f.liftOfRightInverse f_inv hf ⟨g, hg⟩ := by
simp_rw [← hh]
exact ((f.liftOfRightInverse f_inv hf).apply_symm_apply _).symm
end MonoidHom
variable {N : Type*} [Group N]
namespace Subgroup
-- Here `H.Normal` is an explicit argument so we can use dot notation with `comap`.
@[to_additive]
theorem Normal.comap {H : Subgroup N} (hH : H.Normal) (f : G →* N) : (H.comap f).Normal :=
⟨fun _ => by simp +contextual [Subgroup.mem_comap, hH.conj_mem]⟩
@[to_additive]
instance (priority := 100) normal_comap {H : Subgroup N} [nH : H.Normal] (f : G →* N) :
(H.comap f).Normal :=
nH.comap _
-- Here `H.Normal` is an explicit argument so we can use dot notation with `subgroupOf`.
@[to_additive]
theorem Normal.subgroupOf {H : Subgroup G} (hH : H.Normal) (K : Subgroup G) :
(H.subgroupOf K).Normal :=
hH.comap _
@[to_additive]
instance (priority := 100) normal_subgroupOf {H N : Subgroup G} [N.Normal] :
(N.subgroupOf H).Normal :=
Subgroup.normal_comap _
theorem map_normalClosure (s : Set G) (f : G →* N) (hf : Surjective f) :
(normalClosure s).map f = normalClosure (f '' s) := by
have : Normal (map f (normalClosure s)) := Normal.map inferInstance f hf
apply le_antisymm
· simp [map_le_iff_le_comap, normalClosure_le_normal, coe_comap,
← Set.image_subset_iff, subset_normalClosure]
· exact normalClosure_le_normal (Set.image_mono subset_normalClosure)
theorem comap_normalClosure (s : Set N) (f : G ≃* N) :
normalClosure (f ⁻¹' s) = (normalClosure s).comap f := by
have := f.toEquiv.image_symm_eq_preimage s
simp_all [comap_equiv_eq_map_symm, map_normalClosure s (f.symm : N →* G) f.symm.surjective]
lemma Normal.of_map_injective {G H : Type*} [Group G] [Group H] {φ : G →* H}
(hφ : Function.Injective φ) {L : Subgroup G} (n : (L.map φ).Normal) : L.Normal :=
L.comap_map_eq_self_of_injective hφ ▸ n.comap φ
theorem Normal.of_map_subtype {K : Subgroup G} {L : Subgroup K}
(n : (Subgroup.map K.subtype L).Normal) : L.Normal :=
n.of_map_injective K.subtype_injective
end Subgroup
namespace Subgroup
section SubgroupNormal
@[to_additive]
theorem normal_subgroupOf_iff {H K : Subgroup G} (hHK : H ≤ K) :
(H.subgroupOf K).Normal ↔ ∀ h k, h ∈ H → k ∈ K → k * h * k⁻¹ ∈ H :=
⟨fun hN h k hH hK => hN.conj_mem ⟨h, hHK hH⟩ hH ⟨k, hK⟩, fun hN =>
{ conj_mem := fun h hm k => hN h.1 k.1 hm k.2 }⟩
@[to_additive prod_addSubgroupOf_prod_normal]
instance prod_subgroupOf_prod_normal {H₁ K₁ : Subgroup G} {H₂ K₂ : Subgroup N}
[h₁ : (H₁.subgroupOf K₁).Normal] [h₂ : (H₂.subgroupOf K₂).Normal] :
((H₁.prod H₂).subgroupOf (K₁.prod K₂)).Normal where
conj_mem n hgHK g :=
⟨h₁.conj_mem ⟨(n : G × N).fst, (mem_prod.mp n.2).1⟩ hgHK.1
⟨(g : G × N).fst, (mem_prod.mp g.2).1⟩,
h₂.conj_mem ⟨(n : G × N).snd, (mem_prod.mp n.2).2⟩ hgHK.2
⟨(g : G × N).snd, (mem_prod.mp g.2).2⟩⟩
@[to_additive prod_normal]
instance prod_normal (H : Subgroup G) (K : Subgroup N) [hH : H.Normal] [hK : K.Normal] :
(H.prod K).Normal where
conj_mem n hg g :=
⟨hH.conj_mem n.fst (Subgroup.mem_prod.mp hg).1 g.fst,
hK.conj_mem n.snd (Subgroup.mem_prod.mp hg).2 g.snd⟩
@[to_additive]
theorem inf_subgroupOf_inf_normal_of_right (A B' B : Subgroup G)
[hN : (B'.subgroupOf B).Normal] : ((A ⊓ B').subgroupOf (A ⊓ B)).Normal := by
rw [normal_subgroupOf_iff_le_normalizer_inf] at hN ⊢
rw [inf_inf_inf_comm, inf_idem]
exact le_trans (inf_le_inf A.le_normalizer hN) (inf_normalizer_le_normalizer_inf)
@[to_additive]
theorem inf_subgroupOf_inf_normal_of_left {A' A : Subgroup G} (B : Subgroup G)
[hN : (A'.subgroupOf A).Normal] : ((A' ⊓ B).subgroupOf (A ⊓ B)).Normal := by
rw [normal_subgroupOf_iff_le_normalizer_inf] at hN ⊢
rw [inf_inf_inf_comm, inf_idem]
exact le_trans (inf_le_inf hN B.le_normalizer) (inf_normalizer_le_normalizer_inf)
@[to_additive]
instance normal_inf_normal (H K : Subgroup G) [hH : H.Normal] [hK : K.Normal] : (H ⊓ K).Normal :=
⟨fun n hmem g => ⟨hH.conj_mem n hmem.1 g, hK.conj_mem n hmem.2 g⟩⟩
@[to_additive]
theorem normal_iInf_normal {ι : Sort*} {a : ι → Subgroup G}
(norm : ∀ i : ι, (a i).Normal) : (iInf a).Normal := by
constructor
intro g g_in_iInf h
rw [Subgroup.mem_iInf] at g_in_iInf ⊢
intro i
exact (norm i).conj_mem g (g_in_iInf i) h
@[to_additive]
theorem SubgroupNormal.mem_comm {H K : Subgroup G} (hK : H ≤ K) [hN : (H.subgroupOf K).Normal]
{a b : G} (hb : b ∈ K) (h : a * b ∈ H) : b * a ∈ H := by
have := (normal_subgroupOf_iff hK).mp hN (a * b) b h hb
rwa [mul_assoc, mul_assoc, mul_inv_cancel, mul_one] at this
/-- Elements of disjoint, normal subgroups commute. -/
@[to_additive /-- Elements of disjoint, normal subgroups commute. -/]
theorem commute_of_normal_of_disjoint (H₁ H₂ : Subgroup G) (hH₁ : H₁.Normal) (hH₂ : H₂.Normal)
(hdis : Disjoint H₁ H₂) (x y : G) (hx : x ∈ H₁) (hy : y ∈ H₂) : Commute x y := by
suffices x * y * x⁻¹ * y⁻¹ = 1 by
change x * y = y * x
· rw [mul_assoc, mul_eq_one_iff_eq_inv] at this
simpa
apply hdis.le_bot
constructor
· suffices x * (y * x⁻¹ * y⁻¹) ∈ H₁ by simpa [mul_assoc]
exact H₁.mul_mem hx (hH₁.conj_mem _ (H₁.inv_mem hx) _)
· change x * y * x⁻¹ * y⁻¹ ∈ H₂
apply H₂.mul_mem _ (H₂.inv_mem hy)
apply hH₂.conj_mem _ hy
@[to_additive]
theorem normal_subgroupOf_of_le_normalizer {H N : Subgroup G}
(hLE : H ≤ N.normalizer) : (N.subgroupOf H).Normal := by
rw [normal_subgroupOf_iff_le_normalizer_inf]
exact (le_inf hLE H.le_normalizer).trans inf_normalizer_le_normalizer_inf
@[to_additive]
theorem normal_subgroupOf_sup_of_le_normalizer {H N : Subgroup G}
(hLE : H ≤ N.normalizer) : (N.subgroupOf (H ⊔ N)).Normal := by
rw [normal_subgroupOf_iff_le_normalizer le_sup_right]
exact sup_le hLE le_normalizer
end SubgroupNormal
end Subgroup
namespace IsConj
open Subgroup
theorem normalClosure_eq_top_of {N : Subgroup G} [hn : N.Normal] {g g' : G} {hg : g ∈ N}
{hg' : g' ∈ N} (hc : IsConj g g') (ht : normalClosure ({⟨g, hg⟩} : Set N) = ⊤) :
normalClosure ({⟨g', hg'⟩} : Set N) = ⊤ := by
obtain ⟨c, rfl⟩ := isConj_iff.1 hc
have h : ∀ x : N, (MulAut.conj c) x ∈ N := by
rintro ⟨x, hx⟩
exact hn.conj_mem _ hx c
have hs : Function.Surjective (((MulAut.conj c).toMonoidHom.restrict N).codRestrict _ h) := by
rintro ⟨x, hx⟩
refine ⟨⟨c⁻¹ * x * c, ?_⟩, ?_⟩
· have h := hn.conj_mem _ hx c⁻¹
rwa [inv_inv] at h
simp only [MonoidHom.codRestrict_apply, MulEquiv.coe_toMonoidHom, MulAut.conj_apply,
MonoidHom.restrict_apply, Subtype.mk_eq_mk, ← mul_assoc, mul_inv_cancel, one_mul]
rw [mul_assoc, mul_inv_cancel, mul_one]
rw [eq_top_iff, ← MonoidHom.range_eq_top.2 hs, MonoidHom.range_eq_map]
grw [eq_top_iff.1 ht]
refine map_le_iff_le_comap.2 (normalClosure_le_normal ?_)
rw [Set.singleton_subset_iff, SetLike.mem_coe]
simp only [MonoidHom.codRestrict_apply, MulEquiv.coe_toMonoidHom, MulAut.conj_apply,
MonoidHom.restrict_apply, mem_comap]
exact subset_normalClosure (Set.mem_singleton _)
end IsConj
namespace ConjClasses
/-- The conjugacy classes that are not trivial. -/
def noncenter (G : Type*) [Monoid G] : Set (ConjClasses G) :=
{x | x.carrier.Nontrivial}
@[simp] lemma mem_noncenter {G} [Monoid G] (g : ConjClasses G) :
g ∈ noncenter G ↔ g.carrier.Nontrivial := Iff.rfl
end ConjClasses
/-- Suppose `G` acts on `M` and `I` is a subgroup of `M`.
The inertia subgroup of `I` is the subgroup of `G` whose action is trivial mod `I`. -/
def AddSubgroup.inertia {M : Type*} [AddGroup M] (I : AddSubgroup M) (G : Type*)
[Group G] [MulAction G M] : Subgroup G where
carrier := { σ | ∀ x, σ • x - x ∈ I }
mul_mem' {a b} ha hb x := by simpa [mul_smul] using add_mem (ha (b • x)) (hb x)
one_mem' := by simp [zero_mem]
inv_mem' {a} ha x := by simpa using sub_mem_comm_iff.mp (ha (a⁻¹ • x))
@[simp] lemma AddSubgroup.mem_inertia {M : Type*} [AddGroup M] {I : AddSubgroup M} {G : Type*}
[Group G] [MulAction G M] {σ : G} : σ ∈ I.inertia G ↔ ∀ x, σ • x - x ∈ I := .rfl |
.lake/packages/mathlib/Mathlib/Algebra/Group/Subgroup/Defs.lean | import Mathlib.Algebra.Group.Basic
import Mathlib.Algebra.Group.Submonoid.Defs
import Mathlib.Data.Set.Inclusion
import Mathlib.Tactic.Common
import Mathlib.Tactic.FastInstance
/-!
# Subgroups
This file defines multiplicative and additive subgroups as an extension of submonoids, in a bundled
form (unbundled subgroups are in `Deprecated/Subgroups.lean`).
Special thanks goes to Amelia Livingston and Yury Kudryashov for their help and inspiration.
## Main definitions
Notation used here:
- `G N` are `Group`s
- `A` is an `AddGroup`
- `H K` are `Subgroup`s of `G` or `AddSubgroup`s of `A`
- `x` is an element of type `G` or type `A`
- `f g : N →* G` are group homomorphisms
- `s k` are sets of elements of type `G`
Definitions in the file:
* `Subgroup G` : the type of subgroups of a group `G`
* `AddSubgroup A` : the type of subgroups of an additive group `A`
* `Subgroup.subtype` : the natural group homomorphism from a subgroup of group `G` to `G`
## Implementation notes
Subgroup inclusion is denoted `≤` rather than `⊆`, although `∈` is defined as
membership of a subgroup's underlying set.
## Tags
subgroup, subgroups
-/
assert_not_exists RelIso IsOrderedMonoid Multiset MonoidWithZero
open Function
open scoped Int
variable {G : Type*} [Group G] {A : Type*} [AddGroup A]
section SubgroupClass
/-- `InvMemClass S G` states `S` is a type of subsets `s ⊆ G` closed under inverses. -/
class InvMemClass (S : Type*) (G : outParam Type*) [Inv G] [SetLike S G] : Prop where
/-- `s` is closed under inverses -/
inv_mem : ∀ {s : S} {x}, x ∈ s → x⁻¹ ∈ s
export InvMemClass (inv_mem)
/-- `NegMemClass S G` states `S` is a type of subsets `s ⊆ G` closed under negation. -/
class NegMemClass (S : Type*) (G : outParam Type*) [Neg G] [SetLike S G] : Prop where
/-- `s` is closed under negation -/
neg_mem : ∀ {s : S} {x}, x ∈ s → -x ∈ s
export NegMemClass (neg_mem)
/-- Typeclass for substructures `s` such that `s ∪ -s = G`. -/
class HasMemOrNegMem {S G : Type*} [Neg G] [SetLike S G] (s : S) : Prop where
mem_or_neg_mem (s) (a : G) : a ∈ s ∨ -a ∈ s
/-- Typeclass for substructures `s` such that `s ∪ s⁻¹ = G`. -/
@[to_additive]
class HasMemOrInvMem {S G : Type*} [Inv G] [SetLike S G] (s : S) : Prop where
mem_or_inv_mem (s) (a : G) : a ∈ s ∨ a⁻¹ ∈ s
export HasMemOrNegMem (mem_or_neg_mem)
export HasMemOrInvMem (mem_or_inv_mem)
namespace HasMemOrInvMem
variable {S G : Type*} [Inv G] [SetLike S G] (s : S) [HasMemOrInvMem s]
@[to_additive (attr := aesop unsafe 70% apply)]
theorem inv_mem_of_notMem (x : G) (h : x ∉ s) : x⁻¹ ∈ s := by
have := mem_or_inv_mem s x
simp_all
@[to_additive (attr := aesop unsafe 70% apply)]
theorem mem_of_inv_notMem (x : G) (h : x⁻¹ ∉ s) : x ∈ s := by
have := mem_or_inv_mem s x
simp_all
end HasMemOrInvMem
/-- `SubgroupClass S G` states `S` is a type of subsets `s ⊆ G` that are subgroups of `G`. -/
class SubgroupClass (S : Type*) (G : outParam Type*) [DivInvMonoid G] [SetLike S G] : Prop
extends SubmonoidClass S G, InvMemClass S G
/-- `AddSubgroupClass S G` states `S` is a type of subsets `s ⊆ G` that are
additive subgroups of `G`. -/
class AddSubgroupClass (S : Type*) (G : outParam Type*) [SubNegMonoid G] [SetLike S G] : Prop
extends AddSubmonoidClass S G, NegMemClass S G
attribute [to_additive] InvMemClass SubgroupClass
attribute [aesop 90% (rule_sets := [SetLike])] inv_mem neg_mem
@[to_additive (attr := simp)]
theorem inv_mem_iff {S G} [InvolutiveInv G] {_ : SetLike S G} [InvMemClass S G] {H : S}
{x : G} : x⁻¹ ∈ H ↔ x ∈ H :=
⟨fun h => inv_inv x ▸ inv_mem h, inv_mem⟩
variable {M S : Type*} [DivInvMonoid M] [SetLike S M] [hSM : SubgroupClass S M] {H K : S}
/-- A subgroup is closed under division. -/
@[to_additive (attr := aesop 90% (rule_sets := [SetLike]))
/-- An additive subgroup is closed under subtraction. -/]
theorem div_mem {x y : M} (hx : x ∈ H) (hy : y ∈ H) : x / y ∈ H := by
rw [div_eq_mul_inv]; exact mul_mem hx (inv_mem hy)
@[to_additive (attr := aesop 90% (rule_sets := [SetLike]))]
theorem zpow_mem {x : M} (hx : x ∈ K) : ∀ n : ℤ, x ^ n ∈ K
| (n : ℕ) => by
rw [zpow_natCast]
exact pow_mem hx n
| -[n+1] => by
rw [zpow_negSucc]
exact inv_mem (pow_mem hx n.succ)
variable [SetLike S G] [SubgroupClass S G]
@[to_additive]
theorem exists_inv_mem_iff_exists_mem {P : G → Prop} :
(∃ x : G, x ∈ H ∧ P x⁻¹) ↔ ∃ x ∈ H, P x := by
constructor <;>
· rintro ⟨x, x_in, hx⟩
exact ⟨x⁻¹, inv_mem x_in, by simp [hx]⟩
@[to_additive]
theorem mul_mem_cancel_right {x y : G} (h : x ∈ H) : y * x ∈ H ↔ y ∈ H :=
⟨fun hba => by simpa using mul_mem hba (inv_mem h), fun hb => mul_mem hb h⟩
@[to_additive]
theorem mul_mem_cancel_left {x y : G} (h : x ∈ H) : x * y ∈ H ↔ y ∈ H :=
⟨fun hab => by simpa using mul_mem (inv_mem h) hab, mul_mem h⟩
namespace InvMemClass
/-- A subgroup of a group inherits an inverse. -/
@[to_additive /-- An additive subgroup of an `AddGroup` inherits an inverse. -/]
instance inv {G S : Type*} [Inv G] [SetLike S G] [InvMemClass S G] {H : S} : Inv H :=
⟨fun a => ⟨a⁻¹, inv_mem a.2⟩⟩
@[to_additive (attr := simp, norm_cast)]
theorem coe_inv (x : H) : (x⁻¹).1 = x.1⁻¹ :=
rfl
end InvMemClass
namespace SubgroupClass
-- Here we assume H, K, and L are subgroups, but in fact any one of them
-- could be allowed to be a subsemigroup.
-- Counterexample where K and L are submonoids: H = ℤ, K = ℕ, L = -ℕ
-- Counterexample where H and K are submonoids: H = {n | n = 0 ∨ 3 ≤ n}, K = 3ℕ + 4ℕ, L = 5ℤ
@[to_additive]
theorem subset_union {H K L : S} : (H : Set G) ⊆ K ∪ L ↔ H ≤ K ∨ H ≤ L := by
refine ⟨fun h ↦ ?_, fun h x xH ↦ h.imp (· xH) (· xH)⟩
rw [or_iff_not_imp_left, SetLike.not_le_iff_exists]
exact fun ⟨x, xH, xK⟩ y yH ↦ (h <| mul_mem xH yH).elim
((h yH).resolve_left fun yK ↦ xK <| (mul_mem_cancel_right yK).mp ·)
(mul_mem_cancel_left <| (h xH).resolve_left xK).mp
/-- A subgroup of a group inherits a division -/
@[to_additive /-- An additive subgroup of an `AddGroup` inherits a subtraction. -/]
instance div {G S : Type*} [DivInvMonoid G] [SetLike S G] [SubgroupClass S G] {H : S} : Div H :=
⟨fun a b => ⟨a / b, div_mem a.2 b.2⟩⟩
/-- An additive subgroup of an `AddGroup` inherits an integer scaling. -/
instance _root_.AddSubgroupClass.zsmul {M S} [SubNegMonoid M] [SetLike S M]
[AddSubgroupClass S M] {H : S} : SMul ℤ H :=
⟨fun n a => ⟨n • a.1, zsmul_mem a.2 n⟩⟩
/-- A subgroup of a group inherits an integer power. -/
@[to_additive existing]
instance zpow {M S} [DivInvMonoid M] [SetLike S M] [SubgroupClass S M] {H : S} : Pow H ℤ :=
⟨fun a n => ⟨a.1 ^ n, zpow_mem a.2 n⟩⟩
@[to_additive (attr := simp, norm_cast)]
theorem coe_div (x y : H) : (x / y).1 = x.1 / y.1 :=
rfl
variable (H)
-- Prefer subclasses of `Group` over subclasses of `SubgroupClass`.
/-- A subgroup of a group inherits a group structure. -/
@[to_additive /-- An additive subgroup of an `AddGroup` inherits an `AddGroup` structure. -/]
instance (priority := 75) toGroup : Group H := fast_instance%
Subtype.coe_injective.group _ rfl (fun _ _ => rfl) (fun _ => rfl) (fun _ _ => rfl)
(fun _ _ => rfl) fun _ _ => rfl
-- Prefer subclasses of `CommGroup` over subclasses of `SubgroupClass`.
/-- A subgroup of a `CommGroup` is a `CommGroup`. -/
@[to_additive /-- An additive subgroup of an `AddCommGroup` is an `AddCommGroup`. -/]
instance (priority := 75) toCommGroup {G : Type*} [CommGroup G] [SetLike S G] [SubgroupClass S G] :
CommGroup H := fast_instance%
Subtype.coe_injective.commGroup _ rfl (fun _ _ => rfl) (fun _ => rfl) (fun _ _ => rfl)
(fun _ _ => rfl) fun _ _ => rfl
/-- The natural group hom from a subgroup of group `G` to `G`. -/
@[to_additive (attr := coe)
/-- The natural group hom from an additive subgroup of `AddGroup` `G` to `G`. -/]
protected def subtype : H →* G where
toFun := ((↑) : H → G); map_one' := rfl; map_mul' := fun _ _ => rfl
variable {H} in
@[to_additive (attr := simp)]
lemma subtype_apply (x : H) :
SubgroupClass.subtype H x = x := rfl
@[to_additive]
lemma subtype_injective :
Function.Injective (SubgroupClass.subtype H) :=
Subtype.coe_injective
@[to_additive (attr := simp)]
theorem coe_subtype : (SubgroupClass.subtype H : H → G) = ((↑) : H → G) := by
rfl
variable {H}
@[to_additive (attr := simp, norm_cast)]
theorem coe_pow (x : H) (n : ℕ) : ((x ^ n : H) : G) = (x : G) ^ n :=
rfl
@[to_additive (attr := simp, norm_cast)]
theorem coe_zpow (x : H) (n : ℤ) : ((x ^ n : H) : G) = (x : G) ^ n :=
rfl
/-- The inclusion homomorphism from a subgroup `H` contained in `K` to `K`. -/
@[to_additive
/-- The inclusion homomorphism from an additive subgroup `H` contained in `K` to `K`. -/]
def inclusion {H K : S} (h : H ≤ K) : H →* K :=
MonoidHom.mk' (fun x => ⟨x, h x.prop⟩) fun _ _ => rfl
@[to_additive (attr := simp)]
theorem inclusion_self (x : H) : inclusion le_rfl x = x := by
cases x
rfl
@[to_additive (attr := simp)]
theorem inclusion_mk {h : H ≤ K} (x : G) (hx : x ∈ H) : inclusion h ⟨x, hx⟩ = ⟨x, h hx⟩ :=
rfl
@[to_additive]
theorem inclusion_right (h : H ≤ K) (x : K) (hx : (x : G) ∈ H) : inclusion h ⟨x, hx⟩ = x := by
cases x
rfl
@[simp]
theorem inclusion_inclusion {L : S} (hHK : H ≤ K) (hKL : K ≤ L) (x : H) :
inclusion hKL (inclusion hHK x) = inclusion (hHK.trans hKL) x := by
cases x
rfl
@[to_additive (attr := simp)]
theorem coe_inclusion {H K : S} (h : H ≤ K) (a : H) : (inclusion h a : G) = a :=
Set.coe_inclusion h a
@[to_additive (attr := simp)]
theorem subtype_comp_inclusion {H K : S} (h : H ≤ K) :
(SubgroupClass.subtype K).comp (inclusion h) = SubgroupClass.subtype H :=
rfl
end SubgroupClass
end SubgroupClass
/-- A subgroup of a group `G` is a subset containing 1, closed under multiplication
and closed under multiplicative inverse. -/
structure Subgroup (G : Type*) [Group G] extends Submonoid G where
/-- `G` is closed under inverses -/
inv_mem' {x} : x ∈ carrier → x⁻¹ ∈ carrier
/-- An additive subgroup of an additive group `G` is a subset containing 0, closed
under addition and additive inverse. -/
structure AddSubgroup (G : Type*) [AddGroup G] extends AddSubmonoid G where
/-- `G` is closed under negation -/
neg_mem' {x} : x ∈ carrier → -x ∈ carrier
attribute [to_additive] Subgroup
/-- Reinterpret a `Subgroup` as a `Submonoid`. -/
add_decl_doc Subgroup.toSubmonoid
/-- Reinterpret an `AddSubgroup` as an `AddSubmonoid`. -/
add_decl_doc AddSubgroup.toAddSubmonoid
namespace Subgroup
@[to_additive]
instance : SetLike (Subgroup G) G where
coe s := s.carrier
coe_injective' p q h := by
obtain ⟨⟨⟨hp,_⟩,_⟩,_⟩ := p
obtain ⟨⟨⟨hq,_⟩,_⟩,_⟩ := q
congr
initialize_simps_projections Subgroup (carrier → coe, as_prefix coe)
initialize_simps_projections AddSubgroup (carrier → coe, as_prefix coe)
/-- The actual `Subgroup` obtained from an element of a `SubgroupClass` -/
@[to_additive (attr := simps) /-- The actual `AddSubgroup` obtained from an element of a
`AddSubgroupClass` -/]
def ofClass {S G : Type*} [Group G] [SetLike S G] [SubgroupClass S G]
(s : S) : Subgroup G :=
⟨⟨⟨s, MulMemClass.mul_mem⟩, OneMemClass.one_mem s⟩, InvMemClass.inv_mem⟩
@[to_additive]
instance (priority := 100) : CanLift (Set G) (Subgroup G) (↑)
(fun s ↦ 1 ∈ s ∧ (∀ {x y}, x ∈ s → y ∈ s → x * y ∈ s) ∧ ∀ {x}, x ∈ s → x⁻¹ ∈ s) where
prf s h := ⟨{ carrier := s, one_mem' := h.1, mul_mem' := h.2.1, inv_mem' := h.2.2}, rfl⟩
-- TODO: Below can probably be written more uniformly
@[to_additive]
instance : SubgroupClass (Subgroup G) G where
inv_mem := Subgroup.inv_mem' _
one_mem _ := (Subgroup.toSubmonoid _).one_mem'
mul_mem := (Subgroup.toSubmonoid _).mul_mem'
-- This is not a simp lemma,
-- because the simp normal form left-hand side is given by `mem_toSubmonoid` below.
@[to_additive]
theorem mem_carrier {s : Subgroup G} {x : G} : x ∈ s.carrier ↔ x ∈ s :=
Iff.rfl
@[to_additive (attr := simp)]
theorem mem_mk {s : Submonoid G} {x : G} (h_inv) :
x ∈ mk s h_inv ↔ x ∈ s :=
Iff.rfl
@[to_additive (attr := simp)]
theorem coe_set_mk {s : Submonoid G} (h_inv) :
(mk s h_inv : Set G) = s :=
rfl
@[to_additive (attr := simp)]
theorem mk_le_mk {s t : Submonoid G} (h_inv) (h_inv') :
mk s h_inv ≤ mk t h_inv' ↔ s ≤ t :=
Iff.rfl
@[to_additive (attr := simp)]
theorem coe_toSubmonoid (K : Subgroup G) : (K.toSubmonoid : Set G) = K :=
rfl
@[to_additive (attr := simp)]
theorem mem_toSubmonoid (K : Subgroup G) (x : G) : x ∈ K.toSubmonoid ↔ x ∈ K :=
Iff.rfl
@[to_additive]
theorem toSubmonoid_injective : Function.Injective (toSubmonoid : Subgroup G → Submonoid G) :=
fun p q h => by
have := SetLike.ext'_iff.1 h
rw [coe_toSubmonoid, coe_toSubmonoid] at this
exact SetLike.ext'_iff.2 this
@[to_additive (attr := simp)]
theorem toSubmonoid_inj {p q : Subgroup G} : p.toSubmonoid = q.toSubmonoid ↔ p = q :=
toSubmonoid_injective.eq_iff
@[to_additive (attr := mono)]
theorem toSubmonoid_strictMono : StrictMono (toSubmonoid : Subgroup G → Submonoid G) := fun _ _ =>
id
@[to_additive (attr := mono)]
theorem toSubmonoid_mono : Monotone (toSubmonoid : Subgroup G → Submonoid G) :=
toSubmonoid_strictMono.monotone
@[to_additive (attr := simp)]
theorem toSubmonoid_le {p q : Subgroup G} : p.toSubmonoid ≤ q.toSubmonoid ↔ p ≤ q :=
Iff.rfl
@[to_additive (attr := simp)]
lemma coe_nonempty (s : Subgroup G) : (s : Set G).Nonempty := ⟨1, one_mem _⟩
end Subgroup
namespace Subgroup
variable (H K : Subgroup G)
/-- Copy of a subgroup with a new `carrier` equal to the old one. Useful to fix definitional
equalities. -/
@[to_additive (attr := simps)
/-- Copy of an additive subgroup with a new `carrier` equal to the old one.
Useful to fix definitional equalities -/]
protected def copy (K : Subgroup G) (s : Set G) (hs : s = K) : Subgroup G where
carrier := s
one_mem' := hs.symm ▸ K.one_mem'
mul_mem' := hs.symm ▸ K.mul_mem'
inv_mem' hx := by simpa [hs] using hx
@[to_additive]
theorem copy_eq (K : Subgroup G) (s : Set G) (hs : s = ↑K) : K.copy s hs = K :=
SetLike.coe_injective hs
/-- Two subgroups are equal if they have the same elements. -/
@[to_additive (attr := ext) /-- Two `AddSubgroup`s are equal if they have the same elements. -/]
theorem ext {H K : Subgroup G} (h : ∀ x, x ∈ H ↔ x ∈ K) : H = K :=
SetLike.ext h
/-- A subgroup contains the group's 1. -/
@[to_additive /-- An `AddSubgroup` contains the group's 0. -/]
protected theorem one_mem : (1 : G) ∈ H :=
one_mem _
/-- A subgroup is closed under multiplication. -/
@[to_additive /-- An `AddSubgroup` is closed under addition. -/]
protected theorem mul_mem {x y : G} : x ∈ H → y ∈ H → x * y ∈ H :=
mul_mem
/-- A subgroup is closed under inverse. -/
@[to_additive /-- An `AddSubgroup` is closed under inverse. -/]
protected theorem inv_mem {x : G} : x ∈ H → x⁻¹ ∈ H :=
inv_mem
/-- A subgroup is closed under division. -/
@[to_additive /-- An `AddSubgroup` is closed under subtraction. -/]
protected theorem div_mem {x y : G} (hx : x ∈ H) (hy : y ∈ H) : x / y ∈ H :=
div_mem hx hy
@[to_additive]
protected theorem inv_mem_iff {x : G} : x⁻¹ ∈ H ↔ x ∈ H :=
inv_mem_iff
@[to_additive]
protected theorem exists_inv_mem_iff_exists_mem (K : Subgroup G) {P : G → Prop} :
(∃ x : G, x ∈ K ∧ P x⁻¹) ↔ ∃ x ∈ K, P x :=
exists_inv_mem_iff_exists_mem
@[to_additive]
protected theorem mul_mem_cancel_right {x y : G} (h : x ∈ H) : y * x ∈ H ↔ y ∈ H :=
mul_mem_cancel_right h
@[to_additive]
protected theorem mul_mem_cancel_left {x y : G} (h : x ∈ H) : x * y ∈ H ↔ y ∈ H :=
mul_mem_cancel_left h
@[to_additive]
protected theorem pow_mem {x : G} (hx : x ∈ K) : ∀ n : ℕ, x ^ n ∈ K :=
pow_mem hx
@[to_additive]
protected theorem zpow_mem {x : G} (hx : x ∈ K) : ∀ n : ℤ, x ^ n ∈ K :=
zpow_mem hx
/-- Construct a subgroup from a nonempty set that is closed under division. -/
@[to_additive /-- Construct a subgroup from a nonempty set that is closed under subtraction -/]
def ofDiv (s : Set G) (hsn : s.Nonempty) (hs : ∀ᵉ (x ∈ s) (y ∈ s), x * y⁻¹ ∈ s) :
Subgroup G :=
have one_mem : (1 : G) ∈ s := by
let ⟨x, hx⟩ := hsn
simpa using hs x hx x hx
have inv_mem : ∀ x, x ∈ s → x⁻¹ ∈ s := fun x hx => by simpa using hs 1 one_mem x hx
{ carrier := s
one_mem' := one_mem
inv_mem' := inv_mem _
mul_mem' := fun hx hy => by simpa using hs _ hx _ (inv_mem _ hy) }
/-- A subgroup of a group inherits a multiplication. -/
@[to_additive /-- An `AddSubgroup` of an `AddGroup` inherits an addition. -/]
instance mul : Mul H :=
H.toSubmonoid.mul
/-- A subgroup of a group inherits a 1. -/
@[to_additive /-- An `AddSubgroup` of an `AddGroup` inherits a zero. -/]
instance one : One H :=
H.toSubmonoid.one
/-- A subgroup of a group inherits an inverse. -/
@[to_additive /-- An `AddSubgroup` of an `AddGroup` inherits an inverse. -/]
instance inv : Inv H :=
⟨fun a => ⟨a⁻¹, H.inv_mem a.2⟩⟩
/-- A subgroup of a group inherits a division -/
@[to_additive /-- An `AddSubgroup` of an `AddGroup` inherits a subtraction. -/]
instance div : Div H :=
⟨fun a b => ⟨a / b, H.div_mem a.2 b.2⟩⟩
/-- An `AddSubgroup` of an `AddGroup` inherits a natural scaling. -/
instance _root_.AddSubgroup.nsmul {G} [AddGroup G] {H : AddSubgroup G} : SMul ℕ H :=
⟨fun n a => ⟨n • a, H.nsmul_mem a.2 n⟩⟩
/-- A subgroup of a group inherits a natural power -/
@[to_additive existing]
protected instance npow : Pow H ℕ :=
⟨fun a n => ⟨a ^ n, H.pow_mem a.2 n⟩⟩
/-- An `AddSubgroup` of an `AddGroup` inherits an integer scaling. -/
instance _root_.AddSubgroup.zsmul {G} [AddGroup G] {H : AddSubgroup G} : SMul ℤ H :=
⟨fun n a => ⟨n • a, H.zsmul_mem a.2 n⟩⟩
/-- A subgroup of a group inherits an integer power -/
@[to_additive existing]
instance zpow : Pow H ℤ :=
⟨fun a n => ⟨a ^ n, H.zpow_mem a.2 n⟩⟩
@[to_additive (attr := simp, norm_cast)]
theorem coe_mul (x y : H) : (↑(x * y) : G) = ↑x * ↑y :=
rfl
@[to_additive (attr := simp, norm_cast)]
theorem coe_one : ((1 : H) : G) = 1 :=
rfl
@[to_additive (attr := simp, norm_cast)]
theorem coe_inv (x : H) : ↑(x⁻¹ : H) = (x⁻¹ : G) :=
rfl
@[to_additive (attr := simp, norm_cast)]
theorem coe_div (x y : H) : (↑(x / y) : G) = ↑x / ↑y :=
rfl
@[to_additive (attr := norm_cast)]
theorem coe_mk (x : G) (hx : x ∈ H) : ((⟨x, hx⟩ : H) : G) = x :=
rfl
@[to_additive (attr := simp, norm_cast)]
theorem coe_pow (x : H) (n : ℕ) : ((x ^ n : H) : G) = (x : G) ^ n :=
rfl
@[to_additive (attr := norm_cast)]
theorem coe_zpow (x : H) (n : ℤ) : ((x ^ n : H) : G) = (x : G) ^ n := by
dsimp
@[to_additive (attr := simp)]
theorem mk_eq_one {g : G} {h} : (⟨g, h⟩ : H) = 1 ↔ g = 1 := Submonoid.mk_eq_one ..
/-- A subgroup of a group inherits a group structure. -/
@[to_additive /-- An `AddSubgroup` of an `AddGroup` inherits an `AddGroup` structure. -/]
instance toGroup {G : Type*} [Group G] (H : Subgroup G) : Group H := fast_instance%
Subtype.coe_injective.group _ rfl (fun _ _ => rfl) (fun _ => rfl) (fun _ _ => rfl)
(fun _ _ => rfl) fun _ _ => rfl
/-- A subgroup of a `CommGroup` is a `CommGroup`. -/
@[to_additive /-- An `AddSubgroup` of an `AddCommGroup` is an `AddCommGroup`. -/]
instance toCommGroup {G : Type*} [CommGroup G] (H : Subgroup G) : CommGroup H := fast_instance%
Subtype.coe_injective.commGroup _ rfl (fun _ _ => rfl) (fun _ => rfl) (fun _ _ => rfl)
(fun _ _ => rfl) fun _ _ => rfl
/-- The natural group hom from a subgroup of group `G` to `G`. -/
@[to_additive /-- The natural group hom from an `AddSubgroup` of `AddGroup` `G` to `G`. -/]
protected def subtype : H →* G where
toFun := ((↑) : H → G); map_one' := rfl; map_mul' _ _ := rfl
@[to_additive (attr := simp)]
lemma subtype_apply {s : Subgroup G} (x : s) :
s.subtype x = x := rfl
@[to_additive]
lemma subtype_injective (s : Subgroup G) :
Function.Injective s.subtype :=
Subtype.coe_injective
@[to_additive (attr := simp)]
theorem coe_subtype : ⇑H.subtype = ((↑) : H → G) :=
rfl
/-- The inclusion homomorphism from a subgroup `H` contained in `K` to `K`. -/
@[to_additive
/-- The inclusion homomorphism from an additive subgroup `H` contained in `K` to `K`. -/]
def inclusion {H K : Subgroup G} (h : H ≤ K) : H →* K :=
MonoidHom.mk' (fun x => ⟨x, h x.2⟩) fun _ _ => rfl
@[to_additive (attr := simp)]
theorem coe_inclusion {H K : Subgroup G} (h : H ≤ K) (a : H) : (inclusion h a : G) = a :=
Set.coe_inclusion h a
@[to_additive]
theorem inclusion_injective {H K : Subgroup G} (h : H ≤ K) : Function.Injective <| inclusion h :=
Set.inclusion_injective h
@[to_additive (attr := simp)]
lemma inclusion_inj {H K : Subgroup G} (h : H ≤ K) {x y : H} :
inclusion h x = inclusion h y ↔ x = y :=
(inclusion_injective h).eq_iff
@[to_additive (attr := simp)]
theorem subtype_comp_inclusion {H K : Subgroup G} (hH : H ≤ K) :
K.subtype.comp (inclusion hH) = H.subtype :=
rfl
open Set
/-- A subgroup `H` is normal if whenever `n ∈ H`, then `g * n * g⁻¹ ∈ H` for every `g : G` -/
structure Normal : Prop where
/-- `H` is closed under conjugation -/
conj_mem : ∀ n, n ∈ H → ∀ g : G, g * n * g⁻¹ ∈ H
attribute [class] Normal
end Subgroup
namespace AddSubgroup
/-- An AddSubgroup `H` is normal if whenever `n ∈ H`, then `g + n - g ∈ H` for every `g : A` -/
structure Normal (H : AddSubgroup A) : Prop where
/-- `H` is closed under additive conjugation -/
conj_mem : ∀ n, n ∈ H → ∀ g : A, g + n + -g ∈ H
attribute [to_additive] Subgroup.Normal
attribute [class] Normal
end AddSubgroup
namespace Subgroup
variable {H : Subgroup G}
@[to_additive]
instance (priority := 100) normal_of_comm {G : Type*} [CommGroup G] (H : Subgroup G) : H.Normal :=
⟨by simp [mul_comm]⟩
namespace Normal
@[to_additive]
theorem conj_mem' (nH : H.Normal) (n : G) (hn : n ∈ H) (g : G) :
g⁻¹ * n * g ∈ H := by
convert nH.conj_mem n hn g⁻¹
rw [inv_inv]
@[to_additive]
theorem mem_comm (nH : H.Normal) {a b : G} (h : a * b ∈ H) : b * a ∈ H := by
have : a⁻¹ * (a * b) * a⁻¹⁻¹ ∈ H := nH.conj_mem (a * b) h a⁻¹
simpa
@[to_additive]
theorem mem_comm_iff (nH : H.Normal) {a b : G} : a * b ∈ H ↔ b * a ∈ H :=
⟨nH.mem_comm, nH.mem_comm⟩
end Normal
end Subgroup
namespace Subgroup
variable (H : Subgroup G)
section Normalizer
/-- The `normalizer` of `H` is the largest subgroup of `G` inside which `H` is normal. -/
@[to_additive
/-- The `normalizer` of `H` is the largest subgroup of `G` inside which `H` is normal. -/]
def normalizer : Subgroup G where
carrier := { g : G | ∀ n, n ∈ H ↔ g * n * g⁻¹ ∈ H }
one_mem' := by simp
mul_mem' {a b} (ha : ∀ n, n ∈ H ↔ a * n * a⁻¹ ∈ H) (hb : ∀ n, n ∈ H ↔ b * n * b⁻¹ ∈ H) n := by
rw [hb, ha]
simp only [mul_assoc, mul_inv_rev]
inv_mem' {a} (ha : ∀ n, n ∈ H ↔ a * n * a⁻¹ ∈ H) n := by
rw [ha (a⁻¹ * n * a⁻¹⁻¹)]
simp only [inv_inv, mul_assoc, mul_inv_cancel_left, mul_inv_cancel, mul_one]
-- variant for sets.
-- TODO should this replace `normalizer`?
/-- The `setNormalizer` of `S` is the subgroup of `G` whose elements satisfy `g*S*g⁻¹=S` -/
@[to_additive
/-- The `setNormalizer` of `S` is the subgroup of `G` whose elements satisfy
`g+S-g=S`. -/]
def setNormalizer (S : Set G) : Subgroup G where
carrier := { g : G | ∀ n, n ∈ S ↔ g * n * g⁻¹ ∈ S }
one_mem' := by simp
mul_mem' {a b} (ha : ∀ n, n ∈ S ↔ a * n * a⁻¹ ∈ S) (hb : ∀ n, n ∈ S ↔ b * n * b⁻¹ ∈ S) n := by
rw [hb, ha]
simp only [mul_assoc, mul_inv_rev]
inv_mem' {a} (ha : ∀ n, n ∈ S ↔ a * n * a⁻¹ ∈ S) n := by
rw [ha (a⁻¹ * n * a⁻¹⁻¹)]
simp only [inv_inv, mul_assoc, mul_inv_cancel_left, mul_inv_cancel, mul_one]
variable {H}
@[to_additive]
theorem mem_normalizer_iff {g : G} : g ∈ H.normalizer ↔ ∀ h, h ∈ H ↔ g * h * g⁻¹ ∈ H :=
Iff.rfl
@[to_additive]
theorem mem_normalizer_iff'' {g : G} : g ∈ H.normalizer ↔ ∀ h : G, h ∈ H ↔ g⁻¹ * h * g ∈ H := by
rw [← inv_mem_iff (x := g), mem_normalizer_iff, inv_inv]
@[to_additive]
theorem mem_normalizer_iff' {g : G} : g ∈ H.normalizer ↔ ∀ n, n * g ∈ H ↔ g * n ∈ H :=
⟨fun h n => by rw [h, mul_assoc, mul_inv_cancel_right], fun h n => by
rw [mul_assoc, ← h, inv_mul_cancel_right]⟩
@[to_additive]
theorem le_normalizer : H ≤ normalizer H := fun x xH n => by
rw [H.mul_mem_cancel_right (H.inv_mem xH), H.mul_mem_cancel_left xH]
end Normalizer
/-- A subgroup of a commutative group is commutative. -/
@[to_additive /-- A subgroup of a commutative group is commutative. -/]
instance commGroup_isMulCommutative {G : Type*} [CommGroup G] (H : Subgroup G) :
IsMulCommutative H :=
⟨CommMagma.to_isCommutative⟩
@[to_additive]
lemma mul_comm_of_mem_isMulCommutative [IsMulCommutative H] {a b : G} (ha : a ∈ H) (hb : b ∈ H) :
a * b = b * a := by
simpa only [MulMemClass.mk_mul_mk, Subtype.mk.injEq] using mul_comm (⟨a, ha⟩ : H) (⟨b, hb⟩ : H)
end Subgroup
@[to_additive]
theorem Set.injOn_iff_map_eq_one {F G H S : Type*} [Group G] [Group H]
[FunLike F G H] [MonoidHomClass F G H] (f : F)
[SetLike S G] [OneMemClass S G] [MulMemClass S G] [InvMemClass S G] (s : S) :
Set.InjOn f s ↔ ∀ a ∈ s, f a = 1 → a = 1 where
mp h a ha ha' := by
refine h ha (one_mem s) ?_
rwa [map_one]
mpr h x hx y hy hxy := by
refine mul_inv_eq_one.1 <| h _ (mul_mem ?_ (inv_mem ?_)) ?_ <;> simp_all |
.lake/packages/mathlib/Mathlib/Algebra/Group/Subgroup/Finsupp.lean | import Mathlib.Algebra.BigOperators.Finsupp.Basic
import Mathlib.Algebra.Group.Subgroup.Lattice
/-! # Connection between `Subgroup.closure` and `Finsupp.prod` -/
assert_not_exists Field
namespace Subgroup
variable {M : Type*} [CommGroup M] {ι : Type*} (f : ι → M) (x : M)
@[to_additive]
theorem exists_finsupp_of_mem_closure_range (hx : x ∈ closure (Set.range f)) :
∃ a : ι →₀ ℤ, x = a.prod (f · ^ ·) := by
classical
induction hx using closure_induction with
| mem x h => obtain ⟨i, rfl⟩ := h; exact ⟨Finsupp.single i 1, by simp⟩
| one => use 0; simp
| mul x y hx hy hx' hy' =>
obtain ⟨⟨v, rfl⟩, w, rfl⟩ := And.intro hx' hy'
use v + w
rw [Finsupp.prod_add_index]
· simp
· simp [zpow_add]
| inv x hx hx' =>
obtain ⟨a, rfl⟩ := hx'
use -a
rw [Finsupp.prod_neg_index]
· simp
· simp
@[to_additive]
theorem exists_of_mem_closure_range [Fintype ι] (hx : x ∈ closure (Set.range f)) :
∃ a : ι → ℤ, x = ∏ i, f i ^ a i := by
obtain ⟨a, rfl⟩ := exists_finsupp_of_mem_closure_range f x hx
exact ⟨a, by simp⟩
variable {f x}
@[to_additive]
theorem mem_closure_range_iff :
x ∈ closure (Set.range f) ↔ ∃ a : ι →₀ ℤ, x = a.prod (f · ^ ·) := by
refine ⟨exists_finsupp_of_mem_closure_range f x, ?_⟩
rintro ⟨a, rfl⟩
exact Submonoid.prod_mem _ fun i hi ↦ zpow_mem (subset_closure (Set.mem_range_self i)) _
@[to_additive]
theorem mem_closure_range_iff_of_fintype [Fintype ι] :
x ∈ closure (Set.range f) ↔ ∃ a : ι → ℤ, x = ∏ i, f i ^ a i := by
rw [Finsupp.equivFunOnFinite.symm.exists_congr_left, mem_closure_range_iff]
simp
@[to_additive]
theorem mem_closure_iff_of_fintype {s : Set M} [Fintype s] :
x ∈ closure s ↔ ∃ a : s → ℤ, x = ∏ i : s, i.1 ^ a i := by
conv_lhs => rw [← Subtype.range_coe (s := s)]
exact mem_closure_range_iff_of_fintype
end Subgroup |
.lake/packages/mathlib/Mathlib/Algebra/Group/Subgroup/Even.lean | import Mathlib.Algebra.Group.Even
import Mathlib.Algebra.Group.Subgroup.Defs
/-!
# Squares and even elements
This file defines the subgroup of squares / even elements in an abelian group.
-/
assert_not_exists RelIso MonoidWithZero
namespace Subsemigroup
variable {S : Type*} [CommSemigroup S]
variable (S) in
/--
In a commutative semigroup `S`, `Subsemigroup.square S` is the subsemigroup of squares in `S`.
-/
@[to_additive
/-- In a commutative additive semigroup `S`, `AddSubsemigroup.even S`
is the subsemigroup of even elements in `S`. -/]
def square : Subsemigroup S where
carrier := {s : S | IsSquare s}
mul_mem' := IsSquare.mul
@[to_additive (attr := simp)]
theorem mem_square {a : S} : a ∈ square S ↔ IsSquare a := Iff.rfl
@[to_additive (attr := simp, norm_cast)]
theorem coe_square : square S = {s : S | IsSquare s} := rfl
end Subsemigroup
namespace Submonoid
variable {M : Type*} [CommMonoid M]
variable (M) in
/--
In a commutative monoid `M`, `Submonoid.square M` is the submonoid of squares in `M`.
-/
@[to_additive
/-- In a commutative additive monoid `M`, `AddSubmonoid.even M`
is the submonoid of even elements in `M`. -/]
def square : Submonoid M where
__ := Subsemigroup.square M
one_mem' := IsSquare.one
@[to_additive (attr := simp)]
theorem square_toSubsemigroup : (square M).toSubsemigroup = .square M := rfl
@[to_additive (attr := simp)]
theorem mem_square {a : M} : a ∈ square M ↔ IsSquare a := Iff.rfl
@[to_additive (attr := simp, norm_cast)]
theorem coe_square : square M = {s : M | IsSquare s} := rfl
end Submonoid
namespace Subgroup
variable {G : Type*} [CommGroup G]
variable (G) in
/--
In an abelian group `G`, `Subgroup.square G` is the subgroup of squares in `G`.
-/
@[to_additive
/-- In an abelian additive group `G`, `AddSubgroup.even G` is
the subgroup of even elements in `G`. -/]
def square : Subgroup G where
__ := Submonoid.square G
inv_mem' := IsSquare.inv
@[to_additive (attr := simp)]
theorem square_toSubmonoid : (square G).toSubmonoid = .square G := rfl
@[to_additive (attr := simp)]
theorem mem_square {a : G} : a ∈ square G ↔ IsSquare a := Iff.rfl
@[to_additive (attr := simp, norm_cast)]
theorem coe_square : square G = {s : G | IsSquare s} := rfl
end Subgroup |
.lake/packages/mathlib/Mathlib/Algebra/Group/Subgroup/Ker.lean | import Mathlib.Algebra.Group.Subgroup.Map
import Mathlib.Tactic.ApplyFun
/-!
# Kernel and range of group homomorphisms
We define and prove results about the kernel and range of group homomorphisms.
Special thanks goes to Amelia Livingston and Yury Kudryashov for their help and inspiration.
## Main definitions
Notation used here:
- `G N` are `Group`s
- `x` is an element of type `G`
- `f g : N →* G` are group homomorphisms
Definitions in the file:
* `MonoidHom.range f` : the range of the group homomorphism `f` is a subgroup
* `MonoidHom.ker f` : the kernel of a group homomorphism `f` is the subgroup of elements `x : G`
such that `f x = 1`
* `MonoidHom.eqLocus f g` : given group homomorphisms `f`, `g`, the elements of `G` such that
`f x = g x` form a subgroup of `G`
## Implementation notes
Subgroup inclusion is denoted `≤` rather than `⊆`, although `∈` is defined as
membership of a subgroup's underlying set.
## Tags
subgroup, subgroups
-/
assert_not_exists IsOrderedMonoid Multiset Ring
open Function
open scoped Int
variable {G G' G'' : Type*} [Group G] [Group G'] [Group G'']
variable {A : Type*} [AddGroup A]
namespace MonoidHom
variable {N : Type*} {P : Type*} [Group N] [Group P] (K : Subgroup G)
open Subgroup
/-- The range of a monoid homomorphism from a group is a subgroup. -/
@[to_additive /-- The range of an `AddMonoidHom` from an `AddGroup` is an `AddSubgroup`. -/]
def range (f : G →* N) : Subgroup N :=
Subgroup.copy ((⊤ : Subgroup G).map f) (Set.range f) (by simp)
@[to_additive (attr := simp)]
theorem coe_range (f : G →* N) : (f.range : Set N) = Set.range f :=
rfl
@[to_additive (attr := simp)]
theorem mem_range {f : G →* N} {y : N} : y ∈ f.range ↔ ∃ x, f x = y :=
Iff.rfl
@[to_additive]
theorem range_eq_map (f : G →* N) : f.range = (⊤ : Subgroup G).map f := by ext; simp
@[to_additive]
instance range_isMulCommutative {G : Type*} [CommGroup G] {N : Type*} [Group N] (f : G →* N) :
IsMulCommutative f.range :=
range_eq_map f ▸ Subgroup.map_isMulCommutative ⊤ f
@[to_additive (attr := simp)]
theorem restrict_range (f : G →* N) : (f.restrict K).range = K.map f := by
simp_rw [SetLike.ext_iff, mem_range, mem_map, restrict_apply, SetLike.exists,
exists_prop, forall_const]
/-- The canonical surjective group homomorphism `G →* f(G)` induced by a group
homomorphism `G →* N`. -/
@[to_additive
/-- The canonical surjective `AddGroup` homomorphism `G →+ f(G)` induced by a group
homomorphism `G →+ N`. -/]
def rangeRestrict (f : G →* N) : G →* f.range :=
codRestrict f _ fun x => ⟨x, rfl⟩
@[to_additive (attr := simp)]
theorem coe_rangeRestrict (f : G →* N) (g : G) : (f.rangeRestrict g : N) = f g :=
rfl
@[to_additive]
theorem coe_comp_rangeRestrict (f : G →* N) :
((↑) : f.range → N) ∘ (⇑f.rangeRestrict : G → f.range) = f :=
rfl
@[to_additive]
theorem subtype_comp_rangeRestrict (f : G →* N) : f.range.subtype.comp f.rangeRestrict = f :=
ext <| f.coe_rangeRestrict
@[to_additive]
theorem rangeRestrict_surjective (f : G →* N) : Function.Surjective f.rangeRestrict :=
fun ⟨_, g, rfl⟩ => ⟨g, rfl⟩
@[to_additive (attr := simp)]
lemma rangeRestrict_injective_iff {f : G →* N} : Injective f.rangeRestrict ↔ Injective f := by
convert Set.injective_codRestrict _
@[to_additive]
theorem map_range (g : N →* P) (f : G →* N) : f.range.map g = (g.comp f).range := by
rw [range_eq_map, range_eq_map]; exact (⊤ : Subgroup G).map_map g f
@[to_additive]
lemma range_comp (g : N →* P) (f : G →* N) : (g.comp f).range = f.range.map g := (map_range ..).symm
@[to_additive]
theorem range_eq_top {N} [Group N] {f : G →* N} :
f.range = (⊤ : Subgroup N) ↔ Function.Surjective f :=
SetLike.ext'_iff.trans <| Iff.trans (by rw [coe_range, coe_top]) Set.range_eq_univ
/-- The range of a surjective monoid homomorphism is the whole of the codomain. -/
@[to_additive (attr := simp)
/-- The range of a surjective `AddMonoid` homomorphism is the whole of the codomain. -/]
theorem range_eq_top_of_surjective {N} [Group N] (f : G →* N) (hf : Function.Surjective f) :
f.range = (⊤ : Subgroup N) :=
range_eq_top.2 hf
@[to_additive (attr := simp)]
theorem range_one : (1 : G →* N).range = ⊥ :=
SetLike.ext fun x => by simpa using @comm _ (· = ·) _ 1 x
@[to_additive (attr := simp)]
theorem _root_.Subgroup.range_subtype (H : Subgroup G) : H.subtype.range = H :=
SetLike.coe_injective <| (coe_range _).trans <| Subtype.range_coe
@[to_additive]
alias _root_.Subgroup.subtype_range := Subgroup.range_subtype
@[to_additive (attr := simp)]
theorem _root_.Subgroup.inclusion_range {H K : Subgroup G} (h_le : H ≤ K) :
(inclusion h_le).range = H.subgroupOf K :=
Subgroup.ext fun g => Set.ext_iff.mp (Set.range_inclusion h_le) g
@[to_additive]
theorem subgroupOf_range_eq_of_le {G₁ G₂ : Type*} [Group G₁] [Group G₂] {K : Subgroup G₂}
(f : G₁ →* G₂) (h : f.range ≤ K) :
f.range.subgroupOf K = (f.codRestrict K fun x => h ⟨x, rfl⟩).range := by
ext k
refine exists_congr ?_
simp [Subtype.ext_iff]
/-- Computable alternative to `MonoidHom.ofInjective`. -/
@[to_additive /-- Computable alternative to `AddMonoidHom.ofInjective`. -/]
def ofLeftInverse {f : G →* N} {g : N →* G} (h : Function.LeftInverse g f) : G ≃* f.range :=
{ f.rangeRestrict with
toFun := f.rangeRestrict
invFun := g ∘ f.range.subtype
left_inv := h
right_inv := by
rintro ⟨x, y, rfl⟩
solve_by_elim }
@[to_additive (attr := simp)]
theorem ofLeftInverse_apply {f : G →* N} {g : N →* G} (h : Function.LeftInverse g f) (x : G) :
↑(ofLeftInverse h x) = f x :=
rfl
@[to_additive (attr := simp)]
theorem ofLeftInverse_symm_apply {f : G →* N} {g : N →* G} (h : Function.LeftInverse g f)
(x : f.range) : (ofLeftInverse h).symm x = g x :=
rfl
/-- The range of an injective group homomorphism is isomorphic to its domain. -/
@[to_additive /-- The range of an injective additive group homomorphism is isomorphic to its
domain. -/]
noncomputable def ofInjective {f : G →* N} (hf : Function.Injective f) : G ≃* f.range :=
MulEquiv.ofBijective (f.codRestrict f.range fun x => ⟨x, rfl⟩)
⟨fun _ _ h => hf (Subtype.ext_iff.mp h), by
rintro ⟨x, y, rfl⟩
exact ⟨y, rfl⟩⟩
@[to_additive]
theorem ofInjective_apply {f : G →* N} (hf : Function.Injective f) {x : G} :
↑(ofInjective hf x) = f x :=
rfl
@[to_additive (attr := simp)]
theorem apply_ofInjective_symm {f : G →* N} (hf : Function.Injective f) (x : f.range) :
f ((ofInjective hf).symm x) = x :=
Subtype.ext_iff.1 <| (ofInjective hf).apply_symm_apply x
@[simp]
theorem coe_toAdditive_range (f : G →* G') :
(MonoidHom.toAdditive f).range = Subgroup.toAddSubgroup f.range := rfl
@[simp]
theorem coe_toMultiplicative_range {A A' : Type*} [AddGroup A] [AddGroup A'] (f : A →+ A') :
(AddMonoidHom.toMultiplicative f).range = AddSubgroup.toSubgroup f.range := rfl
section Ker
variable {M : Type*} [MulOneClass M]
/-- The multiplicative kernel of a monoid homomorphism is the subgroup of elements `x : G` such that
`f x = 1` -/
@[to_additive
/-- The additive kernel of an `AddMonoid` homomorphism is the `AddSubgroup` of elements
such that `f x = 0` -/]
def ker (f : G →* M) : Subgroup G :=
{ MonoidHom.mker f with
inv_mem' := fun {x} (hx : f x = 1) =>
calc
f x⁻¹ = f x * f x⁻¹ := by rw [hx, one_mul]
_ = 1 := by rw [← map_mul, mul_inv_cancel, map_one] }
@[to_additive (attr := simp)]
theorem ker_toSubmonoid (f : G →* M) : f.ker.toSubmonoid = MonoidHom.mker f := rfl
@[to_additive (attr := simp)]
theorem mem_ker {f : G →* M} {x : G} : x ∈ f.ker ↔ f x = 1 :=
Iff.rfl
@[to_additive]
theorem div_mem_ker_iff (f : G →* N) {x y : G} : x / y ∈ ker f ↔ f x = f y := by
rw [mem_ker, map_div, div_eq_one]
@[to_additive]
theorem coe_ker (f : G →* M) : (f.ker : Set G) = (f : G → M) ⁻¹' {1} :=
rfl
@[to_additive (attr := simp)]
theorem ker_toHomUnits {M} [Monoid M] (f : G →* M) : f.toHomUnits.ker = f.ker := by
ext x
simp [mem_ker, Units.ext_iff]
@[to_additive]
theorem eq_iff (f : G →* M) {x y : G} : f x = f y ↔ y⁻¹ * x ∈ f.ker := by
constructor <;> intro h
· rw [mem_ker, map_mul, h, ← map_mul, inv_mul_cancel, map_one]
· rw [← one_mul x, ← mul_inv_cancel y, mul_assoc, map_mul, mem_ker.1 h, mul_one]
@[to_additive]
instance decidableMemKer [DecidableEq M] (f : G →* M) : DecidablePred (· ∈ f.ker) := fun x =>
decidable_of_iff (f x = 1) f.mem_ker
@[to_additive]
theorem comap_ker {P : Type*} [MulOneClass P] (g : N →* P) (f : G →* N) :
g.ker.comap f = (g.comp f).ker :=
rfl
@[to_additive (attr := simp)]
theorem comap_bot (f : G →* N) : (⊥ : Subgroup N).comap f = f.ker :=
rfl
@[to_additive (attr := simp)]
theorem ker_restrict (f : G →* N) : (f.restrict K).ker = f.ker.subgroupOf K :=
rfl
@[to_additive (attr := simp)]
theorem ker_codRestrict {S} [SetLike S N] [SubmonoidClass S N] (f : G →* N) (s : S)
(h : ∀ x, f x ∈ s) : (f.codRestrict s h).ker = f.ker :=
SetLike.ext fun _x => Subtype.ext_iff
@[to_additive (attr := simp)]
theorem ker_rangeRestrict (f : G →* N) : ker (rangeRestrict f) = ker f :=
ker_codRestrict _ _ _
@[to_additive (attr := simp)]
theorem ker_one : (1 : G →* M).ker = ⊤ :=
SetLike.ext fun _x => eq_self_iff_true _
@[to_additive (attr := simp)]
theorem ker_id : (MonoidHom.id G).ker = ⊥ :=
rfl
@[to_additive] theorem ker_eq_top_iff {f : G →* M} : f.ker = ⊤ ↔ f = 1 := by
simp [ker, ← top_le_iff, SetLike.le_def, f.ext_iff]
@[to_additive] theorem range_eq_bot_iff {f : G →* G'} : f.range = ⊥ ↔ f = 1 := by
rw [← le_bot_iff, f.range_eq_map, map_le_iff_le_comap, top_le_iff, comap_bot, ker_eq_top_iff]
@[to_additive]
theorem ker_eq_bot_iff (f : G →* M) : f.ker = ⊥ ↔ Function.Injective f :=
⟨fun h x y hxy => by rwa [eq_iff, h, mem_bot, inv_mul_eq_one, eq_comm] at hxy, fun h =>
bot_unique fun _ hx => h (hx.trans f.map_one.symm)⟩
@[to_additive (attr := simp)]
theorem _root_.Subgroup.ker_subtype (H : Subgroup G) : H.subtype.ker = ⊥ :=
H.subtype.ker_eq_bot_iff.mpr Subtype.coe_injective
@[to_additive (attr := simp)]
theorem _root_.Subgroup.ker_inclusion {H K : Subgroup G} (h : H ≤ K) : (inclusion h).ker = ⊥ :=
(inclusion h).ker_eq_bot_iff.mpr (Set.inclusion_injective h)
@[to_additive ker_prod]
theorem ker_prod {M N : Type*} [MulOneClass M] [MulOneClass N] (f : G →* M) (g : G →* N) :
(f.prod g).ker = f.ker ⊓ g.ker :=
SetLike.ext fun _ => Prod.mk_eq_one
@[to_additive]
theorem range_le_ker_iff (f : G →* G') (g : G' →* G'') : f.range ≤ g.ker ↔ g.comp f = 1 :=
⟨fun h => ext fun x => h ⟨x, rfl⟩, by rintro h _ ⟨y, rfl⟩; exact DFunLike.congr_fun h y⟩
@[to_additive]
instance (priority := 100) normal_ker (f : G →* M) : f.ker.Normal :=
⟨fun x hx y => by
rw [mem_ker, map_mul, map_mul, mem_ker.1 hx, mul_one, map_mul_eq_one f (mul_inv_cancel y)]⟩
@[simp]
theorem coe_toAdditive_ker (f : G →* G') :
(MonoidHom.toAdditive f).ker = Subgroup.toAddSubgroup f.ker := rfl
@[simp]
theorem coe_toMultiplicative_ker {A A' : Type*} [AddGroup A] [AddZeroClass A'] (f : A →+ A') :
(AddMonoidHom.toMultiplicative f).ker = AddSubgroup.toSubgroup f.ker := rfl
end Ker
section EqLocus
variable {M : Type*} [Monoid M]
/-- The subgroup of elements `x : G` such that `f x = g x` -/
@[to_additive /-- The additive subgroup of elements `x : G` such that `f x = g x` -/]
def eqLocus (f g : G →* M) : Subgroup G :=
{ eqLocusM f g with inv_mem' := eq_on_inv f g }
@[to_additive (attr := simp)]
theorem eqLocus_same (f : G →* N) : f.eqLocus f = ⊤ :=
SetLike.ext fun _ => eq_self_iff_true _
/-- If two monoid homomorphisms are equal on a set, then they are equal on its subgroup closure. -/
@[to_additive
/-- If two monoid homomorphisms are equal on a set, then they are equal on its subgroup
closure. -/]
theorem eqOn_closure {f g : G →* M} {s : Set G} (h : Set.EqOn f g s) : Set.EqOn f g (closure s) :=
show closure s ≤ f.eqLocus g from (closure_le _).2 h
@[to_additive]
theorem eq_of_eqOn_top {f g : G →* M} (h : Set.EqOn f g (⊤ : Subgroup G)) : f = g :=
ext fun _x => h trivial
@[to_additive]
theorem eq_of_eqOn_dense {s : Set G} (hs : closure s = ⊤) {f g : G →* M} (h : s.EqOn f g) : f = g :=
eq_of_eqOn_top <| hs ▸ eqOn_closure h
end EqLocus
end MonoidHom
namespace Subgroup
variable {N : Type*} [Group N] (H : Subgroup G)
@[to_additive]
theorem map_eq_bot_iff {f : G →* N} : H.map f = ⊥ ↔ H ≤ f.ker :=
(gc_map_comap f).l_eq_bot
@[to_additive]
theorem map_eq_bot_iff_of_injective {f : G →* N} (hf : Function.Injective f) :
H.map f = ⊥ ↔ H = ⊥ := by rw [map_eq_bot_iff, f.ker_eq_bot_iff.mpr hf, le_bot_iff]
open MonoidHom
variable (f : G →* N)
@[to_additive]
theorem map_le_range (H : Subgroup G) : map f H ≤ f.range :=
(range_eq_map f).symm ▸ map_mono le_top
@[to_additive]
theorem map_subtype_le {H : Subgroup G} (K : Subgroup H) : K.map H.subtype ≤ H :=
(K.map_le_range H.subtype).trans_eq H.range_subtype
@[to_additive]
theorem ker_le_comap (H : Subgroup N) : f.ker ≤ comap f H :=
comap_bot f ▸ comap_mono bot_le
@[to_additive]
theorem map_comap_eq (H : Subgroup N) : map f (comap f H) = f.range ⊓ H :=
SetLike.ext' <| by
rw [coe_map, coe_comap, Set.image_preimage_eq_inter_range, coe_inf, coe_range, Set.inter_comm]
@[to_additive]
theorem comap_map_eq (H : Subgroup G) : comap f (map f H) = H ⊔ f.ker := by
refine le_antisymm ?_ (sup_le (le_comap_map _ _) (ker_le_comap _ _))
intro x hx; simp only [mem_map, mem_comap] at hx
rcases hx with ⟨y, hy, hy'⟩
rw [← mul_inv_cancel_left y x]
exact mul_mem_sup hy (by simp [mem_ker, hy'])
@[to_additive]
theorem map_comap_eq_self {f : G →* N} {H : Subgroup N} (h : H ≤ f.range) :
map f (comap f H) = H := by
rwa [map_comap_eq, inf_eq_right]
@[to_additive]
theorem map_comap_eq_self_of_surjective {f : G →* N} (h : Function.Surjective f) (H : Subgroup N) :
map f (comap f H) = H :=
map_comap_eq_self (range_eq_top.2 h ▸ le_top)
@[to_additive]
theorem comap_le_comap_of_le_range {f : G →* N} {K L : Subgroup N} (hf : K ≤ f.range) :
K.comap f ≤ L.comap f ↔ K ≤ L :=
⟨(map_comap_eq_self hf).ge.trans ∘ map_le_iff_le_comap.mpr, comap_mono⟩
@[to_additive]
theorem comap_le_comap_of_surjective {f : G →* N} {K L : Subgroup N} (hf : Function.Surjective f) :
K.comap f ≤ L.comap f ↔ K ≤ L :=
comap_le_comap_of_le_range (range_eq_top.2 hf ▸ le_top)
@[to_additive]
theorem comap_lt_comap_of_surjective {f : G →* N} {K L : Subgroup N} (hf : Function.Surjective f) :
K.comap f < L.comap f ↔ K < L := by simp_rw [lt_iff_le_not_ge, comap_le_comap_of_surjective hf]
@[to_additive]
theorem comap_injective {f : G →* N} (h : Function.Surjective f) : Function.Injective (comap f) :=
fun K L => by simp only [le_antisymm_iff, comap_le_comap_of_surjective h, imp_self]
@[to_additive]
theorem comap_map_eq_self {f : G →* N} {H : Subgroup G} (h : f.ker ≤ H) :
comap f (map f H) = H := by
rwa [comap_map_eq, sup_eq_left]
@[to_additive]
theorem comap_map_eq_self_of_injective {f : G →* N} (h : Function.Injective f) (H : Subgroup G) :
comap f (map f H) = H :=
comap_map_eq_self (((ker_eq_bot_iff _).mpr h).symm ▸ bot_le)
@[to_additive]
theorem map_le_map_iff {f : G →* N} {H K : Subgroup G} : H.map f ≤ K.map f ↔ H ≤ K ⊔ f.ker := by
rw [map_le_iff_le_comap, comap_map_eq]
@[to_additive]
theorem map_le_map_iff' {f : G →* N} {H K : Subgroup G} :
H.map f ≤ K.map f ↔ H ⊔ f.ker ≤ K ⊔ f.ker := by
simp only [map_le_map_iff, sup_le_iff, le_sup_right, and_true]
@[to_additive]
theorem map_eq_map_iff {f : G →* N} {H K : Subgroup G} :
H.map f = K.map f ↔ H ⊔ f.ker = K ⊔ f.ker := by simp only [le_antisymm_iff, map_le_map_iff']
@[to_additive]
theorem map_eq_range_iff {f : G →* N} {H : Subgroup G} :
H.map f = f.range ↔ Codisjoint H f.ker := by
rw [f.range_eq_map, map_eq_map_iff, codisjoint_iff, top_sup_eq]
@[to_additive]
theorem map_le_map_iff_of_injective {f : G →* N} (hf : Function.Injective f) {H K : Subgroup G} :
H.map f ≤ K.map f ↔ H ≤ K := by rw [map_le_iff_le_comap, comap_map_eq_self_of_injective hf]
@[to_additive (attr := simp)]
theorem map_subtype_le_map_subtype {G' : Subgroup G} {H K : Subgroup G'} :
H.map G'.subtype ≤ K.map G'.subtype ↔ H ≤ K :=
map_le_map_iff_of_injective G'.subtype_injective
/-- Subgroups of the subgroup `H` are considered as subgroups that are less than or equal to
`H`. -/
@[to_additive (attr := simps apply_coe) /-- Additive subgroups of the subgroup `H` are considered as
additive subgroups that are less than or equal to `H`. -/]
def MapSubtype.orderIso (H : Subgroup G) : Subgroup ↥H ≃o { H' : Subgroup G // H' ≤ H } where
toFun H' := ⟨H'.map H.subtype, map_subtype_le H'⟩
invFun sH' := sH'.1.subgroupOf H
left_inv H' := comap_map_eq_self_of_injective H.subtype_injective H'
right_inv sH' := Subtype.ext (map_subgroupOf_eq_of_le sH'.2)
map_rel_iff' := by simp
@[to_additive (attr := simp)]
lemma MapSubtype.orderIso_symm_apply (H : Subgroup G) (sH' : { H' : Subgroup G // H' ≤ H }) :
(MapSubtype.orderIso H).symm sH' = sH'.1.subgroupOf H :=
rfl
@[to_additive]
protected lemma «forall» {H : Subgroup G} {P : Subgroup H → Prop} :
(∀ H' : Subgroup H, P H') ↔ (∀ H' ≤ H, P (H'.subgroupOf H)) := by
simp [(MapSubtype.orderIso H).forall_congr_left]
@[to_additive]
theorem map_lt_map_iff_of_injective {f : G →* N} (hf : Function.Injective f) {H K : Subgroup G} :
H.map f < K.map f ↔ H < K :=
lt_iff_lt_of_le_iff_le' (map_le_map_iff_of_injective hf) (map_le_map_iff_of_injective hf)
@[to_additive (attr := simp)]
theorem map_subtype_lt_map_subtype {G' : Subgroup G} {H K : Subgroup G'} :
H.map G'.subtype < K.map G'.subtype ↔ H < K :=
map_lt_map_iff_of_injective G'.subtype_injective
@[to_additive]
theorem map_injective {f : G →* N} (h : Function.Injective f) : Function.Injective (map f) :=
Function.LeftInverse.injective <| comap_map_eq_self_of_injective h
/-- Given `f(A) = f(B)`, `ker f ≤ A`, and `ker f ≤ B`, deduce that `A = B`. -/
@[to_additive /-- Given `f(A) = f(B)`, `ker f ≤ A`, and `ker f ≤ B`, deduce that `A = B`. -/]
theorem map_injective_of_ker_le {H K : Subgroup G} (hH : f.ker ≤ H) (hK : f.ker ≤ K)
(hf : map f H = map f K) : H = K := by
apply_fun comap f at hf
rwa [comap_map_eq, comap_map_eq, sup_of_le_left hH, sup_of_le_left hK] at hf
@[to_additive]
theorem ker_subgroupMap : (f.subgroupMap H).ker = f.ker.subgroupOf H :=
ext fun _ ↦ Subtype.ext_iff
@[to_additive]
theorem closure_preimage_eq_top (s : Set G) : closure ((closure s).subtype ⁻¹' s) = ⊤ := by
simp
@[to_additive]
theorem comap_sup_eq_of_le_range {H K : Subgroup N} (hH : H ≤ f.range) (hK : K ≤ f.range) :
comap f H ⊔ comap f K = comap f (H ⊔ K) :=
map_injective_of_ker_le f ((ker_le_comap f H).trans le_sup_left) (ker_le_comap f (H ⊔ K))
(by
rw [map_comap_eq, map_sup, map_comap_eq, map_comap_eq, inf_eq_right.mpr hH,
inf_eq_right.mpr hK, inf_eq_right.mpr (sup_le hH hK)])
@[to_additive]
theorem comap_sup_eq (H K : Subgroup N) (hf : Function.Surjective f) :
comap f H ⊔ comap f K = comap f (H ⊔ K) :=
comap_sup_eq_of_le_range f (range_eq_top.2 hf ▸ le_top) (range_eq_top.2 hf ▸ le_top)
@[to_additive]
theorem subgroupOf_sup {A A' B : Subgroup G} (hA : A ≤ B) (hA' : A' ≤ B) :
(A ⊔ A').subgroupOf B = A.subgroupOf B ⊔ A'.subgroupOf B := by
refine
map_injective_of_ker_le B.subtype (ker_le_comap _ _)
(le_trans (ker_le_comap B.subtype _) le_sup_left) ?_
simp only [subgroupOf, map_comap_eq, map_sup, range_subtype]
rw [inf_of_le_right (sup_le hA hA'), inf_of_le_right hA', inf_of_le_right hA]
@[deprecated "Use in reverse direction." (since := "2025-11-03")] alias sup_subgroupOf_eq :=
subgroupOf_sup
@[to_additive]
theorem codisjoint_subgroupOf_sup (H K : Subgroup G) :
Codisjoint (H.subgroupOf (H ⊔ K)) (K.subgroupOf (H ⊔ K)) := by
rw [codisjoint_iff, ← subgroupOf_sup, subgroupOf_self]
exacts [le_sup_left, le_sup_right]
end Subgroup |
.lake/packages/mathlib/Mathlib/Algebra/Group/Subgroup/Lattice.lean | import Mathlib.Algebra.Group.Submonoid.Operations
import Mathlib.Algebra.Group.Subgroup.Defs
/-!
# Lattice structure of subgroups
We prove subgroups of a group form a complete lattice.
There are also theorems about the subgroups generated by an element or a subset of a group,
defined both inductively and as the infimum of the set of subgroups containing a given
element/subset.
Special thanks goes to Amelia Livingston and Yury Kudryashov for their help and inspiration.
## Main definitions
Notation used here:
- `G` is a `Group`
- `k` is a set of elements of type `G`
Definitions in the file:
* `CompleteLattice (Subgroup G)` : the subgroups of `G` form a complete lattice
* `Subgroup.closure k` : the minimal subgroup that includes the set `k`
* `Subgroup.gi` : `closure` forms a Galois insertion with the coercion to set
## Implementation notes
Subgroup inclusion is denoted `≤` rather than `⊆`, although `∈` is defined as
membership of a subgroup's underlying set.
## Tags
subgroup, subgroups
-/
assert_not_exists IsOrderedMonoid Multiset Ring
open Function
open scoped Int
variable {G : Type*} [Group G]
/-!
### Conversion to/from `Additive`/`Multiplicative`
-/
section mul_add
variable {A : Type*} [AddGroup A]
/-- Subgroups of a group `G` are isomorphic to additive subgroups of `Additive G`. -/
@[simps!]
def Subgroup.toAddSubgroup : Subgroup G ≃o AddSubgroup (Additive G) where
toFun S := { Submonoid.toAddSubmonoid S.toSubmonoid with neg_mem' := S.inv_mem' }
invFun S := { AddSubmonoid.toSubmonoid S.toAddSubmonoid with inv_mem' := S.neg_mem' }
left_inv x := by cases x; rfl
right_inv x := by cases x; rfl
map_rel_iff' := Iff.rfl
@[simp] lemma Additive.mem_toAddSubgroup (S : Subgroup G) (g : Additive G) :
g ∈ S.toAddSubgroup ↔ Additive.toMul g ∈ S :=
.rfl
/-- Additive subgroups of an additive group `Additive G` are isomorphic to subgroups of `G`. -/
abbrev AddSubgroup.toSubgroup' : AddSubgroup (Additive G) ≃o Subgroup G :=
Subgroup.toAddSubgroup.symm
@[simp] lemma AddSubgroup.mem_toSubgroup' (S : AddSubgroup (Additive G)) (g : G) :
g ∈ toSubgroup' S ↔ Additive.ofMul g ∈ S :=
.rfl
/-- Additive subgroups of an additive group `A` are isomorphic to subgroups of `Multiplicative A`.
-/
@[simps!]
def AddSubgroup.toSubgroup : AddSubgroup A ≃o Subgroup (Multiplicative A) where
toFun S := { AddSubmonoid.toSubmonoid S.toAddSubmonoid with inv_mem' := S.neg_mem' }
invFun S := { Submonoid.toAddSubmonoid S.toSubmonoid with neg_mem' := S.inv_mem' }
left_inv x := by cases x; rfl
right_inv x := by cases x; rfl
map_rel_iff' := Iff.rfl
@[simp] lemma Multiplicative.mem_toSubgroup (S : AddSubgroup A) (a : Multiplicative A) :
a ∈ S.toSubgroup ↔ Multiplicative.toAdd a ∈ S :=
.rfl
/-- Subgroups of an additive group `Multiplicative A` are isomorphic to additive subgroups of `A`.
-/
abbrev Subgroup.toAddSubgroup' : Subgroup (Multiplicative A) ≃o AddSubgroup A :=
AddSubgroup.toSubgroup.symm
@[simp] lemma Subgroup.mem_toAddSubgroup' (S : Subgroup (Multiplicative A)) (a : A) :
a ∈ toAddSubgroup' S ↔ Multiplicative.ofAdd a ∈ S :=
.rfl
end mul_add
namespace Subgroup
variable (H K : Subgroup G)
/-- The subgroup `G` of the group `G`. -/
@[to_additive /-- The `AddSubgroup G` of the `AddGroup G`. -/]
instance : Top (Subgroup G) :=
⟨{ (⊤ : Submonoid G) with inv_mem' := fun _ => Set.mem_univ _ }⟩
/-- The top subgroup is isomorphic to the group.
This is the group version of `Submonoid.topEquiv`. -/
@[to_additive (attr := simps!)
/-- The top additive subgroup is isomorphic to the additive group.
This is the additive group version of `AddSubmonoid.topEquiv`. -/]
def topEquiv : (⊤ : Subgroup G) ≃* G :=
Submonoid.topEquiv
/-- The trivial subgroup `{1}` of a group `G`. -/
@[to_additive /-- The trivial `AddSubgroup` `{0}` of an `AddGroup` `G`. -/]
instance : Bot (Subgroup G) :=
⟨{ (⊥ : Submonoid G) with inv_mem' := by simp}⟩
@[to_additive]
instance : Inhabited (Subgroup G) :=
⟨⊥⟩
@[to_additive (attr := simp)]
theorem mem_bot {x : G} : x ∈ (⊥ : Subgroup G) ↔ x = 1 :=
Iff.rfl
@[to_additive (attr := simp)]
theorem mem_top (x : G) : x ∈ (⊤ : Subgroup G) :=
Set.mem_univ x
@[to_additive (attr := simp, norm_cast)]
theorem coe_top : ((⊤ : Subgroup G) : Set G) = Set.univ :=
rfl
@[to_additive (attr := simp, norm_cast)]
theorem coe_bot : ((⊥ : Subgroup G) : Set G) = {1} :=
rfl
@[to_additive]
instance : Unique (⊥ : Subgroup G) :=
⟨⟨1⟩, fun g => Subtype.ext g.2⟩
@[to_additive (attr := simp)]
theorem top_toSubmonoid : (⊤ : Subgroup G).toSubmonoid = ⊤ :=
rfl
@[to_additive (attr := simp)]
theorem bot_toSubmonoid : (⊥ : Subgroup G).toSubmonoid = ⊥ :=
rfl
@[to_additive]
theorem eq_bot_iff_forall : H = ⊥ ↔ ∀ x ∈ H, x = (1 : G) :=
toSubmonoid_injective.eq_iff.symm.trans <| Submonoid.eq_bot_iff_forall _
@[to_additive]
theorem eq_bot_of_subsingleton [Subsingleton H] : H = ⊥ := by
rw [Subgroup.eq_bot_iff_forall]
intro y hy
rw [← Subgroup.coe_mk H y hy, Subsingleton.elim (⟨y, hy⟩ : H) 1, Subgroup.coe_one]
@[to_additive (attr := simp, norm_cast)]
theorem coe_eq_univ {H : Subgroup G} : (H : Set G) = Set.univ ↔ H = ⊤ :=
(SetLike.ext'_iff.trans (by rfl)).symm
@[to_additive]
theorem coe_eq_singleton {H : Subgroup G} : (∃ g : G, (H : Set G) = {g}) ↔ H = ⊥ :=
⟨fun ⟨g, hg⟩ =>
haveI : Subsingleton (H : Set G) := by
rw [hg]
infer_instance
H.eq_bot_of_subsingleton,
fun h => ⟨1, SetLike.ext'_iff.mp h⟩⟩
@[to_additive]
theorem nontrivial_iff_exists_ne_one (H : Subgroup G) : Nontrivial H ↔ ∃ x ∈ H, x ≠ (1 : G) := by
rw [Subtype.nontrivial_iff_exists_ne (fun x => x ∈ H) (1 : H)]
simp
@[to_additive]
theorem exists_ne_one_of_nontrivial (H : Subgroup G) [Nontrivial H] :
∃ x ∈ H, x ≠ 1 := by
rwa [← Subgroup.nontrivial_iff_exists_ne_one]
@[to_additive]
theorem nontrivial_iff_ne_bot (H : Subgroup G) : Nontrivial H ↔ H ≠ ⊥ := by
rw [nontrivial_iff_exists_ne_one, ne_eq, eq_bot_iff_forall]
simp only [ne_eq, not_forall, exists_prop]
/-- A subgroup is either the trivial subgroup or nontrivial. -/
@[to_additive /-- A subgroup is either the trivial subgroup or nontrivial. -/]
theorem bot_or_nontrivial (H : Subgroup G) : H = ⊥ ∨ Nontrivial H := by
have := nontrivial_iff_ne_bot H
tauto
/-- A subgroup is either the trivial subgroup or contains a non-identity element. -/
@[to_additive /-- A subgroup is either the trivial subgroup or contains a nonzero element. -/]
theorem bot_or_exists_ne_one (H : Subgroup G) : H = ⊥ ∨ ∃ x ∈ H, x ≠ (1 : G) := by
convert H.bot_or_nontrivial
rw [nontrivial_iff_exists_ne_one]
@[to_additive]
lemma ne_bot_iff_exists_ne_one {H : Subgroup G} : H ≠ ⊥ ↔ ∃ a : ↥H, a ≠ 1 := by
rw [← nontrivial_iff_ne_bot, nontrivial_iff_exists_ne_one]
simp only [ne_eq, Subtype.exists, mk_eq_one, exists_prop]
/-- The inf of two subgroups is their intersection. -/
@[to_additive /-- The inf of two `AddSubgroup`s is their intersection. -/]
instance : Min (Subgroup G) :=
⟨fun H₁ H₂ =>
{ H₁.toSubmonoid ⊓ H₂.toSubmonoid with
inv_mem' := fun ⟨hx, hx'⟩ => ⟨H₁.inv_mem hx, H₂.inv_mem hx'⟩ }⟩
@[to_additive (attr := simp, norm_cast)]
theorem coe_inf (p p' : Subgroup G) : ((p ⊓ p' : Subgroup G) : Set G) = (p : Set G) ∩ p' :=
rfl
@[to_additive (attr := simp)]
theorem mem_inf {p p' : Subgroup G} {x : G} : x ∈ p ⊓ p' ↔ x ∈ p ∧ x ∈ p' :=
Iff.rfl
@[to_additive]
instance : InfSet (Subgroup G) :=
⟨fun s =>
{ (⨅ S ∈ s, Subgroup.toSubmonoid S).copy (⋂ S ∈ s, ↑S) (by simp) with
inv_mem' := fun {x} hx =>
Set.mem_biInter fun i h => i.inv_mem (by apply Set.mem_iInter₂.1 hx i h) }⟩
@[to_additive (attr := simp, norm_cast)]
theorem coe_sInf (H : Set (Subgroup G)) : ((sInf H : Subgroup G) : Set G) = ⋂ s ∈ H, ↑s :=
rfl
@[to_additive (attr := simp)]
theorem mem_sInf {S : Set (Subgroup G)} {x : G} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p :=
Set.mem_iInter₂
@[to_additive]
theorem mem_iInf {ι : Sort*} {S : ι → Subgroup G} {x : G} : (x ∈ ⨅ i, S i) ↔ ∀ i, x ∈ S i := by
simp only [iInf, mem_sInf, Set.forall_mem_range]
@[to_additive (attr := simp, norm_cast)]
theorem coe_iInf {ι : Sort*} {S : ι → Subgroup G} : (↑(⨅ i, S i) : Set G) = ⋂ i, S i := by
simp only [iInf, coe_sInf, Set.biInter_range]
/-- Subgroups of a group form a complete lattice. -/
@[to_additive /-- The `AddSubgroup`s of an `AddGroup` form a complete lattice. -/]
instance : CompleteLattice (Subgroup G) :=
{ completeLatticeOfInf (Subgroup G) fun _s =>
IsGLB.of_image SetLike.coe_subset_coe isGLB_biInf with
bot := ⊥
bot_le := fun S _x hx => (mem_bot.1 hx).symm ▸ S.one_mem
top := ⊤
le_top := fun _S x _hx => mem_top x
inf := (· ⊓ ·)
le_inf := fun _a _b _c ha hb _x hx => ⟨ha hx, hb hx⟩
inf_le_left := fun _a _b _x => And.left
inf_le_right := fun _a _b _x => And.right }
@[to_additive]
theorem mem_sup_left {S T : Subgroup G} : ∀ {x : G}, x ∈ S → x ∈ S ⊔ T :=
have : S ≤ S ⊔ T := le_sup_left; fun h ↦ this h
@[to_additive]
theorem mem_sup_right {S T : Subgroup G} : ∀ {x : G}, x ∈ T → x ∈ S ⊔ T :=
have : T ≤ S ⊔ T := le_sup_right; fun h ↦ this h
@[to_additive]
theorem mul_mem_sup {S T : Subgroup G} {x y : G} (hx : x ∈ S) (hy : y ∈ T) : x * y ∈ S ⊔ T :=
(S ⊔ T).mul_mem (mem_sup_left hx) (mem_sup_right hy)
@[to_additive]
theorem mem_iSup_of_mem {ι : Sort*} {S : ι → Subgroup G} (i : ι) :
∀ {x : G}, x ∈ S i → x ∈ iSup S :=
have : S i ≤ iSup S := le_iSup _ _; fun h ↦ this h
@[to_additive]
theorem mem_sSup_of_mem {S : Set (Subgroup G)} {s : Subgroup G} (hs : s ∈ S) :
∀ {x : G}, x ∈ s → x ∈ sSup S :=
have : s ≤ sSup S := le_sSup hs; fun h ↦ this h
@[to_additive (attr := simp)]
theorem subsingleton_iff : Subsingleton (Subgroup G) ↔ Subsingleton G :=
⟨fun _ =>
⟨fun x y =>
have : ∀ i : G, i = 1 := fun i =>
mem_bot.mp <| Subsingleton.elim (⊤ : Subgroup G) ⊥ ▸ mem_top i
(this x).trans (this y).symm⟩,
fun _ => ⟨fun x y => Subgroup.ext fun i => Subsingleton.elim 1 i ▸ by simp⟩⟩
@[to_additive (attr := simp)]
theorem nontrivial_iff : Nontrivial (Subgroup G) ↔ Nontrivial G :=
not_iff_not.mp
((not_nontrivial_iff_subsingleton.trans subsingleton_iff).trans
not_nontrivial_iff_subsingleton.symm)
@[to_additive]
instance [Subsingleton G] : Unique (Subgroup G) :=
⟨⟨⊥⟩, fun a => @Subsingleton.elim _ (subsingleton_iff.mpr ‹_›) a _⟩
@[to_additive]
instance [Nontrivial G] : Nontrivial (Subgroup G) :=
nontrivial_iff.mpr ‹_›
@[to_additive]
instance [Nontrivial G] : Nontrivial (⊤ : Subgroup G) := by
rw [nontrivial_iff_ne_bot]
exact top_ne_bot
@[to_additive]
theorem eq_top_iff' : H = ⊤ ↔ ∀ x : G, x ∈ H :=
eq_top_iff.trans ⟨fun h m => h <| mem_top m, fun h m _ => h m⟩
/-- The `Subgroup` generated by a set. -/
@[to_additive /-- The `AddSubgroup` generated by a set -/]
def closure (k : Set G) : Subgroup G :=
sInf { K | k ⊆ K }
variable {k : Set G}
@[to_additive]
theorem mem_closure {x : G} : x ∈ closure k ↔ ∀ K : Subgroup G, k ⊆ K → x ∈ K :=
mem_sInf
/-- The subgroup generated by a set includes the set. -/
@[to_additive (attr := simp, aesop safe 20 (rule_sets := [SetLike]))
/-- The `AddSubgroup` generated by a set includes the set. -/]
theorem subset_closure : k ⊆ closure k := fun _ hx => mem_closure.2 fun _ hK => hK hx
@[to_additive (attr := aesop 80% (rule_sets := [SetLike]))]
theorem mem_closure_of_mem {s : Set G} {x : G} (hx : x ∈ s) : x ∈ closure s := subset_closure hx
@[to_additive]
theorem notMem_of_notMem_closure {P : G} (hP : P ∉ closure k) : P ∉ k := fun h =>
hP (subset_closure h)
@[deprecated (since := "2025-05-23")]
alias _root_.AddSubgroup.not_mem_of_not_mem_closure := AddSubgroup.notMem_of_notMem_closure
@[to_additive existing, deprecated (since := "2025-05-23")]
alias not_mem_of_not_mem_closure := notMem_of_notMem_closure
open Set
/-- A subgroup `K` includes `closure k` if and only if it includes `k`. -/
@[to_additive (attr := simp)
/-- An additive subgroup `K` includes `closure k` if and only if it includes `k` -/]
theorem closure_le : closure k ≤ K ↔ k ⊆ K :=
⟨Subset.trans subset_closure, fun h => sInf_le h⟩
@[to_additive]
theorem closure_eq_of_le (h₁ : k ⊆ K) (h₂ : K ≤ closure k) : closure k = K :=
le_antisymm ((closure_le <| K).2 h₁) h₂
/-- An induction principle for closure membership. If `p` holds for `1` and all elements of `k`, and
is preserved under multiplication and inverse, then `p` holds for all elements of the closure
of `k`.
See also `Subgroup.closure_induction_left` and `Subgroup.closure_induction_right` for versions that
only require showing `p` is preserved by multiplication by elements in `k`. -/
@[to_additive (attr := elab_as_elim)
/-- An induction principle for additive closure membership. If `p`
holds for `0` and all elements of `k`, and is preserved under addition and inverses, then `p`
holds for all elements of the additive closure of `k`.
See also `AddSubgroup.closure_induction_left` and `AddSubgroup.closure_induction_left` for
versions that only require showing `p` is preserved by addition by elements in `k`. -/]
theorem closure_induction {p : (g : G) → g ∈ closure k → Prop}
(mem : ∀ x (hx : x ∈ k), p x (subset_closure hx)) (one : p 1 (one_mem _))
(mul : ∀ x y hx hy, p x hx → p y hy → p (x * y) (mul_mem hx hy))
(inv : ∀ x hx, p x hx → p x⁻¹ (inv_mem hx)) {x} (hx : x ∈ closure k) : p x hx :=
let K : Subgroup G :=
{ carrier := { x | ∃ hx, p x hx }
mul_mem' := fun ⟨_, ha⟩ ⟨_, hb⟩ ↦ ⟨_, mul _ _ _ _ ha hb⟩
one_mem' := ⟨_, one⟩
inv_mem' := fun ⟨_, hb⟩ ↦ ⟨_, inv _ _ hb⟩ }
closure_le (K := K) |>.mpr (fun y hy ↦ ⟨subset_closure hy, mem y hy⟩) hx |>.elim fun _ ↦ id
/-- An induction principle for closure membership for predicates with two arguments. -/
@[to_additive (attr := elab_as_elim)
/-- An induction principle for additive closure membership, for
predicates with two arguments. -/]
theorem closure_induction₂ {p : (x y : G) → x ∈ closure k → y ∈ closure k → Prop}
(mem : ∀ (x) (y) (hx : x ∈ k) (hy : y ∈ k), p x y (subset_closure hx) (subset_closure hy))
(one_left : ∀ x hx, p 1 x (one_mem _) hx) (one_right : ∀ x hx, p x 1 hx (one_mem _))
(mul_left : ∀ x y z hx hy hz, p x z hx hz → p y z hy hz → p (x * y) z (mul_mem hx hy) hz)
(mul_right : ∀ y z x hy hz hx, p x y hx hy → p x z hx hz → p x (y * z) hx (mul_mem hy hz))
(inv_left : ∀ x y hx hy, p x y hx hy → p x⁻¹ y (inv_mem hx) hy)
(inv_right : ∀ x y hx hy, p x y hx hy → p x y⁻¹ hx (inv_mem hy))
{x y : G} (hx : x ∈ closure k) (hy : y ∈ closure k) : p x y hx hy := by
induction hy using closure_induction with
| mem z hz => induction hx using closure_induction with
| mem _ h => exact mem _ _ h hz
| one => exact one_left _ (subset_closure hz)
| mul _ _ _ _ h₁ h₂ => exact mul_left _ _ _ _ _ _ h₁ h₂
| inv _ _ h => exact inv_left _ _ _ _ h
| one => exact one_right x hx
| mul _ _ _ _ h₁ h₂ => exact mul_right _ _ _ _ _ hx h₁ h₂
| inv _ _ h => exact inv_right _ _ _ _ h
@[to_additive (attr := simp)]
theorem closure_closure_coe_preimage {k : Set G} : closure (((↑) : closure k → G) ⁻¹' k) = ⊤ :=
eq_top_iff.2 fun x _ ↦ Subtype.recOn x fun _ hx' ↦
closure_induction (fun _ h ↦ subset_closure h) (one_mem _) (fun _ _ _ _ ↦ mul_mem)
(fun _ _ ↦ inv_mem) hx'
variable (G) in
/-- `closure` forms a Galois insertion with the coercion to set. -/
@[to_additive /-- `closure` forms a Galois insertion with the coercion to set. -/]
protected def gi : GaloisInsertion (@closure G _) (↑) where
choice s _ := closure s
gc s t := @closure_le _ _ t s
le_l_u _s := subset_closure
choice_eq _s _h := rfl
/-- Subgroup closure of a set is monotone in its argument: if `h ⊆ k`,
then `closure h ≤ closure k`. -/
@[to_additive (attr := gcongr)
/-- Additive subgroup closure of a set is monotone in its argument: if `h ⊆ k`,
then `closure h ≤ closure k` -/]
theorem closure_mono ⦃h k : Set G⦄ (h' : h ⊆ k) : closure h ≤ closure k :=
(Subgroup.gi G).gc.monotone_l h'
/-- Closure of a subgroup `K` equals `K`. -/
@[to_additive (attr := simp) /-- Additive closure of an additive subgroup `K` equals `K` -/]
theorem closure_eq : closure (K : Set G) = K :=
(Subgroup.gi G).l_u_eq K
@[to_additive (attr := simp)]
theorem closure_empty : closure (∅ : Set G) = ⊥ :=
(Subgroup.gi G).gc.l_bot
@[to_additive (attr := simp)]
theorem closure_univ : closure (univ : Set G) = ⊤ :=
@coe_top G _ ▸ closure_eq ⊤
@[to_additive]
theorem closure_union (s t : Set G) : closure (s ∪ t) = closure s ⊔ closure t :=
(Subgroup.gi G).gc.l_sup
@[to_additive]
theorem sup_eq_closure (H H' : Subgroup G) : H ⊔ H' = closure ((H : Set G) ∪ (H' : Set G)) := by
simp_rw [closure_union, closure_eq]
@[to_additive]
theorem closure_iUnion {ι} (s : ι → Set G) : closure (⋃ i, s i) = ⨆ i, closure (s i) :=
(Subgroup.gi G).gc.l_iSup
@[to_additive (attr := simp)]
theorem closure_eq_bot_iff : closure k = ⊥ ↔ k ⊆ {1} := le_bot_iff.symm.trans <| closure_le _
@[to_additive]
theorem iSup_eq_closure {ι : Sort*} (p : ι → Subgroup G) :
⨆ i, p i = closure (⋃ i, (p i : Set G)) := by simp_rw [closure_iUnion, closure_eq]
/-- The subgroup generated by an element of a group equals the set of integer number powers of
the element. -/
@[to_additive
/-- The `AddSubgroup` generated by an element of an `AddGroup` equals the set of
natural number multiples of the element. -/]
theorem mem_closure_singleton {x y : G} : y ∈ closure ({x} : Set G) ↔ ∃ n : ℤ, x ^ n = y := by
refine
⟨fun hy => closure_induction ?_ ?_ ?_ ?_ hy, fun ⟨n, hn⟩ =>
hn ▸ zpow_mem (subset_closure <| mem_singleton x) n⟩
· intro y hy
rw [eq_of_mem_singleton hy]
exact ⟨1, zpow_one x⟩
· exact ⟨0, zpow_zero x⟩
· rintro _ _ _ _ ⟨n, rfl⟩ ⟨m, rfl⟩
exact ⟨n + m, zpow_add x n m⟩
rintro _ _ ⟨n, rfl⟩
exact ⟨-n, zpow_neg x n⟩
@[to_additive]
theorem closure_singleton_one : closure ({1} : Set G) = ⊥ := by
simp [eq_bot_iff_forall, mem_closure_singleton]
@[to_additive (attr := simp)]
lemma mem_closure_singleton_self (x : G) : x ∈ closure ({x} : Set G) := by
simpa [-subset_closure] using subset_closure (k := {x})
@[to_additive]
theorem le_closure_toSubmonoid (S : Set G) : Submonoid.closure S ≤ (closure S).toSubmonoid :=
Submonoid.closure_le.2 subset_closure
@[to_additive]
theorem closure_eq_top_of_mclosure_eq_top {S : Set G} (h : Submonoid.closure S = ⊤) :
closure S = ⊤ :=
(eq_top_iff' _).2 fun _ => le_closure_toSubmonoid _ <| h.symm ▸ trivial
@[to_additive (attr := simp)]
theorem closure_insert_one (s : Set G) : closure (insert 1 s) = closure s := by
rw [insert_eq, closure_union]
simp [one_mem]
@[to_additive]
theorem closure_union_one (s : Set G) : closure (s ∪ {1}) = closure s := by
rw [union_singleton, closure_insert_one]
@[to_additive (attr := simp)]
theorem closure_diff_one (s : Set G) : closure (s \ {1}) = closure s := by
rw [← closure_union_one (s \ {1}), diff_union_self, closure_union_one]
theorem toAddSubgroup_closure (S : Set G) :
(Subgroup.closure S).toAddSubgroup = AddSubgroup.closure (Additive.toMul ⁻¹' S) :=
le_antisymm (toAddSubgroup.le_symm_apply.mp <|
(closure_le _).mpr (AddSubgroup.subset_closure (G := Additive G)))
((AddSubgroup.closure_le _).mpr (subset_closure (G := G)))
theorem _root_.AddSubgroup.toSubgroup_closure {A : Type*} [AddGroup A] (S : Set A) :
(AddSubgroup.closure S).toSubgroup = Subgroup.closure (Multiplicative.toAdd ⁻¹' S) :=
Subgroup.toAddSubgroup.injective (Subgroup.toAddSubgroup_closure _).symm
theorem toAddSubgroup'_closure {A : Type*} [AddGroup A] (S : Set (Multiplicative A)) :
(closure S).toAddSubgroup' = AddSubgroup.closure (Multiplicative.ofAdd ⁻¹' S) :=
le_antisymm (toAddSubgroup'.to_galoisConnection.l_le <|
(closure_le _).mpr <| AddSubgroup.subset_closure (G := A))
((AddSubgroup.closure_le _).mpr <| Subgroup.subset_closure (G := Multiplicative A))
theorem _root_.AddSubgroup.toSubgroup'_closure (S : Set (Additive G)) :
(AddSubgroup.closure S).toSubgroup' = Subgroup.closure (Additive.ofMul ⁻¹' S) :=
congr_arg AddSubgroup.toSubgroup' (toAddSubgroup'_closure _).symm
@[to_additive]
theorem mem_biSup_of_directedOn {ι} {p : ι → Prop} {K : ι → Subgroup G} {i : ι} (hp : p i)
(hK : DirectedOn ((· ≤ ·) on K) {i | p i})
{x : G} : x ∈ (⨆ i, ⨆ (_h : p i), K i) ↔ ∃ i, p i ∧ x ∈ K i := by
-- Could use the `Submonoid` version, but we limit the imports here
refine ⟨?_, fun ⟨i, hi', hi⟩ ↦ ?_⟩
· suffices x ∈ closure (⋃ i, ⋃ (_ : p i), (K i : Set G)) → ∃ i, p i ∧ x ∈ K i by
simpa only [closure_iUnion, closure_eq (K _)] using this
refine fun hx ↦ closure_induction (fun _ ↦ ?_) ?_ ?_ ?_ hx
· simp
· exact ⟨i, hp, (K i).one_mem⟩
· rintro x y _ _ ⟨i, hip, hi⟩ ⟨j, hjp, hj⟩
rcases hK i hip j hjp with ⟨k, hk, hki, hkj⟩
exact ⟨k, hk, mul_mem (hki hi) (hkj hj)⟩
· rintro _ _ ⟨i, hi', hi⟩
exact ⟨i, hi', inv_mem hi⟩
· apply le_iSup (fun i ↦ ⨆ (_ : p i), K i) i
simp [hi, hi']
@[to_additive]
theorem mem_iSup_of_directed {ι} [hι : Nonempty ι] {K : ι → Subgroup G} (hK : Directed (· ≤ ·) K)
{x : G} : x ∈ (iSup K : Subgroup G) ↔ ∃ i, x ∈ K i := by
have : iSup K = ⨆ i : PLift ι, ⨆ (_ : True), K i.down := by simp [iSup_plift_down]
rw [this, mem_biSup_of_directedOn trivial]
· simp
· simp only [setOf_true]
rw [directedOn_onFun_iff, Set.image_univ, ← directedOn_range]
-- `Directed.mono_comp` and much of the Set API requires `Type u` instead of `Sort u`
intro i
simp only [PLift.exists]
intro j
refine (hK i.down j.down).imp ?_
simp
· exact PLift.up hι.some
@[to_additive (attr := simp)]
theorem mem_iSup_prop {p : Prop} {K : p → Subgroup G} {x : G} :
x ∈ ⨆ (h : p), K h ↔ x = 1 ∨ ∃ (h : p), x ∈ K h := by
by_cases h : p <;>
simp +contextual [h]
@[to_additive]
theorem coe_iSup_of_directed {ι} [Nonempty ι] {S : ι → Subgroup G} (hS : Directed (· ≤ ·) S) :
((⨆ i, S i : Subgroup G) : Set G) = ⋃ i, S i :=
Set.ext fun x ↦ by simp [mem_iSup_of_directed hS]
@[to_additive]
theorem mem_sSup_of_directedOn {K : Set (Subgroup G)} (Kne : K.Nonempty) (hK : DirectedOn (· ≤ ·) K)
{x : G} : x ∈ sSup K ↔ ∃ s ∈ K, x ∈ s := by
haveI : Nonempty K := Kne.to_subtype
simp only [sSup_eq_iSup', mem_iSup_of_directed hK.directed_val, SetCoe.exists, exists_prop]
variable {C : Type*} [CommGroup C] {s t : Subgroup C} {x : C}
@[to_additive]
theorem mem_sup : x ∈ s ⊔ t ↔ ∃ y ∈ s, ∃ z ∈ t, y * z = x :=
⟨fun h => by
rw [sup_eq_closure] at h
refine Subgroup.closure_induction ?_ ?_ ?_ ?_ h
· rintro y (h | h)
· exact ⟨y, h, 1, t.one_mem, by simp⟩
· exact ⟨1, s.one_mem, y, h, by simp⟩
· exact ⟨1, s.one_mem, 1, ⟨t.one_mem, mul_one 1⟩⟩
· rintro _ _ _ _ ⟨y₁, hy₁, z₁, hz₁, rfl⟩ ⟨y₂, hy₂, z₂, hz₂, rfl⟩
exact ⟨_, mul_mem hy₁ hy₂, _, mul_mem hz₁ hz₂, by simp [mul_assoc, mul_left_comm]⟩
· rintro _ _ ⟨y, hy, z, hz, rfl⟩
exact ⟨_, inv_mem hy, _, inv_mem hz, mul_comm z y ▸ (mul_inv_rev z y).symm⟩, by
rintro ⟨y, hy, z, hz, rfl⟩; exact mul_mem_sup hy hz⟩
@[to_additive]
theorem mem_sup' : x ∈ s ⊔ t ↔ ∃ (y : s) (z : t), (y : C) * z = x :=
mem_sup.trans <| by simp only [SetLike.exists, exists_prop]
@[to_additive]
theorem mem_sup_of_normal_right {s t : Subgroup G} [ht : t.Normal] {x : G} :
x ∈ s ⊔ t ↔ ∃ y ∈ s, ∃ z ∈ t, y * z = x := by
constructor
· intro hx; rw [sup_eq_closure] at hx
refine closure_induction ?_ ?_ ?_ ?_ hx
· rintro x (hx | hx)
· exact ⟨x, hx, 1, t.one_mem, by simp⟩
· exact ⟨1, s.one_mem, x, hx, by simp⟩
· exact ⟨1, s.one_mem, 1, t.one_mem, by simp⟩
· rintro _ _ _ _ ⟨y₁, hy₁, z₁, hz₁, rfl⟩ ⟨y₂, hy₂, z₂, hz₂, rfl⟩
exact ⟨y₁ * y₂, s.mul_mem hy₁ hy₂,
(y₂⁻¹ * z₁ * y₂) * z₂, t.mul_mem (ht.conj_mem' z₁ hz₁ y₂) hz₂, by simp [mul_assoc]⟩
· rintro _ _ ⟨y, hy, z, hz, rfl⟩
exact ⟨y⁻¹, s.inv_mem hy,
y * z⁻¹ * y⁻¹, ht.conj_mem z⁻¹ (t.inv_mem hz) y, by simp [mul_assoc]⟩
· rintro ⟨y, hy, z, hz, rfl⟩; exact mul_mem_sup hy hz
@[to_additive]
theorem mem_sup_of_normal_left {s t : Subgroup G} [hs : s.Normal] {x : G} :
x ∈ s ⊔ t ↔ ∃ y ∈ s, ∃ z ∈ t, y * z = x := by
have h := (sup_comm t s) ▸ mem_sup_of_normal_right (s := t) (t := s) (x := x)
exact h.trans
⟨fun ⟨y, hy, z, hz, hp⟩ ↦ ⟨y * z * y⁻¹, hs.conj_mem z hz y, y, hy, by simp [hp]⟩,
fun ⟨y, hy, z, hz, hp⟩ ↦ ⟨z, hz, z⁻¹ * y * z, hs.conj_mem' y hy z, by simp [mul_assoc, hp]⟩⟩
@[to_additive]
theorem mem_closure_pair {x y z : C} :
z ∈ closure ({x, y} : Set C) ↔ ∃ m n : ℤ, x ^ m * y ^ n = z := by
rw [← Set.singleton_union, Subgroup.closure_union, mem_sup]
simp_rw [mem_closure_singleton, exists_exists_eq_and]
@[to_additive]
theorem disjoint_def {H₁ H₂ : Subgroup G} : Disjoint H₁ H₂ ↔ ∀ {x : G}, x ∈ H₁ → x ∈ H₂ → x = 1 :=
disjoint_iff_inf_le.trans <| by simp only [SetLike.le_def, mem_inf, mem_bot, and_imp]
@[to_additive]
theorem disjoint_def' {H₁ H₂ : Subgroup G} :
Disjoint H₁ H₂ ↔ ∀ {x y : G}, x ∈ H₁ → y ∈ H₂ → x = y → x = 1 :=
disjoint_def.trans ⟨fun h _x _y hx hy hxy ↦ h hx <| hxy.symm ▸ hy, fun h _x hx hx' ↦ h hx hx' rfl⟩
@[to_additive]
theorem disjoint_iff_mul_eq_one {H₁ H₂ : Subgroup G} :
Disjoint H₁ H₂ ↔ ∀ {x y : G}, x ∈ H₁ → y ∈ H₂ → x * y = 1 → x = 1 ∧ y = 1 :=
disjoint_def'.trans
⟨fun h x y hx hy hxy =>
let hx1 : x = 1 := h hx (H₂.inv_mem hy) (eq_inv_iff_mul_eq_one.mpr hxy)
⟨hx1, by simpa [hx1] using hxy⟩,
fun h _ _ hx hy hxy => (h hx (H₂.inv_mem hy) (mul_inv_eq_one.mpr hxy)).1⟩
@[to_additive]
theorem mul_injective_of_disjoint {H₁ H₂ : Subgroup G} (h : Disjoint H₁ H₂) :
Function.Injective (fun g => g.1 * g.2 : H₁ × H₂ → G) := by
intro x y hxy
rw [← inv_mul_eq_iff_eq_mul, ← mul_assoc, ← mul_inv_eq_one, mul_assoc] at hxy
replace hxy := disjoint_iff_mul_eq_one.mp h (y.1⁻¹ * x.1).prop (x.2 * y.2⁻¹).prop hxy
rwa [coe_mul, coe_mul, coe_inv, coe_inv, inv_mul_eq_one, mul_inv_eq_one, ← Subtype.ext_iff, ←
Subtype.ext_iff, eq_comm, ← Prod.ext_iff] at hxy
end Subgroup |
.lake/packages/mathlib/Mathlib/Algebra/Group/Subgroup/MulOppositeLemmas.lean | import Mathlib.Algebra.Group.Subgroup.Basic
import Mathlib.Algebra.Group.Subgroup.MulOpposite
import Mathlib.Algebra.Group.Submonoid.MulOpposite
import Mathlib.Logic.Encodable.Basic
/-!
# Mul-opposite subgroups
This file contains a somewhat arbitrary assortment of results on the opposite subgroup `H.op`
that rely on further theory to define. As such it is a somewhat arbitrary assortment of results,
which might be organized and split up further.
## Tags
subgroup, subgroups
-/
variable {ι : Sort*} {G : Type*} [Group G]
namespace Subgroup
/- We redeclare this instance to get keys
`SMul (@Subtype (MulOpposite _) (@Membership.mem (MulOpposite _)
(Subgroup (MulOpposite _) _) _ (@Subgroup.op _ _ _))) _`
compared to the keys for `Submonoid.smul`
`SMul (@Subtype _ (@Membership.mem _ (Submonoid _ _) _ _)) _` -/
@[to_additive] instance instSMul (H : Subgroup G) : SMul H.op G := Submonoid.smul ..
/-! ### Lattice results -/
@[to_additive (attr := simp)]
theorem op_bot : (⊥ : Subgroup G).op = ⊥ := opEquiv.map_bot
@[to_additive (attr := simp)]
theorem op_eq_bot {S : Subgroup G} : S.op = ⊥ ↔ S = ⊥ := op_injective.eq_iff' op_bot
@[to_additive (attr := simp)]
theorem unop_bot : (⊥ : Subgroup Gᵐᵒᵖ).unop = ⊥ := opEquiv.symm.map_bot
@[to_additive (attr := simp)]
theorem unop_eq_bot {S : Subgroup Gᵐᵒᵖ} : S.unop = ⊥ ↔ S = ⊥ := unop_injective.eq_iff' unop_bot
@[to_additive (attr := simp)]
theorem op_top : (⊤ : Subgroup G).op = ⊤ := rfl
@[to_additive (attr := simp)]
theorem op_eq_top {S : Subgroup G} : S.op = ⊤ ↔ S = ⊤ := op_injective.eq_iff' op_top
@[to_additive (attr := simp)]
theorem unop_top : (⊤ : Subgroup Gᵐᵒᵖ).unop = ⊤ := rfl
@[to_additive (attr := simp)]
theorem unop_eq_top {S : Subgroup Gᵐᵒᵖ} : S.unop = ⊤ ↔ S = ⊤ := unop_injective.eq_iff' unop_top
@[to_additive]
theorem op_sup (S₁ S₂ : Subgroup G) : (S₁ ⊔ S₂).op = S₁.op ⊔ S₂.op :=
opEquiv.map_sup _ _
@[to_additive]
theorem unop_sup (S₁ S₂ : Subgroup Gᵐᵒᵖ) : (S₁ ⊔ S₂).unop = S₁.unop ⊔ S₂.unop :=
opEquiv.symm.map_sup _ _
@[to_additive]
theorem op_inf (S₁ S₂ : Subgroup G) : (S₁ ⊓ S₂).op = S₁.op ⊓ S₂.op := rfl
@[to_additive]
theorem unop_inf (S₁ S₂ : Subgroup Gᵐᵒᵖ) : (S₁ ⊓ S₂).unop = S₁.unop ⊓ S₂.unop := rfl
@[to_additive]
theorem op_sSup (S : Set (Subgroup G)) : (sSup S).op = sSup (.unop ⁻¹' S) :=
opEquiv.map_sSup_eq_sSup_symm_preimage _
@[to_additive]
theorem unop_sSup (S : Set (Subgroup Gᵐᵒᵖ)) : (sSup S).unop = sSup (.op ⁻¹' S) :=
opEquiv.symm.map_sSup_eq_sSup_symm_preimage _
@[to_additive]
theorem op_sInf (S : Set (Subgroup G)) : (sInf S).op = sInf (.unop ⁻¹' S) :=
opEquiv.map_sInf_eq_sInf_symm_preimage _
@[to_additive]
theorem unop_sInf (S : Set (Subgroup Gᵐᵒᵖ)) : (sInf S).unop = sInf (.op ⁻¹' S) :=
opEquiv.symm.map_sInf_eq_sInf_symm_preimage _
@[to_additive]
theorem op_iSup (S : ι → Subgroup G) : (iSup S).op = ⨆ i, (S i).op := opEquiv.map_iSup _
@[to_additive]
theorem unop_iSup (S : ι → Subgroup Gᵐᵒᵖ) : (iSup S).unop = ⨆ i, (S i).unop :=
opEquiv.symm.map_iSup _
@[to_additive]
theorem op_iInf (S : ι → Subgroup G) : (iInf S).op = ⨅ i, (S i).op := opEquiv.map_iInf _
@[to_additive]
theorem unop_iInf (S : ι → Subgroup Gᵐᵒᵖ) : (iInf S).unop = ⨅ i, (S i).unop :=
opEquiv.symm.map_iInf _
@[to_additive]
theorem op_closure (s : Set G) : (closure s).op = closure (MulOpposite.unop ⁻¹' s) := by
simp_rw [closure, op_sInf, Set.preimage_setOf_eq, Subgroup.coe_unop]
congr with a
exact MulOpposite.unop_surjective.forall
@[to_additive]
theorem unop_closure (s : Set Gᵐᵒᵖ) : (closure s).unop = closure (MulOpposite.op ⁻¹' s) := by
rw [← op_inj, op_unop, op_closure]
simp_rw [Set.preimage_preimage, MulOpposite.op_unop, Set.preimage_id']
@[to_additive]
instance (H : Subgroup G) [Encodable H] : Encodable H.op :=
Encodable.ofEquiv H H.equivOp.symm
@[to_additive]
instance (H : Subgroup G) [Countable H] : Countable H.op :=
Countable.of_equiv H H.equivOp
@[to_additive]
theorem smul_opposite_mul {H : Subgroup G} (x g : G) (h : H.op) :
h • (g * x) = g * h • x :=
mul_assoc _ _ _
@[to_additive (attr := simp)]
theorem normal_op {H : Subgroup G} : H.op.Normal ↔ H.Normal := by
simp only [← normalizer_eq_top_iff, ← op_normalizer, op_eq_top]
@[to_additive] alias ⟨Normal.of_op, Normal.op⟩ := normal_op
@[to_additive]
instance op.instNormal {H : Subgroup G} [H.Normal] : H.op.Normal := .op ‹_›
@[to_additive (attr := simp)]
theorem normal_unop {H : Subgroup Gᵐᵒᵖ} : H.unop.Normal ↔ H.Normal := by
rw [← normal_op, op_unop]
@[to_additive] alias ⟨Normal.of_unop, Normal.unop⟩ := normal_unop
@[to_additive]
instance unop.instNormal {H : Subgroup Gᵐᵒᵖ} [H.Normal] : H.unop.Normal := .unop ‹_›
end Subgroup |
.lake/packages/mathlib/Mathlib/Algebra/Group/Subgroup/ZPowers/Lemmas.lean | import Mathlib.Algebra.Group.Subgroup.ZPowers.Basic
import Mathlib.Data.Countable.Basic
import Mathlib.Data.Int.Cast.Lemmas
import Mathlib.GroupTheory.Subgroup.Centralizer
/-!
# Subgroups generated by an element
## Tags
subgroup, subgroups
-/
variable {G : Type*} [Group G]
variable {A : Type*} [AddGroup A]
variable {N : Type*} [Group N]
namespace Subgroup
theorem range_zpowersHom (g : G) : (zpowersHom G g).range = zpowers g := rfl
@[to_additive]
instance (a : G) : Countable (zpowers a) := Set.rangeFactorization_surjective.countable
end Subgroup
namespace AddSubgroup
@[simp]
theorem range_zmultiplesHom (a : A) : (zmultiplesHom A a).range = zmultiples a :=
rfl
section Ring
variable {R : Type*} [Ring R] (r : R) (k : ℤ)
@[simp]
theorem intCast_mul_mem_zmultiples : ↑(k : ℤ) * r ∈ zmultiples r := by
simpa only [← zsmul_eq_mul] using zsmul_mem_zmultiples r k
@[simp]
theorem intCast_mem_zmultiples_one : ↑(k : ℤ) ∈ zmultiples (1 : R) :=
mem_zmultiples_iff.mp ⟨k, by simp⟩
end Ring
end AddSubgroup
@[simp] lemma Int.range_castAddHom {A : Type*} [AddGroupWithOne A] :
(Int.castAddHom A).range = AddSubgroup.zmultiples 1 := by
ext a
simp_rw [AddMonoidHom.mem_range, Int.coe_castAddHom, AddSubgroup.mem_zmultiples_iff, zsmul_one]
namespace Subgroup
variable {s : Set G} {g : G}
@[to_additive]
theorem centralizer_closure (S : Set G) :
centralizer (closure S : Set G) = ⨅ g ∈ S, centralizer (zpowers g : Set G) :=
le_antisymm
(le_iInf fun _ => le_iInf fun hg => centralizer_le <| zpowers_le.2 <| subset_closure hg) <|
le_centralizer_iff.1 <|
(closure_le _).2 fun g =>
SetLike.mem_coe.2 ∘ zpowers_le.1 ∘ le_centralizer_iff.1 ∘ iInf_le_of_le g ∘ iInf_le _
@[to_additive]
theorem center_eq_iInf (S : Set G) (hS : closure S = ⊤) :
center G = ⨅ g ∈ S, centralizer (zpowers g) := by
rw [← centralizer_univ, ← coe_top, ← hS, centralizer_closure]
@[to_additive]
theorem center_eq_infi' (S : Set G) (hS : closure S = ⊤) :
center G = ⨅ g : S, centralizer (zpowers (g : G)) := by
rw [center_eq_iInf S hS, ← iInf_subtype'']
end Subgroup |
.lake/packages/mathlib/Mathlib/Algebra/Group/Subgroup/ZPowers/Basic.lean | import Mathlib.Algebra.Divisibility.Basic
import Mathlib.Algebra.Group.Subgroup.Map
import Mathlib.Algebra.Group.Int.Defs
/-!
# Subgroups generated by an element
## Tags
subgroup, subgroups
-/
variable {G : Type*} [Group G]
variable {A : Type*} [AddGroup A]
variable {N : Type*} [Group N]
namespace Subgroup
/-- The subgroup generated by an element. -/
@[to_additive /-- The additive subgroup generated by an element. -/]
def zpowers (g : G) : Subgroup G where
carrier := Set.range (g ^ · : ℤ → G)
one_mem' := ⟨0, zpow_zero g⟩
mul_mem' := by rintro _ _ ⟨a, rfl⟩ ⟨b, rfl⟩; exact ⟨a + b, zpow_add ..⟩
inv_mem' := by rintro _ ⟨a, rfl⟩; exact ⟨-a, zpow_neg ..⟩
@[to_additive (attr := simp)]
theorem mem_zpowers (g : G) : g ∈ zpowers g :=
⟨1, zpow_one _⟩
@[to_additive (attr := norm_cast)] -- TODO: simp?
theorem coe_zpowers (g : G) : ↑(zpowers g) = Set.range (g ^ · : ℤ → G) :=
rfl
@[to_additive] -- TODO: delete?
noncomputable instance decidableMemZPowers {a : G} : DecidablePred (· ∈ Subgroup.zpowers a) :=
Classical.decPred _
@[to_additive]
theorem zpowers_eq_closure (g : G) : zpowers g = closure {g} := by
ext
exact mem_closure_singleton.symm
@[to_additive]
theorem mem_zpowers_iff {g h : G} : h ∈ zpowers g ↔ ∃ k : ℤ, g ^ k = h :=
Iff.rfl
@[to_additive (attr := simp)]
theorem zpow_mem_zpowers (g : G) (k : ℤ) : g ^ k ∈ zpowers g :=
mem_zpowers_iff.mpr ⟨k, rfl⟩
@[to_additive (attr := simp)]
theorem npow_mem_zpowers (g : G) (k : ℕ) : g ^ k ∈ zpowers g :=
zpow_natCast g k ▸ zpow_mem_zpowers g k
-- increasing simp priority. Better lemma than `Subtype.exists`
@[to_additive (attr := simp 1100)]
theorem forall_zpowers {x : G} {p : zpowers x → Prop} : (∀ g, p g) ↔ ∀ m : ℤ, p ⟨x ^ m, m, rfl⟩ :=
Set.forall_subtype_range_iff
-- increasing simp priority. Better lemma than `Subtype.exists`
@[to_additive (attr := simp 1100)]
theorem exists_zpowers {x : G} {p : zpowers x → Prop} : (∃ g, p g) ↔ ∃ m : ℤ, p ⟨x ^ m, m, rfl⟩ :=
Set.exists_subtype_range_iff
@[to_additive]
theorem forall_mem_zpowers {x : G} {p : G → Prop} : (∀ g ∈ zpowers x, p g) ↔ ∀ m : ℤ, p (x ^ m) :=
Set.forall_mem_range
@[to_additive]
theorem exists_mem_zpowers {x : G} {p : G → Prop} : (∃ g ∈ zpowers x, p g) ↔ ∃ m : ℤ, p (x ^ m) :=
Set.exists_range_iff
end Subgroup
@[to_additive (attr := simp)]
theorem MonoidHom.map_zpowers (f : G →* N) (x : G) :
(Subgroup.zpowers x).map f = Subgroup.zpowers (f x) := by
rw [Subgroup.zpowers_eq_closure, Subgroup.zpowers_eq_closure, f.map_closure, Set.image_singleton]
theorem Int.mem_zmultiples_iff {a b : ℤ} : b ∈ AddSubgroup.zmultiples a ↔ a ∣ b :=
exists_congr fun k => by rw [mul_comm, eq_comm, ← smul_eq_mul]
@[simp]
lemma Int.zmultiples_one : AddSubgroup.zmultiples (1 : ℤ) = ⊤ := by
ext z
simp [Int.mem_zmultiples_iff]
theorem ofMul_image_zpowers_eq_zmultiples_ofMul {x : G} :
Additive.ofMul '' (Subgroup.zpowers x : Set G) = AddSubgroup.zmultiples (Additive.ofMul x) := by
ext
exact Set.mem_image_iff_of_inverse (congrFun rfl) (congrFun rfl)
theorem ofAdd_image_zmultiples_eq_zpowers_ofAdd {x : A} :
Multiplicative.ofAdd '' (AddSubgroup.zmultiples x : Set A) =
Subgroup.zpowers (Multiplicative.ofAdd x) := by
symm
rw [Equiv.eq_image_iff_symm_image_eq]
exact ofMul_image_zpowers_eq_zmultiples_ofMul
namespace Subgroup
variable {s : Set G} {g : G}
@[to_additive]
instance zpowers_isMulCommutative (g : G) : IsMulCommutative (zpowers g) :=
⟨⟨fun ⟨_, _, h₁⟩ ⟨_, _, h₂⟩ => by
rw [Subtype.ext_iff, coe_mul, coe_mul, Subtype.coe_mk, Subtype.coe_mk, ← h₁, ← h₂,
zpow_mul_comm]⟩⟩
@[to_additive (attr := simp)]
theorem zpowers_le {g : G} {H : Subgroup G} : zpowers g ≤ H ↔ g ∈ H := by
rw [zpowers_eq_closure, closure_le, Set.singleton_subset_iff, SetLike.mem_coe]
alias ⟨_, zpowers_le_of_mem⟩ := zpowers_le
alias ⟨_, _root_.AddSubgroup.zmultiples_le_of_mem⟩ := AddSubgroup.zmultiples_le
attribute [to_additive existing] zpowers_le_of_mem
@[to_additive (attr := simp)]
theorem zpowers_eq_bot {g : G} : zpowers g = ⊥ ↔ g = 1 := by rw [eq_bot_iff, zpowers_le, mem_bot]
@[to_additive]
theorem zpowers_ne_bot : zpowers g ≠ ⊥ ↔ g ≠ 1 :=
zpowers_eq_bot.not
@[to_additive (attr := simp)]
theorem zpowers_one_eq_bot : Subgroup.zpowers (1 : G) = ⊥ :=
Subgroup.zpowers_eq_bot.mpr rfl
@[to_additive (attr := simp)]
theorem zpowers_inv : zpowers g⁻¹ = zpowers g :=
eq_of_forall_ge_iff fun _ ↦ by simp only [zpowers_le, inv_mem_iff]
end Subgroup
theorem Int.zmultiples_natAbs (a : ℤ) :
AddSubgroup.zmultiples (a.natAbs : ℤ) = AddSubgroup.zmultiples a := by
simp [le_antisymm_iff, Int.mem_zmultiples_iff, Int.dvd_natAbs, Int.natAbs_dvd]
@[simp] lemma Int.addSubgroupClosure_one : AddSubgroup.closure ({1} : Set ℤ) = ⊤ := by
ext
simp [AddSubgroup.mem_closure_singleton]
@[deprecated (since := "2025-08-12")]
alias AddSubgroup.closure_singleton_int_one_eq_top := Int.addSubgroupClosure_one
@[deprecated (since := "2025-08-12")]
alias AddSubgroup.zmultiples_one_eq_top := Int.zmultiples_one |
.lake/packages/mathlib/Mathlib/Algebra/Group/Pointwise/Finset/Interval.lean | import Mathlib.Algebra.Order.Group.Pointwise.Interval
import Mathlib.Order.Interval.Finset.Defs
import Mathlib.Algebra.Group.Pointwise.Finset.Basic
/-! # Pointwise operations on intervals
This should be kept in sync with `Mathlib/Data/Set/Pointwise/Interval.lean`.
-/
variable {α : Type*}
namespace Finset
open scoped Pointwise
/-! ### Binary pointwise operations
Note that the subset operations below only cover the cases with the largest possible intervals on
the LHS: to conclude that `Ioo a b * Ioo c d ⊆ Ioo (a * c) (c * d)`, you can use monotonicity of `*`
and `Finset.Ico_mul_Ioc_subset`.
TODO: repeat these lemmas for the generality of `mul_le_mul` (which assumes nonnegativity), which
the unprimed names have been reserved for
-/
section ContravariantLE
variable [Mul α] [Preorder α] [DecidableEq α]
variable [MulLeftMono α] [MulRightMono α]
@[to_additive Icc_add_Icc_subset]
theorem Icc_mul_Icc_subset' [LocallyFiniteOrder α] (a b c d : α) :
Icc a b * Icc c d ⊆ Icc (a * c) (b * d) :=
Finset.coe_subset.mp <| by simpa using Set.Icc_mul_Icc_subset' _ _ _ _
@[to_additive Iic_add_Iic_subset]
theorem Iic_mul_Iic_subset' [LocallyFiniteOrderBot α] (a b : α) : Iic a * Iic b ⊆ Iic (a * b) :=
Finset.coe_subset.mp <| by simpa using Set.Iic_mul_Iic_subset' _ _
@[to_additive Ici_add_Ici_subset]
theorem Ici_mul_Ici_subset' [LocallyFiniteOrderTop α] (a b : α) : Ici a * Ici b ⊆ Ici (a * b) :=
Finset.coe_subset.mp <| by simpa using Set.Ici_mul_Ici_subset' _ _
end ContravariantLE
section ContravariantLT
variable [Mul α] [PartialOrder α] [DecidableEq α]
variable [MulLeftStrictMono α] [MulRightStrictMono α]
@[to_additive Icc_add_Ico_subset]
theorem Icc_mul_Ico_subset' [LocallyFiniteOrder α] (a b c d : α) :
Icc a b * Ico c d ⊆ Ico (a * c) (b * d) :=
Finset.coe_subset.mp <| by simpa using Set.Icc_mul_Ico_subset' _ _ _ _
@[to_additive Ico_add_Icc_subset]
theorem Ico_mul_Icc_subset' [LocallyFiniteOrder α] (a b c d : α) :
Ico a b * Icc c d ⊆ Ico (a * c) (b * d) :=
Finset.coe_subset.mp <| by simpa using Set.Ico_mul_Icc_subset' _ _ _ _
@[to_additive Ioc_add_Ico_subset]
theorem Ioc_mul_Ico_subset' [LocallyFiniteOrder α] (a b c d : α) :
Ioc a b * Ico c d ⊆ Ioo (a * c) (b * d) :=
Finset.coe_subset.mp <| by simpa using Set.Ioc_mul_Ico_subset' _ _ _ _
@[to_additive Ico_add_Ioc_subset]
theorem Ico_mul_Ioc_subset' [LocallyFiniteOrder α] (a b c d : α) :
Ico a b * Ioc c d ⊆ Ioo (a * c) (b * d) :=
Finset.coe_subset.mp <| by simpa using Set.Ico_mul_Ioc_subset' _ _ _ _
@[to_additive Iic_add_Iio_subset]
theorem Iic_mul_Iio_subset' [LocallyFiniteOrderBot α] (a b : α) : Iic a * Iio b ⊆ Iio (a * b) :=
Finset.coe_subset.mp <| by simpa using Set.Iic_mul_Iio_subset' _ _
@[to_additive Iio_add_Iic_subset]
theorem Iio_mul_Iic_subset' [LocallyFiniteOrderBot α] (a b : α) : Iio a * Iic b ⊆ Iio (a * b) :=
Finset.coe_subset.mp <| by simpa using Set.Iio_mul_Iic_subset' _ _
@[to_additive Ioi_add_Ici_subset]
theorem Ioi_mul_Ici_subset' [LocallyFiniteOrderTop α] (a b : α) : Ioi a * Ici b ⊆ Ioi (a * b) :=
Finset.coe_subset.mp <| by simpa using Set.Ioi_mul_Ici_subset' _ _
@[to_additive Ici_add_Ioi_subset]
theorem Ici_mul_Ioi_subset' [LocallyFiniteOrderTop α] (a b : α) : Ici a * Ioi b ⊆ Ioi (a * b) :=
Finset.coe_subset.mp <| by simpa using Set.Ici_mul_Ioi_subset' _ _
end ContravariantLT
end Finset |
.lake/packages/mathlib/Mathlib/Algebra/Group/Pointwise/Finset/Density.lean | import Mathlib.Algebra.Group.Pointwise.Finset.Scalar
import Mathlib.Algebra.Group.Action.Pointwise.Finset
import Mathlib.Algebra.Group.Action.Defs
import Mathlib.Data.Finset.Density
/-!
# Theorems about the density of pointwise operations on finsets.
-/
open scoped Pointwise
variable {α β : Type*}
namespace Finset
variable [DecidableEq α] [InvolutiveInv α] {s : Finset α} {a : α} in
@[to_additive (attr := simp)]
lemma dens_inv [Fintype α] (s : Finset α) : s⁻¹.dens = s.dens := by simp [dens]
variable [DecidableEq β] [Group α] [MulAction α β] {s t : Finset β} {a : α} {b : β} in
@[to_additive (attr := simp)]
lemma dens_smul_finset [Fintype β] (a : α) (s : Finset β) : (a • s).dens = s.dens := by simp [dens]
end Finset |
.lake/packages/mathlib/Mathlib/Algebra/Group/Pointwise/Finset/Scalar.lean | import Mathlib.Data.Finset.NAry
import Mathlib.Algebra.Group.Pointwise.Finset.Basic
import Mathlib.Algebra.Group.Pointwise.Set.Finite
/-!
# Pointwise operations of finsets
This file defines pointwise algebraic operations on finsets.
## Main declarations
For finsets `s` and `t`:
* `s +ᵥ t` (`Finset.vadd`): Scalar addition, finset of all `x +ᵥ y` where `x ∈ s` and `y ∈ t`.
* `s • t` (`Finset.smul`): Scalar multiplication, finset of all `x • y` where `x ∈ s` and
`y ∈ t`.
* `s -ᵥ t` (`Finset.vsub`): Scalar subtraction, finset of all `x -ᵥ y` where `x ∈ s` and
`y ∈ t`.
* `a • s` (`Finset.smulFinset`): Scaling, finset of all `a • x` where `x ∈ s`.
* `a +ᵥ s` (`Finset.vaddFinset`): Translation, finset of all `a +ᵥ x` where `x ∈ s`.
For `α` a semigroup/monoid, `Finset α` is a semigroup/monoid.
As an unfortunate side effect, this means that `n • s`, where `n : ℕ`, is ambiguous between
pointwise scaling and repeated pointwise addition; the former has `(2 : ℕ) • {1, 2} = {2, 4}`, while
the latter has `(2 : ℕ) • {1, 2} = {2, 3, 4}`. See note [pointwise nat action].
## Implementation notes
We put all instances in the scope `Pointwise`, so that these instances are not available by
default. Note that we do not mark them as reducible (as argued by note [reducible non-instances])
since we expect the scope to be open whenever the instances are actually used (and making the
instances reducible changes the behavior of `simp`.
## Tags
finset multiplication, finset addition, pointwise addition, pointwise multiplication,
pointwise subtraction
-/
assert_not_exists Cardinal Finset.dens MonoidWithZero MulAction IsOrderedMonoid
open Function MulOpposite
open scoped Pointwise
variable {F α β γ : Type*}
namespace Finset
open Pointwise
/-! ### Scalar addition/multiplication of finsets -/
section SMul
variable [DecidableEq β] [SMul α β] {s s₁ s₂ : Finset α} {t t₁ t₂ u : Finset β} {a : α} {b : β}
/-- The pointwise product of two finsets `s` and `t`: `s • t = {x • y | x ∈ s, y ∈ t}`. -/
@[to_additive
/-- The pointwise sum of two finsets `s` and `t`: `s +ᵥ t = {x +ᵥ y | x ∈ s, y ∈ t}`. -/]
protected def smul : SMul (Finset α) (Finset β) := ⟨image₂ (· • ·)⟩
scoped[Pointwise] attribute [instance] Finset.smul Finset.vadd
@[to_additive] lemma smul_def : s • t = (s ×ˢ t).image fun p : α × β => p.1 • p.2 := rfl
@[to_additive]
lemma image_smul_product : ((s ×ˢ t).image fun x : α × β => x.fst • x.snd) = s • t := rfl
@[to_additive] lemma mem_smul {x : β} : x ∈ s • t ↔ ∃ y ∈ s, ∃ z ∈ t, y • z = x := mem_image₂
@[to_additive (attr := simp, norm_cast)]
lemma coe_smul (s : Finset α) (t : Finset β) : ↑(s • t) = (s : Set α) • (t : Set β) := coe_image₂ ..
@[to_additive] lemma smul_mem_smul : a ∈ s → b ∈ t → a • b ∈ s • t := mem_image₂_of_mem
@[to_additive] lemma card_smul_le : #(s • t) ≤ #s * #t := card_image₂_le ..
@[to_additive (attr := simp)]
lemma empty_smul (t : Finset β) : (∅ : Finset α) • t = ∅ := image₂_empty_left
@[to_additive (attr := simp)]
lemma smul_empty (s : Finset α) : s • (∅ : Finset β) = ∅ := image₂_empty_right
@[to_additive (attr := simp)]
lemma smul_eq_empty : s • t = ∅ ↔ s = ∅ ∨ t = ∅ := image₂_eq_empty_iff
@[to_additive (attr := simp)]
lemma smul_nonempty_iff : (s • t).Nonempty ↔ s.Nonempty ∧ t.Nonempty := image₂_nonempty_iff
@[to_additive (attr := aesop safe apply (rule_sets := [finsetNonempty]))]
lemma Nonempty.smul : s.Nonempty → t.Nonempty → (s • t).Nonempty := .image₂
@[to_additive] lemma Nonempty.of_smul_left : (s • t).Nonempty → s.Nonempty := .of_image₂_left
@[to_additive] lemma Nonempty.of_smul_right : (s • t).Nonempty → t.Nonempty := .of_image₂_right
@[to_additive]
lemma smul_singleton (b : β) : s • ({b} : Finset β) = s.image (· • b) := image₂_singleton_right
@[to_additive]
lemma singleton_smul_singleton (a : α) (b : β) : ({a} : Finset α) • ({b} : Finset β) = {a • b} :=
image₂_singleton
@[to_additive (attr := mono, gcongr)]
lemma smul_subset_smul : s₁ ⊆ s₂ → t₁ ⊆ t₂ → s₁ • t₁ ⊆ s₂ • t₂ := image₂_subset
@[to_additive] lemma smul_subset_smul_left : t₁ ⊆ t₂ → s • t₁ ⊆ s • t₂ := image₂_subset_left
@[to_additive] lemma smul_subset_smul_right : s₁ ⊆ s₂ → s₁ • t ⊆ s₂ • t := image₂_subset_right
@[to_additive] lemma smul_subset_iff : s • t ⊆ u ↔ ∀ a ∈ s, ∀ b ∈ t, a • b ∈ u := image₂_subset_iff
@[to_additive]
lemma union_smul [DecidableEq α] : (s₁ ∪ s₂) • t = s₁ • t ∪ s₂ • t := image₂_union_left
@[to_additive]
lemma smul_union : s • (t₁ ∪ t₂) = s • t₁ ∪ s • t₂ := image₂_union_right
@[to_additive]
lemma inter_smul_subset [DecidableEq α] : (s₁ ∩ s₂) • t ⊆ s₁ • t ∩ s₂ • t :=
image₂_inter_subset_left
@[to_additive]
lemma smul_inter_subset : s • (t₁ ∩ t₂) ⊆ s • t₁ ∩ s • t₂ := image₂_inter_subset_right
@[to_additive]
lemma inter_smul_union_subset_union [DecidableEq α] : (s₁ ∩ s₂) • (t₁ ∪ t₂) ⊆ s₁ • t₁ ∪ s₂ • t₂ :=
image₂_inter_union_subset_union
@[to_additive]
lemma union_smul_inter_subset_union [DecidableEq α] : (s₁ ∪ s₂) • (t₁ ∩ t₂) ⊆ s₁ • t₁ ∪ s₂ • t₂ :=
image₂_union_inter_subset_union
/-- If a finset `u` is contained in the scalar product of two sets `s • t`, we can find two finsets
`s'`, `t'` such that `s' ⊆ s`, `t' ⊆ t` and `u ⊆ s' • t'`. -/
@[to_additive
/-- If a finset `u` is contained in the scalar sum of two sets `s +ᵥ t`, we can find two
finsets `s'`, `t'` such that `s' ⊆ s`, `t' ⊆ t` and `u ⊆ s' +ᵥ t'`. -/]
lemma subset_smul {s : Set α} {t : Set β} :
↑u ⊆ s • t → ∃ (s' : Finset α) (t' : Finset β), ↑s' ⊆ s ∧ ↑t' ⊆ t ∧ u ⊆ s' • t' :=
subset_set_image₂
end SMul
/-! ### Translation/scaling of finsets -/
section SMul
variable [DecidableEq β] [SMul α β] {s s₁ s₂ t : Finset β} {a : α} {b : β}
/-- The scaling of a finset `s` by a scalar `a`: `a • s = {a • x | x ∈ s}`. -/
@[to_additive /-- The translation of a finset `s` by a vector `a`: `a +ᵥ s = {a +ᵥ x | x ∈ s}`. -/]
protected def smulFinset : SMul α (Finset β) where smul a := image <| (a • ·)
scoped[Pointwise] attribute [instance] Finset.smulFinset Finset.vaddFinset
@[to_additive] lemma smul_finset_def : a • s = s.image (a • ·) := rfl
@[to_additive] lemma image_smul : s.image (a • ·) = a • s := rfl
@[to_additive]
lemma mem_smul_finset {x : β} : x ∈ a • s ↔ ∃ y, y ∈ s ∧ a • y = x := by
simp only [Finset.smul_finset_def, mem_image]
@[to_additive (attr := simp, norm_cast)]
lemma coe_smul_finset (a : α) (s : Finset β) : ↑(a • s) = a • (↑s : Set β) := coe_image
@[to_additive] lemma smul_mem_smul_finset : b ∈ s → a • b ∈ a • s := mem_image_of_mem _
@[to_additive] lemma smul_finset_card_le : #(a • s) ≤ #s := card_image_le
@[to_additive (attr := simp)]
lemma smul_finset_empty (a : α) : a • (∅ : Finset β) = ∅ := rfl
@[to_additive (attr := simp)]
lemma smul_finset_eq_empty : a • s = ∅ ↔ s = ∅ := image_eq_empty
@[to_additive (attr := simp)]
lemma smul_finset_nonempty : (a • s).Nonempty ↔ s.Nonempty := image_nonempty
@[to_additive (attr := aesop safe apply (rule_sets := [finsetNonempty]))]
lemma Nonempty.smul_finset (hs : s.Nonempty) : (a • s).Nonempty :=
hs.image _
@[to_additive (attr := simp)]
lemma singleton_smul (a : α) : ({a} : Finset α) • t = a • t := image₂_singleton_left
@[to_additive (attr := mono, gcongr)]
lemma smul_finset_subset_smul_finset : s ⊆ t → a • s ⊆ a • t := image_subset_image
@[to_additive (attr := simp)]
lemma smul_finset_singleton (b : β) : a • ({b} : Finset β) = {a • b} := image_singleton ..
@[to_additive]
lemma smul_finset_union : a • (s₁ ∪ s₂) = a • s₁ ∪ a • s₂ := image_union _ _
@[to_additive]
lemma smul_finset_insert (a : α) (b : β) (s : Finset β) : a • insert b s = insert (a • b) (a • s) :=
image_insert ..
@[to_additive]
lemma smul_finset_inter_subset : a • (s₁ ∩ s₂) ⊆ a • s₁ ∩ a • s₂ := image_inter_subset _ _ _
@[to_additive]
lemma smul_finset_subset_smul {s : Finset α} : a ∈ s → a • t ⊆ s • t := image_subset_image₂_right
@[to_additive (attr := simp)]
lemma biUnion_smul_finset (s : Finset α) (t : Finset β) : s.biUnion (· • t) = s • t :=
biUnion_image_left
end SMul
open scoped Pointwise
/-! ### Instances -/
open Pointwise
/-! ### Scalar subtraction of finsets -/
section VSub
variable [VSub α β] [DecidableEq α] {s s₁ s₂ t t₁ t₂ : Finset β} {u : Finset α} {a : α} {b c : β}
/-- The pointwise subtraction of two finsets `s` and `t`: `s -ᵥ t = {x -ᵥ y | x ∈ s, y ∈ t}`. -/
protected def vsub : VSub (Finset α) (Finset β) :=
⟨image₂ (· -ᵥ ·)⟩
scoped[Pointwise] attribute [instance] Finset.vsub
theorem vsub_def : s -ᵥ t = image₂ (· -ᵥ ·) s t :=
rfl
@[simp]
theorem image_vsub_product : image₂ (· -ᵥ ·) s t = s -ᵥ t :=
rfl
theorem mem_vsub : a ∈ s -ᵥ t ↔ ∃ b ∈ s, ∃ c ∈ t, b -ᵥ c = a :=
mem_image₂
@[simp, norm_cast]
theorem coe_vsub (s t : Finset β) : (↑(s -ᵥ t) : Set α) = (s : Set β) -ᵥ t :=
coe_image₂ _ _ _
theorem vsub_mem_vsub : b ∈ s → c ∈ t → b -ᵥ c ∈ s -ᵥ t :=
mem_image₂_of_mem
theorem vsub_card_le : #(s -ᵥ t : Finset α) ≤ #s * #t :=
card_image₂_le _ _ _
@[simp]
theorem empty_vsub (t : Finset β) : (∅ : Finset β) -ᵥ t = ∅ :=
image₂_empty_left
@[simp]
theorem vsub_empty (s : Finset β) : s -ᵥ (∅ : Finset β) = ∅ :=
image₂_empty_right
@[simp]
theorem vsub_eq_empty : s -ᵥ t = ∅ ↔ s = ∅ ∨ t = ∅ :=
image₂_eq_empty_iff
@[simp]
theorem vsub_nonempty : (s -ᵥ t : Finset α).Nonempty ↔ s.Nonempty ∧ t.Nonempty :=
image₂_nonempty_iff
@[aesop safe apply (rule_sets := [finsetNonempty])]
theorem Nonempty.vsub : s.Nonempty → t.Nonempty → (s -ᵥ t : Finset α).Nonempty :=
Nonempty.image₂
theorem Nonempty.of_vsub_left : (s -ᵥ t : Finset α).Nonempty → s.Nonempty :=
Nonempty.of_image₂_left
theorem Nonempty.of_vsub_right : (s -ᵥ t : Finset α).Nonempty → t.Nonempty :=
Nonempty.of_image₂_right
@[simp]
theorem vsub_singleton (b : β) : s -ᵥ ({b} : Finset β) = s.image (· -ᵥ b) :=
image₂_singleton_right
theorem singleton_vsub (a : β) : ({a} : Finset β) -ᵥ t = t.image (a -ᵥ ·) :=
image₂_singleton_left
theorem singleton_vsub_singleton (a b : β) : ({a} : Finset β) -ᵥ {b} = {a -ᵥ b} :=
image₂_singleton
@[mono, gcongr]
theorem vsub_subset_vsub : s₁ ⊆ s₂ → t₁ ⊆ t₂ → s₁ -ᵥ t₁ ⊆ s₂ -ᵥ t₂ :=
image₂_subset
theorem vsub_subset_vsub_left : t₁ ⊆ t₂ → s -ᵥ t₁ ⊆ s -ᵥ t₂ :=
image₂_subset_left
theorem vsub_subset_vsub_right : s₁ ⊆ s₂ → s₁ -ᵥ t ⊆ s₂ -ᵥ t :=
image₂_subset_right
theorem vsub_subset_iff : s -ᵥ t ⊆ u ↔ ∀ x ∈ s, ∀ y ∈ t, x -ᵥ y ∈ u :=
image₂_subset_iff
section
variable [DecidableEq β]
theorem union_vsub : s₁ ∪ s₂ -ᵥ t = s₁ -ᵥ t ∪ (s₂ -ᵥ t) :=
image₂_union_left
theorem vsub_union : s -ᵥ (t₁ ∪ t₂) = s -ᵥ t₁ ∪ (s -ᵥ t₂) :=
image₂_union_right
theorem inter_vsub_subset : s₁ ∩ s₂ -ᵥ t ⊆ (s₁ -ᵥ t) ∩ (s₂ -ᵥ t) :=
image₂_inter_subset_left
theorem vsub_inter_subset : s -ᵥ t₁ ∩ t₂ ⊆ (s -ᵥ t₁) ∩ (s -ᵥ t₂) :=
image₂_inter_subset_right
end
/-- If a finset `u` is contained in the pointwise subtraction of two sets `s -ᵥ t`, we can find two
finsets `s'`, `t'` such that `s' ⊆ s`, `t' ⊆ t` and `u ⊆ s' -ᵥ t'`. -/
theorem subset_vsub {s t : Set β} :
↑u ⊆ s -ᵥ t → ∃ s' t' : Finset β, ↑s' ⊆ s ∧ ↑t' ⊆ t ∧ u ⊆ s' -ᵥ t' :=
subset_set_image₂
end VSub
section SMul
variable [DecidableEq β] [DecidableEq γ] [SMul αᵐᵒᵖ β] [SMul β γ] [SMul α γ]
-- TODO: replace hypothesis and conclusion with a typeclass
@[to_additive]
theorem op_smul_finset_smul_eq_smul_smul_finset (a : α) (s : Finset β) (t : Finset γ)
(h : ∀ (a : α) (b : β) (c : γ), (op a • b) • c = b • a • c) : (op a • s) • t = s • a • t := by
ext
simp [mem_smul, mem_smul_finset, h]
end SMul
section IsRightCancelMul
variable [Mul α] [IsRightCancelMul α] [DecidableEq α] {s t : Finset α} {a : α}
end IsRightCancelMul
section CancelMonoid
variable [DecidableEq α] [CancelMonoid α] {s : Finset α} {m n : ℕ}
end CancelMonoid
section Group
variable [Group α] [DecidableEq α] {s t : Finset α}
end Group
@[to_additive]
theorem image_smul_comm [DecidableEq β] [DecidableEq γ] [SMul α β] [SMul α γ] (f : β → γ) (a : α)
(s : Finset β) : (∀ b, f (a • b) = a • f b) → (a • s).image f = a • s.image f :=
image_comm
end Finset
namespace Fintype
variable {ι : Type*} {α β : ι → Type*} [Fintype ι] [DecidableEq ι] [∀ i, DecidableEq (β i)]
[∀ i, DecidableEq (α i)]
end Fintype
open Pointwise
namespace Set
section SMul
variable [SMul α β] [DecidableEq β] {s : Set α} {t : Set β}
@[to_additive (attr := simp)]
theorem toFinset_smul (s : Set α) (t : Set β) [Fintype s] [Fintype t] [Fintype ↑(s • t)] :
(s • t).toFinset = s.toFinset • t.toFinset :=
toFinset_image2 _ _ _
@[to_additive]
theorem Finite.toFinset_smul (hs : s.Finite) (ht : t.Finite) (hf := hs.smul ht) :
hf.toFinset = hs.toFinset • ht.toFinset :=
Finite.toFinset_image2 _ _ _
end SMul
section SMul
variable [DecidableEq β] [SMul α β] {a : α} {s : Set β}
@[to_additive (attr := simp)]
theorem toFinset_smul_set (a : α) (s : Set β) [Fintype s] [Fintype ↑(a • s)] :
(a • s).toFinset = a • s.toFinset :=
toFinset_image _ _
@[to_additive]
theorem Finite.toFinset_smul_set (hs : s.Finite) (hf : (a • s).Finite := hs.smul_set) :
hf.toFinset = a • hs.toFinset :=
Finite.toFinset_image _ _ _
end SMul
section VSub
variable [DecidableEq α] [VSub α β] {s t : Set β}
@[simp]
theorem toFinset_vsub (s t : Set β) [Fintype s] [Fintype t] [Fintype ↑(s -ᵥ t)] :
(s -ᵥ t : Set α).toFinset = s.toFinset -ᵥ t.toFinset :=
toFinset_image2 _ _ _
theorem Finite.toFinset_vsub (hs : s.Finite) (ht : t.Finite) (hf := hs.vsub ht) :
hf.toFinset = hs.toFinset -ᵥ ht.toFinset :=
Finite.toFinset_image2 _ _ _
end VSub
end Set |
.lake/packages/mathlib/Mathlib/Algebra/Group/Pointwise/Finset/Basic.lean | import Mathlib.Algebra.Group.Pointwise.Set.Finite
import Mathlib.Algebra.Group.Pointwise.Set.ListOfFn
import Mathlib.Algebra.Order.Monoid.Unbundled.WithTop
import Mathlib.Data.Finset.Max
import Mathlib.Data.Finset.NAry
import Mathlib.Data.Finset.Preimage
/-!
# Pointwise operations of finsets
This file defines pointwise algebraic operations on finsets.
## Main declarations
For finsets `s` and `t`:
* `0` (`Finset.zero`): The singleton `{0}`.
* `1` (`Finset.one`): The singleton `{1}`.
* `-s` (`Finset.neg`): Negation, finset of all `-x` where `x ∈ s`.
* `s⁻¹` (`Finset.inv`): Inversion, finset of all `x⁻¹` where `x ∈ s`.
* `s + t` (`Finset.add`): Addition, finset of all `x + y` where `x ∈ s` and `y ∈ t`.
* `s * t` (`Finset.mul`): Multiplication, finset of all `x * y` where `x ∈ s` and `y ∈ t`.
* `s - t` (`Finset.sub`): Subtraction, finset of all `x - y` where `x ∈ s` and `y ∈ t`.
* `s / t` (`Finset.div`): Division, finset of all `x / y` where `x ∈ s` and `y ∈ t`.
For `α` a semigroup/monoid, `Finset α` is a semigroup/monoid.
As an unfortunate side effect, this means that `n • s`, where `n : ℕ`, is ambiguous between
pointwise scaling and repeated pointwise addition; the former has `(2 : ℕ) • {1, 2} = {2, 4}`, while
the latter has `(2 : ℕ) • {1, 2} = {2, 3, 4}`. See note [pointwise nat action].
## Implementation notes
We put all instances in the scope `Pointwise`, so that these instances are not available by
default. Note that we do not mark them as reducible (as argued by note [reducible non-instances])
since we expect the scope to be open whenever the instances are actually used (and making the
instances reducible changes the behavior of `simp`.
## Tags
finset multiplication, finset addition, pointwise addition, pointwise multiplication,
pointwise subtraction
-/
assert_not_exists Cardinal Finset.dens MonoidWithZero MulAction IsOrderedMonoid
open Function MulOpposite
open scoped Pointwise
variable {F α β γ : Type*}
namespace Finset
/-! ### `0`/`1` as finsets -/
section One
variable [One α] {s : Finset α} {a : α}
/-- The finset `1 : Finset α` is defined as `{1}` in scope `Pointwise`. -/
@[to_additive /-- The finset `0 : Finset α` is defined as `{0}` in scope `Pointwise`. -/]
protected def one : One (Finset α) :=
⟨{1}⟩
scoped[Pointwise] attribute [instance] Finset.one Finset.zero
@[to_additive (attr := simp)]
theorem mem_one : a ∈ (1 : Finset α) ↔ a = 1 :=
mem_singleton
@[to_additive (attr := simp, norm_cast)]
theorem coe_one : ↑(1 : Finset α) = (1 : Set α) :=
coe_singleton 1
@[to_additive (attr := simp, norm_cast)]
lemma coe_eq_one : (s : Set α) = 1 ↔ s = 1 := coe_eq_singleton
@[to_additive (attr := simp)]
theorem one_subset : (1 : Finset α) ⊆ s ↔ (1 : α) ∈ s :=
singleton_subset_iff
-- TODO: This would be a good simp lemma scoped to `Pointwise`, but it seems `@[simp]` can't be
-- scoped
@[to_additive]
theorem singleton_one : ({1} : Finset α) = 1 :=
rfl
@[to_additive]
theorem one_mem_one : (1 : α) ∈ (1 : Finset α) :=
mem_singleton_self _
@[to_additive (attr := simp, aesop safe apply (rule_sets := [finsetNonempty]))]
theorem one_nonempty : (1 : Finset α).Nonempty :=
⟨1, one_mem_one⟩
@[to_additive (attr := simp)]
protected theorem map_one {f : α ↪ β} : map f 1 = {f 1} :=
map_singleton f 1
@[to_additive (attr := simp)]
theorem image_one [DecidableEq β] {f : α → β} : image f 1 = {f 1} :=
image_singleton _ _
@[to_additive]
theorem subset_one_iff_eq : s ⊆ 1 ↔ s = ∅ ∨ s = 1 :=
subset_singleton_iff
@[to_additive]
theorem Nonempty.subset_one_iff (h : s.Nonempty) : s ⊆ 1 ↔ s = 1 :=
h.subset_singleton_iff
@[to_additive (attr := simp)]
theorem card_one : #(1 : Finset α) = 1 :=
card_singleton _
/-- The singleton operation as a `OneHom`. -/
@[to_additive /-- The singleton operation as a `ZeroHom`. -/]
def singletonOneHom : OneHom α (Finset α) where
toFun := singleton; map_one' := singleton_one
@[to_additive (attr := simp)]
theorem coe_singletonOneHom : (singletonOneHom : α → Finset α) = singleton :=
rfl
@[to_additive (attr := simp)]
theorem singletonOneHom_apply (a : α) : singletonOneHom a = {a} :=
rfl
/-- Lift a `OneHom` to `Finset` via `image`. -/
@[to_additive (attr := simps) /-- Lift a `ZeroHom` to `Finset` via `image` -/]
def imageOneHom [DecidableEq β] [One β] [FunLike F α β] [OneHomClass F α β] (f : F) :
OneHom (Finset α) (Finset β) where
toFun := Finset.image f
map_one' := by rw [image_one, map_one, singleton_one]
@[to_additive (attr := simp)]
lemma sup_one [SemilatticeSup β] [OrderBot β] (f : α → β) : sup 1 f = f 1 := sup_singleton
@[to_additive (attr := simp)]
lemma sup'_one [SemilatticeSup β] (f : α → β) : sup' 1 one_nonempty f = f 1 := rfl
@[to_additive (attr := simp)]
lemma inf_one [SemilatticeInf β] [OrderTop β] (f : α → β) : inf 1 f = f 1 := inf_singleton
@[to_additive (attr := simp)]
lemma inf'_one [SemilatticeInf β] (f : α → β) : inf' 1 one_nonempty f = f 1 := rfl
@[to_additive (attr := simp)]
lemma max_one [LinearOrder α] : (1 : Finset α).max = 1 := rfl
@[to_additive (attr := simp)]
lemma min_one [LinearOrder α] : (1 : Finset α).min = 1 := rfl
@[to_additive (attr := simp)]
lemma max'_one [LinearOrder α] : (1 : Finset α).max' one_nonempty = 1 := rfl
@[to_additive (attr := simp)]
lemma min'_one [LinearOrder α] : (1 : Finset α).min' one_nonempty = 1 := rfl
@[to_additive (attr := simp)]
lemma image_op_one [DecidableEq α] : (1 : Finset α).image op = 1 := rfl
@[to_additive (attr := simp)]
lemma map_op_one : (1 : Finset α).map opEquiv.toEmbedding = 1 := rfl
@[to_additive (attr := simp)]
lemma one_product_one [One β] : (1 ×ˢ 1 : Finset (α × β)) = 1 := by ext; simp [Prod.ext_iff]
end One
/-! ### Finset negation/inversion -/
section Inv
variable [DecidableEq α] [Inv α] {s t : Finset α} {a : α}
/-- The pointwise inversion of finset `s⁻¹` is defined as `{x⁻¹ | x ∈ s}` in scope `Pointwise`. -/
@[to_additive
/-- The pointwise negation of finset `-s` is defined as `{-x | x ∈ s}` in scope `Pointwise`. -/]
protected def inv : Inv (Finset α) :=
⟨image Inv.inv⟩
scoped[Pointwise] attribute [instance] Finset.inv Finset.neg
@[to_additive]
theorem inv_def : s⁻¹ = s.image fun x => x⁻¹ :=
rfl
@[to_additive] lemma image_inv_eq_inv (s : Finset α) : s.image (·⁻¹) = s⁻¹ := rfl
@[to_additive]
theorem mem_inv {x : α} : x ∈ s⁻¹ ↔ ∃ y ∈ s, y⁻¹ = x :=
mem_image
@[to_additive]
theorem inv_mem_inv (ha : a ∈ s) : a⁻¹ ∈ s⁻¹ :=
mem_image_of_mem _ ha
@[to_additive]
theorem card_inv_le : #s⁻¹ ≤ #s :=
card_image_le
@[to_additive (attr := simp)]
theorem inv_empty : (∅ : Finset α)⁻¹ = ∅ :=
rfl
@[to_additive (attr := simp)]
theorem inv_nonempty_iff : s⁻¹.Nonempty ↔ s.Nonempty := image_nonempty
alias ⟨Nonempty.of_inv, Nonempty.inv⟩ := inv_nonempty_iff
attribute [to_additive] Nonempty.inv Nonempty.of_inv
attribute [aesop safe apply (rule_sets := [finsetNonempty])] Nonempty.inv Nonempty.neg
@[to_additive (attr := simp)]
theorem inv_eq_empty : s⁻¹ = ∅ ↔ s = ∅ := image_eq_empty
@[to_additive (attr := mono, gcongr)]
theorem inv_subset_inv (h : s ⊆ t) : s⁻¹ ⊆ t⁻¹ :=
image_subset_image h
@[to_additive (attr := simp)]
theorem inv_singleton (a : α) : ({a} : Finset α)⁻¹ = {a⁻¹} :=
image_singleton _ _
@[to_additive (attr := simp)]
theorem inv_insert (a : α) (s : Finset α) : (insert a s)⁻¹ = insert a⁻¹ s⁻¹ :=
image_insert _ _ _
@[to_additive (attr := simp)]
lemma sup_inv [SemilatticeSup β] [OrderBot β] (s : Finset α) (f : α → β) :
sup s⁻¹ f = sup s (f ·⁻¹) :=
sup_image ..
@[to_additive (attr := simp)]
lemma sup'_inv [SemilatticeSup β] {s : Finset α} (hs : s⁻¹.Nonempty) (f : α → β) :
sup' s⁻¹ hs f = sup' s hs.of_inv (f ·⁻¹) :=
sup'_image ..
@[to_additive (attr := simp)]
lemma inf_inv [SemilatticeInf β] [OrderTop β] (s : Finset α) (f : α → β) :
inf s⁻¹ f = inf s (f ·⁻¹) :=
inf_image ..
@[to_additive (attr := simp)]
lemma inf'_inv [SemilatticeInf β] {s : Finset α} (hs : s⁻¹.Nonempty) (f : α → β) :
inf' s⁻¹ hs f = inf' s hs.of_inv (f ·⁻¹) :=
inf'_image ..
@[to_additive] lemma image_op_inv (s : Finset α) : s⁻¹.image op = (s.image op)⁻¹ :=
image_comm op_inv
@[to_additive]
lemma map_op_inv (s : Finset α) : s⁻¹.map opEquiv.toEmbedding = (s.map opEquiv.toEmbedding)⁻¹ := by
simp [map_eq_image, image_op_inv]
end Inv
open Pointwise
section InvolutiveInv
variable [DecidableEq α] [InvolutiveInv α] {s : Finset α} {a : α}
@[to_additive (attr := simp)]
lemma mem_inv' : a ∈ s⁻¹ ↔ a⁻¹ ∈ s := by simp [mem_inv, inv_eq_iff_eq_inv]
@[to_additive (attr := simp)]
theorem inv_filter (s : Finset α) (p : α → Prop) [DecidablePred p] :
({x ∈ s | p x} : Finset α)⁻¹ = {x ∈ s⁻¹ | p x⁻¹} := by
ext; simp
@[to_additive]
theorem inv_filter_univ (p : α → Prop) [Fintype α] [DecidablePred p] :
({x | p x} : Finset α)⁻¹ = {x | p x⁻¹} := by
simp
@[to_additive (attr := simp, norm_cast)]
theorem coe_inv (s : Finset α) : ↑s⁻¹ = (s : Set α)⁻¹ := coe_image.trans Set.image_inv_eq_inv
@[to_additive (attr := simp)]
theorem card_inv (s : Finset α) : #s⁻¹ = #s := card_image_of_injective _ inv_injective
@[to_additive (attr := simp)]
theorem preimage_inv (s : Finset α) : s.preimage (·⁻¹) inv_injective.injOn = s⁻¹ :=
coe_injective <| by rw [coe_preimage, Set.inv_preimage, coe_inv]
@[to_additive (attr := simp)]
lemma inv_univ [Fintype α] : (univ : Finset α)⁻¹ = univ := by ext; simp
@[to_additive (attr := simp)]
lemma inv_inter (s t : Finset α) : (s ∩ t)⁻¹ = s⁻¹ ∩ t⁻¹ := coe_injective <| by simp
@[to_additive (attr := simp)]
lemma inv_product [DecidableEq β] [InvolutiveInv β] (s : Finset α) (t : Finset β) :
(s ×ˢ t)⁻¹ = s⁻¹ ×ˢ t⁻¹ := mod_cast (s : Set α).inv_prod (t : Set β)
end InvolutiveInv
open scoped Pointwise
/-! ### Finset addition/multiplication -/
section Mul
variable [DecidableEq α] [Mul α] [Mul β] [FunLike F α β] [MulHomClass F α β]
(f : F) {s s₁ s₂ t t₁ t₂ u : Finset α} {a b : α}
/-- The pointwise multiplication of finsets `s * t` and `t` is defined as `{x * y | x ∈ s, y ∈ t}`
in scope `Pointwise`. -/
@[to_additive
/-- The pointwise addition of finsets `s + t` is defined as `{x + y | x ∈ s, y ∈ t}` in
scope `Pointwise`. -/]
protected def mul : Mul (Finset α) :=
⟨image₂ (· * ·)⟩
scoped[Pointwise] attribute [instance] Finset.mul Finset.add
@[to_additive]
theorem mul_def : s * t = (s ×ˢ t).image fun p : α × α => p.1 * p.2 :=
rfl
@[to_additive]
theorem image_mul_product : ((s ×ˢ t).image fun x : α × α => x.fst * x.snd) = s * t :=
rfl
@[to_additive]
theorem mem_mul {x : α} : x ∈ s * t ↔ ∃ y ∈ s, ∃ z ∈ t, y * z = x := mem_image₂
@[to_additive (attr := simp, norm_cast)]
theorem coe_mul (s t : Finset α) : (↑(s * t) : Set α) = ↑s * ↑t :=
coe_image₂ _ _ _
@[to_additive]
theorem mul_mem_mul : a ∈ s → b ∈ t → a * b ∈ s * t :=
mem_image₂_of_mem
@[to_additive]
theorem card_mul_le : #(s * t) ≤ #s * #t :=
card_image₂_le _ _ _
@[to_additive]
theorem card_mul_iff :
#(s * t) = #s * #t ↔ (s ×ˢ t : Set (α × α)).InjOn fun p => p.1 * p.2 :=
card_image₂_iff
@[to_additive (attr := simp)]
theorem empty_mul (s : Finset α) : ∅ * s = ∅ :=
image₂_empty_left
@[to_additive (attr := simp)]
theorem mul_empty (s : Finset α) : s * ∅ = ∅ :=
image₂_empty_right
@[to_additive (attr := simp)]
theorem mul_eq_empty : s * t = ∅ ↔ s = ∅ ∨ t = ∅ :=
image₂_eq_empty_iff
@[to_additive (attr := simp)]
theorem mul_nonempty : (s * t).Nonempty ↔ s.Nonempty ∧ t.Nonempty :=
image₂_nonempty_iff
@[to_additive (attr := aesop safe apply (rule_sets := [finsetNonempty]))]
theorem Nonempty.mul : s.Nonempty → t.Nonempty → (s * t).Nonempty :=
Nonempty.image₂
@[to_additive]
theorem Nonempty.of_mul_left : (s * t).Nonempty → s.Nonempty :=
Nonempty.of_image₂_left
@[to_additive]
theorem Nonempty.of_mul_right : (s * t).Nonempty → t.Nonempty :=
Nonempty.of_image₂_right
@[to_additive (attr := simp)]
theorem singleton_mul_singleton (a b : α) : ({a} : Finset α) * {b} = {a * b} :=
image₂_singleton
@[to_additive (attr := mono, gcongr)]
theorem mul_subset_mul : s₁ ⊆ s₂ → t₁ ⊆ t₂ → s₁ * t₁ ⊆ s₂ * t₂ :=
image₂_subset
@[to_additive]
theorem mul_subset_mul_left : t₁ ⊆ t₂ → s * t₁ ⊆ s * t₂ :=
image₂_subset_left
@[to_additive]
theorem mul_subset_mul_right : s₁ ⊆ s₂ → s₁ * t ⊆ s₂ * t :=
image₂_subset_right
@[to_additive] instance : MulLeftMono (Finset α) where elim _s _t₁ _t₂ := mul_subset_mul_left
@[to_additive] instance : MulRightMono (Finset α) where elim _t _s₁ _s₂ := mul_subset_mul_right
@[to_additive]
theorem mul_subset_iff : s * t ⊆ u ↔ ∀ x ∈ s, ∀ y ∈ t, x * y ∈ u :=
image₂_subset_iff
@[to_additive]
theorem union_mul : (s₁ ∪ s₂) * t = s₁ * t ∪ s₂ * t :=
image₂_union_left
@[to_additive]
theorem mul_union : s * (t₁ ∪ t₂) = s * t₁ ∪ s * t₂ :=
image₂_union_right
@[to_additive]
theorem inter_mul_subset : s₁ ∩ s₂ * t ⊆ s₁ * t ∩ (s₂ * t) :=
image₂_inter_subset_left
@[to_additive]
theorem mul_inter_subset : s * (t₁ ∩ t₂) ⊆ s * t₁ ∩ (s * t₂) :=
image₂_inter_subset_right
@[to_additive]
theorem inter_mul_union_subset_union : s₁ ∩ s₂ * (t₁ ∪ t₂) ⊆ s₁ * t₁ ∪ s₂ * t₂ :=
image₂_inter_union_subset_union
@[to_additive]
theorem union_mul_inter_subset_union : (s₁ ∪ s₂) * (t₁ ∩ t₂) ⊆ s₁ * t₁ ∪ s₂ * t₂ :=
image₂_union_inter_subset_union
/-- If a finset `u` is contained in the product of two sets `s * t`, we can find two finsets `s'`,
`t'` such that `s' ⊆ s`, `t' ⊆ t` and `u ⊆ s' * t'`. -/
@[to_additive
/-- If a finset `u` is contained in the sum of two sets `s + t`, we can find two finsets
`s'`, `t'` such that `s' ⊆ s`, `t' ⊆ t` and `u ⊆ s' + t'`. -/]
theorem subset_mul {s t : Set α} :
↑u ⊆ s * t → ∃ s' t' : Finset α, ↑s' ⊆ s ∧ ↑t' ⊆ t ∧ u ⊆ s' * t' :=
subset_set_image₂
@[to_additive]
theorem image_mul [DecidableEq β] : (s * t).image (f : α → β) = s.image f * t.image f :=
image_image₂_distrib <| map_mul f
@[to_additive]
lemma image_op_mul (s t : Finset α) : (s * t).image op = t.image op * s.image op :=
image_image₂_antidistrib op_mul
@[to_additive (attr := simp)]
lemma product_mul_product_comm [DecidableEq β] (s₁ s₂ : Finset α) (t₁ t₂ : Finset β) :
(s₁ ×ˢ t₁) * (s₂ ×ˢ t₂) = (s₁ * s₂) ×ˢ (t₁ * t₂) :=
mod_cast (s₁ : Set α).prod_mul_prod_comm s₂ (t₁ : Set β) t₂
@[to_additive]
lemma map_op_mul (s t : Finset α) :
(s * t).map opEquiv.toEmbedding = t.map opEquiv.toEmbedding * s.map opEquiv.toEmbedding := by
simp [map_eq_image, image_op_mul]
/-- The singleton operation as a `MulHom`. -/
@[to_additive /-- The singleton operation as an `AddHom`. -/]
def singletonMulHom : α →ₙ* Finset α where
toFun := singleton; map_mul' _ _ := (singleton_mul_singleton _ _).symm
@[to_additive (attr := simp)]
theorem coe_singletonMulHom : (singletonMulHom : α → Finset α) = singleton :=
rfl
@[to_additive (attr := simp)]
theorem singletonMulHom_apply (a : α) : singletonMulHom a = {a} :=
rfl
/-- Lift a `MulHom` to `Finset` via `image`. -/
@[to_additive (attr := simps) /-- Lift an `AddHom` to `Finset` via `image` -/]
def imageMulHom [DecidableEq β] : Finset α →ₙ* Finset β where
toFun := Finset.image f
map_mul' _ _ := image_mul _
@[to_additive (attr := simp (default + 1))]
lemma sup_mul_le {β} [SemilatticeSup β] [OrderBot β] {s t : Finset α} {f : α → β} {a : β} :
sup (s * t) f ≤ a ↔ ∀ x ∈ s, ∀ y ∈ t, f (x * y) ≤ a :=
sup_image₂_le
@[to_additive]
lemma sup_mul_left {β} [SemilatticeSup β] [OrderBot β] (s t : Finset α) (f : α → β) :
sup (s * t) f = sup s fun x ↦ sup t (f <| x * ·) :=
sup_image₂_left ..
@[to_additive]
lemma sup_mul_right {β} [SemilatticeSup β] [OrderBot β] (s t : Finset α) (f : α → β) :
sup (s * t) f = sup t fun y ↦ sup s (f <| · * y) :=
sup_image₂_right ..
@[to_additive (attr := simp (default + 1))]
lemma le_inf_mul {β} [SemilatticeInf β] [OrderTop β] {s t : Finset α} {f : α → β} {a : β} :
a ≤ inf (s * t) f ↔ ∀ x ∈ s, ∀ y ∈ t, a ≤ f (x * y) :=
le_inf_image₂
@[to_additive]
lemma inf_mul_left {β} [SemilatticeInf β] [OrderTop β] (s t : Finset α) (f : α → β) :
inf (s * t) f = inf s fun x ↦ inf t (f <| x * ·) :=
inf_image₂_left ..
@[to_additive]
lemma inf_mul_right {β} [SemilatticeInf β] [OrderTop β] (s t : Finset α) (f : α → β) :
inf (s * t) f = inf t fun y ↦ inf s (f <| · * y) :=
inf_image₂_right ..
/--
See `card_le_card_mul_left` for a more convenient but less general version for types with a
left-cancellative multiplication.
-/
@[to_additive
/-- See `card_le_card_add_left` for a more convenient but less general version for types with a
left-cancellative addition. -/]
lemma card_le_card_mul_left_of_injective (has : a ∈ s) (ha : Function.Injective (a * ·)) :
#t ≤ #(s * t) :=
card_le_card_image₂_left _ has ha
/--
See `card_le_card_mul_right` for a more convenient but less general version for types with a
right-cancellative multiplication.
-/
@[to_additive
/-- See `card_le_card_add_right` for a more convenient but less general version for types with a
right-cancellative addition. -/]
lemma card_le_card_mul_right_of_injective (hat : a ∈ t) (ha : Function.Injective (· * a)) :
#s ≤ #(s * t) :=
card_le_card_image₂_right _ hat ha
end Mul
/-! ### Finset subtraction/division -/
section Div
variable [DecidableEq α] [Div α] {s s₁ s₂ t t₁ t₂ u : Finset α} {a b : α}
/-- The pointwise division of finsets `s / t` is defined as `{x / y | x ∈ s, y ∈ t}` in locale
`Pointwise`. -/
@[to_additive
/-- The pointwise subtraction of finsets `s - t` is defined as `{x - y | x ∈ s, y ∈ t}`
in scope `Pointwise`. -/]
protected def div : Div (Finset α) :=
⟨image₂ (· / ·)⟩
scoped[Pointwise] attribute [instance] Finset.div Finset.sub
@[to_additive]
theorem div_def : s / t = (s ×ˢ t).image fun p : α × α => p.1 / p.2 :=
rfl
@[to_additive]
theorem image_div_product : ((s ×ˢ t).image fun x : α × α => x.fst / x.snd) = s / t :=
rfl
@[to_additive]
theorem mem_div : a ∈ s / t ↔ ∃ b ∈ s, ∃ c ∈ t, b / c = a :=
mem_image₂
@[to_additive (attr := simp, norm_cast)]
theorem coe_div (s t : Finset α) : (↑(s / t) : Set α) = ↑s / ↑t :=
coe_image₂ _ _ _
@[to_additive]
theorem div_mem_div : a ∈ s → b ∈ t → a / b ∈ s / t :=
mem_image₂_of_mem
@[to_additive]
theorem card_div_le : #(s / t) ≤ #s * #t :=
card_image₂_le _ _ _
@[deprecated (since := "2025-07-02")] alias div_card_le := card_div_le
@[to_additive (attr := simp)]
theorem empty_div (s : Finset α) : ∅ / s = ∅ :=
image₂_empty_left
@[to_additive (attr := simp)]
theorem div_empty (s : Finset α) : s / ∅ = ∅ :=
image₂_empty_right
@[to_additive (attr := simp)]
theorem div_eq_empty : s / t = ∅ ↔ s = ∅ ∨ t = ∅ :=
image₂_eq_empty_iff
@[to_additive (attr := simp)]
theorem div_nonempty : (s / t).Nonempty ↔ s.Nonempty ∧ t.Nonempty :=
image₂_nonempty_iff
@[to_additive (attr := aesop safe apply (rule_sets := [finsetNonempty]))]
theorem Nonempty.div : s.Nonempty → t.Nonempty → (s / t).Nonempty :=
Nonempty.image₂
@[to_additive]
theorem Nonempty.of_div_left : (s / t).Nonempty → s.Nonempty :=
Nonempty.of_image₂_left
@[to_additive]
theorem Nonempty.of_div_right : (s / t).Nonempty → t.Nonempty :=
Nonempty.of_image₂_right
@[to_additive (attr := simp)]
theorem div_singleton (a : α) : s / {a} = s.image (· / a) :=
image₂_singleton_right
@[to_additive (attr := simp)]
theorem singleton_div (a : α) : {a} / s = s.image (a / ·) :=
image₂_singleton_left
@[to_additive]
theorem singleton_div_singleton (a b : α) : ({a} : Finset α) / {b} = {a / b} :=
image₂_singleton
@[to_additive (attr := mono, gcongr)]
theorem div_subset_div : s₁ ⊆ s₂ → t₁ ⊆ t₂ → s₁ / t₁ ⊆ s₂ / t₂ :=
image₂_subset
@[to_additive]
theorem div_subset_div_left : t₁ ⊆ t₂ → s / t₁ ⊆ s / t₂ :=
image₂_subset_left
@[to_additive]
theorem div_subset_div_right : s₁ ⊆ s₂ → s₁ / t ⊆ s₂ / t :=
image₂_subset_right
@[to_additive]
theorem div_subset_iff : s / t ⊆ u ↔ ∀ x ∈ s, ∀ y ∈ t, x / y ∈ u :=
image₂_subset_iff
@[to_additive]
theorem union_div : (s₁ ∪ s₂) / t = s₁ / t ∪ s₂ / t :=
image₂_union_left
@[to_additive]
theorem div_union : s / (t₁ ∪ t₂) = s / t₁ ∪ s / t₂ :=
image₂_union_right
@[to_additive]
theorem inter_div_subset : s₁ ∩ s₂ / t ⊆ s₁ / t ∩ (s₂ / t) :=
image₂_inter_subset_left
@[to_additive]
theorem div_inter_subset : s / (t₁ ∩ t₂) ⊆ s / t₁ ∩ (s / t₂) :=
image₂_inter_subset_right
@[to_additive]
theorem inter_div_union_subset_union : s₁ ∩ s₂ / (t₁ ∪ t₂) ⊆ s₁ / t₁ ∪ s₂ / t₂ :=
image₂_inter_union_subset_union
@[to_additive]
theorem union_div_inter_subset_union : (s₁ ∪ s₂) / (t₁ ∩ t₂) ⊆ s₁ / t₁ ∪ s₂ / t₂ :=
image₂_union_inter_subset_union
/-- If a finset `u` is contained in the product of two sets `s / t`, we can find two finsets `s'`,
`t'` such that `s' ⊆ s`, `t' ⊆ t` and `u ⊆ s' / t'`. -/
@[to_additive
/-- If a finset `u` is contained in the sum of two sets `s - t`, we can find two finsets
`s'`, `t'` such that `s' ⊆ s`, `t' ⊆ t` and `u ⊆ s' - t'`. -/]
theorem subset_div {s t : Set α} :
↑u ⊆ s / t → ∃ s' t' : Finset α, ↑s' ⊆ s ∧ ↑t' ⊆ t ∧ u ⊆ s' / t' :=
subset_set_image₂
@[to_additive (attr := simp (default + 1))]
lemma sup_div_le [SemilatticeSup β] [OrderBot β] {s t : Finset α} {f : α → β} {a : β} :
sup (s / t) f ≤ a ↔ ∀ x ∈ s, ∀ y ∈ t, f (x / y) ≤ a :=
sup_image₂_le
@[to_additive]
lemma sup_div_left [SemilatticeSup β] [OrderBot β] (s t : Finset α) (f : α → β) :
sup (s / t) f = sup s fun x ↦ sup t (f <| x / ·) :=
sup_image₂_left ..
@[to_additive]
lemma sup_div_right [SemilatticeSup β] [OrderBot β] (s t : Finset α) (f : α → β) :
sup (s / t) f = sup t fun y ↦ sup s (f <| · / y) :=
sup_image₂_right ..
@[to_additive (attr := simp (default + 1))]
lemma le_inf_div [SemilatticeInf β] [OrderTop β] {s t : Finset α} {f : α → β} {a : β} :
a ≤ inf (s / t) f ↔ ∀ x ∈ s, ∀ y ∈ t, a ≤ f (x / y) :=
le_inf_image₂
@[to_additive]
lemma inf_div_left [SemilatticeInf β] [OrderTop β] (s t : Finset α) (f : α → β) :
inf (s / t) f = inf s fun x ↦ inf t (f <| x / ·) :=
inf_image₂_left ..
@[to_additive]
lemma inf_div_right [SemilatticeInf β] [OrderTop β] (s t : Finset α) (f : α → β) :
inf (s / t) f = inf t fun y ↦ inf s (f <| · / y) :=
inf_image₂_right ..
end Div
/-! ### Instances -/
section Instances
variable [DecidableEq α] [DecidableEq β]
/-- Repeated pointwise addition (not the same as pointwise repeated addition!) of a `Finset`. See
note [pointwise nat action]. -/
protected def nsmul [Zero α] [Add α] : SMul ℕ (Finset α) :=
⟨nsmulRec⟩
/-- Repeated pointwise multiplication (not the same as pointwise repeated multiplication!) of a
`Finset`. See note [pointwise nat action]. -/
protected def npow [One α] [Mul α] : Pow (Finset α) ℕ :=
⟨fun s n => npowRec n s⟩
attribute [to_additive existing] Finset.npow
/-- Repeated pointwise addition/subtraction (not the same as pointwise repeated
addition/subtraction!) of a `Finset`. See note [pointwise nat action]. -/
protected def zsmul [Zero α] [Add α] [Neg α] : SMul ℤ (Finset α) :=
⟨zsmulRec⟩
/-- Repeated pointwise multiplication/division (not the same as pointwise repeated
multiplication/division!) of a `Finset`. See note [pointwise nat action]. -/
@[to_additive existing]
protected def zpow [One α] [Mul α] [Inv α] : Pow (Finset α) ℤ :=
⟨fun s n => zpowRec npowRec n s⟩
scoped[Pointwise] attribute [instance] Finset.nsmul Finset.npow Finset.zsmul Finset.zpow
/-- `Finset α` is a `Semigroup` under pointwise operations if `α` is. -/
@[to_additive /-- `Finset α` is an `AddSemigroup` under pointwise operations if `α` is. -/]
protected def semigroup [Semigroup α] : Semigroup (Finset α) :=
coe_injective.semigroup _ coe_mul
section CommSemigroup
variable [CommSemigroup α] {s t : Finset α}
/-- `Finset α` is a `CommSemigroup` under pointwise operations if `α` is. -/
@[to_additive /-- `Finset α` is an `AddCommSemigroup` under pointwise operations if `α` is. -/]
protected def commSemigroup : CommSemigroup (Finset α) :=
coe_injective.commSemigroup _ coe_mul
@[to_additive]
theorem inter_mul_union_subset : s ∩ t * (s ∪ t) ⊆ s * t :=
image₂_inter_union_subset mul_comm
@[to_additive]
theorem union_mul_inter_subset : (s ∪ t) * (s ∩ t) ⊆ s * t :=
image₂_union_inter_subset mul_comm
end CommSemigroup
section MulOneClass
variable [MulOneClass α]
/-- `Finset α` is a `MulOneClass` under pointwise operations if `α` is. -/
@[to_additive /-- `Finset α` is an `AddZeroClass` under pointwise operations if `α` is. -/]
protected def mulOneClass : MulOneClass (Finset α) :=
coe_injective.mulOneClass _ (coe_singleton 1) coe_mul
scoped[Pointwise] attribute [instance] Finset.semigroup Finset.addSemigroup Finset.commSemigroup
Finset.addCommSemigroup Finset.mulOneClass Finset.addZeroClass
@[to_additive]
theorem subset_mul_left (s : Finset α) {t : Finset α} (ht : (1 : α) ∈ t) : s ⊆ s * t := fun a ha =>
mem_mul.2 ⟨a, ha, 1, ht, mul_one _⟩
@[to_additive]
theorem subset_mul_right {s : Finset α} (t : Finset α) (hs : (1 : α) ∈ s) : t ⊆ s * t := fun a ha =>
mem_mul.2 ⟨1, hs, a, ha, one_mul _⟩
/-- The singleton operation as a `MonoidHom`. -/
@[to_additive /-- The singleton operation as an `AddMonoidHom`. -/]
def singletonMonoidHom : α →* Finset α :=
{ singletonMulHom, singletonOneHom with }
@[to_additive (attr := simp)]
theorem coe_singletonMonoidHom : (singletonMonoidHom : α → Finset α) = singleton :=
rfl
@[to_additive (attr := simp)]
theorem singletonMonoidHom_apply (a : α) : singletonMonoidHom a = {a} :=
rfl
/-- The coercion from `Finset` to `Set` as a `MonoidHom`. -/
@[to_additive /-- The coercion from `Finset` to `set` as an `AddMonoidHom`. -/]
def coeMonoidHom : Finset α →* Set α where
toFun := (↑)
map_one' := coe_one
map_mul' := coe_mul
@[to_additive (attr := simp)]
theorem coe_coeMonoidHom : (coeMonoidHom : Finset α → Set α) = (↑) :=
rfl
@[to_additive (attr := simp)]
theorem coeMonoidHom_apply (s : Finset α) : coeMonoidHom s = s :=
rfl
/-- Lift a `MonoidHom` to `Finset` via `image`. -/
@[to_additive (attr := simps) /-- Lift an `add_monoid_hom` to `Finset` via `image` -/]
def imageMonoidHom [MulOneClass β] [FunLike F α β] [MonoidHomClass F α β] (f : F) :
Finset α →* Finset β :=
{ imageMulHom f, imageOneHom f with }
end MulOneClass
section Monoid
variable [Monoid α] {s t : Finset α} {a : α} {m n : ℕ}
@[to_additive (attr := simp, norm_cast)]
theorem coe_pow (s : Finset α) (n : ℕ) : ↑(s ^ n) = (s : Set α) ^ n := by
change ↑(npowRec n s) = (s : Set α) ^ n
induction n with
| zero => rw [npowRec, pow_zero, coe_one]
| succ n ih => rw [npowRec, pow_succ, coe_mul, ih]
/-- `Finset α` is a `Monoid` under pointwise operations if `α` is. -/
@[to_additive /-- `Finset α` is an `AddMonoid` under pointwise operations if `α` is. -/]
protected def monoid : Monoid (Finset α) :=
coe_injective.monoid _ coe_one coe_mul coe_pow
scoped[Pointwise] attribute [instance] Finset.monoid Finset.addMonoid
-- `Finset.pow_left_monotone` doesn't exist since it would syntactically be a special case of
-- `pow_left_mono`
@[to_additive]
protected lemma pow_right_monotone (hs : 1 ∈ s) : Monotone (s ^ ·) :=
pow_right_monotone <| one_subset.2 hs
@[to_additive (attr := gcongr)]
lemma pow_subset_pow_left (hst : s ⊆ t) : s ^ n ⊆ t ^ n := subset_of_le (pow_left_mono n hst)
@[to_additive]
lemma pow_subset_pow_right (hs : 1 ∈ s) (hmn : m ≤ n) : s ^ m ⊆ s ^ n :=
Finset.pow_right_monotone hs hmn
@[to_additive (attr := gcongr)]
lemma pow_subset_pow (hst : s ⊆ t) (ht : 1 ∈ t) (hmn : m ≤ n) : s ^ m ⊆ t ^ n :=
(pow_subset_pow_left hst).trans (pow_subset_pow_right ht hmn)
@[to_additive]
lemma subset_pow (hs : 1 ∈ s) (hn : n ≠ 0) : s ⊆ s ^ n := by
simpa using pow_subset_pow_right hs <| Nat.one_le_iff_ne_zero.2 hn
@[to_additive]
lemma pow_subset_pow_mul_of_sq_subset_mul (hst : s ^ 2 ⊆ t * s) (hn : n ≠ 0) :
s ^ n ⊆ t ^ (n - 1) * s := subset_of_le (pow_le_pow_mul_of_sq_le_mul hst hn)
@[to_additive (attr := simp) nsmul_empty]
lemma empty_pow (hn : n ≠ 0) : (∅ : Finset α) ^ n = ∅ := match n with | n + 1 => by simp [pow_succ]
@[to_additive]
lemma Nonempty.pow (hs : s.Nonempty) : ∀ {n}, (s ^ n).Nonempty
| 0 => by simp
| n + 1 => by rw [pow_succ]; exact hs.pow.mul hs
set_option push_neg.use_distrib true in
@[to_additive (attr := simp)] lemma pow_eq_empty : s ^ n = ∅ ↔ s = ∅ ∧ n ≠ 0 := by
constructor
· contrapose!
rintro (hs | rfl)
-- TODO: The `nonempty_iff_ne_empty` would be unnecessary if `push_neg` knew how to simplify
-- `s ≠ ∅` to `s.Nonempty` when `s : Finset α`.
-- See https://leanprover.zulipchat.com/#narrow/channel/287929-mathlib4/topic/push_neg.20extensibility
· exact nonempty_iff_ne_empty.1 (nonempty_iff_ne_empty.2 hs).pow
· rw [← nonempty_iff_ne_empty]
simp
· rintro ⟨rfl, hn⟩
exact empty_pow hn
@[to_additive (attr := simp) nsmul_singleton]
lemma singleton_pow (a : α) : ∀ n, ({a} : Finset α) ^ n = {a ^ n}
| 0 => by simp [singleton_one]
| n + 1 => by simp [pow_succ, singleton_pow _ n]
@[to_additive] lemma pow_mem_pow (ha : a ∈ s) : a ^ n ∈ s ^ n := by
simpa using pow_subset_pow_left (singleton_subset_iff.2 ha)
@[to_additive] lemma one_mem_pow (hs : 1 ∈ s) : 1 ∈ s ^ n := by simpa using pow_mem_pow hs
@[to_additive]
lemma inter_pow_subset : (s ∩ t) ^ n ⊆ s ^ n ∩ t ^ n := by apply subset_inter <;> gcongr <;> simp
@[to_additive (attr := simp, norm_cast)]
theorem coe_list_prod (s : List (Finset α)) : (↑s.prod : Set α) = (s.map (↑)).prod :=
map_list_prod (coeMonoidHom : Finset α →* Set α) _
@[to_additive]
theorem mem_prod_list_ofFn {a : α} {s : Fin n → Finset α} :
a ∈ (List.ofFn s).prod ↔ ∃ f : ∀ i : Fin n, s i, (List.ofFn fun i => (f i : α)).prod = a := by
rw [← mem_coe, coe_list_prod, List.map_ofFn, Set.mem_prod_list_ofFn]
rfl
@[to_additive]
theorem mem_pow {a : α} {n : ℕ} :
a ∈ s ^ n ↔ ∃ f : Fin n → s, (List.ofFn fun i => ↑(f i)).prod = a := by
simp [← mem_coe (s := s ^ n), coe_pow, Set.mem_pow]
@[to_additive]
lemma card_pow_le : ∀ {n}, #(s ^ n) ≤ #s ^ n
| 0 => by simp
| n + 1 => by rw [pow_succ, pow_succ]; refine card_mul_le.trans (by gcongr; exact card_pow_le)
@[to_additive]
theorem mul_univ_of_one_mem [Fintype α] (hs : (1 : α) ∈ s) : s * univ = univ :=
eq_univ_iff_forall.2 fun _ => mem_mul.2 ⟨_, hs, _, mem_univ _, one_mul _⟩
@[to_additive]
theorem univ_mul_of_one_mem [Fintype α] (ht : (1 : α) ∈ t) : univ * t = univ :=
eq_univ_iff_forall.2 fun _ => mem_mul.2 ⟨_, mem_univ _, _, ht, mul_one _⟩
@[to_additive (attr := simp)]
theorem univ_mul_univ [Fintype α] : (univ : Finset α) * univ = univ :=
mul_univ_of_one_mem <| mem_univ _
@[to_additive (attr := simp) nsmul_univ]
theorem univ_pow [Fintype α] (hn : n ≠ 0) : (univ : Finset α) ^ n = univ :=
coe_injective <| by rw [coe_pow, coe_univ, Set.univ_pow hn]
@[to_additive]
protected theorem _root_.IsUnit.finset : IsUnit a → IsUnit ({a} : Finset α) :=
IsUnit.map (singletonMonoidHom : α →* Finset α)
@[to_additive]
lemma image_op_pow (s : Finset α) : ∀ n : ℕ, (s ^ n).image op = s.image op ^ n
| 0 => by simp [singleton_one]
| n + 1 => by rw [pow_succ, pow_succ', image_op_mul, image_op_pow]
@[to_additive]
lemma map_op_pow (s : Finset α) :
∀ n : ℕ, (s ^ n).map opEquiv.toEmbedding = s.map opEquiv.toEmbedding ^ n
| 0 => by simp [singleton_one]
| n + 1 => by rw [pow_succ, pow_succ', map_op_mul, map_op_pow]
@[to_additive]
lemma product_pow [Monoid β] (s : Finset α) (t : Finset β) : ∀ n, (s ×ˢ t) ^ n = (s ^ n) ×ˢ (t ^ n)
| 0 => by simp
| n + 1 => by simp [pow_succ, product_pow _ _ n]
end Monoid
section CommMonoid
variable [CommMonoid α]
/-- `Finset α` is a `CommMonoid` under pointwise operations if `α` is. -/
@[to_additive /-- `Finset α` is an `AddCommMonoid` under pointwise operations if `α` is. -/]
protected def commMonoid : CommMonoid (Finset α) :=
coe_injective.commMonoid _ coe_one coe_mul coe_pow
scoped[Pointwise] attribute [instance] Finset.commMonoid Finset.addCommMonoid
end CommMonoid
section DivisionMonoid
variable [DivisionMonoid α] {s t : Finset α} {n : ℤ}
@[to_additive (attr := simp)]
theorem coe_zpow (s : Finset α) : ∀ n : ℤ, ↑(s ^ n) = (s : Set α) ^ n
| Int.ofNat _ => coe_pow _ _
| Int.negSucc n => by
refine (coe_inv _).trans ?_
exact congr_arg Inv.inv (coe_pow _ _)
@[to_additive]
protected theorem mul_eq_one_iff : s * t = 1 ↔ ∃ a b, s = {a} ∧ t = {b} ∧ a * b = 1 := by
simp_rw [← coe_inj, coe_mul, coe_one, Set.mul_eq_one_iff, coe_singleton]
/-- `Finset α` is a division monoid under pointwise operations if `α` is. -/
@[to_additive
/-- `Finset α` is a subtraction monoid under pointwise operations if `α` is. -/]
protected def divisionMonoid : DivisionMonoid (Finset α) :=
coe_injective.divisionMonoid _ coe_one coe_mul coe_inv coe_div coe_pow coe_zpow
scoped[Pointwise] attribute [instance] Finset.divisionMonoid Finset.subtractionMonoid
@[to_additive (attr := simp)]
theorem isUnit_iff : IsUnit s ↔ ∃ a, s = {a} ∧ IsUnit a := by
constructor
· rintro ⟨u, rfl⟩
obtain ⟨a, b, ha, hb, h⟩ := Finset.mul_eq_one_iff.1 u.mul_inv
refine ⟨a, ha, ⟨a, b, h, singleton_injective ?_⟩, rfl⟩
rw [← singleton_mul_singleton, ← ha, ← hb]
exact u.inv_mul
· rintro ⟨a, rfl, ha⟩
exact ha.finset
@[to_additive (attr := simp)]
theorem isUnit_coe : IsUnit (s : Set α) ↔ IsUnit s := by
simp_rw [isUnit_iff, Set.isUnit_iff, coe_eq_singleton]
@[to_additive (attr := simp)]
lemma univ_div_univ [Fintype α] : (univ / univ : Finset α) = univ := by simp [div_eq_mul_inv]
@[to_additive] lemma subset_div_left (ht : 1 ∈ t) : s ⊆ s / t := by
rw [div_eq_mul_inv]; exact subset_mul_left _ <| by simpa
@[to_additive] lemma inv_subset_div_right (hs : 1 ∈ s) : t⁻¹ ⊆ s / t := by
rw [div_eq_mul_inv]; exact subset_mul_right _ hs
@[to_additive (attr := simp) zsmul_empty]
lemma empty_zpow (hn : n ≠ 0) : (∅ : Finset α) ^ n = ∅ := by cases n <;> simp_all
@[to_additive]
lemma Nonempty.zpow (hs : s.Nonempty) : ∀ {n : ℤ}, (s ^ n).Nonempty
| (n : ℕ) => hs.pow
| .negSucc n => by simpa using hs.pow
set_option push_neg.use_distrib true in
@[to_additive (attr := simp)] lemma zpow_eq_empty : s ^ n = ∅ ↔ s = ∅ ∧ n ≠ 0 := by
constructor
· contrapose!
rintro (hs | rfl)
· exact nonempty_iff_ne_empty.1 (nonempty_iff_ne_empty.2 hs).zpow
· rw [← nonempty_iff_ne_empty]
simp
· rintro ⟨rfl, hn⟩
exact empty_zpow hn
@[to_additive (attr := simp) zsmul_singleton]
lemma singleton_zpow (a : α) (n : ℤ) : ({a} : Finset α) ^ n = {a ^ n} := by cases n <;> simp
end DivisionMonoid
/-- `Finset α` is a commutative division monoid under pointwise operations if `α` is. -/
@[to_additive subtractionCommMonoid
/-- `Finset α` is a commutative subtraction monoid under pointwise operations if `α` is. -/]
protected def divisionCommMonoid [DivisionCommMonoid α] :
DivisionCommMonoid (Finset α) :=
coe_injective.divisionCommMonoid _ coe_one coe_mul coe_inv coe_div coe_pow coe_zpow
scoped[Pointwise] attribute [instance] Finset.divisionCommMonoid Finset.subtractionCommMonoid
section Group
variable [Group α] [DivisionMonoid β] [FunLike F α β] [MonoidHomClass F α β]
variable (f : F) {s t : Finset α} {a b : α}
/-! Note that `Finset` is not a `Group` because `s / s ≠ 1` in general. -/
@[to_additive (attr := simp)]
theorem one_mem_div_iff : (1 : α) ∈ s / t ↔ ¬Disjoint s t := by
rw [← mem_coe, ← disjoint_coe, coe_div, Set.one_mem_div_iff]
@[to_additive (attr := simp)]
lemma one_mem_inv_mul_iff : (1 : α) ∈ t⁻¹ * s ↔ ¬Disjoint s t := by
aesop (add simp [not_disjoint_iff_nonempty_inter, mem_mul, mul_eq_one_iff_eq_inv,
Finset.Nonempty])
@[to_additive]
theorem one_notMem_div_iff : (1 : α) ∉ s / t ↔ Disjoint s t :=
one_mem_div_iff.not_left
@[deprecated (since := "2025-05-23")] alias not_zero_mem_sub_iff := zero_notMem_sub_iff
@[to_additive existing, deprecated (since := "2025-05-23")]
alias not_one_mem_div_iff := one_notMem_div_iff
@[to_additive]
lemma one_notMem_inv_mul_iff : (1 : α) ∉ t⁻¹ * s ↔ Disjoint s t := one_mem_inv_mul_iff.not_left
@[deprecated (since := "2025-05-23")] alias not_zero_mem_neg_add_iff := zero_notMem_neg_add_iff
@[to_additive existing, deprecated (since := "2025-05-23")]
alias not_one_mem_inv_mul_iff := one_notMem_inv_mul_iff
@[to_additive]
theorem Nonempty.one_mem_div (h : s.Nonempty) : (1 : α) ∈ s / s :=
let ⟨a, ha⟩ := h
mem_div.2 ⟨a, ha, a, ha, div_self' _⟩
@[to_additive]
theorem isUnit_singleton (a : α) : IsUnit ({a} : Finset α) :=
(Group.isUnit a).finset
theorem isUnit_iff_singleton : IsUnit s ↔ ∃ a, s = {a} := by
simp only [isUnit_iff, Group.isUnit, and_true]
@[simp]
theorem isUnit_iff_singleton_aux {α} [Group α] {s : Finset α} :
(∃ a, s = {a} ∧ IsUnit a) ↔ ∃ a, s = {a} := by
simp only [Group.isUnit, and_true]
@[to_additive (attr := simp)]
theorem image_mul_left :
image (fun b => a * b) t = preimage t (fun b => a⁻¹ * b) (mul_right_injective _).injOn :=
coe_injective <| by simp
@[to_additive (attr := simp)]
theorem image_mul_right : image (· * b) t = preimage t (· * b⁻¹) (mul_left_injective _).injOn :=
coe_injective <| by simp
@[to_additive]
theorem image_mul_left' :
image (fun b => a⁻¹ * b) t = preimage t (fun b => a * b) (mul_right_injective _).injOn := by
simp
@[to_additive]
theorem image_mul_right' :
image (· * b⁻¹) t = preimage t (· * b) (mul_left_injective _).injOn := by simp
@[to_additive]
lemma image_inv (f : F) (s : Finset α) : s⁻¹.image f = (s.image f)⁻¹ := image_comm (map_inv _)
theorem image_div : (s / t).image (f : α → β) = s.image f / t.image f :=
image_image₂_distrib <| map_div f
end Group
end Instances
section Group
variable [Group α] {a b : α}
@[to_additive (attr := simp)]
theorem preimage_mul_left_singleton :
preimage {b} (a * ·) (mul_right_injective _).injOn = {a⁻¹ * b} := by
classical rw [← image_mul_left', image_singleton]
@[to_additive (attr := simp)]
theorem preimage_mul_right_singleton :
preimage {b} (· * a) (mul_left_injective _).injOn = {b * a⁻¹} := by
classical rw [← image_mul_right', image_singleton]
@[to_additive (attr := simp)]
theorem preimage_mul_left_one : preimage 1 (a * ·) (mul_right_injective _).injOn = {a⁻¹} := by
classical rw [← image_mul_left', image_one, mul_one]
@[to_additive (attr := simp)]
theorem preimage_mul_right_one : preimage 1 (· * b) (mul_left_injective _).injOn = {b⁻¹} := by
classical rw [← image_mul_right', image_one, one_mul]
@[to_additive]
theorem preimage_mul_left_one' : preimage 1 (a⁻¹ * ·) (mul_right_injective _).injOn = {a} := by
rw [preimage_mul_left_one, inv_inv]
@[to_additive]
theorem preimage_mul_right_one' : preimage 1 (· * b⁻¹) (mul_left_injective _).injOn = {b} := by
rw [preimage_mul_right_one, inv_inv]
end Group
section Monoid
variable [DecidableEq α] [DecidableEq β] [Monoid α] [Monoid β] [FunLike F α β]
@[to_additive]
lemma image_pow_of_ne_zero [MulHomClass F α β] :
∀ {n}, n ≠ 0 → ∀ (f : F) (s : Finset α), (s ^ n).image f = s.image f ^ n
| 1, _ => by simp
| n + 2, _ => by simp [image_mul, pow_succ _ n.succ, image_pow_of_ne_zero]
@[to_additive]
lemma image_pow [MonoidHomClass F α β] (f : F) (s : Finset α) : ∀ n, (s ^ n).image f = s.image f ^ n
| 0 => by simp [singleton_one]
| n + 1 => image_pow_of_ne_zero n.succ_ne_zero ..
end Monoid
section IsLeftCancelMul
variable [Mul α] [IsLeftCancelMul α] [DecidableEq α] {s t : Finset α} {a : α}
@[to_additive]
lemma Nontrivial.mul_left : t.Nontrivial → s.Nonempty → (s * t).Nontrivial := by
rintro ⟨a, ha, b, hb, hab⟩ ⟨c, hc⟩
exact ⟨c * a, mul_mem_mul hc ha, c * b, mul_mem_mul hc hb, by simpa⟩
@[to_additive]
lemma Nontrivial.mul (hs : s.Nontrivial) (ht : t.Nontrivial) : (s * t).Nontrivial :=
ht.mul_left hs.nonempty
@[to_additive (attr := simp)]
theorem card_singleton_mul (a : α) (t : Finset α) : #({a} * t) = #t :=
card_image₂_singleton_left _ <| mul_right_injective _
@[to_additive]
theorem singleton_mul_inter (a : α) (s t : Finset α) : {a} * (s ∩ t) = {a} * s ∩ ({a} * t) :=
image₂_singleton_inter _ _ <| mul_right_injective _
@[to_additive]
theorem card_le_card_mul_left {s : Finset α} (hs : s.Nonempty) : #t ≤ #(s * t) :=
have ⟨_, ha⟩ := hs; card_le_card_mul_left_of_injective ha (mul_right_injective _)
/--
The size of `s * s` is at least the size of `s`, version with left-cancellative multiplication.
See `card_le_card_mul_self'` for the version with right-cancellative multiplication.
-/
@[to_additive
/-- The size of `s + s` is at least the size of `s`, version with left-cancellative addition.
See `card_le_card_add_self'` for the version with right-cancellative addition. -/]
theorem card_le_card_mul_self {s : Finset α} : #s ≤ #(s * s) := by
cases s.eq_empty_or_nonempty <;> simp [card_le_card_mul_left, *]
end IsLeftCancelMul
section IsRightCancelMul
variable [Mul α] [IsRightCancelMul α] [DecidableEq α] {s t : Finset α} {a : α}
@[to_additive]
lemma Nontrivial.mul_right : s.Nontrivial → t.Nonempty → (s * t).Nontrivial := by
rintro ⟨a, ha, b, hb, hab⟩ ⟨c, hc⟩
exact ⟨a * c, mul_mem_mul ha hc, b * c, mul_mem_mul hb hc, by simpa⟩
@[to_additive (attr := simp)]
theorem card_mul_singleton (s : Finset α) (a : α) : #(s * {a}) = #s :=
card_image₂_singleton_right _ <| mul_left_injective _
@[to_additive]
theorem inter_mul_singleton (s t : Finset α) (a : α) : s ∩ t * {a} = s * {a} ∩ (t * {a}) :=
image₂_inter_singleton _ _ <| mul_left_injective _
@[to_additive]
theorem card_le_card_mul_right (ht : t.Nonempty) : #s ≤ #(s * t) :=
have ⟨_, ha⟩ := ht; card_le_card_mul_right_of_injective ha (mul_left_injective _)
/--
The size of `s * s` is at least the size of `s`, version with right-cancellative multiplication.
See `card_le_card_mul_self` for the version with left-cancellative multiplication.
-/
@[to_additive
/-- The size of `s + s` is at least the size of `s`, version with right-cancellative addition.
See `card_le_card_add_self` for the version with left-cancellative addition. -/]
theorem card_le_card_mul_self' : #s ≤ #(s * s) := by
cases s.eq_empty_or_nonempty <;> simp [card_le_card_mul_right, *]
end IsRightCancelMul
section CancelMonoid
variable [DecidableEq α] [CancelMonoid α] {s : Finset α} {m n : ℕ}
@[to_additive]
lemma Nontrivial.pow (hs : s.Nontrivial) : ∀ {n}, n ≠ 0 → (s ^ n).Nontrivial
| 1, _ => by simpa
| n + 2, _ => by simpa [pow_succ] using (hs.pow n.succ_ne_zero).mul hs
/-- See `Finset.card_pow_mono` for a version that works for the empty set. -/
@[to_additive /-- See `Finset.card_nsmul_mono` for a version that works for the empty set. -/]
protected lemma Nonempty.card_pow_mono (hs : s.Nonempty) : Monotone fun n : ℕ ↦ #(s ^ n) :=
monotone_nat_of_le_succ fun n ↦ by rw [pow_succ]; exact card_le_card_mul_right hs
/-- See `Finset.Nonempty.card_pow_mono` for a version that works for zero powers. -/
@[to_additive
/-- See `Finset.Nonempty.card_nsmul_mono` for a version that works for zero scalars. -/]
lemma card_pow_mono (hm : m ≠ 0) (hmn : m ≤ n) : #(s ^ m) ≤ #(s ^ n) := by
obtain rfl | hs := s.eq_empty_or_nonempty
· simp [hm]
· exact hs.card_pow_mono hmn
@[to_additive]
lemma card_le_card_pow (hn : n ≠ 0) : #s ≤ #(s ^ n) := by
simpa using card_pow_mono (s := s) one_ne_zero (Nat.one_le_iff_ne_zero.2 hn)
end CancelMonoid
section Group
variable [Group α] [DecidableEq α] {s t : Finset α}
@[to_additive] lemma card_le_card_div_left (hs : s.Nonempty) : #t ≤ #(s / t) :=
have ⟨_, ha⟩ := hs; card_le_card_image₂_left _ ha div_right_injective
@[to_additive] lemma card_le_card_div_right (ht : t.Nonempty) : #s ≤ #(s / t) :=
have ⟨_, ha⟩ := ht; card_le_card_image₂_right _ ha div_left_injective
@[to_additive] lemma card_le_card_div_self : #s ≤ #(s / s) := by
cases s.eq_empty_or_nonempty <;> simp [card_le_card_div_left, *]
end Group
end Finset
namespace Fintype
variable {ι : Type*} {α β : ι → Type*} [Fintype ι] [DecidableEq ι] [∀ i, DecidableEq (β i)]
[∀ i, DecidableEq (α i)]
@[to_additive]
lemma piFinset_mul [∀ i, Mul (α i)] (s t : ∀ i, Finset (α i)) :
piFinset (fun i ↦ s i * t i) = piFinset s * piFinset t := piFinset_image₂ _ _ _
@[to_additive]
lemma piFinset_div [∀ i, Div (α i)] (s t : ∀ i, Finset (α i)) :
piFinset (fun i ↦ s i / t i) = piFinset s / piFinset t := piFinset_image₂ _ _ _
@[to_additive (attr := simp)]
lemma piFinset_inv [∀ i, Inv (α i)] (s : ∀ i, Finset (α i)) :
piFinset (fun i ↦ (s i)⁻¹) = (piFinset s)⁻¹ := piFinset_image _ _
end Fintype
open Pointwise
namespace Set
section One
-- Redeclaring an instance for better keys
@[to_additive]
instance instFintypeOne [One α] : Fintype (1 : Set α) := Set.fintypeSingleton _
variable [One α]
@[to_additive (attr := simp)]
theorem toFinset_one : (1 : Set α).toFinset = 1 :=
rfl
-- should take simp priority over `Finite.toFinset_singleton`
@[to_additive (attr := simp high)]
theorem Finite.toFinset_one (h : (1 : Set α).Finite := finite_one) : h.toFinset = 1 :=
Finite.toFinset_singleton _
end One
section Mul
variable [DecidableEq α] [Mul α] {s t : Set α}
@[to_additive (attr := simp)]
theorem toFinset_mul (s t : Set α) [Fintype s] [Fintype t] [Fintype ↑(s * t)] :
(s * t).toFinset = s.toFinset * t.toFinset :=
toFinset_image2 _ _ _
@[to_additive]
theorem Finite.toFinset_mul (hs : s.Finite) (ht : t.Finite) (hf := hs.mul ht) :
hf.toFinset = hs.toFinset * ht.toFinset :=
Finite.toFinset_image2 _ _ _
end Mul
end Set |
.lake/packages/mathlib/Mathlib/Algebra/Group/Pointwise/Finset/BigOperators.lean | import Mathlib.Algebra.BigOperators.Group.Finset.Basic
import Mathlib.Algebra.Group.Pointwise.Finset.Basic
/-!
# Pointwise big operators on finsets
This file contains basic results on applying big operators (product and sum) on finsets.
## Implementation notes
We put all instances in the scope `Pointwise`, so that these instances are not available by
default. Note that we do not mark them as reducible (as argued by note [reducible non-instances])
since we expect the scope to be open whenever the instances are actually used (and making the
instances reducible changes the behavior of `simp`.
## Tags
finset multiplication, finset addition, pointwise addition, pointwise multiplication,
pointwise subtraction
-/
open scoped Pointwise
variable {α ι : Type*}
namespace Finset
section CommMonoid
variable [CommMonoid α]
variable [DecidableEq α]
@[to_additive (attr := simp, norm_cast)]
theorem coe_prod (s : Finset ι) (f : ι → Finset α) :
↑(∏ i ∈ s, f i) = ∏ i ∈ s, (f i : Set α) :=
map_prod ((coeMonoidHom) : Finset α →* Set α) _ _
omit [DecidableEq α]
variable [DecidableEq ι]
@[to_additive (attr := simp)] lemma prod_inv_index [InvolutiveInv ι] (s : Finset ι) (f : ι → α) :
∏ i ∈ s⁻¹, f i = ∏ i ∈ s, f i⁻¹ := prod_image inv_injective.injOn
@[to_additive existing, simp] lemma prod_neg_index [InvolutiveNeg ι] (s : Finset ι) (f : ι → α) :
∏ i ∈ -s, f i = ∏ i ∈ s, f (-i) := prod_image neg_injective.injOn
end CommMonoid
section AddCommMonoid
variable [AddCommMonoid α] [DecidableEq ι]
@[to_additive existing, simp] lemma sum_inv_index [InvolutiveInv ι] (s : Finset ι) (f : ι → α) :
∑ i ∈ s⁻¹, f i = ∑ i ∈ s, f i⁻¹ := sum_image inv_injective.injOn
end AddCommMonoid
end Finset |
.lake/packages/mathlib/Mathlib/Algebra/Group/Pointwise/Set/Finite.lean | import Mathlib.Algebra.Group.Pointwise.Set.Scalar
import Mathlib.Data.Finite.Prod
import Mathlib.Algebra.Group.Pointwise.Set.Basic
/-! # Finiteness lemmas for pointwise operations on sets -/
assert_not_exists MulAction MonoidWithZero
open Pointwise
variable {F α β γ : Type*}
namespace Set
section One
variable [One α]
@[to_additive (attr := simp)]
theorem finite_one : (1 : Set α).Finite :=
finite_singleton _
end One
section Mul
variable [Mul α] {s t : Set α}
@[to_additive]
theorem Finite.mul : s.Finite → t.Finite → (s * t).Finite :=
Finite.image2 _
/-- Multiplication preserves finiteness. -/
@[to_additive /-- Addition preserves finiteness. -/]
instance fintypeMul [DecidableEq α] (s t : Set α) [Fintype s] [Fintype t] : Fintype (s * t) :=
Set.fintypeImage2 _ _ _
end Mul
section Monoid
variable [Monoid α] {s t : Set α}
@[to_additive]
instance decidableMemMul [Fintype α] [DecidableEq α] [DecidablePred (· ∈ s)]
[DecidablePred (· ∈ t)] : DecidablePred (· ∈ s * t) := fun _ ↦ decidable_of_iff _ mem_mul.symm
@[to_additive]
instance decidableMemPow [Fintype α] [DecidableEq α] [DecidablePred (· ∈ s)] (n : ℕ) :
DecidablePred (· ∈ s ^ n) := by
induction n with
| zero =>
simp only [pow_zero, mem_one]
infer_instance
| succ n ih =>
rw [pow_succ]
infer_instance
end Monoid
section SMul
variable [SMul α β] {s : Set α} {t : Set β}
@[to_additive]
theorem Finite.smul : s.Finite → t.Finite → (s • t).Finite :=
Finite.image2 _
end SMul
section HasSMulSet
variable [SMul α β] {s : Set β} {a : α}
@[to_additive]
theorem Finite.smul_set : s.Finite → (a • s).Finite :=
Finite.image _
@[to_additive]
theorem Infinite.of_smul_set : (a • s).Infinite → s.Infinite :=
Infinite.of_image _
end HasSMulSet
section Vsub
variable [VSub α β] {s t : Set β}
theorem Finite.vsub (hs : s.Finite) (ht : t.Finite) : Set.Finite (s -ᵥ t) :=
hs.image2 _ ht
end Vsub
section Cancel
variable [Mul α] [IsLeftCancelMul α] [IsRightCancelMul α] {s t : Set α}
@[to_additive]
lemma finite_mul : (s * t).Finite ↔ s.Finite ∧ t.Finite ∨ s = ∅ ∨ t = ∅ :=
finite_image2 (fun _ _ ↦ (mul_left_injective _).injOn) fun _ _ ↦ (mul_right_injective _).injOn
@[to_additive]
lemma infinite_mul : (s * t).Infinite ↔ s.Infinite ∧ t.Nonempty ∨ t.Infinite ∧ s.Nonempty :=
infinite_image2 (fun _ _ => (mul_left_injective _).injOn) fun _ _ => (mul_right_injective _).injOn
end Cancel
section InvolutiveInv
variable [InvolutiveInv α] {s : Set α}
@[to_additive (attr := simp)] lemma finite_inv : s⁻¹.Finite ↔ s.Finite := by
rw [← image_inv_eq_inv, finite_image_iff inv_injective.injOn]
@[to_additive (attr := simp)] lemma infinite_inv : s⁻¹.Infinite ↔ s.Infinite := finite_inv.not
@[to_additive] alias ⟨Finite.of_inv, Finite.inv⟩ := finite_inv
end InvolutiveInv
section Div
variable [Div α] {s t : Set α}
@[to_additive] lemma Finite.div : s.Finite → t.Finite → (s / t).Finite := .image2 _
/-- Division preserves finiteness. -/
@[to_additive /-- Subtraction preserves finiteness. -/]
instance fintypeDiv [DecidableEq α] (s t : Set α) [Fintype s] [Fintype t] : Fintype (s / t) :=
Set.fintypeImage2 _ _ _
end Div
section Group
variable [Group α] {s t : Set α}
@[to_additive]
lemma finite_div : (s / t).Finite ↔ s.Finite ∧ t.Finite ∨ s = ∅ ∨ t = ∅ :=
finite_image2 (fun _ _ ↦ div_left_injective.injOn) fun _ _ ↦ div_right_injective.injOn
@[to_additive]
lemma infinite_div : (s / t).Infinite ↔ s.Infinite ∧ t.Nonempty ∨ t.Infinite ∧ s.Nonempty :=
infinite_image2 (fun _ _ ↦ div_left_injective.injOn) fun _ _ ↦ div_right_injective.injOn
end Group
end Set
open Set
namespace Group
variable {G : Type*} [Group G] [Fintype G] (S : Set G)
@[to_additive]
theorem card_pow_eq_card_pow_card_univ [∀ k : ℕ, DecidablePred (· ∈ S ^ k)] :
∀ k, Fintype.card G ≤ k → Fintype.card (↥(S ^ k)) = Fintype.card (↥(S ^ Fintype.card G)) := by
have hG : 0 < Fintype.card G := Fintype.card_pos
rcases S.eq_empty_or_nonempty with (rfl | ⟨a, ha⟩)
· refine fun k hk ↦ Fintype.card_congr ?_
rw [empty_pow (hG.trans_le hk).ne', empty_pow (ne_of_gt hG)]
have key : ∀ (a) (s t : Set G) [Fintype s] [Fintype t],
(∀ b : G, b ∈ s → b * a ∈ t) → Fintype.card s ≤ Fintype.card t := by
refine fun a s t _ _ h ↦ Fintype.card_le_of_injective (fun ⟨b, hb⟩ ↦ ⟨b * a, h b hb⟩) ?_
rintro ⟨b, hb⟩ ⟨c, hc⟩ hbc
exact Subtype.ext (mul_right_cancel (Subtype.ext_iff.mp hbc))
have mono : Monotone (fun n ↦ Fintype.card (↥(S ^ n)) : ℕ → ℕ) :=
monotone_nat_of_le_succ fun n ↦ key a _ _ fun b hb ↦ Set.mul_mem_mul hb ha
refine fun _ ↦ Nat.stabilises_of_monotone mono (fun n ↦ set_fintype_card_le_univ (S ^ n))
fun n h ↦ le_antisymm (mono (n + 1).le_succ) (key a⁻¹ (S ^ (n + 2)) (S ^ (n + 1)) ?_)
replace h₂ : S ^ n * {a} = S ^ (n + 1) := by
have : Fintype (S ^ n * Set.singleton a) := by
classical
apply fintypeMul
refine Set.eq_of_subset_of_card_le ?_ (le_trans (ge_of_eq h) ?_)
· exact mul_subset_mul Set.Subset.rfl (Set.singleton_subset_iff.mpr ha)
· convert key a (S ^ n) (S ^ n * {a}) fun b hb ↦ Set.mul_mem_mul hb (Set.mem_singleton a)
rw [pow_succ', ← h₂, ← mul_assoc, ← pow_succ', h₂, mul_singleton, forall_mem_image]
intro x hx
rwa [mul_inv_cancel_right]
end Group |
.lake/packages/mathlib/Mathlib/Algebra/Group/Pointwise/Set/Card.lean | import Mathlib.Algebra.Group.Action.Basic
import Mathlib.Algebra.Group.Pointwise.Set.Finite
import Mathlib.Data.Set.Card
/-!
# Cardinalities of pointwise operations on sets
-/
assert_not_exists Field
open scoped Cardinal Pointwise
namespace Set
variable {G M α : Type*}
section Mul
variable [Mul M] {s t : Set M}
@[to_additive]
lemma _root_.Cardinal.mk_mul_le : #(s * t) ≤ #s * #t := by
rw [← image2_mul]; exact Cardinal.mk_image2_le
variable [IsCancelMul M]
@[to_additive]
lemma natCard_mul_le : Nat.card (s * t) ≤ Nat.card s * Nat.card t := by
obtain h | h := (s * t).infinite_or_finite
· simp [Set.Infinite.card_eq_zero h]
simp only [Nat.card, ← Cardinal.toNat_mul]
refine Cardinal.toNat_le_toNat Cardinal.mk_mul_le ?_
aesop (add simp [Cardinal.mul_lt_aleph0_iff, finite_mul])
end Mul
section InvolutiveInv
variable [InvolutiveInv G]
@[to_additive (attr := simp)]
lemma _root_.Cardinal.mk_inv (s : Set G) : #↥(s⁻¹) = #s := by
rw [← image_inv_eq_inv, Cardinal.mk_image_eq_of_injOn _ _ inv_injective.injOn]
@[to_additive (attr := simp)]
lemma encard_inv (s : Set G) : s⁻¹.encard = s.encard := by
simp [← toENat_cardinalMk]
@[to_additive (attr := simp)]
lemma ncard_inv (s : Set G) : s⁻¹.ncard = s.ncard := by simp [ncard]
@[to_additive]
lemma natCard_inv (s : Set G) : Nat.card ↥(s⁻¹) = Nat.card s := by simp
end InvolutiveInv
section DivInvMonoid
variable [DivInvMonoid M] {s t : Set M}
@[to_additive]
lemma _root_.Cardinal.mk_div_le : #(s / t) ≤ #s * #t := by
rw [← image2_div]; exact Cardinal.mk_image2_le
end DivInvMonoid
section Group
variable [Group G] {s t : Set G}
@[to_additive]
lemma natCard_div_le : Nat.card (s / t) ≤ Nat.card s * Nat.card t := by
rw [div_eq_mul_inv, ← natCard_inv t]; exact natCard_mul_le
variable [MulAction G α]
@[to_additive (attr := simp)]
lemma _root_.Cardinal.mk_smul_set (a : G) (s : Set α) : #↥(a • s) = #s :=
Cardinal.mk_image_eq_of_injOn _ _ (MulAction.injective a).injOn
@[to_additive (attr := simp)]
lemma encard_smul_set (a : G) (s : Set α) : (a • s).encard = s.encard := by
simp [← toENat_cardinalMk]
@[to_additive (attr := simp)]
lemma ncard_smul_set (a : G) (s : Set α) : (a • s).ncard = s.ncard := by simp [ncard]
@[to_additive]
lemma natCard_smul_set (a : G) (s : Set α) : Nat.card ↥(a • s) = Nat.card s := by
simp
end Group
end Set |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.