Constraint Theory
A Rust library that snaps continuous vectors to exact Pythagorean coordinates via O(log n) KD-tree lookup.
What It Does
Constraint Theory builds a discrete manifold of Pythagorean triples (integer-ratio points on the unit circle), indexes them in a KD-tree, and provides a "snap" operator that maps any continuous 2D vector to its nearest exact geometric state.
Key property: The output is always an exact rational coordinate — no floating-point drift. The constraint predicate a² + b² = c² is satisfied by construction, not validated after the fact.
Quick Start
use ;
// Build manifold: 200 density → ~1000 Pythagorean states
let manifold = new;
// Snap a continuous vector to its nearest exact state
let = snap;
// (0.6, 0.8) = (3/5, 4/5) — an exact Pythagorean triple
assert!;
Batch Processing (SIMD)
use PythagoreanManifold;
let manifold = new;
let vectors = vec!;
let results = manifold.snap_batch_simd;
for in results
Installation
Add to your Cargo.toml:
[]
= "0.1"
Performance
| Operation | Time | Complexity |
|---|---|---|
| Manifold build | ~50 μs | O(n log n) |
| Single snap (KD-tree) | ~100 ns | O(log n) |
| Batch snap (SIMD) | ~74 ns/op | O(log n) |
Limitations
- 2D only — Higher dimensions are an open research problem
- ~1000 states at default density — finite resolution
- Research-grade — Core algorithms work but not battle-tested in production
Ecosystem
- constraint-theory-python — Python bindings via PyO3
- constraint-theory-web — Interactive demos and visualizations
- constraint-theory-research — Mathematical foundations and papers
Documentation
- Tutorial — Step-by-step guide
- Benchmarks — Performance methodology
- API Docs — Full API reference
Contributing
See CONTRIBUTING.md for build instructions, code style, and PR process.
Areas where contributions are especially valuable:
- Higher-dimensional generalizations (3D Pythagorean quadruples, nD)
- GPU implementations (CUDA, WebGPU)
- Real-world use cases and benchmarks
Citation
License
MIT — see LICENSE.