1 #ifndef _SMART_FRACTION_H_     2 #define _SMART_FRACTION_H_     5 #include "BPASFieldOfFractions.hpp"     6 #include "../../include/RationalFunction/rationalfunction_euclideanmethods.h"     7 #include "../../include/RationalNumberPolynomial/mrpolynomial.h"    11 #include "FactorRefinement.hpp"    18 template <
class Domain>
    22     std::vector<Factor<Domain>> num;
    23     std::vector<Factor<Domain>> den;
    26         for (
int i = 0; i < A.size(); ++i)
    28             Domain curr_Domain = A[i].first;
    29             int curr_exp = A[i].second;
    33             u->push_back(std::make_pair(temp_u,curr_exp));
    34             C->push_back(std::make_pair(temp_C,curr_exp));
    35             v->push_back(std::make_pair(temp_v,curr_exp));
    40         std::vector<Factor<Domain>> left, mid, right;
    41         FactorRefinement::MergeRefineTwoSeq<Domain>(A,B,&left,&mid,&right);
    47         a = convertToDomain(A);
    49         b = convertToDomain(B);
    51         std::vector<Factor<Domain>> v;
    52         v = extractFactors(a);
    58         a = convertToDomain(A);
    60         b = convertToDomain(B);
    62         std::vector<Factor<Domain>> v;
    63         v = extractFactors(a);
    68         std::vector<Factor<Domain>> v1,v2,v3;
    69         FactorRefinement::MergeRefineTwoSeq<Domain>(A,B,&v1,&v2,&v3);
    72         v1.insert(v1.end(),v2.begin(),v2.end());
    73         v1.insert(v1.end(),v3.begin(),v3.end());
    77         std::vector<Factor<Domain>> v1,v2,v3;
    78         FactorRefinement::MergeRefineTwoSeq<Domain>(A,B,&v1,&v2,&v3);
    80             cout << 
"BPAS error: in SmartFraction<Domain>, not exact division" <<endl;
    94         b->push_back(std::make_pair(one,1));
    97     static std::vector<Factor<Domain>> smart_one(){
    98         std::vector<Factor<Domain>> b;
   101         b.push_back(std::make_pair(one,1));
   111         if(b.size() == 1 && b[0].first.isOne()){
   166         num = extractFactors(a);
   167         den = extractFactors(b);
   183     void setNumerator(
const std::vector<std::pair<Domain, int>>& b);
   184     void setDenominator(
const std::vector<std::pair<Domain, int>>& b);
   186     void set(
const std::vector<std::pair<Domain, int>>& a, 
const std::vector<std::pair<Domain, int>>& b);
   223         std::cerr << 
"SmartFraction<Domain>::squareFree NOT YET IMPLEMENTED" << std::endl;
   228             std::cerr << 
"SmartFraction<Domain>::convertToExpressionTree NOT YET IMPLEMENTED" << std::endl;
   234     void print(std::ostream& ostream) 
const;
   241         std::cerr << 
"BPAS WARNING: SmartFraction::extendedEuclidean NOT YET IMPLEMENTED!" << std::endl;
   252     template <
class Domain>
   253     std::vector<Factor<Domain>> extractFactors(
const Domain &p) {
   254         std::vector<Factor<Domain>> ret;
   257             ret.emplace_back(v[0].first * v.ringElement(), 1);
   261         Domain v0 = v.ringElement();
   263             ret.emplace_back(v[0].first * v0, v[0].second);
   265             ret.emplace_back(v[0].first, v[0].second);
   267         for (
int i = 1; i < v.size(); ++i){
   268             if(!v[i].first.isOne()){
   269                 ret.emplace_back(v[i].first, v[i].second);
   279     template <
class Domain>
   285         for (
int i = 0; i < b.size(); ++i)
 An abstract class defining the interface of a field of fractions. 
Definition: BPASFieldOfFractions.hpp:16
void one()
Make *this ring element one. 
Integer euclideanSize() const
Get the euclidean size of *this. 
SmartFraction< Domain > remainder(const SmartFraction< Domain > &b) const
Get the remainder of *this and b. 
bool isZero() const
Determine if *this ring element is zero, that is the additive identity. 
void zero()
Make *this ring element zero. 
SmartFraction< Domain > & operator/=(const SmartFraction< Domain > &b)
Exact division assignment. 
SmartFraction< Domain > inverse() const
Get the inverse of *this. 
bool operator!=(const SmartFraction< Domain > &b) const
Inequality test,. 
SmartFraction< Domain > & operator%=(const SmartFraction< Domain > &b)
Assign *this to be the remainder of *this and b. 
bool isOne() const
Determine if *this ring element is one, that is the multiplication identity. 
An ExpressionTree encompasses various forms of data that can be expressed generically as a binary tre...
Definition: ExpressionTree.hpp:17
SmartFraction< Domain > euclideanDivision(const SmartFraction< Domain > &b, SmartFraction< Domain > *q=NULL) const
Perform the eucldiean division of *this and b. 
SmartFraction< Domain > operator%(const SmartFraction< Domain > &b) const
Get the remainder of *this and b;. 
void canonicalize()
Canonicalize this fraction, reducing terms as needed. 
SmartFraction< Domain > operator-() const
Negation. 
SmartFraction< Domain > & operator^=(long long int e)
Exponentiation assignment. 
SmartFraction< Domain > & operator-=(const SmartFraction< Domain > &b)
Subtraction assignment. 
SmartFraction< Domain > extendedEuclidean(const SmartFraction< Domain > &b, SmartFraction< Domain > *s=NULL, SmartFraction< Domain > *t=NULL) const
Perform the extended euclidean division on *this and b. 
Definition: SmartFraction.hpp:240
SmartFraction< Domain > quotient(const SmartFraction< Domain > &b) const
Get the quotient of *this and b. 
Domain denominator() const
Get the fraction's denominator. 
A simple data structure for encapsulating a collection of Factor elements. 
Definition: Factors.hpp:95
Factors< SmartFraction< Domain > > squareFree() const
Compute squarefree factorization of *this. 
Definition: SmartFraction.hpp:222
SmartFraction< Domain > gcd(const SmartFraction< Domain > &b) const
Get GCD of *this and other. 
ExpressionTree convertToExpressionTree() const
Convert this to an expression tree. 
Definition: SmartFraction.hpp:227
SmartFraction< Domain > operator^(long long int e) const
Exponentiation. 
An arbitrary-precision Integer. 
Definition: Integer.hpp:22
SmartFraction< Domain > operator+(const SmartFraction< Domain > &b) const
Addition. 
bool operator==(const SmartFraction< Domain > &b) const
Equality test,. 
SmartFraction< Domain > & operator+=(const SmartFraction< Domain > &b)
Addition assignment. 
virtual Derived unitCanonical(Derived *u=NULL, Derived *v=NULL) const =0
Obtain the unit normal (a.k.a canonical associate) of an element. 
A field of fractions templated by an arbitrary BPASGCDDomain making use of factor refinement...
Definition: SmartFraction.hpp:19
SmartFraction< Domain > unitCanonical(SmartFraction< Domain > *u=NULL, SmartFraction< Domain > *v=NULL) const
Obtain the unit normal (a.k.a canonical associate) of an element. 
void print(std::ostream &ostream) const
Print the Ring element. 
Domain numerator() const
Get the fraction's numerator. 
SmartFraction< Domain > operator/(const SmartFraction< Domain > &b) const
Exact division. 
SmartFraction< Domain > operator*(const SmartFraction< Domain > &b) const
Multiplication. 
SmartFraction< Domain > & operator*=(const SmartFraction< Domain > &b)
Multiplication assignment.