from fractions import Fraction as F
from pathlib import Path
import json

checks = []
def ck(name, actual, expected):
    assert actual == expected, (name, actual, expected)
    checks.append({'name': name, 'actual': str(actual), 'expected': str(expected), 'pass': True})

def K(q, x): return F(q) + F(25, 23) * (x-q)
def P(q, x): return F(q) + F(70, 69) * (x-q)

ck('existing Covenant direct edge', K(1866, 13136), 14116)
ck('existing Prophetic head', P(1406, 13136), 13306)
ck('existing original SP lower leg', 3106-1406, 1700)
ck('existing 1700 return', P(1406,13136)-1700, 11606)
ck('common stage increment', 11606+2700, 14306)
ck('SP mode change', 14116-14306, -190)
ck('connected circuit', P(1406,13136)-1700+2700-190, K(1866,13136))
ck('connected circuit displacement', 170-1700+2700-190, 980)
ck('Priestly return', 1866+F(23,25)*(14116-1866), 13136)
ck('SP return through Prophetic edge', 1406+F(69,70)*(14116+190-2700+1700-1406), 13136)
ck('rounded double Key composition', K(4106,P(1406,13136)), 14106)
ck('double Key exact miss', 14116-K(4106,P(1406,13136)), 10)
ck('actual counterpart interval', 14116-4116, 10000)
ck('round counterpart interval', 14106-4106, 10000)
ck('changing only the held endpoint', K(4116,13306), F(324418,23))
ck('transport whole construction by 10', K(4116,13316), 14116)
ck('two-stage fixed Covenant result', K(1866,10436), F(257168,23))
ck('two-stage fixed Covenant shortfall', 11416-K(1866,10436), F(5400,23))
ck('stage translation commutator', K(1866,10436+2700)-K(1866,10436)-2700, F(5400,23))
ck('mode changed LXX result', K(1866,13636), F(337168,23))
ck('mode changed miss MT', 14726-K(1866,13636), F(1530,23))
ck('mode changed miss SP regular', K(1866,13636)-14306, F(8130,23))
ck('mode changed miss SP cumulative', K(1866,13636)-14116, F(12500,23))
ck('MT upper edge', 12026-4836, 7190)
ck('SP inverse-to-source edge', 11606-4416, 7190)
ck('translated head', 12026-11606, 420)
ck('translated target', 4836-4416, 420)
ck('cross-tradition regular gap', 14306-13136, 1170)
ck('cross-tradition cumulative gap', 14116-13636, 480)
ck('mode interaction', (14306-13136)-(14116-13636), 690)
ck('Priestly mode module', F(25,23)*690, 750)
ck('Prophetic mode module', F(70,69)*690, 700)
ck('LXX mode residue', 500%69, 17)
ck('SP mode residue', (-190)%69, 17)

out = {'status':'pass', 'grouped_check_count':len(checks), 'scope':'Key circuits and exact misses; no second decimal reversal; no significance scan', 'checks':checks}
Path(__file__).with_name('verification.json').write_text(json.dumps(out, indent=2)+'\n')
print(json.dumps({'status':out['status'], 'grouped_check_count':len(checks)}))
