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);
146 static const fnode* unop(
op o,
const fnode* f);
148 static const fnode* binop(
op o,
const fnode* f,
const fnode* g);
150 static const fnode* multop(
op o, std::vector<const fnode*> l);
152 static const fnode* bunop(
op o,
const fnode* f,
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");
250 const fnode*
const*
end()
const 252 return children + size();
256 const fnode*
nth(
unsigned i)
const 259 throw std::runtime_error(
"access to non-existing child");
264 static const fnode*
ff()
276 static const fnode*
tt()
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;
483 static const fnode* unique(
const fnode*);
488 fnode(
const fnode&) =
delete;
489 fnode& operator=(
const fnode&) =
delete;
494 fnode(
op o, iter begin, iter end)
511 size_t s = std::distance(begin, end);
512 if (s > (
size_t) UINT16_MAX)
513 throw std::runtime_error(
"too many children for formula");
516 for (
auto i = begin; i != end; ++i)
521 fnode(
op o, std::initializer_list<const fnode*> l)
522 : fnode(o, l.begin(), l.end())
526 fnode(
op o,
const fnode* f, uint8_t min, uint8_t max)
527 : op_(o), min_(min), max_(max), saturated_(0), size_(1)
533 static const fnode* ff_;
534 static const fnode* tt_;
535 static const fnode* ew_;
536 static const fnode* one_star_;
541 mutable uint8_t saturated_;
543 mutable uint16_t refs_ = 0;
545 static size_t next_id_;
563 bool sugar_free_boolean:1;
566 bool sugar_free_ltl:1;
573 bool syntactic_safety:1;
574 bool syntactic_guarantee:1;
575 bool syntactic_obligation:1;
576 bool syntactic_recurrence:1;
577 bool syntactic_persistence:1;
579 bool accepting_eword:1;
580 bool lbt_atomic_props:1;
581 bool spin_atomic_props:1;
590 const fnode* children[1];
600 operator()(
const fnode* left,
const fnode* right)
const 620 auto get_literal = [](
const fnode* f) ->
const fnode*
629 const fnode* litl = get_literal(left);
630 const fnode* litr = get_literal(right);
636 int cmp = atomic_prop_cmp(litl, litr);
643 size_t l = left->
id();
644 size_t r = right->
id();
657 std::ostringstream old;
659 std::ostringstream ord;
661 return old.str() < ord.str();
744 std::swap(f.ptr_, ptr_);
748 bool operator<(
const formula& other)
const noexcept
750 if (SPOT_UNLIKELY(!other.ptr_))
752 if (SPOT_UNLIKELY(!ptr_))
754 if (
id() < other.
id())
756 if (
id() > other.
id())
762 return ptr_ < other.ptr_;
765 bool operator<=(
const formula& other)
const noexcept
767 return *
this == other || *
this < other;
770 bool operator>(
const formula& other)
const noexcept
772 return !(*
this <= other);
775 bool operator>=(
const formula& other)
const noexcept
777 return !(*
this < other);
780 bool operator==(
const formula& other)
const noexcept
782 return other.ptr_ == ptr_;
785 bool operator==(std::nullptr_t)
const noexcept
787 return ptr_ ==
nullptr;
790 bool operator!=(
const formula& other)
const noexcept
792 return other.ptr_ != ptr_;
795 bool operator!=(std::nullptr_t)
const noexcept
797 return ptr_ !=
nullptr;
800 operator bool()
const 802 return ptr_ !=
nullptr;
831 throw std::invalid_argument(
"atomic propositions cannot be " 832 "constructed from arbitrary formulas");
853 #define SPOT_DEF_UNOP(Name) \ 854 static formula Name(const formula& f) \ 856 return unop(op::Name, f); \ 859 #define SPOT_DEF_UNOP(Name) \ 860 static formula Name(const formula& f) \ 862 return unop(op::Name, f); \ 864 static formula Name(formula&& f) \ 866 return unop(op::Name, std::move(f)); \ 935 #define SPOT_DEF_BINOP(Name) \ 936 static formula Name(const formula& f, const formula& g) \ 938 return binop(op::Name, f, g); \ 941 #define SPOT_DEF_BINOP(Name) \ 942 static formula Name(const formula& f, const formula& g) \ 944 return binop(op::Name, f, g); \ 946 static formula Name(const formula& f, formula&& g) \ 948 return binop(op::Name, f, std::move(g)); \ 950 static formula Name(formula&& f, const formula& g) \ 952 return binop(op::Name, std::move(f), g); \ 954 static formula Name(formula&& f, formula&& g) \ 956 return binop(op::Name, std::move(f), std::move(g)); \ 1008 #undef SPOT_DEF_BINOP 1017 std::vector<const fnode*> tmp;
1018 tmp.reserve(l.size());
1021 tmp.emplace_back(f.ptr_->
clone());
1028 std::vector<const fnode*> tmp;
1029 tmp.reserve(l.size());
1039 #define SPOT_DEF_MULTOP(Name) \ 1040 static formula Name(const std::vector<formula>& l) \ 1042 return multop(op::Name, l); \ 1045 #define SPOT_DEF_MULTOP(Name) \ 1046 static formula Name(const std::vector<formula>& l) \ 1048 return multop(op::Name, l); \ 1051 static formula Name(std::vector<formula>&& l) \ 1053 return multop(op::Name, std::move(l)); \ 1056 SPOT_DEF_MULTOP(
Or);
1090 #undef SPOT_DEF_MULTOP 1098 uint8_t max = unbounded())
1106 uint8_t max = unbounded())
1114 #define SPOT_DEF_BUNOP(Name) \ 1115 static formula Name(const formula& f, \ 1117 uint8_t max = unbounded()) \ 1119 return bunop(op::Name, f, min, max); \ 1122 #define SPOT_DEF_BUNOP(Name) \ 1123 static formula Name(const formula& f, \ 1125 uint8_t max = unbounded()) \ 1127 return bunop(op::Name, f, min, max); \ 1129 static formula Name(formula&& f, \ 1131 uint8_t max = unbounded()) \ 1133 return bunop(op::Name, std::move(f), min, max); \ 1136 SPOT_DEF_BUNOP(
Star);
1160 SPOT_DEF_BUNOP(
FStar);
1163 #undef SPOT_DEF_BUNOP 1170 static formula sugar_goto(
const formula& b, uint8_t min, uint8_t max);
1177 static formula sugar_equal(
const formula& b, uint8_t min, uint8_t max);
1180 const fnode* to_node_()
1200 return ptr_->kind();
1206 return ptr_->kindstr();
1216 bool is(
op o1,
op o2)
const 1219 return ptr_->is(o1, o2);
1223 bool is(std::initializer_list<op> l)
const 1241 formula get_child_of(std::initializer_list<op> l)
const 1275 return ptr_->size();
1292 class SPOT_API formula_child_iterator final
1295 const fnode*
const* ptr_;
1297 formula_child_iterator()
1302 formula_child_iterator(
const fnode*
const* f)
1307 bool operator==(formula_child_iterator o)
1309 return ptr_ == o.ptr_;
1312 bool operator!=(formula_child_iterator o)
1314 return ptr_ != o.ptr_;
1319 return formula((*ptr_)->clone());
1322 formula_child_iterator operator++()
1328 formula_child_iterator operator++(
int)
1339 return ptr_->begin();
1343 formula_child_iterator
end()
const 1351 return formula(ptr_->nth(i)->clone());
1364 return ptr_->is_ff();
1376 return ptr_->is_tt();
1388 return ptr_->is_eword();
1394 return ptr_->is_constant();
1403 return ptr_->is_Kleene_star();
1420 (is(
op::Not) && is_boolean() && is_in_nenoform()));
1428 return ptr_->ap_name();
1435 std::ostream&
dump(std::ostream& os)
const 1437 return ptr_->dump(os);
1447 return formula(ptr_->all_but(i));
1461 return ptr_->boolean_count();
1479 return formula(ptr_->boolean_operands(width));
1482 #define SPOT_DEF_PROP(Name) \ 1485 return ptr_->Name(); \ 1492 SPOT_DEF_PROP(is_boolean);
1494 SPOT_DEF_PROP(is_sugar_free_boolean);
1499 SPOT_DEF_PROP(is_in_nenoform);
1501 SPOT_DEF_PROP(is_syntactic_stutter_invariant);
1503 SPOT_DEF_PROP(is_sugar_free_ltl);
1505 SPOT_DEF_PROP(is_ltl_formula);
1507 SPOT_DEF_PROP(is_psl_formula);
1509 SPOT_DEF_PROP(is_sere_formula);
1512 SPOT_DEF_PROP(is_finite);
1530 SPOT_DEF_PROP(is_eventual);
1551 SPOT_DEF_PROP(is_universal);
1556 SPOT_DEF_PROP(is_syntactic_safety);
1558 SPOT_DEF_PROP(is_syntactic_guarantee);
1560 SPOT_DEF_PROP(is_syntactic_obligation);
1562 SPOT_DEF_PROP(is_syntactic_recurrence);
1564 SPOT_DEF_PROP(is_syntactic_persistence);
1567 SPOT_DEF_PROP(is_marked);
1569 SPOT_DEF_PROP(accepts_eword);
1575 SPOT_DEF_PROP(has_lbt_atomic_props);
1584 SPOT_DEF_PROP(has_spin_atomic_props);
1585 #undef SPOT_DEF_PROP 1588 template<
typename Trans>
1591 switch (
op o = kind())
1605 return unop(o, trans((*
this)[0]));
1617 formula tmp = trans((*
this)[0]);
1618 return binop(o, tmp, trans((*
this)[1]));
1628 std::vector<formula> tmp;
1629 tmp.reserve(size());
1631 tmp.emplace_back(trans(f));
1632 return multop(o, std::move(tmp));
1636 return bunop(o, trans((*
this)[0]), min(), max());
1646 template<
typename Func>
1659 bool abbreviated =
false);
1667 std::ostream& operator<<(std::ostream& os,
const formula& f);
const fnode *const * begin() const
Definition: formula.hh:244
bool is_boolean() const
Definition: formula.hh:360
static const fnode * eword()
Definition: formula.hh:288
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:238
bool is(op o) const
Definition: formula.hh:165
bool is_psl_formula() const
Definition: formula.hh:396
static const fnode * unop(op o, const fnode *f)
bool is_finite() const
Definition: formula.hh:408
bool is_eword() const
Definition: formula.hh:294
unsigned boolean_count() const
Definition: formula.hh:331
const fnode * get_child_of(op o) const
Definition: formula.hh:190
Definition: formula.hh:1671
bool is_syntactic_guarantee() const
Definition: formula.hh:432
static const fnode * tt()
Definition: formula.hh:276
bool is_syntactic_persistence() const
Definition: formula.hh:450
const fnode * nth(unsigned i) const
Definition: formula.hh:256
bool is_marked() const
Definition: formula.hh:456
bool is_syntactic_recurrence() const
Definition: formula.hh:444
bool is(std::initializer_list< op > l) const
Definition: formula.hh:177
bool is_syntactic_obligation() const
Definition: formula.hh:438
bool is(op o1, op o2) const
Definition: formula.hh:171
bool has_spin_atomic_props() const
Definition: formula.hh:474
bool is_constant() const
Definition: formula.hh:300
bool is_syntactic_stutter_invariant() const
Definition: formula.hh:378
void destroy() const
Dereference an fnode.
Definition: formula.hh:128
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
bool is_syntactic_safety() const
Definition: formula.hh:426
marked version of the Negated PSL Clusure
bool is_sugar_free_boolean() const
Definition: formula.hh:366
bool is_ltl_formula() const
Definition: formula.hh:390
bool is_in_nenoform() const
Definition: formula.hh:372
bool is_ff() const
Definition: formula.hh:270
const fnode * get_child_of(std::initializer_list< op > l) const
Definition: formula.hh:201
static constexpr uint8_t unbounded()
Definition: formula.hh:138
unsigned size() const
Definition: formula.hh:232
const fnode * clone() const
Clone an fnode.
Definition: formula.hh:114
bool has_lbt_atomic_props() const
Definition: formula.hh:468
bool is_sugar_free_ltl() const
Definition: formula.hh:384
static const fnode * binop(op o, const fnode *f, const fnode *g)
bool is_sere_formula() const
Definition: formula.hh:402
op
Operator types.
Definition: formula.hh:62
bool is_tt() const
Definition: formula.hh:282
const fnode *const * end() const
Definition: formula.hh:250
op kind() const
Definition: formula.hh:156
bool is_eventual() const
Definition: formula.hh:414
unsigned min() const
Definition: formula.hh:214
bool is_universal() const
Definition: formula.hh:420
strong release (dual of weak until)
bool accepts_eword() const
Definition: formula.hh:462
static const fnode * multop(op o, std::vector< const fnode *> l)
bool is_Kleene_star() const
Definition: formula.hh:306