mCRL2
Loading...
Searching...
No Matches
test_rewriters.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_DETAIL_TEST_REWRITERS_H
13#define MCRL2_DATA_DETAIL_TEST_REWRITERS_H
14
15#include "mcrl2/data/builder.h"
17#include "mcrl2/data/join.h"
19#include "mcrl2/data/parse.h"
21
22namespace mcrl2 {
23
24namespace data {
25
26namespace detail {
27
28// Normalizes conjunctions and disjunctions.
29template <typename Derived>
31{
33 using super::enter;
34 using super::leave;
35 using super::update;
36 using super::apply;
37
44 std::multiset<data_expression> split_or(const data_expression& expr)
45 {
46 std::multiset<data_expression> result;
47 utilities::detail::split(expr, std::insert_iterator<std::multiset<data_expression> >(result, result.begin()), sort_bool::is_or_application, data::binary_left1, data::binary_right1);
48 return result;
49 }
50
57 std::multiset<data_expression> split_and(const data_expression& expr)
58 {
59 std::multiset<data_expression> result;
60 utilities::detail::split(expr, std::insert_iterator<std::multiset<data_expression> >(result, result.begin()), sort_bool::is_and_application, data::binary_left1, data::binary_right1);
61 return result;
62 }
63
64 template<class T>
65 void apply(T& result, const application& x)
66 {
68 super::apply(y, x);
70 {
71 std::multiset<data_expression> s = split_and(y);
72 result = data::join_and(s.begin(), s.end());
73 return;
74 }
76 {
77 std::multiset<data_expression> s = split_or(y);
78 result = data::join_or(s.begin(), s.end());
79 return;
80 }
81 result = y;
82 }
83};
84
85template <typename T>
86T normalize_and_or(const T& x,
87 typename std::enable_if< std::is_base_of< atermpp::aterm, T >::value>::type* = nullptr
88 )
89{
90 T result;
91 core::make_apply_builder<normalize_and_or_builder>().apply(result, x);
92 return result;
93}
94
95template <typename T>
97 typename std::enable_if< !std::is_base_of< atermpp::aterm, T >::value>::type* = 0
98 )
99{
100 core::make_apply_builder<normalize_and_or_builder>().update(x);
101}
102
103// Normalizes equalities.
104template <typename Derived>
106{
108 using super::enter;
109 using super::leave;
110 using super::apply;
111
112 template<class T>
113 void apply(T& result, const application& x)
114 {
116 super::apply(y, x);
118 {
119 const data_expression& left = data::binary_left1(y);
120 const data_expression& right = data::binary_right1(y);
121 if (left < right)
122 {
123 result = data::equal_to(left, right);
124 return;
125 }
126 else
127 {
128 result = data::equal_to(right, left);
129 return;
130 }
131 }
133 {
134 const data_expression& left = data::binary_left1(y);
135 const data_expression& right = data::binary_right1(y);
136 if (left < right)
137 {
138 result = data::not_equal_to(left, right);
139 return;
140 }
141 else
142 {
143 result = data::not_equal_to(right, left);
144 return;
145 }
146 }
147 result = y;
148 }
149};
150
151template <typename T>
153 typename std::enable_if< std::is_base_of< atermpp::aterm, T >::value>::type* = nullptr
154 )
155{
156 T result;
157 core::make_apply_builder<normalize_equality_builder>().apply(result, x);
158 return result;
159}
160
161template <typename T>
163 typename std::enable_if< !std::is_base_of< atermpp::aterm, T >::value>::type* = 0
164 )
165{
166 core::make_apply_builder<normalize_equality_builder>().update(x);
167}
168
169// normalize operator
170template <typename Function>
172{
173 const Function& f;
174
175 normalizer(const Function& f0)
176 : f(f0)
177 {}
178
180 {
181 return detail::normalize_and_or(f(t));
182 }
183};
184
185// utility function for creating a normalizer
186template <typename Function>
187normalizer<Function> N(const Function& f)
188{
189 return normalizer<Function>(f);
190}
191
192inline
194{
195 return
196 " b: Bool; \n"
197 " b1: Bool; \n"
198 " b2: Bool; \n"
199 " b3: Bool; \n"
200 " \n"
201 " n: Nat; \n"
202 " n1: Nat; \n"
203 " n2: Nat; \n"
204 " n3: Nat; \n"
205 " \n"
206 " p: Pos; \n"
207 " p1: Pos; \n"
208 " p2: Pos; \n"
209 " p3: Pos; \n"
210 ;
211}
212
214{
215 protected:
216 std::string m_var_decl;
217 std::string m_data_spec;
218
219 public:
220
221 parser(const std::string& var_decl = VARIABLE_SPECIFICATION(), const std::string& data_spec = "")
222 : m_var_decl(var_decl),
223 m_data_spec(data_spec)
224 {}
225
226 data_expression operator()(const std::string& expr)
227 {
229 }
230};
231
232template <typename Rewriter1, typename Rewriter2>
233void test_rewriters(Rewriter1 R1, Rewriter2 R2, std::string expr1, std::string expr2, const std::string& var_decl = VARIABLE_SPECIFICATION(), const std::string& data_spec = "")
234{
236 expr1,
237 expr2,
238 parser(var_decl, data_spec),
239 std::equal_to<data_expression>(),
240 R1,
241 "R1",
242 R2,
243 "R2"
244 );
245}
246
247inline
249{
250 return x;
251}
252
253} // namespace detail
254
255} // namespace data
256
257} // namespace mcrl2
258
259#endif // MCRL2_DATA_DETAIL_TEST_REWRITERS_H
260
An application of a data expression to a number of arguments.
data_expression operator()(const std::string &expr)
parser(const std::string &var_decl=VARIABLE_SPECIFICATION(), const std::string &data_spec="")
add your file description here.
add your file description here.
Join and split functions for data expressions.
Parser for data specifications.
data_expression parse_data_expression(const std::string &text)
Definition data.cpp:224
T normalize_and_or(const T &x, typename std::enable_if< std::is_base_of< atermpp::aterm, T >::value >::type *=nullptr)
data_expression I(const data_expression &x)
variable_list parse_variables(const std::string &text)
Definition data.cpp:213
normalizer< Function > N(const Function &f)
T normalize_equality(const T &x, typename std::enable_if< std::is_base_of< atermpp::aterm, T >::value >::type *=nullptr)
std::string VARIABLE_SPECIFICATION()
void test_rewriters(Rewriter1 R1, Rewriter2 R2, std::string expr1, std::string expr2, const std::string &var_decl=VARIABLE_SPECIFICATION(), const std::string &data_spec="")
bool is_or_application(const atermpp::aterm &e)
Recogniser for application of ||.
Definition bool.h:345
bool is_and_application(const atermpp::aterm &e)
Recogniser for application of &&.
Definition bool.h:281
function_symbol not_equal_to(const sort_expression &s)
Constructor for function symbol !=.
Definition standard.h:163
bool is_not_equal_to_application(const DataExpression &e)
Recogniser for application of !=.
Definition standard.h:192
data_specification parse_data_specification(std::istream &in)
Parses a and type checks a data specification.
Definition parse.h:62
data_expression join_or(FwdIt first, FwdIt last)
Returns or applied to the sequence of data expressions [first, last)
Definition join.h:29
const data_expression & binary_right1(const data_expression &x)
const data_expression & binary_left1(const data_expression &x)
function_symbol equal_to(const sort_expression &s)
Constructor for function symbol ==.
Definition standard.h:126
data_expression join_and(FwdIt first, FwdIt last)
Returns and applied to the sequence of data expressions [first, last)
Definition join.h:40
bool is_equal_to_application(const DataExpression &e)
Recogniser for application of ==.
Definition standard.h:155
bool test_operation(const std::string &expr1, const std::string &expr2, Parser parse, Compare comp, Operation1 op1, const std::string &opname1, Operation2 op2, const std::string &opname2)
Generic function that applies two operations to two objects, and compares the results.
void split(const T &t, OutputIterator i, MatchFunction match, AccessorFunction1 lhs, AccessorFunction2 rhs)
Splits a binary tree T into a sequence, and writes the result to the output range given by an output ...
Definition join.h:34
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
std::multiset< data_expression > split_and(const data_expression &expr)
Splits a conjunction into a sequence of operands Given a data expression of the form p1 && p2 && ....
data_expression_builder< Derived > super
void apply(T &result, const application &x)
std::multiset< data_expression > split_or(const data_expression &expr)
Splits a disjunction into a sequence of operands Given a data expression of the form p1 || p2 || ....
data_expression_builder< Derived > super
void apply(T &result, const application &x)
data_expression operator()(const data_expression &t) const
Function for testing operations.