-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquickstart.py
More file actions
executable file
·58 lines (44 loc) · 1.7 KB
/
quickstart.py
File metadata and controls
executable file
·58 lines (44 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/env python3
"""
Quick start example for Constraint Theory Python bindings.
Run with: python examples/quickstart.py
Requirements:
pip install constraint-theory
"""
from constraint_theory import PythagoreanManifold, generate_triples, snap
def main():
print("=" * 60)
print("Constraint Theory - Python Quick Start")
print("=" * 60)
# Create a manifold
print("\n1. Creating Pythagorean Manifold...")
manifold = PythagoreanManifold(density=200)
print(f" Manifold has {manifold.state_count} valid states")
# Snap some vectors
print("\n2. Snapping vectors to Pythagorean triples...")
test_vectors = [
(0.6, 0.8), # Exact: 3-4-5 triangle
(0.8, 0.6), # Same, swapped
(0.707, 0.707), # ~45 degrees
(0.1, 0.995), # Near vertical
]
for x, y in test_vectors:
sx, sy, noise = manifold.snap(x, y)
print(f" ({x:.3f}, {y:.3f}) -> ({sx:.4f}, {sy:.4f}), noise={noise:.6f}")
# Batch processing
print("\n3. Batch processing (SIMD optimized)...")
vectors = [[0.6, 0.8], [0.8, 0.6], [0.1, 0.99], [0.707, 0.707]]
results = manifold.snap_batch(vectors)
for i, (sx, sy, noise) in enumerate(results):
print(f" [{i}] ({vectors[i][0]:.3f}, {vectors[i][1]:.3f}) -> ({sx:.4f}, {sy:.4f})")
# Generate triples
print("\n4. Generating Pythagorean triples (c <= 30)...")
triples = generate_triples(30)
for a, b, c in triples[:5]:
print(f" {a}² + {b}² = {c}² (→ {a}² + {b}² = {a*a + b*b})")
print(f" ... and {len(triples) - 5} more")
print("\n" + "=" * 60)
print("Done! 🎉")
print("=" * 60)
if __name__ == "__main__":
main()