YAML Metadata Warning:empty or missing yaml metadata in repo card
Check out the documentation for more information.
Polynomial Neural Networks for List Sorting (pnn-sort)
Status: Stage 4A Complete (Primary
PolySortNet+ Analytical CKKS Controls) β Stage 4B Running (2026-11-25). Highlight: 6-parameter strictly purePolySortNet-Shared (d=5)reaches0.0079MAE on $n=8$ and generalizes zero-shot $16\times$ to $n=128$ (0.0200MAE, $\tau=0.9978$); 36-parameterPolySortNet-StageAdaptive (d=5)reaches0.0072MAE ($n=8$, Mono95.92%) and0.0097MAE ($n=16$) β $3.85\times$ lower MAE than Cheon/Hong/Mazzone mixed $f_3 \circ g_3$. See Stage 4A Report.
Author: Libor "Burny" Burian
Primary Reports: Literature Review Β· SOTA Review Β· Preregistration (Pre-Results) Β· Planned Run Matrix Β· Live Progress
Documentation: Architecture Β· PNN vs. Classic NN Math & Worked Comparison Β· Methodology
What Is This Project?
In Plain Language (Layman's Summary)
Computers usually sort a list of numbers like [0.8, -0.3, 0.1, -0.9] using if a > b: swap(a, b) decisions. Standard neural networks approximate decisions using non-linear switches like ReLU or sigmoid. Can a neural network learn to sort a list using only addition and multiplication β a pure mathematical polynomial β with zero if statements, zero comparisons, zero divisions, and zero standard activation functions?
It turns out this is surprisingly subtle: exact sorting has sharp corners whenever two numbers cross (max(a, b) = (a + b + |a - b|) / 2), whereas polynomials are infinitely smooth curves. A single "flat" polynomial struggles badly unless its degree is huge. However, stacking simple low-degree polynomials inside a sorting-network structure creates an exponentially high-degree polynomial using just a handful of multiplications β letting a strictly pure polynomial neural network sort lists accurately, conserve the exact sum of the list, work automatically on shifted numbers, and even generalize zero-shot to lists $16\times$ longer than it ever saw during training. At the same time, pure polynomials have a mathematically guaranteed Achilles' heel: if input numbers grow too large outside the training range, any degree $>1$ polynomial must eventually blow up. This project builds, trains, tests, and visualizes both the breakthroughs and the exact failure boundaries.
In Technical Terms (Expert Summary)
We conduct a preregistered, statistically rigorous empirical and theoretical investigation of strictly pure Polynomial Neural Networks (PNNs) $f_\theta : [-1, 1]^n \to \mathbb{R}^n$ (verified via automated PyTorch FX graph auditing to contain exclusively affine maps, additions, and multiplications) trained to approximate the order-statistics map $S(x) = (x_{(1)}, \dots, x_{(n)})$. Our study bridges three previously disconnected literatures:
- Deep Polynomial Neural Networks: $\Pi$-Nets (CCP/NCP/NCP-Skip/ProdPoly; Chrysos et al., CVPR 2020 / IEEE TPAMI 2021) and polynomial-activation MLPs (Kileel et al., NeurIPS 2019).
- Symmetric Set Networks: DeepSets (Zaheer et al., NeurIPS 2017) and latent-dimension bottlenecks (Wagstaff et al., ICML 2019 / JMLR 2022).
- Differentiable & Homomorphic Polynomial Sorting: Differentiable Sorting Networks (Petersen et al., ICML 2021; ICLR 2022) and CKKS composite polynomial sorting (Cheon et al., ASIACRYPT 2020; Lee et al., IEEE TDSC 2022; Mazzone et al., USENIX Security 2025).
Novelty & Key Scientific Questions
- Fixed-Point Odd Chebyshev Composite CAS Parameterization: $h_k(u) = u + u(1 - u^2)\sum_{j=0}^{m-1} c_{k,j} T_{2j}(u)$ mathematically preserves $h_k(0)=0, h_k(\pm 1)=\pm 1$, odd symmetry, exact sum conservation, exact shift equivariance, and range boundedness on $[-1, 1]$, while strictly subsuming Cheon et al.'s analytical $f_1, f_2, f_3$ polynomials.
- Data-Trained vs. Analytical Minimax at Iso-Depth: Tests whether gradient-trained shared and stage-adaptive
PolySortNetmodels surpass zero-training analytical Cheon/Remez CKKS sorting networks at identical multiplicative depth and degree by optimizing value-weighted sorting error ($|\Delta||1-s(|\Delta|)|$) rather than unweighted sign error ($|1-s(u)|$). - Swap-Network vs. Constant-Depth All-to-All PNNs: Benchmarks Bitonic/Odd-Even
PolySortNetagainst a trainable Mazzone-inspired constant-depthPolyPairwiseRankPNN (with exact quadratic tie-correction $E = 4C(1-C)$),DeepSetsPoly, unstructuredPiNet-NCPSkip,PolyMLP, and non-polynomial baselines (DiffSort,ReLU-MLP,SetTransformer).
Architecture & Experimental Overview
flowchart LR
X["Unsorted List x in [-1,1]^n"] --> P1["PolySortNet (Shared & Stage-Adaptive)\nBitonic/Odd-Even + Fixed-Point Chebyshev CAS"]
X --> P2["PolyPairwiseRank\nConstant-Depth All-Pairs + Tie Offset E=4C(1-C)"]
X --> P3["DeepSetsPoly / PiNet-NCPSkip / PolyMLP\nSymmetric & Unstructured Pure PNNs"]
X --> A1["Analytical CKKS Controls (Zero Training)\nCheon f1/f2 & Lee Remez Minimax"]
X --> B1["Non-Poly Baselines & Controls\nDiffSort (Cauchy/Logistic), ReLU-MLP, SetTransf, Linear"]
P1 --> Audit["PyTorch FX Purity Audit\n(0 non-poly ops)"]
P2 --> Audit
P3 --> Audit
A1 --> Audit
Audit --> Eval["Held-Out Test + 10 OOD Stress Suites\n(Shift, Scale Cliff, Near-Ties, Duplicates, Zero-Shot n=4..128)"]
B1 --> Eval
Planned Run Matrix Summary
Full specifications are locked in reports/planned-runs.md and reports/preregistration.md.
| Category | Models | Pure Poly? | Zero-Shot Length? | Status |
|---|---|---|---|---|
| Main PNNs | PolySortNet-Shared ($d=3, 5$), PolySortNet-StageAdaptive ($d=3, 5$), PolySortNet-LearnedWire, PolyPairwiseRank, DeepSetsPoly, PiNet-NCPSkip, PolyMLP |
Yes | Shared & Pairwise: Yes | Planned (Stages 4Aβ4B) |
| Analytical / Controls | AnalyticalCheonSort ($f_1, f_2$), AnalyticalRemezSort, LinearControl, IdentityControl, RandomInitControl, ShuffledTargetControl |
Yes | Analytical & Id: Yes | Planned (Stages 4A, 4C) |
| Non-Poly Baselines | DiffSort-Logistic, DiffSort-Cauchy, ReLU-MLP, SetTransformer |
No | DiffSort & SetTransf: Yes | Planned (Stage 4C) |
| Causal Ablations | Parameterization (4), Iso-Degree Depth (4), Init (3), Wiring + Random-Wire Control (4), Loss (4), Scale-Norm Wrapper (2) | Mixed (A6 explicit) | β | Planned (Stage 4D) |
| Statistical Rigor | 5 seeds (42, 123, 456, 789, 1024) across 10 core models ($n=8, 16$) + LR/WD/batch/float64 sweeps |
β | β | Planned (Stage 4E) |
Installation & Setup
Requires Python 3.12+ and uv. Tested on Windows 11 with NVIDIA GeForce RTX 5070 Laptop GPU (torch 2.11.0+cu128).
git clone https://github.com/BurnyCoder/polynomial-neural-network-sort-list.git
cd polynomial-neural-network-sort-list
uv sync --python 3.12
uv run pytest -v
Running Experiments & Live Accuracy Dashboard
# Run a single experiment (FX purity audit -> resumable training -> ID/OOD/float64/zero-shot eval)
uv run python -m pnn_sort.pipeline --run-id main_polysort_shared_n8_s42 --model polysort_shared --n 8 --seed 42
# Run an entire preregistered stage with the real-time web accuracy dashboard active
uv run python -m pnn_sort.experiments_runner --stage 4a_main --dashboard-port 8765
# Or run the live training dashboard standalone at http://127.0.0.1:8765
uv run python -m pnn_sort.dashboard.server --port 8765
Data Flow When Running pnn-sort
- Pure-Polynomial Audit (
src/pnn_sort/audit.py): Traces the model viatorch.fx.symbolic_traceand rejects any non-polynomial op before a single gradient step executes. - Seed-Isolated Data Generation (
src/pnn_sort/data/): Generates deterministic SHA-256 keyedtrain($200\text{k}$),val($10\text{k}$),test($10\text{k}$), and 10 held-out OOD stress suites ($2\text{k}$ each) with zero overlap. - Resumable Training + Live Telemetry (
src/pnn_sort/train/,dashboard/): Runs AdamW + cosine schedule with gradient clipping, atomic per-epoch checkpointing (full RNG state resume), and live JSONL updates rendered athttp://127.0.0.1:8765. - Statistical Evaluation (
src/pnn_sort/eval/): Evaluates Value MAE, RMSE, $L_\infty$, Monotonicity Rate, Pairwise Order Accuracy / Kendall's $\tau$, Multiset $W_1$, Sum Conservation Error, Float64 precision verification, Scale Stability Radius $R_{\text{stable}}$, and Zero-Shot length generalization ($n = 4\text{--}128$), saving per-list arrays for 10,000-resample paired bootstrap CIs and Wilcoxon signed-rank tests.
Technologies Used
- Deep Learning & Symbolic Verification: PyTorch (
cu128), PyTorch FX symbolic tracing, SymPy - Numerical & Statistical Analysis: NumPy, SciPy (Remez/minimax, Wilcoxon, Kendall's $\tau$), Pandas
- Visualization & Publishing: Matplotlib, Seaborn, Typst/LaTeX (
paper.pdf), GitHub Pages (client-side interactive pure-polynomial sorter), Hugging Face Hub
Roadmap (To-Do)
- Phase 1: Full primary-source literature & state-of-the-art review
- Phase 2: Preregistration, run matrix, documentation & pre-results GitHub commit
- Phase 3: Modular
src/pnn_sort/codebase, FX purity tests, real-time training dashboard & Adversarial Review #1 - Phase 4: Staged training, controls, baselines, 6 ablation suites, 5-seed sweeps & incremental GitHub/HF sync
- Phase 5: Publication figures, interactive GitHub Pages explorer,
reports/paper.pdf& Final Triple-Check