"""Exact identities used for the polar angle estimate and order of turns.""" from sympy import Matrix, diag, eye, factor, symbols, trace u,v,z,a,b,c,e,x,y=symbols('u v z a b c e x y',positive=True) # A positive symmetric determinant-one B is orthogonally diagonalizable. B=diag(u,1/u) assert (B.inv() * trace(B) - eye(2) - B.inv()**2).applyfunc(factor)==Matrix.zeros(2) H=Matrix([[a,b],[b,c]]) lhs=trace(H)*trace(B.inv()**2*H)-trace(B.inv()*H)**2 assert factor(lhs-a*c*(u-1/u)**2)==0 J=Matrix([[0,-1],[1,0]]) X=J*H assert factor(trace(B.inv()*H)+trace(J*B*X))==0 f=lambda a,x: 1-a*x/(a+x)**2 assert factor(f(a,x)-f(a,y)-a*(y-x)*(a*a-x*y)/((a+x)**2*(a+y)**2))==0 assert factor(f(a,x)-(3+(x-a)**2/(x+a)**2)/4)==0 print('PASS polar trace, trace Schwarz remainder, angular speed numerator, turn ordering and interval mean.') # Linear interpolation at the intervening turns. The two endpoint # inequalities used in Proposition 8.1 persist along the whole interval. lam = symbols('lam', real=True) p = (1-lam)*a + lam*x q = (1-lam)*y + lam*e assert factor(e*q-x*p - ((1-lam)*(e*y-x*a)+lam*(e**2-x**2))) == 0 assert factor(e*x-p*q - ((e-q)*x+q*(x-p))) == 0 # Subtract the stationarity equation evaluated at the individual bounds. left, right, scale, logterm, s0, s1 = symbols('left right scale logterm s0 s1') row = lambda u0,u1: 1+left+right-scale+logterm-(1-8*u0)/left-(1-8*u1)/right threshold = lambda share: (1-share+share**2)/8 row_star = row(threshold(left),threshold(right)) assert factor(row_star - (-1+2*left+2*right-scale+logterm)) == 0 assert factor((row(s0,s1)-row_star)/8 - (s0-threshold(left))/left - (s1-threshold(right))/right) == 0 print('PASS both turn interpolation identities and stationary cross-pairing threshold.')