23 for(
const auto &bit : bv)
24 if(!bit.is_constant())
66 return result.first->second;
72 result.first->second = literal;
89 else if(expr.
id() == ID_symbol)
91 symbolst::const_iterator result =
101 else if(expr.
id() == ID_literal)
108 if(expr.
id() == ID_not)
119 else if(expr.
id() == ID_and || expr.
id() == ID_or)
123 for(
const auto &op : expr.
operands())
129 if(expr.
id() == ID_and)
141 return expr.
id() == ID_and;
147 cachet::const_iterator cache_result =
cache.find(expr);
148 if(cache_result ==
cache.end())
168 auto &cache_entry = result.first->second;
178 cache_entry = literal;
184 std::cout << literal <<
"=" << expr <<
'\n';
204 "constant expression of type bool should be either true or false");
208 else if(expr.
id() == ID_symbol)
212 else if(expr.
id() == ID_literal)
216 else if(expr.
id() == ID_nondet_symbol)
220 else if(expr.
id() == ID_implies)
226 else if(expr.
id() == ID_if)
234 else if(expr.
id() == ID_constraint_select_one)
238 "constraint_select_one should have at least two operands");
240 std::vector<literalt> op_bv;
241 op_bv.reserve(op.size());
243 for(
const auto &op : expr.
operands())
249 b.reserve(op_bv.size() - 1);
251 for(
unsigned i = 1; i < op_bv.size(); i++)
259 expr.
id() == ID_or || expr.
id() == ID_and || expr.
id() == ID_xor ||
260 expr.
id() == ID_nor || expr.
id() == ID_nand)
264 "operator '" + expr.
id_string() +
"' takes at least one operand");
268 for(
const auto &operand : op)
269 bv.push_back(
convert(operand));
273 if(expr.
id() == ID_or)
275 else if(expr.
id() == ID_nor)
277 else if(expr.
id() == ID_and)
279 else if(expr.
id() == ID_nand)
281 else if(expr.
id() == ID_xor)
285 else if(expr.
id() == ID_not)
287 INVARIANT(op.size() == 1,
"not takes one operand");
290 else if(expr.
id() == ID_equal || expr.
id() == ID_notequal)
292 INVARIANT(op.size() == 2,
"equality takes two operands");
293 bool equal = (expr.
id() == ID_equal);
295 if(op[0].is_boolean() && op[1].is_boolean())
301 else if(expr.
id() == ID_named_term)
307 return value_converted;
328 if(expr.
lhs().
id() == ID_symbol)
334 std::pair<symbolst::iterator, bool> result =
335 symbols.insert(std::pair<irep_idt, literalt>(identifier, tmp));
350 const bool has_only_boolean_operands = std::all_of(
352 return expr.is_boolean();
355 if(has_only_boolean_operands)
357 if(expr.
id() == ID_not)
368 if(expr.
id() == ID_and)
370 for(
const auto &op : expr.
operands())
375 else if(expr.
id() == ID_or)
385 for(
const auto &op : expr.
operands())
392 else if(expr.
id() == ID_implies)
400 else if(expr.
id() == ID_equal)
409 if(expr.
id() == ID_implies)
417 else if(expr.
id() == ID_or)
419 for(
const auto &op : expr.
operands())
448 const auto post_process_start = std::chrono::steady_clock::now();
454 const auto post_process_stop = std::chrono::steady_clock::now();
455 std::chrono::duration<double> post_process_runtime =
456 std::chrono::duration<double>(post_process_stop - post_process_start);
457 log.
statistics() <<
"Runtime Post-process: " << post_process_runtime.count()
491 if(value.has_value())
511 for(
const auto &symbol :
symbols)
512 out << symbol.first <<
" = " <<
prop.
l_get(symbol.second) <<
'\n';
541 for(
const auto &assumption : assumptions)
543 auto literal =
convert(assumption);
544 if(!literal.is_constant())
575 return "propositional reduction";
resultt
Result of running the decision procedure.
void set_to_true(const exprt &)
For a Boolean expression expr, add the constraint 'expr'.
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Base class for all expressions.
std::vector< exprt > operandst
bool is_true() const
Return whether the expression is a constant representing true.
bool is_boolean() const
Return whether the expression represents a Boolean.
bool is_false() const
Return whether the expression is a constant representing false.
bool is_constant() const
Return whether the expression is a constant.
The Boolean constant false.
The trinary if-then-else operator.
std::string pretty(unsigned indent=0, unsigned max_indent=0) const
const std::string & id_string() const
const irep_idt & id() const
literalt get_literal() const
mstreamt & statistics() const
mstreamt & warning() const
mstreamt & progress() const
void pop() override
Pop whatever is on top of the stack.
virtual bool set_equality_to_true(const equal_exprt &expr)
virtual literalt convert_bool(const exprt &expr)
decision_proceduret::resultt dec_solve(const exprt &) override
Implementation of the decision procedure.
void set_frozen(literalt)
std::vector< size_t > context_size_stack
assumption_stack is segmented in contexts; Number of assumptions in each context on the stack
std::size_t context_literal_counter
To generate unique literal names for contexts.
std::size_t get_number_of_solver_calls() const override
Return the number of incremental solver calls.
bool equality_propagation
bool post_processing_done
virtual void finish_eager_conversion()
virtual literalt get_literal(const irep_idt &symbol)
std::string decision_procedure_text() const override
Return a textual description of the decision procedure.
virtual void ignoring(const exprt &expr)
void add_constraints_to_prop(const exprt &expr, bool value)
Helper method used by set_to for adding the constraints to prop.
void push() override
Push a new context on the stack This context becomes a child context nested in the current context.
virtual std::optional< bool > get_bool(const exprt &expr) const
Get a boolean value from the model if the formula is satisfiable.
literalt convert(const exprt &expr) override
Convert a Boolean expression and return the corresponding literal.
exprt get(const exprt &expr) const override
Return expr with variables replaced by values from satisfying assignment if available.
bvt assumption_stack
Assumptions on the stack.
virtual literalt convert_rest(const exprt &expr)
void set_to(const exprt &expr, bool value) override
For a Boolean expression expr, add the constraint 'current_context => expr' if value is true,...
exprt handle(const exprt &expr) override
Generate a handle, which is an expression that has the same value as the argument in any model that i...
static const char * context_prefix
bool is_in_conflict(const exprt &expr) const override
Returns true if an expression is in the final conflict leading to UNSAT.
void print_assignment(std::ostream &out) const override
Print satisfying assignment to out.
void l_set_to_true(literalt a)
virtual literalt land(literalt a, literalt b)=0
std::size_t get_number_of_solver_calls() const
virtual void set_variable_name(literalt, const irep_idt &)
virtual literalt limplies(literalt a, literalt b)=0
virtual literalt lselect(literalt a, literalt b, literalt c)=0
virtual void set_frozen(literalt)
virtual void l_set_to(literalt a, bool value)
virtual literalt lxor(literalt a, literalt b)=0
virtual std::string solver_text() const =0
void lcnf(literalt l0, literalt l1)
virtual literalt new_variable()=0
virtual literalt lequal(literalt a, literalt b)=0
virtual literalt lor(literalt a, literalt b)=0
virtual bool is_in_conflict(literalt l) const =0
Returns true if an assumption is in the final conflict.
virtual tvt l_get(literalt a) const =0
Expression to hold a symbol (variable)
const irep_idt & get_identifier() const
The Boolean constant true.
std::vector< literalt > bvt
literalt const_literal(bool value)
const literal_exprt & to_literal_expr(const exprt &expr)
Cast a generic exprt to a literal_exprt.
#define UNREACHABLE
This should be used to mark dead code.
#define DATA_INVARIANT(CONDITION, REASON)
This condition should be used to document that assumptions that are made on goto_functions,...
#define PRECONDITION(CONDITION)
const if_exprt & to_if_expr(const exprt &expr)
Cast an exprt to an if_exprt.
const symbol_exprt & to_symbol_expr(const exprt &expr)
Cast an exprt to a symbol_exprt.
const not_exprt & to_not_expr(const exprt &expr)
Cast an exprt to an not_exprt.
const named_term_exprt & to_named_term_expr(const exprt &expr)
Cast an exprt to a named_term_exprt.
const equal_exprt & to_equal_expr(const exprt &expr)
Cast an exprt to an equal_exprt.
const implies_exprt & to_implies_expr(const exprt &expr)
Cast an exprt to a implies_exprt.
std::string to_string(const string_not_contains_constraintt &expr)
Used for debug printing.