Vcsn  2.0
Be Rational
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
are-equivalent.hh
Go to the documentation of this file.
1 #ifndef VCSN_ALGOS_ARE_EQUIVALENT_HH
2 # define VCSN_ALGOS_ARE_EQUIVALENT_HH
3 
4 # include <vcsn/algos/accessible.hh> // is_useless
5 # include <vcsn/algos/complement.hh>
6 # include <vcsn/algos/complete.hh>
8 # include <vcsn/algos/left-mult.hh>
9 # include <vcsn/algos/product.hh>
10 # include <vcsn/algos/reduce.hh>
11 # include <vcsn/algos/strip.hh>
12 # include <vcsn/algos/union.hh>
13 # include <vcsn/dyn/automaton.hh>
14 # include <vcsn/dyn/ratexp.hh>
15 
16 namespace vcsn
17 {
18 
19  /*---------------------------------------.
20  | are_equivalent(automaton, automaton). |
21  `---------------------------------------*/
22 
24  template <typename Aut1, typename Aut2>
25  auto
26  are_equivalent(const Aut1& a1, const Aut2& a2)
27  -> typename std::enable_if<(labelset_t_of<Aut1>::is_free()
28  && std::is_same<weightset_t_of<Aut1>, b>::value
30  && std::is_same<weightset_t_of<Aut2>, b>::value),
31  bool>::type
32  {
33  return (is_useless(difference(a1, a2))
34  && is_useless(difference(a2, a1)));
35  }
36 
37 
39  template <typename Aut1, typename Aut2>
40  auto
41  are_equivalent(const Aut1& a1, const Aut2& a2)
42  -> decltype((a2->weightset()->sub(a2->weightset()->zero(),
43  a2->weightset()->one()),
44  true))
45  {
46  const auto& ws2 = *a2->weightset();
47  // d = a1 U -a2.
48  auto d = union_a(a1,
49  left_mult(ws2.sub(ws2.zero(), ws2.one()),
50  a2));
51  return is_empty(reduce(d));
52  }
53 
54 
55  namespace dyn
56  {
57  namespace detail
58  {
60  template <typename Aut1, typename Aut2>
61  bool
62  are_equivalent(const automaton& aut1, const automaton& aut2)
63  {
64  const auto& a1 = aut1->as<Aut1>();
65  const auto& a2 = aut2->as<Aut2>();
67  }
68 
70  (const automaton&, const automaton&) -> bool);
71  }
72  }
73 
74 
75  /*-----------------------------------.
76  | difference(automaton, automaton). |
77  `-----------------------------------*/
78 
80  template <typename Lhs, typename Rhs>
81  typename Lhs::element_type::automaton_nocv_t
82  difference(const Lhs& lhs, const Rhs& rhs)
83  {
84  // Meet complement()'s requirements.
85  auto r = strip(rhs);
86  if (!is_deterministic(r))
88  else if (!is_complete(r))
89  r = complete(r);
90  return strip(product(lhs, complement(r)));
91  }
92 
93  namespace dyn
94  {
95  namespace detail
96  {
98  template <typename Lhs, typename Rhs>
99  automaton
100  difference(const automaton& lhs, const automaton& rhs)
101  {
102  const auto& l = lhs->as<Lhs>();
103  const auto& r = rhs->as<Rhs>();
104  return make_automaton(::vcsn::difference(l, r));
105  }
106 
108  (const automaton&, const automaton&) -> automaton);
109  }
110  }
111 
112  /*-----------------------------.
113  | difference(ratexp, ratexp). |
114  `-----------------------------*/
115 
117  template <typename RatExpSet>
118  inline
119  typename RatExpSet::value_t
120  difference(const RatExpSet& rs,
121  const typename RatExpSet::value_t& lhs,
122  const typename RatExpSet::value_t& rhs)
123  {
124  return rs.conjunction(lhs, rs.complement(rhs));
125  }
126 
127  namespace dyn
128  {
129  namespace detail
130  {
132  template <typename RatExpSetLhs, typename RatExpSetRhs>
133  ratexp
134  difference_ratexp(const ratexp& lhs, const ratexp& rhs)
135  {
136  const auto& l = lhs->as<RatExpSetLhs>();
137  const auto& r = rhs->as<RatExpSetLhs>();
138  return make_ratexp(l.ratexpset(),
139  ::vcsn::difference<RatExpSetLhs>(l.ratexpset(),
140  l.ratexp(),
141  r.ratexp()));
142  }
143 
145  (const ratexp&, const ratexp&) -> ratexp);
146  }
147  }
148 }
149 
150 #endif // !VCSN_ALGOS_ARE_EQUIVALENT_HH
ratexp make_ratexp(const RatExpSet &rs, const typename RatExpSet::value_t &ratexp)
Definition: ratexp.hh:85
bool is_deterministic(const Aut &aut, state_t_of< Aut > s)
Whether state s is deterministic in aut.
auto are_equivalent(const Aut1 &a1, const Aut2 &a2) -> typename std::enable_if<(labelset_t_of< Aut1 >::is_free()&&std::is_same< weightset_t_of< Aut1 >, b >::value &&labelset_t_of< Aut2 >::is_free()&&std::is_same< weightset_t_of< Aut2 >, b >::value), bool >::type
Check equivalence between Boolean automata on a free labelset.
REGISTER_DECLARE(accessible,(const automaton &) -> automaton)
std::shared_ptr< detail::automaton_base > automaton
Definition: automaton.hh:71
auto product(const Auts &...as) -> product_automaton< decltype(meet_automata(as...)), Auts...>
Build the (accessible part of the) product.
Definition: product.hh:445
typename detail::labelset_t_of_impl< base_t< ValueSet >>::type labelset_t_of
Definition: traits.hh:34
bool is_useless(const Aut &a)
Definition: accessible.hh:157
auto reduce(const Aut &input) -> decltype(copy(input))
Definition: reduce.hh:610
automaton make_automaton(const Aut &aut)
Build a dyn::automaton.
Definition: automaton.hh:77
std::shared_ptr< detail::ratexp_base > ratexp
Definition: fwd.hh:64
bool is_complete(const Aut &aut)
Whether aut is complete.
Definition: is-complete.hh:15
typename detail::weightset_t_of_impl< base_t< ValueSet >>::type weightset_t_of
Definition: traits.hh:38
auto complete(const Aut &aut) -> decltype(::vcsn::copy(aut))
Definition: complete.hh:64
auto complement(const Aut &aut) -> decltype(copy(aut))
Definition: complement.hh:52
bool is_empty(const Aut &a) ATTRIBUTE_PURE
Definition: accessible.hh:178
auto determinize(const Aut &a) -> determinized_automaton< Aut >
Definition: determinize.hh:244
auto union_a(const A &lhs, const B &rhs) -> decltype(join_automata(lhs, rhs))
Union of two automata.
Definition: union.hh:33
Provide a variadic mul on top of a binary mul(), and one().
Definition: fwd.hh:36
auto strip(const Aut &aut) -> decltype(detail::strip(aut, 0))
Remove (all) the decorations from a decorated automaton.
Definition: strip.hh:38
Lhs::element_type::automaton_nocv_t difference(const Lhs &lhs, const Rhs &rhs)
An automaton that computes weights of lhs, but not by rhs.
automaton difference(const automaton &lhs, const automaton &rhs)
Bridge.
bool are_equivalent(const automaton &aut1, const automaton &aut2)
Bridge.
AutOut left_mult(const weight_t_of< AutOut > &w, const AutIn &aut)
Definition: left-mult.hh:91
ratexp difference_ratexp(const ratexp &lhs, const ratexp &rhs)
Bridge.