Basic Polynomial Algebra Subprograms (BPAS)  v. 1.791
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  /**
26  * Construct the zero fraction function
27  *
28  * @param
29  **/
31  den.one();
32  num.zero();
33  Domain e;
34  };
35  /**
36  * Copy constructor
37  *
38  * @param b: A rational function
39  **/
40  Fraction<Domain>(const Fraction<Domain> &b): num(b.num),den(b.den){
41  }
42 
43  /**
44  * constructor with two parameter
45  *
46  * @param a: the numerator
47  * @param b: the denominator
48  **/
49  Fraction<Domain>(Domain a, Domain b){
50  if (b.isZero()) {
51  std::cout << "BPAS error: denominator is zero from Fraction<Domain>" << std::endl;
52  exit(1);
53  }
54  num = a;
55  den = b;
56  Domain e;
57  }
58 
59  /**
60  * Deconstructor for fraction
61  *
62  * @param
63  **/
65 
66 
67  void setNumerator(const Domain& b);
68  void setDenominator(const Domain& b);
69 
70  void set(const Domain& a, const Domain& b);
71 
72  Domain numerator() const;
73  Domain denominator() const;
74 
75  bool operator!=(const Fraction<Domain> &b) const;
76  bool operator==(const Fraction<Domain> &b) const;
77 
80 
83 
86 
89 
91 
92  /**
93  * Overload operator ^
94  * replace xor operation by exponentiation
95  *
96  * @param e: The exponentiation, e > 0
97  **/
98  Fraction<Domain> operator^(long long int e) const;
99  /**
100  * Overload operator ^=
101  * replace xor operation by exponentiation
102  *
103  * @param e: The exponentiation, e > 0
104  **/
105  Fraction<Domain>& operator^=(long long int e);
106 
107  Fraction<Domain> inverse() const;
108 
109  bool isZero() const;
110  void zero();
111  bool isOne() const;
112  void one();
113  bool isNegativeOne() const;
114  void negativeOne();
115  int isConstant() const;
117 
118  /**
119  * Overload operator =
120  *
121  * @param b: A rational function
122  **/
124 
125  void print(std::ostream& ostream) const;
126 
128 
129  //not implemented yet
131  //not implemented yet
133  //not implemented yet
135 
136 
137  void canonicalize();
138 
139  void differentiate();
140 
141 
142  void normalize();
143  //RefineReturn<Domain> Refine(Domain a, Domain e, Domain b, Domain f);
144 
145 
146 
147 
149  std::cerr << "UnivariateRationalFunction::convertToExpressionTree NOT YET IMPLEMENTED" << std::endl;
150  //TODO
151  return ExpressionTree();
152  }
153 
155  //std::cerr << "UnivariateRationalFunction::gcd NOT YET IMPLEMENTED" << std::endl;
156  //if both are 0 then return 0
157  Fraction<Domain> ret;
158  if(isZero() == true &&b.isZero() == true){
159  ret.zero();
160 
161  }
162  //otherwise is one
163  else{
164  ret.one();
165  }
166 
167  return ret;
168  }
169 
171  std::cerr << "BPAS ERROR: Fraction::squareFree NOT YET IMPLEMENTED" << std::endl;
172  return Factors<Fraction<Domain>>(*this);
173  }
174 
176  //TODO
177  //if is zero, throw error exit(1)
178  //otherwise return 0
179 
180  if(isZero() == true){
181  std::cerr << "in Fraction<Domain>, zero does not have a euclidean size" << std::endl;
182  exit(1);
183  }
184  else{
185  return Integer(1);
186  }
187  }
188 
190  //TODO
191  //return type is remainder,
192  //q is quo,
193  //it always exact division
194  Fraction<Domain> ret;
195  ret.zero();
196  if(q!=NULL){
197  Fraction<Domain> curr(num,den);
198  *q = curr/b;
199  }
200 
201  return ret;
202  }
203 
205  std::cerr << "Fraction::extendedEuclidean NOT YET IMPLEMENTED" << std::endl;
206  //TODO
207  //
208  return *this;
209  }
210 
211 };
212 
213 
214 
215 
216 
217 #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:170
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:154
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)
Overload operator =.
Fraction< Domain > & operator-=(const Fraction< Domain > &b)
Subtraction assignment.
void zero()
Make *this ring element zero.
Fraction< Domain > & operator+=(const Fraction< Domain > &b)
Addition assignment.
Fraction< Domain > euclideanDivision(const Fraction< Domain > &b, Fraction< Domain > *q=NULL) const
Perform the eucldiean division of *this and b.
Definition: Fraction.hpp:189
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.
An arbitrary-precision Integer.
Definition: Integer.hpp:22
Fraction< Domain > unitCanonical(Fraction< Domain > *u=NULL, Fraction< Domain > *v=NULL) const
Obtain the unit normal (a.k.a canonical associate) of an element.
Integer euclideanSize() const
Get the euclidean size of *this.
Definition: Fraction.hpp:175
Fraction< Domain > operator+(const Fraction< Domain > &b) const
Addition.
ExpressionTree convertToExpressionTree() const
Convert this to an expression tree.
Definition: Fraction.hpp:148
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.
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
Perform the extended euclidean division on *this and b.
Definition: Fraction.hpp:204
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.