Theorem: Nat.totient_eq_mul_prod_factors
File: Mathlib/Data/Nat/Totient.lean

tactic: by_cases hn : n = 0
state_before: n : ℕ
⊢ ↑(φ n) = ↑n * ∏ p ∈ n.primeFactors, (1 - (↑p)⁻¹)
state_after: case pos
n : ℕ
hn : n = 0
⊢ ↑(φ n) = ↑n * ∏ p ∈ n.primeFactors, (1 - (↑p)⁻¹)

case neg
n : ℕ
hn : ¬n = 0
⊢ ↑(φ n) = ↑n * ∏ p ∈ n.primeFactors, (1 - (↑p)⁻¹)

tactic: have hn' : (n : ℚ) ≠ 0 := by simp [hn]
state_before: case neg
n : ℕ
hn : ¬n = 0
⊢ ↑(φ n) = ↑n * ∏ p ∈ n.primeFactors, (1 - (↑p)⁻¹)
state_after: case neg
n : ℕ
hn : ¬n = 0
hn' : ↑n ≠ 0
⊢ ↑(φ n) = ↑n * ∏ p ∈ n.primeFactors, (1 - (↑p)⁻¹)

tactic: have hpQ : (∏ p ∈ n.primeFactors, (p : ℚ)) ≠ 0 := by
  rw [← cast_prod, cast_ne_zero, ← zero_lt_iff, prod_primeFactors_prod_factorization]
  exact prod_pos fun p hp => pos_of_mem_primeFactors hp
state_before: case neg
n : ℕ
hn : ¬n = 0
hn' : ↑n ≠ 0
⊢ ↑(φ n) = ↑n * ∏ p ∈ n.primeFactors, (1 - (↑p)⁻¹)
state_after: case neg
n : ℕ
hn : ¬n = 0
hn' : ↑n ≠ 0
hpQ : ∏ p ∈ n.primeFactors, ↑p ≠ 0
⊢ ↑(φ n) = ↑n * ∏ p ∈ n.primeFactors, (1 - (↑p)⁻¹)

tactic: simp only [totient_eq_div_primeFactors_mul n, prod_primeFactors_dvd n, cast_mul, cast_prod,
  cast_div_charZero, mul_comm_div, mul_right_inj' hn', div_eq_iff hpQ, ← prod_mul_distrib]
state_before: case neg
n : ℕ
hn : ¬n = 0
hn' : ↑n ≠ 0
hpQ : ∏ p ∈ n.primeFactors, ↑p ≠ 0
⊢ ↑(φ n) = ↑n * ∏ p ∈ n.primeFactors, (1 - (↑p)⁻¹)
state_after: case neg
n : ℕ
hn : ¬n = 0
hn' : ↑n ≠ 0
hpQ : ∏ p ∈ n.primeFactors, ↑p ≠ 0
⊢ ∏ i ∈ n.primeFactors, ↑(i - 1) = ∏ x ∈ n.primeFactors, (1 - (↑x)⁻¹) * ↑x

tactic: refine prod_congr rfl fun p hp => ?_
state_before: case neg
n : ℕ
hn : ¬n = 0
hn' : ↑n ≠ 0
hpQ : ∏ p ∈ n.primeFactors, ↑p ≠ 0
⊢ ∏ i ∈ n.primeFactors, ↑(i - 1) = ∏ x ∈ n.primeFactors, (1 - (↑x)⁻¹) * ↑x
state_after: case neg
n : ℕ
hn : ¬n = 0
hn' : ↑n ≠ 0
hpQ : ∏ p ∈ n.primeFactors, ↑p ≠ 0
p : ℕ
hp : p ∈ n.primeFactors
⊢ ↑(p - 1) = (1 - (↑p)⁻¹) * ↑p

tactic: have hp := pos_of_mem_factors (List.mem_toFinset.mp hp)
state_before: case neg
n : ℕ
hn : ¬n = 0
hn' : ↑n ≠ 0
hpQ : ∏ p ∈ n.primeFactors, ↑p ≠ 0
p : ℕ
hp : p ∈ n.primeFactors
⊢ ↑(p - 1) = (1 - (↑p)⁻¹) * ↑p
state_after: case neg
n : ℕ
hn : ¬n = 0
hn' : ↑n ≠ 0
hpQ : ∏ p ∈ n.primeFactors, ↑p ≠ 0
p : ℕ
hp✝ : p ∈ n.primeFactors
hp : 0 < p
⊢ ↑(p - 1) = (1 - (↑p)⁻¹) * ↑p

tactic: have hp' : (p : ℚ) ≠ 0 := cast_ne_zero.mpr hp.ne.symm
state_before: case neg
n : ℕ
hn : ¬n = 0
hn' : ↑n ≠ 0
hpQ : ∏ p ∈ n.primeFactors, ↑p ≠ 0
p : ℕ
hp✝ : p ∈ n.primeFactors
hp : 0 < p
⊢ ↑(p - 1) = (1 - (↑p)⁻¹) * ↑p
state_after: case neg
n : ℕ
hn : ¬n = 0
hn' : ↑n ≠ 0
hpQ : ∏ p ∈ n.primeFactors, ↑p ≠ 0
p : ℕ
hp✝ : p ∈ n.primeFactors
hp : 0 < p
hp' : ↑p ≠ 0
⊢ ↑(p - 1) = (1 - (↑p)⁻¹) * ↑p

tactic: rw [sub_mul, one_mul, mul_comm, mul_inv_cancel hp', cast_pred hp]
state_before: case neg
n : ℕ
hn : ¬n = 0
hn' : ↑n ≠ 0
hpQ : ∏ p ∈ n.primeFactors, ↑p ≠ 0
p : ℕ
hp✝ : p ∈ n.primeFactors
hp : 0 < p
hp' : ↑p ≠ 0
⊢ ↑(p - 1) = (1 - (↑p)⁻¹) * ↑p
state_after: no goals

tactic: simp [hn]
state_before: case pos
n : ℕ
hn : n = 0
⊢ ↑(φ n) = ↑n * ∏ p ∈ n.primeFactors, (1 - (↑p)⁻¹)
state_after: no goals

tactic: simp [hn]
state_before: n : ℕ
hn : ¬n = 0
⊢ ↑n ≠ 0
state_after: no goals

tactic: rw [← cast_prod, cast_ne_zero, ← zero_lt_iff, prod_primeFactors_prod_factorization]
state_before: n : ℕ
hn : ¬n = 0
hn' : ↑n ≠ 0
⊢ ∏ p ∈ n.primeFactors, ↑p ≠ 0
state_after: n : ℕ
hn : ¬n = 0
hn' : ↑n ≠ 0
⊢ 0 < n.factorization.prod fun p x => p

tactic: exact prod_pos fun p hp => pos_of_mem_primeFactors hp
state_before: n : ℕ
hn : ¬n = 0
hn' : ↑n ≠ 0
⊢ 0 < n.factorization.prod fun p x => p
state_after: no goals