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();
347 return min_ == 0 && max_ == unbounded();
362 std::ostream&
dump(std::ostream& os)
const;
372 while (pos < s && children[pos]->is_boolean())
405 return is_.sugar_free_boolean;
411 return is_.in_nenoform;
417 return is_.syntactic_si;
423 return is_.sugar_free_ltl;
429 return is_.ltl_formula;
435 return is_.psl_formula;
441 return is_.sere_formula;
459 return is_.universal;
465 return is_.syntactic_safety;
471 return is_.syntactic_guarantee;
477 return is_.syntactic_obligation;
483 return is_.syntactic_recurrence;
489 return is_.syntactic_persistence;
495 return !is_.not_marked;
501 return is_.accepting_eword;
507 return is_.lbt_atomic_props;
513 return is_.spin_atomic_props;
517 static size_t bump_next_id();
518 void setup_props(
op o);
519 void destroy_aux()
const;
521 [[noreturn]]
static void report_non_existing_child();
522 [[noreturn]]
static void report_too_many_children();
523 [[noreturn]]
static void
524 report_get_child_of_expecting_single_child_node();
525 [[noreturn]]
static void report_min_invalid_arg();
526 [[noreturn]]
static void report_max_invalid_arg();
539 fnode(
op o, iter begin, iter end)
556 size_t s = std::distance(begin, end);
557 if (SPOT_UNLIKELY(s > (
size_t) UINT16_MAX))
558 report_too_many_children();
561 for (
auto i = begin; i != end; ++i)
566 fnode(
op o, std::initializer_list<const fnode*> l)
567 : fnode(o, l.begin(), l.end())
571 fnode(
op o,
const fnode* f, uint8_t min, uint8_t max)
572 : op_(o), min_(min), max_(max), saturated_(0), size_(1)
578 static const fnode* ff_;
579 static const fnode* tt_;
580 static const fnode* ew_;
581 static const fnode* one_star_;
586 mutable uint8_t saturated_;
588 mutable uint16_t refs_ = 0;
590 static size_t next_id_;
608 bool sugar_free_boolean:1;
611 bool sugar_free_ltl:1;
618 bool syntactic_safety:1;
619 bool syntactic_guarantee:1;
620 bool syntactic_obligation:1;
621 bool syntactic_recurrence:1;
622 bool syntactic_persistence:1;
624 bool accepting_eword:1;
625 bool lbt_atomic_props:1;
626 bool spin_atomic_props:1;
635 const fnode* children[1];
645 operator()(
const fnode* left,
const fnode* right)
const
665 auto get_literal = [](
const fnode* f) ->
const fnode*
674 const fnode* litl = get_literal(left);
675 const fnode* litr = get_literal(right);
688 size_t l = left->
id();
689 size_t r = right->
id();
702 std::ostringstream old;
704 std::ostringstream ord;
706 return old.str() < ord.str();
787 const formula& operator=(formula&& f) noexcept
789 std::swap(f.ptr_, ptr_);
793 bool operator<(
const formula& other)
const noexcept
795 if (SPOT_UNLIKELY(!other.ptr_))
797 if (SPOT_UNLIKELY(!ptr_))
799 if (
id() < other.id())
801 if (
id() > other.id())
807 return ptr_ < other.ptr_;
810 bool operator<=(
const formula& other)
const noexcept
812 return *
this == other || *
this < other;
815 bool operator>(
const formula& other)
const noexcept
817 return !(*
this <= other);
820 bool operator>=(
const formula& other)
const noexcept
822 return !(*
this < other);
825 bool operator==(
const formula& other)
const noexcept
827 return other.ptr_ == ptr_;
830 bool operator==(std::nullptr_t)
const noexcept
832 return ptr_ ==
nullptr;
835 bool operator!=(
const formula& other)
const noexcept
837 return other.ptr_ != ptr_;
840 bool operator!=(std::nullptr_t)
const noexcept
842 return ptr_ !=
nullptr;
845 explicit operator bool() const noexcept
847 return ptr_ !=
nullptr;
874 report_ap_invalid_arg();
896 #define SPOT_DEF_UNOP(Name) \
897 static formula Name(const formula& f) \
899 return unop(op::Name, f); \
902 #define SPOT_DEF_UNOP(Name) \
903 static formula Name(const formula& f) \
905 return unop(op::Name, f); \
907 static formula Name(formula&& f) \
909 return unop(op::Name, std::move(f)); \
927 return nested_unop_range(
op::X,
op::Or , level, level, f);
930 #if SPOT_WANT_STRONG_X
933 SPOT_DEF_UNOP(strong_X);
941 return nested_unop_range(op::strong_X,
op::Or ,
959 return nested_unop_range(
op::X,
op::Or, min_level, max_level, f);
970 return nested_unop_range(
op::X,
op::And, min_level, max_level, f);
980 SPOT_DEF_UNOP(Closure);
985 SPOT_DEF_UNOP(NegClosure);
990 SPOT_DEF_UNOP(NegClosureMarked);
995 SPOT_DEF_UNOP(first_match);
1029 #define SPOT_DEF_BINOP(Name) \
1030 static formula Name(const formula& f, const formula& g) \
1032 return binop(op::Name, f, g); \
1035 #define SPOT_DEF_BINOP(Name) \
1036 static formula Name(const formula& f, const formula& g) \
1038 return binop(op::Name, f, g); \
1040 static formula Name(const formula& f, formula&& g) \
1042 return binop(op::Name, f, std::move(g)); \
1044 static formula Name(formula&& f, const formula& g) \
1046 return binop(op::Name, std::move(f), g); \
1048 static formula Name(formula&& f, formula&& g) \
1050 return binop(op::Name, std::move(f), std::move(g)); \
1055 SPOT_DEF_BINOP(Xor);
1060 SPOT_DEF_BINOP(Implies);
1065 SPOT_DEF_BINOP(Equiv);
1090 SPOT_DEF_BINOP(EConcat);
1095 SPOT_DEF_BINOP(EConcatMarked);
1100 SPOT_DEF_BINOP(UConcat);
1102 #undef SPOT_DEF_BINOP
1111 std::vector<const fnode*> tmp;
1112 tmp.reserve(l.size());
1115 tmp.emplace_back(f.ptr_->
clone());
1122 std::vector<const fnode*> tmp;
1123 tmp.reserve(l.size());
1133 #define SPOT_DEF_MULTOP(Name) \
1134 static formula Name(const std::vector<formula>& l) \
1136 return multop(op::Name, l); \
1139 #define SPOT_DEF_MULTOP(Name) \
1140 static formula Name(const std::vector<formula>& l) \
1142 return multop(op::Name, l); \
1145 static formula Name(std::vector<formula>&& l) \
1147 return multop(op::Name, std::move(l)); \
1152 SPOT_DEF_MULTOP(Or);
1157 SPOT_DEF_MULTOP(OrRat);
1162 SPOT_DEF_MULTOP(And);
1167 SPOT_DEF_MULTOP(AndRat);
1172 SPOT_DEF_MULTOP(AndNLM);
1177 SPOT_DEF_MULTOP(Concat);
1182 SPOT_DEF_MULTOP(Fusion);
1184 #undef SPOT_DEF_MULTOP
1192 unsigned max = unbounded())
1200 unsigned max = unbounded())
1208 #define SPOT_DEF_BUNOP(Name) \
1209 static formula Name(const formula& f, \
1210 unsigned min = 0U, \
1211 unsigned max = unbounded()) \
1213 return bunop(op::Name, f, min, max); \
1216 #define SPOT_DEF_BUNOP(Name) \
1217 static formula Name(const formula& f, \
1218 unsigned min = 0U, \
1219 unsigned max = unbounded()) \
1221 return bunop(op::Name, f, min, max); \
1223 static formula Name(formula&& f, \
1224 unsigned min = 0U, \
1225 unsigned max = unbounded()) \
1227 return bunop(op::Name, std::move(f), min, max); \
1232 SPOT_DEF_BUNOP(Star);
1240 SPOT_DEF_BUNOP(FStar);
1242 #undef SPOT_DEF_BUNOP
1298 unsigned min,
unsigned max);
1300 unsigned min,
unsigned max);
1324 return ptr_->kind();
1330 return ptr_->kindstr();
1343 return ptr_->is(o1, o2);
1349 return ptr_->is(o1, o2, o3);
1356 return ptr_->is(o1, o2, o3, o4);
1360 bool is(std::initializer_list<op> l)
const
1412 return ptr_->size();
1421 return ptr_->is_leaf();
1441 const fnode*
const* ptr_;
1455 return ptr_ == o.ptr_;
1460 return ptr_ != o.ptr_;
1465 return formula((*ptr_)->clone());
1485 return ptr_->begin();
1497 return formula(ptr_->nth(i)->clone());
1510 return ptr_->is_ff();
1522 return ptr_->is_tt();
1534 return ptr_->is_eword();
1540 return ptr_->is_constant();
1549 return ptr_->is_Kleene_star();
1566 (is(
op::Not) && is_boolean() && is_in_nenoform()));
1574 return ptr_->ap_name();
1581 std::ostream&
dump(std::ostream& os)
const
1583 return ptr_->dump(os);
1593 return formula(ptr_->all_but(i));
1607 return ptr_->boolean_count();
1625 return formula(ptr_->boolean_operands(width));
1628 #define SPOT_DEF_PROP(Name) \
1631 return ptr_->Name(); \
1638 SPOT_DEF_PROP(is_boolean);
1640 SPOT_DEF_PROP(is_sugar_free_boolean);
1645 SPOT_DEF_PROP(is_in_nenoform);
1647 SPOT_DEF_PROP(is_syntactic_stutter_invariant);
1649 SPOT_DEF_PROP(is_sugar_free_ltl);
1651 SPOT_DEF_PROP(is_ltl_formula);
1653 SPOT_DEF_PROP(is_psl_formula);
1655 SPOT_DEF_PROP(is_sere_formula);
1658 SPOT_DEF_PROP(is_finite);
1666 SPOT_DEF_PROP(is_eventual);
1676 SPOT_DEF_PROP(is_syntactic_safety);
1678 SPOT_DEF_PROP(is_syntactic_guarantee);
1680 SPOT_DEF_PROP(is_syntactic_obligation);
1682 SPOT_DEF_PROP(is_syntactic_recurrence);
1684 SPOT_DEF_PROP(is_syntactic_persistence);
1687 SPOT_DEF_PROP(is_marked);
1689 SPOT_DEF_PROP(accepts_eword);
1695 SPOT_DEF_PROP(has_lbt_atomic_props);
1704 SPOT_DEF_PROP(has_spin_atomic_props);
1705 #undef SPOT_DEF_PROP
1710 template<
typename Trans,
typename... Args>
1713 switch (
op o = kind())
1722 #if SPOT_HAS_STRONG_X
1731 return unop(o, trans((*
this)[0], std::forward<Args>(args)...));
1743 formula tmp = trans((*
this)[0], std::forward<Args>(args)...);
1744 return binop(o, tmp,
1745 trans((*
this)[1], std::forward<Args>(args)...));
1755 std::vector<formula> tmp;
1756 tmp.reserve(size());
1758 tmp.emplace_back(trans(f, std::forward<Args>(args)...));
1759 return multop(o, std::move(tmp));
1763 return bunop(o, trans((*
this)[0], std::forward<Args>(args)...),
1777 template<
typename Func,
typename... Args>
1780 if (func(*
this, std::forward<Args>(args)...))
1783 f.
traverse(func, std::forward<Args>(args)...);
1788 [[noreturn]]
static void report_ap_invalid_arg();
1795 bool abbreviated =
false);
1803 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:397
size_t id() const
Definition: formula.hh:275
bool is_ff() const
Definition: formula.hh:307
bool is_sugar_free_boolean() const
Definition: formula.hh:403
bool is_Kleene_star() const
Definition: formula.hh:343
unsigned min() const
Definition: formula.hh:247
bool is_syntactic_safety() const
Definition: formula.hh:463
bool is_syntactic_stutter_invariant() const
Definition: formula.hh:415
unsigned size() const
Definition: formula.hh:263
static constexpr uint8_t unbounded()
Definition: formula.hh:158
static const fnode * eword()
Definition: formula.hh:325
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:301
const fnode * boolean_operands(unsigned *width=nullptr) const
bool accepts_eword() const
Definition: formula.hh:499
bool is_eventual() const
Definition: formula.hh:451
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:511
bool is_eword() const
Definition: formula.hh:331
static const fnode * tt()
Definition: formula.hh:313
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:505
bool is_sugar_free_ltl() const
Definition: formula.hh:421
bool is_syntactic_persistence() const
Definition: formula.hh:487
static const fnode * nested_unop_range(op uo, op bo, unsigned min, unsigned max, const fnode *f)
unsigned boolean_count() const
Definition: formula.hh:368
bool is_universal() const
Definition: formula.hh:457
bool is_tt() const
Definition: formula.hh:319
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:337
static const fnode * binop(op o, const fnode *f, const fnode *g)
static const fnode * one_star()
Definition: formula.hh:351
const fnode * all_but(unsigned i) const
bool is_syntactic_recurrence() const
Definition: formula.hh:481
bool is(std::initializer_list< op > l) const
Definition: formula.hh:210
bool is_syntactic_obligation() const
Definition: formula.hh:475
static const fnode * unop(op o, const fnode *f)
bool is_ltl_formula() const
Definition: formula.hh:427
bool is_finite() const
Definition: formula.hh:445
bool is_psl_formula() const
Definition: formula.hh:433
static const fnode * multop(op o, std::vector< const fnode * > l)
bool is_marked() const
Definition: formula.hh:493
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:409
static const fnode * ap(const std::string &name)
bool is_syntactic_guarantee() const
Definition: formula.hh:469
bool is_sere_formula() const
Definition: formula.hh:439
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.