Logicandapplications2023/class_21_05102023/getmodel.cpp

46 lines
860 B
C++

#include <iostream>
#include <sstream>
#include<vector>
#include"z3++.h"
using namespace z3;
/**
find values of expressions that satisfy the following ineaualities
x >= 1
y < x +3
*/
int main(){
context c;
expr x = c.int_const("x");
expr y = c.int_const("y");
//create a solver
solver s(c);
//adding the constraints
s.add(x >=1);
s.add(y < x+3);
std::cout << s.check() << "\n\n";
model m = s.get_model();
std::cout << m << "\n";
//traversing the model
std::cout << "traversing the model" << "\n";
for (unsigned i =0; i < m.size(); i++){
func_decl v = m[i];
assert(v.arity() ==0);
std::cout << v.name()<<"="<<m.get_const_interp(v) << "\n";
}
// evaluating the expressions in the model.
std::cout << "evaluating the expressions in the model" << "\n";
std::cout << "x+y+1= "<< m.eval(x+y+1)<<"\n";
return 0;
} //end of function