equivalent.hxx

00001 // equivalent.hxx: this file is part of the Vaucanson project.
00002 //
00003 // Vaucanson, a generic library for finite state machines.
00004 //
00005 // Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 The Vaucanson Group.
00006 //
00007 // This program is free software; you can redistribute it and/or
00008 // modify it under the terms of the GNU General Public License
00009 // as published by the Free Software Foundation; either version 2
00010 // of the License, or (at your option) any later version.
00011 //
00012 // The complete GNU General Public Licence Notice can be found as the
00013 // `COPYING' file in the root directory.
00014 //
00015 // The Vaucanson Group consists of people listed in the `AUTHORS' file.
00016 //
00017 #ifndef VCSN_ALGORITHMS_EQUIVALENT_HXX
00018 # define VCSN_ALGORITHMS_EQUIVALENT_HXX
00019 
00020 # include <vaucanson/algorithms/equivalent.hh>
00021 # include <vaucanson/algorithms/determinize.hh>
00022 # include <vaucanson/algorithms/is_deterministic.hh>
00023 # include <vaucanson/algorithms/complement.hh>
00024 # include <vaucanson/algorithms/complete.hh>
00025 # include <vaucanson/algorithms/trim.hh>
00026 # include <vaucanson/algorithms/product.hh>
00027 
00028 # include <vaucanson/algebra/implementation/series/rat/exp.hh>
00029 # include <vaucanson/misc/usual_macros.hh>
00030 
00031 
00032 namespace vcsn
00033 {
00034 
00035   template<typename SA, typename A,
00036            typename SB, typename B>
00037   bool
00038   do_are_equivalent(const AutomataBase<SA>&, const A& a,
00039                     const AutomataBase<SB>&, const B& b)
00040   {
00041     A pos_a(a);
00042     B pos_b(b);
00043 
00044     if (not is_realtime(pos_a))
00045       realtime_here(pos_a);
00046     if (not is_realtime(pos_b))
00047       realtime_here(pos_b);
00048 
00049     // L(a) = L(b) \iff (L(b) \subset L(a) \land L(a) \subset L(b))
00050 
00051     // L(b) \subset L(a)  \iff   \overline{L(a)}\cap L(b)=\emptyset
00052     // We compute the latter with complement and product.
00053     A neg_a(pos_a);
00054     if (not is_deterministic(neg_a))
00055       neg_a = determinize(neg_a);
00056     else if (not is_complete(neg_a))
00057       complete_here(neg_a);
00058     complement_here(neg_a);
00059     if (trim(product(neg_a, pos_b)).states().size() != 0)
00060       return false;
00061 
00062     // L(a) \subset L(b)  \iff   L(a)\cap\overline{L(b)}=\emptyset
00063     A neg_b(pos_b);
00064     if (not is_deterministic(neg_b))
00065       neg_b = determinize(neg_b);
00066     else if(not is_complete(neg_b))
00067       complete_here(neg_b);
00068     complement_here(neg_b);
00069     return (trim(product(pos_a, neg_b)).states().size() == 0);
00070   }
00071 
00072 
00073   template<typename S, typename A, typename B>
00074   bool
00075   are_equivalent(const Element<S, A>& a, const Element<S, B>& b)
00076   {
00077     return do_are_equivalent(a.structure(), a,
00078                              b.structure(), b);
00079   }
00080 
00081 } // vcsn
00082 
00083 #endif // ! VCSN_ALGORITHMS_EQUIVALENT_HXX

Generated on Thu Oct 9 20:22:34 2008 for Vaucanson by  doxygen 1.5.1