members.py
Checks: DEGREE: At sixteen cells of depths 17 and 18 the pure law holds rule; DEGREE: A failing cell is a break on the dial property; DEGREE: At heights 8, 9 and 11 the dial breaks rule; FLATTEN: A traded pure product attains every failing cell of the chart rule; FLATTEN: The nine non-cyclotomic factors are reciprocal and need not sit on the circle observation; property.
To run it: save members.py, with flatten.py beside it; needs sympy.
"""members.py -- what the least-height polynomials are made of where
products of x^d - 1 lose: the factor they carry that is not cyclotomic,
the construction that rebuilds them from a pure product, and the same
trade read on the inverse dial's columns k = 9..12.
QUESTION. flatten.py finds h(M, J) < ph(M, J) at 83 cells of its chart
and one break on the inverse dial, d_8(15) = 55 against a least pure
degree of 56, where the witness is a pure product with ten degrees of
it traded for a factor that is not cyclotomic. Are the chart's
failures the same trade? If so, what are the traded factors, can the
trade be run forward as a construction with no lattice reduction in
it, and do the dial's next columns break the same way?
THE OBJECTS (flatten.py's senses). A vector of width M is P(x) =
sum c_i x^i of degree < M; its HEIGHT is max |c_i|; h(M, J) is the
least height of a nonzero P with (x - 1)^J | P; the PURE PRODUCTS are
prod (x^{g_i} - 1); ph is the least admissible pure height; a cell
FAILS when h < ph; d_k(J) is the least degree of a nonzero multiple
of (x - 1)^J of height at most k. The RANK is r = M - J.
THE SPLIT. Dividing out every cyclotomic factor and any power of x
leaves the RESIDUAL, well defined up to sign; its irreducible
factors over Z, a content above 1 among them as a constant, are
the vector's NON-CYCLOTOMIC FACTORS.
THE SEED. A = 2 + 4x + 5x^2 + 4x^3 + 2x^4, B = 2 + 3x + 2x^2 and
Q = 3 + 5x + 3x^2. THE SHAM is each with its coefficients
rearranged out of a palindrome: 5 + 4x + 4x^2 + 2x^3 + 2x^4,
3 + 2x + 2x^2, 5 + 3x + 3x^2.
THE SWAP FAMILY at a cell. An admissible pure cofactor is
q = (x - 1)^t prod_{d in E} [d]_x, [d]_x = 1 + x + ... + x^(d-1),
E a multiset of parts >= 2, with t + sum (d - 1) <= r - 1 and
|E| <= J + t (the other J + t - |E| parts are 1s). Its cyclotomic
multiset S is {1}^t with every divisor e > 1 of every d in E, and
prod_{n in S} Phi_n = q. A SWAP drops a sub-multiset of S and
brings in a MULTIPLIER, a product of members of the seed (or of
the sham), the empty product included, of exactly the dropped
degree:
(prod_{n in S'} Phi_n) * m * (x - 1)^J, S' within S,
deg m = deg q - sum_{n in S'} phi(n).
hs(M, J) is the least height over every swap of every admissible
q with the seed, hst with the sham, and hs0 over the EMPTY swaps
alone, m = 1, which are the admissible pure products.
THE CLASS TESTS on an irreducible factor f. It is a PALINDROME when
it reads the same reversed. A palindrome of even degree 2n is
x^n S(x + 1/x) with S, its TRACE POLYNOMIAL, of degree n, and
its roots lie on |z| = 1 exactly when S has n roots in [-2, 2].
An irreducible integer polynomial with every root on the circle
is a palindrome up to sign, and a monic one is cyclotomic
(Kronecker): so a factor that is not monic, or has a trace root
outside [-2, 2], is not cyclotomic.
THE ENGINE.
pmul, normal, value: a product, a polynomial stripped of its powers
of x with its leading sign turned positive, a value at a point.
factors(p): the irreducible factors over Z, by sympy's factor_list,
with multiplicity, a content above 1 among them.
trace(p), in integers, and circle_roots(p), how many roots of the
trace polynomial lie in [-2, 2] and its degree, by sympy's Sturm
count, which is of distinct roots: it reads a squarefree trace
polynomial, as an irreducible f's is; describe(f), the class
tests' eight fields.
rebuilds(v, mult, fs): whether v is, up to sign and a power of x,
the product of the Phi_n of mult and the factors fs. split(v):
flatten.cyclotomic_split's two, the residual's factors, rebuilds.
inside(v, M, J): v is a nonzero multiple of (x - 1)^J of degree < M,
by J divisions; height_in its height if so, else None. Every vector
an arm exhibits (a minimiser, an attaining swap, a break's witness)
is read through it: the searches that find them are finders alone.
pure_multisets(r, J), sub_multisets(S), multipliers(members,
maxdeg) and swap_height(M, J, members), which returns the least
height, a swap attaining it, hs0 and how many swaps it read.
chart_rows(): flatten.route's h and minimiser and flatten.ph_of's ph
at the chart's cells, J >= 2. split_row, swap_row, deep_row: one
cell each. dial_rows(jlo, jhi, cap): flatten.dial_row at k = 9..12,
J = jlo..jhi, under a cap of nodes a decision; break_row reads a
break's witness and sets it against the traded product TRADES
names.
split_record, swap_record, deep_record, hunt_record, class_record:
the records, functions of plain rows. factors_met gathers the
factors the stages exhibit; name_of names a residual.
What the script does not prove: that a minimiser is least (flatten.py's
rule, resting on its enumeration), that a "pure" cell of the dial holds
nothing below its pure degree or a break nothing below its d (the same
enumeration's float slack), that a pure degree is least (flatten.py's
walk), or that a factor is irreducible (sympy's word, read on hand
cases). And hs0 = ph is no finding: both are the least admissible pure
height, walked two ways, and the count reads the walks against each
other.
BY HAND, the controls' values.
Products. (x - 1)^2 Phi_3 = 1, -1, 0, -1, 1; times B: T6 = 2, 1, -1,
-4, -1, 1, 2, of width 7, depth exactly 2, height 4. A B = 4, 14,
26, 31, 26, 14, 4. B^2 = 4, 12, 17, 12, 4. B Q = 6, 19, 27, 19, 6.
Q^2 = 9, 30, 43, 30, 9. (2 + x)(1 + 2x) = 2, 5, 2. (x - 1)(4 + 6x +
4x^2) = -4, -2, 2, 4.
The split. T6 splits to Phi_1^2 Phi_3 with residual B, and so does
0, -2, -1, 1, 4, 1, -1, -2. -4, -2, 2, 4 splits to Phi_1, residual
4, 6, 4, factors 2 and B. A B factors to B, A; B^2 to B, B; 2, 5, 2,
a reducible palindrome, to 1 + 2x and 2 + x; 0, 0, 2, 3, 2 to B, the
power of x struck first. Irreducible: 5 + 9x +
5x^2 (discriminant -19); A and G = 3 + 6x + 8x^2 + 6x^3 + 3x^4,
whose trace polynomials 2y^2 + 4y + 1 and 3y^2 + 6y + 2 have
discriminants 8 and 12, no squares, and roots inside (-2, 2), so a
root z is not real while Q(y) is.
Values at 1 and -1. A 17, 1; B 7, 1; Q 11, 1; R 35, 1; N 17, 1; D
71, 1; E 193, 1; F 157, 1; G 26, 2. The sham: 17, 5; 7, 3; 11, 5.
Trace polynomials, from V_1 = y, V_2 = y^2 - 2, V_3 = y^3 - 3y, V_4
= y^4 - 4y^2 + 2, V_5 = y^5 - 5y^3 + 5y. B: 2y + 3, root -3/2. A:
2y^2 + 4y + 1, roots -1.707, -0.293. N: y^4 + y^3 - 2y^2 + 1, which
is 1, -1.8125, -1, 0.4375 at -2, -1.5, -1, -0.5 and at least 0.603
on y >= 0: 2 of 4 in [-2, 2]. E: 3y^4 + 11y^3 + 12y^2 + 4y + 1,
which is 1, -0.0752, 0.0625 at -2, -1.6, -1.5 and positive past
-1.5 (its other minimum 0.589, near -0.24): 2 of 4. R: 2y^5 + 3y^4
- 7y^3 - 9y^2 + 5y + 5. (x^2 - 3x + 1)(x^2 + x + 1) = 1, -2, -1,
-2, 1 has y^2 - 2y - 3 = (y - 3)(y + 1), 1 of 2; x^2 - 3x + 1 has
y - 3 and x^2 + 3x + 1 has y + 3, 0 of 1 each, one past either
end; (x - 1)^2 has y - 2 and (x + 1)^2 has y + 2, 1 of 1
each, the interval closed; Phi_5 has y^2 + y - 1, 2 of 2; Phi_15,
its eight roots on the circle, 4 of 4; v + (2v - 1)x + vx^2 has
vy + 2v - 1, root 1/v - 2, 1 of 1.
Inside a cell: (1, -2, 1) = (x - 1)^2 at width 3, depth 2; not at
depth 3, not at width 2; the zero vector nowhere; (0, 1, -2, 1) at
width 4 and not at width 3. T6 at (7, 2), not at (7, 3) nor (6, 2).
The pure family. pure_multisets(3, 1): (), (1), (1, 1), (2), (1, 2),
(3). (3, 2): those and (2, 2). (4, 1): (), (1), (1, 1), (1, 1, 1),
(2), (1, 2), (1, 1, 2), (1, 2, 2), (3), (1, 3), (2, 4). (4, 2):
those and (2, 2), (2, 3). (4, 3): and (2, 2, 2). The multiset fixes
the parts (its largest entry is a part; strike that part's divisors
and repeat), so no two cofactors share one. sub_multisets of (1, 1,
2): (), (1), (1, 1), (2), (1, 2), (1, 1, 2). multipliers of the seed
to degree 4: 1; B, Q; A, B^2, B Q, Q^2, and to degree 3 none of
degree 4; of B alone: 1; B; B^2; of
the seed at degree 6: A B, A Q, B^3, B^2 Q, B Q^2, Q^3. Degrees:
Phi_1 Phi_2 Phi_4 Phi_6 has 1 + 1 + 2 + 2 = 6, Phi_5^2 Phi_12 has
4 + 4 + 4 = 12.
A swap family whole, at (7, 4), rank 3. The seven empty swaps:
(x - 1)^4, height 6; with Phi_2, 1, -3, 2, 2, -3, 1, height 3; with
Phi_3, 1, -3, 3, -2, 3, -3, 1, 3; with Phi_2^2, 1, -2, -1, 4, -1,
-2, 1, 4; (x - 1)^5, 10; with Phi_2, 5; (x - 1)^6, 20. One trade,
two degrees dropped: (x - 1)^4 B = 2, -5, 2, 2, 2, -5, 2, height 5,
and (x - 1)^4 Q = 3, -7, 1, 6, 1, -7, 3, height 7. So hs = hs0 = 3,
nine swaps read with the seed, seven with no member, and the first
multiset in order to reach 3 is (2). At (5, 3), rank 2: (x - 1)^3,
3; (x - 1)^4, 6; with Phi_2, -1, 2, 0, -2, 1, height 2; with the toy
member 1 + 2x one trade, (x - 1)^3 (1 + 2x) = -1, 1, 3, -5, 2: hs =
hs0 = 2, four swaps, three with no member. At (3, 1) with the toy:
-1, 1 first, hs = hs0 = 1, four swaps.
The rows. split_row on T6 with h = 4, ph = 5: its height 4 inside
(7, 2), none at (6, 2) nor at (7, 3), rebuilt, B. deep_row at (3, 2):
the cell holds the integer multiples of (x - 1)^2 alone, so h = 2,
the minimiser inside at 2, Phi_1^2 with nothing left. swap_row at
the clean cells (5, 3) and (7, 4): seed and sham both at h, 2 and 3
(a trade is a lattice vector, so not below h, and h(7, 4) = 3 by
flatten.py's table, d_2(4) = 7), inside, three and nine swaps each;
at (7, 4) the row is handed h = 2 and ph = 5, so no field repeats
another.
describe on 1 + x^2, a palindrome with a zero coefficient and trace
y, and on 1 + x, of odd degree, no trace read.
The first failure, whole. The pure product of parts 1 six times, 2,
2, 3, 5 is 1, -6, 13, -9, -8, 14, 0, -7, -6, 16, -6, -7, 0, 14, -8,
-9, 13, -6, 1, by (x^2 - 1)^2 (x^3 - 1)(x^5 - 1) = 1, 0, -2, -1, 1,
1, 0, 1, 1, -1, -2, 0, 1 and six differences. Times A:
T23 = 2, -8, 7, 8, -9, -9, 6, 6, 0, 1, -6, 4, -6, 1, 0, 6, 6, -9,
-9, 8, 7, -8, 2
of width 23, depth exactly 10 (the other factors are 4, 3, 5 and 17
at 1), height 9. It is a swap at (23, 10): the cofactor with parts
2, 2, 3, 5, 5, of weight 12, one Phi_5 dropped for A. So hs(23, 10)
<= 9 by hand, and T23 splits to Phi_1^10 Phi_2^2 Phi_3 Phi_5 with
residual A. That hs is not below 9 and that hs0 = 10 there are
flatten.py's record's h and ph, and the sham's 10 the earlier form's
run (it reached h at no cell), none by hand. break_row on T23: at
(9, 10) with d = 22 its height 9, its split and the trade, with its
sign turned too; with d = 21 no height, T23 being 23 wide; at (9,
11) and (11, 15) no height, its depth being 10, and no trade named
or another's.
The records on plain rows, each clause missing somewhere.
split_record over nine cells, five failing, rows (h, ph, the
minimiser's height inside or None, rebuilt, factors): at (9, 4): 5,
6, 5, no, B; (5, 3): 2, 4, none, no, B and A; (8, 3): 7, 9, 7, yes,
nothing; (6, 2): 3, 5, 4, no, 1 + 2x and a content 2; (7, 2): 4, 8,
4, yes, B. Then inside at h at 3, rebuilt 2, residual 1 at 1; B at 2
cells, and 1, A*B and [1, 2]*[2] at one each; heights 2 to 7; the
first failure by depth (6, 2), the first of two at depth 2 and not
the narrowest cell, at 3 with residual [1, 2]*[2]; two factors
outside the seed, 1 + 2x and 2.
swap_record over four rows (h, ph, hs, the attaining swap's
height inside, hs0, swaps; the sham's hst, its swap's height inside,
its swaps): 5, 8, 5, 5, 8, 10; 8, 8, 10. 5, 8, 6, 6, 8, 20; 5, 5, 21.
3, 4, 3, none, 5, 1; 2, 3, 2. 3, 4, 2, 2, 3, 5; 6, 6, 5. Then the
attaining swap inside at hs at 3, hs0 = ph at 2; hs = h at 2, above
it at 1; the sham at h at 1, above h at 2, inside at hst at 3; 36
and 38 swaps. deep_record over (9, 4): 5, 5, yes, B and
(8, 3): 7, none, no, B and A: residuals A*B and B, inside 1,
rebuilt 1 of 2. hunt_record over two columns of three depths: (1,
1) pure at 1, floor 1, found one up; (1, 2) pure at 3, floor 4, not
found; (1, 3) capped at pure degree 6; (2, 1) pure at 1, floor 2,
found; (2, 2) a break, d = 4 against 5, floor 2, found; (2, 3)
capped at 7: six cells, three pure, two capped, one break; found
one up at 3 of the 4 decided, floor at or below d at 2; columns 1,
3 and 1, 4. class_record over the sham's 3 + 2x + 2x^2, G, the
mixed quartic (-3 at 1, 5 at -1), N, 1 + x, Phi_5 and x^2 - 3x + 1:
six palindromes, five with positive coefficients, of seven; not
read on the circle the sham's (no palindrome), the quartic (1 of
2), N (2 of 4), 1 + x (odd degree) and x^2 - 3x + 1 (0 of 1); a
value at -1 other than 1 at five (3, 2, 5, 0 and 5); monic the
quartic, N, 1 + x, Phi_5 and x^2 - 3x + 1; monic and read on the
circle Phi_5 alone.
FROZEN FOR THIS FORM, before its first draft ran. Seen in a run of the
form it replaces, or in a timing run of its pieces, unless marked
DERIVED, which no run had shown.
T1 THE SPLIT. 695 cells, 83 failing, flatten.py's record's pair;
each minimiser inside its cell at its height (DERIVED), rebuilt
from its split with its factors' product (DERIVED), none with
residual 1; B at 51 cells, A at 29, A*B at 2, Q at 1; heights 9
to 6323160; the first failure (23, 10) at 9 with residual A; no
factor outside the seed.
T2 THE SWAP. hs = h at 83 of 83; hs0 = ph at 83 of 83; the attaining
swap inside its cell at height hs at 83 of 83 (DERIVED); the sham
at 0 of 83, above h and at most ph at 83; 182027 swaps keyed with
the seed, and as many with the sham (DERIVED: the keys read
degrees alone).
T3 THE DEEP CELLS. h = 42222, 108376, 140702, 67323 at (52, 30),
(54, 32), (61, 34), (61, 33), residuals A*D, E, A*F, G; each
minimiser inside its cell (DERIVED).
T4 THE HUNT, J = 1..16 at 5000000 nodes. 64 cells, 62 pure, none
capped, breaks (9, 10, 22, 23) and (11, 15, 48, 49); found one
width up at 64 of 64; the floor at or below d at 64 (DERIVED);
the columns as recorded. The witnesses are, up to sign, T23 and N
times the pure product of parts 1 six times, 2, 2, 3, 3, 3, 4, 5,
5, 7 (DERIVED from the split the earlier form printed: degree 40
+ 8), of heights 9 and 11 (DERIVED: h(23, 10) = 9; d_10(15) = 51
leaves nothing of height 10 below width 52).
T5 THE EXTENSION, J = 17..20. 16 cells; pure (11, 17) and (12, 17)
at 59; the other 14 capped, at the least pure degrees recorded.
T6 THE CLASSES. The table of degrees, leading coefficients and
values; nine of nine palindromes with positive coefficients; a
root off the circle at E and N alone, each with 2 of 4 trace
roots in [-2, 2] (by hand, no run had counted them); a value at
-1 other than 1 at G alone; N alone monic.
KILL, read off the record's lines: a failing cell with hs above h; the
sham reaching h at all 83; no break on k = 9..12 at J <= 16; every
break's residual inside A, B, Q, R; an exhibited vector not inside its
cell.
FINDINGS (copied from the printed output).
(1) The eighteen control lines pass, 136 cases, by hand but for the
three at (23, 10) the hand block names and h(7, 4).
(2) T1 holds. 695 cells, 83 failing, flatten.py's record's pair. At
83 of 83 the minimiser is inside its cell at height h and is
rebuilt from its split; none has residual 1. The residual is B
at 51 cells, A at 29, A*B at 2 and Q at 1; the failing heights
run from 9 to 6323160; the first failure by depth is (23, 10) at
9 with residual A; no factor lies outside the seed.
(3) T2 holds and its kills miss. hs = h at 83 of 83, above it at
none; the attaining swap is inside its cell at height hs at 83;
the empty swaps' least is ph at 83. The sham reaches h at 0 of
the 83 and sits above it at 83, its attaining swap inside. Each
family read 509873 swaps.
(4) T3 holds. h(52, 30) = 42222 with residual A*D, h(54, 32) =
108376 with E, h(61, 33) = 67323 with G, h(61, 34) = 140702 with
A*F; 4 of 4 minimisers inside their cells at height h, rebuilt.
(5) T4 holds and its kills miss. At J = 1..16, 64 cells: 62 pure,
none capped, 2 breaks; found one width up at 64, the floor at
or below d at 64. d_9(10) = 22 against a least pure degree of
23, parts 1, 1, 1, 1, 2, 2, 3, 3, 4, 5: the witness, of height 9
inside (23, 10), is T23 up to sign, Phi_1^10 Phi_2^2 Phi_3 Phi_5
times A, the chart's first failure. d_11(15) = 48 against 49,
parts 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 5, 5, 6, 7: the witness,
of height 11 inside (49, 15), is N times the pure product of
parts 1 six times, 2, 2, 3, 3, 3, 4, 5, 5, 7, its cyclotomic
part Phi_1^15 Phi_2^3 Phi_3^3 Phi_4 Phi_5^2 Phi_7. The columns:
k = 9 1 2 3 4 6 7 10 12 17 22 24 31 37 45 53 58
k = 10 1 2 3 4 5 7 10 12 17 20 24 27 36 40 51 54
k = 11 1 2 3 4 5 7 10 12 16 20 24 27 36 40 48 54
k = 12 1 2 3 4 5 7 10 12 16 20 24 27 34 39 43 54
(6) T5 holds (python members.py extend). At J = 17..20, 16 cells:
pure at (11, 17) and (12, 17), d = 59 each, found one width up;
14 capped, at least pure degrees 69, 77, 84, 94 (k = 9); 67, 73,
83, 94 (k = 10); 73, 83, 90 (k = 11, J = 18..20); 69, 80, 88
(k = 12, J = 18..20). No break.
(7) T6 holds. A, B, D, E, F, G, N, Q, R have degrees 4, 2, 6, 8, 8,
4, 8, 2, 10, leading coefficients 2, 2, 3, 3, 3, 3, 1, 3, 2,
values 17, 7, 71, 193, 157, 26, 17, 11, 35 at 1 and 1 at -1 but
for G's 2. Nine of nine are palindromes with positive
coefficients. E and N alone are not read on the circle, each
with 2 of its 4 trace roots in [-2, 2]: four roots on the circle
and four off. N alone is monic, and none is monic with every
root on the circle, so none is cyclotomic.
(8) The weld, 3 of 3: the chart's (695, 83) and its first failure
(23, 10) at 9 are flatten.py's record's, and the break at k = 9
is that failure, d + 1 = 23.
What the record does not read: whether a minimiser is unique; ph at
the deep cells, so whether they fail; any column past k = 12 or
depth past 20; the 14 capped cells, where the pure degree is an
upper bound on d alone.
RUN RECORD. python members.py: 42 of 42 checks, 49.4 s (split 2.5 s,
swap 19.1 s, deep 7.5 s, hunt 20.1 s), peak commit 66.1 MB under a 512
MB guard. python members.py extend: 25 of 25 checks, 261.9 s, 53.0 MB.
The form it replaces ran 73.2 s at 65.9 MB bare and 301.3 s at 51.4 MB
with its hunt.
Changed after the lines were frozen. The first draft counted the swaps
it keyed, (S', dropped degree), 182027 with the seed and with the sham
as T2 has it; its reader showed that count reads degrees alone, so the
sham cut to one member kept it, and the record now counts the swaps
read, 509873, entered from a print with no hand value behind it; it
reads how many members each degree has, and the sham's coefficients
are its control line's. The
sham's "at most ph" left its line: hs0 = ph forces it. The deep cells
are read by split_row. Added from that reading, each by hand before
its run: the row functions' cases, a power of x and a content in the
split, a tie at the least failing depth, 1 + x^2 and 1 + x in the
class tests, degree_of.
Entered from a print of the earlier form: the record's lines, but for
those the hand block computes (the first failure's 9 and T23, the
values at 1 and -1, N's and E's trace counts) and N's witness as a
traded product, derived from that form's split.
Left with their arms, read by the earlier form's runs or by timing
its pieces. The empty
swaps gave ph at all 370 chart cells of ranks 5..18, the 287 clean
ones 34.9 s of its run. Every swap at the failing cells cleared its J
divisions, 9.3 s. The hunt's own cell, the walk, a decision and a step
down, re-found d_8(15) = 55 against 56; here that cell is flatten.py's
record and the columns are read through flatten.dial_row. Its columns
ran to a wall of 60 s each, reaching depth 20 in 67.5, 81.9, 70.3 and
62.0 s, the clock read before a cell: about 270 of its 300 s went to
the 14 capped cells. In floats, N's four roots off the circle had
moduli 0.8059 and 1.2408, and its Mahler measure was 1.540. The deep
cells cost 113881, 33787, 998492 and 365454 nodes; the largest
decision of the hunt 3581001, at (9, 15).
That form's frozen lines. P1 (a residual at all 83) and P2 (inside the
seed) held: T1. P3 (every factor at the 83 and at the height-8 break a
palindrome, on the circle, not monic, 1 at -1) held. P4 (hs = h at
the 83) and P5 (the sham at fewer) held: T2. P6 (a break on k = 9..12
within its walls, every break's factors passing P3's tests) held in
its first clause, T4, and died in its second at (11, 15), N being
monic and off the circle; of the deep cells' factors, under no frozen
line, E leaves the circle and G is 2 at -1. P7 (a factor outside A, B,
Q, R) held: T4. K1..K6 were P2..P7's kills and share their fates. Its
bug lines: hs or the sham's hst below h, a split that does not
rebuild, a break's witness above k or not cleared, are the inside,
rebuilt and height fields here; a residual with a cyclotomic factor
is the class record's empty "monic with every root on the circle";
hs or hst above ph is not read, hs0 = ph forcing both.
Edits no check notices. Of the meter's 357 sites, 344 red, 13 moving
no line, each equivalent on what the script feeds it: normal's two
length guards, dropped or loosened, and its sign test moved to 0 or
1, on a nonzero polynomial (six); divisors_gt1 one past d;
pure_multisets one part
past its budget; multipliers two degrees past the rank's bound, which
no swap drops; hs0 at a tie; trace's p_(n-k) for p_(n+k) on a
palindrome; and class_record's two tests of None on fields that are
None together. A first meter had 19: six had a case and got it (a
trace root below -2, a trailing zero, a multiplier past an odd bound,
two record fields the hand rows had not parted, and the first
failure's tie on the width, which the cells' order makes and which
was cut). Three checks no site fails: the sham's line and the factors
outside the seed, each failed by a hand break below, and the count of
check lines. By hand three more edits pass: the inside read of the
attaining swap, the seed's and the sham's (no input reaches it with a
swap outside its cell, each being built as a multiple of (x - 1)^J of
degree below M), and the multisets taken in set order.
Broken by hand, single edits, each named by the lines it would fail
before its run, the control stop lifted. On the drafts: 14 of the
harness and the tables, then 16 a reader proposed, 26 red, three green
(the three above, the third marked unsure), one stopped at 900 s and
unread (the pure table cut to degree 30). On this form 15: the hunt a
depth short, from depth 2, or at 3000000 nodes; three columns; a trade
with a wrong part; R or the deep cells' factors left out of the
classes; a deep cell dropped; the swap handed ph for h, or a cell
short; the chart's last cell unsplit or its first unread; the sham's
second member made B; the seed's factors listed as outside it; the
first failure taken by width: 15 red, two to eight lines each, the
lines named for 14, and for the last the real lines where its hand
row was named, which then had the narrowest cell the shallowest; with
the rows parted it fails its hand row too, as does a tie taken last.
"""
import sys
import time
import sympy as sp
import flatten
X = sp.Symbol("x")
Y = sp.Symbol("y")
SEED = {"A": (2, 4, 5, 4, 2), "B": (2, 3, 2), "Q": (3, 5, 3)}
SHAM = {"A~": (5, 4, 4, 2, 2), "B~": (3, 2, 2), "Q~": (5, 3, 3)}
NAMED = dict(SEED, R=tuple(flatten.BREAK_R),
N=(1, 1, 2, 3, 3, 3, 2, 1, 1),
D=(3, 9, 15, 17, 15, 9, 3),
E=(3, 11, 24, 37, 43, 37, 24, 11, 3),
F=(3, 10, 20, 29, 33, 29, 20, 10, 3),
G=(3, 6, 8, 6, 3))
NAMES = {f: name for name, f in NAMED.items()}
DEEP = ((52, 30), (54, 32), (61, 34), (61, 33))
COLUMNS = range(9, 13)
TRADES = {(9, 10): ((1,) * 6 + (2, 2, 3, 5), "A"),
(11, 15): ((1,) * 6 + (2, 2, 3, 3, 3, 4, 5, 5, 7), "N")}
# ------------------------------------------------------------ polynomials
def pmul(a, b):
out = [0] * (len(a) + len(b) - 1)
for i, x in enumerate(a):
if x:
for j, y in enumerate(b):
out[i + j] += x * y
return out
def normal(p):
"""p with its powers of x and trailing zeros struck and its sign
turned to a positive leading coefficient."""
p = list(p)
while len(p) > 1 and p[-1] == 0:
p.pop()
while len(p) > 1 and p[0] == 0:
p.pop(0)
return [-c for c in p] if p[-1] < 0 else p
def value(p, x):
return sum(c * x ** i for i, c in enumerate(p))
def factors(p):
"""The irreducible factors over Z of p, each normalised, with
multiplicity, sorted; a content above 1 among them, as a
constant."""
p = normal(p)
content, fl = sp.factor_list(sp.Poly(p[::-1], X).as_expr())
out = [(abs(int(content)),)] if abs(content) != 1 else []
for f, m in fl:
c = [int(v) for v in sp.Poly(f, X).all_coeffs()[::-1]]
out += [tuple(normal(c))] * m
return tuple(sorted(out))
def trace(p):
"""S, low degree first, with p = x^n S(x + 1/x), p a palindrome of
degree 2n: S = p_n + sum_k p_(n+k) V_k, V_0 = 2, V_1 = y,
V_(k+1) = y V_k - V_(k-1)."""
n = (len(p) - 1) // 2
S = [p[n]] + [0] * n
prev, cur = [2], [0, 1]
for k in range(1, n + 1):
for i, c in enumerate(cur):
S[i] += p[n + k] * c
prev, cur = cur, [a - b for a, b in
zip([0] + cur, prev + [0, 0], strict=True)]
return S
def circle_roots(p):
"""(how many roots of the trace polynomial of p lie in [-2, 2],
its degree), p a palindrome of even degree."""
S = trace(p)
return int(sp.Poly(S[::-1], Y).count_roots(-2, 2)), len(S) - 1
def describe(f):
"""(degree, leading coefficient, value at 1, value at -1, whether a
palindrome, whether every coefficient is positive, the trace roots
in [-2, 2] and of how many, both None unless f is a palindrome of
even degree)."""
f = list(f)
pal = f == f[::-1]
on, of = circle_roots(f) if pal and len(f) % 2 == 1 else (None, None)
return (len(f) - 1, f[-1], value(f, 1), value(f, -1), pal,
min(f) > 0, on, of)
def rebuilds(v, mult, fs):
"""v is, up to sign and a power of x, the product of Phi_n^mult[n]
and the factors fs."""
back = [1]
for f in fs:
back = pmul(back, f)
for n, m in mult.items():
for _ in range(m):
back = pmul(back, flatten.phi(n))
return normal(back) == normal(v)
def split(v):
"""({n: multiplicity of Phi_n}, the residual, its factors, whether
they rebuild v)."""
mult, res = flatten.cyclotomic_split(v)
fs = factors(res)
return mult, tuple(res), fs, rebuilds(v, mult, fs)
def name_of(fs):
"""A residual's name from its factors: the named ones by name, the
rest as lists, "1" for none."""
return "*".join(sorted(NAMES.get(tuple(f), str(list(f)))
for f in fs)) or "1"
# -------------------------------------------------------------- a witness
def inside(v, M, J):
"""v is a nonzero multiple of (x - 1)^J of degree < M."""
return len(v) <= M and any(v) and flatten.clears(v, J)
def height_in(v, M, J):
"""v's height if v is a vector inside the cell (M, J), else None."""
if v is None or not inside(v, M, J):
return None
return flatten.height(v)
# --------------------------------------------------------------- the swap
def divisors_gt1(d):
return [e for e in range(2, d + 1) if d % e == 0]
def pure_multisets(r, J):
"""The cyclotomic multisets S (sorted tuples) of the admissible
pure cofactors of rank r at depth J."""
out = set()
def walk(E, budget, last):
# E: parts >= 2 so far; budget: degree left for t + more parts
for t in range(budget + 1):
if len(E) <= J + t:
out.add(tuple(sorted(
[1] * t + [e for d in E for e in divisors_gt1(d)])))
for d in range(last, budget + 2):
walk(E + [d], budget - (d - 1), d)
walk([], r - 1, 2)
return out
def sub_multisets(S):
res = [()]
for n in sorted(set(S)):
res = [s + (n,) * k for s in res for k in range(S.count(n) + 1)]
return res
def multipliers(members, maxdeg):
"""{degree: [polynomials]}, every product of members of degree
<= maxdeg, the empty product at degree 0."""
out = {0: [[1]]}
items = [list(f) for f in members.values()]
def walk(p, i):
for j in range(i, len(items)):
q = pmul(p, items[j])
if len(q) - 1 <= maxdeg:
out.setdefault(len(q) - 1, []).append(q)
walk(q, j)
walk([1], 0)
return out
def degree_of(S):
"""The degree of prod_{n in S} Phi_n."""
return sum(len(flatten.phi(n)) - 1 for n in S)
def swap_height(M, J, members):
"""(hs, a swap attaining it, hs0, swaps): the least height over
the swap family of the cell with these members, the first swap to
reach it with the multisets taken in order, the least over the
empty swaps alone, and how many swaps were read, each (S', dropped
degree) once."""
r = M - J
base = flatten.pow_xm1(J)
mults = multipliers(members, r - 1)
seen, cyc = set(), {}
best = arg = hs0 = None
swaps = 0
for S in sorted(pure_multisets(r, J)):
deg = degree_of(S)
for Sp in sub_multisets(S):
delta = deg - degree_of(Sp)
if (Sp, delta) in seen or delta not in mults:
continue
seen.add((Sp, delta))
if Sp not in cyc:
p = base
for n in Sp:
p = pmul(p, flatten.phi(n))
cyc[Sp] = p
for m in mults[delta]:
v = pmul(cyc[Sp], m)
swaps += 1
hv = flatten.height(v)
if best is None or hv < best:
best, arg = hv, v
if delta == 0 and (hs0 is None or hv < hs0):
hs0 = hv
return best, arg, hs0, swaps
# ---------------------------------------------------------------- the rows
def chart_rows():
"""{(M, J): (h, ph, the route's minimiser)} over the chart's cells,
J >= 2."""
table = flatten.pure_table(39)
rows = {}
for (M, J) in flatten.chart_cells():
if J >= 2:
h, v, _ = flatten.least_height(M, J)
rows[(M, J)] = (h, flatten.ph_of(table, M, J)[0], v)
return rows
def split_row(M, J, h, ph, v):
"""(h, ph, v's height inside the cell or None, whether its split
rebuilds it, its residual's factors)."""
_, _, fs, rebuilt = split(v)
return h, ph, height_in(v, M, J), rebuilt, fs
def swap_row(M, J, h, ph):
hs, v, hs0, swaps = swap_height(M, J, SEED)
hst, vt, _, swapst = swap_height(M, J, SHAM)
return {"h": h, "ph": ph, "hs": hs, "in": height_in(v, M, J),
"hs0": hs0, "swaps": swaps, "hst": hst,
"int": height_in(vt, M, J), "swapst": swapst}
def deep_row(M, J):
"""split_row at the route's own h and minimiser, no ph read."""
h, v, _ = flatten.least_height(M, J)
return split_row(M, J, h, None, v)
def dial_rows(jlo, jhi, cap):
"""flatten.dial_row at k = 9..12, J = jlo..jhi."""
return {(k, J): flatten.dial_row(k, J, cap)
for k in COLUMNS for J in range(jlo, jhi + 1)}
def break_row(k, J, d, v):
"""A break's witness: (its height inside (d + 1, J) or None,
whether its split rebuilds it, its cyclotomic factors, its
residual's factors, whether it is up to sign the traded product
TRADES names at (k, J))."""
mult, _, fs, rebuilt = split(v)
trade = TRADES.get((k, J))
return (height_in(v, d + 1, J), rebuilt, tuple(sorted(mult.items())),
fs, trade is not None and flatten.same_up_to_sign(
v, flatten.traded(trade[0], NAMED[trade[1]])))
def factors_met(*groups):
"""The distinct factors in the groups of factor tuples, sorted."""
return tuple(sorted(set(f for fs in groups for f in fs)))
# ------------------------------------------------------------- the records
def split_record(ncells, rows):
"""rows: split_row's, by cell, over the failing cells of ncells."""
cells = sorted(rows)
census = {}
for c in cells:
census[name_of(rows[c][4])] = census.get(name_of(rows[c][4]), 0) + 1
first = min(cells, key=lambda c: c[1])
seed = set(SEED.values())
return {
"cells, with h < ph": (ncells, len(cells)),
"failing cells: the minimiser inside its cell at height h, "
"rebuilt from its split, with residual 1": (
sum(1 for c in cells if rows[c][2] == rows[c][0]),
sum(1 for c in cells if rows[c][3]),
sum(1 for c in cells if not rows[c][4])),
"failing cells by residual": tuple(
sorted(census.items(), key=lambda kv: (-kv[1], kv[0]))),
"failing heights: least, largest": (
min(rows[c][0] for c in cells), max(rows[c][0] for c in cells)),
"the first failure by depth: M, J, h, its residual":
first + (rows[first][0], name_of(rows[first][4])),
"factors met outside the seed": tuple(
f for f in factors_met(*(rows[c][4] for c in cells))
if f not in seed),
}
def swap_record(rows):
"""rows: swap_row's, by cell."""
w = [rows[c] for c in sorted(rows)]
return {
"cells; the attaining swap inside its cell at height hs; the "
"empty swaps' least is ph": (
len(w), sum(1 for x in w if x["in"] == x["hs"]),
sum(1 for x in w if x["hs0"] == x["ph"])),
"cells with hs = h, with hs above h": (
sum(1 for x in w if x["hs"] == x["h"]),
sum(1 for x in w if x["hs"] > x["h"])),
"the sham: cells with hst = h, with hst above h, its attaining "
"swap inside its cell at height hst": (
sum(1 for x in w if x["hst"] == x["h"]),
sum(1 for x in w if x["hst"] > x["h"]),
sum(1 for x in w if x["int"] == x["hst"])),
"swaps read over the cells: the seed's, the sham's": (
sum(x["swaps"] for x in w), sum(x["swapst"] for x in w)),
}
def deep_record(rows):
"""rows: deep_row's, by cell."""
cells = sorted(rows)
return {
"deep cells: M, J, h, its residual": tuple(
c + (rows[c][0], name_of(rows[c][4])) for c in cells),
"cells; the minimiser inside its cell at height h; rebuilt from "
"its split": (
len(cells), sum(1 for c in cells if rows[c][2] == rows[c][0]),
sum(1 for c in cells if rows[c][3])),
}
def hunt_record(rows, breaks):
"""rows: flatten.dial_row's, by (k, J); breaks: break_row's at the
cells whose verdict is "break"."""
cells = sorted(rows)
decided = [c for c in cells if rows[c][2] != "capped"]
return {
"cells, pure, capped, breaks": (
len(cells), sum(1 for c in cells if rows[c][2] == "pure"),
len(cells) - len(decided),
sum(1 for c in cells if rows[c][2] == "break")),
"decided cells: found one width up, the floor at or below d": (
sum(1 for c in decided if rows[c][5]),
sum(1 for c in decided if rows[c][4] <= rows[c][3])),
"d by column over the decided cells, in depth order": tuple(
tuple(rows[c][3] for c in decided if c[0] == k)
for k in sorted(set(c[0] for c in cells))),
"capped: k, J, least pure degree": tuple(
c + (rows[c][0],) for c in cells if rows[c][2] == "capped"),
"breaks: k, J, d, least pure degree, its parts": tuple(
c + (rows[c][3], rows[c][0], rows[c][1]) for c in sorted(breaks)),
"breaks: the witness's height inside (d + 1, J), rebuilt from its "
"split, its cyclotomic factors, its residual, whether it is the "
"traded product named": tuple(
breaks[c][:3] + (name_of(breaks[c][3]), breaks[c][4])
for c in sorted(breaks)),
}
def class_record(found):
"""found: {name: factor}."""
names = sorted(found)
d = {n: describe(found[n]) for n in names}
return {
"factors: name, degree, leading coefficient, value at 1, value "
"at -1": tuple((n,) + d[n][:4] for n in names),
"palindromes, with positive coefficients, of how many": (
sum(1 for n in names if d[n][4]),
sum(1 for n in names if d[n][5]), len(names)),
"not every root read on the circle: name, trace roots in "
"[-2, 2], of how many": tuple((n,) + d[n][6:] for n in names
if d[n][6] is None or d[n][6] < d[n][7]),
"value at -1 other than 1; monic; monic with every root on the "
"circle": (
tuple(n for n in names if d[n][3] != 1),
tuple(n for n in names if d[n][1] == 1),
tuple(n for n in names if d[n][1] == 1
and d[n][6] is not None and d[n][6] == d[n][7])),
}
# -------------------------------------------------------------- the stages
def stage_split():
"""The chart's failing cells, each minimiser split."""
chart = chart_rows()
rows = {c: split_row(*c, *chart[c])
for c in flatten.failing(chart, sorted(chart))}
return rows, split_record(len(chart), rows)
def stage_swap(rows):
"""The swap family, seed and sham, at the cells of rows."""
return swap_record({c: swap_row(c[0], c[1], rows[c][0], rows[c][1])
for c in rows})
def stage_deep():
rows = {c: deep_row(*c) for c in DEEP}
return rows, deep_record(rows)
def stage_hunt(jlo, jhi, cap):
"""The dial's columns k = 9..12 at J = jlo..jhi."""
rows = dial_rows(jlo, jhi, cap)
breaks = {c: break_row(c[0], c[1], rows[c][3], rows[c][6])
for c in rows if rows[c][2] == "break"}
return breaks, hunt_record(rows, breaks)
def stage_classes(met):
"""The class tests on the factors met."""
return class_record({name_of((f,)): f for f in met})
# ------------------------------------------------------------- the record
RECORD = {
"split": {
"cells, with h < ph": (695, 83),
"failing cells: the minimiser inside its cell at height h, "
"rebuilt from its split, with residual 1": (83, 83, 0),
"failing cells by residual":
(("B", 51), ("A", 29), ("A*B", 2), ("Q", 1)),
"failing heights: least, largest": (9, 6323160),
"the first failure by depth: M, J, h, its residual":
(23, 10, 9, "A"),
"factors met outside the seed": (),
},
"swap": {
"cells; the attaining swap inside its cell at height hs; the "
"empty swaps' least is ph": (83, 83, 83),
"cells with hs = h, with hs above h": (83, 0),
"the sham: cells with hst = h, with hst above h, its attaining "
"swap inside its cell at height hst": (0, 83, 83),
"swaps read over the cells: the seed's, the sham's":
(509873, 509873),
},
"deep": {
"deep cells: M, J, h, its residual": (
(52, 30, 42222, "A*D"), (54, 32, 108376, "E"),
(61, 33, 67323, "G"), (61, 34, 140702, "A*F")),
"cells; the minimiser inside its cell at height h; rebuilt from "
"its split": (4, 4, 4),
},
"hunt": {
"cells, pure, capped, breaks": (64, 62, 0, 2),
"decided cells: found one width up, the floor at or below d":
(64, 64),
"d by column over the decided cells, in depth order": (
(1, 2, 3, 4, 6, 7, 10, 12, 17, 22, 24, 31, 37, 45, 53, 58),
(1, 2, 3, 4, 5, 7, 10, 12, 17, 20, 24, 27, 36, 40, 51, 54),
(1, 2, 3, 4, 5, 7, 10, 12, 16, 20, 24, 27, 36, 40, 48, 54),
(1, 2, 3, 4, 5, 7, 10, 12, 16, 20, 24, 27, 34, 39, 43, 54)),
"capped: k, J, least pure degree": (),
"breaks: k, J, d, least pure degree, its parts": (
(9, 10, 22, 23, (1, 1, 1, 1, 2, 2, 3, 3, 4, 5)),
(11, 15, 48, 49,
(1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 5, 5, 6, 7))),
"breaks: the witness's height inside (d + 1, J), rebuilt from its "
"split, its cyclotomic factors, its residual, whether it is the "
"traded product named": (
(9, True, ((1, 10), (2, 2), (3, 1), (5, 1)), "A", True),
(11, True, ((1, 15), (2, 3), (3, 3), (4, 1), (5, 2), (7, 1)),
"N", True)),
},
"classes": {
"factors: name, degree, leading coefficient, value at 1, value "
"at -1": (
("A", 4, 2, 17, 1), ("B", 2, 2, 7, 1), ("D", 6, 3, 71, 1),
("E", 8, 3, 193, 1), ("F", 8, 3, 157, 1), ("G", 4, 3, 26, 2),
("N", 8, 1, 17, 1), ("Q", 2, 3, 11, 1), ("R", 10, 2, 35, 1)),
"palindromes, with positive coefficients, of how many": (9, 9, 9),
"not every root read on the circle: name, trace roots in "
"[-2, 2], of how many": (("E", 2, 4), ("N", 2, 4)),
"value at -1 other than 1; monic; monic with every root on the "
"circle": (("G",), ("N",), ()),
},
"extend": {
"cells, pure, capped, breaks": (16, 2, 14, 0),
"decided cells: found one width up, the floor at or below d":
(2, 2),
"d by column over the decided cells, in depth order":
((), (), (59,), (59,)),
"capped: k, J, least pure degree": (
(9, 17, 69), (9, 18, 77), (9, 19, 84), (9, 20, 94),
(10, 17, 67), (10, 18, 73), (10, 19, 83), (10, 20, 94),
(11, 18, 73), (11, 19, 83), (11, 20, 90),
(12, 18, 69), (12, 19, 80), (12, 20, 88)),
"breaks: k, J, d, least pure degree, its parts": (),
"breaks: the witness's height inside (d + 1, J), rebuilt from its "
"split, its cyclotomic factors, its residual, whether it is the "
"traded product named": (),
},
}
BARE = ("split", "swap", "deep", "hunt", "classes")
CONTROL_LINES = 18
CHECKS = []
def check(name, ok, detail=""):
CHECKS.append(bool(ok))
print(f" [{'PASS' if ok else 'FAIL'}] {name}"
+ (f" {detail}" if detail else ""))
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(stage, got):
want = RECORD[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))
A, B, Q = SEED["A"], SEED["B"], SEED["Q"]
T6 = [2, 1, -1, -4, -1, 1, 2]
T23 = [2, -8, 7, 8, -9, -9, 6, 6, 0, 1, -6, 4, -6, 1, 0, 6, 6, -9, -9, 8,
7, -8, 2]
MIXED = [1, -2, -1, -2, 1]
HAND_SPLIT = {
(9, 4): (5, 6, 5, False, (B,)),
(5, 3): (2, 4, None, False, (B, A)),
(8, 3): (7, 9, 7, True, ()),
(6, 2): (3, 5, 4, False, ((1, 2), (2,))),
(7, 2): (4, 8, 4, True, (B,)),
}
HAND_SWAP = {
(9, 4): {"h": 5, "ph": 8, "hs": 5, "in": 5, "hs0": 8, "swaps": 10,
"hst": 8, "int": 8, "swapst": 10},
(8, 3): {"h": 5, "ph": 8, "hs": 6, "in": 6, "hs0": 8, "swaps": 20,
"hst": 5, "int": 5, "swapst": 21},
(7, 3): {"h": 3, "ph": 4, "hs": 3, "in": None, "hs0": 5, "swaps": 1,
"hst": 2, "int": 3, "swapst": 2},
(6, 2): {"h": 3, "ph": 4, "hs": 2, "in": 2, "hs0": 3, "swaps": 5,
"hst": 6, "int": 6, "swapst": 5},
}
HAND_DIAL = {
(1, 1): (1, (1,), "pure", 1, 1, True, None),
(1, 2): (3, (1, 2), "pure", 3, 4, False, None),
(1, 3): (6, (1, 2, 3), "capped", None, None, None, None),
(2, 1): (1, (1,), "pure", 1, 2, True, None),
(2, 2): (5, (1, 4), "break", 4, 2, True, None),
(2, 3): (7, (1, 2, 4), "capped", None, None, None, None),
}
HAND_BREAKS = {(2, 2): (2, True, ((1, 2),), (B,), False)}
def section_controls():
section("CONTROLS: each function on values written by hand")
check_hand("pmul, normal and value", [
(pmul([1, -2, 1], [1, 1, 1]), [1, -1, 0, -1, 1]),
(pmul([1, -1, 0, -1, 1], B), T6),
(pmul(A, B), [4, 14, 26, 31, 26, 14, 4]),
(pmul(B, Q), [6, 19, 27, 19, 6]),
(normal([0, -2, -1, 1, 4, 1, -1, -2, 0]), T6),
(normal([0, 0, 3]), [3]), (normal([3, 0, 0]), [3]),
(normal(T6), T6),
(value(A, 1), 17), (value(A, -1), 1), (value(T23, 1), 0),
(value(NAMED["G"], -1), 2), (value([1, -3, 1], -1), 5)])
check_hand("factors on nine hand polynomials", [
(factors([0, 0, 2, 3, 2]), (B,)),
(factors([4, 14, 26, 31, 26, 14, 4]), (B, A)),
(factors([4, 12, 17, 12, 4]), (B, B)),
(factors([2, 5, 2]), ((1, 2), (2, 1))),
(factors([4, 6, 4]), ((2,), B)),
(factors(A), (A,)), (factors(NAMED["G"]), (NAMED["G"],)),
(factors([5, 9, 5]), ((5, 9, 5),)), (factors([1]), ())])
check_hand("trace on six palindromes, circle_roots on twelve", [
(trace(B), [3, 2]), (trace(A), [1, 4, 2]),
(trace(NAMED["N"]), [1, 0, -2, 1, 1]),
(trace(NAMED["E"]), [1, 4, 12, 11, 3]),
(trace(NAMED["R"]), [5, 5, -9, -7, 3, 2]),
(trace(MIXED), [-3, -2, 1]),
(circle_roots(B), (1, 1)), (circle_roots(A), (2, 2)),
(circle_roots(NAMED["N"]), (2, 4)),
(circle_roots(NAMED["E"]), (2, 4)),
(circle_roots(MIXED), (1, 2)), (circle_roots([1, -3, 1]), (0, 1)),
(circle_roots([1, -2, 1]), (1, 1)),
(circle_roots([1, 2, 1]), (1, 1)),
(circle_roots([1, 3, 1]), (0, 1)),
(circle_roots(flatten.phi(5)), (2, 2)),
(circle_roots(flatten.phi(15)), (4, 4)),
(tuple(circle_roots([v, 2 * v - 1, v]) for v in range(2, 10)),
((1, 1),) * 8)])
check_hand("describe on six polynomials", [
(describe(NAMED["G"]), (4, 3, 26, 2, True, True, 2, 2)),
(describe(NAMED["N"]), (8, 1, 17, 1, True, True, 2, 4)),
(describe(SHAM["A~"]), (4, 2, 17, 5, False, True, None, None)),
(describe([1, -3, 1]), (2, 1, -1, 5, True, False, 0, 1)),
(describe([1, 0, 1]), (2, 1, 2, 2, True, False, 1, 1)),
(describe([1, 1]), (1, 1, 2, 0, True, True, None, None))])
check_hand("the sham: the seed's coefficients rearranged, no "
"palindrome, its values at -1", [
(tuple(sorted(f) for f in SHAM.values()),
tuple(sorted(f) for f in SEED.values())),
(sum(1 for f in SHAM.values() if f == f[::-1]), 0),
(sum(1 for f in SEED.values() if f == f[::-1]), 3),
(tuple(value(f, -1) for f in SHAM.values()), (5, 3, 5))])
check_hand("rebuilds on six cases, split on four vectors", [
(rebuilds(T6, {1: 2, 3: 1}, (B,)), True),
(rebuilds([0] + [-c for c in T6], {1: 2, 3: 1}, (B,)), True),
(rebuilds(T6, {1: 2}, (B,)), False),
(rebuilds(T6, {1: 2, 3: 1}, ()), False),
(rebuilds([-4, -2, 2, 4], {1: 1}, (B,)), False),
(rebuilds([-4, -2, 2, 4], {1: 1}, ((2,), B)), True),
(split(T6), ({1: 2, 3: 1}, B, (B,), True)),
(split([0, -2, -1, 1, 4, 1, -1, -2]),
({1: 2, 3: 1}, B, (B,), True)),
(split([-4, -2, 2, 4]), ({1: 1}, (4, 6, 4), ((2,), B), True)),
(split(T23), ({1: 10, 2: 2, 3: 1, 5: 1}, A, (A,), True))])
check_hand("name_of on five residuals, factors_met on three groups", [
(name_of((B, A)), "A*B"), (name_of(()), "1"),
(name_of(((1, 2),)), "[1, 2]"), (name_of((NAMED["R"],)), "R"),
(name_of((B, B)), "B*B"),
(factors_met((B, A), (), (B, (1, 2))), ((1, 2), B, A))])
check_hand("inside on eleven vectors, widths and depths, height_in "
"on four", [
(inside([1, -2, 1], 3, 2), True),
(inside([1, -2, 1], 3, 3), False),
(inside([1, -2, 1], 2, 2), False),
(inside([0, 0, 0], 3, 2), False),
(inside([0, 1, -2, 1], 4, 2), True),
(inside([0, 1, -2, 1], 3, 2), False),
(inside(T6, 7, 2), True), (inside(T6, 7, 3), False),
(inside(T6, 6, 2), False),
(inside(T23, 23, 10), True),
(inside(T23, 23, 11), False),
(height_in([1, -2, 1], 3, 2), 2),
(height_in([1, -2, 1], 3, 3), None),
(height_in(None, 3, 2), None),
(height_in(T23, 23, 10), 9)])
check_hand("pure_multisets at five cells, sub_multisets, multipliers, "
"degree_of", [
(pure_multisets(3, 1), {(), (1,), (1, 1), (2,), (1, 2), (3,)}),
(pure_multisets(3, 2) - pure_multisets(3, 1), {(2, 2)}),
(pure_multisets(4, 1),
{(), (1,), (1, 1), (1, 1, 1), (2,), (1, 2), (1, 1, 2), (1, 2, 2),
(3,), (1, 3), (2, 4)}),
(pure_multisets(4, 2) - pure_multisets(4, 1), {(2, 2), (2, 3)}),
(pure_multisets(4, 3) - pure_multisets(4, 2), {(2, 2, 2)}),
(sorted(sub_multisets((1, 1, 2))),
[(), (1,), (1, 1), (1, 1, 2), (1, 2), (2,)]),
(multipliers(SEED, 4),
{0: [[1]], 2: [list(B), list(Q)],
4: [list(A), [4, 12, 17, 12, 4], [6, 19, 27, 19, 6],
[9, 30, 43, 30, 9]]}),
(multipliers({"B": B}, 4),
{0: [[1]], 2: [list(B)], 4: [[4, 12, 17, 12, 4]]}),
(sorted((d, len(ms)) for d, ms in multipliers(SEED, 6).items()),
[(0, 1), (2, 2), (4, 4), (6, 6)]),
(sorted(multipliers(SEED, 3)), [0, 2]),
(degree_of(()), 0), (degree_of((1, 2, 4, 6)), 6),
(degree_of((5, 5, 12)), 12)])
toy = {"T": (1, 2)}
check_hand("swap_height at (7, 4), (5, 3) and (3, 1), with the seed, "
"a toy member and none", [
(swap_height(7, 4, SEED), (3, [1, -3, 2, 2, -3, 1], 3, 9)),
(swap_height(7, 4, {}), (3, [1, -3, 2, 2, -3, 1], 3, 7)),
(swap_height(5, 3, toy), (2, [-1, 2, 0, -2, 1], 2, 4)),
(swap_height(5, 3, {}), (2, [-1, 2, 0, -2, 1], 2, 3)),
(swap_height(3, 1, toy), (1, [-1, 1], 1, 4)),
(swap_height(3, 1, {}), (1, [-1, 1], 1, 3))])
hs, v, hs0, _ = swap_height(23, 10, SEED)
check_hand("swap_height at the first failure, (23, 10): 9 with the "
"seed, its swap inside, 10 with the sham and with none", [
((hs, height_in(v, 23, 10), hs0), (9, 9, 10)),
(swap_height(23, 10, SHAM)[0], 10),
(swap_height(23, 10, {})[0], 10)])
clean = {"h": 2, "ph": 2, "hs": 2, "in": 2, "hs0": 2, "swaps": 3,
"hst": 2, "int": 2, "swapst": 3}
check_hand("split_row on T6 at three cells, deep_row at (3, 2), "
"swap_row at (5, 3) and (7, 4)", [
(split_row(7, 2, 4, 5, T6), (4, 5, 4, True, (B,))),
(split_row(6, 2, 4, 5, T6), (4, 5, None, True, (B,))),
(split_row(7, 3, 4, 5, T6), (4, 5, None, True, (B,))),
(deep_row(3, 2), (2, None, 2, True, ())),
(swap_row(5, 3, 2, 2), clean),
(swap_row(7, 4, 2, 5),
{"h": 2, "ph": 5, "hs": 3, "in": 3, "hs0": 3,
"swaps": 9, "hst": 3, "int": 3, "swapst": 9})])
check_hand("break_row on T23 at five cells", [
(break_row(9, 10, 22, T23),
(9, True, ((1, 10), (2, 2), (3, 1), (5, 1)), (A,), True)),
(break_row(9, 10, 22, [-c for c in T23])[::4], (9, True)),
(break_row(9, 10, 21, T23)[::4], (None, True)),
(break_row(9, 11, 22, T23)[::4], (None, False)),
(break_row(11, 15, 22, T23)[::4], (None, False))])
check_hand("split_record on five failing rows of nine cells",
list(zip(split_record(9, HAND_SPLIT).values(), [
(9, 5), (3, 2, 1),
(("B", 2), ("1", 1), ("A*B", 1), ("[1, 2]*[2]", 1)),
(2, 7), (6, 2, 3, "[1, 2]*[2]"), ((1, 2), (2,))],
strict=True)))
check_hand("swap_record on four plain rows",
list(zip(swap_record(HAND_SWAP).values(), [
(4, 3, 2), (2, 1), (1, 2, 3), (36, 38)], strict=True)))
check_hand("deep_record on two plain rows",
list(zip(deep_record({
(9, 4): (5, None, 5, True, (B,)),
(8, 3): (7, None, None, False, (B, A))}).values(), [
((8, 3, 7, "A*B"), (9, 4, 5, "B")), (2, 1, 1)],
strict=True)))
check_hand("hunt_record on two columns of three plain rows",
list(zip(hunt_record(HAND_DIAL, HAND_BREAKS).values(), [
(6, 3, 2, 1), (3, 2), ((1, 3), (1, 4)),
((1, 3, 6), (2, 3, 7)), ((2, 2, 4, 5, (1, 4)),),
((2, True, ((1, 2),), "B", False),)], strict=True)))
check_hand("class_record on seven polynomials",
list(zip(class_record({
"B~": SHAM["B~"], "G": NAMED["G"], "M": tuple(MIXED),
"N": NAMED["N"], "P2": (1, 1),
"P5": tuple(flatten.phi(5)),
"X": (1, -3, 1)}).values(), [
(("B~", 2, 2, 7, 3), ("G", 4, 3, 26, 2),
("M", 4, 1, -3, 5), ("N", 8, 1, 17, 1),
("P2", 1, 1, 2, 0), ("P5", 4, 1, 5, 1),
("X", 2, 1, -1, 5)),
(6, 5, 7),
(("B~", None, None), ("M", 1, 2), ("N", 2, 4),
("P2", None, None), ("X", 0, 1)),
(("B~", "G", "M", "P2", "X"),
("M", "N", "P2", "P5", "X"), ("P5",))],
strict=True)))
def section_stage(stage, title, got, t0):
section(title)
check_record(stage, got)
print(" %s: %.1f s" % (stage, time.time() - t0))
def main(argv):
if argv not in ([], ["extend"]):
print("usage: members.py [extend]")
sys.exit(2)
t_all = time.time()
section_controls()
if not all(CHECKS):
print("\nCONTROL FAILED: nothing below is read.")
sys.exit(1)
stages = ("extend",) if argv else BARE
lines = (CONTROL_LINES + sum(len(RECORD[s]) for s in stages)
+ (0 if argv else 1))
if argv:
t0 = time.time()
_, got = stage_hunt(17, 20, 5000000)
section_stage("extend", "THE EXTENSION: k = 9..12, J = 17..20, "
"5000000 nodes a decision", got, t0)
else:
t0 = time.time()
rows, split_got = stage_split()
section_stage("split", "THE SPLIT: the chart's failing cells",
split_got, t0)
t0 = time.time()
section_stage("swap", "THE SWAP: seed and sham at the failing "
"cells", stage_swap(rows), t0)
t0 = time.time()
deep, got = stage_deep()
section_stage("deep", "THE DEEP CELLS", got, t0)
t0 = time.time()
breaks, hunt_got = stage_hunt(1, 16, 5000000)
section_stage("hunt", "THE HUNT: k = 9..12, J = 1..16, 5000000 "
"nodes a decision", hunt_got, t0)
t0 = time.time()
met = factors_met(factors(NAMED["R"]),
*(r[4] for r in rows.values()),
*(r[4] for r in deep.values()),
*(b[3] for b in breaks.values()))
section_stage("classes", "THE CLASSES: the factors met, and the "
"height-8 break's residual", stage_classes(met), t0)
chart = flatten.RECORD["chart"]
first = split_got["the first failure by depth: M, J, h, its "
"residual"][:3]
k, J, d = hunt_got["breaks: k, J, d, least pure degree, its "
"parts"][0][:3]
section("THE WELD: flatten.py's record")
check_hand("the chart's cells and failures, its first failure, "
"and that failure as the break at k = 9", [
(split_got["cells, with h < ph"],
chart["J >= 2: cells, with h < ph"]),
(first, chart["first failures by depth: M, J, h, "
"ph"][0][:3]),
((d + 1, J, k), first)])
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(sys.argv[1:])