walkc.py
Checks: DEGREE: Through its table the inverse dial is a pure-product degree rule; DEGREE: At sixteen cells of depths 17 and 18 the pure law holds rule; DEGREE: Height 1's extremal polynomials are pure products where decided rule; DEGREE: At two cells a polynomial of no pure product ties the pure product rule; observation.
Cited on: DEGREE.
To run it: save walkc.py, with flatten.py, suffixwalk.py beside it; standard library only.
"""walkc.py -- suffixwalk.py's walk with its inner loop compiled: the
least degree d_k(J) of a nonzero multiple of (x - 1)^J of height at
most k, at the cells whose price in Python is hours.
USE. From the folder holding walkc.py, suffixwalk.py and flatten.py,
with gcc on the path (a 64-bit target with __int128); without it a
run prints one line and exits 2. python walkc.py runs the controls;
python walkc.py controls, the longer form of the first; python
walkc.py cell k J walks one cell on four processes, a line at each
of its wider widths,
pricing itself as it goes and stopping where the price passes two
hours, and at a cell of its record or suffixwalk.py's (its RECORD and
DIAL) exits on the
comparison. A cell's widths done are kept in a file under the
system's temporary folder (walkc_runs), named by the build, and read
back by its next run on that build, whose check line says so.
QUESTION. suffixwalk.py decides the dial at J <= 16, k <= 8 but for
(2, 16), priced at 4.80e10 children, and prices depth 17 at k = 1 at
some 6e10, each "a low read" and ten hours or more of one Python
process. Asked: (a) whether the same walk, its node in C on exact
128-bit moments and a fixed-point S, returns suffixwalk.py's counts of
children to the unit and its vectors; (b) at what rate; (c) through it,
d_2(16) and d_1(17), each with its extremal polynomials, read for a
break (a degree under the least pure degree) and, at k = 1, for an
extremal polynomial that is no pure product (the question of the
column's source, Borwein and Mossinghoff, Experiment. Math. 9 (2000)
425-433).
THE ENGINE, as it will be built. suffixwalk.py's rec(), row by row.
Row r is the level that chooses c_r: it holds g_r = G_r^(-1) a(r) and
1 + kappa_r; a node there carries mu, the moments of the suffix above
r (t >= r + 1), and E_(r+1); a child c_r has
E_r = E_(r+1) + (S + c_r (1 + kappa_r))^2 / (1 + kappa_r) - c_r^2,
S = g_r . mu, and dies at E_r > k^2 r + 1e-6 or at an increment above
4 k^2 W. The top coefficient's E is c^2 kappa_(W-1), untested. At the
bottom the prefix on [0, J) is solved in integers.
mu: exact, each entry a signed 128-bit integer.
g_r: each entry rounded to the nearest multiple of 2^-F, F = 128, as
a sign and a magnitude of three 64-bit limbs; 1 + kappa_r the same,
Aq. Python builds the table from suffixwalk.py's Levels, exact
rationals.
N = sum_j Gq_j mu_j + c Aq: exact, in four limbs (two's complement,
256 bits). Its magnitude's two leading nonzero limbs are converted
to doubles and summed, n = (hi 2^64 + lo) scaled by a power of 2;
inc = (n * n) / w, w the double nearest 1 + kappa_r.
The tests are suffixwalk.py's on these doubles, in its order.
Shards: the tree is walked from the top by every process; a node at
level W - P (P the prefix length, an argument; J if that is lower)
is numbered in walk order and entered only by the process owning
its number mod the processes; the levels above are counted by
process 0 alone. A width's shards run four at once, and a width
done is one line appended to a file: a cell resumes at its first
width not in it.
THE HAND ATTACK, the engine's own bound, nothing carried from
suffixwalk.py's (5) or (H5) but the argument's shape. u = 2^-53.
(E1) THE SIZES, every node, true path or not. A suffix of height
<= k has |mu_j| <= k sum_(t<W) C(t, j) = k C(W, j + 1). So mu
fits 128 bits where k C(W, j + 1) < 2^126 for every j < J, and
N fits 256 where sum_j (|Gq_j| + 1) k C(W, j + 1) + k (Aq + 1)
< 2^254 at every row. Both are computed from the table before a
width is walked, and the width refused otherwise. Read before
the freeze (a print of Levels, no walk): at J = 17, W = 186,
k = 1 the largest |Gq_j| has 159 bits (row 17, j = 16), Aq 160,
the sum 237, k C(W, j + 1) 79; at J = 20, W = 95, k = 12: 165,
166, 235 and 71. Three limbs hold Gq, four N.
(E2) THE FIXED POINT. Rounded to nearest, |Gq_j 2^-F - g_j| <=
2^-(F+1), and Aq 2^-F is as near 1 + kappa.
So N 2^-F = N' + eps, N' = S + c (1 + kappa) the true numerator,
|eps| <= delta = 2^-(F+1) k (1 + sum_(j<J) C(W, j + 1)), on any
suffix of height <= k. Read before the freeze: delta = 8.2e-16
at J = 17, W = 186, k = 1; 4.1e-18 at J = 20, W = 95, k = 12.
(E3) THE DOUBLE. The magnitude's two leading limbs drop a part
under 2^-64 of it; each limb's conversion and their sum round
once on nonnegative terms. So n = N 2^-F (1 + t), |t| <= 2.1 u.
w = (1 + kappa)(1 + t'), |t'| <= u (Python's float of a
Fraction is the nearest double). The product and the quotient
round once each. So inc = (N' + eps)^2 / (1 + kappa) times a
factor within 7.3 u of 1.
(E4) A TRUE PATH. On the path of a vector of height <= k every true
E_r is at most k^2 r and the true increment I_r = E_r - E_(r+1)
+ c_r^2 is in [0, k^2 W]; N'^2 = I_r (1 + kappa), 1 + kappa >= 1.
So (N' + eps)^2 / (1 + kappa) is within X = 2 k sqrt(W) delta +
delta^2 of I_r. With delta <= 1e-9 (the engine refuses past it)
inc <= (k^2 W + X)(1 + 7.3 u) < 4 k^2 W, W >= 2: the early kill
never fires on a true path.
(E5) THE PATH'S ERROR. inc is within 7.3 u (k^2 W + X) + X of I_r.
The two additions each round a sum under 2 k^2 W + 1 in size.
So a level adds at most 7.3 u k^2 W + 4.1 u k^2 W + 1.1 X <
12 u k^2 W + 2 X to the error of E while the error stays under
0.4, and the top's two roundings 2.1 u k^2 W. Down a path:
B(J, W, k) = 12 u k^2 W^2 + 2 W X.
A level kills at a float E above k^2 r + 1e-6, the limit itself
rounded by at most u k^2 W. So no vector's suffix is killed
where B + u k^2 W < 1e-6. The engine computes B a width and
refuses a width with B > 2.5e-7. Read before the freeze: B =
4.7e-11 at J = 17, W = 186, k = 1; 1.4e-9 at J = 20, W = 95,
k = 12. The top is never tested, as in suffixwalk.py's (H5): a
level lowers E by at most k^2.
(E6) WHAT IS EXACT. mu, N, the bottom's integer solve; a vector
returned is re-read in Python by J exact sums. What rests on
the bound: every "nothing at this width".
TRANSPLANTS, to be read off the prints: that the two engines decide
every child alike, so the counts agree to the unit (they differ by
some 1e-13 at a level, and a child within that of its limit is rare
among 1e9, never excluded); that a node costs some 150 ns at J = 17
(17 products of 2 by 3 limbs) and a child a third of it at k = 1.
PREDICTIONS, before the engine.
EP1 At depths 12, 13, 14, 15 at k = 1 and at the cells (2, 12),
(3, 13), (8, 15) the engine's d, its children tried over all
widths, and its vectors at the last width are suffixwalk.py's.
EP2 A process tries at least 8e6 children a second at k = 1, J = 16
(suffixwalk.py: 1.6e6), and four processes at least three times
one's rate at a width of 1e8 children or more.
EP3 d_2(16) = 118, the least pure degree: no vector at any width
W <= 118. Its children to width 118: 4.8e10 to 2e11.
EP4 d_1(17) = 185, the least pure degree; every extremal vector a
pure product. Its children to width 185: 6e10 to 3e11.
KILLS, as prints.
EK1 (a bug) "the engine at the record: N of M cells", N < M: a cell
of EP1 whose d, children tried or last width's vectors differ.
EK2 (the plant reads nothing, or the engine does not read its
table whole) "the plant: the engine N, the walk N', unplanted
N''" with N != N' or N' = N''.
EK3 (a finding) "(2, 16): first vector at width W", W <= 118, the
vector printed and re-read by exact sums.
EK4 (a finding) at k = 1, J = 17 the same at W <= 185, or at width
186 an extremal vector that is no pure product.
EKP THE PRICE. A cell's widths run upward; its price is read from
the last three widths' counts and the last width's rate, a whole
width's children over its seconds on four processes, and read
again each ten widths. Priced under ten minutes it runs on;
priced under two hours it runs the same day, the estimate
named; past that the price is the cell's line. A width past
twice its estimate stops the cell.
CONTROLS, frozen before the engine.
EC1 the record: EP1's seven cells, each line "tried" against
suffixwalk.py's RECORD and DIAL, the last width's vectors
against suffixwalk.py's walk run at that width, sorted, and its
kept counts a level against that walk's.
EC2 the plant: one bit of one |Gq_j| of one row flipped in the
table, at depth 12, k = 1. The bit is chosen by suffixwalk.py's
walk on that row's planted rationals, the least bit of a scan
that moves the children tried over depth 12's widths; the
engine on the planted table must print the planted walk's
count, not the record's. The row, the entry and the bit are
named in the record.
EC3 the shards: depth 12 at one process, prefix 1, and at four,
prefix 12: equal counts, equal vectors.
EC4 a break seen, read before any new cell: at (9, 10) the engine's
first vector at width 23, d = 22 under the least pure degree 23,
its count DIAL's 18962.
EC5 the bound: delta and B printed at each cell's widest width, B
under 2.5e-7, the sizes of (E1) under their limits.
CHANGED AFTER THE FREEZE. No frozen line moved. As coded: EC5 reads
the bound at four widths named in main (the last widths of (1, 15),
(8, 15), (1, 17) and (2, 16)), and a cell's own run prints its sizes
at its last width; EC2's scan tries every fourth bit of one entry
chosen before it, row 60's entry 11; the engine has no stop at a
first vector, so a last width is always listed whole; EKP's price is
printed at every width of five seconds or more, and its stop is armed
from a width of thirty seconds, at twice that width's seconds times
the growth, plus sixty. Read after the freeze: (E5)'s middle figure,
4.1 u k^2 W for the two additions, wants k^2 W >= 20; they round sums
under 2 k^2 W + 1/2, so a level adds under 11.3 u k^2 W + u + 1.1 X,
which is under 12 u k^2 W + 2 X from k^2 W >= 2, every width walked.
EP2's second half is frozen at a width of 1e8 children or more and
the rate stage first ran at one of 7.5e7.
Read after the findings were first written: the bare run reads EC1 at
three of its seven
cells, depths 12 and 14 and (2, 12), and the seven under the argument
"controls". (E5)'s two figures read before the freeze, 4.7e-11 and
1.4e-9, are a scratch print's 10 u k^2 W^2 + 2 W X; B as (E5) defines
it and table computes it is 5.4e-11 and 1.7e-9 there. The QUESTION's
"each a low read" is suffixwalk.py's word for (2, 16) alone. EKP's
price is of the widths to the least pure degree: the last width,
listed whole, is not in it. The driver moved after cells ran, the C
never (one build, its tag 01075f34ce8f): (2, 16) and (1, 17) ran at
prefix 12 with the run files beside the script, since moved to the
system's temporary folder;
(1, 18) at prefix 20; then, after the findings, the wait on the
processes
polls each 0.01 s where it polled each 0.2 s, a failed process raises
where it asserted, the driver's cap left, a cell's least pure degree
is computed once, a width of 1e6 children or more prints its line,
and a cell says how many widths it read back from its run file. One
frozen line was reworded for the published form: EKP's cell priced
under two hours "runs the same day"; the frozen line named, in place
of the day, the working sitting.
FINDINGS.
EF1 EP1 holds, EK1 silent: "the engine at the record: 7 of 7
cells". Each cell's d and its children tried over all widths are
suffixwalk.py's record's to the unit (3588285, 77545929, 7668786
and 146387613 at depths 12 to 15; 10385190, 435486933 and
259791858 at (2, 12), (3, 13) and (8, 15)), and at its last
width the vectors, the children and the kept count of every
level are those of suffixwalk.py's walk run there.
EF2 The controls. EC2: "the plant: the engine 3588282, the walk
3588282, unplanted 3588285", the plant bit 76 of |Gq_11| at row
60, depth 12, the least of every fourth bit that moves the
walk's count; bits 0 to 72 move nothing. EC3: "3588285 and
3588285 children, 1 and 1 vectors". EC4: "first vector at width
23, d = 22 under the least pure degree 23, tried 18962". EC5:
B = 2.7e-11 at (1, 15), 2.7e-10 at (8, 15), 5.4e-11 at (1, 17),
width 186, 7.5e-11 at (2, 16), each with delta under 1e-15.
EF3 EP2's first half holds: "rate at (1, 16), width 158, 74671074
children: one process 4.14e+07 a second (1.8 s), four 1.05e+08
(0.7 s), 2.54 times", at prefix 12, its 1.8 s on the 0.2 s
clock, 26 times suffixwalk.py's 1.6e6. Its second half fails at
the prefix 12 that (2, 16) and (1, 17) ran at and holds at a
longer one. On the 0.01 s clock, width 160, 171933825 children
(a scratch loop over run_width): "prefix 12: four processes
1.03e+08 a second (1.66 s), 2.45 times one (4.07 s)", "prefix
20: four processes 1.45e+08 a second (1.18 s), 3.44 times one
(4.07 s)", "prefix 30: four processes 1.52e+08 a second (1.13
s), 3.59 times one (4.07 s)". The default prefix is 20 since, and the rate stage
runs at it: "rate at (1, 16), width 160, 171933825 children: one
process 4.21e+07 a second (4.1 s), four 1.49e+08 (1.2 s), 3.53
times". At k = 2 four processes try 2.3e8 children a second
((2, 16)'s widths 117 to 119, prefix 12).
EF4 EP3 holds, EK3 silent: d_2(16) = 118, the least pure degree. "(2,
16): first vector at width 119: d_2(16) = 118, least pure degree
118, tried 202631652795 (107340779935 below the last width),
extremal 2, not pure 0, 898.8 s". Both extremal vectors are pure
products, parts (1, 1, 2, 3, 3, 4, 5, 5, 6, 7, 8, 9, 11, 13, 17,
23) and (1, 2, 2, 3, 4, 5, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17).
Its sizes at width 119: |Gq| 157 bits, N 222, mu 66, delta
9.3e-20, B 7.5e-11. The growth a width, as printed, rose from
1.81 at width 112 to 1.87 at 117; the price read at 112, 9.28e10
children for widths 113 to 118, was 11% low (1.046e11).
suffixwalk.py's price to width 118, 4.80e10, was under half the
1.073e11 tried. The kept counts peak at suffix length 43 of 119.
EF5 EP4 holds but for its price, EK4 silent: d_1(17) = 185, the
least pure degree, and its one extremal vector is a pure
product. "(1, 17): first vector at width 186: d_1(17) = 185,
least pure degree 185, tried 31630176753 (20788555758 below the
last width), extremal 1, not pure 0, 304.2 s", parts (1, 2, 3, 4,
5, 6, 7, 9, 10, 11, 13, 14, 16, 17, 19, 23, 25). Its sizes at
width 186: |Gq| 159 bits, N 237, mu 79, delta 8.2e-16, B 5.4e-11.
The price fails low: 2.08e10 children to width 185 against the
6e10 to 3e11 predicted, the growth a width falling as printed,
1.55 at width 177 and 1.51 from 181 to 184, where suffixwalk.py
read 1.69 at widths 166 to 170. The price read at width 177,
2.31e10 for widths 178 to 185, was 15% high (20093609292). At
widths 166, 168 and 170 the engine's children are 1232355,
3636642 and 9955482, suffixwalk.py's own at depth 17 to the unit
(its DEPTH 17). The kept counts peak at suffix length 60 of 186.
The sum and the three counts were read off the cell's run file
by a scratch line, the run having printed no line at widths
166, 168, 170, 178 and 179; a rerun prints them.
EF6 Depth 18, run with no prediction or kill frozen for it, its line
its own: d_1(18) = 207, the least pure degree, one extremal
vector, a pure product. "(1, 18): first vector at width 208:
d_1(18) = 207, least pure degree 207, tried 222843990303
(146944499709 below the last width), extremal 1, not pure 0,
1653.0 s", parts (1, 2, 3, 4, 5, 6, 7, 9, 10, 11, 13, 15, 16, 17,
19, 21, 23, 25). EKP: priced at width 197 at 1.77e11 children
and 1360 s for the widths 198 to 207, under two hours, so run;
the growth as printed fell from 1.57 there to 1.51. Its sizes at width
208: |Gq| 161 bits, Aq 162, (E1)'s bound on N 246 of the 254
table allows, that on mu
86, delta 6.3e-14, B 8.1e-10: a depth more wants a fifth limb
for N and more fractional bits.
EF7 A ninth cell at the record (EC1's seven, EC4's, this), run
after the findings above, the dearest of
suffixwalk.py's: "(6, 16): first vector at width 72: d_6(16) =
71, least pure degree 71, tried 9048986414 (3602510093 below the
last width), extremal 2, not pure 0, 30.0 s", its two counts and
its parts, (1, 1, 1, 1, 2, 2, 3, 3, 3, 4, 5, 5, 7, 9, 11, 13) and
(1, 1, 1, 2, 2, 3, 3, 3, 4, 5, 5, 6, 7, 8, 9, 11), suffixwalk.py's
DIAL's and its run record's, which took 1927.0 s.
WHAT THE RECORD DOES NOT READ. The engine's float E against an exact
rational off a vector's path: THE PATHS reads it on six paths
(EF8), and every "nothing at this width" still rests on the
bound (E1) to (E6). The counts are read equal to suffixwalk.py's
to width 142 and a bound on N of 221 bits, and at depth 17's
widths 166, 168 and 170; the new cells' bounds on N are 222, 237
and 246 bits, at widths 119, 186 and 208, where the engine is
read against nothing but the four paths and its own two builds.
THE PATHS, asked after the record above and before the engine was
touched for it. The read that record lacks: the engine's own float E
against an exact rational. The engine printed no E, so it is given a
path form: a seventh argument, a file of the W coefficients of one
vector, and it then walks that vector's suffixes alone, printing the
double E_m it carries into each level m it reaches alive, bit for
bit. The node's arithmetic is the walk's own lines; the build is new,
so every cell above is run again on it and read against its line.
THE CONVENTION, read off the engine: rec(m, E) holds E = E_m, the
suffix fixed for t >= m; the top is entered at m = W - 1 with
c^2 kappa_(W-1); a path alive to the bottom prints W - J lines, m =
W - 1 down to J, and its vector. suffixwalk.py's energy_exact(J, m,
v) is E_m of the same suffix by its definition, mu^T G_m^(-1) mu, in
exact rationals, sharing nothing with the table.
THE STATISTIC. gap_m = float E_m - exact E_m, signed. (E5) claims
|gap_m| <= B(J, W, k) at every level of the path of a vector of
height <= k, B as table() computes it at that width. Nothing divides
it. Its expected size: some W roundings of a sum of size E <= k^2 W,
each u E, so about sqrt(W) u k^2 W: 3e-13 at W = 208, k = 1.
THE PLANT'S ALGEBRA. Bit b of |Gq_j| flipped at row r moves the
numerator there by dN = s 2^(b-128) mu_j, mu the suffix's moments
above r, s the sign of g_j, negated where the bit was set. The
increment at row r moves by (2 N' dN + dN^2) / (1 + kappa_r), N' =
S + c_r (1 + kappa_r), and no other row's moves: an increment reads
mu and its own row, never E. So the planted engine's E_m is the
unplanted one above row r and that plus the shift at every m <= r,
the shift an exact rational computed from suffixwalk.py's Levels
before the engine reads the planted table. Read before the freeze,
no engine (a scratch print): at (1, 18), width 208, row 113, entry
17, the least b of every fourth with |shift| >= 1e-6 is 48, the
shift -1.566e-05; the exact E_m there 11.98 of 113 and 9 of 18 at
the bottom, so the planted path stays alive.
EP5 On each of the four extremal vectors' paths, built from the
parts of EF4, EF5 and EF6 and never from a walk, the engine
reaches the bottom and returns the vector, and the largest
|gap_m| is under 1e-12: a TRANSPLANT from suffixwalk.py's own
floats (8.1e-15 at height 1, 1.8e-13 at height k), whose
increment is rounded otherwise.
EK5 (the bound is wrong, or the engine's E is not the E it bounds;
no "nothing at this width" stands) "the paths: N of M levels
within B", N < M: a level of one of the four paths with |gap_m|
above B at its width, or a path that dies.
EK6 (the path form reads nothing) "the path plant: N of M levels
within B of the shift", N < M: on the planted table a level m <=
r whose gap is not within B of the exact shift, or one above r
whose gap is not within B of 0; or a shift not above 1e-6 in
size.
EC6 the reference and the path form where another float is read
against the same exact rationals: depth 12's extremal vector and
the traded product of (8, 15), each down its path in the engine
and in suffixwalk.py's walk (its trace), both gaps printed, the
engine's under B.
EC7 the plant: (1, 18), width 208, row (J + W) // 2 = 113, entry
J - 1 = 17, the bit chosen by the rule above and printed with
its exact shift before the engine runs. Read with EC6 before the
four paths, and all of it before any cell is run again.
CHANGED AFTER THE FREEZE OF THE PATHS. No frozen line moved. As
coded: the path's own child is still put to the early kill, so a
path dies where the walk would drop it; a cell of the record
(CELLS, the three cells of EF4 to EF6) or of suffixwalk.py's DIAL
now ends in a check of its line and exits on it. The build is new,
its tag 3af8220bdbb6 where the first was 01075f34ce8f; the driver
did not move between the controls and the three cells. After the
three cells, the C untouched: the check against suffixwalk.py's
DIAL and RECORD; a recorded cell that ends with no vector fails
its check; a run file carries the build's tag in its name, and a
check made on widths read back says so in its line; the refusal
without gcc, made before anything is printed.
EF8 EP5 holds, EK5 silent: "the paths: 565 of 565 levels within B".
Each of the four paths reaches the bottom and returns its vector;
the largest |gap_m| prints as 7.8e-15 at (1, 17), 3.2e-15 at
(1, 18), 8.5e-15 and 1.2e-14 at (2, 16)'s two, against B printed
as 5.4e-11, 8.1e-10 and 7.5e-11, each figure rounded to nearest,
and the largest E_m / (k^2 m) on them is
0.6109, 0.5000, 0.3594 and 0.3677. EC6: "82 levels, the engine's
largest gap 4.8e-15, the walk's 2.2e-15, B 1.2e-11" at (1, 12)
and "41 levels, the engine's largest gap 1.9e-13, the walk's
1.8e-13, B 2.7e-10" at (8, 15).
EF9 EK6 silent: "the path plant at (1, 18), width 208: row 113,
entry 17, bit 48, the exact shift -1.565538e-05", then "the path
plant: 190 of 190 levels within B of the shift; the gap at level
114 1.298e-15, at level 113 -1.565538e-05, at the bottom
-1.565538e-05, B 8.1e-10".
EF10 The new build at the record. python walkc.py controls: "the
engine at the record: 7 of 7 cells", the plant, the shards and
the break as in EF2, "12 of 12 checks, 169 s". Each of the three
cells run whole again, no width read back, its line EF4's, EF5's
and EF6's to the unit but for the seconds (841.6 s, 221.8 s and
1603.3 s), each check "at its record" passing; at depth 17 the
widths 166, 168 and 170 print 1232355, 3636642 and 9955482
children. The peak commit of a cell's whole process tree: 25.9,
26.1 and 26.2 MB. The ninth cell of EF7 on this build: "(6, 16):
first vector at width 72: d_6(16) = 71, least pure degree 71,
tried 9048986414 (3602510093 below the last width), extremal 2,
not pure 0, 28.8 s", its check against suffixwalk.py's DIAL
passing.
THE COLUMNS PAST DEPTH 16, asked after the record above, the C
untouched (the build's tag stands, 3af8220bdbb6). QUESTION: at the 44
cells J = 17..20, k = 2..12, is d_k(J) the least pure degree, and is
every polynomial that attains it a pure product? Two are decided,
(11, 17) and (12, 17), by the lattice at 59 (members.py's T5); the
other 42 are decided by nothing, 14 of them capped by the lattice
(members.py's T5). Read before the freeze, no walk: the
engine accepts 43 of the 44, each B under 1.6e-9 and each bound on N
at most 247 bits, and refuses (2, 20) at width 191, its bound on N
255 bits. The least pure degrees, k = 12 down to 2: J = 17: 59, 59,
67, 69, 72, 75, 75, 84, 88, 104, 126; J = 18: 69, 73, 73, 77, 82, 82,
82, 91, 101, 116, 147; J = 19: 80, 83, 83, 84, 88, 91, 94, 100, 116,
124, 169; J = 20: 88, 90, 94, 94, 97, 103, 105, 117, 125, 147, 190.
The order: J = 17 from k = 12 down, then J = 18 from k = 12 down,
each cell's price read off its own widths before the next.
CP1 (11, 17) and (12, 17): the first vector at width 60, d = 59,
the lattice's.
CP2 Every other cell decided obeys the pure law, and each extremal
polynomial is a pure product: a TRANSPLANT from 127 of 128 cells
at J <= 16, k <= 8 and 62 of 64 at k = 9..12, J <= 16. Three
breaks in 192 cells, all at k >= 8: of a dozen new cells at
k >= 8, none expected, one no surprise.
CP3 A break, if one, has one extremal polynomial, one degree under
the least pure degree (the three read).
CP4 THE PRICE, a TRANSPLANT from depth 16 ((8, 16): 2.4e9 children
in all, (6, 16): 9.0e9, (2, 16): 2.0e11) and a factor of some
10 a depth ((8, 15) to (8, 16): 9.3): J = 17 at k >= 6 costs
1e10 to 1e11 children a cell, minutes; J = 18 ten times that;
(2, 17) past 1e12 and (3, 17) unknown.
CK1 (a finding) "(k, J): first vector at width W: d_k(J) = W - 1,
a break", at any cell.
CK2 (a finding) "not pure N", N >= 1, on the line of a cell with no
break.
CK3 (a bug, or the lattice's slack wrong) (11, 17) or (12, 17) with
its first vector at a width other than 60.
CK4 (the arc's exit) the cells run all printed, no CK1 and no CK2
among them: the arc closes to its front.
The price is EKP's as coded: a cell priced past two hours stops
on its price, which is then its line.
CC1 python walkc.py on a fresh build, the known break d_9(10) and
the planted bit among its checks. CC2 a break seen at the
new cells' heights: cell 11 15 and cell 8 15 against
suffixwalk.py's DIAL, d = 48 under 49 and 55 under 56, one
polynomial each, no pure product, 34860456 and 259791858
children. CC3 CP1's two cells. All read
before any
cell the lattice left.
CHANGED AFTER THE FREEZE. No frozen line moved; the ask as frozen
counted 42 cells, 41 accepted and 26 at k <= 8 where the print it
read has 44, 43 and 28; this section restates the frozen lines
and moves none. The driver moved
while the cells ran, the C never: CELLS took each cell decided,
NOT_PURE the vector of (11, 18), the record check compares the
vectors of no pure product, and stage_paths reads their paths; no
line of cell or run_width moved.
CF1 The controls. CC1: "12 of 12 checks, 22 s". CC2: "(11, 15):
first vector at width 49: d_11(15) = 48, a break, least pure
degree 49, tried 34860456 (12763160 below the last width),
extremal 1, not pure 1, 0.6 s" and "(8, 15): first vector at
width 56: d_8(15) = 55, a break, least pure degree 56, tried
259791858 (98015880 below the last width), extremal 1, not pure
1, 1.9 s", each check at suffixwalk.py's record passing. CC3,
CK3 silent: "(12, 17): first vector at width 60: d_12(17) = 59,
least pure degree 59, tried 297531050 (109448175 below the last
width), extremal 1, not pure 0, 1.9 s" and "(11, 17): first
vector at width 60: d_11(17) = 59, least pure degree 59, tried
65856636 (26167675 below the last width), extremal 1, not pure
0, 0.9 s".
CF2 CK1 silent: no break at any of the sixteen cells decided, the
two of CC3 and fourteen the lattice left. Each line reads "(k,
J): first vector at width d + 1: d_k(J) = d, least pure degree
d", and CELLS holds its d, its children tried, those below the
last width and its parts as printed. At J = 17, k = 10 down to
4: d = 67, 69, 72, 75, 75, 84, 88, children tried 35567737653,
30558364354, 40477406436, 28909378590, 827842652, 20609324615,
1491273504, seconds 100.1, 85.2, 105.7, 77.2, 4.1, 58.1, 6.3. At
J = 18, k = 12, 11, 10, 9, 7, 6, 5: d = 69, 73, 73, 77, 82, 82,
91, children tried 28104889900, 280370637698, 31924250715,
169581029650, 32045216685, 846207609, 12749544654, seconds 79.4,
587.4, 85.2, 366.3, 81.1, 4.1, 37.0. Extremal 1 at each but (5,
17), 2, both pure
products, and (11, 18). The largest B at a last width is 9.4e-10,
(12, 18)'s, the largest bound on N 225 bits, (5, 18)'s.
CF3 CK2 FIRES at (11, 18): "(11, 18): first vector at width 74:
d_11(18) = 73, least pure degree 73, tried 280370637698
(94098813158 below the last width), extremal 2, not pure 1,
587.4 s". One of the two is (10, 18)'s pure product, of height
10; the other is NOT_PURE's vector, of height 11.
It is no minimiser of a height: d_10(18) = 73 too. CP2's second
half fails here; its first half holds at all sixteen. CK4 is
silent with CK2 fired, and no cell stopped on its price.
CF4 CP4 fails low at seven of the thirteen decided cells it prices
(J = 18 read at k >= 6, as J = 17) and
holds at six, (10, 17), (9, 17), (8, 17), (7, 17), (11, 18) and
(9, 18); none is high. (12, 17) and (11, 17) cost
3.0e8 and 6.6e7 children, (12, 18) and (10, 18) 2.8e10 and
3.2e10, (6, 17) 8.3e8 beside (7, 17)'s 2.9e10
at the same degree 75, (6, 18) and (7, 18) 8.5e8 and 3.2e10 at
the same 82, both low. Unpriced by CP4: (4, 17), 1.5e9. The growth
a width, as printed: 2.62 to 2.75 at (10, 17), 2.45 to 2.57 at
(8, 17).
CF5 The paths, on the bare run after CELLS took the sixteen: "the
paths: 1621 of 1621 levels within B", 22 paths, the vector of no
pure product among them ("56 of 56 levels alive, the largest gap
2.1e-13, B 8.8e-10"); the largest gap on the new paths prints as
3.0e-13.
CF6 Five cells more, the same source, each run once and none in
CELLS, so no check reads them. The first four were run a width
a call through `cell`, the widths kept, each stopped if its
price to the least pure degree passed 600 s; the line below is
a later call's, "READ BACK, NOT RUN" over every width. CK1 and
CK2 silent at each: "(4, 18): first vector at width 102:
d_4(18) = 101, least pure degree 101, tried 45005897151
(21836079603 below the last width), extremal 1, not pure 0,
130.6 s", parts (1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 7, 7, 8, 9,
10, 11, 13); "(3, 17): first vector at width 105: d_3(17) =
104, least pure degree 104, tried 38642558983 (19631928379
below the last width), extremal 1, not pure 0, 131.8 s", parts
(1, 1, 2, 2, 3, 3, 4, 5, 5, 6, 7, 7, 8, 9, 11, 13, 17); "(2,
17): first vector at width 127: d_2(17) = 126, least pure
degree 126, tried 29657017185 (16494710020 below the last
width), extremal 1, not pure 0, 130.0 s", parts (1, 1, 2, 3, 3,
4, 5, 6, 7, 7, 8, 9, 10, 11, 13, 17, 19); "(3, 18): first
vector at width 117: d_3(18) = 116, least pure degree 116,
tried 207723450746 (106698813473 below the last width),
extremal 1, not pure 0, 710.3 s", parts (1, 1, 2, 3, 3, 4, 4,
5, 5, 6, 7, 7, 8, 9, 10, 11, 13, 17). (8, 18), priced at width
75 at 975 s to width 82, ran as one call, its widths 19 to 75
read back from the pricing: "(8, 18): first vector at width 83:
d_8(18) = 82, least pure degree 82, tried 1209086281497
(441841590005 below the last width), extremal 1, not pure 0,
2286.9 s", parts (1, 1, 1, 2, 2, 3, 3, 3, 4, 4, 5, 5, 6, 7, 7,
8, 9, 11), its last width alone 1403.1 s. The largest B at a
last width is 5.9e-10, (8, 18)'s; the largest bound on N 231
bits, (3, 18)'s. (2, 18) stopped at width 131 on its price:
"9521 s to width 147 and the last width unpriced", growth 1.67.
With CK2 fired at (11, 18), CK4 as frozen stays unmet; these
five add no CK1 and no CK2.
WHAT THIS RECORD DOES NOT READ. The 23 cells left: (2, 18), and
J = 19 and 20 whole. The sixteen of CF2
ran a second time, the same source built afresh, each at its
record's line to the unit; none on a second source. No path of
CF6's five is read by stage_paths.
RUN RECORD. python walkc.py controls, four processes: "8 of 8
checks, 162 s", of them 134 s suffixwalk.py's walk at the seven last
widths. python walkc.py cell 2 16: 910 s; python walkc.py cell 1 17:
342 s, of it some 38 s flatten.py's least pure degree; python walkc.py
cell 1 18, prefix 20: 1740 s. Each wide width ran four processes of
the engine and nothing beside them. After the repairs named under
CHANGED AFTER THE FREEZE: python
walkc.py, "8 of 8 checks, 16 s"; python walkc.py cell 6 16, 31 s.
The second build, with THE PATHS: python walkc.py, "12 of 12 checks,
21 s"; python walkc.py controls, "12 of 12 checks, 169 s"; the three
cells, 847 s, 242 s and 1647 s. The columns past depth 16: python
walkc.py, "12 of 12 checks, 22 s" before the cells and "12 of 12
checks, 27 s" with their paths; the fourteen cells and the four
controls each one call, 589 s the longest, (11, 18). The sixteen
again, the build made afresh: python walkc.py, "12 of 12 checks, 26
s", then each cell one call, its check at its record passing, 584 s
the longest, (11, 18). CF6's five: the four priced cells 132 s, 133
s, 132 s and 712 s over their calls, then python walkc.py cell 8 18,
2285 s.
"""
import hashlib
import json
import os
import shutil
import struct
import subprocess
import sys
import tempfile
import time
from math import comb, sqrt
import flatten as F
import suffixwalk as SW
FB = 128 # fractional bits of the fixed point
U = 2.0 ** -53
BMAX = 2.5e-7 # (E5): a width with B above it is refused
DMAX = 1e-9 # (E4): and one with delta above it
PROCS = 4
PREFIX = 20 # the shards' prefix of top coefficients
C_SOURCE = r"""
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef unsigned long long u64;
typedef long long i64;
typedef unsigned __int128 u128;
typedef __int128 i128;
#define MAXJ 48
#define MAXW 1024
static int J, W, K, NSH, ISH, MS;
static u64 Gm[MAXW][MAXJ][3];
static unsigned char Gs[MAXW][MAXJ];
static u64 Aq[MAXW][3];
static double wd[MAXW], lim[MAXW], kaptop, big;
static i128 acol[MAXW][MAXJ];
static i128 mus[MAXW][MAXJ];
static int cur[MAXW];
static u64 tried, kept[MAXW], roots, cap;
static const double P64 = 18446744073709551616.0;
static double pw[3];
static int PATH, pth[MAXW];
static double bits(u64 x) { double d; memcpy(&d, &x, 8); return d; }
static u64 dbits(double d) { u64 x; memcpy(&x, &d, 8); return x; }
/* a 256-bit two's complement integer, in units of 2^-128, as a double:
the two leading nonzero limbs of its magnitude */
static inline double todbl(const u64 *n) {
u64 m[4];
int neg = (i64)n[3] < 0, i;
if (neg) {
u128 t = (u128)(~n[0]) + 1;
m[0] = (u64)t; t = (u128)(~n[1]) + (u64)(t >> 64);
m[1] = (u64)t; t = (u128)(~n[2]) + (u64)(t >> 64);
m[2] = (u64)t; t = (u128)(~n[3]) + (u64)(t >> 64);
m[3] = (u64)t;
} else {
m[0] = n[0]; m[1] = n[1]; m[2] = n[2]; m[3] = n[3];
}
i = 3;
while (i > 0 && m[i] == 0) i--;
double d;
if (i == 0) d = (double)m[0] * pw[0];
else d = ((double)m[i] * P64 + (double)m[i - 1]) * pw[i - 1];
return neg ? -d : d;
}
static void bottom(const i128 *mu) {
int y[MAXJ], j, t;
for (j = J - 1; j >= 0; j--) {
i128 v = -mu[j];
for (t = j + 1; t < J; t++)
if (y[t]) v -= (i128)y[t] * acol[t][j];
if (v > K || v < -K) return;
y[j] = (int)v;
}
if (y[0] == 0) return;
printf("V");
for (t = 0; t < J; t++) printf(" %d", y[t]);
for (t = J; t < W; t++) printf(" %d", cur[t]);
printf("\n");
}
static void rec(int m, double E) {
int counting = 1, j, c;
if (m == MS) {
u64 id = roots++;
if ((int)(id % (u64)NSH) != ISH) return;
} else if (m > MS) counting = (ISH == 0);
if (counting) kept[m]++;
if (PATH) printf("E %d %016llx\n", m, dbits(E));
const i128 *mu = mus[m];
if (m == J) { bottom(mu); return; }
const int r = m - 1;
u128 col[2][4];
memset(col, 0, sizeof col);
for (j = 0; j < J; j++) {
i128 v = mu[j];
int s = v < 0;
u128 a = s ? (u128)0 - (u128)v : (u128)v;
u64 a0 = (u64)a, a1 = (u64)(a >> 64);
const u64 *b = Gm[r][j];
u128 *q = col[s ^ Gs[r][j]];
u128 p;
p = (u128)a0 * b[0]; q[0] += (u64)p; q[1] += (u64)(p >> 64);
p = (u128)a0 * b[1]; q[1] += (u64)p; q[2] += (u64)(p >> 64);
p = (u128)a0 * b[2]; q[2] += (u64)p; q[3] += (u64)(p >> 64);
if (a1) {
p = (u128)a1 * b[0]; q[1] += (u64)p; q[2] += (u64)(p >> 64);
p = (u128)a1 * b[1]; q[2] += (u64)p; q[3] += (u64)(p >> 64);
q[3] += (u64)(a1 * b[2]);
}
}
u64 P[4], Q[4], N[4], kA[4];
u128 t = 0;
for (j = 0; j < 4; j++) { t += col[0][j]; P[j] = (u64)t; t >>= 64; }
t = 0;
for (j = 0; j < 4; j++) { t += col[1][j]; Q[j] = (u64)t; t >>= 64; }
/* N = P - Q - K Aq, mod 2^256 */
t = 0;
for (j = 0; j < 3; j++) {
t += (u128)Aq[r][j] * (u64)K; kA[j] = (u64)t; t >>= 64;
}
kA[3] = (u64)t;
u64 borrow = 0;
for (j = 0; j < 4; j++) {
u128 d = (u128)P[j] - Q[j] - borrow;
N[j] = (u64)d; borrow = (u64)(d >> 64) & 1;
}
borrow = 0;
for (j = 0; j < 4; j++) {
u128 d = (u128)N[j] - kA[j] - borrow;
N[j] = (u64)d; borrow = (u64)(d >> 64) & 1;
}
if (counting) {
tried += (u64)(2 * K + 1);
if (cap && tried > cap) { printf("C\n"); exit(3); }
}
const double w = wd[r], lm = lim[r];
for (c = -K; c <= K; c++) {
double n = todbl(N);
double inc = (n * n) / w;
if (!(inc > big) && (!PATH || c == pth[r])) {
double e = (E + inc) - (double)(c * c);
if (!(e > lm)) {
i128 *mu2 = mus[r];
const i128 *a = acol[r];
if (c == 0) for (j = 0; j < J; j++) mu2[j] = mu[j];
else if (c == 1) for (j = 0; j < J; j++) mu2[j] = mu[j] + a[j];
else if (c == -1) for (j = 0; j < J; j++) mu2[j] = mu[j] - a[j];
else for (j = 0; j < J; j++) mu2[j] = mu[j] + (i128)c * a[j];
cur[r] = c;
rec(r, e);
}
}
u128 s = (u128)N[0] + Aq[r][0];
N[0] = (u64)s; s = (u128)N[1] + Aq[r][1] + (u64)(s >> 64);
N[1] = (u64)s; s = (u128)N[2] + Aq[r][2] + (u64)(s >> 64);
N[2] = (u64)s; N[3] += (u64)(s >> 64);
}
}
int main(int argc, char **argv) {
if (argc < 6) return 2;
PATH = argc > 6;
FILE *f = fopen(argv[1], "r");
int P = atoi(argv[2]), r, j, top;
u64 x, y;
NSH = atoi(argv[3]); ISH = atoi(argv[4]);
cap = strtoull(argv[5], 0, 10);
if (!f || fscanf(f, "%d %d %d", &J, &W, &K) != 3) return 2;
if (J >= MAXJ || W >= MAXW || P < 1) return 2;
if (fscanf(f, "%llx %llx", &x, &y) != 2) return 2;
big = bits(x); kaptop = bits(y);
for (r = J; r < W; r++) {
if (fscanf(f, "%llx %llx", &x, &y) != 2) return 2;
wd[r] = bits(x); lim[r] = bits(y);
if (fscanf(f, "%llx %llx %llx", &Aq[r][0], &Aq[r][1], &Aq[r][2])
!= 3) return 2;
for (j = 0; j < J; j++) {
int s;
if (fscanf(f, "%d %llx %llx %llx", &s, &Gm[r][j][0],
&Gm[r][j][1], &Gm[r][j][2]) != 4) return 2;
Gs[r][j] = (unsigned char)s;
}
}
fclose(f);
if (PATH) {
f = fopen(argv[6], "r");
if (!f) return 2;
for (r = 0; r < W; r++)
if (fscanf(f, "%d", &pth[r]) != 1) return 2;
fclose(f);
}
pw[2] = 1.0; pw[1] = 1.0 / P64; pw[0] = pw[1] / P64;
for (r = 0; r < W; r++)
for (j = 0; j < J; j++)
acol[r][j] = j == 0 ? 1 : (r == 0 ? 0
: acol[r - 1][j] + acol[r - 1][j - 1]);
MS = W - P > J ? W - P : J;
for (top = 1; top <= K; top++) {
if (PATH && top != pth[W - 1]) continue;
cur[W - 1] = top;
for (j = 0; j < J; j++) mus[W - 1][j] = (i128)top * acol[W - 1][j];
rec(W - 1, (double)(top * top) * kaptop);
}
printf("T %llu\nR %llu\n", tried, roots);
for (r = J; r < W; r++)
if (kept[r]) printf("K %d %llu\n", r, kept[r]);
printf("D\n");
return 0;
}
"""
TAG = hashlib.sha1(C_SOURCE.encode()).hexdigest()[:12] # the build's
_EXE = []
def build():
"""The engine's executable, compiled once a source under the
system's temporary folder. Without gcc on the path the run stops
here: one line, exit 2, nothing read."""
if _EXE:
return _EXE[0]
d = os.path.join(tempfile.gettempdir(), "walkc_" + TAG)
exe = os.path.join(d, "walkc.exe")
if not os.path.exists(exe):
if shutil.which("gcc") is None:
print("walkc.py: no gcc on the path; the engine is not built "
"and nothing is read")
sys.exit(2)
os.makedirs(d, exist_ok=True)
src = os.path.join(d, "walkc.c")
with open(src, "w", newline="\n") as f:
f.write(C_SOURCE)
subprocess.run(["gcc", "-O2", "-march=native", "-ffp-contract=off",
"-o", exe, src], check=True)
_EXE.append(exe)
return exe
def fbits(x):
return "%016x" % struct.unpack("<Q", struct.pack("<d", x))[0]
def limbs(q):
return "%x %x %x" % (q & (2 ** 64 - 1), (q >> 64) & (2 ** 64 - 1),
q >> 128)
def nearest(num, den):
"""The integer nearest num 2^FB / den, den > 0."""
return ((num << (FB + 1)) + den) // (2 * den)
def table(J, W, k, plant=None):
"""The engine's table at width W as text, and the reads of (E1),
(E2) and (E5): (text, sizes) with sizes = (bits of the largest
|Gq_j|, of the largest Aq, of the bound on N, of the bound on mu,
delta, B), or (None, sizes) where a limit is passed."""
rows = SW.levels(J, W - 1)
kk = k * k
out = ["%d %d %d" % (J, W, k),
"%s %s" % (fbits(4.0 * kk * W), fbits(rows[W - 1][3]))]
mubound = [k * comb(W, j + 1) for j in range(J)]
gb = ab = nb = 0
for r in range(J, W):
gi, A, den, _ = rows[r]
aq = nearest(A, den)
mags = []
for j, x in enumerate(gi):
q = nearest(abs(x), den)
if plant is not None and tuple(plant[:2]) == (r, j):
q ^= 1 << plant[2]
mags.append((1 if x < 0 else 0, q))
gb = max(gb, q.bit_length())
ab = max(ab, aq.bit_length())
nb = max(nb, (sum((q + 1) * b for (_, q), b in zip(mags, mubound))
+ k * (aq + 1)).bit_length())
out.append("%s %s" % (fbits(float(SW.Fraction(A, den))),
fbits(kk * r + SW.SLACK)))
out.append(limbs(aq))
out.extend("%d %s" % (s, limbs(q)) for s, q in mags)
mb = max(b.bit_length() for b in mubound)
delta = (k * (1 + sum(comb(W, j + 1) for j in range(J)))) / 2.0 ** (FB + 1)
X = 2 * k * sqrt(W) * delta + delta * delta
B = 12 * U * kk * W * W + 2 * W * X
sizes = (gb, ab, nb, mb, delta, B)
ok = (gb <= 190 and ab <= 190 and nb <= 254 and mb <= 126
and delta <= DMAX and B <= BMAX and W >= 2)
return ("\n".join(out) + "\n" if ok else None), sizes
def run_width(J, W, k=1, prefix=PREFIX, procs=PROCS, plant=None,
limit=None):
"""One width through the engine: (vectors sorted, kept a level,
children tried, seconds, sizes), each vector re-read by exact sums.
None where table() refuses the width. TimeoutError past limit
seconds. The engine's own cap of children is passed as 0, none."""
if W <= J:
return [], {}, 0, 0.0, None
text, sizes = table(J, W, k, plant)
if text is None:
return None
exe = build()
stem = os.path.join(os.path.dirname(exe),
"t_%d_%d_%d_%d" % (J, W, k, os.getpid()))
with open(stem + ".tab", "w", newline="\n") as f:
f.write(text)
t0 = time.time()
names = ["%s.%d.out" % (stem, i) for i in range(procs)]
outs = [open(n, "w") for n in names]
ps = [subprocess.Popen([exe, stem + ".tab", str(prefix), str(procs),
str(i), "0"], stdout=outs[i])
for i in range(procs)]
try:
while any(p.poll() is None for p in ps):
if limit is not None and time.time() - t0 > limit:
raise TimeoutError("width %d past %.0f s" % (W, limit))
time.sleep(0.002 if time.time() - t0 < 1 else 0.01)
secs = time.time() - t0
vecs, kept, tried, roots = [], {}, 0, set()
for i, p in enumerate(ps):
outs[i].close()
with open(names[i]) as f:
lines = f.read().split("\n")
if p.returncode != 0 or "D" not in lines:
raise RuntimeError("width %d, process %d: exit %s, its "
"end line %s" % (W, i, p.returncode,
"D" in lines))
for ln in lines:
if ln.startswith("V"):
vecs.append([int(x) for x in ln.split()[1:]])
elif ln.startswith("T"):
tried += int(ln.split()[1])
elif ln.startswith("R"):
roots.add(int(ln.split()[1]))
elif ln.startswith("K"):
_, m, n = ln.split()
kept[int(m)] = kept.get(int(m), 0) + int(n)
finally:
for p in ps:
if p.poll() is None:
p.kill()
p.wait()
for o, n in zip(outs, names):
o.close()
os.remove(n)
os.remove(stem + ".tab")
if len(roots) != 1:
raise RuntimeError("the processes number the shards apart: %s"
% (roots,))
for v in vecs:
if not (len(v) == W and F.height(v) <= k and F.clears(v, J)
and v[0] != 0 and 1 <= v[-1] <= k):
raise RuntimeError("no vector at height %d, depth %d: %s"
% (k, J, v))
return sorted(vecs), kept, tried, secs, sizes
def product(parts):
"""The pure product of the parts, its top coefficient positive."""
v = [1]
for g in parts:
v = F.mul_part(v, g)
return [-c for c in v] if v[-1] < 0 else v
def run_path(J, k, v, plant=None):
"""The engine's path form on the vector v at width len(v): ({m: the
double E_m it carries into level m}, whether it returned v, sizes),
one process. None where table() refuses the width."""
W = len(v)
text, sizes = table(J, W, k, plant)
if text is None:
return None
exe = build()
stem = os.path.join(os.path.dirname(exe),
"p_%d_%d_%d_%d" % (J, W, k, os.getpid()))
try:
with open(stem + ".tab", "w", newline="\n") as f:
f.write(text)
with open(stem + ".path", "w", newline="\n") as f:
f.write(" ".join(str(c) for c in v) + "\n")
got = subprocess.run([exe, stem + ".tab", "1", "1", "0", "0",
stem + ".path"], capture_output=True, text=True)
finally:
for ext in (".tab", ".path"):
if os.path.exists(stem + ext):
os.remove(stem + ext)
lines = got.stdout.split("\n")
if got.returncode != 0 or "D" not in lines:
raise RuntimeError("the path at width %d: exit %s, its end line %s"
% (W, got.returncode, "D" in lines))
E, back = {}, False
for ln in lines:
if ln.startswith("E"):
_, m, x = ln.split()
E[int(m)] = struct.unpack("<d", struct.pack("<Q", int(x, 16)))[0]
elif ln.startswith("V"):
back = [int(x) for x in ln.split()[1:]] == list(v)
return E, back, sizes
def path_gaps(J, k, v, plant=None):
"""The engine's float E_m less suffixwalk.py's exact one at every
level the path reaches: ({m: gap, a Fraction}, whether the engine
returned v, sizes, {m: float E_m})."""
E, back, sizes = run_path(J, k, v, plant)
gaps = {m: SW.Fraction(e) - SW.energy_exact(J, m, v)
for m, e in E.items()}
return gaps, back, sizes, E
# ------------------------------------------------------------- the stages
# a cell's widths done, a line each, outside the tree
DATA = os.path.join(tempfile.gettempdir(), "walkc_runs")
HOURS2 = 7200.0
PLANT = (60, 11, 76) # EC2: (row, entry j, bit)
PLANT_J, PLANT_TOP = 12, 94 # the plant's depth, its last width
EC1_BARE = ((1, 12), (1, 14), (2, 12))
EC1_ALL = ((1, 12), (1, 13), (1, 14), (1, 15), (2, 12), (3, 13), (8, 15))
SEEN = (9, 10)
# the cells past suffixwalk.py's record: (k, J): (d_k(J), the least pure
# degree, children tried over all widths, of them below the last width,
# the extremal vectors' parts, extremal vectors of no pure product)
CELLS = {
(2, 16): (118, 118, 202631652795, 107340779935,
((1, 1, 2, 3, 3, 4, 5, 5, 6, 7, 8, 9, 11, 13, 17, 23),
(1, 2, 2, 3, 4, 5, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17)), 0),
(1, 17): (185, 185, 31630176753, 20788555758,
((1, 2, 3, 4, 5, 6, 7, 9, 10, 11, 13, 14, 16, 17, 19, 23,
25),), 0),
(1, 18): (207, 207, 222843990303, 146944499709,
((1, 2, 3, 4, 5, 6, 7, 9, 10, 11, 13, 15, 16, 17, 19, 21, 23,
25),), 0),
(12, 17): (59, 59, 297531050, 109448175,
((1, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 5, 5, 6, 7, 9),), 0),
(11, 17): (59, 59, 65856636, 26167675,
((1, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 5, 5, 6, 7, 9),), 0),
(10, 17): (67, 67, 35567737653, 12288233727,
((1, 1, 1, 1, 1, 2, 2, 3, 3, 3, 4, 4, 5, 5, 7, 11, 13),), 0),
(9, 17): (69, 69, 30558364354, 11088534444,
((1, 1, 1, 2, 2, 3, 3, 3, 4, 4, 5, 5, 5, 6, 7, 8, 9),), 0),
(8, 17): (72, 72, 40477406436, 15081437392,
((1, 1, 1, 1, 2, 2, 3, 3, 3, 4, 5, 5, 6, 7, 8, 9, 11),), 0),
(7, 17): (75, 75, 28909378590, 11017155870,
((1, 1, 1, 2, 2, 3, 3, 3, 4, 4, 5, 5, 6, 7, 8, 9, 11),), 0),
(6, 17): (75, 75, 827842652, 367278444,
((1, 1, 1, 2, 2, 3, 3, 3, 4, 4, 5, 5, 6, 7, 8, 9, 11),), 0),
(12, 18): (69, 69, 28104889900, 9670901075,
((1, 1, 1, 1, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 6, 7, 8, 9),), 0),
(11, 18): (73, 73, 280370637698, 94098813158,
((1, 1, 1, 1, 2, 2, 3, 3, 3, 4, 4, 5, 5, 5, 6, 7, 9, 11),),
1),
(10, 18): (73, 73, 31924250715, 11669912646,
((1, 1, 1, 1, 2, 2, 3, 3, 3, 4, 4, 5, 5, 5, 6, 7, 9, 11),),
0),
(9, 18): (77, 77, 169581029650, 62350625302,
((1, 1, 1, 2, 2, 3, 3, 3, 3, 4, 4, 5, 5, 6, 7, 7, 9, 11),), 0),
(5, 17): (84, 84, 20609324615, 9123235561,
((1, 1, 1, 2, 2, 3, 3, 3, 4, 5, 5, 6, 7, 8, 9, 11, 13),
(1, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 7, 7, 9, 11, 13)), 0),
(4, 17): (88, 88, 1491273504, 741519828,
((1, 1, 1, 2, 2, 3, 3, 4, 5, 5, 6, 7, 7, 8, 9, 11, 13),), 0),
(6, 18): (82, 82, 846207609, 391105065,
((1, 1, 1, 2, 2, 3, 3, 3, 4, 4, 5, 5, 6, 7, 7, 8, 9, 11),), 0),
(7, 18): (82, 82, 32045216685, 12755844315,
((1, 1, 1, 2, 2, 3, 3, 3, 4, 4, 5, 5, 6, 7, 7, 8, 9, 11),), 0),
(5, 18): (91, 91, 12749544654, 5966077073,
((1, 1, 1, 2, 2, 3, 3, 3, 4, 5, 5, 6, 7, 7, 8, 9, 11, 13),), 0),
}
# a cell's extremal vectors of no pure product, each as listed, its top
# coefficient positive
NOT_PURE = {
(11, 18): ((1, -4, 3, 6, -7, -5, 7, 2, -3, -5, 6, 4, -5, 7, -10, -5, 0,
11, -4, 6, 8, -11, -7, -5, 10, -1, 6, -7, -4, 6, 9, -3, -7,
-2, 0, -8, 11, 11, -8, 0, -2, -7, -3, 9, 6, -4, -7, 6, -1,
10, -5, -7, -11, 8, 6, -4, 11, 0, -5, -10, 7, -5, 4, 6, -5,
-3, 2, 7, -5, -7, 6, 3, -4, 1),),
}
PATH_PLANT = (1, 18) # EC7: its cell
SHIFT_MIN = 1e-6 # and the least size of its shift
CHECKS = []
def check(name, ok, detail=""):
CHECKS.append(bool(ok))
print(" [%s] %s%s" % ("PASS" if ok else "FAIL", name,
" " + detail if detail else ""), flush=True)
def price(counts, secs, W, dp):
"""EKP: (growth a width, children, seconds) for the widths W + 1 to
dp, from the last three widths' counts and the last width's rate."""
if len(counts) < 3 or not counts[-3] or W >= dp:
return None
g = sqrt(counts[-1] / counts[-3])
rest = sum(counts[-1] * g ** i for i in range(1, dp - W + 1))
return g, rest, rest * secs / counts[-1]
def cell(k, J, until=None, keep=False, prefix=PREFIX, procs=PROCS,
say=False, dp=None, back=None):
"""Widths J + 1 upward to the first that holds a vector, or to
`until`: (status, W, vectors, children tried a width, the last
width's kept, its sizes, seconds). status is "found", "none" (no
vector to `until`), "refused", "priced" (EKP: past two hours) or
"late" (a width past twice its estimate). keep: a width done is a
line of DATA's file for the cell, read back at the next call, and
`back` (a list) takes each width read back and not run."""
if dp is None:
dp = F.least_pure_degree(J, k, 400)[0]
path = os.path.join(DATA, "walkc_%s_%d_%d.jsonl" % (TAG, k, J))
done = {}
if keep and os.path.exists(path):
with open(path) as f:
for ln in f:
row = json.loads(ln)
done[row["W"]] = row
counts, times = [], []
total = 0.0
W = J + 1
while True:
if W in done:
if back is not None:
back.append(W)
row = done[W]
vecs, kept, n, secs, sizes = (row["vectors"], row["kept"],
row["tried"], row["secs"],
row["sizes"])
else:
limit = None
if len(counts) >= 3 and counts[-3] and times[-1] > 30:
limit = 2 * times[-1] * sqrt(counts[-1] / counts[-3]) + 60
try:
got = run_width(J, W, k, prefix, procs, limit=limit)
except TimeoutError:
return "late", W, [], counts, {}, None, total
if got is None:
return "refused", W, [], counts, {}, None, total
vecs, kept, n, secs, sizes = got
if keep:
os.makedirs(DATA, exist_ok=True)
with open(path, "a", newline="\n") as f:
f.write(json.dumps({"W": W, "tried": n, "secs": secs,
"vectors": vecs, "kept": kept,
"sizes": sizes}) + "\n")
counts.append(n)
times.append(secs)
total += secs
est = price(counts, secs, W, dp)
if say and (secs >= 5 or (W - J) % 10 == 0 or vecs or n >= 10 ** 6):
print(" (%d, %d) width %d: %d children, %d vectors, %.1f s%s"
% (k, J, W, n, len(vecs), secs,
"" if est is None or secs < 1 else
"; growth %.2f, to width %d: %.2e children, %.0f s"
% (est[0], dp, est[1], est[2])), flush=True)
if vecs:
return "found", W, vecs, counts, kept, sizes, total
if until is not None and W >= until:
return "none", W, [], counts, kept, sizes, total
if est is not None and secs >= 5 and est[2] > HOURS2:
return "priced", W, [], counts, kept, sizes, total
W += 1
def record_of(k, J):
"""(d, children tried over all widths) from suffixwalk.py's record."""
if k == 1:
return SW.RECORD[J][:2]
return SW.DIAL[(k, J)][0], SW.DIAL[(k, J)][2]
def stage_record(cells):
"""EC1: each cell's d and children tried against suffixwalk.py's
record; its last width's vectors, kept counts and children against
suffixwalk.py's walk at that width. Returns the cells equal."""
good = 0
for k, J in cells:
status, W, vecs, counts, kept, sizes, secs = cell(k, J)
t0 = time.time()
out, pkept, pn = SW.walk(J, W, k)
same = (status == "found" and (W - 1, sum(counts)) == record_of(k, J)
and sorted(out) == vecs and pn == counts[-1]
and {str(m): n for m, n in pkept.items() if n}
== {str(m): n for m, n in kept.items()})
good += same
print(" (%d, %2d): d = %d, tried %d, %d vectors, %.1f s; the walk "
"at width %d: %d children, %d vectors, %.1f s%s"
% (k, J, W - 1, sum(counts), len(vecs), secs, W, pn, len(out),
time.time() - t0, "" if same else " DIFFERS"), flush=True)
check("EC1 the engine at the record: d, children tried, the last "
"width's vectors and kept counts", good == len(cells),
"the engine at the record: %d of %d cells" % (good, len(cells)))
class planted:
"""suffixwalk.py's rows at depth J with the plant's entry replaced
by the table's planted rational, every other entry exact."""
def __init__(self, J, plant):
self.rows = SW.levels(J, PLANT_TOP - 1)
self.plant = plant
def __enter__(self):
r, j, bit = self.plant
self.old = self.rows[r]
gi, A, den, kf = self.old
q = nearest(abs(gi[j]), den) ^ (1 << bit)
new = [x << FB for x in gi]
new[j] = (-q if gi[j] < 0 else q) * den
self.rows[r] = (tuple(new), A << FB, den << FB, kf)
def __exit__(self, *exc):
self.rows[self.plant[0]] = self.old
def walk_tried(J, plant=None):
"""suffixwalk.py's children tried over the widths J + 1 to
PLANT_TOP, on the planted rows if a plant is given."""
if plant is None:
return sum(SW.walk(J, W)[2] for W in range(J + 1, PLANT_TOP + 1))
with planted(J, plant):
return sum(SW.walk(J, W)[2] for W in range(J + 1, PLANT_TOP + 1))
def engine_tried(J, plant=None, prefix=12, procs=PROCS):
got = [run_width(J, W, 1, prefix, procs, plant)
for W in range(J + 1, PLANT_TOP + 1)]
return sum(g[2] for g in got), [v for g in got for v in g[0]]
def stage_scan(row, j, step=4):
"""EC2's choice: the least bit, of every step-th, whose flip in
|Gq_j| of the row moves suffixwalk.py's children tried."""
base = walk_tried(PLANT_J)
for bit in range(0, FB + 32, step):
n = walk_tried(PLANT_J, (row, j, bit))
print(" row %d, entry %d, bit %3d: %d%s"
% (row, j, bit, n, "" if n == base else " MOVED"), flush=True)
if n != base:
return bit, n, base
return None, base, base
def stage_plant():
base = SW.RECORD[PLANT_J][1]
want = walk_tried(PLANT_J, PLANT)
got, _ = engine_tried(PLANT_J, PLANT)
check("EC2 the plant: row %d, entry %d, bit %d of |Gq_j|" % PLANT,
got == want and want != base,
"the plant: the engine %d, the walk %d, unplanted %d"
% (got, want, base))
def stage_shards():
one = engine_tried(PLANT_J, None, 1, 1)
four = engine_tried(PLANT_J, None, 12, 4)
check("EC3 the shards: depth %d at one process, prefix 1, and at "
"four, prefix 12" % PLANT_J,
one == four and one[0] == SW.RECORD[PLANT_J][1] and one[1],
"%d and %d children, %d and %d vectors"
% (one[0], four[0], len(one[1]), len(four[1])))
def stage_seen():
k, J = SEEN
dp = F.least_pure_degree(J, k, 400)[0]
status, W, vecs, counts, kept, sizes, secs = cell(k, J, dp=dp)
check("EC4 a break seen at (%d, %d)" % SEEN,
status == "found" and W - 1 < dp
and (W - 1, sum(counts)) == record_of(k, J),
"first vector at width %d, d = %d under the least pure degree "
"%d, tried %d" % (W, W - 1, dp, sum(counts)))
def stage_reference():
"""EC6: depth 12's extremal vector and the traded product of
(8, 15), each down its path in the engine and in suffixwalk.py's
walk, both floats against the exact E."""
v8 = F.traded(F.BREAK_PARTS, F.BREAK_R)
cases = ((1, 12, product(SW.RECORD[12][2][0])),
(8, 15, [-c for c in v8] if v8[-1] < 0 else v8))
for k, J, v in cases:
W = len(v)
gaps, back, sizes, _ = path_gaps(J, k, v)
trace = {}
SW.walk(J, W, k, path=v, trace=trace)
theirs = max(abs(SW.Fraction(e) - SW.energy_exact(J, m, v))
for m, e in trace.items())
mine = max(abs(g) for g in gaps.values())
check("EC6 the path form at (%d, %d), width %d, beside "
"suffixwalk.py's own float" % (k, J, W),
back and len(gaps) == W - J == len(trace) and mine <= sizes[5]
and theirs < 1e-9,
"%d levels, the engine's largest gap %.1e, the walk's %.1e, "
"B %.1e" % (len(gaps), mine, theirs, sizes[5]))
def stage_path_plant():
"""EC7: one bit of the table flipped on a row of an extremal path;
the engine's gap is the exact shift from that row down, 0 above."""
k, J = PATH_PLANT
v = product(CELLS[(k, J)][4][0])
W = len(v)
r, j = (J + W) // 2, J - 1
gi, A, den, _ = SW.levels(J, W - 1)[r]
mu = [sum(v[t] * comb(t, i) for t in range(r + 1, W)) for i in range(J)]
N = SW.Fraction(sum(g * m for g, m in zip(gi, mu)) + v[r] * A, den)
q = nearest(abs(gi[j]), den)
for bit in range(0, FB + 32, 4):
sgn = (1 if gi[j] > 0 else -1) * (-1 if (q >> bit) & 1 else 1)
dN = SW.Fraction(sgn * (1 << bit) * mu[j], 1 << FB)
shift = (2 * N * dN + dN * dN) * den / A
if abs(shift) >= SHIFT_MIN:
break
print(" the path plant at (%d, %d), width %d: row %d, entry %d, bit "
"%d, the exact shift %.6e" % (k, J, W, r, j, bit, float(shift)),
flush=True)
gaps, back, sizes, _ = path_gaps(J, k, v, (r, j, bit))
B = SW.Fraction(sizes[5])
good = sum(abs(g - (shift if m <= r else 0)) <= B
for m, g in gaps.items())
check("EC7 the planted path: its gap the shift from row %d down, 0 "
"above" % r,
good == len(gaps) == W - J and back and abs(shift) >= SHIFT_MIN,
"the path plant: %d of %d levels within B of the shift; the gap "
"at level %d %.3e, at level %d %.6e, at the bottom %.6e, B %.1e"
% (good, len(gaps), r + 1, float(gaps.get(r + 1, 0)), r,
float(gaps.get(r, 0)), float(gaps.get(J, 0)), sizes[5]))
def stage_paths():
"""EP5, EK5: the engine's float E against the exact one at every
level of each new cell's extremal vectors' paths, the vectors built
from CELLS' parts, NOT_PURE's as the walk listed them."""
good = levels = 0
alive = True
for (k, J), want in sorted(CELLS.items()):
for parts, v in ([(q, product(q)) for q in want[4]]
+ [("no pure product", list(v))
for v in NOT_PURE.get((k, J), ())]):
W = len(v)
assert (W == want[0] + 1 and F.height(v) <= k and F.clears(v, J)
and v[0] != 0)
gaps, back, sizes, E = path_gaps(J, k, v)
B = SW.Fraction(sizes[5])
good += sum(abs(g) <= B for g in gaps.values())
levels += W - J
alive = alive and back and len(gaps) == W - J
print(" (%d, %d), width %d, parts %s: %d of %d levels alive, "
"the largest gap %.1e, B %.1e, the largest E_m / (k^2 m) "
"%.4f" % (k, J, W, parts, len(gaps), W - J,
max(abs(g) for g in gaps.values()), sizes[5],
max(e / (k * k * m) for m, e in E.items())),
flush=True)
check("EK5 the engine's float E within its bound B of the exact one "
"down the new cells' extremal paths", alive and good == levels,
"the paths: %d of %d levels within B" % (good, levels))
def say_sizes(k, J, W, sizes):
print(" (%d, %d) at width %d: |Gq| %d bits, Aq %d, N %d, mu %d; "
"delta %.1e, B %.1e" % ((k, J, W) + tuple(sizes)), flush=True)
def stage_rate(J=16, W=158):
one = run_width(J, W, 1, 1, 1)
four = run_width(J, W, 1, PREFIX, 4)
print(" rate at (1, %d), width %d, %d children: one process %.2e a "
"second (%.1f s), four %.2e (%.1f s), %.2f times"
% (J, W, one[2], one[2] / one[3], one[3], four[2] / four[3],
four[3], one[3] / four[3]), flush=True)
assert one[:3] == four[:3]
def stage_cell(k, J, until):
dp = F.least_pure_degree(J, k, 400)[0]
back = []
status, W, vecs, counts, kept, sizes, secs = cell(
k, J, until, keep=True, say=True, dp=dp, back=back)
if back:
print(" READ BACK, NOT RUN: %d widths, %d to %d, from %s"
% (len(back), back[0], back[-1], DATA), flush=True)
below = sum(counts) - (counts[-1] if status == "found" else 0)
if sizes:
say_sizes(k, J, W, sizes)
want = CELLS.get((k, J)) if until is None else None
theirs = None
if until is None and k > 1:
theirs = SW.DIAL.get((k, J))
elif until is None and J in SW.RECORD:
d1, n1, parts1 = SW.RECORD[J]
theirs = (d1, d1, n1, parts1, 0)
how = " (%d widths read back, not run)" % len(back) if back else ""
if status != "found":
print(" (%d, %d): %s at width %d; no vector at any width to %d, "
"the least pure degree %d; %d children, %.0f s"
% (k, J, status, W, W - (status in ("late", "refused")), dp,
below, secs))
if want or theirs:
check("(%d, %d) at its record%s" % (k, J, how), False,
"no vector: %s" % status)
return
pure = [SW.pure_parts(v) for v in vecs]
print(" (%d, %d): first vector at width %d: d_%d(%d) = %d%s, least "
"pure degree %d, tried %d (%d below the last width), extremal "
"%d, not pure %d, %.1f s"
% (k, J, W, k, J, W - 1, ", a break" if W - 1 < dp else "", dp,
sum(counts), below, len(vecs), sum(q is None for q in pure),
secs))
for v, q in zip(vecs, pure):
print(" parts %s" % (q,) if q else
" no pure product: %s" % (v,))
got = (W - 1, dp, sum(counts), below,
tuple(sorted(q for q in pure if q)), sum(q is None for q in pure))
odd = sorted(tuple(v) for v, q in zip(vecs, pure) if q is None)
if want:
check("(%d, %d) at its record: d, the least pure degree, children "
"tried, those below the last width, the parts, the vectors "
"of no pure product%s" % (k, J, how),
got == want and odd == sorted(NOT_PURE.get((k, J), ())))
elif theirs:
check("(%d, %d) at suffixwalk.py's record: d, the least pure "
"degree, children tried, the parts%s" % (k, J, how),
got[:3] + got[4:] == theirs)
peak = max(kept, key=lambda m: kept[m])
print(" peak %d at suffix length %d of %d; the last level "
"alive below the top: %s"
% (kept[peak], W - int(peak), W, min(int(m) for m in kept)))
def main(argv):
t0 = time.time()
build()
if argv and argv[0] == "cell":
k, J = int(argv[1]), int(argv[2])
stage_cell(k, J, int(argv[3]) if len(argv) > 3 else None)
print("%.0f s" % (time.time() - t0))
sys.exit(0 if all(CHECKS) else 1)
if argv and argv[0] == "scan":
print(stage_scan(int(argv[1]), int(argv[2])))
return
if argv and argv[0] == "rate":
stage_rate(*(int(x) for x in argv[1:3]))
return
print("THE CONTROLS")
stage_seen()
stage_record(EC1_ALL if argv and argv[0] == "controls" else EC1_BARE)
stage_plant()
stage_shards()
for k, J, W in ((1, 15, 142), (8, 15, 56), (1, 17, 186), (2, 16, 119)):
text, sizes = table(J, W, k)
say_sizes(k, J, W, sizes)
check("EC5 the bound and the sizes under their limits at (%d, %d), "
"width %d" % (k, J, W), text is not None)
print("\nTHE PATHS")
stage_reference()
stage_path_plant()
stage_paths()
print("\n%d of %d checks, %.0f s"
% (sum(CHECKS), len(CHECKS), time.time() - t0))
sys.exit(0 if all(CHECKS) else 1)
if __name__ == "__main__":
main(sys.argv[1:])