mCRL2
Loading...
Searching...
No Matches
simplify_rewriter.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//
11
12#ifndef MCRL2_DATA_REWRITERS_SIMPLIFY_REWRITER_H
13#define MCRL2_DATA_REWRITERS_SIMPLIFY_REWRITER_H
14
15#include "mcrl2/data/builder.h"
18
19namespace mcrl2 {
20
21namespace data {
22
23namespace detail {
24
25template <typename Derived>
27{
28 public:
30
31 using super::apply;
32
33 Derived& derived()
34 {
35 return static_cast<Derived&>(*this);
36 }
37
38 bool is_not(const data_expression& x) const
39 {
41 }
42
43 bool is_and(const data_expression& x) const
44 {
46 }
47
48 bool is_or(const data_expression& x) const
49 {
51 }
52
53 bool is_imp(const data_expression& x) const
54 {
56 }
57
58 bool is_forall(const data_expression& x) const
59 {
60 return data::is_forall(x);
61 }
62
63 bool is_exists(const data_expression& x) const
64 {
65 return data::is_exists(x);
66 }
67
68 template <class T>
69 void apply(T& result, const application& x)
70 {
71 derived().enter(x);
72 if (is_not(x)) // x = !y
73 {
75 derived().apply(y, *x.begin());
76 data::optimized_not(result, y);
77 }
78 else if (is_and(x)) // x = y && z
79 {
81 derived().apply(y, binary_left(x));
83 derived().apply(z, binary_right(x));
84 data::optimized_and(result, y, z);
85 }
86 else if (is_or(x)) // x = y || z
87 {
89 derived().apply(y, binary_left(x));
91 derived().apply(z, binary_right(x));
92 data::optimized_or(result, y, z);
93 }
94 else if (is_imp(x)) // x = y => z
95 {
97 derived().apply(y, binary_left(x));
99 derived().apply(z, binary_right(x));
100 data::optimized_imp(result, y, z);
101 }
102 else
103 {
104 super::apply(result, x);
105 }
106 derived().leave(x);
107 }
108
109 template <class T>
110 void apply(T& result, const forall& x) // x = forall d. y
111 {
114 derived().apply(y, forall(x).body());
115 data::optimized_forall(result, d, y, true);
116 }
117
118 template <class T>
119 void apply(T& result, const exists& x) // x = exists d. y
120 {
123 derived().apply(y, exists(x).body());
124 data::optimized_exists(result, d, y, true);
125 }
126};
127
128} // namespace detail
129
131{
134
135 void operator()(data_expression& result, const data_expression& x) const
136 {
137 core::make_apply_builder<detail::simplify_rewrite_builder>().apply(result, x);
138 }
139
141 {
142 data_expression result;
143 core::make_apply_builder<detail::simplify_rewrite_builder>().apply(result, x);
144 return result;
145 }
146};
147
148template <typename T>
149void simplify(T& x, typename std::enable_if< !std::is_base_of< atermpp::aterm, T >::value>::type* = 0)
150{
151 core::make_update_apply_builder<data::data_expression_builder>(simplify_rewriter()).update(x);
152}
153
154template <typename T>
155T simplify(const T& x, typename std::enable_if< std::is_base_of< atermpp::aterm, T >::value>::type* = nullptr)
156{
157 T result;
158 core::make_update_apply_builder<data::data_expression_builder>(simplify_rewriter()).apply(result, x);
159 return result;
160}
161
162} // namespace data
163
164} // namespace mcrl2
165
166#endif // MCRL2_DATA_REWRITERS_SIMPLIFY_REWRITER_H
167
const variable_list & variables() const
Definition abstraction.h:63
An application of a data expression to a number of arguments.
const_iterator begin() const
Returns an iterator pointing to the first argument of the application.
data_expression_builder< Derived > super
bool is_forall(const data_expression &x) const
bool is_exists(const data_expression &x) const
void apply(T &result, const application &x)
bool is_imp(const data_expression &x) const
bool is_and(const data_expression &x) const
bool is_or(const data_expression &x) const
bool is_not(const data_expression &x) const
existential quantification.
Definition exists.h:26
universal quantification.
Definition forall.h:26
add your file description here.
Contains term traits for data_expression.
bool is_or_application(const atermpp::aterm &e)
Recogniser for application of ||.
Definition bool.h:345
bool is_implies_application(const atermpp::aterm &e)
Recogniser for application of =>.
Definition bool.h:409
bool is_and_application(const atermpp::aterm &e)
Recogniser for application of &&.
Definition bool.h:281
bool is_not_application(const atermpp::aterm &e)
Recogniser for application of !.
Definition bool.h:217
const data_expression & binary_right(const application &x)
void optimized_exists(Term &result, const VariableSequence &l, const Term &p, bool remove_variables=false)
Make an existential quantification.
void optimized_or(Term &result, const Term &p, const Term &q)
Make a conjunction, and optimize if possible.
void simplify(T &x, typename std::enable_if< !std::is_base_of< atermpp::aterm, T >::value >::type *=0)
const data_expression & binary_left(const application &x)
void optimized_imp(Term &result, const Term &p, const Term &q)
Make an implication.
bool is_forall(const atermpp::aterm &x)
Returns true if the term t is a universal quantification.
bool is_exists(const atermpp::aterm &x)
Returns true if the term t is an existential quantification.
void optimized_not(Term &result, const Term &arg)
Make a negation.
void optimized_and(Term &result, const Term &p, const Term &q)
Make a conjunction, and optimize if possible.
void optimized_forall(Term &result, const VariableSequence &l, const Term &p, bool remove_variables=false)
Make a universal quantification.
A class that takes a linear process specification and checks all tau-summands of that LPS for conflue...
Definition indexed_set.h:72
add your file description here.
void apply(T &result, const data::variable &x)
Definition builder.h:443
data_expression operator()(const data_expression &x) const
void operator()(data_expression &result, const data_expression &x) const