Introduce rational operators and trivial simplification rules.
Trivial simplifications rules (such as "FFa=Fa" or "x&1=x") are performed any time a formule is instanciated. * src/ltlast/constant.hh, src/ltlast/constant.cc (true_instance, true_instance_): Declare the true_instance_ as a static member, and move true_instance() into the .hh so it gets inlined. Have true_instance_ as a class variable will ensure that it is the first formula instantiated. Binop simplifications rely on this to order arguments. (false_instance, false_instance_): Likewise. (empty_word_instance, empty_word_instance_): New method and static member. * src/ltlast/formula.hh (formula::formula): If max_count_ ever loops, skip the first three values so that constants always have smaller hash codes. * src/ltlast/binop.hh, src/ltlast/binop.cc (instance): Add simplifications and document them. * src/ltlast/multop.hh (multop::Concat): New operator. * src/ltlast/multop.cc (op_name): Handle Concat. (instance): Inline Concat arguments without reordering. Handle absorbent and neutral elements for all operators. * src/ltlast/unop.hh (unop::Star): New operator. * src/ltlast/unop.cc (op_name): Handle Star. (instance): Handle Star, and add trivial simplifications for other unary operators. * src/ltlparse/ltlparse.yy (OP_CONCAT, OP_STAR, CONST_EMPTYWORD): Declare these new operators and add rules for them. * src/ltlparse/ltlscan.ll (OP_CONCAT, OP_STAR, CONST_EMPTYWORD): Output these new operators. * src/ltltest/equals.test: New tests. * src/ltltest/parse.test: Remove redundant test. * src/ltltest/tunabbrev.test, src/tgbatest/emptchk.test: Adjust tests. * src/ltlvisit/basicreduce.cc, src/ltlvisit/contain.cc, src/ltlvisit/nenoform.cc, src/ltlvisit/reduce.cc, src/ltlvisit/syntimpl.cc, src/ltlvisit/tostring.cc, src/ltlvisit/tunabbrev.cc: Complete visitors to handle new operators. * src/ltltest/nenoform.test: More tests. * src/ltlvisit/lunabbrev.cc (unabbreviate_logic_visitor::visit): Clone formulae before instance() function actually have a chance to destroy them. * src/tgba/formula2bdd.cc, src/tgbaalgos/eltl2tgba_lacim.cc, src/tgbaalgos/ltl2taa.cc, src/tgbaalgos/ltl2tgba_fm.cc, src/tgbaalgos/ltl2tgba_lacim.cc: Adjust switches to assert on new operators.
This commit is contained in:
parent
4fcc4f829c
commit
546559b8c3
29 changed files with 575 additions and 120 deletions
|
|
@ -1,8 +1,8 @@
|
|||
// Copyright (C) 2008, 2009, 2010 Laboratoire de Recherche et
|
||||
// Développement de l'Epita (LRDE).
|
||||
// Copyright (C) 2004, 2007 Laboratoire d'Informatique de
|
||||
// Paris 6 (LIP6), département Systèmes Répartis Coopératifs (SRC),
|
||||
// Université Pierre et Marie Curie.
|
||||
// Paris 6 (LIP6), d<EFBFBD>partement Syst<73>mes R<>partis Coop<6F>ratifs (SRC),
|
||||
// Universit<EFBFBD> Pierre et Marie Curie.
|
||||
//
|
||||
// This file is part of Spot, a model checking library.
|
||||
//
|
||||
|
|
@ -241,6 +241,10 @@ namespace spot
|
|||
case unop::Finish:
|
||||
result_ = unop::instance(unop::Finish, result_);
|
||||
return;
|
||||
|
||||
case unop::Star:
|
||||
result_ = unop::instance(unop::Star, result_);
|
||||
return;
|
||||
}
|
||||
/* Unreachable code. */
|
||||
assert(0);
|
||||
|
|
@ -477,7 +481,7 @@ namespace spot
|
|||
|| b->op() == binop::M)
|
||||
&& b->first() == a)
|
||||
{
|
||||
binop* r =
|
||||
formula* r =
|
||||
binop::instance(binop::M,
|
||||
a->clone(),
|
||||
b->second()->clone());
|
||||
|
|
@ -490,7 +494,7 @@ namespace spot
|
|||
|| b->op() == binop::U)
|
||||
&& b->second() == a)
|
||||
{
|
||||
binop* r =
|
||||
formula* r =
|
||||
binop::instance(binop::U,
|
||||
b->first()->clone(),
|
||||
a->clone());
|
||||
|
|
@ -656,7 +660,7 @@ namespace spot
|
|||
|| b->op() == binop::W)
|
||||
&& b->first() == a)
|
||||
{
|
||||
binop* r =
|
||||
formula* r =
|
||||
binop::instance(binop::W,
|
||||
a->clone(),
|
||||
b->second()->clone());
|
||||
|
|
@ -779,6 +783,9 @@ namespace spot
|
|||
}
|
||||
|
||||
break;
|
||||
case multop::Concat:
|
||||
std::copy(res->begin(), res->end(), tmpOther->end());
|
||||
break;
|
||||
}
|
||||
|
||||
res->clear();
|
||||
|
|
|
|||
|
|
@ -355,6 +355,8 @@ namespace spot
|
|||
}
|
||||
}
|
||||
break;
|
||||
case multop::Concat:
|
||||
break;
|
||||
}
|
||||
if (changed)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
// Copyright (C) 2009, 2010 Laboratoire de Recherche et Développement
|
||||
// de l'Epita (LRDE).
|
||||
// Copyright (C) 2003, 2004 Laboratoire d'Informatique de Paris 6 (LIP6),
|
||||
// département Systèmes Répartis Coopératifs (SRC), Université Pierre
|
||||
// d<EFBFBD>partement Syst<73>mes R<>partis Coop<6F>ratifs (SRC), Universit<69> Pierre
|
||||
// et Marie Curie.
|
||||
//
|
||||
// This file is part of Spot, a model checking library.
|
||||
|
|
@ -49,14 +49,15 @@ namespace spot
|
|||
{
|
||||
/* f1 ^ f2 == (f1 & !f2) | (f2 & !f1) */
|
||||
case binop::Xor:
|
||||
result_ = multop::instance(multop::Or,
|
||||
multop::instance(multop::And, f1->clone(),
|
||||
unop::instance(unop::Not,
|
||||
f2)),
|
||||
multop::instance(multop::And, f2->clone(),
|
||||
unop::instance(unop::Not,
|
||||
f1)));
|
||||
return;
|
||||
{
|
||||
formula* a = multop::instance(multop::And, f1->clone(),
|
||||
unop::instance(unop::Not,
|
||||
f2->clone()));
|
||||
formula* b = multop::instance(multop::And, f2,
|
||||
unop::instance(unop::Not, f1));
|
||||
result_ = multop::instance(multop::Or, a, b);
|
||||
return;
|
||||
}
|
||||
/* f1 => f2 == !f1 | f2 */
|
||||
case binop::Implies:
|
||||
result_ = multop::instance(multop::Or,
|
||||
|
|
@ -64,15 +65,18 @@ namespace spot
|
|||
return;
|
||||
/* f1 <=> f2 == (f1 & f2) | (!f1 & !f2) */
|
||||
case binop::Equiv:
|
||||
result_ = multop::instance(multop::Or,
|
||||
multop::instance(multop::And,
|
||||
f1->clone(), f2->clone()),
|
||||
multop::instance(multop::And,
|
||||
unop::instance(unop::Not,
|
||||
f1),
|
||||
unop::instance(unop::Not,
|
||||
f2)));
|
||||
return;
|
||||
{
|
||||
formula* f1c = f1->clone();
|
||||
formula* f2c = f2->clone();
|
||||
|
||||
result_ =
|
||||
multop::instance(multop::Or,
|
||||
multop::instance(multop::And, f1c, f2c),
|
||||
multop::instance(multop::And,
|
||||
unop::instance(unop::Not, f1),
|
||||
unop::instance(unop::Not, f2)));
|
||||
return;
|
||||
}
|
||||
/* f1 U f2 == f1 U f2 */
|
||||
/* f1 R f2 == f1 R f2 */
|
||||
/* f1 W f2 == f1 W f2 */
|
||||
|
|
|
|||
|
|
@ -76,6 +76,10 @@ namespace spot
|
|||
case constant::False:
|
||||
result_ = constant::true_instance();
|
||||
return;
|
||||
case constant::EmptyWord:
|
||||
result_ = unop::instance(unop::Not,
|
||||
constant::empty_word_instance());
|
||||
return;
|
||||
}
|
||||
/* Unreachable code. */
|
||||
assert(0);
|
||||
|
|
@ -104,12 +108,18 @@ namespace spot
|
|||
result_ = unop::instance(negated_ ? unop::F : unop::G,
|
||||
recurse(f));
|
||||
return;
|
||||
|
||||
case unop::Finish:
|
||||
/* Finish(x) is not simplified */
|
||||
result_ = unop::instance(unop::Finish, recurse_(f, false));
|
||||
if (negated_)
|
||||
result_ = unop::instance(unop::Not, result_);
|
||||
return;
|
||||
case unop::Star:
|
||||
/* !(a*) is not simplified */
|
||||
result_ = unop::instance(unop::Star, recurse_(f, false));
|
||||
if (negated_)
|
||||
result_ = unop::instance(unop::Not, result_);
|
||||
return;
|
||||
}
|
||||
/* Unreachable code. */
|
||||
assert(0);
|
||||
|
|
@ -184,9 +194,9 @@ namespace spot
|
|||
void
|
||||
visit(multop* mo)
|
||||
{
|
||||
multop::type op = mo->op();
|
||||
/* !(a & b & c) == !a | !b | !c */
|
||||
/* !(a | b | c) == !a & !b & !c */
|
||||
multop::type op = mo->op();
|
||||
if (negated_)
|
||||
switch (op)
|
||||
{
|
||||
|
|
@ -196,12 +206,25 @@ namespace spot
|
|||
case multop::Or:
|
||||
op = multop::And;
|
||||
break;
|
||||
case multop::Concat:
|
||||
break;
|
||||
}
|
||||
multop::vec* res = new multop::vec;
|
||||
unsigned mos = mo->size();
|
||||
for (unsigned i = 0; i < mos; ++i)
|
||||
res->push_back(recurse(mo->nth(i)));
|
||||
result_ = multop::instance(op, res);
|
||||
if (op != multop::Concat)
|
||||
{
|
||||
for (unsigned i = 0; i < mos; ++i)
|
||||
res->push_back(recurse(mo->nth(i)));
|
||||
result_ = multop::instance(op, res);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (unsigned i = 0; i < mos; ++i)
|
||||
res->push_back(recurse_(mo->nth(i), false));
|
||||
result_ = multop::instance(op, res);
|
||||
if (negated_)
|
||||
result_ = unop::instance(unop::Not, result_);
|
||||
}
|
||||
}
|
||||
|
||||
formula*
|
||||
|
|
|
|||
|
|
@ -256,6 +256,11 @@ namespace spot
|
|||
case unop::Finish:
|
||||
result_ = unop::instance(unop::Finish, result_);
|
||||
return;
|
||||
|
||||
case unop::Star:
|
||||
result_ = unop::instance(unop::Star, result_);
|
||||
return;
|
||||
|
||||
}
|
||||
/* Unreachable code. */
|
||||
assert(0);
|
||||
|
|
@ -470,7 +475,8 @@ namespace spot
|
|||
for (unsigned i = 0; i < mos; ++i)
|
||||
res->push_back(recurse(mo->nth(i)));
|
||||
|
||||
if (opt_ & Reduce_Syntactic_Implications)
|
||||
if ((opt_ & Reduce_Syntactic_Implications)
|
||||
&& (mo->op() != multop::Concat))
|
||||
{
|
||||
|
||||
bool removed = true;
|
||||
|
|
|
|||
|
|
@ -74,6 +74,8 @@ namespace spot
|
|||
case constant::False:
|
||||
result_ = false;
|
||||
return;
|
||||
case constant::EmptyWord:
|
||||
result_ = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -105,6 +107,8 @@ namespace spot
|
|||
return;
|
||||
case unop::Finish:
|
||||
return;
|
||||
case unop::Star:
|
||||
return;
|
||||
}
|
||||
/* Unreachable code. */
|
||||
assert(0);
|
||||
|
|
@ -195,6 +199,8 @@ namespace spot
|
|||
if (syntactic_implication(f, mo->nth(i)))
|
||||
result_ = true;
|
||||
break;
|
||||
case multop::Concat:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -230,6 +236,15 @@ namespace spot
|
|||
return false;
|
||||
}
|
||||
|
||||
bool
|
||||
special_case_check(const formula* f2)
|
||||
{
|
||||
const binop* f2b = dynamic_cast<const binop*>(f2);
|
||||
if (!f2b)
|
||||
return false;
|
||||
return special_case(f2b);
|
||||
}
|
||||
|
||||
int
|
||||
result() const
|
||||
{
|
||||
|
|
@ -257,6 +272,9 @@ namespace spot
|
|||
case constant::False:
|
||||
result_ = true;
|
||||
return;
|
||||
case constant::EmptyWord:
|
||||
result_ = true;
|
||||
return;
|
||||
}
|
||||
/* Unreachable code. */
|
||||
assert(0);
|
||||
|
|
@ -283,10 +301,10 @@ namespace spot
|
|||
case unop::F:
|
||||
{
|
||||
/* F(a) = true U a */
|
||||
const binop* tmp = binop::instance(binop::U,
|
||||
constant::true_instance(),
|
||||
f1->clone());
|
||||
if (special_case(tmp))
|
||||
const formula* tmp = binop::instance(binop::U,
|
||||
constant::true_instance(),
|
||||
f1->clone());
|
||||
if (special_case_check(tmp))
|
||||
{
|
||||
result_ = true;
|
||||
tmp->destroy();
|
||||
|
|
@ -300,10 +318,10 @@ namespace spot
|
|||
case unop::G:
|
||||
{
|
||||
/* G(a) = false R a */
|
||||
const binop* tmp = binop::instance(binop::R,
|
||||
constant::false_instance(),
|
||||
f1->clone());
|
||||
if (special_case(tmp))
|
||||
const formula* tmp = binop::instance(binop::R,
|
||||
constant::false_instance(),
|
||||
f1->clone());
|
||||
if (special_case_check(tmp))
|
||||
{
|
||||
result_ = true;
|
||||
tmp->destroy();
|
||||
|
|
@ -316,6 +334,8 @@ namespace spot
|
|||
}
|
||||
case unop::Finish:
|
||||
return;
|
||||
case unop::Star:
|
||||
return;
|
||||
}
|
||||
/* Unreachable code. */
|
||||
assert(0);
|
||||
|
|
@ -431,6 +451,8 @@ namespace spot
|
|||
return;
|
||||
result_ = true;
|
||||
break;
|
||||
case multop::Concat:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -174,6 +174,10 @@ namespace spot
|
|||
os_ << "finish";
|
||||
need_parent = true;
|
||||
break;
|
||||
case unop::Star:
|
||||
// Do not output anything yet, star is a postfix operator.
|
||||
need_parent = false;
|
||||
break;
|
||||
}
|
||||
|
||||
top_level_ = false;
|
||||
|
|
@ -185,6 +189,9 @@ namespace spot
|
|||
|
||||
if (full_parent_ && !top_level)
|
||||
os_ << ")";
|
||||
|
||||
if (uo->op() == unop::Star)
|
||||
os_ << "*";
|
||||
}
|
||||
|
||||
void
|
||||
|
|
@ -227,6 +234,9 @@ namespace spot
|
|||
case multop::And:
|
||||
ch = " & ";
|
||||
break;
|
||||
case multop::Concat:
|
||||
ch = ";";
|
||||
break;
|
||||
}
|
||||
|
||||
for (unsigned n = 1; n < max; ++n)
|
||||
|
|
@ -351,6 +361,11 @@ namespace spot
|
|||
os_ << "finish";
|
||||
need_parent = true;
|
||||
break;
|
||||
case unop::Star:
|
||||
// Do not output anything yet, star is a postfix operator.
|
||||
// FIXME: is there a better way to output "Star" for Spin?
|
||||
need_parent = false;
|
||||
break;
|
||||
}
|
||||
|
||||
top_level_ = false;
|
||||
|
|
@ -359,6 +374,8 @@ namespace spot
|
|||
uo->child()->accept(*this);
|
||||
if (need_parent)
|
||||
os_ << ")";
|
||||
if (uo->op() == unop::Star)
|
||||
os_ << "*";
|
||||
if (full_parent_ && !top_level)
|
||||
os_ << ")";
|
||||
}
|
||||
|
|
@ -403,6 +420,9 @@ namespace spot
|
|||
case multop::And:
|
||||
ch = " && ";
|
||||
break;
|
||||
case multop::Concat:
|
||||
ch = ";";
|
||||
break;
|
||||
}
|
||||
|
||||
for (unsigned n = 1; n < max; ++n)
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
// Copyright (C) 2003 Laboratoire d'Informatique de Paris 6 (LIP6),
|
||||
// Copyright (C) 2003, 2009 Laboratoire d'Informatique de Paris 6 (LIP6),
|
||||
// département Systèmes Répartis Coopératifs (SRC), Université Pierre
|
||||
// et Marie Curie.
|
||||
//
|
||||
|
|
@ -42,6 +42,7 @@ namespace spot
|
|||
case unop::Finish:
|
||||
case unop::X:
|
||||
case unop::Not:
|
||||
case unop::Star:
|
||||
this->super::visit(uo);
|
||||
return;
|
||||
case unop::F:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue