import sys, os; sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) import sympy as sp, random, itertools from grass import * from casimir import casimir, B, F, tB, tF I = sp.I p = B**2 - 1; q = 1 - F**2; d = B - F sq = sp.sqrt(p*q) ph = sp.exp(I*(tB - tF)) kap = {(1, 2): 2*(B*F - 1)/d**2, (3, 4): 2*(B*F - 1)/d**2, (1, 4): 2*I*sq*ph/d**2, (2, 3): -2*I*sq/ph/d**2} cpart = {1: (G.gen(2), sp.Rational(1, 2)*I), 2: (G.gen(1), sp.Rational(1, 2)*I), 3: (G.gen(4), -sp.Rational(1, 2)*I), 4: (G.gen(3), -sp.Rational(1, 2)*I)} def Theta(f): return f.diff(tB) + f.diff(tF) def D(a, f): xi, c = cpart[a] return f.dleft(a) + (xi * Theta(f)) * c def C0(f): return (f.diff(B) * p).diff(B) + (f.diff(F) * q).diff(F) + f.diff(B) * (-2*p/d) + f.diff(F) * (2*q/d) def Lhyp(f): out = C0(f) + f.diff(tB).diff(tB) * (1/p) + f.diff(tF).diff(tF) * (1/q) for (a, b), k in kap.items(): out = out + (D(b, D(a, f)) - D(a, D(b, f))) * (k/2) return out def Ltrue(f): return casimir(f) * sp.Rational(1, 2) random.seed(3) pts = [] for _ in range(3): pts.append({B: sp.Rational(random.randint(11, 60), 10), F: sp.Rational(random.randint(-9, 9), 10), tB: sp.Rational(random.randint(-30, 30), 10), tF: sp.Rational(random.randint(-30, 30), 10)}) gens = [1, 2, 3, 4] monos = [()] + [(a,) for a in gens] + list(itertools.combinations(gens, 2)) + list(itertools.combinations(gens, 3)) + [(1, 2, 3, 4)] bodies = [B*F + F**2, sp.exp(I*tB)*B, sp.exp(-2*I*tF)*(1 + F)*B**2, sp.exp(I*(tB + tF))*sp.sqrt(1 - F**2), sp.cos(B)*sp.exp(I*tF), tB*F] maxerr = 0; ntest = 0 for mono in monos: for body in random.sample(bodies, 3): f = G({mono: body}) diff = Ltrue(f) - Lhyp(f) for pt in pts: for k, v in diff.d.items(): e = abs(complex(sp.N(v.subs(pt), 30))) maxerr = max(maxerr, e) ntest += 1 print("tested", ntest, "functions at", len(pts), "points; max |L_true f - L_hyp f| =", maxerr)