l3lab/ntp-mathlib huggingface dataset:
theorem aemeasurable_withDensity_iff {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E]
    [SecondCountableTopology E] [MeasurableSpace E] [BorelSpace E] {f : α → ℝ≥0}
    (hf : Measurable f) {g : α → E} :
    AEMeasurable g (μ.withDensity fun x => (f x : ℝ≥0∞)) ↔
      AEMeasurable (fun x => (f x : ℝ) • g x) μ := by
  constructor
  · rintro ⟨g', g'meas, hg'⟩
    have A : MeasurableSet { x : α | f x ≠ 0 } := (hf (measurableSet_singleton 0)).compl
    refine' ⟨fun x => (f x : ℝ) • g' x, hf.coe_nnreal_real.smul g'meas, _⟩
    apply @ae_of_ae_restrict_of_ae_restrict_compl _ _ _ { x | f x ≠ 0 }
    · rw [EventuallyEq, ae_withDensity_iff hf.coe_nnreal_ennreal] at hg'
      rw [ae_restrict_iff' A]
      filter_upwards [hg']
      intro a ha h'a
      have : (f a : ℝ≥0∞) ≠ 0 := by simpa only [Ne.def, coe_eq_zero] using h'a
      rw [ha this]
    · filter_upwards [ae_restrict_mem A.compl]
      intro x hx
      simp only [Classical.not_not, mem_setOf_eq, mem_compl_iff] at hx
      simp [hx]
  · rintro ⟨g', g'meas, hg'⟩
    refine' ⟨fun x => (f x : ℝ)⁻¹ • g' x, hf.coe_nnreal_real.inv.smul g'meas, _⟩
    rw [EventuallyEq, ae_withDensity_iff hf.coe_nnreal_ennreal]
    filter_upwards [hg']
    

Proof state:
case h
α : Type u_1
β : Type u_2
γ : Type u_3
δ : Type u_4
m : MeasurableSpace α
μ : Measure α
E : Type u_5
inst✝⁴ : NormedAddCommGroup E
inst✝³ : NormedSpace ℝ E
inst✝² : SecondCountableTopology E
inst✝¹ : MeasurableSpace E
inst✝ : BorelSpace E
f : α → ℝ≥0
hf : Measurable f
g g' : α → E
g'meas : Measurable g'
hg' : (fun x => ↑(f x) • g x) =ᵐ[μ] g'
⊢ ∀ (a : α), ↑(f a) • g a = g' a → ↑(f a) ≠ 0 → g a = (↑(f a))⁻¹ • g' a

Next tactic:
intro x hx h'x
theorem aemeasurable_withDensity_iff {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E]
    [SecondCountableTopology E] [MeasurableSpace E] [BorelSpace E] {f : α → ℝ≥0}
    (hf : Measurable f) {g : α → E} :
    AEMeasurable g (μ.withDensity fun x => (f x : ℝ≥0∞)) ↔
      AEMeasurable (fun x => (f x : ℝ) • g x) μ := by
  constructor
  · rintro ⟨g', g'meas, hg'⟩
    have A : MeasurableSet { x : α | f x ≠ 0 } := (hf (measurableSet_singleton 0)).compl
    refine' ⟨fun x => (f x : ℝ) • g' x, hf.coe_nnreal_real.smul g'meas, _⟩
    apply @ae_of_ae_restrict_of_ae_restrict_compl _ _ _ { x | f x ≠ 0 }
    · rw [EventuallyEq, ae_withDensity_iff hf.coe_nnreal_ennreal] at hg'
      rw [ae_restrict_iff' A]
      filter_upwards [hg']
      intro a ha h'a
      have : (f a : ℝ≥0∞) ≠ 0 := by simpa only [Ne.def, coe_eq_zero] using h'a
      rw [ha this]
    · filter_upwards [ae_restrict_mem A.compl]
      intro x hx
      simp only [Classical.not_not, mem_setOf_eq, mem_compl_iff] at hx
      simp [hx]
  · rintro ⟨g', g'meas, hg'⟩
    refine' ⟨fun x => (f x : ℝ)⁻¹ • g' x, hf.coe_nnreal_real.inv.smul g'meas, _⟩
    rw [EventuallyEq, ae_withDensity_iff hf.coe_nnreal_ennreal]
    filter_upwards [hg']
    intro x hx h'x
    

Proof state:
case h
α : Type u_1
β : Type u_2
γ : Type u_3
δ : Type u_4
m : MeasurableSpace α
μ : Measure α
E : Type u_5
inst✝⁴ : NormedAddCommGroup E
inst✝³ : NormedSpace ℝ E
inst✝² : SecondCountableTopology E
inst✝¹ : MeasurableSpace E
inst✝ : BorelSpace E
f : α → ℝ≥0
hf : Measurable f
g g' : α → E
g'meas : Measurable g'
hg' : (fun x => ↑(f x) • g x) =ᵐ[μ] g'
x : α
hx : ↑(f x) • g x = g' x
h'x : ↑(f x) ≠ 0
⊢ g x = (↑(f x))⁻¹ • g' x

Next tactic:
rw [← hx, smul_smul, _root_.inv_mul_cancel, one_smul]
theorem aemeasurable_withDensity_iff {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E]
    [SecondCountableTopology E] [MeasurableSpace E] [BorelSpace E] {f : α → ℝ≥0}
    (hf : Measurable f) {g : α → E} :
    AEMeasurable g (μ.withDensity fun x => (f x : ℝ≥0∞)) ↔
      AEMeasurable (fun x => (f x : ℝ) • g x) μ := by
  constructor
  · rintro ⟨g', g'meas, hg'⟩
    have A : MeasurableSet { x : α | f x ≠ 0 } := (hf (measurableSet_singleton 0)).compl
    refine' ⟨fun x => (f x : ℝ) • g' x, hf.coe_nnreal_real.smul g'meas, _⟩
    apply @ae_of_ae_restrict_of_ae_restrict_compl _ _ _ { x | f x ≠ 0 }
    · rw [EventuallyEq, ae_withDensity_iff hf.coe_nnreal_ennreal] at hg'
      rw [ae_restrict_iff' A]
      filter_upwards [hg']
      intro a ha h'a
      have : (f a : ℝ≥0∞) ≠ 0 := by simpa only [Ne.def, coe_eq_zero] using h'a
      rw [ha this]
    · filter_upwards [ae_restrict_mem A.compl]
      intro x hx
      simp only [Classical.not_not, mem_setOf_eq, mem_compl_iff] at hx
      simp [hx]
  · rintro ⟨g', g'meas, hg'⟩
    refine' ⟨fun x => (f x : ℝ)⁻¹ • g' x, hf.coe_nnreal_real.inv.smul g'meas, _⟩
    rw [EventuallyEq, ae_withDensity_iff hf.coe_nnreal_ennreal]
    filter_upwards [hg']
    intro x hx h'x
    rw [← hx, smul_smul, _root_.inv_mul_cancel, one_smul]
    

Proof state:
case h
α : Type u_1
β : Type u_2
γ : Type u_3
δ : Type u_4
m : MeasurableSpace α
μ : Measure α
E : Type u_5
inst✝⁴ : NormedAddCommGroup E
inst✝³ : NormedSpace ℝ E
inst✝² : SecondCountableTopology E
inst✝¹ : MeasurableSpace E
inst✝ : BorelSpace E
f : α → ℝ≥0
hf : Measurable f
g g' : α → E
g'meas : Measurable g'
hg' : (fun x => ↑(f x) • g x) =ᵐ[μ] g'
x : α
hx : ↑(f x) • g x = g' x
h'x : ↑(f x) ≠ 0
⊢ ↑(f x) ≠ 0

Next tactic:
simp only [Ne.def, coe_eq_zero] at h'x
theorem aemeasurable_withDensity_iff {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E]
    [SecondCountableTopology E] [MeasurableSpace E] [BorelSpace E] {f : α → ℝ≥0}
    (hf : Measurable f) {g : α → E} :
    AEMeasurable g (μ.withDensity fun x => (f x : ℝ≥0∞)) ↔
      AEMeasurable (fun x => (f x : ℝ) • g x) μ := by
  constructor
  · rintro ⟨g', g'meas, hg'⟩
    have A : MeasurableSet { x : α | f x ≠ 0 } := (hf (measurableSet_singleton 0)).compl
    refine' ⟨fun x => (f x : ℝ) • g' x, hf.coe_nnreal_real.smul g'meas, _⟩
    apply @ae_of_ae_restrict_of_ae_restrict_compl _ _ _ { x | f x ≠ 0 }
    · rw [EventuallyEq, ae_withDensity_iff hf.coe_nnreal_ennreal] at hg'
      rw [ae_restrict_iff' A]
      filter_upwards [hg']
      intro a ha h'a
      have : (f a : ℝ≥0∞) ≠ 0 := by simpa only [Ne.def, coe_eq_zero] using h'a
      rw [ha this]
    · filter_upwards [ae_restrict_mem A.compl]
      intro x hx
      simp only [Classical.not_not, mem_setOf_eq, mem_compl_iff] at hx
      simp [hx]
  · rintro ⟨g', g'meas, hg'⟩
    refine' ⟨fun x => (f x : ℝ)⁻¹ • g' x, hf.coe_nnreal_real.inv.smul g'meas, _⟩
    rw [EventuallyEq, ae_withDensity_iff hf.coe_nnreal_ennreal]
    filter_upwards [hg']
    intro x hx h'x
    rw [← hx, smul_smul, _root_.inv_mul_cancel, one_smul]
    simp only [Ne.def, coe_eq_zero] at h'x
    

Proof state:
case h
α : Type u_1
β : Type u_2
γ : Type u_3
δ : Type u_4
m : MeasurableSpace α
μ : Measure α
E : Type u_5
inst✝⁴ : NormedAddCommGroup E
inst✝³ : NormedSpace ℝ E
inst✝² : SecondCountableTopology E
inst✝¹ : MeasurableSpace E
inst✝ : BorelSpace E
f : α → ℝ≥0
hf : Measurable f
g g' : α → E
g'meas : Measurable g'
hg' : (fun x => ↑(f x) • g x) =ᵐ[μ] g'
x : α
hx : ↑(f x) • g x = g' x
h'x : ¬f x = 0
⊢ ↑(f x) ≠ 0

Next tactic:
simpa only [NNReal.coe_eq_zero, Ne.def] using h'x
/-- The exponential characteristic is one if the characteristic is zero. -/
theorem expChar_one_of_char_zero (q : ℕ) [hp : CharP R 0] [hq : ExpChar R q] : q = 1 := by
  

Proof state:
R : Type u
inst✝ : Semiring R
q : ℕ
hp : CharP R 0
hq : ExpChar R q
⊢ q = 1

Next tactic:
cases' hq with q hq_one hq_prime hq_hchar
/-- The exponential characteristic is one if the characteristic is zero. -/
theorem expChar_one_of_char_zero (q : ℕ) [hp : CharP R 0] [hq : ExpChar R q] : q = 1 := by
  cases' hq with q hq_one hq_prime hq_hchar
  · 

Proof state:
case zero
R : Type u
inst✝ : Semiring R
hp : CharP R 0
q : CharZero R
⊢ 1 = 1

Next tactic:
rfl
/-- The exponential characteristic is one if the characteristic is zero. -/
theorem expChar_one_of_char_zero (q : ℕ) [hp : CharP R 0] [hq : ExpChar R q] : q = 1 := by
  cases' hq with q hq_one hq_prime hq_hchar
  · rfl
  · 

Proof state:
case prime
R : Type u
inst✝ : Semiring R
q : ℕ
hp : CharP R 0
hq_prime : Nat.Prime q
hq_hchar : CharP R q
⊢ q = 1

Next tactic:
exact False.elim (lt_irrefl _ ((hp.eq R hq_hchar).symm ▸ hq_prime : (0 : ℕ).Prime).pos)
/-- The characteristic equals the exponential characteristic iff the former is prime. -/
theorem char_eq_expChar_iff (p q : ℕ) [hp : CharP R p] [hq : ExpChar R q] : p = q ↔ p.Prime := by
  

Proof state:
R : Type u
inst✝ : Semiring R
p q : ℕ
hp : CharP R p
hq : ExpChar R q
⊢ p = q ↔ Nat.Prime p

Next tactic:
cases' hq with q hq_one hq_prime hq_hchar
/-- The characteristic equals the exponential characteristic iff the former is prime. -/
theorem char_eq_expChar_iff (p q : ℕ) [hp : CharP R p] [hq : ExpChar R q] : p = q ↔ p.Prime := by
  cases' hq with q hq_one hq_prime hq_hchar
  · 

Proof state:
case zero
R : Type u
inst✝ : Semiring R
p : ℕ
hp : CharP R p
q : CharZero R
⊢ p = 1 ↔ Nat.Prime p

Next tactic:
rw [(CharP.eq R hp inferInstance : p = 0)]
/-- The characteristic equals the exponential characteristic iff the former is prime. -/
theorem char_eq_expChar_iff (p q : ℕ) [hp : CharP R p] [hq : ExpChar R q] : p = q ↔ p.Prime := by
  cases' hq with q hq_one hq_prime hq_hchar
  · rw [(CharP.eq R hp inferInstance : p = 0)]
    

Proof state:
case zero
R : Type u
inst✝ : Semiring R
p : ℕ
hp : CharP R p
q : CharZero R
⊢ 0 = 1 ↔ Nat.Prime 0

Next tactic:
decide
/-- The characteristic equals the exponential characteristic iff the former is prime. -/
theorem char_eq_expChar_iff (p q : ℕ) [hp : CharP R p] [hq : ExpChar R q] : p = q ↔ p.Prime := by
  cases' hq with q hq_one hq_prime hq_hchar
  · rw [(CharP.eq R hp inferInstance : p = 0)]
    decide
  · 

Proof state:
case prime
R : Type u
inst✝ : Semiring R
p q : ℕ
hp : CharP R p
hq_prime : Nat.Prime q
hq_hchar : CharP R q
⊢ p = q ↔ Nat.Prime p

Next tactic:
exact ⟨fun hpq => hpq.symm ▸ hq_prime, fun _ => CharP.eq R hp hq_hchar⟩
/-- The exponential characteristic is one if the characteristic is zero. -/
theorem char_zero_of_expChar_one (p : ℕ) [hp : CharP R p] [hq : ExpChar R 1] : p = 0 := by
  

Proof state:
R : Type u
inst✝¹ : Semiring R
inst✝ : Nontrivial R
p : ℕ
hp : CharP R p
hq : ExpChar R 1
⊢ p = 0

Next tactic:
cases hq
/-- The exponential characteristic is one if the characteristic is zero. -/
theorem char_zero_of_expChar_one (p : ℕ) [hp : CharP R p] [hq : ExpChar R 1] : p = 0 := by
  cases hq
  · 

Proof state:
case zero
R : Type u
inst✝² : Semiring R
inst✝¹ : Nontrivial R
p : ℕ
hp : CharP R p
inst✝ : CharZero R
⊢ p = 0

Next tactic:
exact CharP.eq R hp inferInstance
/-- The exponential characteristic is one if the characteristic is zero. -/
theorem char_zero_of_expChar_one (p : ℕ) [hp : CharP R p] [hq : ExpChar R 1] : p = 0 := by
  cases hq
  · exact CharP.eq R hp inferInstance
  · 

Proof state:
case prime
R : Type u
inst✝¹ : Semiring R
inst✝ : Nontrivial R
p : ℕ
hp : CharP R p
hprime✝ : Nat.Prime 1
hchar✝ : CharP R 1
⊢ p = 0

Next tactic:
exact False.elim (CharP.char_ne_one R 1 rfl)
/-- The characteristic is zero if the exponential characteristic is one. -/
theorem charZero_of_expChar_one' [hq : ExpChar R 1] : CharZero R := by
  

Proof state:
R : Type u
inst✝¹ : Semiring R
inst✝ : Nontrivial R
hq : ExpChar R 1
⊢ CharZero R

Next tactic:
cases hq
/-- The characteristic is zero if the exponential characteristic is one. -/
theorem charZero_of_expChar_one' [hq : ExpChar R 1] : CharZero R := by
  cases hq
  · 

Proof state:
case zero
R : Type u
inst✝² : Semiring R
inst✝¹ : Nontrivial R
inst✝ : CharZero R
⊢ CharZero R

Next tactic:
assumption
/-- The characteristic is zero if the exponential characteristic is one. -/
theorem charZero_of_expChar_one' [hq : ExpChar R 1] : CharZero R := by
  cases hq
  · assumption
  · 

Proof state:
case prime
R : Type u
inst✝¹ : Semiring R
inst✝ : Nontrivial R
hprime✝ : Nat.Prime 1
hchar✝ : CharP R 1
⊢ CharZero R

Next tactic:
exact False.elim (CharP.char_ne_one R 1 rfl)
/-- The exponential characteristic is one iff the characteristic is zero. -/
theorem expChar_one_iff_char_zero (p q : ℕ) [CharP R p] [ExpChar R q] : q = 1 ↔ p = 0 := by
  

Proof state:
R : Type u
inst✝³ : Semiring R
inst✝² : Nontrivial R
p q : ℕ
inst✝¹ : CharP R p
inst✝ : ExpChar R q
⊢ q = 1 ↔ p = 0

Next tactic:
constructor
/-- The exponential characteristic is one iff the characteristic is zero. -/
theorem expChar_one_iff_char_zero (p q : ℕ) [CharP R p] [ExpChar R q] : q = 1 ↔ p = 0 := by
  constructor
  · 

Proof state:
case mp
R : Type u
inst✝³ : Semiring R
inst✝² : Nontrivial R
p q : ℕ
inst✝¹ : CharP R p
inst✝ : ExpChar R q
⊢ q = 1 → p = 0

Next tactic:
rintro rfl
/-- The exponential characteristic is one iff the characteristic is zero. -/
theorem expChar_one_iff_char_zero (p q : ℕ) [CharP R p] [ExpChar R q] : q = 1 ↔ p = 0 := by
  constructor
  · rintro rfl
    

Proof state:
case mp
R : Type u
inst✝³ : Semiring R
inst✝² : Nontrivial R
p : ℕ
inst✝¹ : CharP R p
inst✝ : ExpChar R 1
⊢ p = 0

Next tactic:
exact char_zero_of_expChar_one R p
/-- The exponential characteristic is one iff the characteristic is zero. -/
theorem expChar_one_iff_char_zero (p q : ℕ) [CharP R p] [ExpChar R q] : q = 1 ↔ p = 0 := by
  constructor
  · rintro rfl
    exact char_zero_of_expChar_one R p
  · 

Proof state:
case mpr
R : Type u
inst✝³ : Semiring R
inst✝² : Nontrivial R
p q : ℕ
inst✝¹ : CharP R p
inst✝ : ExpChar R q
⊢ p = 0 → q = 1

Next tactic:
rintro rfl
/-- The exponential characteristic is one iff the characteristic is zero. -/
theorem expChar_one_iff_char_zero (p q : ℕ) [CharP R p] [ExpChar R q] : q = 1 ↔ p = 0 := by
  constructor
  · rintro rfl
    exact char_zero_of_expChar_one R p
  · rintro rfl
    

Proof state:
case mpr
R : Type u
inst✝³ : Semiring R
inst✝² : Nontrivial R
q : ℕ
inst✝¹ : ExpChar R q
inst✝ : CharP R 0
⊢ q = 1

Next tactic:
exact expChar_one_of_char_zero R q
/-- A helper lemma: the characteristic is prime if it is non-zero. -/
theorem char_prime_of_ne_zero {p : ℕ} [hp : CharP R p] (p_ne_zero : p ≠ 0) : Nat.Prime p := by
  

Proof state:
R : Type u
inst✝² : Semiring R
inst✝¹ : Nontrivial R
inst✝ : NoZeroDivisors R
p : ℕ
hp : CharP R p
p_ne_zero : p ≠ 0
⊢ Nat.Prime p

Next tactic:
cases' CharP.char_is_prime_or_zero R p with h h
/-- A helper lemma: the characteristic is prime if it is non-zero. -/
theorem char_prime_of_ne_zero {p : ℕ} [hp : CharP R p] (p_ne_zero : p ≠ 0) : Nat.Prime p := by
  cases' CharP.char_is_prime_or_zero R p with h h
  · 

Proof state:
case inl
R : Type u
inst✝² : Semiring R
inst✝¹ : Nontrivial R
inst✝ : NoZeroDivisors R
p : ℕ
hp : CharP R p
p_ne_zero : p ≠ 0
h : Nat.Prime p
⊢ Nat.Prime p

Next tactic:
exact h
/-- A helper lemma: the characteristic is prime if it is non-zero. -/
theorem char_prime_of_ne_zero {p : ℕ} [hp : CharP R p] (p_ne_zero : p ≠ 0) : Nat.Prime p := by
  cases' CharP.char_is_prime_or_zero R p with h h
  · exact h
  · 

Proof state:
case inr
R : Type u
inst✝² : Semiring R
inst✝¹ : Nontrivial R
inst✝ : NoZeroDivisors R
p : ℕ
hp : CharP R p
p_ne_zero : p ≠ 0
h : p = 0
⊢ Nat.Prime p

Next tactic:
contradiction
/-- The exponential characteristic is a prime number or one. -/
theorem expChar_is_prime_or_one (q : ℕ) [hq : ExpChar R q] : Nat.Prime q ∨ q = 1 := by
  

Proof state:
R : Type u
inst✝² : Semiring R
inst✝¹ : Nontrivial R
inst✝ : NoZeroDivisors R
q : ℕ
hq : ExpChar R q
⊢ Nat.Prime q ∨ q = 1

Next tactic:
cases hq
/-- The exponential characteristic is a prime number or one. -/
theorem expChar_is_prime_or_one (q : ℕ) [hq : ExpChar R q] : Nat.Prime q ∨ q = 1 := by
  cases hq
  

Proof state:
case zero
R : Type u
inst✝³ : Semiring R
inst✝² : Nontrivial R
inst✝¹ : NoZeroDivisors R
inst✝ : CharZero R
⊢ Nat.Prime 1 ∨ 1 = 1
case prime
R : Type u
inst✝² : Semiring R
inst✝¹ : Nontrivial R
inst✝ : NoZeroDivisors R
q : ℕ
hprime✝ : Nat.Prime q
hchar✝ : CharP R q
⊢ Nat.Prime q ∨ q = 1

Next tactic:
case zero => exact .inr rfl
/-- The exponential characteristic is a prime number or one. -/
theorem expChar_is_prime_or_one (q : ℕ) [hq : ExpChar R q] : Nat.Prime q ∨ q = 1 := by
  cases hq
  

Proof state:
R : Type u
inst✝³ : Semiring R
inst✝² : Nontrivial R
inst✝¹ : NoZeroDivisors R
inst✝ : CharZero R
⊢ Nat.Prime 1 ∨ 1 = 1

Next tactic:
case zero => exact .inr rfl
/-- The exponential characteristic is a prime number or one. -/
theorem expChar_is_prime_or_one (q : ℕ) [hq : ExpChar R q] : Nat.Prime q ∨ q = 1 := by
  cases hq
  case zero => 

Proof state:
R : Type u
inst✝³ : Semiring R
inst✝² : Nontrivial R
inst✝¹ : NoZeroDivisors R
inst✝ : CharZero R
⊢ Nat.Prime 1 ∨ 1 = 1

Next tactic:
exact .inr rfl
/-- The exponential characteristic is a prime number or one. -/
theorem expChar_is_prime_or_one (q : ℕ) [hq : ExpChar R q] : Nat.Prime q ∨ q = 1 := by
  cases hq
  case zero => exact .inr rfl
  

Proof state:
case prime
R : Type u
inst✝² : Semiring R
inst✝¹ : Nontrivial R
inst✝ : NoZeroDivisors R
q : ℕ
hprime✝ : Nat.Prime q
hchar✝ : CharP R q
⊢ Nat.Prime q ∨ q = 1

Next tactic:
case prime hp _ => exact .inl hp
/-- The exponential characteristic is a prime number or one. -/
theorem expChar_is_prime_or_one (q : ℕ) [hq : ExpChar R q] : Nat.Prime q ∨ q = 1 := by
  cases hq
  case zero => exact .inr rfl
  

Proof state:
R : Type u
inst✝² : Semiring R
inst✝¹ : Nontrivial R
inst✝ : NoZeroDivisors R
q : ℕ
hp : Nat.Prime q
hchar✝ : CharP R q
⊢ Nat.Prime q ∨ q = 1

Next tactic:
case prime hp _ => exact .inl hp
/-- The exponential characteristic is a prime number or one. -/
theorem expChar_is_prime_or_one (q : ℕ) [hq : ExpChar R q] : Nat.Prime q ∨ q = 1 := by
  cases hq
  case zero => exact .inr rfl
  case prime hp _ => 

Proof state:
R : Type u
inst✝² : Semiring R
inst✝¹ : Nontrivial R
inst✝ : NoZeroDivisors R
q : ℕ
hp : Nat.Prime q
hchar✝ : CharP R q
⊢ Nat.Prime q ∨ q = 1

Next tactic:
exact .inl hp
theorem ExpChar.exists [Ring R] [IsDomain R] : ∃ q, ExpChar R q := by
  

Proof state:
R : Type u
inst✝¹ : Ring R
inst✝ : IsDomain R
⊢ ∃ q, ExpChar R q

Next tactic:
obtain ⟨p, h⟩ := CharP.exists R
theorem ExpChar.exists [Ring R] [IsDomain R] : ∃ q, ExpChar R q := by
  obtain ⟨p, h⟩ := CharP.exists R
  

Proof state:
case intro
R : Type u
inst✝¹ : Ring R
inst✝ : IsDomain R
p : ℕ
h : CharP R p
⊢ ∃ q, ExpChar R q

Next tactic:
by_cases hp : p = 0
theorem ExpChar.exists [Ring R] [IsDomain R] : ∃ q, ExpChar R q := by
  obtain ⟨p, h⟩ := CharP.exists R
  by_cases hp : p = 0
  · 

Proof state:
case pos
R : Type u
inst✝¹ : Ring R
inst✝ : IsDomain R
p : ℕ
h : CharP R p
hp : p = 0
⊢ ∃ q, ExpChar R q

Next tactic:
exact ⟨1, by rw [hp] at h; haveI := CharP.charP_to_charZero R; exact .zero⟩
theorem ExpChar.exists [Ring R] [IsDomain R] : ∃ q, ExpChar R q := by
  obtain ⟨p, h⟩ := CharP.exists R
  by_cases hp : p = 0
  · exact ⟨1, by 

Proof state:
R : Type u
inst✝¹ : Ring R
inst✝ : IsDomain R
p : ℕ
h : CharP R p
hp : p = 0
⊢ ExpChar R 1

Next tactic:
rw [hp] at h
theorem ExpChar.exists [Ring R] [IsDomain R] : ∃ q, ExpChar R q := by
  obtain ⟨p, h⟩ := CharP.exists R
  by_cases hp : p = 0
  · exact ⟨1, by rw [hp] at h; 

Proof state:
R : Type u
inst✝¹ : Ring R
inst✝ : IsDomain R
p : ℕ
h : CharP R 0
hp : p = 0
⊢ ExpChar R 1

Next tactic:
haveI := CharP.charP_to_charZero R
theorem ExpChar.exists [Ring R] [IsDomain R] : ∃ q, ExpChar R q := by
  obtain ⟨p, h⟩ := CharP.exists R
  by_cases hp : p = 0
  · exact ⟨1, by rw [hp] at h; haveI := CharP.charP_to_charZero R; 

Proof state:
R : Type u
inst✝¹ : Ring R
inst✝ : IsDomain R
p : ℕ
h : CharP R 0
hp : p = 0
this : CharZero R
⊢ ExpChar R 1

Next tactic:
exact .zero
theorem ExpChar.exists [Ring R] [IsDomain R] : ∃ q, ExpChar R q := by
  obtain ⟨p, h⟩ := CharP.exists R
  by_cases hp : p = 0
  · exact ⟨1, by rw [hp] at h; haveI := CharP.charP_to_charZero R; exact .zero⟩
  

Proof state:
case neg
R : Type u
inst✝¹ : Ring R
inst✝ : IsDomain R
p : ℕ
h : CharP R p
hp : ¬p = 0
⊢ ∃ q, ExpChar R q

Next tactic:
exact ⟨p, haveI := NeZero.mk hp; .prime (CharP.char_is_prime_of_pos R p).out⟩
/-- If a ring homomorphism `R →+* A` is injective then `A` has the same exponential characteristic
as `R`. -/
theorem expChar_of_injective_ringHom {R A : Type*}
    [Semiring R] [Semiring A] {f : R →+* A} (h : Function.Injective f)
    (q : ℕ) [hR : ExpChar R q] : ExpChar A q := by
  

Proof state:
R✝ : Type u
R : Type u_1
A : Type u_2
inst✝¹ : Semiring R
inst✝ : Semiring A
f : R →+* A
h : Function.Injective ⇑f
q : ℕ
hR : ExpChar R q
⊢ ExpChar A q

Next tactic:
cases' hR with _ _ hprime _
/-- If a ring homomorphism `R →+* A` is injective then `A` has the same exponential characteristic
as `R`. -/
theorem expChar_of_injective_ringHom {R A : Type*}
    [Semiring R] [Semiring A] {f : R →+* A} (h : Function.Injective f)
    (q : ℕ) [hR : ExpChar R q] : ExpChar A q := by
  cases' hR with _ _ hprime _
  · 

Proof state:
case zero
R✝ : Type u
R : Type u_1
A : Type u_2
inst✝² : Semiring R
inst✝¹ : Semiring A
f : R →+* A
h : Function.Injective ⇑f
inst✝ : CharZero R
⊢ ExpChar A 1

Next tactic:
haveI := charZero_of_injective_ringHom h
/-- If a ring homomorphism `R →+* A` is injective then `A` has the same exponential characteristic
as `R`. -/
theorem expChar_of_injective_ringHom {R A : Type*}
    [Semiring R] [Semiring A] {f : R →+* A} (h : Function.Injective f)
    (q : ℕ) [hR : ExpChar R q] : ExpChar A q := by
  cases' hR with _ _ hprime _
  · haveI := charZero_of_injective_ringHom h; 

Proof state:
case zero
R✝ : Type u
R : Type u_1
A : Type u_2
inst✝² : Semiring R
inst✝¹ : Semiring A
f : R →+* A
h : Function.Injective ⇑f
inst✝ : CharZero R
this : CharZero A
⊢ ExpChar A 1

Next tactic:
exact .zero
/-- If a ring homomorphism `R →+* A` is injective then `A` has the same exponential characteristic
as `R`. -/
theorem expChar_of_injective_ringHom {R A : Type*}
    [Semiring R] [Semiring A] {f : R →+* A} (h : Function.Injective f)
    (q : ℕ) [hR : ExpChar R q] : ExpChar A q := by
  cases' hR with _ _ hprime _
  · haveI := charZero_of_injective_ringHom h; exact .zero
  

Proof state:
case prime
R✝ : Type u
R : Type u_1
A : Type u_2
inst✝¹ : Semiring R
inst✝ : Semiring A
f : R →+* A
h : Function.Injective ⇑f
q : ℕ
hprime : Nat.Prime q
hchar✝ : CharP R q
⊢ ExpChar A q

Next tactic:
haveI := charP_of_injective_ringHom h q
/-- If a ring homomorphism `R →+* A` is injective then `A` has the same exponential characteristic
as `R`. -/
theorem expChar_of_injective_ringHom {R A : Type*}
    [Semiring R] [Semiring A] {f : R →+* A} (h : Function.Injective f)
    (q : ℕ) [hR : ExpChar R q] : ExpChar A q := by
  cases' hR with _ _ hprime _
  · haveI := charZero_of_injective_ringHom h; exact .zero
  haveI := charP_of_injective_ringHom h q; 

Proof state:
case prime
R✝ : Type u
R : Type u_1
A : Type u_2
inst✝¹ : Semiring R
inst✝ : Semiring A
f : R →+* A
h : Function.Injective ⇑f
q : ℕ
hprime : Nat.Prime q
hchar✝ : CharP R q
this : CharP A q
⊢ ExpChar A q

Next tactic:
exact .prime hprime
theorem add_pow_expChar_of_commute [Semiring R] {q : ℕ} [hR : ExpChar R q]
    (x y : R) (h : Commute x y) : (x + y) ^ q = x ^ q + y ^ q := by
  

Proof state:
R : Type u
inst✝ : Semiring R
q : ℕ
hR : ExpChar R q
x y : R
h : Commute x y
⊢ (x + y) ^ q = x ^ q + y ^ q

Next tactic:
cases' hR with _ _ hprime _
theorem add_pow_expChar_of_commute [Semiring R] {q : ℕ} [hR : ExpChar R q]
    (x y : R) (h : Commute x y) : (x + y) ^ q = x ^ q + y ^ q := by
  cases' hR with _ _ hprime _
  · 

Proof state:
case zero
R : Type u
inst✝¹ : Semiring R
x y : R
h : Commute x y
inst✝ : CharZero R
⊢ (x + y) ^ 1 = x ^ 1 + y ^ 1

Next tactic:
simp only [pow_one]
theorem add_pow_expChar_of_commute [Semiring R] {q : ℕ} [hR : ExpChar R q]
    (x y : R) (h : Commute x y) : (x + y) ^ q = x ^ q + y ^ q := by
  cases' hR with _ _ hprime _
  · simp only [pow_one]
  

Proof state:
case prime
R : Type u
inst✝ : Semiring R
q : ℕ
x y : R
h : Commute x y
hprime : Nat.Prime q
hchar✝ : CharP R q
⊢ (x + y) ^ q = x ^ q + y ^ q

Next tactic:
haveI := Fact.mk hprime
theorem add_pow_expChar_of_commute [Semiring R] {q : ℕ} [hR : ExpChar R q]
    (x y : R) (h : Commute x y) : (x + y) ^ q = x ^ q + y ^ q := by
  cases' hR with _ _ hprime _
  · simp only [pow_one]
  haveI := Fact.mk hprime; 

Proof state:
case prime
R : Type u
inst✝ : Semiring R
q : ℕ
x y : R
h : Commute x y
hprime : Nat.Prime q
hchar✝ : CharP R q
this : Fact (Nat.Prime q)
⊢ (x + y) ^ q = x ^ q + y ^ q

Next tactic:
exact add_pow_char_of_commute R x y h