Evidence

independent sp cap review.py

Download source fileOpen in research workspace
#!/usr/bin/env python3
"""Independent arithmetic audit from original File18 literals; no journal writes."""
from pathlib import Path
from fractions import Fraction
from itertools import permutations
import argparse
import hashlib
import json
import re

ROOT = Path(__file__).resolve().parents[1]
SOURCE = ROOT.parent / 'project_sources/38-File_18.Chronological_Data_Tables-20260919-141048-.md'
NAMES = ['Adam', 'Seth', 'Enosh', 'Kenan', 'Mahalalel', 'Jared', 'Enoch', 'Methuselah', 'Lamech']


def rows_between(text, start, stop):
    body = text.split(start, 1)[1].split(stop, 1)[0]
    out = {}
    for line in body.splitlines():
        if line.startswith('|'):
            cells = [c.strip() for c in line.strip('|').split('|')]
            out[cells[0]] = cells[1:]
    return out


def leading_int(value):
    return int(re.match(r'^\s*([0-9]+)', value)[1])


def rank(matrix):
    a = [[Fraction(x) for x in row] for row in matrix]
    pivot = 0
    for col in range(len(a[0])):
        choices = [r for r in range(pivot, len(a)) if a[r][col]]
        if not choices:
            continue
        r = choices[0]
        a[pivot], a[r] = a[r], a[pivot]
        scale = a[pivot][col]
        a[pivot] = [x / scale for x in a[pivot]]
        for r in range(len(a)):
            if r != pivot:
                scale = a[r][col]
                a[r] = [x - scale * y for x, y in zip(a[r], a[pivot])]
        pivot += 1
        if pivot == len(a):
            break
    return pivot


def suffix(values):
    return [sum(values[i:]) for i in range(len(values))]


def main():
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument('--through', type=int, required=True)
    parser.add_argument('--output', type=Path, required=True)
    args = parser.parse_args()
    raw = SOURCE.read_bytes()
    text = raw.decode()
    mt = rows_between(text, '### 2.1 Creation to Flood:', '### 2.2')
    sp = rows_between(text, '### 3.1 Creation to Flood:', 'Arithmetic verification:')
    lxx = rows_between(text, '### 4.1 Creation to Flood:', 'Source note:')
    sp_rows = [sp['Adam / preferred chain head' if n == 'Adam' else n] for n in NAMES]
    B_source = [leading_int(r[0]) for r in sp_rows]
    D_source = [leading_int(r[1]) for r in sp_rows]
    life_source = [leading_int(r[2]) for r in sp_rows]
    b = [leading_int(r[3]) - int('53rd year' in r[3]) for r in sp_rows]
    base = [leading_int(mt[n][2]) for n in NAMES]
    lxx_base = [leading_int(lxx[n][2]) for n in NAMES]
    N = leading_int(sp['Noah — G2 primary'][0])
    F = leading_int(sp['Flood — start / close'][0])
    close = leading_int(sp['Flood — start / close'][1])
    k = N - F + 1
    u = suffix(b)
    B = [N + v for v in u]
    cap = [v - F + 1 for v in B]
    life = [min(l, c) for l, c in zip(base, cap)]
    active = [i for i in range(9) if cap[i] < base[i]]
    delta = [v - l for v, l in zip(life, base)]
    slack = [c - v for c, v in zip(cap, life)]
    Q = lambda n: 5 * ((n + 2) // 5)
    records = json.loads((ROOT / 'journal.json').read_text())
    journal = {r['step']: r for r in records if r['step'] <= args.through}
    checks = []

    def check(label, condition, detail=None):
        checks.append({'check': label, 'passed': bool(condition), **({'detail': detail} if detail is not None else {})})

    check('Original File18 source identity', hashlib.sha256(raw).hexdigest() == '68301ab760bfbe2e874aedc5c8d943ced7a6219d34bc2859332a70713f9630d5')
    p = json.loads((ROOT / 'model/sp_cap_inputs.json').read_text())
    check('Forward packet matches independent original-source extraction', p['names'] == NAMES and p['begetting_completed'] == b and p['baseline_lives'] == base and p['Noah_primary'] == N and p['Noah_to_Flood_start'] == N - F)
    check('Forward packet excludes the SP answer lifespan field', set(p) == {'names', 'begetting_completed', 'Noah_primary', 'Noah_to_Flood_start', 'inclusive_adjustment', 'baseline_lives', 'rule', 'scope', 'source_sha256'})
    check('Nine births regenerated from completed begetting edges', B == B_source)
    check('Lamech ordinal binding resolved once', leading_int(sp_rows[-1][3]) == 53 and b[-1] == 52 and B[-1] - b[-1] == N)
    check('Inclusive capacities equal suffix field plus 601', cap == [v + k for v in u] and k == 601 and cap == [1307, 1177, 1072, 982, 912, 847, 785, 720, 653])
    check('Nine cap outputs match independently read SP answers', life == life_source)
    check('Exactly three strict clips', active == [5, 7, 8])
    check('Slack and reductions', slack == [377, 265, 167, 72, 17, 0, 420, 0, 0] and delta == [0, 0, 0, 0, 0, -115, 0, -249, -124])
    death = [birth - lifespan + int(i in active) for i, (birth, lifespan) in enumerate(zip(B, life))]
    check('Ordinary and inclusive death branches match all source dates', death == D_source and all(death[i] == F for i in active))
    check('Equivalent close capacity does not change physical death assignment', close == F - 1 and cap == [v - close for v in B] and F == 2893)
    inferred_F = [B[i] - life[i] + 1 for i in active]
    check('Three inverse boundaries synchronize', inferred_F == [F] * 3)
    pair_matrix = [[1, -1, 0], [0, 1, -1], [1, 0, -1]]
    check('Three pairwise synchronization differences have rank two', rank(pair_matrix) == 2)
    threshold = [l - offset for l, offset in zip(base, u)]
    lower = max(threshold[i] for i in range(9) if i not in active)
    upper = min(threshold[i] for i in active)
    check('Strict-support interval and endpoint qualifications', lower == 584 and upper == 716 and [i for i in range(9) if lower < threshold[i]] == active and [i for i in range(9) if upper < threshold[i]] == [7, 8])
    check('Whole-field total determines same k within fixed support', sum(base[i] for i in range(9) if i not in active) + sum(u[i] for i in active) == 5334 and sum(life) == 7137 and (sum(life) - 5334) / 3 == k)
    late = [[1, 1, 1, 1], [0, 0, 1, 1], [0, 0, 0, 1]]
    check('Late incidence rank and Jared/Enoch exchange kernel', rank(late) == 3 and all(sum(a * v for a, v in zip(row, [1, -1, 0, 0])) == 0 for row in late))
    recovered = [life[8] - k, life[7] - life[8], life[5] - life[7]]
    check('Conditional inverse recovers Lamech, Methuselah, and Jared+Enoch', recovered == [52, 67, 127] and recovered[2] - b[6] == 62)
    altered = b.copy()
    altered[5] += 1
    altered[6] -= 1
    altered_B = [N + v for v in suffix(altered)]
    altered_life = [min(l, birth - F + 1) for l, birth in zip(base, altered_B)]
    check('Exchange kernel changes only Enoch birth and preserves all nine lives', altered_life == life and [x - y for x, y in zip(altered_B, B)] == [0, 0, 0, 0, 0, 0, -1, 0, 0])
    for i in range(5):
        changed = b.copy()
        changed[i] += 1
        check(f'Upper begetting column {i} does not enter any active capacity', all(suffix(changed)[j] == u[j] for j in active))
    check('Inverse min has six exact inputs and three lower bounds', all(life[i] < cap[i] for i in range(9) if i not in active) and all(life[i] == cap[i] for i in active))
    fits = [list(v) for v in permutations([962, 969, 777]) if [min(l, cap[i]) for l, i in zip(v, active)] == [life[i] for i in active]]
    check('Four multiset assignments have identical cap outputs', len(fits) == 4 and [962, 969, 777] in fits)
    lxx_output = [min(l, c) for l, c in zip(lxx_base, cap)]
    check('Main LXX 753 and MT 777 project to identical SP output', lxx_base[-1] == 753 and lxx_output == life and sum(base) - sum(life) == 488 and sum(lxx_base) - sum(life) == 464)
    joint = [[1, 1, 1, 1, -1, 0, 0, 1], [0, 0, 1, 1, 0, -1, 0, 1], [0, 0, 0, 1, 0, 0, -1, 1]]
    check('Bidirectional equation dimensions', rank(joint) == 3 and 8 - rank(joint) == 5 and 8 - rank(joint) - 2 == 3)
    cumulative = suffix(delta)
    check('All cumulative displacements and adjacent recovery', cumulative == [-488, -488, -488, -488, -488, -488, -373, -373, -124] and [cumulative[i] - (cumulative[i+1] if i+1 < 9 else 0) for i in range(9)] == delta)
    check('Dependent total separates the two post-Flood reductions', cumulative[0] - 60 - 60 == -608)
    matrices = json.loads((ROOT / 'model/sp_cap_response_matrices.json').read_text())
    all_B_columns, all_L_columns, all_C_columns = [], [], []
    for j in range(9):
        changed = b.copy()
        changed[j] += 1
        next_B = [N + v for v in suffix(changed)]
        next_L = [min(l, birth - F + 1) for l, birth in zip(base, next_B)]
        all_B_columns.append([x - y for x, y in zip(next_B, B)])
        all_L_columns.append([x - y for x, y in zip(next_L, life)])
        all_C_columns.append(suffix(all_L_columns[-1]))
    transpose = lambda cols: [list(row) for row in zip(*cols)]
    check('Full nine-column finite response matches all three derivative matrices', transpose(all_B_columns) == matrices['dB_db'] and transpose(all_L_columns) == matrices['dL_db'] and transpose(all_C_columns) == matrices['dC_db'])
    check('Regular derivative requires fixed Noah placement or relative coordinates', [v + 215 for v in B] != B and [v + 215 - (F + 215) + 1 for v in B] == cap, 'dB = U db + 1 dN; at fixed k, the lifespan/cumulative response has no whole-frame term.')
    check('Admitted +215 whole-frame shift preserves all capacities', [birth + 215 - (F + 215) + 1 for birth in B] == cap and B[0] + 215 == 4414)
    local_paths = [[52, 500, 100], [53, 499, 100], [53, 500, 99]]
    check('Three source-local paths preserve Lamech capacity', [sum(path) for path in local_paths] == [652] * 3 and [B[-1] - sum(path) for path in local_paths] == [F] * 3)
    rounded = list(map(Q, life))
    check('Nearest-five min commutation for all nine resolved counts', rounded == [min(Q(l), Q(c)) for l, c in zip(base, cap)] and rounded == [930, 910, 905, 910, 895, 845, 365, 720, 655])
    check('Strict support remains unchanged for this particular rounded field', [i for i in range(9) if Q(cap[i]) < Q(base[i])] == active and not any(Q(cap[i]) == Q(base[i]) for i in range(9)))
    date_first = [Q(B[i]) - Q(F) + 1 for i in active]
    count_first = [Q(cap[i]) for i in active]
    check('Date-first and count-first rounding are different operations', count_first == [845, 720, 655] and date_first == [846, 716, 651])
    base_rounded = list(map(Q, base))
    relative_residual = [(Q(v) - v) - (Q(l) - l) for v, l in zip(life, base)]
    check('Rounding changes the cap-derived difference by three', relative_residual == [0, 0, 0, 0, 0, 0, 0, -1, 4] and sum(rounded) - sum(base_rounded) == -485 and sum(rounded) - sum(base_rounded) - 120 == -605)
    check('Cap is idempotent for every source row', [min(v, c) for v, c in zip(life, cap)] == life)
    check('Cap is not injective at active rows', [min(v + 1, cap[i]) for i, v in enumerate(base)] == [life[i] + int(i not in active) for i in range(9)])
    complete = json.loads((ROOT / 'model/sp_cap_complete_ledger.json').read_text())
    check('C983 complete ledger matches independent source reconstruction', complete['generated'] == {'births': B, 'capacities': cap, 'lives': life, 'deaths': death})
    check('C983 records both review clarifications', 'fixed Noah placement' in complete['review_clarifications']['C974'] and 'File18 §3.1;' in complete['review_clarifications']['C977_locator'])
    check('Reviewed journal scope is complete', all(i in journal for i in range(953, args.through + 1)))
    report = {
        'status': 'PASS' if all(c['passed'] for c in checks) else 'FAIL',
        'scope': f'C953–C{args.through}; independent original-source arithmetic and claim-domain review, not a statistical or historical-origin test',
        'source': {'path': str(SOURCE), 'sha256': hashlib.sha256(raw).hexdigest()},
        'journal_record_bindings': {str(i): journal[i]['sha256'] for i in range(953, args.through + 1)},
        'independent_literals': {'names': NAMES, 'completed_begetting': b, 'SP_births': B_source, 'SP_deaths': D_source, 'SP_lifespan_answers': life_source, 'MT_baseline': base, 'main_LXX_baseline': lxx_base, 'Noah_primary': N, 'Flood_start': F, 'Flood_close': close},
        'checks': checks,
        'passed_checks': sum(c['passed'] for c in checks),
        'failed_checks': sum(not c['passed'] for c in checks),
        'clarification_resolution': 'Both C974 derivative-placement and C977 locator qualifications were incorporated explicitly in C983/model/sp_cap_complete_ledger.json. No outstanding arithmetic correction.',
        'qualifications': [
            'C974 dB/db=U is at fixed Noah placement, or on relative B−N coordinates. Merely fixing Noah−Flood does not freeze absolute birth labels.',
            'C977 three admitted local paths occur in File18 §3.1, not §3.1.2.',
            'The source already supplies the cap rule and SP birth architecture; excluding SP answer lives creates a forward validation packet, not a blind empirical prediction.',
            'The forward projection is compatible with both MT and main LXX ancestral ledgers, so it does not establish historical MT→SP dependence.',
            'Formal perturbations, alternative cap placements, and multiset permutations are diagnostics, not admitted source states.',
        ],
    }
    args.output.write_text(json.dumps(report, indent=2, ensure_ascii=False) + '\n')
    print(json.dumps({'status': report['status'], 'passed_checks': report['passed_checks'], 'failed_checks': report['failed_checks'], 'output': str(args.output)}))


if __name__ == '__main__':
    main()

Linked sources and evidence

Edition and provenance

independent_sp_cap_review.py

SHA-256 525f787957c1e7ad57ef2af9fdaa8a7f0edf62b5f25753e5cb03c3a3e34e487e

C480–C1634/Research_Cycles/C0932_C1131/evidence/independent_sp_cap_review.py