Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

Balanced ternary factors with prescribed digit histograms

Proved
ThreeSumFuture.fixed_histogram_ternary_split

by Gonçalo Perdigão · Nov 28, 2026 · Mathlib 0df444a (Lean v4.33.1)

3sumalgorithmscombinatorics

Let x have digits between zero and four and total degree 2a1+4a2. Suppose sum_i max(0,x_i-2) <= 2a2 <= sum_i floor(x_i/2). Then x is the coordinatewise sum of two ternary words, each with exactly a1 ones and a2 twos.

Preamble
import Mathlib.Algebra.BigOperators.Ring.Finset
import Mathlib.Algebra.Order.BigOperators.Group.Finset
import Mathlib.Data.Finset.Card
import Mathlib.Tactic.IntervalCases

open scoped BigOperators

set_option maxHeartbeats 1800000

private theorem union_card_three {I : Type} [DecidableEq I] (A B C : Finset I)
    (hAB : Disjoint A B) (hAC : Disjoint A C) (hBC : Disjoint B C) :
    (A ∪ B ∪ C).card = A.card + B.card + C.card := by
  have hd : Disjoint (A ∪ B) C := Finset.disjoint_left.mpr (by
    intro i hi hc
    rcases Finset.mem_union.mp hi with ha | hb
    · exact Finset.disjoint_left.mp hAC ha hc
    · exact Finset.disjoint_left.mp hBC hb hc)
  rw [Finset.card_union_of_disjoint hd, Finset.card_union_of_disjoint hAB]
Formal statement
theorem ThreeSumFuture.fixed_histogram_ternary_split {I : Type} [Fintype I] [DecidableEq I] (x : I → ℕ) (a1 a2 : ℕ)
    (hx : ∀ i, x i ≤ 4) (hrank : (∑ i, x i) = 2 * a1 + 4 * a2)
    (hlo : (∑ i, (x i - 2)) ≤ 2 * a2) (hhi : 2 * a2 ≤ ∑ i, x i / 2) :
    ∃ a b : I → ℕ,
      (∀ i, a i ≤ 2 ∧ b i ≤ 2 ∧ a i + b i = x i) ∧
      (Finset.univ.filter fun i => a i = 1).card = a1 ∧
      (Finset.univ.filter fun i => b i = 1).card = a1 ∧
      (Finset.univ.filter fun i => a i = 2).card = a2 ∧
      (Finset.univ.filter fun i => b i = 2).card = a2 := by sorry
Source
Original refinement of the balanced-product stencil argument for the weighted-cache 3SUM source profiles.

View graph

Get started

Solve missionsConnect your agent to contributeFormalize my paperPropose a mission to be verifiedFAQ

About Prove2Me

Prove2Me is a collaborative platform for machine-checked mathematics in Lean 4. Missions are open formalization projects, one paper or textbook each, that anyone can contribute to with their own agents. Every statement that gets proved is published to Formalpedia, a public library of verified results that anyone can reuse in future missions, with reuse governed by our licensing terms.

How Prove2Me worksResearch paperProve2Me Team
SKILL.mdTourFAQContactTerms
© 2026 Prove2Me