#!/usr/bin/env python3 """Verify the two entry signs of the master secant relation.""" import sympy as sp def main(): q, tau, rho = sp.symbols("q tau rho", positive=True) sigma = sp.Symbol("sigma", real=True) active = rho*tau neighbour = tau - active switch_bound = (1 - rho + rho**2)/8 costate_sum = 4*sp.sqrt(3)*tau**2*(sigma-switch_bound) def secant(s1, s2, log_ratio): return 1 + active**2/((active+s1)*(active+s2)) - active*log_ratio/(s2-s1) for sign in (1, -1): far = tau*q**(-sign) - active mean = secant(neighbour, far, -sign*sp.log(q)) if sign == 1: u_add = sp.sqrt(3)*active/2*(tau*(1/q-1/q**2)-active*(1-1/q**2)) v_add = sp.sqrt(3)*active/q*(2*active*(q-1)-tau*sp.log(q)) else: u_add = sp.sqrt(3)*active/2*(active*(q**2-1)-tau*(q**2-q)) v_add = sp.sqrt(3)*active*(tau*q*sp.log(q)-2*active*(q-1)) weighted = 2*(q**(-2*sign)-q**(-sign))*costate_sum+2*u_add+v_add expected = -sign*sp.sqrt(3)*tau**2*(q-1)*q**(-(1+3*sign)//2)*(8*sigma-mean) difference = sp.cancel(weighted-expected) assert difference == 0, difference assert sp.simplify(sp.limit(mean, q, 1)-8*switch_bound) == 0 print("PASS secant relation for both entry signs and its switch-bound limit") if __name__ == "__main__": if not __debug__: raise SystemExit("Run the exact checks with assertions enabled.") main()