quater.h
4.97 KB
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
// -*- mode:C++ ; compile-command: "g++ -I.. -I../include -g -c quater.cc" -*-
/*
* Copyright (C) 2001,2014 B. Parisse, Institut Fourier, 38402 St Martin d'Heres
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _GIAC_QUATER_H
#define _GIAC_QUATER_H
#include "first.h"
#include "gen.h"
#include <string>
#ifndef NO_NAMESPACE_GIAC
namespace giac {
#endif // ndef NO_NAMESPACE_GIAC
extern const unary_function_ptr * const at_quaternion; // user-level quaternion constructor
#ifndef NO_RTTI
class quaternion : public gen_user {
public:
gen r,i,j,k;
virtual gen_user * memory_alloc() const {
quaternion * ptr= new quaternion(*this);
return dynamic_cast<gen_user *>(ptr);
}
quaternion(const quaternion & q):r(q.r),i(q.i),j(q.j),k(q.k){};
quaternion(const gen & myr,const gen & myi,const gen & myj,const gen & myk):r(myr),i(myi),j(myj),k(myk) {};
quaternion():r(zero),i(zero),j(zero),k(zero) {};
quaternion(const gen & g);
virtual gen operator + (const gen & g) const {
quaternion q(g);
return quaternion(r+q.r,i+q.i,j+q.j,k+q.k);
}
virtual gen operator - (const gen & g) const {
quaternion q(g);
return quaternion(r-q.r,i-q.i,j-q.j,k-q.k);
}
virtual std::string print (GIAC_CONTEXT) const ;
};
gen _quaternion(const gen & args,GIAC_CONTEXT);
class galois_field : public gen_user {
public:
gen p; // F_p^m, characteristic of the field
gen P; // minimal irreducible polynomial of degree m, as vector
gen x; // the name of the variable for construction
gen a; // value as a vector polynomial or undef (whole field)
virtual gen_user * memory_alloc() const {
galois_field * ptr= new galois_field(*this,false);
// if (a != smod(a,p) && smod(a,p)) CERR << "not reduced" << endl;
return ptr;
}
galois_field(const galois_field & q,bool doreduce=true);
galois_field(const gen p_,const gen & P_,const gen & x_,const gen & a_,bool doreduce=true);
galois_field(const gen & g,bool primitive,GIAC_CONTEXT);
void reduce(); // reduce a
virtual gen operator + (const gen & g) const;
virtual gen operator - (const gen & g) const;
virtual gen operator - () const;
virtual gen operator * (const gen & g) const;
virtual gen operator / (const gen & g) const;
virtual gen inv () const ;
virtual std::string print (GIAC_CONTEXT) const ;
virtual std::string texprint (GIAC_CONTEXT) const ;
virtual bool operator == (const gen &) const ;
virtual bool is_zero() const;
virtual bool is_one() const;
virtual bool is_minus_one() const;
virtual gen operator () (const gen &,GIAC_CONTEXT) const;
virtual gen operator [] (const gen &) ;
virtual gen operator > (const gen & g) const;
virtual gen operator < (const gen & g) const;
virtual gen operator >= (const gen & g) const;
virtual gen operator <= (const gen & g) const;
virtual gen gcd (const gen &) const { return plus_one;}
virtual gen gcd (const gen_user & a) const { return plus_one; }
virtual gen polygcd (const polynome &,const polynome &,polynome &) const ;
virtual gen makegen(int i) const ;
virtual gen polyfactor (const polynome & p,factorization & f) const ;
virtual gen conj(GIAC_CONTEXT) const { return *this;}
virtual gen re(GIAC_CONTEXT) const { return *this;}
virtual gen im(GIAC_CONTEXT) const { return 0;}
virtual gen sqrt(GIAC_CONTEXT) const;
virtual gen rand(GIAC_CONTEXT) const;
polynome poly_reduce(const polynome & p) const ;
};
// Is the polynomial v irreducible and primitive modulo p?
// If it is only irreducible, returns 2 and sets vmin
int is_irreducible_primitive(const vecteur & v,const gen & p,vecteur & vmin,bool primitive,GIAC_CONTEXT);
vecteur find_irreducible_primitive(int p,int m,bool primitive,GIAC_CONTEXT);
gen _galois_field(const gen & args,GIAC_CONTEXT);
struct gen_context_t {
gen g;
context * ptr ;
};
// All Galois field in a map[p^m]=generator of GF(p,m)
// the generator might be replaced by some polynomial of a GF(p,m*m2)
// if a binary operation on two elements of different GF(p,.) happens
typedef std::map<gen,gen_context_t,comparegen > gfmap;
gfmap & gf_list();
int gfsize(const gen & P);
bool has_gf_coeff(const gen & e,gen & p, gen & pmin);
#endif // NO_RTTI
#ifndef NO_NAMESPACE_GIAC
} // namespace giac
#endif // ndef NO_NAMESPACE_GIAC
#endif // _GIAC_QUATER_H