17 #ifndef VCSN_ALGEBRA_IMPLEMENTATION_SEMIRING_CYCLIC_SEMIRING_HXX
18 # define VCSN_ALGEBRA_IMPLEMENTATION_SEMIRING_CYCLIC_SEMIRING_HXX
20 # include <vaucanson/algebra/implementation/semiring/cyclic_semiring.hh>
23 # include <boost/swap.hpp>
24 # include <boost/tuple/tuple.hpp>
40 boost::tuple<unsigned int, int, int>
58 return boost::tuple<unsigned int, int, int> (a, 1, 0);
74 return boost::tuple<unsigned int, int, int> (a, x2, y2);
81 template<
unsigned int n,
typename T>
87 template<
unsigned int n,
typename T>
88 bool show_identity_value(
SELECTOR(algebra::CyclicSemiring<n>),
94 template<
unsigned int n,
typename T>
101 template<
unsigned int n,
typename T>
110 template<
unsigned int n,
typename T>
111 bool op_contains(
const algebra::CyclicSemiring<n>&, T c)
119 template<
unsigned int n,
typename T,
typename U>
120 void op_in_mul(
const algebra::CyclicSemiring<n>&,
123 dst = (dst * arg) % n;
124 dst = (dst < 0) ? dst + n : dst;
127 template<
unsigned int n,
typename T,
typename U>
128 T op_mul(
const algebra::CyclicSemiring<n>&, T a, U b)
131 return ((res < 0) ? res + n : res);
139 void op_in_mul(
const algebra::CyclicSemiring<2>&,
146 bool op_mul(
const algebra::CyclicSemiring<2>&,
bool a,
bool b)
154 template<
unsigned int n,
typename T,
typename U>
155 void op_in_add(
const algebra::CyclicSemiring<n>&,
158 dst = ((dst + arg) + (2 * n)) % n;
161 template<
unsigned int n,
typename T,
typename U>
162 T op_add(
const algebra::CyclicSemiring<n>&, T a, U b)
164 return ((a + b) + (2 * n)) % n;
172 void op_in_add(
const algebra::CyclicSemiring<2>&,
179 bool op_add(
const algebra::CyclicSemiring<2>&,
bool a,
bool b)
188 template<
unsigned int n,
typename T,
typename U>
189 void op_in_div (
const algebra::CyclicSemiring<n>& s1,
192 boost::tuple<unsigned int , int, int> res =
ext_gcd (dst, arg);
193 if (res.get<0> () == 1)
195 op_in_mul (s1, dst, res.get<2> ());
199 assertion(!
"tried to divide by a number"
200 " without multiplicative inverse.");
203 template<
unsigned int n,
typename T,
typename U>
204 T op_div (
const algebra::CyclicSemiring<n>& s, T a, U b)
206 boost::tuple<unsigned int , int, int> res =
ext_gcd (a, b);
207 if (res.get<0> () == 1)
208 return (op_mul (s, a, res.get<2> ()));
210 assertion(!
"tried to divide by a number"
211 " without multiplicative inverse.");
219 void op_in_div (
const algebra::CyclicSemiring<2>& s1,
224 assertion (!
"Division by zero.");
228 bool op_div (
const algebra::CyclicSemiring<2>& s,
bool a,
bool b)
232 assertion(!
"Division by zero.");
239 template<
unsigned int n,
typename T,
typename U>
240 void op_in_sub(
const algebra::CyclicSemiring<n>& s1,
243 dst = (dst - arg) % n;
244 dst = (dst < 0) ? dst + n : dst;
247 template<
unsigned int n,
typename T,
typename U>
248 T op_sub(
const algebra::CyclicSemiring<n>& s,
252 return ((res < 0) ? res + n : res);
260 void op_in_sub(
const algebra::CyclicSemiring<2>& s1,
267 bool op_sub(
const algebra::CyclicSemiring<2>& s,
277 template <
unsigned int n,
typename T>
279 op_starable(
const algebra::CyclicSemiring<n>&, T b)
286 template <
unsigned int n,
class T>
288 op_in_star(
const algebra::CyclicSemiring<n>&, T& b)
295 assertion(!
"star not defined.");
298 template <
unsigned int n,
class T>
299 Element<algebra::CyclicSemiring<n>, T>
300 op_choose(
const algebra::CyclicSemiring<n>&
set,
SELECTOR(T))
302 return Element<algebra::CyclicSemiring<n>, T>
303 (
set, misc::random::generate<T>());
306 template <
unsigned int n,
typename T>
314 template <
unsigned int n,
class T>
315 Element<algebra::CyclicSemiring<n>, T>
321 r = op_choose(
set,
SELECT(T));
322 while (!op_starable(
set, r));
326 template <
unsigned int n,
class T>
327 Element<algebra::CyclicSemiring<n>, T>
333 r = op_choose(
set,
SELECT(T));
334 while (op_starable(
set, r));
341 template<
unsigned int n,
typename St,
typename T>
342 St&
op_rout(
const algebra::CyclicSemiring<n>&, St& st,
const T& v)
352 #endif // ! VCSN_ALGEBRA_IMPLEMENTATION_SEMIRING_CYCLIC_SEMIRING_HXX