Developer documentation

scalar_integer.hpp
Go to the documentation of this file.
1 /*********************************************************************
2 * This file is part of the source code of ALP software. *
3 * (C) B. Mourrain, GALAAD, INRIA *
4 **********************************************************************
5 History:
6 $Id: scalar_mpz.H,v 1.1.1.1 2006/10/06 08:01:40 trebuche Exp $
7 **********************************************************************/
8 #ifndef _scalar_integer_hpp
9 #define _scalar_integer_hpp
10 //----------------------------------------------------------------------
11 #include <iostream>
12 #include <string>
13 #include <gmp.h>
14 #include <realroot/scalar.hpp>
15 //======================================================================
16 namespace mmx {
17 //----------------------------------------------------------------------
18 typedef MP_INT MPZ;
19 //----------------------------------------------------------------------
20 // template<> inline
21 // shared_object<MPZ>::rep::~rep()
22 // {
23 // //COUT <<"Delete mpz"<<endl;
24 // mpz_clear(&obj);
25 // }
26 //----------------------------------------------------------------------
27 template<> inline scalar<MPZ>::~scalar ( )
28 {
29  //COUT <<"Delete mpz"<<endl;
30  mpz_clear(&rep());
31 }
32 //----------------------------------------------------------------------
33 template<> inline
34 void scalar<MPZ>::init ( )
35 {
36  mpz_init(&rep());
37 }
38 //------------------- scalar<T> (...) -------------------------------------
39 template<> inline
40 scalar<MPZ>::scalar () //: data()
41 {
42  mpz_init(&rep());
43 }
44 //----------------------------------------------------------------------
45 template<> inline
46 scalar<MPZ>::scalar (signed long int sl): data() {mpz_init_set_si(&rep(),sl);}
47 //----------------------------------------------------------------------
48 template<> inline
49 scalar<MPZ>::scalar (unsigned long int ul): data() {mpz_init_set_ui(&rep(),ul);}
50 //----------------------------------------------------------------------
51 template<> inline
52 scalar<MPZ>::scalar (int si): data() {mpz_init_set_si(&rep(), si);}
53 //----------------------------------------------------------------------
54 template<> inline
55 scalar<MPZ>::scalar (const char *s, unsigned int base): data()
56 {
57  if (mpz_init_set_str(&rep(), s, base))
58  std::cerr << "scalar<MPZ>: The string " << s
59  << " is not a valid number in base " << base << std::endl;
60 }
61 //----------------------------------------------------------------------
62 template<> inline
64 {
65  //COUT <<"Init mpz"<<endl;
66  //COUNT<MPZ>('c');
67  mpz_init_set(&rep(), &rhs.rep());
68 }
69 //{ data=b.data;}
70 //----------------------------------------------------------------------
71 template<> inline
73 {
74  //COUNT<MPZ>('=');
75  if (this != &rhs) mpz_set(&rep(), &rhs.rep());
76  return *this;
77 }
78 template<> inline
80 {
81  //COUNT<MPZ>('=');
82  mpz_set_ui(&rep(), rhs);
83  return *this;
84 }
85 // == ------------------------------------------------------------------
86 template<> inline
87 bool scalar<MPZ>::operator == (const scalar<MPZ>& rhs) const
88 {
89  return mpz_cmp(&rep(), &rhs.rep()) == 0;
90 }
91 
92 template<> inline
93 bool scalar<MPZ>::operator == (long sl) const {
94  return mpz_cmp_si(&rep(), sl) == 0;
95 }
96 
97 template<> inline
98 bool scalar<MPZ>::operator == (int si) const {
99  return mpz_cmp_si(&rep(), (long) si) == 0;
100 }
101 
102 template<> inline
103 bool scalar<MPZ>::operator == (unsigned long ul) const
104 {
105  return mpz_cmp_ui(&rep(), ul) == 0;
106 }
107 
108 // != ------------------------------------------------------------------
109 template<> inline
111 {
112  return mpz_cmp(&rep(), &rhs.rep()) != 0;
113 }
114 
115 template<> inline
116 bool scalar<MPZ>::operator != (long sl) const {
117  return mpz_cmp_si(&rep(), sl) != 0;
118 }
119 
120 template<> inline
121 bool scalar<MPZ>::operator != (int si) const {
122  return mpz_cmp_si(&rep(), (long) si) != 0;
123 }
124 
125 template<> inline
126 bool scalar<MPZ>::operator != (unsigned long ul) const
127 {
128  return mpz_cmp_ui(&rep(), ul) != 0;
129 }
130 // > -------------------------------------------------------------------
131 template<> inline
132 bool scalar<MPZ>::operator > (const scalar<MPZ>& rhs) const
133 {
134  return mpz_cmp(&rep(), &rhs.rep()) > 0;
135 }
136 
137 template<> inline
138 bool scalar<MPZ>::operator > (long sl) const {
139  return mpz_cmp_si(&rep(), sl) > 0;
140 }
141 
142 template<> inline
143 bool scalar<MPZ>::operator > (int si) const {
144  return mpz_cmp_si(&rep(), (long) si) > 0;
145 }
146 
147 template<> inline
148 bool scalar<MPZ>::operator > (unsigned long ul) const
149 {
150  return mpz_cmp_ui(&rep(), ul) > 0;
151 }
152 // <= --------------------------------------------------------------------
153 template<> inline
155 {
156  return mpz_cmp(&rep(), &rhs.rep()) >= 0;
157 }
158 
159 template<> inline
160 bool scalar<MPZ>::operator >= (long sl) const {
161  return mpz_cmp_si(&rep(), sl) >= 0;
162 }
163 
164 template<> inline
165 bool scalar<MPZ>::operator >= (int si) const
166 {
167  return mpz_cmp_si(&rep(), (long) si) >= 0;
168 }
169 
170 template<> inline
171 bool scalar<MPZ>::operator >= (unsigned long ul) const
172 {
173  return mpz_cmp_ui(&rep(), ul) >= 0;
174 }
175 
176 // < -------------------------------------------------------------------
177 template<> inline
178 bool scalar<MPZ>::operator < (const scalar<MPZ>& rhs) const
179 {
180  return mpz_cmp(&rep(), &rhs.rep()) < 0;
181 }
182 
183 template<> inline
184 bool scalar<MPZ>::operator < (long sl) const {
185  return mpz_cmp_si(&rep(), sl) < 0;
186 }
187 
188 template<> inline
189 bool scalar<MPZ>::operator < (int si) const
190 {
191  return mpz_cmp_si(&rep(), (long) si) < 0;
192 }
193 
194 template<> inline
195 bool scalar<MPZ>::operator < (unsigned long ul) const
196 {
197  return mpz_cmp_ui(&rep(), ul) < 0;
198 }
199 
200 // <= ------------------------------------------------------------------
201 
202 template<> inline
204 {
205  return mpz_cmp(&rep(), &rhs.rep()) <= 0;
206 }
207 
208 template<> inline
209 bool scalar<MPZ>::operator <= (long sl) const {
210  return mpz_cmp_si(&rep(), sl) <= 0;
211 }
212 
213 template<> inline
214 bool scalar<MPZ>::operator <= (int si) const
215 {
216  return mpz_cmp_si(&rep(), (long) si) <= 0;
217 }
218 
219 template<> inline
220 bool scalar<MPZ>::operator <= (unsigned long ul) const
221 {
222  return mpz_cmp_ui(&rep(), ul) <= 0;
223 }
224 
225 // = -------------------------------------------------------------------
226 template<> inline
228 {
229  mpz_set_ui(&rep(), ul); return *this;
230 }
231 
232 template<> inline
234 {
235  mpz_set_si(&rep(), sl); return *this;
236 }
237 
238 template<> inline
240 {
241  mpz_init_set_si(&(this->rep()), ul); return *this;
242 }
243 // += -------------------------------------------------------------------
244 template<> inline
246 {
247  mpz_add(&rep(), &rep(), &rhs.rep()); return *this;
248 }
249 
250 template<> inline
252 {
253  mpz_add_ui(&rep(), &rep(), ul); return *this;
254 }
255 
256 template<> inline
258 {
259  if (sl >= 0)
260  mpz_add_ui(&rep(), &rep(), (unsigned long) sl);
261  else
262  mpz_sub_ui(&rep(), &rep(), ((unsigned long) -sl));
263  return *this;
264 }
265 
266 template<> inline
268 {
269  *this += scalar<MPZ>(ul); return *this;
270 }
271 
272 // -= -------------------------------------------------------------------
273 template<> inline
275 {
276  mpz_sub(&rep(), &rep(), &rhs.rep()); return *this;
277 }
278 
279 template<> inline
281 {
282  mpz_sub_ui(&rep(), &rep(), ul); return *this;
283 }
284 
285 template<> inline
287 {
288  if (sl >= 0)
289  mpz_sub_ui(&rep(), &rep(), (unsigned long) sl);
290  else
291  mpz_add_ui(&rep(), &rep(), (unsigned long) sl);
292  return *this;
293 }
294 
295 template<> inline
297 {
298  *this -= scalar<MPZ>(ul); return *this;
299 }
300 // *= -----------------------------------------------------------------
301 template<> inline
303 {
304  mpz_mul(&rep(), &rep(), &rhs.rep()); return *this;
305 }
306 template<> inline
308 {
309  mpz_mul_ui(&rep(), &rep(), ul); return *this;
310 }
311 template<> inline
313 {
314  if (sl >= 0)
315  mpz_mul_ui(&rep(), &rep(), (unsigned long) sl);
316  else
317  {
318  rep()._mp_size = -rep()._mp_size;
319  mpz_mul_ui(&rep(), &rep(), ((unsigned long) -sl));
320  }
321  return *this;
322 }
323 template<> inline
325 {
326  if (ul >= 0)
327  mpz_mul_ui(&rep(), &rep(), (unsigned long) ul);
328  else {
329  mpz_mul_ui(&rep(), &rep(), (unsigned long) (-ul));
330  mpz_neg(&rep(), &rep());
331  }
332  return *this;
333 }
334 // /= ------------------------------------------------------------------
335 template<> inline
337 {
338  mpz_div(&rep(), &rep(), &rhs.rep());
339  //mpz_divexact(&rep(), &rep(), &rhs.rep());
340  return *this;
341 }
342 template<> inline
344 {
345  mpz_div_ui(&rep(), &rep(), ul); return *this;
346 }
347 
348 template<> inline
350 {
351  if (sl >= 0)
352  mpz_div_ui(&rep(), &rep(), (unsigned long) sl);
353  else
354  {
355  rep()._mp_size = -rep()._mp_size;
356  mpz_div_ui(&rep(), &rep(), ((unsigned long) -sl));
357  }
358  return *this;
359 }
360 
361 // %= ------------------------------------------------------------------
362 template<> inline
364 {
365  mpz_mod(&rep(), &rep(), &rhs.rep()); return *this;
366 }
367 
368 template<> inline
370 {
371  mpz_mod_ui(&rep(), &rep(), ul); return *this;
372 }
373 
374 //======================================================================
375 // ARITHMETIC OPERATORS
376 //======================================================================
377 inline
379 {
380  scalar<MPZ> result;
381  mpz_add(&result.rep(), &a1.rep(), &a2.rep());
382  return result;
383 }
384 //----------------------------------------------------------------------
385 inline
387 {
388  scalar<MPZ> result;
389  mpz_sub(&result.rep(), &a1.rep(), &a2.rep());
390  return result;
391  }
392 
393 inline
395 {
396  scalar<MPZ> r; mpz_neg(&r.rep(), &a1.rep()); return r;
397 }
398 //----------------------------------------------------------------------
399 inline
401 {
402  scalar<MPZ> result;
403  mpz_mul(&result.rep(), &a1.rep(), &a2.rep());
404  return result;
405 }
406 
407 //--------------------------------------------------------------------
408 inline
410 {
411  scalar<MPZ> result;
412  mpz_div(&result.rep(), &a1.rep(), &a2.rep());
413  return result;
414 }
415 //======================================================================
417 template<> inline
419 {
420  mpz_add_ui(&rep(), &rep(), 1);
421 }
422 //----------------------------------------------------------------------
424 template<> inline
426 {
427  mpz_sub_ui(&rep(), &rep(), 1);
428 }
429 //======================================================================
430 inline void convert(scalar<MPZ>& n, char *s)
431 {
432  mpz_init_set_str(&n.rep(), s, 10);
433 }
434 //======================================================================
435 // INPUT OUTPUT
436 //======================================================================
437 inline
438 std::ostream& operator << (std::ostream& os, const scalar<MPZ>& b)
439 {
440  mpz_out_str(stdout, 10, &b.rep());
441  return os;
442 }
443 
444 inline char* as_charp(const scalar<MPZ>& b) {
445  return mpz_get_str(NULL, 10, &b.rep());
446 }
447 
448 inline std::string to_string(const scalar<MPZ>& b) {
449  char* str= mpz_get_str(NULL, 10, &b.rep());
450  return std::string(str);
451 }
452 template<class OSTREAM> inline void
453 print(OSTREAM& os, const scalar<MPZ>& b) {
454  os << as_charp(b);
455 }
456 //----------------------------------------------------------------------
457 inline
458 std::istream& operator >> (std::istream& is, scalar<MPZ>& b)
459 {
460  std::string s;is >> s;
461  mpz_init_set_str(&b.rep(),s.c_str(), 10);
462  return is;
463 }
464 //======================================================================
465 // SPECIAL FUNCTIONS
466 //======================================================================
467 template<> inline void
468 scalar<MPZ>::Div2Exp (unsigned long exponent_of_2)
469 {
470  mpz_div_2exp(&rep(), &rep(), exponent_of_2);
471 }
472 
473 template<> inline
475 {
476  mpz_gcd (&rep(), &rep(), &b2.rep());
477 }
478 
479 
480 template<> inline void
481 scalar<MPZ>::Mod2Exp (unsigned long exponent_of_2)
482 {
483  mpz_mod_2exp(&rep(), &rep(), exponent_of_2);
484 }
485 
486 template<> inline void
487 scalar<MPZ>::Mul2Exp (unsigned long exponent_of_2)
488 {
489  mpz_mul_2exp(&rep(), &rep(), exponent_of_2);
490 }
491 
492 template<> inline void
494 {
495  mpz_powm(&rep(), &rep(), &exp.rep(), &m.rep());
496 }
497 
498 template<> inline void
499 scalar<MPZ>::PowMod (unsigned long exp, const scalar<MPZ>& m)
500 {
501  mpz_powm_ui(&rep(), &rep(), exp, &m.rep());
502 }
503 
504 template<> inline void
506 {
507  if (rep()._mp_size < 0)
508  rep()._mp_size = - rep()._mp_size;
509 }
510 
511 template<> inline void
512 scalar<MPZ>::factorial (unsigned long n)
513 {
514  mpz_fac_ui(&rep(), n);
515 }
516 
517 template<> inline
519 {
520  rep()._mp_size = - rep()._mp_size; return *this;
521 }
522 
523 inline scalar<MPZ> rfloor (const scalar<MPZ>& q) { return q; }
524 inline scalar<MPZ> rceil (const scalar<MPZ>& q) { return rfloor(q)+1; }
525 
526 template<> inline
527 scalar<MPZ>& scalar<MPZ>::pow (unsigned long exp)
528 {
529  mpz_pow_ui(&rep(), &rep(), exp); return *this;
530 }
531 
532 template<> inline
533 scalar<MPZ>& scalar<MPZ>::pow (unsigned long base, unsigned long exp)
534 {
535  mpz_ui_pow_ui(&rep(), base, exp); return *this;
536 }
537 
538 template<> inline void
540 {
541  mpz_mdiv (&rep(), &rep(), &divisor.rep());
542 }
543 
544 template<> inline void
545 scalar<MPZ>::quo (unsigned long divisor)
546 {
547  mpz_mdiv_ui(&rep(), &rep(), divisor);
548 }
549 
550 template<> inline void
552 {
553  mpz_mmod(&rep(), &rep(), &divisor.rep());
554 }
555 
556 template<> inline unsigned long
557 scalar<MPZ>::rem (unsigned long divisor)
558 {
559  return mpz_mmod_ui(&rep(), &rep(), divisor);
560 }
561 
562 template<> inline void
564 {
565  mpz_sqrt(&rep(), &rep());
566 }
567 
568 inline void
570 {
571  mpz_sqrtrem(&sqrt.rep(), &rem.rep(), &b.rep());
572 }
573 
574 inline void
575 QuoRem (scalar<MPZ>& q, scalar<MPZ>& r, const scalar<MPZ>& divdend, const scalar<MPZ>& divisor)
576 {
577  mpz_mdivmod(&q.rep(), &r.rep(), &divdend.rep(), &divisor.rep());
578 }
579 
580 inline unsigned long
581 QuoRem (scalar<MPZ>& q, scalar<MPZ>& r, const scalar<MPZ>& divdend, unsigned long divisor)
582 {
583  return mpz_mdivmod_ui(&q.rep(), &r.rep(), &divdend.rep(), divisor);
584 }
585 
586 inline void
587 DivMod (scalar<MPZ>& q, scalar<MPZ>& r, const scalar<MPZ>& divdend, const scalar<MPZ>& divisor)
588 {
589  mpz_divmod(&q.rep(), &r.rep(), &divdend.rep(), &divisor.rep());
590 }
591 
592 inline void
593 DivMod (scalar<MPZ>& q, scalar<MPZ>& r, const scalar<MPZ>& divdend, unsigned long divisor)
594 {
595  mpz_divmod_ui(&q.rep(), &r.rep(), &divdend.rep(), divisor);
596 }
597 
598 inline
600  const scalar<MPZ>& x, const scalar<MPZ>& y)
601 {
602  mpz_gcdext(&gcd.rep(), &a.rep(), &b.rep(), &x.rep(), &y.rep());
603 }
604 
605 inline
607  const scalar<MPZ>& x, const scalar<MPZ>& y)
608 {
609  mpz_gcdext(&gcd.rep(), &a.rep(), 0, &x.rep(), &y.rep());
610 }
611 
612 inline unsigned long BigIntToUL (const scalar<MPZ>& b)
613 {
614  return mpz_get_ui(&b.rep());
615 }
616 //-------------------------- BigIntToSL ---------------------------------
617 inline signed long BigIntToSL (const scalar<MPZ>& b)
618 {
619  return mpz_get_si(&b.rep());
620 }
621 //-------------------------- log(...) -----------------------------------
622 inline size_t log (const scalar<MPZ>& b)
623 {
624  return mpz_size(&b.rep());
625 }
626 
627 inline size_t log (const scalar<MPZ>& b, int base)
628 {
629  assert(base >= 2 && base <= 36);
630  return mpz_sizeinbase(&b.rep(), base);
631 }
632 //-------------------------- sign ---------------------------------------------
633 inline int sign (const scalar<MPZ>& b)
634 {
635  if (b.rep()._mp_size == 0)
636  return 0;
637  else
638  return b.rep()._mp_size > 0 ? 1 : -1;
639 }
640 //-------------------------- compare (...) ------------------------------------
641 inline int compare (const scalar<MPZ>& b1, const scalar<MPZ>& b2)
642 {
643  return mpz_cmp(&b1.rep(), &b2.rep());
644 }
645 
646 inline int compare (const scalar<MPZ>& b, unsigned long ul)
647 {
648  return mpz_cmp_ui(&b.rep(), ul);
649 }
650 
651 inline int compare (const scalar<MPZ>& b, long sl)
652 {
653  return mpz_cmp_si(&b.rep(), sl);
654 }
655 //-------------------------- IsPositive etc. ----------------------------------
656 inline bool IsPositive (const scalar<MPZ>& b) {
657  return b.rep()._mp_size > 0;
658 }
659 
660 inline bool IsNegative (const scalar<MPZ>& b) {
661  return b.rep()._mp_size < 0;
662 }
663 
664 inline bool IsZero (const scalar<MPZ>& b) {
665  return b.rep()._mp_size == 0;
666 }
667 
668 inline bool IsOne(const scalar<MPZ>& b) {
669  return b.rep()._mp_size == 1 && b.rep()._mp_d[0] == 1;
670 }
671 
672 inline bool IsMinusOne (const scalar<MPZ>& b) {
673  return b.rep()._mp_size == -1 && b.rep()._mp_d[0] == 1;
674 }
675 
676 inline bool IsOdd (const scalar<MPZ>& b) {
677  return b.rep()._mp_size != 0 && (b.rep()._mp_d[0] & ((mp_limb_t) 1));
678 }
679 
680 inline bool IsEven (const scalar<MPZ>& b) {
681  return b.rep()._mp_size == 0 || (b.rep()._mp_d[0] ^ ((mp_limb_t) 0));
682 }
683 
684 inline bool IsPerfectSquare (const scalar<MPZ>& b)
685 {
686  return mpz_perfect_square_p(&b.rep());
687 }
688 
689 inline bool IsProbablyPrime (const scalar<MPZ>& b, int reps /* = 25 */)
690 {
691  return mpz_probab_prime_p(&b.rep(), reps);
692 }
693 //----------------------------------------------------------------------
694 inline
695 scalar<MPZ> operator << (const scalar<MPZ>& x, long int s) {
696  scalar<MPZ> r;
697  if (s >= 0) mpz_mul_2exp (&r.rep(), &x.rep(), s);
698  else mpz_div_2exp (&r.rep(), &x.rep(), -s);
699  return r;
700 }
701 //----------------------------------------------------------------------
702 inline
703 scalar<MPZ>& operator <<= (scalar<MPZ>& x, long int s)
704 {
705  if (s >= 0) mpz_mul_2exp (&x.rep(), &x.rep(), s);
706  else mpz_div_2exp (&x.rep(), &x.rep(), -s);
707  return x;
708 }
709 
710 inline scalar<MPZ> Size( const scalar<MPZ> & z ) { return abs(z); };
711 
712 inline long int bit_size(const scalar<MPZ>& z) {return mpz_sizeinbase(&z.rep(),2);}
713 
714 inline scalar<MPZ> gcd(const scalar<MPZ> & a, const scalar<MPZ> & b)
715 {
716  scalar<MPZ> r;
717  mpz_gcd(&r.rep(), &a.rep(), &b.rep());
718  return r;
719 }
720 
721 inline scalar<MPZ> lcm(const scalar<MPZ> & a, const scalar<MPZ> & b) { return (a*b)/gcd(a,b); }
722 //--------------------------------------------------------------------
723 inline scalar<MPZ> pow(const scalar<MPZ>& a, unsigned n)
724 {
725  scalar<MPZ> r;
726  mpz_pow_ui(&r.rep(), &a.rep(), n);
727  return r;
728 }
729 
730 inline scalar<MPZ> isqrt(const scalar<MPZ>& a) { return sqrt(a) + 1; }
731 
732 //--------------------------------------------------------------------
733 namespace let
734 {
735  inline void assign(scalar<MPZ>& z, char * s) { mpz_set_str(&z.rep(), s, 10); }
736  inline void assign(scalar<MPZ>& z, int n) { mpz_set_si(&z.rep(),n); }
737  inline void assign(scalar<MPZ>& z, double d ) { z = (int)d; };
738  inline void assign(scalar<MPZ>& x, const scalar<MPZ>& r) { mpz_set(&x.rep(),&r.rep()); }
739  inline void assign(int& x, const scalar<MPZ>& r) { x = mpz_get_si(&r.rep()); }
740  inline void assign(long int& x, const scalar<MPZ>& r) { x = mpz_get_si(&r.rep()); }
741  inline void assign( double & r, const scalar<MPZ> & z ) { r = mpz_get_d(&z.rep()); }
742 
743 }
744 
745 // inline double convert( const scalar<MPZ> & z, meta::As<double> ) { return z.get_d(); };
746 
747  inline double to_double(const scalar<MPZ>& z) { return mpz_get_d(&z.rep()); }
748  inline double as_double(const scalar<MPZ>& z) { return mpz_get_d(&z.rep()); }
749 #ifndef __MMX__DOUBLE_HPP__
750  inline double as_double(const double& d) { return d; }
751 #endif
752  template<typename T,typename F> struct as_helper;
753  template<> struct as_helper<double,scalar<MPZ> > {
754  static inline double cv(const scalar<MPZ>& x) {return mpz_get_d(&x.rep());}
755 };
756 } // namespace mmx
757 //======================================================================
758 #endif // //SCL_MPZ_H
TMPL void rem(POLYNOMIAL &r, const POLYNOMIAL &a, const POLYNOMIAL &b)
Definition: polynomial_operators.hpp:73
bool operator>(const scalar< T > &rhs) const
scalar< T > & operator+=(const scalar< T > &rhs)
scalar()
Definition: scalar.hpp:37
T pow(const T &a, int i)
Definition: binomials.hpp:12
const C & b
Definition: Interval_glue.hpp:25
void DivMod(scalar< MPZ > &q, scalar< MPZ > &r, const scalar< MPZ > &divdend, const scalar< MPZ > &divisor)
Definition: scalar_integer.hpp:587
bool IsNegative(const scalar< MPZ > &b)
Definition: scalar_integer.hpp:660
bool IsPerfectSquare(const scalar< MPZ > &b)
Definition: scalar_integer.hpp:684
scalar< T > & operator=(const scalar< T > &rhs)
bool operator>=(const scalar< T > &rhs) const
QQ Size(const QQ &r)
Definition: GMPXX.hpp:64
Definition: assign.hpp:48
void rem(const scalar< T > &divisor)
double gcd(const double &, const double &)
Definition: GMP.hpp:90
bool IsZero(const scalar< MPZ > &b)
Definition: scalar_integer.hpp:664
T & rep()
Definition: scalar.hpp:30
R & rep(R &r)
Definition: shared_object.hpp:180
signed long BigIntToSL(const scalar< MPZ > &b)
Definition: scalar_integer.hpp:617
scalar< T > & operator%=(const scalar< T > &rhs)
void PowMod(const scalar< T > &exp, const scalar< T > &m)
extended< NT > operator-(const extended< NT > &lhs, const extended< NT > &rhs)
Definition: extended.hpp:132
extended< NT > operator/(const extended< NT > &lhs, const extended< NT > &rhs)
Definition: extended.hpp:111
scalar< T > & pow(unsigned long exp)
scalar< T > & operator-=(const scalar< T > &rhs)
double to_double(const RR &a)
Definition: GMP.hpp:66
int compare(const QQ &a, const QQ &b)
Definition: GMPXX.hpp:71
std::string to_string(int x)
to_string convert int to std::string In C++11, it should use std::to_string
Definition: assign.hpp:24
bool IsEven(const scalar< MPZ > &b)
Definition: scalar_integer.hpp:680
extended< NT > operator+(const extended< NT > &lhs, const extended< NT > &rhs)
Definition: extended.hpp:122
void Mul2Exp(unsigned long exponent_of_2)
bool operator<(const scalar< T > &rhs) const
void quo(const scalar< T > &divisor)
void Mod2Exp(unsigned long exponent_of_2)
bool operator<=(const scalar< T > &rhs) const
bool operator!=(const scalar< T > &rhs) const
unsigned long BigIntToUL(const scalar< MPZ > &b)
Definition: scalar_integer.hpp:612
scalar< T > & operator*=(const scalar< T > &rhs)
long int bit_size(const ZZ &z)
Definition: GMPXX.hpp:32
static double cv(const scalar< MPZ > &x)
Definition: scalar_integer.hpp:754
scalar< T > & negate()
void operator++()
ZZ isqrt(const ZZ &a)
Definition: GMPXX.hpp:104
double rceil(double x)
Definition: scalar.hpp:536
scalar< T > & operator/=(const scalar< T > &rhs)
char * as_charp(const scalar< MPZ > &b)
Definition: scalar_integer.hpp:444
void abs(Interval< C, r > &x, const Interval< C, r > &a)
Definition: Interval_fcts.hpp:185
void print(OSTREAM &os, const Interval< T, r > &a)
Definition: Interval.hpp:135
scalar< T > sqrt(const scalar< T > &b)
Definition: scalar.hpp:501
bool IsPositive(const scalar< MPZ > &b)
Definition: scalar_integer.hpp:656
bool operator==(const scalar< T > &rhs) const
MP_INT MPZ
Definition: scalar_integer.hpp:18
void SqrtRem(scalar< MPZ > &sqrt, scalar< MPZ > &rem, const scalar< MPZ > &b)
Definition: scalar_integer.hpp:569
bool IsMinusOne(const scalar< MPZ > &b)
Definition: scalar_integer.hpp:672
std::istream & operator>>(std::istream &is, scalar< MPF > &b)
Definition: scalar_floating.hpp:453
void factorial(unsigned long n)
void GCD(const scalar< T > &b2)
void operator--()
int sign(const QQ &a)
Definition: GMP.hpp:60
bool IsOdd(const scalar< MPZ > &b)
Definition: scalar_integer.hpp:676
bool IsProbablyPrime(const scalar< MPZ > &b, int reps)
Definition: scalar_integer.hpp:689
void convert(scalar< MPF > &n, char *s)
Definition: scalar_floating.hpp:433
void assign(A &a, const B &b)
Generic definition of the assignement function.
Definition: assign.hpp:97
Definition: array.hpp:12
double rfloor(double x)
Definition: scalar.hpp:535
extended< NT > operator*(const extended< NT > &lhs, const extended< NT > &rhs)
Definition: extended.hpp:101
double as_double(const RR &a)
Definition: GMP.hpp:67
Definition: scalar.hpp:24
size_t log(const scalar< MPF > &b)
Definition: scalar_floating.hpp:506
void Div2Exp(unsigned long exponent_of_2)
void HalfExtGCD(scalar< MPZ > &gcd, scalar< MPZ > &a, const scalar< MPZ > &x, const scalar< MPZ > &y)
Definition: scalar_integer.hpp:606
void ExtGCD(scalar< MPZ > &gcd, scalar< MPZ > &a, scalar< MPZ > &b, const scalar< MPZ > &x, const scalar< MPZ > &y)
Definition: scalar_integer.hpp:599
~scalar()
Definition: scalar.hpp:55
ZZ lcm(const ZZ &a, const ZZ &b)
Definition: GMPXX.hpp:58
void QuoRem(scalar< MPZ > &q, scalar< MPZ > &r, const scalar< MPZ > &divdend, const scalar< MPZ > &divisor)
Definition: scalar_integer.hpp:575
#define assert(expr, msg)
Definition: shared_object.hpp:57
bool IsOne(const scalar< MPZ > &b)
Definition: scalar_integer.hpp:668
Home