File: regfrmtrans.cpp

package info (click to toggle)
mcrl2 201409.0-1
  • links: PTS, VCS
  • area: main
  • in suites: buster, jessie, jessie-kfreebsd
  • size: 46,348 kB
  • ctags: 29,960
  • sloc: cpp: 213,160; ansic: 16,219; python: 13,238; yacc: 309; lex: 214; xml: 197; makefile: 83; sh: 82; pascal: 17
file content (216 lines) | stat: -rwxr-xr-x 7,935 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
// Author(s): Aad Mathijssen
// Copyright: see the accompanying file COPYING or copy at
// https://svn.win.tue.nl/trac/MCRL2/browser/trunk/COPYING
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
/// \file regfrmtrans.cpp

#include "mcrl2/utilities/logger.h"
#include "mcrl2/data/xyz_identifier_generator.h"
#include "mcrl2/modal_formula/translate_regular_formulas.h"

using namespace mcrl2::core;
using namespace mcrl2::core::detail;
using namespace mcrl2::data;
using namespace mcrl2::state_formulas;
using namespace mcrl2::regular_formulas;

namespace mcrl2
{
namespace regular_formulas
{
namespace detail
{

//local declarations
//------------------

static state_formula translate_reg_frms_appl(state_formula part, xyz_identifier_generator &xyz_generator);
/*Pre: part represents a part of a state formula
 *     after the data implementation phase
 *Ret: part in which all regular formulas are translated in terms of state and
 *     action formulas
 */

//implementation
//--------------

state_formula translate_reg_frms(const state_formula &state_frm)
{
  xyz_identifier_generator xyz_generator(find_identifiers(state_frm));
  return translate_reg_frms_appl(state_frm, xyz_generator);
}

static state_formula translate_reg_frms_appl(state_formula part, xyz_identifier_generator &xyz_generator)
{
  if (data::is_data_expression(part) ||
      lps::is_multi_action(part) ||
      state_formulas::is_variable(part) ||
      data::is_assignment(part) ||
      state_formulas::is_true(part) ||
      state_formulas::is_false(part) ||
      state_formulas::is_yaled(part) ||
      state_formulas::is_yaled_timed(part) ||
      state_formulas::is_delay(part) ||
      state_formulas::is_delay_timed(part)
     )
  {
    //part is a data expression, a multiaction, a state variable or a data
    //variable declaration (with or without initialisation); return part
  }
  else if (state_formulas::is_must(part))
  {
    //part is the must operator; return equivalent non-regular formula
    const regular_formula reg_frm = must(part).formula();
    const state_formula phi = must(part).operand();
    if (regular_formulas::is_nil(reg_frm))
    {
      //red([nil]phi) -> red([false*]phi)
      part = translate_reg_frms_appl(must(trans_or_nil(false_()), phi),xyz_generator);
    }
    else if (regular_formulas::is_seq(reg_frm))
    {
      const regular_formula R1 = seq(reg_frm).left();
      const regular_formula R2 = seq(reg_frm).right();
      //red([R1.R2]phi) -> red([R1][R2]phi)
      part = translate_reg_frms_appl(must(R1, must(R2, phi)),xyz_generator);
    }
    else if (regular_formulas::is_alt(reg_frm))
    {
      const regular_formula R1 = alt(reg_frm).left();
      const regular_formula R2 = alt(reg_frm).right();
      //red([R1+R2]phi) -> red([R1]phi) && red([R2]phi)
      part = and_(
               translate_reg_frms_appl(must(R1,phi),xyz_generator),
               translate_reg_frms_appl(must(R2,phi),xyz_generator)
             );
    }
    else if (regular_formulas::is_trans(reg_frm))
    {
      const regular_formula R = trans(atermpp::aterm_appl(reg_frm)).operand();
      //red([R+]phi) -> red([R.R*]phi)
      part = translate_reg_frms_appl(must(seq(R,trans_or_nil(R)),phi),xyz_generator);
    }
    else if (regular_formulas::is_trans_or_nil(reg_frm))
    {
      const regular_formula R = trans_or_nil(atermpp::aterm_appl(reg_frm)).operand();
      //red([R*]phi) -> nu X. red(phi) && red([R]X),
      //where X does not occur free in phi and R
      const identifier_string X = xyz_generator("X");
      part = nu(X, assignment_list(), and_(
                     translate_reg_frms_appl(phi,xyz_generator),
                     translate_reg_frms_appl(must(R,mcrl2::state_formulas::variable(X, data_expression_list())),xyz_generator)
               ));
    }
    else
    {
      //reg_frm is an action formula; reduce phi
      part = must(reg_frm, translate_reg_frms_appl(phi,xyz_generator));
    }
  }
  else if (state_formulas::is_may(part))
  {
    //part is the may operator; return equivalent non-regular formula
    regular_formula reg_frm = may(part).formula();
    state_formula phi = may(part).operand();
    if (regular_formulas::is_nil(reg_frm))
    {
      //red(<nil>phi) -> red(<false*>phi)
      part = translate_reg_frms_appl(may(trans_or_nil(false_()), phi),xyz_generator);
    }
    else if (regular_formulas::is_seq(reg_frm))
    {
      const regular_formula R1 = seq(reg_frm).left();
      const regular_formula R2 = seq(reg_frm).right();
      //red(<R1.R2>phi) -> red(<R1><R2>phi)
      part = translate_reg_frms_appl(may(R1, may(R2, phi)),xyz_generator);
    }
    else if (regular_formulas::is_alt(reg_frm))
    {
      const regular_formula R1 = alt(reg_frm).left();
      const regular_formula R2 = alt(reg_frm).right();
      //red(<R1+R2>phi) -> red(<R1>phi) || red(<R2>phi)
      part = or_(
               translate_reg_frms_appl(may(R1,phi),xyz_generator),
               translate_reg_frms_appl(may(R2,phi),xyz_generator)
             );
    }
    else if (regular_formulas::is_trans(reg_frm))
    {
      const regular_formula R = trans(atermpp::aterm_appl(reg_frm)).operand();
      //red(<R+>phi) -> red(<R.R*>phi)
      part = translate_reg_frms_appl(may(seq(R,trans_or_nil(R)),phi),xyz_generator);
    }
    else if (regular_formulas::is_trans_or_nil(reg_frm))
    {
      const regular_formula R = trans_or_nil(atermpp::aterm_appl(reg_frm)).operand();
      //red(<R*>phi) -> mu X. red(phi) || red(<R>X),
      //where X does not occur free in phi and R
      const identifier_string X =xyz_generator("X");
      part = mu(X, assignment_list(), or_(
                     translate_reg_frms_appl(phi,xyz_generator),
                     translate_reg_frms_appl(may(R,mcrl2::state_formulas::variable(X, data_expression_list())),xyz_generator)
               ));
    }
    else
    {
      //reg_frm is an action formula; reduce phi
      part = may(reg_frm, translate_reg_frms_appl(phi,xyz_generator));
    }
  }
  else if (state_formulas::is_not(part))
  {
    const not_& not_part = atermpp::down_cast<not_>(part);
    part = not_(translate_reg_frms_appl(not_part.operand(),xyz_generator));
  }
  else if (state_formulas::is_and(part))
  {
    part = and_(translate_reg_frms_appl(and_(part).left(),xyz_generator),
                translate_reg_frms_appl(and_(part).right(),xyz_generator));
  }
  else if (state_formulas::is_or(part))
  {
    part = or_(translate_reg_frms_appl(or_(part).left(),xyz_generator),
               translate_reg_frms_appl(or_(part).right(),xyz_generator));
  }
  else if (state_formulas::is_imp(part))
  {
    part = imp(translate_reg_frms_appl(imp(part).left(),xyz_generator),
                translate_reg_frms_appl(imp(part).right(),xyz_generator));
  }
  else if (state_formulas::is_forall(part))
  {
    part = mcrl2::state_formulas::forall(mcrl2::state_formulas::forall(part).variables(),
                  translate_reg_frms_appl(mcrl2::state_formulas::forall(part).body(),xyz_generator));
  }
  else if (state_formulas::is_exists(part))
  {
    part = mcrl2::state_formulas::exists(mcrl2::state_formulas::exists(part).variables(),
                  translate_reg_frms_appl(mcrl2::state_formulas::exists(part).body(),xyz_generator));
  }
  else if (state_formulas::is_nu(part))
  {
    const nu nu_part(part);
    part = nu(nu_part.name(),nu_part.assignments(),
                  translate_reg_frms_appl(nu_part.operand(),xyz_generator));
  }
  else if (state_formulas::is_mu(part))
  {
    const mu mu_part(part);
    part = mu(mu_part.name(),mu_part.assignments(),
                  translate_reg_frms_appl(mu_part.operand(),xyz_generator));
  }
  else
  {
    assert(0); //Unexpected state_formula.
  }

  return part;
}

}   // namespace detail
}   // namespace regular_formulas
}     // namespace mcrl2