AFTD Auto-Formalizing Theoretical Domains

op861_disjoint_boolean_windows_count

theoremverified

For a finite Boolean coordinate set, pairwise disjoint coordinate blocks, and integer offsets depending only on coordinates outside all blocks, the number of assignments satisfying one integer score window on each block, multiplied by the product of two to each block size, is at most two to the number of coordinates times the product over blocks of the window length times the largest binomial coefficient of that block size. Each score adds the offset to the number of bits matching a specified pattern.

Statement

theorem op861_disjoint_boolean_windows_count (β ι : Type) [Fintype β]
    [DecidableEq β] [DecidableEq ι] (J : Finset ι) (B : ι → Finset β)
    (pattern : ι → β → Bool) (lo hi : ι → ℤ) (offset : ι → (β → Bool) → ℤ)
    (hdisj : ∀ i ∈ J, ∀ j ∈ J, i ≠ j → Disjoint (B i) (B j))
    (hwindow : ∀ i ∈ J, lo i ≤ hi i)
    (hstable : ∀ i ∈ J, ∀ ω ω' : β → Bool,
      (∀ t, t ∉ J.biUnion B → ω t = ω' t) → offset i ω = offset i ω') :
    let score : ι → (β → Bool) → ℤ := fun i ω =>
      offset i ω + ∑ t ∈ B i, (if ω t = pattern i t then (1 : ℤ) else 0)
    ((Finset.univ : Finset (β → Bool)).filter (fun ω =>
      ∀ i ∈ J, lo i ≤ score i ω ∧ score i ω ≤ hi i)).card *
      (∏ i ∈ J, 2 ^ (B i).card) ≤
        2 ^ Fintype.card β *
          ∏ i ∈ J, ((hi i - lo i + 1).toNat * (B i).card.choose ((B i).card / 2))
Source
Finite independent-block small-ball counting step for op861_dense_triangle_orientation_sqrt_cover.
Verified
18 Nov 2026
Axioms
Classical.choiceQuot.soundpropext
Built on 6
Used by 2

The proof, explained

The proof bounds the number of global Boolean assignments whose score on each coordinate block falls in a given integer window. Because the blocks are pairwise disjoint and the score offsets depend only on coordinates outside all blocks, conditioning on any assignment to the external coordinates decouples the blocks. On each block, Sperner-type bounds for windowed sums limit the number of valid local assignments by the window length times the central binomial coefficient of the block size. Combining these local bounds via a uniform block product theorem and multiplying by the product of 2 to each block size transforms the external factor into 2 to the total number of coordinates.

  1. Set up the score function, an extension operator from external coordinates, and the per-block window condition.

    Assuming classical logic, we introduce the score definition. To separate coordinates inside the blocks from those outside, we define ext (which extends an assignment on the complement of the block union to all coordinates by setting all block coordinates to false), cnt (which counts pattern matches within a block), and P (which requires that the offset determined by ext plus the local block count falls into [lo i, hi i]).

    lines 15–23

      classical
      intro score
      let ext : ({t : β // t ∉ J.biUnion B} → Bool) → β → Bool :=
        fun a t => if h : t ∉ J.biUnion B then a ⟨t, h⟩ else false
      let cnt : ∀ i : {i : ι // i ∈ J}, ({t : β // t ∈ B i.1} → Bool) → ℤ := fun i v =>
        (((Finset.univ : Finset {t : β // t ∈ B i.1}).filter (fun t => v t = pattern i.1 t.1)).card : ℤ)
      let P : ({t : β // t ∉ J.biUnion B} → Bool) →
          ∀ i : {i : ι // i ∈ J}, ({t : β // t ∈ B i.1} → Bool) → Prop :=
        fun a i v => lo i.1 ≤ offset i.1 (ext a) + cnt i v ∧ offset i.1 (ext a) + cnt i v ≤ hi i.1
  2. For any block and assignment, the indicator sum for pattern matches equals the number of matching coordinates in that block.

    Rewriting the sum over the block as a sum over the corresponding subtype using Finset.sum_coe_sort, the indicator sum simplifies via Finset.sum_boole to the cardinality of the filtered subtype of coordinates where the assignment matches the pattern.

    lines 24–28

    uses Finset.sum_coe_sort, Finset.sum_boole

      have hsum : ∀ (i : ι) (ω : β → Bool), ∑ t ∈ B i, (if ω t = pattern i t then (1 : ℤ) else 0)
          = (((Finset.univ : Finset {t : β // t ∈ B i}).filter
              (fun t => (fun t : {t : β // t ∈ B i} => ω t.1) t = pattern i t.1)).card : ℤ) := by
        intro i ω
        rw [← Finset.sum_coe_sort (B i), Finset.sum_boole]
  3. The offset for each block depends only on coordinates outside all blocks.

    The stability hypothesis hstable guarantees that the offset is unchanged if an assignment is modified only on the coordinates within the blocks. Since ext preserves all values outside the blocks and sets block coordinates to false, the offset on the extended assignment equals the offset on the original assignment.

    lines 29–33

    uses dif_pos

      have hext : ∀ i ∈ J, ∀ ω : β → Bool, offset i (ext (fun t => ω t.1)) = offset i ω := by
        intro i hi ω
        apply hstable i hi
        intro t ht
        simp only [ext, dif_pos ht]
  4. The number of global assignments satisfying all block score windows is bounded by the number of external assignments times the product of each block's local window bound.

    We apply op861_boolean_block_uniform_bound. To satisfy its premises, we verify: (1) every global satisfying assignment fulfills the block predicate P for each block, since the score decomposes into the external offset and the match count; and (2) for any fixed external assignment and any block, the number of local assignments satisfying P is at most the window length times the central binomial coefficient of the block size, by op861_boolean_matching_window_count.

    lines 34–52

    uses op861_boolean_block_uniform_bound, op861_boolean_matching_window_count, Fintype.card_coe, le_trans, le_of_eq, Finset.mem_filter, Finset.mem_univ, true_and

      have key := op861_boolean_block_uniform_bound β ι J B
        (fun ω => ∀ i ∈ J, lo i ≤ score i ω ∧ score i ω ≤ hi i) P
        (fun i => (hi i - lo i + 1).toNat * (B i).card.choose ((B i).card / 2))
        (by
          intro ω hω i
          have h := hω i.1 i.2
          simp only [score, hsum] at h
          simp only [P, cnt]
          rw [hext i.1 i.2 ω]
          exact h)
        (by
          intro a i
          have := op861_boolean_matching_window_count {t : β // t ∈ B i.1} (fun t => pattern i.1 t.1)
            (lo i.1) (hi i.1) (offset i.1 (ext a)) (hwindow i.1 i.2)
          rw [Fintype.card_coe] at this
          refine le_trans (le_of_eq ?_) this
          congr 1
          ext v
          simp only [Finset.mem_filter, Finset.mem_univ, true_and, P, cnt])
  5. The subtype product over block indices equals the finset product over J.

    We rewrite the product over the subtype {i // i ∈ J} in the key bound to a product over the finite set J using Finset.prod_coe_sort.

    lines 53–57

    uses Finset.prod_coe_sort

      have hprod : (∏ i : {i : ι // i ∈ J},
          (hi i.1 - lo i.1 + 1).toNat * (B i.1).card.choose ((B i.1).card / 2))
          = ∏ i ∈ J, ((hi i - lo i + 1).toNat * (B i).card.choose ((B i).card / 2)) :=
        Finset.prod_coe_sort J (fun i => (hi i - lo i + 1).toNat * (B i).card.choose ((B i).card / 2))
      rw [hprod] at key
  6. Multiplying by the product of 2 to each block size yields the theorem inequality.

    By op861_disjoint_boolean_partition_card, the pairwise disjointness of the blocks implies that 2 to the number of external coordinates times the product of 2 to each block size equals 2 to the total number of coordinates. Multiplying both sides of the key bound by the product of 2 to each block size and substituting this identity finishes the proof by ring arithmetic.

    lines 58–62

    uses op861_disjoint_boolean_partition_card, Nat.mul_le_mul_right

      have hpart := op861_disjoint_boolean_partition_card β ι J B hdisj
      calc _ ≤ (Fintype.card ({t : β // t ∉ J.biUnion B} → Bool) *
            ∏ i ∈ J, ((hi i - lo i + 1).toNat * (B i).card.choose ((B i).card / 2))) *
              (∏ i ∈ J, 2 ^ (B i).card) := Nat.mul_le_mul_right _ key
        _ = _ := by rw [← hpart]; ring
dif_pos
A dependent if-then-else evaluates to its true branch when the condition holds.
Fintype.card_coe
The cardinality of the subtype corresponding to a finite set equals the cardinality of the finite set.
Finset.sum_boole
The sum of the indicator of a predicate over a finite set equals the cardinality of the subset satisfying that predicate.
Finset.sum_coe_sort
Summing a function over the subtype of elements in a finite set equals the sum over the finite set itself.
Finset.prod_coe_sort
Multiplying a function over the subtype of elements in a finite set equals the product over the finite set itself.
Finset.mem_filter
An element belongs to a filtered finite set if and only if it belongs to the set and satisfies the filter predicate.
Finset.mem_univ
Every element of a finite type belongs to its universal finite set.
le_trans
Inequality is transitive.
le_of_eq
An equality implies a weak inequality.
Nat.mul_le_mul_right
Multiplying both sides of a natural inequality by a non-negative factor preserves the inequality.
op861_boolean_block_uniform_bound
If a global property implies local block predicates and each block predicate has at most limit_i satisfying assignments regardless of the coordinates outside the blocks, then the number of global satisfying assignments is at most the number of external assignments times the product of the limits.
op861_boolean_matching_window_count
The number of assignments on a finite set whose number of pattern matches shifted by an offset falls in [lo, hi] is at most the interval length times the central binomial coefficient of the set size.
op861_disjoint_boolean_partition_card
For pairwise disjoint blocks of coordinates, the number of assignments outside the blocks times the product over blocks of 2 to each block size equals 2 to the total number of coordinates.
true_and
The conjunction of True with any proposition p is logically equivalent to p.

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

theorem op861_disjoint_boolean_windows_count (β ι : Type) [Fintype β]    [DecidableEq β] [DecidableEq ι] (J : Finset ι) (B : ι → Finset β)    (pattern : ι → β → Bool) (lo hi : ι → ℤ) (offset : ι → (β → Bool) → ℤ)    (hdisj : ∀ i ∈ J, ∀ j ∈ J, i ≠ j → Disjoint (B i) (B j))    (hwindow : ∀ i ∈ J, lo i ≤ hi i)    (hstable : ∀ i ∈ J, ∀ ω ω' : β → Bool,      (∀ t, t ∉ J.biUnion B → ω t = ω' t) → offset i ω = offset i ω') :    let score : ι → (β → Bool) → ℤ := fun i ω =>      offset i ω + ∑ t ∈ B i, (if ω t = pattern i t then (1 : ℤ) else 0)    ((Finset.univ : Finset (β → Bool)).filter (fun ω =>      ∀ i ∈ J, lo i ≤ score i ω ∧ score i ω ≤ hi i)).card *      (∏ i ∈ J, 2 ^ (B i).card) ≤        2 ^ Fintype.card β *          ∏ i ∈ J, ((hi i - lo i + 1).toNat * (B i).card.choose ((B i).card / 2)) := by  classical  intro score  let ext : ({t : β // t ∉ J.biUnion B} → Bool) → β → Bool :=    fun a t => if h : t ∉ J.biUnion B then a ⟨t, h⟩ else false  let cnt : ∀ i : {i : ι // i ∈ J}, ({t : β // t ∈ B i.1} → Bool) → ℤ := fun i v =>    (((Finset.univ : Finset {t : β // t ∈ B i.1}).filter (fun t => v t = pattern i.1 t.1)).card : ℤ)  let P : ({t : β // t ∉ J.biUnion B} → Bool) →      ∀ i : {i : ι // i ∈ J}, ({t : β // t ∈ B i.1} → Bool) → Prop :=    fun a i v => lo i.1 ≤ offset i.1 (ext a) + cnt i v ∧ offset i.1 (ext a) + cnt i v ≤ hi i.1  have hsum : ∀ (i : ι) (ω : β → Bool), ∑ t ∈ B i, (if ω t = pattern i t then (1 : ℤ) else 0)      = (((Finset.univ : Finset {t : β // t ∈ B i}).filter          (fun t => (fun t : {t : β // t ∈ B i} => ω t.1) t = pattern i t.1)).card : ℤ) := by    intro i ω    rw [← Finset.sum_coe_sort (B i), Finset.sum_boole]  have hext : ∀ i ∈ J, ∀ ω : β → Bool, offset i (ext (fun t => ω t.1)) = offset i ω := by    intro i hi ω    apply hstable i hi    intro t ht    simp only [ext, dif_pos ht]  have key := op861_boolean_block_uniform_bound β ι J B    (fun ω => ∀ i ∈ J, lo i ≤ score i ω ∧ score i ω ≤ hi i) P    (fun i => (hi i - lo i + 1).toNat * (B i).card.choose ((B i).card / 2))    (by      intro ω hω i      have h := hω i.1 i.2      simp only [score, hsum] at h      simp only [P, cnt]      rw [hext i.1 i.2 ω]      exact h)    (by      intro a i      have := op861_boolean_matching_window_count {t : β // t ∈ B i.1} (fun t => pattern i.1 t.1)        (lo i.1) (hi i.1) (offset i.1 (ext a)) (hwindow i.1 i.2)      rw [Fintype.card_coe] at this      refine le_trans (le_of_eq ?_) this      congr 1      ext v      simp only [Finset.mem_filter, Finset.mem_univ, true_and, P, cnt])  have hprod : (∏ i : {i : ι // i ∈ J},      (hi i.1 - lo i.1 + 1).toNat * (B i.1).card.choose ((B i.1).card / 2))      = ∏ i ∈ J, ((hi i - lo i + 1).toNat * (B i).card.choose ((B i).card / 2)) :=    Finset.prod_coe_sort J (fun i => (hi i - lo i + 1).toNat * (B i).card.choose ((B i).card / 2))  rw [hprod] at key  have hpart := op861_disjoint_boolean_partition_card β ι J B hdisj  calc _ ≤ (Fintype.card ({t : β // t ∉ J.biUnion B} → Bool) *        ∏ i ∈ J, ((hi i - lo i + 1).toNat * (B i).card.choose ((B i).card / 2))) *          (∏ i ∈ J, 2 ^ (B i).card) := Nat.mul_le_mul_right _ key    _ = _ := by rw [← hpart]; ring
See it in the graphDiscuss this resultChallenge it