mCRL2
Loading...
Searching...
No Matches
enumerator_substitution.h
Go to the documentation of this file.
1// Author(s): Muck van Weerdenburg, 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_SUBSTITUTIONS_ENUMERATOR_SUBSTITUTION_H
13#define MCRL2_DATA_SUBSTITUTIONS_ENUMERATOR_SUBSTITUTION_H
14
15#include "mcrl2/data/builder.h"
17
18namespace mcrl2 {
19
20namespace data {
21
22namespace detail {
23
24// applies the enumerator substitution defined by variables and expressions to x
25template <typename T>
26data_expression enumerator_replace(const T& x,
27 const variable_list::const_iterator variables_begin,
28 const variable_list::const_iterator variables_end,
29 const data_expression_list::const_iterator expressions_begin);
30
31struct enumerator_replace_builder: public data_expression_builder<enumerator_replace_builder>
32{
34 using super::enter;
35 using super::leave;
36 using super::apply;
37 using super::update;
38
42
44 const variable_list::const_iterator variables_end,
45 const data_expression_list::const_iterator expressions_begin)
46 : m_vars_begin(variables_begin),
47 m_vars_end(variables_end),
48 m_expressions_begin(expressions_begin)
49 {}
50
51 template <class T>
52 void apply(T& result, const variable& x)
53 {
56 while (i_vars!=m_vars_end && x != *i_vars)
57 {
58 ++i_vars;
59 ++i_exprs;
60 }
61 if (i_vars==m_vars_end)
62 {
63 result = x;
64 return;
65 }
66 else
67 {
68 result = enumerator_replace(*i_exprs, i_vars, m_vars_end, i_exprs);
69 return;
70 }
71 }
72};
73
74template <typename T>
75inline
77 const variable_list::const_iterator variables_begin,
78 const variable_list::const_iterator variables_end,
79 const data_expression_list::const_iterator expressions_begin)
80{
81 data_expression result;
82 enumerator_replace_builder f(variables_begin, variables_end, expressions_begin);
83 f.apply(result, x);
84 return result;
85}
86
87template <typename T>
88inline
89data_expression enumerator_replace(const T& x, const variable_list& variables, const data_expression_list& expressions)
90{
91 assert(variables.size()==expressions.size());
92 return enumerator_replace(x, variables.begin(), variables.end(), expressions.begin());
93}
94
95} // namespace detail
96
101{
104
107
110
112
114 : variables(std::move(variables_)),
115 expressions(std::move(expressions_))
116 {
117 assert(variables.size() == expressions.size());
118 }
119
121 {
123 }
124
125 // Adds the assignment [v := e] to this substitution, by putting it in front of the lists with variables and expressions.
126 // Note that this operation has not the same effect as function composition with [v := e]. Therefore we use a different
127 // syntax than sigma[v] = e.
129 {
132 }
133
134 // Reverses the order of the assignments in the substitution.
135 void revert()
136 {
139 }
140
141 std::string to_string() const
142 {
143 std::ostringstream out;
144 out << "[";
145 auto i = variables.begin();
146 auto j = expressions.begin();
147 for (; i != variables.end(); ++i, ++j)
148 {
149 out << (i == variables.begin() ? "" : "; ") << *i << " := " << *j;
150 }
151 out << "]";
152 return out.str();
153 }
154};
155
156inline
157std::ostream& operator<<(std::ostream& out, const enumerator_substitution& sigma)
158{
159 return out << sigma.to_string();
160}
161
162inline
164{
165 auto i = sigma.variables.begin();
166 auto j = sigma.expressions.begin();
167 for (i = sigma.variables.begin(); i != sigma.variables.end(); ++i, ++j)
168 {
169 if (!is_simple_substitution(*i, *j))
170 {
171 return false;
172 }
173 }
174 return true;
175}
176
177} // namespace data
178
179} // namespace mcrl2
180
181#endif // MCRL2_DATA_SUBSTITUTIONS_ENUMERATOR_SUBSTITUTION_H
Iterator for term_appl.
Iterator for term_list.
size_type size() const
Returns the size of the term_list.
Definition aterm_list.h:256
const_iterator end() const
Returns a const_iterator pointing to the end of the term_list.
Definition aterm_list.h:282
const_iterator begin() const
Returns a const_iterator pointing to the beginning of the term_list.
Definition aterm_list.h:275
term_list_iterator< variable > const_iterator
Const iterator used to iterate through an term_list.
Definition aterm_list.h:55
void push_front(const Term &el)
Inserts a new element at the beginning of the current list.
\brief A data variable
Definition variable.h:28
add your file description here.
add your file description here.
static RewriterCompilingJitty::substitution_type & sigma(RewriterCompilingJitty *this_rewriter)
term_list< Term > reverse(const term_list< Term > &l)
Returns the list with the elements in reversed order.
data_expression enumerator_replace(const T &x, const variable_list::const_iterator variables_begin, const variable_list::const_iterator variables_end, const data_expression_list::const_iterator expressions_begin)
bool is_simple_substitution(const Substitution &)
Returns true if the substitution sigma satisfies the property that FV(sigma(x)) is included in {x} fo...
std::ostream & operator<<(std::ostream &out, const abstraction &x)
Definition abstraction.h:94
A class that takes a linear process specification and checks all tau-summands of that LPS for conflue...
Definition indexed_set.h:72
STL namespace.
void apply(T &result, const data::variable &x)
Definition builder.h:443
enumerator_replace_builder(const variable_list::const_iterator variables_begin, const variable_list::const_iterator variables_end, const data_expression_list::const_iterator expressions_begin)
data_expression_builder< enumerator_replace_builder > super
const data_expression_list::const_iterator m_expressions_begin
Substitution that stores the assignments as a sequence of variables and a sequence of expressions....
data::data_expression expression_type
type used to represent expressions
enumerator_substitution(data::variable_list variables_, data::data_expression_list expressions_)
data::data_expression operator()(const data::variable &v) const
void add_assignment(const data::variable &v, const data::data_expression &e)
data::variable variable_type
type used to represent variables