46 #include <spot/misc/common.hh> 49 #include <initializer_list> 64 enum class op: uint8_t
103 class SPOT_API fnode final
120 if (SPOT_UNLIKELY(!refs_))
132 if (SPOT_LIKELY(refs_))
134 else if (SPOT_LIKELY(id_ > 2) && SPOT_LIKELY(!saturated_))
146 static const fnode*
ap(
const std::string& name);
148 static const fnode* unop(
op o,
const fnode* f);
150 static const fnode* binop(
op o,
const fnode* f,
const fnode* g);
152 static const fnode* multop(
op o, std::vector<const fnode*> l);
154 static const fnode* bunop(
op o,
const fnode* f,
155 uint8_t min, uint8_t max = unbounded());
158 static const fnode* nested_unop_range(
op uo,
op bo,
unsigned min,
159 unsigned max,
const fnode* f);
168 std::string kindstr()
const;
179 return op_ == o1 || op_ == o2;
183 bool is(std::initializer_list<op> l)
const 185 const fnode* n =
this;
200 if (SPOT_UNLIKELY(size_ != 1))
201 report_get_child_of_expecting_single_child_node();
222 report_min_invalid_arg();
230 report_max_invalid_arg();
259 const fnode*
const*
end()
const 261 return children + size();
265 const fnode*
nth(
unsigned i)
const 267 if (SPOT_UNLIKELY(i >= size()))
268 report_non_existing_child();
273 static const fnode*
ff()
285 static const fnode*
tt()
319 return min_ == 0 && max_ == unbounded();
331 const std::string& ap_name()
const;
334 std::ostream& dump(std::ostream& os)
const;
337 const fnode* all_but(
unsigned i)
const;
344 while (pos < s && children[pos]->is_boolean())
350 const fnode* boolean_operands(
unsigned* width =
nullptr)
const;
362 static bool instances_check();
377 return is_.sugar_free_boolean;
383 return is_.in_nenoform;
389 return is_.syntactic_si;
395 return is_.sugar_free_ltl;
401 return is_.ltl_formula;
407 return is_.psl_formula;
413 return is_.sere_formula;
431 return is_.universal;
437 return is_.syntactic_safety;
443 return is_.syntactic_guarantee;
449 return is_.syntactic_obligation;
455 return is_.syntactic_recurrence;
461 return is_.syntactic_persistence;
467 return !is_.not_marked;
473 return is_.accepting_eword;
479 return is_.lbt_atomic_props;
485 return is_.spin_atomic_props;
489 void setup_props(
op o);
490 void destroy_aux()
const;
492 [[noreturn]]
static void report_non_existing_child();
493 [[noreturn]]
static void report_too_many_children();
494 [[noreturn]]
static void 495 report_get_child_of_expecting_single_child_node();
496 [[noreturn]]
static void report_min_invalid_arg();
497 [[noreturn]]
static void report_max_invalid_arg();
499 static const fnode* unique(fnode*);
504 fnode(
const fnode&) =
delete;
505 fnode& operator=(
const fnode&) =
delete;
510 fnode(
op o, iter begin, iter end)
527 size_t s = std::distance(begin, end);
528 if (SPOT_UNLIKELY(s > (
size_t) UINT16_MAX))
529 report_too_many_children();
532 for (
auto i = begin; i != end; ++i)
537 fnode(
op o, std::initializer_list<const fnode*> l)
538 : fnode(o, l.begin(), l.end())
542 fnode(
op o,
const fnode* f, uint8_t min, uint8_t max)
543 : op_(o), min_(min), max_(max), saturated_(0), size_(1)
549 static const fnode* ff_;
550 static const fnode* tt_;
551 static const fnode* ew_;
552 static const fnode* one_star_;
557 mutable uint8_t saturated_;
559 mutable uint16_t refs_ = 0;
561 static size_t next_id_;
579 bool sugar_free_boolean:1;
582 bool sugar_free_ltl:1;
589 bool syntactic_safety:1;
590 bool syntactic_guarantee:1;
591 bool syntactic_obligation:1;
592 bool syntactic_recurrence:1;
593 bool syntactic_persistence:1;
595 bool accepting_eword:1;
596 bool lbt_atomic_props:1;
597 bool spin_atomic_props:1;
606 const fnode* children[1];
616 operator()(
const fnode* left,
const fnode* right)
const 636 auto get_literal = [](
const fnode* f) ->
const fnode*
645 const fnode* litl = get_literal(left);
646 const fnode* litr = get_literal(right);
652 int cmp = atomic_prop_cmp(litl, litr);
659 size_t l = left->
id();
660 size_t r = right->
id();
673 std::ostringstream old;
675 std::ostringstream ord;
677 return old.str() < ord.str();
760 std::swap(f.ptr_, ptr_);
764 bool operator<(
const formula& other)
const noexcept
766 if (SPOT_UNLIKELY(!other.ptr_))
768 if (SPOT_UNLIKELY(!ptr_))
770 if (
id() < other.
id())
772 if (
id() > other.
id())
778 return ptr_ < other.ptr_;
781 bool operator<=(
const formula& other)
const noexcept
783 return *
this == other || *
this < other;
786 bool operator>(
const formula& other)
const noexcept
788 return !(*
this <= other);
791 bool operator>=(
const formula& other)
const noexcept
793 return !(*
this < other);
796 bool operator==(
const formula& other)
const noexcept
798 return other.ptr_ == ptr_;
801 bool operator==(std::nullptr_t)
const noexcept
803 return ptr_ ==
nullptr;
806 bool operator!=(
const formula& other)
const noexcept
808 return other.ptr_ != ptr_;
811 bool operator!=(std::nullptr_t)
const noexcept
813 return ptr_ !=
nullptr;
816 operator bool()
const 818 return ptr_ !=
nullptr;
845 report_ap_invalid_arg();
867 #define SPOT_DEF_UNOP(Name) \ 868 static formula Name(const formula& f) \ 870 return unop(op::Name, f); \ 873 #define SPOT_DEF_UNOP(Name) \ 874 static formula Name(const formula& f) \ 876 return unop(op::Name, f); \ 878 static formula Name(formula&& f) \ 880 return unop(op::Name, std::move(f)); \ 898 return nested_unop_range(
op::X,
op::Or , level, level, f);
913 return nested_unop_range(
op::X,
op::Or, min_level, max_level, f);
923 return nested_unop_range(
op::X,
op::And, min_level, max_level, f);
977 #define SPOT_DEF_BINOP(Name) \ 978 static formula Name(const formula& f, const formula& g) \ 980 return binop(op::Name, f, g); \ 983 #define SPOT_DEF_BINOP(Name) \ 984 static formula Name(const formula& f, const formula& g) \ 986 return binop(op::Name, f, g); \ 988 static formula Name(const formula& f, formula&& g) \ 990 return binop(op::Name, f, std::move(g)); \ 992 static formula Name(formula&& f, const formula& g) \ 994 return binop(op::Name, std::move(f), g); \ 996 static formula Name(formula&& f, formula&& g) \ 998 return binop(op::Name, std::move(f), std::move(g)); \ 1001 SPOT_DEF_BINOP(
Xor);
1050 #undef SPOT_DEF_BINOP 1059 std::vector<const fnode*> tmp;
1060 tmp.reserve(l.size());
1063 tmp.emplace_back(f.ptr_->
clone());
1070 std::vector<const fnode*> tmp;
1071 tmp.reserve(l.size());
1081 #define SPOT_DEF_MULTOP(Name) \ 1082 static formula Name(const std::vector<formula>& l) \ 1084 return multop(op::Name, l); \ 1087 #define SPOT_DEF_MULTOP(Name) \ 1088 static formula Name(const std::vector<formula>& l) \ 1090 return multop(op::Name, l); \ 1093 static formula Name(std::vector<formula>&& l) \ 1095 return multop(op::Name, std::move(l)); \ 1098 SPOT_DEF_MULTOP(
Or);
1132 #undef SPOT_DEF_MULTOP 1140 uint8_t max = unbounded())
1148 uint8_t max = unbounded())
1156 #define SPOT_DEF_BUNOP(Name) \ 1157 static formula Name(const formula& f, \ 1159 uint8_t max = unbounded()) \ 1161 return bunop(op::Name, f, min, max); \ 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); \ 1171 static formula Name(formula&& f, \ 1173 uint8_t max = unbounded()) \ 1175 return bunop(op::Name, std::move(f), min, max); \ 1178 SPOT_DEF_BUNOP(
Star);
1202 SPOT_DEF_BUNOP(
FStar);
1205 #undef SPOT_DEF_BUNOP 1226 static formula sugar_goto(
const formula& b, uint8_t min, uint8_t max);
1233 static formula sugar_equal(
const formula& b, uint8_t min, uint8_t max);
1236 const fnode* to_node_()
1256 return ptr_->kind();
1262 return ptr_->kindstr();
1272 bool is(
op o1,
op o2)
const 1275 return ptr_->is(o1, o2);
1279 bool is(std::initializer_list<op> l)
const 1297 formula get_child_of(std::initializer_list<op> l)
const 1331 return ptr_->size();
1340 return ptr_->is_leaf();
1357 class SPOT_API formula_child_iterator final
1360 const fnode*
const* ptr_;
1362 formula_child_iterator()
1367 formula_child_iterator(
const fnode*
const* f)
1372 bool operator==(formula_child_iterator o)
1374 return ptr_ == o.ptr_;
1377 bool operator!=(formula_child_iterator o)
1379 return ptr_ != o.ptr_;
1384 return formula((*ptr_)->clone());
1387 formula_child_iterator operator++()
1393 formula_child_iterator operator++(
int)
1404 return ptr_->begin();
1408 formula_child_iterator
end()
const 1416 return formula(ptr_->nth(i)->clone());
1429 return ptr_->is_ff();
1441 return ptr_->is_tt();
1453 return ptr_->is_eword();
1459 return ptr_->is_constant();
1468 return ptr_->is_Kleene_star();
1485 (is(
op::Not) && is_boolean() && is_in_nenoform()));
1493 return ptr_->ap_name();
1500 std::ostream&
dump(std::ostream& os)
const 1502 return ptr_->dump(os);
1512 return formula(ptr_->all_but(i));
1526 return ptr_->boolean_count();
1544 return formula(ptr_->boolean_operands(width));
1547 #define SPOT_DEF_PROP(Name) \ 1550 return ptr_->Name(); \ 1557 SPOT_DEF_PROP(is_boolean);
1559 SPOT_DEF_PROP(is_sugar_free_boolean);
1564 SPOT_DEF_PROP(is_in_nenoform);
1566 SPOT_DEF_PROP(is_syntactic_stutter_invariant);
1568 SPOT_DEF_PROP(is_sugar_free_ltl);
1570 SPOT_DEF_PROP(is_ltl_formula);
1572 SPOT_DEF_PROP(is_psl_formula);
1574 SPOT_DEF_PROP(is_sere_formula);
1577 SPOT_DEF_PROP(is_finite);
1595 SPOT_DEF_PROP(is_eventual);
1621 SPOT_DEF_PROP(is_syntactic_safety);
1623 SPOT_DEF_PROP(is_syntactic_guarantee);
1625 SPOT_DEF_PROP(is_syntactic_obligation);
1627 SPOT_DEF_PROP(is_syntactic_recurrence);
1629 SPOT_DEF_PROP(is_syntactic_persistence);
1632 SPOT_DEF_PROP(is_marked);
1634 SPOT_DEF_PROP(accepts_eword);
1640 SPOT_DEF_PROP(has_lbt_atomic_props);
1649 SPOT_DEF_PROP(has_spin_atomic_props);
1650 #undef SPOT_DEF_PROP 1655 template<
typename Trans,
typename... Args>
1658 switch (
op o = kind())
1672 return unop(o, trans((*
this)[0], std::forward<Args>(args)...));
1684 formula tmp = trans((*
this)[0], std::forward<Args>(args)...);
1685 return binop(o, tmp,
1686 trans((*
this)[1], std::forward<Args>(args)...));
1696 std::vector<formula> tmp;
1697 tmp.reserve(size());
1699 tmp.emplace_back(trans(f, std::forward<Args>(args)...));
1700 return multop(o, std::move(tmp));
1704 return bunop(o, trans((*
this)[0], std::forward<Args>(args)...),
1718 template<
typename Func,
typename... Args>
1721 if (func(*
this, std::forward<Args>(args)...))
1724 f.
traverse(func, std::forward<Args>(args)...);
1729 [[noreturn]]
static void report_ap_invalid_arg();
1736 bool abbreviated =
false);
1744 std::ostream& operator<<(std::ostream& os,
const formula& f);
const fnode *const * begin() const
Definition: formula.hh:253
Definition: automata.hh:26
bool is_boolean() const
Definition: formula.hh:369
static const fnode * eword()
Definition: formula.hh:297
static const fnode * ap(const std::string &name)
std::ostream & dump(std::ostream &os) const
unsigned max() const
Definition: formula.hh:227
size_t id() const
Definition: formula.hh:247
bool is(op o) const
Definition: formula.hh:171
bool is_psl_formula() const
Definition: formula.hh:405
static const fnode * unop(op o, const fnode *f)
bool is_leaf() const
Definition: formula.hh:241
bool is_finite() const
Definition: formula.hh:417
bool is_eword() const
Definition: formula.hh:303
unsigned boolean_count() const
Definition: formula.hh:340
const fnode * get_child_of(op o) const
Definition: formula.hh:196
Definition: bitset.hh:405
bool is_syntactic_guarantee() const
Definition: formula.hh:441
static const fnode * tt()
Definition: formula.hh:285
bool is_syntactic_persistence() const
Definition: formula.hh:459
const fnode * nth(unsigned i) const
Definition: formula.hh:265
bool is_marked() const
Definition: formula.hh:465
bool is_syntactic_recurrence() const
Definition: formula.hh:453
bool is(std::initializer_list< op > l) const
Definition: formula.hh:183
bool is_syntactic_obligation() const
Definition: formula.hh:447
bool is(op o1, op o2) const
Definition: formula.hh:177
bool has_spin_atomic_props() const
Definition: formula.hh:483
bool is_constant() const
Definition: formula.hh:309
bool is_syntactic_stutter_invariant() const
Definition: formula.hh:387
void destroy() const
Dereference an fnode.
Definition: formula.hh:130
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:273
static const fnode * one_star()
Definition: formula.hh:323
bool is_syntactic_safety() const
Definition: formula.hh:435
marked version of the Negated PSL Closure
bool is_sugar_free_boolean() const
Definition: formula.hh:375
bool is_ltl_formula() const
Definition: formula.hh:399
bool is_in_nenoform() const
Definition: formula.hh:381
bool is_ff() const
Definition: formula.hh:279
const fnode * get_child_of(std::initializer_list< op > l) const
Definition: formula.hh:206
static constexpr uint8_t unbounded()
Definition: formula.hh:140
unsigned size() const
Definition: formula.hh:235
const fnode * clone() const
Clone an fnode.
Definition: formula.hh:116
bool has_lbt_atomic_props() const
Definition: formula.hh:477
bool is_sugar_free_ltl() const
Definition: formula.hh:393
static const fnode * binop(op o, const fnode *f, const fnode *g)
bool is_sere_formula() const
Definition: formula.hh:411
op
Operator types.
Definition: formula.hh:64
bool is_tt() const
Definition: formula.hh:291
const fnode *const * end() const
Definition: formula.hh:259
bool is_universal(const const_twa_graph_ptr &aut)
Return true iff aut is universal.
op kind() const
Definition: formula.hh:162
static const fnode * nested_unop_range(op uo, op bo, unsigned min, unsigned max, const fnode *f)
bool is_eventual() const
Definition: formula.hh:423
unsigned min() const
Definition: formula.hh:219
bool is_universal() const
Definition: formula.hh:429
strong release (dual of weak until)
bool accepts_eword() const
Definition: formula.hh:471
static const fnode * multop(op o, std::vector< const fnode *> l)
bool is_Kleene_star() const
Definition: formula.hh:315