void process(expr e) { if (e.num_args() > 0) { for (int i = 0; i < e.num_args(); i++) process(e.arg(i)); return; } if (e.kind() != Z3_APP_AST) return; //not a variable VARIBLE_VALUE vv; func_decl def = e.decl(); vv.name = def.name().str(); if (e.is_bool()) // bool { if (vv.name == "false" || vv.name == "true") return; vv.type = "bool"; vv.size = 1; vv.value = "false"; } else if (e.is_bv()) //bitvector { sort s = def.range(); vv.type = "bitvector"; vv.size = s.bv_size(); vv.value = "0"; } else // we do not handle other sorts { std::cout << "we just handle bool or bitvector.\n"; exit(0); } defaultSolution.insert(std::make_pair(def.name().str(), vv)); }
void ConstraintManager::addConstraint(expr constraint) { cid idx = id2Constraint.size(); expr pi = Utils::get_ctx().bool_const(string("pmuc"+to_string(idx)).c_str()); id2Constraint.push_back(constraint); if (isHLC) constraint = Utils::convert_to_cnf_simplified(constraint); vector<clid> clauses; if (constraint.decl().decl_kind() == Z3_OP_AND) { for (unsigned i = 0; i < constraint.num_args(); ++i) { clauses.push_back(clid2Clause.size()); clid2Clause.push_back(constraint.arg(i)); clid2Cid.push_back(idx); } } else { clauses.push_back(clid2Clause.size()); clid2Clause.push_back(constraint); clid2Cid.push_back(idx); } cid2clauses.push_back(clauses); id2CnfConstraint.push_back(constraint); id2AssumptionP.push_back(pi); p2Id[pi] = idx; }
CoreParser::CoreParser(expr& _ast, ArgParser& _parser): formula(_ast), core(_ast){ stats.isInitCoreUsed = true; vector<expr> initialCore; stats.originalProblemSize = _ast.num_args(); extractInitialCore(_ast, _parser, initialCore); stats.coreSize = initialCore.size(); core = Utils::convert_to_cnf_simplified(Utils::m_and(initialCore)); }
void visit(expr const & e) { if (e.is_app()) { unsigned num = e.num_args(); for (unsigned i = 0; i < num; i++) { visit(e.arg(i)); } // do something // Example: print the visited expression func_decl f = e.decl(); std::cout << "application of " << f.name() << ": " << e << "\n"; } else if (e.is_quantifier()) { visit(e.body()); // do something } else { assert(e.is_var()); // do something } }
// extracts a vector<expr> that represents a core input extracted with Utils::read_core_file method // return 0 if successful (core in resulting clause), or a positive integer if unsuccessful (with empty resultingClause). void CoreParser::extractInitialCore(expr& ast, ArgParser parser, vector<expr>& resultingCore) { vector<string> initialCore; read_core_file(parser.getInputFile(), initialCore); vector<expr> core; unsigned i; for (i = 0; i < initialCore.size(); ++i) { int index = -1; try { index = std::stoi(initialCore[i].substr(initialCore[i].find('c', 0)+1, initialCore[i].size() - 1)); // line should be of the form "C<num>" where C is a char and <num> is an integer between 0 and the number of clauses in the ast } catch (std::invalid_argument& e) { resultingCore.clear(); throw PropsitionalCoreParserException((string(__func__) + ": ERROR in parsing clause named " + initialCore[i] + "at line " + std::to_string(i) + " in core file, clause not named in the form 'C<num>' (for a given number num)").c_str(),3); } if (0 > index || ast.num_args() <= index) { resultingCore.clear(); throw PropsitionalCoreParserException((string(__func__) + ": ERROR index "+ std::to_string(index) + ", at line " + std::to_string(i) + " in core file is out of bounds of formula.").c_str(),4); } resultingCore.push_back(ast.arg(index)); } }