Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
154 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
2434f47
feat(matrix): prove the tensor recursion and pruned evaluation core
edemaine Oct 28, 2026
62dc601
doc(matrix): clarify the overlapping contributing leaf
edemaine Oct 28, 2026
4f3226c
doc(matrix): make tensor and pruning explanations standalone
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
844522a
feat(matrix): prove finite thin-product correctness and sparse bounds
edemaine Oct 28, 2026
5cbb93d
feat(wordram): compute Chan–He parameters from native input
edemaine Oct 28, 2026
b4936ce
doc(matrix): explain finite thin-product guarantees in the Lean API
edemaine Oct 28, 2026
0505439
fix(wordram): repair parameter proof hygiene and ceiling-log docs
edemaine Oct 28, 2026
ad3e097
feat(wordram): implement shared tensor encodings
edemaine Oct 28, 2026
3b9234d
test(wordram): connect encoder witnesses to charged runs
edemaine Oct 28, 2026
46e9e72
feat(wordram): checkpoint native pruned-query controller proofs
edemaine Oct 28, 2026
68bbe40
refactor(schonhage): reuse binomial bounds and sharpen signed tests
edemaine Oct 28, 2026
cb261f6
feat(WordRAM): prepare and encode every shared matrix band
edemaine Oct 28, 2026
87ff44c
feat(wordram): checkpoint native pruned accumulation and frame transi…
edemaine Oct 28, 2026
b3b8047
feat(wordram): checkpoint actual pruned-query root-frame stores
edemaine Oct 28, 2026
6603615
fix(nat): reuse existing tuple digit identity in band preparation
edemaine Oct 28, 2026
79c9407
feat(wordram): checkpoint complete native pruned-controller phases
edemaine Oct 28, 2026
99b8a1b
doc(matrix): replace copied source prose with API descriptions
edemaine Oct 28, 2026
12abeee
refactor(finset): use order-embedding names in OrderGlue
edemaine Oct 28, 2026
829613f
feat(WordRAM): prove all-depth pruned controller execution
edemaine Oct 28, 2026
a93c021
style(WordRAM): normalize native proof file modes
edemaine Oct 28, 2026
0c2e0eb
feat(wordram): complete initialized sparse pruned-query execution
edemaine Oct 28, 2026
60bec64
chore(wordram): combine band and query evaluator prerequisites
edemaine Oct 29, 2026
06b3563
feat(wordram): checkpoint computed wanted-query routing
edemaine Oct 29, 2026
7772a34
feat(wordram): checkpoint wanted count-pass proofs
edemaine Oct 29, 2026
702c14b
doc(finset): restore ordered-gluing source credit
SamuelSchlesinger Oct 29, 2026
ce77926
fix(wordram): address pruned-query review findings
edemaine Oct 29, 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
0b5cfe4
chore(wordram): retain reviewed pruned-query parent repair
edemaine 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
60dfe9a
Merge commit '02f1b495322d8cfee81969186795670e3574defa' into coordina…
SamuelSchlesinger Oct 29, 2026
6f48d5c
Merge remote-tracking branch 'origin/main' into coordinator/integrate…
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
3187bca
chore(wordram): retain reviewed sibling source-credit fix
edemaine Oct 29, 2026
a6e4005
feat(wordram): route and group wanted thin-product queries
edemaine Oct 29, 2026
249f960
Merge commit '6f48d5c0efdfea1984c4accf368de9eaa9716b95' into coordina…
SamuelSchlesinger Oct 29, 2026
08a0415
Merge remote-tracking branch 'origin/main' into coordinator/integrate…
SamuelSchlesinger Oct 29, 2026
b0fa45b
Merge commit '08a0415413677534785113b7cf643b1ba9a6ee78' into coordina…
SamuelSchlesinger Oct 29, 2026
bd9bd2b
fix(imports): regenerate aggregate after shared-encoder integration
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
5f6aad5
chore(integration): refresh tensor recursion supplier after hashing l…
SamuelSchlesinger Oct 29, 2026
d91296f
perf(schonhage): focus cell arithmetic and use the default heartbeat …
SamuelSchlesinger Oct 29, 2026
d8f4162
fix(doc): restore unrelated upstream coordination records
SamuelSchlesinger Oct 29, 2026
a63864f
chore(three-sum): merge corrected supplier preserving scope and sourc…
SamuelSchlesinger Oct 29, 2026
781297c
chore(three-sum): merge refreshed thin-product supplier preserving en…
SamuelSchlesinger Oct 29, 2026
1f2cfc4
Merge commit '781297cef838ef99c33e4036195e58b06ca46779' into coordina…
SamuelSchlesinger Oct 29, 2026
b4aa7b5
Merge remote-tracking branch 'origin/main' into coordinator/integrate…
SamuelSchlesinger Oct 29, 2026
780531b
fix(imports): regenerate band-preparation aggregate from merged inven…
SamuelSchlesinger Oct 29, 2026
04349d4
Merge commit '780531b426051080bb274a0511f49142af03557c' into coordina…
SamuelSchlesinger Oct 29, 2026
5bf1f0e
doc(order-glue): preserve reviewed source credit through supplier merge
SamuelSchlesinger Oct 29, 2026
ec46a4f
chore(schonhage): integrate reviewed query and band suppliers
SamuelSchlesinger Oct 29, 2026
a9d3fb9
chore(schonhage): integrate wanted routing with refreshed query supplier
SamuelSchlesinger Oct 29, 2026
91f485e
chore(schonhage): adopt actual reviewed naming-refactor supplier
SamuelSchlesinger Oct 29, 2026
a677276
Merge remote-tracking branch 'origin/main' into coordinator/refresh-1…
SamuelSchlesinger Oct 29, 2026
8a81617
Merge remote-tracking branch 'github/main' into coordinator-refresh-1…
SamuelSchlesinger Oct 29, 2026
9e9cb10
Merge commit 'a67727699b41ff9fa7d7227964d67c26699ab7f6' into coordina…
SamuelSchlesinger Oct 29, 2026
c3e1bcd
doc(order-glue): restore paper citation and finite scope
SamuelSchlesinger Oct 29, 2026
606fd61
Merge commit 'c3e1bcd3c8d9bb1dc4819d1b0a994bf52119731b' into coordina…
SamuelSchlesinger Oct 29, 2026
59c6f80
feat(wordram): checkpoint native queried-product construction (#1581)
edemaine Oct 29, 2026
9d33c95
Merge commit '606fd614454016f738d69d2cd768cb4d9a9ad795' into coordina…
SamuelSchlesinger Oct 29, 2026
936457e
Merge commit '9d33c950c695a353b20fe43fd7524f25663a4bce' into coordina…
SamuelSchlesinger Oct 29, 2026
4b2d75c
Merge remote-tracking branch 'github/main' into coordinator-queue-146…
SamuelSchlesinger Oct 29, 2026
ea38fc5
Merge remote-tracking branch 'origin/main' into coordinator/refresh-1…
SamuelSchlesinger Oct 29, 2026
6a86e25
fix(imports): regenerate thin-product aggregate after main integration
SamuelSchlesinger Oct 29, 2026
6dbd0cc
Merge commit '6a86e258db83b7724f5bd93c43c0cbc4221a992f' into coordina…
SamuelSchlesinger Oct 29, 2026
c94a52f
Merge commit '4b2d75ce50dbca1101868ed3726170770d0a3e77' into coordina…
SamuelSchlesinger Oct 29, 2026
d072322
Merge remote-tracking branch 'origin/main' into coordinator/repair-15…
SamuelSchlesinger Oct 29, 2026
61e7fe7
doc(wordram): separate shared-encoder integration records
SamuelSchlesinger Oct 29, 2026
e21cbd0
chore(integration): preserve local band-refresh preparation
SamuelSchlesinger Oct 29, 2026
d2e8386
Merge commit '38f32f97e76ad36666b99d1f0d39a64fc0ef3306' into coordina…
SamuelSchlesinger Oct 29, 2026
f55b418
Merge commit 'd2e8386e3352241f97fc1c3faa3da53c1fbb1f68' into coordina…
SamuelSchlesinger Oct 29, 2026
8f25b31
Merge commit 'f04ad02616791b3fa37ff236ac27b0a8690ca985' into coordina…
SamuelSchlesinger Oct 29, 2026
debd649
doc(matrix): keep progress links out of shared reference append block
SamuelSchlesinger Oct 29, 2026
af20863
feat(wordram): checkpoint complete queried-product source before supp…
edemaine Oct 29, 2026
cf25502
chore(wordram): merge actual reviewed queried-product supplier
edemaine Oct 29, 2026
ff31104
feat(wordram): execute queried thin-matrix products (#1581)
edemaine Oct 29, 2026
9a57e13
style(Schonhage): remove trailing space in queried products
edemaine Oct 29, 2026
37306ef
doc(Schonhage): retain band catalogue encoding contract
edemaine Oct 29, 2026
b71ae0e
Merge commit 'cf63e382d02ba396b4f8d460958d70b15735f23e' into coordina…
SamuelSchlesinger Oct 29, 2026
8527c1f
Merge commit 'cf63e382d02ba396b4f8d460958d70b15735f23e' into coordina…
SamuelSchlesinger Oct 29, 2026
82f86fe
Merge commit '8527c1f4d25246fee901303e7c0f1310d30306c0' into coordina…
SamuelSchlesinger Oct 29, 2026
d429833
Merge commit '82f86fec9b93d546f96542987255aa9f16377b3b' into coordina…
SamuelSchlesinger Oct 29, 2026
f43c26e
Merge commit '82f86fec9b93d546f96542987255aa9f16377b3b' into coordina…
SamuelSchlesinger Oct 29, 2026
168a8be
Merge commit 'f43c26edef5bc586602e0678be9f8a59759bd5f2' into coordina…
SamuelSchlesinger Oct 29, 2026
7d82da6
Merge commit 'd429833391f88fe96223bef8124be7e6b21a117f' into coordina…
SamuelSchlesinger Oct 29, 2026
70898da
fix(imports): regenerate wanted-routing aggregate from actual inventory
SamuelSchlesinger Oct 29, 2026
a8cb7c9
chore(schonhage): refresh queried products onto actual wanted parent
SamuelSchlesinger Oct 29, 2026
7cb7ade
wip(wordram): checkpoint callable thin-product source
edemaine Oct 29, 2026
904c620
chore(wordram): merge reviewed queried-product parent into callable c…
edemaine Oct 29, 2026
f5e6949
feat(WordRAM): run queried thin products in caller-owned memory
edemaine Oct 29, 2026
fd1f2fc
chore(WordRAM): merge pinned landed main into callable product child
edemaine Oct 29, 2026
ce10624
refactor(WordRAM): align ArrayNormalize module name and admission prose
edemaine Oct 29, 2026
8f46341
feat(ExactTriangle): checkpoint actual record product composition
edemaine Oct 29, 2026
8612aff
chore(ExactTriangle): merge pinned main into record product child
edemaine Oct 29, 2026
96842bb
feat(ExactTriangle): validate initialized record product adapter
edemaine Oct 29, 2026
0e10700
feat(ExactTriangle): checkpoint native candidate-verification source
edemaine Oct 29, 2026
b461744
feat(ExactTriangle): compose initialized per-record native witness re…
edemaine Oct 29, 2026
c02ed27
chore(ExactTriangle): merge pinned main for witness validation
edemaine Oct 29, 2026
888918d
chore(deps): track CSLib main and Lean rc2
SamuelSchlesinger Oct 29, 2026
9a1b754
refactor(probability): use generic infinite-sum lemmas
SamuelSchlesinger Oct 29, 2026
d7dcd79
fix(build): adapt proofs to the rc2 Mathlib API
SamuelSchlesinger Oct 29, 2026
7925011
Merge remote-tracking branch 'origin/main' into work/cslib-rc2-sync-1…
SamuelSchlesinger Oct 29, 2026
f5a70cb
test(quantum): qualify the protected matrix lemma
SamuelSchlesinger Oct 29, 2026
bb3e910
fix(build): normalize goals before proof automation
SamuelSchlesinger Oct 29, 2026
d4b0493
chore(WordRAM): finalize native record witness validation
edemaine Oct 29, 2026
0d38523
Merge commit '96fd02a85579bbbce97c02110ed80da02684cb2e' into work/csl…
SamuelSchlesinger Oct 29, 2026
2e388dc
doc(ExactTriangle): state native code bound inclusively
edemaine Oct 29, 2026
9ed4900
feat(ExactTriangle): execute the native fixed-prime catalogue
edemaine Oct 29, 2026
0749a5b
chore(ExactTriangle): merge pinned rc2 prerequisites for validation
edemaine Oct 29, 2026
b6519e9
doc(ExactTriangle): merge the exact reviewed supplier bound wording
edemaine Oct 29, 2026
0edd088
Merge commit '0d38523e96f8b431aeadc86c548c9994714f9b00' into coordina…
edemaine Oct 29, 2026
52b94d0
chore(ExactTriangle): validate fixed-prime native solver on supported…
edemaine Oct 30, 2026
741051c
Merge commit '0ba8b2e59d4d7009c814096d8bbb4a9823d06963' into coordina…
edemaine Oct 30, 2026
3cda568
chore(ExactTriangle): align fixed-prime stack with supported rc2 parent
edemaine Oct 30, 2026
14e4ba5
feat(WordRAM): implement native cyclic coefficient multiplication
edemaine Oct 30, 2026
ffa8337
feat(ExactTriangle): implement concrete cyclic Strassen counter code
edemaine Oct 30, 2026
77b8c71
chore(ExactTriangle): normalize own counter source file modes
edemaine Oct 30, 2026
c0cf4a4
feat(WordRAM): prove native Strassen forms and counter preparation st…
edemaine Oct 30, 2026
0aa2272
feat(WordRAM): prove Strassen phase bounds and native traversal base …
edemaine Oct 30, 2026
19859fe
feat(WordRAM): bound the Strassen proof recurrence by seven to the depth
edemaine Oct 30, 2026
100826d
feat(WordRAM): prove native Strassen child preparation and return stages
edemaine Oct 30, 2026
30f3af5
feat(WordRAM): prove complete native cyclic-coefficient Strassen exec…
edemaine Oct 30, 2026
bfa3de1
feat(WordRAM): prove concrete CountPrime multiplication and metadata …
edemaine Oct 30, 2026
18ea336
feat(WordRAM): prove the complete native CountPrime matrix-building loop
edemaine Oct 30, 2026
4419dca
feat(WordRAM): identify computed CountPrime matrices with existing co…
edemaine Oct 30, 2026
e1ba17a
chore(ExactTriangle): align resumed counter with pinned landed kernel
edemaine Oct 31, 2026
35a8294
fix(ExactTriangle): finish coefficient merge after UTF-8 read failure
edemaine Oct 31, 2026
3c119cc
feat(ExactTriangle): prove actual selected-coefficient counter scan
edemaine Oct 31, 2026
2c3657a
feat(ExactTriangle): compose complete native modular counter caller
edemaine Oct 31, 2026
61c82f6
feat(ExactTriangle): finish initialized subcubic native modular counter
edemaine Oct 31, 2026
7bc9b1c
chore(ExactTriangle): register complete native modular counter
edemaine Oct 31, 2026
02a7822
doc(Strassen): correct pinned recurrence and identity locators
edemaine Oct 31, 2026
4027bd9
Merge main into native modular counter PR #2109
edemaine Oct 31, 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
67 changes: 67 additions & 0 deletions Complexity.lean
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
module -- shake: keep-all --deprecated_module: ignore

public import Complexity.Algorithms.ExactTriangle.CountPrime
public import Complexity.Algorithms.ExactTriangle.CountPrime.Extraction
public import Complexity.Algorithms.ExactTriangle.Defs
public import Complexity.Algorithms.ExactTriangle.FailureAccounting
public import Complexity.Algorithms.ExactTriangle.Hashing
Expand Down Expand Up @@ -92,6 +94,10 @@ public import Complexity.Algorithms.MatrixMultiplication.Schonhage.Sparse
public import Complexity.Algorithms.MatrixMultiplication.Schonhage.SplitDigits
public import Complexity.Algorithms.MatrixMultiplication.Schonhage.ThinProduct
public import Complexity.Algorithms.MatrixMultiplication.Schonhage.Tiling
public import Complexity.Algorithms.MatrixMultiplication.Strassen.Coefficients
public import Complexity.Algorithms.MatrixMultiplication.Strassen.Correctness
public import Complexity.Algorithms.MatrixMultiplication.Strassen.Defs
public import Complexity.Algorithms.MatrixMultiplication.Strassen.Phases
public import Complexity.Algorithms.Reachability.BreadthFirst
public import Complexity.Algorithms.Reachability.InductiveCounting
public import Complexity.Algorithms.Reachability.InductiveCounting.Bounds
Expand Down Expand Up @@ -151,6 +157,34 @@ public import Complexity.Algorithms.WordRAM.ExactTriangle.Catalogue
public import Complexity.Algorithms.WordRAM.ExactTriangle.ChunkCatalogue
public import Complexity.Algorithms.WordRAM.ExactTriangle.Chunks
public import Complexity.Algorithms.WordRAM.ExactTriangle.Classes
public import Complexity.Algorithms.WordRAM.ExactTriangle.CountPrime
public import Complexity.Algorithms.WordRAM.ExactTriangle.CountPrime.Access
public import Complexity.Algorithms.WordRAM.ExactTriangle.CountPrime.Bounds
public import Complexity.Algorithms.WordRAM.ExactTriangle.CountPrime.CoefficientMatrices
public import Complexity.Algorithms.WordRAM.ExactTriangle.CountPrime.Exec
public import Complexity.Algorithms.WordRAM.ExactTriangle.CountPrime.ExecReady
public import Complexity.Algorithms.WordRAM.ExactTriangle.CountPrime.Flat
public import Complexity.Algorithms.WordRAM.ExactTriangle.CountPrime.Input
public import Complexity.Algorithms.WordRAM.ExactTriangle.CountPrime.Layout
public import Complexity.Algorithms.WordRAM.ExactTriangle.CountPrime.Logarithm
public import Complexity.Algorithms.WordRAM.ExactTriangle.CountPrime.Matrix
public import Complexity.Algorithms.WordRAM.ExactTriangle.CountPrime.MatrixCell
public import Complexity.Algorithms.WordRAM.ExactTriangle.CountPrime.MatrixReadback
public import Complexity.Algorithms.WordRAM.ExactTriangle.CountPrime.MatrixResidue
public import Complexity.Algorithms.WordRAM.ExactTriangle.CountPrime.Monomial
public import Complexity.Algorithms.WordRAM.ExactTriangle.CountPrime.Product
public import Complexity.Algorithms.WordRAM.ExactTriangle.CountPrime.Program
public import Complexity.Algorithms.WordRAM.ExactTriangle.CountPrime.ResidueArray
public import Complexity.Algorithms.WordRAM.ExactTriangle.CountPrime.ResidueArrays
public import Complexity.Algorithms.WordRAM.ExactTriangle.CountPrime.Scan
public import Complexity.Algorithms.WordRAM.ExactTriangle.CountPrime.ScanCell
public import Complexity.Algorithms.WordRAM.ExactTriangle.CountPrime.ScanReadback
public import Complexity.Algorithms.WordRAM.ExactTriangle.CountPrime.Setup
public import Complexity.Algorithms.WordRAM.ExactTriangle.CountPrime.Solve
public import Complexity.Algorithms.WordRAM.ExactTriangle.CountPrime.SourceBounds
public import Complexity.Algorithms.WordRAM.ExactTriangle.CountPrime.Spread
public import Complexity.Algorithms.WordRAM.ExactTriangle.CountPrime.TimeBound
public import Complexity.Algorithms.WordRAM.ExactTriangle.CountPrime.Width
public import Complexity.Algorithms.WordRAM.ExactTriangle.FixedPrime
public import Complexity.Algorithms.WordRAM.ExactTriangle.FixedPrime.Accounting
public import Complexity.Algorithms.WordRAM.ExactTriangle.FixedPrime.Controller
Expand Down Expand Up @@ -399,6 +433,35 @@ public import Complexity.Algorithms.WordRAM.MatrixMultiplication.Schonhage.Wante
public import Complexity.Algorithms.WordRAM.MatrixMultiplication.Schonhage.Wanted.ScatterWrite
public import Complexity.Algorithms.WordRAM.MatrixMultiplication.Schonhage.Wanted.Setup
public import Complexity.Algorithms.WordRAM.MatrixMultiplication.Schonhage.Wanted.Width
public import Complexity.Algorithms.WordRAM.MatrixMultiplication.Strassen.Accumulate
public import Complexity.Algorithms.WordRAM.MatrixMultiplication.Strassen.ArithmeticForm
public import Complexity.Algorithms.WordRAM.MatrixMultiplication.Strassen.Bounds
public import Complexity.Algorithms.WordRAM.MatrixMultiplication.Strassen.Child
public import Complexity.Algorithms.WordRAM.MatrixMultiplication.Strassen.Control
public import Complexity.Algorithms.WordRAM.MatrixMultiplication.Strassen.CopyForm
public import Complexity.Algorithms.WordRAM.MatrixMultiplication.Strassen.Dispatch
public import Complexity.Algorithms.WordRAM.MatrixMultiplication.Strassen.Entry
public import Complexity.Algorithms.WordRAM.MatrixMultiplication.Strassen.Exec
public import Complexity.Algorithms.WordRAM.MatrixMultiplication.Strassen.Finish
public import Complexity.Algorithms.WordRAM.MatrixMultiplication.Strassen.Form
public import Complexity.Algorithms.WordRAM.MatrixMultiplication.Strassen.Frame
public import Complexity.Algorithms.WordRAM.MatrixMultiplication.Strassen.Initialize
public import Complexity.Algorithms.WordRAM.MatrixMultiplication.Strassen.Leaf
public import Complexity.Algorithms.WordRAM.MatrixMultiplication.Strassen.LeafStep
public import Complexity.Algorithms.WordRAM.MatrixMultiplication.Strassen.Next
public import Complexity.Algorithms.WordRAM.MatrixMultiplication.Strassen.Pending
public import Complexity.Algorithms.WordRAM.MatrixMultiplication.Strassen.Prepare
public import Complexity.Algorithms.WordRAM.MatrixMultiplication.Strassen.Program
public import Complexity.Algorithms.WordRAM.MatrixMultiplication.Strassen.Progress
public import Complexity.Algorithms.WordRAM.MatrixMultiplication.Strassen.Push
public import Complexity.Algorithms.WordRAM.MatrixMultiplication.Strassen.Quadrant
public import Complexity.Algorithms.WordRAM.MatrixMultiplication.Strassen.QuarterUpdate
public import Complexity.Algorithms.WordRAM.MatrixMultiplication.Strassen.Receive
public import Complexity.Algorithms.WordRAM.MatrixMultiplication.Strassen.Restore
public import Complexity.Algorithms.WordRAM.MatrixMultiplication.Strassen.Resume
public import Complexity.Algorithms.WordRAM.MatrixMultiplication.Strassen.State
public import Complexity.Algorithms.WordRAM.MatrixMultiplication.Strassen.Traversal
public import Complexity.Algorithms.WordRAM.MatrixMultiplication.Strassen.Zero
public import Complexity.Algorithms.WordRAM.NatClog
public import Complexity.Algorithms.WordRAM.NatGcd
public import Complexity.Algorithms.WordRAM.NatLog
Expand Down Expand Up @@ -2431,6 +2494,9 @@ public import Complexity.Computability.WordRAM.Randomized.UniformLoopExit
public import Complexity.Computability.WordRAM.RegisterFrame
public import Complexity.Computability.WordRAM.Sequence
public import Complexity.Computability.WordRAM.Signed.Arithmetic
public import Complexity.Computability.WordRAM.Signed.ArrayArithmetic.Body
public import Complexity.Computability.WordRAM.Signed.ArrayArithmetic.Exec
public import Complexity.Computability.WordRAM.Signed.ArrayArithmetic.Program
public import Complexity.Computability.WordRAM.Signed.Comparison
public import Complexity.Computability.WordRAM.Signed.Compile
public import Complexity.Computability.WordRAM.Signed.Encoding
Expand Down Expand Up @@ -3025,6 +3091,7 @@ public import Complexity.Foundations.Data.Nat.Factorial
public import Complexity.Foundations.Data.Nat.Fields
public import Complexity.Foundations.Data.Nat.IntermediateValue
public import Complexity.Foundations.Data.Nat.Log
public import Complexity.Foundations.Data.Nat.Morton
public import Complexity.Foundations.Data.Nat.OddMulMod
public import Complexity.Foundations.Data.Nat.OfDigits
public import Complexity.Foundations.Data.Nat.PolynomialBound.Closure
Expand Down
147 changes: 147 additions & 0 deletions Complexity/Algorithms/ExactTriangle/CountPrime.lean
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
/-
Copyright (c) 2026 Anthropic, PBC, Erik Demaine. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anthropic, PBC, Erik Demaine
-/

module
-- upstream: candidate

public import Complexity.Algorithms.ExactTriangle.Hashing
public import Complexity.Algorithms.MatrixMultiplication.Strassen.Correctness

/-!
# Modular triangle counts from the actual seven-product coefficient recursion

The coefficient arrays contain zero padding and one monomial for each real edge residue.
`CountPrime.count` applies the executable finite Strassen recursion and selects one product
coefficient for each original AB pair. It equals the existing `countZeroMod`, including
modular false positives. This is a mathematical specification and correctness bridge for
the native counter, not a native execution or running-time theorem.

The construction selectively adapts Spec/Sec3/Theorem17/Strassen.lean, the `matPList`,
`matQList`, `countBy` and `countOf_eq` sections, at revision
16a5ce41304fcdaea4e0be7c132e1c361dc26da5. Existing `matP`, `matQ`, cyclic coefficients and
modular triangle counts are reused; no parallel triangle problem or polynomial ring is added.
-/

public section

namespace Cslib.Algorithms.ExactTriangle.CountPrime

open Cslib.CyclicIntRing Cslib.Algorithms.MatrixMultiplication.Strassen

/-- Native P coefficient specification, including true zero padding outside the original side. -/
@[expose] def pCoefficients {n : ℕ} (p : ℕ) (wAC : Fin n → Fin n → ℤ) (i : ℕ) : ℤ :=
if h : Nat.Morton.row (i / p) < n ∧ Nat.Morton.column (i / p) < n then
if i % p = (wAC ⟨_, h.1⟩ ⟨_, h.2⟩ % (p : ℤ)).toNat then 1 else 0
else 0

/-- Native Q coefficient specification; the original BC coordinates are transposed. -/
@[expose] def qCoefficients {n : ℕ} (p : ℕ) (wBC : Fin n → Fin n → ℤ) (i : ℕ) : ℤ :=
if h : Nat.Morton.row (i / p) < n ∧ Nat.Morton.column (i / p) < n then
if i % p = (wBC ⟨_, h.2⟩ ⟨_, h.1⟩ % (p : ℤ)).toNat then 1 else 0
else 0

/-- Every actual monomial coefficient, including padding, has magnitude at most one. -/
theorem pCoefficients_natAbs_le_one {n : ℕ} (p : ℕ) (wAC : Fin n → Fin n → ℤ) (i : ℕ) :
(pCoefficients p wAC i).natAbs ≤ 1 := by
unfold pCoefficients
split_ifs <;> decide

/-- The transposed monomial matrix has the same unit coefficient bound. -/
theorem qCoefficients_natAbs_le_one {n : ℕ} (p : ℕ) (wBC : Fin n → Fin n → ℤ) (i : ℕ) :
(qCoefficients p wBC i).natAbs ≤ 1 := by
unfold qCoefficients
split_ifs <;> decide

private noncomputable def pad {n p : ℕ} (M : Matrix (Fin n) (Fin n) (CyclicIntRing p))
(a b : ℕ) : CyclicIntRing p := if h : a < n ∧ b < n then M ⟨a, h.1⟩ ⟨b, h.2⟩ else 0

private theorem pCoefficients_eq {n p : ℕ} (hp : p ≠ 0) (wAC : Fin n → Fin n → ℤ) :
pCoefficients p wAC = coefficients hp (pad (matP wAC p)) := by
funext i
by_cases h : Nat.Morton.row (i / p) < n ∧ Nat.Morton.column (i / p) < n
· simp only [pCoefficients, coefficients, pad, dite_eq_left h, matP, Matrix.of_apply,
coeff_x_pow]
rw [Nat.mod_eq_of_lt (show (wAC ⟨_, h.1⟩ ⟨_, h.2⟩ % (p : ℤ)).toNat < p from
Int.natMod_lt hp)]
· simp only [pCoefficients, coefficients, pad, dite_eq_right h, map_zero]

private theorem qCoefficients_eq {n p : ℕ} (hp : p ≠ 0) (wBC : Fin n → Fin n → ℤ) :
qCoefficients p wBC = coefficients hp (pad (matQ wBC p)) := by
funext i
by_cases h : Nat.Morton.row (i / p) < n ∧ Nat.Morton.column (i / p) < n
· simp only [qCoefficients, coefficients, pad, dite_eq_left h, matQ, Matrix.of_apply,
coeff_x_pow]
rw [Nat.mod_eq_of_lt (show (wBC ⟨_, h.2⟩ ⟨_, h.1⟩ % (p : ℤ)).toNat < p from
Int.natMod_lt hp)]
· simp only [qCoefficients, coefficients, pad, dite_eq_right h, map_zero]

private theorem sum_pad {n p N : ℕ} (hN : n ≤ N)
(M K : Matrix (Fin n) (Fin n) (CyclicIntRing p)) (a b : Fin n) :
∑ c ∈ Finset.range N, pad M a c * pad K c b = (M * K) a b := by
obtain ⟨k, rfl⟩ := Nat.exists_eq_add_of_le hN
have ht : ∑ c ∈ Finset.range k, pad M a (n + c) * pad K (n + c) b = 0 :=
Finset.sum_eq_zero fun c _ => by simp [pad]
rw [Finset.sum_range_add, ht, add_zero, Matrix.mul_apply, Finset.sum_range]
exact Finset.sum_congr rfl fun c _ => by simp [pad]

/-- Every original pair and residue in the executable finite Strassen coefficient array
has exactly the existing cyclic matrix-product meaning, including power-of-two padding. -/
theorem multiply_entry_eq_coeff {n p k : ℕ} (hp : p ≠ 0) (hn : n ≤ 2 ^ k)
(wBC wAC : Fin n → Fin n → ℤ) (a b : Fin n) (r : ℕ) (hr : r < p) :
multiply p k (pCoefficients p wAC) (qCoefficients p wBC)
(Nat.Morton.index a b * p + r) =
CyclicIntRing.coeff hp r ((matP wAC p * matQ wBC p) a b) := by
have hi := Nat.Morton.index_lt (a.isLt.trans_le hn) (b.isLt.trans_le hn)
have hmul := Nat.mul_le_mul_right p (Nat.succ_le_of_lt hi)
rw [Nat.succ_mul] at hmul
have hidx : Nat.Morton.index a b * p + r < 4 ^ k * p := by omega
rw [multiply_eq_coefficients hp k (pad (matP wAC p)) (pad (matQ wBC p))
(pCoefficients p wAC) (qCoefficients p wBC)
(fun i _ => congrFun (pCoefficients_eq hp wAC) i)
(fun i _ => congrFun (qCoefficients_eq hp wBC) i) hidx,
coefficients_at hp _ a b hr, sum_pad hn]

/-- The selected real product coefficient is a nonnegative count of at most n middle
vertices. Native signed-to-unsigned extraction uses this bound before every sum. -/
theorem multiply_entry_bounds {n p k : ℕ} (hp : p ≠ 0) (hn : n ≤ 2 ^ k)
(wBC wAC : Fin n → Fin n → ℤ) (a b : Fin n) (r : ℕ) (hr : r < p) :
0 ≤ multiply p k (pCoefficients p wAC) (qCoefficients p wBC)
(Nat.Morton.index a b * p + r) ∧
multiply p k (pCoefficients p wAC) (qCoefficients p wBC)
(Nat.Morton.index a b * p + r) ≤ (n : ℤ) := by
classical
rw [multiply_entry_eq_coeff hp hn wBC wAC a b r hr,
coeff_matP_mul_matQ wBC wAC hp a b r hr]
have hc := Finset.card_le_card (Finset.filter_subset (s := Finset.univ)
(p := fun c : Fin n => wAC a c + wBC b c ≡ (r : ℤ) [ZMOD (p : ℤ)]))
simp only [Finset.card_univ, Fintype.card_fin] at hc
constructor
· positivity
· exact_mod_cast hc

/-- Select the (-AB)-residue coefficient for each original pair after the real seven-product
finite recursion. The depth controls zero padding; it is not a supplied multiplication. -/
@[expose] def count {n : ℕ} (p k : ℕ) (wAB wBC wAC : Fin n → Fin n → ℤ) : ℤ :=
∑ a : Fin n, ∑ b : Fin n,
multiply p k (pCoefficients p wAC) (qCoefficients p wBC)
(Nat.Morton.index a b * p + ((-wAB a b) % (p : ℤ)).toNat)

/-- The finite coefficient algorithm counts exactly the existing modular-zero predicate,
for every nonzero modulus and every power-of-two padding covering the input. -/
theorem count_eq {n p k : ℕ} (hp : p ≠ 0) (hn : n ≤ 2 ^ k)
(wAB wBC wAC : Fin n → Fin n → ℤ) :
count p k wAB wBC wAC = (countZeroMod wAB wBC wAC p : ℤ) := by
have hc := falsePositiveCount_add_zeroCount_eq_sum_coeff wAB wBC wAC hp
rw [← countZeroMod_eq] at hc
rw [count, hc]
apply Finset.sum_congr rfl
intro a _
apply Finset.sum_congr rfl
intro b _
have hr : ((-wAB a b) % (p : ℤ)).toNat < p := Int.natMod_lt hp
exact multiply_entry_eq_coeff hp hn wBC wAC a b _ hr

end Cslib.Algorithms.ExactTriangle.CountPrime
91 changes: 91 additions & 0 deletions Complexity/Algorithms/ExactTriangle/CountPrime/Extraction.lean
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/-
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.ExactTriangle.CountPrime

/-!
# Nonnegative selected coefficients for modular triangle counting

These bridges justify the real counter's unsigned extraction and summation from the existing
cyclic product specification. They do not assume a matrix multiplication or native execution.
-/

public section

namespace Cslib.Algorithms.ExactTriangle.CountPrime

open Cslib.Algorithms.MatrixMultiplication.Strassen

/-- The unsigned value extracted from one actual original-coordinate product coefficient. -/
@[expose] def pairCoefficient {n : ℕ} (p k : ℕ)
(wAB wBC wAC : Fin n → Fin n → ℤ) (a b : Fin n) : ℕ :=
(multiply p k (pCoefficients p wAC) (qCoefficients p wBC)
(Nat.Morton.index a b * p + ((-wAB a b) % (p : ℤ)).toNat)).natAbs

/-- Nonnegativity makes signed decoding by division by two an exact natural count. -/
theorem pairCoefficient_cast {n p k : ℕ} (hp : p ≠ 0) (hn : n ≤ 2 ^ k)
(wAB wBC wAC : Fin n → Fin n → ℤ) (a b : Fin n) :
(pairCoefficient p k wAB wBC wAC a b : ℤ) =
multiply p k (pCoefficients p wAC) (qCoefficients p wBC)
(Nat.Morton.index a b * p + ((-wAB a b) % (p : ℤ)).toNat) := by
exact Int.natAbs_of_nonneg
(multiply_entry_bounds hp hn wBC wAC a b _ (Int.natMod_lt hp)).1

/-- Each selected coefficient counts at most the original side many middle vertices. -/
theorem pairCoefficient_le {n p k : ℕ} (hp : p ≠ 0) (hn : n ≤ 2 ^ k)
(wAB wBC wAC : Fin n → Fin n → ℤ) (a b : Fin n) :
pairCoefficient p k wAB wBC wAC a b ≤ n := by
have he := pairCoefficient_cast hp hn wAB wBC wAC a b
have hb := (multiply_entry_bounds hp hn wBC wAC a b
(((-wAB a b) % (p : ℤ)).toNat) (Int.natMod_lt hp)).2
omega

/-- All selected original-coordinate coefficients sum to the existing modular triangle count. -/
theorem sum_pairCoefficient {n p k : ℕ} (hp : p ≠ 0) (hn : n ≤ 2 ^ k)
(wAB wBC wAC : Fin n → Fin n → ℤ) :
∑ a : Fin n, ∑ b : Fin n, pairCoefficient p k wAB wBC wAC a b =
countZeroMod wAB wBC wAC p := by
apply Int.natCast_inj.mp
push_cast
simp_rw [pairCoefficient_cast hp hn]
exact count_eq hp hn wAB wBC wAC

/-- The selected counts in the exact original row-major order traversed by native code.
Out-of-range entries are zero, so empty input requires no arbitrary coordinate witness. -/
@[expose] def rowMajorCoefficient {n : ℕ} (p k : ℕ)
(wAB wBC wAC : Fin n → Fin n → ℤ) (i : ℕ) : ℕ :=
if h : i < n * n then
let q := finProdFinEquiv.symm (⟨i, h⟩ : Fin (n * n))
pairCoefficient p k wAB wBC wAC q.1 q.2
else 0

/-- The real row-major coefficient bound supplies the native prefix-accumulator admission. -/
theorem rowMajorCoefficient_le {n p k i : ℕ} (hp : p ≠ 0) (hn : n ≤ 2 ^ k)
(wAB wBC wAC : Fin n → Fin n → ℤ) :
rowMajorCoefficient p k wAB wBC wAC i ≤ n := by
unfold rowMajorCoefficient
split_ifs
· exact pairCoefficient_le hp hn wAB wBC wAC _ _
· omega

/-- Summation in the actual native scan order preserves the existing modular count. -/
theorem sum_rowMajorCoefficient {n p k : ℕ} (hp : p ≠ 0) (hn : n ≤ 2 ^ k)
(wAB wBC wAC : Fin n → Fin n → ℤ) :
∑ i ∈ Finset.range (n * n), rowMajorCoefficient p k wAB wBC wAC i =
countZeroMod wAB wBC wAC p := by
rw [Finset.sum_range]
simp only [rowMajorCoefficient, Fin.isLt, dite_true]
rw [← Equiv.sum_comp (finProdFinEquiv : Fin n × Fin n ≃ Fin (n * n))]
rw [Fintype.sum_prod_type]
change (∑ a : Fin n, ∑ b : Fin n, pairCoefficient p k wAB wBC wAC
(finProdFinEquiv.symm (finProdFinEquiv (a, b))).1
(finProdFinEquiv.symm (finProdFinEquiv (a, b))).2) = _
simpa only [Equiv.symm_apply_apply] using sum_pairCoefficient hp hn wAB wBC wAC

end Cslib.Algorithms.ExactTriangle.CountPrime
Loading
Loading