46 #include <spot/misc/common.hh>
49 #include <initializer_list>
63 #if defined(SPOT_BUILD) or defined(SPOT_USES_STRONG_X)
66 # define SPOT_HAS_STRONG_X 1
69 # define SPOT_WANT_STRONG_X 1
78 enum class op: uint8_t
115 #ifdef SPOT_WANT_STRONG_X
138 if (SPOT_UNLIKELY(!refs_))
150 if (SPOT_LIKELY(refs_))
152 else if (SPOT_LIKELY(id_ > 2) && SPOT_LIKELY(!saturated_))
164 static const fnode*
ap(
const std::string& name);
173 unsigned min,
unsigned max = unbounded());
177 unsigned max,
const fnode* f);
197 return op_ == o1 || op_ == o2;
202 return op_ == o1 || op_ == o2 || op_ == o3;
207 return op_ == o1 || op_ == o2 || op_ == o3 || op_ == o4;
210 bool is(std::initializer_list<op> l)
const
212 const fnode* n =
this;
228 if (SPOT_UNLIKELY(size_ != 1))
229 report_get_child_of_expecting_single_child_node();
250 report_min_invalid_arg();
258 report_max_invalid_arg();
289 return children + size();
295 if (SPOT_UNLIKELY(i >= size()))
296 report_non_existing_child();
297 const fnode* c = children[i];
298 SPOT_ASSUME(c !=
nullptr);
349 return min_ == 0 && max_ == unbounded();
364 std::ostream&
dump(std::ostream& os)
const;
374 while (pos < s && children[pos]->is_boolean())
407 return is_.sugar_free_boolean;
413 return is_.in_nenoform;
419 return is_.syntactic_si;
425 return is_.sugar_free_ltl;
431 return is_.ltl_formula;
437 return is_.psl_formula;
443 return is_.sere_formula;
461 return is_.universal;
467 return is_.syntactic_safety;
473 return is_.syntactic_guarantee;
479 return is_.syntactic_obligation;
485 return is_.syntactic_recurrence;
491 return is_.syntactic_persistence;
497 return !is_.not_marked;
503 return is_.accepting_eword;
509 return is_.lbt_atomic_props;
515 return is_.spin_atomic_props;
519 static size_t bump_next_id();
520 void setup_props(
op o);
521 void destroy_aux()
const;
523 [[noreturn]]
static void report_non_existing_child();
524 [[noreturn]]
static void report_too_many_children();
525 [[noreturn]]
static void
526 report_get_child_of_expecting_single_child_node();
527 [[noreturn]]
static void report_min_invalid_arg();
528 [[noreturn]]
static void report_max_invalid_arg();
541 fnode(
op o, iter begin, iter end)
558 size_t s = std::distance(begin, end);
559 if (SPOT_UNLIKELY(s > (
size_t) UINT16_MAX))
560 report_too_many_children();
563 for (
auto i = begin; i != end; ++i)
568 fnode(
op o, std::initializer_list<const fnode*> l)
569 : fnode(o, l.begin(), l.end())
573 fnode(
op o,
const fnode* f, uint8_t min, uint8_t max)
574 : op_(o), min_(min), max_(max), saturated_(0), size_(1)
580 static const fnode* ff_;
581 static const fnode* tt_;
582 static const fnode* ew_;
583 static const fnode* one_star_;
588 mutable uint8_t saturated_;
590 mutable uint16_t refs_ = 0;
592 static size_t next_id_;
610 bool sugar_free_boolean:1;
613 bool sugar_free_ltl:1;
620 bool syntactic_safety:1;
621 bool syntactic_guarantee:1;
622 bool syntactic_obligation:1;
623 bool syntactic_recurrence:1;
624 bool syntactic_persistence:1;
626 bool accepting_eword:1;
627 bool lbt_atomic_props:1;
628 bool spin_atomic_props:1;
637 const fnode* children[1];
647 operator()(
const fnode* left,
const fnode* right)
const
667 auto get_literal = [](
const fnode* f) ->
const fnode*
676 const fnode* litl = get_literal(left);
677 const fnode* litr = get_literal(right);
690 size_t l = left->
id();
691 size_t r = right->
id();
704 std::ostringstream old;
706 std::ostringstream ord;
708 return old.str() < ord.str();
789 const formula& operator=(formula&& f) noexcept
791 std::swap(f.ptr_, ptr_);
795 bool operator<(
const formula& other)
const noexcept
797 if (SPOT_UNLIKELY(!other.ptr_))
799 if (SPOT_UNLIKELY(!ptr_))
801 if (
id() < other.id())
803 if (
id() > other.id())
809 return ptr_ < other.ptr_;
812 bool operator<=(
const formula& other)
const noexcept
814 return *
this == other || *
this < other;
817 bool operator>(
const formula& other)
const noexcept
819 return !(*
this <= other);
822 bool operator>=(
const formula& other)
const noexcept
824 return !(*
this < other);
827 bool operator==(
const formula& other)
const noexcept
829 return other.ptr_ == ptr_;
832 bool operator==(std::nullptr_t)
const noexcept
834 return ptr_ ==
nullptr;
837 bool operator!=(
const formula& other)
const noexcept
839 return other.ptr_ != ptr_;
842 bool operator!=(std::nullptr_t)
const noexcept
844 return ptr_ !=
nullptr;
847 explicit operator bool() const noexcept
849 return ptr_ !=
nullptr;
876 report_ap_invalid_arg();
898 #define SPOT_DEF_UNOP(Name) \
899 static formula Name(const formula& f) \
901 return unop(op::Name, f); \
904 #define SPOT_DEF_UNOP(Name) \
905 static formula Name(const formula& f) \
907 return unop(op::Name, f); \
909 static formula Name(formula&& f) \
911 return unop(op::Name, std::move(f)); \
929 return nested_unop_range(
op::X,
op::Or , level, level, f);
932 #if SPOT_WANT_STRONG_X
935 SPOT_DEF_UNOP(strong_X);
943 return nested_unop_range(op::strong_X,
op::Or ,
961 return nested_unop_range(
op::X,
op::Or, min_level, max_level, f);
972 return nested_unop_range(
op::X,
op::And, min_level, max_level, f);
982 SPOT_DEF_UNOP(Closure);
987 SPOT_DEF_UNOP(NegClosure);
992 SPOT_DEF_UNOP(NegClosureMarked);
997 SPOT_DEF_UNOP(first_match);
1031 #define SPOT_DEF_BINOP(Name) \
1032 static formula Name(const formula& f, const formula& g) \
1034 return binop(op::Name, f, g); \
1037 #define SPOT_DEF_BINOP(Name) \
1038 static formula Name(const formula& f, const formula& g) \
1040 return binop(op::Name, f, g); \
1042 static formula Name(const formula& f, formula&& g) \
1044 return binop(op::Name, f, std::move(g)); \
1046 static formula Name(formula&& f, const formula& g) \
1048 return binop(op::Name, std::move(f), g); \
1050 static formula Name(formula&& f, formula&& g) \
1052 return binop(op::Name, std::move(f), std::move(g)); \
1057 SPOT_DEF_BINOP(Xor);
1062 SPOT_DEF_BINOP(Implies);
1067 SPOT_DEF_BINOP(Equiv);
1092 SPOT_DEF_BINOP(EConcat);
1097 SPOT_DEF_BINOP(EConcatMarked);
1102 SPOT_DEF_BINOP(UConcat);
1104 #undef SPOT_DEF_BINOP
1113 std::vector<const fnode*> tmp;
1114 tmp.reserve(l.size());
1117 tmp.emplace_back(f.ptr_->
clone());
1124 std::vector<const fnode*> tmp;
1125 tmp.reserve(l.size());
1135 #define SPOT_DEF_MULTOP(Name) \
1136 static formula Name(const std::vector<formula>& l) \
1138 return multop(op::Name, l); \
1141 #define SPOT_DEF_MULTOP(Name) \
1142 static formula Name(const std::vector<formula>& l) \
1144 return multop(op::Name, l); \
1147 static formula Name(std::vector<formula>&& l) \
1149 return multop(op::Name, std::move(l)); \
1154 SPOT_DEF_MULTOP(Or);
1159 SPOT_DEF_MULTOP(OrRat);
1164 SPOT_DEF_MULTOP(And);
1169 SPOT_DEF_MULTOP(AndRat);
1174 SPOT_DEF_MULTOP(AndNLM);
1179 SPOT_DEF_MULTOP(Concat);
1184 SPOT_DEF_MULTOP(Fusion);
1186 #undef SPOT_DEF_MULTOP
1194 unsigned max = unbounded())
1202 unsigned max = unbounded())
1210 #define SPOT_DEF_BUNOP(Name) \
1211 static formula Name(const formula& f, \
1212 unsigned min = 0U, \
1213 unsigned max = unbounded()) \
1215 return bunop(op::Name, f, min, max); \
1218 #define SPOT_DEF_BUNOP(Name) \
1219 static formula Name(const formula& f, \
1220 unsigned min = 0U, \
1221 unsigned max = unbounded()) \
1223 return bunop(op::Name, f, min, max); \
1225 static formula Name(formula&& f, \
1226 unsigned min = 0U, \
1227 unsigned max = unbounded()) \
1229 return bunop(op::Name, std::move(f), min, max); \
1234 SPOT_DEF_BUNOP(Star);
1242 SPOT_DEF_BUNOP(FStar);
1244 #undef SPOT_DEF_BUNOP
1300 unsigned min,
unsigned max);
1302 unsigned min,
unsigned max);
1326 return ptr_->kind();
1332 return ptr_->kindstr();
1345 return ptr_->is(o1, o2);
1351 return ptr_->is(o1, o2, o3);
1358 return ptr_->is(o1, o2, o3, o4);
1362 bool is(std::initializer_list<op> l)
const
1414 return ptr_->size();
1423 return ptr_->is_leaf();
1443 const fnode*
const* ptr_;
1457 return ptr_ == o.ptr_;
1462 return ptr_ != o.ptr_;
1467 return formula((*ptr_)->clone());
1487 return ptr_->begin();
1499 return formula(ptr_->nth(i)->clone());
1512 return ptr_->is_ff();
1524 return ptr_->is_tt();
1536 return ptr_->is_eword();
1542 return ptr_->is_constant();
1551 return ptr_->is_Kleene_star();
1568 (is(
op::Not) && is_boolean() && is_in_nenoform()));
1576 return ptr_->ap_name();
1583 std::ostream&
dump(std::ostream& os)
const
1585 return ptr_->dump(os);
1595 return formula(ptr_->all_but(i));
1609 return ptr_->boolean_count();
1627 return formula(ptr_->boolean_operands(width));
1630 #define SPOT_DEF_PROP(Name) \
1633 return ptr_->Name(); \
1640 SPOT_DEF_PROP(is_boolean);
1642 SPOT_DEF_PROP(is_sugar_free_boolean);
1647 SPOT_DEF_PROP(is_in_nenoform);
1649 SPOT_DEF_PROP(is_syntactic_stutter_invariant);
1651 SPOT_DEF_PROP(is_sugar_free_ltl);
1653 SPOT_DEF_PROP(is_ltl_formula);
1655 SPOT_DEF_PROP(is_psl_formula);
1657 SPOT_DEF_PROP(is_sere_formula);
1660 SPOT_DEF_PROP(is_finite);
1668 SPOT_DEF_PROP(is_eventual);
1678 SPOT_DEF_PROP(is_syntactic_safety);
1680 SPOT_DEF_PROP(is_syntactic_guarantee);
1682 SPOT_DEF_PROP(is_syntactic_obligation);
1684 SPOT_DEF_PROP(is_syntactic_recurrence);
1686 SPOT_DEF_PROP(is_syntactic_persistence);
1689 SPOT_DEF_PROP(is_marked);
1691 SPOT_DEF_PROP(accepts_eword);
1697 SPOT_DEF_PROP(has_lbt_atomic_props);
1706 SPOT_DEF_PROP(has_spin_atomic_props);
1707 #undef SPOT_DEF_PROP
1712 template<
typename Trans,
typename... Args>
1715 switch (
op o = kind())
1724 #if SPOT_HAS_STRONG_X
1733 return unop(o, trans((*
this)[0], std::forward<Args>(args)...));
1745 formula tmp = trans((*
this)[0], std::forward<Args>(args)...);
1746 return binop(o, tmp,
1747 trans((*
this)[1], std::forward<Args>(args)...));
1757 std::vector<formula> tmp;
1758 tmp.reserve(size());
1760 tmp.emplace_back(trans(f, std::forward<Args>(args)...));
1761 return multop(o, std::move(tmp));
1765 return bunop(o, trans((*
this)[0], std::forward<Args>(args)...),
1779 template<
typename Func,
typename... Args>
1782 if (func(*
this, std::forward<Args>(args)...))
1785 f.
traverse(func, std::forward<Args>(args)...);
1790 [[noreturn]]
static void report_ap_invalid_arg();
1797 bool abbreviated =
false);
1805 std::ostream& operator<<(std::ostream& os,
const formula& f);
Actual storage for formula nodes.
Definition: formula.hh:128
const fnode *const * begin() const
Definition: formula.hh:281
const fnode *const * end() const
Definition: formula.hh:287
std::string kindstr() const
std::ostream & dump(std::ostream &os) const
bool is_boolean() const
Definition: formula.hh:399
size_t id() const
Definition: formula.hh:275
bool is_ff() const
Definition: formula.hh:309
bool is_sugar_free_boolean() const
Definition: formula.hh:405
bool is_Kleene_star() const
Definition: formula.hh:345
unsigned min() const
Definition: formula.hh:247
bool is_syntactic_safety() const
Definition: formula.hh:465
bool is_syntactic_stutter_invariant() const
Definition: formula.hh:417
unsigned size() const
Definition: formula.hh:263
static constexpr uint8_t unbounded()
Definition: formula.hh:158
static const fnode * eword()
Definition: formula.hh:327
const fnode * get_child_of(op o) const
Definition: formula.hh:224
unsigned max() const
Definition: formula.hh:255
static const fnode * ff()
Definition: formula.hh:303
const fnode * boolean_operands(unsigned *width=nullptr) const
bool accepts_eword() const
Definition: formula.hh:501
bool is_eventual() const
Definition: formula.hh:453
const std::string & ap_name() const
bool is(op o1, op o2, op o3, op o4) const
Definition: formula.hh:205
static bool instances_check()
safety check for the reference counters
bool is_leaf() const
Definition: formula.hh:269
bool has_spin_atomic_props() const
Definition: formula.hh:513
bool is_eword() const
Definition: formula.hh:333
static const fnode * tt()
Definition: formula.hh:315
bool is(op o1, op o2, op o3) const
Definition: formula.hh:200
op kind() const
Definition: formula.hh:180
bool has_lbt_atomic_props() const
Definition: formula.hh:507
bool is_sugar_free_ltl() const
Definition: formula.hh:423
bool is_syntactic_persistence() const
Definition: formula.hh:489
static const fnode * nested_unop_range(op uo, op bo, unsigned min, unsigned max, const fnode *f)
unsigned boolean_count() const
Definition: formula.hh:370
bool is_universal() const
Definition: formula.hh:459
bool is_tt() const
Definition: formula.hh:321
const fnode * get_child_of(std::initializer_list< op > l) const
Definition: formula.hh:234
const fnode * nth(unsigned i) const
Definition: formula.hh:293
bool is_constant() const
Definition: formula.hh:339
static const fnode * binop(op o, const fnode *f, const fnode *g)
static const fnode * one_star()
Definition: formula.hh:353
const fnode * all_but(unsigned i) const
bool is_syntactic_recurrence() const
Definition: formula.hh:483
bool is(std::initializer_list< op > l) const
Definition: formula.hh:210
bool is_syntactic_obligation() const
Definition: formula.hh:477
static const fnode * unop(op o, const fnode *f)
bool is_ltl_formula() const
Definition: formula.hh:429
bool is_finite() const
Definition: formula.hh:447
bool is_psl_formula() const
Definition: formula.hh:435
static const fnode * multop(op o, std::vector< const fnode * > l)
bool is_marked() const
Definition: formula.hh:495
void destroy() const
Dereference an fnode.
Definition: formula.hh:148
static const fnode * bunop(op o, const fnode *f, unsigned min, unsigned max=unbounded())
bool is(op o1, op o2) const
Definition: formula.hh:195
bool is_in_nenoform() const
Definition: formula.hh:411
static const fnode * ap(const std::string &name)
bool is_syntactic_guarantee() const
Definition: formula.hh:471
bool is_sere_formula() const
Definition: formula.hh:441
const fnode * clone() const
Clone an fnode.
Definition: formula.hh:134
bool is(op o) const
Definition: formula.hh:190
op
Operator types.
Definition: formula.hh:79
@ first_match
first_match(sere)
@ EConcatMarked
Seq, Marked.
@ NegClosure
Negated PSL Closure.
@ M
strong release (dual of weak until)
@ NegClosureMarked
marked version of the Negated PSL Closure
@ And
(omega-Rational) And
@ AndNLM
Non-Length-Matching Rational-And.
@ R
release (dual of until)
bool is_universal(const const_twa_graph_ptr &aut)
Return true iff aut is universal.
Definition: automata.hh:27
int atomic_prop_cmp(const fnode *f, const fnode *g)
Order two atomic propositions.
std::list< std::string > list_formula_props(const formula &f)
List the properties of formula f.
std::ostream & print_formula_props(std::ostream &out, const formula &f, bool abbreviated=false)
Print the properties of formula f on stream out.