Datasets:
Formats:
json
Languages:
English
Size:
< 1K
Tags:
mathematical-physics
arrow-of-time
temporal-irreversibility
time-reversal-symmetry
quantum-information
quantum-foundations
Download verification/verify_v2_ordered_completion.py from PureOne/Neixarua-Operational-Temporal-Orientation: direct link, hf CLI and curl.
- Browser
- Download file 4.37 kB
-
https://huggingface.co/datasets/PureOne/Neixarua-Operational-Temporal-Orientation/resolve/main/verification/verify_v2_ordered_completion.py
- Command line
-
hf download hf://datasets/PureOne/Neixarua-Operational-Temporal-Orientation/verification/verify_v2_ordered_completion.py
-
curl -L -o verify_v2_ordered_completion.py https://huggingface.co/datasets/PureOne/Neixarua-Operational-Temporal-Orientation/resolve/main/verification/verify_v2_ordered_completion.py
4.37 kB
| """Checks of the record-conditioned quantum endpoint completion. | |
| The matrix construction and equalities are theorems proved in the manuscript. | |
| These finite examples test singular, noncommuting and retained-record cases. | |
| """ | |
| from pathlib import Path | |
| import json | |
| import numpy as np | |
| from scipy.linalg import eigh | |
| I=np.eye(2,dtype=complex) | |
| X=np.array([[0,1],[1,0]],dtype=complex) | |
| Y=np.array([[0,-1j],[1j,0]],dtype=complex) | |
| Z=np.diag([1,-1]).astype(complex) | |
| def entropy(a): | |
| ev=eigh((a+a.conj().T)/2,eigvals_only=True) | |
| ev=ev[ev>1e-14] | |
| return float(-np.sum(ev*np.log(ev))) | |
| def js(a,b): | |
| return entropy((a+b)/2)-(entropy(a)+entropy(b))/2 | |
| def tv(a,b): | |
| return float(np.abs(eigh(a-b,eigvals_only=True)).sum()/2) | |
| def j(x): | |
| return sum(0 if t==0 else t*np.log(t)/2 for t in (1+x,1-x)) | |
| def close(a,b): | |
| return np.allclose(a,b,atol=1e-12,rtol=0) | |
| def positive(a): | |
| return min(eigh((a+a.conj().T)/2,eigvals_only=True))>=-1e-12 | |
| checks=[] | |
| rho=(I+.6*X+.4*Z)/2 | |
| sigma=(I+.6*X-.4*Z)/2 | |
| mu=(rho+sigma)/2 | |
| delta=(rho-sigma)/2 | |
| c=.5 | |
| minus=mu-delta/c | |
| plus=mu+delta/c | |
| assert positive(minus) and positive(plus) | |
| assert close(minus@minus,minus) and close(plus@plus,plus) | |
| checks.append("pure nonorthogonal endpoint preparations are positive") | |
| assert abs(np.trace(minus@plus).real-.36)<1e-12 | |
| assert close(.25*minus+.75*plus,rho) | |
| assert close(.75*minus+.25*plus,sigma) | |
| checks.append("common endpoint preparation reconstructs both noncommuting states") | |
| assert not close(rho@sigma,sigma@rho) | |
| assert abs(tv(rho,sigma)-.4)<1e-12 | |
| assert js(rho,sigma)<j(.5) | |
| checks.append("strict loss from endpoint to noncommuting pair") | |
| # Three retained records, asymmetric intervals, and an unused endpoint. | |
| m=[.2,.3,.5]; b=[.25,-1/6,0] | |
| l=[-.5,-.5,0]; u=[.75,.5,0] | |
| taus=[((I+Z)/2,(I+X)/2),((I+Y)/2,(I-Y)/2),(I/2,I/2)] | |
| assert abs(sum(mm*bb for mm,bb in zip(m,b)))<1e-12 | |
| upper_js=0; blocks_r=[];blocks_s=[] | |
| max_res=0 | |
| for mm,bb,ll,uu,(tm,tp) in zip(m,b,l,u,taus): | |
| wm=(uu-bb)/(uu-ll) if uu>ll else 1 | |
| wp=1-wm | |
| a=mm*wm*tm; B=mm*wp*tp | |
| r=(1+ll)*a+(1+uu)*B | |
| s=(1-ll)*a+(1-uu)*B | |
| M=(r+s)/2; D=(r-s)/2 | |
| assert positive(D-ll*M) and positive(uu*M-D) | |
| if uu>ll: | |
| max_res=max(max_res,float(np.linalg.norm((uu*M-D)/(uu-ll)-a))) | |
| max_res=max(max_res,float(np.linalg.norm((D-ll*M)/(uu-ll)-B))) | |
| assert abs(np.trace(r).real-mm*(1+bb))<1e-12 | |
| assert abs(np.trace(s).real-mm*(1-bb))<1e-12 | |
| upper_js+=mm*(wm*j(ll)+wp*j(uu)) | |
| blocks_r.append(r);blocks_s.append(s) | |
| from scipy.linalg import block_diag | |
| r=block_diag(*blocks_r); s=block_diag(*blocks_s) | |
| assert abs(np.trace(r)-1)<1e-12 and abs(np.trace(s)-1)<1e-12 | |
| assert max_res<1e-12 | |
| assert sum(mm*j(bb) for mm,bb in zip(m,b))<=js(r,s)+1e-12<=upper_js+1e-12 | |
| checks.append("asymmetric conditional bounds, retained traces and degenerate fiber") | |
| # Orthogonal endpoint states attain the information ceiling. | |
| rm=np.diag([.25,.75]);sm=np.diag([.75,.25]) | |
| assert abs(js(rm,sm)-j(.5))<1e-12 | |
| assert abs(tv(rm,sm)-.5)<1e-12 | |
| checks.append("orthogonal endpoint equality and recoverability") | |
| # Singular endpoint and zero-mass component require no inverse. | |
| singular_r=np.diag([1.,0.]); singular_s=np.diag([0.,1.]) | |
| M=(singular_r+singular_s)/2;D=(singular_r-singular_s)/2 | |
| A=(M-D)/2;B=(D+M)/2 | |
| assert close(2*B,singular_r) and close(2*A,singular_s) | |
| assert abs(js(singular_r,singular_s)-np.log(2))<1e-12 | |
| checks.append("mutually singular pair from scores plus/minus one") | |
| # Physical antiunitary J=Z conjugation after complex conjugation flips X. | |
| # Here take J=X complex-conjugation, which flips Z while fixing X. | |
| J=lambda a:X@a.conj()@X | |
| assert close(J(rho),sigma) | |
| assert close(J(plus),minus) | |
| checks.append("physical reversal swaps preparation endpoints") | |
| out={ | |
| "scope":"Finite analytic examples, not measured data.", | |
| "noncommuting_example":{"input_trace_distance":tv(rho,sigma), | |
| "endpoint_trace_distance":c,"input_js":js(rho,sigma), | |
| "endpoint_js":j(c),"squared_preparation_overlap":.36}, | |
| "retained_record_example":{"preparation_residual":max_res, | |
| "quantum_js":js(r,s),"endpoint_js_ceiling":upper_js}, | |
| "verification":{"named_checks":len(checks),"passed":len(checks), | |
| "all_passed":True,"absolute_tolerance":1e-12,"checks":checks} | |
| } | |
| path=Path(__file__).parent/"results"/"v2_ordered_completion_results.json" | |
| path.parent.mkdir(exist_ok=True) | |
| path.write_text(json.dumps(out,indent=2)+"\n") | |
| print(json.dumps(out,indent=2)) | |