Vaucanson  1.4.1
equivalent.hxx
1 // equivalent.hxx: this file is part of the Vaucanson project.
2 //
3 // Vaucanson, a generic library for finite state machines.
4 //
5 // Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 The Vaucanson Group.
6 //
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License
9 // as published by the Free Software Foundation; either version 2
10 // of the License, or (at your option) any later version.
11 //
12 // The complete GNU General Public Licence Notice can be found as the
13 // `COPYING' file in the root directory.
14 //
15 // The Vaucanson Group consists of people listed in the `AUTHORS' file.
16 //
17 #ifndef VCSN_ALGORITHMS_EQUIVALENT_HXX
18 # define VCSN_ALGORITHMS_EQUIVALENT_HXX
19 
27 
28 # include <vaucanson/algebra/implementation/series/rat/exp.hh>
29 # include <vaucanson/misc/usual_macros.hh>
30 
31 
32 namespace vcsn
33 {
34 
35  template<typename SA, typename A,
36  typename SB, typename B>
37  bool
38  do_are_equivalent(const AutomataBase<SA>&, const A& a,
39  const AutomataBase<SB>&, const B& b)
40  {
41  A pos_a(a);
42  B pos_b(b);
43 
44  if (not is_realtime(pos_a))
45  realtime_here(pos_a);
46  if (not is_realtime(pos_b))
47  realtime_here(pos_b);
48 
49  // L(a) = L(b) \iff (L(b) \subset L(a) \land L(a) \subset L(b))
50 
51  // L(b) \subset L(a) \iff \overline{L(a)}\cap L(b)=\emptyset
52  // We compute the latter with complement and product.
53  A neg_a(pos_a);
54  if (not is_deterministic(neg_a))
55  neg_a = determinize(neg_a);
56  else if (not is_complete(neg_a))
57  complete_here(neg_a);
58  complement_here(neg_a);
59  if (trim(product(neg_a, pos_b)).states().size() != 0)
60  return false;
61 
62  // L(a) \subset L(b) \iff L(a)\cap\overline{L(b)}=\emptyset
63  A neg_b(pos_b);
64  if (not is_deterministic(neg_b))
65  neg_b = determinize(neg_b);
66  else if(not is_complete(neg_b))
67  complete_here(neg_b);
68  complement_here(neg_b);
69  return (trim(product(pos_a, neg_b)).states().size() == 0);
70  }
71 
72 
73  template<typename S, typename A, typename B>
74  bool
76  {
77  return do_are_equivalent(a.structure(), a,
78  b.structure(), b);
79  }
80 
81 } // vcsn
82 
83 #endif // ! VCSN_ALGORITHMS_EQUIVALENT_HXX