11#include "dlinear/util/logging.h"
15Nnfizer::Nnfizer(
const dlinear::Config &config) : FormulaVisitor<bool, bool>{config,
"Nnfizer"} {}
17Formula Nnfizer::Process(
const Formula &f,
bool push_negation_into_relationals)
const {
18 DLINEAR_TRACE_FMT(
"Nnfizer::Convert({}, {})", f, push_negation_into_relationals);
19 const TimerGuard timer_guard{&stats_.m_timer(), stats_.enabled()};
21 return VisitFormula(f,
true, push_negation_into_relationals);
23Formula Nnfizer::operator()(
const Formula &f,
const bool push_negation_into_relationals)
const {
24 return Process(f, push_negation_into_relationals);
27Formula Nnfizer::VisitFalse(
const Formula &,
const bool polarity,
const bool)
const {
30 return polarity ? Formula::False() : Formula::True();
33Formula Nnfizer::VisitTrue(
const Formula &,
const bool polarity,
const bool)
const {
36 return polarity ? Formula::True() :
Formula::False();
39Formula Nnfizer::VisitVariable(
const Formula &f,
const bool polarity,
const bool)
const {
42 return polarity ? f : !f;
45Formula Nnfizer::VisitEqualTo(
const Formula &f,
const bool polarity,
const bool push_negation_into_relationals)
const {
46 if (polarity)
return f;
48 return push_negation_into_relationals ? get_lhs_expression(f) != get_rhs_expression(f) : !f;
51Formula Nnfizer::VisitNotEqualTo(
const Formula &f,
const bool polarity,
52 const bool push_negation_into_relationals)
const {
53 if (polarity)
return f;
55 return push_negation_into_relationals ? get_lhs_expression(f) == get_rhs_expression(f) : !f;
58Formula Nnfizer::VisitGreaterThan(
const Formula &f,
const bool polarity,
59 const bool push_negation_into_relationals)
const {
60 if (polarity)
return f;
62 return push_negation_into_relationals ? get_lhs_expression(f) <= get_rhs_expression(f) : !f;
65Formula Nnfizer::VisitGreaterThanOrEqualTo(
const Formula &f,
const bool polarity,
66 const bool push_negation_into_relationals)
const {
67 if (polarity)
return f;
69 return push_negation_into_relationals ? get_lhs_expression(f) < get_rhs_expression(f) : !f;
72Formula Nnfizer::VisitLessThan(
const Formula &f,
const bool polarity,
const bool push_negation_into_relationals)
const {
73 if (polarity)
return f;
75 return push_negation_into_relationals ? get_lhs_expression(f) >= get_rhs_expression(f) : !f;
78Formula Nnfizer::VisitLessThanOrEqualTo(
const Formula &f,
const bool polarity,
79 const bool push_negation_into_relationals)
const {
80 if (polarity)
return f;
82 return push_negation_into_relationals ? get_lhs_expression(f) > get_rhs_expression(f) : !f;
85Formula Nnfizer::VisitConjunction(
const Formula &f,
const bool polarity,
86 const bool push_negation_into_relationals)
const {
89 const std::set<Formula> new_operands{
90 map(get_operands(f), [
this, polarity, push_negation_into_relationals](
const Formula &formula) {
91 return this->VisitFormula(formula, polarity, push_negation_into_relationals);
96Formula Nnfizer::VisitDisjunction(
const Formula &f,
const bool polarity,
97 const bool push_negation_into_relationals)
const {
100 const std::set<Formula> new_operands{
101 map(get_operands(f), [
this, polarity, push_negation_into_relationals](
const Formula &formula) {
102 return this->VisitFormula(formula, polarity, push_negation_into_relationals);
107Formula Nnfizer::VisitNegation(
const Formula &f,
const bool polarity,
const bool push_negation_into_relationals)
const {
110 return VisitFormula(get_operand(f), !polarity, push_negation_into_relationals);
113Formula Nnfizer::VisitForall(
const Formula &f,
const bool polarity,
const bool)
const {
120 return polarity ? f : !f;
Simple dataclass used to store the configuration of the program.
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...
Formula make_disjunction(const std::vector< Formula > &formulas)
Make disjunction of formulas.