#!/usr/bin/env python3 """Compute recoil amplitudes of a six-stage dark-port readout, using only Python.""" from cmath import exp from fractions import Fraction from math import atan, ceil, cos, expm1, fsum, isclose, pi, sin, sqrt KICKS = (-1, 1, 0, 1, -1, 0) LEVELS = 44 LOW_CARRIER_PHASE = 2 * pi * 1024 + pi / 2 def norm_squared(state): return fsum(abs(a)**2 for a in state) def links(levels, eta, theta, carrier_phase, feedback): """Tridiagonal generator. The feedback uses the midpoint sideband energy.""" ratio = len(KICKS) * theta / carrier_phase if feedback else 0 return [eta * sqrt(n + 1) * (1 - (n + 0.5) * ratio) for n in range(levels - 1)] def apply_generator(state, couplings): result = [0j] * len(state) for n, g in enumerate(couplings): result[n] += g * state[n + 1] result[n + 1] += g * state[n] return result def apply_kick(state, sign, couplings): """Apply exp(i sign G) with scaled Taylor actions on a tridiagonal matrix.""" if sign == 0: return state # Maximum absolute row sum is bounded by twice the largest link. # This scaling makes the operator norm of each Taylor argument at most one. parts = max(1, ceil(2 * max(abs(g) for g in couplings))) scale = 1j * sign / parts for _ in range(parts): total = state[:] term = state for order in range(1, 31): term = [z * scale / order for z in apply_generator(term, couplings)] total = [a + b for a, b in zip(total, term)] state = total return state def route(eta, theta, carrier_phase, sign, feedback=True, levels=LEVELS): state = [1 + 0j] + [0j] * (levels - 1) phases = [exp(-1j * n * theta) for n in range(levels)] couplings = links(levels, eta, theta, carrier_phase, feedback) for q in KICKS: state = [a * phase for a, phase in zip(state, phases)] state = apply_kick(state, sign * q, couplings) return state def readout(eta, theta, carrier_phase, feedback=True, levels=LEVELS): a = route(eta, theta, carrier_phase, 1, feedback, levels) b = route(eta, theta, carrier_phase, -1, feedback, levels) # The routing amplitudes at (2, 0, 2) are -i/4 and +i/4. dark = [-0.25j * (x - y) for x, y in zip(a, b)] route_weights = [abs(v)**2 for v in a] dark_weights = [abs(v)**2 for v in dark] probability = norm_squared(dark) mean_n = fsum(n * p for n, p in enumerate(route_weights)) assert isclose(sum(route_weights), 1, rel_tol=0, abs_tol=2e-13) assert isclose(norm_squared(b), 1, rel_tol=0, abs_tol=2e-13) assert max(abs(y - (-1)**n * x) for n, (x, y) in enumerate(zip(a, b))) < 1e-13 assert isclose(probability, fsum(route_weights[1::2]) / 4, rel_tol=0, abs_tol=2e-15) energy = carrier_phase / (len(KICKS) * theta) assert energy > levels - 1 # Each retained joint channel has optical energy energy-n and material energy n. mean_optical = fsum((energy - n) * p for n, p in enumerate(route_weights)) assert isclose(mean_optical + mean_n, energy, rel_tol=0, abs_tol=1e-10) if probability > 1e-14: dark_n = fsum(n * p for n, p in enumerate(dark_weights)) / probability dark_optical = fsum((energy - n) * p for n, p in enumerate(dark_weights)) / probability assert isclose(dark_optical + dark_n, energy, rel_tol=0, abs_tol=1e-10) return probability, mean_n def ideal(eta, theta): mean_n = 16 * eta**2 * sin(theta / 2)**2 * sin(3 * theta / 2)**2 return -expm1(-2 * mean_n) / 8, mean_n def rod_energy(): transfer = (Fraction(9, 5), Fraction(-3, 5)) q_squared = sum(q*q for q in transfer) gap = Fraction(1, 5) assert q_squared / (2 * 9) == gap rest_mass, final_energy = Fraction(89, 10), Fraction(91, 10) assert rest_mass**2 + q_squared == final_energy**2 assert final_energy - rest_mass == gap released_phase = atan(3 / 4) assert isclose(sin(released_phase), 3 / 5) assert isclose(cos(released_phase), 4 / 5) return gap, released_phase def main(): cases = [(1/8, LOW_CARRIER_PHASE, 0.0146693774791, 0.06240470071), (5/8, 5*LOW_CARRIER_PHASE, 0.1195133328433, 1.56156606348)] # Each complete carrier cycle gives the same sampled phase; a half-cycle separates them. frequency_difference_in_turns = (cases[1][1] - cases[0][1]) / (2 * pi) assert isclose(frequency_difference_in_turns, 4097, rel_tol=0, abs_tol=1e-11) for eta, carrier, expected_prob, expected_n in cases: for sign in (-1, 1): no_drift = route(eta, 0, carrier, sign) assert abs(no_drift[0] - 1) < 1e-13 assert norm_squared(no_drift[1:]) < 1e-25 for theta in (pi/2, 2*pi/3): p, n = readout(eta, theta, carrier) raw = readout(eta, theta, carrier, feedback=False) analytic = ideal(eta, theta) assert all(isclose(a, b, rel_tol=0, abs_tol=2e-12) for a, b in zip(raw, analytic)) # Repeat with twelve more levels to test the number cutoff. extended = readout(eta, theta, carrier, levels=LEVELS+12) assert all(isclose(a, b, rel_tol=0, abs_tol=2e-12) for a, b in zip((p, n), extended)) if theta == pi/2: assert isclose(p, expected_prob, rel_tol=0, abs_tol=2e-12) assert isclose(n, expected_n, rel_tol=0, abs_tol=1e-10) print(f"eta={eta:g} theta/pi={theta/pi:.6f} " f"Pdark={p:.13g} mean_n={n:.13g} ideal_Pdark={raw[0]:.13g}") gap, phase = rod_energy() print(f"rod energy transfer={gap}; released quasienergy={phase:.12f} rad") if __name__ == "__main__": main()