"""Two forward stationarity rows in the margins at their common switch.""" import sympy as sp def same(left, right): delta = sp.factor(sp.together(left-right)) if delta != 0: raise ValueError(f"Unequal rational expressions: {delta}") def main(): z,m,h,q,U,V,Lh,Lq=sp.symbols("z m h q u v logh logq",positive=True) s=1+z w=(1+m)*q-1 f=lambda b,c:1-b*c/(b+c)**2 t=(1+m)*q c0=z+w+1-1/s-1/t+1/(s*(1+m))-Lq c1=(z+m)*h+1-z*z/((z+m)*h)-z*z/s+z**3/(s*(z+m))-z*Lh cross=s*U+t*V-c0 outer=(s*s*U+(1+m)**2*V-s*(1+m)*cross)/(z+m)**2 prior_cross=(2*s*U-(1+m)*cross)/(z+m) preceding=(z+m)*h*outer+s*U-z*prior_cross-c1 lam=(q-1)*(1+s*(h-1)); k=z*(h-1) secant=1+1/((1+m)*t)-Lq/((1+m)*(q-1)) g=(z+m)*(Lh/(h-1)-1)+z*(1-1/h) J=f(1,m)+(g-m*s*s/z*(U-f(1,z)))/(1+m)**2 same(preceding,-(1+m)**2/(z+m)*(lam*(V-secant)+k*(V-J))) ell=1-1/h defect=(1+1/h)/2-Lh/(h-1) same(g,(z-m)*ell/2-(z+m)*defect) F=1+(z/s)**2*h-(z/s)*h*Lh/(h-1) upper=ell*(z*(1-m)-m*(z-1)*(h-1))/2-(z+m+m*s*h)*defect same(g-m*s*s/z*(F-f(1,z)),upper) # The area checker works with excesses over the common floor 3/4. x=1/t Dq=(1+1/q)/2-Lq/(q-1) same(secant-sp.Rational(3,4), (x-sp.Rational(1,2))**2+x*(x-sp.Rational(1,2))*(q-1)+x*q*Dq) p=s/h-z same(k/(k+lam), z*(1-p)/(z*(1-p)+(q-1)*(1+2*z-z*p))) print("PASS: adjacent forward stationarity rows, secant and transported value, " "preceding arc bound, convex weight and centered secant.") if __name__=="__main__": main()