dReal4
tseitin_cnfizer.h
1 #pragma once
2 
3 #include <map>
4 #include <unordered_map>
5 #include <vector>
6 
8 #include "dreal/util/naive_cnfizer.h"
9 
10 namespace dreal {
11 /// Transforms a symbolic formula @p f into an equi-satisfiable CNF
12 /// formula by introducing extra Boolean variables (Tseitin transformation).
14  public:
15  /// Convert @p f into an equi-satisfiable formula @c f' in CNF.
16  std::vector<Formula> Convert(const Formula& f);
17 
18  /// Returns a const reference of `map_` member.
19  ///
20  /// @note that this member `map_` is cleared at the beginning of `Convert`
21  /// method.
22  const std::map<Variable, Formula>& map() const { return map_; }
23 
24  private:
25  Formula Visit(const Formula& f);
26  Formula VisitFalse(const Formula& f);
27  Formula VisitTrue(const Formula& f);
28  Formula VisitVariable(const Formula& f);
29  Formula VisitEqualTo(const Formula& f);
30  Formula VisitNotEqualTo(const Formula& f);
31  Formula VisitGreaterThan(const Formula& f);
32  Formula VisitGreaterThanOrEqualTo(const Formula& f);
33  Formula VisitLessThan(const Formula& f);
34  Formula VisitLessThanOrEqualTo(const Formula& f);
35  Formula VisitConjunction(const Formula& f);
36  Formula VisitDisjunction(const Formula& f);
37  Formula VisitNegation(const Formula& f);
38  Formula VisitForall(const Formula& f);
39 
40  // Maps a temporary variable, which is introduced by a Tseitin
41  // transformation, to a corresponding Formula.
42  //
43  // @note that this map_ is cleared at the beginning of `Convert`
44  // call.
45  std::map<Variable, Formula> map_;
46 
47  // To transform nested formulas inside of universal quantifications.
48  const NaiveCnfizer naive_cnfizer_{};
49 
50  // Makes VisitFormula a friend of this class so that it can use private
51  // operator()s.
52  friend Formula drake::symbolic::VisitFormula<Formula, TseitinCnfizer>(
53  TseitinCnfizer*, const Formula&);
54 };
55 } // namespace dreal
Sum type of symbolic::Expression and symbolic::Formula.
Definition: api.cc:9
Transforms a symbolic formula f into a CNF formula by preserving its semantics.
Definition: naive_cnfizer.h:13
std::vector< Formula > Convert(const Formula &f)
Convert f into an equi-satisfiable formula f&#39; in CNF.
Definition: tseitin_cnfizer.cc:68
Transforms a symbolic formula f into an equi-satisfiable CNF formula by introducing extra Boolean var...
Definition: tseitin_cnfizer.h:13
const std::map< Variable, Formula > & map() const
Returns a const reference of map_ member.
Definition: tseitin_cnfizer.h:22
This is the header file that we consolidate Drake&#39;s symbolic classes and expose them inside of dreal ...
Represents a symbolic form of a first-order logic formula.
Definition: symbolic_formula.h:101