#!/usr/bin/env python3
"""
PROVENANCE: PROOF

Computation 183 -- Born agreement: the failing graphs are exactly the ones with a
bounded vertex cover, and no two properties may share a distinction set
==================================================================================
WHAT THIS DOES.  comp 180 showed that Born agreement is jointly a condition on the
law of T and on the distinction graph, because two admissible families keep an atom
that never shrinks: the star, and K_k with isolated vertices.  It named the shared
property informally, a BOUNDED ACTIVE PART, and left the register asking for "a
genericity constraint on delta that the theory does not supply".

That is too vague to act on and too large to ask for.  This file replaces it with a
graph invariant, a proof, and one named minimal condition.

THE INVARIANT IS THE VERTEX COVER NUMBER c(D, delta).  Let S be any set of properties
meeting every distinction, so that I = D \\ S is distinction-free.  Every C contained
in I has T_ex(C) = 0, and there are 2^|I| of them, so under the book's own measure
mu = Bern(1/2)^{|D|} the atom at zero is

        P[T_ex = 0]  >=  2^{-|S|},      hence      largest atom  >=  2^{-c}.

That is a one-line proof, and it accounts for comp 180's whole table.  The three
families that fail have c = 1, 3, 5 fixed as |D| grows; the three that pass have c
growing with |D|.  Nothing else in the table does any work.

WHAT KILLS IT.  Call (D, delta) REDUCED when no property has an empty distinction
set and no two properties have the same one, that is, when delta alone tells the
properties of D apart.  Then the map u -> {b : delta(u,b)} is injective on I and
lands in the subsets of S, so

        |D| - c  <=  2^c,     hence     c  >=  log_2(|D| - c).

The guaranteed floor 2^-c is therefore at most about 1/|D| and vanishes.  At the
|D| ~ 10^80 of a realised substrate the cover is at least 266 and the floor is below
10^-80.  THE BOUNDED-ACTIVE-PART MECHANISM CANNOT OPERATE ON A REDUCED SUBSTRATE.

AND THE BOUND IS TIGHT, so this is not slack being spent.  Part 3 builds the extremal
reduced graphs, the ones with the smallest cover reducedness permits (a cover S, and
one independent property for each nonempty subset of S).  Their atom is 1.3 to 1.6
times 2^-c at every size and falls as |D|^-1.10.  Part 4 is the control: take one of
them and add false twins, which is exactly what reducedness forbids.  |D| triples, the
cover does not move, and the atom stops falling and sits on 2^-c.  It is the cover
that carries the atom, not the size.

    extremal reduced, c = 3..7    |D| = 10, 19, 36, 69, 134   atom 0.193 -> 0.011
    the same graph + false twins  |D| = 19 -> 59, c = 4       atom 0.089 -> 0.063 = 2^-4

SETTLED SINCE, BY COMPUTATION 184 AND P1 CLAUSE (iii).  The question this section leaves
open was answered the other way: reducedness is not assumed but derived, from delta
recording every difference the triple carries, and the book now carries that as P1(iii).
The reading below of what the book said at the time is kept as written, because it is the
reason the question was asked.  Nothing measured here moves, and the Born item still does
not close: what P1(iii) discharges is the graph half.

IS REDUCEDNESS AVAILABLE TO PST?  NOT AS THINGS STAND, AND THIS FILE DOES NOT CLAIM
THE ITEM CLOSED.  sec:property-diff-math says in as many words: "No further axioms are
imposed on delta.  There is no transitivity requirement, no totality requirement, no
metric on D, no topology, and no ordering."  Reducedness is a further axiom on delta.
sec:phi-construction does invoke Leibniz's identity of indiscernibles, but for the
fibres of rho, and it does not reach here: the substrate is the triple (D, delta, v),
so two properties with the same distinction set can still be told apart by v, and the
principle as the book states it leaves them in D.

WHAT THIS CONTRIBUTES.  The residue stops being a genericity assumption and becomes one
line of the substrate's definition, with the excluded class described exactly rather
than as a null set: for the cover mechanism to guarantee an atom of mass m, at least
m(|D| - log_2(1/m)) properties must share a single distinction set.  Breaking Born
agreement this way needs a substrate almost all of whose properties are delta-duplicates
of one another.  Whether PST should say that such a thing is not a set of primitive
PROPERTIES at all is a decision about P1's wording, not a calculation, and it is the
decision the register should now record.

WHAT THIS IS NOT.  It is not a proof that reduced substrates satisfy Born agreement.
One mechanism is excluded, and part 5 searches for another over Erdos-Renyi graphs at
three densities and by hill-climbing the atom over reduced graphs directly.  The search
is informative about what it finds: it walks to a PERFECT MATCHING, whose law is exactly
Binomial(|D|/2, 1/4), so its atom is a binomial mode mass and goes as 1.303|D|^-1/2.  That
is the slowest-vanishing reduced family found, and it is the same |D|^-1/2 comp 180
measured for the regular graphs.  It still vanishes.  Absence of a second mechanism is
measured over the graphs searched, not proved, and it is reported as measured.
"""

import itertools
import math
from collections import Counter

import numpy as np


def rule():
    print("=" * 100)


# --- the tension magnitude of eq:texample, over all of P(D) or a sample ----------
def bits_table(D):
    """Row a is property a's indicator across all 2^|D| configurations.

    Filled row by row into one int8 array rather than built as a list of rows:
    the list holds |D| int64 temporaries of length 2^|D| at once, 80 MB at the
    |D| = 19 this file reaches, and the browser runtime this book publishes to
    cannot be relied on for that.  Row by row the transient is a single
    2^|D| int64, 4 MB, and the table itself is int8 throughout."""
    n = 1 << D
    m = np.arange(n, dtype=np.int64)
    out = np.empty((D, n), dtype=np.int8)
    for a in range(D):
        out[a] = (m >> a) & 1
    return out


def tex_all(D, edges, bt=None):
    """T_ex(C) for every C in P(D): the induced edge count."""
    bt = bits_table(D) if bt is None else bt
    out = np.zeros(1 << D, dtype=np.int32)
    for u, v in edges:
        out += bt[u] * bt[v]
    return out


def atom_exact(D, edges, bt=None):
    v = tex_all(D, edges, bt)
    return int(np.bincount(v).max()) / (1 << D)


def atom_sampled(D, edges, n=2_000_000, seed=3, chunk=10_000):
    """Same quantity under mu = Bern(1/2)^{|D|}, when 2^|D| is out of reach.

    The chunk is small on purpose.  Each one holds a chunk-by-|D| array, and at
    the |D| = 134 this file reaches a 100k chunk is 107 MB in one allocation,
    which the browser runtime this book publishes to cannot be relied on to
    give.  10k holds 11 MB and costs only more iterations of a cheap loop."""
    E = np.asarray(edges, dtype=np.int64)
    rng = np.random.default_rng(seed)
    cnt, done = Counter(), 0
    while done < n:
        k = min(chunk, n - done)
        done += k
        inC = rng.random((k, D)) < 0.5
        t = (inC[:, E[:, 0]] & inC[:, E[:, 1]]).sum(1)
        cnt.update(t.tolist())
    return max(cnt.values()) / n


# --- graph utilities ------------------------------------------------------------
def neighbourhoods(D, edges):
    N = [set() for _ in range(D)]
    for u, v in edges:
        N[u].add(v)
        N[v].add(u)
    return N


def is_reduced(D, edges):
    """No empty distinction set, and no two properties sharing one."""
    N = neighbourhoods(D, edges)
    if any(not s for s in N):
        return False
    return len({frozenset(s) for s in N}) == D


def min_cover(D, edges):
    """Exact minimum vertex cover by search; only used where D is small."""
    E = list(edges)
    for c in range(D + 1):
        for S in itertools.combinations(range(D), c):
            s = set(S)
            if all(u in s or v in s for u, v in E):
                return c
    return D


def family(kind, D):
    if kind == "complete":
        return list(itertools.combinations(range(D), 2))
    if kind == "cycle":
        return [(i, (i + 1) % D) for i in range(D)]
    if kind == "erdos":
        r = np.random.default_rng(5)
        return [e for e in itertools.combinations(range(D), 2) if r.random() < 0.5]
    if kind == "star":
        return [(0, i) for i in range(1, D)]
    if kind == "K4+iso":
        return list(itertools.combinations(range(4), 2))
    if kind == "K6+iso":
        return list(itertools.combinations(range(6), 2))
    raise ValueError(kind)


def subset_graph(c):
    """The extremal reduced graph for cover c: a cover S of size c, and one
    independent property for every nonempty subset of S.  |D| = c + 2^c - 1, the
    largest a reduced graph with a cover of size c can be."""
    edges, idx = [], c
    for k in range(1, c + 1):
        for T in itertools.combinations(range(c), k):
            for s in T:
                edges.append((s, idx))
            idx += 1
    return idx, edges


# ---------------------------------------------------------------------------
def part1():
    rule()
    print("  1.  THE INVARIANT: THE ATOM IS AT LEAST 2^-c, c THE VERTEX COVER NUMBER")
    rule()
    print("      PROOF.  Let S meet every distinction and put I = D \\ S.  I carries no")
    print("      distinction, so T_ex(C) = 0 for every C contained in I, and there are")
    print("      2^|I| such C out of 2^|D|.  Under mu = Bern(1/2)^{|D|} that is a mass of")
    print("      2^-|S| on the single value 0.  Minimising over covers:")
    print()
    print("          largest atom  >=  P[T_ex = 0]  >=  2^{-c(D,delta)}.")
    print()
    print("      comp 180's table is this invariant and nothing else.  The three families")
    print("      that fail hold c FIXED as |D| grows; the three that pass do not.")
    print()
    print(f"      {'family':>12}{'|D|':>5}{'cover c':>9}{'2^-c':>10}{'atom':>10}"
          f"{'reduced':>10}")
    rows = {}
    for kind in ("complete", "cycle", "erdos", "star", "K4+iso", "K6+iso"):
        cs, ats = [], []
        for D in (10, 12, 14):
            E = family(kind, D)
            bt = bits_table(D)
            c = min_cover(D, E)
            a = atom_exact(D, E, bt)
            cs.append(c)
            ats.append(a)
            print(f"      {kind:>12}{D:>5}{c:>9}{2.0 ** -c:>10.4f}{a:>10.4f}"
                  f"{str(is_reduced(D, E)):>10}")
        rows[kind] = (cs, ats)
    print()
    bound_ok = all(a >= 2.0 ** -c - 1e-12
                   for cs, ats in rows.values() for c, a in zip(cs, ats))
    fixed = [k for k, (cs, _) in rows.items() if cs[0] == cs[-1]]
    grows = [k for k, (cs, _) in rows.items() if cs[-1] > cs[0]]
    print(f"      the bound holds on every row                          : {bound_ok}")
    print(f"      cover FIXED as |D| grows : {', '.join(fixed)}")
    print(f"      cover GROWS with |D|     : {', '.join(grows)}")
    print()
    print("      Those are exactly comp 180's failures and comp 180's passes.  'Bounded")
    print("      active part' was the right diagnosis; the vertex cover number is what")
    print("      it measures.")
    print()
    match = set(fixed) == {"star", "K4+iso", "K6+iso"}
    ok = bound_ok and match
    print(f"      -> the invariant reproduces comp 180's split exactly   : {ok}")
    print()
    return ok


def part2():
    rule()
    print("  2.  REDUCEDNESS FORCES c >= log_2(|D| - c), SO THE FLOOR VANISHES")
    rule()
    print("      DEFINITION.  (D, delta) is REDUCED when no property has an empty")
    print("      distinction set and no two properties have the same one: delta alone")
    print("      tells the properties of D apart.")
    print()
    print("      PROOF.  Let S be a minimum cover, I = D \\ S.  Each u in I has its whole")
    print("      distinction set inside S, so u -> {b : delta(u,b)} maps I into the")
    print("      subsets of S, and reducedness makes it injective.  Hence")
    print()
    print("          |D| - c  <=  2^c,      c  >=  log_2(|D| - c),")
    print()
    print("      and the guaranteed floor 2^-c is at most about 1/|D|.")
    print()
    print(f"      {'|D|':>12}{'c at least':>13}{'floor 2^-c at most':>22}")
    ok = True
    for D in (10 ** 3, 10 ** 6, 10 ** 20, 10 ** 80):
        c = 1
        while D - c > 2 ** c:
            c += 1
        print(f"      {('10^%d' % round(math.log10(D))):>12}{c:>13}"
              f"{2.0 ** -c:>22.3e}")
        ok &= (D - c <= 2 ** c)
    print()
    print("      At the |D| of a realised substrate the floor this mechanism can")
    print("      guarantee is below 10^-80.  It is dead, not merely small.")
    print()
    print("      Verified directly: no reduced graph beats the counting bound.")
    checked = 0
    for D in (8, 10, 12):
        for t in range(300):
            r = np.random.default_rng(D * 10000 + t)
            p = float(r.integers(1, 10)) / 10.0
            E = [e for e in itertools.combinations(range(D), 2) if r.random() < p]
            if not is_reduced(D, E):
                continue
            c = min_cover(D, E)
            ok &= (D - c <= 2 ** c)
            checked += 1
    print(f"      reduced graphs checked against |D| - c <= 2^c         : {checked}")
    print()
    print(f"      -> reducedness kills the bounded-cover mechanism       : {ok}")
    print()
    return ok


def part3():
    rule()
    print("  3.  THE BOUND IS TIGHT: THE EXTREMAL REDUCED GRAPHS STILL VANISH")
    rule()
    print("      If reducedness only barely moved the cover, the argument would be")
    print("      spending slack it does not have.  Build the graph that saturates the")
    print("      counting bound: a cover S of size c, and one independent property for")
    print("      every nonempty subset of S, so |D| = c + 2^c - 1 is as large as a")
    print("      reduced graph with cover c can be.  This is the hardest reduced case.")
    print()
    print(f"      {'c':>4}{'|D|':>7}{'reduced':>10}{'2^-c':>10}{'atom':>10}"
          f"{'atom/2^-c':>12}{'how':>9}")
    ns, ats = [], []
    ok = True
    for c in range(3, 8):
        D, E = subset_graph(c)
        red = is_reduced(D, E)
        ok &= red
        if D <= 20:
            a, how = atom_exact(D, E), "exact"
        else:
            a, how = atom_sampled(D, E), "sampled"
        ns.append(D)
        ats.append(a)
        print(f"      {c:>4}{D:>7}{str(red):>10}{2.0 ** -c:>10.5f}{a:>10.5f}"
              f"{a * 2 ** c:>12.2f}{how:>9}")
    slope = float(np.polyfit(np.log(ns), np.log(ats), 1)[0])
    print()
    print(f"      atom ~ |D|^{slope:+.2f}, and it sits within a factor 1.6 of 2^-c at")
    print("      every size, so the bound is tight and what it bounds does vanish.")
    ok &= slope < -1.0
    print()
    print(f"      -> even the extremal reduced graphs lose their atom    : {ok}")
    print()
    return ok


def part4():
    rule()
    print("  4.  CONTROL: PUT THE FALSE TWINS BACK AND THE ATOM COMES BACK")
    rule()
    print("      The claim is that the COVER carries the atom, not |D|.  Test it by")
    print("      violating reducedness in the one way that leaves the cover alone: take")
    print("      the extremal reduced graph at c = 4 and add properties whose distinction")
    print("      set is a copy of an existing one.  |D| triples; the cover cannot move,")
    print("      because the new properties attach to a vertex already in the cover.")
    print()
    D0, E0 = subset_graph(4)
    print(f"      {'twins':>7}{'|D|':>7}{'reduced':>10}{'atom':>10}{'2^-4':>9}")
    seen = []
    for k in (0, 4, 10, 20, 40):
        E = list(E0)
        D = D0
        for _ in range(k):
            E.append((0, D))
            D += 1
        a = atom_exact(D, E) if D <= 20 else atom_sampled(D, E, n=500_000, seed=11)
        seen.append(a)
        print(f"      {k:>7}{D:>7}{str(is_reduced(D, E)):>10}{a:>10.5f}{0.0625:>9.4f}")
    plateau = abs(seen[-1] - seen[-2]) < 0.005 and seen[-1] > 0.0625 - 0.002
    print()
    print("      The atom stops falling and sits on 2^-4 while |D| goes from 19 to 59.")
    print("      In part 3 the same |D| growth, kept reduced, drove the atom down by an")
    print("      order of magnitude.  The invariant is the cover, and the condition that")
    print("      moves it is exactly the one named.")
    print()
    print(f"      -> the atom plateaus on 2^-c once twins are allowed    : {plateau}")
    print()
    return plateau


def part5():
    rule()
    print("  5.  IS THERE A SECOND MECHANISM?  SEARCHED FOR, AND WHAT THE SEARCH FINDS")
    rule()
    print("      Killing one mechanism is not proving the condition holds.  Look for a")
    print("      reduced graph with a persistent atom two ways.")
    print()
    print("      (a) Erdos-Renyi at three densities, keeping only the reduced draws.")
    print()
    print(f"      {'p':>8}{'|D|=12':>10}{'|D|=14':>10}{'|D|=16':>10}{'slope':>10}")
    ok = True
    for p in (0.15, 0.5, 0.85):
        row, sizes = [], (12, 14, 16)
        for D in sizes:
            bt = bits_table(D)
            vals = []
            for t in range(25):
                r = np.random.default_rng(int(p * 100) * 997 + D * 31 + t)
                E = [e for e in itertools.combinations(range(D), 2) if r.random() < p]
                if is_reduced(D, E):
                    vals.append(atom_exact(D, E, bt))
            row.append(float(np.mean(vals)))
        sl = float(np.polyfit(np.log(sizes), np.log(row), 1)[0])
        ok &= sl < -0.3
        print(f"      {p:>8.2f}{row[0]:>10.4f}{row[1]:>10.4f}{row[2]:>10.4f}{sl:>10.2f}")
    print()
    print("      (b) An adversarial search: hill-climb the atom over REDUCED graphs,")
    print("      flipping one distinction at a time and keeping the move only when the")
    print("      graph stays reduced and the atom does not fall.")
    print()
    print(f"      {'|D|':>7}{'best atom over reduced':>26}{'cover':>8}"
          f"{'distinctions':>15}{'|D|/2':>8}")
    sizes, best_by_n = (10, 12, 14, 16), []
    for D in sizes:
        bt = bits_table(D)
        allp = list(itertools.combinations(range(D), 2))
        best, best_c, best_m = 0.0, None, None
        for seed in range(6):
            r = np.random.default_rng(700 + seed)
            E = {e for e in allp if r.random() < 0.5}
            if not is_reduced(D, list(E)):
                continue
            cur = atom_exact(D, list(E), bt)
            for _ in range(300):
                e = allp[int(r.integers(len(allp)))]
                F = set(E)
                F.symmetric_difference_update({e})
                if not is_reduced(D, list(F)):
                    continue
                val = atom_exact(D, list(F), bt)
                if val >= cur:
                    E, cur = F, val
            if cur > best:
                best, best_c, best_m = cur, min_cover(D, list(E)), len(E)
        best_by_n.append(best)
        print(f"      {D:>7}{best:>26.4f}{best_c:>8}{best_m:>15}{D // 2:>8}")
    sl = float(np.polyfit(np.log(sizes), np.log(best_by_n), 1)[0])
    ok &= sl < -0.3
    print()
    print(f"      the best reduced graph found falls as |D|^{sl:+.2f}.")
    print()
    print("      AND THE SEARCH IS INFORMATIVE ABOUT WHAT IT FOUND.  It walks to a")
    print("      PERFECT MATCHING: |D|/2 distinctions, cover |D|/2, every distinction set")
    print("      a distinct singleton, which is reduced.  Its law is exact.  A matched")
    print("      pair is inside C with probability 1/4 independently, so")
    print()
    print("          T_ex ~ Binomial(|D|/2, 1/4),    atom = max_k P[T_ex = k],")
    print()
    print("      whose mode mass goes as (2 pi (|D|/2)(1/4)(3/4))^-1/2 = 1.303|D|^-1/2.  So")
    print("      the hardest reduced family the search reaches still vanishes, at the same")
    print("      |D|^-1/2 comp 180 measured for the regular graphs.  Checked against the")
    print("      exact enumeration and continued analytically well past it:")
    print()
    print(f"      {'|D|':>9}{'matching atom, enumerated':>28}"
          f"{'binomial mode mass':>22}{'1.303/sqrt(|D|)':>18}")
    for D in (10, 14, 18, 100, 10000, 10 ** 8):
        m = D // 2
        lo, hi = max(0, m // 4 - 3), min(m, m // 4 + 4)
        mode = max(math.exp(math.lgamma(m + 1) - math.lgamma(k + 1)
                            - math.lgamma(m - k + 1)
                            + k * math.log(0.25) + (m - k) * math.log(0.75))
                   for k in range(lo, hi + 1))
        if D <= 18:
            bt = bits_table(D)
            ex = atom_exact(D, [(2 * i, 2 * i + 1) for i in range(m)], bt)
            ok &= abs(ex - mode) < 1e-12
            shown = f"{ex:.6f}"
        else:
            shown = "--"
        print(f"      {('10^%d' % round(math.log10(D))) if D > 1000 else D:>9}"
              f"{shown:>28}{mode:>22.6f}{1.303 / math.sqrt(D):>18.6f}")
    print()
    print("      Nothing found here is a second mechanism, and nothing here proves there")
    print("      is none: absence of a counterexample over the graphs searched is")
    print("      measured, not proved, and it is reported as measured.")
    print()
    print(f"      -> no reduced graph found with a persistent atom       : {ok}")
    print()
    return ok


def part6():
    rule()
    print("  6.  IS REDUCEDNESS AVAILABLE TO PST?  NO, AND THE ITEM IS NOT CLOSED")
    rule()
    print("      The honest reading of the book, checked rather than assumed.")
    print()
    print("      sec:property-diff-math, stating the substrate triple:")
    print()
    print("          'No further axioms are imposed on delta.  There is no transitivity")
    print("           requirement, no totality requirement, no metric on D, no topology,")
    print("           and no ordering.'")
    print()
    print("      Reducedness is a further axiom on delta.  It is not currently PST's.")
    print()
    print("      sec:phi-construction does invoke the right principle:")
    print()
    print("          'Leibniz's principle of the identity of indiscernibles: things that")
    print("           share all the same properties are the same thing.'")
    print()
    print("      but it invokes it for the FIBRES OF rho, to justify defining a spacetime")
    print("      point as an equivalence class of properties.  It does not reach delta,")
    print("      and it cannot be stretched to: the substrate is the TRIPLE (D, delta, v),")
    print("      so two properties with the same distinction set are still discernible by")
    print("      v, and the principle as the book states it leaves both in D.")
    print()
    print("      So this file does NOT close the Born condition, and does not close")
    print("      item 1's second disjunct with it.  What it changes is the size and the")
    print("      shape of what is left.")
    print()
    print("      BEFORE : 'closing it needs a genericity constraint on delta that the")
    print("                theory does not supply' -- an unnamed constraint, and the")
    print("                excluded class known only as a null set.")
    print("      AFTER  : one line, 'no two properties share a distinction set', with the")
    print("                excluded class described exactly.")
    print()
    print("      The exact description.  For the cover mechanism to guarantee an atom of")
    print("      mass m the cover must satisfy c <= log_2(1/m), and then at least")
    print("      (|D| - c)/2^c properties share a single distinction set:")
    print()
    print(f"      {'atom m':>10}{'cover at most':>16}"
          f"{'duplicates at least, |D| = 10^80':>36}")
    ok = True
    for m in (0.5, 0.1, 0.01, 1e-6):
        c = int(math.floor(math.log2(1.0 / m)))
        dup = (1e80 - c) / 2 ** c
        print(f"      {m:>10.6g}{c:>16}{dup:>36.3e}")
        ok &= dup > 1e60
    print()
    print("      Breaking Born agreement by this mechanism needs a substrate almost all")
    print("      of whose properties are delta-duplicates of one another.  Whether such a")
    print("      thing is a set of primitive PROPERTIES at all is a question about P1's")
    print("      wording, and it is a decision rather than a calculation.  That is what")
    print("      the register should now record.")
    print()
    print(f"      -> the residue restated as one named condition         : {ok}")
    print()
    return ok


def main():
    rule()
    print("  COMPUTATION 183 -- BORN AGREEMENT: THE COVER NUMBER IS THE OBSTRUCTION")
    rule()
    print()
    r1, r2, r3 = part1(), part2(), part3()
    r4, r5, r6 = part4(), part5(), part6()
    rule()
    print("  SUMMARY")
    rule()
    print(f"  1. the atom is at least 2^-c, and that is comp 180's split  : {r1}")
    print(f"  2. reducedness forces c >= log_2(|D| - c), so the floor dies: {r2}")
    print(f"  3. the bound is tight and the extremal reduced case vanishes: {r3}")
    print(f"  4. control: restore the twins and the atom sits on 2^-c     : {r4}")
    print(f"  5. the hardest reduced family found is a matching, |D|^-1/2 : {r5}")
    print(f"  6. reducedness is NOT an axiom of PST; the item stays open  : {r6}")
    print()
    print("""  RESULT.  comp 180 left the Born condition waiting on 'a genericity constraint
  on delta that the theory does not supply'.  That is now one named condition, and
  a proof stands behind the naming.

  The obstruction is the VERTEX COVER NUMBER c of (D, delta).  A cover S leaves a
  distinction-free remainder, every configuration inside it ties at T_ex = 0, and
  under the book's own Bernoulli measure that is an atom of at least 2^-c.  The
  three families comp 180 found failing are the three whose cover stays fixed as
  |D| grows, and the three it found passing are the three whose cover grows.  The
  informal 'bounded active part' was measuring this and nothing else.

  Requiring only that delta tell the properties of D apart, no empty distinction
  set and no two the same, forces |D| - c <= 2^c, hence c >= log_2(|D| - c), hence a
  floor below 10^-80 at substrate scale.  The bound is tight rather than slack: the
  extremal reduced graphs sit within a factor 1.6 of 2^-c and their atom falls as
  |D|^-1.10.  The control confirms the mechanism is the cover and not the size:
  adding false twins to one of them holds the atom on 2^-4 while |D| triples.  An
  adversarial hill-climb over reduced graphs walks to the perfect matching, whose atom
  is exactly a Binomial(|D|/2, 1/4) mode mass and falls as 1.303|D|^-1/2: the hardest
  reduced family reachable, and it vanishes too.

  This does NOT close the item.  sec:property-diff-math says 'No further axioms are
  imposed on delta', and reducedness is a further axiom; sec:phi-construction's
  appeal to the identity of indiscernibles is made for the fibres of rho and does
  not reach delta, because v can discern two properties that delta cannot.  The search
  for a second mechanism found none: it walks to the perfect matching, whose atom is
  exact and falls as 1.303|D|^-1/2.  That is measured over the graphs searched, not
  proved over all of them, and it is reported as measured.

  What is settled is the shape of the residue.  Born agreement can fail by this
  mechanism only on a substrate in which at least m(|D| - log_2(1/m)) properties
  share one distinction set, which at |D| ~ 10^80 and any interesting m is nearly
  all of them.  The question the register should carry is therefore not 'is delta
  generic' but 'does P1's set of primitive properties admit delta-duplicates',
  which is a decision about the postulate's wording.""")
    print()
    return all([r1, r2, r3, r4, r5, r6])


if __name__ == "__main__":
    import sys
    # Exit only on FAILURE.  The website runs these in the browser under Pyodide,
    # where SystemExit is fatal even at status 0: it tears the runtime down, and the
    # page prints ERROR after output that was in fact correct.  Falling off the end
    # hands the build gates the same status 0, and a failure still exits 1.
    if not main():
        sys.exit(1)
