field.cpp
Go to the documentation of this file.
1 
12 #include "field.hpp"
13 
14 
15 using namespace arithm;
16 
17 
18 Field::Field(mpz_class aOrder) : Group(1,0)
19 {
20  addOrder = aOrder;
21 }
22 
23 
24 Field::Field(mpz_class aOrder, mpz_class mOrder, mpz_class gen) :
25  Group(mOrder,gen)
26 {
27  addOrder = aOrder;
28 }
29 
30 
31 
32 // ----------------------------------------- Additive element operations
33 
34 
35 
37 {
38  return Elmt(0,this);
39 }
40 
41 
43 {
44  return Elmt(0,this);
45 }
46 
47 
48 
49 // ------------------------------------------ Additive array operations
50 
51 
52 
54 {
55  if (e1.size() != e2.size())
56  {
57  std::cout<<"ERROR: in Field.addition(e1,e2), sizes of "
58  <<"e1 and e2 mismatch."
59  <<"\ne1.size()"<<e1.size()
60  <<"\ne2.size()"<<e2.size()<<std::endl;
61  exit(1);
62  }
63  ArrayOfElmts result;
64  for (unsigned int i=0; i<e1.size(); i++)
65  result.addElmt(addition(e1.getElmt(i),e2.getElmt(i)));
66  return result;
67 }
68 
69 
71 {
72  ArrayOfElmts result;
73  for (unsigned int i=0; i<a.size(); i++)
74  result.addElmt(addInverse(a.getElmt(i)));
75  return result;
76 }
77 
78 
80 {
81  Elmt result = getZero();
82  for (unsigned int i=0; i<a.size(); i++)
83  result = addition(result, a.getElmt(i));
84  return result;
85 }
86 
87 
88 
89 // ---------------------------------------- Obtaining field elements
90 
91 
92 
94 {
95  return Elmt(0,this);
96 }
97 
98 
100 {
101  ArrayOfElmts result;
102  for (unsigned int i=0; i<n; i++)
103  result.addElmt(getZero());
104  return result;
105 }
106 
107 
108 
109 // ----------------------------------------- Data about the field.
110 
111 
112 
114 {
115  return addOrder;
116 }
117 
118 
119 unsigned int Field::getLeafSize()
120 {
121  return ((unsigned int)mpz_sizeinbase(
122  addOrder.get_mpz_t(), 16)+1)/2;
123 }
124 
125 
126 std::string Field::getType()
127 {
128  return "Field";
129 }