17 #ifndef VCSN_ALGORITHMS_LETTER_TO_LETTER_COMPOSITION_HXX
18 # define VCSN_ALGORITHMS_LETTER_TO_LETTER_COMPOSITION_HXX
20 # include <vaucanson/automata/concept/transducer_base.hh>
21 # include <vaucanson/misc/usual_macros.hh>
29 template <
class Self,
class T>
31 do_letter_to_letter_composition(
const TransducerBase<Self>& s,
32 const Element<Self, T>& f,
33 const Element<Self, T>& g)
35 typedef Element<Self, T> transducer_t;
36 AUTOMATON_TYPES(transducer_t);
37 typedef std::map<std::pair<hstate_t, hstate_t>, hstate_t> assoc_t;
38 typedef std::list<htransition_t> delta_ret_t;
40 semiring_t output_series(f.series().semiring().semiring(),
41 f.series().semiring().monoid());
42 series_set_t series(output_series, g.series().monoid());
43 automata_set_t structure(series);
44 transducer_t output(s);
46 series_set_elt_t zero =
47 algebra::zero_as<series_set_elt_value_t>::of(output.series());
49 for_all_const_states(s, f)
50 for_all_const_states(t, g)
52 hstate_t ns = output.add_state();
53 conv[std::make_pair(*s, *t)] = ns;
54 output.set_initial(ns,
55 f.get_initial(*s) * g.get_initial(*t));
57 f.get_final(*s) * g.get_final(*t));
61 for_all_const_states(s, f)
62 for_all_const_states(t, g)
64 for (delta_iterator lhs_e(f.value(), *s); ! lhs_e.done(); lhs_e.next())
66 series_set_elt_t l = f.series_of(*lhs_e);
67 for (delta_iterator rhs_e(g.value(), *s); ! rhs_e.done(); rhs_e.next())
69 series_set_elt_t l_ = g.series_of(*rhs_e);
70 series_set_elt_t l__(series);
71 typedef typename series_set_t::support_t support_t;
72 for_all_const_(support_t, supp, l.supp())
74 semiring_elt_t ol = l.get(*supp);
75 typedef typename semiring_elt_t::support_t wsupport_t;
76 wsupport_t wsupp = ol.supp();
77 series_set_t ts(series, monoid_elt_t(*supp));
78 for_all_const_(wsupport_t, ss, wsupp)
79 l__ += ts * l_.
get(*ss);
83 output.add_series_transition(conv[std::make_pair(*s, *t)],
84 conv[std::make_pair(f.dst_of(*lhs_e),
95 template <
class S,
class T>
100 BENCH_TASK_SCOPED(
"letter_to_letter_composition");
101 return do_letter_to_letter_composition(lhs.
structure(), lhs, rhs);
106 #endif // ! VCSN_ALGORITHMS_LETTER_TO_LETTER_COMPOSITION_HXX