I am trying to evaluate resultant matrix by asserting constraint on matrix multiplication using z3py API. The following method works for matrix addition. Following is the code, which have 3 matrices: x, y, and sol. sol is the addition of x and y (sol==x+y), I am interested to restrict the values of resultant matrix (sol) to zero, and check which unknown values in "x" and "y" yield resultant matrix to be zero. Following is the list comprehension approach for addition.
from z3 import*
x = [ [Real("x_%s_%s" %(i+1, j+1)) for j in range(2) ] for i in range(2)]
y = [ [Real("y_%s_%s" %(i+1, j+1)) for j in range(2) ] for i in range(2)]
sol = [ [Real("sol_%s_%s" %(i+1, j+1)) for j in range(2) ] for i in range(2)]
addition = [sol[i][j]==x[i][j]+y[i][j] for i in range(2) for j in range(2) ]
s = Solver()
s.add(addition)
s.add(x[0][0]>=0)
s.add(x[0][1]>=0)
s.add(x[1][0]>=0)
s.add(x[1][1]>=1)
s.add(And(y[0][0]>=0, y[0][0]<=2))
s.add(And(y[0][1]>=0, y[0][0]<=2))
s.add(And(y[1][0]>=0, y[0][0]<=2))
s.add(And(y[1][1]>=0, y[0][0]<=2))
s.add(sol[0][0]==0)
s.add(sol[0][1]==0)
s.add(sol[1][0]==0)
s.add(sol[1][1]==0)
if s.check()==sat:
m =s.model()
print SAT,'\n', m
result=[[ m.evaluate(sol[i][j]) for i in range (2)] for j in range (2)]
print result
if (s.check()==unsat):
print "UNSAT, no model exists"
Now, is there any way in list comprehension through which I can assert matrix multiplication? (sol==x*y)...?