43 #include <spot/misc/common.hh>
46 #include <initializer_list>
55 #include <initializer_list>
62 enum class op: uint8_t
101 class SPOT_API fnode final
118 if (SPOT_UNLIKELY(!refs_))
130 if (SPOT_LIKELY(refs_))
132 else if (SPOT_LIKELY(id_ > 2) && SPOT_LIKELY(!saturated_))
144 static const fnode*
ap(
const std::string& name);
150 static const fnode* multop(
op o, std::vector<const fnode*> l);
153 uint8_t min, uint8_t max = unbounded());
162 std::string kindstr()
const;
173 return op_ == o1 || op_ == o2;
177 bool is(std::initializer_list<op> l)
const
179 const fnode* n =
this;
194 if (SPOT_UNLIKELY(size_ != 1))
195 throw std::invalid_argument
196 (
"get_child_of() expecting single-child node");
217 throw std::invalid_argument
218 (
"min() only works on Star and FStar nodes");
226 throw std::invalid_argument
227 (
"max() only works on Star and FStar nodes");
252 return children + size();
259 throw std::runtime_error(
"access to non-existing child");
310 return min_ == 0 && max_ == unbounded();
322 const std::string& ap_name()
const;
325 std::ostream& dump(std::ostream& os)
const;
328 const fnode* all_but(
unsigned i)
const;
335 while (pos < s && children[pos]->is_boolean())
341 const fnode* boolean_operands(
unsigned* width =
nullptr)
const;
353 static bool instances_check();
368 return is_.sugar_free_boolean;
374 return is_.in_nenoform;
380 return is_.syntactic_si;
386 return is_.sugar_free_ltl;
392 return is_.ltl_formula;
398 return is_.psl_formula;
404 return is_.sere_formula;
422 return is_.universal;
428 return is_.syntactic_safety;
434 return is_.syntactic_guarantee;
440 return is_.syntactic_obligation;
446 return is_.syntactic_recurrence;
452 return is_.syntactic_persistence;
458 return !is_.not_marked;
464 return is_.accepting_eword;
470 return is_.lbt_atomic_props;
476 return is_.spin_atomic_props;
480 void setup_props(
op o);
481 void destroy_aux()
const;
494 fnode(
op o, iter begin, iter end)
496 size_t s = std::distance(begin, end);
497 if (s > (
size_t) UINT16_MAX)
498 throw std::runtime_error(
"too many children for formula");
501 for (
auto i = begin; i != end; ++i)
506 fnode(
op o, std::initializer_list<const fnode*> l)
507 : fnode(o, l.begin(), l.end())
511 fnode(
op o,
const fnode* f, uint8_t min, uint8_t max)
520 static const fnode* ff_;
521 static const fnode* tt_;
522 static const fnode* ew_;
523 static const fnode* one_star_;
528 mutable uint8_t saturated_ = 0;
530 mutable uint16_t refs_ = 0;
532 static size_t next_id_;
550 bool sugar_free_boolean:1;
553 bool sugar_free_ltl:1;
560 bool syntactic_safety:1;
561 bool syntactic_guarantee:1;
562 bool syntactic_obligation:1;
563 bool syntactic_recurrence:1;
564 bool syntactic_persistence:1;
566 bool accepting_eword:1;
567 bool lbt_atomic_props:1;
568 bool spin_atomic_props:1;
577 const fnode* children[1];
582 int atomic_prop_cmp(
const fnode* f,
const fnode* g);
587 operator()(
const fnode* left,
const fnode* right)
const
607 auto get_literal = [](
const fnode* f) ->
const fnode*
616 const fnode* litl = get_literal(left);
617 const fnode* litr = get_literal(right);
623 int cmp = atomic_prop_cmp(litl, litr);
630 size_t l = left->
id();
631 size_t r = right->
id();
644 std::ostringstream old;
646 std::ostringstream ord;
648 return old.str() < ord.str();
729 const formula& operator=(formula&& f) noexcept
731 std::swap(f.ptr_, ptr_);
735 bool operator<(
const formula& other)
const noexcept
737 if (SPOT_UNLIKELY(!other.ptr_))
739 if (SPOT_UNLIKELY(!ptr_))
741 if (
id() < other.id())
743 if (
id() > other.id())
749 return ptr_ < other.ptr_;
752 bool operator<=(
const formula& other)
const noexcept
754 return *
this == other || *
this < other;
757 bool operator>(
const formula& other)
const noexcept
759 return !(*
this <= other);
762 bool operator>=(
const formula& other)
const noexcept
764 return !(*
this < other);
767 bool operator==(
const formula& other)
const noexcept
769 return other.ptr_ == ptr_;
772 bool operator==(std::nullptr_t) const noexcept
774 return ptr_ ==
nullptr;
777 bool operator!=(
const formula& other)
const noexcept
779 return other.ptr_ != ptr_;
782 bool operator!=(std::nullptr_t) const noexcept
784 return ptr_ !=
nullptr;
787 operator bool()
const
789 return ptr_ !=
nullptr;
818 throw std::invalid_argument(
"atomic propositions cannot be "
819 "constructed from arbitrary formulas");
840 #define SPOT_DEF_UNOP(Name) \
841 static formula Name(const formula& f) \
843 return unop(op::Name, f); \
846 #define SPOT_DEF_UNOP(Name) \
847 static formula Name(const formula& f) \
849 return unop(op::Name, f); \
851 static formula Name(formula&& f) \
853 return unop(op::Name, std::move(f)); \
922 #define SPOT_DEF_BINOP(Name) \
923 static formula Name(const formula& f, const formula& g) \
925 return binop(op::Name, f, g); \
928 #define SPOT_DEF_BINOP(Name) \
929 static formula Name(const formula& f, const formula& g) \
931 return binop(op::Name, f, g); \
933 static formula Name(const formula& f, formula&& g) \
935 return binop(op::Name, f, std::move(g)); \
937 static formula Name(formula&& f, const formula& g) \
939 return binop(op::Name, std::move(f), g); \
941 static formula Name(formula&& f, formula&& g) \
943 return binop(op::Name, std::move(f), std::move(g)); \
995 #undef SPOT_DEF_BINOP
1004 std::vector<const fnode*> tmp;
1005 tmp.reserve(l.size());
1008 tmp.push_back(f.ptr_->
clone());
1015 std::vector<const fnode*> tmp;
1016 tmp.reserve(l.size());
1026 #define SPOT_DEF_MULTOP(Name) \
1027 static formula Name(const std::vector<formula>& l) \
1029 return multop(op::Name, l); \
1032 #define SPOT_DEF_MULTOP(Name) \
1033 static formula Name(const std::vector<formula>& l) \
1035 return multop(op::Name, l); \
1038 static formula Name(std::vector<formula>&& l) \
1040 return multop(op::Name, std::move(l)); \
1043 SPOT_DEF_MULTOP(
Or);
1077 #undef SPOT_DEF_MULTOP
1085 uint8_t max = unbounded())
1093 uint8_t max = unbounded())
1101 #define SPOT_DEF_BUNOP(Name) \
1102 static formula Name(const formula& f, \
1104 uint8_t max = unbounded()) \
1106 return bunop(op::Name, f, min, max); \
1109 #define SPOT_DEF_BUNOP(Name) \
1110 static formula Name(const formula& f, \
1112 uint8_t max = unbounded()) \
1114 return bunop(op::Name, f, min, max); \
1116 static formula Name(formula&& f, \
1118 uint8_t max = unbounded()) \
1120 return bunop(op::Name, std::move(f), min, max); \
1123 SPOT_DEF_BUNOP(
Star);
1147 SPOT_DEF_BUNOP(
FStar);
1150 #undef SPOT_DEF_BUNOP
1157 static formula sugar_goto(
const formula& b, uint8_t min, uint8_t max);
1164 static formula sugar_equal(
const formula& b, uint8_t min, uint8_t max);
1167 const fnode* to_node_()
1187 return ptr_->kind();
1193 return ptr_->kindstr();
1203 bool is(
op o1,
op o2)
const
1206 return ptr_->is(o1, o2);
1210 bool is(std::initializer_list<op> l)
const
1228 formula get_child_of(std::initializer_list<op> l)
const
1262 return ptr_->size();
1279 class SPOT_API formula_child_iterator final
1282 const fnode*
const* ptr_;
1284 formula_child_iterator()
1289 formula_child_iterator(
const fnode*
const* f)
1294 bool operator==(formula_child_iterator o)
1296 return ptr_ == o.ptr_;
1299 bool operator!=(formula_child_iterator o)
1301 return ptr_ != o.ptr_;
1306 return formula((*ptr_)->clone());
1309 formula_child_iterator operator++()
1315 formula_child_iterator operator++(
int)
1326 return ptr_->begin();
1338 return formula(ptr_->nth(i)->clone());
1351 return ptr_->is_ff();
1363 return ptr_->is_tt();
1375 return ptr_->is_eword();
1381 return ptr_->is_constant();
1390 return ptr_->is_Kleene_star();
1407 (is(
op::Not) && is_boolean() && is_in_nenoform()));
1415 return ptr_->ap_name();
1422 std::ostream&
dump(std::ostream& os)
const
1424 return ptr_->dump(os);
1434 return formula(ptr_->all_but(i));
1448 return ptr_->boolean_count();
1466 return formula(ptr_->boolean_operands(width));
1469 #define SPOT_DEF_PROP(Name) \
1472 return ptr_->Name(); \
1479 SPOT_DEF_PROP(is_boolean);
1481 SPOT_DEF_PROP(is_sugar_free_boolean);
1486 SPOT_DEF_PROP(is_in_nenoform);
1488 SPOT_DEF_PROP(is_syntactic_stutter_invariant);
1490 SPOT_DEF_PROP(is_sugar_free_ltl);
1492 SPOT_DEF_PROP(is_ltl_formula);
1494 SPOT_DEF_PROP(is_psl_formula);
1496 SPOT_DEF_PROP(is_sere_formula);
1499 SPOT_DEF_PROP(is_finite);
1517 SPOT_DEF_PROP(is_eventual);
1538 SPOT_DEF_PROP(is_universal);
1543 SPOT_DEF_PROP(is_syntactic_safety);
1545 SPOT_DEF_PROP(is_syntactic_guarantee);
1547 SPOT_DEF_PROP(is_syntactic_obligation);
1549 SPOT_DEF_PROP(is_syntactic_recurrence);
1551 SPOT_DEF_PROP(is_syntactic_persistence);
1554 SPOT_DEF_PROP(is_marked);
1556 SPOT_DEF_PROP(accepts_eword);
1562 SPOT_DEF_PROP(has_lbt_atomic_props);
1571 SPOT_DEF_PROP(has_spin_atomic_props);
1572 #undef SPOT_DEF_PROP
1575 template<
typename Trans>
1578 switch (
op o = kind())
1592 return unop(o, trans((*
this)[0]));
1604 formula tmp = trans((*
this)[0]);
1605 return binop(o, tmp, trans((*
this)[1]));
1615 std::vector<formula> tmp;
1616 tmp.reserve(size());
1618 tmp.push_back(trans(f));
1619 return multop(o, std::move(tmp));
1623 return bunop(o, trans((*
this)[0]), min(), max());
1633 template<
typename Func>
1645 std::ostream& print_formula_props(std::ostream& out,
const formula& f,
1646 bool abbreviated =
false);
1650 std::list<std::string> list_formula_props(
const formula& f);
1654 std::ostream& operator<<(std::ostream& os,
const formula& f);
bool is_tt() const
Definition: formula.hh:282
bool is(op o) const
Definition: formula.hh:165
const fnode *const * begin() const
Definition: formula.hh:244
static const fnode * eword()
Definition: formula.hh:288
static const fnode * ap(const std::string &name)
bool is_syntactic_stutter_invariant() const
Definition: formula.hh:378
static const fnode * unop(op o, const fnode *f)
bool is_syntactic_safety() const
Definition: formula.hh:426
bool is_eventual() const
Definition: formula.hh:414
bool is_ltl_formula() const
Definition: formula.hh:390
Definition: formula.hh:1658
bool is_psl_formula() const
Definition: formula.hh:396
bool is_sere_formula() const
Definition: formula.hh:402
static const fnode * tt()
Definition: formula.hh:276
bool is_marked() const
Definition: formula.hh:456
bool is(op o1, op o2) const
Definition: formula.hh:171
bool is_syntactic_recurrence() const
Definition: formula.hh:444
const fnode * clone() const
Clone an fnode.
Definition: formula.hh:114
unsigned size() const
Definition: formula.hh:232
bool is_Kleene_star() const
Definition: formula.hh:306
bool is_in_nenoform() const
Definition: formula.hh:372
unsigned boolean_count() const
Definition: formula.hh:331
bool is_sugar_free_boolean() const
Definition: formula.hh:366
unsigned max() const
Definition: formula.hh:223
unsigned min() const
Definition: formula.hh:214
static const fnode * multop(op o, std::vector< const fnode * > l)
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:264
static const fnode * one_star()
Definition: formula.hh:314
marked version of the Negated PSL Clusure
bool is_constant() const
Definition: formula.hh:300
const fnode * get_child_of(op o) const
Definition: formula.hh:190
const fnode *const * end() const
Definition: formula.hh:250
bool has_spin_atomic_props() const
Definition: formula.hh:474
bool accepts_eword() const
Definition: formula.hh:462
const fnode * nth(unsigned i) const
Definition: formula.hh:256
void destroy() const
Dereference an fnode.
Definition: formula.hh:128
op kind() const
Definition: formula.hh:156
static constexpr uint8_t unbounded()
Definition: formula.hh:138
bool is_syntactic_guarantee() const
Definition: formula.hh:432
std::ostream & dump(std::ostream &os) const
static const fnode * binop(op o, const fnode *f, const fnode *g)
op
Operator types.
Definition: formula.hh:62
bool is_syntactic_persistence() const
Definition: formula.hh:450
bool is_ff() const
Definition: formula.hh:270
bool is_universal() const
Definition: formula.hh:420
bool is_boolean() const
Definition: formula.hh:360
bool is_syntactic_obligation() const
Definition: formula.hh:438
bool is_sugar_free_ltl() const
Definition: formula.hh:384
Actual storage for formula nodes.
Definition: formula.hh:107
bool is(std::initializer_list< op > l) const
Definition: formula.hh:177
bool is_finite() const
Definition: formula.hh:408
strong release (dual of weak until)
bool has_lbt_atomic_props() const
Definition: formula.hh:468
const fnode * get_child_of(std::initializer_list< op > l) const
Definition: formula.hh:201
size_t id() const
Definition: formula.hh:238
bool is_eword() const
Definition: formula.hh:294