NYRAELUNE-V / verify_frontier_api.py
PureOne's picture
NYRAELUNE V 5.0.0: manuscript, exact solvers, and verification
fda6cea verified
Raw History Blame Contribute Delete
2.27 kB
"""Hand-computed positive/negative certificates for the reusable exact solver."""
from pathlib import Path
import json
from precision_frontier import analyze
checks=0
def check(test,label):
global checks
if not test:raise AssertionError(label)
checks+=1
def run():
example=json.loads(Path(__file__).with_name('signed_cancellation_input.json').read_text())
result=analyze(example)
check(result['regime_certified'],'polynomial marginality certificate')
check(result['word_valuations']==[0,0,3,None],'third order canceled word')
check(result['beta']=='6','hand-derived cancellation frontier six')
check(result['precision_power_N']=='1/6','inverse frontier exponent')
check(result['leading_psd_matrices'][2][3][3]=='1','hand-derived leading word square')
# Same nonzero edge pattern, exact cancellation gives square zero.
example['generators'][0][2][3]={'1':'-1'}
protected=analyze(example)
check(protected['regime_certified'],'protected marginality')
check(protected['beta']=='infinity','exact protected cancellation')
# Analytic moving image/kernel flag, no fixed one-dimensional invariant flag.
moving={'generators':[[[{'1':'1'},{'2':'-1'}],[1,{'1':'-1'}]]]}
moved=analyze(moving)
check(moved['regime_certified'],'changing flag nilpotence')
check(moved['word_valuations']==[0,0],'changing flag word depth')
check(moved['beta']=='infinity','changing flag baseline uniform')
# A feedback cycle is marginal only at zero, so the full-family certificate fails.
cycle=analyze({'generators':[[[0,1],[{'1':'1'},0]]]})
check(not cycle['regime_certified'],'nonmarginal feedback rejected')
check('beta' not in cycle,'no frontier falsely asserted outside regime')
for invalid in [
{'generators':[]},
{'generators':[[[1,0]]]},
{'generators':[[[0]]],'probabilities':['0']},
{'generators':[[[0]]],'probabilities':['1/2']},
{'generators':[[[{'-1':'1'}]]]},
]:
rejected=False
try:analyze(invalid)
except (ValueError,TypeError):rejected=True
check(rejected,'invalid input rejected')
out={'checks_passed':checks,'failures':0,'method':'hand-derived exact frontier and regime certificates'}
Path(__file__).with_name('frontier_api_results.json').write_text(json.dumps(out,indent=2)+'\n')
print(json.dumps(out))
if __name__=='__main__':run()