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/misc/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(),
00122 op_choose_from_supp(this->structure(), this->value()));
00123 }
00124
00125 template <typename S, typename T>
00126 void
00127 MetaElement<algebra::SeriesBase<S>, T>::transpose()
00128 {
00129 op_in_transpose(this->structure(), this->value());
00130 }
00131
00132 template <typename S, typename T>
00133 typename MetaElement<algebra::SeriesBase<S>, T>::support_t
00134 MetaElement<algebra::SeriesBase<S>, T>::supp() const
00135 {
00136 return op_support(this->structure(), this->value());
00137 }
00138
00139 template<typename S, typename T>
00140 MetaElement<algebra::SeriesBase<S>, T>::MetaElement()
00141 {}
00142
00143 template<typename S, typename T>
00144 MetaElement<algebra::SeriesBase<S>, T>::MetaElement(const MetaElement& other) :
00145 MetaElement<algebra::SemiringBase<S>, T>(other)
00146 {}
00147
00148 template<typename S, typename T>
00149 bool op_is_finite_app(const algebra::SeriesBase<S>& s, const T& t)
00150 {
00151 return false;
00152 }
00153
00154 template<typename S, typename T, typename M, typename W>
00155 void op_series_structure(const algebra::SeriesBase<S>& s, const T& t, const W& w)
00156 {
00157 pure_service_call ("default implementation of op_series_structure()");
00158 }
00159
00160 template <class S, class T>
00161 Element<S, T> op_series_choose(const algebra::SeriesBase<S>& s, SELECTOR(T))
00162 {
00163 pure_service_call ("default implementation of op_series_choose()");
00164 return Element<S, T>();
00165 }
00166
00167 template <class S, class T>
00168 typename algebra::series_traits<T>::support_t
00169 op_support(const algebra::SeriesBase<S>&, const T& v)
00170 {
00171 return v;
00172 }
00173
00174 template <class S, class T>
00175 Element<S, T>
00176 transpose(const algebra::SeriesBase<S>& s, const T& t)
00177 {
00178 T new_t(t);
00179 new_t.transpose();
00180 return new_t;
00181 }
00182
00183 template <class S, class T>
00184 bool
00185 is_letter_support(const Element<S, T>& s)
00186 {
00187 typedef typename algebra::series_traits<T>::support_t support_t;
00188 support_t supp = s.supp();
00189 for_all_const_(support_t, e, supp)
00190 if (op_size(s.structure().monoid(), *e) != 1)
00191 return false;
00192 return true;
00193 }
00194
00195 template <typename S1, typename S2, typename T1, typename T2>
00196 void
00197 extract_support(Element<S1, T1>& s1, Element<S2, T2>& s2)
00198 {
00199 typedef typename algebra::series_traits<T2>::support_t support_t;
00200 typedef typename algebra::series_traits<T1>::semiring_elt_value_t
00201 semiring_elt_value_t;
00202 for_all_const_(support_t, e, s2.supp())
00203 s1.assoc(*e,
00204 algebra::identity_as<semiring_elt_value_t>::
00205 of(s1.structure().semiring()));
00206 }
00207
00208 template <class S, class T>
00209 Element<S, T> hadamard(const Element<S, T>& lhs,
00210 const Element<S, T>& rhs)
00211 {
00212 typedef Element<S, T> series_set_elt_t;
00213 typedef typename Element<S, T>::monoid_elt_t monoid_elt_t;
00214 typedef typename Element<S, T>::semiring_elt_t semiring_elt_t;
00215 typedef typename Element<S, T>::support_t support_t;
00216 Element<S, T> output;
00217 support_t support = lhs.supp();
00218 for (typename support_t::iterator supp = support.begin();
00219 supp != support.end();
00220 ++supp)
00221 {
00222 output += lhs.get(*supp) *
00223 rhs.get(*supp) * series_set_elt_t(lhs.structure(), monoid_elt_t(*supp));
00224 }
00225 return output;
00226 }
00227
00228 template <class S, class M>
00229 S
00230 op_convert(const algebra::SeriesBase<S>&,
00231 const algebra::FreeMonoidBase<M>& monoid)
00232 {
00233
00234 enum { compatible = misc::static_eq<typename S::monoid_t, M>::value };
00235 static_assertion_(compatible, invalid_conversion_from_monoid_to_series);
00236
00237 typename S::semiring_t semiring;
00238 return S (semiring, monoid.self());
00239 }
00240
00241 template <class S, class T>
00242 T op_convert(const algebra::SeriesBase<S>&, SELECTOR(T), const T& src_)
00243 {
00244 return src_;
00245 }
00246
00247 template <class S, class T, class U>
00248 T op_convert(const algebra::SeriesBase<S>& s, SELECTOR(T), const U& src_)
00249 {
00250 typedef typename algebra::series_traits<U>::support_t support_t;
00251 typedef typename Element<S, T>::monoid_elt_t monoid_elt_t;
00252 S ts = s.self();
00253 Element<S, U> src(ts, src_);
00254 Element<S, T> dst(ts);
00255 support_t support = src.supp();
00256 for_all_const_(support_t, ss, support)
00257 dst += src.get(monoid_elt_t(s.monoid(), *ss)) *
00258 Element<S, T>(s.self(), monoid_elt_t(s.monoid(), *ss));
00259 return dst.value();
00260 }
00261
00262 }
00263
00264 #endif // ! VCSN_ALGEBRA_CONCEPT_SERIES_BASE_HXX