Commit bafc92d0 authored by martinez's avatar martinez
Browse files

*** empty log message ***

parent faf4a2af
......@@ -30,15 +30,18 @@ check_SCRIPTS = defs
# Keep this sorted alphabetically.
check_PROGRAMS = \
equals \
inf \
ltl2dot \
ltl2text \
lunabbrev \
nenoform \
reduc \
tostring \
tunabbrev \
tunenoform
tunenoform
equals_SOURCES = equals.cc
inf_SOURCES = inf.cc
ltl2dot_SOURCES = readltl.cc
ltl2dot_CPPFLAGS = $(AM_CPPFLAGS) -DDOTTY
ltl2text_SOURCES = readltl.cc
......@@ -46,6 +49,7 @@ lunabbrev_SOURCES = equals.cc
lunabbrev_CPPFLAGS = $(AM_CPPFLAGS) -DLUNABBREV
nenoform_SOURCES = equals.cc
nenoform_CPPFLAGS = $(AM_CPPFLAGS) -DNENOFORM
reduc_SOURCES = reduc.cc
tostring_SOURCES = tostring.cc
tunabbrev_SOURCES = equals.cc
tunabbrev_CPPFLAGS = $(AM_CPPFLAGS) -DTUNABBREV
......@@ -57,6 +61,8 @@ EXTRA_DIST = $(TESTS)
# Ordered by strength of the test. Test basic features first.
TESTS = \
inf.test \
reduc.test \
parse.test \
parseerr.test \
equals.test \
......
This diff is collapsed.
// Copyright (C) 2003 Laboratoire d'Informatique de Paris 6 (LIP6),
// dpartement Systmes Rpartis Coopratifs (SRC), Universit Pierre
// et Marie Curie.
//
// This file is part of Spot, a model checking library.
//
// Spot is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// Spot is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
// License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Spot; see the file COPYING. If not, write to the Free
// Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
#include <iostream>
#include <cassert>
#include "ltlparse/public.hh"
#include "ltlvisit/lunabbrev.hh"
#include "ltlvisit/tunabbrev.hh"
#include "ltlvisit/dump.hh"
#include "ltlvisit/nenoform.hh"
#include "ltlvisit/destroy.hh"
#include "ltlvisit/tostring.hh"
#include "ltlvisit/reducform.hh"
#include "ltlast/allnodes.hh"
void
syntax(char* prog)
{
std::cerr << prog << " formula1 formula2?" << std::endl;
exit(2);
}
int
main(int argc, char** argv)
{
if (argc < 3)
syntax(argv[0]);
spot::ltl::parse_error_list p1;
spot::ltl::formula* f1 = spot::ltl::parse(argv[1], p1);
spot::ltl::formula* f2 = NULL;
if (spot::ltl::format_parse_errors(std::cerr, argv[1], p1))
return 2;
spot::ltl::parse_error_list p2;
f2 = spot::ltl::parse(argv[2], p2);
if (spot::ltl::format_parse_errors(std::cerr, argv[2], p2))
return 2;
std::string f1s = spot::ltl::to_string(f1);
std::string f2s = spot::ltl::to_string(f2);
int exit_return = 0;
std::cout << "Test f1 < f2" << std::endl;
if (spot::ltl::inf_form(f1,f2)) {
std::cout << f1s << " < " << f2s << std::endl;
exit_return = 1;
}
/*
std::cout << "Test !f1 < f2" << std::endl;
if (spot::ltl::infneg_form(f1,f2,0)) {
std::cout << "!(" << f1s << ") < " << f2s << std::endl;
exit_return = 2;
}
std::cout << "Test f1 < !f2" << std::endl;
if (spot::ltl::infneg_form(f1,f2,1)) {
std::cout << f1s << " < !(" << f2s << ")" << std::endl;
exit_return = 3;
}
*/
spot::ltl::dump(std::cout, f1); std::cout << std::endl;
spot::ltl::dump(std::cout, f2); std::cout << std::endl;
spot::ltl::destroy(f1);
spot::ltl::destroy(f2);
assert(spot::ltl::atomic_prop::instance_count() == 0);
assert(spot::ltl::unop::instance_count() == 0);
assert(spot::ltl::binop::instance_count() == 0);
assert(spot::ltl::multop::instance_count() == 0);
return exit_return;
}
#! /bin/sh
# Copyright (C) 2003 Laboratoire d'Informatique de Paris 6 (LIP6),
# département Systèmes Répartis Coopératifs (SRC), Université Pierre
# et Marie Curie.
#
# This file is part of Spot, a model checking library.
#
# Spot is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# Spot is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
# License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Spot; see the file COPYING. If not, write to the Free
# Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
# 02111-1307, USA.
# Check for the reduc visitor
. ./defs || exit 1
#
run 1 ./inf '1' '1'
run 1 ./inf '0' '0'
run 1 ./inf 'a' '1'
run 1 ./inf 'a' 'a'
run 1 ./inf 'a' 'a * 1'
run 1 ./inf 'a * b' 'b'
run 1 ./inf 'a * b' 'a'
run 1 ./inf 'a' 'a + b'
run 1 ./inf 'b' 'a + b'
run 1 ./inf 'a + b' '1'
run 1 ./inf 'a' 'b U a'
run 1 ./inf 'a' 'b U 1'
run 1 ./inf 'a U b' '1'
run 1 ./inf 'a' '1 R a'
run 1 ./inf 'a' 'a R 1'
run 1 ./inf 'a R b' 'b'
run 1 ./inf 'a R b' '1'
run 1 ./inf 'a U b' '1 U b'
run 1 ./inf 'a R b' '1 R b'
run 1 ./inf 'b * (a U b)' 'a U b'
run 1 ./inf 'a U b' 'c + (a U b)'
exit 0
#
#run 1 ./inf '(a U b) U ((a U b) U (a U b))' 'a U b'
#run 1 ./inf '(a U b) && (a U b)' 'a U b'
'X1' '1'
'a U 0' '0'
'a R 1' '1'
'Xa * Xb' 'X(a * b)'
'F(a * GFb)' 'Fa * GFb'
'G(a + GFb)' 'Ga + GFb'
'X(a * GFb)' 'Xa * GFb'
'X(a + GFb)' 'Xa + GFb'
// Copyright (C) 2003 Laboratoire d'Informatique de Paris 6 (LIP6),
// dpartement Systmes Rpartis Coopratifs (SRC), Universit Pierre
// et Marie Curie.
//
// This file is part of Spot, a model checking library.
//
// Spot is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// Spot is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
// License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Spot; see the file COPYING. If not, write to the Free
// Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
#include <iostream>
#include <cassert>
#include "ltlparse/public.hh"
#include "ltlvisit/lunabbrev.hh"
#include "ltlvisit/tunabbrev.hh"
#include "ltlvisit/dump.hh"
#include "ltlvisit/nenoform.hh"
#include "ltlvisit/destroy.hh"
#include "ltlvisit/tostring.hh"
#include "ltlvisit/reducform.hh"
#include "ltlast/allnodes.hh"
void
syntax(char* prog)
{
std::cerr << prog << " formula1 (formula2)?" << std::endl;
exit(2);
}
typedef spot::ltl::formula* ptrfunct(const spot::ltl::formula*);
int
main(int argc, char** argv)
{
if (argc < 2)
syntax(argv[0]);
spot::ltl::parse_error_list p1;
spot::ltl::formula* f1 = spot::ltl::parse(argv[1], p1);
spot::ltl::formula* f2 = NULL;
if (spot::ltl::format_parse_errors(std::cerr, argv[1], p1))
return 2;
if (argc == 3){
spot::ltl::parse_error_list p2;
f2 = spot::ltl::parse(argv[2], p2);
if (spot::ltl::format_parse_errors(std::cerr, argv[2], p2))
return 2;
}
int exit_code = 0;
spot::ltl::formula* ftmp1;
spot::ltl::formula* ftmp2;
ftmp1 = f1;
f1 = unabbreviate_logic(f1);
ftmp2 = f1;
f1 = negative_normal_form(f1);
spot::ltl::destroy(ftmp1);
spot::ltl::destroy(ftmp2);
int length_f1_before = spot::ltl::form_length(f1);
std::string f1s_before = spot::ltl::to_string(f1);
ftmp1 = f1;
f1 = spot::ltl::reduce(f1);
ftmp2 = f1;
f1 = spot::ltl::unabbreviate_logic(f1);
spot::ltl::destroy(ftmp1);
spot::ltl::destroy(ftmp2);
int length_f1_after = spot::ltl::form_length(f1);
std::string f1s_after = spot::ltl::to_string(f1);
bool red = (length_f1_after < length_f1_before);
if (red);
std::string f2s = "";
if (f2 != NULL) {
ftmp1 = f2;
f2 = unabbreviate_logic(f2);
ftmp2 = f2;
f2 = negative_normal_form(f2);
spot::ltl::destroy(ftmp1);
spot::ltl::destroy(ftmp2);
ftmp1 = f2;
f2 = unabbreviate_logic(f2);
spot::ltl::destroy(ftmp1);
f2s = spot::ltl::to_string(f2);
}
if (red && (f2 == NULL)) {
std::cout << length_f1_before << " " << length_f1_after
<< " '" << f1s_before << "' reduce to '" << f1s_after << "'" << std::endl;
}
if (f2 != NULL){
if (f1 != f2) {
if (length_f1_after < length_f1_before)
std::cout << f1s_before << " ** " << f2s << " ** " << f1s_after << " KOREDUC " << std::endl;
else
std::cout << f1s_before << " ** " << f2s << " ** " << f1s_after << " KOIDEM " << std::endl;
exit_code = 1;
}
else {
if (f1s_before != f1s_after)
std::cout << f1s_before << " ** " << f2s << " ** " << f1s_after << " OKREDUC " << std::endl;
else
std::cout << f1s_before << " ** " << f2s << " ** " << f1s_after << " OKIDEM" << std::endl;
exit_code = 0;
}
}
else{
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);
if (f2 != NULL)
spot::ltl::destroy(f2);
assert(spot::ltl::atomic_prop::instance_count() == 0);
assert(spot::ltl::unop::instance_count() == 0);
assert(spot::ltl::binop::instance_count() == 0);
assert(spot::ltl::multop::instance_count() == 0);
return exit_code;
}
#! /bin/sh
# Copyright (C) 2003 Laboratoire d'Informatique de Paris 6 (LIP6),
# dpartement Systmes Rpartis Coopratifs (SRC), Universit Pierre
# et Marie Curie.
#
# This file is part of Spot, a model checking library.
#
# Spot is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# Spot is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
# License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Spot; see the file COPYING. If not, write to the Free
# Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
# 02111-1307, USA.
# Check for the reduc visitor
#. ./defs || exit 1
if [ $1 ]; then
FICH=$1
else
FICH="formules.ltl"
fi
#####################################
rm output? result_bri.test -f
for opt in bri ##b r i br bi rb ri ib ir bri bir rbi rib ibr irb
do
for f in `awk '{print $1}' $FICH`
do
if [ ! $f = "####" ]; then
#echo $f;
if ./reduc "$f" >> result_$opt.test;
then
#echo $f >> output1
# if ../tgbatest/ltl2tgba -f "$f" >> output1; then #automate FM
# echo "" >> output1
# else
# echo $f;
# fi
#echo "'$f' is reduce ($NB)"
(( NB += 1 ));
else
(( NB = NB ));
#echo "reduc failed to reduce '$f'";
fi
fi
done
#echo "$NB formula reduce"
(( NB = 0 ));
done
#####################################
#ftmp=""
#for f in `sed -e "s/\(.* reduce to \)/'1'/" result_bri.test`
# do
# if [ $ftmp = "" ]; then
# echo $ftmp;
# ftmp="";
# else
# echo $f;
# ftmp="$ftmp $f";
# echo $ftmp;
# fi
# echo $f >> output2
# ../tgbatest/ltl2tgba -f "$f" >> output2 #automate FM
# echo "" >> output2
#done
##############################################
#exit 0
##############################################
SUM1=0
SUM2=0
AVG=0
for res in `awk '{print $1}' result_bri.test`
do
SUM1=$(expr $res + $SUM1)
done
#echo $SUM1
for res in `awk '{print $2}' result_bri.test`
do
SUM2=$(expr $res + $SUM2)
done
(( SUM2 *= 100 ))
#echo $SUM2
if [ ! $SUM1 = 0 ]; then
AVG=$(expr $SUM2 / $SUM1)
fi
#AVG=$(expr $AVG / $NB)
#AVG=$(expr $AVG)
#echo "average reduce $AVG %"
exit 0;
### Formule qui ne passe pas !! => Segmentation fault !!
#'(((p2)R((X(p2))U(X(1))))*(p0))*((p1)R((p2)R(p0)))'
#'(((p2)R((X(p2))U(X(1))))*(p0))'
#'((p1)R((p2)R(p0)))'
#'(p0 R (Gp0 U (p0 U Xp1)))'
#'(((!p)*(X(X(p))))*((p)R((q)+(!q))))+((!q)U(q))'
#'X(((p1)R(1))*((0)R((p0)+(p1))))'
#'((p0)U(0))U(((0)R(0))*(X(p2)))'
#'(((X(1))R(1))U((0)R(1)))R(p0)'
#'((X(p0))R(X(p2)))+((0)R((((p2)+(0))*(p0))R(0)))'
#'((X(0))+((0)R(p2)))U(((p0)R((p2)*(p2)))R(X(p2)))'
#'(p1)R(((p2)R(1))R(((p1)U((1)U(p0)))R((p2)U(0))))'
#'(((X(p0))R(X(p0)))R((p0)R(1)))*((0)R((p1)R(0)))'
#'(((p1)R(X(p2)))R((0)+((1)U(1))))U((X(1))R(p2))'
(((!p)*(X(X(p))))*((p)R((q)+(!q))))+((!q)U(q))
X(((p1)R(1))*((0)R((p0)+(p1))))
((p0)U(0))U(((0)R(0))*(X(p2)))
(((X(1))R(1))U((0)R(1)))R(p0)
((X(p0))R(X(p2)))+((0)R((((p2)+(0))*(p0))R(0)))
((X(0))+((0)R(p2)))U(((p0)R((p2)*(p2)))R(X(p2)))
(p1)R(((p2)R(1))R(((p1)U((1)U(p0)))R((p2)U(0))))
(((X(p0))R(X(p0)))R((p0)R(1)))*((0)R((p1)R(0)))
(((p1)R(X(p2)))R((0)+((1)U(1))))U((X(1))R(p2))
\ No newline at end of file
......@@ -33,7 +33,8 @@ ltlvisit_HEADERS = \
lunabbrev.hh \
nenoform.hh \
postfix.hh \
tunabbrev.hh
tunabbrev.hh \
reducform.hh
noinst_LTLIBRARIES = libltlvisit.la
libltlvisit_la_SOURCES = \
......@@ -45,4 +46,8 @@ libltlvisit_la_SOURCES = \
lunabbrev.cc \
nenoform.cc \
postfix.cc \
tunabbrev.cc
tunabbrev.cc \
reducform.cc \
basereduc.cc \
forminf.cc \
formlength.cc
\ No newline at end of file
// Copyright (C) 2003 Laboratoire d'Informatique de Paris 6 (LIP6),
// dpartement Systmes Rpartis Coopratifs (SRC), Universit Pierre
// et Marie Curie.
//
// This file is part of Spot, a model checking library.
//
// Spot is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// Spot is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
// License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Spot; see the file COPYING. If not, write to the Free
// Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
#include "reducform.hh"
#include "ltlast/allnodes.hh"
#include "ltlvisit/clone.hh"
#include <cassert>
#include "ltlvisit/destroy.hh"
namespace spot
{
namespace ltl
{
class basic_reduce_form_visitor : public visitor
{
public:
basic_reduce_form_visitor(){}
virtual ~basic_reduce_form_visitor(){}
formula*
result() const
{
return result_;
}
void
visit(atomic_prop* ap)
{
formula* f = ap->ref();
result_ = f;
}
void
visit(constant* c)
{
switch (c->val())
{
case constant::True:
result_ = constant::true_instance();
return;
case constant::False:
result_ = constant::false_instance();
return;
}
}
void
visit(unop* uo)
{
formula* f = uo->child();
result_ = basic_reduce_form(f);
switch (uo->op())
{
case unop::Not:
result_ = unop::instance(unop::Not, result_);
return;
case unop::X:
/* X(true) = true
X(false) = false */
if (node_type(result_) == (node_type_form_visitor::Const))
return;
/* XGF(f) = GF(f) */
if (is_GF(result_)) return;
/* 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 (spot::ltl::nb_term_multop(result_) == 2) {
if (is_GF(((multop*)result_)->nth(0)) ||
is_FG(((multop*)result_)->nth(0))) {
multop::vec* res = new multop::vec;
res->push_back(unop::instance(unop::F, basic_reduce_form(((multop*)result_)->nth(1))));
res->push_back(basic_reduce_form(((multop*)result_)->nth(0)));
f = result_;
result_ = multop::instance(((multop*)(result_))->op(), res);
spot::ltl::destroy(f);
return;
}
if (is_GF(((multop*)result_)->nth(1)) ||
is_FG(((multop*)result_)->nth(1))) {
multop::vec* res = new multop::vec;
res->push_back(unop::instance(unop::F, basic_reduce_form(((multop*)result_)->nth(0))));
res->push_back(basic_reduce_form(((multop*)result_)->nth(1)));
f = result_;