File: Mathlib/NumberTheory/MulChar/Basic.lean

full_name: MulChar
code: /-- Define a structure for multiplicative characters.
A multiplicative character from a commutative monoid `R` to a commutative monoid with zero `R'`
is a homomorphism of (multiplicative) monoids that sends non-units to zero. -/
structure MulChar extends MonoidHom R R' where
  map_nonunit' : ∀ a : R, ¬IsUnit a → toFun a = 0
goal: Type (max u_1 u_2)

full_name: MulChar.map_nonunit'
code: /-- Define a structure for multiplicative characters.
A multiplicative character from a commutative monoid `R` to a commutative monoid with zero `R'`
is a homomorphism of (multiplicative) monoids that sends non-units to zero. -/
structure MulChar extends MonoidHom R R' where
  map_nonunit' : ∀ a : R, ¬IsUnit a → toFun a = 0
goal: ¬IsUnit a → (↑self.toMonoidHom).toFun a = 0

full_name: MulChar.instFunLike
code: instance MulChar.instFunLike : FunLike (MulChar R R') R R' 
goal: FunLike (MulChar R R') R R'

full_name: MulCharClass
code: /-- This is the corresponding extension of `MonoidHomClass`. -/
class MulCharClass (F : Type*) (R R' : outParam Type*) [CommMonoid R]
  [CommMonoidWithZero R'] [FunLike F R R'] extends MonoidHomClass F R R' : Prop where
  map_nonunit : ∀ (χ : F) {a : R} (_ : ¬IsUnit a), χ a = 0
goal: Prop

full_name: MulCharClass.map_nonunit
code: /-- This is the corresponding extension of `MonoidHomClass`. -/
class MulCharClass (F : Type*) (R R' : outParam Type*) [CommMonoid R]
  [CommMonoidWithZero R'] [FunLike F R R'] extends MonoidHomClass F R R' : Prop where
  map_nonunit : ∀ (χ : F) {a : R} (_ : ¬IsUnit a), χ a = 0
goal: ¬IsUnit a → χ a = 0

full_name: MulChar.trivial
code: /-- The trivial multiplicative character. It takes the value `0` on non-units and
the value `1` on units. -/
@[simps]
noncomputable def trivial : MulChar R R' 
goal: MulChar R R'

full_name: MulChar.trivial_apply
code: /-- The trivial multiplicative character. It takes the value `0` on non-units and
the value `1` on units. -/
@[simps]
noncomputable def trivial : MulChar R R' 
goal: (MulChar.trivial R R') x = if IsUnit x then 1 else 0

full_name: MulChar.coe_mk
code: @[simp]
theorem coe_mk (f : R →* R') (hf) : (MulChar.mk f hf : R → R') = f 
goal: ⇑{ toMonoidHom := f, map_nonunit' := hf } = ⇑f

full_name: MulChar.ext'
code: /-- Extensionality. See `ext` below for the version that will actually be used. -/
theorem ext' {χ χ' : MulChar R R'} (h : ∀ a, χ a = χ' a) : χ = χ' 
goal: χ = χ'

full_name: MulChar.instMulCharClass
code: instance : MulCharClass (MulChar R R') R R' 
goal: MulCharClass (MulChar R R') R R'

full_name: MulChar.map_nonunit
code: theorem map_nonunit (χ : MulChar R R') {a : R} (ha : ¬IsUnit a) : χ a = 0 
goal: χ a = 0

full_name: MulChar.ext
code: /-- Extensionality. Since `MulChar`s always take the value zero on non-units, it is sufficient
to compare the values on units. -/
@[ext]
theorem ext {χ χ' : MulChar R R'} (h : ∀ a : Rˣ, χ a = χ' a) : χ = χ' 
goal: χ = χ'

full_name: MulChar.ext_iff
code: theorem ext_iff {χ χ' : MulChar R R'} : χ = χ' ↔ ∀ a : Rˣ, χ a = χ' a 
goal: χ = χ' ↔ ∀ (a : Rˣ), χ ↑a = χ' ↑a

full_name: MulChar.toUnitHom
code: /-- Turn a `MulChar` into a homomorphism between the unit groups. -/
def toUnitHom (χ : MulChar R R') : Rˣ →* R'ˣ 
goal: Rˣ →* R'ˣ

full_name: MulChar.coe_toUnitHom
code: theorem coe_toUnitHom (χ : MulChar R R') (a : Rˣ) : ↑(χ.toUnitHom a) = χ a 
goal: ↑(χ.toUnitHom a) = χ ↑a

full_name: MulChar.ofUnitHom
code: /-- Turn a homomorphism between unit groups into a `MulChar`. -/
noncomputable def ofUnitHom (f : Rˣ →* R'ˣ) : MulChar R R' 
goal: MulChar R R'

full_name: MulChar.ofUnitHom_coe
code: theorem ofUnitHom_coe (f : Rˣ →* R'ˣ) (a : Rˣ) : ofUnitHom f ↑a = f a 
goal: (MulChar.ofUnitHom f) ↑a = ↑(f a)

full_name: MulChar.equivToUnitHom
code: /-- The equivalence between multiplicative characters and homomorphisms of unit groups. -/
noncomputable def equivToUnitHom : MulChar R R' ≃ (Rˣ →* R'ˣ) 
goal: MulChar R R' ≃ (Rˣ →* R'ˣ)

full_name: MulChar.toUnitHom_eq
code: @[simp]
theorem toUnitHom_eq (χ : MulChar R R') : toUnitHom χ = equivToUnitHom χ 
goal: χ.toUnitHom = MulChar.equivToUnitHom χ

full_name: MulChar.ofUnitHom_eq
code: @[simp]
theorem ofUnitHom_eq (χ : Rˣ →* R'ˣ) : ofUnitHom χ = equivToUnitHom.symm χ 
goal: MulChar.ofUnitHom χ = MulChar.equivToUnitHom.symm χ

full_name: MulChar.coe_equivToUnitHom
code: @[simp]
theorem coe_equivToUnitHom (χ : MulChar R R') (a : Rˣ) : ↑(equivToUnitHom χ a) = χ a 
goal: ↑((MulChar.equivToUnitHom χ) a) = χ ↑a

full_name: MulChar.equivToUnitHom_symm_coe
code: @[simp]
theorem equivToUnitHom_symm_coe (f : Rˣ →* R'ˣ) (a : Rˣ) : equivToUnitHom.symm f ↑a = f a 
goal: (MulChar.equivToUnitHom.symm f) ↑a = ↑(f a)

full_name: MulChar.coe_toMonoidHom
code: @[simp]
lemma coe_toMonoidHom [CommMonoid R] (χ : MulChar R R')
    (x : R) : χ.toMonoidHom x = χ x 
goal: χ.toMonoidHom x = χ x

full_name: MulChar.map_one
code: protected theorem map_one (χ : MulChar R R') : χ (1 : R) = 1 
goal: χ 1 = 1

full_name: MulChar.map_zero
code: /-- If the domain has a zero (and is nontrivial), then `χ 0 = 0`. -/
protected theorem map_zero {R : Type*} [CommMonoidWithZero R] [Nontrivial R] (χ : MulChar R R') :
    χ (0 : R) = 0 
goal: χ 0 = 0

full_name: MulChar.toMonoidWithZeroHom_apply
code: /-- We can convert a multiplicative character into a homomorphism of monoids with zero when
the source has a zero and another element. -/
@[coe, simps]
def toMonoidWithZeroHom {R : Type*} [CommMonoidWithZero R] [Nontrivial R] (χ : MulChar R R') :
    R →*₀ R' 
goal: ∀ (a : R), ↑χ a = (↑χ.toMonoidHom).toFun a

full_name: MulChar.toMonoidWithZeroHom
code: /-- We can convert a multiplicative character into a homomorphism of monoids with zero when
the source has a zero and another element. -/
@[coe, simps]
def toMonoidWithZeroHom {R : Type*} [CommMonoidWithZero R] [Nontrivial R] (χ : MulChar R R') :
    R →*₀ R' 
goal: R →*₀ R'

full_name: MulChar.map_ringChar
code: /-- If the domain is a ring `R`, then `χ (ringChar R) = 0`. -/
theorem map_ringChar {R : Type*} [CommRing R] [Nontrivial R] (χ : MulChar R R') :
    χ (ringChar R) = 0 
goal: χ ↑(ringChar R) = 0

full_name: MulChar.hasOne
code: noncomputable instance hasOne : One (MulChar R R') 
goal: One (MulChar R R')

full_name: MulChar.inhabited
code: noncomputable instance inhabited : Inhabited (MulChar R R') 
goal: Inhabited (MulChar R R')

full_name: MulChar.one_apply_coe
code: /-- Evaluation of the trivial character -/
@[simp]
theorem one_apply_coe (a : Rˣ) : (1 : MulChar R R') a = 1 
goal: 1 ↑a = 1

full_name: MulChar.one_apply
code: /-- Evaluation of the trivial character -/
lemma one_apply {x : R} (hx : IsUnit x) : (1 : MulChar R R') x = 1 
goal: 1 x = 1

full_name: MulChar.mul
code: /-- Multiplication of multiplicative characters. (This needs the target to be commutative.) -/
def mul (χ χ' : MulChar R R') : MulChar R R' 
goal: MulChar R R'

full_name: MulChar.hasMul
code: instance hasMul : Mul (MulChar R R') 
goal: Mul (MulChar R R')

full_name: MulChar.mul_apply
code: theorem mul_apply (χ χ' : MulChar R R') (a : R) : (χ * χ') a = χ a * χ' a 
goal: (χ * χ') a = χ a * χ' a

full_name: MulChar.coeToFun_mul
code: @[simp]
theorem coeToFun_mul (χ χ' : MulChar R R') : ⇑(χ * χ') = χ * χ' 
goal: ⇑(χ * χ') = ⇑χ * ⇑χ'

full_name: MulChar.one_mul
code: protected theorem one_mul (χ : MulChar R R') : (1 : MulChar R R') * χ = χ 
goal: 1 * χ = χ

full_name: MulChar.mul_one
code: protected theorem mul_one (χ : MulChar R R') : χ * 1 = χ 
goal: χ * 1 = χ

full_name: MulChar.inv
code: /-- The inverse of a multiplicative character. We define it as `inverse ∘ χ`. -/
noncomputable def inv (χ : MulChar R R') : MulChar R R' 
goal: MulChar R R'

full_name: MulChar.hasInv
code: noncomputable instance hasInv : Inv (MulChar R R') 
goal: Inv (MulChar R R')

full_name: MulChar.inv_apply_eq_inv
code: /-- The inverse of a multiplicative character `χ`, applied to `a`, is the inverse of `χ a`. -/
theorem inv_apply_eq_inv (χ : MulChar R R') (a : R) : χ⁻¹ a = Ring.inverse (χ a) 
goal: χ⁻¹ a = Ring.inverse (χ a)

full_name: MulChar.inv_apply_eq_inv'
code: /-- The inverse of a multiplicative character `χ`, applied to `a`, is the inverse of `χ a`.
Variant when the target is a field -/
theorem inv_apply_eq_inv' {R' : Type*} [Field R'] (χ : MulChar R R') (a : R) : χ⁻¹ a = (χ a)⁻¹ 
goal: χ⁻¹ a = (χ a)⁻¹

full_name: MulChar.inv_apply
code: /-- When the domain has a zero, then the inverse of a multiplicative character `χ`,
applied to `a`, is `χ` applied to the inverse of `a`. -/
theorem inv_apply {R : Type*} [CommMonoidWithZero R] (χ : MulChar R R') (a : R) :
    χ⁻¹ a = χ (Ring.inverse a) 
goal: χ⁻¹ a = χ (Ring.inverse a)

full_name: MulChar.inv_apply'
code: /-- When the domain has a zero, then the inverse of a multiplicative character `χ`,
applied to `a`, is `χ` applied to the inverse of `a`. -/
theorem inv_apply' {R : Type*} [Field R] (χ : MulChar R R') (a : R) : χ⁻¹ a = χ a⁻¹ 
goal: χ⁻¹ a = χ a⁻¹

full_name: MulChar.inv_mul
code: /-- The product of a character with its inverse is the trivial character. -/
-- Porting note (#10618): @[simp] can prove this (later)
theorem inv_mul (χ : MulChar R R') : χ⁻¹ * χ = 1 
goal: χ⁻¹ * χ = 1

full_name: MulChar.commGroup
code: /-- The commutative group structure on `MulChar R R'`. -/
noncomputable instance commGroup : CommGroup (MulChar R R') 
goal: CommGroup (MulChar R R')

full_name: MulChar.pow_apply_coe
code: /-- If `a` is a unit and `n : ℕ`, then `(χ ^ n) a = (χ a) ^ n`. -/
theorem pow_apply_coe (χ : MulChar R R') (n : ℕ) (a : Rˣ) : (χ ^ n) a = χ a ^ n 
goal: (χ ^ n) ↑a = χ ↑a ^ n

full_name: MulChar.pow_apply'
code: /-- If `n` is positive, then `(χ ^ n) a = (χ a) ^ n`. -/
theorem pow_apply' (χ : MulChar R R') {n : ℕ} (hn : n ≠ 0) (a : R) : (χ ^ n) a = χ a ^ n 
goal: (χ ^ n) a = χ a ^ n

full_name: MulChar.equivToUnitHom_mul_apply
code: lemma equivToUnitHom_mul_apply (χ₁ χ₂ : MulChar R R') (a : Rˣ) :
    equivToUnitHom (χ₁ * χ₂) a = equivToUnitHom χ₁ a * equivToUnitHom χ₂ a 
goal: (MulChar.equivToUnitHom (χ₁ * χ₂)) a = (MulChar.equivToUnitHom χ₁) a * (MulChar.equivToUnitHom χ₂) a

full_name: MulChar.mulEquivToUnitHom
code: /-- The equivalence between multiplicative characters and homomorphisms of unit groups
as a multiplicative equivalence. -/
noncomputable
def mulEquivToUnitHom : MulChar R R' ≃* (Rˣ →* R'ˣ) 
goal: MulChar R R' ≃* (Rˣ →* R'ˣ)

full_name: MulChar.eq_one_iff
code: lemma eq_one_iff {χ : MulChar R R'} : χ = 1 ↔ ∀ a : Rˣ, χ a = 1 
goal: χ = 1 ↔ ∀ (a : Rˣ), χ ↑a = 1

full_name: MulChar.ne_one_iff
code: lemma ne_one_iff {χ : MulChar R R'} : χ ≠ 1 ↔ ∃ a : Rˣ, χ a ≠ 1 
goal: χ ≠ 1 ↔ ∃ a, χ ↑a ≠ 1

full_name: MulChar.IsNontrivial
code: /-- A multiplicative character is *nontrivial* if it takes a value `≠ 1` on a unit. -/
@[deprecated (since := "2024-06-16")]
def IsNontrivial (χ : MulChar R R') : Prop 
goal: Prop

full_name: MulChar.isNontrivial_iff
code: /-- A multiplicative character is nontrivial iff it is not the trivial character. -/
@[deprecated (since := "2024-06-16")]
theorem isNontrivial_iff (χ : MulChar R R') : χ.IsNontrivial ↔ χ ≠ 1 
goal: χ.IsNontrivial ↔ χ ≠ 1

full_name: MulChar.IsQuadratic
code: /-- A multiplicative character is *quadratic* if it takes only the values `0`, `1`, `-1`. -/
def IsQuadratic (χ : MulChar R R') : Prop 
goal: Prop

full_name: MulChar.IsQuadratic.eq_of_eq_coe
code: /-- If two values of quadratic characters with target `ℤ` agree after coercion into a ring
of characteristic not `2`, then they agree in `ℤ`. -/
theorem IsQuadratic.eq_of_eq_coe {χ : MulChar R ℤ} (hχ : IsQuadratic χ) {χ' : MulChar R' ℤ}
    (hχ' : IsQuadratic χ') [Nontrivial R''] (hR'' : ringChar R'' ≠ 2) {a : R} {a' : R'}
    (h : (χ a : R'') = χ' a') : χ a = χ' a' 
goal: χ a = χ' a'

full_name: MulChar.ringHomComp
code: /-- We can post-compose a multiplicative character with a ring homomorphism. -/
@[simps]
def ringHomComp (χ : MulChar R R') (f : R' →+* R'') : MulChar R R'' 
goal: MulChar R R''

full_name: MulChar.ringHomComp_apply
code: /-- We can post-compose a multiplicative character with a ring homomorphism. -/
@[simps]
def ringHomComp (χ : MulChar R R') (f : R' →+* R'') : MulChar R R'' 
goal: (χ.ringHomComp f) a = f (χ a)

full_name: MulChar.ringHomComp_one
code: @[simp]
lemma ringHomComp_one (f : R' →+* R'') : (1 : MulChar R R').ringHomComp f = 1 
goal: MulChar.ringHomComp 1 f = 1

full_name: MulChar.ringHomComp_inv
code: lemma ringHomComp_inv {R : Type*} [CommRing R] (χ : MulChar R R') (f : R' →+* R'') :
    (χ.ringHomComp f)⁻¹ = χ⁻¹.ringHomComp f 
goal: (χ.ringHomComp f)⁻¹ = χ⁻¹.ringHomComp f

full_name: MulChar.ringHomComp_mul
code: lemma ringHomComp_mul (χ φ : MulChar R R') (f : R' →+* R'') :
    (χ * φ).ringHomComp f = χ.ringHomComp f * φ.ringHomComp f 
goal: (χ * φ).ringHomComp f = χ.ringHomComp f * φ.ringHomComp f

full_name: MulChar.ringHomComp_pow
code: lemma ringHomComp_pow (χ : MulChar R R') (f : R' →+* R'') (n : ℕ) :
    χ.ringHomComp f ^ n = (χ ^ n).ringHomComp f 
goal: χ.ringHomComp f ^ n = (χ ^ n).ringHomComp f

full_name: MulChar.injective_ringHomComp
code: lemma injective_ringHomComp {f : R' →+* R''} (hf : Function.Injective f) :
    Function.Injective (ringHomComp (R := R) · f) 
goal: Function.Injective fun x => x.ringHomComp f

full_name: MulChar.ringHomComp_eq_one_iff
code: lemma ringHomComp_eq_one_iff {f : R' →+* R''} (hf : Function.Injective f) {χ : MulChar R R'} :
    χ.ringHomComp f = 1 ↔ χ = 1 
goal: χ.ringHomComp f = 1 ↔ χ = 1

full_name: MulChar.ringHomComp_ne_one_iff
code: lemma ringHomComp_ne_one_iff {f : R' →+* R''} (hf : Function.Injective f) {χ : MulChar R R'} :
    χ.ringHomComp f ≠ 1 ↔ χ ≠ 1 
goal: χ.ringHomComp f ≠ 1 ↔ χ ≠ 1

full_name: MulChar.IsNontrivial.comp
code: /-- Composition with an injective ring homomorphism preserves nontriviality. -/
@[deprecated ringHomComp_ne_one_iff (since := "2024-06-16")]
theorem IsNontrivial.comp {χ : MulChar R R'} (hχ : χ.IsNontrivial) {f : R' →+* R''}
    (hf : Function.Injective f) : (χ.ringHomComp f).IsNontrivial 
goal: (χ.ringHomComp f).IsNontrivial

full_name: MulChar.IsQuadratic.comp
code: /-- Composition with a ring homomorphism preserves the property of being a quadratic character. -/
theorem IsQuadratic.comp {χ : MulChar R R'} (hχ : χ.IsQuadratic) (f : R' →+* R'') :
    (χ.ringHomComp f).IsQuadratic 
goal: (χ.ringHomComp f).IsQuadratic

full_name: MulChar.IsQuadratic.inv
code: /-- The inverse of a quadratic character is itself. →  -/
theorem IsQuadratic.inv {χ : MulChar R R'} (hχ : χ.IsQuadratic) : χ⁻¹ = χ 
goal: χ⁻¹ = χ

full_name: MulChar.IsQuadratic.sq_eq_one
code: /-- The square of a quadratic character is the trivial character. -/
theorem IsQuadratic.sq_eq_one {χ : MulChar R R'} (hχ : χ.IsQuadratic) : χ ^ 2 = 1 
goal: χ ^ 2 = 1

full_name: MulChar.IsQuadratic.pow_char
code: /-- The `p`th power of a quadratic character is itself, when `p` is the (prime) characteristic
of the target ring. -/
theorem IsQuadratic.pow_char {χ : MulChar R R'} (hχ : χ.IsQuadratic) (p : ℕ) [hp : Fact p.Prime]
    [CharP R' p] : χ ^ p = χ 
goal: χ ^ p = χ

full_name: MulChar.IsQuadratic.pow_even
code: /-- The `n`th power of a quadratic character is the trivial character, when `n` is even. -/
theorem IsQuadratic.pow_even {χ : MulChar R R'} (hχ : χ.IsQuadratic) {n : ℕ} (hn : Even n) :
    χ ^ n = 1 
goal: χ ^ n = 1

full_name: MulChar.IsQuadratic.pow_odd
code: /-- The `n`th power of a quadratic character is itself, when `n` is odd. -/
theorem IsQuadratic.pow_odd {χ : MulChar R R'} (hχ : χ.IsQuadratic) {n : ℕ} (hn : Odd n) :
    χ ^ n = χ 
goal: χ ^ n = χ

full_name: MulChar.pow_card_eq_one
code: /-- If `χ` is a multiplicative character on a commutative monoid `M` with finitely many units,
then `χ ^ #Mˣ = 1`. -/
protected lemma pow_card_eq_one [Fintype Mˣ] (χ : MulChar M R) : χ ^ (Fintype.card Mˣ) = 1 
goal: χ ^ Fintype.card Mˣ = 1

full_name: MulChar.orderOf_pos
code: /-- A multiplicative character on a commutative monoid with finitely many units
has finite (= positive) order. -/
lemma orderOf_pos [Finite Mˣ] (χ : MulChar M R) : 0 < orderOf χ 
goal: 0 < orderOf χ

full_name: MulChar.sum_eq_zero_of_ne_one
code: /-- The sum over all values of a nontrivial multiplicative character on a finite ring is zero
(when the target is a domain). -/
theorem sum_eq_zero_of_ne_one [IsDomain R'] {χ : MulChar R R'} (hχ : χ ≠ 1) : ∑ a, χ a = 0 
goal: ∑ a : R, χ a = 0

full_name: MulChar.IsNontrivial.sum_eq_zero
code: @[deprecated (since := "2024-06-16")]
lemma IsNontrivial.sum_eq_zero [IsDomain R'] {χ : MulChar R R'} (hχ : χ.IsNontrivial) :
    ∑ a, χ a = 0 
goal: ∑ a : R, χ a = 0

full_name: MulChar.sum_one_eq_card_units
code: /-- The sum over all values of the trivial multiplicative character on a finite ring is
the cardinality of its unit group. -/
theorem sum_one_eq_card_units [DecidableEq R] :
    (∑ a, (1 : MulChar R R') a) = Fintype.card Rˣ 
goal: ∑ a : R, 1 a = ↑(Fintype.card Rˣ)

full_name: MulChar.val_neg_one_eq_one_of_odd_order
code: /-- If `χ` is of odd order, then `χ(-1) = 1` -/
lemma val_neg_one_eq_one_of_odd_order {χ : MulChar R R'} {n : ℕ} (hn : Odd n) (hχ : χ ^ n = 1) :
    χ (-1) = 1 
goal: χ (-1) = 1