~ubuntu-branches/ubuntu/saucy/gfan/saucy-proposed

« back to all changes in this revision

Viewing changes to field.h

  • Committer: Package Import Robot
  • Author(s): Cédric Boutillier
  • Date: 2013-07-09 10:44:01 UTC
  • mfrom: (2.1.2 experimental)
  • Revision ID: package-import@ubuntu.com-20130709104401-5q66ozz5j5af0dak
Tags: 0.5+dfsg-3
* Upload to unstable.
* modify remove_failing_tests_on_32bits.patch to replace command of
  0009RenderStairCase test with an empty one instead of deleting it.
* remove lintian override about spelling error

Show diffs side-by-side

added added

removed removed

Lines of Context:
7
7
 
8
8
#include <assert.h>
9
9
 
 
10
#include <cstdio> /* Always include cstdio before gmp.h.*/
10
11
#include <gmp.h>  //SHOULD BE REMOVED
11
12
 
 
13
/** A FieldElement is an element of a Field in the algebraic sense. A
 
14
    FieldElement always knows its associated Field to which it
 
15
    belongs.  We may perform arithmetic operations on a FieldElement
 
16
    and a FieldElement is passed around by value. Thus in C++ it makes
 
17
    no sense to derive classes from the FieldElement class. The actual
 
18
    data is contained in an object of the class
 
19
    FieldElementImplementation and the FieldElement serves as a smart
 
20
    pointer with reference counting to this implementation.
 
21
 */
12
22
class FieldElement
13
23
{
 
24
 public:
14
25
  class FieldElementImplementation *implementingObject;
15
 
 public:
16
26
  FieldElement(class FieldElementImplementation *implementingObject_);
17
27
 public:
18
28
  class FieldImplementation *getField()const;
23
33
     Would it also work for this (a+a).getField(); or could the ref count get 0 before it is increased?
24
34
  */
25
35
 
 
36
/*
 
37
 * The following two are only supported for rationals.
 
38
 */
26
39
  mpq_t const *getGmpRationalTemporaryPointer()const;
 
40
  double floatingPointApproximation()const;
 
41
  bool isInteger()const;
27
42
 
28
43
  void setImplementingObject(FieldElementImplementation *implementingObject_){implementingObject=implementingObject_;assert(0);}
29
44
 
30
45
  FieldElement one() const;
31
 
  bool isZero();
 
46
  bool isZero()const;
32
47
  virtual bool isOne()const;
33
48
  friend FieldElement operator+(const FieldElement &a,const FieldElement &b);
34
49
  friend FieldElement operator-(const FieldElement &a,const FieldElement &b);
35
50
  friend FieldElement operator-(const FieldElement &b);
36
51
  FieldElement inverse()const;
 
52
  int sign()const; // Only allowed for ordered field. Asserts otherwise.
 
53
  int pAdicValuation(int p)const; // Only allowed for the field Q.
 
54
  FieldElement pAdicRemainder(class Field const &ZModPZ)const; // Only allowed for the field Q.
 
55
  int integerRepresentative()const; // Only allowed for Z/pZ
37
56
  std::string toString(bool writeIfOne=true, bool alwaysWriteSign=false ,bool latexMode=false) const;
38
57
  void operator*=(const FieldElement &a);
 
58
  void operator+=(const FieldElement &a);
 
59
  /** Adds a*b to the value of the object. */
 
60
  void madd(const FieldElement &a, const FieldElement &b);
39
61
  friend FieldElement operator*(const FieldElement &a,const FieldElement &b);
40
62
 
41
63
  // Constructors:
42
 
  FieldElement(class Field const &f);
43
 
    
 
64
  FieldElement(class Field const &f);//Initializes to zero
 
65
 
44
66
    FieldElement()              // This constructor causes a lot of trouble
45
67
    {                         // Having a legal FieldElement without an implementing object
46
68
      implementingObject=0;   // we must check for each assignment (copy constructor/assignment operator)
47
69
    }                         // if the pointer is zero. - And some operation will be illegal on
48
70
                              // on this element ( one(),..... )
49
 
                              
 
71
 
50
72
  FieldElement(const FieldElement &a);
51
73
  FieldElement& operator=(const FieldElement& a);
52
74
  virtual ~FieldElement();
53
75
};
54
76
 
 
77
/** The Field class describes an object which has as its value a field
 
78
    (in the algebraic sense). The value/object can be copied around as
 
79
    a value. The Field object serves as a smart pointer with reference
 
80
    counting to a FieldImplementation which is hidden for the user of
 
81
    the Field class. In C++ it makes no sense to derive classes from
 
82
    this class because the object must be passable by value. */
 
83
 
55
84
class Field
56
85
{
57
86
  friend class FieldElement;
58
 
 protected:
 
87
  // protected:
 
88
 public:
59
89
  class FieldImplementation *implementingObject;
60
90
 public:
61
91
  FieldElementImplementation *zHomomorphismImplementation(int n)const;
 
92
  /**
 
93
     @return The image of the integer n under the unique ring homomorphism from the integers Z to the Field taking 1 to the multiplicative neutral element.
 
94
   */
62
95
  FieldElement zHomomorphism(int n)const;
 
96
  bool isRationals()const;
 
97
 
63
98
  const char *name();
64
99
  std::string toString()const;
65
100
 
94
129
  virtual FieldElementImplementation *inverse()const=0;
95
130
  virtual std::string toString(bool writeIfOne=true, bool alwaysWriteSign=false, bool latexMode=false) const=0;
96
131
  virtual void operator*=(const FieldElementImplementation &a)=0;
 
132
  virtual void operator+=(const FieldElementImplementation &a)=0;
 
133
  virtual void madd(const FieldElementImplementation &a,const FieldElementImplementation &b)=0;
 
134
  virtual int sign()const
 
135
  {
 
136
    assert(0);
 
137
    return 0;
 
138
  }
 
139
  virtual int pAdicValuation(int p)const
 
140
  {
 
141
    assert(0);
 
142
    return 0;
 
143
  }
 
144
  virtual FieldElement pAdicRemainder(Field const &ZModPZ)const
 
145
  {
 
146
    assert(0);
 
147
    return pAdicRemainder(ZModPZ);
 
148
  }
 
149
  virtual int integerRepresentative()const
 
150
  {
 
151
    assert(0);
 
152
    return 0;
 
153
  }
97
154
  virtual mpq_t const *getGmpRationalTemporaryPointer()const
98
155
    {
99
156
      fprintf(stderr,"*this object is not implemented using GMP\n");
100
 
      assert(0);   
 
157
      assert(0);
101
158
 
102
159
      return 0;
103
160
    }
 
161
  virtual bool isInteger()const
 
162
  {
 
163
    assert(0);
 
164
    return false;
 
165
  }
104
166
 
105
167
  Field& operator=(const Field& a)
106
168
    {
136
198
    {
137
199
      numberOfLivingFieldImplementations--;
138
200
    }
 
201
  virtual bool isRationals()const
 
202
  {
 
203
    return false;
 
204
  }
139
205
    //  static Field *find(const char *name);
140
206
  //  static void printList(FILE *f);
141
207
    virtual FieldElement zHomomorphism(int n)=0;