mCRL2
Loading...
Searching...
No Matches
complement.h
Go to the documentation of this file.
1// Author(s): 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//
9/// \file complement.h
10/// \brief The complement function for pbes expressions.
11//
12// Comp ( val(b) ) = val (! b)
13//
14// Comp ( X(d) ) = "ABORT, should not happen"
15//
16// Comp ( PbesAnd (f, g) ) = PbesOr (Comp (f), Comp (g) )
17//
18// Comp ( PbesOr (f, g) ) = PbesAnd (Comp (f), Comp (g) )
19//
20// Comp (PbesForAll (f) ) = PbesExists (Comp (f) )
21//
22// Comp (PbesExists (f) ) = PbesForall (Comp (f) )
23//
24// Comp (Comp (f) ) = f
25
26#ifndef MCRL2_PBES_COMPLEMENT_H
27#define MCRL2_PBES_COMPLEMENT_H
28
29#include "mcrl2/data/consistency.h"
30#include "mcrl2/pbes/builder.h"
31
32
33
34namespace mcrl2::pbes_system
35{
36
37/// \cond INTERNAL_DOCS
38// \brief Visitor that pushes a negation in a PBES expression as far as possible
39// inwards towards a data expression.
40template <typename Derived>
41struct complement_builder: public pbes_expression_builder<Derived>
42{
43 using super = pbes_expression_builder<Derived>;
44 using super::enter;
45 using super::leave;
46 using super::update;
47 using super::apply;
48
49 template <class T>
50 void apply(T& result, const data::data_expression& x)
51 {
52 result = pbes_system::not_(atermpp::down_cast<pbes_expression>(x));
53 }
54
55 template <class T>
56 void apply(T& result, const and_& x)
57 {
58 pbes_expression left;
59 static_cast<Derived&>(*this).apply(left, x.left());
60 pbes_expression right;
61 static_cast<Derived&>(*this).apply(right, x.right());
62 optimized_or(result, left, right);
63 }
64
65 template <class T>
66 void apply(T& result, const or_& x)
67 {
68 pbes_expression left;
69 static_cast<Derived&>(*this).apply(left, x.left());
70 pbes_expression right;
71 static_cast<Derived&>(*this).apply(right, x.right());
72 optimized_and(result, left, right);
73 }
74
75 template <class T>
76 void apply(T& /* result */, const propositional_variable_instantiation& x)
77 {
78 throw mcrl2::runtime_error(std::string("complement_builder error: unexpected propositional variable encountered ") + mcrl2::pbes_system::pp(x));
79 }
80};
81/// \endcond
82
83/// \brief Returns the complement of a pbes expression
84/// \param x A PBES expression
85/// \return The expression obtained by pushing the negations in the pbes
86/// expression as far as possible inwards towards a data expression.
87inline
89{
90 pbes_expression result;
91 core::make_apply_builder<complement_builder>().apply(result, x);
92 return result;
93}
94
95} // namespace mcrl2::pbes_system
96
97
98
99#endif // MCRL2_PBES_COMPLEMENT_H
\brief The and operator for pbes expressions
const pbes_expression & left() const
const pbes_expression & right() const
\brief The or operator for pbes expressions
const pbes_expression & left() const
const pbes_expression & right() const
\brief A propositional variable instantiation
pbes_expression complement(const pbes_expression &x)
Returns the complement of a pbes expression.
Definition complement.h:88