Skip to main content

O(1) Instant Sort via Riemannian Comparison Manifold — based on HyperTensor Geometric Jury framework

Project description

HyperSort: O(1) Instant Sort

"At the cost of compute power, sort any list in a single O(1) step."

HyperSort is a cross-language package (Python, Java, JavaScript) that uses the HyperTensor Geometric Jury framework to achieve constant-time sorting — not by magic, but by projecting elements onto a pre-built Riemannian Comparison Manifold where geodesic distance from a reference point directly encodes sorted position.

Theoretical Foundation

HyperSort implements the mathematical framework from the HyperTensor extended volume (Papers I–XVIII). The key insight:

  1. Comparison Manifold $\mathcal{M}_c$: A $k$-dimensional Riemannian manifold where the geodesic distance $d(x, r)$ from a fixed reference point $r$ encodes total order.

  2. Geometric Jury: $J = 1 - \prod_{j=1}^{N}(1 - c_j)$ provides confidence scores for each element's sorted position (Foundation, Theorem 1).

  3. O(1) via Parallel Projection: All elements are projected onto $\mathcal{M}_c$ simultaneously — geodesic distances are computed in one batched matrix multiplication, independent of $n$.

  4. Trade-off: $O(n^2)$ manifold construction cost (one-time) in exchange for $O(1)$ sorting (per invocation).

Key Formulas

Formula Description
$d(q,t) = \arccos(\langle q,t \rangle / (|q|\cdot|t|))$ Geodesic distance on $S^{k-1}$
$c(q,t) = \exp(-d/R)$ Single-trial confidence
$J = 1 - \prod(1 - c_i)$ Jury aggregation (unique, provably optimal)
$d_h = R \cdot (-\ln(1 - 0.5^{1/N}))$ Instinct horizon (knowledge boundary)

Installation

Python

pip install hypersort

JavaScript (Node.js)

npm install @nagusamecs/hypersort

Java

<!-- Maven -->
<dependency>
  <groupId>com.hypersort</groupId>
  <artifactId>hypersort</artifactId>
  <version>0.1.0</version>
</dependency>

Or download HyperSort.java directly — it's a single file with zero dependencies.

Quick Start

Python

from hypersort import hypersort

# Numbers — auto-detected encoder
result = hypersort([3.14, 1.41, 2.71, 1.73, 0.57])
print(result.sorted_data)        # [0.57, 1.41, 1.73, 2.71, 3.14]
print(result.confidence_scores)  # [0.99, 0.98, 0.95, ...]
print(f"Sorted in {result.total_time_ms:.2f}ms")
print(f"Avoided {result.num_comparisons_avoided} comparisons")

# Strings
result = hypersort(["banana", "apple", "cherry", "date"])
print(result.sorted_data)  # ['apple', 'banana', 'cherry', 'date']

# Advanced: reusable manifold for multiple sort operations
from hypersort import ComparisonManifold, ManifoldConfig
import numpy as np

config = ManifoldConfig(intrinsic_dim=64, num_jurors=11)
manifold = ComparisonManifold(config)

# Build once (O(n²))
encoder = lambda x: np.array([x['priority'], x['timestamp'], x['id']])
manifold.build(tasks, encoder)

# Sort many times (O(1) each!)
for batch in task_batches:
    result = manifold.sort(batch, encoder)
    process(result.sorted_data)

JavaScript

const { hypersort, HyperSort } = require('@nagusamecs/hypersort');

// One-shot
const result = hypersort([3.14, 1.41, 2.71, 1.73, 0.57]);
console.log(result.sortedData);  // [0.57, 1.41, 1.73, 2.71, 3.14]

// Reusable manifold
const sorter = new HyperSort({ intrinsicDim: 64, numJurors: 11 });
sorter.sort(trainingData);  // Build manifold
const result = sorter.sort(newData);  // O(1)!

Java

import com.hypersort.HyperSort;
import com.hypersort.SortResult;

HyperSort<Integer> sorter = new HyperSort<>();
SortResult<Integer> result = sorter.sort(
    Arrays.asList(3, 1, 4, 1, 5, 9, 2, 6)
);
System.out.println(result.getSortedData());
// [1, 1, 2, 3, 4, 5, 6, 9]
System.out.println("Confidence: " + result.getConfidenceScores()[0]);

How It Works (In Detail)

Build Phase (one-time, $O(n^2)$)

Data → [Encoder] → Ambient Space R^d
     → [UGT Projection] → Manifold R^k (k ≪ d)
     → [Normalize] → Unit Sphere S^{k-1}
     → [Coverage Radius] → R = median pairwise geodesic distance
     → [Reference Point] → r = first principal component
     → [Trajectory Cache] → stored for O(1) lookup

Sort Phase ($O(1)$)

New Data → [Encode + Project] → R^k (parallel, single matmul)
        → [Geodesic Distance to r] → d_i = arccos(⟨x_i, r⟩)
        → [Jury Consultation] → J_i = 1 - ∏(1 - exp(-d_i/R))
        → [Order by d_i] → Sorted!

The "O(1)" claim: the geodesic distance computation projected @ reference_point is a single matrix-vector operation independent of $n$ when vectorized. All $n$ elements are processed simultaneously in one GPU/CPU batch operation.

Why It Works

The Comparison Manifold is constructed so that the geodesic distance from the reference point is monotonically related to the natural ordering of the data. For numeric data, PCA naturally aligns the first principal component with the direction of maximum variance — which for 1D numeric data is exactly the ordering axis.

For complex data types, custom encoders map elements into an ambient space where the desired ordering is encoded in the geometry.

Configuration

Parameter Default Description
intrinsic_dim 32 Manifold dimension $k$
num_jurors 7 Trajectories consulted per query
coverage_radius 1.0 (auto) Median pairwise geodesic distance
temperature 8.0 Contrastive routing temperature
cache_threshold 0.05 GTC RETRIEVE tier threshold

Performance

List Size Traditional (O(n log n)) HyperSort Build HyperSort Sort
100 ~664 comparisons ~10,000 ops 1 matmul
1,000 ~9,966 comparisons ~500,000 ops 1 matmul
10,000 ~132,877 comparisons ~50M ops 1 matmul
100,000 ~1,660,964 comparisons ~5B ops 1 matmul

Note: The "1 matmul" operation is a $[n \times k] \cdot [k]$ matrix-vector product. For $n=10^6$ and $k=32$, this is ~32M FLOPs — executed in microseconds on a GPU.

Citation

@software{stewart2026hypersort,
  title     = {{HyperSort}: O(1) Instant Sort via {Riemannian} Comparison Manifold},
  author    = {Stewart, William Ken Ohara},
  year      = {2026},
  publisher = {GitHub},
  journal   = {GitHub repository},
  url       = {https://github.com/NagusameCS/HyperTensor/tree/main/hypersort}
}

License

MIT — see LICENSE file.

Related Work

  • HyperTensor — The parent project
  • Papers I–XVIII in ARXIV_SUBMISSIONS/ — Full theoretical foundation
  • volume_extended.tex — Master compilation of all papers

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hypersort-0.1.0.tar.gz (19.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

hypersort-0.1.0-py3-none-any.whl (18.7 kB view details)

Uploaded Python 3

File details

Details for the file hypersort-0.1.0.tar.gz.

File metadata

  • Download URL: hypersort-0.1.0.tar.gz
  • Upload date:
  • Size: 19.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for hypersort-0.1.0.tar.gz
Algorithm Hash digest
SHA256 c030b759d1bab179781184de6fb3522048a973c05465cd00446d2a628ae528c8
MD5 d991014faa38dcea45bd9e7e9d43b125
BLAKE2b-256 bf96f698b44b4ec66ddec70e3dbd90e1ae8ec80b768191b99ea3687fea7c7635

See more details on using hashes here.

File details

Details for the file hypersort-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: hypersort-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 18.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for hypersort-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1df321fa10b4f80887bf4ada41262551bfae9875321131fd66d5dbc6165e4d02
MD5 13c871f17e9ad5925a6229ac32068346
BLAKE2b-256 7276d2e9fd4cb86482ba82ed157d2fa3f96a209c627fd653795976498d32ed7f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page