10#ifndef MCRL2_PRES_CONSTELM_H
11#define MCRL2_PRES_CONSTELM_H
32 for (
const auto& i : m)
34 result[i.first] = i.second;
67 return !(*
this == other);
82 std::ostringstream out;
91 std::list<quantified_variable>
Q;
96 return std::tie(
Q,
X_e) < std::tie(other.
Q, other.
X_e);
117 typedef std::multimap<QPVI, edge_details>
edge_map;
121 std::set<data::variable>
FV;
140 typedef std::list<detail::quantified_variable>
qvar_list;
173 for (
auto& i: ec1.
edges)
175 auto& [Q_X_e, details] = i;
176 details.conditions.insert(negate2 ? ec2.
Cneg : ec2.
Cpos);
177 (is_conjunctive ? details.conjunctive_context_FV : details.disjunctive_context_FV)
178 .insert(ec2.
FV.begin(), ec2.
FV.end());
181 for (
auto& i: ec2.
edges)
183 auto& [Q_X_e, details] = i;
184 details.conditions.insert(negate1 ? ec1.
Cneg : ec1.
Cpos);
185 (is_conjunctive ? details.conjunctive_context_FV : details.disjunctive_context_FV)
186 .insert(ec1.
FV.begin(), ec1.
FV.end());
292 for (
auto& [X_e, details]: ec.
edges)
294 auto& [cond_set, conj_FV, disj_FV] = details;
297 std::set<data::data_expression> new_conditions;
302 new_conditions.insert(t);
304 cond_set = std::move(new_conditions);
308 cond_set.insert(forall);
331 for (
auto& [X_e, details]: ec.
edges)
333 auto& [cond_set, conj_FV, disj_FV] = details;
336 std::set<data::data_expression> new_conditions;
341 new_conditions.insert(t);
343 cond_set = std::move(new_conditions);
347 cond_set.insert(forall);
367std::cerr <<
"MUST STILL BE DONE\n";
383 QPVI Q_X_e{qvars, x};
387 ec.
edges.insert(std::make_pair(Q_X_e,
389 std::set<data::variable>{}, std::set<data::variable>{}}));
405template <
typename DataRewriter,
typename PresRewriter>
411 typedef std::list<detail::quantified_variable>
qvar_list;
455 const std::set<data::variable>& conj_context,
456 const std::set<data::variable>& disj_context,
471 std::ostringstream out;
475 out << qv.to_string();
509 for (
auto it = Q.crbegin(); it != Q.crend(); ++it)
516 result.push_front(*it);
557 return std::all_of(free_vars.begin(), free_vars.end(), [&](
const data::variable& v)
559 return std::find_if(qvars.begin(), qvars.end(), [&](const detail::quantified_variable& qvar){ return qvar.variable() == v; }) != qvars.end();
568 while (!deleted_constraints.empty())
570 std::set<data::variable> vars_deleted;
575 deleted_constraints.clear();
579 return vars_deleted.find(qv.variable()) != vars_deleted.end();
582 m_qvars.erase(m_qvars.begin(), del_i.base());
586 auto k = m_constraints.find(par);
587 if(k == m_constraints.end())
591 if(!bound_in_quantifiers(m_qvars, k->second))
593 deleted_constraints.push_back(k->second);
594 m_constraints.erase(k);
625 return m_constraints;
632 std::vector<std::size_t> result;
633 std::size_t index = 0;
638 result.push_back(index);
649 std::ostringstream out;
650 out << m_variable <<
" assertions = ";
653 out << v.to_string();
655 for (
const auto& constraint: m_constraints)
657 out <<
"{" << constraint.first <<
" := " << constraint.second <<
"} ";
666 bool changed =
false;
680 std::vector<data::data_expression> deleted_constraints;
681 auto par = params.
begin();
682 for (
auto i = e.
begin(); i != e.
end(); ++i, ++par)
685 if (bound_in_quantifiers(m_qvars, e1))
687 m_constraints[*par] = e1;
691 deleted_constraints.push_back(e1);
694 fix_constraints(deleted_constraints);
699 auto mismatch_it = std::mismatch(m_qvars.rbegin(), m_qvars.rend(), qvars.rbegin(), qvars.rend()).first;
700 changed |= mismatch_it != m_qvars.rend();
702 m_qvars.erase(m_qvars.begin(), mismatch_it.base());
706 std::vector<data::data_expression> deleted_constraints;
708 for (
auto par = params.
begin(); i != e.
end(); ++i, ++par)
710 auto k = m_constraints.find(*par);
711 if(k == m_constraints.end())
717 if (fi != ei || !bound_in_quantifiers(m_qvars, fi))
720 deleted_constraints.push_back(fi);
721 deleted_constraints.push_back(ei);
722 m_constraints.erase(k);
725 fix_constraints(deleted_constraints);
732 typedef std::map<core::identifier_string, vertex>
vertex_map;
735 typedef std::map<core::identifier_string, std::vector<edge> >
edge_map;
751 std::ostringstream out;
752 for (
const auto& v: m_vertices)
754 out << v.second.to_string() << std::endl;
762 std::ostringstream out;
763 for (
const auto& source: m_edges)
765 for (
const auto& e: source.second)
767 out << e.to_string() << std::endl;
775 std::ostringstream out;
776 out <<
"\n<todo list> [";
777 for (
auto i = todo.begin(); i != todo.end(); ++i)
779 if (i != todo.begin())
785 out <<
"]" << std::endl;
791 std::ostringstream out;
792 out <<
"\n<updating edge> " << e.
to_string() << std::endl;
793 out <<
" <source vertex > " << u.
to_string() << std::endl;
794 out <<
" <target vertex before> " << v.
to_string() << std::endl;
800 std::ostringstream out;
803 out <<
" <condition > " << e.
condition() <<
sigma <<
" to " << value << std::endl;
809 std::ostringstream out;
812 out <<
"\nCould not evaluate condition " << e.
condition() <<
sigma <<
" to true or false";
816 template <
typename E>
817 std::list<E>
concat(
const std::list<E> a,
const std::list<E> b)
819 std::list<E> result(a);
820 result.insert(result.end(), b.begin(), b.end());
830 : m_data_rewriter(datar), m_pres_rewriter(presr)
837 std::map<propositional_variable, std::vector<data::variable> > result;
838 for (
const std::pair<
const core::identifier_string, std::vector<std::size_t>>& red_pair: m_redundant_parameters)
840 const vertex& v = m_vertices.find(red_pair.first)->second;
841 std::vector<data::variable>& variables = result[v.
variable()];
842 for (
const std::size_t par: red_pair.second)
845 std::advance(k, par);
846 variables.push_back(*k);
856 void run(
pres& p,
bool compute_conditions =
false,
bool check_quantifiers =
true)
860 m_redundant_parameters.clear();
866 m_vertices[name] =
vertex(eqn.variable());
870 f.
apply(eqn.formula());
872 std::vector<edge>& edges = m_edges[name];
873 for (
const auto& [Q_X_e, details]: f.
result())
875 const auto& [Q, X_e] = Q_X_e;
876 const auto& [conditions, conj_FV, disj_FV] = details;
884 edges.emplace_back(eqn.variable(), quantifier_list, X_e, conj_FV, disj_FV, condition);
890 std::deque<propositional_variable> todo;
900 while (!todo.empty())
906 todo.erase(std::remove(todo.begin(), todo.end(), var), todo.end());
908 const vertex& u = m_vertices[var.name()];
909 const std::vector<edge>& u_edges = m_edges[var.name()];
911 for (
const edge& e: u_edges)
913 vertex& v = m_vertices[e.target().name()];
929 e.target().parameters(),
947 const vertex& v = m_vertices[name];
953 m_redundant_parameters[name] = r;
962 const vertex& v = m_vertices[name];
971 body = i->make_expr(body);
988 for (
const std::pair<
const propositional_variable, std::vector<data::variable>>& i: redundant_parameters())
1009 bool compute_conditions =
false,
1010 bool remove_redundant_equations =
true,
1011 bool check_quantifiers =
true
1018 switch (rewriter_type)
1023 pres_rewriter presr(p.
data(), datar);
1025 algorithm.
run(p, compute_conditions, check_quantifiers);
1026 if (remove_redundant_equations)
1028 std::vector<propositional_variable> V = algorithms::remove_unreachable_variables(p);
1033 case quantifier_all:
1034 case quantifier_finite:
1036 bool enumerate_infinite_sorts = (rewriter_type == quantifier_all);
1039 algorithm.
run(p, compute_conditions, check_quantifiers);
1040 if (remove_redundant_equations)
1042 std::vector<propositional_variable> V = algorithms::remove_unreachable_variables(p);
Term containing a string.
const_iterator end() const
Returns a const_iterator pointing to the end of the term_list.
const Term & front() const
Returns the first element of the list.
const_iterator begin() const
Returns a const_iterator pointing to the beginning of the term_list.
data_expression()
\brief Default constructor X3.
Rewriter that operates on data expressions.
basic_rewriter< data_expression >::substitution_type substitution_type
\brief A propositional variable declaration
const data::variable_list & parameters() const
const core::identifier_string & name() const
\brief The and operator for pres expressions
bool operator<(const quantified_variable &other) const
bool operator==(const quantified_variable &other) const
pres_expression make_expr(const pres_expression &expr) const
const data::variable & variable() const
quantified_variable(bool is_infimum, const data::variable &var)
bool operator!=(const quantified_variable &other) const
std::string to_string() const
\brief The implication operator for pres expressions
\brief The infimum over a data type for pres expressions
const data::variable_list & variables() const
\brief The not operator for pres expressions
\brief The or operator for pres expressions
Represents an edge of the dependency graph. The assignments are stored implicitly using the 'right' p...
const propositional_variable_instantiation m_target
The propositional variable instantiation that determines the target of the edge.
edge(const propositional_variable &src, const qvar_list &qvars, const propositional_variable_instantiation &tgt, const std::set< data::variable > &conj_context, const std::set< data::variable > &disj_context, data::data_expression c=data::sort_bool::true_())
Constructor.
const qvar_list m_qvars
The quantifiers in whose direct context the target PVI occurs.
const data::data_expression & condition() const
The condition of the edge.
const std::set< data::variable > m_disj_context
std::string to_string() const
Returns a string representation of the edge.
edge()=default
Constructor.
const propositional_variable & source() const
The propositional variable at the source of the edge.
const qvar_list & quantified_variables() const
const std::set< data::variable > m_conj_context
qvar_list quantifier_inside_approximation(const qvar_list &Q) const
Try to guess which quantifiers of Q can end up directly before target, when the quantifier inside rew...
const propositional_variable m_source
The propositional variable at the source of the edge.
const propositional_variable_instantiation & target() const
The propositional variable instantiation that determines the target of the edge.
Represents a vertex of the dependency graph.
bool update(const qvar_list &qvars, const data::data_expression_list &e, const constraint_map &e_constraints, const DataRewriter &datar)
Assign new values to the parameters of this vertex, and update the constraints accordingly....
const qvar_list & quantified_variables() const
std::vector< std::size_t > constant_parameter_indices() const
Returns the indices of the constant parameters of this vertex.
const constraint_map & constraints() const
Maps data variables to data expressions. If the right hand side is a data variable,...
bool m_visited
Indicates whether this vertex has been visited at least once.
const propositional_variable & variable() const
The propositional variable that corresponds to the vertex.
std::string to_string() const
Returns a string representation of the vertex.
propositional_variable m_variable
The propositional variable that corresponds to the vertex.
vertex()=default
Constructor.
void fix_constraints(std::vector< data::data_expression > deleted_constraints)
Weaken the constraints so they satisfy.
vertex(propositional_variable x)
Constructor.
qvar_list m_qvars
The list of quantified variables that occur in the constraints.
constraint_map m_constraints
Maps data variables to data expressions. If a parameter is not.
bool bound_in_quantifiers(const qvar_list &qvars, const data::data_expression &e)
Returns true iff all free variables in e are bound in qvars.
bool is_constant(const data::variable &v) const
Returns true if the parameter v has been assigned a constant expression.
Algorithm class for the constelm algorithm.
std::string print_condition(const edge &e, const vertex &u, const pres_expression &value)
void run(pres &p, bool compute_conditions=false, bool check_quantifiers=true)
Runs the constelm algorithm.
std::map< core::identifier_string, vertex > vertex_map
The storage type for vertices.
std::map< core::identifier_string, std::vector< edge > > edge_map
The storage type for edges.
vertex_map m_vertices
The vertices of the dependency graph. They are stored in a map, to support searching for a vertex.
pres_constelm_algorithm(const DataRewriter &datar, const PresRewriter &presr)
Constructor.
edge_map m_edges
The edges of the dependency graph. They are stored in a map, to easily access all out-edges correspon...
const PresRewriter & m_pres_rewriter
Compares data expressions for equality.
std::string print_todo_list(const std::deque< propositional_variable > &todo)
std::map< core::identifier_string, std::vector< std::size_t > > m_redundant_parameters
The redundant parameters.
std::string print_evaluation_failure(const edge &e, const vertex &u)
std::string print_edges()
Logs the edges of the dependency graph.
const DataRewriter & m_data_rewriter
Compares data expressions for equality.
std::list< E > concat(const std::list< E > a, const std::list< E > b)
std::string print_edge_update(const edge &e, const vertex &u, const vertex &v)
std::list< detail::quantified_variable > qvar_list
std::string print_vertices() const
Logs the vertices of the dependency graph.
std::map< propositional_variable, std::vector< data::variable > > redundant_parameters() const
Returns the parameters that have been removed by the constelm algorithm.
std::map< data::variable, data::data_expression > constraint_map
A map with constraints on the vertices of the graph.
parameterized boolean equation system
const data::data_specification & data() const
Returns the data specification.
const propositional_variable_instantiation & initial_state() const
Returns the initial state.
const std::vector< pres_equation > & equations() const
Returns the equations.
\brief A propositional variable instantiation
const core::identifier_string & name() const
const data::data_expression_list & parameters() const
\brief The generic sum operator for pres expressions
\brief The supremeum over a data type for pres expressions
const data::variable_list & variables() const
MCRL2_EXPORT bool init(rewriter_interface *i, RewriterCompilingJitty *this_rewriter)
static RewriterCompilingJitty::substitution_type & sigma(RewriterCompilingJitty *this_rewriter)
#define mCRL2log(LEVEL)
mCRL2log(LEVEL) provides the stream used to log.
std::string pp(const identifier_string &x)
data_expression join_and(ForwardTraversalIterator first, ForwardTraversalIterator last)
Returns and applied to the sequence of data expressions [first, last)
const function_symbol & true_()
Constructor for function symbol true.
void optimized_exists(Term &result, const VariableSequence &l, const Term &p, bool remove_variables=false)
Make an existential quantification.
void optimized_or(Term &result, const Term &p, const Term &q)
Make a conjunction, and optimize if possible.
rewrite_strategy
The strategy of the rewriter.
std::string pp(const abstraction &x)
std::set< data::variable > find_free_variables(const data::data_expression &x)
void optimized_not(Term &result, const Term &arg)
Make a negation.
void optimized_and(Term &result, const Term &p, const Term &q)
Make a conjunction, and optimize if possible.
void optimized_forall(Term &result, const VariableSequence &l, const Term &p, bool remove_variables=false)
Make a universal quantification.
void remove_parameters(pres &x, const std::set< data::variable > &to_be_removed)
Removes parameters from propositional variable instantiations in a pres expression.
void make_constelm_substitution(const std::map< data::variable, data::data_expression > &m, data::rewriter::substitution_type &result)
bool is_true(const pres_expression &t)
Test for the value true.
bool is_infimum(const atermpp::aterm &x)
pres_rewriter_type
An enumerated type for the available pres rewriters.
bool is_supremum(const atermpp::aterm &x)
void replace_free_variables(T &x, const Substitution &sigma, typename std::enable_if<!std::is_base_of< atermpp::aterm, T >::value >::type *=nullptr)
bool is_false(const pres_expression &t)
Test for the value false.
bool is_constant(const pres_expression &x)
std::set< T > set_union(const std::set< T > &x, const std::set< T > &y)
Returns the union of two sets.
std::set< T > set_difference(const std::set< T > &x, const std::set< T > &y)
Returns the difference of two sets.
A class that takes a linear process specification and checks all tau-summands of that LPS for conflue...
void swap(atermpp::unprotected_aterm_core &t1, atermpp::unprotected_aterm_core &t2) noexcept
Swaps two aterms.
add your file description here.
add your file description here.
add your file description here.
The class pres_expression.
add your file description here.
void apply(const pres_system::pres_equation &x)
A quantified predicate variable instantiation.
std::list< quantified_variable > Q
propositional_variable_instantiation X_e
bool operator<(const QPVI &other) const
void leave(const minus &)
const stack_elem & top() const
std::list< detail::quantified_variable > qvar_list
void merge_conditions(stack_elem &ec1, bool negate1, stack_elem &ec2, bool negate2, stack_elem &ec, bool is_conjunctive)
stack_elem::edge_map edge_map
void enter(const minus &)
void leave(const supremum &x)
void enter(const infimum &x)
void push(const stack_elem &x)
void leave(const infimum &x)
const edge_map & result() const
edge_traverser_stack_elem stack_elem
std::vector< stack_elem > condition_fv_stack
void leave(const propositional_variable_instantiation &x)
std::list< pres_expression > quantified_context
void leave(const data::data_expression &x)
pres_expression_traverser< edge_condition_traverser > super
void enter(const supremum &x)
std::set< data::variable > conjunctive_context_FV
The set of free variables that occur on the other side of the conjunctions this PVI occurs in....
std::set< data::data_expression > conditions
Contains expressions that characterise when an edge is enabled. The conjunction of these expressions ...
std::set< data::variable > disjunctive_context_FV
The set of free variables that occur on the other side of the conjunctions this PVI occurs in....
edge_traverser_stack_elem(const data::data_expression &cond_pos, const data::data_expression &cond_neg, std::set< data::variable > &&free_vars)
std::multimap< QPVI, edge_details > edge_map
data::data_expression Cpos
std::set< data::variable > FV
data::data_expression Cneg
An attempt for improving the efficiency.
A rewriter that simplifies boolean expressions in a term, and rewrites data expressions.