spot/doc/org/tut02.org
Alexandre Duret-Lutz cb39210166 kill the ltl namespace
* NEWS: Mention it.
* bench/stutter/stutter_invariance_formulas.cc,
bench/stutter/stutter_invariance_randomgraph.cc, doc/mainpage.dox,
doc/org/tut01.org, doc/org/tut02.org, doc/org/tut10.org, doc/tl/tl.tex,
iface/ltsmin/ltsmin.cc, iface/ltsmin/ltsmin.hh,
iface/ltsmin/modelcheck.cc, src/bin/autfilt.cc,
src/bin/common_aoutput.cc, src/bin/common_aoutput.hh,
src/bin/common_finput.cc, src/bin/common_finput.hh,
src/bin/common_output.cc, src/bin/common_output.hh, src/bin/common_r.hh,
src/bin/common_trans.cc, src/bin/common_trans.hh, src/bin/dstar2tgba.cc,
src/bin/genltl.cc, src/bin/ltl2tgba.cc, src/bin/ltl2tgta.cc,
src/bin/ltlcross.cc, src/bin/ltldo.cc, src/bin/ltlfilt.cc,
src/bin/ltlgrind.cc, src/bin/randaut.cc, src/bin/randltl.cc,
src/kripke/kripkeexplicit.cc, src/kripke/kripkeexplicit.hh,
src/kripkeparse/kripkeparse.yy, src/kripkeparse/public.hh,
src/ltlparse/fmterror.cc, src/ltlparse/ltlparse.yy,
src/ltlparse/ltlscan.ll, src/ltlparse/parsedecl.hh,
src/ltlparse/public.hh, src/parseaut/parseaut.yy,
src/parseaut/public.hh, src/tests/checkpsl.cc, src/tests/checkta.cc,
src/tests/complementation.cc, src/tests/consterm.cc,
src/tests/emptchk.cc, src/tests/equalsf.cc, src/tests/ikwiad.cc,
src/tests/kind.cc, src/tests/length.cc, src/tests/ltlprod.cc,
src/tests/ltlrel.cc, src/tests/parse.test,
src/tests/parse_print_test.cc, src/tests/randtgba.cc,
src/tests/readltl.cc, src/tests/reduc.cc, src/tests/syntimpl.cc,
src/tests/taatgba.cc, src/tests/tostring.cc, src/tests/tostring.test,
src/tl/apcollect.cc, src/tl/apcollect.hh, src/tl/contain.cc,
src/tl/contain.hh, src/tl/declenv.cc, src/tl/declenv.hh,
src/tl/defaultenv.cc, src/tl/defaultenv.hh, src/tl/dot.cc,
src/tl/dot.hh, src/tl/environment.hh, src/tl/exclusive.cc,
src/tl/exclusive.hh, src/tl/formula.cc, src/tl/formula.hh,
src/tl/length.cc, src/tl/length.hh, src/tl/mark.cc, src/tl/mark.hh,
src/tl/mutation.cc, src/tl/mutation.hh, src/tl/nenoform.cc,
src/tl/nenoform.hh, src/tl/print.cc, src/tl/print.hh,
src/tl/randomltl.cc, src/tl/randomltl.hh, src/tl/relabel.cc,
src/tl/relabel.hh, src/tl/remove_x.cc, src/tl/remove_x.hh,
src/tl/simpfg.cc, src/tl/simpfg.hh, src/tl/simplify.cc,
src/tl/simplify.hh, src/tl/snf.cc, src/tl/snf.hh, src/tl/unabbrev.cc,
src/tl/unabbrev.hh, src/twa/bdddict.cc, src/twa/bdddict.hh,
src/twa/bddprint.cc, src/twa/formula2bdd.cc, src/twa/formula2bdd.hh,
src/twa/taatgba.cc, src/twa/taatgba.hh, src/twa/twa.hh,
src/twa/twagraph.cc, src/twa/twagraph.hh, src/twaalgos/compsusp.cc,
src/twaalgos/compsusp.hh, src/twaalgos/ltl2taa.cc,
src/twaalgos/ltl2taa.hh, src/twaalgos/ltl2tgba_fm.cc,
src/twaalgos/ltl2tgba_fm.hh, src/twaalgos/minimize.cc,
src/twaalgos/minimize.hh, src/twaalgos/neverclaim.cc,
src/twaalgos/postproc.cc, src/twaalgos/postproc.hh,
src/twaalgos/powerset.cc, src/twaalgos/powerset.hh,
src/twaalgos/randomgraph.cc, src/twaalgos/randomgraph.hh,
src/twaalgos/relabel.cc, src/twaalgos/relabel.hh,
src/twaalgos/remprop.cc, src/twaalgos/remprop.hh, src/twaalgos/stats.cc,
src/twaalgos/stats.hh, src/twaalgos/stutter.cc, src/twaalgos/stutter.hh,
src/twaalgos/translate.cc, src/twaalgos/translate.hh,
wrap/python/spot_impl.i: Remove the ltl namespace.
2015-09-28 16:20:53 +02:00

4.1 KiB

Relabeling Formulas

The task is to read an LTL formula, relabel all (possibly complex) atomic propositions, and provide #define statements for each of these renamings, writing everything in Spin's syntax.

Shell

ltlfilt -ps --relabel=pnn --define -f '"Proc@Here" U ("var > 10" | "var < 4")'
#define p0 (Proc@Here)
#define p1 (var < 4)
#define p2 (var > 10)
(p0) U ((p1) || (p2))

When is this output interesting, you may ask? It is useful for instance if you want to call ltl2ba (or any other LTL-to-Büchi translator) using a formula with complex atomic propositions it cannot parse. Then you can pass the rewritten formula to ltl2ba, and prepend all those #define to its output. For instance:

ltlfilt -ps --relabel=pnn --define=tmp.defs -f '"Proc@Here" U ("var > 10" | "var < 4")' >tmp.ltl
cat tmp.defs; ltl2ba -F tmp.ltl
rm tmp.defs tmp.ltl
#define p0 (Proc@Here)
#define p1 (var < 4)
#define p2 (var > 10)
never { /* (p0) U ((p1) || (p2))
 */
T0_init:
	if
	:: (p0) -> goto T0_init
	:: (p1) || (p2) -> goto accept_all
	fi;
accept_all:
	skip
}

Python

The spot.relabel function takes an optional third parameter that should be a relabeling_map. If supplied, this map is filled with pairs of atomic propositions of the form (new-name, old-name).

import spot
f = spot.formula('"Proc@Here" U ("var > 10" | "var < 4")')
m = spot.relabeling_map()
g = spot.relabel(f, spot.Pnn, m)
for newname, oldname in m.items():
  print("#define {} ({})".format(newname.to_str(), oldname.to_str('spin', True)))
print(g.to_str('spin', True))
#define p0 ((Proc@Here))
#define p1 ((var < 4))
#define p2 ((var > 10))
(p0) U ((p1) || (p2))

C++

The spot::relabeling_map is just a std::map with a custom destructor.

  #include <string>
  #include <iostream>
  #include "ltlparse/public.hh"
  #include "tl/print.hh"
  #include "tl/relabel.hh"

  int main()
  {
    std::string input = "\"Proc@Here\" U (\"var > 10\" | \"var < 4\")";
    spot::parse_error_list pel;
    spot::formula f = spot::parse_infix_psl(input, pel);
    if (spot::format_parse_errors(std::cerr, input, pel))
      return 1;
    spot::relabeling_map m;
    f = spot::relabel(f, spot::Pnn, &m);
    for (auto& i: m)
      {
        std::cout << "#define ";
        print_psl(std::cout, i.first) << " (";
        print_spin_ltl(std::cout, i.second, true) << ")\n";
      }
    print_spin_ltl(std::cout, f, true) << '\n';
    return 0;
  }
#define p0 (Proc@Here)
#define p1 (var < 4)
#define p2 (var > 10)
(p0) U ((p1) || (p2))

Additional comments

Two ways to name atomic propositions

Instead of --relabel=pnn (or spot.Pnn, or spot::Pnn), you can actually use --relabel=abc (or spot.Abc, or spot::Abc) to have the atomic propositions named a, b, c, etc.

Relabeling Boolean sub-expressions

Instead of relabeling each atomic proposition, you could decide to relabel each Boolean sub-expression:

ltlfilt -ps --relabel-bool=pnn --define -f '"Proc@Here" U ("var > 10" | "var < 4")'
#define p0 (Proc@Here)
#define p1 ((var < 4) || (var > 10))
(p0) U (p1)

The relabeling routine is smart enough to not give different names to Boolean expressions that have some sub-expression in common.

For instance a U (a & b) will not be relabeled into (p0) U (p1) because that would hide the fact that both p0 and p1 check for a. Instead we get this:

ltlfilt -ps --relabel-bool=pnn --define -f 'a U (a & b)'
#define p0 (a)
#define p1 (b)
(p0) U ((p0) && (p1))

This "Boolean sub-expression" relabeling is available in Python and C++ via the relabel_bse function. The interface is identical to relabel.