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//
9/// \file mcrl2/lps/rewriters/one_point_condition_rewrite.h
10/// \brief Rewriter for LPSs that takes equalities of the form p_i == c, where
11/// p_i is a process parameter, and c is a constant, into account when
12/// simplifying the remainder of a summand.
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"
18#include "mcrl2/data/substitutions/mutable_map_substitution.h"
19#include "mcrl2/data/rewriter.h"
20#include "mcrl2/lps/rewriters/data_rewriter.h"
21#include "mcrl2/lps/builder.h"
22
23namespace mcrl2::lps
24{
25
26namespace detail {
27
28// Extracts all conjuncts d == e from the data expression x, for variables d, and with e a constant.
30 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;
36 if (data::is_equal_to_application(v_i))
37 {
38 const data::data_expression& left = data::binary_left1(v_i);
39 const data::data_expression& right = data::binary_right1(v_i);
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 }
57 else if (data::sort_bool::is_not_application(v_i))
58 {
59 const data::data_expression& narg = data::sort_bool::arg(v_i);
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::log_level_t::trace) << " computing one point variables: expression = " << x << ", result = " << core::detail::print_map(result) << std::endl;
68}
69
70template <typename 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);
105 calculate_substitutions(x.condition());
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);
122 calculate_substitutions(x.condition());
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);
136 calculate_substitutions(x.condition());
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
162/// \brief Applies the one point condition rewriter to all embedded data expressions in an object x
163/// \param x an object containing data expressions
164template <typename T, typename DataRewriter>
165 requires(!std::is_base_of_v<atermpp::aterm, T>)
167 const DataRewriter& R)
168{
170 f.update(x);
171}
172
173/// \brief Applies the one point condition rewriter to all embedded data expressions in an object x
174/// \param x an object containing data expressions
175/// \return the rewrite result
176template <typename T, typename DataRewriter>
177 requires(std::is_base_of_v<atermpp::aterm, T>)
179 const DataRewriter& R)
180{
181 T result;
183 f.apply(result, x);
184 return result;
185}
186
187} // namespace mcrl2::lps
188
189#endif // MCRL2_LPS_DETAIL_ONE_POINT_CONDITION_REWRITE_H
LPS summand containing a multi-action.
LPS summand containing a deadlock.
\brief A timed multi-action
multi_action & operator=(const multi_action &) noexcept=default
LPS summand containing a multi-action.
stochastic_distribution & distribution()
Returns the distribution of this summand.
\brief A stochastic distribution
stochastic_distribution & operator=(const stochastic_distribution &) noexcept=default
#define mCRL2log(LEVEL)
mCRL2log(LEVEL) provides the stream used to log.
Definition logger.h:435
A class that takes a linear process specification and checks all tau-summands of that LPS for conflue...
void find_equality_conjuncts(const data::data_expression &x, std::map< data::variable, data::data_expression > &result)
The main namespace for the LPS library.
Definition constelm.h:18
void apply(T &result, const data::data_expression &x)