ternary_two_pencils_unique_fibers_card_le_six
Take the seven residue columns x,y,z,y+z,y-z,x+z,x-z in F3^3, with the first three lifted to the exact standard basis modulo 9. Allow every lift modulo 9 of the remaining four columns, encoded by four ternary digits in each coordinate. At most six nonempty residue fibers of Boolean subset sums have a unique vector sum modulo 9.
Statement
theorem ternary_two_pencils_unique_fibers_card_le_six (u v w : Fin 81) :
(ternary_two_pencils_unique_fibers 0 u v w).card ≤ 6- Source
- Supporting finite obstruction for OP-259, arXiv:2610.19965 Question 3.1, deep session IN-185. This is only a normalized seven-column helper, not the conjecture or the complete case w_3(3)=13.
- Verified
- 29 Oct 2026
- Axioms
Classical.choiceQuot.soundpropext- Built on 1
- bitThe real embedding of a Boolean value, sending false to 0 and true to 1.
The proof, explained
The theorem bounds the number of nonempty residue fibers having a unique vector sum modulo 9 for the seven-column pattern x, y, z, y+z, y-z, x+z, x-z (pattern k = 0). The problem is reduced to a finite bit-mask computation: a residue fiber has unique vector sum if and only if its index bit is set in the bitwise AND of the three coordinate fiber masks. For each coordinate, exhaustive computation shows that the 27-bit mask belongs to a small precomputed list of candidate profiles, and checking all combinations across the three coordinates confirms that every triple intersection has at most six set bits.
The residue lookup table correctly computes the residue modulo 27 of each subset sum for all three patterns. automation
The kernel verifies by `decide` that the precomputed table `ternary_two_pencils_residue` matches the ternary base-3 encoding of the subset sums along the three coordinates for all 3 patterns and 128 subsets.
theorem ternary_two_pencils_residue_table : ∀ k s, ternary_two_pencils_residue k s = (((List.finRange 7).foldl (fun z i => z + if s.val.testBit i.val then ternary_two_pencils_rows k i 0 else 0) 0) % 3) * 9 + (((List.finRange 7).foldl (fun z i => z + if s.val.testBit i.val then ternary_two_pencils_rows k i 1 else 0) 0) % 3) * 3 + (((List.finRange 7).foldl (fun z i => z + if s.val.testBit i.val then ternary_two_pencils_rows k i 2 else 0) 0) % 3) := by decide
For each residue, either it is the designated missing residue or the reference table specifies a subset with that residue. automation
Exhaustive check by `decide` over all 3 patterns and 27 residues confirms that `ternary_two_pencils_reference` provides a subset realizing each achievable residue.
theorem ternary_two_pencils_reference_table : ∀ k g, (g.val = ternary_two_pencils_missing k ∨ ternary_two_pencils_residue k (ternary_two_pencils_reference k g) = g.val) := by decide
The designated missing residue is never achieved by any subset sum. automation
Exhaustive check by `decide` confirms that no subset among the 128 possibilities achieves the missing residue for any pattern.
theorem ternary_two_pencils_missing_table : ∀ k s, ternary_two_pencils_residue k s ≠ ternary_two_pencils_missing k := by decide
A residue fiber is good if and only if it is not missing and every subset in that fiber has the same scalar sum modulo 9 as the reference subset.
Unfolding the definition of `ternary_two_pencils_good_fiber` and simplifying with `List.all_eq_true` and `imp_iff_not_or` transforms the boolean check into the corresponding universal mathematical statement.
uses
List.all_eq_true,imp_iff_not_ortheorem ternary_two_pencils_good_fiber_iff (k j : Fin 3) (u : Fin 81) (g : Fin 27) : ternary_two_pencils_good_fiber k j u g = true ↔ g.val ≠ ternary_two_pencils_missing k ∧ ∀ s, ternary_two_pencils_residue k s = g.val → ternary_two_pencils_scalar_sum k j u s = ternary_two_pencils_scalar_sum k j u (ternary_two_pencils_reference k g) := by simp [ternary_two_pencils_good_fiber, List.all_eq_true, imp_iff_not_or]
The i-th bit of folding the bitwise OR of 2^g for good residues over a list equals the accumulator's i-th bit OR the condition that some residue in the list is good and equals i.
By induction on the list `l`. The empty list is trivial. In the induction step, rewriting by `List.foldl_cons`, the induction hypothesis, and `Nat.testBit_or` decomposes the bit test into the accumulator bit and the new element's bit; case analysis on `good g` simplifies via `Nat.testBit_two_pow` and associativity of boolean disjunction `Bool.or_assoc`.
uses
Bool.or_assoc,List.foldl_cons,Nat.testBit_or,Nat.testBit_two_powtheorem ternary_fiber_mask_fold_testBit (l : List (Fin 27)) (good : Fin 27 → Bool) (a i : ℕ) : (l.foldl (fun z g => z ||| if good g then 2 ^ g.val else 0) a).testBit i = (a.testBit i || l.any (fun g => good g && decide (g.val = i))) := by induction l generalizing a with | nil => simp | cons g l ih => rw [List.foldl_cons, ih, Nat.testBit_or] cases h : good g <;> simp [h, Nat.testBit_two_pow, Bool.or_assoc]
The g-th bit of the coordinate fiber mask is set if and only if residue g is a good fiber.
Unfolding `ternary_two_pencils_fiber_mask` and applying `ternary_fiber_mask_fold_testBit` reduces the goal to checking whether g appears in the range with `good g = true`. The 0 accumulator has no bits set by `Nat.zero_testBit` and `Bool.false_or`. Converting the boolean equality to a logical equivalence with `Bool.eq_iff_iff.mpr`, `List.any_eq_true`, `Bool.and_eq_true`, and `decide_eq_true_eq`, both directions follow: one by injectivity of `Fin` (`Fin.ext`), the other by witnessing g itself.
uses
Bool.and_eq_true,Bool.eq_iff_iff.mpr,Bool.false_or,Fin.ext,List.any_eq_true,Nat.zero_testBit,decide_eq_true_eq,ternary_fiber_mask_fold_testBittheorem ternary_two_pencils_fiber_mask_testBit (k j : Fin 3) (u : Fin 81) (g : Fin 27) : (ternary_two_pencils_fiber_mask k j u).testBit g.val = ternary_two_pencils_good_fiber k j u g := by rw [ternary_two_pencils_fiber_mask, ternary_fiber_mask_fold_testBit] simp only [Nat.zero_testBit, Bool.false_or] apply Bool.eq_iff_iff.mpr simp only [List.any_eq_true, Bool.and_eq_true, decide_eq_true_eq] constructor · rintro ⟨h, _, hh, he⟩ have he' : h = g := Fin.ext he subst h exact hh · intro hg exact ⟨g, by simp, hg, rfl⟩
A residue fiber produces a unique sum modulo 9 across all three coordinates if and only if its index bit is set in the bitwise AND of the three coordinate masks.
By extensionality on residues g, membership in the filtered set unfolds via `Nat.testBit_and`, `ternary_two_pencils_fiber_mask_testBit`, and `ternary_two_pencils_good_fiber_iff`. Non-missing residues have valid reference subsets by `ternary_two_pencils_reference_table`. If a fiber is unique, its subsets all agree with the reference subset, and it cannot be the missing residue by `ternary_two_pencils_missing_table`. Conversely, if the mask bits are set for all three coordinates, the reference subset witnesses nonemptiness, and transitivity through the reference value shows all pairs in the fiber agree.
uses
Nat.testBit_and,ternary_two_pencils_fiber_mask_testBit,ternary_two_pencils_good_fiber_iff,ternary_two_pencils_missing_table,ternary_two_pencils_reference_tabletheorem ternary_two_pencils_unique_fibers_eq_mask (k : Fin 3) (u v w : Fin 81) : ternary_two_pencils_unique_fibers k u v w = Finset.univ.filter (fun g : Fin 27 => (((ternary_two_pencils_fiber_mask k 0 u &&& ternary_two_pencils_fiber_mask k 1 v) &&& ternary_two_pencils_fiber_mask k 2 w).testBit g.val)) := by ext g simp only [ternary_two_pencils_unique_fibers, Finset.mem_filter, Finset.mem_univ, true_and, Nat.testBit_and, Bool.and_eq_true, ternary_two_pencils_fiber_mask_testBit, ternary_two_pencils_good_fiber_iff] have href : g.val ≠ ternary_two_pencils_missing k → ternary_two_pencils_residue k (ternary_two_pencils_reference k g) = g.val := by intro hg exact (ternary_two_pencils_reference_table k g).resolve_left hg constructor · rintro ⟨⟨s, hs⟩, hall⟩ have hg : g.val ≠ ternary_two_pencils_missing k := by intro he exact ternary_two_pencils_missing_table k s (hs.trans he) have hh := fun t ht => hall t (ternary_two_pencils_reference k g) ht (href hg) exact ⟨⟨⟨hg, fun t ht => (hh t ht).1⟩, ⟨hg, fun t ht => (hh t ht).2.1⟩⟩, hg, fun t ht => (hh t ht).2.2⟩ · rintro ⟨⟨⟨hg, h0⟩, ⟨_, h1⟩⟩, ⟨_, h2⟩⟩ refine ⟨⟨ternary_two_pencils_reference k g, href hg⟩, ?_⟩ intro s t hs ht exact ⟨(h0 s hs).trans (h0 t ht).symm, (h1 s hs).trans (h1 t ht).symm, (h2 s hs).trans (h2 t ht).symm⟩
For pattern 0 and each coordinate j ∈ {0, 1, 2}, the fiber mask for any lift parameter u belongs to the precomputed list of options. automation
For each coordinate j = 0, 1, 2, decidability of the finite check over all 81 lift digit choices verifies membership in the candidate list by `decide`. A case analysis on j (`fin_cases j`) combines these three checks.
have ternary_two_pencils_profile_0_0 : ∀ u, ternary_two_pencils_fiber_mask 0 0 u ∈ ternary_two_pencils_profile_options 0 0 := by decide have ternary_two_pencils_profile_0_1 : ∀ u, ternary_two_pencils_fiber_mask 0 1 u ∈ ternary_two_pencils_profile_options 0 1 := by decide have ternary_two_pencils_profile_0_2 : ∀ u, ternary_two_pencils_fiber_mask 0 2 u ∈ ternary_two_pencils_profile_options 0 2 := by decide have ternary_two_pencils_profile_mem (j : Fin 3) (u : Fin 81) : ternary_two_pencils_fiber_mask 0 j u ∈ ternary_two_pencils_profile_options 0 j := by fin_cases j · exact ternary_two_pencils_profile_0_0 u · exact ternary_two_pencils_profile_0_1 u · exact ternary_two_pencils_profile_0_2 u
For any triple of candidate profile masks from the three coordinates, their bitwise intersection has at most 6 set bits. automation
An exhaustive search by `decide` checks all triples (a, b, c) of candidate masks from the three coordinate lists and verifies that the popcount of (a &&& b) &&& c is at most 6.
have ternary_two_pencils_options_intersection : (ternary_two_pencils_profile_options 0 0).all (fun a => (ternary_two_pencils_profile_options 0 1).all (fun b => (ternary_two_pencils_profile_options 0 2).all (fun c => decide (ternary_residue_mask_card ((a &&& b) &&& c) ≤ 6)))) = true := by decide
For any lift parameters u, v, w, the bitwise intersection of the three coordinate masks has at most 6 set bits.
Specializing the universal property of the candidate options (`List.all_eq_true`) using the fact that each coordinate mask is in the corresponding list of options, and converting the boolean decision to a proposition with `of_decide_eq_true`.
uses
List.all_eq_true,of_decide_eq_truehave ternary_two_pencils_mask_intersection_card_le (u v w : Fin 81) : ternary_residue_mask_card ((ternary_two_pencils_fiber_mask 0 0 u &&& ternary_two_pencils_fiber_mask 0 1 v) &&& ternary_two_pencils_fiber_mask 0 2 w) ≤ 6 := by have h0 := (List.all_eq_true.mp ternary_two_pencils_options_intersection) _ (ternary_two_pencils_profile_mem 0 u) have h1 := (List.all_eq_true.mp h0) _ (ternary_two_pencils_profile_mem 1 v) have h2 := (List.all_eq_true.mp h1) _ (ternary_two_pencils_profile_mem 2 w) exact of_decide_eq_true h2
The number of nonempty residue fibers with a unique vector sum modulo 9 is at most 6.
Rewriting the set of unique fibers as the filtered set of set bits in the triple mask intersection via `ternary_two_pencils_unique_fibers_eq_mask`, and applying the bound on the number of set bits.
uses
ternary_two_pencils_unique_fibers_eq_maskrw [ternary_two_pencils_unique_fibers_eq_mask] exact ternary_two_pencils_mask_intersection_card_le u v w
Bool.and_eq_true- A boolean conjunction a && b evaluates to true if and only if both a and b are true.
Bool.false_or- Disjunction with false on the left is the identity on booleans.
Bool.or_assoc- Boolean disjunction is associative.
Bool.eq_iff_iff.mpr- Two booleans are equal if and only if their truth as propositions are equivalent.
Fin.ext- Elements of Fin n are equal if and only if their underlying natural values are equal.
List.all_eq_true- A boolean predicate is true for all elements of a list if and only if List.all evaluates to true.
List.any_eq_true- List.any evaluates to true if and only if there exists an element in the list satisfying the predicate.
List.foldl_cons- A left fold on a cons cell a :: l with accumulator b equals the left fold on l with accumulator f b a.
Nat.testBit_and- The i-th bit of a bitwise AND x &&& y is the boolean AND of the i-th bits of x and y.
Nat.testBit_or- The i-th bit of a bitwise OR x ||| y is the boolean OR of the i-th bits of x and y.
Nat.testBit_two_pow- The m-th bit of 2^n is 1 if and only if m = n.
Nat.zero_testBit- Every bit of 0 is false.
decide_eq_true_eq- The decision decide p evaluates to true if and only if proposition p holds.
imp_iff_not_or- An implication a → b is logically equivalent to ¬a ∨ b.
of_decide_eq_true- A decidable proposition holds if its boolean decision evaluates to true.
ternary_fiber_mask_fold_testBit- The i-th bit of bitwise folding 2^g for good residues equals the accumulator's i-th bit OR whether any element in the list matches i and is good.
ternary_two_pencils_fiber_mask_testBit- The g-th bit of the coordinate fiber mask is set if and only if residue g is a good fiber.
ternary_two_pencils_good_fiber_iff- A residue fiber is good if and only if it is not the missing residue and all subsets in the fiber have the same coordinate sum modulo 9 as the reference subset.
ternary_two_pencils_missing_table- No subset of columns has residue equal to the missing residue.
ternary_two_pencils_reference_table- For each residue g, either g is the missing residue or the reference table subset for g has residue g.
ternary_two_pencils_unique_fibers_eq_mask- The set of unique fibers modulo 9 equals the set of residue indices whose bit is set in the bitwise AND of all three coordinate fiber masks.
- The proof is a finite certificate verification: all universal statements over the 81 lift choices per coordinate and the candidate profile options are verified computationally by Lean's kernel using `decide`.
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
Choose a tactic — a marked line — to see the goals Lean had before and after it, as in Lean’s infoview. Step with ← → or j k.
/-!Computable mirrors and sanity lemmas for the seven-column residue patternx,y,z,y+z,y-z,x+z,x-z. Provenance: supporting finite certificate for OP-259,arXiv:2610.19965 Question 3.1, developed in IN-185. The residue, reference,and missing-value table lemmas check the data; the mask lemmas connect thefinite certificate to the set of nonempty unique lifted fibers.-/set_option maxRecDepth 100000set_option maxHeartbeats 16000000/-- Three normalized seven-term residue patterns in the ternary cube. -/def ternary_two_pencils_rows : Fin 3 → Fin 7 → Fin 3 → ℕ := ![![![1, 0, 0], ![0, 1, 0], ![0, 0, 1], ![0, 1, 1], ![0, 1, 2], ![1, 0, 1], ![1, 0, 2]], ![![1, 0, 0], ![0, 1, 0], ![0, 0, 1], ![0, 1, 1], ![0, 1, 2], ![1, 0, 1], ![2, 0, 1]], ![![1, 0, 0], ![0, 1, 0], ![0, 0, 1], ![0, 1, 1], ![0, 1, 2], ![1, 1, 0], ![2, 1, 0]]]def ternary_two_pencils_residue : Fin 3 → Fin 128 → ℕ := ![![0, 9, 3, 12, 1, 10, 4, 13, 4, 13, 7, 16, 5, 14, 8, 17, 5, 14, 8, 17, 3, 12, 6, 15, 6, 15, 0, 9, 7, 16, 1, 10, 10, 19, 13, 22, 11, 20, 14, 23, 14, 23, 17, 26, 12, 21, 15, 24, 12, 21, 15, 24, 13, 22, 16, 25, 16, 25, 10, 19, 17, 26, 11, 20, 11, 20, 14, 23, 9, 18, 12, 21, 12, 21, 15, 24, 13, 22, 16, 25, 13, 22, 16, 25, 14, 23, 17, 26, 17, 26, 11, 20, 15, 24, 9, 18, 18, 0, 21, 3, 19, 1, 22, 4, 22, 4, 25, 7, 23, 5, 26, 8, 23, 5, 26, 8, 21, 3, 24, 6, 24, 6, 18, 0, 25, 7, 19, 1], ![0, 9, 3, 12, 1, 10, 4, 13, 4, 13, 7, 16, 5, 14, 8, 17, 5, 14, 8, 17, 3, 12, 6, 15, 6, 15, 0, 9, 7, 16, 1, 10, 10, 19, 13, 22, 11, 20, 14, 23, 14, 23, 17, 26, 12, 21, 15, 24, 12, 21, 15, 24, 13, 22, 16, 25, 16, 25, 10, 19, 17, 26, 11, 20, 19, 1, 22, 4, 20, 2, 23, 5, 23, 5, 26, 8, 21, 3, 24, 6, 21, 3, 24, 6, 22, 4, 25, 7, 25, 7, 19, 1, 26, 8, 20, 2, 2, 11, 5, 14, 0, 9, 3, 12, 3, 12, 6, 15, 4, 13, 7, 16, 4, 13, 7, 16, 5, 14, 8, 17, 8, 17, 2, 11, 6, 15, 0, 9], ![0, 9, 3, 12, 1, 10, 4, 13, 4, 13, 7, 16, 5, 14, 8, 17, 5, 14, 8, 17, 3, 12, 6, 15, 6, 15, 0, 9, 7, 16, 1, 10, 12, 21, 15, 24, 13, 22, 16, 25, 16, 25, 10, 19, 17, 26, 11, 20, 17, 26, 11, 20, 15, 24, 9, 18, 9, 18, 12, 21, 10, 19, 13, 22, 21, 3, 24, 6, 22, 4, 25, 7, 25, 7, 19, 1, 26, 8, 20, 2, 26, 8, 20, 2, 24, 6, 18, 0, 18, 0, 21, 3, 19, 1, 22, 4, 6, 15, 0, 9, 7, 16, 1, 10, 1, 10, 4, 13, 2, 11, 5, 14, 2, 11, 5, 14, 0, 9, 3, 12, 3, 12, 6, 15, 4, 13, 7, 16]]def ternary_two_pencils_reference : Fin 3 → Fin 27 → Fin 128 := ![![0, 4, 0, 2, 6, 12, 22, 10, 14, 1, 5, 36, 3, 7, 13, 23, 11, 15, 69, 33, 37, 45, 35, 39, 47, 55, 43], ![0, 4, 69, 2, 6, 12, 22, 10, 14, 1, 5, 36, 3, 7, 13, 23, 11, 15, 0, 33, 37, 45, 35, 39, 47, 55, 43], ![0, 4, 79, 2, 6, 12, 22, 10, 14, 1, 5, 46, 3, 7, 13, 23, 11, 15, 55, 43, 47, 33, 37, 0, 35, 39, 45]]def ternary_two_pencils_missing : Fin 3 → ℕ := ![2, 18, 23]/-- u encodes four ternary lift digits; the first three columns are an exact basis. -/def ternary_two_pencils_scalar_sum (k j : Fin 3) (u : Fin 81) (s : Fin 128) : ℕ := ((List.finRange 7).foldl (fun z i => z + if s.val.testBit i.val then ternary_two_pencils_rows k i j + (if i.val < 3 then 0 else 3 * ((u.val / 3 ^ (i.val - 3)) % 3)) else 0) 0) % 9/-- A scalar residue fiber is nonempty and all its subset values agree with its reference. -/def ternary_two_pencils_good_fiber (k j : Fin 3) (u : Fin 81) (g : Fin 27) : Bool := g.val != ternary_two_pencils_missing k && (List.finRange 128).all (fun s => ternary_two_pencils_residue k s != g.val || ternary_two_pencils_scalar_sum k j u s == ternary_two_pencils_scalar_sum k j u (ternary_two_pencils_reference k g))/-- The bit mask of the scalar unique fibers. -/def ternary_two_pencils_fiber_mask (k j : Fin 3) (u : Fin 81) : ℕ := ((List.finRange 27).foldl (fun z g => z ||| if ternary_two_pencils_good_fiber k j u g then 2 ^ g.val else 0) 0)def ternary_two_pencils_profile_options : Fin 3 → Fin 3 → List ℕ := ![![[0, 80, 136, 288, 263168, 263171, 263675, 524800, 524803, 525307, 1050624, 1050627, 1051131, 1838592, 134217216], [0, 80, 83, 136, 139, 288, 291, 504, 263168, 524800, 1050624, 1838675, 1838731, 1838883, 132379128], [0, 3, 80, 136, 219, 291, 368, 424, 263168, 524800, 787971, 788187, 788259, 1050627, 1050843, 1050915, 1313792, 1575424]], ![[0, 513, 1028, 2050, 3591, 262143, 1573377, 1573892, 1574914, 18874368, 41943040, 71303168, 133693953, 133694468, 133695490], [0, 513, 1028, 2050, 18874368, 20447232, 20450823, 41943040, 43515904, 43519495, 71303168, 72876032, 72879623, 132120576, 132379128], [0, 1028, 1541, 2050, 2563, 1572864, 1573377, 1575942, 20447232, 20447745, 20450310, 41943040, 60817408, 71303168, 90177536, 114819072, 114819585, 114822150]], ![[0, 2304, 16416, 131076, 149796, 262143, 6291456, 17301504, 33816576, 68159744, 68173856, 68288516, 125569280, 125583392, 125698052], [0, 2304, 18720, 131076, 147492, 17301504, 23592960, 33816576, 40108032, 68157440, 68173856, 68290820, 74448896, 74465312, 74582276, 119275520, 119291936, 119408900], [0, 2304, 16416, 131076, 6291456, 17301504, 33816576, 57409536, 57521883, 74448896, 74598692, 85458944, 85608740, 101974016, 102123812]]]def ternary_residue_mask_card (m : ℕ) : ℕ := ((Finset.univ : Finset (Fin 27)).filter (fun i => m.testBit i.val)).cardtheorem ternary_two_pencils_residue_table : ∀ k s, ternary_two_pencils_residue k s = (((List.finRange 7).foldl (fun z i => z + if s.val.testBit i.val then ternary_two_pencils_rows k i 0 else 0) 0) % 3) * 9 + (((List.finRange 7).foldl (fun z i => z + if s.val.testBit i.val then ternary_two_pencils_rows k i 1 else 0) 0) % 3) * 3 + (((List.finRange 7).foldl (fun z i => z + if s.val.testBit i.val then ternary_two_pencils_rows k i 2 else 0) 0) % 3) := by decidetheorem ternary_two_pencils_reference_table : ∀ k g, (g.val = ternary_two_pencils_missing k ∨ ternary_two_pencils_residue k (ternary_two_pencils_reference k g) = g.val) := by decidetheorem ternary_two_pencils_missing_table : ∀ k s, ternary_two_pencils_residue k s ≠ ternary_two_pencils_missing k := by decidetheorem ternary_two_pencils_good_fiber_iff (k j : Fin 3) (u : Fin 81) (g : Fin 27) : ternary_two_pencils_good_fiber k j u g = true ↔ g.val ≠ ternary_two_pencils_missing k ∧ ∀ s, ternary_two_pencils_residue k s = g.val → ternary_two_pencils_scalar_sum k j u s = ternary_two_pencils_scalar_sum k j u (ternary_two_pencils_reference k g) := by simp [ternary_two_pencils_good_fiber, List.all_eq_true, imp_iff_not_or]theorem ternary_fiber_mask_fold_testBit (l : List (Fin 27)) (good : Fin 27 → Bool) (a i : ℕ) : (l.foldl (fun z g => z ||| if good g then 2 ^ g.val else 0) a).testBit i = (a.testBit i || l.any (fun g => good g && decide (g.val = i))) := by induction l generalizing a with | nil => simp | cons g l ih => rw [List.foldl_cons, ih, Nat.testBit_or] cases h : good g <;> simp [h, Nat.testBit_two_pow, Bool.or_assoc]theorem ternary_two_pencils_fiber_mask_testBit (k j : Fin 3) (u : Fin 81) (g : Fin 27) : (ternary_two_pencils_fiber_mask k j u).testBit g.val = ternary_two_pencils_good_fiber k j u g := by rw [ternary_two_pencils_fiber_mask, ternary_fiber_mask_fold_testBit] simp only [Nat.zero_testBit, Bool.false_or] apply Bool.eq_iff_iff.mpr simp only [List.any_eq_true, Bool.and_eq_true, decide_eq_true_eq] constructor · rintro ⟨h, _, hh, he⟩ have he' : h = g := Fin.ext he subst h exact hh · intro hg exact ⟨g, by simp, hg, rfl⟩/-- Fibers whose actual three-coordinate subset values are unique modulo 9. -/def ternary_two_pencils_unique_fibers (k : Fin 3) (u v w : Fin 81) : Finset (Fin 27) := Finset.univ.filter (fun g => (∃ s, ternary_two_pencils_residue k s = g.val) ∧ ∀ s t, ternary_two_pencils_residue k s = g.val → ternary_two_pencils_residue k t = g.val → ternary_two_pencils_scalar_sum k 0 u s = ternary_two_pencils_scalar_sum k 0 u t ∧ ternary_two_pencils_scalar_sum k 1 v s = ternary_two_pencils_scalar_sum k 1 v t ∧ ternary_two_pencils_scalar_sum k 2 w s = ternary_two_pencils_scalar_sum k 2 w t)theorem ternary_two_pencils_unique_fibers_eq_mask (k : Fin 3) (u v w : Fin 81) : ternary_two_pencils_unique_fibers k u v w = Finset.univ.filter (fun g : Fin 27 => (((ternary_two_pencils_fiber_mask k 0 u &&& ternary_two_pencils_fiber_mask k 1 v) &&& ternary_two_pencils_fiber_mask k 2 w).testBit g.val)) := by ext g simp only [ternary_two_pencils_unique_fibers, Finset.mem_filter, Finset.mem_univ, true_and, Nat.testBit_and, Bool.and_eq_true, ternary_two_pencils_fiber_mask_testBit, ternary_two_pencils_good_fiber_iff] have href : g.val ≠ ternary_two_pencils_missing k → ternary_two_pencils_residue k (ternary_two_pencils_reference k g) = g.val := by intro hg exact (ternary_two_pencils_reference_table k g).resolve_left hg constructor · rintro ⟨⟨s, hs⟩, hall⟩ have hg : g.val ≠ ternary_two_pencils_missing k := by intro he exact ternary_two_pencils_missing_table k s (hs.trans he) have hh := fun t ht => hall t (ternary_two_pencils_reference k g) ht (href hg) exact ⟨⟨⟨hg, fun t ht => (hh t ht).1⟩, ⟨hg, fun t ht => (hh t ht).2.1⟩⟩, hg, fun t ht => (hh t ht).2.2⟩ · rintro ⟨⟨⟨hg, h0⟩, ⟨_, h1⟩⟩, ⟨_, h2⟩⟩ refine ⟨⟨ternary_two_pencils_reference k g, href hg⟩, ?_⟩ intro s t hs ht exact ⟨(h0 s hs).trans (h0 t ht).symm, (h1 s hs).trans (h1 t ht).symm, (h2 s hs).trans (h2 t ht).symm⟩theorem ternary_two_pencils_unique_fibers_card_le_six (u v w : Fin 81) : (ternary_two_pencils_unique_fibers 0 u v w).card ≤ 6 := by have ternary_two_pencils_profile_0_0 : ∀ u, ternary_two_pencils_fiber_mask 0 0 u ∈ ternary_two_pencils_profile_options 0 0 := by decide have ternary_two_pencils_profile_0_1 : ∀ u, ternary_two_pencils_fiber_mask 0 1 u ∈ ternary_two_pencils_profile_options 0 1 := by decide have ternary_two_pencils_profile_0_2 : ∀ u, ternary_two_pencils_fiber_mask 0 2 u ∈ ternary_two_pencils_profile_options 0 2 := by decide have ternary_two_pencils_profile_mem (j : Fin 3) (u : Fin 81) : ternary_two_pencils_fiber_mask 0 j u ∈ ternary_two_pencils_profile_options 0 j := by fin_cases j · exact ternary_two_pencils_profile_0_0 u · exact ternary_two_pencils_profile_0_1 u · exact ternary_two_pencils_profile_0_2 u have ternary_two_pencils_options_intersection : (ternary_two_pencils_profile_options 0 0).all (fun a => (ternary_two_pencils_profile_options 0 1).all (fun b => (ternary_two_pencils_profile_options 0 2).all (fun c => decide (ternary_residue_mask_card ((a &&& b) &&& c) ≤ 6)))) = true := by decide have ternary_two_pencils_mask_intersection_card_le (u v w : Fin 81) : ternary_residue_mask_card ((ternary_two_pencils_fiber_mask 0 0 u &&& ternary_two_pencils_fiber_mask 0 1 v) &&& ternary_two_pencils_fiber_mask 0 2 w) ≤ 6 := by have h0 := (List.all_eq_true.mp ternary_two_pencils_options_intersection) _ (ternary_two_pencils_profile_mem 0 u) have h1 := (List.all_eq_true.mp h0) _ (ternary_two_pencils_profile_mem 1 v) have h2 := (List.all_eq_true.mp h1) _ (ternary_two_pencils_profile_mem 2 w) exact of_decide_eq_true h2 rw [ternary_two_pencils_unique_fibers_eq_mask] exact ternary_two_pencils_mask_intersection_card_le u v w