1 #ifndef SYMENGINE_INTEGER_CLASS_H
2 #define SYMENGINE_INTEGER_CLASS_H
4 #include <symengine/symengine_config.h>
5 #include <symengine/symengine_casts.h>
7 #if SYMENGINE_INTEGER_CLASS != SYMENGINE_BOOSTMP
8 #include <symengine/mp_wrapper.h>
11 #if SYMENGINE_INTEGER_CLASS == SYMENGINE_BOOSTMP
12 #include <boost/multiprecision/cpp_int.hpp>
13 #include <boost/random/mersenne_twister.hpp>
14 #include <boost/random/uniform_int.hpp>
15 #include <symengine/symengine_rcp.h>
17 #elif SYMENGINE_INTEGER_CLASS == SYMENGINE_PIRANHA
18 #include <piranha/mp_integer.hpp>
19 #include <piranha/mp_rational.hpp>
20 #elif SYMENGINE_INTEGER_CLASS == SYMENGINE_GMPXX
21 #define __GMPXX_USE_CXX11 1
51 #if SYMENGINE_INTEGER_CLASS == SYMENGINE_BOOSTMP
52 typedef boost::multiprecision::number<boost::multiprecision::cpp_int_backend<>,
53 boost::multiprecision::et_off>
55 typedef boost::multiprecision::number<
56 boost::multiprecision::cpp_rational_backend, boost::multiprecision::et_off>
58 #elif SYMENGINE_INTEGER_CLASS == SYMENGINE_PIRANHA
61 #elif SYMENGINE_INTEGER_CLASS == SYMENGINE_FLINT
62 typedef fmpz_wrapper integer_class;
63 typedef fmpq_wrapper rational_class;
64 #elif SYMENGINE_INTEGER_CLASS == SYMENGINE_GMP
65 typedef mpz_wrapper integer_class;
66 typedef mpq_wrapper rational_class;
67 #elif SYMENGINE_INTEGER_CLASS == SYMENGINE_GMPXX
68 typedef mpz_class integer_class;
69 typedef mpq_class rational_class;
74 inline namespace literals
77 inline integer_class
operator"" _z(
const char *str)
79 return integer_class(str);
82 inline rational_class
operator"" _q(
const char *str)
84 return rational_class(integer_class(str));
88 #if SYMENGINE_INTEGER_CLASS == SYMENGINE_GMPXX \
89 || SYMENGINE_INTEGER_CLASS == SYMENGINE_GMP
91 inline integer_class mp_abs(
const integer_class &i)
94 mpz_abs(res.get_mpz_t(), i.get_mpz_t());
98 inline int mp_sign(
const integer_class &i)
100 return mpz_sgn(i.get_mpz_t());
103 inline integer_class mp_sqrt(
const integer_class &i)
106 mpz_sqrt(res.get_mpz_t(), i.get_mpz_t());
110 inline double mp_get_d(
const integer_class &i)
112 return static_cast<double>(i.get_d());
115 inline void mp_set_d(integer_class &i,
double a)
117 mpz_set_d(i.get_mpz_t(), a);
120 inline void mp_set_str(integer_class &i,
const std::string &a)
122 mpz_set_str(i.get_mpz_t(), a.
c_str(), 0);
125 inline std::string mp_get_hex_str(
const integer_class &i)
127 void (*freefunc)(
void *, size_t);
128 mp_get_memory_functions(NULL, NULL, &freefunc);
129 char *c = mpz_get_str(NULL, 16, i.get_mpz_t());
131 freefunc(c,
strlen(c) + 1);
135 inline void mp_demote(integer_class &i) {}
137 inline bool mp_fits_ulong_p(
const integer_class &i)
139 return i.fits_ulong_p() != 0;
142 inline bool mp_fits_slong_p(
const integer_class &i)
144 return i.fits_slong_p() != 0;
147 inline unsigned long mp_get_ui(
const integer_class &i)
152 inline long mp_get_si(
const integer_class &i)
157 inline mpz_srcptr get_mpz_t(
const integer_class &i)
159 return i.get_mpz_t();
162 inline mpz_ptr get_mpz_t(integer_class &i)
164 return i.get_mpz_t();
167 inline void mp_pow_ui(integer_class &res,
const integer_class &i,
170 mpz_pow_ui(res.get_mpz_t(), i.get_mpz_t(), n);
173 inline void mp_pow_ui(rational_class &res,
const rational_class &i,
176 mpz_pow_ui(res.get_num().get_mpz_t(), i.get_num().get_mpz_t(), n);
177 mpz_pow_ui(res.get_den().get_mpz_t(), i.get_den().get_mpz_t(), n);
180 inline void mp_powm(integer_class &res,
const integer_class &a,
181 const integer_class &b,
const integer_class &m)
183 mpz_powm(res.get_mpz_t(), a.get_mpz_t(), b.get_mpz_t(), m.get_mpz_t());
186 inline bool mp_invert(integer_class &res,
const integer_class &a,
187 const integer_class &m)
189 return mpz_invert(res.get_mpz_t(), a.get_mpz_t(), m.get_mpz_t()) != 0;
192 inline void mp_gcd(integer_class &res,
const integer_class &a,
193 const integer_class &b)
195 mpz_gcd(res.get_mpz_t(), a.get_mpz_t(), b.get_mpz_t());
198 inline void mp_gcdext(integer_class &res, integer_class &r, integer_class &s,
199 const integer_class &a,
const integer_class &b)
201 mpz_gcdext(res.get_mpz_t(), r.get_mpz_t(), s.get_mpz_t(), a.get_mpz_t(),
205 inline void mp_and(integer_class &res,
const integer_class &a,
206 const integer_class &b)
208 mpz_and(res.get_mpz_t(), a.get_mpz_t(), b.get_mpz_t());
211 inline void mp_fdiv_r(integer_class &res,
const integer_class &a,
212 const integer_class &b)
214 mpz_fdiv_r(res.get_mpz_t(), a.get_mpz_t(), b.get_mpz_t());
217 inline void mp_fdiv_q(integer_class &res,
const integer_class &a,
218 const integer_class &b)
220 mpz_fdiv_q(res.get_mpz_t(), a.get_mpz_t(), b.get_mpz_t());
223 inline void mp_cdiv_q(integer_class &res,
const integer_class &a,
224 const integer_class &b)
226 mpz_cdiv_q(res.get_mpz_t(), a.get_mpz_t(), b.get_mpz_t());
229 inline void mp_tdiv_q(integer_class &res,
const integer_class &a,
230 const integer_class &b)
232 mpz_tdiv_q(res.get_mpz_t(), a.get_mpz_t(), b.get_mpz_t());
235 inline void mp_fdiv_qr(integer_class &q, integer_class &r,
236 const integer_class &a,
const integer_class &b)
238 mpz_fdiv_qr(q.get_mpz_t(), r.get_mpz_t(), a.get_mpz_t(), b.get_mpz_t());
241 inline void mp_divexact(integer_class &q,
const integer_class &a,
242 const integer_class &b)
244 mpz_divexact(q.get_mpz_t(), a.get_mpz_t(), b.get_mpz_t());
247 inline void mp_lcm(integer_class &q,
const integer_class &a,
248 const integer_class &b)
250 mpz_lcm(q.get_mpz_t(), a.get_mpz_t(), b.get_mpz_t());
253 inline void mp_tdiv_qr(integer_class &q, integer_class &r,
254 const integer_class &a,
const integer_class &b)
256 mpz_tdiv_qr(q.get_mpz_t(), r.get_mpz_t(), a.get_mpz_t(), b.get_mpz_t());
259 inline void mp_addmul(integer_class &r,
const integer_class &a,
260 const integer_class &b)
262 mpz_addmul(r.get_mpz_t(), a.get_mpz_t(), b.get_mpz_t());
266 inline const integer_class &get_den(
const rational_class &i)
271 inline const integer_class &get_num(
const rational_class &i)
276 inline integer_class &get_den(rational_class &i)
281 inline integer_class &get_num(rational_class &i)
286 inline mpq_srcptr get_mpq_t(
const rational_class &i)
288 return i.get_mpq_t();
291 inline void canonicalize(rational_class &i)
296 inline double mp_get_d(
const rational_class &i)
301 inline int mp_sign(
const rational_class &i)
303 return mpq_sgn(i.get_mpq_t());
306 inline rational_class mp_abs(
const rational_class &i)
309 mpq_abs(res.get_mpq_t(), i.get_mpq_t());
313 inline integer_class mp_primorial(
unsigned long n)
316 mpz_primorial_ui(res.get_mpz_t(), n);
320 #elif SYMENGINE_INTEGER_CLASS == SYMENGINE_PIRANHA
336 return i._get_mpz_ptr();
339 inline auto get_mpz_t(
const piranha::integer &i) -> decltype(i.get_mpz_view())
341 return i.get_mpz_view();
359 auto _res = get_mpz_t(res);
360 mpz_powm(_res, get_mpz_t(a), get_mpz_t(b), get_mpz_t(m));
366 auto _res = get_mpz_t(res);
367 return mpz_invert(_res, get_mpz_t(a), get_mpz_t(m)) != 0;
373 piranha::integer::gcd(g, a, b);
380 auto _g = get_mpz_t(g);
381 auto _r = get_mpz_t(r);
382 auto _s = get_mpz_t(s);
383 mpz_gcdext(_g, _r, _s, get_mpz_t(a), get_mpz_t(b));
389 auto _res = get_mpz_t(res);
390 mpz_and(_res, get_mpz_t(a), get_mpz_t(b));
396 auto _res = get_mpz_t(res);
397 mpz_fdiv_r(_res, get_mpz_t(a), get_mpz_t(b));
403 auto _res = get_mpz_t(res);
404 mpz_fdiv_q(_res, get_mpz_t(a), get_mpz_t(b));
410 auto _res = get_mpz_t(res);
411 mpz_cdiv_q(_res, get_mpz_t(a), get_mpz_t(b));
417 auto _res = get_mpz_t(res);
418 mpz_tdiv_q(_res, get_mpz_t(a), get_mpz_t(b));
424 auto _q = get_mpz_t(q);
425 mpz_fdiv_qr(_q, get_mpz_t(r), get_mpz_t(a), get_mpz_t(b));
431 piranha::integer::_divexact(q, a, b);
437 auto _q = get_mpz_t(q);
438 mpz_lcm(_q, get_mpz_t(a), get_mpz_t(b));
444 piranha::integer::divrem(q, r, a, b);
454 return mpz_get_si(i.get_mpz_view());
459 return mpz_get_ui(i.get_mpz_view());
464 return mpz_get_d(i.get_mpz_view());
472 inline void mp_set_str(integer_class &i,
const std::string &a)
476 mpz_set_str(m, a.
c_str(), 0);
477 i = integer_class(m);
480 inline std::string mp_get_hex_str(
const integer_class &i)
483 void (*freefunc)(
void *, size_t);
484 mp_get_memory_functions(NULL, NULL, &freefunc);
485 char *c = mpz_get_str(NULL, 16, i.get_mpz_view());
487 freefunc(c,
strlen(c) + 1);
493 return mpz_fits_ulong_p(i.get_mpz_view()) != 0;
498 return mpz_fits_slong_p(i.get_mpz_view()) != 0;
501 inline void mp_addmul(integer_class &r,
const integer_class &a,
502 const integer_class &b)
504 piranha::math::multiply_accumulate(r, a, b);
507 inline integer_class mp_primorial(
unsigned long n)
510 mpz_primorial_ui(get_mpz_t(res), n);
548 return mpq_get_d(i.get_mpq_view().get());
553 return i.get_mpq_view();
558 return i.num().sign();
560 #elif SYMENGINE_INTEGER_CLASS == SYMENGINE_FLINT
564 inline mpz_view_flint get_mpz_t(
const fmpz_wrapper &i)
566 return mpz_view_flint(i);
569 inline mpz_ptr get_mpz_t(fmpz_wrapper &i)
571 return _fmpz_promote_val(i.get_fmpz_t());
574 inline void mp_demote(fmpz_wrapper &i)
576 _fmpz_demote_val(i.get_fmpz_t());
579 inline int mp_sign(
const fmpz_wrapper &i)
581 return fmpz_sgn(i.get_fmpz_t());
584 inline long mp_get_si(
const fmpz_wrapper &i)
586 return fmpz_get_si(i.get_fmpz_t());
589 inline unsigned long mp_get_ui(
const fmpz_wrapper &i)
591 return fmpz_get_ui(i.get_fmpz_t());
594 inline bool mp_fits_slong_p(
const fmpz_wrapper &i)
596 return fmpz_fits_si(i.get_fmpz_t());
599 inline bool mp_fits_ulong_p(
const fmpz_wrapper &i)
601 return fmpz_sgn(i.get_fmpz_t()) >= 0 && fmpz_abs_fits_ui(i.get_fmpz_t());
604 inline double mp_get_d(
const fmpz_wrapper &i)
606 return fmpz_get_d(i.get_fmpz_t());
609 inline void mp_set_d(fmpz_wrapper &i,
double a)
611 return fmpz_set_d(i.get_fmpz_t(), a);
614 inline void mp_set_str(fmpz_wrapper &i,
const std::string &a)
616 fmpz_set_str(i.get_fmpz_t(), a.
c_str(), 0);
619 inline std::string mp_get_hex_str(
const fmpz_wrapper &i)
621 void (*freefunc)(
void *, size_t);
622 mp_get_memory_functions(NULL, NULL, &freefunc);
623 char *c = fmpz_get_str(NULL, 16, i.get_fmpz_t());
625 freefunc(c,
strlen(c) + 1);
629 inline fmpz_wrapper mp_abs(
const fmpz_wrapper &i)
632 fmpz_abs(res.get_fmpz_t(), i.get_fmpz_t());
636 inline fmpz_wrapper mp_sqrt(
const fmpz_wrapper &i)
639 fmpz_sqrt(res.get_fmpz_t(), i.get_fmpz_t());
643 inline void mp_pow_ui(fmpz_wrapper &res,
const fmpz_wrapper &i,
unsigned long n)
645 fmpz_pow_ui(res.get_fmpz_t(), i.get_fmpz_t(), n);
648 inline void mp_pow_ui(fmpq_wrapper &res,
const fmpq_wrapper &i,
unsigned long n)
650 fmpq_pow_si(res.get_fmpq_t(), i.get_fmpq_t(), n);
653 inline void mp_powm(fmpz_wrapper &res,
const fmpz_wrapper &a,
654 const fmpz_wrapper &b,
const fmpz_wrapper &m)
657 fmpz_powm(res.get_fmpz_t(), a.get_fmpz_t(), b.get_fmpz_t(),
660 fmpz_neg(res.get_fmpz_t(), b.get_fmpz_t());
661 fmpz_powm(res.get_fmpz_t(), a.get_fmpz_t(), res.get_fmpz_t(),
663 fmpz_invmod(res.get_fmpz_t(), res.get_fmpz_t(), m.get_fmpz_t());
667 inline bool mp_invert(fmpz_wrapper &res,
const fmpz_wrapper &a,
668 const fmpz_wrapper &m)
670 return fmpz_invmod(res.get_fmpz_t(), a.get_fmpz_t(), m.get_fmpz_t()) != 0;
673 inline void mp_gcd(fmpz_wrapper &res,
const fmpz_wrapper &a,
674 const fmpz_wrapper &b)
676 fmpz_gcd(res.get_fmpz_t(), a.get_fmpz_t(), b.get_fmpz_t());
679 inline void mp_gcdext(fmpz_wrapper &g, fmpz_wrapper &r, fmpz_wrapper &s,
680 const fmpz_wrapper &a,
const fmpz_wrapper &b)
682 fmpz_xgcd(g.get_fmpz_t(), r.get_fmpz_t(), s.get_fmpz_t(), a.get_fmpz_t(),
686 inline void mp_and(fmpz_wrapper &res,
const fmpz_wrapper &a,
687 const fmpz_wrapper &b)
689 fmpz_and(res.get_fmpz_t(), a.get_fmpz_t(), b.get_fmpz_t());
692 inline void mp_fdiv_r(fmpz_wrapper &res,
const fmpz_wrapper &a,
693 const fmpz_wrapper &b)
695 fmpz_fdiv_r(res.get_fmpz_t(), a.get_fmpz_t(), b.get_fmpz_t());
698 inline void mp_fdiv_q(fmpz_wrapper &res,
const fmpz_wrapper &a,
699 const fmpz_wrapper &b)
701 fmpz_fdiv_q(res.get_fmpz_t(), a.get_fmpz_t(), b.get_fmpz_t());
704 inline void mp_cdiv_q(fmpz_wrapper &res,
const fmpz_wrapper &a,
705 const fmpz_wrapper &b)
707 fmpz_cdiv_q(res.get_fmpz_t(), a.get_fmpz_t(), b.get_fmpz_t());
710 inline void mp_tdiv_q(fmpz_wrapper &res,
const fmpz_wrapper &a,
711 const fmpz_wrapper &b)
713 fmpz_tdiv_q(res.get_fmpz_t(), a.get_fmpz_t(), b.get_fmpz_t());
716 inline void mp_fdiv_qr(fmpz_wrapper &q, fmpz_wrapper &r,
const fmpz_wrapper &a,
717 const fmpz_wrapper &b)
719 fmpz_fdiv_qr(q.get_fmpz_t(), r.get_fmpz_t(), a.get_fmpz_t(),
723 inline void mp_divexact(fmpz_wrapper &q,
const fmpz_wrapper &a,
724 const fmpz_wrapper &b)
726 fmpz_divexact(q.get_fmpz_t(), a.get_fmpz_t(), b.get_fmpz_t());
729 inline void mp_lcm(fmpz_wrapper &q,
const fmpz_wrapper &a,
730 const fmpz_wrapper &b)
732 fmpz_lcm(q.get_fmpz_t(), a.get_fmpz_t(), b.get_fmpz_t());
735 inline void mp_tdiv_qr(fmpz_wrapper &q, fmpz_wrapper &r,
const fmpz_wrapper &a,
736 const fmpz_wrapper &b)
738 fmpz_tdiv_qr(q.get_fmpz_t(), r.get_fmpz_t(), a.get_fmpz_t(),
742 inline void mp_addmul(fmpz_wrapper &r,
const fmpz_wrapper &a,
743 const fmpz_wrapper &b)
745 fmpz_addmul(r.get_fmpz_t(), a.get_fmpz_t(), b.get_fmpz_t());
748 inline integer_class mp_primorial(
unsigned long n)
751 fmpz_primorial(res.get_fmpz_t(), n);
757 inline const fmpz_wrapper &get_den(
const fmpq_wrapper &i)
762 inline const fmpz_wrapper &get_num(
const fmpq_wrapper &i)
767 inline fmpz_wrapper &get_den(fmpq_wrapper &i)
772 inline fmpz_wrapper &get_num(fmpq_wrapper &i)
777 inline mpq_view_flint get_mpq_t(
const fmpq_wrapper &i)
779 return mpq_view_flint(i);
782 inline void canonicalize(fmpq_wrapper &i)
784 fmpq_canonicalise(i.get_fmpq_t());
787 inline double mp_get_d(
const fmpq_wrapper &i)
789 return mp_get_d(i.get_num()) / mp_get_d(i.get_den());
792 inline int mp_sign(
const fmpq_wrapper &i)
794 return fmpq_sgn(i.get_fmpq_t());
797 inline fmpq_wrapper mp_abs(
const fmpq_wrapper &i)
800 fmpq_abs(res.get_fmpq_t(), i.get_fmpq_t());
804 #elif SYMENGINE_INTEGER_CLASS == SYMENGINE_BOOSTMP
806 inline integer_class mp_abs(
const integer_class &i)
811 return boost::multiprecision::abs(i);
814 inline int mp_cmpabs(
const integer_class &a,
const integer_class &b)
816 if (mp_abs(a) > mp_abs(b)) {
819 if (mp_abs(a) == mp_abs(b)) {
825 inline int mp_sign(
const integer_class &i)
827 return boost::math::sign(i);
830 inline double mp_get_d(
const integer_class &i)
832 return i.convert_to<
double>();
835 inline void mp_set_d(integer_class &i,
double a)
840 inline void mp_set_str(integer_class &i,
const std::string &a)
842 i = integer_class(a.
c_str());
845 inline std::string mp_get_hex_str(
const integer_class &i)
847 if (mp_sign(i) >= 0) {
848 return i.str(0, std::ios_base::hex);
850 return std::string(
"-") + (-i).str(0, std::ios_base::hex);
854 inline unsigned long mp_get_ui(
const integer_class &i)
856 return mp_abs(i).convert_to<
unsigned long>();
859 inline long mp_get_si(
const integer_class &i)
861 return i.convert_to<
long>();
864 inline bool mp_fits_ulong_p(
const integer_class &i)
866 return (i >= 0) && (i <= ULONG_MAX);
869 inline bool mp_fits_slong_p(
const integer_class &i)
871 return (i >= LONG_MIN) && (i <= LONG_MAX);
875 inline void mp_and(integer_class &res,
const integer_class &a,
876 const integer_class &b)
878 res = boost::multiprecision::operator&(a, b);
881 inline void mp_pow_ui(integer_class &res,
const integer_class &i,
884 res = boost::multiprecision::pow(i, numeric_cast<unsigned>(n));
887 inline void mp_gcd(integer_class &res,
const integer_class &a,
888 const integer_class &b)
890 res = boost::multiprecision::gcd(a, b);
893 void mp_fdiv_qr(integer_class &q, integer_class &r,
const integer_class &a,
894 const integer_class &b);
896 void mp_cdiv_qr(integer_class &q, integer_class &r,
const integer_class &a,
897 const integer_class &b);
899 inline void mp_fdiv_r(integer_class &res,
const integer_class &a,
900 const integer_class &b)
904 mp_fdiv_qr(quo, res, a, b);
907 inline void mp_fdiv_q(integer_class &res,
const integer_class &a,
908 const integer_class &b)
912 mp_fdiv_qr(res, rem, a, b);
915 inline void mp_cdiv_q(integer_class &res,
const integer_class &a,
916 const integer_class &b)
920 mp_cdiv_qr(res, rem, a, b);
923 inline void mp_tdiv_qr(integer_class &q, integer_class &r,
924 const integer_class &a,
const integer_class &b)
926 boost::multiprecision::divide_qr(a, b, q, r);
929 inline void mp_tdiv_q(integer_class &res,
const integer_class &a,
930 const integer_class &b)
933 mp_tdiv_qr(res, rem, a, b);
936 inline void mp_divexact(integer_class &q,
const integer_class &a,
937 const integer_class &b)
943 inline void mp_lcm(integer_class &q,
const integer_class &a,
944 const integer_class &b)
946 q = boost::multiprecision::lcm(a, b);
949 inline void mp_addmul(integer_class &r,
const integer_class &a,
950 const integer_class &b)
958 inline const integer_class get_den(
const rational_class &i)
960 return boost::multiprecision::denominator(i);
963 inline const integer_class get_num(
const rational_class &i)
965 return boost::multiprecision::numerator(i);
968 inline void canonicalize(rational_class &i)
976 inline double mp_get_d(
const rational_class &i)
978 return i.convert_to<
double>();
981 inline int mp_sign(
const rational_class &i)
986 inline rational_class mp_abs(
const rational_class &i)
988 return boost::multiprecision::abs(i);
991 inline bool mp_divisible_p(
const integer_class &a,
const integer_class &b)
999 void mp_pow_ui(rational_class &res,
const rational_class &i,
unsigned long n);
1001 void mp_powm(integer_class &res,
const integer_class &a,
const integer_class &b,
1002 const integer_class &m);
1009 void mp_gcdext(integer_class &
gcd, integer_class &s, integer_class &t,
1010 const integer_class &a,
const integer_class &b);
1012 bool mp_invert(integer_class &res,
const integer_class &a,
1013 const integer_class &m);
1015 bool mp_root(integer_class &res,
const integer_class &i,
unsigned long n);
1017 integer_class mp_sqrt(
const integer_class &i);
1019 void mp_rootrem(integer_class &a, integer_class &b,
const integer_class &i,
1022 void mp_sqrtrem(integer_class &a, integer_class &b,
const integer_class &i);
1024 int mp_probab_prime_p(
const integer_class &i,
unsigned retries);
1026 void mp_nextprime(integer_class &res,
const integer_class &i);
1028 unsigned long mp_scan1(
const integer_class &i);
1030 void mp_fib_ui(integer_class &res,
unsigned long n);
1032 void mp_fib2_ui(integer_class &a, integer_class &b,
unsigned long n);
1034 void mp_lucnum_ui(integer_class &res,
unsigned long n);
1036 void mp_lucnum2_ui(integer_class &a, integer_class &b,
unsigned long n);
1038 void mp_fac_ui(integer_class &res,
unsigned long n);
1040 void mp_bin_ui(integer_class &res,
const integer_class &n,
unsigned long r);
1042 bool mp_perfect_power_p(
const integer_class &i);
1044 bool mp_perfect_square_p(
const integer_class &i);
1046 int mp_legendre(
const integer_class &a,
const integer_class &n);
1048 int mp_jacobi(
const integer_class &a,
const integer_class &n);
1050 int mp_kronecker(
const integer_class &a,
const integer_class &n);
1052 integer_class mp_primorial(
unsigned long n);
1059 void urandomint(integer_class &res,
const integer_class &a)
1061 boost::random::uniform_int_distribution<integer_class> ui(0, a);
1065 void seed(
const uint32_t &i)
1071 boost::random::mt19937 _twister;
1082 #if SYMENGINE_INTEGER_CLASS == SYMENGINE_PIRANHA \
1083 || SYMENGINE_INTEGER_CLASS == SYMENGINE_FLINT \
1084 || SYMENGINE_INTEGER_CLASS == SYMENGINE_GMP \
1085 || SYMENGINE_INTEGER_CLASS == SYMENGINE_GMPXX
1087 inline bool mp_root(integer_class &res,
const integer_class &i,
unsigned long n)
1089 auto _res = get_mpz_t(res);
1090 int ret = mpz_root(_res, get_mpz_t(i), n);
1095 inline void mp_nextprime(integer_class &res,
const integer_class &i)
1097 auto _res = get_mpz_t(res);
1098 mpz_nextprime(_res, get_mpz_t(i));
1102 inline void mp_sqrtrem(integer_class &a, integer_class &b,
1103 const integer_class &i)
1105 auto _a = get_mpz_t(a);
1106 auto _b = get_mpz_t(b);
1107 mpz_sqrtrem(_a, _b, get_mpz_t(i));
1112 inline void mp_rootrem(integer_class &a, integer_class &b,
1113 const integer_class &i,
unsigned long n)
1115 auto _a = get_mpz_t(a);
1116 auto _b = get_mpz_t(b);
1117 mpz_rootrem(_a, _b, get_mpz_t(i), n);
1122 inline unsigned long mp_scan1(
const integer_class &i)
1124 return mpz_scan1(get_mpz_t(i), 0);
1127 inline void mp_fib_ui(integer_class &res,
unsigned long n)
1129 mpz_fib_ui(get_mpz_t(res), n);
1133 inline void mp_fib2_ui(integer_class &a, integer_class &b,
unsigned long n)
1135 mpz_fib2_ui(get_mpz_t(a), get_mpz_t(b), n);
1140 inline void mp_lucnum_ui(integer_class &res,
unsigned long n)
1142 mpz_lucnum_ui(get_mpz_t(res), n);
1146 inline void mp_lucnum2_ui(integer_class &a, integer_class &b,
unsigned long n)
1148 mpz_lucnum2_ui(get_mpz_t(a), get_mpz_t(b), n);
1153 inline void mp_bin_ui(integer_class &res,
const integer_class &n,
1156 auto _res = get_mpz_t(res);
1157 mpz_bin_ui(_res, get_mpz_t(n), r);
1161 inline void mp_fac_ui(integer_class &res,
unsigned long n)
1163 mpz_fac_ui(get_mpz_t(res), n);
1167 inline int mp_legendre(
const integer_class &a,
const integer_class &n)
1169 return mpz_legendre(get_mpz_t(a), get_mpz_t(n));
1172 inline int mp_kronecker(
const integer_class &a,
const integer_class &n)
1174 return mpz_kronecker(get_mpz_t(a), get_mpz_t(n));
1177 inline int mp_jacobi(
const integer_class &a,
const integer_class &n)
1179 return mpz_jacobi(get_mpz_t(a), get_mpz_t(n));
1182 inline bool mp_perfect_power_p(
const integer_class &i)
1184 return mpz_perfect_power_p(get_mpz_t(i)) != 0;
1187 inline bool mp_perfect_square_p(
const integer_class &i)
1189 return mpz_perfect_square_p(get_mpz_t(i)) != 0;
1192 inline int mp_probab_prime_p(
const integer_class &i,
unsigned retries)
1194 return mpz_probab_prime_p(get_mpz_t(i), retries);
1197 inline bool mp_divisible_p(
const integer_class &a,
const integer_class &b)
1199 return mpz_divisible_p(get_mpz_t(a), get_mpz_t(b)) != 0;
1202 inline void mp_urandomm(integer_class &a, gmp_randstate_t &t,
1203 const integer_class &b)
1205 auto _a = get_mpz_t(a);
1206 mpz_urandomm(_a, t, get_mpz_t(b));
1210 inline auto get_mp_t(
const integer_class &x) -> decltype(get_mpz_t(x))
1212 return get_mpz_t(x);
1215 inline auto get_mp_t(
const rational_class &x) -> decltype(get_mpq_t(x))
1217 return get_mpq_t(x);
1220 inline int mp_cmpabs(
const integer_class &a,
const integer_class &b)
1222 return mpz_cmpabs(get_mpz_t(a), get_mpz_t(b));
1230 void urandomint(integer_class &res,
const integer_class &a)
1232 mpz_urandomm(get_mpz_t(res), _state, get_mpz_t(a));
1236 void seed(
const integer_class &i)
1238 gmp_randseed(_state, get_mpz_t(i));
1243 gmp_randinit_default(_state);
1249 gmp_randclear(_state);
1253 gmp_randstate_t _state;
1260 #if !defined(HAVE_SYMENGINE_GMP) && defined(HAVE_SYMENGINE_BOOST) \
1261 && BOOST_VERSION < 105900
1267 struct make_unsigned_imp<
SymEngine::integer_class> {
1268 typedef SymEngine::integer_class type;
Main namespace for SymEngine package.
std::enable_if< std::is_integral< T >::value, RCP< const Integer > >::type integer(T i)
RCP< const Integer > gcd(const Integer &a, const Integer &b)
Greatest Common Divisor.
RCP< const Number > rational(long n, long d)
convenience creator from two longs