Theorem: Configuration.HasLines.lineCount_eq_pointCount
File: Mathlib/Combinatorics/Configuration.lean

tactic: obtain ⟨f, hf1, hf2⟩ := HasLines.exists_bijective_of_card_eq hPL
state_before: P : Type u_1
L : Type u_2
inst✝³ : Membership P L
inst✝² : HasLines P L
inst✝¹ : Fintype P
inst✝ : Fintype L
hPL : Fintype.card P = Fintype.card L
p : P
l : L
hpl : ¬p ∈ l
⊢ lineCount L p = pointCount P l

tactic: let s : Finset (P × L) := Set.toFinset { i | i.1 ∈ i.2 }
state_before: case intro.intro
P : Type u_1
L : Type u_2
inst✝³ : Membership P L
inst✝² : HasLines P L
inst✝¹ : Fintype P
inst✝ : Fintype L
hPL : Fintype.card P = Fintype.card L
p : P
l : L
hpl : ¬p ∈ l
f : L → P
hf1 : Function.Bijective f
hf2 : ∀ (l : L), pointCount P l = lineCount L (f l)
⊢ lineCount L p = pointCount P l

tactic: have step1 : (∑ i : P × L, lineCount L i.1) = ∑ i : P × L, pointCount P i.2 := by
  rw [← Finset.univ_product_univ, Finset.sum_product_right, Finset.sum_product]
  simp_rw [Finset.sum_const, Finset.card_univ, hPL, sum_lineCount_eq_sum_pointCount]
state_before: case intro.intro
P : Type u_1
L : Type u_2
inst✝³ : Membership P L
inst✝² : HasLines P L
inst✝¹ : Fintype P
inst✝ : Fintype L
hPL : Fintype.card P = Fintype.card L
p : P
l : L
hpl : ¬p ∈ l
f : L → P
hf1 : Function.Bijective f
hf2 : ∀ (l : L), pointCount P l = lineCount L (f l)
s : Finset (P × L) := Set.toFinset {i | i.fst ∈ i.snd}
⊢ lineCount L p = pointCount P l

tactic: have step3 : (∑ i in sᶜ, lineCount L i.1) = ∑ i in sᶜ, pointCount P i.2 := by
  rwa [← s.sum_add_sum_compl, ← s.sum_add_sum_compl, step2, add_left_cancel_iff] at step1
state_before: case intro.intro
P : Type u_1
L : Type u_2
inst✝³ : Membership P L
inst✝² : HasLines P L
inst✝¹ : Fintype P
inst✝ : Fintype L
hPL : Fintype.card P = Fintype.card L
p : P
l : L
hpl : ¬p ∈ l
f : L → P
hf1 : Function.Bijective f
hf2 : ∀ (l : L), pointCount P l = lineCount L (f l)
s : Finset (P × L) := Set.toFinset {i | i.fst ∈ i.snd}
step1 : ∑ i : P × L, lineCount L i.fst = ∑ i : P × L, pointCount P i.snd
step2 : ∑ i in s, lineCount L i.fst = ∑ i in s, pointCount P i.snd
⊢ lineCount L p = pointCount P l

tactic: rw [← Set.toFinset_compl] at step3
state_before: case intro.intro
P : Type u_1
L : Type u_2
inst✝³ : Membership P L
inst✝² : HasLines P L
inst✝¹ : Fintype P
inst✝ : Fintype L
hPL : Fintype.card P = Fintype.card L
p : P
l : L
hpl : ¬p ∈ l
f : L → P
hf1 : Function.Bijective f
hf2 : ∀ (l : L), pointCount P l = lineCount L (f l)
s : Finset (P × L) := Set.toFinset {i | i.fst ∈ i.snd}
step1 : ∑ i : P × L, lineCount L i.fst = ∑ i : P × L, pointCount P i.snd
step2 : ∑ i in s, lineCount L i.fst = ∑ i in s, pointCount P i.snd
step3 : ∑ i in sᶜ, lineCount L i.fst = ∑ i in sᶜ, pointCount P i.snd
⊢ lineCount L p = pointCount P l

tactic: exact
  ((Finset.sum_eq_sum_iff_of_le fun i hi =>
          HasLines.pointCount_le_lineCount (by exact Set.mem_toFinset.mp hi)).mp
      step3.symm (p, l) (Set.mem_toFinset.mpr hpl)).symm
state_before: case intro.intro
P : Type u_1
L : Type u_2
inst✝³ : Membership P L
inst✝² : HasLines P L
inst✝¹ : Fintype P
inst✝ : Fintype L
hPL : Fintype.card P = Fintype.card L
p : P
l : L
hpl : ¬p ∈ l
f : L → P
hf1 : Function.Bijective f
hf2 : ∀ (l : L), pointCount P l = lineCount L (f l)
s : Finset (P × L) := Set.toFinset {i | i.fst ∈ i.snd}
step1 : ∑ i : P × L, lineCount L i.fst = ∑ i : P × L, pointCount P i.snd
step2 : ∑ i in s, lineCount L i.fst = ∑ i in s, pointCount P i.snd
step3 :
  ∑ i in Set.toFinset ({i | i.fst ∈ i.snd}ᶜ), lineCount L i.fst =
    ∑ i in Set.toFinset ({i | i.fst ∈ i.snd}ᶜ), pointCount P i.snd
⊢ lineCount L p = pointCount P l

tactic: rw [← Finset.univ_product_univ, Finset.sum_product_right, Finset.sum_product]
state_before: P : Type u_1
L : Type u_2
inst✝³ : Membership P L
inst✝² : HasLines P L
inst✝¹ : Fintype P
inst✝ : Fintype L
hPL : Fintype.card P = Fintype.card L
p : P
l : L
hpl : ¬p ∈ l
f : L → P
hf1 : Function.Bijective f
hf2 : ∀ (l : L), pointCount P l = lineCount L (f l)
s : Finset (P × L) := Set.toFinset {i | i.fst ∈ i.snd}
⊢ ∑ i : P × L, lineCount L i.fst = ∑ i : P × L, pointCount P i.snd

tactic: simp_rw [Finset.sum_const, Finset.card_univ, hPL, sum_lineCount_eq_sum_pointCount]
state_before: P : Type u_1
L : Type u_2
inst✝³ : Membership P L
inst✝² : HasLines P L
inst✝¹ : Fintype P
inst✝ : Fintype L
hPL : Fintype.card P = Fintype.card L
p : P
l : L
hpl : ¬p ∈ l
f : L → P
hf1 : Function.Bijective f
hf2 : ∀ (l : L), pointCount P l = lineCount L (f l)
s : Finset (P × L) := Set.toFinset {i | i.fst ∈ i.snd}
⊢ ∑ y : L, ∑ x : P, lineCount L (x, y).fst = ∑ x : P, ∑ y : L, pointCount P (x, y).snd

tactic: rw [s.sum_finset_product Finset.univ fun p => Set.toFinset { l | p ∈ l }]
state_before: P : Type u_1
L : Type u_2
inst✝³ : Membership P L
inst✝² : HasLines P L
inst✝¹ : Fintype P
inst✝ : Fintype L
hPL : Fintype.card P = Fintype.card L
p : P
l : L
hpl : ¬p ∈ l
f : L → P
hf1 : Function.Bijective f
hf2 : ∀ (l : L), pointCount P l = lineCount L (f l)
s : Finset (P × L) := Set.toFinset {i | i.fst ∈ i.snd}
step1 : ∑ i : P × L, lineCount L i.fst = ∑ i : P × L, pointCount P i.snd
⊢ ∑ i in s, lineCount L i.fst = ∑ i in s, pointCount P i.snd

tactic: rw [s.sum_finset_product_right Finset.univ fun l => Set.toFinset { p | p ∈ l }]
state_before: P : Type u_1
L : Type u_2
inst✝³ : Membership P L
inst✝² : HasLines P L
inst✝¹ : Fintype P
inst✝ : Fintype L
hPL : Fintype.card P = Fintype.card L
p : P
l : L
hpl : ¬p ∈ l
f : L → P
hf1 : Function.Bijective f
hf2 : ∀ (l : L), pointCount P l = lineCount L (f l)
s : Finset (P × L) := Set.toFinset {i | i.fst ∈ i.snd}
step1 : ∑ i : P × L, lineCount L i.fst = ∑ i : P × L, pointCount P i.snd
⊢ ∑ c : P, ∑ a in Set.toFinset {l | c ∈ l}, lineCount L (c, a).fst = ∑ i in s, pointCount P i.snd

case h
P : Type u_1
L : Type u_2
inst✝³ : Membership P L
inst✝² : HasLines P L
inst✝¹ : Fintype P
inst✝ : Fintype L
hPL : Fintype.card P = Fintype.card L
p : P
l : L
hpl : ¬p ∈ l
f : L → P
hf1 : Function.Bijective f
hf2 : ∀ (l : L), pointCount P l = lineCount L (f l)
s : Finset (P × L) := Set.toFinset {i | i.fst ∈ i.snd}
step1 : ∑ i : P × L, lineCount L i.fst = ∑ i : P × L, pointCount P i.snd
⊢ ∀ (p : P × L), p ∈ s ↔ p.fst ∈ Finset.univ ∧ p.snd ∈ Set.toFinset {l | p.fst ∈ l}

tactic: refine'
  (Finset.sum_bij (fun l _ => f l) (fun l _ => Finset.mem_univ (f l)) (fun l hl => _)
      (fun _ _ _ _ h => hf1.1 h) fun p _ => _).symm
state_before: P : Type u_1
L : Type u_2
inst✝³ : Membership P L
inst✝² : HasLines P L
inst✝¹ : Fintype P
inst✝ : Fintype L
hPL : Fintype.card P = Fintype.card L
p : P
l : L
hpl : ¬p ∈ l
f : L → P
hf1 : Function.Bijective f
hf2 : ∀ (l : L), pointCount P l = lineCount L (f l)
s : Finset (P × L) := Set.toFinset {i | i.fst ∈ i.snd}
step1 : ∑ i : P × L, lineCount L i.fst = ∑ i : P × L, pointCount P i.snd
⊢ ∑ c : P, ∑ a in Set.toFinset {l | c ∈ l}, lineCount L (c, a).fst =
    ∑ c : L, ∑ a in Set.toFinset {p | p ∈ c}, pointCount P (a, c).snd

case h
P : Type u_1
L : Type u_2
inst✝³ : Membership P L
inst✝² : HasLines P L
inst✝¹ : Fintype P
inst✝ : Fintype L
hPL : Fintype.card P = Fintype.card L
p : P
l : L
hpl : ¬p ∈ l
f : L → P
hf1 : Function.Bijective f
hf2 : ∀ (l : L), pointCount P l = lineCount L (f l)
s : Finset (P × L) := Set.toFinset {i | i.fst ∈ i.snd}
step1 : ∑ i : P × L, lineCount L i.fst = ∑ i : P × L, pointCount P i.snd
⊢ ∀ (p : P × L), p ∈ s ↔ p.snd ∈ Finset.univ ∧ p.fst ∈ Set.toFinset {p_1 | p_1 ∈ p.snd}

case h
P : Type u_1
L : Type u_2
inst✝³ : Membership P L
inst✝² : HasLines P L
inst✝¹ : Fintype P
inst✝ : Fintype L
hPL : Fintype.card P = Fintype.card L
p : P
l : L
hpl : ¬p ∈ l
f : L → P
hf1 : Function.Bijective f
hf2 : ∀ (l : L), pointCount P l = lineCount L (f l)
s : Finset (P × L) := Set.toFinset {i | i.fst ∈ i.snd}
step1 : ∑ i : P × L, lineCount L i.fst = ∑ i : P × L, pointCount P i.snd
⊢ ∀ (p : P × L), p ∈ s ↔ p.fst ∈ Finset.univ ∧ p.snd ∈ Set.toFinset {l | p.fst ∈ l}

tactic: all_goals simp_rw [Finset.mem_univ, true_and_iff, Set.mem_toFinset]; exact fun p => Iff.rfl
state_before: case h
P : Type u_1
L : Type u_2
inst✝³ : Membership P L
inst✝² : HasLines P L
inst✝¹ : Fintype P
inst✝ : Fintype L
hPL : Fintype.card P = Fintype.card L
p : P
l : L
hpl : ¬p ∈ l
f : L → P
hf1 : Function.Bijective f
hf2 : ∀ (l : L), pointCount P l = lineCount L (f l)
s : Finset (P × L) := Set.toFinset {i | i.fst ∈ i.snd}
step1 : ∑ i : P × L, lineCount L i.fst = ∑ i : P × L, pointCount P i.snd
⊢ ∀ (p : P × L), p ∈ s ↔ p.snd ∈ Finset.univ ∧ p.fst ∈ Set.toFinset {p_1 | p_1 ∈ p.snd}

case h
P : Type u_1
L : Type u_2
inst✝³ : Membership P L
inst✝² : HasLines P L
inst✝¹ : Fintype P
inst✝ : Fintype L
hPL : Fintype.card P = Fintype.card L
p : P
l : L
hpl : ¬p ∈ l
f : L → P
hf1 : Function.Bijective f
hf2 : ∀ (l : L), pointCount P l = lineCount L (f l)
s : Finset (P × L) := Set.toFinset {i | i.fst ∈ i.snd}
step1 : ∑ i : P × L, lineCount L i.fst = ∑ i : P × L, pointCount P i.snd
⊢ ∀ (p : P × L), p ∈ s ↔ p.fst ∈ Finset.univ ∧ p.snd ∈ Set.toFinset {l | p.fst ∈ l}

tactic: simp_rw [Finset.sum_const, Set.toFinset_card, ← Nat.card_eq_fintype_card]
state_before: case refine'_1
P : Type u_1
L : Type u_2
inst✝³ : Membership P L
inst✝² : HasLines P L
inst✝¹ : Fintype P
inst✝ : Fintype L
hPL : Fintype.card P = Fintype.card L
p : P
l✝ : L
hpl : ¬p ∈ l✝
f : L → P
hf1 : Function.Bijective f
hf2 : ∀ (l : L), pointCount P l = lineCount L (f l)
s : Finset (P × L) := Set.toFinset {i | i.fst ∈ i.snd}
step1 : ∑ i : P × L, lineCount L i.fst = ∑ i : P × L, pointCount P i.snd
l : L
hl : l ∈ Finset.univ
⊢ ∑ a in Set.toFinset {p | p ∈ l}, pointCount P (a, l).snd =
    ∑ a in Set.toFinset {l_1 | (fun l x => f l) l hl ∈ l_1}, lineCount L ((fun l x => f l) l hl, a).fst

tactic: change pointCount P l • pointCount P l = lineCount L (f l) • lineCount L (f l)
state_before: case refine'_1
P : Type u_1
L : Type u_2
inst✝³ : Membership P L
inst✝² : HasLines P L
inst✝¹ : Fintype P
inst✝ : Fintype L
hPL : Fintype.card P = Fintype.card L
p : P
l✝ : L
hpl : ¬p ∈ l✝
f : L → P
hf1 : Function.Bijective f
hf2 : ∀ (l : L), pointCount P l = lineCount L (f l)
s : Finset (P × L) := Set.toFinset {i | i.fst ∈ i.snd}
step1 : ∑ i : P × L, lineCount L i.fst = ∑ i : P × L, pointCount P i.snd
l : L
hl : l ∈ Finset.univ
⊢ Nat.card ↑{p | p ∈ l} • pointCount P l = Nat.card ↑{l_1 | f l ∈ l_1} • lineCount L (f l)

tactic: rw [hf2]
state_before: case refine'_1
P : Type u_1
L : Type u_2
inst✝³ : Membership P L
inst✝² : HasLines P L
inst✝¹ : Fintype P
inst✝ : Fintype L
hPL : Fintype.card P = Fintype.card L
p : P
l✝ : L
hpl : ¬p ∈ l✝
f : L → P
hf1 : Function.Bijective f
hf2 : ∀ (l : L), pointCount P l = lineCount L (f l)
s : Finset (P × L) := Set.toFinset {i | i.fst ∈ i.snd}
step1 : ∑ i : P × L, lineCount L i.fst = ∑ i : P × L, pointCount P i.snd
l : L
hl : l ∈ Finset.univ
⊢ pointCount P l • pointCount P l = lineCount L (f l) • lineCount L (f l)

tactic: obtain ⟨l, hl⟩ := hf1.2 p
state_before: case refine'_2
P : Type u_1
L : Type u_2
inst✝³ : Membership P L
inst✝² : HasLines P L
inst✝¹ : Fintype P
inst✝ : Fintype L
hPL : Fintype.card P = Fintype.card L
p✝ : P
l : L
hpl : ¬p✝ ∈ l
f : L → P
hf1 : Function.Bijective f
hf2 : ∀ (l : L), pointCount P l = lineCount L (f l)
s : Finset (P × L) := Set.toFinset {i | i.fst ∈ i.snd}
step1 : ∑ i : P × L, lineCount L i.fst = ∑ i : P × L, pointCount P i.snd
p : P
x✝ : p ∈ Finset.univ
⊢ ∃ a ha, p = (fun l x => f l) a ha

tactic: exact ⟨l, Finset.mem_univ l, hl.symm⟩
state_before: case refine'_2.intro
P : Type u_1
L : Type u_2
inst✝³ : Membership P L
inst✝² : HasLines P L
inst✝¹ : Fintype P
inst✝ : Fintype L
hPL : Fintype.card P = Fintype.card L
p✝ : P
l✝ : L
hpl : ¬p✝ ∈ l✝
f : L → P
hf1 : Function.Bijective f
hf2 : ∀ (l : L), pointCount P l = lineCount L (f l)
s : Finset (P × L) := Set.toFinset {i | i.fst ∈ i.snd}
step1 : ∑ i : P × L, lineCount L i.fst = ∑ i : P × L, pointCount P i.snd
p : P
x✝ : p ∈ Finset.univ
l : L
hl : f l = p
⊢ ∃ a ha, p = (fun l x => f l) a ha

tactic: simp_rw [Finset.mem_univ, true_and_iff, Set.mem_toFinset]
state_before: case h
P : Type u_1
L : Type u_2
inst✝³ : Membership P L
inst✝² : HasLines P L
inst✝¹ : Fintype P
inst✝ : Fintype L
hPL : Fintype.card P = Fintype.card L
p : P
l : L
hpl : ¬p ∈ l
f : L → P
hf1 : Function.Bijective f
hf2 : ∀ (l : L), pointCount P l = lineCount L (f l)
s : Finset (P × L) := Set.toFinset {i | i.fst ∈ i.snd}
step1 : ∑ i : P × L, lineCount L i.fst = ∑ i : P × L, pointCount P i.snd
⊢ ∀ (p : P × L), p ∈ s ↔ p.fst ∈ Finset.univ ∧ p.snd ∈ Set.toFinset {l | p.fst ∈ l}

tactic: exact fun p => Iff.rfl
state_before: case h
P : Type u_1
L : Type u_2
inst✝³ : Membership P L
inst✝² : HasLines P L
inst✝¹ : Fintype P
inst✝ : Fintype L
hPL : Fintype.card P = Fintype.card L
p : P
l : L
hpl : ¬p ∈ l
f : L → P
hf1 : Function.Bijective f
hf2 : ∀ (l : L), pointCount P l = lineCount L (f l)
s : Finset (P × L) := Set.toFinset {i | i.fst ∈ i.snd}
step1 : ∑ i : P × L, lineCount L i.fst = ∑ i : P × L, pointCount P i.snd
⊢ ∀ (p : P × L), p ∈ {i | i.fst ∈ i.snd} ↔ p.snd ∈ {l | p.fst ∈ l}

tactic: rwa [← s.sum_add_sum_compl, ← s.sum_add_sum_compl, step2, add_left_cancel_iff] at step1
state_before: P : Type u_1
L : Type u_2
inst✝³ : Membership P L
inst✝² : HasLines P L
inst✝¹ : Fintype P
inst✝ : Fintype L
hPL : Fintype.card P = Fintype.card L
p : P
l : L
hpl : ¬p ∈ l
f : L → P
hf1 : Function.Bijective f
hf2 : ∀ (l : L), pointCount P l = lineCount L (f l)
s : Finset (P × L) := Set.toFinset {i | i.fst ∈ i.snd}
step1 : ∑ i : P × L, lineCount L i.fst = ∑ i : P × L, pointCount P i.snd
step2 : ∑ i in s, lineCount L i.fst = ∑ i in s, pointCount P i.snd
⊢ ∑ i in sᶜ, lineCount L i.fst = ∑ i in sᶜ, pointCount P i.snd

tactic: exact Set.mem_toFinset.mp hi
state_before: P : Type u_1
L : Type u_2
inst✝³ : Membership P L
inst✝² : HasLines P L
inst✝¹ : Fintype P
inst✝ : Fintype L
hPL : Fintype.card P = Fintype.card L
p : P
l : L
hpl : ¬p ∈ l
f : L → P
hf1 : Function.Bijective f
hf2 : ∀ (l : L), pointCount P l = lineCount L (f l)
s : Finset (P × L) := Set.toFinset {i | i.fst ∈ i.snd}
step1 : ∑ i : P × L, lineCount L i.fst = ∑ i : P × L, pointCount P i.snd
step2 : ∑ i in s, lineCount L i.fst = ∑ i in s, pointCount P i.snd
step3 :
  ∑ i in Set.toFinset ({i | i.fst ∈ i.snd}ᶜ), lineCount L i.fst =
    ∑ i in Set.toFinset ({i | i.fst ∈ i.snd}ᶜ), pointCount P i.snd
i : P × L
hi : i ∈ Set.toFinset ({i | i.fst ∈ i.snd}ᶜ)
⊢ ¬i.fst ∈ i.snd