Basic Polynomial Algebra Subprograms (BPAS)  v. 1.652
Fraction.hpp
1 #ifndef _FRACTION_H_
2 #define _FRACTION_H_
3
4 #include <iostream>
5 #include "BPASFieldOfFractions.hpp"
6 #include "../../include/RationalFunction/rationalfunction_euclideanmethods.h"
7 #include "../../include/RationalNumberPolynomial/mrpolynomial.h"
8 #include <algorithm>
9 #include <vector>
10
11 /**
12  * A field of fractions templated by an arbitrary BPASGCDDomain.
13  */
14 template <class Domain>
15 class Fraction: public BPASFieldOfFractions<Domain, Fraction<Domain>> {
16
17  private:
18  Domain den;//denominator
19  Domain num;//numerator
20
21
22
23  public:
24
25  mpz_class characteristic;
26  /**
27  * Construct the zero fraction function
28  *
29  * @param
30  **/
32  den.one();
33  num.zero();
34  Domain e;
35  characteristic = e.characteristic;
36  };
37  /**
38  * Copy constructor
39  *
40  * @param b: A rational function
41  **/
42  Fraction<Domain>(const Fraction<Domain> &b): num(b.num),den(b.den){
43  characteristic = b.characteristic;
44  }
45
46  /**
47  * constructor with two parameter
48  *
49  * @param a: the numerator
50  * @param b: the denominator
51  **/
52  Fraction<Domain>(Domain a, Domain b){
53  if (b.isZero()) {
54  std::cout << "BPAS error: denominator is zero from Fraction<Domain>" << std::endl;
55  exit(1);
56  }
57  num = a;
58  den = b;
59  Domain e;
60  characteristic = e.characteristic;
61  }
62
63  /**
64  * Deconstructor for fraction
65  *
66  * @param
67  **/
69
70
71  void setNumerator(const Domain& b);
72  void setDenominator(const Domain& b);
73
74  void set(const Domain& a, const Domain& b);
75
76  Domain numerator() const;
77  Domain denominator() const;
78
79  bool operator!=(const Fraction<Domain> &b) const;
80  bool operator==(const Fraction<Domain> &b) const;
81
84
87
90
93
95
96  /**
98  * replace xor operation by exponentiation
99  *
100  * @param e: The exponentiation, e > 0
101  **/
102  Fraction<Domain> operator^(long long int e) const;
103  /**
105  * replace xor operation by exponentiation
106  *
107  * @param e: The exponentiation, e > 0
108  **/
109  Fraction<Domain>& operator^=(long long int e);
110
111  Fraction<Domain> inverse() const;
112
113  bool isZero() const;
114  void zero();
115  bool isOne() const;
116  void one();
117  bool isNegativeOne() const;
118  void negativeOne();
119  int isConstant() const;
121
122  /**
124  *
125  * @param b: A rational function
126  **/
128
129  void print(std::ostream& ostream) const;
130
132
133  //not implemented yet
135  //not implemented yet
137  //not implemented yet
139
140
141  void canonicalize();
142
143  void differentiate();
144
145
146  void normalize();
147  //RefineReturn<Domain> Refine(Domain a, Domain e, Domain b, Domain f);
148
149
150
151
153  std::cerr << "UnivariateRationalFunction::convertToExpressionTree NOT YET IMPLEMENTED" << std::endl;
154  //TODO
155  return ExpressionTree();
156  }
157
159  //std::cerr << "UnivariateRationalFunction::gcd NOT YET IMPLEMENTED" << std::endl;
160  //if both are 0 then return 0
161  Fraction<Domain> ret;
162  if(isZero() == true &&b.isZero() == true){
163  ret.zero();
164
165  }
166  //otherwise is one
167  else{
168  ret.one();
169  }
170
171  return ret;
172  }
173
175  std::cerr << "BPAS ERROR: Fraction::squareFree NOT YET IMPLEMENTED" << std::endl;
176  return Factors<Fraction<Domain>>(*this);
177  }
178
180  //TODO
181  //if is zero, throw error exit(1)
182  //otherwise return 0
183
184  if(isZero() == true){
185  std::cerr << "in Fraction<Domain>, zero does not have a euclidean size" << std::endl;
186  exit(1);
187  }
188  else{
189  Fraction<Domain> ret;
190  ret.zero();
191  return ret;
192  }
193  }
194
196  //TODO
197  //return type is remainder,
198  //q is quo,
199  //it always exact division
200  Fraction<Domain> ret;
201  ret.zero();
202  if(q!=NULL){
203  Fraction<Domain> curr(num,den);
204  *q = curr/b;
205  }
206
207  return ret;
208  }
209
211  std::cerr << "UnivariateRationalFunction::extendedEuclidean NOT YET IMPLEMENTED" << std::endl;
212  //TODO
213  //
214  return *this;
215  }
216
217 };
218
219
220
221
222
223 #endif
Fraction< Domain > inverse() const
Get the inverse of *this.
An abstract class defining the interface of a field of fractions.
Definition: BPASFieldOfFractions.hpp:16
Fraction< Domain > operator*(const Fraction< Domain > &b) const
Multiplication.
Factors< Fraction< Domain > > squareFree() const
Compute squarefree factorization of *this.
Definition: Fraction.hpp:174
void one()
Make *this ring element one.
Fraction< Domain > operator^(long long int e) const
Overload operator ^ replace xor operation by exponentiation.
An ExpressionTree encompasses various forms of data that can be expressed generically as a binary tre...
Definition: ExpressionTree.hpp:17
Fraction< Domain > gcd(const Fraction< Domain > &b) const
Get GCD of *this and other.
Definition: Fraction.hpp:158
Domain numerator() const
Get the fraction&#39;s numerator.
bool operator!=(const Fraction< Domain > &b) const
Inequality test,.
Fraction< Domain > operator-() const
Negation.
Domain denominator() const
Get the fraction&#39;s denominator.
Fraction< Domain > operator/(const Fraction< Domain > &b) const
Exact division.
A field of fractions templated by an arbitrary BPASGCDDomain.
Definition: Fraction.hpp:15
Fraction< Domain > & operator=(const Fraction< Domain > &b)
Fraction< Domain > & operator-=(const Fraction< Domain > &b)
Subtraction assignment.
void zero()
Make *this ring element zero.
Fraction< Domain > & operator+=(const Fraction< Domain > &b)
Fraction< Domain > euclideanDivision(const Fraction< Domain > &b, Fraction< Domain > *q=NULL) const
Perform the eucldiean division of *this and b.
Definition: Fraction.hpp:195
Fraction< Domain > euclideanSize() const
Get the euclidean size of *this.
Definition: Fraction.hpp:179
A simple data structure for encapsulating a collection of Factor elements.
Definition: Factors.hpp:95
void canonicalize()
Canonicalize this fraction, reducing terms as needed.
void print(std::ostream &ostream) const
Print the Ring element.
Fraction< Domain > unitCanonical(Fraction< Domain > *u=NULL, Fraction< Domain > *v=NULL) const
Obtain the unit normal (a.k.a canonical associate) of an element.
Fraction< Domain > operator+(const Fraction< Domain > &b) const
ExpressionTree convertToExpressionTree() const
Convert this to an expression tree.
Definition: Fraction.hpp:152
Fraction< Domain > & operator^=(long long int e)
Overload operator ^= replace xor operation by exponentiation.
Fraction< Domain > & operator%=(const Fraction< Domain > &b)
Assign *this to be the remainder of *this and b.
Fraction< Domain > operator%(const Fraction< Domain > &b) const
Get the remainder of *this and b;.
bool isOne() const
Determine if *this ring element is one, that is the multiplication identity.
virtual mpz_class characteristic()
The characteristic of this ring class.
Definition: BPASRing.hpp:87
bool operator==(const Fraction< Domain > &b) const
Equality test,.
bool isZero() const
Determine if *this ring element is zero, that is the additive identity.
Fraction< Domain > & operator*=(const Fraction< Domain > &b)
Multiplication assignment.
Fraction< Domain > & operator/=(const Fraction< Domain > &b)
Exact division assignment.
Fraction< Domain > extendedEuclidean(const Fraction< Domain > &b, Fraction< Domain > *s=NULL, Fraction< Domain > *t=NULL) const
Perofrm the extended euclidean division on *this and b.
Definition: Fraction.hpp:210
Fraction< Domain > quotient(const Fraction< Domain > &b) const
Get the quotient of *this and b.
Fraction< Domain > remainder(const Fraction< Domain > &b) const
Get the remainder of *this and b.