mCRL2
Loading...
Searching...
No Matches
normalize_and_or.h
Go to the documentation of this file.
1// Author(s): Wieger Wesselink
2// Copyright: see the accompanying file COPYING or copy at
3// https://github.com/mCRL2org/mCRL2/blob/master/COPYING
4//
5// Distributed under the Boost Software License, Version 1.0.
6// (See accompanying file LICENSE_1_0.txt or copy at
7// http://www.boost.org/LICENSE_1_0.txt)
8//
9/// \file mcrl2/pbes/detail/normalize_and_or.h
10/// \brief Function to normalize 'and' and 'or' sub expressions.
11
12#ifndef MCRL2_PBES_DETAIL_NORMALIZE_AND_OR_H
13#define MCRL2_PBES_DETAIL_NORMALIZE_AND_OR_H
14
15#include "mcrl2/pbes/builder.h"
16#include "mcrl2/pbes/join.h"
17
18namespace mcrl2::pbes_system::detail
19{
20
21// Simplifying PBES rewriter.
22template <typename Derived>
24{
25 using super = pbes_expression_builder<Derived>;
26 using super::enter;
27 using super::leave;
28 using super::update;
29 using super::apply;
30
31 /// \brief Splits a disjunction into a sequence of operands
32 /// Given a pbes expression of the form p1 || p2 || .... || pn, this will yield a
33 /// set of the form { p1, p2, ..., pn }, assuming that pi does not have a || as main
34 /// function symbol.
35 /// \param expr A PBES expression
36 /// \return A sequence of operands
38 {
39 using namespace accessors;
40 std::multiset<pbes_expression> result;
41 utilities::detail::split(expr, std::insert_iterator<std::multiset<pbes_expression> >(result, result.begin()), is_or, left, right);
42 return result;
43 }
44
45 /// \brief Splits a conjunction into a sequence of operands
46 /// Given a pbes expression of the form p1 && p2 && .... && pn, this will yield a
47 /// set of the form { p1, p2, ..., pn }, assuming that pi does not have a && as main
48 /// function symbol.
49 /// \param expr A PBES expression
50 /// \return A sequence of operands
52 {
53 using namespace accessors;
54 std::multiset<pbes_expression> result;
55 utilities::detail::split(expr, std::insert_iterator<std::multiset<pbes_expression> >(result, result.begin()), is_and, left, right);
56 return result;
57 }
58
60 {
61 if (is_and(x))
62 {
63 std::multiset<pbes_expression> s = split_and(x);
64 return join_and(s.begin(), s.end());
65 }
66 else if (is_or(x))
67 {
68 std::multiset<pbes_expression> s = split_or(x);
69 return join_or(s.begin(), s.end());
70 }
71 return x;
72 }
73
74 // to prevent default operator() being called
75 template <class T>
76 void apply(T& result, const data::data_expression& x)
77 {
78 result = atermpp::down_cast<pbes_expression>(x);
79 }
80
81 template <class T>
82 void apply(T& result, const pbes_expression& x)
83 {
84 super::apply(result, x);
85 result = normalize(result);
86 }
87};
88
89template <typename T>
90 requires(std::is_base_of_v<atermpp::aterm, T>)
92{
93 T result;
95 return result;
96}
97
98template <typename T>
99 requires(!std::is_base_of_v<atermpp::aterm, T>)
101{
103}
104
105} // namespace mcrl2::pbes_system::detail
106
107
108
109
110
111#endif // MCRL2_PBES_DETAIL_NORMALIZE_AND_OR_H
The namespace for accessor functions on pbes expressions.
bool is_or(const atermpp::aterm &x)
bool is_and(const atermpp::aterm &x)
void apply(T &result, const data::data_expression &x)
pbes_expression normalize(const pbes_expression &x)
void apply(T &result, const pbes_expression &x)
std::multiset< pbes_expression > split_or(const pbes_expression &expr)
Splits a disjunction into a sequence of operands Given a pbes expression of the form p1 || p2 || ....
std::multiset< pbes_expression > split_and(const pbes_expression &expr)
Splits a conjunction into a sequence of operands Given a pbes expression of the form p1 && p2 && ....