Vaucanson 1.4
numerical_semiring.hh
00001 
00002 // numerical_semiring.hh: this file is part of the Vaucanson project.
00003 //
00004 // Vaucanson, a generic library for finite state machines.
00005 //
00006 // Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2011 The Vaucanson Group.
00007 //
00008 // This program is free software; you can redistribute it and/or
00009 // modify it under the terms of the GNU General Public License
00010 // as published by the Free Software Foundation; either version 2
00011 // of the License, or (at your option) any later version.
00012 //
00013 // The complete GNU General Public Licence Notice can be found as the
00014 // `COPYING' file in the root directory.
00015 //
00016 // The Vaucanson Group consists of people listed in the `AUTHORS' file.
00017 //
00018 #ifndef VCSN_ALGEBRA_IMPLEMENTATION_SEMIRING_NUMERICAL_SEMIRING_HH
00019 # define VCSN_ALGEBRA_IMPLEMENTATION_SEMIRING_NUMERICAL_SEMIRING_HH
00020 
00021 # include <vaucanson/algebra/concept/numerical_semiring.hh>
00022 # include <vaucanson/algebra/implementation/semiring/q_number.hh>
00023 
00024 namespace vcsn {
00025 
00026   namespace algebra {
00027 
00028     template<typename T>
00029     bool op_contains(const algebra::NumericalSemiring& s, T c);
00030 
00031     template<typename T, typename U>
00032     void op_in_mul(const algebra::NumericalSemiring& s1, T& dst, U arg);
00033 
00034     template<typename T, typename U>
00035     void op_in_add(const algebra::NumericalSemiring& s1, T& dst, U arg);
00036 
00037     template<typename T, typename U>
00038     T op_mul(const algebra::NumericalSemiring& s, T a, U b);
00039 
00040     template<typename T, typename U>
00041     T op_add(const algebra::NumericalSemiring& s, T a, U b);
00042 
00043     template<typename T>
00044     T identity_value(SELECTOR(algebra::NumericalSemiring), SELECTOR(T));
00045 
00046     template<typename T>
00047     bool show_identity_value(SELECTOR(algebra::NumericalSemiring), SELECTOR(T));
00048 
00049     template<typename T>
00050     T zero_value(SELECTOR(algebra::NumericalSemiring), SELECTOR(T));
00051 
00052     template <class T>
00053     Element<algebra::NumericalSemiring, T>
00054     op_choose(const algebra::NumericalSemiring& s, SELECTOR(T));
00055 
00056     /*-----------------------------.
00057     | specializations for integers |
00058     `-----------------------------*/
00059 
00060     bool
00061     op_can_choose_non_starable(const algebra::NumericalSemiring& set,
00062                                SELECTOR(int));
00063 
00064     Element<algebra::NumericalSemiring, int>
00065     op_choose_starable(const algebra::NumericalSemiring& set, SELECTOR(int));
00066 
00067     Element<algebra::NumericalSemiring, int>
00068     op_choose_non_starable(const algebra::NumericalSemiring& set,
00069                            SELECTOR(int));
00070 
00071     /*-----------------------------.
00072     | specializations for Booleans |
00073     `-----------------------------*/
00074     template<typename T>
00075     void op_in_mul(const algebra::NumericalSemiring& s1,
00076                           bool& dst, bool src);
00077 
00078     inline bool op_mul(const algebra::NumericalSemiring& s, bool a, bool b);
00079 
00080     inline void op_in_add(const algebra::NumericalSemiring& s1,
00081                           bool& dst, bool src);
00082 
00083     inline bool op_add(const algebra::NumericalSemiring& s, bool a, bool b);
00084 
00085     inline bool identity_value(SELECTOR(algebra::NumericalSemiring),
00086                                SELECTOR(bool));
00087 
00088     inline bool zero_value(SELECTOR(algebra::NumericalSemiring),
00089                            SELECTOR(bool));
00090 
00091     inline bool op_starable(const algebra::NumericalSemiring& s, bool b);
00092 
00093     inline void op_in_star(const algebra::NumericalSemiring& s, bool& b);
00094 
00095     Element<algebra::NumericalSemiring, bool>
00096     op_choose_starable(const algebra::NumericalSemiring& set, SELECTOR(bool));
00097 
00098     Element<algebra::NumericalSemiring, bool>
00099     op_choose_non_starable(const algebra::NumericalSemiring& set,
00100                            SELECTOR(bool));
00101 
00102     /*-------------------------.
00103     | goodies for real numbers |
00104     `-------------------------*/
00105 
00106     /* Operators only available for fields */
00107     inline float op_sub(const algebra::NumericalSemiring&, const float& a, const float& b);
00108 
00109     inline double op_sub(const algebra::NumericalSemiring&, const double& a, const double& b);
00110 
00111     inline float op_div(const algebra::NumericalSemiring&, const float& a, const float& b);
00112 
00113     inline double op_div(const algebra::NumericalSemiring&, const double& a, const double& b);
00114     
00115 
00116     inline bool op_eq(const algebra::NumericalSemiring&, float& a, float& b);
00117 
00118     inline bool op_eq(const algebra::NumericalSemiring&, double& a, double& b);
00119 
00120     template<typename T>
00121     bool op_starable(const algebra::NumericalSemiring& s, T v);
00122 
00123     inline bool op_starable(const algebra::NumericalSemiring& s,
00124                             const float& f);
00125 
00126     inline bool op_starable(const algebra::NumericalSemiring& s,
00127                             const double& f);
00128 
00129     inline void op_in_star(const algebra::NumericalSemiring& s, float& f);
00130 
00131     inline void op_in_star(const algebra::NumericalSemiring& s, double& f);
00132 
00133     bool
00134     op_can_choose_non_starable(const algebra::NumericalSemiring& set,
00135                                 SELECTOR(float));
00136 
00137     Element<algebra::NumericalSemiring, float>
00138     op_choose_starable(const algebra::NumericalSemiring& set,
00139                        SELECTOR(float));
00140 
00141     Element<algebra::NumericalSemiring, float>
00142     op_choose_non_starable(const algebra::NumericalSemiring& set,
00143                            SELECTOR(float));
00144 
00145     bool
00146     op_can_choose_non_starable(const algebra::NumericalSemiring& set,
00147                                 SELECTOR(double));
00148 
00149     Element<algebra::NumericalSemiring, double>
00150     op_choose_starable(const algebra::NumericalSemiring& set,
00151                        SELECTOR(double));
00152 
00153     Element<algebra::NumericalSemiring, double>
00154     op_choose_non_starable(const algebra::NumericalSemiring& set,
00155                            SELECTOR(double));
00156 
00157     /*-------------------------------------.
00158     | specializations for rational numbers |
00159     `-------------------------------------*/
00160 
00161 
00162     inline RationalNumber
00163     op_sub(const algebra::NumericalSemiring&, const RationalNumber&, const RationalNumber&);
00164 
00165     inline RationalNumber
00166     op_div(const algebra::NumericalSemiring&, const RationalNumber&, const RationalNumber&);
00167 
00168 
00169     inline algebra::RationalNumber
00170     identity_value(SELECTOR(algebra::NumericalSemiring),
00171                    SELECTOR(algebra::RationalNumber));
00172 
00173 
00174     inline algebra::RationalNumber
00175     zero_value(SELECTOR(algebra::NumericalSemiring),
00176                SELECTOR(algebra::RationalNumber));
00177 
00178     inline
00179     bool op_starable(const algebra::NumericalSemiring& s, RationalNumber& v);
00180 
00181     inline bool op_starable(const algebra::NumericalSemiring& s,
00182                             const algebra::RationalNumber& r);
00183 
00184     inline void op_in_star(const algebra::NumericalSemiring& s,
00185                            algebra::RationalNumber& r);
00186 
00187     inline
00188     bool
00189     op_can_choose_non_starable(const algebra::NumericalSemiring& set,
00190                                SELECTOR(algebra::RationalNumber));
00191 
00192     inline
00193     Element<algebra::NumericalSemiring, algebra::RationalNumber>
00194     op_choose_starable(const algebra::NumericalSemiring& set,
00195                        SELECTOR(algebra::RationalNumber));
00196 
00197     inline
00198     Element<algebra::NumericalSemiring, algebra::RationalNumber>
00199     op_choose_non_starable(const algebra::NumericalSemiring& set,
00200                            SELECTOR(algebra::RationalNumber));
00201 
00202   } // algebra
00203 
00204   template <typename T>
00205   struct semiring_traits<algebra::NumericalSemiring, T>
00206   {
00207     enum { is_positive = 0 };
00208   };
00209 
00210   template <>
00211   struct semiring_traits<algebra::NumericalSemiring, bool>
00212   {
00213     enum { is_positive = 1 };
00214   };
00215 
00216 } // vcsn
00217 
00218 
00219 # if !defined VCSN_USE_INTERFACE_ONLY || defined VCSN_USE_LIB
00220 # include <vaucanson/algebra/implementation/semiring/numerical_semiring.hxx>
00221 #endif // VCSN_USE_INTERFACE_ONLY
00222 
00223 
00224 #endif // ! VCSN_ALGEBRA_IMPLEMENTATION_SEMIRING_NUMERICAL_SEMIRING_HH