17 #ifndef VCSN_ALGEBRA_IMPLEMENTATION_SERIES_KRAT_EXP_SUPPORT_HXX
18 # define VCSN_ALGEBRA_IMPLEMENTATION_SERIES_KRAT_EXP_SUPPORT_HXX
21 # include <vaucanson/algebra/implementation/series/krat_exp_pattern.hh>
22 # include <vaucanson/algebra/implementation/series/krat_exp_is_finite_app.hxx>
26 template <
class Series,
class T,
class Dispatch>
27 class SupportMatcher :
public algebra::KRatExpMatcher<
28 SupportMatcher<Series, T, Dispatch>,
35 typedef IsFiniteAppMatcher<Series, T, Dispatch> self_t;
36 typedef int return_type;
37 typedef Series series_set_t;
38 typedef Element<Series, T> series_set_elt_t;
39 typedef typename series_set_elt_t::monoid_elt_t monoid_elt_t;
40 typedef typename monoid_elt_t::value_t monoid_elt_value_t;
41 typedef typename series_set_elt_t::semiring_elt_t semiring_elt_t;
42 typedef typename semiring_elt_t::value_t semiring_elt_value_t;
43 typedef std::list<monoid_elt_value_t> support_t;
44 typedef std::list<std::pair<semiring_elt_value_t, monoid_elt_value_t> >
46 INHERIT_CONSTRUCTORS(self_t, T, return_type, Dispatch);
48 SupportMatcher(
const series_set_t& s):
52 MATCH__(Product, lhs, rhs)
54 ext_support_t old_supp_ = supp_;
57 ext_support_t lhs_s = supp_;
61 for_all_const_(ext_support_t, c, lhs_s)
62 for_all_const_(ext_support_t, d, supp_)
64 monoid_elt_t mc(series_.monoid(), c->second);
65 monoid_elt_t md(series_.monoid(), d->second);
66 semiring_elt_t wc(series_.semiring(), c->first);
67 semiring_elt_t wd(series_.semiring(), d->first);
68 ret.push_back(std::make_pair((wc * wd).value(),
72 supp_.insert(supp_.begin(), old_supp_.begin(), old_supp_.end());
77 MATCH__(Sum, lhs, rhs)
87 result_not_computable(
"undefined case (star) in krat_exp_support");
92 MATCH__(LeftWeight, w, node)
94 ext_support_t old_supp_ = supp_;
97 for_all_(ext_support_t, c, supp_)
98 c->first =
op_mul(series_.semiring(), w, c->first);
99 supp_.insert(supp_.begin(), old_supp_.begin(), old_supp_.end());
104 MATCH__(RightWeight, node, w)
106 ext_support_t old_supp_ = supp_;
109 for_all_(ext_support_t, c, supp_)
110 c->first =
op_mul(series_.semiring(), c->first, w);
111 supp_.insert(supp_.begin(), old_supp_.begin(), old_supp_.end());
118 supp_.push_back(std::make_pair
119 (identity_value(series_.semiring(),
120 SELECT(semiring_elt_value_t)),
134 supp_.push_back(std::make_pair
135 (identity_value(series_.semiring(),
136 SELECT(semiring_elt_value_t)),
137 identity_value(series_.monoid(),
138 SELECT(monoid_elt_value_t))));
146 ext_support_t s = ext_get();
147 for_all_const_(ext_support_t, c, s)
148 ret.push_back(c->second);
152 ext_support_t& ext_get()
155 typedef std::map<monoid_elt_value_t, semiring_elt_value_t> tmap_t;
157 typename tmap_t::iterator f;
158 for_all_const_(ext_support_t, c, supp_)
160 if ((f = v.find(c->second)) == v.end())
161 v[c->second] = c->first;
163 v[c->second] =
op_add(series_.semiring(), v[c->second], c->first);
166 for_all_const_(tmap_t, m, v)
167 supp_.push_back(std::make_pair(m->second, m->first));
173 const series_set_t& series_;
178 #endif // ! VCSN_ALGEBRA_IMPLEMENTATION_SERIES_KRAT_EXP_SUPPORT_HXX