Balanced ternary factors with prescribed digit histograms
ProvedThreeSumFuture.fixed_histogram_ternary_split3sumalgorithmscombinatorics
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 sorrySource
Original refinement of the balanced-product stencil argument for the weighted-cache 3SUM source profiles.