45#include <spot/misc/common.hh>
48#include <initializer_list>
62#if defined(SPOT_BUILD) || defined(SPOT_USES_STRONG_X)
65# define SPOT_HAS_STRONG_X 1
68# define SPOT_WANT_STRONG_X 1
77 enum class op: uint8_t
114#ifdef SPOT_WANT_STRONG_X
137 if (SPOT_UNLIKELY(!refs_))
149 if (SPOT_LIKELY(refs_))
151 else if (SPOT_LIKELY(!saturated_))
163 static const fnode*
ap(
const std::string& name);
172 unsigned min,
unsigned max = unbounded());
176 unsigned max,
const fnode* f);
196 return op_ == o1 || op_ == o2;
201 return op_ == o1 || op_ == o2 || op_ == o3;
206 return op_ == o1 || op_ == o2 || op_ == o3 || op_ == o4;
209 bool is(std::initializer_list<op> l)
const
211 const fnode* n =
this;
227 if (SPOT_UNLIKELY(size_ != 1))
228 report_get_child_of_expecting_single_child_node();
249 report_min_invalid_arg();
257 report_max_invalid_arg();
288 return children + size();
294 if (SPOT_UNLIKELY(i >= size()))
295 report_non_existing_child();
296 const fnode* c = children[i];
297 SPOT_ASSUME(c !=
nullptr);
348 return min_ == 0 && max_ == unbounded();
371 std::ostream&
dump(std::ostream& os)
const;
381 while (pos < s && children[pos]->is_boolean())
414 return is_.sugar_free_boolean;
420 return is_.in_nenoform;
426 return is_.syntactic_si;
432 return is_.sugar_free_ltl;
438 return is_.ltl_formula;
444 return is_.psl_formula;
450 return is_.sere_formula;
468 return is_.universal;
474 return is_.syntactic_safety;
480 return is_.syntactic_guarantee;
486 return is_.syntactic_obligation;
492 return is_.syntactic_recurrence;
498 return is_.syntactic_persistence;
504 return !is_.not_marked;
510 return is_.accepting_eword;
516 return is_.lbt_atomic_props;
522 return is_.spin_atomic_props;
550 static size_t bump_next_id();
551 void setup_props(
op o);
552 void destroy_aux()
const;
554 [[noreturn]]
static void report_non_existing_child();
555 [[noreturn]]
static void report_too_many_children();
556 [[noreturn]]
static void
557 report_get_child_of_expecting_single_child_node();
558 [[noreturn]]
static void report_min_invalid_arg();
559 [[noreturn]]
static void report_max_invalid_arg();
572 fnode(
op o, iter begin, iter end,
bool saturated =
false)
587 saturated_(saturated)
589 size_t s = std::distance(begin, end);
590 if (SPOT_UNLIKELY(s > (
size_t) UINT16_MAX))
591 report_too_many_children();
594 for (
auto i = begin; i != end; ++i)
599 fnode(
op o, std::initializer_list<const fnode*> l,
600 bool saturated =
false)
601 : fnode(o, l.begin(), l.end(), saturated)
605 fnode(
op o,
const fnode* f, uint8_t min, uint8_t max,
606 bool saturated =
false)
607 : op_(o), min_(min), max_(max), saturated_(saturated), size_(1)
613 static const fnode* ff_;
614 static const fnode* tt_;
615 static const fnode* ew_;
616 static const fnode* one_star_;
617 static const fnode* one_plus_;
622 mutable uint8_t saturated_;
624 mutable uint16_t refs_ = 0;
626 static size_t next_id_;
644 bool sugar_free_boolean:1;
647 bool sugar_free_ltl:1;
654 bool syntactic_safety:1;
655 bool syntactic_guarantee:1;
656 bool syntactic_obligation:1;
657 bool syntactic_recurrence:1;
658 bool syntactic_persistence:1;
660 bool accepting_eword:1;
661 bool lbt_atomic_props:1;
662 bool spin_atomic_props:1;
675 const fnode* children[1];
687 operator()(
const fnode* left,
const fnode* right)
const
707 auto get_literal = [](
const fnode* f) ->
const fnode*
716 const fnode* litl = get_literal(left);
717 const fnode* litr = get_literal(right);
730 size_t l = left->
id();
731 size_t r = right->
id();
744 std::ostringstream old;
746 std::ostringstream ord;
748 return old.str() < ord.str();
833 const formula& operator=(formula&& f)
noexcept
835 std::swap(f.ptr_, ptr_);
839 bool operator<(
const formula& other)
const noexcept
841 if (SPOT_UNLIKELY(!other.ptr_))
843 if (SPOT_UNLIKELY(!ptr_))
845 if (
id() < other.id())
847 if (
id() > other.id())
853 return ptr_ < other.ptr_;
856 bool operator<=(
const formula& other)
const noexcept
858 return *
this == other || *
this < other;
861 bool operator>(
const formula& other)
const noexcept
863 return !(*
this <= other);
866 bool operator>=(
const formula& other)
const noexcept
868 return !(*
this < other);
871 bool operator==(
const formula& other)
const noexcept
873 return other.ptr_ == ptr_;
876 bool operator==(std::nullptr_t)
const noexcept
878 return ptr_ ==
nullptr;
881 bool operator!=(
const formula& other)
const noexcept
883 return other.ptr_ != ptr_;
886 bool operator!=(std::nullptr_t)
const noexcept
888 return ptr_ !=
nullptr;
891 explicit operator bool() const noexcept
893 return ptr_ !=
nullptr;
920 report_ap_invalid_arg();
942#define SPOT_DEF_UNOP(Name) \
943 static formula Name(const formula& f) \
945 return unop(op::Name, f); \
948#define SPOT_DEF_UNOP(Name) \
949 static formula Name(const formula& f) \
951 return unop(op::Name, f); \
953 static formula Name(formula&& f) \
955 return unop(op::Name, std::move(f)); \
973 return nested_unop_range(
op::X,
op::Or , level, level, f);
976#if SPOT_WANT_STRONG_X
979 SPOT_DEF_UNOP(strong_X);
987 return nested_unop_range(op::strong_X,
op::Or ,
1005 return nested_unop_range(
op::X,
op::Or, min_level, max_level, f);
1016 return nested_unop_range(
op::X,
op::And, min_level, max_level, f);
1026 SPOT_DEF_UNOP(Closure);
1031 SPOT_DEF_UNOP(NegClosure);
1036 SPOT_DEF_UNOP(NegClosureMarked);
1041 SPOT_DEF_UNOP(first_match);
1075#define SPOT_DEF_BINOP(Name) \
1076 static formula Name(const formula& f, const formula& g) \
1078 return binop(op::Name, f, g); \
1081#define SPOT_DEF_BINOP(Name) \
1082 static formula Name(const formula& f, const formula& g) \
1084 return binop(op::Name, f, g); \
1086 static formula Name(const formula& f, formula&& g) \
1088 return binop(op::Name, f, std::move(g)); \
1090 static formula Name(formula&& f, const formula& g) \
1092 return binop(op::Name, std::move(f), g); \
1094 static formula Name(formula&& f, formula&& g) \
1096 return binop(op::Name, std::move(f), std::move(g)); \
1101 SPOT_DEF_BINOP(Xor);
1106 SPOT_DEF_BINOP(Implies);
1111 SPOT_DEF_BINOP(Equiv);
1136 SPOT_DEF_BINOP(EConcat);
1141 SPOT_DEF_BINOP(EConcatMarked);
1146 SPOT_DEF_BINOP(UConcat);
1148#undef SPOT_DEF_BINOP
1157 std::vector<const fnode*> tmp;
1158 tmp.reserve(l.size());
1161 tmp.emplace_back(f.ptr_->
clone());
1168 std::vector<const fnode*> tmp;
1169 tmp.reserve(l.size());
1179#define SPOT_DEF_MULTOP(Name) \
1180 static formula Name(const std::vector<formula>& l) \
1182 return multop(op::Name, l); \
1185#define SPOT_DEF_MULTOP(Name) \
1186 static formula Name(const std::vector<formula>& l) \
1188 return multop(op::Name, l); \
1191 static formula Name(std::vector<formula>&& l) \
1193 return multop(op::Name, std::move(l)); \
1198 SPOT_DEF_MULTOP(Or);
1203 SPOT_DEF_MULTOP(OrRat);
1208 SPOT_DEF_MULTOP(And);
1213 SPOT_DEF_MULTOP(AndRat);
1218 SPOT_DEF_MULTOP(AndNLM);
1223 SPOT_DEF_MULTOP(Concat);
1228 SPOT_DEF_MULTOP(Fusion);
1230#undef SPOT_DEF_MULTOP
1238 unsigned max = unbounded())
1246 unsigned max = unbounded())
1254#define SPOT_DEF_BUNOP(Name) \
1255 static formula Name(const formula& f, \
1256 unsigned min = 0U, \
1257 unsigned max = unbounded()) \
1259 return bunop(op::Name, f, min, max); \
1262#define SPOT_DEF_BUNOP(Name) \
1263 static formula Name(const formula& f, \
1264 unsigned min = 0U, \
1265 unsigned max = unbounded()) \
1267 return bunop(op::Name, f, min, max); \
1269 static formula Name(formula&& f, \
1270 unsigned min = 0U, \
1271 unsigned max = unbounded()) \
1273 return bunop(op::Name, std::move(f), min, max); \
1278 SPOT_DEF_BUNOP(Star);
1286 SPOT_DEF_BUNOP(FStar);
1288#undef SPOT_DEF_BUNOP
1344 unsigned min,
unsigned max);
1346 unsigned min,
unsigned max);
1370 return ptr_->kind();
1376 return ptr_->kindstr();
1389 return ptr_->is(o1, o2);
1395 return ptr_->is(o1, o2, o3);
1402 return ptr_->is(o1, o2, o3, o4);
1406 bool is(std::initializer_list<op> l)
const
1458 return ptr_->size();
1467 return ptr_->is_leaf();
1487 const fnode*
const* ptr_;
1501 return ptr_ == o.ptr_;
1506 return ptr_ != o.ptr_;
1511 return formula((*ptr_)->clone());
1531 return ptr_->begin();
1543 return formula(ptr_->nth(i)->clone());
1556 return ptr_->is_ff();
1568 return ptr_->is_tt();
1580 return ptr_->is_eword();
1586 return ptr_->is_constant();
1595 return ptr_->is_Kleene_star();
1620 (is(
op::Not) && is_boolean() && is_in_nenoform()));
1628 return ptr_->ap_name();
1635 std::ostream&
dump(std::ostream& os)
const
1637 return ptr_->dump(os);
1647 return formula(ptr_->all_but(i));
1661 return ptr_->boolean_count();
1679 return formula(ptr_->boolean_operands(width));
1682#define SPOT_DEF_PROP(Name) \
1685 return ptr_->Name(); \
1692 SPOT_DEF_PROP(is_boolean);
1694 SPOT_DEF_PROP(is_sugar_free_boolean);
1699 SPOT_DEF_PROP(is_in_nenoform);
1701 SPOT_DEF_PROP(is_syntactic_stutter_invariant);
1703 SPOT_DEF_PROP(is_sugar_free_ltl);
1705 SPOT_DEF_PROP(is_ltl_formula);
1707 SPOT_DEF_PROP(is_psl_formula);
1709 SPOT_DEF_PROP(is_sere_formula);
1712 SPOT_DEF_PROP(is_finite);
1720 SPOT_DEF_PROP(is_eventual);
1732 SPOT_DEF_PROP(is_syntactic_safety);
1736 SPOT_DEF_PROP(is_syntactic_guarantee);
1741 SPOT_DEF_PROP(is_delta1);
1746 SPOT_DEF_PROP(is_syntactic_obligation);
1748 SPOT_DEF_PROP(is_sigma2);
1750 SPOT_DEF_PROP(is_pi2);
1755 SPOT_DEF_PROP(is_syntactic_recurrence);
1760 SPOT_DEF_PROP(is_syntactic_persistence);
1765 SPOT_DEF_PROP(is_delta2);
1768 SPOT_DEF_PROP(is_marked);
1770 SPOT_DEF_PROP(accepts_eword);
1776 SPOT_DEF_PROP(has_lbt_atomic_props);
1785 SPOT_DEF_PROP(has_spin_atomic_props);
1791 template<
typename Trans,
typename... Args>
1794 switch (
op o = kind())
1803#if SPOT_HAS_STRONG_X
1812 return unop(o, trans((*
this)[0], std::forward<Args>(args)...));
1824 formula tmp = trans((*
this)[0], std::forward<Args>(args)...);
1825 return binop(o, tmp,
1826 trans((*
this)[1], std::forward<Args>(args)...));
1836 std::vector<formula> tmp;
1837 tmp.reserve(size());
1839 tmp.emplace_back(trans(f, std::forward<Args>(args)...));
1840 return multop(o, std::move(tmp));
1844 return bunop(o, trans((*
this)[0], std::forward<Args>(args)...),
1858 template<
typename Func,
typename... Args>
1861 if (func(*
this, std::forward<Args>(args)...))
1864 f.
traverse(func, std::forward<Args>(args)...);
1869 [[noreturn]]
static void report_ap_invalid_arg();
1876 bool abbreviated =
false);
1884 std::ostream& operator<<(std::ostream& os,
const formula& f);
Actual storage for formula nodes.
Definition: formula.hh:127
bool is_pi2() const
Definition: formula.hh:532
std::string kindstr() const
const fnode * boolean_operands(unsigned *width=nullptr) const
bool is_boolean() const
Definition: formula.hh:406
size_t id() const
Definition: formula.hh:274
bool is_ff() const
Definition: formula.hh:308
bool is_sugar_free_boolean() const
Definition: formula.hh:412
bool is_Kleene_star() const
Definition: formula.hh:344
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:286
unsigned min() const
Definition: formula.hh:246
bool is_syntactic_safety() const
Definition: formula.hh:472
bool is_syntactic_stutter_invariant() const
Definition: formula.hh:424
static const fnode * binop(op o, const fnode *f, const fnode *g)
bool is_delta2() const
Definition: formula.hh:544
unsigned size() const
Definition: formula.hh:262
static constexpr uint8_t unbounded()
Definition: formula.hh:157
const fnode * get_child_of(std::initializer_list< op > l) const
Definition: formula.hh:233
unsigned max() const
Definition: formula.hh:254
const fnode * get_child_of(op o) const
Definition: formula.hh:223
const fnode * all_but(unsigned i) const
bool accepts_eword() const
Definition: formula.hh:508
bool is_eventual() const
Definition: formula.hh:460
bool is(op o1, op o2, op o3, op o4) const
Definition: formula.hh:204
static bool instances_check()
safety check for the reference counters
bool is_leaf() const
Definition: formula.hh:268
bool has_spin_atomic_props() const
Definition: formula.hh:520
bool is_eword() const
Definition: formula.hh:332
bool is(op o1, op o2, op o3) const
Definition: formula.hh:199
op kind() const
Definition: formula.hh:179
const fnode * clone() const
Clone an fnode.
Definition: formula.hh:133
bool has_lbt_atomic_props() const
Definition: formula.hh:514
bool is_sugar_free_ltl() const
Definition: formula.hh:430
const std::string & ap_name() const
bool is_syntactic_persistence() const
Definition: formula.hh:496
unsigned boolean_count() const
Definition: formula.hh:377
static const fnode * tt()
Definition: formula.hh:314
bool is_universal() const
Definition: formula.hh:466
bool is_tt() const
Definition: formula.hh:320
bool is_constant() const
Definition: formula.hh:338
bool is_syntactic_recurrence() const
Definition: formula.hh:490
bool is(std::initializer_list< op > l) const
Definition: formula.hh:209
bool is_syntactic_obligation() const
Definition: formula.hh:484
static const fnode * unop(op o, const fnode *f)
const fnode * nth(unsigned i) const
Definition: formula.hh:292
bool is_ltl_formula() const
Definition: formula.hh:436
static const fnode * ff()
Definition: formula.hh:302
bool is_finite() const
Definition: formula.hh:454
bool is_sigma2() const
Definition: formula.hh:526
bool is_psl_formula() const
Definition: formula.hh:442
bool is_delta1() const
Definition: formula.hh:538
static const fnode * eword()
Definition: formula.hh:326
bool is_marked() const
Definition: formula.hh:502
std::ostream & dump(std::ostream &os) const
void destroy() const
Dereference an fnode.
Definition: formula.hh:147
static const fnode * one_plus()
Definition: formula.hh:360
static const fnode * ap(const std::string &name)
bool is(op o1, op o2) const
Definition: formula.hh:194
bool is_in_nenoform() const
Definition: formula.hh:418
static const fnode * bunop(op o, const fnode *f, unsigned min, unsigned max=unbounded())
bool is_syntactic_guarantee() const
Definition: formula.hh:478
static const fnode * multop(op o, std::vector< const fnode * > l)
bool is_sere_formula() const
Definition: formula.hh:448
static const fnode * one_star()
Definition: formula.hh:352
const fnode *const * begin() const
Definition: formula.hh:280
bool is(op o) const
Definition: formula.hh:189
op
Operator types.
Definition: formula.hh:78
@ 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:26
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.