from research import *
s=begin(835,'Recover both complete Tishri margins','Do event-category and species totals measure the same frozen count matrix?',{},['File58 §3.1 literal category table'])
p=json.loads((ROOT/'model/list_inputs.json').read_text());rows=p['tables']['category']['rows'];body=rows[:-1];m=[[int(z) for z in r['cells'][1:5]] for r in body]
r=[sum(x) for x in m];c=[sum(x[j] for x in m) for j in range(4)]
a=artifact('model/Tishri_count_matrix.json',json.dumps({'categories':[x['cells'][0] for x in body],'matrix':m,'row_totals':r,'column_totals':c},indent=2)+'\n')
finish(s,{'matrix':a,'category_totals':r,'species_totals':c,'grand_total':sum(r)},'The two280 totals are different marginals of one seven-by-four matrix. Their agreement is forced by the shared ledger, while the chosen categories and entries remain source inputs.','Determine what the margins preserve and what they cannot recover.',{'literal_rows':r==[int(x['cells'][5]) for x in body],'literal_cols':c==[int(x) for x in rows[-1]['cells'][1:5]],'same_total':sum(r)==sum(c)==280})
