I encountered a problem and found that variables can only be solved simultaneously as integers or real numbers。
from pysmt.shortcuts import *
from pysmt.typing import *
hello = [Symbol(s, INT) for s in "hello"]
pysmt = [Symbol(s, REAL) for s in "pysmt"]
domains_1 = And([And(GE(l, Int(1)),
LT(l, Int(10))) for l in hello])
domains_2 = And([And(GE(l, Real(1)),
LT(l, Real(10))) for l in pysmt])
hello = [Symbol(s, INT) for s in "hello"]
pysmt = [Symbol(s, REAL) for s in "pysmt"]
domains_1 = And([And(GE(l, Int(1)),
LT(l, Int(10))) for l in hello])
domains_2 = And([And(GE(l, Real(1)),
LT(l, Real(10))) for l in pysmt])
sum_hello = Plus(hello) # n-ary operators can take lists
sum_pysmt = Plus(pysmt) # as arguments
problem = And(Equals(sum_hello, sum_pysmt),
Equals(sum_hello, Int(25)))
formula = And(domains_1, domains_2, problem)
print("Serialization of the formula:")
print(formula)
model = get_model(formula, solver_name="z3")
if model:
print(model)
else:
print("No solution found")
---------------------------------------------------------------------------
PysmtTypeError Traceback (most recent call last)
Input In [2], in <cell line: 10>()
8 sum_hello = Plus(hello) # n-ary operators can take lists
9 sum_pysmt = Plus(pysmt) # as arguments
---> 10 problem = And(Equals(sum_hello, sum_pysmt),
11 Equals(sum_hello, Int(25)))
12 formula = And(domains_1, domains_2, problem)
14 print("Serialization of the formula:")
File D:\python38\lib\site-packages\pysmt\shortcuts.py:209, in Equals(left, right)
207 def Equals(left, right):
208 r""".. math:: l = r"""
--> 209 return get_env().formula_manager.Equals(left, right)
File D:\python38\lib\site-packages\pysmt\formula.py:284, in FormulaManager.Equals(self, left, right)
279 def Equals(self, left, right):
280 """ Creates an expression of the form: left = right
281
282 For the boolean case use Iff
283 """
--> 284 return self.create_node(node_type=op.EQUALS,
285 args=(left, right))
File D:\python38\lib\site-packages\pysmt\formula.py:96, in FormulaManager.create_node(self, node_type, args, payload)
94 self._next_free_id += 1
95 self.formulae[content] = n
---> 96 self._do_type_check(n)
97 return n
File D:\python38\lib\site-packages\pysmt\formula.py:81, in FormulaManager._do_type_check_real(self, formula)
80 def _do_type_check_real(self, formula):
---> 81 self.get_type(formula)
File D:\python38\lib\site-packages\pysmt\type_checker.py:45, in SimpleTypeChecker.get_type(self, formula)
43 res = self.walk(formula)
44 if not self.be_nice and res is None:
---> 45 raise PysmtTypeError("The formula '%s' is not well-formed" \
46 % str(formula))
47 return res
PysmtTypeError: The formula '((h + e + l + l + o) = (p + y + s + m + t))' is not well-formed