-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCoefficientTraits.hpp
105 lines (88 loc) · 2.18 KB
/
CoefficientTraits.hpp
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
/**
* @file CoefficientTraits.hpp
*
* Tuning set of polynomial coefficient-related operations.
*
* @author Artem Pelenitsyn
* @date 2010-07-28
*/
#ifndef COEFFICIENTTRAITS_HPP_
#define COEFFICIENTTRAITS_HPP_
#include <boost/mpl/contains.hpp>
#include <boost/utility/enable_if.hpp>
#include <NTL/GF2.h>
#include <NTL/GF2E.h>
#include <NTL/ZZ_p.h>
#include <NTL/ZZ_pE.h>
#include "NtlUtilities.hpp"
namespace mv_poly {
/**
* \class CoefficientTraits
* Provide basic algebraic properties of the
* polynomial coefficients type.
*
* \note
* We suppose that coefficient set forms a field,
* so we want the type to have a way to obtain 0, 1, -a, a^{-1}.
*/
template<typename CoefT, typename Enable = void>
struct CoefficientTraits {
/**
* Obtaining multiplicative inverse in the field.
* @param c Non-zero element.
* @return \c c^{-1} (additive inverse in CoefT field).
*/
static CoefT multInverse(CoefT const & c) {
return 1 / c;
}
/**
* Obtaining multiplicative inverse in the field.
* @param c Any element of CoefT.
* @return \c -c (additive inverse in CoefT field).
*/
static CoefT addInverse(CoefT const & c) {
return -c;
}
/**
* Obtaining multiplicative identity of CoefT field.
* @return Multiplicative identity (\c 1) of CoefT field.
*/
static CoefT multId() {
return 1;
}
/**
* Obtaining additive identity of CoefT field.
* @return Additive identity (\c 1) of CoefT field.
*/
static CoefT addId() {
return CoefT();
}
};
/**
* CoefficientTraits template specialization for NTL field types
* (triggers with the boost::enable_if help).
*/
template<typename T>
struct CoefficientTraits<
T,
typename boost::enable_if<
boost::mpl::contains<NtlFieldTypes, T>
>::type > {
static T multInverse(T const & c) {
return NTL::inv(c);
}
static T addInverse(T const & c) {
return -c;
}
static T multId() {
T a;
NTL::set(a);
return a;
}
static T addId() {
T zero;
return zero;
}
};
} // namespace mv_poly
#endif /* COEFFICIENTTRAITS_HPP_ */