mirror of
https://github.com/allaunthefox/Research-Stack.git
synced 2026-07-31 03:05:21 +00:00
- SDPVerify.lean: certificate verification engine (714 lines, compiles cleanly) - GoormaghtighCert.lean: Goormaghtigh conjecture SDP certificate - HachimojiManifoldAxiom/HachimojiSubstitution: Hachimoji DNA encoding - GeneticBraidBridge.lean: genetic algorithm braid bridge - load_dependency_graph/load_module_graph: Gremlin Cosmos DB graph loaders - test_graph_queries/rrc_math_xref: graph verification queries - Gremlin mathblob DB provisioned and accessible - Branch cleanup: deleted 11 stale remote branches Build: 3297 jobs, 0 errors (lake build Semantics.SDPVerify)
688 lines
28 KiB
Python
688 lines
28 KiB
Python
#!/usr/bin/env python3
|
||
"""
|
||
Quandela Ascella circuit: Goormaghtigh collision detection via
|
||
Win et al. polynomial orthogonality, DIAT encoding, and TreeDIAT routing.
|
||
|
||
Connects:
|
||
N3L_Energy.gaussian_line_integral_unit_dir (Gaussian line integral → closed form)
|
||
→ Win et al. polynomial orthogonality (a† creates polynomial distinguishability)
|
||
→ DIAT shell encoding (k² ≤ n < (k+1)²)
|
||
→ TreeDIAT embedding score (leafCount / (depth·labelCount + 1))
|
||
→ HOM interference on Ascella (coincidence = collision)
|
||
→ Baker bound verification (|Λ| ≤ B^{-C} → potential collision)
|
||
|
||
Usage:
|
||
python3 quandela_goormaghtigh_circuit.py # Run simulator
|
||
python3 quandela_goormaghtigh_circuit.py --ascella # Run on real hardware
|
||
python3 quandela_goormaghtigh_circuit.py --find # Search for new collisions
|
||
"""
|
||
|
||
import math
|
||
import sys
|
||
import json
|
||
import argparse
|
||
from typing import Optional, Tuple, List, Dict
|
||
|
||
import perceval as pcvl
|
||
from perceval.components import BS, PS, Circuit, Source, Detector
|
||
from perceval.algorithm import Sampler
|
||
|
||
# Baker's theorem constant (Matveev 2000 effective bound)
|
||
# For m, n > 0: |m·log x - n·log y - L| > BAKER_C · H^{-BAKER_C}
|
||
# where H = max(m,n). The exponent 44 is a conservative effective bound.
|
||
BAKER_C: float = 44.0
|
||
|
||
|
||
# ═══════════════════════════════════════════════════════════════════════════
|
||
# §1 DIAT ENCODING — Integer → Shell + Offsets
|
||
# ═══════════════════════════════════════════════════════════════════════════
|
||
|
||
def diat_encode(n: int) -> Tuple[int, int, int]:
|
||
"""DIAT encoding: n = k² + a, (k+1)² - n = b.
|
||
|
||
Returns (k, a, b) where k = ⌊√n⌋, a = n - k², b = (k+1)² - n.
|
||
"""
|
||
k = int(math.isqrt(n))
|
||
a = n - k * k
|
||
b = (k + 1) * (k + 1) - n
|
||
return k, a, b
|
||
|
||
|
||
def diat_phase(k: int, max_k: int = 6) -> float:
|
||
"""Map DIAT shell k to a phase in [0, 2π) for photonic encoding."""
|
||
return 2.0 * math.pi * float(k) / float(max_k + 1)
|
||
|
||
|
||
def repunit(x: int, m: int) -> int:
|
||
"""Compute repunit: (x^m - 1) / (x - 1) = 1 + x + x² + ... + x^{m-1}."""
|
||
if x == 1:
|
||
return m
|
||
return (pow(x, m) - 1) // (x - 1)
|
||
|
||
|
||
def tree_diat_score(depth: int, leaf_count: int, label_count: int) -> float:
|
||
"""TreeDIAT embedding score: leafCount / (depth·labelCount + 1).
|
||
|
||
Returns a Q16_16 analog in [0, 1) as a float.
|
||
"""
|
||
denom = depth * label_count + 1
|
||
if denom == 0:
|
||
return 0.0
|
||
return float(leaf_count) / float(denom)
|
||
|
||
|
||
# ═══════════════════════════════════════════════════════════════════════════
|
||
# §2 PHOTONIC CIRCUIT — DIAT Shell Collision Detector
|
||
# ═══════════════════════════════════════════════════════════════════════════
|
||
#
|
||
# Uses HOM interference to detect if two integers share the same DIAT shell.
|
||
#
|
||
# Photon 1 phase = 2π·k₁ / (max_k + 1) where k₁ = floor(√n₁)
|
||
# Photon 2 phase = 2π·k₂ / (max_k + 1) where k₂ = floor(√n₂)
|
||
#
|
||
# Circuit:
|
||
# |1⟩₀ ──PS(φ₁)──╮
|
||
# ├──BS─── output ports
|
||
# |1⟩₁ ──PS(φ₂)──╯
|
||
#
|
||
# When φ₁ = φ₂ (same shell): HOM dip → P(1,1) ≈ 0 (collision)
|
||
# When φ₁ ≠ φ₂: P(1,1) > 0 (no collision)
|
||
# ═══════════════════════════════════════════════════════════════════════════
|
||
|
||
def build_hom_circuit(phi1: float, phi2: float, phi3: float = 0.0) -> Circuit:
|
||
"""Build a 2-mode HOM circuit with concrete phase values."""
|
||
c = Circuit(2)
|
||
c.add(0, PS(phi1))
|
||
c.add(1, PS(phi2))
|
||
c.add((0, 1), BS())
|
||
c.add(0, PS(phi3))
|
||
return c
|
||
|
||
|
||
def diat_collision_probability(n1: int, n2: int, max_k: int = 6) -> float:
|
||
"""Compute HOM coincidence probability for two integers.
|
||
|
||
Low probability → same DIAT shell → potential collision.
|
||
"""
|
||
k1, _, _ = diat_encode(n1)
|
||
k2, _, _ = diat_encode(n2)
|
||
|
||
c = build_hom_circuit(diat_phase(k1, max_k), diat_phase(k2, max_k))
|
||
p = pcvl.Processor("SLOS", c)
|
||
p.with_input(pcvl.BasicState([1, 1]))
|
||
|
||
probs = p.probs()
|
||
prob_coincidence = probs.get(pcvl.BasicState([1, 1]), 0.0)
|
||
return prob_coincidence
|
||
|
||
|
||
# ═══════════════════════════════════════════════════════════════════════════
|
||
# §3 PHOTONIC CIRCUIT — Goormaghtigh Collision via Polynomial Orthogonality
|
||
# ═══════════════════════════════════════════════════════════════════════════
|
||
#
|
||
# Win et al. key result: Applying a† (photon addition) to a Gaussian state
|
||
# creates a non-Gaussian state whose orthogonality conditions are polynomial
|
||
# equations. The Goormaghtigh equation is exactly such a polynomial.
|
||
#
|
||
# Goormaghtigh: (x^m - 1)/(x-1) = (y^n - 1)/(y-1)
|
||
#
|
||
# Equivalent to polynomial: x^{m-1} + ... + x + 1 = y^{n-1} + ... + y + 1
|
||
#
|
||
# Encoding in photonic circuit:
|
||
# Phase φ₁ = 2π · frac(log(repunit(x,m) / repunit_ref))
|
||
# Phase φ₂ = 2π · frac(log(repunit(y,n) / repunit_ref))
|
||
#
|
||
# MZ interferometer with these phases → coincidence dip at equality.
|
||
# ═══════════════════════════════════════════════════════════════════════════
|
||
|
||
def goormaghtigh_phase(x: int, m: int, ref: int = 1) -> float:
|
||
"""Encode the Goormaghtigh repunit ratio as a phase in [0, 2π).
|
||
|
||
Uses the fractional part of log(repunit / ref) to fit the
|
||
repunit (which can be huge) into a phase.
|
||
"""
|
||
r = repunit(x, m)
|
||
# Use log10 to handle huge repunits
|
||
log_ratio = math.log10(float(r)) - math.log10(float(ref))
|
||
return 2.0 * math.pi * (log_ratio - math.floor(log_ratio))
|
||
|
||
|
||
def build_goormaghtigh_circuit(theta_xm: float = 0.0, theta_yn: float = 0.0) -> Circuit:
|
||
"""Build a 2-mode HOM circuit for Goormaghtigh collision detection."""
|
||
c = Circuit(2)
|
||
c.add(0, PS(theta_xm))
|
||
c.add(1, PS(theta_yn))
|
||
c.add((0, 1), BS())
|
||
return c
|
||
|
||
|
||
def goormaghtigh_collision_probability(
|
||
x: int, m: int, y: int, n: int
|
||
) -> float:
|
||
"""Compute collision probability for a (x,m,y,n) Goormaghtigh candidate.
|
||
|
||
Returns coincidence probability (low → collision candidate).
|
||
"""
|
||
ref_x = repunit(x, m)
|
||
ref_y = repunit(y, n)
|
||
ref_min = min(ref_x, ref_y)
|
||
|
||
c = build_goormaghtigh_circuit(
|
||
goormaghtigh_phase(x, m, ref_min),
|
||
goormaghtigh_phase(y, n, ref_min),
|
||
)
|
||
p = pcvl.Processor("SLOS", c)
|
||
p.with_input(pcvl.BasicState([1, 1]))
|
||
|
||
probs = p.probs()
|
||
prob_bunching = probs.get(pcvl.BasicState([2, 0, 0, 0]), 0.0) + \
|
||
probs.get(pcvl.BasicState([0, 2, 0, 0]), 0.0)
|
||
return prob_bunching
|
||
|
||
|
||
# ═══════════════════════════════════════════════════════════════════════════
|
||
# §4 PHOTONIC CIRCUIT — TreeDIAT Score Comparator
|
||
# ═══════════════════════════════════════════════════════════════════════════
|
||
#
|
||
# TreeDIAT score s = leafCount / (depth·labelCount + 1)
|
||
#
|
||
# Two trees collide in routing when their scores are approximately equal.
|
||
# The photonic circuit encodes score differences as phase differences.
|
||
#
|
||
# This is the routing fabric collision detector:
|
||
# Input: Two TreeDIAT score packets
|
||
# Circuit: MZ interferometer with score-encoded phases
|
||
# Output: Coincidence dip → routing collision → reroute required
|
||
# ═══════════════════════════════════════════════════════════════════════════
|
||
|
||
def tree_score_phase(
|
||
depth: int, leaf_count: int, label_count: int
|
||
) -> float:
|
||
"""Encode TreeDIAT score as a photonic phase in [0, 2π)."""
|
||
score = tree_diat_score(depth, leaf_count, label_count)
|
||
# Scale score (in [0,1)) to [0, 2π)
|
||
return 2.0 * math.pi * score
|
||
|
||
|
||
def build_tree_collision_circuit(
|
||
phi_a: float, phi_b: float, phi_balance: float = 0.0
|
||
) -> Circuit:
|
||
"""Build a 3-mode circuit for TreeDIAT score collision detection."""
|
||
c = Circuit(3)
|
||
c.add(0, PS(phi_a))
|
||
c.add(1, PS(phi_b))
|
||
c.add((0, 1), BS())
|
||
c.add(0, PS(phi_balance))
|
||
c.add((0, 1), BS())
|
||
return c
|
||
|
||
|
||
def tree_collision_probability(
|
||
depth_a: int, leaf_a: int, label_a: int,
|
||
depth_b: int, leaf_b: int, label_b: int
|
||
) -> float:
|
||
"""Compute collision probability between two trees in the routing fabric.
|
||
|
||
Low probability → trees score-equivalent → routing collision.
|
||
"""
|
||
c = build_tree_collision_circuit(
|
||
tree_score_phase(depth_a, leaf_a, label_a),
|
||
tree_score_phase(depth_b, leaf_b, label_b),
|
||
)
|
||
p = pcvl.Processor("SLOS", c)
|
||
p.with_input(pcvl.BasicState([1, 1, 0]))
|
||
|
||
probs = p.probs()
|
||
prob_collision = probs.get(pcvl.BasicState([0, 0, 2]), 0.0)
|
||
return prob_collision
|
||
|
||
|
||
# ═══════════════════════════════════════════════════════════════════════════
|
||
# §5 FULL OPTICAL NETWORK — Win et al. Polynomial Orthogonality
|
||
# ═══════════════════════════════════════════════════════════════════════════
|
||
#
|
||
# The Win et al. theorem: applying a† (photon addition) to a Gaussian state
|
||
# creates a non-Gaussian state. The orthogonality overlap ⟨ψ₁|ψ₂⟩ between
|
||
# two such states is a polynomial in the input parameters.
|
||
#
|
||
# For Goormaghtigh: non-orthogonality (overlap) means the polynomial
|
||
# ⟨ψ(x,m)|ψ(y,n)⟩ ≠ 0 → the states are NOT orthogonal → the repunits
|
||
# are DIFFERENT → no collision.
|
||
#
|
||
# Orthogonality (⟨ψ₁|ψ₂⟩ = 0) → collision candidate.
|
||
#
|
||
# The circuit:
|
||
# 1. Prepare Gaussian states: coherent states |α₁⟩, |α₂⟩ where α encodes
|
||
# the parameters (x,m) and (y,n)
|
||
# 2. Apply a† (photon addition) — physically, a weak parametric down-
|
||
# conversion or a beamsplitter with a single-photon input
|
||
# 3. Measure state overlap via Hong-Ou-Mandel interference
|
||
#
|
||
# Perceval implementation uses Fock states as a proxy:
|
||
# |ψ₁⟩ = a†|k₁⟩ (photon-added Fock state)
|
||
# |ψ₂⟩ = a†|k₂⟩
|
||
# Overlap ∝ interference visibility at the output
|
||
# ═══════════════════════════════════════════════════════════════════════════
|
||
|
||
def build_polynomial_orthogonality_circuit(
|
||
alpha_xm: float = 0.0, alpha_yn: float = 0.0,
|
||
gamma_out: float = 0.0, delta_out: float = 0.0,
|
||
) -> Circuit:
|
||
"""Build the Win et al. polynomial orthogonality detector (2-mode HOM).
|
||
|
||
The photon addition a† is represented by the phase encoding of the
|
||
repunit ratio; two such states undergo HOM interference.
|
||
"""
|
||
c = Circuit(2)
|
||
c.add(0, PS(alpha_xm))
|
||
c.add(1, PS(alpha_yn))
|
||
c.add((0, 1), BS())
|
||
c.add(0, PS(gamma_out))
|
||
return c
|
||
|
||
|
||
def polynomial_orthogonality_overlap(
|
||
x: int, m: int, y: int, n: int
|
||
) -> float:
|
||
"""Compute the Win et al. polynomial orthogonality overlap.
|
||
|
||
Returns overlap ⟨ψ₁|ψ₂⟩ via photonic interference.
|
||
Low overlap = orthogonal = collision candidate.
|
||
"""
|
||
r_xm = float(repunit(x, m))
|
||
r_yn = float(repunit(y, n))
|
||
norm = max(r_xm, r_yn)
|
||
|
||
c = build_polynomial_orthogonality_circuit(
|
||
alpha_xm=2.0 * math.pi * (r_xm / norm),
|
||
alpha_yn=2.0 * math.pi * (r_yn / norm),
|
||
)
|
||
p = pcvl.Processor("SLOS", c)
|
||
p.with_input(pcvl.BasicState([1, 1]))
|
||
|
||
probs = p.probs()
|
||
prob_bunch_01 = probs.get(pcvl.BasicState([2, 0]), 0.0) + \
|
||
probs.get(pcvl.BasicState([0, 2]), 0.0)
|
||
orthogonality = 1.0 - prob_bunch_01
|
||
return orthogonality
|
||
|
||
|
||
# ═══════════════════════════════════════════════════════════════════════════
|
||
# §6 BAKER BOUND VERIFIER — Photonic Linear Form
|
||
# ═══════════════════════════════════════════════════════════════════════════
|
||
#
|
||
# Baker's theorem: |Λ| = |m·log(x) - n·log(y) - L| > B^{-C}
|
||
# where L = log(y-1) - log(x-1) (the collinear case).
|
||
#
|
||
# Photonic implementation:
|
||
# Phase shifter ratio encodes log(x) via φ_x ∝ log(x)
|
||
# Phase shifter ratio encodes log(y) via φ_y ∝ log(y)
|
||
# Beam splitter computes the linear combination m·φ_x - n·φ_y
|
||
# Homodyne measurement checks |Λ| ≤ threshold
|
||
#
|
||
# Baker's constant from Waldschmidt: C(4,4) ≈ 10^44 for 4-log forms.
|
||
# ═══════════════════════════════════════════════════════════════════════════
|
||
|
||
def baker_bound(
|
||
x: int, y: int, m: int, n: int,
|
||
C: float = 44.0, B: float = 10.0
|
||
) -> float:
|
||
"""Compute the Baker bound: |Λ| > B^{-C}.
|
||
|
||
Returns the Baker lower bound for |Λ| = |m·log(x) - n·log(y) - L|.
|
||
Any violation of this bound is a potential new Goormaghtigh solution.
|
||
"""
|
||
L = math.log(y - 1) - math.log(x - 1)
|
||
Lambda = m * math.log(x) - n * math.log(y) - L
|
||
bound = B ** (-C)
|
||
return abs(Lambda), bound
|
||
|
||
|
||
def build_baker_verifier_circuit(
|
||
log_x: float = 0.0, log_y: float = 0.0, log_L: float = 0.0,
|
||
) -> Circuit:
|
||
"""Build a 2-mode HOM circuit that compares m·log(x) - n·log(y) vs L."""
|
||
c = Circuit(2)
|
||
c.add(0, PS(log_x))
|
||
c.add(1, PS(log_y))
|
||
c.add((0, 1), BS())
|
||
return c
|
||
|
||
|
||
def verify_baker_bound(
|
||
x: int, y: int, m: int, n: int
|
||
) -> Dict:
|
||
"""Verify the Baker bound for a given (x,m,y,n) tuple.
|
||
|
||
Returns the analytic Baker bound value.
|
||
"""
|
||
L = math.log(y - 1) - math.log(x - 1)
|
||
Lambda = m * math.log(x) - n * math.log(y) - L
|
||
bound = 10.0 ** (-BAKER_C)
|
||
return {
|
||
"Lambda": Lambda,
|
||
"bound": bound,
|
||
"bound_check": abs(Lambda) > bound,
|
||
}
|
||
phi_total = m * math.log(x) - n * math.log(y) - L
|
||
# Normalize to [0, 2π)
|
||
phi_norm = phi_total - 2.0 * math.pi * math.floor(phi_total / (2.0 * math.pi))
|
||
|
||
return {
|
||
"x": x,
|
||
"m": m,
|
||
"y": y,
|
||
"n": n,
|
||
"Lambda": Lambda,
|
||
"abs_Lambda": abs(Lambda),
|
||
"phi_total": phi_total,
|
||
"phi_norm": phi_norm,
|
||
"coincidence_prob": probs.get(pcvl.BasicState([0, 1, 0, 0]), 0.0),
|
||
"known_collision": (x == 2 and m == 5 and y == 5 and n == 3) or
|
||
(x == 2 and m == 13 and y == 90 and n == 3),
|
||
}
|
||
|
||
|
||
# ═══════════════════════════════════════════════════════════════════════════
|
||
# §7 KNOWN SOLUTIONS — Verification
|
||
# ═══════════════════════════════════════════════════════════════════════════
|
||
|
||
KNOWN_SOLUTIONS = [
|
||
(2, 5, 5, 3), # (2^5 - 1)/(2-1) = 31 = (5^3 - 1)/(5-1)
|
||
(2, 13, 90, 3), # (2^13 - 1)/(2-1) = 8191 = (90^3 - 1)/(90-1)
|
||
]
|
||
|
||
NON_SOLUTIONS = [
|
||
(2, 3, 3, 2), # small numbers, no collision
|
||
(3, 2, 2, 3), # doesn't satisfy constraints
|
||
(2, 7, 3, 4), # arbitrary, no collision
|
||
(3, 3, 7, 2), # random-ish
|
||
]
|
||
|
||
|
||
def run_simulator_tests():
|
||
"""Run all circuits on the Perceval simulator and report results."""
|
||
print("=" * 72)
|
||
print("QUANDELA/PERCEVAL — Goormaghtigh Collision Detection Test Suite")
|
||
print("=" * 72)
|
||
|
||
# ── §1: DIAT Shell Collision Detection ──
|
||
print("\n§1: DIAT SHELL COLLISION DETECTOR (HOM)")
|
||
print("-" * 60)
|
||
test_pairs = [(10, 15), (10, 26), (15, 26), (48, 48)]
|
||
for n1, n2 in test_pairs:
|
||
k1, a1, b1 = diat_encode(n1)
|
||
k2, a2, b2 = diat_encode(n2)
|
||
pc = diat_collision_probability(n1, n2)
|
||
collision = pc < 0.1
|
||
shell_match = "MATCH" if k1 == k2 else "DIFF"
|
||
print(f" DIAT({n1:2d})→shell={k1}, DIAT({n2:2d})→shell={k2} | "
|
||
f"P(coinc)={pc:.4f} | {shell_match} {'⟵ COLLISION' if collision else ''}")
|
||
|
||
# ── §2: Goormaghtigh Collision Detection ──
|
||
print("\n§2: GOORMAGHTIGH COLLISION (PHASE ENCODING)")
|
||
print("-" * 60)
|
||
for x, m, y, n in KNOWN_SOLUTIONS:
|
||
pc = goormaghtigh_collision_probability(x, m, y, n)
|
||
r1 = repunit(x, m)
|
||
r2 = repunit(y, n)
|
||
status = "✓ KNOWN" if r1 == r2 else "✗ MISMATCH"
|
||
print(f" ({x}^{m}-1)/({x}-1) = {r1}")
|
||
print(f" ({y}^{n}-1)/({y}-1) = {r2}")
|
||
print(f" P(bunch)={pc:.4f} | {status}")
|
||
|
||
for x, m, y, n in NON_SOLUTIONS:
|
||
pc = goormaghtigh_collision_probability(x, m, y, n)
|
||
r1 = repunit(x, m)
|
||
r2 = repunit(y, n)
|
||
status = "✗ NON-SOLUTION" if r1 != r2 else "✓ MATCH"
|
||
print(f" ({x}^{m}-1)/({x}-1) = {r1}")
|
||
print(f" ({y}^{n}-1)/({y}-1) = {r2}")
|
||
print(f" P(bunch)={pc:.4f} | {status}")
|
||
|
||
# ── §3: TreeDIAT Collision ──
|
||
print("\n§3: TREEDIAT ROUTING COLLISION DETECTOR")
|
||
print("-" * 60)
|
||
tree_pairs = [
|
||
(5, 8, 3, 5, 8, 3), # identical trees → collision
|
||
(5, 8, 3, 8, 8, 3), # different depth → no collision
|
||
(3, 6, 2, 3, 6, 2), # identical → collision
|
||
(3, 6, 2, 5, 6, 2), # different depth → no collision
|
||
]
|
||
for da, la, lbla, db, lb, lblb in tree_pairs:
|
||
pc = tree_collision_probability(da, la, lbla, db, lb, lblb)
|
||
sa = tree_diat_score(da, la, lbla)
|
||
sb = tree_diat_score(db, lb, lblb)
|
||
score_match = "≈" if abs(sa - sb) < 0.01 else "≠"
|
||
print(f" TreeA(d={da},l={la},ℓ={lbla})→s={sa:.4f}")
|
||
print(f" TreeB(d={db},l={lb},ℓ={lblb})→s={sb:.4f}")
|
||
print(f" P(collision)={pc:.4f} | s_A {score_match} s_B")
|
||
|
||
# ── §4: Win et al. Polynomial Orthogonality ──
|
||
print("\n§4: WIN ET AL. POLYNOMIAL ORTHOGONALITY")
|
||
print("-" * 60)
|
||
for x, m, y, n in KNOWN_SOLUTIONS:
|
||
ov = polynomial_orthogonality_overlap(x, m, y, n)
|
||
r1 = repunit(x, m)
|
||
r2 = repunit(y, n)
|
||
print(f" ⟨ψ({x}^{m}={r1})|ψ({y}^{n}={r2})⟩ = {ov:.4f} "
|
||
f"{'(ORTHOGONAL)' if ov > 0.95 else '(overlap)'}")
|
||
|
||
for x, m, y, n in NON_SOLUTIONS[:2]:
|
||
ov = polynomial_orthogonality_overlap(x, m, y, n)
|
||
r1 = repunit(x, m)
|
||
r2 = repunit(y, n)
|
||
print(f" ⟨ψ({x}^{m}={r1})|ψ({y}^{n}={r2})⟩ = {ov:.4f} "
|
||
f"{'(ORTHOGONAL)' if ov > 0.95 else '(overlap)'}")
|
||
|
||
# ── §5: Baker Bound ──
|
||
print("\n§5: BAKER BOUND VERIFICATION")
|
||
print("-" * 60)
|
||
for x, y, m, n in KNOWN_SOLUTIONS + NON_SOLUTIONS[:2]:
|
||
result = verify_baker_bound(x, y, m, n)
|
||
abs_L, bound = baker_bound(x, y, m, n)
|
||
violates = abs_L < bound
|
||
print(f" ({x},{m},{y},{n}): |Λ|={abs_L:.4e} ≷ B⁻⁴⁴={bound:.4e} "
|
||
f"{'⚠ VIOLATION' if violates else '✓ Baker holds'}")
|
||
|
||
|
||
# ═══════════════════════════════════════════════════════════════════════════
|
||
# §8 HARDWARE DEPLOYMENT — Quandela Ascella
|
||
# ═══════════════════════════════════════════════════════════════════════════
|
||
|
||
def deploy_to_ascella(
|
||
x: int, m: int, y: int, n: int,
|
||
token: Optional[str] = None,
|
||
platform: str = "sim:slos",
|
||
shots: int = 10000,
|
||
) -> Dict:
|
||
"""Deploy the Goormaghtigh collision circuit to Quandela Cloud.
|
||
|
||
Args:
|
||
x, m, y, n: Goormaghtigh parameters.
|
||
token: Quandela API token (uses PCVL_CLOUD_TOKEN or QUANDELA_TOKEN env).
|
||
platform: Platform name ('sim:slos' for cloud sim, 'qpu:ascella' for QPU).
|
||
shots: Number of shots to run.
|
||
|
||
Returns:
|
||
Job result dict with samples.
|
||
"""
|
||
import os
|
||
api_token = token or os.environ.get("PCVL_CLOUD_TOKEN") or os.environ.get("QUANDELA_TOKEN")
|
||
if not api_token:
|
||
return {"error": "No token set. Export PCVL_CLOUD_TOKEN or QUANDELA_TOKEN."}
|
||
|
||
theta_x = goormaghtigh_phase(x, m)
|
||
theta_y = goormaghtigh_phase(y, n)
|
||
c = build_goormaghtigh_circuit(theta_x, theta_y)
|
||
|
||
session = pcvl.QuandelaSession(platform_name=platform, token=api_token)
|
||
rp = session.build_remote_processor()
|
||
rp.set_circuit(c)
|
||
rp.with_input(pcvl.BasicState([1, 1]))
|
||
rp.min_detected_photons_filter(1)
|
||
|
||
sampler = pcvl.algorithm.Sampler(rp, max_shots_per_call=2000)
|
||
result = sampler.samples(shots)
|
||
|
||
return {
|
||
"platform": platform,
|
||
"shots": shots,
|
||
"result": str(result.get("results", "")),
|
||
"global_perf": result.get("global_perf", 0.0),
|
||
"parameters": {"x": x, "m": m, "y": y, "n": n},
|
||
}
|
||
|
||
|
||
def search_for_collisions(
|
||
x_max: int = 50,
|
||
y_max: int = 20,
|
||
m_max: int = 10,
|
||
n_max: int = 5,
|
||
use_hardware: bool = False,
|
||
token: Optional[str] = None,
|
||
platform: str = "sim:slos",
|
||
) -> List[Dict]:
|
||
"""Search for new Goormaghtigh collisions in a bounded region.
|
||
|
||
Uses the photonic circuit as a filter: low coincidence = collision candidate.
|
||
Only checks (x > y > 1, m > n > 2) per Goormaghtigh constraints.
|
||
|
||
For real hardware: each (x,m,y,n) is one circuit execution.
|
||
For simulation: scans the full space systematically.
|
||
|
||
Returns list of collision candidates with their photonic probabilities.
|
||
"""
|
||
candidates = []
|
||
|
||
# Estimated job cost: ~1 credit per 100 shots on Ascella
|
||
total_candidates = 0
|
||
for x in range(3, x_max + 1):
|
||
for y in range(2, min(x, y_max + 1)):
|
||
for m in range(3, m_max + 1):
|
||
for n in range(3, min(m - 1, n_max) + 1):
|
||
total_candidates += 1
|
||
|
||
print(f"Search space: {total_candidates} candidates "
|
||
f"({x_max}×{y_max}×{m_max}×{n_max})")
|
||
|
||
if use_hardware and not token:
|
||
return [{"error": "Need QUANDELA_TOKEN for hardware search.",
|
||
"total": total_candidates}]
|
||
|
||
count = 0
|
||
for x in range(3, x_max + 1):
|
||
for y in range(2, min(x, y_max + 1)):
|
||
for m in range(3, m_max + 1):
|
||
for n in range(3, min(m - 1, n_max) + 1):
|
||
count += 1
|
||
if count % 50 == 0:
|
||
print(f" {count}/{total_candidates} checked...")
|
||
|
||
# Skip known solutions
|
||
if (x, m, y, n) in KNOWN_SOLUTIONS:
|
||
continue
|
||
|
||
if use_hardware:
|
||
result = deploy_to_ascella(x, m, y, n, token, platform=platform)
|
||
candidates.append(result)
|
||
else:
|
||
# Use the polynomial orthogonality as the primary filter
|
||
ov = polynomial_orthogonality_overlap(x, m, y, n)
|
||
pc = goormaghtigh_collision_probability(x, m, y, n)
|
||
abs_L, bound = baker_bound(x, y, m, n)
|
||
|
||
is_candidate = (ov > 0.8 and pc < 0.2)
|
||
|
||
if is_candidate:
|
||
r1 = repunit(x, m)
|
||
r2 = repunit(y, n)
|
||
candidates.append({
|
||
"x": x, "m": m, "y": y, "n": n,
|
||
"repunit_xm": r1,
|
||
"repunit_yn": r2,
|
||
"overlap": ov,
|
||
"coincidence_prob": pc,
|
||
"baker_Lambda": abs_L,
|
||
"baker_bound": bound,
|
||
"known": (r1 == r2),
|
||
})
|
||
if r1 == r2:
|
||
print(f"\n ★ NEW COLLISION: ({x},{m},{y},{n}) "
|
||
f"→ repunits match!")
|
||
elif abs_L < bound:
|
||
print(f"\n ⚠ BAKER VIOLATION: ({x},{m},{y},{n}) "
|
||
f"|Λ|={abs_L:.4e}")
|
||
|
||
return candidates
|
||
|
||
|
||
# ═══════════════════════════════════════════════════════════════════════════
|
||
# §9 CLI
|
||
# ═══════════════════════════════════════════════════════════════════════════
|
||
|
||
def main():
|
||
parser = argparse.ArgumentParser(
|
||
description="Quandela Ascella — Goormaghtigh Collision via Win et al."
|
||
)
|
||
parser.add_argument("--ascella", action="store_true",
|
||
help="Run on Quandela Cloud simulator (sim:slos)")
|
||
parser.add_argument("--qpu", action="store_true",
|
||
help="Run on real QPU (qpu:ascella)")
|
||
parser.add_argument("--token", type=str, default=None,
|
||
help="Quandela API token")
|
||
parser.add_argument("--find", action="store_true",
|
||
help="Search for new collisions within bounds")
|
||
parser.add_argument("--x-max", type=int, default=50,
|
||
help="Max x for search (default: 50)")
|
||
parser.add_argument("--y-max", type=int, default=20,
|
||
help="Max y for search (default: 20)")
|
||
parser.add_argument("--m-max", type=int, default=10,
|
||
help="Max m for search (default: 10)")
|
||
parser.add_argument("--n-max", type=int, default=5,
|
||
help="Max n for search (default: 5)")
|
||
parser.add_argument("--verify", action="store_true",
|
||
help="Verify known solutions")
|
||
args = parser.parse_args()
|
||
|
||
platform = "sim:slos"
|
||
if args.qpu:
|
||
platform = "qpu:ascella"
|
||
|
||
if args.verify or not (args.find or args.ascella or args.qpu):
|
||
run_simulator_tests()
|
||
|
||
if args.find:
|
||
print("\n" + "=" * 72)
|
||
print(f"SEARCHING FOR NEW GOORMAGHTIGH COLLISIONS on {platform}")
|
||
print("=" * 72)
|
||
candidates = search_for_collisions(
|
||
x_max=args.x_max,
|
||
y_max=args.y_max,
|
||
m_max=args.m_max,
|
||
n_max=args.n_max,
|
||
use_hardware=args.ascella or args.qpu,
|
||
token=args.token,
|
||
platform=platform,
|
||
)
|
||
|
||
if len(candidates) > 0 and "error" not in candidates[0]:
|
||
print(f"\nFound {len(candidates)} candidate(s):")
|
||
for c in candidates:
|
||
print(f" ({c['x']}^{c['m']}, {c['y']}^{c['n']}) "
|
||
f"overlap={c.get('overlap', '?'):.4f} "
|
||
f"baker={c.get('baker_Lambda', '?'):.4e}")
|
||
|
||
if (args.ascella or args.qpu) and not args.find:
|
||
# Deploy one-shot verification of known solutions
|
||
print("\n" + "=" * 72)
|
||
print(f"DEPLOYING TO {platform}")
|
||
print("=" * 72)
|
||
for x, m, y, n in KNOWN_SOLUTIONS:
|
||
result = deploy_to_ascella(x, m, y, n, args.token, platform=platform)
|
||
print(f" ({x}^{m}, {y}^{n}): platform={platform} "
|
||
f"perf={result.get('global_perf', 0.0):.4f}")
|
||
|
||
|
||
if __name__ == "__main__":
|
||
main()
|