00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef VCSN_ALGEBRA_CONCEPT_SERIES_BASE_HXX
00018 # define VCSN_ALGEBRA_CONCEPT_SERIES_BASE_HXX
00019
00020 # include <vaucanson/algebra/concept/series_base.hh>
00021 # include <vaucanson/tools/usual_macros.hh>
00022
00023 namespace vcsn {
00024
00025 namespace algebra {
00026
00027
00028
00029
00030
00031 template<class Self>
00032 const typename SeriesBase<Self>::monoid_t&
00033 SeriesBase<Self>::monoid() const
00034 {
00035 return this->self().monoid();
00036 }
00037
00038 template<class Self>
00039 const typename SeriesBase<Self>::semiring_t&
00040 SeriesBase<Self>::semiring() const
00041 {
00042 return this->self().semiring();
00043 }
00044
00045 template<class Self>
00046 typename SeriesBase<Self>::monoid_t&
00047 SeriesBase<Self>::monoid()
00048 {
00049 return this->self().monoid();
00050 }
00051
00052 template<class Self>
00053 typename SeriesBase<Self>::semiring_t&
00054 SeriesBase<Self>::semiring()
00055 {
00056 return this->self().semiring();
00057 }
00058
00059 template<class Self>
00060 SeriesBase<Self>::SeriesBase()
00061 {}
00062
00063 template<class Self>
00064 SeriesBase<Self>::SeriesBase(const SeriesBase& other) :
00065 SemiringBase<Self>(other)
00066 {}
00067
00068 }
00069
00070
00071
00072
00073
00074
00075 template<typename S, typename T>
00076 typename MetaElement<algebra::SeriesBase<S>, T>::semiring_elt_value_t
00077 MetaElement<algebra::SeriesBase<S>, T>::get(const monoid_elt_value_t& m) const
00078 {
00079
00080 return op_series_get(this->structure(), this->value(), m);
00081 }
00082
00083 template<typename S, typename T>
00084 typename MetaElement<algebra::SeriesBase<S>, T>::semiring_elt_t
00085 MetaElement<algebra::SeriesBase<S>, T>::get(const monoid_elt_t& m) const
00086 {
00087 return semiring_elt_t(this->structure().semiring(), get(m.value()));
00088 }
00089
00090 template<typename S, typename T>
00091 void
00092 MetaElement<algebra::SeriesBase<S>, T>::assoc(const monoid_elt_value_t& m,
00093 const semiring_elt_value_t& w)
00094 {
00095
00096
00097 return op_series_set(this->structure(), this->value(), m, w);
00098 }
00099
00100 template<typename S, typename T>
00101 void
00102 MetaElement<algebra::SeriesBase<S>, T>::assoc(const monoid_elt_t& m,
00103 const semiring_elt_t& w)
00104 {
00105 assoc(m.value(), w.value());
00106 }
00107
00108 template<typename S, typename T>
00109 bool
00110 MetaElement<algebra::SeriesBase<S>, T>::is_finite_app() const
00111 {
00112 return op_is_finite_app(this->structure(), this->value());
00113 }
00114
00115 template <typename S, typename T>
00116 typename MetaElement<algebra::SeriesBase<S>, T>::monoid_elt_t
00117 MetaElement<algebra::SeriesBase<S>, T>::choose_from_supp() const
00118 {
00119 return
00120 typename MetaElement<algebra::SeriesBase<S>, T>::monoid_elt_t
00121 (this->structure().monoid(), op_choose_from_supp(this->structure(), this->value()));
00122 }
00123
00124 template <typename S, typename T>
00125 void
00126 MetaElement<algebra::SeriesBase<S>, T>::transpose()
00127 {
00128 op_in_transpose(this->structure(), this->value());
00129 }
00130
00131 template <typename S, typename T>
00132 typename MetaElement<algebra::SeriesBase<S>, T>::support_t
00133 MetaElement<algebra::SeriesBase<S>, T>::supp() const
00134 {
00135 return op_support(this->structure(), this->value());
00136 }
00137
00138 template<typename S, typename T>
00139 MetaElement<algebra::SeriesBase<S>, T>::MetaElement()
00140 {}
00141
00142 template<typename S, typename T>
00143 MetaElement<algebra::SeriesBase<S>, T>::MetaElement(const MetaElement& other) :
00144 MetaElement<algebra::SemiringBase<S>, T>(other)
00145 {}
00146
00147 template<typename S, typename T>
00148 bool op_is_finite_app(const algebra::SeriesBase<S>& s, const T& t)
00149 {
00150 return false;
00151 }
00152
00153 template<typename S, typename T, typename M, typename W>
00154 void op_series_structure(const algebra::SeriesBase<S>& s, const T& t, const W& w)
00155 {
00156 pure_service_call ("default implementation of op_series_structure()");
00157 }
00158
00159 template <class S, class T>
00160 Element<S, T> op_series_choose(const algebra::SeriesBase<S>& s, SELECTOR(T))
00161 {
00162 pure_service_call ("default implementation of op_series_choose()");
00163 return Element<S, T>();
00164 }
00165
00166 template <class S, class T>
00167 typename algebra::series_traits<T>::support_t
00168 op_support(const algebra::SeriesBase<S>&, const T& v)
00169 {
00170 return v;
00171 }
00172
00173 template <class S, class T>
00174 Element<S, T>
00175 transpose(const algebra::SeriesBase<S>& s, const T& t)
00176 {
00177 T new_t(t);
00178 new_t.transpose();
00179 return new_t;
00180 }
00181
00182 template <class S, class T>
00183 bool
00184 is_letter_support(const Element<S, T>& s)
00185 {
00186 typedef typename algebra::series_traits<T>::support_t support_t;
00187 support_t supp = s.supp();
00188 for_each_const_(support_t, e, supp)
00189 if (op_size(s.structure().monoid(), *e) != 1)
00190 return false;
00191 return true;
00192 }
00193
00194 template <typename S1, typename S2, typename T1, typename T2>
00195 void
00196 extract_support(Element<S1, T1>& s1, Element<S2, T2>& s2)
00197 {
00198 typedef typename algebra::series_traits<T2>::support_t support_t;
00199 typedef typename algebra::series_traits<T1>::semiring_elt_value_t
00200 semiring_elt_value_t;
00201 for_each_const_(support_t, e, s2.supp())
00202 s1.assoc(*e,
00203 algebra::identity_as<semiring_elt_value_t>::
00204 of(s1.structure().semiring()));
00205 }
00206
00207 template <class S, class T>
00208 Element<S, T> hadamard(const Element<S, T>& lhs,
00209 const Element<S, T>& rhs)
00210 {
00211 typedef Element<S, T> series_set_elt_t;
00212 typedef typename Element<S, T>::monoid_elt_t monoid_elt_t;
00213 typedef typename Element<S, T>::semiring_elt_t semiring_elt_t;
00214 typedef typename Element<S, T>::support_t support_t;
00215 Element<S, T> output;
00216 support_t support = lhs.supp();
00217 for (typename support_t::iterator supp = support.begin();
00218 supp != support.end();
00219 ++supp)
00220 {
00221 output += lhs.get(*supp) *
00222 rhs.get(*supp) * series_set_elt_t(lhs.structure(), monoid_elt_t(*supp));
00223 }
00224 return output;
00225 }
00226
00227 template <class S, class M>
00228 S
00229 op_convert(const algebra::SeriesBase<S>&,
00230 const algebra::FreeMonoidBase<M>& monoid)
00231 {
00232
00233 enum { compatible = utility::static_eq<typename S::monoid_t, M>::value };
00234 static_assertion_(compatible, invalid_conversion_from_monoid_to_series);
00235
00236 typename S::semiring_t semiring;
00237 return S (semiring, monoid.self());
00238 }
00239
00240 template <class S, class T>
00241 T op_convert(const algebra::SeriesBase<S>&, SELECTOR(T), const T& src_)
00242 {
00243 return src_;
00244 }
00245
00246 template <class S, class T, class U>
00247 T op_convert(const algebra::SeriesBase<S>& s, SELECTOR(T), const U& src_)
00248 {
00249 typedef typename algebra::series_traits<U>::support_t support_t;
00250 typedef typename Element<S, T>::monoid_elt_t monoid_elt_t;
00251 S ts = s.self();
00252 Element<S, U> src(ts, src_);
00253 Element<S, T> dst(ts);
00254 support_t support = src.supp();
00255 for_each_const_(support_t, ss, support)
00256 dst += src.get(monoid_elt_t(s.monoid(), *ss)) *
00257 Element<S, T>(s.self(), monoid_elt_t(s.monoid(), *ss));
00258 return dst.value();
00259 }
00260
00261 }
00262
00263 #endif // ! VCSN_ALGEBRA_CONCEPT_SERIES_BASE_HXX