""" fixed_y.py -- the codings of one point beside a fixed periodic one, in integers: sigma's S^inf has no second coding at d = 4..16, read beside two words whose second codings the search finds at d = 5..15, one of them at d = 4 and 16. QUESTION. sigma = (2, 3, 2, 0, ..., 0) of P_4 has the periodic coding S^inf, S = 1 0^(d+1) 1^(d-3) 0 1 0 (period 2d + 2, low digit first). pairs.py reads every pair of codings at once and S^inf alone to d = 10, on a cube of 5^d windows; at d = 11 its cube would hold 7^11. With y = S^inf held fixed and only y' free, is there a second coding of y's point at d = 11, 12, ..., and what does the same search find when y' need not be legal? THE ARGUMENT. (1) WINDOWS. pairs.py's (1): where y codes a point of some P_m and y' is legal, y' codes y's point iff a bounded integer carry sequence x has delta_t = y_t - y'_t = x_t - (x_(t+1) + ... + x_(t+d)) and first window sum 0; its windows W_t = (x_t, ..., x_(t+d-1)) step by the new carry c = 2 w_1 - sum w - delta, and the new window sums to w_1 - delta. (2) THE SIGN BOX. On such a path every carry is a linear form in delta, x_t = sum_k g^(t)_k delta_k (real_support.py's g, which carries the first window sum 0), and so is every combination of carries. Under a fixed y each delta_k has one sign: it lies in [0, 1] where y_k = 1 and in [-1, 0] where y_k = 0, whatever y' is, legal or not. So a form with coefficients f_k lies in [-lo, up], up summing f_k over y_k = 1, f positive, and -f_k over y_k = 0, f negative, lo the rest of sum |f_k|. The box holds four kinds of form: a carry x_n; a sum x_n + x_(n+g) and a difference x_n - x_(n+g) of two carries of one window, 1 <= g < d; a window's sum. Each is an integer on a path, so it lies in the integers of its interval. The ends are read in integers: real_support.py's row gh^(t), on the second grid 2^-36 and in units of 2^-58, is within tau_t of g^(t) in l^1 (its (b) and (c), an exact certificate), and an end moves by at most the l^1 distance its form does, so each true end is within the sum of its rows' tau of the end read on the gh rows. (3) ROWS AND PHASES. y has period P and g^(t)_k = h_(k-t) - eps_t h_(k+1), eps_t at most beta^(-t). Two rows t' < t of one phase differ, in the sum of the sizes of their differences, by at most 3 L beta^(-t'): the terms of h below -t', h being geometric in 1/beta there (one root in the disc), and the two eps terms, L = sum |h_m|. So past LATE = 64 a form's ends move by less than KAPPA a row, KAPPA = 3 (||hh||_1 + eta) v^64 a rational at least 3 L beta^(-64), v the upper end of 1/beta's enclosure: 2.4e-13 at d = 2, beta the golden mean and L = 1.894, 6.1e-17 at d = 3 and under 3.2e-18 at d = 4..16. The start window is read on the rows at their own times, 0..d - 1. Every later window is read on the UNION of the rows of its phase, times below LATE + P (a single carry's below LATE + P + d), which holds every later row once each end is moved outward by its SLACK, the sum over its rows of tau_t + KAPPA, before its floor. (4) THE GRAPH. Nodes (W, ph, a'), ph the phase of y and a' the current run of ones of y'; an edge for y' = 0 or 1 that keeps the new window in the box and a' below d. Starts: the windows of the start's box at phase 0, run 0, whose whole sum is held to [0, 0]. The box is finite, so the reach from the starts closes, and the LIVE part is the reached nodes that continue for ever. Every coding of y's point is an infinite path from a start inside the box, so its nodes are live. With y' = y the carries solve the relation at delta = 0, whose bounded solutions are c beta^(-t), and the first window sum 0 leaves c = 0: y itself is the path through the zero window alone. So a live node off the zero window is on a bounded path whose y' is not y, a second coding by (1), whatever the box; and a second coding starts off the zero window or leaves it where y' first differs, the step writing the carry -delta. y's point has one coding iff no live node is off zero. (5) WHAT A VERDICT RESTS ON. With the runs kept, a second coding found is a second coding. None found rests on the box: on (2), on real_support.py's certificate and on (3), no float among them. Each interval is the integers of an enclosure of the true one, so the box holds every coding however wide the slack; the run adds how little it gives away. And "none found" is read beside two words whose second codings are known, through the same box and reach: A^inf, coded also by B^inf, A turned half a period, from the window (0, -1, 0, ..., 0, 1); and the triangle wave's y, whose pair's carries reach floor((d - 1)/4). At d = 16 the wave's reach passes 2 GB and its pair is read against the box alone, step by step (inside). (6) THE RUNS NOT KEPT. (2) asks nothing of y', so with a' not kept the same search reads every 0/1 string carried to y^inf by a bounded carry, first window sum 0. S holds a one at m = d + 2 over the d + 1 zeros at 1..d + 1; x = e_m has delta = +1 at m and -1 at 2..d + 1, so y' is S with its 0^d 1 at 2..d + 2 made 1^d 0, and its nonzero windows are e_(m-t+1) at t = 3..d + 2: THE EXCURSION, d nodes, a finite carry 0^d 1 <-> 1^d 0 that returns to the zero window. A has no one over d zeros. THE ENGINE. kappa is (3)'s rational; gh_rows the rows gh^(t) as a matrix of integers over 2^58 and what each is owed, tau_t + KAPPA in those units, rounded up, a d whose d rows could sum past int64 refused (d >= 32); totals and ends read (2)'s ends of every row of a matrix of forms, exact; box_ends builds the four kinds of form, each with its slack; whole moves an interval's ends outward by its slack and takes its integers; union joins the rows of a phase and counts the rows before LATE that hold an integer their phase's late row lacks; table is the box in integers, "row" for the start and "ph" for the rest, with near, the ends whose enclosure holds an integer, spare, the least distance of any other enclosure from one, and slack, the largest. starts builds the start windows a place at a time; cuts_at lists, for each phase of a step, what the window it enters is held to; after is one step of a layer of nodes on arrays; keys and unkey write a node as an integer and back, keys refusing a base and a d whose integers pass 2^62; reach is the breadth from the starts, peel the live part; read is one word through all of it. walk lists a known pair's nodes by pairs.step on tuples, inside reads whether the box holds its start and how many of its steps, excursion lists (6)'s nodes for any word, zero_sum the nonzero zero-sum windows of {-1, 0, 1}^d, a_pair and wave_pair the two known pairs. THE STAGES, bare (python fixed_y.py, d = 4..14) and deep (--deep, d = 15, 16). weld every y = [w = 1]^inf, w a nonzero zero-sum window of {-1, 0, 1}^d, d = 3..6: the starts of its second codings and its forks against pairs.product's on the cube's live part, an engine that shares no line with this one. words S^inf, A^inf and the wave's y, legal. A row of sizes each d, and the laws counted over the d read, a count a clause. free S^inf and A^inf with the runs not kept, the laws alike. THE RECORD. weld 6, 18, 50, 140 words at d = 3..6, each agreeing, with 12, 66, 350, 1790 second starts in all (entered from the print). words S^inf: at every d = 4..16 the live part is the 2d + 2 nodes of the zero window, none off it. A^inf: live 8d + 9, 4d + 4 off zero, its second starts the one at (0, -1, 0, ..., 0, 1), the 4d + 4 nodes of its pair live. The wave's y, d = 5..15: its start a second start, the d - 1 nodes of its pair live; live 10, 10, 20, 23, 95, 138, 245, 370, 1088, 1893, 3363, second starts 1, 1, 2, 2, 9, 13, 21, 29, 79, 131, 216. At d = 5..16 three periods of the wave's pair lie inside its y's box. No live node of any of them has two live successors. Nodes reached under S: 34, 58, 101, 228, 705, 1736, 10538, 29439, 82078, 261142, 791917, 2023335, 7068727 at d = 4..16, from 1, 2, 4, 7, 21, 62, 281, 673, 2005, 5253, 14297, 42520, 161595 starts. S's box: a carry's interval holds at most 2 integers at d = 4..6, 3 at 7..11, 4 at 12..15, 5 at 16; two enclosures hold an integer, the first window's sum's two ends, 0 by the rows' construction; 1 to 3 early rows are wider than their phase's late row from d = 7, and each floor is the true end's. Over the 37 tables of this stage no enclosure that holds no integer is within 9.28e-06 of one and no slack passes 3.97e-08 (2.24e-08 to d = 14). free S^inf: at every d = 4..16 the live nodes off zero are the excursion's d and no start among them. A^inf: its pair's 4d + 4 and no excursion. What the record does not read: how many enclosures of A's and the wave's tables hold an integer; that S and A code sigma and -sigma (periodic.py); the wave's live part at d = 16, whose reach passes 2 GB, its table there read by inside alone; any d past 16, where S's reach does. And one part of the box no known pair reads: with the union narrowed to the rows from LATE on every law here still holds (the counts of nodes reached move at 19 rows of d = 7..14, and the hand row of union fails), so that the rows before LATE are joined stands on (3) and that row alone. That LATE is late enough is KAPPA's, a rational in every slack. PREDICTIONS, frozen before this engine was written, the run of the form it replaces saved and read first. P1 S^inf has no second coding at d = 4..10, live 2d + 2. P2 A^inf: live 8d + 9, 4d + 4 off zero, one second start, (0, -1, 0, ..., 0, 1), at d = 4..10. P3 the wave's y at d = 5..10: live 10, 10, 20, 23, 95, 138, second starts 1, 1, 2, 2, 9, 13, its own among them. P4 d = 11..14: S^inf none, live 24, 26, 28, 30; A^inf live 97, 105, 113, 121; the wave's y live 245 at d = 11. P5 d = 15, read by no engine before: S^inf none, live 32; A^inf live 129. P6 the runs not kept: under S the excursion's d nodes and no other, no second start; under A its pair's 4d + 4. P7 the weld of the weld stage. P8 d = 4..12 inside 60 s and 512 MB, d = 14 inside ten minutes and 2 GB. KILL of the route: a count of P1 to P4, P6 or P7 off, or d = 11 outside the 512 MB guard. KILL of sigma's one coding: a second coding of S^inf at any d; no second coding counts only beside A's pair and the wave's own pair live at that d, through the same box and reach. Frozen before the exact ends, the tables of the box they replace saved first (its ends real_support's g in floating point by the roots, moved outward by 1e-9): E1 every table, the 103 distinct words the bare run builds one for (two hand rows' among them) and 6 of --deep, equal to that box's entry for entry. E2 near, a table: that box's count of ends within 1e-9 of an integer (2, 8 or 12 a table, 222 in all; 12 for --deep). E3 every row of the record and every law unchanged. E4 the largest slack under 5e-8 to d = 14 and under 1e-7 at 15, 16; the least spare of the bare run in [9.2e-6, 9.3e-6], --deep's at least 5.0e-5. E5 the bare run under 20 s and 512 MB, --deep under 60 s and 2 GB. KILL of the exact ends as that record's: a table of E1 differing, or near above that box's at a table. FINDINGS. Neither KILL fired. P1 to P3, P6, P7 and P4 to d = 12 held at the first run, on the box as frozen; P8 missed there, 515.9 MB at d = 4..12, and holds on the box kept, which reads d = 4..14 inside the guard; P4 at d = 13, 14 and P5 were first read on the box kept, and held. d = 16 was not predicted and reads as 15 does, but short of the frozen control: the wave's own pair is not read live there, only inside its box. The box changed twice after the first run, which the predictions do not see, the live part being the same in every box that holds the codings. As frozen it held each carry and each window sum: every count as predicted at d = 4..12, 3364022 nodes reached under S at d = 12. With every sum of consecutive carries of a window: 2252062. With every sum and difference of two carries, the form kept: 82078, the bare run inside 512 MB to d = 14. Starts walked a chunk at a time were tried between and cut: one chunk of 20000 starts reached over 32 million nodes at d = 14, the dead part of the graph being one mass that most starts reach. LATE went from 40 to 64 when the hand row at d = 2 failed at 1e-9, a late row there being 2.5e-8 from its limit. And three hand values were wrong by hand: a start list one window short, which its check failed on, and two met before any run, the live count at d = 2 (the pair's start is a node again at run 1) and a case of union. Changed on later readings: (1) names what its converse asks, y a coding and y' legal; (4) says a second coding may start off the zero window; (3)'s bound is the number computed; keys refuses a key past 2^62; inside returns the start's verdict apart from the steps'; the weld counts its words' second starts; the excursion has a hand row of a one over just d zeros; A's law with the runs not kept lost a clause that read the word and not the engine. The exact ends. Their KILL missed: read once against the saved tables of the box they replace, before it was cut, "TABLES: 103 of 103 equal, 248358 integers read; near equal at 103" and, for --deep, "6 of 6 equal, 52170 integers read; near equal at 6". E2 to E5 held: every row and law of the record as it was, no slack past 2.24e-08 to d = 14 or 3.97e-08 at 16, the least spare 9.28e-06 and --deep's 5.06e-05, the walls in the run record. Two hand values of the freeze were wrong by hand: the guard was to refuse d = 17 and refuses d = 32, a row's entry staying under 2^58 + 2^42 and int64 ending at 2^63; and KAPPA was given for d rows where a row was meant (4.8e-13 for 2.4e-13 at d = 2, 1.1e-17 for 6.1e-17 at d = 3), which a reader of the draft found. KAPPA's control was frozen without its first count, entered from the first print: neither of row 8's ends holds its limit by tau alone. That reader's other rulings: a hand row for x_0 + x_1, which no row read; a bit at 2^31 in ends' toy; "each floor is the true end's" kept to S's tables, where near is counted. Sixteen breaks by hand were listed: fourteen fail the hand row named for them (a slack a row short, a first row counted twice, KAPPA dropped or a power of u less, whole inward at either end, y turned a place, the guard's budget doubled, lo given up's parts, a half of totals shifted, the certificate on the default grids, a window's form a row short, the difference read as a sum, the union narrowed to its late rows, which fails union's row and no law); near at a distance of exactly 0 moves no line, no enclosure of a table ending on an integer; and kappa on the lower end of 1/beta's enclosure passed unseen, 2^-64 of u moving no unit, until the control read kappa against sqrt 5's upper end. Twelve breaks were listed before the first run and twelve more written for the box kept (its pairs' tables, gaps and phases, inside's start). Run with the stop after the hand rows lifted, each fails a check. As listed, the starts read on the phase table and the union narrowed to late rows were to move no verdict: the first crashes in the hand rows, and the second is the narrowing named above, with the window's sum not held after the start the third that moves counts of nodes reached and no law. Every single-token fault of the engine and the stages was run through the bare run (426: 397 fail a check, 4 loop without end, 25 print the same lines). The 25: a_pair's B past the period walk reads (2); gh_rows' guard at equality, its margin doubled, and a matrix some zero columns wider (3); keys' guard at equality (1); in reach, a base one too wide, a third column of successors, the fillers for no successor and no id, and one of two equal lengths (5); the weld's words complemented, which the family's totals do not tell apart (1); the wave's top d, which --deep reads, and the two bars of the tables' law, at equality and moved to a nearby value (6); starts' partial sums one entry long (2); near and spare at a distance of exactly 0 or one unit, where no enclosure ends (4); walk's cap, never met (1). RUN RECORD. python fixed_y.py: 61 of 61 checks, 8.9 s, peak commit 200.3 MB under a 512 MB guard. --deep: 30 of 30, 38.1 s, 967.5 MB under a 2048 MB guard. On the floating ends: 57 of 57 checks, 9.2 s, peak commit 203.3 MB under a 512 MB guard. --deep: 26 of 26, 37.5 s, 966.6 MB under a 2048 MB guard. The form before that read the same graph in a floating box in eigen-coordinates: polygon sides widened by 1e-7, a cut by y's own tail sums at each phase, 300 or 1000 joint cuts in complex directions drawn from a seed, the starts enumerated under a slack by linear programming, a two-step lookahead. Its bare run, d = 4..10, was 52 checks in 899.7 s at 215.0 MB; d = 11..13 took 576.1 s behind a flag and d = 14 750.6 s at 821.8 MB, S reaching 35831, 174114, 839232 and 4745652 nodes at d = 11..14 where this box reaches 29439, 82078, 261142 and 791917. Every live count it printed is this record's: S 2d + 2 and A 8d + 9 at d = 4..14, the wave's 10, 10, 20, 23, 95, 138 and 245. Its arm with every carry and window sum held to max(1, floor((d - 1)/4)) left with it, the box asking no carry bound; so did its plants, which are the hand rows and the breaks here, the wave at a cap one short, which missed as first posed, among them. Of its frozen predictions, S^inf single past d = 11 is the words stage; a reach growing 4 to 8 times a d missed there at d = 5 and 7, and S's grows 2.5 to 3.5 times here at d = 11..16; the two that priced its joint cuts left with them. Two scripts read through that box and left with it. One read S^inf with legality dropped at d = 4..13, the free stage here, its kill, a live node off the excursion, missing there and here; its controls checked in floating point that the box's sides, built over legal strings, hold every 0/1 string, which (2) needs no check for. The other read the largest carry over the nodes the sampled cuts left reachable, 1, 1, 1, 1, 1, 2, 2, 2, 3 at d = 4..12, a property of those cuts: its kill, the carry rising with d, fired, and both its guesses failed. USAGE. python fixed_y.py runs the bare stages; --deep reads d = 15, 16 (about 40 s, 1 GB). """ import math import os import sys import time from fractions import Fraction os.environ.setdefault("OPENBLAS_NUM_THREADS", "1") import numpy as np # noqa: E402 import real_support as rs # noqa: E402 from pairs import (legal_live, product, relaxed, step, wave, # noqa: E402 words) LATE = 64 CAP = 2 QE, W = 36, 16 UNIT = 1 << rs.QH + W # ------------------------------------------------------------ the sign box def kappa(c, d, late): """A rational at least 3 L u^late, which two rows of one phase at times late and later differ by in l^1, at most: (3).""" return 3 * (c["norm"] + c["eta"]) * rs.root(d)[1] ** late def gh_rows(d, n): """real_support's rows gh^(t), t < n, on the second grid 2^-QE: an int64 matrix of numerators over UNIT, and what each row's ends are owed, tau_t + KAPPA in units, rounded up. A d whose d rows could sum past int64 is refused.""" if d * ((1 << rs.QH + W) + (1 << rs.QH)) >= 1 << 63: raise OverflowError(f"d = {d}: a window's rows pass int64") c = rs.certificate(d, n, QE, W) G = np.zeros((n, len(c["A"]) - c["nb"] + n), np.int64) for t in range(n): v = rs.row(c["A"], c["nb"], t, c["E"][t], QE, W) G[t, :len(v)] = v k = kappa(c, d, LATE) return G, np.array([math.ceil((tau + k) * UNIT) for tau in c["tau"]], dtype=object) def totals(M): """The exact sum of each row of an int64 matrix of entries >= 0, in two halves: Python ints.""" return ((M >> 31).sum(axis=1).astype(object) << 31) \ + (M & rs.MASK).sum(axis=1).astype(object) def ends(F, one): """(up, lo) of each row of F under the mask one, y's ones: up takes the row's positive part at the ones and its negative part at the zeros, lo the rest.""" pos, neg = np.maximum(F, 0), np.maximum(-F, 0) return totals(np.where(one, pos, neg)), totals(np.where(one, neg, pos)) def box_ends(d, y): """The sign box's ends under y^inf from the rows gh, exact, as (up, lo, slack) in units: the true form lies in [-lo - slack, up + slack], slack the sum of what its rows are owed. "one": the carry x_n, n < T + d, T = LATE + len(y). "sum" and "dif": x_n + x_(n+g) and x_n - x_(n+g) at [g, n], 1 <= g < d, n < T (row g = 0 unused). "all": the sum of the window at t, x_t + ... + x_(t+d-1), t < T.""" T = LATE + len(y) G, sl = gh_rows(d, T + d) one = rs.periodic(list(y), G.shape[1]) == 1 out = {"one": ends(G, one) + (sl,)} for kind, sign in (("sum", 1), ("dif", -1)): up, lo = np.zeros((d, T), object), np.zeros((d, T), object) for g in range(1, d): up[g], lo[g] = ends(G[:T] + sign * G[g:T + g], one) out[kind] = (up, lo, np.array([sl[:T] + sl[g:T + g] for g in range(d)])) out["all"] = ends(sum(G[s:s + T] for s in range(d)), one) + ( sum(sl[s:s + T] for s in range(d)),) return out def whole(lo, up, slack, unit=UNIT): """The integers of [-lo, up] widened by slack at each end, all three in units: its least and its largest, arrays.""" return ((-((lo + slack) // unit)).astype(np.int64), ((up + slack) // unit).astype(np.int64)) def off_integer(v, slack, unit=UNIT): """How far each enclosure [v - slack, v + slack] lies from the nearest integer, in units: 0 or less where it holds one.""" r = v % unit return np.minimum(r, unit - r) - slack def union(a, b, P, late): """Rows of integer intervals (least a, largest b, time on the last axis) joined over each class of times mod P: the least and largest by phase, and how many rows before the time late hold an integer their phase's row at late or just past lacks.""" lo = np.stack([a[..., ph::P].min(axis=-1) for ph in range(P)], axis=-1) hi = np.stack([b[..., ph::P].max(axis=-1) for ph in range(P)], axis=-1) at = late + (np.arange(late) - late) % P wider = (a[..., :late] < a[..., at]) | (b[..., :late] > b[..., at]) return lo, hi, int(wider.sum()) def table(d, y): """The sign box in integers. For each kind of box_ends: "row", the least and largest integer of each row, read at the start; "ph", the same joined over the times of a phase, read after it. near: the ends whose enclosure holds an integer; spare: the least distance of any other enclosure from one; slack: the largest; early: union's count, summed.""" P = len(y) tb = {"row": {}, "ph": {}, "early": 0, "slack": Fraction(0)} dist = [] for kind, (up, lo, sl) in box_ends(d, y).items(): if kind in ("sum", "dif"): up, lo, sl = up[1:], lo[1:], sl[1:] a, b = whole(lo, up, sl) ulo, uhi, early = union(a, b, P, LATE) tb["row"][kind], tb["ph"][kind] = (a, b), (ulo, uhi) tb["early"] += early tb["slack"] = max(tb["slack"], Fraction(int(sl.max()), UNIT)) dist += [off_integer(up, sl).ravel(), off_integer(lo, sl).ravel()] dist = np.concatenate(dist) tb["near"] = int(sum(1 for v in dist if v <= 0)) tb["spare"] = Fraction(int(min(v for v in dist if v > 0)), UNIT) return tb def starts(row, d): """The windows of the start's box, a row each, built a place at a time from the rows at their own times: place i in its interval, its sum and difference with each earlier place j in theirs (row j, gap i - j), a partial sum kept while the places left can still bring it into the whole window's interval, which is [0, 0], the first window sum.""" (a1, b1), (as_, bs), (ad, bd), (az, bz) = (row[k] for k in ( "one", "sum", "dif", "all")) least = [int(a1[i:d].sum()) for i in range(d + 1)] most = [int(b1[i:d].sum()) for i in range(d + 1)] W = np.zeros((1, 0), dtype=np.int16) s = np.zeros(1, dtype=np.int64) for i in range(d): vals = np.arange(a1[i], b1[i] + 1, dtype=np.int16) n = len(W) W = np.concatenate([np.repeat(W, len(vals), axis=0), np.tile(vals, n)[:, None]], axis=1) s = np.repeat(s, len(vals)) + np.tile(vals, n) j = np.arange(i) g = i - 1 - j # the gap i - j, less 1 plus = W[:, :i] + W[:, i:] minus = W[:, :i] - W[:, i:] keep = ((s + least[i + 1] <= bz[0]) & (s + most[i + 1] >= az[0]) & ((plus >= as_[g, j]) & (plus <= bs[g, j])).all(axis=1) & ((minus >= ad[g, j]) & (minus <= bd[g, j])).all(axis=1)) W, s = W[keep], s[keep] return W.astype(np.int8) def cuts_at(ph, d, P): """What the window entered at t + 1 is held to, t the time of the step, by t mod P: its new carry x_n, n = t + d, the sums and differences x_(n-g) +- x_n by place (place k of the new window is n - g, g = d - 1 - k), and its whole sum; each a least and a largest.""" (a1, b1), (as_, bs), (ad, bd), (az, bz) = (ph[k] for k in ( "one", "sum", "dif", "all")) out = [] for t in range(P): k = np.arange(d - 1) g = d - 2 - k # the gap d - 1 - k, less 1 m = (t + 1 + k) % P n = (t + d) % P out.append(((a1[n], b1[n]), (as_[g, m], bs[g, m]), (ad[g, m], bd[g, m]), (az[(t + 1) % P], bz[(t + 1) % P]))) return out # ---------------------------------------------------------------- the reach def keys(W, a, low, base): """Nodes as integers: the window's entries less low as digits in base, w_1 high, then the run as a digit in base d. Refused where such an integer could pass 2^62.""" d = W.shape[1] if base ** d * d >= 2 ** 62: raise OverflowError("a node's key passes 2^62") k = np.zeros(len(W), dtype=np.int64) for j in range(d): k = k * base + (W[:, j].astype(np.int64) - low) return k * d + a def unkey(k, low, base, d): """keys undone: the window as a tuple, and the run.""" a, q = int(k % d), int(k // d) w = [] for _ in range(d): w.append(q % base + low) q //= base return tuple(reversed(w)), a def after(W, a, yt, y2, cut, legal): """One step of every node (W, a) of a layer when y reads yt and y' reads y2: delta = yt - y2, the new carry c = 2 w_1 - sum w - delta, the new window held to cut (cuts_at), the run of y' below d when legal (not kept when not). Returns the rows kept, their new windows and runs.""" d = W.shape[1] (lo1, hi1), (los, his), (lod, hid), (loz, hiz) = cut W16 = W.astype(np.int16) c = 2 * W16[:, 0] - W16.sum(axis=1, dtype=np.int16) - (yt - y2) rest = W16[:, 1:] plus, minus = rest + c[:, None], rest - c[:, None] z = W16[:, 0] - (yt - y2) # the new window's sum ok = ((c >= lo1) & (c <= hi1) & (z >= loz) & (z <= hiz) & ((plus >= los) & (plus <= his)).all(axis=1) & ((minus >= lod) & (minus <= hid)).all(axis=1)) a1 = a + 1 if (legal and y2) else np.zeros(len(W), dtype=np.int64) if legal: ok &= a1 < d i = np.flatnonzero(ok) return (i, np.concatenate([rest[i], c[i, None]], axis=1).astype(np.int8), a1[i]) def reach(d, y, tb, legal=True): """Breadth from the start windows at phase 0 through the box: every node (W, ph, a') a start reaches, numbered as met, the starts first. Returns the number of starts, each node's key and phase, each node's two successors (by y' = 0, 1; -1 for none), and the keys' low and base, taken off the carries' intervals by phase, which join every row, the start's among them.""" P = len(y) low = int(tb["ph"]["one"][0].min()) base = int(tb["ph"]["one"][1].max()) - low + 1 cuts = cuts_at(tb["ph"], d, P) W = starts(tb["row"], d) a = np.zeros(len(W), dtype=np.int64) k = keys(W, a, low, base) n0 = total = len(W) order = np.argsort(k) seen = [None] * P seen[0] = (k[order], order) allk, allph, succ = [k], [np.zeros(n0, dtype=np.int16)], [] t = 0 while len(W): ph1 = (t + 1) % P out = np.full((len(W), 2), -1, dtype=np.int64) parts = [after(W, a, y[t % P], y2, cuts[t % P], legal) for y2 in (0, 1)] src = np.concatenate([p[0] for p in parts]) col = np.concatenate([np.full(len(p[0]), y2, dtype=np.int64) for y2, p in enumerate(parts)]) W1 = np.concatenate([p[1] for p in parts]) a1 = np.concatenate([p[2] for p in parts]) k1 = keys(W1, a1, low, base) ids = np.full(len(k1), -1, dtype=np.int64) if seen[ph1] is not None: sk, si = seen[ph1] pos = np.minimum(np.searchsorted(sk, k1), len(sk) - 1) hit = sk[pos] == k1 ids[hit] = si[pos[hit]] fresh = ids < 0 uk, first, inv = np.unique(k1[fresh], return_index=True, return_inverse=True) nid = total + np.arange(len(uk)) ids[fresh] = nid[inv] out[src, col] = ids succ.append(out) if seen[ph1] is None: seen[ph1] = (uk, nid) else: mk = np.concatenate([seen[ph1][0], uk]) mi = np.concatenate([seen[ph1][1], nid]) o = np.argsort(mk) seen[ph1] = (mk[o], mi[o]) W, a = W1[fresh][first], a1[fresh][first] allk.append(uk) allph.append(np.full(len(uk), ph1, dtype=np.int16)) total += len(uk) t += 1 return (n0, np.concatenate(allk), np.concatenate(allph), np.concatenate(succ), low, base) def peel(succ): """The nodes that continue for ever: those with no successor left are struck until none is. Returns the nodes left and, of them, those with two successors left.""" alive = np.ones(len(succ), dtype=bool) ids = np.arange(len(succ)) while True: t = succ[ids] deg = ((t >= 0) & alive[np.maximum(t, 0)]).sum(axis=1) if deg.all(): return ids, ids[deg == 2] alive[ids[deg == 0]] = False ids = ids[deg > 0] def read(d, y, legal=True): """One word through the box, the reach and the peel. Returns the table's near, spare, slack and early, the widest interval of a single carry, the number of starts, of nodes reached and of live nodes, the live nodes off the zero window as (ph, a', w), the live starts among them, and the number of live nodes with two live successors.""" tb = table(d, y) n0, k, ph, succ, low, base = reach(d, y, tb, legal) left, two = peel(succ) node = {int(i): (int(ph[i]),) + unkey(k[i], low, base, d)[::-1] for i in left} off = {i: v for i, v in node.items() if any(v[2])} return {"near": tb["near"], "spare": tb["spare"], "early": tb["early"], "slack": tb["slack"], "width": int((tb["ph"]["one"][1] - tb["ph"]["one"][0]).max()) + 1, "starts": n0, "reached": len(k), "live": len(node), "off": sorted(off.values()), "second": sorted(v[2] for i, v in off.items() if i < n0), "forks": len(two)} # ---------------------------------------------- what the reads are set against def walk(y, y2, w0, n, legal=True): """The nodes (ph, a', w) of the pair (y^inf, y2^inf) from the start w0 over n steps, by pairs.step on tuples.""" out, w, a = [], tuple(w0), 0 for t in range(n): out.append((t % len(y), a, w)) w = step(w, y[t % len(y)] - y2[t % len(y2)], 10 ** 6) a = a + 1 if (legal and y2[t % len(y2)]) else 0 return out def inside(d, y, y2, w0, n): """The pair (y^inf, y2^inf) from w0 against the box of y: whether the start is one of starts' windows, and how many of its first n steps after keeps, counted until one is cut.""" tb = table(d, y) cuts = cuts_at(tb["ph"], d, len(y)) W = np.array([w0], dtype=np.int8) a = np.zeros(1, dtype=np.int64) first = bool((starts(tb["row"], d) == W).all(axis=1).any()) kept = 0 for t in range(n): i, W, a = after(W, a, y[t % len(y)], y2[t % len(y2)], cuts[t % len(y)], True) if not len(i): break kept += 1 return first, kept def excursion(d, y): """The nonzero nodes (ph, 0, w) of y^inf with the carry e_m at a place m where y holds a one over d zeros, cyclically.""" P, out = len(y), set() for m in range(P): if y[m] == 1 and all(y[(m - j) % P] == 0 for j in range(1, d + 1)): for t in range(m - d + 1, m + 1): out.add((t % P, 0, tuple(int(j == m - t) for j in range(d)))) return out def zero_sum(d): """The nonzero zero-sum windows of {-1, 0, 1}^d.""" out = [()] for _ in range(d): out = [w + (v,) for w in out for v in (-1, 0, 1)] return [w for w in out if sum(w) == 0 and any(w)] def a_pair(d): """A, its other coding B (A turned half a period) and the start of their pair, E_0 = -e_3 as a window.""" A = words(d)[1] return A, A[2 * d + 2:] + A[:2 * d + 2], (0, -1) + (0,) * (d - 3) + (1,) def wave_pair(d): """The wave's two words and its start window.""" x, dl, _ = wave(d) return ([int(v == 1) for v in dl], [int(v == -1) for v in dl], tuple((x + x)[:d])) # ------------------------------------------------------------------ stages def stage_weld(ds): """Every y = [w = 1]^inf, w a nonzero zero-sum window of {-1, 0, 1}^d: the second starts and forks here against pairs.product's on the cube's live part.""" got = {} for d in ds: R = relaxed(d, CAP) L, nxt = legal_live(R, d, CAP) ws = zero_sum(d) same = seconds = 0 for w in ws: y = [int(v == 1) for v in w] r = read(d, y) same += (r["second"], r["forks"]) == product(R, L, nxt, d, CAP, [], y) seconds += len(r["second"]) got[f"d = {d}: words, agreeing, second starts in all"] = ( len(ws), same, seconds) return got, {}, None def among(own, r): """How many nodes of a known pair are live off zero in a read.""" return sum(1 for v in own if v in set(r["off"])) def stage_words(ds): """S^inf, A^inf and the wave's y through the box, legal: a row of sizes each d (S: starts, reached, its box's widest carry, real ends on an integer, early rows wider; A: starts, reached; wave: starts, reached, live, off zero, second starts), and the laws as counts over the d read, a count a clause.""" got, laws = {}, {} s_law, a_law, w_law, spare, slack = [0] * 3, [0] * 5, [0] * 3, [], [] waves = held = 0 for d in ds: S = words(d)[0] A, B, w0 = a_pair(d) r = read(d, S) spare.append(r["spare"]) slack.append(r["slack"]) got[f"d = {d}: S"] = (r["starts"], r["reached"], r["width"], r["near"], r["early"]) for i, ok in enumerate((r["live"] == 2 * d + 2, len(r["off"]) == 0, r["forks"] == 0)): s_law[i] += ok r = read(d, A) spare.append(r["spare"]) slack.append(r["slack"]) got[f"d = {d}: A"] = (r["starts"], r["reached"]) for i, ok in enumerate((r["live"] == 8 * d + 9, len(r["off"]) == 4 * d + 4, r["second"] == [w0], among(walk(A, B, w0, len(A)), r) == 4 * d + 4, r["forks"] == 0)): a_law[i] += ok if d >= 5: y, y2, w0 = wave_pair(d) held += inside(d, y, y2, w0, 3 * len(y)) == (True, 3 * len(y)) if 5 <= d <= WAVE_TOP: r = read(d, y) spare.append(r["spare"]) slack.append(r["slack"]) waves += 1 got[f"d = {d}: wave"] = (r["starts"], r["reached"], r["live"], len(r["off"]), len(r["second"])) for i, ok in enumerate((w0 in r["second"], among(walk(y, y2, w0, len(y)), r) == d - 1, r["forks"] == 0)): w_law[i] += ok laws["S, the d read; of them: live 2d + 2, none off zero, no fork"] = ( len(ds), *s_law) laws["A, the d read; of them: live 8d + 9, 4d + 4 off zero, its second " "starts the one at -e_3, its pair's 4d + 4 nodes live, no fork"] = ( len(ds), *a_law) laws["wave, the d read; of them: its start a second start, its pair's " "d - 1 nodes live, no fork"] = (waves, *w_law) laws["the wave's pair, the d from 5; of them: three periods of it " "inside its y's box"] = (sum(1 for d in ds if d >= 5), held) laws["tables read; of them: every enclosure holding no integer more " "than 1e-6 from one, every tolerance under 1e-7"] = ( len(spare), sum(1 for v in spare if v > Fraction(1, 10 ** 6)), sum(1 for v in slack if v < Fraction(1, 10 ** 7))) return got, laws, (min(spare), max(slack)) def stage_free(ds): """The runs not kept: S^inf's live nodes off zero against the excursion's, A's against its pair's, as counts over the d read.""" s_law, a_law = [0] * 3, [0] * 2 for d in ds: S = words(d)[0] A, B, w0 = a_pair(d) r = read(d, S, legal=False) ex = excursion(d, S) for i, ok in enumerate((len(r["off"]) == d, len(ex & set(r["off"])) == d, r["second"] == [])): s_law[i] += ok r = read(d, A, legal=False) own = walk(A, B, w0, len(A), legal=False) for i, ok in enumerate((len(r["off"]) == 4 * d + 4, among(own, r) == 4 * d + 4)): a_law[i] += ok return {}, { "S, the d read; of them: d nodes live off zero, the excursion's d " "among them, no second start": (len(ds), *s_law), "A, the d read; of them: 4d + 4 live off zero, its pair's 4d + 4 " "among them": (len(ds), *a_law)}, None # ------------------------------------------------------------------ record S_ROWS = { 4: (1, 34, 2, 2, 0), 5: (2, 58, 2, 2, 0), 6: (4, 101, 2, 2, 0), 7: (7, 228, 3, 2, 2), 8: (21, 705, 3, 2, 1), 9: (62, 1736, 3, 2, 1), 10: (281, 10538, 3, 2, 2), 11: (673, 29439, 3, 2, 1), 12: (2005, 82078, 4, 2, 2), 13: (5253, 261142, 4, 2, 2), 14: (14297, 791917, 4, 2, 1), 15: (42520, 2023335, 4, 2, 2), 16: (161595, 7068727, 5, 2, 3), } A_ROWS = { 4: (2, 72), 5: (3, 120), 6: (4, 225), 7: (8, 491), 8: (26, 1383), 9: (60, 3301), 10: (261, 20481), 11: (791, 57468), 12: (1890, 158095), 13: (5452, 498173), 14: (13676, 1545210), 15: (42729, 3952690), 16: (171096, 13866929), } WAVE_ROWS = { 5: (2, 14, 10, 6, 1), 6: (3, 20, 10, 5, 1), 7: (10, 157, 20, 14, 2), 8: (23, 525, 23, 16, 2), 9: (14, 179, 95, 87, 9), 10: (112, 1859, 138, 129, 13), 11: (296, 5877, 245, 235, 21), 12: (889, 17895, 370, 359, 29), 13: (19224, 755836, 1088, 1076, 79), 14: (64890, 2509052, 1893, 1880, 131), 15: (247992, 8662667, 3363, 3349, 216), } RUNS = {"bare": range(4, 15), "deep": (15, 16)} WAVE_TOP = 15 def recorded(ds): """The rows of the words stage at the d of a run.""" out = {} for d in ds: out[f"d = {d}: S"] = S_ROWS[d] out[f"d = {d}: A"] = A_ROWS[d] if d in WAVE_ROWS: out[f"d = {d}: wave"] = WAVE_ROWS[d] return out RECORD = { "bare": { "weld": { "d = 3: words, agreeing, second starts in all": (6, 6, 12), "d = 4: words, agreeing, second starts in all": (18, 18, 66), "d = 5: words, agreeing, second starts in all": (50, 50, 350), "d = 6: words, agreeing, second starts in all": (140, 140, 1790), }, "words": recorded(RUNS["bare"]), "free": {}, }, "deep": {"words": recorded(RUNS["deep"]), "free": {}}, } LAWS = {"weld": 0, "words": 5, "free": 2} CONTROL_LINES = 17 CHECKS = [] def check(name, ok, detail=""): CHECKS.append(bool(ok)) print(f" [{'PASS' if ok else 'FAIL'}] {name}" + (f" {detail}" if detail else ""), flush=True) def check_hand(name, pairs): hits = sum(1 for got, want in pairs if got == want) check(name, hits == len(pairs), f"{hits} of {len(pairs)} cases") def check_record(run, stage, got): want = RECORD[run][stage] for key in got: ok = got[key] == want.get(key) check(f"{stage}: {key}", ok, f"{got[key]}" + ("" if ok else f", recorded {want.get(key)}")) def section(title): print() print(title) print("-" * len(title), flush=True) def section_hand(): section("HAND") F = Fraction s5 = rs.sqrt5() def holds(v, slack, a, b): """Whether [v - slack, v + slack], in units, holds a + b sqrt 5.""" ends5 = sorted(a + b * r for r in s5) return (F(int(v - slack), UNIT) <= ends5[0] and ends5[1] <= F(int(v + slack), UNIT)) e10, e0 = box_ends(2, [1, 0]), box_ends(2, [0]) (up, lo, sl), (up0, lo0, sl0) = e10["one"], e0["one"] dif, win, two = e10["dif"], e10["all"], e10["sum"] check_hand("the box's ends at d = 2, each enclosure holding its value " "and under 1e-10 wide a side: under (10)^inf row 0, a late " "even row, x_0 - x_1, x_0 + x_1 and the first window's sum; " "row 0 under 0^inf", [(holds(up[0], sl[0], 1, 0), True), (holds(lo[0], sl[0], 0, 0), True), (holds(up[LATE], sl[LATE], 1, F(1, 5)), True), (holds(lo[LATE], sl[LATE], 0, F(1, 5)), True), (holds(dif[0][1, 0], dif[2][1, 0], 2, 0), True), (holds(dif[1][1, 0], dif[2][1, 0], 0, 0), True), (holds(two[0][1, 0], two[2][1, 0], 0, 0), True), (holds(two[1][1, 0], two[2][1, 0], 0, 0), True), (holds(win[0][0], win[2][0], 0, 0), True), (holds(win[1][0], win[2][0], 0, 0), True), (holds(up0[0], sl0[0], F(3, 2), F(-1, 2)), True), (holds(lo0[0], sl0[0], F(-1, 2), F(1, 2)), True), (max(sl[0], sl[LATE], dif[2][1, 0], win[2][0], sl0[0]) < UNIT // 10 ** 10, True)]) def owed(d, ts): """The rows ts' tau and KAPPA in units, each rounded up, from the library's constants and a root of its own.""" c = rs.certificate(d, max(ts) + 1, QE, W) k = 3 * (c["norm"] + c["eta"]) * rs.root(d)[1] ** 64 return sum(math.ceil((c["tau"][t] + k) * UNIT) for t in ts) e3 = box_ends(3, [1, 0, 0]) check_hand("a form's tolerance is its rows' tau and KAPPA: a carry, " "x_0 - x_1 and the first window's sum at d = 2; x_2 + x_4 " "and the window at t = 1 at d = 3", [(sl[5], owed(2, [5])), (dif[2][1, 0], owed(2, [0, 1])), (win[2][0], owed(2, [0, 1])), (e3["sum"][2][2, 2], owed(3, [2, 4])), (e3["all"][2][1], owed(3, [1, 2, 3]))]) c2 = rs.certificate(2, 9, QE, W) tau8 = math.ceil(c2["tau"][8] * UNIT) k8 = math.ceil(kappa(c2, 2, 8) * UNIT) lim = ((up[8], 1, F(1, 5)), (lo[8], 0, F(1, 5))) check_hand("KAPPA at d = 2, late 8: of row 8's two ends, how many " "enclosures hold their limits 1 + 1/sqrt 5 and 1/sqrt 5 by " "tau alone, and with KAPPA; KAPPA at least 3 (norm + eta) " "u^8 at an upper end of u by sqrt 5", [(sum(holds(v, tau8, a, b) for v, a, b in lim), 0), (sum(holds(v, tau8 + k8, a, b) for v, a, b in lim), 2), (kappa(c2, 2, 8) >= 3 * (c2["norm"] + c2["eta"]) * ((s5[1] - 1) / 2) ** 8, True)]) try: gh_rows(32, 1) refused = False except OverflowError: refused = True check_hand("gh_rows: d = 32 refused, d = 31 read", [(refused, True), (gh_rows(31, 1)[0].shape[0], 1)]) toy = np.array([[-10, 8, -4], [(1 << 62) + (1 << 31), (1 << 62) + 5, -(1 << 62)]]) tu, tl = ends(toy, np.array([False, False, True])) cu, cl = ends(toy, np.array([True, True, False])) check_hand("ends: (-10, 8, -4) under (0, 0, 1) and its complement; a " "row summing past 2^63, a bit at 2^31 in it", [((tu[0], tl[0]), (10, 12)), ((cu[0], cl[0]), (12, 10)), ((tu[1], tl[1]), (0, 3 * (1 << 62) + (1 << 31) + 5)), ((cu[1], cl[1]), (3 * (1 << 62) + (1 << 31) + 5, 0))]) f = lambda lo, up: tuple(int(v[0]) for v in whole( np.array([lo], object), np.array([up], object), 1, 1000)) check_hand("whole, a unit of 1000 and 1 owed: an end one under an " "integer keeps it, two under does not", [(f(300, 999), (0, 1)), (f(999, 200), (-1, 0)), (f(500, 998), (0, 0)), (f(1500, 2250), (-1, 2))]) ua, ub = np.array([[1, 5, 0, 0, 0, 0]]), np.array([[1, 5, 1, 2, 0, 1]]) lo_, hi_, early = union(ua, ub, 2, 2) check_hand("union, period 2, late from time 2: phase 0 joins times 0, " "2, 4, phase 1 times 1, 3, 5; time 1 holds a 5 its late row " "lacks, time 0 a 1 its late row holds", [((lo_.tolist(), hi_.tolist(), early), ([[0, 0]], [[1, 5]], 1))]) wide2 = np.full((2, 3), -9), np.full((2, 3), 9) def box3(one, sums=None, difs=None): a1, b1 = (np.array(v) for v in zip(*one)) pair = lambda cut: wide2 if cut is None else tuple( np.where((np.arange(2)[:, None] == cut[0]) & (np.arange(3) == cut[1]), cut[2 + i], w) for i, w in enumerate(wide2)) return {"one": (a1, b1), "sum": pair(sums), "dif": pair(difs), "all": (np.array([0]), np.array([0]))} g = lambda row: [tuple(int(v) for v in w) for w in starts(row, 3)] full = [(-1, 1)] * 3 check_hand("starts at d = 3, the whole sum held to 0: a box; x_0 - " "x_1 held to [1, 2]; x_0 + x_2 held to 0; a box no window " "fits", [(g(box3([(-1, 1), (-1, 1), (0, 0)])), [(-1, 1, 0), (0, 0, 0), (1, -1, 0)]), (g(box3(full, difs=(0, 0, 1, 2))), [(0, -1, 1), (1, -1, 0), (1, 0, -1)]), (g(box3(full, sums=(1, 0, 0, 0))), [(-1, 0, 1), (0, 0, 0), (1, 0, -1)]), (g(box3([(1, 1), (0, 1), (0, 1)])), [])]) rows = [((0, -1, 0, 1), 1, 0), ((1, -1, 0, 0), 0, 1), ((2, -1, 1), 1, 1), ((0, 0, 0), 0, 1), ((-1, 2, 0, 1), 1, 0)] free = lambda n: ((-9, 9), (np.full(n - 1, -9), np.full(n - 1, 9)), (np.full(n - 1, -9), np.full(n - 1, 9)), (-9, 9)) hits = [] for w, yt, y2 in rows: _, W1, _ = after(np.array([w], dtype=np.int8), np.zeros(1, dtype=np.int64), yt, y2, free(len(w)), True) hits.append((tuple(int(v) for v in W1[0]), step(w, yt - y2, 9))) check_hand("after: a step on an array is pairs.step on the tuple, and " "by hand", hits + [(hits[0][0], (-1, 0, 1, -1)), (hits[2][0], (-1, 1, 2))]) def cut(legal, a, **held): c = dict(zip(("one", "sum", "dif", "all"), free(3))) for kind, v in held.items(): c[kind] = v return [len(after(np.array([(1, 0, -1)], dtype=np.int8), np.array([a]), 1, y2, tuple(c.values()), legal)[0]) for y2 in (0, 1)] n9 = np.full(2, 9) check_hand("after: from (1, 0, -1) under a one, y' = 0 writes (0, -1, " "1) and y' = 1 writes (0, -1, 2); the carry's interval, the " "window's, a sum's, a difference's and the run each cut one", [(cut(True, 0), [1, 1]), (cut(True, 0, one=(-9, 1)), [1, 0]), (cut(True, 0, all=(1, 9)), [0, 1]), (cut(True, 0, sum=(np.array([-9, 1]), n9)), [0, 1]), (cut(True, 0, dif=(np.array([-1, -9]), n9)), [1, 0]), (cut(True, 2), [1, 0]), (cut(False, 2), [1, 1])]) ph3 = {"one": (np.arange(3), np.arange(3) + 10), "sum": (np.arange(6).reshape(2, 3) + 20, np.arange(6).reshape(2, 3) + 30), "dif": (np.arange(6).reshape(2, 3) + 40, np.arange(6).reshape(2, 3) + 50), "all": (np.arange(3) + 60, np.arange(3) + 70)} c1 = cuts_at(ph3, 3, 3)[1] check_hand("cuts_at, d = 3, P = 3, the step at t = 1: the new carry is " "x_4, phase 1; place 1 of the new window is x_2, gap 2, " "place 2 is x_3, gap 1; the window entered is phase 2", [(c1[0], (1, 11)), (c1[1][0].tolist(), [25, 20]), (c1[1][1].tolist(), [35, 30]), (c1[2][0].tolist(), [45, 40]), (c1[3], (62, 72))]) y5, y5b, w5 = wave_pair(5) out5 = inside(5, y5, y5b, (w5[0] + 1,) + w5[1:], 4) stay5 = inside(5, y5, y5, w5, 8) check_hand("inside: the wave's pair at d = 5, its start held and its 4 " "steps kept; a start off by one is not held; with y' = y " "from the wave's start the start is held and a step is cut", [(inside(5, y5, y5b, w5, 4), (True, 4)), (out5[0], False), (stay5[0], True), (stay5[1] < 8, True)]) succ = np.array([[1, -1], [2, -1], [-1, -1], [3, -1], [3, -1], [0, 3], [3, 4]]) left, two = peel(succ) check_hand("peel: a chain to a dead end goes, a loop and what feeds it " "stay, one node with two successors", [(left.tolist(), [3, 4, 5, 6]), (two.tolist(), [6])]) w = (1, -2, 0, 2) k = keys(np.array([w], dtype=np.int8), np.array([3]), -2, 5) def refused(base): try: keys(np.zeros((1, 16), dtype=np.int8), np.zeros(1), 0, base) except OverflowError: return True return False check_hand("keys and unkey: a window and its run, there and back; at " "d = 16 base 12 fits 2^62 and base 13 is refused", [(int(k[0]), ((((3 * 5 + 0) * 5 + 2) * 5 + 4) * 4 + 3)), (unkey(k[0], -2, 5, 4), (w, 3)), (refused(12), False), (refused(13), True)]) check_hand("the excursion under S at d = 4: phases 3..6, the 1 last to " "first; none under A at d = 4..16; under (1000)^inf at d = " "3, a one over just d zeros, phases 2, 3, 0", [(sorted(excursion(4, words(4)[0])), [(3, 0, (0, 0, 0, 1)), (4, 0, (0, 0, 1, 0)), (5, 0, (0, 1, 0, 0)), (6, 0, (1, 0, 0, 0))]), (sum(len(excursion(d, words(d)[1])) for d in range(4, 17)), 0), (sorted(excursion(3, [1, 0, 0, 0])), [(0, 0, (1, 0, 0)), (2, 0, (0, 0, 1)), (3, 0, (0, 1, 0))])]) check_hand("off_integer, a unit of 1000 and 1 owed: a quarter, a " "tenth under 2, an integer, one and two under 3", [(off_integer(np.array([250, 1900, 2000, 2999, 2998], object), 1, 1000).tolist(), [249, 99, -1, 0, 1])]) r2 = read(2, [1, 0]) r3 = read(3, [1, 0, 0]) check_hand("the engine by hand: (10)^inf at d = 2 has the one second " "start (1, -1), on an end of its box, 3 nodes live off zero " "(its start again at run 1) and 2 on it; (100)^inf at d = 3 " "has two second starts", [(r2["second"], [(1, -1)]), (r2["near"] > 0, True), (r2["off"], [(0, 0, (1, -1)), (0, 1, (1, -1)), (1, 0, (-1, 1))]), (r2["live"], 5), (r3["second"], [(1, -1, 0), (1, 0, -1)])]) def section_stage(run, stage, title, stage_fn, *args): if stage not in RECORD[run]: return t0 = time.time() got, laws, note = stage_fn(*args) section(title) check_record(run, stage, got) for name, counts in laws.items(): check(f"{stage}: {name}", len(set(counts)) == 1, " ".join(str(v) for v in counts)) if note is not None: print(" no other enclosure within %s of an integer; a tolerance " "at most %s" % (rs.dec(note[0], 9, False), rs.dec(note[1], 11, True))) print(" (%.1f s)" % (time.time() - t0), flush=True) def main(): t_all = time.time() run = "deep" if "--deep" in sys.argv else "bare" ds = RUNS[run] section_hand() if not all(CHECKS): print("\nCONTROL FAILED: nothing below is read.") sys.exit(1) lines = CONTROL_LINES + sum(len(RECORD[run][s]) + LAWS[s] for s in RECORD[run]) section_stage(run, "weld", "WELD: second starts against the cube's", stage_weld, range(3, 7)) section_stage(run, "words", "WORDS: S^inf, A^inf and the wave's y, " "legal. S: starts, reached, its box's widest carry, ends " "on an integer, early rows wider. A: starts, reached. " "wave: starts, reached, live, off zero, second starts", stage_words, ds) section_stage(run, "free", "FREE: the runs not kept", stage_free, ds) ran = len(CHECKS) check("every check line of the run printed, this one aside", ran == lines, f"{ran} of {lines}") print() print("%d of %d checks, %.1f s" % (sum(CHECKS), len(CHECKS), time.time() - t_all)) sys.exit(0 if all(CHECKS) else 1) if __name__ == "__main__": main()