orbits.py

Checks: BONACCI: The shift on classes theorem.

Cited on: BONACCI.

To run it: save orbits.py, with bonacci.py, fibre.py beside it; needs mpmath.

"""orbits.py — is the number of codings constant on an orbit of M mod m?

The question, the derivation by hand and the frozen prints, committed
before any code; then the engine, its controls, the kill (missed) and a
proof reader's verdict, in FINDINGS.

QUESTION. In the d-bonacci numeration a point (g - r alpha)/m of the
torus lies in the class kappa = (r mod m, g mod m), and every point of
a nonzero class has the same number c(kappa) of codings. The census of
classes reads the multiply coded ones as a union of orbits of kappa ->
M kappa mod m, (r, g) -> (r + sum g, r, g_1, .., g_(d-2)), the count
constant on each, with no proof. Is c(M kappa) = c(kappa) a theorem at
every d >= 2, m >= 2 and nonzero kappa?

DERIVATION (by hand; every step to re-derive before it is used).
Theta(y) = sum_k y_k theta_k in R^(d-1), not reduced mod Z^(d-1): the
sum converges and Theta is continuous on the completion. For an integer
n with digits y put V(n) = sum_k y_k (q_k, q_(k-1), .., q_(k-d+1)) in
Z^d, its first coordinate n, and pi(q, nu) = q alpha - nu, so Theta(n) =
pi(V(n)). Let C(q, nu) = (q + sum nu, q, nu_1, .., nu_(d-2)); with the
weights run backward (q_(-1) = 1, q_j = 0 for -d < j <= -2) the
recurrence holds at every index, so V(0n) = C V(n), 0n the string of n
with a 0 put below it. C(1, alpha) = beta (1, alpha), since 1 + sum
alpha = beta, and pi kills (1, alpha); so T pi = pi C defines a linear
T on R^(d-1), with T(alpha) = alpha - e_1 and T(g) = -(sum g) alpha +
(0, g_1, .., g_(d-2)), and Theta(0y) = T Theta(y) on the completion.

 (1) 0y codes a point of M kappa. If Theta(y) = (g - r alpha)/m + nu,
     nu integral, then Theta(0y) = ((r, g_1, .., g_(d-2)) - (r + sum g)
     alpha)/m + T nu, and T nu lies in Z alpha + Z^(d-1): a point of
     the class (r + sum g, r, g_1, .., g_(d-2)).
 (2) A nonzero class is one orbit of the translation by alpha and
     misses -alpha, so the successor s+ carries the codings of each of
     its points one to one onto those of the next. Fix w in M kappa
     and let B_n be the bijection from the codings of w to those of w +
     n alpha, B_(n+k) = (s+)^k B_n at k >= 0 (M kappa is nonzero, M
     being invertible mod m). Each coding y of z in kappa goes to
     B_n^(-1)(0y), n = n(y) by (1).
 (3) That map is injective. If y, y' go to one coding of w then, up to
     their order, 0y' = (s+)^k (0y) with k >= 0, and k = 0 gives y =
     y'. At k >= 1 let n_l be the prefixes of y: 0n_l + k tends to 0y'
     by the continuity of s+, so from some l on it ends in 0 and is
     0n'_l, with n'_l -> y'. D_l = V(n'_l) - V(n_l) has C D_l with first
     coordinate k and pi(C D_l) = Theta(0n'_l) - Theta(0n_l)
     convergent; its other coordinates are integers, so C D_l is
     constant from some l on, and so is D_l = (c, nu), C being
     invertible over Z. Then c alpha - nu = lim pi(D_l) = Theta(y') -
     Theta(y), which is integral, y and y' coding one point: c = 0,
     alpha_1 being irrational, and n'_l = n_l. But 0n'_l = 0n_l + k
     with k >= 1.
 (4) So c(kappa) <= c(M kappa). M is invertible mod m and permutes the
     finitely many nonzero classes, so around kappa's cycle every <= is
     an equality.

PREDICTIONS, frozen before any engine (refrozen twice, before any
run: a reader found the first kill unable to fire, its third
prediction a tautology and its plant no permutation; a second found
the shift's evaluator, in doubles, unable to meet its bar, and its
control one-sided).
  O1 at pairs the census has not read (d = 4, m = 8..12; d = 5, m = 5,
     6; d = 6, m = 2, 3, each as far as the node limit reads every
     class of an orbit), every orbit of M mod m on the classes new at m
     (in no P_m', m' | m, m' < m: those the census has read, and M
     commutes with the embedding) holds one count. A pair with no such
     orbit read whole reads nothing and is printed so. On the census's
     own pairs its record already says so.
  O2 step (1) alone, at the classes of d = 3, 4, m = 2..4: for each
     class's first coding y, 400 digits, the sum of y_k theta_(k + 1)
     lies within 1e-9 of (g' - r' alpha)/m + n alpha mod Z^(d-1), (r',
     g') = M kappa, at some |n| <= 64, by an evaluator that never forms
     T: theta_k = q_k alpha - nu_k at 700 digits, as pairs.py's hp
     reads its own (in doubles the difference cancels by k = 40, and
     the digits that matter run past k = 100). A class is dense in the
     torus: the bound on n is what makes this a read (n is -sum nu less
     a floor of (r + sum g)/m, at most d - 1, nu the integral part of
     Theta(y), bounded with Theta; the bound by hand before the run).
  THE BOUND ON n, re-derived by hand before the engine. The census reads
  the point (g - r alpha)/m with r = r_0 or m and g in [0, m)^(d-1), so
  Theta(y) = (g - r alpha)/m + nu with |nu_j| < S_j + 1, S_j = sup over
  legal y of |Theta_j(y)| <= sum_k |theta_(k,j)| (the j-th coordinate of
  (g - r alpha)/m lies in (-1, 1)). Step (1) gives Theta(0y) = (g' - r'
  alpha)/m - (sum nu) alpha mod Z^(d-1), r' = r + sum g in [1, m + (d -
  1)(m - 1)], g' = (r, g_1, .., g_(d-2)); the class's own representative
  r'' = r' mod m in [1, m] moves it by t alpha, t = (r' - r'')/m in [0, d
  - 1]. So n = -sum nu - t and |n| <= B = sum_j (S_j + 1) + d - 1. The
  script prints B from the 700-digit sums (to k = 700, the terms past
  that below 1e-80) and asserts B <= 64; by eye S_j is a few units at
  d = 3, 4 (the conjugates of modulus 0.74 and 0.82), so B is near 15.
  INSIDE's n is 0 exactly (Theta(y) is the read point mod Z^(d-1)):
  the control prints its largest |n|, which must be 0.
  No print reads step (3): on integers it is a tautology (first
  coordinate 0 is n' = n). It rests on the proof and its reader.

THE KILL, as the script will print it.
  "NEW ORBITS: N orbits at P pairs, K holding two counts": K > 0.
  "SHIFT: N first codings, K with 0y outside M kappa": K > 0.

THE CONTROLS, read before either.
  A permutation of the classes that is not M, kappa -> -kappa, in the
  same loop: "PLANT: N orbits, K holding two counts" must print K > 0
  at d = 3, m = 4, where (1, 3, 3) is multiply and (3, 1, 1), its
  negative, singly coded. It passes no node limit there: the
  filter on new pairs is read by its own print of what it dropped. For
  SHIFT, two: the evaluator on a case known inside, the unshifted sum
  of y_k theta_k against kappa, "INSIDE: N first codings, K inside
  kappa", must print K = N; and the shifted sum against kappa itself,
  "UNSHIFTED: N first codings, K inside kappa", must print K = 4 of N
  = 446, the classes M fixes: M kappa = kappa forces every g_i = r and
  (d - 1) r = 0 mod m, so (1, 1, 1) at (3, 2), (2, 2, 2) at (3, 4),
  (1, 1, 1, 1) and (2, 2, 2, 2) at (4, 3), by hand.

WHAT IT WOULD CHANGE. The census needs one class an orbit; "a union of
orbits, the count constant on each" becomes a theorem at every d and m,
and the open front it answers closes. The proof wants a fresh reader on
its written form, step (3) first, before any page holds it. Unsearched
outside: whether the count's invariance under the shift is published
(the literature on Rauzy fractals and their boundaries is where to look).

THE ENGINE. fibre.py's census reads each class: read_class, its label
and its count of codings (count_paths over the live part), at the node
limit LIMIT = 800000. A class of P_m is new at m when gcd(m, r, g) = 1
(it lies in P_m' for m' = m / e exactly when e divides every entry), a
set M keeps. The classes are read in one process, or over four by
--full; an orbit is read whole when none of its classes is unread.

    python orbits.py          the controls, then the kill at the pairs
                              (4, 8), (4, 9), (6, 2), one process
    python orbits.py --full   the controls, then the kill at all nine
                              pairs, over four processes

Each verdict and each number FINDINGS quotes is a check line read
against RECORD below; a failed control stops the run before the kill.

FINDINGS (copied from the run's print). The controls first: "PLANT: 28
orbits, 4 holding two counts", (1, 3, 3) with 2 beside (3, 1, 1) with
1 among them, the filter at (3, 4) dropping the 7 old classes of 63;
M there "8 orbits, 0 holding two counts". "BOUND d = 3: B = 6.629",
"d = 4: B = 10.669", both <= 64. "INSIDE: 446 first codings, 446 inside
kappa (largest |n| 0, two hits at 0)". "UNSHIFTED: 446 first codings, 4
inside kappa", the four classes predicted. Then the kill, missed at
both prints: "SHIFT: 446 first codings, 0 with 0y outside M kappa
(largest |n| 2, two hits at 0)"; "NEW ORBITS: 662 orbits at 9 pairs,
0 holding two counts", every class read (no class unread, uncoded or
of infinite count), the multiply coded new classes 60 at (4, 8), 40 at
(4, 12) (2 codings each) and 42 at (6, 2) (3 or 10), none at the other
six pairs; the orbits there long, (6, 3)'s 728 classes one orbit.
Toy scale: nine pairs, d <= 6, m <= 12. A fresh proof reader then read
steps (1) to (4): each holds, a proof at every d >= 2 and m >= 2, once
four sentences are added, all in the written proof now: Theta's
continuity (the theta_k shrink geometrically, beta being Pisot); an
integer's legal string unique; z fixed in step (2) (over all of kappa
at once the map is not injective); and step (4) by Schroeder-Bernstein,
the count never assumed finite. The recurrence holds at k >= 1, not
"at every index" as step (1)'s preamble says. Against the freeze: B <=
64 is asserted, and theta past k = 700 is below 2.8e-62 at
d = 4 (9.3e-94 at d = 3), not 1e-80, immaterial beside 1e-9.
Read again in code, every number above a check line against RECORD:
the default run, one process, finds at (4, 8), (4, 9) and (6, 2) 192,
85 and 9 orbits, each read whole with one count, counts [1, 2], [1]
and [1, 3, 10], "NEW ORBITS: 286 orbits at 3 pairs, 0 holding two
counts"; --full, 6, 129, 192, 4, 44 and 1 orbits at (4, 10), (4, 11),
(4, 12), (5, 5), (5, 6) and (6, 3), "NEW ORBITS: 662 orbits at 9
pairs, 0 holding two counts". No published statement of the count's
invariance was found (Rauzy fractals, their boundary graphs, beta
numeration's arithmetic codings). The nearest, the arithmetic codings
of Pisot toral automorphisms (N. Sidorov, J. Dynam. Control Systems
7, 2001), map a two-sided compactum onto the d-torus, the shift semiconjugate
to the automorphism; there the shift is invertible and the count's
constancy on orbits immediate. The completion's y -> 0y is not onto,
which steps (2) and (3) pay for.

RUN RECORD. A first run, the same engine: --controls 4.5 s, peak 65.7
MB; the whole run 536.8 s over four processes, peak commit 348.7 MB.
Read alone, one process each: (6, 2) 0.7 s, (4, 8) 9.7 s, (4, 9) 27.0
s, (5, 5) 189.0 s, (6, 3) 194.1 s, each under 32 MB.
In code: the default run 12 of 12 checks, 41.4 s, peak commit 50.7 MB
under a 512 MB cap; --full 18 of 18, 325.4 s over four processes, peak
commit 347.0 MB.
"""


import math
import sys
import time

from fibre import Num, act, label, read_class

PAIRS = ((4, 8), (4, 9), (4, 10), (4, 11), (4, 12), (5, 5), (5, 6),
         (6, 2), (6, 3))
BARE_PAIRS = ((4, 8), (4, 9), (6, 2))
PLANT_PAIR = (3, 4)
SHIFT_PAIRS = tuple((d, m) for d in (3, 4) for m in (2, 3, 4))
NMAX = 64
TOL = 1e-9
DIGITS = 400
DPS = 700
WORKERS = 4

# The findings, as the run prints them.
RECORD = {
    "filter": (63, 7, 56),
    "plant": (28, 4),
    "plant pair": ((1, 3, 3), 2, (3, 1, 1), 1),
    "M at plant": (8, 0),
    "bound": {3: (6.629, "9.3e-94"), 4: (10.669, "2.8e-62")},
    "inside": (446, 446, 0, 0),
    "unshifted": (446, 4, [(3, 2, (1, 1, 1)), (3, 4, (2, 2, 2)),
                           (4, 3, (1, 1, 1, 1)), (4, 3, (2, 2, 2, 2))]),
    "shift": (446, 0, 2, 0),
    "multiple": {(4, 8): 60, (4, 12): 40, (6, 2): 42},
    "counts": {(4, 8): [1, 2], (4, 12): [1, 2], (6, 2): [1, 3, 10]},
    "new": {(4, 8): 3840, (4, 9): 6480, (4, 10): 9360, (4, 11): 14640,
            (4, 12): 19200, (5, 5): 3124, (5, 6): 7502, (6, 2): 63,
            (6, 3): 728},
    "orbits": {(4, 8): 192, (4, 9): 85, (4, 10): 6, (4, 11): 129,
               (4, 12): 192, (5, 5): 4, (5, 6): 44, (6, 2): 9,
               (6, 3): 1},
    "bare": (286, 3, 0),
    "full": (662, 9, 0),
}

CHECKS = []


def check(name, ok):
    CHECKS.append(bool(ok))
    print(("PASS  " if ok else "FAIL  ") + name, flush=True)


# ------------------------------------------------------------- the census
def new_classes(d, m):
    """The nonzero classes of P_m, and those new at m."""
    keys = [k for k in _keys(d, m) if any(k)]
    return keys, [k for k in keys if math.gcd(m, *k) == 1]


def _keys(d, m):
    if d == 0:
        yield ()
        return
    for k in _keys(d - 1, m):
        for x in range(m):
            yield k + (x,)


def _read(job):
    d, m, keys = job
    N = Num(d)
    out = []
    for k in keys:
        f = read_class(N, m, k)
        out.append((k, label(f), f and f["count"], f and f["coding"]))
    return d, m, out


def read_all(jobs, pool=None):
    """jobs: (d, m, keys); the reads as {(d, m): {key: (label, count,
    coding)}}, over the pool's processes when one is given, else in this
    one, a pair at a time and timed."""
    got = {}
    if pool is None:
        for d, m, keys in jobs:
            t = time.time()
            _, _, out = _read((d, m, keys))
            for k, lab, cnt, cod in out:
                got.setdefault((d, m), {})[k] = (lab, cnt, cod)
            print(f"  read ({d}, {m}): {len(keys)} classes, "
                  f"{time.time() - t:.1f} s", flush=True)
        return got
    work = []
    for d, m, keys in jobs:
        step = max(1, len(keys) // (4 * WORKERS))
        work += [(d, m, keys[i:i + step]) for i in range(0, len(keys), step)]
    for d, m, out in pool.imap_unordered(_read, work):
        for k, lab, cnt, cod in out:
            got.setdefault((d, m), {})[k] = (lab, cnt, cod)
    return got


def orbits(S, f):
    """S cut into cycles of the permutation f (f keeps S)."""
    left, out = set(S), []
    while left:
        orb = [min(left)]
        while f(orb[-1]) != orb[0]:
            orb.append(f(orb[-1]))
        left -= set(orb)
        out.append(orb)
    return out


def orbit_row(reads, keys, f):
    """Orbits of f on keys: (all, read whole, holding two counts), and
    the classes unread, multiply coded, with no finite count."""
    orbs = orbits(keys, f)
    whole = [o for o in orbs if all(reads[k][0] != "unread" for k in o)]
    mixed = [o for o in whole if len({reads[k][1] for k in o}) > 1]
    return dict(orbits=len(orbs), whole=len(whole), mixed=mixed,
                unread=sum(1 for k in keys if reads[k][0] == "unread"),
                multiple=sum(1 for k in keys if reads[k][0] == "multiple"),
                uncoded=sum(1 for k in keys if reads[k][0] == "uncoded"),
                infinite=sum(1 for k in keys if reads[k][0] in
                             ("single", "multiple") and reads[k][1] is None))


# ----------------------------------------------------------- the shift
class Shift:
    """theta_k = q_k alpha - (q_(k-1), .., q_(k-d+1)) at DPS digits, q_(-1)
    = 1 and q_j = 0 for -d < j <= -2, alpha = (beta^-1, .., beta^-(d-1))."""

    def __init__(self, d, K=DPS):
        import mpmath
        self.mp = mpmath
        mpmath.mp.dps = DPS
        self.d = d
        b = mpmath.findroot(lambda z: z ** d - sum(z ** j for j in range(d)),
                            mpmath.mpf(2))
        self.alpha = [b ** -j for j in range(1, d)]
        q = {j: 0 for j in range(-d + 1, -1)}
        q[-1] = 1
        for k in range(0, K + 2):
            q[k] = sum(q[k - 1 - i] for i in range(d)) if k else 1
        self.q = q
        self.theta = [[q[k] * a - q[k - j] for j, a in
                       zip(range(1, d), self.alpha)] for k in range(K + 2)]
        self.tail = max(abs(x) for x in self.theta[K + 1])

    def S(self):
        """sum_k |theta_(k,j)|, k <= K, each j: S_j's majorant."""
        return [sum(abs(t[j]) for t in self.theta) for j in range(self.d - 1)]

    def sum(self, y, shift):
        mp = self.mp
        X = [mp.mpf(0)] * (self.d - 1)
        for k, yk in enumerate(y):
            if yk:
                t = self.theta[k + shift]
                X = [x + tj for x, tj in zip(X, t)]
        return X

    def locate(self, X, key, m):
        """The n, |n| <= NMAX, with X within TOL of (g - r alpha)/m + n
        alpha mod Z^(d-1), r = key[0] or m: a list (empty when none)."""
        mp = self.mp
        r, g = key[0] or m, key[1:]
        base = [x - (gj - r * a) / m for x, gj, a in zip(X, g, self.alpha)]
        hits = []
        for n in range(-NMAX, NMAX + 1):
            off = max(abs(v - n * a - mp.nint(v - n * a))
                      for v, a in zip(base, self.alpha))
            if off < TOL:
                hits.append(n)
        return hits


def shift_rows(reads):
    """INSIDE, UNSHIFTED and SHIFT over the first codings of SHIFT_PAIRS:
    (N, K, largest |n| of a hit, codings with two hits) for each."""
    rows = {"inside": [0, 0, 0, 0], "unshifted": [0, 0, 0, 0],
            "shift": [0, 0, 0, 0]}
    fixed, B = [], {}
    for d in sorted({d for d, _ in SHIFT_PAIRS}):
        sh = Shift(d)
        Sj = sh.S()
        B[d] = (float(sum(s + 1 for s in Sj) + d - 1), float(sh.tail))
        N = Num(d)
        for (e, m), got in sorted(reads.items()):
            if e != d:
                continue
            for key, (lab, _, y) in sorted(got.items()):
                if y is None:
                    continue
                y = y[:DIGITS]
                X0, X1 = sh.sum(y, 0), sh.sum(y, 1)
                Mk = act(N, m, key)
                for name, X, target in (("inside", X0, key),
                                        ("unshifted", X1, key),
                                        ("shift", X1, Mk)):
                    hits = sh.locate(X, target, m)
                    row = rows[name]
                    row[0] += 1
                    row[1] += bool(hits)
                    if hits:
                        row[2] = max(row[2], min(abs(n) for n in hits))
                    row[3] += len(hits) > 1
                    if name == "unshifted" and hits:
                        fixed.append((d, m, key))
    return rows, fixed, B


# ------------------------------------------------------------- the run
def section_controls(pool):
    """The filter, PLANT, M beside it, BOUND, INSIDE and UNSHIFTED, each
    against RECORD; SHIFT's row, read off the same sums, returned."""
    d, m = PLANT_PAIR
    allk, newk = new_classes(d, m)
    jobs = [(d, m, allk)]
    jobs += [(e, n, new_classes(e, n)[0]) for e, n in SHIFT_PAIRS
             if (e, n) != PLANT_PAIR]
    reads = read_all(jobs, pool)
    got = reads[PLANT_PAIR]
    filt = (len(allk), len(allk) - len(newk), len(newk))
    check(f"FILTER at {PLANT_PAIR}: {filt[0]} nonzero classes, {filt[1]} "
          f"dropped as old, {filt[2]} new", filt == RECORD["filter"])
    neg = orbit_row(got, newk, lambda k: tuple(-x % m for x in k))
    pair = [(k, got[k][1]) for o in neg["mixed"] for k in o]
    w, cw, v, cv = RECORD["plant pair"]
    check(f"PLANT: {neg['orbits']} orbits, {len(neg['mixed'])} holding two "
          f"counts (read whole {neg['whole']}, unread {neg['unread']}); "
          f"{w} with {got[w][1]} beside {v} with {got[v][1]} among them",
          (neg["orbits"], len(neg["mixed"])) == RECORD["plant"]
          and neg["unread"] == 0 and (w, cw) in pair and (v, cv) in pair)
    N = Num(d)
    mo = orbit_row(got, newk, lambda k: act(N, m, k))
    check(f"M at {PLANT_PAIR}: {mo['orbits']} orbits, {len(mo['mixed'])} "
          f"holding two counts",
          (mo["orbits"], len(mo["mixed"])) == RECORD["M at plant"])
    shift, fixed, B = shift_rows(reads)
    for e, (b, tail) in sorted(B.items()):
        check(f"BOUND d = {e}: B = {b:.3f} <= {NMAX}, theta past k = {DPS} "
              f"below {tail:.1e}",
              b <= NMAX
              and (round(b, 3), f"{tail:.1e}") == RECORD["bound"][e])
    n, k, big, two = shift["inside"]
    check(f"INSIDE: {n} first codings, {k} inside kappa (largest |n| "
          f"{big}, two hits at {two})",
          (n, k, big, two) == RECORD["inside"])
    n, k = shift["unshifted"][:2]
    check(f"UNSHIFTED: {n} first codings, {k} inside kappa {sorted(fixed)}",
          (n, k, sorted(fixed)) == RECORD["unshifted"])
    return shift


def section_shift(shift):
    """SHIFT: step (1) of the proof read on the first codings."""
    n, k, big, two = shift["shift"]
    check(f"SHIFT: {n} first codings, {n - k} with 0y outside M kappa "
          f"(largest |n| {big}, two hits at {two})",
          (n, n - k, big, two) == RECORD["shift"])


def section_orbits(pairs, pool):
    """NEW ORBITS: every orbit of M on the classes new at each pair, read
    whole, one count on each."""
    jobs = []
    for d, m in pairs:
        allk, newk = new_classes(d, m)
        print(f"  FILTER at {(d, m)}: {len(allk)} nonzero classes, "
              f"{len(allk) - len(newk)} dropped as old, {len(newk)} new",
              flush=True)
        jobs.append((d, m, newk))
    reads = read_all(jobs, pool)
    tot = mixed = read = 0
    for d, m in pairs:
        got = reads[d, m]
        N = Num(d)
        row = orbit_row(got, sorted(got), lambda k: act(N, m, k))
        counts = sorted({c for _, c, _ in got.values()},
                        key=lambda c: (c is None, c or 0))
        clean = not (row["unread"] or row["uncoded"] or row["infinite"])
        check(f"({d}, {m}): {len(got)} new classes, {row['orbits']} "
              f"orbits, {row['whole']} read "
              f"whole, {len(row['mixed'])} holding two counts; unread "
              f"{row['unread']}, multiple {row['multiple']}, uncoded "
              f"{row['uncoded']}, no finite count {row['infinite']}; "
              f"counts {counts}",
              clean and row["whole"] == row["orbits"]
              and len(got) == RECORD["new"][d, m]
              and counts == RECORD["counts"].get((d, m), [1])
              and row["multiple"] == RECORD["multiple"].get((d, m), 0)
              and row["orbits"] == RECORD["orbits"][d, m])
        tot += row["whole"]
        mixed += len(row["mixed"])
        read += bool(row["whole"])
    full = len(pairs) == len(PAIRS)
    want = RECORD["full" if full else "bare"]
    check(f"NEW ORBITS: {tot} orbits at {read} pairs, {mixed} holding two "
          f"counts", mixed == 0 and (tot, read, mixed) == want)


def main():
    full = "--full" in sys.argv[1:]
    t0 = time.time()
    pool = None
    if full:
        from multiprocessing import Pool
        pool = Pool(WORKERS)
    try:
        shift = section_controls(pool)
        if not all(CHECKS):
            print("CONTROL FAILED: no verdict")
            return 1
        print(f"  (controls {time.time() - t0:.1f} s)")
        section_shift(shift)
        section_orbits(PAIRS if full else BARE_PAIRS, pool)
    finally:
        if pool is not None:
            pool.close()
            pool.join()
    print(f"{sum(CHECKS)} of {len(CHECKS)} checks, {time.time() - t0:.1f} s")
    return 0 if all(CHECKS) else 1


if __name__ == "__main__":
    sys.exit(main())