AFTD Auto-Formalizing Theoretical Domains

wild_three_uniform_disjoint_pair_count

theoremverified

Let T_i be three-element subsets of a finite vertex type, indexed by a finite type of size N, with repeated subsets allowed. Suppose each vertex occurs in exactly d indices and each distinct vertex pair occurs in exactly l indices. Write v for the vertex count, D for the number of ORDERED index pairs with disjoint supports, and Q for the number of ORDERED index pairs with identical supports. Then2*D=2*N^2-2*v*d^2+(v^2-v)*l^2-2*Q as an integer identity. Identical supports include different indices; Q is not merely N.

Statement

theorem wild_three_uniform_disjoint_pair_count
    {ι κ : Type*} [Fintype ι] [Fintype κ] [DecidableEq ι] [DecidableEq κ]
    (T : ι → Finset κ) (d l : ℕ)
    (hsize : ∀ i, (T i).card = 3)
    (hvertex : ∀ a, (univ.filter fun i => a ∈ T i).card = d)
    (hpair : ∀ a b, a ≠ b →
      (univ.filter fun i => a ∈ T i ∧ b ∈ T i).card = l) :
    2 * ((univ.filter fun p : ι × ι => Disjoint (T p.1) (T p.2)).card : ℤ) =
      2 * (Fintype.card ι : ℤ)^2 - 2 * (Fintype.card κ : ℤ) * (d : ℤ)^2 +
        ((Fintype.card κ : ℤ)^2 - Fintype.card κ) * (l : ℤ)^2 -
        2 * ((univ.filter fun p : ι × ι => T p.1 = T p.2).card : ℤ)
Source
IN-359 / OP-306 helper for the uniform weighted-moment route. The associated threefold triple system is standard: Compatible factorizations and three-fold triple systems (2006), construction in the proof of Theorem4.1, https://citeseerx.ist.psu.edu/document?doi=58cc9f2b7c3862f0964a05e0ac1529b9c9de8e5e&repid=rep1&type=pdf (bibliographic record https://repo.uum.edu.my/id/eprint/3494/). The graph motivation is https://arxiv.org/html/2610.22142v1, Section3.3 and the open conjecture in Section6. Incidence square sums and three-element inclusion-exclusion are ordinary finite counting. No novelty, wild-number bound, sharpness case, or research advance is claimed. Exact finite audit8955 is diagnostic, not a hypothesis.
Verified
29 Oct 2026
Axioms
Classical.choiceQuot.soundpropext
Used by 2

The proof, explained

The theorem determines the number D of ordered disjoint pairs among N 3-element blocks in a design-like hypergraph on v vertices with regular degree d and pair co-degree l. The proof hinges on an indicator identity valid for any two 3-element sets S and T: 2 * 1_{Disjoint S T} = 2 - 2|S ∩ T| + |(S ∩ T).offDiag| - 2 * 1_{S = T}. Summing this relation over all ordered pairs (i, j) of block indices expresses 2 * D as four constituent sums. The total intersection sum and the off-diagonal intersection sum are evaluated via double counting (incidence matrix squares) as v * d^2 and (v^2 - v) * l^2 respectively, yielding the exact formula 2*D = 2*N^2 - 2*v*d^2 + (v^2 - v)*l^2 - 2*Q.

  1. For any indices i and j, the intersection size |T i ∩ T j| equals the sum over all vertices a ∈ κ of the product of indicator functions 1_{a ∈ T i} * 1_{a ∈ T j}.

    For each vertex a ∈ κ, the product 1_{a ∈ T i} * 1_{a ∈ T j} is 1 if a ∈ T i ∩ T j and 0 otherwise. Summing this indicator product over all vertices in κ yields the cardinality of T i ∩ T j.

    lines 10–25

    uses sum_congr, sum_filter

      classical
      have hcard (i j : ι) : ((T i ∩ T j).card : ℤ) =
          ∑ a : κ, (if a ∈ T i then (1 : ℤ) else 0) *
            (if a ∈ T j then (1 : ℤ) else 0) := by
        symm
        have hfilter : (univ.filter fun a : κ => a ∈ T i ∩ T j) = T i ∩ T j := by
          ext a
          simp
        calc
          _ = ∑ a : κ, if a ∈ T i ∩ T j then (1 : ℤ) else 0 := by
            apply sum_congr rfl
            intro a ha
            by_cases hi : a ∈ T i <;> by_cases hj : a ∈ T j <;> simp [hi,hj]
          _ = ((univ.filter fun a : κ => a ∈ T i ∩ T j).card : ℤ) := by
            simp [← sum_filter]
          _ = _ := by rw [hfilter]
  2. The double sum of intersection sizes ∑_{i, j} |T i ∩ T j| equals the sum of squared vertex degrees ∑_{a ∈ κ} |{i | a ∈ T i}|^2.

    Replacing |T i ∩ T j| by the indicator sum and exchanging the order of summation gives ∑_{a ∈ κ} (∑_i 1_{a ∈ T i}) * (∑_j 1_{a ∈ T j}). Factoring the inner double sum as the square of the degree of vertex a completes the identity wild_finite_incidence_intersection_square.

    lines 26–43

    uses sum_congr, sum_comm, sum_filter, sum_mul_sum, sq

      simp_rw [hcard]
      calc
        _ = ∑ i : ι, ∑ a : κ, ∑ j : ι,
            (if a ∈ T i then (1 : ℤ) else 0) *
              (if a ∈ T j then (1 : ℤ) else 0) := by
          apply sum_congr rfl
          intro i hi
          exact sum_comm
        _ = ∑ a : κ, ∑ i : ι, ∑ j : ι,
            (if a ∈ T i then (1 : ℤ) else 0) *
              (if a ∈ T j then (1 : ℤ) else 0) := sum_comm
        _ = _ := by
          apply sum_congr rfl
          intro a ha
          have h : (∑ i : ι, if a ∈ T i then (1 : ℤ) else 0) =
              ((univ.filter fun i => a ∈ T i).card : ℤ) := by simp [← sum_filter]
          rw [← sum_mul_sum, ← sq, h]
    
  3. For any finite set S, the integer cardinality of its off-diagonal pairs is |S.offDiag| = |S|^2 - |S|.

    Since |S| ≤ |S|^2 for any finite set, casting the natural number equality |S.offDiag| = |S|^2 - |S| to integers preserves the subtraction, yielding |S|^2 - |S| in ℤ.

    lines 44–53

    uses Nat.one_le_iff_ne_zero.mpr, Nat.mul_le_mul_left, offDiag_card, Nat.cast_sub, Nat.cast_mul

    theorem wild_finset_offDiag_card_int {κ : Type*} [DecidableEq κ] (S : Finset κ) :
        (S.offDiag.card : ℤ) = (S.card : ℤ)^2 - S.card := by
      have hle : S.card ≤ S.card * S.card := by
        by_cases h : S.card = 0
        · simp [h]
        · have hp : 1 ≤ S.card := Nat.one_le_iff_ne_zero.mpr h
          simpa using Nat.mul_le_mul_left S.card hp
      rw [offDiag_card, Nat.cast_sub hle, Nat.cast_mul]
      ring
    
  4. The indicator identity 2 * 1_{Disjoint S T} = 2 - 2|S ∩ T| + |(S ∩ T).offDiag| - 2 * 1_{S = T} holds when S = T.

    When S = T, the equality indicator is 1. Since |S| = 3, S is non-empty and cannot be disjoint from itself, so the left-hand side is 0. The intersection is S itself, having size 3 and 3^2 - 3 = 6 off-diagonal pairs; the right-hand side evaluates to 2 - 2(3) + 6 - 2(1) = 0.

    lines 54–73

    uses wild_finset_offDiag_card_int, congrArg

    theorem wild_three_set_disjoint_indicator
        {κ : Type*} [DecidableEq κ] (S T : Finset κ)
        (hS : S.card = 3) (hT : T.card = 3) :
        2 * (if Disjoint S T then (1 : ℤ) else 0) =
          2 - 2 * ((S ∩ T).card : ℤ) + ((S ∩ T).offDiag.card : ℤ) -
            2 * (if S = T then (1 : ℤ) else 0) := by
      classical
      rw [wild_finset_offDiag_card_int]
      by_cases heq : S = T
      · subst T
        have hne : S ≠ ∅ := by
          intro h
          rw [h] at hS
          simp at hS
        have hnot : ¬ Disjoint S S := by
          intro h
          have hz := disjoint_iff_inter_eq_empty.mp h
          have hcard := congrArg Finset.card hz
          simp [hS] at hcard
        simp [hne,hS]
  5. The indicator identity holds when S ≠ T.

    When S ≠ T, the equality indicator is 0. Since both S and T have size 3, their intersection size is strictly less than 3. If S and T are disjoint, |S ∩ T| = 0 and both sides equal 2. If they are not disjoint, |S ∩ T| must be 1 or 2; in both cases disjointness is false and the right-hand side evaluates to 0 (2 - 2(1) + 0 = 0 and 2 - 2(2) + 2 = 0).

    lines 74–91

    uses card_le_card, inter_subset_left, eq_of_subset_of_card_le, inter_subset_right

      · have hle : (S ∩ T).card ≤ 3 := by
          have h := card_le_card (inter_subset_left : S ∩ T ⊆ S)
          omega
        have hlt : (S ∩ T).card < 3 := by
          by_contra h
          have hleft : S ∩ T = S := eq_of_subset_of_card_le inter_subset_left (by omega)
          have hright : S ∩ T = T := eq_of_subset_of_card_le inter_subset_right (by omega)
          exact heq (hleft.symm.trans hright)
        by_cases hdis : Disjoint S T
        · have hz := disjoint_iff_inter_eq_empty.mp hdis
          simp [hdis,heq,hz]
        · have hp : 0 < (S ∩ T).card := by
            by_contra h
            have hz : (S ∩ T).card = 0 := by omega
            exact hdis (disjoint_iff_inter_eq_empty.mpr (card_eq_zero.mp hz))
          have hcases : (S ∩ T).card = 1 ∨ (S ∩ T).card = 2 := by omega
          rcases hcases with h | h <;> norm_num [heq,hdis,h]
    
  6. The total intersection sum over all index pairs satisfies ∑_{i, j} |T i ∩ T j| = v * d^2.

    By lemma wild_finite_incidence_intersection_square, the double sum of intersection sizes equals the sum over all vertices a ∈ κ of the square of their degree. Since each vertex occurs in exactly d blocks, the sum evaluates to |κ| * d^2 = v * d^2.

    lines 92–107

    uses wild_finite_incidence_intersection_square

    theorem wild_three_uniform_disjoint_pair_count
        {ι κ : Type*} [Fintype ι] [Fintype κ] [DecidableEq ι] [DecidableEq κ]
        (T : ι → Finset κ) (d l : ℕ)
        (hsize : ∀ i, (T i).card = 3)
        (hvertex : ∀ a, (univ.filter fun i => a ∈ T i).card = d)
        (hpair : ∀ a b, a ≠ b →
          (univ.filter fun i => a ∈ T i ∧ b ∈ T i).card = l) :
        2 * ((univ.filter fun p : ι × ι => Disjoint (T p.1) (T p.2)).card : ℤ) =
          2 * (Fintype.card ι : ℤ)^2 - 2 * (Fintype.card κ : ℤ) * (d : ℤ)^2 +
            ((Fintype.card κ : ℤ)^2 - Fintype.card κ) * (l : ℤ)^2 -
            2 * ((univ.filter fun p : ι × ι => T p.1 = T p.2).card : ℤ) := by
      classical
      have hinter : (∑ i : ι, ∑ j : ι, ((T i ∩ T j).card : ℤ)) =
          (Fintype.card κ : ℤ) * (d : ℤ)^2 := by
        rw [wild_finite_incidence_intersection_square]
        simp [hvertex]
  7. The total off-diagonal intersection sum satisfies ∑_{i, j} |(T i ∩ T j).offDiag| = (v^2 - v) * l^2.

    Since (T i ∩ T j).offDiag = (T i).offDiag ∩ (T j).offDiag, wild_finite_incidence_intersection_square rewrites the double sum as the sum over pairs p ∈ κ × κ of the square of the number of blocks containing p. Pairs with p.1 = p.2 never occur in the off-diagonal (giving 0), while distinct pairs p.1 ≠ p.2 occur in exactly l blocks. Summing l^2 over all v^2 - v off-diagonal pairs in κ gives (v^2 - v) * l^2.

    lines 108–128

    uses offDiag_inter, wild_finite_incidence_intersection_square, mem_offDiag, sum_filter, sum_const, nsmul_eq_mul, wild_finset_offDiag_card_int

      have hoff : (∑ i : ι, ∑ j : ι, ((T i ∩ T j).offDiag.card : ℤ)) =
          ((Fintype.card κ : ℤ)^2 - Fintype.card κ) * (l : ℤ)^2 := by
        simp_rw [offDiag_inter]
        rw [wild_finite_incidence_intersection_square]
        have hdeg (p : κ × κ) :
            ((univ.filter fun i => p ∈ (T i).offDiag).card : ℤ)^2 =
              if p.1 ≠ p.2 then (l : ℤ)^2 else 0 := by
          by_cases h : p.1 = p.2
          · simp [mem_offDiag,h]
          · simpa [mem_offDiag,h] using hpair p.1 p.2 h
        simp_rw [hdeg]
        have hfilter : (univ.filter fun p : κ × κ => p.1 ≠ p.2) =
            (univ : Finset κ).offDiag := by
          ext p
          simp
        calc
          _ = (((univ : Finset κ).offDiag.card : ℕ) : ℤ) * (l : ℤ)^2 := by
            rw [← hfilter]
            rw [← sum_filter]
            simp only [sum_const,nsmul_eq_mul]
          _ = _ := by rw [wild_finset_offDiag_card_int]; simp
  8. The counts of disjoint pairs D and identical pairs Q are expressed as iterated double sums of indicators.

    The cardinality of index pairs (i, j) with disjoint supports is converted from a filtered finset cardinality into a single sum of indicators over ι × ι, and then expanded into an iterated sum over i and j using Fintype.sum_prod_type. The count of pairs with identical supports Q is rewritten identically.

    lines 129–140

    uses sum_filter, Fintype.sum_prod_type

      have hD : ((univ.filter fun p : ι × ι => Disjoint (T p.1) (T p.2)).card : ℤ) =
          ∑ i : ι, ∑ j : ι, if Disjoint (T i) (T j) then (1 : ℤ) else 0 := by
        calc
          _ = ∑ p : ι × ι, if Disjoint (T p.1) (T p.2) then (1 : ℤ) else 0 := by
            simp [← sum_filter]
          _ = _ := Fintype.sum_prod_type _
      have hQ : ((univ.filter fun p : ι × ι => T p.1 = T p.2).card : ℤ) =
          ∑ i : ι, ∑ j : ι, if T i = T j then (1 : ℤ) else 0 := by
        calc
          _ = ∑ p : ι × ι, if T p.1 = T p.2 then (1 : ℤ) else 0 := by
            simp [← sum_filter]
          _ = _ := Fintype.sum_prod_type _
  9. The integer identity 2 * D = 2 * N^2 - 2 * v * d^2 + (v^2 - v) * l^2 - 2 * Q holds.

    We rewrite 2 * D as the double sum of 2 * 1_{Disjoint (T i) (T j)} and substitute the pointwise indicator identity from wild_three_set_disjoint_indicator for each pair (T i, T j). Distributing the sum yields four terms: summing 2 over all N^2 pairs gives 2 * N^2, the intersection sum contributes -2 * v * d^2, the off-diagonal sum contributes (v^2 - v) * l^2, and the identical support sum contributes -2 * Q. Linear arithmetic completes the proof.

    lines 141–162

    uses mul_sum, sum_congr, wild_three_set_disjoint_indicator, sum_sub_distrib, sum_add_distrib, sum_const, card_univ, nsmul_eq_mul

      calc
        _ = ∑ i : ι, ∑ j : ι, 2 * (if Disjoint (T i) (T j) then (1 : ℤ) else 0) := by
          rw [hD]
          simp_rw [mul_sum]
        _ = ∑ i : ι, ∑ j : ι,
            (2 - 2 * ((T i ∩ T j).card : ℤ) + ((T i ∩ T j).offDiag.card : ℤ) -
              2 * (if T i = T j then (1 : ℤ) else 0)) := by
          apply sum_congr rfl
          intro i hi
          apply sum_congr rfl
          intro j hj
          exact wild_three_set_disjoint_indicator _ _ (hsize i) (hsize j)
        _ = 2 * (Fintype.card ι : ℤ)^2 -
            2 * (∑ i : ι, ∑ j : ι, ((T i ∩ T j).card : ℤ)) +
            (∑ i : ι, ∑ j : ι, ((T i ∩ T j).offDiag.card : ℤ)) -
            2 * ((univ.filter fun p : ι × ι => T p.1 = T p.2).card : ℤ) := by
          rw [hQ]
          simp only [sum_sub_distrib,sum_add_distrib]
          simp_rw [← mul_sum]
          all_goals try simp only [sum_const,card_univ,nsmul_eq_mul]
          all_goals ring
        _ = _ := by rw [hinter,hoff]; ring
sum_congr
sums of pointwise equal functions over equal finite sets are equal
sum_filter
rewriting a sum of an indicator over a set as a sum over the filtered subset
sum_comm
swapping the order of summation in a double finite sum
sum_mul_sum
distributing the product of two finite sums into a double sum of products
sq
the square of an element equals the element multiplied by itself
Nat.one_le_iff_ne_zero.mpr
a natural number is at least 1 if and only if it is non-zero
Nat.mul_le_mul_left
multiplication by a constant preserves order on natural numbers
offDiag_card
the number of distinct pairs from a finite set S is |S|^2 - |S|
Nat.cast_sub
casting a subtraction of natural numbers to an ordered ring preserves subtraction when m ≤ n
Nat.cast_mul
casting a product of natural numbers to a semiring preserves multiplication
wild_finset_offDiag_card_int
the integer cardinality of the off-diagonal pairs of a finite set S is |S|^2 - |S|
congrArg
equality is preserved under applying a function to both sides
card_le_card
a subset has cardinality at most the superset
inter_subset_left
an intersection S ∩ T is a subset of S
eq_of_subset_of_card_le
if S ⊆ T and |T| ≤ |S|, then S = T
inter_subset_right
an intersection S ∩ T is a subset of T
wild_finite_incidence_intersection_square
the double sum of intersection sizes of a family of subsets equals the sum of squares of the vertex degrees
offDiag_inter
the off-diagonal of an intersection equals the intersection of the off-diagonals
mem_offDiag
a pair belongs to the off-diagonal of S if and only if both components are in S and are distinct
sum_const
summing a constant over a finite set equals the cardinality of the set times the constant
nsmul_eq_mul
scalar multiplication by a natural number equals multiplication by the natural number cast to the ring
Fintype.sum_prod_type
a sum over a Cartesian product type equals an iterated sum over the factors
mul_sum
multiplication by a constant factor distributes over a finite sum
wild_three_set_disjoint_indicator
for any two 3-element sets, 2 times the disjointness indicator equals 2 - 2|S ∩ T| + |(S ∩ T).offDiag| - 2 * [S = T]
sum_sub_distrib
a sum of differences of functions over a finite set distributes as the difference of the sums
sum_add_distrib
a sum of sums of functions over a finite set distributes as the sum of the sums
card_univ
the cardinality of the universal finset of a finite type is the type's cardinality

Written by a model (gemini-3.8-flash) from the Lean proof and the goal states Lean reported at each step. Lean verified the proof; this explanation is a reading aid and is not itself machine-checked.

Lean source view module on GitHub

open Finsetopen scoped BigOperatorsset_option maxHeartbeats 4000000theorem wild_finite_incidence_intersection_square    {ι κ : Type*} [Fintype ι] [Fintype κ] [DecidableEq ι] [DecidableEq κ]    (T : ι → Finset κ) :    (∑ i : ι, ∑ j : ι, ((T i ∩ T j).card : ℤ)) =      ∑ a : κ, ((univ.filter fun i => a ∈ T i).card : ℤ)^2 := by  classical  have hcard (i j : ι) : ((T i ∩ T j).card : ℤ) =      ∑ a : κ, (if a ∈ T i then (1 : ℤ) else 0) *        (if a ∈ T j then (1 : ℤ) else 0) := by    symm    have hfilter : (univ.filter fun a : κ => a ∈ T i ∩ T j) = T i ∩ T j := by      ext a      simp    calc      _ = ∑ a : κ, if a ∈ T i ∩ T j then (1 : ℤ) else 0 := by        apply sum_congr rfl        intro a ha        by_cases hi : a ∈ T i <;> by_cases hj : a ∈ T j <;> simp [hi,hj]      _ = ((univ.filter fun a : κ => a ∈ T i ∩ T j).card : ℤ) := by        simp [← sum_filter]      _ = _ := by rw [hfilter]  simp_rw [hcard]  calc    _ = ∑ i : ι, ∑ a : κ, ∑ j : ι,        (if a ∈ T i then (1 : ℤ) else 0) *          (if a ∈ T j then (1 : ℤ) else 0) := by      apply sum_congr rfl      intro i hi      exact sum_comm    _ = ∑ a : κ, ∑ i : ι, ∑ j : ι,        (if a ∈ T i then (1 : ℤ) else 0) *          (if a ∈ T j then (1 : ℤ) else 0) := sum_comm    _ = _ := by      apply sum_congr rfl      intro a ha      have h : (∑ i : ι, if a ∈ T i then (1 : ℤ) else 0) =          ((univ.filter fun i => a ∈ T i).card : ℤ) := by simp [← sum_filter]      rw [← sum_mul_sum, ← sq, h]theorem wild_finset_offDiag_card_int {κ : Type*} [DecidableEq κ] (S : Finset κ) :    (S.offDiag.card : ℤ) = (S.card : ℤ)^2 - S.card := by  have hle : S.card ≤ S.card * S.card := by    by_cases h : S.card = 0    · simp [h]    · have hp : 1 ≤ S.card := Nat.one_le_iff_ne_zero.mpr h      simpa using Nat.mul_le_mul_left S.card hp  rw [offDiag_card, Nat.cast_sub hle, Nat.cast_mul]  ringtheorem wild_three_set_disjoint_indicator    {κ : Type*} [DecidableEq κ] (S T : Finset κ)    (hS : S.card = 3) (hT : T.card = 3) :    2 * (if Disjoint S T then (1 : ℤ) else 0) =      2 - 2 * ((S ∩ T).card : ℤ) + ((S ∩ T).offDiag.card : ℤ) -        2 * (if S = T then (1 : ℤ) else 0) := by  classical  rw [wild_finset_offDiag_card_int]  by_cases heq : S = T  · subst T    have hne : S ≠ ∅ := by      intro h      rw [h] at hS      simp at hS    have hnot : ¬ Disjoint S S := by      intro h      have hz := disjoint_iff_inter_eq_empty.mp h      have hcard := congrArg Finset.card hz      simp [hS] at hcard    simp [hne,hS]  · have hle : (S ∩ T).card ≤ 3 := by      have h := card_le_card (inter_subset_left : S ∩ T ⊆ S)      omega    have hlt : (S ∩ T).card < 3 := by      by_contra h      have hleft : S ∩ T = S := eq_of_subset_of_card_le inter_subset_left (by omega)      have hright : S ∩ T = T := eq_of_subset_of_card_le inter_subset_right (by omega)      exact heq (hleft.symm.trans hright)    by_cases hdis : Disjoint S T    · have hz := disjoint_iff_inter_eq_empty.mp hdis      simp [hdis,heq,hz]    · have hp : 0 < (S ∩ T).card := by        by_contra h        have hz : (S ∩ T).card = 0 := by omega        exact hdis (disjoint_iff_inter_eq_empty.mpr (card_eq_zero.mp hz))      have hcases : (S ∩ T).card = 1 ∨ (S ∩ T).card = 2 := by omega      rcases hcases with h | h <;> norm_num [heq,hdis,h]theorem wild_three_uniform_disjoint_pair_count    {ι κ : Type*} [Fintype ι] [Fintype κ] [DecidableEq ι] [DecidableEq κ]    (T : ι → Finset κ) (d l : ℕ)    (hsize : ∀ i, (T i).card = 3)    (hvertex : ∀ a, (univ.filter fun i => a ∈ T i).card = d)    (hpair : ∀ a b, a ≠ b →      (univ.filter fun i => a ∈ T i ∧ b ∈ T i).card = l) :    2 * ((univ.filter fun p : ι × ι => Disjoint (T p.1) (T p.2)).card : ℤ) =      2 * (Fintype.card ι : ℤ)^2 - 2 * (Fintype.card κ : ℤ) * (d : ℤ)^2 +        ((Fintype.card κ : ℤ)^2 - Fintype.card κ) * (l : ℤ)^2 -        2 * ((univ.filter fun p : ι × ι => T p.1 = T p.2).card : ℤ) := by  classical  have hinter : (∑ i : ι, ∑ j : ι, ((T i ∩ T j).card : ℤ)) =      (Fintype.card κ : ℤ) * (d : ℤ)^2 := by    rw [wild_finite_incidence_intersection_square]    simp [hvertex]  have hoff : (∑ i : ι, ∑ j : ι, ((T i ∩ T j).offDiag.card : ℤ)) =      ((Fintype.card κ : ℤ)^2 - Fintype.card κ) * (l : ℤ)^2 := by    simp_rw [offDiag_inter]    rw [wild_finite_incidence_intersection_square]    have hdeg (p : κ × κ) :        ((univ.filter fun i => p ∈ (T i).offDiag).card : ℤ)^2 =          if p.1 ≠ p.2 then (l : ℤ)^2 else 0 := by      by_cases h : p.1 = p.2      · simp [mem_offDiag,h]      · simpa [mem_offDiag,h] using hpair p.1 p.2 h    simp_rw [hdeg]    have hfilter : (univ.filter fun p : κ × κ => p.1 ≠ p.2) =        (univ : Finset κ).offDiag := by      ext p      simp    calc      _ = (((univ : Finset κ).offDiag.card : ℕ) : ℤ) * (l : ℤ)^2 := by        rw [← hfilter]        rw [← sum_filter]        simp only [sum_const,nsmul_eq_mul]      _ = _ := by rw [wild_finset_offDiag_card_int]; simp  have hD : ((univ.filter fun p : ι × ι => Disjoint (T p.1) (T p.2)).card : ℤ) =      ∑ i : ι, ∑ j : ι, if Disjoint (T i) (T j) then (1 : ℤ) else 0 := by    calc      _ = ∑ p : ι × ι, if Disjoint (T p.1) (T p.2) then (1 : ℤ) else 0 := by        simp [← sum_filter]      _ = _ := Fintype.sum_prod_type _  have hQ : ((univ.filter fun p : ι × ι => T p.1 = T p.2).card : ℤ) =      ∑ i : ι, ∑ j : ι, if T i = T j then (1 : ℤ) else 0 := by    calc      _ = ∑ p : ι × ι, if T p.1 = T p.2 then (1 : ℤ) else 0 := by        simp [← sum_filter]      _ = _ := Fintype.sum_prod_type _  calc    _ = ∑ i : ι, ∑ j : ι, 2 * (if Disjoint (T i) (T j) then (1 : ℤ) else 0) := by      rw [hD]      simp_rw [mul_sum]    _ = ∑ i : ι, ∑ j : ι,        (2 - 2 * ((T i ∩ T j).card : ℤ) + ((T i ∩ T j).offDiag.card : ℤ) -          2 * (if T i = T j then (1 : ℤ) else 0)) := by      apply sum_congr rfl      intro i hi      apply sum_congr rfl      intro j hj      exact wild_three_set_disjoint_indicator _ _ (hsize i) (hsize j)    _ = 2 * (Fintype.card ι : ℤ)^2 -        2 * (∑ i : ι, ∑ j : ι, ((T i ∩ T j).card : ℤ)) +        (∑ i : ι, ∑ j : ι, ((T i ∩ T j).offDiag.card : ℤ)) -        2 * ((univ.filter fun p : ι × ι => T p.1 = T p.2).card : ℤ) := by      rw [hQ]      simp only [sum_sub_distrib,sum_add_distrib]      simp_rw [← mul_sum]      all_goals try simp only [sum_const,card_univ,nsmul_eq_mul]      all_goals ring    _ = _ := by rw [hinter,hoff]; ring
See it in the graphDiscuss this resultChallenge it