Vaucanson  1.4.1
implementation/semiring/numerical_semiring.hh
1 
2 // numerical_semiring.hh: this file is part of the Vaucanson project.
3 //
4 // Vaucanson, a generic library for finite state machines.
5 //
6 // Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2011 The Vaucanson Group.
7 //
8 // This program is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU General Public License
10 // as published by the Free Software Foundation; either version 2
11 // of the License, or (at your option) any later version.
12 //
13 // The complete GNU General Public Licence Notice can be found as the
14 // `COPYING' file in the root directory.
15 //
16 // The Vaucanson Group consists of people listed in the `AUTHORS' file.
17 //
18 #ifndef VCSN_ALGEBRA_IMPLEMENTATION_SEMIRING_NUMERICAL_SEMIRING_HH
19 # define VCSN_ALGEBRA_IMPLEMENTATION_SEMIRING_NUMERICAL_SEMIRING_HH
20 
21 # include <vaucanson/algebra/concept/numerical_semiring.hh>
23 
24 namespace vcsn {
25 
26  namespace algebra {
27 
28  template<typename T>
29  bool op_contains(const algebra::NumericalSemiring& s, T c);
30 
31  template<typename T, typename U>
32  void op_in_mul(const algebra::NumericalSemiring& s1, T& dst, U arg);
33 
34  template<typename T, typename U>
35  void op_in_add(const algebra::NumericalSemiring& s1, T& dst, U arg);
36 
37  template<typename T, typename U>
38  T op_mul(const algebra::NumericalSemiring& s, T a, U b);
39 
40  template<typename T, typename U>
41  T op_add(const algebra::NumericalSemiring& s, T a, U b);
42 
43  template<typename T>
44  T identity_value(SELECTOR(algebra::NumericalSemiring), SELECTOR(T));
45 
46  template<typename T>
47  bool show_identity_value(SELECTOR(algebra::NumericalSemiring), SELECTOR(T));
48 
49  template<typename T>
50  T zero_value(SELECTOR(algebra::NumericalSemiring), SELECTOR(T));
51 
52  template <class T>
53  Element<algebra::NumericalSemiring, T>
54  op_choose(const algebra::NumericalSemiring& s, SELECTOR(T));
55 
56  /*-----------------------------.
57  | specializations for integers |
58  `-----------------------------*/
59 
60  bool
61  op_can_choose_non_starable(const algebra::NumericalSemiring& set,
62  SELECTOR(int));
63 
64  Element<algebra::NumericalSemiring, int>
65  op_choose_starable(const algebra::NumericalSemiring& set, SELECTOR(int));
66 
67  Element<algebra::NumericalSemiring, int>
68  op_choose_non_starable(const algebra::NumericalSemiring& set,
69  SELECTOR(int));
70 
71  /*-----------------------------.
72  | specializations for Booleans |
73  `-----------------------------*/
74  template<typename T>
75  void op_in_mul(const algebra::NumericalSemiring& s1,
76  bool& dst, bool src);
77 
78  inline bool op_mul(const algebra::NumericalSemiring& s, bool a, bool b);
79 
80  inline void op_in_add(const algebra::NumericalSemiring& s1,
81  bool& dst, bool src);
82 
83  inline bool op_add(const algebra::NumericalSemiring& s, bool a, bool b);
84 
85  inline bool identity_value(SELECTOR(algebra::NumericalSemiring),
86  SELECTOR(bool));
87 
88  inline bool zero_value(SELECTOR(algebra::NumericalSemiring),
89  SELECTOR(bool));
90 
91  inline bool op_starable(const algebra::NumericalSemiring& s, bool b);
92 
93  inline void op_in_star(const algebra::NumericalSemiring& s, bool& b);
94 
95  Element<algebra::NumericalSemiring, bool>
96  op_choose_starable(const algebra::NumericalSemiring& set, SELECTOR(bool));
97 
98  Element<algebra::NumericalSemiring, bool>
99  op_choose_non_starable(const algebra::NumericalSemiring& set,
100  SELECTOR(bool));
101 
102  /*-------------------------.
103  | goodies for real numbers |
104  `-------------------------*/
105 
106  /* Operators only available for fields */
107  inline float op_sub(const algebra::NumericalSemiring&, const float& a, const float& b);
108 
109  inline double op_sub(const algebra::NumericalSemiring&, const double& a, const double& b);
110 
111  inline float op_div(const algebra::NumericalSemiring&, const float& a, const float& b);
112 
113  inline double op_div(const algebra::NumericalSemiring&, const double& a, const double& b);
114 
115 
116  inline bool op_eq(const algebra::NumericalSemiring&, float& a, float& b);
117 
118  inline bool op_eq(const algebra::NumericalSemiring&, double& a, double& b);
119 
120  template<typename T>
121  bool op_starable(const algebra::NumericalSemiring& s, T v);
122 
123  inline bool op_starable(const algebra::NumericalSemiring& s,
124  const float& f);
125 
126  inline bool op_starable(const algebra::NumericalSemiring& s,
127  const double& f);
128 
129  inline void op_in_star(const algebra::NumericalSemiring& s, float& f);
130 
131  inline void op_in_star(const algebra::NumericalSemiring& s, double& f);
132 
133  bool
134  op_can_choose_non_starable(const algebra::NumericalSemiring& set,
135  SELECTOR(float));
136 
137  Element<algebra::NumericalSemiring, float>
138  op_choose_starable(const algebra::NumericalSemiring& set,
139  SELECTOR(float));
140 
141  Element<algebra::NumericalSemiring, float>
142  op_choose_non_starable(const algebra::NumericalSemiring& set,
143  SELECTOR(float));
144 
145  bool
146  op_can_choose_non_starable(const algebra::NumericalSemiring& set,
147  SELECTOR(double));
148 
149  Element<algebra::NumericalSemiring, double>
150  op_choose_starable(const algebra::NumericalSemiring& set,
151  SELECTOR(double));
152 
153  Element<algebra::NumericalSemiring, double>
154  op_choose_non_starable(const algebra::NumericalSemiring& set,
155  SELECTOR(double));
156 
157  /*-------------------------------------.
158  | specializations for rational numbers |
159  `-------------------------------------*/
160 
161 
162  inline RationalNumber
163  op_sub(const algebra::NumericalSemiring&, const RationalNumber&, const RationalNumber&);
164 
165  inline RationalNumber
166  op_div(const algebra::NumericalSemiring&, const RationalNumber&, const RationalNumber&);
167 
168 
169  inline algebra::RationalNumber
170  identity_value(SELECTOR(algebra::NumericalSemiring),
171  SELECTOR(algebra::RationalNumber));
172 
173 
174  inline algebra::RationalNumber
175  zero_value(SELECTOR(algebra::NumericalSemiring),
176  SELECTOR(algebra::RationalNumber));
177 
178  inline
179  bool op_starable(const algebra::NumericalSemiring& s, RationalNumber& v);
180 
181  inline bool op_starable(const algebra::NumericalSemiring& s,
182  const algebra::RationalNumber& r);
183 
184  inline void op_in_star(const algebra::NumericalSemiring& s,
185  algebra::RationalNumber& r);
186 
187  inline
188  bool
189  op_can_choose_non_starable(const algebra::NumericalSemiring& set,
190  SELECTOR(algebra::RationalNumber));
191 
192  inline
193  Element<algebra::NumericalSemiring, algebra::RationalNumber>
194  op_choose_starable(const algebra::NumericalSemiring& set,
195  SELECTOR(algebra::RationalNumber));
196 
197  inline
198  Element<algebra::NumericalSemiring, algebra::RationalNumber>
199  op_choose_non_starable(const algebra::NumericalSemiring& set,
200  SELECTOR(algebra::RationalNumber));
201 
202  } // algebra
203 
204  template <typename T>
205  struct semiring_traits<algebra::NumericalSemiring, T>
206  {
207  enum { is_positive = 0 };
208  };
209 
210  template <>
211  struct semiring_traits<algebra::NumericalSemiring, bool>
212  {
213  enum { is_positive = 1 };
214  };
215 
216 } // vcsn
217 
218 
219 # if !defined VCSN_USE_INTERFACE_ONLY || defined VCSN_USE_LIB
220 # include <vaucanson/algebra/implementation/semiring/numerical_semiring.hxx>
221 #endif // VCSN_USE_INTERFACE_ONLY
222 
223 
224 #endif // ! VCSN_ALGEBRA_IMPLEMENTATION_SEMIRING_NUMERICAL_SEMIRING_HH