Constructing paired prefix-mask product arrays in matching order
ProvedThreeSum.LightReportingPrefixArrays.program_meets3sumalgorithmsfine-grained-complexitythree-sum-1962word-ram
Let and . Enumerate all ordered disjoint pairs of -subsets of an -element set, first by and then by . Their number is . Let be the resulting left and right mask lists, and define , in nested list order.
The fixed program uses nonoverlapping ordered regions for the initial -subset list, both -cell pair arrays, both complete radix-stage constructions, and scratch. Assume their stated endpoints fit , , , the radix word budget for fits , and . It writes headers followed by
returns the left header address, preserves cells below the initial subset-list base, and meets the defined prefix-array budget.
Both outputs retain the same ordered pair-occurrence indexing.
Preamble
/- Copyright (c) 2026 Anthropic, PBC. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. SPDX-License-Identifier: Apache-2.0 -/ import Aesop import Definitions.Def_APSPSource_RemainingDefinitions import Definitions.Def_APSPSource_ThreeSumApsp_Lang_Logic import Definitions.Def_APSPSource_ThreeSumApsp_Lang_Regions import Definitions.Def_APSPSource_ThreeSumApsp_Lang_Syntax import Definitions.Def_ThreeSum1962Source_Bundle01 import Definitions.Def_ThreeSum1962Source_Bundle03 import Definitions.Def_ThreeSum1962Source_Bundle04 import Definitions.Def_ThreeSum1962Source_Bundle05 import Definitions.Def_ThreeSum1962Source_Bundle07 import Definitions.Def_ThreeSum1962Source_Bundle08 import Definitions.Def_ThreeSum1962Source_Bundle09 import Definitions.Def_ThreeSum1962Source_Bundle10 import Lean.Elab.Tactic.Omega import Mathlib.Algebra.BigOperators.Fin import Mathlib.Algebra.BigOperators.Group.Finset.Basic import Mathlib.Algebra.BigOperators.Group.Finset.Powerset import Mathlib.Algebra.BigOperators.Group.Finset.Sigma import Mathlib.Algebra.BigOperators.Ring.Finset import Mathlib.Algebra.Field.ZMod import Mathlib.Algebra.Group.Equiv.Basic import Mathlib.Algebra.Group.Int.Defs import Mathlib.Algebra.GroupWithZero.Nat import Mathlib.Algebra.Order.BigOperators.Group.Finset import Mathlib.Algebra.Order.BigOperators.Group.List import Mathlib.Algebra.Order.BigOperators.Group.Multiset import Mathlib.Algebra.Order.Chebyshev import Mathlib.Algebra.Order.Field.Basic import Mathlib.Algebra.Order.Floor.Div import Mathlib.Algebra.Order.Group.Abs import Mathlib.Algebra.Order.Group.Int import Mathlib.Algebra.Order.Group.Nat import Mathlib.Algebra.Order.Group.Unbundled.Abs import Mathlib.Algebra.Order.Ring.Abs import Mathlib.Algebra.Order.Ring.Int import Mathlib.Algebra.Order.Ring.Pow import Mathlib.Algebra.Ring.Nat import Mathlib.Combinatorics.Colex import Mathlib.Data.Bool.Basic import Mathlib.Data.Fin.Embedding import Mathlib.Data.Fin.VecNotation import Mathlib.Data.Finset.Card import Mathlib.Data.Finset.Max import Mathlib.Data.Finset.Powerset import Mathlib.Data.Finset.Prod import Mathlib.Data.Finset.Sigma import Mathlib.Data.Finset.Sort import Mathlib.Data.Fintype.BigOperators import Mathlib.Data.Fintype.Card import Mathlib.Data.Fintype.Fin import Mathlib.Data.Fintype.Pi import Mathlib.Data.Fintype.Prod import Mathlib.Data.Int.Cast.Lemmas import Mathlib.Data.Int.ModEq import Mathlib.Data.Int.Notation import Mathlib.Data.Int.SuccPred import Mathlib.Data.List.Basic import Mathlib.Data.List.GetD import Mathlib.Data.List.MinMax import Mathlib.Data.List.Nodup import Mathlib.Data.List.OfFn import Mathlib.Data.List.Pi import Mathlib.Data.List.Sublists import Mathlib.Data.List.TakeDrop import Mathlib.Data.Nat.Cast.Order.Ring import Mathlib.Data.Nat.Choose.Basic import Mathlib.Data.Nat.Choose.Bounds import Mathlib.Data.Nat.Choose.Central import Mathlib.Data.Nat.Choose.Sum import Mathlib.Data.Nat.Count import Mathlib.Data.Nat.Notation import Mathlib.Data.Nat.Sqrt import Mathlib.Data.Nat.SuccPred import Mathlib.Data.Real.Basic import Mathlib.Data.ZMod.Basic import Mathlib.GroupTheory.Index import Mathlib.LinearAlgebra.Dual.Lemmas import Mathlib.LinearAlgebra.Matrix.Defs import Mathlib.LinearAlgebra.Matrix.Dual import Mathlib.LinearAlgebra.Matrix.ToLin import Mathlib.Logic.Equiv.Fin.Basic import Mathlib.Logic.Function.Basic import Mathlib.NumberTheory.Bertrand import Mathlib.Order.ConditionallyCompleteLattice.Basic import Mathlib.RingTheory.Coprime.Lemmas import Mathlib.Tactic.Abel import Mathlib.Tactic.ByContra import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.FinCases import Mathlib.Tactic.GCongr import Mathlib.Tactic.Linarith import Mathlib.Tactic.NormNum import Mathlib.Tactic.Positivity import Mathlib.Tactic.Push import Mathlib.Tactic.Ring import Mathlib.Tactic.SplitIfs import Mathlib.Tactic.Tauto import Theorems.Thm_Light_powTable_ends import Theorems.Thm_Light_seg_append import Theorems.Thm_ThreeSum_LightRadixKeys_meets import Theorems.Thm_ThreeSum_LightReportingPairRows_program_meets import Theorems.Thm_ThreeSum_ReportingHostPairEnumeration_leftAt_card import Theorems.Thm_ThreeSum_ReportingHostPairEnumeration_lefts_length import Theorems.Thm_ThreeSum_ReportingHostPairEnumeration_pairs_length import Theorems.Thm_ThreeSum_ReportingHostPairEnumeration_rights_length set_option autoImplicit false set_option relaxedAutoImplicit false set_option Elab.async false namespace Light end Light namespace Light.PowTable end Light.PowTable namespace ThreeSum.LayerCounts end ThreeSum.LayerCounts namespace ThreeSum.LightPascal end ThreeSum.LightPascal namespace ThreeSum.LightSubsetAddress end ThreeSum.LightSubsetAddress namespace ThreeSum.LocalGraph end ThreeSum.LocalGraph namespace ThreeSum.ReportingHostPairEnumeration end ThreeSum.ReportingHostPairEnumeration namespace ThreeSum.ReportingHostPairSegments end ThreeSum.ReportingHostPairSegments namespace ThreeSum.SubsetAddress end ThreeSum.SubsetAddress
Formal statement
theorem ThreeSum.LightReportingPrefixArrays.program_meets : ∀ {lim : Light.Limits} {μ : Nat → Int} {L h k srcS pairL pairR stageL stageR work d : Nat}
(hw : @LE.le.{0} Int Int.instLEInt (@Nat.cast.{0} Int instNatCastInt lim.space) lim.word)
(hh :
@LE.le.{0} Nat instLENat
(@HMul.hMul.{0, 0, 0} Nat Nat Nat (@instHMul.{0} Nat instMulNat)
(@OfNat.ofNat.{0} Nat (nat_lit 2) (instOfNatNat (nat_lit 2))) h)
L)
(hS :
@LE.le.{0} Nat instLENat (@HAdd.hAdd.{0, 0, 0} Nat Nat Nat (@instHAdd.{0} Nat instAddNat) srcS (L.choose h)) pairL)
(hL :
@LE.le.{0} Nat instLENat
(@HAdd.hAdd.{0, 0, 0} Nat Nat Nat (@instHAdd.{0} Nat instAddNat) pairL
(ThreeSum.LightReportingPrefixArrays.localCount L h))
pairR)
(hR :
@LE.le.{0} Nat instLENat
(@HAdd.hAdd.{0, 0, 0} Nat Nat Nat (@instHAdd.{0} Nat instAddNat) pairR
(ThreeSum.LightReportingPrefixArrays.localCount L h))
stageL)
(hstageL :
@LE.le.{0} Nat instLENat
(ThreeSum.LightRadixKeys.space stageL (ThreeSum.LightReportingPrefixArrays.localCount L h) k) stageR)
(hstageR :
@LE.le.{0} Nat instLENat
(ThreeSum.LightRadixKeys.space stageR (ThreeSum.LightReportingPrefixArrays.localCount L h) k) work)
(hspace :
@LE.le.{0} Nat instLENat
(@HAdd.hAdd.{0, 0, 0} Nat Nat Nat (@instHAdd.{0} Nat instAddNat)
(@HAdd.hAdd.{0, 0, 0} Nat Nat Nat (@instHAdd.{0} Nat instAddNat) work
(@HMul.hMul.{0, 0, 0} Nat Nat Nat (@instHMul.{0} Nat instMulNat)
(@OfNat.ofNat.{0} Nat (nat_lit 2) (instOfNatNat (nat_lit 2))) L))
(@OfNat.ofNat.{0} Nat (nat_lit 2) (instOfNatNat (nat_lit 2))))
lim.space)
(hpowWord :
@LE.le.{0} Int Int.instLEInt
(@Nat.cast.{0} Int instNatCastInt
(@HPow.hPow.{0, 0, 0} Nat Nat Nat
(@instHPow.{0, 0} Nat Nat (@NPow.toPow.{0} Nat (@Monoid.toNPow.{0} Nat Nat.instMonoid)))
(@OfNat.ofNat.{0} Nat (nat_lit 2) (instOfNatNat (nat_lit 2)))
(@HAdd.hAdd.{0, 0, 0} Nat Nat Nat (@instHAdd.{0} Nat instAddNat) L
(@OfNat.ofNat.{0} Nat (nat_lit 1) (instOfNatNat (nat_lit 1))))))
lim.word)
(hkeysWord :
@LE.le.{0} Int Int.instLEInt
(@Nat.cast.{0} Int instNatCastInt
(ThreeSum.LightRadixKeys.word
(@HPow.hPow.{0, 0, 0} Nat Nat Nat
(@instHPow.{0, 0} Nat Nat (@NPow.toPow.{0} Nat (@Monoid.toNPow.{0} Nat Nat.instMonoid)))
(@OfNat.ofNat.{0} Nat (nat_lit 2) (instOfNatNat (nat_lit 2))) L)
(@HPow.hPow.{0, 0, 0} Nat Nat Nat
(@instHPow.{0, 0} Nat Nat (@NPow.toPow.{0} Nat (@Monoid.toNPow.{0} Nat Nat.instMonoid)))
(@OfNat.ofNat.{0} Nat (nat_lit 2) (instOfNatNat (nat_lit 2))) L)
k))
lim.word)
(hd :
@LE.le.{0} Nat instLENat
(@HAdd.hAdd.{0, 0, 0} Nat Nat Nat (@instHAdd.{0} Nat instAddNat)
(@HAdd.hAdd.{0, 0, 0} Nat Nat Nat (@instHAdd.{0} Nat instAddNat)
(@HAdd.hAdd.{0, 0, 0} Nat Nat Nat (@instHAdd.{0} Nat instAddNat) d L) k)
(@OfNat.ofNat.{0} Nat (nat_lit 4) (instOfNatNat (nat_lit 4))))
lim.depth),
Light.Meets lim ThreeSum.LightReportingPrefixArrays.program
(@OfNat.ofNat.{0} Nat (nat_lit 10) (instOfNatNat (nat_lit 10))) d
(@List.cons.{0} Int (@Nat.cast.{0} Int instNatCastInt L)
(@List.cons.{0} Int (@Nat.cast.{0} Int instNatCastInt h)
(@List.cons.{0} Int (@Nat.cast.{0} Int instNatCastInt k)
(@List.cons.{0} Int (@Nat.cast.{0} Int instNatCastInt srcS)
(@List.cons.{0} Int (@Nat.cast.{0} Int instNatCastInt pairL)
(@List.cons.{0} Int (@Nat.cast.{0} Int instNatCastInt pairR)
(@List.cons.{0} Int (@Nat.cast.{0} Int instNatCastInt stageL)
(@List.cons.{0} Int (@Nat.cast.{0} Int instNatCastInt stageR)
(@List.cons.{0} Int (@Nat.cast.{0} Int instNatCastInt work) (@List.nil.{0} Int))))))))))
μ (ThreeSum.LightReportingPrefixArrays.time L h k) fun (r : Int) (μ' : Nat → Int) =>
And
(@Eq.{1} Int r
(@Nat.cast.{0} Int instNatCastInt
(@HAdd.hAdd.{0, 0, 0} Nat Nat Nat (@instHAdd.{0} Nat instAddNat) stageL
(ThreeSum.LightRadixKeys.offset (ThreeSum.LightReportingPrefixArrays.localCount L h) k))))
(And
(@Eq.{1} Int
(μ'
(@HAdd.hAdd.{0, 0, 0} Nat Nat Nat (@instHAdd.{0} Nat instAddNat) stageL
(ThreeSum.LightRadixKeys.offset (ThreeSum.LightReportingPrefixArrays.localCount L h) k)))
(@Nat.cast.{0} Int instNatCastInt
(@HPow.hPow.{0, 0, 0} Nat Nat Nat
(@instHPow.{0, 0} Nat Nat (@NPow.toPow.{0} Nat (@Monoid.toNPow.{0} Nat Nat.instMonoid)))
(ThreeSum.LightReportingPrefixArrays.localCount L h) k)))
(And
(@Eq.{1} Int
(μ'
(@HAdd.hAdd.{0, 0, 0} Nat Nat Nat (@instHAdd.{0} Nat instAddNat) stageR
(ThreeSum.LightRadixKeys.offset (ThreeSum.LightReportingPrefixArrays.localCount L h) k)))
(@Nat.cast.{0} Int instNatCastInt
(@HPow.hPow.{0, 0, 0} Nat Nat Nat
(@instHPow.{0, 0} Nat Nat (@NPow.toPow.{0} Nat (@Monoid.toNPow.{0} Nat Nat.instMonoid)))
(ThreeSum.LightReportingPrefixArrays.localCount L h) k)))
(And
(Light.Seg μ'
(@HAdd.hAdd.{0, 0, 0} Nat Nat Nat (@instHAdd.{0} Nat instAddNat)
(@HAdd.hAdd.{0, 0, 0} Nat Nat Nat (@instHAdd.{0} Nat instAddNat) stageL
(ThreeSum.LightRadixKeys.offset (ThreeSum.LightReportingPrefixArrays.localCount L h) k))
(@OfNat.ofNat.{0} Nat (nat_lit 1) (instOfNatNat (nat_lit 1))))
(ThreeSum.RadixKeyLists.values
(@Nat.cast.{0} Int instNatCastInt
(@HPow.hPow.{0, 0, 0} Nat Nat Nat
(@instHPow.{0, 0} Nat Nat (@NPow.toPow.{0} Nat (@Monoid.toNPow.{0} Nat Nat.instMonoid)))
(@OfNat.ofNat.{0} Nat (nat_lit 2) (instOfNatNat (nat_lit 2))) L))
(ThreeSum.ReportingHostPairSegments.leftMasks L h) k))
(And
(Light.Seg μ'
(@HAdd.hAdd.{0, 0, 0} Nat Nat Nat (@instHAdd.{0} Nat instAddNat)
(@HAdd.hAdd.{0, 0, 0} Nat Nat Nat (@instHAdd.{0} Nat instAddNat) stageR
(ThreeSum.LightRadixKeys.offset (ThreeSum.LightReportingPrefixArrays.localCount L h) k))
(@OfNat.ofNat.{0} Nat (nat_lit 1) (instOfNatNat (nat_lit 1))))
(ThreeSum.RadixKeyLists.values
(@Nat.cast.{0} Int instNatCastInt
(@HPow.hPow.{0, 0, 0} Nat Nat Nat
(@instHPow.{0, 0} Nat Nat (@NPow.toPow.{0} Nat (@Monoid.toNPow.{0} Nat Nat.instMonoid)))
(@OfNat.ofNat.{0} Nat (nat_lit 2) (instOfNatNat (nat_lit 2))) L))
(ThreeSum.ReportingHostPairSegments.rightMasks L h) k))
(Light.Kept μ μ' srcS))))) := by
sorry
Source