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//
9/// \file mcrl2/pbes/tools/pbesbackelm.h
10/// \brief This file provides a tool that can simplify PBESs by
11/// substituting PBES equations for variables in the rhs,
12/// simplifying the result, and keeping it when it can
13/// eliminate PBES variables.
14
15#ifndef MCRL2_PBES_TOOLS_PBESBACKELM_H
16#define MCRL2_PBES_TOOLS_PBESBACKELM_H
17
18#include "mcrl2/pbes/algorithms.h"
19#include "mcrl2/pbes/rewrite.h"
20#include "mcrl2/pbes/rewriter.h"
21#include "mcrl2/pbes/io.h"
22
23namespace mcrl2::pbes_system
24{
25
27{
29};
30
31
32/* template <template <class> class Builder, class Substitution>
33struct substitute_propositional_variables_builder: public Builder<substitute_propositional_variables_builder<Builder, Substitution> >
34{
35 typedef Builder<substitute_propositional_variables_builder<Builder, Substitution> > super;
36 using super::apply; */
37template <template <class> class Builder>
39{
41 using super::apply;
42
43
45 core::identifier_string name;
47 bool m_stable=false;
48
51 {}
52
53 void set_stable(bool b)
54 {
55 m_stable=b;
56 }
57
58 bool stable() const
59 {
60 return m_stable;
61 }
62
64 {
65 m_eq=eq;
66 }
67
68 void set_name(const core::identifier_string& s)
69 {
70 name=s;
71 }
72
73 template <class T>
75 {
77 {
79 data::data_expression_list pars=x.parameters();
80 for(const data::variable& v: m_eq.variable().parameters())
81 {
82 data::data_expression par=pars.front();
83 pars.pop_front();
84 if (par.sort()!=v.sort())
85 {
86 // Parameters do not match with variables. Ignore this substitution.
87 result=x;
88 return;
89 }
90 sigma[v]=par;
91 }
92 pbes_expression p=pbes_rewrite(m_eq.formula(),m_pbes_rewriter,sigma);
93 std::set<propositional_variable_instantiation> set=find_propositional_variable_instantiations(p);
94 if (std::all_of(set.begin(),
95 set.end(),
96 [this](const propositional_variable_instantiation& v){ return v.name()!=m_eq.variable().name(); }))
97 {
98 // The result does not contain the variable m_eq.variable().name() and is therefore considered simpler.
99 mCRL2log(log::log_level_t::verbose) << "Replaced in PBES equation for " << name << ":\n" << x << " --> " << p << "\n";
100 result=p;
101 m_stable=false;
102 return;
103 }
104 mCRL2log(log::log_level_t::debug) << "No Replacement in PBES equation for " << name << ":\n" << x << " --> " << p << "\n";
105 result=x;
106 return;
107 }
108 result=x;
109 }
110};
111
112inline
113void self_substitute(pbes_equation& equation, substitute_propositional_variables_builder<pbes_system::pbes_expression_builder>& substituter)
114{
115 substituter.set_stable(false);
116 while (!substituter.stable())
117 {
118 substituter.set_equation(equation);
119 substituter.set_name(equation.variable().name());
120 substituter.set_stable(true);
121 pbes_expression p;
122 substituter.apply(p, equation.formula());
123 equation.formula()=p;
124 }
125}
126
127inline
128void substitute(pbes_equation& into, const pbes_equation& by, substitute_propositional_variables_builder<pbes_system::pbes_expression_builder>& substituter)
129{
130 substituter.set_equation(by);
131 substituter.set_name(into.variable().name());
133 substituter.apply(p, into.formula());
134 into.formula()=p;
135}
136
138{
139 void run(pbes& p,
140 pbesbackelm_options options
141 )
142 {
143 data::rewriter data_rewriter(p.data(),options.rewrite_strategy);
144 simplify_quantifiers_data_rewriter<data::rewriter> pbes_rewriter(data_rewriter);
145 substitute_propositional_variables_builder<pbes_system::pbes_expression_builder> substituter(pbes_rewriter);
146 for(std::vector<pbes_equation>::reverse_iterator i=p.equations().rbegin(); i!=p.equations().rend(); i++)
147 {
148 // Simplify the equation *i by substituting in itself.
149 mCRL2log(log::log_level_t::verbose) << "Investigating the equation for " << i->variable().name() << "\n";
150 self_substitute(*i,substituter);
151 for(std::vector<pbes_equation>::reverse_iterator j=i+1; j!=p.equations().rend(); j++)
152 {
153 substitute(*j, *i, substituter);
154 }
155 }
156 pbes_rewrite(p, pbes_rewriter);
157 }
158};
159
160} // namespace mcrl2::pbes_system
161
162#endif // MCRL2_PBES_TOOLS_PBESBACKELM_H
aterm_string & operator=(const aterm_string &t) noexcept=default
Rewriter that operates on data expressions.
Definition rewriter.h:84
propositional_variable & variable()
Returns the pbes variable of the equation.
pbes_expression & formula()
Returns the predicate formula on the right hand side of the equation.
pbes_expression & operator=(const pbes_expression &) noexcept=default
parameterized boolean equation system
Definition pbes.h:54
\brief A propositional variable instantiation
const core::identifier_string & name() const
#define mCRL2log(LEVEL)
mCRL2log(LEVEL) provides the stream used to log.
Definition logger.h:435
void self_substitute(pbes_equation &equation, substitute_propositional_variables_builder< pbes_system::pbes_expression_builder > &substituter)
void substitute(pbes_equation &into, const pbes_equation &by, substitute_propositional_variables_builder< pbes_system::pbes_expression_builder > &substituter)
data::rewrite_strategy rewrite_strategy
Definition pbesbackelm.h:28
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:46
void apply(T &result, const propositional_variable_instantiation &x)
Definition pbesbackelm.h:74
substitute_propositional_variables_builder(simplify_quantifiers_data_rewriter< data::rewriter > &r)
Definition pbesbackelm.h:49