CBMC
prop.h
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module:
4 
5 Author: Daniel Kroening, kroening@kroening.com
6 
7 \*******************************************************************/
8 
9 
10 #ifndef CPROVER_SOLVERS_PROP_PROP_H
11 #define CPROVER_SOLVERS_PROP_PROP_H
12 
13 // decision procedure wrapper for boolean propositional logics
14 
15 #include <util/message.h>
16 #include <util/threeval.h>
17 
18 #include "literal.h"
19 
22 class propt
23 {
24 public:
25  explicit propt(message_handlert &message_handler) : log(message_handler)
26  {
27  }
28 
29  virtual ~propt() { }
30 
31  // boolean operators
32  virtual literalt land(literalt a, literalt b)=0;
33  virtual literalt lor(literalt a, literalt b)=0;
34  virtual literalt land(const bvt &bv)=0;
35  virtual literalt lor(const bvt &bv)=0;
36  virtual literalt lxor(literalt a, literalt b)=0;
37  virtual literalt lxor(const bvt &bv)=0;
38  virtual literalt lnand(literalt a, literalt b)=0;
39  virtual literalt lnor(literalt a, literalt b)=0;
40  virtual literalt lequal(literalt a, literalt b)=0;
41  virtual literalt limplies(literalt a, literalt b)=0;
42  virtual literalt lselect(literalt a, literalt b, literalt c)=0; // a?b:c
43  virtual void set_equal(literalt a, literalt b);
44 
45  virtual void l_set_to(literalt a, bool value)
46  {
47  set_equal(a, const_literal(value));
48  }
49 
51  { l_set_to(a, true); }
53  { l_set_to(a, false); }
54 
55  // constraints
56  void lcnf(literalt l0, literalt l1)
57  { lcnf_bv.resize(2); lcnf_bv[0]=l0; lcnf_bv[1]=l1; lcnf(lcnf_bv); }
58 
59  void lcnf(literalt l0, literalt l1, literalt l2)
60  {
61  lcnf_bv.resize(3);
62  lcnf_bv[0]=l0;
63  lcnf_bv[1]=l1;
64  lcnf_bv[2]=l2;
65  lcnf(lcnf_bv);
66  }
67 
68  void lcnf(literalt l0, literalt l1, literalt l2, literalt l3)
69  {
70  lcnf_bv.resize(4);
71  lcnf_bv[0]=l0;
72  lcnf_bv[1]=l1;
73  lcnf_bv[2]=l2;
74  lcnf_bv[3]=l3;
75  lcnf(lcnf_bv);
76  }
77 
78  virtual void lcnf(const bvt &bv)=0;
79  virtual bool has_set_to() const { return true; }
80 
81  // Some solvers (notably aig) prefer encodings that avoid raw CNF
82  // They overload this to return false and thus avoid some optimisations
83  virtual bool cnf_handled_well() const { return true; }
84 
85  // assumptions
86  virtual void set_assumptions(const bvt &) { }
87  virtual bool has_set_assumptions() const { return false; }
88 
89  // variables
90  virtual literalt new_variable()=0;
91  virtual void set_variable_name(literalt, const irep_idt &) { }
92  virtual size_t no_variables() const=0;
93  virtual bvt new_variables(std::size_t width);
94 
95  // solving
96  virtual const std::string solver_text()=0;
99 
100  // satisfying assignment
101  virtual tvt l_get(literalt a) const=0;
102  virtual void set_assignment(literalt a, bool value) = 0;
103 
108  virtual bool is_in_conflict(literalt l) const = 0;
109  virtual bool has_is_in_conflict() const { return false; }
110 
111  // an incremental solver may remove any variables that aren't frozen
112  virtual void set_frozen(literalt) { }
113 
114  // Resource limits:
115  virtual void set_time_limit_seconds(uint32_t)
116  {
117  log.warning() << "CPU limit ignored (not implemented)" << messaget::eom;
118  }
119 
120  std::size_t get_number_of_solver_calls() const;
121 
122 protected:
123  virtual resultt do_prop_solve() = 0;
124 
125  // to avoid a temporary for lcnf(...)
127 
129  std::size_t number_of_solver_calls = 0;
130 };
131 
132 #endif // CPROVER_SOLVERS_PROP_PROP_H
messaget
Class that provides messages with a built-in verbosity 'level'.
Definition: message.h:154
dstringt
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Definition: dstring.h:36
propt::has_is_in_conflict
virtual bool has_is_in_conflict() const
Definition: prop.h:109
propt::set_assumptions
virtual void set_assumptions(const bvt &)
Definition: prop.h:86
propt::solver_text
virtual const std::string solver_text()=0
resultt
resultt
The result of goto verifying.
Definition: properties.h:44
propt::new_variables
virtual bvt new_variables(std::size_t width)
generates a bitvector of given width with new variables
Definition: prop.cpp:20
bvt
std::vector< literalt > bvt
Definition: literal.h:201
threeval.h
propt::resultt::P_UNSATISFIABLE
@ P_UNSATISFIABLE
propt::set_equal
virtual void set_equal(literalt a, literalt b)
asserts a==b in the propositional formula
Definition: prop.cpp:12
propt::lcnf
void lcnf(literalt l0, literalt l1, literalt l2)
Definition: prop.h:59
propt::set_time_limit_seconds
virtual void set_time_limit_seconds(uint32_t)
Definition: prop.h:115
propt::new_variable
virtual literalt new_variable()=0
propt::lor
virtual literalt lor(literalt a, literalt b)=0
propt::l_set_to_true
void l_set_to_true(literalt a)
Definition: prop.h:50
propt::l_set_to
virtual void l_set_to(literalt a, bool value)
Definition: prop.h:45
messaget::eom
static eomt eom
Definition: message.h:297
propt::no_variables
virtual size_t no_variables() const =0
propt::do_prop_solve
virtual resultt do_prop_solve()=0
propt::has_set_assumptions
virtual bool has_set_assumptions() const
Definition: prop.h:87
propt::land
virtual literalt land(literalt a, literalt b)=0
propt::number_of_solver_calls
std::size_t number_of_solver_calls
Definition: prop.h:129
propt::lcnf
void lcnf(literalt l0, literalt l1, literalt l2, literalt l3)
Definition: prop.h:68
propt::lxor
virtual literalt lxor(literalt a, literalt b)=0
propt::prop_solve
resultt prop_solve()
Definition: prop.cpp:29
propt::limplies
virtual literalt limplies(literalt a, literalt b)=0
propt::propt
propt(message_handlert &message_handler)
Definition: prop.h:25
propt::set_assignment
virtual void set_assignment(literalt a, bool value)=0
propt::lnand
virtual literalt lnand(literalt a, literalt b)=0
propt::resultt::P_ERROR
@ P_ERROR
propt::resultt::P_SATISFIABLE
@ P_SATISFIABLE
propt::cnf_handled_well
virtual bool cnf_handled_well() const
Definition: prop.h:83
const_literal
literalt const_literal(bool value)
Definition: literal.h:188
message_handlert
Definition: message.h:27
propt::set_frozen
virtual void set_frozen(literalt)
Definition: prop.h:112
propt::resultt
resultt
Definition: prop.h:97
propt::get_number_of_solver_calls
std::size_t get_number_of_solver_calls() const
Definition: prop.cpp:35
propt::is_in_conflict
virtual bool is_in_conflict(literalt l) const =0
Returns true if an assumption is in the final conflict.
tvt
Definition: threeval.h:19
literal.h
propt::set_variable_name
virtual void set_variable_name(literalt, const irep_idt &)
Definition: prop.h:91
propt::l_set_to_false
void l_set_to_false(literalt a)
Definition: prop.h:52
propt::lequal
virtual literalt lequal(literalt a, literalt b)=0
propt
TO_BE_DOCUMENTED.
Definition: prop.h:22
propt::~propt
virtual ~propt()
Definition: prop.h:29
propt::l_get
virtual tvt l_get(literalt a) const =0
literalt
Definition: literal.h:25
propt::has_set_to
virtual bool has_set_to() const
Definition: prop.h:79
propt::lcnf_bv
bvt lcnf_bv
Definition: prop.h:126
propt::log
messaget log
Definition: prop.h:128
message.h
messaget::warning
mstreamt & warning() const
Definition: message.h:404
propt::lselect
virtual literalt lselect(literalt a, literalt b, literalt c)=0
propt::lcnf
void lcnf(literalt l0, literalt l1)
Definition: prop.h:56
propt::lnor
virtual literalt lnor(literalt a, literalt b)=0