File size: 2,493 Bytes
9755170
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
59
60
61
62
63
64
65
66
67
68
"""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