Here are the source code of my testing program of enumerated types:
Z3_symbol enum_names[3];
Z3_func_decl enum_consts[3];
Z3_func_decl enum_testers[3];
enum_names[0]=Z3_mk_string_symbol(z3_cont,"a");
enum_names[1]=Z3_mk_string_symbol(z3_cont,"b");
enum_names[3]=Z3_mk_string_symbol(z3_cont,"c");
Z3_symbol enum_nm = Z3_mk_string_symbol(z3_cont,"enumT");
Z3_sort s = Z3_mk_enumeration_sort(z3_cont, enum_nm, 3, enum_names, enum_consts, enum_testers);
z3::sort ss(z3_cont,s);
z3::expr a = z3::expr(z3_cont,Z3_mk_app(z3_cont,enum_consts[0],0,0));
z3::expr b = z3::expr(z3_cont,Z3_mk_app(z3_cont,enum_consts[1],0,0));
z3::expr x = z3::expr(z3_cont,Z3_mk_const(z3_cont,Z3_mk_string_symbol(z3_cont,"x"),s));
z3::expr test = (x==a)&&(x==b);
cout<<"1:"<<test<<endl;
printf("%s
", Z3_func_decl_to_string(z3_cont, enum_consts[0]));
printf("%s
", Z3_func_decl_to_string(z3_cont, enum_consts[1]));
printf("%s
", Z3_func_decl_to_string(z3_cont, enum_consts[2]));
z3::tactic qe(z3_cont,"ctx-solver-simplify");
z3::goal g(z3_cont);
g.add(test);
z3::expr res(z3_cont);
z3::apply_result result_of_elimination = qe.apply(g);
if ( result_of_elimination.size() == 1){
z3::goal result_formula = result_of_elimination[0];
res = result_formula.operator[](0);
for (int i = 1; i < result_formula.size(); ++i){
res = res && result_formula.operator[](i);
}
}
cout<<"2:"<<res<<endl;
printf("%s
", Z3_func_decl_to_string(z3_cont, enum_consts[0]));
printf("%s
", Z3_func_decl_to_string(z3_cont, enum_consts[1]));
printf("%s
", Z3_func_decl_to_string(z3_cont, enum_consts[2]));
Screen output is the following:
1:(and (= x a) (= x b))
(declare-fun a () enumT)
(declare-fun b () enumT)
(declare-fun x () enumT) Here I have expected "c", Why "x"?
2:false
(declare-fun a () enumT)
(declare-fun bv () (_ BitVec 1)) Why not "b"?
(declare-fun x () enumT)
The main question is how I should use enumerated constants in my program after calling some tactics?
enum_consts structures are broken, Z3_mk_app(z3_cont,Z3_mk_func_decl(z3_cont,Z3_mk_string_symbol(z3_cont,"a"),0,0,s),0,0) doesn't work.
See Question&Answers more detail:
os