The ChainCon Software (Release 0.03)
euclwrap.h
Go to the documentation of this file.
1 /////////////////////////////////////////////////////////////////////////////
2 ///
3 /// \file
4 ///
5 /// A wrapper of a generic coefficient type for the CHomP library.
6 ///
7 /////////////////////////////////////////////////////////////////////////////
8 
9 // Copyright (C) 2009-2016 by Pawel Pilarczyk.
10 //
11 // This file is part of my research software package. This is free software:
12 // you can redistribute it and/or modify it under the terms of the GNU
13 // General Public License as published by the Free Software Foundation,
14 // either version 3 of the License, or (at your option) any later version.
15 //
16 // This software is distributed in the hope that it will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 // GNU General Public License for more details.
20 //
21 // You should have received a copy of the GNU General Public License
22 // along with this software; see the file "license.txt". If not,
23 // please, see <http://www.gnu.org/licenses/>.
24 
25 // Started on March 24, 2009. Last revision: June 20, 2012.
26 
27 
28 #ifndef _CHAINCON_EUCLWRAP_H_
29 #define _CHAINCON_EUCLWRAP_H_
30 
31 
32 // include some standard C++ header files
33 #include <istream>
34 #include <ostream>
35 #include <algorithm>
36 #include <vector>
37 
38 // include selected header files from the CHomP library
39 #include "chomp/system/config.h"
40 
41 
42 // --------------------------------------------------
43 // ----------- a wrapper for coefficients -----------
44 // --------------------------------------------------
45 
46 /// A wrapper of coefficients as defined in this sofware package
47 /// for what is required by CHomP.
48 template <class CoefT>
49 class tEuclWrap
50 {
51 public:
52  /// The default constructor of an undefined element.
53  tEuclWrap ();
54 
55  /// Constructor from a coefficient element.
56  explicit tEuclWrap (const CoefT &element);
57 
58  /// Extraction of the actual coefficient inside.
59  const CoefT &getCoef () const;
60 
61  /// Assignment of an integer number.
63 
64  /// Computes the delta function for the element.
65  int delta (void) const;
66 
67  /// Returns a normalized number (does nothing here).
69 
70  /// The negation operator.
72 
73  /// The addition operator.
75 
76  /// The multiplication operator.
78 
79  /// The addition operator that returns the result separately.
81 
82  /// The multiplication operator that returns the result separately.
84 
85  /// The division with remainder operator.
87 
88  /// The remainder operator.
90 
91  /// The equality operator.
92  int operator == (const tEuclWrap<CoefT> &n) const;
93 
94  /// Returns the name of the ring (returns its symbol here).
95  static const char *ringname ();
96 
97  /// Returns the symbol of the ring.
98  static const char *ringsymbol ();
99 
100 private:
101  /// An element of the coefficient type.
102  CoefT e;
103 
104 }; /* class tEuclWrap */
105 
106 // --------------------------------------------------
107 
108 template <class CoefT>
110 {
111  return;
112 } /* tEuclWrap::tEuclWrap */
113 
114 template <class CoefT>
115 inline tEuclWrap<CoefT>::tEuclWrap (const CoefT &element): e (element)
116 {
117  return;
118 } /* tEuclWrap::tEuclWrap */
119 
120 template <class CoefT>
121 inline const CoefT &tEuclWrap<CoefT>::getCoef () const
122 {
123  return e;
124 } /* tEuclWrap::getCoef */
125 
126 template <class CoefT>
128 {
129  e = CoefT (n);
130  return *this;
131 } /* tEuclWrap::operator = */
132 
133 template <class CoefT>
134 inline int tEuclWrap<CoefT>::delta (void) const
135 {
136  return e. delta ();
137 } /* tEuclWrap::delta */
138 
139 template <class CoefT>
141 {
142  return *this;
143 } /* tEuclWrap::normalized */
144 
145 template <class CoefT>
147 {
148  CoefT n (e);
149  n. negate ();
150  return tEuclWrap<CoefT> (n);
151 } /* tEuclWrap::operator - */
152 
153 template <class CoefT>
155  (const tEuclWrap<CoefT> &n)
156 {
157  e += n. e;
158  return *this;
159 } /* tEuclWrap::operator += */
160 
161 template <class CoefT>
162 inline tEuclWrap<CoefT> &tEuclWrap<CoefT>::operator *=
163  (const tEuclWrap<CoefT> &n)
164 {
165  e *= n. e;
166  return *this;
167 } /* tEuclWrap::operator *= */
168 
169 template <class CoefT>
170 inline tEuclWrap<CoefT> tEuclWrap<CoefT>::operator +
171  (const tEuclWrap<CoefT> &n) const
172 {
173  CoefT m (e);
174  m += n. e;
175  return tEuclWrap<CoefT> (m);
176 } /* tEuclWrap::operator + */
177 
178 template <class CoefT>
179 inline tEuclWrap<CoefT> tEuclWrap<CoefT>::operator *
180  (const tEuclWrap<CoefT> &n) const
181 {
182  CoefT m (e);
183  m *= n. e;
184  return tEuclWrap<CoefT> (m);
185 } /* tEuclWrap::operator * */
186 
187 template <class CoefT>
188 inline tEuclWrap<CoefT> tEuclWrap<CoefT>::operator /
189  (const tEuclWrap<CoefT> &n) const
190 {
191  CoefT q, r;
192  divide (e, n. e, q, r);
193  return tEuclWrap<CoefT> (q);
194 } /* tEuclWrap::operator / */
195 
196 template <class CoefT>
197 inline tEuclWrap<CoefT> tEuclWrap<CoefT>::operator %
198  (const tEuclWrap<CoefT> &n) const
199 {
200  CoefT q, r;
201  divide (e, n. e, q, r);
202  return tEuclWrap<CoefT> (r);
203 } /* tEuclWrap::operator % */
204 
205 template <class CoefT>
207 {
208  return (e == n. e);
209 } /* tEuclWrap::operator == */
210 
211 template <class CoefT>
212 inline const char *tEuclWrap<CoefT>::ringname ()
213 {
214  return CoefT::ringsymbol (). c_str ();
215 } /* tEuclWrap::ringname */
216 
217 template <class CoefT>
218 inline const char *tEuclWrap<CoefT>::ringsymbol ()
219 {
220  return CoefT::ringsymbol (). c_str ();
221 } /* tEuclWrap::ringsymbol */
222 
223 // --------------------------------------------------
224 
225 template <class CoefT>
226 inline bool operator != (const tEuclWrap<CoefT> &n,
227  const tEuclWrap<CoefT> &m)
228 {
229  return (!(n == m));
230 } /* operator != */
231 
232 template <class CoefT>
233 inline bool operator == (const tEuclWrap<CoefT> &n, int m)
234 {
235  tEuclWrap<CoefT> intm;
236  intm = m;
237  return (n == intm);
238 } /* operator == */
239 
240 template <class CoefT>
241 inline int operator != (const tEuclWrap<CoefT> &n, int m)
242 {
243  return !(n == m);
244 } /* operator != */
245 
246 template <class CoefT>
248  const tEuclWrap<CoefT> &m)
249 {
250  return (n + -m);
251 } /* operator - */
252 
253 // --------------------------------------------------
254 
255 template <class CoefT>
256 inline std::istream &operator >> (std::istream &in,
257  tEuclWrap<CoefT> &n)
258 {
259  CoefT element;
260  in >> element;
261  n = tEuclWrap<CoefT> (element);
262  return in;
263 } /* operator >> */
264 
265 /// Writing an element to an output stream.
266 template <class CoefT>
267 inline std::ostream &operator << (std::ostream &out,
268  const tEuclWrap<CoefT> &n)
269 {
270  out << n. getCoef ();
271  return out;
272 } /* operator << */
273 
274 
275 #endif // _CHAINCON_EUCLWRAP_H_
276 
CoefT e
An element of the coefficient type.
Definition: euclwrap.h:102
const CoefT & getCoef() const
Extraction of the actual coefficient inside.
Definition: euclwrap.h:121
tEuclWrap< CoefT > & operator=(int n)
Assignment of an integer number.
Definition: euclwrap.h:127
tEuclWrap< CoefT > & operator+=(const tEuclWrap< CoefT > &n)
The addition operator.
Definition: euclwrap.h:155
A wrapper of coefficients as defined in this sofware package for what is required by CHomP...
Definition: euclwrap.h:49
tEuclWrap()
The default constructor of an undefined element.
Definition: euclwrap.h:109
tEuclWrap< CoefT > operator-() const
The negation operator.
Definition: euclwrap.h:146
static const char * ringname()
Returns the name of the ring (returns its symbol here).
Definition: euclwrap.h:212
tEuclWrap< CoefT > & operator*=(const tEuclWrap< CoefT > &n)
The multiplication operator.
Definition: euclwrap.h:163
tEuclWrap< CoefT > operator+(const tEuclWrap< CoefT > &n) const
The addition operator that returns the result separately.
Definition: euclwrap.h:171
bool divide(const tZp< intType > &a, const tZp< intType > &b, tZp< intType > &quotient, tZp< intType > &remainder)
Definition: ringzp.h:182
int delta(void) const
Computes the delta function for the element.
Definition: euclwrap.h:134
int operator==(const tEuclWrap< CoefT > &n) const
The equality operator.
Definition: euclwrap.h:206
std::ostream & operator<<(std::ostream &out, const tEuclWrap< CoefT > &n)
Writing an element to an output stream.
Definition: euclwrap.h:267
tEuclWrap< CoefT > operator%(const tEuclWrap< CoefT > &n) const
The remainder operator.
Definition: euclwrap.h:198
static const char * ringsymbol()
Returns the symbol of the ring.
Definition: euclwrap.h:218
tEuclWrap< CoefT > operator*(const tEuclWrap< CoefT > &n) const
The multiplication operator that returns the result separately.
Definition: euclwrap.h:180
bool operator!=(const tEuclWrap< CoefT > &n, const tEuclWrap< CoefT > &m)
Definition: euclwrap.h:226
tEuclWrap< CoefT > operator/(const tEuclWrap< CoefT > &n) const
The division with remainder operator.
Definition: euclwrap.h:189
std::istream & operator>>(std::istream &in, tEuclWrap< CoefT > &n)
Definition: euclwrap.h:256
tEuclWrap< CoefT > normalized() const
Returns a normalized number (does nothing here).
Definition: euclwrap.h:140