@@ -123,37 +123,23 @@ namespace Sym2
123123variable [DecidableEq α]
124124
125125/-- The `diag` of `s : Finset α` is sent on a finset of `Sym2 α` of card `#s`. -/
126- theorem card_image_diag (s : Finset α) : #(s.diag.image Sym2.mk) = #s := by
127- rw [card_image_of_injOn, diag_card]
128- rintro ⟨x₀, x₁⟩ hx _ _ h
129- cases Sym2.eq.1 h
130- · rfl
131- · simp only [mem_coe, mem_diag] at hx
132- rw [hx.2 ]
133-
134- lemma two_mul_card_image_offDiag (s : Finset α) : 2 * #(s.offDiag.image Sym2.mk) = #s.offDiag := by
135- rw [card_eq_sum_card_image (Sym2.mk : α × α → _), sum_const_nat (Sym2.ind _), mul_comm]
136- rintro x y hxy
137- simp_rw [mem_image, mem_offDiag] at hxy
138- obtain ⟨a, ⟨ha₁, ha₂, ha⟩, h⟩ := hxy
139- replace h := Sym2.eq.1 h
140- obtain ⟨hx, hy, hxy⟩ : x ∈ s ∧ y ∈ s ∧ x ≠ y := by
141- cases h <;> refine ⟨‹_›, ‹_›, ?_⟩ <;> [exact ha; exact ha.symm]
142- have hxy' : y ≠ x := hxy.symm
143- have : {z ∈ s.offDiag | Sym2.mk z = s(x, y)} = {(x, y), (y, x)} := by
144- ext ⟨x₁, y₁⟩
145- rw [mem_filter, mem_insert, mem_singleton, Sym2.eq_iff, Prod.mk_inj, Prod.mk_inj,
146- and_iff_right_iff_imp]
147- -- `hxy'` is used in `exact`
148- rintro (⟨rfl, rfl⟩ | ⟨rfl, rfl⟩) <;> rw [mem_offDiag] <;> exact ⟨‹_›, ‹_›, ‹_›⟩
149- rw [this, card_insert_of_notMem, card_singleton]
150- simp only [not_and, Prod.mk_inj, mem_singleton]
151- exact fun _ => hxy'
126+ theorem card_image_diag (s : Finset α) : #(s.diag.image Sym2.mk.uncurry) = #s := by
127+ simp [card_image_of_injOn]
128+
129+ lemma two_mul_card_image_offDiag (s : Finset α) :
130+ 2 * #(s.offDiag.image Sym2.mk.uncurry) = #s.offDiag := by
131+ rw [card_eq_sum_card_image (Sym2.mk.uncurry : α × α → _), sum_const_nat (Sym2.ind _), mul_comm]
132+ -- FIXME: Would be cool for the final `aesop` call not to require this `a ≠ b ∨ b ≠ a` trick.
133+ have (a b : α) (ha : a ∈ s) (hb : b ∈ s) (hab : a ≠ b ∨ b ≠ a) :
134+ {z ∈ s.offDiag | Sym2.mk.uncurry z = s(a, b)} = .cons (a, b) {(b, a)}
135+ (by simpa [eq_comm] using hab) := by aesop
136+ aesop
152137
153138/-- The `offDiag` of `s : Finset α` is sent on a finset of `Sym2 α` of card `#s.offDiag / 2`.
154139This is because every element `s(x, y)` of `Sym2 α` not on the diagonal comes from exactly two
155140pairs: `(x, y)` and `(y, x)`. -/
156- theorem card_image_offDiag (s : Finset α) : #(s.offDiag.image Sym2.mk) = (#s).choose 2 := by
141+ theorem card_image_offDiag (s : Finset α) :
142+ #(s.offDiag.image Sym2.mk.uncurry) = (#s).choose 2 := by
157143 rw [Nat.choose_two_right, Nat.mul_sub_left_distrib, mul_one, ← offDiag_card,
158144 Nat.div_eq_of_eq_mul_right Nat.zero_lt_two (two_mul_card_image_offDiag s).symm]
159145
0 commit comments