I'm am trying to load in an smt2 file using the C++/C API for z3 (v4.5.1), and then add assertions using the API, with datatypes and functions that were declared in the smt2 file.
Here is an example of what I do to load a file into a solver:
solver loadBackgroundTheoryFile(context& c, string filename) {
Z3_ast ast = Z3_parse_smtlib2_file(c, filename.c_str(), 0, 0, 0, 0, 0, 0);
Z3_solver c_solver;
expr e(c, ast);
solver s(c);
s.add(e);
return s;
}
int main() {
context g;
solver s = loadBackgroundTheoryFile(g, "family.smt2");
std::cout << s << std::endl;
// Here it shows that the solver has all the contents of the family.smt2 file
return 0;
}
So how do I use what was defined in the smt2 file, using the C or C++ API? (If possible). I would like to make more assertions, get a model, and then evaluate, using the functions and data types defined in the smt2 file. Here are the contents of the smt2 file if anyone is interested:
;(declare-sort Person)
(declare-datatypes () ((Person (person (name String)))))
(declare-fun related (Person Person) Bool)
(declare-fun father (Person Person) Bool)
(declare-fun sibling (Person Person) Bool)
; related symetric
(assert
(forall ((p Person) (q Person))
(=> (related p q)
(related q p))))
; related transitive
(assert
(forall ((p Person) (q Person) (j Person))
(=> (and (related p q) (related q j))
(related p j))))
; the father of a person is related to that person
(assert
(forall ((p Person) (q Person))
(=> (father p q)
(related p q))))
; for all people, there exists another person that is their father
(assert
(forall ((p Person))
(exists ((q Person)) (father q p))))
; sibling symetric
(assert
(forall ((p Person) (q Person))
(=> (sibling p q) (sibling q p))))
; siblings have the same father
(assert
(forall ((p Person) (q Person) (j Person))
(=> (and (sibling p q) (father j p))
(father j q))))
(declare-fun get-father (Person) Person)
; here we use a double implication to define the behavior of get-father
(assert
(forall ((p Person) (q Person))
(= (father q p) (= (get-father p) q))))
This is a very "z3 implementation specific" question. You might get a better response if you filed a ticket with the developers here: https://github.com/Z3Prover/z3/issues