7#include "NaiveCnfizer.h"
12#include "dlinear/util/exception.h"
28Formula NaiveCnfizer::VisitEqualTo(
const Formula &f)
const {
29 const Expression &lhs{get_lhs_expression(f)};
30 const Expression &rhs{get_rhs_expression(f)};
31 return (lhs >= rhs) && (lhs <= rhs);
33Formula NaiveCnfizer::VisitNotEqualTo(
const Formula &f)
const {
34 const Expression &lhs{get_lhs_expression(f)};
35 const Expression &rhs{get_rhs_expression(f)};
36 return (lhs > rhs) || (lhs < rhs);
38Formula NaiveCnfizer::VisitForall(
const Formula &f)
const {
40 const Variables &quantified_variables{get_quantified_variables(f)};
41 const Formula &quantified_formula{get_quantified_formula(f)};
42 return forall(quantified_variables,
Process(quantified_formula));
45Formula NaiveCnfizer::VisitConjunction(
const Formula &f)
const {
46 const std::set<Formula> transformed_operands{
47 map(get_operands(f), [
this](
const Formula &formula) {
return this->VisitFormula(formula); })};
51Formula NaiveCnfizer::VisitDisjunction(
const Formula &f)
const {
52 const std::set<Formula> &transformed_operands{
53 map(get_operands(f), [
this](
const Formula &formula) {
return this->VisitFormula(formula); })};
54 return std::accumulate(transformed_operands.begin(), transformed_operands.end(), Formula::False(),
55 [](
const Formula &cnf1,
const Formula &cnf2) {
56 std::set<Formula> clauses;
57 if (is_conjunction(cnf1)) {
58 if (is_conjunction(cnf2)) {
60 for (const Formula &c1 : get_operands(cnf1)) {
61 for (const Formula &c2 : get_operands(cnf2)) {
62 clauses.insert(c1 || c2);
67 for (const Formula &c1 : get_operands(cnf1)) {
68 clauses.insert(c1 || cnf2);
72 if (is_conjunction(cnf2)) {
74 for (const Formula &c2 : get_operands(cnf2)) {
75 clauses.insert(cnf1 || c2);
79 clauses.insert(cnf1 || cnf2);
86Formula NaiveCnfizer::VisitNegation(
const Formula &f)
const {
87 DLINEAR_ASSERT(
is_atomic(get_operand(f)),
"The formula must be atomic");
void Increase()
Increase the iteration counter by one.
Formula Process(const Formula &f) const
Convert a f into an equivalent formula f' in CNF.
Nnfizer nnfizer_
NNFizer. Used to convert the formula into NNF.
Formula Process(const Formula &f, bool push_negation_into_relationals=false) const
Convert a f into an equivalent formula f' in NNF.
Timer & m_timer()
Get read-write access to the timer of the stats.
bool enabled() const
Check whether the stats is enabled.
The TimeGuard wraps a timer object and pauses it when the guard object is destructed.
Global namespace for the dlinear library.
Formula make_conjunction(const std::vector< Formula > &formulas)
Make conjunction of formulas.
std::set< Formula > map(const std::set< Formula > &formulas, const std::function< Formula(const Formula &)> &func)
Given formulas = {f₁, ..., fₙ} and a func : Formula → Formula, map(formulas, func) returns a set {fun...
bool is_atomic(const Formula &f)
Check if f is atomic.