Commit 4cd10c3d authored by martinez's avatar martinez
Browse files

* src/ltlvisit/Makefile.am: Copyright 2004.

* src/ltltest/inf.test: More test.
* src/ltlvisit/basereduc.cc, src/ltlvisit/forminf.cc (spot):
Use dynamic_cast.
* src/ltlvisit/reducform.cc, src/ltlvisit/reducform.hh,
src/ltltest/reduc.test, src/ltltest/reduc.cc: Add an option
to choose which rules applies to simplify the formula.
parent f7e5fe08
2004-05-13 Thomas Martinez <martinez@src.lip6.fr>
* src/ltlvisit/Makefile.am: Copyright 2004.
* src/ltltest/inf.test: More test.
* src/ltlvisit/basereduc.cc, src/ltlvisit/forminf.cc (spot):
Use dynamic_cast.
* src/ltlvisit/reducform.cc, src/ltlvisit/reducform.hh,
src/ltltest/reduc.test, src/ltltest/reduc.cc: Add an option
to choose which rules applies to simplify the formula.
2004-05-13 Alexandre Duret-Lutz <adl@src.lip6.fr> 2004-05-13 Alexandre Duret-Lutz <adl@src.lip6.fr>
* src/ltltest/reduc.test: Typo. * src/ltltest/reduc.test: Typo.
......
...@@ -26,6 +26,27 @@ ...@@ -26,6 +26,27 @@
. ./defs || exit 1 . ./defs || exit 1
# #
run 1 ./inf 'Xa' 'X(b U a)'
run 1 ./inf 'XXa' 'XX(b U a)'
run 1 ./inf '(e R f)' '(g U f)'
run 1 ./inf '( X(a + b))' '( X((a + b)+(c)+(d)))'
run 1 ./inf '( X(a + b)) U (e R f)' '( X((a + b)+(c)+(d))) U (g U f)'
run 0 ./inf 'Xa' 'XX(b U a)'
run 0 ./inf 'XXa' 'X(b U a)'
run 0 ./inf '( X(a + b))' '( X(X(a + b)+(c)+(d)))'
run 0 ./inf '( X(a + b)) U (e R f)' '( X(X(a + b)+(c)+(d))) U (g U f)'
run 0 ./inf 'a' 'b'
run 0 ./inf 'a' 'b + c'
run 0 ./inf 'a + b' 'a'
run 0 ./inf 'a' 'a * c'
run 0 ./inf 'a * b' 'c'
run 0 ./inf 'a' 'a U b'
run 0 ./inf 'a' 'a R b'
run 0 ./inf 'a R b' 'a'
run 1 ./inf '1' '1' run 1 ./inf '1' '1'
run 1 ./inf '0' '0' run 1 ./inf '0' '0'
...@@ -52,6 +73,9 @@ run 1 ./inf 'a' 'a R 1' ...@@ -52,6 +73,9 @@ run 1 ./inf 'a' 'a R 1'
run 1 ./inf 'a R b' 'b' run 1 ./inf 'a R b' 'b'
run 1 ./inf 'a R b' '1' run 1 ./inf 'a R b' '1'
run 1 ./inf 'Xa' 'X(b U a)'
run 1 ./inf 'X(a R b)' 'Xb'
run 1 ./inf 'a U b' '1 U b' run 1 ./inf 'a U b' '1 U b'
run 1 ./inf 'a R b' '1 R b' run 1 ./inf 'a R b' '1 R b'
......
...@@ -34,30 +34,45 @@ ...@@ -34,30 +34,45 @@
void void
syntax(char* prog) syntax(char* prog)
{ {
std::cerr << prog << " formula1 (formula2)?" << std::endl; std::cerr << prog << " option formula1 (formula2)?" << std::endl;
exit(2); exit(2);
} }
typedef spot::ltl::formula* ptrfunct(const spot::ltl::formula*);
int int
main(int argc, char** argv) main(int argc, char** argv)
{ {
if (argc < 2) if (argc < 3)
syntax(argv[0]); syntax(argv[0]);
spot::ltl::option o;
switch(atoi(argv[1])){
case 0:
o = spot::ltl::Base;
break;
case 1:
o = spot::ltl::Inf;
break;
case 2:
o = spot::ltl::EventualUniversal;
break;
case 3:
o = spot::ltl::BRI;
break;
default: return 2;
}
spot::ltl::parse_error_list p1; spot::ltl::parse_error_list p1;
spot::ltl::formula* f1 = spot::ltl::parse(argv[1], p1); spot::ltl::formula* f1 = spot::ltl::parse(argv[2], p1);
spot::ltl::formula* f2 = NULL; spot::ltl::formula* f2 = NULL;
if (spot::ltl::format_parse_errors(std::cerr, argv[1], p1)) if (spot::ltl::format_parse_errors(std::cerr, argv[2], p1))
return 2; return 2;
if (argc == 3){ if (argc == 4){
spot::ltl::parse_error_list p2; spot::ltl::parse_error_list p2;
f2 = spot::ltl::parse(argv[2], p2); f2 = spot::ltl::parse(argv[3], p2);
if (spot::ltl::format_parse_errors(std::cerr, argv[2], p2)) if (spot::ltl::format_parse_errors(std::cerr, argv[3], p2))
return 2; return 2;
} }
...@@ -78,7 +93,7 @@ main(int argc, char** argv) ...@@ -78,7 +93,7 @@ main(int argc, char** argv)
std::string f1s_before = spot::ltl::to_string(f1); std::string f1s_before = spot::ltl::to_string(f1);
ftmp1 = f1; ftmp1 = f1;
f1 = spot::ltl::reduce(f1); f1 = spot::ltl::reduce(f1,o);
ftmp2 = f1; ftmp2 = f1;
f1 = spot::ltl::unabbreviate_logic(f1); f1 = spot::ltl::unabbreviate_logic(f1);
spot::ltl::destroy(ftmp1); spot::ltl::destroy(ftmp1);
...@@ -134,13 +149,6 @@ main(int argc, char** argv) ...@@ -134,13 +149,6 @@ main(int argc, char** argv)
if (length_f1_after < length_f1_before) exit_code = 0; if (length_f1_after < length_f1_before) exit_code = 0;
} }
/*
spot::ltl::dump(std::cout, f1); std::cout << std::endl;
if (f2 != NULL)
spot::ltl::dump(std::cout, f2); std::cout << std::endl;
*/
spot::ltl::destroy(f1); spot::ltl::destroy(f1);
if (f2 != NULL) if (f2 != NULL)
spot::ltl::destroy(f2); spot::ltl::destroy(f2);
......
...@@ -23,30 +23,37 @@ ...@@ -23,30 +23,37 @@
# Check for the reduc visitor. # Check for the reduc visitor.
. ./defs || exit 1 #. ./defs || exit 1
set -e set -e
FICH=${1-$srcdir/formules.ltl} #FICH=${1-$srcdir/formules.ltl}
FICH=${1-formules.ltl}
##################################### #####################################
rm -f result.data for opt in 0 1 2 3
do
cat $FICH | rm -f result.data
while read f; do
if [ -n "$f" ] && [ "$f" != "####" ]; then cat $FICH |
./reduc "$f" >> result.data while read f; do
fi if [ -n "$f" ] && [ "$f" != "####" ]; then
done ./reduc $opt "$f" >> result.data
fi
test $? == 0 || exit 1 done
test $? == 0 || exit 1
##################################### #####################################
perl -ne 'BEGIN { $sum1 = 0; $sum2 = 0; } perl -ne 'BEGIN { $sum1 = 0; $sum2 = 0; }
/^(\d+)\s+(\d+)/; /^(\d+)\s+(\d+)/;
$sum1 += $1; $sum1 += $1;
$sum2 += $2; $sum2 += $2;
END { print $sum2 * 100 / $sum1; print "\n"; } END { print 100 - ($sum2 * 100 / $sum1); print "\n"; }
' < result.data ' < result.data
done
#####################################
## Copyright (C) 2003 Laboratoire d'Informatique de Paris 6 (LIP6), ## Copyright (C) 2004 Laboratoire d'Informatique de Paris 6 (LIP6),
## dpartement Systmes Rpartis Coopratifs (SRC), Universit Pierre ## dpartement Systmes Rpartis Coopratifs (SRC), Universit Pierre
## et Marie Curie. ## et Marie Curie.
## ##
......
// Copyright (C) 2003 Laboratoire d'Informatique de Paris 6 (LIP6), // Copyright (C) 2004 Laboratoire d'Informatique de Paris 6 (LIP6),
// dpartement Systmes Rpartis Coopratifs (SRC), Universit Pierre // dpartement Systmes Rpartis Coopratifs (SRC), Universit Pierre
// et Marie Curie. // et Marie Curie.
// //
...@@ -33,9 +33,9 @@ namespace spot ...@@ -33,9 +33,9 @@ namespace spot
class basic_reduce_form_visitor : public visitor class basic_reduce_form_visitor : public visitor
{ {
public: public:
basic_reduce_form_visitor(){} basic_reduce_form_visitor(){}
virtual ~basic_reduce_form_visitor(){} virtual ~basic_reduce_form_visitor(){}
formula* formula*
...@@ -43,14 +43,14 @@ namespace spot ...@@ -43,14 +43,14 @@ namespace spot
{ {
return result_; return result_;
} }
void void
visit(atomic_prop* ap) visit(atomic_prop* ap)
{ {
formula* f = ap->ref(); formula* f = ap->ref();
result_ = f; result_ = f;
} }
void void
visit(constant* c) visit(constant* c)
{ {
...@@ -64,7 +64,7 @@ namespace spot ...@@ -64,7 +64,7 @@ namespace spot
return; return;
} }
} }
void void
visit(unop* uo) visit(unop* uo)
{ {
...@@ -77,35 +77,35 @@ namespace spot ...@@ -77,35 +77,35 @@ namespace spot
return; return;
case unop::X: case unop::X:
/* X(true) = true /* X(true) = true
X(false) = false */ X(false) = false */
if (node_type(result_) == (node_type_form_visitor::Const)) if (node_type(result_) == (node_type_form_visitor::Const))
return; return;
/* XGF(f) = GF(f) */ /* XGF(f) = GF(f) */
if (is_GF(result_)) return; if (is_GF(result_)) return;
/* X(f1 & GF(f2)) = X(f1) & GF(F2) */ /* X(f1 & GF(f2)) = X(f1) & GF(F2) */
/* X(f1 | GF(f2)) = X(f1) | GF(F2) */ /* X(f1 | GF(f2)) = X(f1) | GF(F2) */
if (node_type(result_) == (node_type_form_visitor::Multop)) { if (node_type(result_) == (node_type_form_visitor::Multop)) {
if (spot::ltl::nb_term_multop(result_) == 2) { if (dynamic_cast<multop*>(result_)->size() == 2) {
if (is_GF(((multop*)result_)->nth(0)) || if (is_GF(dynamic_cast<multop*>(result_)->nth(0)) ||
is_FG(((multop*)result_)->nth(0))) { is_FG(dynamic_cast<multop*>(result_)->nth(0))) {
multop::vec* res = new multop::vec; multop::vec* res = new multop::vec;
res->push_back(unop::instance(unop::F, basic_reduce_form(((multop*)result_)->nth(1)))); res->push_back(unop::instance(unop::F, basic_reduce_form(dynamic_cast<multop*>(result_)->nth(1))));
res->push_back(basic_reduce_form(((multop*)result_)->nth(0))); res->push_back(basic_reduce_form(dynamic_cast<multop*>(result_)->nth(0)));
f = result_; f = result_;
result_ = multop::instance(((multop*)(result_))->op(), res); result_ = multop::instance(dynamic_cast<multop*>(result_)->op(), res);
spot::ltl::destroy(f); spot::ltl::destroy(f);
return; return;
} }
if (is_GF(((multop*)result_)->nth(1)) || if (is_GF(dynamic_cast<multop*>(result_)->nth(1)) ||
is_FG(((multop*)result_)->nth(1))) { is_FG(dynamic_cast<multop*>(result_)->nth(1))) {
multop::vec* res = new multop::vec; multop::vec* res = new multop::vec;
res->push_back(unop::instance(unop::F, basic_reduce_form(((multop*)result_)->nth(0)))); res->push_back(unop::instance(unop::F, basic_reduce_form(dynamic_cast<multop*>(result_)->nth(0))));
res->push_back(basic_reduce_form(((multop*)result_)->nth(1))); res->push_back(basic_reduce_form(dynamic_cast<multop*>(result_)->nth(1)));
f = result_; f = result_;
result_ = multop::instance(((multop*)(result_))->op(), res); result_ = multop::instance(dynamic_cast<multop*>(result_)->op(), res);
spot::ltl::destroy(f); spot::ltl::destroy(f);
return; return;
} }
...@@ -114,43 +114,43 @@ namespace spot ...@@ -114,43 +114,43 @@ namespace spot
result_ = unop::instance(unop::X, result_); result_ = unop::instance(unop::X, result_);
return; return;
case unop::F: case unop::F:
/* F(true) = true /* F(true) = true
F(false) = false */ F(false) = false */
if (node_type(result_) == (node_type_form_visitor::Const)) if (node_type(result_) == (node_type_form_visitor::Const))
return; return;
/* FX(a) = XF(a) */ /* FX(a) = XF(a) */
if (node_type(result_) == (node_type_form_visitor::Unop)) if (node_type(result_) == (node_type_form_visitor::Unop))
if ( ((unop*)(result_))->op() == unop::X ){ if (dynamic_cast<unop*>(result_)->op() == unop::X){
f = result_; f = result_;
result_ = unop::instance(unop::X, result_ = unop::instance(unop::X,
unop::instance(unop::F, unop::instance(unop::F,
basic_reduce_form(((unop*)(result_))->child()) )); basic_reduce_form(dynamic_cast<unop*>(result_)->child()) ));
spot::ltl::destroy(f); spot::ltl::destroy(f);
return; return;
} }
/* F(f1 & GF(f2)) = F(f1) & GF(F2) */ /* F(f1 & GF(f2)) = F(f1) & GF(F2) */
if (node_type(result_) == (node_type_form_visitor::Multop)) { if (node_type(result_) == (node_type_form_visitor::Multop)) {
if ( ((multop*)(result_))->op() == multop::And ) { if (dynamic_cast<multop*>(result_)->op() == multop::And) {
if (spot::ltl::nb_term_multop(result_) == 2) { if (dynamic_cast<multop*>(result_)->size() == 2) {
if (is_GF(((multop*)result_)->nth(0)) || if (is_GF(dynamic_cast<multop*>(result_)->nth(0)) ||
is_FG(((multop*)result_)->nth(0))) { is_FG(dynamic_cast<multop*>(result_)->nth(0))) {
multop::vec* res = new multop::vec; multop::vec* res = new multop::vec;
res->push_back(unop::instance(unop::F, basic_reduce_form(((multop*)result_)->nth(1)))); res->push_back(unop::instance(unop::F, basic_reduce_form(dynamic_cast<multop*>(result_)->nth(1))));
res->push_back(basic_reduce_form(((multop*)result_)->nth(0))); res->push_back(basic_reduce_form(dynamic_cast<multop*>(result_)->nth(0)));
spot::ltl::destroy(result_); spot::ltl::destroy(result_);
result_ = multop::instance(multop::And, res); result_ = multop::instance(multop::And, res);
return; return;
} }
if (is_GF(((multop*)result_)->nth(1)) || if (is_GF(dynamic_cast<multop*>(result_)->nth(1)) ||
is_FG(((multop*)result_)->nth(1))) { is_FG(dynamic_cast<multop*>(result_)->nth(1))) {
multop::vec* res = new multop::vec; multop::vec* res = new multop::vec;
res->push_back(unop::instance(unop::F, basic_reduce_form(((multop*)result_)->nth(0)))); res->push_back(unop::instance(unop::F, basic_reduce_form(dynamic_cast<multop*>(result_)->nth(0))));
res->push_back(basic_reduce_form(((multop*)result_)->nth(1))); res->push_back(basic_reduce_form(dynamic_cast<multop*>(result_)->nth(1)));
spot::ltl::destroy(result_); spot::ltl::destroy(result_);
result_ = multop::instance(multop::And, res); result_ = multop::instance(multop::And, res);
return; return;
...@@ -163,50 +163,50 @@ namespace spot ...@@ -163,50 +163,50 @@ namespace spot
return; return;
case unop::G: case unop::G:
/* G(true) = true /* G(true) = true
G(false) = false */ G(false) = false */
if (node_type(result_) == (node_type_form_visitor::Const)) if (node_type(result_) == (node_type_form_visitor::Const))
return; return;
/* G(a R b) = G(b) */ /* G(a R b) = G(b) */
if (node_type(result_) == node_type_form_visitor::Binop) if (node_type(result_) == node_type_form_visitor::Binop)
if ( ((binop*)(result_))->op() == binop::R ){ if (dynamic_cast<binop*>(result_)->op() == binop::R){
f = result_; f = result_;
result_ = unop::instance(unop::G, basic_reduce_form(((binop*)(result_))->second())); result_ = unop::instance(unop::G, basic_reduce_form(dynamic_cast<binop*>(result_)->second()));
spot::ltl::destroy(f); spot::ltl::destroy(f);
return; return;
} }
/* GX(a) = XG(a) */ /* GX(a) = XG(a) */
if (node_type(result_) == (node_type_form_visitor::Unop)) if (node_type(result_) == (node_type_form_visitor::Unop))
if ( ((unop*)(result_))->op() == unop::X ){ if ( dynamic_cast<unop*>(result_)->op() == unop::X ){
f = result_; f = result_;
result_ = unop::instance(unop::X, result_ = unop::instance(unop::X,
unop::instance(unop::G, unop::instance(unop::G,
basic_reduce_form(((unop*)(result_))->child()) )); basic_reduce_form(dynamic_cast<unop*>(result_)->child())));
spot::ltl::destroy(f); spot::ltl::destroy(f);
return; return;
} }
/* G(f1 | GF(f2)) = G(f1) | GF(F2) */ /* G(f1 | GF(f2)) = G(f1) | GF(F2) */
if (node_type(result_) == (node_type_form_visitor::Multop)) { if (node_type(result_) == (node_type_form_visitor::Multop)) {
if ( ((multop*)(f))->op() == multop::Or ) { if (dynamic_cast<multop*>(f)->op() == multop::Or) {
if (spot::ltl::nb_term_multop(result_) == 2) { if (dynamic_cast<multop*>(result_)->size() == 2) {
if (is_GF(((multop*)result_)->nth(0)) || if (is_GF(dynamic_cast<multop*>(result_)->nth(0)) ||
is_FG(((multop*)result_)->nth(0))) { is_FG(dynamic_cast<multop*>(result_)->nth(0))) {
multop::vec* res = new multop::vec; multop::vec* res = new multop::vec;
res->push_back(unop::instance(unop::G, basic_reduce_form(((multop*)result_)->nth(1)))); res->push_back(unop::instance(unop::G, basic_reduce_form(dynamic_cast<multop*>(result_)->nth(1))));
res->push_back(basic_reduce_form(((multop*)result_)->nth(0))); res->push_back(basic_reduce_form(dynamic_cast<multop*>(result_)->nth(0)));
spot::ltl::destroy(result_); spot::ltl::destroy(result_);
result_ = multop::instance(multop::Or, res); result_ = multop::instance(multop::Or, res);
return; return;
} }
if (is_GF(((multop*)result_)->nth(1)) || if (is_GF(dynamic_cast<multop*>(result_)->nth(1)) ||
is_FG(((multop*)result_)->nth(1))) { is_FG(dynamic_cast<multop*>(result_)->nth(1))) {
multop::vec* res = new multop::vec; multop::vec* res = new multop::vec;
res->push_back(unop::instance(unop::G, basic_reduce_form(((multop*)result_)->nth(0)))); res->push_back(unop::instance(unop::G, basic_reduce_form(dynamic_cast<multop*>(result_)->nth(0))));
res->push_back(basic_reduce_form(((multop*)result_)->nth(1))); res->push_back(basic_reduce_form(dynamic_cast<multop*>(result_)->nth(1)));
spot::ltl::destroy(result_); spot::ltl::destroy(result_);
result_ = multop::instance(multop::Or, res); result_ = multop::instance(multop::Or, res);
return; return;
...@@ -221,7 +221,7 @@ namespace spot ...@@ -221,7 +221,7 @@ namespace spot
/* Unreachable code. */ /* Unreachable code. */
assert(0); assert(0);
} }
void void
visit(binop* bo) visit(binop* bo)
{ {
...@@ -233,24 +233,24 @@ namespace spot ...@@ -233,24 +233,24 @@ namespace spot
switch (bo->op()) switch (bo->op())
{ {
case binop::Xor: case binop::Xor:
result_ = binop::instance(binop::Xor, result_ = binop::instance(binop::Xor,
basic_reduce_form(f1), basic_reduce_form(f1),
basic_reduce_form(f2)); basic_reduce_form(f2));
return; return;
case binop::Equiv: case binop::Equiv:
result_ = binop::instance(binop::Equiv, result_ = binop::instance(binop::Equiv,
basic_reduce_form(f1), basic_reduce_form(f1),
basic_reduce_form(f2)); basic_reduce_form(f2));
return; return;
case binop::Implies: case binop::Implies:
result_ = binop::instance(binop::Implies, result_ = binop::instance(binop::Implies,
basic_reduce_form(f1), basic_reduce_form(f1),
basic_reduce_form(f2)); basic_reduce_form(f2));
return; return;
case binop::U: case binop::U:
f2 = basic_reduce_form(f2); f2 = basic_reduce_form(f2);
/* a U false = false /* a U false = false
a U true = true */ a U true = true */
if (node_type(f2) == (node_type_form_visitor::Const)) { if (node_type(f2) == (node_type_form_visitor::Const)) {
result_ = f2; result_ = f2;
...@@ -262,11 +262,11 @@ namespace spot ...@@ -262,11 +262,11 @@ namespace spot
/* X(a) U X(b) = X(a U b) */ /* X(a) U X(b) = X(a U b) */
if ( node_type(f1) == (node_type_form_visitor::Unop) if ( node_type(f1) == (node_type_form_visitor::Unop)
&& node_type(f2) == (node_type_form_visitor::Unop)) { && node_type(f2) == (node_type_form_visitor::Unop)) {
if ( (((unop*)(f1))->op() == unop::X)