17 #ifndef VCSN_ALGORITHMS_INITIAL_DERIVATION_HXX
18 # define VCSN_ALGORITHMS_INITIAL_DERIVATION_HXX
20 # include <vaucanson/algebra/concept/series_base.hh>
21 # include <vaucanson/algebra/implementation/series/krat_exp_pattern.hh>
35 template <
class Series,
class T,
class Dispatch>
37 KRatExpInitialDerivation<Series, T, Dispatch>,
39 std::list< Element<Series, T> >,
45 typedef std::list<exp_t> list_t;
46 typedef std::list<exp_t> return_type;
47 typedef typename list_t::iterator iterator_t;
48 IMPORT_TYPEDEF_(
exp_t, semiring_elt_t);
49 IMPORT_TYPEDEF_(
exp_t, monoid_elt_t);
50 typedef typename semiring_elt_t::value_t semiring_elt_value_t;
51 INHERIT_CONSTRUCTORS(
self_t, T, semiring_elt_t, Dispatch);
59 list_t apply_sum(list_t explist)
61 if (explist.size() != 1)
63 iterator_t i = explist.begin();
65 for (i++; i != explist.end(); ++i)
70 explist.push_back(res);
75 list_t& put_in(list_t& s,
exp_t e)
85 MATCH__(Product, lhs, rhs)
87 list_t llist =
match(lhs);
90 for (
typename list_t::const_iterator it = llist.begin();
91 it != llist.end(); ++it)
92 res.push_back(*it * s);
97 MATCH__(Sum, lhs, rhs)
99 list_t llist =
match(lhs);
100 list_t rlist =
match(rhs);
102 merge(llist.begin(), llist.end(),
103 rlist.begin(), rlist.end(),
104 inserter(res, res.begin()));
118 MATCH__(LeftWeight, w, e)
120 list_t clist = apply_sum(
match(e));
121 put_in(clist, semiring_elt_t(w) * *clist.begin());
126 MATCH__(RightWeight, e, w)
128 list_t clist = apply_sum(
match(e));
129 put_in(clist, *clist.begin() * semiring_elt_t(w));
165 #endif // ! VCSN_ALGORITHMS_INITIAL_DERIVATION_HXX