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());
164 std::string kindstr()
const;
175 return op_ == o1 || op_ == o2;
179 bool is(std::initializer_list<op> l)
const 181 const fnode* n =
this;
196 if (SPOT_UNLIKELY(size_ != 1))
197 report_get_child_of_expecting_single_child_node();
218 report_min_invalid_arg();
226 report_max_invalid_arg();
255 const fnode*
const*
end()
const 257 return children + size();
261 const fnode*
nth(
unsigned i)
const 263 if (SPOT_UNLIKELY(i >= size()))
264 report_non_existing_child();
269 static const fnode*
ff()
281 static const fnode*
tt()
315 return min_ == 0 && max_ == unbounded();
327 const std::string& ap_name()
const;
330 std::ostream& dump(std::ostream& os)
const;
333 const fnode* all_but(
unsigned i)
const;
340 while (pos < s && children[pos]->is_boolean())
346 const fnode* boolean_operands(
unsigned* width =
nullptr)
const;
358 static bool instances_check();
373 return is_.sugar_free_boolean;
379 return is_.in_nenoform;
385 return is_.syntactic_si;
391 return is_.sugar_free_ltl;
397 return is_.ltl_formula;
403 return is_.psl_formula;
409 return is_.sere_formula;
427 return is_.universal;
433 return is_.syntactic_safety;
439 return is_.syntactic_guarantee;
445 return is_.syntactic_obligation;
451 return is_.syntactic_recurrence;
457 return is_.syntactic_persistence;
463 return !is_.not_marked;
469 return is_.accepting_eword;
475 return is_.lbt_atomic_props;
481 return is_.spin_atomic_props;
485 void setup_props(
op o);
486 void destroy_aux()
const;
488 [[noreturn]]
static void report_non_existing_child();
489 [[noreturn]]
static void report_too_many_children();
490 [[noreturn]]
static void 491 report_get_child_of_expecting_single_child_node();
492 [[noreturn]]
static void report_min_invalid_arg();
493 [[noreturn]]
static void report_max_invalid_arg();
495 static const fnode* unique(fnode*);
500 fnode(
const fnode&) =
delete;
501 fnode& operator=(
const fnode&) =
delete;
506 fnode(
op o, iter begin, iter end)
523 size_t s = std::distance(begin, end);
524 if (SPOT_UNLIKELY(s > (
size_t) UINT16_MAX))
525 report_too_many_children();
528 for (
auto i = begin; i != end; ++i)
533 fnode(
op o, std::initializer_list<const fnode*> l)
534 : fnode(o, l.begin(), l.end())
538 fnode(
op o,
const fnode* f, uint8_t min, uint8_t max)
539 : op_(o), min_(min), max_(max), saturated_(0), size_(1)
545 static const fnode* ff_;
546 static const fnode* tt_;
547 static const fnode* ew_;
548 static const fnode* one_star_;
553 mutable uint8_t saturated_;
555 mutable uint16_t refs_ = 0;
557 static size_t next_id_;
575 bool sugar_free_boolean:1;
578 bool sugar_free_ltl:1;
585 bool syntactic_safety:1;
586 bool syntactic_guarantee:1;
587 bool syntactic_obligation:1;
588 bool syntactic_recurrence:1;
589 bool syntactic_persistence:1;
591 bool accepting_eword:1;
592 bool lbt_atomic_props:1;
593 bool spin_atomic_props:1;
602 const fnode* children[1];
612 operator()(
const fnode* left,
const fnode* right)
const 632 auto get_literal = [](
const fnode* f) ->
const fnode*
641 const fnode* litl = get_literal(left);
642 const fnode* litr = get_literal(right);
648 int cmp = atomic_prop_cmp(litl, litr);
655 size_t l = left->
id();
656 size_t r = right->
id();
669 std::ostringstream old;
671 std::ostringstream ord;
673 return old.str() < ord.str();
756 std::swap(f.ptr_, ptr_);
760 bool operator<(
const formula& other)
const noexcept
762 if (SPOT_UNLIKELY(!other.ptr_))
764 if (SPOT_UNLIKELY(!ptr_))
766 if (
id() < other.
id())
768 if (
id() > other.
id())
774 return ptr_ < other.ptr_;
777 bool operator<=(
const formula& other)
const noexcept
779 return *
this == other || *
this < other;
782 bool operator>(
const formula& other)
const noexcept
784 return !(*
this <= other);
787 bool operator>=(
const formula& other)
const noexcept
789 return !(*
this < other);
792 bool operator==(
const formula& other)
const noexcept
794 return other.ptr_ == ptr_;
797 bool operator==(std::nullptr_t)
const noexcept
799 return ptr_ ==
nullptr;
802 bool operator!=(
const formula& other)
const noexcept
804 return other.ptr_ != ptr_;
807 bool operator!=(std::nullptr_t)
const noexcept
809 return ptr_ !=
nullptr;
812 operator bool()
const 814 return ptr_ !=
nullptr;
841 report_ap_invalid_arg();
863 #define SPOT_DEF_UNOP(Name) \ 864 static formula Name(const formula& f) \ 866 return unop(op::Name, f); \ 869 #define SPOT_DEF_UNOP(Name) \ 870 static formula Name(const formula& f) \ 872 return unop(op::Name, f); \ 874 static formula Name(formula&& f) \ 876 return unop(op::Name, std::move(f)); \ 945 #define SPOT_DEF_BINOP(Name) \ 946 static formula Name(const formula& f, const formula& g) \ 948 return binop(op::Name, f, g); \ 951 #define SPOT_DEF_BINOP(Name) \ 952 static formula Name(const formula& f, const formula& g) \ 954 return binop(op::Name, f, g); \ 956 static formula Name(const formula& f, formula&& g) \ 958 return binop(op::Name, f, std::move(g)); \ 960 static formula Name(formula&& f, const formula& g) \ 962 return binop(op::Name, std::move(f), g); \ 964 static formula Name(formula&& f, formula&& g) \ 966 return binop(op::Name, std::move(f), std::move(g)); \ 1018 #undef SPOT_DEF_BINOP 1027 std::vector<const fnode*> tmp;
1028 tmp.reserve(l.size());
1031 tmp.emplace_back(f.ptr_->
clone());
1038 std::vector<const fnode*> tmp;
1039 tmp.reserve(l.size());
1049 #define SPOT_DEF_MULTOP(Name) \ 1050 static formula Name(const std::vector<formula>& l) \ 1052 return multop(op::Name, l); \ 1055 #define SPOT_DEF_MULTOP(Name) \ 1056 static formula Name(const std::vector<formula>& l) \ 1058 return multop(op::Name, l); \ 1061 static formula Name(std::vector<formula>&& l) \ 1063 return multop(op::Name, std::move(l)); \ 1066 SPOT_DEF_MULTOP(
Or);
1100 #undef SPOT_DEF_MULTOP 1108 uint8_t max = unbounded())
1116 uint8_t max = unbounded())
1124 #define SPOT_DEF_BUNOP(Name) \ 1125 static formula Name(const formula& f, \ 1127 uint8_t max = unbounded()) \ 1129 return bunop(op::Name, f, min, max); \ 1132 #define SPOT_DEF_BUNOP(Name) \ 1133 static formula Name(const formula& f, \ 1135 uint8_t max = unbounded()) \ 1137 return bunop(op::Name, f, min, max); \ 1139 static formula Name(formula&& f, \ 1141 uint8_t max = unbounded()) \ 1143 return bunop(op::Name, std::move(f), min, max); \ 1146 SPOT_DEF_BUNOP(
Star);
1170 SPOT_DEF_BUNOP(
FStar);
1173 #undef SPOT_DEF_BUNOP 1180 static formula sugar_goto(
const formula& b, uint8_t min, uint8_t max);
1187 static formula sugar_equal(
const formula& b, uint8_t min, uint8_t max);
1190 const fnode* to_node_()
1210 return ptr_->kind();
1216 return ptr_->kindstr();
1226 bool is(
op o1,
op o2)
const 1229 return ptr_->is(o1, o2);
1233 bool is(std::initializer_list<op> l)
const 1251 formula get_child_of(std::initializer_list<op> l)
const 1285 return ptr_->size();
1294 return ptr_->is_leaf();
1311 class SPOT_API formula_child_iterator final
1314 const fnode*
const* ptr_;
1316 formula_child_iterator()
1321 formula_child_iterator(
const fnode*
const* f)
1326 bool operator==(formula_child_iterator o)
1328 return ptr_ == o.ptr_;
1331 bool operator!=(formula_child_iterator o)
1333 return ptr_ != o.ptr_;
1338 return formula((*ptr_)->clone());
1341 formula_child_iterator operator++()
1347 formula_child_iterator operator++(
int)
1358 return ptr_->begin();
1362 formula_child_iterator
end()
const 1370 return formula(ptr_->nth(i)->clone());
1383 return ptr_->is_ff();
1395 return ptr_->is_tt();
1407 return ptr_->is_eword();
1413 return ptr_->is_constant();
1422 return ptr_->is_Kleene_star();
1439 (is(
op::Not) && is_boolean() && is_in_nenoform()));
1447 return ptr_->ap_name();
1454 std::ostream&
dump(std::ostream& os)
const 1456 return ptr_->dump(os);
1466 return formula(ptr_->all_but(i));
1480 return ptr_->boolean_count();
1498 return formula(ptr_->boolean_operands(width));
1501 #define SPOT_DEF_PROP(Name) \ 1504 return ptr_->Name(); \ 1511 SPOT_DEF_PROP(is_boolean);
1513 SPOT_DEF_PROP(is_sugar_free_boolean);
1518 SPOT_DEF_PROP(is_in_nenoform);
1520 SPOT_DEF_PROP(is_syntactic_stutter_invariant);
1522 SPOT_DEF_PROP(is_sugar_free_ltl);
1524 SPOT_DEF_PROP(is_ltl_formula);
1526 SPOT_DEF_PROP(is_psl_formula);
1528 SPOT_DEF_PROP(is_sere_formula);
1531 SPOT_DEF_PROP(is_finite);
1549 SPOT_DEF_PROP(is_eventual);
1575 SPOT_DEF_PROP(is_syntactic_safety);
1577 SPOT_DEF_PROP(is_syntactic_guarantee);
1579 SPOT_DEF_PROP(is_syntactic_obligation);
1581 SPOT_DEF_PROP(is_syntactic_recurrence);
1583 SPOT_DEF_PROP(is_syntactic_persistence);
1586 SPOT_DEF_PROP(is_marked);
1588 SPOT_DEF_PROP(accepts_eword);
1594 SPOT_DEF_PROP(has_lbt_atomic_props);
1603 SPOT_DEF_PROP(has_spin_atomic_props);
1604 #undef SPOT_DEF_PROP 1609 template<
typename Trans,
typename... Args>
1612 switch (
op o = kind())
1626 return unop(o, trans((*
this)[0], std::forward<Args>(args)...));
1638 formula tmp = trans((*
this)[0], std::forward<Args>(args)...);
1639 return binop(o, tmp,
1640 trans((*
this)[1], std::forward<Args>(args)...));
1650 std::vector<formula> tmp;
1651 tmp.reserve(size());
1653 tmp.emplace_back(trans(f, std::forward<Args>(args)...));
1654 return multop(o, std::move(tmp));
1658 return bunop(o, trans((*
this)[0], std::forward<Args>(args)...),
1672 template<
typename Func,
typename... Args>
1675 if (func(*
this, std::forward<Args>(args)...))
1678 f.
traverse(func, std::forward<Args>(args)...);
1683 [[noreturn]]
static void report_ap_invalid_arg();
1690 bool abbreviated =
false);
1698 std::ostream& operator<<(std::ostream& os,
const formula& f);
const fnode *const * begin() const
Definition: formula.hh:249
Definition: automata.hh:26
bool is_boolean() const
Definition: formula.hh:365
static const fnode * eword()
Definition: formula.hh:293
static const fnode * ap(const std::string &name)
std::ostream & dump(std::ostream &os) const
unsigned max() const
Definition: formula.hh:223
size_t id() const
Definition: formula.hh:243
bool is(op o) const
Definition: formula.hh:167
bool is_psl_formula() const
Definition: formula.hh:401
static const fnode * unop(op o, const fnode *f)
bool is_leaf() const
Definition: formula.hh:237
bool is_finite() const
Definition: formula.hh:413
bool is_eword() const
Definition: formula.hh:299
unsigned boolean_count() const
Definition: formula.hh:336
const fnode * get_child_of(op o) const
Definition: formula.hh:192
Definition: bitset.hh:405
bool is_syntactic_guarantee() const
Definition: formula.hh:437
static const fnode * tt()
Definition: formula.hh:281
bool is_syntactic_persistence() const
Definition: formula.hh:455
const fnode * nth(unsigned i) const
Definition: formula.hh:261
bool is_marked() const
Definition: formula.hh:461
bool is_syntactic_recurrence() const
Definition: formula.hh:449
bool is(std::initializer_list< op > l) const
Definition: formula.hh:179
bool is_syntactic_obligation() const
Definition: formula.hh:443
bool is(op o1, op o2) const
Definition: formula.hh:173
bool has_spin_atomic_props() const
Definition: formula.hh:479
bool is_constant() const
Definition: formula.hh:305
bool is_syntactic_stutter_invariant() const
Definition: formula.hh:383
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:269
static const fnode * one_star()
Definition: formula.hh:319
bool is_syntactic_safety() const
Definition: formula.hh:431
marked version of the Negated PSL Closure
bool is_sugar_free_boolean() const
Definition: formula.hh:371
bool is_ltl_formula() const
Definition: formula.hh:395
bool is_in_nenoform() const
Definition: formula.hh:377
bool is_ff() const
Definition: formula.hh:275
const fnode * get_child_of(std::initializer_list< op > l) const
Definition: formula.hh:202
static constexpr uint8_t unbounded()
Definition: formula.hh:140
unsigned size() const
Definition: formula.hh:231
const fnode * clone() const
Clone an fnode.
Definition: formula.hh:116
bool has_lbt_atomic_props() const
Definition: formula.hh:473
bool is_sugar_free_ltl() const
Definition: formula.hh:389
static const fnode * binop(op o, const fnode *f, const fnode *g)
bool is_sere_formula() const
Definition: formula.hh:407
op
Operator types.
Definition: formula.hh:64
bool is_tt() const
Definition: formula.hh:287
const fnode *const * end() const
Definition: formula.hh:255
bool is_universal(const const_twa_graph_ptr &aut)
Return true iff aut is universal.
op kind() const
Definition: formula.hh:158
bool is_eventual() const
Definition: formula.hh:419
unsigned min() const
Definition: formula.hh:215
bool is_universal() const
Definition: formula.hh:425
strong release (dual of weak until)
bool accepts_eword() const
Definition: formula.hh:467
static const fnode * multop(op o, std::vector< const fnode *> l)
bool is_Kleene_star() const
Definition: formula.hh:311