"""Symplectic/Bogoliubov formulas with a FIXED reference vacuum. Expected pair count equals per-mode photon number for the homogeneous +/-k pair. Total photons in that pair are twice this number. Not a dispersive QED solver. """ from __future__ import annotations import math import numpy as np from scipy.special import eval_chebyu def bogoliubov(M:np.ndarray,omega:float=1.)->tuple[complex,complex]: M=np.asarray(M,dtype=float) if M.shape!=(2,2) or not np.all(np.isfinite(M)) or not math.isfinite(omega) or omega<=0: raise ValueError('2x2 real M and fixed positive reference frequency required.') a,b,c,d=M.ravel() return complex((a+d)/2,(c/omega-omega*b)/2),complex((a-d)/2,(c/omega+omega*b)/2) def _log_sinh(x:float)->float: if x<=0:raise ValueError('Positive argument required.') return math.log(math.sinh(x)) if x<20 else x-math.log(2)+math.log1p(-math.exp(-2*x)) def log_photon_number(M:np.ndarray,N:int=1,omega:float=1.)->float: """Logarithmic expected pair count; avoids overflow for large hyperbolic N. Returns -infinity at exact zero. Input M must be real determinant one; near a band edge, floating-point classification is not an interval certificate. """ if not isinstance(N,int) or N<1:raise ValueError('Positive integer N required.') _,beta=bogoliubov(M,omega);b=abs(beta) if b==0:return -math.inf D=float(np.trace(M))/2 if abs(D)>1: L=math.acosh(abs(D));logU=_log_sinh(N*L)-_log_sinh(L) elif abs(D)==1: logU=math.log(N) else: value=abs(float(eval_chebyu(N-1,D))) if value==0:return -math.inf logU=math.log(value) return 2*(math.log(b)+logU) def photon_number(M:np.ndarray,N:int=1,omega:float=1.)->float: value=log_photon_number(M,N,omega) return math.exp(value) if value<=math.log(np.finfo(float).max) else math.inf def squeezing(M:np.ndarray,N:int=1,omega:float=1.)->float: half=log_photon_number(M,N,omega)/2 if half==-math.inf:return 0. if half<0:return math.asinh(math.exp(half)) return half+math.log1p(math.sqrt(1+math.exp(-2*half))) def hyperbolic_prefactor(M:np.ndarray,omega:float=1.)->float: D=abs(float(np.trace(M)))/2 if D<=1:raise ValueError('Strictly hyperbolic matrix required.') _,beta=bogoliubov(M,omega) return abs(beta)**2/(D*D-1) def finite_cycle_rate_error(K0:float,N:int)->float: if K0<1 or N<1:raise ValueError('K0 >= 1 and N >= 1 required.') return math.log(N*(K0+1))/N