diff --git a/src/api/python/z3/z3.py b/src/api/python/z3/z3.py index ed9c7f0a856..af1d32972ed 100644 --- a/src/api/python/z3/z3.py +++ b/src/api/python/z3/z3.py @@ -1101,6 +1101,28 @@ def children(self): else: return [] + def from_string(self, s): + pass + + def serialize(self): + s = Solver() + f = Function('F', self.sort(), BoolSort(self.ctx)) + s.add(f(self)) + return s.sexpr() + +def deserialize(st): + """inverse function to the serialize method on ExprRef. + It is made available to make it easier for users to serialize expressions back and forth between + strings. Solvers can be serialized using the 'sexpr()' method. + """ + s = Solver() + s.from_string(st) + if len(s.assertions()) != 1: + raise Z3Exception("single assertion expected") + fml = s.assertions()[0] + if fml.num_args() != 1: + raise Z3Exception("dummy function 'F' expected") + return fml.arg(0) def _to_expr_ref(a, ctx): if isinstance(a, Pattern):