-
Notifications
You must be signed in to change notification settings - Fork 7
/
hcp.h
79 lines (64 loc) · 2.47 KB
/
hcp.h
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
/*
* File: hcp.h
* Author: gadial
*
* Created on December 3, 2009, 11:50 AM
*/
#ifndef _HCP_H
#define _HCP_H
#include <map>
#include <string>
#include <gmpxx.h>
#include <vector>
#include <iostream>
#include "zp_int.h"
using std::map;
using std::string;
using std::vector;
using std::ostream;
typedef vector<zp_int> NumberArray;
class ModularPolynomial{
public:
ModularPolynomial():modulus(0),degree(-1){};
ModularPolynomial(string, mpz_class);
ModularPolynomial(const ModularPolynomial&);
ModularPolynomial(const NumberArray&, mpz_class);
static ModularPolynomial build_from_roots(const NumberArray& roots, mpz_class p);
static ModularPolynomial build_hcp_from_discriminant(int D, mpz_class p);
string to_string() const;
ModularPolynomial& operator=(const ModularPolynomial&);
ModularPolynomial& operator+=(const ModularPolynomial&);
ModularPolynomial& operator-=(const ModularPolynomial&);
ModularPolynomial& operator*=(const ModularPolynomial&);
ModularPolynomial& operator/=(const ModularPolynomial&);
ModularPolynomial modular_exponent(mpz_class exp, const ModularPolynomial& mod) const;
zp_int operator()(zp_int a) const;
ModularPolynomial operator%(const ModularPolynomial& lhs);
bool operator==(const ModularPolynomial&) const;
ModularPolynomial& normalize();
bool is_zero() const;
NumberArray find_roots();
zp_int find_one_root();
int get_degree(){return degree;}
mpz_class get_modulus(){return modulus;}
void full_print(ostream&);
private:
mutable map<int,zp_int> coefficients; //mutable since otherwise we get const-correctness problem (seems like mpz_class is not very const-correct)
mpz_class modulus;
int degree;
void divide(ModularPolynomial lhs, ModularPolynomial& Q,ModularPolynomial& R);
};
ModularPolynomial operator+(const ModularPolynomial& rhs, const ModularPolynomial& lhs);
ModularPolynomial operator-(const ModularPolynomial& rhs, const ModularPolynomial& lhs);
ModularPolynomial operator*(const ModularPolynomial& rhs, const ModularPolynomial& lhs);
ModularPolynomial operator/(const ModularPolynomial& rhs, const ModularPolynomial& lhs);
ModularPolynomial gcd(const ModularPolynomial& rhs, const ModularPolynomial& lhs);
ostream& operator<<(ostream& o, const ModularPolynomial& lhs);
ostream& operator<<(ostream& o, const NumberArray lhs);
class HCP{ //Hilbert class polynomials
public:
HCP();
map<int, string> H;
int degree(int D);
};
#endif /* _HCP_H */