46 #include <spot/misc/common.hh> 49 #include <initializer_list> 64 enum class op: uint8_t
104 class SPOT_API fnode final
121 if (SPOT_UNLIKELY(!refs_))
133 if (SPOT_LIKELY(refs_))
135 else if (SPOT_LIKELY(id_ > 2) && SPOT_LIKELY(!saturated_))
147 static const fnode*
ap(
const std::string& name);
149 static const fnode* unop(
op o,
const fnode* f);
151 static const fnode* binop(
op o,
const fnode* f,
const fnode* g);
153 static const fnode* multop(
op o, std::vector<const fnode*> l);
155 static const fnode* bunop(
op o,
const fnode* f,
156 uint8_t min, uint8_t max = unbounded());
159 static const fnode* nested_unop_range(
op uo,
op bo,
unsigned min,
160 unsigned max,
const fnode* f);
169 std::string kindstr()
const;
180 return op_ == o1 || op_ == o2;
184 bool is(std::initializer_list<op> l)
const 186 const fnode* n =
this;
201 if (SPOT_UNLIKELY(size_ != 1))
202 report_get_child_of_expecting_single_child_node();
223 report_min_invalid_arg();
231 report_max_invalid_arg();
260 const fnode*
const*
end()
const 262 return children + size();
266 const fnode*
nth(
unsigned i)
const 268 if (SPOT_UNLIKELY(i >= size()))
269 report_non_existing_child();
274 static const fnode*
ff()
286 static const fnode*
tt()
320 return min_ == 0 && max_ == unbounded();
332 const std::string& ap_name()
const;
335 std::ostream& dump(std::ostream& os)
const;
338 const fnode* all_but(
unsigned i)
const;
345 while (pos < s && children[pos]->is_boolean())
351 const fnode* boolean_operands(
unsigned* width =
nullptr)
const;
363 static bool instances_check();
378 return is_.sugar_free_boolean;
384 return is_.in_nenoform;
390 return is_.syntactic_si;
396 return is_.sugar_free_ltl;
402 return is_.ltl_formula;
408 return is_.psl_formula;
414 return is_.sere_formula;
432 return is_.universal;
438 return is_.syntactic_safety;
444 return is_.syntactic_guarantee;
450 return is_.syntactic_obligation;
456 return is_.syntactic_recurrence;
462 return is_.syntactic_persistence;
468 return !is_.not_marked;
474 return is_.accepting_eword;
480 return is_.lbt_atomic_props;
486 return is_.spin_atomic_props;
490 void setup_props(
op o);
491 void destroy_aux()
const;
493 [[noreturn]]
static void report_non_existing_child();
494 [[noreturn]]
static void report_too_many_children();
495 [[noreturn]]
static void 496 report_get_child_of_expecting_single_child_node();
497 [[noreturn]]
static void report_min_invalid_arg();
498 [[noreturn]]
static void report_max_invalid_arg();
500 static const fnode* unique(fnode*);
505 fnode(
const fnode&) =
delete;
506 fnode& operator=(
const fnode&) =
delete;
511 fnode(
op o, iter begin, iter end)
528 size_t s = std::distance(begin, end);
529 if (SPOT_UNLIKELY(s > (
size_t) UINT16_MAX))
530 report_too_many_children();
533 for (
auto i = begin; i != end; ++i)
538 fnode(
op o, std::initializer_list<const fnode*> l)
539 : fnode(o, l.begin(), l.end())
543 fnode(
op o,
const fnode* f, uint8_t min, uint8_t max)
544 : op_(o), min_(min), max_(max), saturated_(0), size_(1)
550 static const fnode* ff_;
551 static const fnode* tt_;
552 static const fnode* ew_;
553 static const fnode* one_star_;
558 mutable uint8_t saturated_;
560 mutable uint16_t refs_ = 0;
562 static size_t next_id_;
580 bool sugar_free_boolean:1;
583 bool sugar_free_ltl:1;
590 bool syntactic_safety:1;
591 bool syntactic_guarantee:1;
592 bool syntactic_obligation:1;
593 bool syntactic_recurrence:1;
594 bool syntactic_persistence:1;
596 bool accepting_eword:1;
597 bool lbt_atomic_props:1;
598 bool spin_atomic_props:1;
607 const fnode* children[1];
617 operator()(
const fnode* left,
const fnode* right)
const 637 auto get_literal = [](
const fnode* f) ->
const fnode*
646 const fnode* litl = get_literal(left);
647 const fnode* litr = get_literal(right);
653 int cmp = atomic_prop_cmp(litl, litr);
660 size_t l = left->
id();
661 size_t r = right->
id();
674 std::ostringstream old;
676 std::ostringstream ord;
678 return old.str() < ord.str();
761 std::swap(f.ptr_, ptr_);
765 bool operator<(
const formula& other)
const noexcept
767 if (SPOT_UNLIKELY(!other.ptr_))
769 if (SPOT_UNLIKELY(!ptr_))
771 if (
id() < other.
id())
773 if (
id() > other.
id())
779 return ptr_ < other.ptr_;
782 bool operator<=(
const formula& other)
const noexcept
784 return *
this == other || *
this < other;
787 bool operator>(
const formula& other)
const noexcept
789 return !(*
this <= other);
792 bool operator>=(
const formula& other)
const noexcept
794 return !(*
this < other);
797 bool operator==(
const formula& other)
const noexcept
799 return other.ptr_ == ptr_;
802 bool operator==(std::nullptr_t)
const noexcept
804 return ptr_ ==
nullptr;
807 bool operator!=(
const formula& other)
const noexcept
809 return other.ptr_ != ptr_;
812 bool operator!=(std::nullptr_t)
const noexcept
814 return ptr_ !=
nullptr;
817 operator bool()
const 819 return ptr_ !=
nullptr;
846 report_ap_invalid_arg();
868 #define SPOT_DEF_UNOP(Name) \ 869 static formula Name(const formula& f) \ 871 return unop(op::Name, f); \ 874 #define SPOT_DEF_UNOP(Name) \ 875 static formula Name(const formula& f) \ 877 return unop(op::Name, f); \ 879 static formula Name(formula&& f) \ 881 return unop(op::Name, std::move(f)); \ 899 return nested_unop_range(
op::X,
op::Or , level, level, f);
915 return nested_unop_range(
op::X,
op::Or, min_level, max_level, f);
926 return nested_unop_range(
op::X,
op::And, min_level, max_level, f);
985 #define SPOT_DEF_BINOP(Name) \ 986 static formula Name(const formula& f, const formula& g) \ 988 return binop(op::Name, f, g); \ 991 #define SPOT_DEF_BINOP(Name) \ 992 static formula Name(const formula& f, const formula& g) \ 994 return binop(op::Name, f, g); \ 996 static formula Name(const formula& f, formula&& g) \ 998 return binop(op::Name, f, std::move(g)); \ 1000 static formula Name(formula&& f, const formula& g) \ 1002 return binop(op::Name, std::move(f), g); \ 1004 static formula Name(formula&& f, formula&& g) \ 1006 return binop(op::Name, std::move(f), std::move(g)); \ 1009 SPOT_DEF_BINOP(
Xor);
1058 #undef SPOT_DEF_BINOP 1067 std::vector<const fnode*> tmp;
1068 tmp.reserve(l.size());
1071 tmp.emplace_back(f.ptr_->
clone());
1078 std::vector<const fnode*> tmp;
1079 tmp.reserve(l.size());
1089 #define SPOT_DEF_MULTOP(Name) \ 1090 static formula Name(const std::vector<formula>& l) \ 1092 return multop(op::Name, l); \ 1095 #define SPOT_DEF_MULTOP(Name) \ 1096 static formula Name(const std::vector<formula>& l) \ 1098 return multop(op::Name, l); \ 1101 static formula Name(std::vector<formula>&& l) \ 1103 return multop(op::Name, std::move(l)); \ 1106 SPOT_DEF_MULTOP(
Or);
1140 #undef SPOT_DEF_MULTOP 1148 uint8_t max = unbounded())
1156 uint8_t max = unbounded())
1164 #define SPOT_DEF_BUNOP(Name) \ 1165 static formula Name(const formula& f, \ 1167 uint8_t max = unbounded()) \ 1169 return bunop(op::Name, f, min, max); \ 1172 #define SPOT_DEF_BUNOP(Name) \ 1173 static formula Name(const formula& f, \ 1175 uint8_t max = unbounded()) \ 1177 return bunop(op::Name, f, min, max); \ 1179 static formula Name(formula&& f, \ 1181 uint8_t max = unbounded()) \ 1183 return bunop(op::Name, std::move(f), min, max); \ 1186 SPOT_DEF_BUNOP(
Star);
1198 #undef SPOT_DEF_BUNOP 1223 static formula sugar_goto(
const formula& b, uint8_t min, uint8_t max);
1230 static formula sugar_equal(
const formula& b, uint8_t min, uint8_t max);
1254 unsigned min,
unsigned max);
1256 unsigned min,
unsigned max);
1260 const fnode* to_node_()
1280 return ptr_->kind();
1286 return ptr_->kindstr();
1296 bool is(
op o1,
op o2)
const 1299 return ptr_->is(o1, o2);
1303 bool is(std::initializer_list<op> l)
const 1321 formula get_child_of(std::initializer_list<op> l)
const 1355 return ptr_->size();
1364 return ptr_->is_leaf();
1381 class SPOT_API formula_child_iterator final
1384 const fnode*
const* ptr_;
1386 formula_child_iterator()
1391 formula_child_iterator(
const fnode*
const* f)
1396 bool operator==(formula_child_iterator o)
1398 return ptr_ == o.ptr_;
1401 bool operator!=(formula_child_iterator o)
1403 return ptr_ != o.ptr_;
1408 return formula((*ptr_)->clone());
1411 formula_child_iterator operator++()
1417 formula_child_iterator operator++(
int)
1428 return ptr_->begin();
1432 formula_child_iterator
end()
const 1440 return formula(ptr_->nth(i)->clone());
1453 return ptr_->is_ff();
1465 return ptr_->is_tt();
1477 return ptr_->is_eword();
1483 return ptr_->is_constant();
1492 return ptr_->is_Kleene_star();
1509 (is(
op::Not) && is_boolean() && is_in_nenoform()));
1517 return ptr_->ap_name();
1524 std::ostream&
dump(std::ostream& os)
const 1526 return ptr_->dump(os);
1536 return formula(ptr_->all_but(i));
1550 return ptr_->boolean_count();
1568 return formula(ptr_->boolean_operands(width));
1571 #define SPOT_DEF_PROP(Name) \ 1574 return ptr_->Name(); \ 1581 SPOT_DEF_PROP(is_boolean);
1583 SPOT_DEF_PROP(is_sugar_free_boolean);
1588 SPOT_DEF_PROP(is_in_nenoform);
1590 SPOT_DEF_PROP(is_syntactic_stutter_invariant);
1592 SPOT_DEF_PROP(is_sugar_free_ltl);
1594 SPOT_DEF_PROP(is_ltl_formula);
1596 SPOT_DEF_PROP(is_psl_formula);
1598 SPOT_DEF_PROP(is_sere_formula);
1601 SPOT_DEF_PROP(is_finite);
1609 SPOT_DEF_PROP(is_eventual);
1619 SPOT_DEF_PROP(is_syntactic_safety);
1621 SPOT_DEF_PROP(is_syntactic_guarantee);
1623 SPOT_DEF_PROP(is_syntactic_obligation);
1625 SPOT_DEF_PROP(is_syntactic_recurrence);
1627 SPOT_DEF_PROP(is_syntactic_persistence);
1630 SPOT_DEF_PROP(is_marked);
1632 SPOT_DEF_PROP(accepts_eword);
1638 SPOT_DEF_PROP(has_lbt_atomic_props);
1647 SPOT_DEF_PROP(has_spin_atomic_props);
1648 #undef SPOT_DEF_PROP 1653 template<
typename Trans,
typename... Args>
1656 switch (
op o = kind())
1671 return unop(o, trans((*
this)[0], std::forward<Args>(args)...));
1683 formula tmp = trans((*
this)[0], std::forward<Args>(args)...);
1684 return binop(o, tmp,
1685 trans((*
this)[1], std::forward<Args>(args)...));
1695 std::vector<formula> tmp;
1696 tmp.reserve(size());
1698 tmp.emplace_back(trans(f, std::forward<Args>(args)...));
1699 return multop(o, std::move(tmp));
1703 return bunop(o, trans((*
this)[0], std::forward<Args>(args)...),
1717 template<
typename Func,
typename... Args>
1720 if (func(*
this, std::forward<Args>(args)...))
1723 f.
traverse(func, std::forward<Args>(args)...);
1728 [[noreturn]]
static void report_ap_invalid_arg();
1735 bool abbreviated =
false);
1743 std::ostream& operator<<(std::ostream& os,
const formula& f);
const fnode *const * begin() const
Definition: formula.hh:254
Definition: automata.hh:26
bool is_boolean() const
Definition: formula.hh:370
static const fnode * eword()
Definition: formula.hh:298
static const fnode * ap(const std::string &name)
std::ostream & dump(std::ostream &os) const
unsigned max() const
Definition: formula.hh:228
size_t id() const
Definition: formula.hh:248
bool is(op o) const
Definition: formula.hh:172
bool is_psl_formula() const
Definition: formula.hh:406
static const fnode * unop(op o, const fnode *f)
bool is_leaf() const
Definition: formula.hh:242
bool is_finite() const
Definition: formula.hh:418
bool is_eword() const
Definition: formula.hh:304
unsigned boolean_count() const
Definition: formula.hh:341
const fnode * get_child_of(op o) const
Definition: formula.hh:197
Definition: bitset.hh:405
bool is_syntactic_guarantee() const
Definition: formula.hh:442
static const fnode * tt()
Definition: formula.hh:286
bool is_syntactic_persistence() const
Definition: formula.hh:460
const fnode * nth(unsigned i) const
Definition: formula.hh:266
bool is_marked() const
Definition: formula.hh:466
bool is_syntactic_recurrence() const
Definition: formula.hh:454
bool is(std::initializer_list< op > l) const
Definition: formula.hh:184
bool is_syntactic_obligation() const
Definition: formula.hh:448
bool is(op o1, op o2) const
Definition: formula.hh:178
bool has_spin_atomic_props() const
Definition: formula.hh:484
bool is_constant() const
Definition: formula.hh:310
bool is_syntactic_stutter_invariant() const
Definition: formula.hh:388
void destroy() const
Dereference an fnode.
Definition: formula.hh:131
static const fnode * bunop(op o, const fnode *f, uint8_t min, uint8_t max=unbounded())
Non-Length-Matching Rational-And.
static const fnode * ff()
Definition: formula.hh:274
static const fnode * one_star()
Definition: formula.hh:324
bool is_syntactic_safety() const
Definition: formula.hh:436
marked version of the Negated PSL Closure
bool is_sugar_free_boolean() const
Definition: formula.hh:376
bool is_ltl_formula() const
Definition: formula.hh:400
bool is_in_nenoform() const
Definition: formula.hh:382
bool is_ff() const
Definition: formula.hh:280
const fnode * get_child_of(std::initializer_list< op > l) const
Definition: formula.hh:207
static constexpr uint8_t unbounded()
Definition: formula.hh:141
unsigned size() const
Definition: formula.hh:236
const fnode * clone() const
Clone an fnode.
Definition: formula.hh:117
bool has_lbt_atomic_props() const
Definition: formula.hh:478
bool is_sugar_free_ltl() const
Definition: formula.hh:394
static const fnode * binop(op o, const fnode *f, const fnode *g)
bool is_sere_formula() const
Definition: formula.hh:412
op
Operator types.
Definition: formula.hh:64
bool is_tt() const
Definition: formula.hh:292
const fnode *const * end() const
Definition: formula.hh:260
bool is_universal(const const_twa_graph_ptr &aut)
Return true iff aut is universal.
op kind() const
Definition: formula.hh:163
static const fnode * nested_unop_range(op uo, op bo, unsigned min, unsigned max, const fnode *f)
bool is_eventual() const
Definition: formula.hh:424
unsigned min() const
Definition: formula.hh:220
bool is_universal() const
Definition: formula.hh:430
strong release (dual of weak until)
bool accepts_eword() const
Definition: formula.hh:472
static const fnode * multop(op o, std::vector< const fnode *> l)
bool is_Kleene_star() const
Definition: formula.hh:316