z3py - z3 fails with this system of equations -
over years keep track of solving technology - and maintain blog post applying them specific puzzle - "crossing ladders".
to point, accidentally found out z3, , tried putting use in specific problem. used python bindings, , wrote this:
$ cat laddersz3.py #!/usr/bin/env python z3 import * = int('a') b = int('b') c = int('c') d = int('d') e = int('e') f = int('f') solve( a>0, a<200, b>0, b<200, c>0, c<200, d>0, d<200, e>0, e<200, f>0, f<200, (e+f)**2 + d**2 == 119**2, (e+f)**2 + c**2 == 70**2, e**2 + 30**2 == a**2, f**2 + 30**2 == b**2, a*d == 119*30, b*c == 70*30, a*f - 119*e + a*e == 0, b*e - 70*f + b*f == 0, d*e == c*f) unfortunately, z3 reports...
$ python laddersz3.py failed solve the problem have @ least integer solution: a=34, b=50, c=42, d=105, e=16, f=40.
am doing wrong, or kind of system of equations / range constraints beyond z3 can solve?
thanks in advance help.
you can solve using z3 if encode integers reals, force z3 use nonlinear real arithmetic solver. see more details on nonlinear integer vs. real arithmetic solvers: how z3 handle non-linear integer arithmetic?
here's example encoded reals solution (z3py link: http://rise4fun.com/z3py/1lxh ):
a,b,c,d,e,f = reals('a b c d e f') solve( a>0, a<200, b>0, b<200, c>0, c<200, d>0, d<200, e>0, e<200, f>0, f<200, (e+f)**2 + d**2 == 119**2, (e+f)**2 + c**2 == 70**2, e**2 + 30**2 == a**2, f**2 + 30**2 == b**2, a*d == 119*30, b*c == 70*30, a*f - 119*e + a*e == 0, b*e - 70*f + b*f == 0, d*e == c*f) # yields [a = 34, b = 50, c = 42, d = 105, e = 16, f = 40] while result integer noted, , z3 finds, z3 apparently needs use real arithmetic solver handle it.
alternatively, can leave variables declared integers , following suggestion @ referenced post:
t = then('purify-arith','nlsat') s = t.solver() solve_using(s, p) where p conjunction of constraints (z3py link: http://rise4fun.com/z3py/7nqn ).
Comments
Post a Comment