README.md
12.3 kB · markdown
Roulette Nodes
- Counts the nodes of a design's roulette: a wheel of radius
rrolls inside or outside a circle of radiusRwithR/r = a/bin lowest terms, a pencil at seatpin wheel radii draws a trochoid, and a node is a crossing of one curve with itself or of two curves with each other. - The counter is
mrlylab::roulette::nodesovermrlynum::spirograph::trace: every pair of polyline segments is tested for a proper crossing by orientation signs on a grid of buckets, each pair judged in the one bucket the two bounding boxes first share, so no crossing is counted twice and no pair is missed. - The orientation sign is
mrlylab::roulette::side, exact whenever the two differences it is handed are exact, whatever the size of their products: the determinant is taken by the fused multiply-add identity of Kahan, whose error is at most twice the rounding unit times the determinant itself, so it can neither flip a sign nor invent one. The differences of twof32endpoints are exact inf64while the picture's coordinates keep their exponents within 29 of one another, as these pictures do. - Three numbers come back and they are not the same number.
totaladds the crossings, and a node wherenbranches meet contributesn(n - 1)/2of them;pointscounts the distinct nodes;branchesaddsnover the nodes, which is the edge count of the picture as a plane graph. The three agree astotal = pointsandbranches = 2 pointsexactly whencrowdedis zero. - Coincident pencils are dropped before counting by
mrlylab::roulette::spread: on a circle the seats fall into classes under the rotation group of ordergcd(b, 4), and on a line or a polygon every distinct seat draws its own curve, two seats of one radius on a line drawing translates of one shape and never one curve. - Crossings within
4e-4of the picture's longer side cluster into one node; every cell with a crowded node is printed, and reprinted at a tenth of that tolerance to separate an alignment from a near miss. - Every count is three sample counts alike, the last two doubled, to five doublings; a cell that never settles is printed with its count.
- The census sweeps both tracks, every
a/bin lowest terms witha <= 20andb <= 10, four designs of one, two, four and eight pencils, and seven reaches, and prints every cell that breaks a law. - Two instruments stand against the counter and share no code with it: the torus reduction, which counts the roots of one real equation in one variable and multiplies by
a, and a flood, which rasters the curves as walls and counts the faces they cut the plane into.
THE REDUCTION
- Over
borbits the centre turns once foruin[0, 2 pi), and the pencil at seatpdrawsz(u) = A e^(i b u) + r p e^(-i M u)inside andA e^(i b u) + r p e^(i M u)outside, withAthe centre path radius andM = a - binside,M = a + boutside, soA = r M / bin both cases. - Two pencils meet where
z_p(u) = z_q(v); withs = u + vandd = u - vande^(i b u) - e^(i b v) = 2i e^(i b s/2) sin(b d/2)the equation becomes2i A e^(i a s/2) sin(b d/2) = -r(p e^(i M d/2) - q e^(-i M d/2))inside, whereb + M = a, and the same withe^(-i a s/2)outside, whereb - M = -a. - Taking moduli kills
sand leaves one equation indalone,2 A abs(sin(b d/2)) = r abs(p e^(i M d/2) - q e^(-i M d/2)); for every solutiondthe phase then fixesa s / 2modulo2 pi, giving exactlyavalues ofsin[0, 4 pi). - So with
x = d/2andNthe number ofxin[0, 2 pi)solving that equation, two distinct curves meet ata N / 2parameter pairs and one curve meets itself ata (N - 2) / 4, the two dropped solutionsx = 0andx = pibeing the diagonalu = v. - Two thresholds fall out of it:
A b > r abs(p) Misabs(p) < 1, the loop threshold, andA > r abs(p)isabs(p) b < M, the seat inside the centre path. With0 < abs(p)for the centre seat they make one window,0 < abs(p) < min(1, M/b), which is three hypotheses and not one: the loop threshold binds whenevera > 2band outside every track, the seat threshold whenevera < 2binside. - The seat at the wheel's centre,
abs(p) = 0, is outside every statement below: it draws the centre circlebtimes over, so its own crossing count is0and nota(b - 1), and its2abparameter pairs with another curve sit at2apoints, each hit once a lap.
THE PROOF
- One curve crosses itself
a(b - 1)times when0 < abs(p)and both thresholds hold. SetC = r abs(p). Forp = qthe reduction readsA abs(sin(b x)) = C abs(sin(M x)), that isA sin(b x) = -+ C sin(M x), the zeros of the imaginary parts ofF = A e^(i b x) - C e^(i M x)andG = A e^(i b x) + C e^(i M x). arg Fturns at the rate(A^2 b + C^2 M - A C (b + M) cos((b - M) x)) / abs(F)^2, which is positive for everyxif and only if(A - C)(A b - C M) > 0, and the same rate with the sign of the cosine reversed governsG. That product is positive on two components; below both thresholds is the one whereA > C, and it is the component that matters, since on the other,abs(p) > 1with the seat outside the centre path, the argument climbs by2 pi Mand each branch takes2Mzeros, not2b.- Below both thresholds
arg Fclimbs by2 pi bover a period, soIm Fhas exactly2bzeros, andIm Glikewise; withC > 0the two share a zero only wheresin(b x) = 0 = sin(M x), which sincegcd(b, M) = gcd(a, b) = 1meansx = 0orx = pi. AtC = 0the two branches are the same function and share all2b, which is the centre seat and its count of nothing. - Hence
N = 4b - 2and the self count isa (N - 2) / 4 = a(b - 1). - Two distinct curves of one radius cross
2abtimes when0 < abs(p) = abs(q)and both thresholds hold. The right side is2 r abs(p) abs(sin(M x + f))with2fthe angle between the seats, the turning rate is unchanged because a phase only shifts the cosine, each branch again has exactly2bzeros, and the two share none unlesssin(b x) = 0 = sin(M x + f), soN = 4band the count isa N / 2 = 2ab. - Two distinct curves of different radii, both with
0 < abs(p), cross2abtimes under a sufficient bound. The equation squares to4 A^2 sin^2(b x) = r^2(abs(p) - abs(q))^2 + 4 r^2 abs(p) abs(q) sin^2(M x + f), whose right siderhonever vanishes and obeysabs(rho') <= 2 r sqrt(abs(p) abs(q)) M, so2A sin(b x) - rhocan only turn whereabs(cos(b x)) <= k = r sqrt(abs(p) abs(q)) M / (A b); if2 A sqrt(1 - k^2) > r(abs(p) + abs(q))it is positive there, hence strictly monotone on both flanks of each of thebhumps, giving two zeros a hump,N = 4b, and again2ab. - That bound is sufficient and far from necessary: inside
7/3the two design atabs(p) = 0.950and0.672reads1.604against1.622and so fails it, while the count is 42, which is2ab. - A whole design. With
kdistinct curves, every seat obeying the hypotheses above, the roulette carries2ab C(k, 2) + k a(b - 1)crossings, and as many distinct nodes when no three branches meet, which the multiplicity bucket is there to check.
THE REGIONS
- At a generic reach the roulette is a connected 4-regular plane graph on its nodes, so Euler cuts the plane into
points + 2regions, the unbounded one among them; connected because every two curves cross,2ab > 0, and 4-regular because every node is a transversal double point. - With a crowded node the graph is not 4-regular and the count is
branches - points + 2, which is the same number where nothing is crowded. - The flood confirms both at 1600 and at 2400 pixels: inside
3/1one seat 2,5/27,7/316 atabs(p) = 0.5and at0.9,3/1two seats 8,5/2two seats 32, and the alignment cell inside7/3at seat0.527, where 1288 crossings sit at 1148 nodes carrying 2352 branches, 1206. - At
k = 1andb = 1there is no node at all and the 2 regions are Jordan's, not Euler's. - Past the seat threshold the flood tracks the counted crossings and never the law: inside
7/4two seats atabs(p) = 0.900and0.636count 84 crossings and flood 86 regions, where the law would say 98 and 100.
THE CREST
- Past the seat threshold the curve is not the one the proof describes, and the count falls in steps, each step the loss of one hump of
R(x) = abs(sin(b x)) / abs(sin(M x))under the levelC/A. - The steps are exactly the local maxima of
R, so the self law holds up to the crest, the least local maximum ofR, which is never below 1 becauseRreaches 1 at the midpoint of any two consecutive zeros ofsin(b x),abs(sin(b x)) = 1there andabs(sin(M x)) <= 1. - Below the crest the count is
a(b - 1); at the top of the band, asC/Aclimbs tob/M, it isa(a - b); between them it is a multiple ofathat never rises. - The pair law is not so patient: one seat past the seat threshold is enough to lose it, inside
7/4at seats0.900and0.636reading 42 against2ab = 56while both self counts hold at 21 and the crest,1.333, is not yet reached. - At exactly
C/A = 1the curve runs through the centre andabranches meet there, so the counts printed at that one reach, 25 at7/5and 31 at7/6, are neither the law nor a multiple ofa; no census cell sits on it. - Inside a track with
a >= 2b, and outside every track, the seat threshold is past the loop threshold and the crest never bites.
RUN
CARGO_BUILD_JOBS=4 cargo run --release -p roulette-nodes- About two minutes; prints only, writes nothing.
- The verbs
scratch,law,gap,torus,centreandregionsrun one section each.
WITNESSES
- The law: 5553 cells and 4455175 crossings over both tracks,
a <= 20,b <= 10, four designs and seven reaches, with 143 aligned cells printed, 576 near misses, 26 cells needing a further doubling and none left unsettled. - Two cells disagree, both by a few crossings on a pair at a near tangency, both reading the law at their base sample count and losing crossings under refinement: inside
20/3carpet at seat0.250, four pairs at 116 against 120, settled 3664 against 3680; outside10/9carpet at seat0.400, two pairs at 178 against 180, settled 5676 against 5680. The torus reads 3680 and 5680, at two million roots and at eight million. - The self law by ratio, one pencil inside at
abs(p) = 0.5:3/1and4/1and5/1and7/1at 0,5/2at 5,7/2at 7,7/3at 14,8/3at 16,11/4at 33, againsta(b - 1). - The pair law: the carpet's eight fills inside
a/1at tile reach0.30, seat0.20, give168, 224, 280, 336, 392fora = 3..7, against2ab C(8, 2) = 56a, with no self crossing. - The whole law: the carpet's eight fills inside
7/3give1176 + 112 = 1288at every tile reach from0.2to1.2, seat0.13to0.80, against2ab C(8, 2) + 8 a(b - 1). - Two curves inside
7/4at tile reach0.90, seats0.600and0.424, give 56 crossings and 21 self crossings each, against2ab = 56anda(b - 1) = 21. - The alignment: the carpet inside
7/3at tile reach0.79, seats0.527and0.373, carries 28 crowded nodes each holding 6 crossings, which is four branches through one point, and none at0.78or0.80; the census cell nearest it, seat0.950, crowds 28 nodes at three branches. - The centre seat: inside
5/2a seat at0.5beside a seat at the wheel's centre reads 20 crossings against2ab = 20, but they sit at2a = 10points and the flood reads 17 regions against the law's 27; the centre curve's own polyline self count is meaningless, 5999 at 6000 samples and 2999 at 3000. - The crest: 213 cells over 31 ratios, every count a multiple of
a, no rung rising, every cell readinga(b - 1)below the crest and less above it, and all 31 ladders ending ata(a - b). - The crest bites: inside
7/6the self count is 35 at seat0.158, 21 at0.175and 7 at0.9, whilea(b - 1) = 35; inside7/5it is 28 at0.42and 14 at0.44; the crest is 1 at4/3and6/5and1.089at5/4, and wherea = 2b - 1the two ends agree and the ladder is flat. - The torus against the polyline: twelve named cells, eleven agreeing, the twelfth the outside
1/10carpet cell at seat0.100where the polyline reads 172 against the torus and the law at 156. - The crate tests
two_curves_on_one_orbit_cross_twice_the_ratio_whatever_their_seats,a_curve_below_the_threshold_crosses_itself_a_times_b_less_one,an_alignment_reach_crowds_the_nodes_and_the_points_fall_shortandthe_coincident_pencils_collapse_to_one_pencil_a_curve.