File size: 6,762 Bytes
22ef089
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#!/usr/bin/env python3
"""Exact finite checks for the radical-product alternative.

Python 3 standard library only. This checks finite instances, not novelty or
universal theorems. The manuscript appendix supplies the proofs.

Run:
    python verify_candidates.py
"""
from itertools import product
import json


def recurrence_terminal(N, m):
    """Iterate the stated scalar one-step recurrence to its fixed point."""
    while True:
        nxt = max(m, 2 * min(m, N - m - 1))
        if nxt == m:
            return m
        if not m < nxt <= N - 1:
            raise AssertionError((N, m, nxt))
        m = nxt


def interval_formula(N, m):
    """Evaluate the closed terminal formula independently of the recurrence."""
    n = N - 1
    a = m
    while 2 * a < n:
        a *= 2
    return max(a, 2 * (n - a))


def literal_step(S, caps):
    """Monomial update by complementary supports and pairwise multiplication.

    Exponents are tuples. This function does not use interval endpoints or the
    tensor dimension formula. Coordinates exceeding their truncation cap
    represent a zero product and are omitted.
    """
    S = frozenset(S)
    dark = {
        u for u in S
        if tuple(cap - value for cap, value in zip(caps, u)) not in S
    }
    out = set(S)
    for u in dark:
        for v in dark:
            w = tuple(a + b for a, b in zip(u, v))
            if all(value <= cap for value, cap in zip(w, caps)):
                out.add(w)
    return frozenset(out), frozenset(dark)


def literal_terminal(S, caps):
    S = frozenset(S)
    rounds = 0
    while True:
        nxt, dark = literal_step(S, caps)
        if nxt == S:
            return S, dark, rounds
        if not S < nxt:
            raise AssertionError("Literal update was not strictly extensive")
        S = nxt
        rounds += 1


def interval_support(m):
    return frozenset((i,) for i in range(1, m + 1))


def check_async_sequence(N, products, expected):
    S = interval_support(1)
    for i, j in products:
        nxt, dark = literal_step(S, (N,))
        if (i,) not in dark or (j,) not in dark:
            raise AssertionError(("Unauthorized asynchronous product", S, i, j))
        born = (i + j,)
        if i + j > N or born in S or born not in nxt:
            raise AssertionError(("Invalid asynchronous birth", S, born))
        S = S | {born}
    if S != frozenset((i,) for i in expected):
        raise AssertionError(("Wrong asynchronous endpoint", S, expected))
    nxt, dark = literal_step(S, (N,))
    if nxt != S:
        raise AssertionError("Asynchronous endpoint was not terminal")
    return {
        "N": N,
        "products": [list(pair) for pair in products],
        "terminal_exponents": sorted(i for (i,) in S),
        "terminal_dark_exponents": sorted(i for (i,) in dark),
    }


def main():
    recurrence_cases = 0
    for N in range(2, 301):
        for m in range(1, N):
            actual = recurrence_terminal(N, m)
            expected = interval_formula(N, m)
            if actual != expected:
                raise AssertionError(("Recurrence/formula mismatch", N, m, actual, expected))
            recurrence_cases += 1
    assert recurrence_cases == 44850

    literal_interval_cases = 0
    literal_boundary_cases = 0
    for N in range(2, 41):
        for m in range(1, N):
            actual, dark, rounds = literal_terminal(interval_support(m), (N,))
            expected = interval_support(interval_formula(N, m))
            if actual != expected:
                raise AssertionError(("Literal interval mismatch", N, m, actual, expected))
            literal_interval_cases += 1
        for seed in (frozenset(), interval_support(N)):
            actual, dark, rounds = literal_terminal(seed, (N,))
            if actual != seed or rounds != 0:
                raise AssertionError(("Boundary state not fixed", N, seed, actual))
            literal_boundary_cases += 1
    assert literal_interval_cases == 780
    assert literal_boundary_cases == 78

    n13 = []
    for m in (3, 4):
        S = interval_support(m)
        dimensions = [len(S)]
        while True:
            nxt, dark = literal_step(S, (13,))
            if nxt == S:
                break
            S = nxt
            dimensions.append(len(S))
        n13.append({"initial_m": m, "dimensions_until_fixed": dimensions})
    assert [item["dimensions_until_fixed"] for item in n13] == [[3, 6, 12], [4, 8]]

    tensor_rows = []
    for r in range(1, 7):
        seed = frozenset(product((1, 2), repeat=r))
        first, initial_dark = literal_step(seed, (4,) * r)
        second, terminal_dark = literal_step(first, (4,) * r)
        expected = 2**r + 3**r - r - 2
        if len(first) != expected or second != first:
            raise AssertionError(("Tensor dimension/terminality mismatch", r, len(first), expected))
        if r >= 2 and len(terminal_dark) != 3**r - 2**r - r - 1:
            raise AssertionError(("Tensor terminal radical mismatch", r))
        tensor_rows.append({
            "r": r,
            "initial_dimension": len(seed),
            "initial_radical_dimension": len(initial_dark),
            "terminal_dimension": len(first),
            "terminal_radical_dimension": len(terminal_dark),
            "first_update_is_terminal": second == first,
        })
    assert [row["terminal_dimension"] for row in tensor_rows] == [2, 9, 30, 91, 268, 785]

    asynchronous = [
        check_async_sequence(7, [(1, 1), (2, 2), (1, 2)], [1, 2, 3, 4]),
        check_async_sequence(7, [(1, 1), (1, 2), (2, 3), (1, 3)], [1, 2, 3, 4, 5]),
    ]
    result = {
        "status": "PASS",
        "arithmetic": "Exact integer exponents and finite sets; Python standard library",
        "recurrence_vs_closed_formula": {
            "N_range_inclusive": [2, 300],
            "m_range": "1 <= m < N",
            "cases": recurrence_cases,
        },
        "independent_literal_interval_updates": {
            "N_range_inclusive": [2, 40],
            "m_range": "1 <= m < N",
            "cases": literal_interval_cases,
        },
        "literal_boundary_states": {
            "N_range_inclusive": [2, 40],
            "states_per_N": "empty and {1,...,N}",
            "cases": literal_boundary_cases,
        },
        "N13_nonmonotonicity": n13,
        "literal_tensor_cases": tensor_rows,
        "asynchronous_terminal_histories": asynchronous,
        "scope": (
            "Finite instances and implementation consistency only. These checks "
            "do not establish universal theorems, priority, general nonmonomial "
            "behavior, perturbation robustness, or computational usefulness."
        ),
    }
    print(json.dumps(result, indent=2))


if __name__ == "__main__":
    main()