File size: 2,271 Bytes
fda6cea
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""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()