mCRL2
Loading...
Searching...
No Matches
one_point_condition_rewrite.h
Go to the documentation of this file.
1// Author(s): Jeroen Keiren
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//
13
14#ifndef MCRL2_LPS_REWRITERS_ONE_POINT_CONDITION_REWRITE_H
15#define MCRL2_LPS_REWRITERS_ONE_POINT_CONDITION_REWRITE_H
16
17#include "mcrl2/data/join.h"
19#include "mcrl2/data/rewriter.h"
21#include "mcrl2/lps/builder.h"
22
23namespace mcrl2 {
24
25namespace lps {
26
27namespace detail {
28
29// Extracts all conjuncts d == e from the data expression x, for variables d, and with e a constant.
30void find_equality_conjuncts(const data::data_expression& x, std::map<data::variable, data::data_expression>& result)
31{
32 std::set<data::data_expression> conjuncts = data::split_and(x);
33 for (const data::data_expression& expr: conjuncts)
34 {
35 const auto& v_i = expr;
37 {
40 if (data::is_variable(left) && data::is_constant(right))
41 {
42 const auto& vleft = atermpp::down_cast<data::variable>(left);
43 result[vleft] = right;
44 }
45 else if (data::is_variable(right) && data::is_constant(left))
46 {
47 const auto& vright = atermpp::down_cast<data::variable>(right);
48 result[vright] = left;
49 }
50 }
51 // handle conjuncts b and !b, with b a variable with sort Bool
52 else if (data::is_variable(v_i) && data::sort_bool::is_bool(v_i.sort()))
53 {
54 const auto& v = atermpp::down_cast<data::variable>(v_i);
55 result[v] = data::sort_bool::true_();
56 }
58 {
60 if (data::is_variable(narg) && data::sort_bool::is_bool(v_i.sort()))
61 {
62 const auto& v = atermpp::down_cast<data::variable>(narg);
63 result[v] = data::sort_bool::false_();
64 }
65 }
66 }
67 mCRL2log(log::trace) << " computing one point variables: expression = " << x << ", result = " << core::detail::print_map(result) << std::endl;
68}
69
70template <typename DataRewriter>
71struct one_point_condition_rewrite_builder: public lps::data_expression_builder<one_point_condition_rewrite_builder<DataRewriter> >
72{
74 using super::enter;
75 using super::leave;
76 using super::apply;
77 using super::update;
78
79 const DataRewriter& R;
80 data::mutable_map_substitution<> sigma; // substitution is only used for variables that appear condition of summand, and is cleared after.
81
83 : R(R_)
84 {}
85
87 {
88 // calculate substitutions
89 std::map<data::variable, data::data_expression> assignments; // TODO: adapt to substitution
90 detail::find_equality_conjuncts(x, assignments);
91 for (const auto& [k,v]: assignments)
92 {
93 sigma[k] = v;
94 }
95 }
96
98 {
99 sigma.clear();
100 }
101
103 {
104 enter(x);
106
107 // rewrite summand
108 lps::multi_action result_multi_action;
109 apply(result_multi_action, x.multi_action());
110 x.multi_action() = result_multi_action;
111 data::assignment_list result_assignments;
112 apply(result_assignments, x.assignments());
113 x.assignments() = result_assignments;
114
116 leave(x);
117 }
118
120 {
121 enter(x);
123
124 // rewrite summand
125 update(x.deadlock());
126
127 // reset substitution
129 leave(x);
130 }
131
132 // TODO: should the stochastic distribution be rewritten or not?
134 {
135 enter(x);
137
138 // rewrite summand
139 lps::multi_action result_multi_action;
140 apply(result_multi_action, x.multi_action());
141 x.multi_action() = result_multi_action;
142 data::assignment_list result_assignments;
143 apply(result_assignments, x.assignments());
144 x.assignments() = result_assignments;
145 stochastic_distribution result_distribution;
146 apply(result_distribution, x.distribution());
147 x.distribution() = result_distribution;
148
150 leave(x);
151 }
152
153 template <class T>
154 void apply(T& result, const data::data_expression& x)
155 {
156 result = R(x, sigma);
157 }
158};
159
160} // namespace detail
161
164template <typename T, typename DataRewriter>
165void one_point_condition_rewrite(T& x, const DataRewriter& R, typename std::enable_if<!std::is_base_of<atermpp::aterm, T>::value>::type* = nullptr)
166{
168 f.update(x);
169}
170
174template <typename T, typename DataRewriter>
175T one_point_condition_rewrite(const T& x, const DataRewriter& R, typename std::enable_if<std::is_base_of<atermpp::aterm, T>::value>::type* = nullptr)
176{
177 T result;
179 f.apply(result, x);
180 return result;
181}
182
183} // namespace lps
184
185} // namespace mcrl2
186
187#endif // MCRL2_LPS_DETAIL_ONE_POINT_CONDITION_REWRITE_H
188
189
Generic substitution function. The substitution is stored as a mapping of variables to expressions....
void clear()
Resets the substitution by letting every variable yield itself. Cf. clear() of a map.
LPS summand containing a multi-action.
const lps::multi_action & multi_action() const
Returns the multi-action of this summand.
const data::assignment_list & assignments() const
Returns the sequence of assignments.
LPS summand containing a deadlock.
const lps::deadlock & deadlock() const
Returns the deadlock of this summand.
\brief A timed multi-action
LPS summand containing a multi-action.
const stochastic_distribution & distribution() const
Returns the distribution of this summand.
\brief A stochastic distribution
const data::data_expression & condition() const
Returns the condition expression.
Definition summand.h:60
Join and split functions for data expressions.
The class rewriter.
#define mCRL2log(LEVEL)
mCRL2log(LEVEL) provides the stream used to log.
Definition logger.h:391
add your file description here.
add your file description here.
add your file description here.
std::string print_map(const MapContainer &v, const std::string &message="")
Creates a string representation of a map.
const data_expression & arg(const data_expression &e)
Function for projecting out argument. arg from an application.
Definition bool.h:469
bool is_bool(const sort_expression &e)
Recogniser for sort expression Bool.
Definition bool.h:54
const function_symbol & false_()
Constructor for function symbol false.
Definition bool.h:109
bool is_not_application(const atermpp::aterm &e)
Recogniser for application of !.
Definition bool.h:217
const function_symbol & true_()
Constructor for function symbol true.
Definition bool.h:77
const data_expression & binary_right1(const data_expression &x)
const data_expression & binary_left1(const data_expression &x)
bool is_constant(const data_expression &x)
bool is_equal_to_application(const DataExpression &e)
Recogniser for application of ==.
Definition standard.h:155
std::set< 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 && ....
Definition join.h:68
bool is_variable(const atermpp::aterm &x)
Returns true if the term t is a variable.
void find_equality_conjuncts(const data::data_expression &x, std::map< data::variable, data::data_expression > &result)
void one_point_condition_rewrite(T &x, const DataRewriter &R, typename std::enable_if<!std::is_base_of< atermpp::aterm, T >::value >::type *=nullptr)
Applies the one point condition rewriter to all embedded data expressions in an object x.
A class that takes a linear process specification and checks all tau-summands of that LPS for conflue...
Definition indexed_set.h:72
void apply(T &result, const lps::multi_action &x)
Definition builder.h:212
void update(lps::deadlock &x)
Definition builder.h:202
void apply(T &result, const data::data_expression &x)
lps::data_expression_builder< one_point_condition_rewrite_builder< DataRewriter > > super