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