Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
104 commits
Select commit Hold shift + click to select a range
6094ec9
feat(exactTriangle): relate lopsided queries and matrix products
edemaine Oct 28, 2026
dec963a
feat(exactTriangle): prove modular counts and the selected-prime bound
edemaine Oct 28, 2026
0d8da3e
doc(threeSum): cite the lopsided triangle paper and clarify adaptatio…
edemaine Oct 28, 2026
8d80ecc
doc(bibliography): sort the new paper entry
edemaine Oct 28, 2026
fd69be7
fix(exactTriangle): repair the prime-window header and hashing docume…
edemaine Oct 28, 2026
ce646c7
feat(exactTriangle): split modular queries and recover witnesses
edemaine Oct 28, 2026
2cae26c
doc(threeSum): record finite splitting and recovery milestone
edemaine Oct 28, 2026
dc4206a
refactor(exactTriangle): reuse the natural residue bound and clarify …
edemaine Oct 28, 2026
19ee942
feat(wordram): count Chan–He collisions with native histograms
edemaine Oct 28, 2026
a712205
fix(wordram): preserve collision-counting parameters explicitly
edemaine Oct 28, 2026
4fc6a70
feat(wordram): add native radix sorting and multiplicity arrays
edemaine Oct 28, 2026
4edf0b8
chore(wordram): keep Lean sources non-executable
edemaine Oct 28, 2026
5cbb93d
feat(wordram): compute Chan–He parameters from native input
edemaine Oct 28, 2026
0505439
fix(wordram): repair parameter proof hygiene and ceiling-log docs
edemaine Oct 28, 2026
0e05605
feat(wordram): implement prime tables and collision minimum searches
edemaine Oct 28, 2026
a5a5391
feat(wordram): compute the Chan–He two-prime modulus natively
edemaine Oct 28, 2026
ba4cab2
feat(wordram): construct native Chan–He node outputs
edemaine Oct 28, 2026
b2554d5
fix(wordram): export sorted radix keys from composed contracts
edemaine Oct 28, 2026
36e0f7e
Merge commit 'b2554d58b9eb90291e7d9314128433b62016e203' into t3/nativ…
edemaine Oct 28, 2026
ebe62bc
Merge commit 'ba4cab2a6096c4d692e2d7a75b59d7591ea5162e' into t3/nativ…
edemaine Oct 28, 2026
374795a
Merge commit 'b2554d58b9eb90291e7d9314128433b62016e203' into t3/nativ…
edemaine Oct 28, 2026
712b07d
feat(wordram): implement complete native distinct-position frontend
edemaine Oct 28, 2026
6372d31
fix(wordram): link frontend readback to its native run
edemaine Oct 28, 2026
0781373
Merge commit '6372d314a08ff7215b78425b25315021c0c936a7' into t3/nativ…
edemaine Oct 28, 2026
ceb537f
feat(three-sum): prove complete native Chan-He root traversal
edemaine Oct 28, 2026
f6f22da
test(wordram): remove disconnected native node checks
edemaine Oct 28, 2026
d32859e
refactor(wordram): reuse prime counts and test later acceptance
edemaine Oct 28, 2026
ec8aa56
test(wordram): drop disconnected radix contract example
edemaine Oct 28, 2026
1085648
doc(wordram): explain the Chan-He prime-window interface
edemaine Oct 28, 2026
787aa2c
feat(three-sum): bound charged traversal tree overhead
edemaine Oct 28, 2026
1d150b5
Merge commit 'f6f22dac7018f00793f6aae1aa44bd04ae08cee6' into t3/nativ…
edemaine Oct 28, 2026
eae533d
Merge commit 'd32859e8beea19d17a763e0a241463ad7c7d4aa0' into t3/nativ…
edemaine Oct 28, 2026
5c172a9
Merge commit 'ec8aa561feae957effa539ac6f84d64c5db903c8' into t3/nativ…
edemaine Oct 28, 2026
e12766c
feat(three-sum): assemble initialized-input native Chan-He preprocessing
edemaine Oct 28, 2026
af8fdb7
Merge commit '108564889ee67ecae0ad1e2e2973aae98b401666' into t3/nativ…
edemaine Oct 28, 2026
a49400c
doc(wordram): record complete bounded Chan-He traversal scope
edemaine Oct 28, 2026
c97fa1b
Merge commit 'a49400ce31c854d74f86b62c6580c4b99c714b16' into t3/nativ…
edemaine Oct 28, 2026
11fd4dd
feat(wordram): complete initialized Chan-He preprocessing
edemaine Oct 28, 2026
a33aea0
fix(wordram): resolve native preprocessing review findings
edemaine Oct 28, 2026
48a0fa3
chore(exactTriangle): merge current main for sibling integration
codex Oct 29, 2026
3fb98bd
chore(exactTriangle): join reviewed query splitting and counting layers
codex Oct 29, 2026
d1bc583
chore(exactTriangle): reconcile modular-hashing integration documenta…
SamuelSchlesinger Oct 29, 2026
c0b0511
chore(exactTriangle): carry hashing integration through query splitting
SamuelSchlesinger Oct 29, 2026
a76a7d3
chore(exactTriangle): carry documentation integration through native …
SamuelSchlesinger Oct 29, 2026
4f6de79
fix(imports): deduplicate aggregate after counting integration
SamuelSchlesinger Oct 29, 2026
02f1b49
fix(imports): deduplicate aggregate after query-splitting integration
SamuelSchlesinger Oct 29, 2026
b17ece3
Merge commit '4f6de797203eb5dac02b2cadd9e8fa33e7427d57' into coordina…
SamuelSchlesinger Oct 29, 2026
e031b72
Merge remote-tracking branch 'origin/main' into coordinator/integrate…
SamuelSchlesinger Oct 29, 2026
b79ae8e
fix(imports): regenerate aggregate after Chan-He parameter integration
SamuelSchlesinger Oct 29, 2026
f219cb7
chore(three-sum): integrate reviewed prime search with parameter supp…
SamuelSchlesinger Oct 29, 2026
ec9351c
chore(three-sum): merge current main before prime-search validation
SamuelSchlesinger Oct 29, 2026
4d3d55a
chore(three-sum): integrate reviewed modulus with refreshed prime search
SamuelSchlesinger Oct 29, 2026
1d7ce92
chore(three-sum): integrate reviewed node packing with refreshed prim…
SamuelSchlesinger Oct 29, 2026
3552eb0
Merge remote-tracking branch 'origin/main' into integrate/1497-remain…
SamuelSchlesinger Oct 29, 2026
5337d45
Merge branch 'integrate/1497-remainingmath-20261029' into integrate/1…
SamuelSchlesinger Oct 29, 2026
eb8f925
perf(three-sum): check native query tests within default heartbeats
SamuelSchlesinger Oct 29, 2026
b94e77f
perf(three-sum): run modulus instance within default heartbeats
SamuelSchlesinger Oct 29, 2026
350a66b
Merge branch 'integrate/1497-remainingmath-20261029' into integrate/1…
SamuelSchlesinger Oct 29, 2026
ab3e96c
chore(integration): reconcile splitting layer with landed hashing parent
SamuelSchlesinger Oct 29, 2026
9c8b9fc
perf(wordram): reduce native parameter proof heartbeat budget
SamuelSchlesinger Oct 29, 2026
0c9b346
Merge remote-tracking branch 'github/main' into coordinator-heartbeat…
SamuelSchlesinger Oct 29, 2026
da6a301
chore(integration): adopt splitting layer after its parent landed
SamuelSchlesinger Oct 29, 2026
452924e
chore(wordram): scope measured parameter proof budget to reduction task
SamuelSchlesinger Oct 29, 2026
6aaf569
Merge commit 'da6a301aca1e0c03e6953b3329474b2236f0fac8' into coordina…
SamuelSchlesinger Oct 29, 2026
170d9eb
Merge remote-tracking branch 'origin/p1469' into integrate/1497-remai…
SamuelSchlesinger Oct 29, 2026
af80519
Merge branch 'integrate/1497-remainingmath-20261029' into integrate/1…
SamuelSchlesinger Oct 29, 2026
e69b812
Merge branch 'integrate/1497-remainingmath-20261029' into integrate/1…
SamuelSchlesinger Oct 29, 2026
0940d1f
Merge commit 'af80519e7bb5034a6d4979ffcb91c653e4c693d4' into coordina…
SamuelSchlesinger Oct 29, 2026
aa7cebd
chore(wordram): regenerate frontend integration imports
SamuelSchlesinger Oct 29, 2026
5265a9b
chore(three-sum): integrate reviewed recursion with initialized frontend
SamuelSchlesinger Oct 29, 2026
7ba74ea
chore(three-sum): include refreshed node-packing supplier
SamuelSchlesinger Oct 29, 2026
06214ec
Merge remote-tracking branch 'origin/main' into integrate/1535-remain…
SamuelSchlesinger Oct 29, 2026
a8cb58f
chore(three-sum): integrate reviewed initialized preprocessing stack
SamuelSchlesinger Oct 29, 2026
6685166
doc(three-sum): reconcile inherited preprocessing milestone status
SamuelSchlesinger Oct 29, 2026
8a81617
Merge remote-tracking branch 'github/main' into coordinator-refresh-1…
SamuelSchlesinger Oct 29, 2026
618654d
Merge commit '8a81617ea81ea15a43e8581ceb848ec31ed2126b' into coordina…
SamuelSchlesinger Oct 29, 2026
5f1d90a
Merge commit '618654db3356a6a45b35091d0b9605c4401c3e61' into coordina…
SamuelSchlesinger Oct 29, 2026
0a6d3b6
Merge commit '618654db3356a6a45b35091d0b9605c4401c3e61' into coordina…
SamuelSchlesinger Oct 29, 2026
3b77142
Merge commit '5f1d90a31b4b247815170813376db6a32e029afc' into coordina…
SamuelSchlesinger Oct 29, 2026
1b2d346
Merge commit '1666428cd' into coordinator-refresh-1527-main
SamuelSchlesinger Oct 29, 2026
48a8d3a
chore(wordram): refresh frontend imports after landed main
SamuelSchlesinger Oct 29, 2026
4b2d75c
Merge remote-tracking branch 'github/main' into coordinator-queue-146…
SamuelSchlesinger Oct 29, 2026
1f57c3c
Merge commit '4b2d75ce50dbca1101868ed3726170770d0a3e77' into coordina…
SamuelSchlesinger Oct 29, 2026
e2bf09d
Merge remote-tracking branch 'github/main' into coordinator-warm-1497
SamuelSchlesinger Oct 29, 2026
4b71a93
doc(roadmap): restore tensor milestone reference
SamuelSchlesinger Oct 29, 2026
6a18c48
Merge commit '4b71a936e4f8f33ff009045bf58d9a1c3d7400c1' into coordina…
SamuelSchlesinger Oct 29, 2026
677ea83
Merge commit '4b71a936e4f8f33ff009045bf58d9a1c3d7400c1' into coordina…
SamuelSchlesinger Oct 29, 2026
24a8774
Merge commit 'a1d1fa882117891cabd7865b108d12b5eb850d5b' into coordina…
SamuelSchlesinger Oct 29, 2026
4cb34a9
doc(roadmap): separate native Chan-He progress from tensor work
SamuelSchlesinger Oct 29, 2026
7023643
Merge commit '4cb34a93df09ff1776a998df7565d98ad7df9644' into coordina…
SamuelSchlesinger Oct 29, 2026
b70f51e
Merge commit '4cb34a93df09ff1776a998df7565d98ad7df9644' into coordina…
SamuelSchlesinger Oct 29, 2026
fa68703
Merge commit '70236432a6cef8644d5256a75edc215df92af844' into coordina…
SamuelSchlesinger Oct 29, 2026
20a40e6
Merge commit '70236432a6cef8644d5256a75edc215df92af844' into coordina…
SamuelSchlesinger Oct 29, 2026
3bb8edf
Merge commit '38f32f97e76ad36666b99d1f0d39a64fc0ef3306' into coordina…
SamuelSchlesinger Oct 29, 2026
16f2809
doc(roadmap): separate initialized frontend progress and references
SamuelSchlesinger Oct 29, 2026
ee6c863
Merge commit 'fa687036fbd8890c3dc9e0f018dd937d471f5b23' into coordina…
SamuelSchlesinger Oct 29, 2026
ad112d3
Merge commit 'cf63e382d02ba396b4f8d460958d70b15735f23e' into coordina…
SamuelSchlesinger Oct 29, 2026
490d996
Merge commit 'ad112d34ed1a803ad492859089800e30b1213541' into coordina…
SamuelSchlesinger Oct 29, 2026
dbf76d0
Merge commit '490d996b7ade2a8b41a8e8c4b7a6f9b5c6008e26' into coordina…
SamuelSchlesinger Oct 29, 2026
5a0fce5
Merge commit 'dbf76d0bcf9e4660026080f44d716a91efbc081b' into coordina…
SamuelSchlesinger Oct 29, 2026
ccc8586
chore(wordram): refresh traversal onto actual frontend parent
SamuelSchlesinger Oct 29, 2026
4a00e3d
Merge commit 'ccc8586e843aaafd3e9e1913790b2ee258447045' into coordina…
SamuelSchlesinger Oct 29, 2026
8c65438
doc(wordram): restore preprocessing resource and API handoff details
SamuelSchlesinger Oct 29, 2026
c168ecc
Merge commit 'acb3170c640efafdc24e53fa14b9dbd72588cec7' into coordina…
SamuelSchlesinger Oct 29, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions Complexity.lean
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ public import Complexity.Algorithms.ThreeSum.ChanHe.Collisions
public import Complexity.Algorithms.ThreeSum.ChanHe.Defs
public import Complexity.Algorithms.ThreeSum.ChanHe.FromNumbers
public import Complexity.Algorithms.ThreeSum.ChanHe.Recursion
public import Complexity.Algorithms.ThreeSum.ChanHe.SelectorBounds
public import Complexity.Algorithms.ThreeSum.ChanHe.ShiftedSizes
public import Complexity.Algorithms.ThreeSum.ChanHe.Sizes
public import Complexity.Algorithms.ThreeSum.Convolution
public import Complexity.Algorithms.ThreeSum.Defs
Expand Down Expand Up @@ -146,17 +148,87 @@ public import Complexity.Algorithms.WordRAM.RadixSort.Scan
public import Complexity.Algorithms.WordRAM.Stack
public import Complexity.Algorithms.WordRAM.Stack.Controller
public import Complexity.Algorithms.WordRAM.ThreeSum.Cell
public import Complexity.Algorithms.WordRAM.ThreeSum.ChanHe.BucketCounts
public import Complexity.Algorithms.WordRAM.ThreeSum.ChanHe.CollisionTest
public import Complexity.Algorithms.WordRAM.ThreeSum.ChanHe.Collisions
public import Complexity.Algorithms.WordRAM.ThreeSum.ChanHe.Count
public import Complexity.Algorithms.WordRAM.ThreeSum.ChanHe.CountCall
public import Complexity.Algorithms.WordRAM.ThreeSum.ChanHe.CountFrame
public import Complexity.Algorithms.WordRAM.ThreeSum.ChanHe.CountPlace
public import Complexity.Algorithms.WordRAM.ThreeSum.ChanHe.CountPlaceMemory
public import Complexity.Algorithms.WordRAM.ThreeSum.ChanHe.CountTriple
public import Complexity.Algorithms.WordRAM.ThreeSum.ChanHe.Modulus
public import Complexity.Algorithms.WordRAM.ThreeSum.ChanHe.NodeExec
public import Complexity.Algorithms.WordRAM.ThreeSum.ChanHe.NodeInitialize
public import Complexity.Algorithms.WordRAM.ThreeSum.ChanHe.NodeLayout
public import Complexity.Algorithms.WordRAM.ThreeSum.ChanHe.NodeMemory
public import Complexity.Algorithms.WordRAM.ThreeSum.ChanHe.NodeProgram
public import Complexity.Algorithms.WordRAM.ThreeSum.ChanHe.NodeRound
public import Complexity.Algorithms.WordRAM.ThreeSum.ChanHe.NodeSetup
public import Complexity.Algorithms.WordRAM.ThreeSum.ChanHe.NodeSpec
public import Complexity.Algorithms.WordRAM.ThreeSum.ChanHe.Padding
public import Complexity.Algorithms.WordRAM.ThreeSum.ChanHe.Parameters
public import Complexity.Algorithms.WordRAM.ThreeSum.ChanHe.Place
public import Complexity.Algorithms.WordRAM.ThreeSum.ChanHe.PlaceExec
public import Complexity.Algorithms.WordRAM.ThreeSum.ChanHe.PlaceMemory
public import Complexity.Algorithms.WordRAM.ThreeSum.ChanHe.Preprocessing
public import Complexity.Algorithms.WordRAM.ThreeSum.ChanHe.PreprocessingBounds
public import Complexity.Algorithms.WordRAM.ThreeSum.ChanHe.PreprocessingEntries
public import Complexity.Algorithms.WordRAM.ThreeSum.ChanHe.PreprocessingExecute
public import Complexity.Algorithms.WordRAM.ThreeSum.ChanHe.PreprocessingFinish
public import Complexity.Algorithms.WordRAM.ThreeSum.ChanHe.PreprocessingInput
public import Complexity.Algorithms.WordRAM.ThreeSum.ChanHe.PreprocessingIntermediates
public import Complexity.Algorithms.WordRAM.ThreeSum.ChanHe.PreprocessingInvariant
public import Complexity.Algorithms.WordRAM.ThreeSum.ChanHe.PreprocessingLayout
public import Complexity.Algorithms.WordRAM.ThreeSum.ChanHe.PreprocessingLoad
public import Complexity.Algorithms.WordRAM.ThreeSum.ChanHe.PreprocessingLoop
public import Complexity.Algorithms.WordRAM.ThreeSum.ChanHe.PreprocessingPrimes
public import Complexity.Algorithms.WordRAM.ThreeSum.ChanHe.PreprocessingProgram
public import Complexity.Algorithms.WordRAM.ThreeSum.ChanHe.PreprocessingReserve
public import Complexity.Algorithms.WordRAM.ThreeSum.ChanHe.PreprocessingSetup
public import Complexity.Algorithms.WordRAM.ThreeSum.ChanHe.PreprocessingSnapshot
public import Complexity.Algorithms.WordRAM.ThreeSum.ChanHe.PreprocessingStep
public import Complexity.Algorithms.WordRAM.ThreeSum.ChanHe.PreprocessingTime
public import Complexity.Algorithms.WordRAM.ThreeSum.ChanHe.PreprocessingWidth
public import Complexity.Algorithms.WordRAM.ThreeSum.ChanHe.Query
public import Complexity.Algorithms.WordRAM.ThreeSum.ChanHe.Residues
public import Complexity.Algorithms.WordRAM.ThreeSum.ChanHe.Search
public import Complexity.Algorithms.WordRAM.ThreeSum.ChanHe.TraversalAdmitted
public import Complexity.Algorithms.WordRAM.ThreeSum.ChanHe.TraversalCall
public import Complexity.Algorithms.WordRAM.ThreeSum.ChanHe.TraversalChildren
public import Complexity.Algorithms.WordRAM.ThreeSum.ChanHe.TraversalCost
public import Complexity.Algorithms.WordRAM.ThreeSum.ChanHe.TraversalDeliver
public import Complexity.Algorithms.WordRAM.ThreeSum.ChanHe.TraversalEmission
public import Complexity.Algorithms.WordRAM.ThreeSum.ChanHe.TraversalEmissionFrame
public import Complexity.Algorithms.WordRAM.ThreeSum.ChanHe.TraversalExec
public import Complexity.Algorithms.WordRAM.ThreeSum.ChanHe.TraversalFrames
public import Complexity.Algorithms.WordRAM.ThreeSum.ChanHe.TraversalInvariant
public import Complexity.Algorithms.WordRAM.ThreeSum.ChanHe.TraversalLive
public import Complexity.Algorithms.WordRAM.ThreeSum.ChanHe.TraversalLoop
public import Complexity.Algorithms.WordRAM.ThreeSum.ChanHe.TraversalModel
public import Complexity.Algorithms.WordRAM.ThreeSum.ChanHe.TraversalOutput
public import Complexity.Algorithms.WordRAM.ThreeSum.ChanHe.TraversalPending
public import Complexity.Algorithms.WordRAM.ThreeSum.ChanHe.TraversalProgram
public import Complexity.Algorithms.WordRAM.ThreeSum.ChanHe.TraversalResources
public import Complexity.Algorithms.WordRAM.ThreeSum.ChanHe.TraversalRoot
public import Complexity.Algorithms.WordRAM.ThreeSum.ChanHe.TraversalSkip
public import Complexity.Algorithms.WordRAM.ThreeSum.ChanHe.TraversalStack
public import Complexity.Algorithms.WordRAM.ThreeSum.ChanHe.TraversalStep
public import Complexity.Algorithms.WordRAM.ThreeSum.ChanHe.TraversalTime
public import Complexity.Algorithms.WordRAM.ThreeSum.ChanHe.TraversalVisit
public import Complexity.Algorithms.WordRAM.ThreeSum.Fill
public import Complexity.Algorithms.WordRAM.ThreeSum.Frontend
public import Complexity.Algorithms.WordRAM.ThreeSum.Frontend.Arrays
public import Complexity.Algorithms.WordRAM.ThreeSum.Frontend.Bounds
public import Complexity.Algorithms.WordRAM.ThreeSum.Frontend.Execute
public import Complexity.Algorithms.WordRAM.ThreeSum.Frontend.Frame
public import Complexity.Algorithms.WordRAM.ThreeSum.Frontend.Input
public import Complexity.Algorithms.WordRAM.ThreeSum.Frontend.Layout
public import Complexity.Algorithms.WordRAM.ThreeSum.Frontend.Model
public import Complexity.Algorithms.WordRAM.ThreeSum.Frontend.Program
public import Complexity.Algorithms.WordRAM.ThreeSum.Frontend.Scan
public import Complexity.Algorithms.WordRAM.ThreeSum.Frontend.Select
public import Complexity.Algorithms.WordRAM.ThreeSum.Frontend.Time
public import Complexity.Algorithms.WordRAM.ThreeSum.Host.Loop
public import Complexity.Algorithms.WordRAM.ThreeSum.Host.Prepare
public import Complexity.Algorithms.WordRAM.ThreeSum.Host.Program
Expand Down Expand Up @@ -1725,6 +1797,7 @@ public import Complexity.Computability.WordRAM.Dynamic
public import Complexity.Computability.WordRAM.ExactNotation
public import Complexity.Computability.WordRAM.Function
public import Complexity.Computability.WordRAM.Generic
public import Complexity.Computability.WordRAM.GhostLoop
public import Complexity.Computability.WordRAM.Heap
public import Complexity.Computability.WordRAM.ListArray
public import Complexity.Computability.WordRAM.MapOp
Expand Down Expand Up @@ -1765,6 +1838,7 @@ public import Complexity.Computability.WordRAM.Structured
public import Complexity.Computability.WordRAM.Subroutine
public import Complexity.Computability.WordRAM.Time
public import Complexity.Computability.WordRAM.Trace
public import Complexity.Computability.WordRAM.Width
public import Complexity.Crypto.Computational.Basic
public import Complexity.Crypto.Computational.CollisionResistant
public import Complexity.Crypto.Computational.Commitment
Expand Down
64 changes: 64 additions & 0 deletions Complexity/Algorithms/ThreeSum/ChanHe/SelectorBounds.lean
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/-
Copyright (c) 2026 Erik Demaine. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Erik Demaine
-/

module
-- upstream: candidate

public import Complexity.Algorithms.ThreeSum.ChanHe.Defs

/-!
# Size bounds for the Chan–He selectors, including their default

Bounding the modulus does not require either filter to succeed: a failed filter returns one.
These bounds therefore apply to native execution with arbitrary nonnegative collision thresholds,
including empty input sets. They do not assert the collision-shrinking property of a successful
search.

## Main results

* `minOrOne_filter_bounds`: a positive bounded candidate set keeps its filtered selector bounded.
* `modulus_bounds_of_candidates`: both selections, including defaults, have product in `[1,m²]`.

The bounds are original elementary consequences of the existing finite selectors.
-/

@[expose] public section

namespace Cslib.Algorithms.ThreeSum.ChanHe

open Finset

/-- Filtering positive candidates bounded by `m` keeps the default-one selector in `[1,m]`.
The candidate set and the filtered set may both be empty. -/
theorem minOrOne_filter_bounds {Q : Finset ℕ} {m : ℕ} (hm : 1 ≤ m)
(hpos : ∀ q ∈ Q, 1 ≤ q) (hle : ∀ q ∈ Q, q ≤ m)
(A : ℕ → Prop) [DecidablePred A] :
1 ≤ minOrOne {q ∈ Q | A q} ∧ minOrOne {q ∈ Q | A q} ≤ m := by
let S := {q ∈ Q | A q}
by_cases h : S.Nonempty
· have hmem : S.min' h ∈ Q := (mem_filter.mp (min'_mem S h)).1
change 1 ≤ minOrOne S ∧ minOrOne S ≤ m
rw [minOrOne, dite_eq_left h]
exact ⟨hpos _ hmem, hle _ hmem⟩
· change 1 ≤ minOrOne S ∧ minOrOne S ≤ m
rw [minOrOne, dite_eq_right h]
exact ⟨le_rfl, hm⟩

/-- Positive bounded candidates bound the modulus regardless of whether either filter succeeds.
This is a size bound only; no magnitude or successful-search premise is needed. -/
theorem modulus_bounds_of_candidates {Q : Finset ℕ} {m : ℕ} (hm : 1 ≤ m)
(hpos : ∀ q ∈ Q, 1 ≤ q) (hle : ∀ q ∈ Q, q ≤ m)
(Λ : ℕ) (S₁ S₂ S₃ : Finset ℤ) :
1 ≤ modulus Q Λ S₁ S₂ S₃ ∧ modulus Q Λ S₁ S₂ S₃ ≤ m ^ 2 := by
have hp : 1 ≤ firstP Q Λ S₁ S₂ S₃ ∧ firstP Q Λ S₁ S₂ S₃ ≤ m :=
minOrOne_filter_bounds hm hpos hle _
have hq : 1 ≤ secondP Q Λ S₁ S₂ S₃ (firstP Q Λ S₁ S₂ S₃) ∧
secondP Q Λ S₁ S₂ S₃ (firstP Q Λ S₁ S₂ S₃) ≤ m :=
minOrOne_filter_bounds hm hpos hle _
exact ⟨Nat.mul_le_mul hp.1 hq.1,
(Nat.mul_le_mul hp.2 hq.2).trans_eq (pow_two m).symm⟩

end Cslib.Algorithms.ThreeSum.ChanHe
74 changes: 74 additions & 0 deletions Complexity/Algorithms/ThreeSum/ChanHe/ShiftedSizes.lean
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/-
Copyright (c) 2026 Erik Demaine. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Erik Demaine
-/

module
-- upstream: candidate

public import Complexity.Algorithms.ThreeSum.ChanHe.Sizes

/-!
# Size bounds for the initialized-input magnitude convention

Native parameter computation uses `(n+2)^κ`, including at lengths zero and one. The existing
finite instances retain their actual input-length parameter `n`; only their quantitative upper
bounds are compared with the existing estimates at `n+2`.

## Main results

* `mPar_mono_input`: candidate bounds are monotone in input length.
* `mPar_shifted_pow_le`: square-root times squared-logarithm bound for the actual native modulus.
* `length_instances_shifted_pow_le`: degree-seven logarithmic instance count at every length.
* `packed_length_shifted_pow_le`: linear times fourth-logarithm common packed length.

These elementary parameter bridges are original and reuse the existing finite Chan–He bounds.
They do not change the finite instances or replace the actual input length by a padded input.
-/

@[expose] public section

namespace Cslib.Algorithms.ThreeSum.ChanHe

/-- Increasing the length parameter increases the candidate window without changing magnitude. -/
theorem mPar_mono_input {n n' : ℕ} (hn : n ≤ n') (U : ℕ) : mPar n U ≤ mPar n' U := by
have hs := Nat.sqrt_le_sqrt hn
unfold mPar wPar
gcongr

/-- The actual native parameter keeps length `n` and uses shifted polynomial magnitude. -/
theorem mPar_shifted_pow_le (n κ : ℕ) :
mPar n (2 * (n + 2) ^ κ) ≤
(5 * κ + 16) * (10 * κ + 40) * (Nat.sqrt (n + 2) + 1) *
(Nat.log 2 (n + 2) + 1) ^ 2 :=
(mPar_mono_input (show n ≤ n + 2 by omega) _).trans (mPar_pow_le (n + 2) κ)

/-- The unchanged actual finite instance list has a logarithmic count even at lengths zero/one. -/
theorem length_instances_shifted_pow_le (n κ : ℕ) (x : Fin n → ℤ) :
(instances n ((n + 2) ^ κ) x).length ≤ numBound κ (n + 2) := by
have hlog : 1 ≤ Nat.log 2 (n + 2) := Nat.log_pos (by decide) (by omega)
have hΛ : labelBits (2 * (n + 2) ^ κ) ≤ (κ + 2) * (Nat.log 2 (n + 2) + 1) :=
(labelBits_pow_le (n + 2) κ).trans (by rw [add_mul]; omega)
have hone : 1 ≤ ((κ + 2) * (Nat.log 2 (n + 2) + 1)) ^ 2 :=
Nat.one_le_pow _ _ (by positivity)
have hn : Nat.log 2 n ≤ Nat.log 2 (n + 2) := Nat.log_mono_right (by omega)
calc (instances n ((n + 2) ^ κ) x).length
≤ (2 * labelBits (2 * (n + 2) ^ κ) ^ 2 + 2) * (2 * Nat.log 2 n + 2) ^ 5 :=
length_instances_le ..
_ ≤ (2 * ((κ + 2) * (Nat.log 2 (n + 2) + 1)) ^ 2 +
2 * ((κ + 2) * (Nat.log 2 (n + 2) + 1)) ^ 2) *
(2 * Nat.log 2 (n + 2) + 2) ^ 5 := by gcongr; omega
_ = numBound κ (n + 2) := by unfold numBound; ring

/-- The unchanged common packed length is bounded by the old estimate evaluated at `n+2`. -/
theorem packed_length_shifted_pow_le (κ n : ℕ) :
8 * mPar n (2 * (n + 2) ^ κ) ^ 2 ≤
32 * ((5 * κ + 16) * (10 * κ + 40)) ^ 2 * (n + 2) *
(Nat.log 2 (n + 2) + 1) ^ 4 := by
calc 8 * mPar n (2 * (n + 2) ^ κ) ^ 2 ≤ lenOf κ (n + 2) :=
Nat.mul_le_mul_left 8 (Nat.pow_le_pow_left
(mPar_mono_input (show n ≤ n + 2 by omega) _) 2)
_ ≤ _ := lenOf_le κ (n + 2) (by omega)

end Cslib.Algorithms.ThreeSum.ChanHe
Loading
Loading