int_rat.h
Go to the documentation of this file.
1 /* emacs edit mode for this file is -*- C++ -*- */
2 
3 #ifndef INCL_INT_RAT_H
4 #define INCL_INT_RAT_H
5 
6 /**
7  * @file int_rat.h
8  *
9  * Factory's internal rationals
10 **/
11 // #include "config.h"
12 
13 #ifndef NOSTREAMIO
14 #ifdef HAVE_IOSTREAM
15 #include <iostream>
16 #define OSTREAM std::ostream
17 #elif defined(HAVE_IOSTREAM_H)
18 #include <iostream.h>
19 #define OSTREAM ostream
20 #endif
21 #endif /* NOSTREAMIO */
22 
23 #include "cf_assert.h"
24 
25 #include "canonicalform.h"
26 #include "int_cf.h"
27 #include "imm.h"
28 // #include <factory/cf_gmp.h>
29 
30 /**
31  * factory's class for rationals
32  *
33  * a rational is represented as two mpz_t's _num, _den
34  *
35  * Note: If you want to compute over Q make sure that SW_RATIONAL is set to 1!
36  *
37  * @sa InternalInteger
38 **/
40 {
41 private:
42  mpz_t _num;
43  mpz_t _den;
44  static int initialized;
45  static mpz_ptr MPQNUM( const InternalCF * const c );
46  static mpz_ptr MPQDEN( const InternalCF * const c );
47  static void normalize( const mpz_ptr, const mpz_ptr, mpz_ptr, mpz_ptr );
48 public:
51  {
52  ASSERT( 0, "ups there is something wrong in your code" );
53  }
54  InternalRational( const int i );
55  InternalRational( const int n, const int d );
56  InternalRational( const long i );
57  InternalRational( const long n, const long d );
58  InternalRational( const char * str );
59  InternalRational( const mpz_ptr );
60  InternalRational( const mpz_ptr , const mpz_ptr );
62  InternalCF* deepCopyObject() const;
63  const char * classname() const { return "InternalRational"; }
64 #ifndef NOSTREAMIO
65  void print( OSTREAM&, char* );
66 #endif /* NOSTREAMIO */
68  InternalCF* genOne();
69 
70  bool is_imm() const;
71  int levelcoeff() const { return RationalDomain; }
72 
73  InternalCF* num();
74  InternalCF* den();
75 
76  InternalCF* neg();
77 
78  int comparesame( InternalCF* );
79 
89 
90  int comparecoeff( InternalCF* );
91 
93  InternalCF* subcoeff( InternalCF*, bool );
97  InternalCF* divcoeff( InternalCF*, bool );
98  InternalCF* modcoeff( InternalCF*, bool );
99  void divremcoeff( InternalCF*, InternalCF*&, InternalCF*&, bool );
100  bool divremcoefft( InternalCF*, InternalCF*&, InternalCF*&, bool );
101 
102  InternalCF * bgcdsame ( const InternalCF * const ) const;
103  InternalCF * bgcdcoeff ( const InternalCF * const );
104 
107 
108  long intval() const;
109 
110  int sign() const;
111 
113 
114  friend class InternalInteger;
115  friend void gmp_numerator ( const CanonicalForm & f, mpz_ptr result );
116  friend void gmp_denominator ( const CanonicalForm & f, mpz_ptr result );
117  friend CanonicalForm make_cf ( const mpz_ptr n, const mpz_ptr d );
118 };
119 
120 inline mpz_ptr InternalRational::MPQNUM( const InternalCF * const c )
121 {
122  return (((InternalRational*)c)->_num);
123 }
124 
125 inline mpz_ptr InternalRational::MPQDEN( const InternalCF * const c )
126 {
127  return (((InternalRational*)c)->_den);
128 }
129 
130 #endif /* ! INCL_INT_RAT_H */
#define OSTREAM
Definition: int_rat.h:16
InternalCF * modcoeff(InternalCF *, bool)
Definition: int_rat.cc:797
InternalCF * mulcoeff(InternalCF *)
Definition: int_rat.cc:654
InternalCF * den()
Definition: int_rat.cc:196
InternalCF * addsame(InternalCF *)
Definition: int_rat.cc:234
int comparesame(InternalCF *)
comparesame(), comparecoeff() - compare with an InternalRational.
Definition: int_rat.cc:516
InternalCF * mulsame(InternalCF *)
Definition: int_rat.cc:348
void divremcoeff(InternalCF *, InternalCF *&, InternalCF *&, bool)
Definition: int_rat.cc:805
InternalCF * normalize_myself()
reduce InternalRational to lowest terms
Definition: int_rat.cc:859
void divremsame(InternalCF *, InternalCF *&, InternalCF *&)
Definition: int_rat.cc:489
InternalCF * addcoeff(InternalCF *)
Definition: int_rat.cc:560
bool divremcoefft(InternalCF *, InternalCF *&, InternalCF *&, bool)
Definition: int_rat.cc:812
InternalCF * dividecoeff(InternalCF *, bool)
Definition: int_rat.cc:707
const CanonicalForm CFMap CFMap int &both_non_zero int n
Definition: cfEzgcd.cc:52
InternalCF * bextgcdsame(InternalCF *, CanonicalForm &, CanonicalForm &)
Definition: int_rat.cc:840
factory's main class
Definition: canonicalform.h:75
assertions for Factory
friend void gmp_denominator(const CanonicalForm &f, mpz_ptr result)
Definition: singext.cc:40
InternalCF * genOne()
Definition: int_rat.cc:167
static mpz_ptr MPQDEN(const InternalCF *const c)
Definition: int_rat.h:125
virtual class for internal CanonicalForm's
Definition: int_cf.h:39
InternalCF * genZero()
Definition: int_rat.cc:159
InternalCF * neg()
InternalCF * InternalRational::neg ()
Definition: int_rat.cc:215
InternalCF * num()
Definition: int_rat.cc:178
InternalCF * bgcdcoeff(const InternalCF *const )
Definition: int_rat.cc:831
InternalCF * subcoeff(InternalCF *, bool)
Definition: int_rat.cc:597
int comparecoeff(InternalCF *)
comparecoeff() compares the CO=a/b and the integer c using the equivalence a/b < c iff a < c*b...
Definition: int_rat.cc:536
bool is_imm() const
Definition: int_rat.cc:154
InternalCF * dividesame(InternalCF *)
Definition: int_rat.cc:408
void print(OSTREAM &, char *)
Definition: int_rat.cc:141
InternalCF * divsame(InternalCF *)
Definition: int_rat.cc:473
const char * classname() const
Definition: int_rat.h:63
static void normalize(const mpz_ptr, const mpz_ptr, mpz_ptr, mpz_ptr)
FILE * f
Definition: checklibs.c:7
int i
Definition: cfEzgcd.cc:123
InternalCF * modulosame(InternalCF *)
Definition: int_rat.cc:478
#define RationalDomain
Definition: cf_defs.h:24
friend void gmp_numerator(const CanonicalForm &f, mpz_ptr result)
Definition: singext.cc:20
static int initialized
Definition: int_rat.h:44
friend CanonicalForm make_cf(const mpz_ptr n, const mpz_ptr d)
InternalCF * bgcdsame(const InternalCF *const ) const
Definition: int_rat.cc:822
InternalRational(const InternalCF &)
Definition: int_rat.h:50
InternalCF * subsame(InternalCF *)
Definition: int_rat.cc:292
operations on immediates, that is elements of F_p, GF, Z, Q that fit into intrinsic int...
bool divremsamet(InternalCF *, InternalCF *&, InternalCF *&)
Definition: int_rat.cc:496
InternalCF * modulocoeff(InternalCF *, bool)
Definition: int_rat.cc:792
Factory's internal CanonicalForm's.
InternalCF * modsame(InternalCF *)
Definition: int_rat.cc:483
#define ASSERT(expression, message)
Definition: cf_assert.h:99
long intval() const
Definition: int_rat.cc:897
factory's class for integers
Definition: int_int.h:44
InternalCF * bextgcdcoeff(InternalCF *, CanonicalForm &, CanonicalForm &)
Definition: int_rat.cc:850
int levelcoeff() const
Definition: int_rat.h:71
InternalCF * divcoeff(InternalCF *, bool)
Definition: int_rat.cc:787
factory's class for rationals
Definition: int_rat.h:39
return result
Definition: facAbsBiFact.cc:76
static mpz_ptr MPQNUM(const InternalCF *const c)
Definition: int_rat.h:120
Header for factory's main class CanonicalForm.
InternalCF * deepCopyObject() const
Definition: int_rat.cc:131
int sign() const
Definition: int_rat.cc:909