/usr/include/givaro/givgfq.h is in libgivaro-dev 3.2.13-1.2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | #ifndef _GIVARO_GFQ1_H_
#define _GIVARO_GFQ1_H_
// ==========================================================================
// file: givgfq.h
// Time-stamp: <22 Apr 08 17:24:36 Jean-Guillaume.Dumas@imag.fr>
// (c) Givaro Team
// date: 1999
// version:
// author: Jean-Guillaume.Dumas
// Description:
// Arithmetic on GF(p^k), with p a prime number less than 2^15
// ==========================================================================
#include "givaro/givconfig.h"
#include "givaro/givinteger.h"
#include <iostream>
#include <vector>
#include "givaro/giv_randiter.h"
#include "givaro/givpoly1factor.h"
// ------------------------------------------------- class GFqDom
template<class TT> class GFqDom {
protected:
typedef typename Signed_Trait<TT>::unsigned_type UTT;
typedef TT Rep;
public:
Rep zero;
Rep one;
protected:
UTT _characteristic; // Field Characteristic (p)
UTT _exponent; // Extension degree (k)
UTT _irred; // Irreducible polynomial in p-adic
UTT _q; // p^k
UTT _qm1; // p^k-1
UTT _qm1o2; // (p^k-1)/2
// G is a generator of GF(q)
// p is GF(q)'s characteristic
// log2pol[ i ] = G^i(p)
// pol2log[ j ] = i such that log2pol[i] = j
// plus1[i] = k such that G^i + 1 = G^k
std::vector<UTT> _log2pol;
std::vector<UTT> _pol2log;
std::vector<TT> _plus1;
// Floating point representations
double _dcharacteristic;
public:
typedef GFqDom<TT> Self_t;
typedef Rep Element;
// class Element {
// public:
// mutable Rep _value;
// Element() {}
// };
typedef UTT Residu_t;
// ----- Representation of vector of the Element
typedef Rep* Array;
typedef const Rep* constArray;
GFqDom(): zero(0), _log2pol(0), _pol2log(0),_plus1(0) {}
GFqDom( const UTT P, const UTT e = 1);
GFqDom( const UTT P, const UTT e, const std::vector<UTT>& modPoly);
GFqDom( const GFqDom<TT>& F)
{
zero = F.zero;
one = F.one;
_characteristic = F._characteristic;
_dcharacteristic = F._dcharacteristic;
_exponent = F._exponent;
_irred = F._irred;
_q = F._q;
_qm1 = F._qm1;
_qm1o2 = F._qm1o2;
_log2pol = F._log2pol;
_pol2log = F._pol2log;
_plus1 = F._plus1;
}
// Allows to choose the randomization
// and therefore the field generator
// template<class RandIter >
// GFqDom(RandIter& g, const UTT P, const UTT e = 1);
~GFqDom() {};
GFqDom<TT> operator=( const GFqDom<TT>& F)
{
this->zero = F.zero;
this->one = F.one;
this->_characteristic = F._characteristic;
this->_dcharacteristic = F._dcharacteristic;
this->_exponent = F._exponent;
this->_irred = F._irred;
this->_q = F._q;
this->_qm1 = F._qm1;
this->_qm1o2 = F._qm1o2;
this->_log2pol = F._log2pol;
this->_pol2log = F._pol2log;
this->_plus1 = F._plus1;
return *this;
}
// Access to the modulus, characteristic, size, exponent
UTT residu() const;
UTT characteristic() const;
Integer& characteristic(Integer& p) const{return p=characteristic();}
UTT cardinality() const;
UTT size() const;
UTT exponent() const;
// Internal representation of the used generator
Rep& generator(Rep&) const;
// p-adic representation of the used generator
UTT generator() const;
// an integer representation of the polynomial
// where the indeterminate is replaced by the characteristic
// This has no meaning if exponent is 1
UTT sage_generator() const;
UTT irreducible() const;
// Initialization of Elements
Rep& init( Rep&) const;
Rep& init( Rep&, const int) const ;
Rep& init( Rep&, const unsigned int) const ;
Rep& init( Rep&, const long) const ;
Rep& init( Rep&, const unsigned long) const ;
Rep& init( Rep&, const Integer) const;
Rep& init( Rep&, const float) const ;
Rep& init( Rep&, const double) const ;
#ifndef __GIVARO__DONOTUSE_longlong__
Rep& init( Rep&, const long long) const;
Rep& init( Rep&, const unsigned long long) const ;
#endif
Rep& init( Rep& a, std::istream& s ) const { return read(a,s); }
// Initialization of a polynomial
template<typename val_t, template<class,class> class Vector,template <class> class Alloc>
Rep& init( Rep&, const Vector<val_t,Alloc<val_t> >&);
// -- Misc: r <- a mod p
Rep& assign (Rep&, const Integer) const;
Rep& assign (Rep&, const Rep) const;
void assign ( const size_t sz, Array r, constArray a ) const;
// --- IO methods for the Domain
std::istream& read ( std::istream& s );
std::ostream& write( std::ostream& s ) const;
// --- IO methods for the Elements
std::istream& read ( std::istream& s, Rep& a ) const;
std::ostream& write( std::ostream& s, const Rep a ) const;
// Conversions of the elements
std::ostream& convert(std::ostream& s, const Rep a ) const { return write(s,a); }
TT convert(const Rep) const ;
long& convert(long&, const Rep) const ;
unsigned long& convert(unsigned long&, const Rep) const ;
int& convert(int&, const Rep) const ;
float& convert(float&, const Rep) const ;
double& convert(double&, const Rep) const ;
unsigned int& convert(unsigned int&, const Rep) const ;
Integer& convert(Integer&, const Rep) const ;
#ifndef __GIVARO__DONOTUSE_longlong__
long long& convert(long long&, const Rep) const ;
unsigned long long& convert(unsigned long long&, const Rep) const ;
#endif
// Test operators
inline int operator== (const GFqDom<TT>& a) const;
inline int operator!= (const GFqDom<TT>& a) const;
// Miscellaneous functions
bool areEqual( const Rep&, const Rep& ) const;
bool areNEqual ( const Rep , const Rep ) const;
bool isZero( const Rep ) const;
bool isnzero( const Rep ) const;
bool isOne ( const Rep ) const;
bool isunit ( const Rep ) const; // Element belongs to prime subfield
size_t length ( const Rep ) const;
// ----- Operations with reduction: r <- a op b mod p, r <- op a mod p
Rep& mul (Rep& r, const Rep a, const Rep b) const;
Rep& div (Rep& r, const Rep a, const Rep b) const;
Rep& add (Rep& r, const Rep a, const Rep b) const;
Rep& sub (Rep& r, const Rep a, const Rep b) const;
Rep& neg (Rep& r, const Rep a) const;
Rep& inv (Rep& r, const Rep a) const;
Rep& mulin (Rep& r, const Rep a) const;
Rep& divin (Rep& r, const Rep a) const;
Rep& addin (Rep& r, const Rep a) const;
Rep& subin (Rep& r, const Rep a) const;
Rep& negin (Rep& r) const;
Rep& invin (Rep& r) const;
// ----- Operations with reduction: r <- a op b mod p, r <- op a mod p
void mul (const size_t sz, Array r, constArray a, constArray b) const;
void mul (const size_t sz, Array r, constArray a, Rep b) const;
void div (const size_t sz, Array r, constArray a, constArray b) const;
void div (const size_t sz, Array r, constArray a, Rep b) const;
void add (const size_t sz, Array r, constArray a, constArray b) const;
void add (const size_t sz, Array r, constArray a, Rep b) const;
void sub (const size_t sz, Array r, constArray a, constArray b) const;
void sub (const size_t sz, Array r, constArray a, Rep b) const;
void neg (const size_t sz, Array r, constArray a) const;
void inv (const size_t sz, Array r, constArray a) const;
Rep& axpy (Rep& r, const Rep a, const Rep b, const Rep c) const;
void axpy (const size_t sz, Array r, Rep a, constArray x, constArray y) const;
void axpy (const size_t sz, Array r, Rep a, constArray x, Rep c) const;
// -- axpyin: r <- r + a * x mod p
Rep& axpyin (Rep& r, const Rep a, const Rep b) const;
void axpyin (const size_t sz, Array r, Rep a, constArray x) const;
// -- axmy: r <- a * x - y mod p
Rep& axmy (Rep& r, const Rep a, const Rep b, const Rep c) const;
void axmy (const size_t sz, Array r, Rep a, constArray x, constArray y) const;
void axmy (const size_t sz, Array r, Rep a, constArray x, Rep c) const;
// -- amxy: r <- c - a * b mod p
Rep& amxy (Rep& r, const Rep a, const Rep b, const Rep c) const;
// -- axmyin: r <- r - a * b mod p
Rep& axmyin (Rep& r, const Rep a, const Rep b) const;
void axmyin (const size_t sz, Array r, Rep a, constArray x) const;
// // -- sqpyin: r <- r + a * a mod p
// Rep& sqpyin (Rep& r, const Rep a) const;
// -- axpyin: r <- r - a * b mod p
Rep& amxyin (Rep& r, const Rep a, const Rep b) const;
// <- \sum_i a[i], return 1 if a.size() ==0,
void reduceadd ( Rep& r, const size_t sz, constArray a ) const;
// <- \prod_i a[i], return 1 if a.size() ==0,
void reducemul ( Rep& r, const size_t sz, constArray a ) const;
// <- \sum_i a[i] * b[i]
Rep& dotprod ( Rep& r, const size_t sz, constArray a, constArray b ) const;
// ----- random generators
// ----- random generators
template<class RandIter> Rep& random(RandIter& g, Rep& r) const ;
template<class RandIter> Rep& random(RandIter& g, Rep& r, long s) const ;
template<class RandIter> Rep& random(RandIter& g, Rep& r, const Rep& b) const ;
template<class RandIter> Rep& nonzerorandom(RandIter& g, Rep& r) const ;
template<class RandIter> Rep& nonzerorandom(RandIter& g, Rep& r, long s) const ;
template<class RandIter> Rep& nonzerorandom(RandIter& g, Rep& r, const Rep& b) const ;
typedef GIV_randIter< GFqDom<TT> , Rep> randIter;
// // - Set to a non zero random value
// void set_nrand(Rep&) const;
// // - Set to a random value
// void set_rand(Rep&) const;
#ifdef __GIVARO_COUNT__
void clear() {
_add_count = 0;
_mul_count = 0;
_neg_count = 0;
_div_count = 0;
_sub_count = 0;
_inv_count = 0;
_add_call = 0;
_mul_call = 0;
_neg_call = 0;
_div_call = 0;
_sub_call = 0;
_inv_call = 0;
}
void info() const {
cerr << "Mul Call: " << _mul_call << ", real: " << _mul_count << endl;
cerr << "Add Call: " << _add_call << ", real: " << _add_count << endl;
cerr << "Div Call: " << _div_call << ", real: " << _div_count << endl;
cerr << "Sub Call: " << _sub_call << ", real: " << _sub_count << endl;
cerr << "Neg Call: " << _neg_call << ", real: " << _neg_count << endl;
cerr << "Inv Call: " << _inv_call << ", real: " << _inv_count << endl;
}
#endif
#ifdef __GIVARO_COUNT__
static long long _add_count;
static long long _mul_count;
static long long _neg_count;
static long long _div_count;
static long long _sub_count;
static long long _inv_count;
static long long _add_call;
static long long _mul_call;
static long long _neg_call;
static long long _div_call;
static long long _sub_call;
static long long _inv_call;
#endif
static void Init();
static void End();
};
#include "givaro/givgfq.inl"
#endif
|