Vaucanson  1.4.1
implementation/semiring/cyclic_semiring.hh
1 // cyclic_semiring.hh: this file is part of the Vaucanson project.
2 //
3 // Vaucanson, a generic library for finite state machines.
4 //
5 // Copyright (C) 2001, 2002, 2003, 2004, 2005, 2007, 2011 The Vaucanson Group.
6 //
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License
9 // as published by the Free Software Foundation; either version 2
10 // of the License, or (at your option) any later version.
11 //
12 // The complete GNU General Public Licence Notice can be found as the
13 // `COPYING' file in the root directory.
14 //
15 // The Vaucanson Group consists of people listed in the `AUTHORS' file.
16 //
17 #ifndef VCSN_ALGEBRA_IMPLEMENTATION_SEMIRING_CYCLIC_SEMIRING_HH
18 # define VCSN_ALGEBRA_IMPLEMENTATION_SEMIRING_CYCLIC_SEMIRING_HH
19 
20 # include <vaucanson/algebra/concept/cyclic_semiring.hh>
21 
22 namespace vcsn {
23 
24  namespace algebra {
25 
26  // We provide a generic implementation of cyclic semirings
27  // formed with C++-builtins and standard operations (+, *, %).
28 
29  /*---------------.
30  | Identity value |
31  `---------------*/
32  template<unsigned int n, typename T>
33  T identity_value(SELECTOR(algebra::CyclicSemiring<n>),
34  SELECTOR(T));
35 
36  template<unsigned int n, typename T>
37  bool show_identity_value(SELECTOR(algebra::CyclicSemiring<n>),
38  SELECTOR(T));
39 
40  template<unsigned int n, typename T>
41  bool
42  is_positive_semiring(SELECTOR(algebra::CyclicSemiring<n>), SELECTOR(T));
43 
44  template<unsigned int n, typename T>
45  T zero_value(SELECTOR(algebra::CyclicSemiring<n>),
46  SELECTOR(T));
47 
48  template<unsigned int n, typename T>
49  T zero_value(SELECTOR(algebra::CyclicSemiring<n>),
50  SELECTOR(T));
51 
52  /*------------.
53  | op_contains |
54  `------------*/
55  template<unsigned int n, typename T>
56  bool op_contains(const algebra::CyclicSemiring<n>& s, T c);
57 
58  /*---------------.
59  | Multiplication |
60  `---------------*/
61  template<unsigned int n, typename T, typename U>
62  void op_in_mul(const algebra::CyclicSemiring<n>& s1,
63  T& dst, U arg);
64 
65  template<unsigned int n, typename T, typename U>
66  T op_mul(const algebra::CyclicSemiring<n>& s, T a, U b);
67 
68  /*-----------------------.
69  | Mutiplication for Z/2Z |
70  `-----------------------*/
71 
72  template<>
73  void op_in_mul<2, bool, bool>(const algebra::CyclicSemiring<2>&,
74  bool& dst, bool arg);
75 
76  template<>
77  bool op_mul<2, bool, bool>(const algebra::CyclicSemiring<2>&, bool a, bool b);
78 
79  /*---------.
80  | Addition |
81  `---------*/
82  template<unsigned int n, typename T, typename U>
83  void op_in_add(const algebra::CyclicSemiring<n>& s1,
84  T& dst, U arg);
85 
86  template<unsigned int n, typename T, typename U>
87  T op_add(const algebra::CyclicSemiring<n>& s,
88  T a, U b);
89 
90  /*------------------.
91  | Addition for Z/2Z |
92  `------------------*/
93 
94  template<>
95  void op_in_add<2, bool, bool>(const algebra::CyclicSemiring<2>&,
96  bool& dst, bool arg);
97 
98  template<>
99  bool op_add<2, bool, bool>(const algebra::CyclicSemiring<2>&, bool a, bool b);
100 
101  /*---------.
102  | Division |
103  `---------*/
104 
105  template<unsigned int n, typename T, typename U>
106  void op_in_div(const algebra::CyclicSemiring<n>& s1,
107  T& dst, U arg);
108 
109  template<unsigned int n, typename T, typename U>
110  T op_div(const algebra::CyclicSemiring<n>& s, T a, U b);
111 
112  /*------------------.
113  | Division for Z/2Z |
114  `------------------*/
115 
116  template<>
117  void op_in_div<2, bool, bool> (const algebra::CyclicSemiring<2>& s1,
118  bool& dst, bool arg);
119 
120  template<>
121  bool op_div<2, bool, bool> (const algebra::CyclicSemiring<2>& s, bool a, bool b);
122 
123  /*-------------.
124  | Substraction |
125  `-------------*/
126 
127  template<unsigned int n, typename T, typename U>
128  void op_in_sub(const algebra::CyclicSemiring<n>& s1,
129  T& dst, U arg);
130 
131  template<unsigned int n, typename T, typename U>
132  T op_sub(const algebra::CyclicSemiring<n>& s,
133  T a, U b);
134 
135  /*----------------------.
136  | Substraction for Z/2Z |
137  `----------------------*/
138 
139  template<>
140  void op_in_sub<2, bool, bool> (const algebra::CyclicSemiring<2>& s1,
141  bool& dst, bool arg);
142 
143  template<>
144  bool op_sub(const algebra::CyclicSemiring<2>& s,
145  bool a, bool b);
146 
147  /*-----.
148  | Star |
149  `-----*/
150  template <unsigned int n, typename T>
151  bool
152  op_starable(const algebra::CyclicSemiring<n>&, T b);
153 
154  template <unsigned int n, class T>
155  void
156  op_in_star(const algebra::CyclicSemiring<n>& s, T& b);
157 
158  template <unsigned int n, class T>
159  Element<algebra::CyclicSemiring<n>, T>
160  op_choose(const algebra::CyclicSemiring<n>& set, SELECTOR(T));
161 
162  template <unsigned int n, typename T>
163  bool
164  op_can_choose_non_starable(const algebra::CyclicSemiring<n>&
165  set, SELECTOR(T));
166 
167  template <unsigned int n, typename T>
168  Element<algebra::CyclicSemiring<n>, T>
169  op_choose_starable(const algebra::CyclicSemiring<n>& set,
170  SELECTOR(T));
171 
172  template <unsigned int n, typename T>
173  Element<algebra::CyclicSemiring<n>, T>
174  op_choose_non_starable(const algebra::CyclicSemiring<n>& set,
175  SELECTOR(T));
176 
177  /*---------------.
178  | Pretty printer |
179  `---------------*/
180  template<unsigned int n, typename St, typename T>
181  St& op_rout(const algebra::CyclicSemiring<n>& s,
182  St& st, const T& v);
183 
184  } // algebra
185 
186 } // vcsn
187 
188 
189 # if !defined VCSN_USE_INTERFACE_ONLY || defined VCSN_USE_LIB
190 # include <vaucanson/algebra/implementation/semiring/cyclic_semiring.hxx>
191 # endif // VCSN_USE_INTERFACE_ONLY
192 
193 
194 #endif // ! VCSN_ALGEBRA_IMPLEMENTATION_SEMIRING_CYCLIC_SEMIRING_HH