mCRL2
Loading...
Searching...
No Matches
pbesbackelm.h
Go to the documentation of this file.
1// Author(s): Jan Friso Groote
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//
14
15#ifndef MCRL2_PBES_TOOLS_PBESBACKELM_H
16#define MCRL2_PBES_TOOLS_PBESBACKELM_H
17
19// #include "mcrl2/pbes/replace_capture_avoiding.h"
20#include "mcrl2/pbes/rewrite.h"
21#include "mcrl2/pbes/rewriter.h"
22#include "mcrl2/pbes/io.h"
23
24namespace mcrl2 {
25
26namespace pbes_system {
27
29{
31};
32
33
34/* template <template <class> class Builder, class Substitution>
35struct substitute_propositional_variables_builder: public Builder<substitute_propositional_variables_builder<Builder, Substitution> >
36{
37 typedef Builder<substitute_propositional_variables_builder<Builder, Substitution> > super;
38 using super::apply; */
39template <template <class> class Builder>
40struct substitute_propositional_variables_builder: public Builder<substitute_propositional_variables_builder<Builder> >
41{
42 typedef Builder<substitute_propositional_variables_builder<Builder> > super;
43 using super::apply;
44
45
49 bool m_stable=false;
50
53 {}
54
55 void set_stable(bool b)
56 {
57 m_stable=b;
58 }
59
60 bool stable() const
61 {
62 return m_stable;
63 }
64
66 {
67 m_eq=eq;
68 }
69
71 {
72 name=s;
73 }
74
75 template <class T>
77 {
78 if (x.name()==m_eq.variable().name())
79 {
82 for(const data::variable& v: m_eq.variable().parameters())
83 {
85 pars.pop_front();
86 if (par.sort()!=v.sort())
87 {
88 // Parameters do not match with variables. Ignore this substitution.
89 result=x;
90 return;
91 }
92 sigma[v]=par;
93 }
95 std::set<propositional_variable_instantiation> set=find_propositional_variable_instantiations(p);
96 if (std::all_of(set.begin(),
97 set.end(),
98 [this](const propositional_variable_instantiation& v){ return v.name()!=m_eq.variable().name(); }))
99 {
100 // The result does not contain the variable m_eq.variable().name() and is therefore considered simpler.
101 mCRL2log(log::verbose) << "Replaced in PBES equation for " << name << ":\n" << x << " --> " << p << "\n";
102 result=p;
103 m_stable=false;
104 return;
105 }
106 mCRL2log(log::debug) << "No Replacement in PBES equation for " << name << ":\n" << x << " --> " << p << "\n";
107 result=x;
108 return;
109 }
110 result=x;
111 }
112};
113
115{
116 substituter.set_stable(false);
117 while (!substituter.stable())
118 {
119 substituter.set_equation(equation);
120 substituter.set_name(equation.variable().name());
121 substituter.set_stable(true);
123 substituter.apply(p, equation.formula());
124 equation.formula()=p;
125 }
126}
127
129{
130 // substitute_propositional_variables_builder<pbes_system::pbes_expression_builder> substituter(by,r);
131 substituter.set_equation(by);
132 substituter.set_name(into.variable().name());
134 substituter.apply(p, into.formula());
135 into.formula()=p;
136}
137
139{
140 void run(pbes& p,
141 pbesbackelm_options options
142 )
143 {
147 for(std::vector<pbes_equation>::reverse_iterator i=p.equations().rbegin(); i!=p.equations().rend(); i++)
148 {
149 // Simplify the equation *i by substituting in itself.
150 mCRL2log(log::verbose) << "Investigating the equation for " << i->variable().name() << "\n";
151 self_substitute(*i,substituter);
152 for(std::vector<pbes_equation>::reverse_iterator j=i+1; j!=p.equations().rend(); j++)
153 {
154 substitute(*j, *i, substituter);
155 }
156 }
157 pbes_rewrite(p, pbes_rewriter);
158 }
159};
160
161void pbesbackelm(const std::string& input_filename,
162 const std::string& output_filename,
163 const utilities::file_format& input_format,
164 const utilities::file_format& output_format,
165 pbesbackelm_options options
166 )
167{
168 pbes p;
169 load_pbes(p, input_filename, input_format);
171 pbesbackelm_pbes_backward_substituter backward_substituter;
172 backward_substituter.run(p, options);
173 save_pbes(p, output_filename, output_format);
174}
175
176} // namespace pbes_system
177
178} // namespace mcrl2
179
180#endif // MCRL2_PBES_TOOLS_PBESBACKELM_H
Term containing a string.
const Term & front() const
Returns the first element of the list.
Definition aterm_list.h:239
void pop_front()
Removes the first element of the list.
Definition aterm_list.h:232
sort_expression sort() const
Returns the sort of the data expression.
Definition data.cpp:108
Rewriter that operates on data expressions.
Definition rewriter.h:81
\brief A data variable
Definition variable.h:28
const pbes_expression & formula() const
Returns the predicate formula on the right hand side of the equation.
const propositional_variable & variable() const
Returns the pbes variable of the equation.
parameterized boolean equation system
Definition pbes.h:58
const data::data_specification & data() const
Returns the data specification.
Definition pbes.h:150
const std::vector< pbes_equation > & equations() const
Returns the equations.
Definition pbes.h:164
\brief A propositional variable instantiation
const data::data_expression_list & parameters() const
const data::variable_list & parameters() const
const core::identifier_string & name() const
static RewriterCompilingJitty::substitution_type & sigma(RewriterCompilingJitty *this_rewriter)
#define mCRL2log(LEVEL)
mCRL2log(LEVEL) provides the stream used to log.
Definition logger.h:391
rewrite_strategy
The strategy of the rewriter.
@ verbose
Definition logger.h:37
void normalize(pbes &x)
The function normalize brings (embedded) pbes expressions into positive normal form,...
void self_substitute(pbes_equation &equation, substitute_propositional_variables_builder< pbes_system::pbes_expression_builder > &substituter)
void pbesbackelm(const std::string &input_filename, const std::string &output_filename, const utilities::file_format &input_format, const utilities::file_format &output_format, pbesbackelm_options options)
void load_pbes(pbes &pbes, std::istream &stream, utilities::file_format format, const std::string &source="")
Load a PBES from file.
Definition io.cpp:82
void save_pbes(const pbes &pbes, std::ostream &stream, utilities::file_format format=utilities::file_format())
Save a PBES in the format specified.
Definition io.cpp:49
void pbes_rewrite(T &x, const Rewriter &R, typename std::enable_if< !std::is_base_of< atermpp::aterm, T >::value >::type *=nullptr)
Rewrites all embedded pbes expressions in an object x.
Definition rewrite.h:156
void find_propositional_variable_instantiations(Container const &container, OutputIterator o)
Returns all data variables that occur in a range of expressions.
Definition find.h:196
void substitute(pbes_equation &into, const pbes_equation &by, substitute_propositional_variables_builder< pbes_system::pbes_expression_builder > &substituter)
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.
IO routines for boolean equation systems.
add your file description here.
Rewriters for pbes expressions.
A rewriter that applies a data rewriter to data expressions in a term.
data::rewrite_strategy rewrite_strategy
Definition pbesbackelm.h:30
void run(pbes &p, pbesbackelm_options options)
A rewriter that simplifies boolean expressions and quantifiers, and rewrites data expressions.
simplify_quantifiers_data_rewriter< data::rewriter > m_pbes_rewriter
Definition pbesbackelm.h:48
void apply(T &result, const propositional_variable_instantiation &x)
Definition pbesbackelm.h:76
substitute_propositional_variables_builder(simplify_quantifiers_data_rewriter< data::rewriter > &r)
Definition pbesbackelm.h:51
Builder< substitute_propositional_variables_builder< Builder > > super
Definition pbesbackelm.h:42