Theorem: DihedralGroup.commProb_reciprocal
File: Mathlib/GroupTheory/CommutingProbability.lean

tactic: by_cases h0 : n = 0
state_before: M : Type u_1
inst✝³ : Mul M
inst✝² : Finite M
G : Type u_2
inst✝¹ : Group G
inst✝ : Finite G
H : Subgroup G
n : ℕ
⊢ commProb (Product (reciprocalFactors n)) = 1 / ↑n
state_after: case pos
M : Type u_1
inst✝³ : Mul M
inst✝² : Finite M
G : Type u_2
inst✝¹ : Group G
inst✝ : Finite G
H : Subgroup G
n : ℕ
h0 : n = 0
⊢ commProb (Product (reciprocalFactors n)) = 1 / ↑n

case neg
M : Type u_1
inst✝³ : Mul M
inst✝² : Finite M
G : Type u_2
inst✝¹ : Group G
inst✝ : Finite G
H : Subgroup G
n : ℕ
h0 : ¬n = 0
⊢ commProb (Product (reciprocalFactors n)) = 1 / ↑n

tactic: by_cases h1 : n = 1
state_before: case neg
M : Type u_1
inst✝³ : Mul M
inst✝² : Finite M
G : Type u_2
inst✝¹ : Group G
inst✝ : Finite G
H : Subgroup G
n : ℕ
h0 : ¬n = 0
⊢ commProb (Product (reciprocalFactors n)) = 1 / ↑n
state_after: case pos
M : Type u_1
inst✝³ : Mul M
inst✝² : Finite M
G : Type u_2
inst✝¹ : Group G
inst✝ : Finite G
H : Subgroup G
n : ℕ
h0 : ¬n = 0
h1 : n = 1
⊢ commProb (Product (reciprocalFactors n)) = 1 / ↑n

case neg
M : Type u_1
inst✝³ : Mul M
inst✝² : Finite M
G : Type u_2
inst✝¹ : Group G
inst✝ : Finite G
H : Subgroup G
n : ℕ
h0 : ¬n = 0
h1 : ¬n = 1
⊢ commProb (Product (reciprocalFactors n)) = 1 / ↑n

tactic: rcases Nat.even_or_odd n with h2 | h2
state_before: case neg
M : Type u_1
inst✝³ : Mul M
inst✝² : Finite M
G : Type u_2
inst✝¹ : Group G
inst✝ : Finite G
H : Subgroup G
n : ℕ
h0 : ¬n = 0
h1 : ¬n = 1
⊢ commProb (Product (reciprocalFactors n)) = 1 / ↑n
state_after: case neg.inl
M : Type u_1
inst✝³ : Mul M
inst✝² : Finite M
G : Type u_2
inst✝¹ : Group G
inst✝ : Finite G
H : Subgroup G
n : ℕ
h0 : ¬n = 0
h1 : ¬n = 1
h2 : Even n
⊢ commProb (Product (reciprocalFactors n)) = 1 / ↑n

case neg.inr
M : Type u_1
inst✝³ : Mul M
inst✝² : Finite M
G : Type u_2
inst✝¹ : Group G
inst✝ : Finite G
H : Subgroup G
n : ℕ
h0 : ¬n = 0
h1 : ¬n = 1
h2 : Odd n
⊢ commProb (Product (reciprocalFactors n)) = 1 / ↑n

tactic: rw [h0, reciprocalFactors_zero, commProb_cons, commProb_nil, mul_one, Nat.cast_zero, div_zero]
state_before: case pos
M : Type u_1
inst✝³ : Mul M
inst✝² : Finite M
G : Type u_2
inst✝¹ : Group G
inst✝ : Finite G
H : Subgroup G
n : ℕ
h0 : n = 0
⊢ commProb (Product (reciprocalFactors n)) = 1 / ↑n
state_after: case pos
M : Type u_1
inst✝³ : Mul M
inst✝² : Finite M
G : Type u_2
inst✝¹ : Group G
inst✝ : Finite G
H : Subgroup G
n : ℕ
h0 : n = 0
⊢ commProb (DihedralGroup 0) = 0

tactic: apply commProb_eq_zero_of_infinite
state_before: case pos
M : Type u_1
inst✝³ : Mul M
inst✝² : Finite M
G : Type u_2
inst✝¹ : Group G
inst✝ : Finite G
H : Subgroup G
n : ℕ
h0 : n = 0
⊢ commProb (DihedralGroup 0) = 0
state_after: no goals

tactic: rw [h1, reciprocalFactors_one, commProb_nil, Nat.cast_one, div_one]
state_before: case pos
M : Type u_1
inst✝³ : Mul M
inst✝² : Finite M
G : Type u_2
inst✝¹ : Group G
inst✝ : Finite G
H : Subgroup G
n : ℕ
h0 : ¬n = 0
h1 : n = 1
⊢ commProb (Product (reciprocalFactors n)) = 1 / ↑n
state_after: no goals

tactic: have := div_two_lt h0
state_before: case neg.inl
M : Type u_1
inst✝³ : Mul M
inst✝² : Finite M
G : Type u_2
inst✝¹ : Group G
inst✝ : Finite G
H : Subgroup G
n : ℕ
h0 : ¬n = 0
h1 : ¬n = 1
h2 : Even n
⊢ commProb (Product (reciprocalFactors n)) = 1 / ↑n
state_after: case neg.inl
M : Type u_1
inst✝³ : Mul M
inst✝² : Finite M
G : Type u_2
inst✝¹ : Group G
inst✝ : Finite G
H : Subgroup G
n : ℕ
h0 : ¬n = 0
h1 : ¬n = 1
h2 : Even n
this : n / 2 < n
⊢ commProb (Product (reciprocalFactors n)) = 1 / ↑n

tactic: rw [reciprocalFactors_even h0 h2, commProb_cons, commProb_reciprocal (n / 2),
    commProb_odd (by decide)]
state_before: case neg.inl
M : Type u_1
inst✝³ : Mul M
inst✝² : Finite M
G : Type u_2
inst✝¹ : Group G
inst✝ : Finite G
H : Subgroup G
n : ℕ
h0 : ¬n = 0
h1 : ¬n = 1
h2 : Even n
this : n / 2 < n
⊢ commProb (Product (reciprocalFactors n)) = 1 / ↑n
state_after: case neg.inl
M : Type u_1
inst✝³ : Mul M
inst✝² : Finite M
G : Type u_2
inst✝¹ : Group G
inst✝ : Finite G
H : Subgroup G
n : ℕ
h0 : ¬n = 0
h1 : ¬n = 1
h2 : Even n
this : n / 2 < n
⊢ (↑3 + 3) / (4 * ↑3) * (1 / ↑(n / 2)) = 1 / ↑n

tactic: field_simp [h0, h2.two_dvd]
state_before: case neg.inl
M : Type u_1
inst✝³ : Mul M
inst✝² : Finite M
G : Type u_2
inst✝¹ : Group G
inst✝ : Finite G
H : Subgroup G
n : ℕ
h0 : ¬n = 0
h1 : ¬n = 1
h2 : Even n
this : n / 2 < n
⊢ (↑3 + 3) / (4 * ↑3) * (1 / ↑(n / 2)) = 1 / ↑n
state_after: case neg.inl
M : Type u_1
inst✝³ : Mul M
inst✝² : Finite M
G : Type u_2
inst✝¹ : Group G
inst✝ : Finite G
H : Subgroup G
n : ℕ
h0 : ¬n = 0
h1 : ¬n = 1
h2 : Even n
this : n / 2 < n
⊢ (3 + 3) * 2 = 4 * 3

tactic: norm_num
state_before: case neg.inl
M : Type u_1
inst✝³ : Mul M
inst✝² : Finite M
G : Type u_2
inst✝¹ : Group G
inst✝ : Finite G
H : Subgroup G
n : ℕ
h0 : ¬n = 0
h1 : ¬n = 1
h2 : Even n
this : n / 2 < n
⊢ (3 + 3) * 2 = 4 * 3
state_after: no goals

tactic: decide
state_before: M : Type u_1
inst✝³ : Mul M
inst✝² : Finite M
G : Type u_2
inst✝¹ : Group G
inst✝ : Finite G
H : Subgroup G
n : ℕ
h0 : ¬n = 0
h1 : ¬n = 1
h2 : Even n
this : n / 2 < n
⊢ Odd 3
state_after: no goals

tactic: have := div_four_lt h0 h1
state_before: case neg.inr
M : Type u_1
inst✝³ : Mul M
inst✝² : Finite M
G : Type u_2
inst✝¹ : Group G
inst✝ : Finite G
H : Subgroup G
n : ℕ
h0 : ¬n = 0
h1 : ¬n = 1
h2 : Odd n
⊢ commProb (Product (reciprocalFactors n)) = 1 / ↑n
state_after: case neg.inr
M : Type u_1
inst✝³ : Mul M
inst✝² : Finite M
G : Type u_2
inst✝¹ : Group G
inst✝ : Finite G
H : Subgroup G
n : ℕ
h0 : ¬n = 0
h1 : ¬n = 1
h2 : Odd n
this : n / 4 + 1 < n
⊢ commProb (Product (reciprocalFactors n)) = 1 / ↑n

tactic: rw [reciprocalFactors_odd h1 h2, commProb_cons, commProb_reciprocal (n / 4 + 1)]
state_before: case neg.inr
M : Type u_1
inst✝³ : Mul M
inst✝² : Finite M
G : Type u_2
inst✝¹ : Group G
inst✝ : Finite G
H : Subgroup G
n : ℕ
h0 : ¬n = 0
h1 : ¬n = 1
h2 : Odd n
this : n / 4 + 1 < n
⊢ commProb (Product (reciprocalFactors n)) = 1 / ↑n
state_after: case neg.inr
M : Type u_1
inst✝³ : Mul M
inst✝² : Finite M
G : Type u_2
inst✝¹ : Group G
inst✝ : Finite G
H : Subgroup G
n : ℕ
h0 : ¬n = 0
h1 : ¬n = 1
h2 : Odd n
this : n / 4 + 1 < n
⊢ commProb (DihedralGroup (n % 4 * n)) * (1 / ↑(n / 4 + 1)) = 1 / ↑n

tactic: have key : n % 4 = 1 ∨ n % 4 = 3 := Nat.odd_mod_four_iff.mp (Nat.odd_iff.mp h2)
state_before: case neg.inr
M : Type u_1
inst✝³ : Mul M
inst✝² : Finite M
G : Type u_2
inst✝¹ : Group G
inst✝ : Finite G
H : Subgroup G
n : ℕ
h0 : ¬n = 0
h1 : ¬n = 1
h2 : Odd n
this : n / 4 + 1 < n
⊢ commProb (DihedralGroup (n % 4 * n)) * (1 / ↑(n / 4 + 1)) = 1 / ↑n
state_after: case neg.inr
M : Type u_1
inst✝³ : Mul M
inst✝² : Finite M
G : Type u_2
inst✝¹ : Group G
inst✝ : Finite G
H : Subgroup G
n : ℕ
h0 : ¬n = 0
h1 : ¬n = 1
h2 : Odd n
this : n / 4 + 1 < n
key : n % 4 = 1 ∨ n % 4 = 3
⊢ commProb (DihedralGroup (n % 4 * n)) * (1 / ↑(n / 4 + 1)) = 1 / ↑n

tactic: have hn : Odd (n % 4) := by rcases key with h | h <;> rw [h] <;> decide
state_before: case neg.inr
M : Type u_1
inst✝³ : Mul M
inst✝² : Finite M
G : Type u_2
inst✝¹ : Group G
inst✝ : Finite G
H : Subgroup G
n : ℕ
h0 : ¬n = 0
h1 : ¬n = 1
h2 : Odd n
this : n / 4 + 1 < n
key : n % 4 = 1 ∨ n % 4 = 3
⊢ commProb (DihedralGroup (n % 4 * n)) * (1 / ↑(n / 4 + 1)) = 1 / ↑n
state_after: case neg.inr
M : Type u_1
inst✝³ : Mul M
inst✝² : Finite M
G : Type u_2
inst✝¹ : Group G
inst✝ : Finite G
H : Subgroup G
n : ℕ
h0 : ¬n = 0
h1 : ¬n = 1
h2 : Odd n
this : n / 4 + 1 < n
key : n % 4 = 1 ∨ n % 4 = 3
hn : Odd (n % 4)
⊢ commProb (DihedralGroup (n % 4 * n)) * (1 / ↑(n / 4 + 1)) = 1 / ↑n

tactic: rw [commProb_odd (hn.mul h2), div_mul_div_comm, mul_one, div_eq_div_iff, one_mul] <;> norm_cast
state_before: case neg.inr
M : Type u_1
inst✝³ : Mul M
inst✝² : Finite M
G : Type u_2
inst✝¹ : Group G
inst✝ : Finite G
H : Subgroup G
n : ℕ
h0 : ¬n = 0
h1 : ¬n = 1
h2 : Odd n
this : n / 4 + 1 < n
key : n % 4 = 1 ∨ n % 4 = 3
hn : Odd (n % 4)
⊢ commProb (DihedralGroup (n % 4 * n)) * (1 / ↑(n / 4 + 1)) = 1 / ↑n
state_after: case neg.inr
M : Type u_1
inst✝³ : Mul M
inst✝² : Finite M
G : Type u_2
inst✝¹ : Group G
inst✝ : Finite G
H : Subgroup G
n : ℕ
h0 : ¬n = 0
h1 : ¬n = 1
h2 : Odd n
this : n / 4 + 1 < n
key : n % 4 = 1 ∨ n % 4 = 3
hn : Odd (n % 4)
⊢ (n % 4 * n + 3) * n = 4 * (n % 4 * n) * (n / 4 + 1)

case neg.inr.hb
M : Type u_1
inst✝³ : Mul M
inst✝² : Finite M
G : Type u_2
inst✝¹ : Group G
inst✝ : Finite G
H : Subgroup G
n : ℕ
h0 : ¬n = 0
h1 : ¬n = 1
h2 : Odd n
this : n / 4 + 1 < n
key : n % 4 = 1 ∨ n % 4 = 3
hn : Odd (n % 4)
⊢ ¬4 * (n % 4 * n) * (n / 4 + 1) = 0

tactic: rcases key with h | h <;> rw [h] <;> decide
state_before: M : Type u_1
inst✝³ : Mul M
inst✝² : Finite M
G : Type u_2
inst✝¹ : Group G
inst✝ : Finite G
H : Subgroup G
n : ℕ
h0 : ¬n = 0
h1 : ¬n = 1
h2 : Odd n
this : n / 4 + 1 < n
key : n % 4 = 1 ∨ n % 4 = 3
⊢ Odd (n % 4)
state_after: no goals

tactic: have h0 : (n % 4) ^ 2 + 3 = n % 4 * 4 := by rcases key with h | h <;> rw [h] <;> norm_num
state_before: case neg.inr
M : Type u_1
inst✝³ : Mul M
inst✝² : Finite M
G : Type u_2
inst✝¹ : Group G
inst✝ : Finite G
H : Subgroup G
n : ℕ
h0 : ¬n = 0
h1 : ¬n = 1
h2 : Odd n
this : n / 4 + 1 < n
key : n % 4 = 1 ∨ n % 4 = 3
hn : Odd (n % 4)
⊢ (n % 4 * n + 3) * n = 4 * (n % 4 * n) * (n / 4 + 1)
state_after: case neg.inr
M : Type u_1
inst✝³ : Mul M
inst✝² : Finite M
G : Type u_2
inst✝¹ : Group G
inst✝ : Finite G
H : Subgroup G
n : ℕ
h0✝ : ¬n = 0
h1 : ¬n = 1
h2 : Odd n
this : n / 4 + 1 < n
key : n % 4 = 1 ∨ n % 4 = 3
hn : Odd (n % 4)
h0 : (n % 4) ^ 2 + 3 = n % 4 * 4
⊢ (n % 4 * n + 3) * n = 4 * (n % 4 * n) * (n / 4 + 1)

tactic: have h1 := (Nat.div_add_mod n 4).symm
state_before: case neg.inr
M : Type u_1
inst✝³ : Mul M
inst✝² : Finite M
G : Type u_2
inst✝¹ : Group G
inst✝ : Finite G
H : Subgroup G
n : ℕ
h0✝ : ¬n = 0
h1 : ¬n = 1
h2 : Odd n
this : n / 4 + 1 < n
key : n % 4 = 1 ∨ n % 4 = 3
hn : Odd (n % 4)
h0 : (n % 4) ^ 2 + 3 = n % 4 * 4
⊢ (n % 4 * n + 3) * n = 4 * (n % 4 * n) * (n / 4 + 1)
state_after: case neg.inr
M : Type u_1
inst✝³ : Mul M
inst✝² : Finite M
G : Type u_2
inst✝¹ : Group G
inst✝ : Finite G
H : Subgroup G
n : ℕ
h0✝ : ¬n = 0
h1✝ : ¬n = 1
h2 : Odd n
this : n / 4 + 1 < n
key : n % 4 = 1 ∨ n % 4 = 3
hn : Odd (n % 4)
h0 : (n % 4) ^ 2 + 3 = n % 4 * 4
h1 : n = 4 * (n / 4) + n % 4
⊢ (n % 4 * n + 3) * n = 4 * (n % 4 * n) * (n / 4 + 1)

tactic: zify at h0 h1 ⊢
state_before: case neg.inr
M : Type u_1
inst✝³ : Mul M
inst✝² : Finite M
G : Type u_2
inst✝¹ : Group G
inst✝ : Finite G
H : Subgroup G
n : ℕ
h0✝ : ¬n = 0
h1✝ : ¬n = 1
h2 : Odd n
this : n / 4 + 1 < n
key : n % 4 = 1 ∨ n % 4 = 3
hn : Odd (n % 4)
h0 : (n % 4) ^ 2 + 3 = n % 4 * 4
h1 : n = 4 * (n / 4) + n % 4
⊢ (n % 4 * n + 3) * n = 4 * (n % 4 * n) * (n / 4 + 1)
state_after: case neg.inr
M : Type u_1
inst✝³ : Mul M
inst✝² : Finite M
G : Type u_2
inst✝¹ : Group G
inst✝ : Finite G
H : Subgroup G
n : ℕ
h0✝ : ¬n = 0
h1✝ : ¬n = 1
h2 : Odd n
this : n / 4 + 1 < n
key : n % 4 = 1 ∨ n % 4 = 3
hn : Odd (n % 4)
h0 : (↑n % 4) ^ 2 + 3 = ↑n % 4 * 4
h1 : ↑n = 4 * (↑n / 4) + ↑n % 4
⊢ (↑n % 4 * ↑n + 3) * ↑n = 4 * (↑n % 4 * ↑n) * (↑n / 4 + 1)

tactic: linear_combination (h0 + h1 * (n % 4)) * n
state_before: case neg.inr
M : Type u_1
inst✝³ : Mul M
inst✝² : Finite M
G : Type u_2
inst✝¹ : Group G
inst✝ : Finite G
H : Subgroup G
n : ℕ
h0✝ : ¬n = 0
h1✝ : ¬n = 1
h2 : Odd n
this : n / 4 + 1 < n
key : n % 4 = 1 ∨ n % 4 = 3
hn : Odd (n % 4)
h0 : (↑n % 4) ^ 2 + 3 = ↑n % 4 * 4
h1 : ↑n = 4 * (↑n / 4) + ↑n % 4
⊢ (↑n % 4 * ↑n + 3) * ↑n = 4 * (↑n % 4 * ↑n) * (↑n / 4 + 1)
state_after: no goals

tactic: rcases key with h | h <;> rw [h] <;> norm_num
state_before: M : Type u_1
inst✝³ : Mul M
inst✝² : Finite M
G : Type u_2
inst✝¹ : Group G
inst✝ : Finite G
H : Subgroup G
n : ℕ
h0 : ¬n = 0
h1 : ¬n = 1
h2 : Odd n
this : n / 4 + 1 < n
key : n % 4 = 1 ∨ n % 4 = 3
hn : Odd (n % 4)
⊢ (n % 4) ^ 2 + 3 = n % 4 * 4
state_after: no goals

tactic: have := hn.pos.ne'
state_before: case neg.inr.hb
M : Type u_1
inst✝³ : Mul M
inst✝² : Finite M
G : Type u_2
inst✝¹ : Group G
inst✝ : Finite G
H : Subgroup G
n : ℕ
h0 : ¬n = 0
h1 : ¬n = 1
h2 : Odd n
this : n / 4 + 1 < n
key : n % 4 = 1 ∨ n % 4 = 3
hn : Odd (n % 4)
⊢ ¬4 * (n % 4 * n) * (n / 4 + 1) = 0
state_after: case neg.inr.hb
M : Type u_1
inst✝³ : Mul M
inst✝² : Finite M
G : Type u_2
inst✝¹ : Group G
inst✝ : Finite G
H : Subgroup G
n : ℕ
h0 : ¬n = 0
h1 : ¬n = 1
h2 : Odd n
this✝ : n / 4 + 1 < n
key : n % 4 = 1 ∨ n % 4 = 3
hn : Odd (n % 4)
this : n % 4 ≠ 0
⊢ ¬4 * (n % 4 * n) * (n / 4 + 1) = 0

tactic: positivity
state_before: case neg.inr.hb
M : Type u_1
inst✝³ : Mul M
inst✝² : Finite M
G : Type u_2
inst✝¹ : Group G
inst✝ : Finite G
H : Subgroup G
n : ℕ
h0 : ¬n = 0
h1 : ¬n = 1
h2 : Odd n
this✝ : n / 4 + 1 < n
key : n % 4 = 1 ∨ n % 4 = 3
hn : Odd (n % 4)
this : n % 4 ≠ 0
⊢ ¬4 * (n % 4 * n) * (n / 4 + 1) = 0
state_after: no goals