from research import *
from algebra import Matrix
s=begin(1133,'Form the joint SP age constraints','How many free age coordinates remain after the explicit source relations and inherited cap equations?',{'variables':['Adam','Seth','Enosh','Kenan','Mahalalel','Jared','Enoch','Methuselah','Lamech']},['C1132','File18 §3.1','File51a §8.3'])
a=[[1,0,0,0,-2,0,0,0,0],[0,0,0,0,-1,0,1,0,0],[1,1,1,1,1,0,0,0,0],[0,0,0,0,0,0,0,0,1],[0,0,0,0,0,0,0,1,0],[0,0,0,0,0,1,1,0,0]]
rhs=[0,0,460,52,67,127];v=[130,105,90,70,65,62,65,67,52];A=Matrix(a)
data={'variables':s['inputs']['variables'],'matrix':a,'rhs':rhs,'source_ages':v,'rank':A.rank(),'free_coordinates':9-A.rank(),'kernel':[clean(list(x)) for x in A.nullspace()]}
art=artifact('model/SP_age_constraints.json',json.dumps(data,indent=2)+'\n')
finish(s,{'age_constraints':art,'rank':A.rank(),'free_coordinates':9-A.rank()},'The six retained relations have rank6 on nine ages, leaving three free coordinates. They reduce the local input model without uniquely recovering the whole age sequence.','Describe the three remaining freedoms explicitly to see which source values are still needed.',{'all_source_equations':list(A*Matrix(v))==list(Matrix(rhs)),'rank6':A.rank()==6})
