z3 - Checking satisfiability for matrix valued function -
i trying multiply 2 matrices of 2*2 order. 1 of matrix contains unknown parameter "k1". want check satisfiable solution value of k1. product of 2 matrices equal third one. note: dont want convert multiplication linear relation or set of equation want manipulate matrices.
here stuck.
k1 = int ('k1') x = [ [ int("x_%s_%s" % (i+1, j+1)) j in range(2) ] in range(2) ] =((1,k1),(3,4)) b =((1,1),(1,1)) c= ((3,3),(7,7)) s = solver() s.add(a[0][1]>0) s.add(a*b==c) if s.check() == sat: m = s.model() r = [ [ m.evaluate(x[i][j]) j in range(2) ] in range(2) ] print_matrix(r) else: print "failed solve" any way out?
one possible solution is
k1 = int ('k1') x = [ [ int("x_%s_%s" % (i+1, j+1)) j in range(2) ] in range(2) ] =((1,k1),(3,4)) b =((1,1),(1,1)) c= ((3,3),(7,7)) s = solver() eq1= a[0][1]>0 eq2 =[[sum(a[i][k]*b[k][j] k in range(2)) == c[i][j] in range(2) ] j in range(2) ] s.add(eq1) s.add(eq2[0][0]) s.add(eq2[0][1]) s.add(eq2[1][0]) s.add(eq2[1][1]) print s print s.check() m = s.model() print m and corresponding output is
[k1 > 0, 1 + k1*1 == 3, true, 1 + k1*1 == 3, true] sat [k1 = 2] please run example online here
Comments
Post a Comment