l3lab/ntp-mathlib huggingface dataset:
/-- 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 := by
  

Proof state:
R : Type u
inst✝² : CommRing R
R' : Type v
inst✝¹ : CommRing R'
R'' : Type w
inst✝ : CommRing R''
χ : MulChar R R'
hχ : IsQuadratic χ
f : R' →+* R''
⊢ IsQuadratic (ringHomComp χ f)

Next tactic:
intro a
/-- 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 := by
  intro a
  

Proof state:
R : Type u
inst✝² : CommRing R
R' : Type v
inst✝¹ : CommRing R'
R'' : Type w
inst✝ : CommRing R''
χ : MulChar R R'
hχ : IsQuadratic χ
f : R' →+* R''
a : R
⊢ (ringHomComp χ f) a = 0 ∨ (ringHomComp χ f) a = 1 ∨ (ringHomComp χ f) a = -1

Next tactic:
rcases hχ a with (ha | ha | ha)
/-- 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 := by
  intro a
  rcases hχ a with (ha | ha | ha) <;> 

Proof state:
case inl
R : Type u
inst✝² : CommRing R
R' : Type v
inst✝¹ : CommRing R'
R'' : Type w
inst✝ : CommRing R''
χ : MulChar R R'
hχ : IsQuadratic χ
f : R' →+* R''
a : R
ha : χ a = 0
⊢ (ringHomComp χ f) a = 0 ∨ (ringHomComp χ f) a = 1 ∨ (ringHomComp χ f) a = -1

Next tactic:
simp [ha]
/-- 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 := by
  intro a
  rcases hχ a with (ha | ha | ha) <;> 

Proof state:
case inr.inl
R : Type u
inst✝² : CommRing R
R' : Type v
inst✝¹ : CommRing R'
R'' : Type w
inst✝ : CommRing R''
χ : MulChar R R'
hχ : IsQuadratic χ
f : R' →+* R''
a : R
ha : χ a = 1
⊢ (ringHomComp χ f) a = 0 ∨ (ringHomComp χ f) a = 1 ∨ (ringHomComp χ f) a = -1

Next tactic:
simp [ha]
/-- 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 := by
  intro a
  rcases hχ a with (ha | ha | ha) <;> 

Proof state:
case inr.inr
R : Type u
inst✝² : CommRing R
R' : Type v
inst✝¹ : CommRing R'
R'' : Type w
inst✝ : CommRing R''
χ : MulChar R R'
hχ : IsQuadratic χ
f : R' →+* R''
a : R
ha : χ a = -1
⊢ (ringHomComp χ f) a = 0 ∨ (ringHomComp χ f) a = 1 ∨ (ringHomComp χ f) a = -1

Next tactic:
simp [ha]
/-- The inverse of a quadratic character is itself. →  -/
theorem IsQuadratic.inv {χ : MulChar R R'} (hχ : χ.IsQuadratic) : χ⁻¹ = χ := by
  

Proof state:
R : Type u
inst✝² : CommRing R
R' : Type v
inst✝¹ : CommRing R'
R'' : Type w
inst✝ : CommRing R''
χ : MulChar R R'
hχ : IsQuadratic χ
⊢ χ⁻¹ = χ

Next tactic:
ext x
/-- The inverse of a quadratic character is itself. →  -/
theorem IsQuadratic.inv {χ : MulChar R R'} (hχ : χ.IsQuadratic) : χ⁻¹ = χ := by
  ext x
  

Proof state:
case h
R : Type u
inst✝² : CommRing R
R' : Type v
inst✝¹ : CommRing R'
R'' : Type w
inst✝ : CommRing R''
χ : MulChar R R'
hχ : IsQuadratic χ
x : Rˣ
⊢ χ⁻¹ ↑x = χ ↑x

Next tactic:
rw [inv_apply_eq_inv]
/-- The inverse of a quadratic character is itself. →  -/
theorem IsQuadratic.inv {χ : MulChar R R'} (hχ : χ.IsQuadratic) : χ⁻¹ = χ := by
  ext x
  rw [inv_apply_eq_inv]
  

Proof state:
case h
R : Type u
inst✝² : CommRing R
R' : Type v
inst✝¹ : CommRing R'
R'' : Type w
inst✝ : CommRing R''
χ : MulChar R R'
hχ : IsQuadratic χ
x : Rˣ
⊢ Ring.inverse (χ ↑x) = χ ↑x

Next tactic:
rcases hχ x with (h₀ | h₁ | h₂)
/-- The inverse of a quadratic character is itself. →  -/
theorem IsQuadratic.inv {χ : MulChar R R'} (hχ : χ.IsQuadratic) : χ⁻¹ = χ := by
  ext x
  rw [inv_apply_eq_inv]
  rcases hχ x with (h₀ | h₁ | h₂)
  · 

Proof state:
case h.inl
R : Type u
inst✝² : CommRing R
R' : Type v
inst✝¹ : CommRing R'
R'' : Type w
inst✝ : CommRing R''
χ : MulChar R R'
hχ : IsQuadratic χ
x : Rˣ
h₀ : χ ↑x = 0
⊢ Ring.inverse (χ ↑x) = χ ↑x

Next tactic:
rw [h₀, Ring.inverse_zero]
/-- The inverse of a quadratic character is itself. →  -/
theorem IsQuadratic.inv {χ : MulChar R R'} (hχ : χ.IsQuadratic) : χ⁻¹ = χ := by
  ext x
  rw [inv_apply_eq_inv]
  rcases hχ x with (h₀ | h₁ | h₂)
  · rw [h₀, Ring.inverse_zero]
  · 

Proof state:
case h.inr.inl
R : Type u
inst✝² : CommRing R
R' : Type v
inst✝¹ : CommRing R'
R'' : Type w
inst✝ : CommRing R''
χ : MulChar R R'
hχ : IsQuadratic χ
x : Rˣ
h₁ : χ ↑x = 1
⊢ Ring.inverse (χ ↑x) = χ ↑x

Next tactic:
rw [h₁, Ring.inverse_one]
/-- The inverse of a quadratic character is itself. →  -/
theorem IsQuadratic.inv {χ : MulChar R R'} (hχ : χ.IsQuadratic) : χ⁻¹ = χ := by
  ext x
  rw [inv_apply_eq_inv]
  rcases hχ x with (h₀ | h₁ | h₂)
  · rw [h₀, Ring.inverse_zero]
  · rw [h₁, Ring.inverse_one]
  · -- Porting note: was `by norm_cast`
    

Proof state:
case h.inr.inr
R : Type u
inst✝² : CommRing R
R' : Type v
inst✝¹ : CommRing R'
R'' : Type w
inst✝ : CommRing R''
χ : MulChar R R'
hχ : IsQuadratic χ
x : Rˣ
h₂ : χ ↑x = -1
⊢ Ring.inverse (χ ↑x) = χ ↑x

Next tactic:
have : (-1 : R') = (-1 : R'ˣ) := by rw [Units.val_neg, Units.val_one]
/-- The inverse of a quadratic character is itself. →  -/
theorem IsQuadratic.inv {χ : MulChar R R'} (hχ : χ.IsQuadratic) : χ⁻¹ = χ := by
  ext x
  rw [inv_apply_eq_inv]
  rcases hχ x with (h₀ | h₁ | h₂)
  · rw [h₀, Ring.inverse_zero]
  · rw [h₁, Ring.inverse_one]
  · -- Porting note: was `by norm_cast`
    have : (-1 : R') = (-1 : R'ˣ) := by 

Proof state:
R : Type u
inst✝² : CommRing R
R' : Type v
inst✝¹ : CommRing R'
R'' : Type w
inst✝ : CommRing R''
χ : MulChar R R'
hχ : IsQuadratic χ
x : Rˣ
h₂ : χ ↑x = -1
⊢ -1 = ↑(-1)

Next tactic:
rw [Units.val_neg, Units.val_one]
/-- The inverse of a quadratic character is itself. →  -/
theorem IsQuadratic.inv {χ : MulChar R R'} (hχ : χ.IsQuadratic) : χ⁻¹ = χ := by
  ext x
  rw [inv_apply_eq_inv]
  rcases hχ x with (h₀ | h₁ | h₂)
  · rw [h₀, Ring.inverse_zero]
  · rw [h₁, Ring.inverse_one]
  · -- Porting note: was `by norm_cast`
    have : (-1 : R') = (-1 : R'ˣ) := by rw [Units.val_neg, Units.val_one]
    

Proof state:
case h.inr.inr
R : Type u
inst✝² : CommRing R
R' : Type v
inst✝¹ : CommRing R'
R'' : Type w
inst✝ : CommRing R''
χ : MulChar R R'
hχ : IsQuadratic χ
x : Rˣ
h₂ : χ ↑x = -1
this : -1 = ↑(-1)
⊢ Ring.inverse (χ ↑x) = χ ↑x

Next tactic:
rw [h₂, this, Ring.inverse_unit (-1 : R'ˣ)]
/-- The inverse of a quadratic character is itself. →  -/
theorem IsQuadratic.inv {χ : MulChar R R'} (hχ : χ.IsQuadratic) : χ⁻¹ = χ := by
  ext x
  rw [inv_apply_eq_inv]
  rcases hχ x with (h₀ | h₁ | h₂)
  · rw [h₀, Ring.inverse_zero]
  · rw [h₁, Ring.inverse_one]
  · -- Porting note: was `by norm_cast`
    have : (-1 : R') = (-1 : R'ˣ) := by rw [Units.val_neg, Units.val_one]
    rw [h₂, this, Ring.inverse_unit (-1 : R'ˣ)]
    

Proof state:
case h.inr.inr
R : Type u
inst✝² : CommRing R
R' : Type v
inst✝¹ : CommRing R'
R'' : Type w
inst✝ : CommRing R''
χ : MulChar R R'
hχ : IsQuadratic χ
x : Rˣ
h₂ : χ ↑x = -1
this : -1 = ↑(-1)
⊢ ↑(-1)⁻¹ = ↑(-1)

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

Proof state:
R : Type u
inst✝² : CommRing R
R' : Type v
inst✝¹ : CommRing R'
R'' : Type w
inst✝ : CommRing R''
χ : MulChar R R'
hχ : IsQuadratic χ
⊢ χ ^ 2 = 1

Next tactic:
rw [← mul_left_inv χ, pow_two, hχ.inv]
/-- 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 = χ := by
  

Proof state:
R : Type u
inst✝³ : CommRing R
R' : Type v
inst✝² : CommRing R'
R'' : Type w
inst✝¹ : CommRing R''
χ : MulChar R R'
hχ : IsQuadratic χ
p : ℕ
hp : Fact (Nat.Prime p)
inst✝ : CharP R' p
⊢ χ ^ p = χ

Next tactic:
ext x
/-- 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 = χ := by
  ext x
  

Proof state:
case h
R : Type u
inst✝³ : CommRing R
R' : Type v
inst✝² : CommRing R'
R'' : Type w
inst✝¹ : CommRing R''
χ : MulChar R R'
hχ : IsQuadratic χ
p : ℕ
hp : Fact (Nat.Prime p)
inst✝ : CharP R' p
x : Rˣ
⊢ (χ ^ p) ↑x = χ ↑x

Next tactic:
rw [pow_apply_coe]
/-- 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 = χ := by
  ext x
  rw [pow_apply_coe]
  

Proof state:
case h
R : Type u
inst✝³ : CommRing R
R' : Type v
inst✝² : CommRing R'
R'' : Type w
inst✝¹ : CommRing R''
χ : MulChar R R'
hχ : IsQuadratic χ
p : ℕ
hp : Fact (Nat.Prime p)
inst✝ : CharP R' p
x : Rˣ
⊢ χ ↑x ^ p = χ ↑x

Next tactic:
rcases hχ x with (hx | hx | hx)
/-- 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 = χ := by
  ext x
  rw [pow_apply_coe]
  rcases hχ x with (hx | hx | hx) <;> 

Proof state:
case h.inl
R : Type u
inst✝³ : CommRing R
R' : Type v
inst✝² : CommRing R'
R'' : Type w
inst✝¹ : CommRing R''
χ : MulChar R R'
hχ : IsQuadratic χ
p : ℕ
hp : Fact (Nat.Prime p)
inst✝ : CharP R' p
x : Rˣ
hx : χ ↑x = 0
⊢ χ ↑x ^ p = χ ↑x

Next tactic:
rw [hx]
/-- 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 = χ := by
  ext x
  rw [pow_apply_coe]
  rcases hχ x with (hx | hx | hx) <;> 

Proof state:
case h.inr.inl
R : Type u
inst✝³ : CommRing R
R' : Type v
inst✝² : CommRing R'
R'' : Type w
inst✝¹ : CommRing R''
χ : MulChar R R'
hχ : IsQuadratic χ
p : ℕ
hp : Fact (Nat.Prime p)
inst✝ : CharP R' p
x : Rˣ
hx : χ ↑x = 1
⊢ χ ↑x ^ p = χ ↑x

Next tactic:
rw [hx]
/-- 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 = χ := by
  ext x
  rw [pow_apply_coe]
  rcases hχ x with (hx | hx | hx) <;> 

Proof state:
case h.inr.inr
R : Type u
inst✝³ : CommRing R
R' : Type v
inst✝² : CommRing R'
R'' : Type w
inst✝¹ : CommRing R''
χ : MulChar R R'
hχ : IsQuadratic χ
p : ℕ
hp : Fact (Nat.Prime p)
inst✝ : CharP R' p
x : Rˣ
hx : χ ↑x = -1
⊢ χ ↑x ^ p = χ ↑x

Next tactic:
rw [hx]
/-- 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 = χ := by
  ext x
  rw [pow_apply_coe]
  rcases hχ x with (hx | hx | hx) <;> rw [hx]
  · 

Proof state:
case h.inl
R : Type u
inst✝³ : CommRing R
R' : Type v
inst✝² : CommRing R'
R'' : Type w
inst✝¹ : CommRing R''
χ : MulChar R R'
hχ : IsQuadratic χ
p : ℕ
hp : Fact (Nat.Prime p)
inst✝ : CharP R' p
x : Rˣ
hx : χ ↑x = 0
⊢ 0 ^ p = 0

Next tactic:
rw [zero_pow (@Fact.out p.Prime).pos]
/-- 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 = χ := by
  ext x
  rw [pow_apply_coe]
  rcases hχ x with (hx | hx | hx) <;> rw [hx]
  · rw [zero_pow (@Fact.out p.Prime).pos]
  · 

Proof state:
case h.inr.inl
R : Type u
inst✝³ : CommRing R
R' : Type v
inst✝² : CommRing R'
R'' : Type w
inst✝¹ : CommRing R''
χ : MulChar R R'
hχ : IsQuadratic χ
p : ℕ
hp : Fact (Nat.Prime p)
inst✝ : CharP R' p
x : Rˣ
hx : χ ↑x = 1
⊢ 1 ^ p = 1

Next tactic:
rw [one_pow]
/-- 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 = χ := by
  ext x
  rw [pow_apply_coe]
  rcases hχ x with (hx | hx | hx) <;> rw [hx]
  · rw [zero_pow (@Fact.out p.Prime).pos]
  · rw [one_pow]
  · 

Proof state:
case h.inr.inr
R : Type u
inst✝³ : CommRing R
R' : Type v
inst✝² : CommRing R'
R'' : Type w
inst✝¹ : CommRing R''
χ : MulChar R R'
hχ : IsQuadratic χ
p : ℕ
hp : Fact (Nat.Prime p)
inst✝ : CharP R' p
x : Rˣ
hx : χ ↑x = -1
⊢ (-1) ^ p = -1

Next tactic:
exact CharP.neg_one_pow_char R' p
/-- 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 := by
  

Proof state:
R : Type u
inst✝² : CommRing R
R' : Type v
inst✝¹ : CommRing R'
R'' : Type w
inst✝ : CommRing R''
χ : MulChar R R'
hχ : IsQuadratic χ
n : ℕ
hn : Even n
⊢ χ ^ n = 1

Next tactic:
obtain ⟨n, rfl⟩ := even_iff_two_dvd.mp hn
/-- 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 := by
  obtain ⟨n, rfl⟩ := even_iff_two_dvd.mp hn
  

Proof state:
case intro
R : Type u
inst✝² : CommRing R
R' : Type v
inst✝¹ : CommRing R'
R'' : Type w
inst✝ : CommRing R''
χ : MulChar R R'
hχ : IsQuadratic χ
n : ℕ
hn : Even (2 * n)
⊢ χ ^ (2 * n) = 1

Next tactic:
rw [pow_mul, hχ.sq_eq_one, one_pow]
/-- 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 = χ := by
  

Proof state:
R : Type u
inst✝² : CommRing R
R' : Type v
inst✝¹ : CommRing R'
R'' : Type w
inst✝ : CommRing R''
χ : MulChar R R'
hχ : IsQuadratic χ
n : ℕ
hn : Odd n
⊢ χ ^ n = χ

Next tactic:
obtain ⟨n, rfl⟩ := hn
/-- 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 = χ := by
  obtain ⟨n, rfl⟩ := hn
  

Proof state:
case intro
R : Type u
inst✝² : CommRing R
R' : Type v
inst✝¹ : CommRing R'
R'' : Type w
inst✝ : CommRing R''
χ : MulChar R R'
hχ : IsQuadratic χ
n : ℕ
⊢ χ ^ (2 * n + 1) = χ

Next tactic:
rw [pow_add, pow_one, hχ.pow_even (even_two_mul _), one_mul]
/-- The sum over all values of a nontrivial multiplicative character on a finite ring is zero
(when the target is a domain). -/
theorem IsNontrivial.sum_eq_zero [Fintype R] [IsDomain R'] {χ : MulChar R R'}
    (hχ : χ.IsNontrivial) : ∑ a, χ a = 0 := by
  

Proof state:
R : Type u
inst✝⁴ : CommRing R
R' : Type v
inst✝³ : CommRing R'
R'' : Type w
inst✝² : CommRing R''
inst✝¹ : Fintype R
inst✝ : IsDomain R'
χ : MulChar R R'
hχ : IsNontrivial χ
⊢ ∑ a : R, χ a = 0

Next tactic:
rcases hχ with ⟨b, hb⟩
/-- The sum over all values of a nontrivial multiplicative character on a finite ring is zero
(when the target is a domain). -/
theorem IsNontrivial.sum_eq_zero [Fintype R] [IsDomain R'] {χ : MulChar R R'}
    (hχ : χ.IsNontrivial) : ∑ a, χ a = 0 := by
  rcases hχ with ⟨b, hb⟩
  

Proof state:
case intro
R : Type u
inst✝⁴ : CommRing R
R' : Type v
inst✝³ : CommRing R'
R'' : Type w
inst✝² : CommRing R''
inst✝¹ : Fintype R
inst✝ : IsDomain R'
χ : MulChar R R'
b : Rˣ
hb : χ ↑b ≠ 1
⊢ ∑ a : R, χ a = 0

Next tactic:
refine' eq_zero_of_mul_eq_self_left hb _
/-- The sum over all values of a nontrivial multiplicative character on a finite ring is zero
(when the target is a domain). -/
theorem IsNontrivial.sum_eq_zero [Fintype R] [IsDomain R'] {χ : MulChar R R'}
    (hχ : χ.IsNontrivial) : ∑ a, χ a = 0 := by
  rcases hχ with ⟨b, hb⟩
  refine' eq_zero_of_mul_eq_self_left hb _
  -- POrting note: `map_mul` isn't applied
  

Proof state:
case intro
R : Type u
inst✝⁴ : CommRing R
R' : Type v
inst✝³ : CommRing R'
R'' : Type w
inst✝² : CommRing R''
inst✝¹ : Fintype R
inst✝ : IsDomain R'
χ : MulChar R R'
b : Rˣ
hb : χ ↑b ≠ 1
⊢ χ ↑b * ∑ a : R, χ a = ∑ a : R, χ a

Next tactic:
simp only [Finset.mul_sum, ← map_mul]
/-- The sum over all values of a nontrivial multiplicative character on a finite ring is zero
(when the target is a domain). -/
theorem IsNontrivial.sum_eq_zero [Fintype R] [IsDomain R'] {χ : MulChar R R'}
    (hχ : χ.IsNontrivial) : ∑ a, χ a = 0 := by
  rcases hχ with ⟨b, hb⟩
  refine' eq_zero_of_mul_eq_self_left hb _
  -- POrting note: `map_mul` isn't applied
  simp only [Finset.mul_sum, ← map_mul]
  

Proof state:
case intro
R : Type u
inst✝⁴ : CommRing R
R' : Type v
inst✝³ : CommRing R'
R'' : Type w
inst✝² : CommRing R''
inst✝¹ : Fintype R
inst✝ : IsDomain R'
χ : MulChar R R'
b : Rˣ
hb : χ ↑b ≠ 1
⊢ ∑ x : R, χ (↑b * x) = ∑ a : R, χ a

Next tactic:
refine Fintype.sum_bijective _ (Units.mulLeft_bijective b) _ _ fun x => rfl
/-- 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 [Fintype R] [DecidableEq R] :
    (∑ a, (1 : MulChar R R') a) = Fintype.card Rˣ := by
  

Proof state:
R : Type u
inst✝⁴ : CommRing R
R' : Type v
inst✝³ : CommRing R'
R'' : Type w
inst✝² : CommRing R''
inst✝¹ : Fintype R
inst✝ : DecidableEq R
⊢ ∑ a : R, 1 a = ↑(Fintype.card Rˣ)

Next tactic:
calc
    (∑ a, (1 : MulChar R R') a) = ∑ a : R, if IsUnit a then 1 else 0 :=
      Finset.sum_congr rfl fun a _ => ?_
    _ = ((Finset.univ : Finset R).filter IsUnit).card := Finset.sum_boole
    _ = (Finset.univ.map ⟨((↑) : Rˣ → R), Units.ext⟩).card := ?_
    _ = Fintype.card Rˣ := congr_arg _ (Finset.card_map _)
/-- 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 [Fintype R] [DecidableEq R] :
    (∑ a, (1 : MulChar R R') a) = Fintype.card Rˣ := by
  calc
    (∑ a, (1 : MulChar R R') a) = ∑ a : R, if IsUnit a then 1 else 0 :=
      Finset.sum_congr rfl fun a _ => ?_
    _ = ((Finset.univ : Finset R).filter IsUnit).card := Finset.sum_boole
    _ = (Finset.univ.map ⟨((↑) : Rˣ → R), Units.ext⟩).card := ?_
    _ = Fintype.card Rˣ := congr_arg _ (Finset.card_map _)
  · 

Proof state:
case calc_1
R : Type u
inst✝⁴ : CommRing R
R' : Type v
inst✝³ : CommRing R'
R'' : Type w
inst✝² : CommRing R''
inst✝¹ : Fintype R
inst✝ : DecidableEq R
a : R
x✝ : a ∈ Finset.univ
⊢ 1 a = if IsUnit a then 1 else 0

Next tactic:
split_ifs with h
/-- 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 [Fintype R] [DecidableEq R] :
    (∑ a, (1 : MulChar R R') a) = Fintype.card Rˣ := by
  calc
    (∑ a, (1 : MulChar R R') a) = ∑ a : R, if IsUnit a then 1 else 0 :=
      Finset.sum_congr rfl fun a _ => ?_
    _ = ((Finset.univ : Finset R).filter IsUnit).card := Finset.sum_boole
    _ = (Finset.univ.map ⟨((↑) : Rˣ → R), Units.ext⟩).card := ?_
    _ = Fintype.card Rˣ := congr_arg _ (Finset.card_map _)
  · split_ifs with h
    · 

Proof state:
case pos
R : Type u
inst✝⁴ : CommRing R
R' : Type v
inst✝³ : CommRing R'
R'' : Type w
inst✝² : CommRing R''
inst✝¹ : Fintype R
inst✝ : DecidableEq R
a : R
x✝ : a ∈ Finset.univ
h : IsUnit a
⊢ 1 a = 1

Next tactic:
exact one_apply_coe h.unit
/-- 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 [Fintype R] [DecidableEq R] :
    (∑ a, (1 : MulChar R R') a) = Fintype.card Rˣ := by
  calc
    (∑ a, (1 : MulChar R R') a) = ∑ a : R, if IsUnit a then 1 else 0 :=
      Finset.sum_congr rfl fun a _ => ?_
    _ = ((Finset.univ : Finset R).filter IsUnit).card := Finset.sum_boole
    _ = (Finset.univ.map ⟨((↑) : Rˣ → R), Units.ext⟩).card := ?_
    _ = Fintype.card Rˣ := congr_arg _ (Finset.card_map _)
  · split_ifs with h
    · exact one_apply_coe h.unit
    · 

Proof state:
case neg
R : Type u
inst✝⁴ : CommRing R
R' : Type v
inst✝³ : CommRing R'
R'' : Type w
inst✝² : CommRing R''
inst✝¹ : Fintype R
inst✝ : DecidableEq R
a : R
x✝ : a ∈ Finset.univ
h : ¬IsUnit a
⊢ 1 a = 0

Next tactic:
exact map_nonunit _ h
/-- 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 [Fintype R] [DecidableEq R] :
    (∑ a, (1 : MulChar R R') a) = Fintype.card Rˣ := by
  calc
    (∑ a, (1 : MulChar R R') a) = ∑ a : R, if IsUnit a then 1 else 0 :=
      Finset.sum_congr rfl fun a _ => ?_
    _ = ((Finset.univ : Finset R).filter IsUnit).card := Finset.sum_boole
    _ = (Finset.univ.map ⟨((↑) : Rˣ → R), Units.ext⟩).card := ?_
    _ = Fintype.card Rˣ := congr_arg _ (Finset.card_map _)
  · split_ifs with h
    · exact one_apply_coe h.unit
    · exact map_nonunit _ h
  · 

Proof state:
case calc_2
R : Type u
inst✝⁴ : CommRing R
R' : Type v
inst✝³ : CommRing R'
R'' : Type w
inst✝² : CommRing R''
inst✝¹ : Fintype R
inst✝ : DecidableEq R
⊢ ↑(Finset.card (Finset.filter IsUnit Finset.univ)) =
    ↑(Finset.card (Finset.map { toFun := Units.val, inj' := (_ : Function.Injective Units.val) } Finset.univ))

Next tactic:
congr
/-- 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 [Fintype R] [DecidableEq R] :
    (∑ a, (1 : MulChar R R') a) = Fintype.card Rˣ := by
  calc
    (∑ a, (1 : MulChar R R') a) = ∑ a : R, if IsUnit a then 1 else 0 :=
      Finset.sum_congr rfl fun a _ => ?_
    _ = ((Finset.univ : Finset R).filter IsUnit).card := Finset.sum_boole
    _ = (Finset.univ.map ⟨((↑) : Rˣ → R), Units.ext⟩).card := ?_
    _ = Fintype.card Rˣ := congr_arg _ (Finset.card_map _)
  · split_ifs with h
    · exact one_apply_coe h.unit
    · exact map_nonunit _ h
  · congr
    

Proof state:
case calc_2.e_a.e_s
R : Type u
inst✝⁴ : CommRing R
R' : Type v
inst✝³ : CommRing R'
R'' : Type w
inst✝² : CommRing R''
inst✝¹ : Fintype R
inst✝ : DecidableEq R
⊢ Finset.filter IsUnit Finset.univ =
    Finset.map { toFun := Units.val, inj' := (_ : Function.Injective Units.val) } Finset.univ

Next tactic:
ext a
/-- 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 [Fintype R] [DecidableEq R] :
    (∑ a, (1 : MulChar R R') a) = Fintype.card Rˣ := by
  calc
    (∑ a, (1 : MulChar R R') a) = ∑ a : R, if IsUnit a then 1 else 0 :=
      Finset.sum_congr rfl fun a _ => ?_
    _ = ((Finset.univ : Finset R).filter IsUnit).card := Finset.sum_boole
    _ = (Finset.univ.map ⟨((↑) : Rˣ → R), Units.ext⟩).card := ?_
    _ = Fintype.card Rˣ := congr_arg _ (Finset.card_map _)
  · split_ifs with h
    · exact one_apply_coe h.unit
    · exact map_nonunit _ h
  · congr
    ext a
    

Proof state:
case calc_2.e_a.e_s.a
R : Type u
inst✝⁴ : CommRing R
R' : Type v
inst✝³ : CommRing R'
R'' : Type w
inst✝² : CommRing R''
inst✝¹ : Fintype R
inst✝ : DecidableEq R
a : R
⊢ a ∈ Finset.filter IsUnit Finset.univ ↔
    a ∈ Finset.map { toFun := Units.val, inj' := (_ : Function.Injective Units.val) } Finset.univ

Next tactic:
simp only [Finset.mem_filter, Finset.mem_univ, true_and_iff, Finset.mem_map,
      Function.Embedding.coeFn_mk, exists_true_left, IsUnit]