Rewrite "(Xc) M b" as "b & X(b U c)", plus three similar rules.

* src/ltlvisit/simplify.hh (ltl_simplifier_options): New option
reduce_size_stricly.
* src/ltlvisit/simplify.cc (simplify_visitor): Implement these
rules.
* src/ltltest/reduc.cc: Check with reduce_size_strictly unset or
set, but only use the latter result to check sizes.
* src/ltltest/reduccmp.test: Test them.
* doc/tl/tl.tex: Document them.
This commit is contained in:
Alexandre Duret-Lutz 2012-02-13 17:58:57 +01:00
parent c9b34d684a
commit bb56c26d1c
5 changed files with 122 additions and 48 deletions

View file

@ -1,5 +1,5 @@
// Copyright (C) 2008, 2009, 2010, 2011 Laboratoire de Recherche et
// Développement de l'Epita (LRDE).
// Copyright (C) 2008, 2009, 2010, 2011, 2012 Laboratoire de Recherche
// et Développement de l'Epita (LRDE).
// Copyright (C) 2004, 2006, 2007 Laboratoire d'Informatique de Paris
// 6 (LIP6), département Systèmes Répartis Coopératifs (SRC),
// Université Pierre et Marie Curie.
@ -141,6 +141,8 @@ main(int argc, char** argv)
}
spot::ltl::ltl_simplifier* simp = new spot::ltl::ltl_simplifier(o);
o.reduce_size_strictly = true;
spot::ltl::ltl_simplifier* simp_size = new spot::ltl::ltl_simplifier(o);
spot::ltl::formula* f1 = 0;
spot::ltl::formula* f2 = 0;
@ -202,24 +204,35 @@ main(int argc, char** argv)
spot::ltl::formula* ftmp1;
ftmp1 = f1;
f1 = simp->negative_normal_form(f1, false);
f1 = simp_size->negative_normal_form(f1, false);
ftmp1->destroy();
int length_f1_before = spot::ltl::length(f1);
std::string f1s_before = spot::ltl::to_string(f1);
ftmp1 = f1;
f1 = simp->simplify(f1);
if (!simp->are_equivalent(ftmp1, f1))
spot::ltl::formula* input_f = f1;
f1 = simp_size->simplify(input_f);
if (!simp_size->are_equivalent(input_f, f1))
{
std::cerr << "Incorrect reduction from `" << f1s_before
<< "' to `" << spot::ltl::to_string(f1) << "'."
<< std::endl;
exit_code = 3;
}
else
{
spot::ltl::formula* maybe_larger = simp->simplify(input_f);
if (!simp->are_equivalent(input_f, maybe_larger))
{
std::cerr << "Incorrect reduction (reduce_size_strictly=0) from `"
<< f1s_before << "' to `" << spot::ltl::to_string(f1)
<< "'." << std::endl;
exit_code = 3;
}
maybe_larger->destroy();
}
ftmp1->destroy();
input_f->destroy();
int length_f1_after = spot::ltl::length(f1);
std::string f1s_after = spot::ltl::to_string(f1);
@ -228,7 +241,7 @@ main(int argc, char** argv)
if (f2)
{
ftmp1 = f2;
f2 = simp->negative_normal_form(f2, false);
f2 = simp_size->negative_normal_form(f2, false);
ftmp1->destroy();
f2s = spot::ltl::to_string(f2);
}
@ -282,6 +295,7 @@ main(int argc, char** argv)
}
end:
delete simp_size;
delete simp;
if (fin)

View file

@ -1,6 +1,6 @@
#! /bin/sh
# Copyright (C) 2009, 2010, 2011, 2012 Laboratoire de Recherche et Developpement
# de l'Epita (LRDE).
# Copyright (C) 2009, 2010, 2011, 2012 Laboratoire de Recherche et
# Developpement de l'Epita (LRDE).
# Copyright (C) 2004, 2006 Laboratoire d'Informatique de Paris 6 (LIP6),
# département Systčmes Répartis Coopératifs (SRC), Université Pierre
# et Marie Curie.
@ -105,6 +105,13 @@ for x in ../reduccmp ../reductaustr; do
run 0 $x 'Xa & Xb' 'X(a & b)'
run 0 $x 'Xa | Xb' 'X(a | b)'
run 0 $x 'X(a) M X(b)' 'X(a M b)'
run 0 $x 'X(a) W X(b)' 'X(a W b)'
run 0 $x 'X(a) M b' 'b & X(b U a)'
run 0 $x 'X(a) R b' 'b & X(b W a)'
run 0 $x 'X(a) U b' 'b | X(b M a)'
run 0 $x 'X(a) W b' 'b | X(b R a)'
run 0 $x '(a U b) & (c U b)' '(a & c) U b'
run 0 $x '(a R b) & (a R c)' 'a R (b & c)'
run 0 $x '(a U b) | (a U c)' 'a U (b | c)'

View file

@ -1747,6 +1747,24 @@ namespace spot
}
}
}
// If b is Boolean:
// (Xc) U b = b | X(b M c)
// (Xc) W b = b | X(b R c)
if (!opt_.reduce_size_strictly
&& fu1 && fu1->op() == unop::X && b->is_boolean())
{
formula* c = fu1->child()->clone();;
fu1->destroy();
formula* x =
unop::instance(unop::X,
binop::instance(op == binop::U
? binop::M
: binop::R,
b->clone(), c));
result_ =
recurse_destroy(multop::instance(multop::Or, b, x));
return;
}
}
else if (op == binop::M || op == binop::R)
{
@ -1791,6 +1809,25 @@ namespace spot
}
}
}
// If b is Boolean:
// (Xc) R b = b & X(b W c)
// (Xc) M b = b & X(b U c)
if (!opt_.reduce_size_strictly
&& fu1 && fu1->op() == unop::X && b->is_boolean())
{
formula* c = fu1->child()->clone();;
fu1->destroy();
formula* x =
unop::instance(unop::X,
binop::instance(op == binop::M
? binop::U
: binop::W,
b->clone(), c));
result_ =
recurse_destroy(multop::instance(multop::And, b, x));
return;
}
}
}
case binop::Xor:

View file

@ -1,5 +1,5 @@
// Copyright (C) 2011 Laboratoire de Recherche et Developpement de
// l'Epita (LRDE).
// Copyright (C) 2011, 2012 Laboratoire de Recherche et Developpement
// de l'Epita (LRDE).
//
// This file is part of Spot, a model checking library.
//
@ -37,15 +37,15 @@ namespace spot
bool event_univ = true,
bool containment_checks = false,
bool containment_checks_stronger = false,
bool nenoform_stop_on_boolean = false)
bool nenoform_stop_on_boolean = false,
bool reduce_size_strictly = false)
: reduce_basics(basics),
synt_impl(synt_impl),
event_univ(event_univ),
containment_checks(containment_checks),
containment_checks_stronger(containment_checks_stronger),
// If true, Boolean subformulae will not be put into
// negative normal form.
nenoform_stop_on_boolean(nenoform_stop_on_boolean)
nenoform_stop_on_boolean(nenoform_stop_on_boolean),
reduce_size_strictly(reduce_size_strictly)
{
}
@ -57,6 +57,10 @@ namespace spot
// If true, Boolean subformulae will not be put into
// negative normal form.
bool nenoform_stop_on_boolean;
// If true, some rules that produce slightly larger formulae
// will be disabled. Those larger formulae are normally easier
// to translate, so we recommend to set this to false.
bool reduce_size_strictly;
};
// fwd declaration to hide technical details.