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(!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();
249 if (SPOT_UNLIKELY(op_ != op::FStar && op_ != op::Star))
250 report_min_invalid_arg();
257 if (SPOT_UNLIKELY(op_ != op::FStar && op_ != op::Star))
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);
311 return op_ == op::ff;
323 return op_ == op::tt;
335 return op_ == op::eword;
341 return op_ == op::ff || op_ == op::tt || op_ == op::eword;
349 return min_ == 0 && max_ == unbounded();
356 one_star_ =
new fnode(op::Star, tt_, 0, unbounded(),
true);
364 one_plus_ =
new fnode(op::Star, tt_, 1, unbounded(),
true);
372 std::ostream&
dump(std::ostream& os)
const;
382 while (pos < s && children[pos]->is_boolean())
415 return is_.sugar_free_boolean;
421 return is_.in_nenoform;
427 return is_.syntactic_si;
433 return is_.sugar_free_ltl;
439 return is_.ltl_formula;
445 return is_.psl_formula;
451 return is_.sere_formula;
469 return is_.universal;
475 return is_.syntactic_safety;
481 return is_.syntactic_guarantee;
487 return is_.syntactic_obligation;
493 return is_.syntactic_recurrence;
499 return is_.syntactic_persistence;
505 return !is_.not_marked;
511 return is_.accepting_eword;
517 return is_.lbt_atomic_props;
523 return is_.spin_atomic_props;
527 static size_t bump_next_id();
528 void setup_props(
op o);
529 void destroy_aux()
const;
531 [[noreturn]]
static void report_non_existing_child();
532 [[noreturn]]
static void report_too_many_children();
533 [[noreturn]]
static void
534 report_get_child_of_expecting_single_child_node();
535 [[noreturn]]
static void report_min_invalid_arg();
536 [[noreturn]]
static void report_max_invalid_arg();
549 fnode(
op o, iter begin, iter end,
bool saturated =
false)
564 saturated_(saturated)
566 size_t s = std::distance(begin, end);
567 if (SPOT_UNLIKELY(s > (
size_t) UINT16_MAX))
568 report_too_many_children();
571 for (
auto i = begin; i != end; ++i)
576 fnode(op o, std::initializer_list<const fnode*> l,
577 bool saturated =
false)
578 : fnode(o, l.begin(), l.end(), saturated)
582 fnode(op o,
const fnode* f, uint8_t min, uint8_t max,
583 bool saturated =
false)
584 : op_(o), min_(min), max_(max), saturated_(saturated), size_(1)
590 static const fnode* ff_;
591 static const fnode* tt_;
592 static const fnode* ew_;
593 static const fnode* one_star_;
594 static const fnode* one_plus_;
599 mutable uint8_t saturated_;
601 mutable uint16_t refs_ = 0;
603 static size_t next_id_;
621 bool sugar_free_boolean:1;
624 bool sugar_free_ltl:1;
631 bool syntactic_safety:1;
632 bool syntactic_guarantee:1;
633 bool syntactic_obligation:1;
634 bool syntactic_recurrence:1;
635 bool syntactic_persistence:1;
637 bool accepting_eword:1;
638 bool lbt_atomic_props:1;
639 bool spin_atomic_props:1;
648 const fnode* children[1];
658 operator()(
const fnode* left,
const fnode* right)
const
678 auto get_literal = [](
const fnode* f) ->
const fnode*
687 const fnode* litl = get_literal(left);
688 const fnode* litr = get_literal(right);
701 size_t l = left->
id();
702 size_t r = right->
id();
715 std::ostringstream old;
717 std::ostringstream ord;
719 return old.str() < ord.str();
800 const formula& operator=(formula&& f)
noexcept
802 std::swap(f.ptr_, ptr_);
806 bool operator<(
const formula& other)
const noexcept
808 if (SPOT_UNLIKELY(!other.ptr_))
810 if (SPOT_UNLIKELY(!ptr_))
812 if (
id() < other.id())
814 if (
id() > other.id())
820 return ptr_ < other.ptr_;
823 bool operator<=(
const formula& other)
const noexcept
825 return *
this == other || *
this < other;
828 bool operator>(
const formula& other)
const noexcept
830 return !(*
this <= other);
833 bool operator>=(
const formula& other)
const noexcept
835 return !(*
this < other);
838 bool operator==(
const formula& other)
const noexcept
840 return other.ptr_ == ptr_;
843 bool operator==(std::nullptr_t)
const noexcept
845 return ptr_ ==
nullptr;
848 bool operator!=(
const formula& other)
const noexcept
850 return other.ptr_ != ptr_;
853 bool operator!=(std::nullptr_t)
const noexcept
855 return ptr_ !=
nullptr;
858 explicit operator bool() const noexcept
860 return ptr_ !=
nullptr;
870 return fnode::unbounded();
876 return formula(fnode::ap(name));
886 if (SPOT_UNLIKELY(a.
kind() != op::ap))
887 report_ap_invalid_arg();
909#define SPOT_DEF_UNOP(Name) \
910 static formula Name(const formula& f) \
912 return unop(op::Name, f); \
915#define SPOT_DEF_UNOP(Name) \
916 static formula Name(const formula& f) \
918 return unop(op::Name, f); \
920 static formula Name(formula&& f) \
922 return unop(op::Name, std::move(f)); \
940 return nested_unop_range(op::X, op::Or , level, level, f);
943#if SPOT_WANT_STRONG_X
946 SPOT_DEF_UNOP(strong_X);
954 return nested_unop_range(op::strong_X, op::Or ,
972 return nested_unop_range(op::X, op::Or, min_level, max_level, f);
983 return nested_unop_range(op::X, op::And, min_level, max_level, f);
993 SPOT_DEF_UNOP(Closure);
998 SPOT_DEF_UNOP(NegClosure);
1003 SPOT_DEF_UNOP(NegClosureMarked);
1008 SPOT_DEF_UNOP(first_match);
1025 return formula(fnode::binop(o, f.ptr_->
clone(), g.to_node_()));
1042#define SPOT_DEF_BINOP(Name) \
1043 static formula Name(const formula& f, const formula& g) \
1045 return binop(op::Name, f, g); \
1048#define SPOT_DEF_BINOP(Name) \
1049 static formula Name(const formula& f, const formula& g) \
1051 return binop(op::Name, f, g); \
1053 static formula Name(const formula& f, formula&& g) \
1055 return binop(op::Name, f, std::move(g)); \
1057 static formula Name(formula&& f, const formula& g) \
1059 return binop(op::Name, std::move(f), g); \
1061 static formula Name(formula&& f, formula&& g) \
1063 return binop(op::Name, std::move(f), std::move(g)); \
1068 SPOT_DEF_BINOP(Xor);
1073 SPOT_DEF_BINOP(Implies);
1078 SPOT_DEF_BINOP(Equiv);
1103 SPOT_DEF_BINOP(EConcat);
1108 SPOT_DEF_BINOP(EConcatMarked);
1113 SPOT_DEF_BINOP(UConcat);
1115#undef SPOT_DEF_BINOP
1124 std::vector<const fnode*> tmp;
1125 tmp.reserve(l.size());
1128 tmp.emplace_back(f.ptr_->
clone());
1129 return formula(fnode::multop(o, std::move(tmp)));
1135 std::vector<const fnode*> tmp;
1136 tmp.reserve(l.size());
1140 return formula(fnode::multop(o, std::move(tmp)));
1146#define SPOT_DEF_MULTOP(Name) \
1147 static formula Name(const std::vector<formula>& l) \
1149 return multop(op::Name, l); \
1152#define SPOT_DEF_MULTOP(Name) \
1153 static formula Name(const std::vector<formula>& l) \
1155 return multop(op::Name, l); \
1158 static formula Name(std::vector<formula>&& l) \
1160 return multop(op::Name, std::move(l)); \
1165 SPOT_DEF_MULTOP(Or);
1170 SPOT_DEF_MULTOP(OrRat);
1175 SPOT_DEF_MULTOP(And);
1180 SPOT_DEF_MULTOP(AndRat);
1185 SPOT_DEF_MULTOP(AndNLM);
1190 SPOT_DEF_MULTOP(Concat);
1195 SPOT_DEF_MULTOP(Fusion);
1197#undef SPOT_DEF_MULTOP
1205 unsigned max = unbounded())
1207 return formula(fnode::bunop(o, f.ptr_->
clone(), min, max));
1213 unsigned max = unbounded())
1221#define SPOT_DEF_BUNOP(Name) \
1222 static formula Name(const formula& f, \
1223 unsigned min = 0U, \
1224 unsigned max = unbounded()) \
1226 return bunop(op::Name, f, min, max); \
1229#define SPOT_DEF_BUNOP(Name) \
1230 static formula Name(const formula& f, \
1231 unsigned min = 0U, \
1232 unsigned max = unbounded()) \
1234 return bunop(op::Name, f, min, max); \
1236 static formula Name(formula&& f, \
1237 unsigned min = 0U, \
1238 unsigned max = unbounded()) \
1240 return bunop(op::Name, std::move(f), min, max); \
1245 SPOT_DEF_BUNOP(Star);
1253 SPOT_DEF_BUNOP(FStar);
1255#undef SPOT_DEF_BUNOP
1271 return formula(fnode::nested_unop_range(uo, bo, min, max,
1311 unsigned min,
unsigned max);
1313 unsigned min,
unsigned max);
1337 return ptr_->kind();
1343 return ptr_->kindstr();
1356 return ptr_->is(o1, o2);
1362 return ptr_->is(o1, o2, o3);
1369 return ptr_->is(o1, o2, o3, o4);
1373 bool is(std::initializer_list<op> l)
const
1425 return ptr_->size();
1434 return ptr_->is_leaf();
1454 const fnode*
const* ptr_;
1468 return ptr_ == o.ptr_;
1473 return ptr_ != o.ptr_;
1478 return formula((*ptr_)->clone());
1498 return ptr_->begin();
1510 return formula(ptr_->nth(i)->clone());
1523 return ptr_->is_ff();
1535 return ptr_->is_tt();
1541 return formula(fnode::eword());
1547 return ptr_->is_eword();
1553 return ptr_->is_constant();
1562 return ptr_->is_Kleene_star();
1569 return formula(fnode::one_star());
1576 return formula(fnode::one_plus());
1583 return (is(op::ap) ||
1587 (is(op::Not) && is_boolean() && is_in_nenoform()));
1595 return ptr_->ap_name();
1602 std::ostream&
dump(std::ostream& os)
const
1604 return ptr_->dump(os);
1614 return formula(ptr_->all_but(i));
1628 return ptr_->boolean_count();
1646 return formula(ptr_->boolean_operands(width));
1649#define SPOT_DEF_PROP(Name) \
1652 return ptr_->Name(); \
1659 SPOT_DEF_PROP(is_boolean);
1661 SPOT_DEF_PROP(is_sugar_free_boolean);
1666 SPOT_DEF_PROP(is_in_nenoform);
1668 SPOT_DEF_PROP(is_syntactic_stutter_invariant);
1670 SPOT_DEF_PROP(is_sugar_free_ltl);
1672 SPOT_DEF_PROP(is_ltl_formula);
1674 SPOT_DEF_PROP(is_psl_formula);
1676 SPOT_DEF_PROP(is_sere_formula);
1679 SPOT_DEF_PROP(is_finite);
1687 SPOT_DEF_PROP(is_eventual);
1695 SPOT_DEF_PROP(is_universal);
1697 SPOT_DEF_PROP(is_syntactic_safety);
1699 SPOT_DEF_PROP(is_syntactic_guarantee);
1701 SPOT_DEF_PROP(is_syntactic_obligation);
1703 SPOT_DEF_PROP(is_syntactic_recurrence);
1705 SPOT_DEF_PROP(is_syntactic_persistence);
1708 SPOT_DEF_PROP(is_marked);
1710 SPOT_DEF_PROP(accepts_eword);
1716 SPOT_DEF_PROP(has_lbt_atomic_props);
1725 SPOT_DEF_PROP(has_spin_atomic_props);
1731 template<
typename Trans,
typename... Args>
1734 switch (
op o = kind())
1743#if SPOT_HAS_STRONG_X
1749 case op::NegClosure:
1750 case op::NegClosureMarked:
1751 case op::first_match:
1752 return unop(o, trans((*
this)[0], std::forward<Args>(args)...));
1761 case op::EConcatMarked:
1764 formula tmp = trans((*
this)[0], std::forward<Args>(args)...);
1765 return binop(o, tmp,
1766 trans((*
this)[1], std::forward<Args>(args)...));
1776 std::vector<formula> tmp;
1777 tmp.reserve(size());
1779 tmp.emplace_back(trans(f, std::forward<Args>(args)...));
1780 return multop(o, std::move(tmp));
1784 return bunop(o, trans((*
this)[0], std::forward<Args>(args)...),
1798 template<
typename Func,
typename... Args>
1801 if (func(*
this, std::forward<Args>(args)...))
1804 f.
traverse(func, std::forward<Args>(args)...);
1809 [[noreturn]]
static void report_ap_invalid_arg();
1816 bool abbreviated =
false);
1824 std::ostream& operator<<(std::ostream& os,
const formula& f);
Actual storage for formula nodes.
Definition formula.hh:128
std::string kindstr() const
const fnode * boolean_operands(unsigned *width=nullptr) const
bool is_boolean() const
Definition formula.hh:407
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:413
bool is_Kleene_star() const
Definition formula.hh:345
static const fnode * nested_unop_range(op uo, op bo, unsigned min, unsigned max, const fnode *f)
const fnode *const * end() const
Definition formula.hh:287
unsigned min() const
Definition formula.hh:247
bool is_syntactic_safety() const
Definition formula.hh:473
bool is_syntactic_stutter_invariant() const
Definition formula.hh:425
static const fnode * binop(op o, const fnode *f, const fnode *g)
unsigned size() const
Definition formula.hh:263
static constexpr uint8_t unbounded()
Definition formula.hh:158
const fnode * get_child_of(std::initializer_list< op > l) const
Definition formula.hh:234
unsigned max() const
Definition formula.hh:255
const fnode * get_child_of(op o) const
Definition formula.hh:224
const fnode * all_but(unsigned i) const
bool accepts_eword() const
Definition formula.hh:509
bool is_eventual() const
Definition formula.hh:461
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:521
bool is_eword() const
Definition formula.hh:333
bool is(op o1, op o2, op o3) const
Definition formula.hh:200
op kind() const
Definition formula.hh:180
const fnode * clone() const
Clone an fnode.
Definition formula.hh:134
bool has_lbt_atomic_props() const
Definition formula.hh:515
bool is_sugar_free_ltl() const
Definition formula.hh:431
const std::string & ap_name() const
bool is_syntactic_persistence() const
Definition formula.hh:497
unsigned boolean_count() const
Definition formula.hh:378
static const fnode * tt()
Definition formula.hh:315
bool is_universal() const
Definition formula.hh:467
bool is_tt() const
Definition formula.hh:321
bool is_constant() const
Definition formula.hh:339
bool is_syntactic_recurrence() const
Definition formula.hh:491
bool is(std::initializer_list< op > l) const
Definition formula.hh:210
bool is_syntactic_obligation() const
Definition formula.hh:485
static const fnode * unop(op o, const fnode *f)
const fnode * nth(unsigned i) const
Definition formula.hh:293
bool is_ltl_formula() const
Definition formula.hh:437
static const fnode * ff()
Definition formula.hh:303
bool is_finite() const
Definition formula.hh:455
bool is_psl_formula() const
Definition formula.hh:443
static const fnode * eword()
Definition formula.hh:327
bool is_marked() const
Definition formula.hh:503
std::ostream & dump(std::ostream &os) const
void destroy() const
Dereference an fnode.
Definition formula.hh:148
static const fnode * one_plus()
Definition formula.hh:361
static const fnode * ap(const std::string &name)
bool is(op o1, op o2) const
Definition formula.hh:195
bool is_in_nenoform() const
Definition formula.hh:419
static const fnode * bunop(op o, const fnode *f, unsigned min, unsigned max=unbounded())
bool is_syntactic_guarantee() const
Definition formula.hh:479
static const fnode * multop(op o, std::vector< const fnode * > l)
bool is_sere_formula() const
Definition formula.hh:449
static const fnode * one_star()
Definition formula.hh:353
const fnode *const * begin() const
Definition formula.hh:281
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)
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.