Commit 7b9f6952 authored by Alexandre Duret-Lutz's avatar Alexandre Duret-Lutz
Browse files

Speedup reduccmp.test

This test used to take more than 10min because an instance of valgrind
was launched for each separate equivalence check.  The list of
equivalences to checks are not given in a file, and only two valgrind
instances are run.  The test takes less than 15sec.

* src/ltltest/equalsf.cc: New file.
* src/ltltest/Makefile.am (reduccmp, reductaustr): Build using
equalsf.cc.
* src/ltltest/reduccmp.test: Rewrite.
* src/ltltest/uwrm.test: Also rewrite, and use valgrind.
parent b43f75e9
......@@ -60,13 +60,13 @@ lunabbrev_CPPFLAGS = $(AM_CPPFLAGS) -DLUNABBREV
nenoform_SOURCES = equals.cc
nenoform_CPPFLAGS = $(AM_CPPFLAGS) -DNENOFORM
reduc_SOURCES = reduc.cc
reduccmp_SOURCES = equals.cc
reduccmp_SOURCES = equalsf.cc
reduccmp_CPPFLAGS = $(AM_CPPFLAGS) -DREDUC
reduceu_SOURCES = equals.cc
reduceu_CPPFLAGS = $(AM_CPPFLAGS) -DREDUC -DEVENT_UNIV
reductau_SOURCES = equals.cc
reductau_CPPFLAGS = $(AM_CPPFLAGS) -DREDUC_TAU
reductaustr_SOURCES = equals.cc
reductaustr_SOURCES = equalsf.cc
reductaustr_CPPFLAGS = $(AM_CPPFLAGS) -DREDUC_TAUSTR
syntimpl_SOURCES = syntimpl.cc
tostring_SOURCES = tostring.cc
......
// -*- coding: utf-8 -*-
// Copyright (C) 2008, 2009, 2010, 2011, 2012, 2014 Laboratoire de
// Recherche et Développement de l'Epita (LRDE).
// Copyright (C) 2003, 2004, 2006 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 3 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 this program. If not, see <http://www.gnu.org/licenses/>.
#include <iostream>
#include <fstream>
#include <sstream>
#include <cassert>
#include <cstdlib>
#include <cstring>
#include "ltlparse/public.hh"
#include "ltlvisit/lunabbrev.hh"
#include "ltlvisit/tunabbrev.hh"
#include "ltlvisit/dump.hh"
#include "ltlvisit/wmunabbrev.hh"
#include "ltlvisit/nenoform.hh"
#include "ltlast/allnodes.hh"
#include "ltlvisit/simplify.hh"
#include "ltlvisit/tostring.hh"
void
syntax(char* prog)
{
std::cerr << prog << " [-E] file" << std::endl;
exit(2);
}
int
main(int argc, char** argv)
{
bool check_first = true;
if (argc > 1 && !strcmp(argv[1], "-E"))
{
check_first = false;
argv[1] = argv[0];
++argv;
--argc;
}
if (argc != 2)
syntax(argv[0]);
std::ifstream input(argv[1]);
std::string s;
unsigned line = 0;
while (std::getline(input, s))
{
++line;
std::cerr << line << ": " << s << '\n';
if (s[0] == '#') // Skip comments
continue;
std::vector<std::string> formulas;
{
std::istringstream ss(s);
std::string form;
while (std::getline(ss, form, ','))
formulas.push_back(form);
}
unsigned size = formulas.size();
if (size == 0) // Skip empty lines
continue;
if (size == 1)
{
std::cerr << "Not enough formulas on line " << line << '\n';
return 2;
}
spot::ltl::parse_error_list p2;
const spot::ltl::formula* f2 = spot::ltl::parse(formulas[size - 1], p2);
if (spot::ltl::format_parse_errors(std::cerr, formulas[size - 1], p2))
return 2;
for (unsigned n = 0; n < size - 1; ++n)
{
spot::ltl::parse_error_list p1;
const spot::ltl::formula* f1 = spot::ltl::parse(formulas[n], p1);
if (check_first &&
spot::ltl::format_parse_errors(std::cerr, formulas[n], p1))
return 2;
int exit_code = 0;
{
#if defined LUNABBREV || defined TUNABBREV || defined NENOFORM || defined WM
const spot::ltl::formula* tmp;
#endif
#ifdef LUNABBREV
tmp = f1;
f1 = spot::ltl::unabbreviate_logic(f1);
tmp->destroy();
spot::ltl::dump(std::cout, f1);
std::cout << std::endl;
#endif
#ifdef TUNABBREV
tmp = f1;
f1 = spot::ltl::unabbreviate_ltl(f1);
tmp->destroy();
spot::ltl::dump(std::cout, f1);
std::cout << std::endl;
#endif
#ifdef WM
tmp = f1;
f1 = spot::ltl::unabbreviate_wm(f1);
tmp->destroy();
spot::ltl::dump(std::cout, f1);
std::cout << std::endl;
#endif
#ifdef NENOFORM
tmp = f1;
f1 = spot::ltl::negative_normal_form(f1);
tmp->destroy();
spot::ltl::dump(std::cout, f1);
std::cout << std::endl;
#endif
#ifdef REDUC
spot::ltl::ltl_simplifier_options opt(true, true, true,
false, false);
# ifdef EVENT_UNIV
opt.favor_event_univ = true;
# endif
spot::ltl::ltl_simplifier simp(opt);
{
const spot::ltl::formula* tmp;
tmp = f1;
f1 = simp.simplify(f1);
if (!simp.are_equivalent(f1, tmp))
{
std::cerr
<< "Source and simplified formulae are not equivalent!\n";
std::cerr
<< "Simplified: " << spot::ltl::to_string(f1) << '\n';
exit_code = 1;
}
tmp->destroy();
}
spot::ltl::dump(std::cout, f1);
std::cout << std::endl;
#endif
#ifdef REDUC_TAU
spot::ltl::ltl_simplifier_options opt(false, false, false,
true, false);
spot::ltl::ltl_simplifier simp(opt);
{
const spot::ltl::formula* tmp;
tmp = f1;
f1 = simp.simplify(f1);
if (!simp.are_equivalent(f1, tmp))
{
std::cerr
<< "Source and simplified formulae are not equivalent!\n";
std::cerr
<< "Simplified: " << spot::ltl::to_string(f1) << '\n';
exit_code = 1;
}
tmp->destroy();
}
spot::ltl::dump(std::cout, f1);
std::cout << std::endl;
#endif
#ifdef REDUC_TAUSTR
spot::ltl::ltl_simplifier_options opt(false, false, false,
true, true);
spot::ltl::ltl_simplifier simp(opt);
{
const spot::ltl::formula* tmp;
tmp = f1;
f1 = simp.simplify(f1);
if (!simp.are_equivalent(f1, tmp))
{
std::cerr
<< "Source and simplified formulae are not equivalent!\n";
std::cerr
<< "Simplified: " << spot::ltl::to_string(f1) << '\n';
exit_code = 1;
}
tmp->destroy();
}
spot::ltl::dump(std::cout, f1);
std::cout << std::endl;
#endif
exit_code |= f1 != f2;
#if (!defined(REDUC) && !defined(REDUC_TAU) && !defined(REDUC_TAUSTR))
spot::ltl::ltl_simplifier simp;
#endif
if (!simp.are_equivalent(f1, f2))
{
#if (!defined(REDUC) && !defined(REDUC_TAU) && !defined(REDUC_TAUSTR))
std::cerr
<< "Source and destination formulae are not equivalent!\n";
#else
std::cerr
<< "Simpl. and destination formulae are not equivalent!\n";
#endif
exit_code = 1;
}
if (exit_code)
{
spot::ltl::dump(std::cerr, f1) << std::endl;
spot::ltl::dump(std::cerr, f2) << std::endl;
return exit_code;
}
}
f1->destroy();
}
f2->destroy();
}
spot::ltl::atomic_prop::dump_instances(std::cerr);
spot::ltl::unop::dump_instances(std::cerr);
spot::ltl::binop::dump_instances(std::cerr);
spot::ltl::multop::dump_instances(std::cerr);
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 0;
}
This diff is collapsed.
#! /bin/sh
# Copyright (C) 2012 Laboratoire de Recherche et Developpement
# Copyright (C) 2012, 2014 Laboratoire de Recherche et Developpement
# de l'Epita (LRDE).
#
# This file is part of Spot, a model checking library.
......@@ -22,52 +22,39 @@
# These formulas comes from an appendix of tl/tl.tex
. ./defs || exit 1
set -e
equiv()
{
dst=$1
shift
for src in "$@"; do
../reduccmp "$src" "$dst"
done
}
cat >input.txt<<EOF
# Equivalences with U
equiv Ff '1 U f'
equiv Gf '!F!f' '!(1 U!f)'
equiv 'f W g' '(f U g) | (G f)' '(f U g) | !(1 U ! f)' \
'f U (g | G f)' 'f U (g | !(1 U ! f ))'
equiv 'f M g' 'g U (f & g)'
equiv 'f R g' 'g W (f & g)' '(g U (f & g)) | !(1 U ! g)' \
'g U ((f & g) | !(1 U ! g))'
1 U f, Ff
!F!f, !(1 U!f), Gf
(f U g)|(G f), (f U g) | !(1 U ! f), f U (g | G f), f U (g | !(1 U !f)), f W g
g U (f & g), f M g
g W (f & g), (g U (f & g)) | !(1 U ! g), g U ((f & g) | !(1 U ! g)), f R g
# Equivalences with W
equiv Ff '!G!f' '!((! f) W 0)'
equiv Gf '0 R f' 'f W 0'
equiv 'f U g' '(f W g) & (F g)' '(f W g) & !((! g) W 0)'
equiv 'f M g' '(g W (f & g)) & (F f)' '(g W (f & g)) & !((!f) W 0)'
equiv 'f R g' 'g W (f & g)'
!G!f, !((! f) W 0), Ff
0 R f, f W 0, Gf
(f W g) & (F g), (f W g) & !((! g) W 0), f U g
(g W (f & g)) & (F f), (g W (f & g)) & !((!f) W 0), f M g
g W (f & g), f R g
# Equivalences with R
!G!f, !(0 R !f), Ff
0 R f, Gf
# (((X g) R f) & F g) | g, (((X g) R f ) & (!(0 R ! g))) | g, f U g
((X g) R f) | g, g R (f | g), f W g
(f R g) & F f, (f R g) & !(0 R !f), f R (g & F f), f R (g & !(0 R !f)), f M g
equiv Ff '!G!f' '!(0 R !f)'
equiv Gf '0 R f'
#equiv 'f U g' '(((X g) R f) & F g) | g' '(((X g) R f ) & (!(0 R ! g))) | g'
equiv 'f W g' '((X g) R f) | g' 'g R (f | g)'
equiv 'f M g' '( f R g) & F f' '(f R g) & ! (0 R ! f)' \
'f R (g & F f)' 'f R (g & !(0 R !f))'
# Equivalences with M
equiv Ff 'f M 1'
equiv Gf '!F!f' '!((!f) M 1)'
equiv 'f U g' '((X g) M f) | g' 'g M (f | g)'
equiv 'f W g' '(f U g) | G f' '((X g) M f) | g | !((! f ) M 1)'
equiv 'f R g' '(f M g) | G g' '(f M g) | !((! g) M 1)'
f M 1, Ff
!F!f, !((!f) M 1), Gf
((X g) M f) | g, g M (f | g), f U g
(f U g) | G f, ((X g) M f) | g | !((! f ) M 1), f W g
(f M g) | G g, (f M g) | !((! g) M 1), f R g
# Example from tl.tex
#(((f U (Xg & f))|!(1 U !f))&(1 U Xg)) | g, f U g
EOF
# equiv 'f U g' '(((f U (Xg & f))|!(1 U !f))&(1 U Xg)) | g'
run 0 ../reduccmp input.txt
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment