1 #ifndef SYMENGINE_FLINT_WRAPPER_H
2 #define SYMENGINE_FLINT_WRAPPER_H
4 #include <symengine/symengine_rcp.h>
7 #include <flint/fmpz.h>
8 #include <flint/fmpq.h>
9 #include <flint/fmpz_poly.h>
10 #include <flint/fmpz_poly_factor.h>
11 #include <flint/fmpq_poly.h>
59 fmpz_set_str(mp, s.
c_str(), base);
64 fmpz_set(mp, other.get_fmpz_t());
69 fmpz_swap(mp, other.get_fmpz_t());
73 fmpz_set(mp, other.get_fmpz_t());
78 fmpz_swap(mp, other.get_fmpz_t());
85 inline fmpz *get_fmpz_t()
89 inline const fmpz *get_fmpz_t()
const
97 fmpz_add(res.get_fmpz_t(), a.get_fmpz_t(), b.get_fmpz_t());
102 fmpz_add(mp, mp, a.get_fmpz_t());
109 fmpz_sub(res.get_fmpz_t(), a.get_fmpz_t(), b.get_fmpz_t());
114 fmpz_sub(mp, mp, a.get_fmpz_t());
120 fmpz_neg(res.get_fmpz_t(), mp);
127 fmpz_mul(res.get_fmpz_t(), a.get_fmpz_t(), b.get_fmpz_t());
132 fmpz_mul(mp, mp, a.get_fmpz_t());
139 fmpz_tdiv_q(res.get_fmpz_t(), a.get_fmpz_t(), b.get_fmpz_t());
144 fmpz_tdiv_q(mp, mp, a.get_fmpz_t());
151 fmpz_tdiv_qr(tmp.get_fmpz_t(), res.get_fmpz_t(), a.get_fmpz_t(),
158 fmpz_tdiv_qr(tmp.get_fmpz_t(), mp, mp, a.get_fmpz_t());
163 fmpz_add_ui(mp, mp, 1);
174 fmpz_sub_ui(mp, mp, 1);
185 return fmpz_equal(a.get_fmpz_t(), b.get_fmpz_t()) == 1;
189 return fmpz_equal(a.get_fmpz_t(), b.get_fmpz_t()) != 1;
193 return fmpz_cmp(a.get_fmpz_t(), b.get_fmpz_t()) < 0;
197 return fmpz_cmp(a.get_fmpz_t(), b.get_fmpz_t()) <= 0;
201 return fmpz_cmp(a.get_fmpz_t(), b.get_fmpz_t()) > 0;
205 return fmpz_cmp(a.get_fmpz_t(), b.get_fmpz_t()) >= 0;
209 fmpz_mul_2exp(mp, mp, u);
215 fmpz_mul_2exp(res.get_fmpz_t(), mp, u);
220 fmpz_tdiv_q_2exp(mp, mp, u);
226 fmpz_tdiv_q_2exp(res.get_fmpz_t(), mp, u);
232 fmpz_root(res.get_fmpz_t(), mp, n);
243 if (!COEFF_IS_MPZ(*i.get_fmpz_t())) {
245 fmpz_get_mpz(m, i.get_fmpz_t());
247 ptr = COEFF_TO_PTR(*i.get_fmpz_t());
250 operator mpz_srcptr()
const
263 mpz_srcptr ptr =
nullptr;
277 const fmpq *get_fmpq_t()
const
288 fmpz_set_mpz(fmpq_numref(mp), m);
293 fmpz_set(fmpq_numref(mp), m);
313 fmpz_set_ui(fmpq_numref(mp), i);
323 fmpz_set_si(fmpq_numref(mp), i);
328 fmpz_set(fmpq_numref(mp), n.get_fmpz_t());
329 fmpz_set(fmpq_denref(mp), d.get_fmpz_t());
330 fmpq_canonicalise(mp);
335 fmpq_set(mp, other.get_fmpq_t());
340 fmpq_swap(mp, other.get_fmpq_t());
344 fmpq_set(mp, other.get_fmpq_t());
349 fmpq_swap(mp, other.get_fmpq_t());
358 fmpq_canonicalise(mp);
362 return reinterpret_cast<const fmpz_wrapper &
>(*fmpq_denref(mp));
366 return reinterpret_cast<const fmpz_wrapper &
>(*fmpq_numref(mp));
370 return reinterpret_cast<fmpz_wrapper &
>(*fmpq_denref(mp));
374 return reinterpret_cast<fmpz_wrapper &
>(*fmpq_numref(mp));
379 fmpq_add(res.get_fmpq_t(), a.get_fmpq_t(), b.get_fmpq_t());
384 fmpq_add(mp, mp, a.get_fmpq_t());
390 fmpq_sub(res.get_fmpq_t(), a.get_fmpq_t(), b.get_fmpq_t());
395 fmpq_sub(mp, mp, a.get_fmpq_t());
401 fmpq_neg(res.get_fmpq_t(), mp);
407 fmpq_mul(res.get_fmpq_t(), a.get_fmpq_t(), b.get_fmpq_t());
412 fmpq_mul(mp, mp, a.get_fmpq_t());
418 fmpq_div(res.get_fmpq_t(), a.get_fmpq_t(), b.get_fmpq_t());
423 fmpq_div(mp, mp, a.get_fmpq_t());
428 return fmpq_equal(mp, other.get_fmpq_t());
432 return not(*
this == other);
436 return fmpq_cmp(mp, other.get_fmpq_t()) < 0;
440 return fmpq_cmp(mp, other.get_fmpq_t()) <= 0;
444 return fmpq_cmp(mp, other.get_fmpq_t()) > 0;
448 return fmpq_cmp(mp, other.get_fmpq_t()) >= 0;
452 return fmpq_is_zero(mp);
456 return fmpq_is_one(mp);
467 fmpq_get_mpq(m, i.get_fmpq_t());
469 operator mpq_srcptr()
const
485 fmpz_poly_factor_t fac;
492 fmpz_poly_factor_init(fac);
496 fmpz_poly_factor_init(fac);
497 fmpz_poly_factor_set(fac, other.get_fmpz_poly_factor_t());
501 fmpz_poly_factor_set(fac, other.get_fmpz_poly_factor_t());
506 fmpz_poly_factor_clear(fac);
509 const fmpz_poly_factor_t &get_fmpz_poly_factor_t()
const
513 fmpz_poly_factor_t &get_fmpz_poly_factor_t()
529 fmpz_poly_init(poly);
533 fmpz_poly_init(poly);
534 fmpz_poly_set_si(poly, i);
538 fmpz_poly_init(poly);
539 fmpz_poly_set_str(poly, cp);
543 fmpz_poly_init(poly);
544 fmpz_poly_set_fmpz(poly, z.get_fmpz_t());
548 fmpz_poly_init(poly);
549 fmpz_poly_set(poly, *other.get_fmpz_poly_t());
553 fmpz_poly_init(poly);
554 fmpz_poly_swap(poly, *other.get_fmpz_poly_t());
558 fmpz_poly_set(poly, *other.get_fmpz_poly_t());
563 fmpz_poly_swap(poly, *other.get_fmpz_poly_t());
566 void swap_fmpz_poly_t(fmpz_poly_struct &other)
568 fmpz_poly_swap(poly, &other);
572 fmpz_poly_clear(poly);
574 const fmpz_poly_t *get_fmpz_poly_t()
const
578 fmpz_poly_t *get_fmpz_poly_t()
584 return fmpz_poly_equal(poly, *other.get_fmpz_poly_t()) == 1;
588 return fmpz_poly_degree(poly);
592 return fmpz_poly_length(poly);
596 return fmpz_poly_get_str(poly);
601 fmpz_poly_get_coeff_fmpz(z.get_fmpz_t(), poly, n);
606 fmpz_poly_set_coeff_fmpz(poly, n, z.get_fmpz_t());
611 fmpz_poly_evaluate_fmpz(r.get_fmpz_t(), poly, z.get_fmpz_t());
614 void eval_vec(fmpz *ovec, fmpz *ivec,
unsigned int n)
const
616 fmpz_poly_evaluate_fmpz_vec(ovec, *get_fmpz_poly_t(), ivec, n);
621 fmpz_poly_neg(*r.get_fmpz_poly_t(), *get_fmpz_poly_t());
626 fmpz_poly_add(*get_fmpz_poly_t(), *get_fmpz_poly_t(),
627 *other.get_fmpz_poly_t());
631 fmpz_poly_sub(*get_fmpz_poly_t(), *get_fmpz_poly_t(),
632 *other.get_fmpz_poly_t());
636 fmpz_poly_mul(*get_fmpz_poly_t(), *get_fmpz_poly_t(),
637 *other.get_fmpz_poly_t());
644 fmpz_poly_mul(*res.get_fmpz_poly_t(), *a.get_fmpz_poly_t(),
645 *b.get_fmpz_poly_t());
652 fmpz_poly_gcd(*r.get_fmpz_poly_t(), poly, *other.get_fmpz_poly_t());
658 fmpz_poly_lcm(*r.get_fmpz_poly_t(), poly, *other.get_fmpz_poly_t());
664 fmpz_poly_pow(*r.get_fmpz_poly_t(), poly, n);
670 return fmpz_poly_divrem(*q.get_fmpz_poly_t(), *r.get_fmpz_poly_t(),
671 *get_fmpz_poly_t(), *b.get_fmpz_poly_t());
676 #if __FLINT_RELEASE > 20502
677 fmpz_poly_factor(r.get_fmpz_poly_factor_t(), poly);
680 "FLINT's Version must be higher than 2.5.2 to obtain factors");
687 fmpz_poly_derivative(*r.get_fmpz_poly_t(), poly);
702 fmpq_poly_init(poly);
706 fmpq_poly_init(poly);
707 fmpq_poly_set_si(poly, i);
711 fmpq_poly_init(poly);
712 fmpq_poly_set_str(poly, cp);
717 fmpq_poly_init(poly);
718 fmpq_poly_set_fmpz(poly, fz.get_fmpz_t());
723 fmpq_poly_init(poly);
724 fmpq_poly_set_fmpq(poly, fq.get_fmpq_t());
728 fmpq_poly_init(poly);
729 fmpq_poly_set_fmpq(poly, q.get_fmpq_t());
733 fmpq_poly_init(poly);
734 fmpq_poly_set(poly, *other.get_fmpq_poly_t());
738 fmpq_poly_init(poly);
739 fmpq_poly_swap(poly, *other.get_fmpq_poly_t());
743 fmpq_poly_set(poly, *other.get_fmpq_poly_t());
748 fmpq_poly_swap(poly, *other.get_fmpq_poly_t());
753 fmpq_poly_clear(poly);
756 const fmpq_poly_t *get_fmpq_poly_t()
const
760 fmpq_poly_t *get_fmpq_poly_t()
766 return fmpq_poly_get_str(poly);
770 return fmpq_poly_degree(poly);
774 return fmpq_poly_length(poly);
778 fmpq_poly_set_coeff_fmpq(poly, n, z.get_fmpq_t());
783 fmpq_poly_evaluate_fmpq(r.get_fmpq_t(), poly, z.get_fmpq_t());
789 fmpq_poly_get_coeff_fmpq(q.get_fmpq_t(), poly, deg);
794 unsigned int prec)
const
797 fmpq_poly_mullow(*r.get_fmpq_poly_t(), poly, *o.get_fmpq_poly_t(),
804 fmpq_poly_pow(*r.get_fmpq_poly_t(), poly, n);
810 fmpq_poly_derivative(*r.get_fmpq_poly_t(), poly);
816 fmpq_poly_integral(*r.get_fmpq_poly_t(), poly);
823 fmpq_poly_inv_series(*r.get_fmpq_poly_t(), poly, prec);
829 fmpq_poly_revert_series(*r.get_fmpq_poly_t(), poly, prec);
835 fmpq_poly_log_series(*r.get_fmpq_poly_t(), poly, prec);
841 fmpq_poly_exp_series(*r.get_fmpq_poly_t(), poly, prec);
847 fmpq_poly_sin_series(*r.get_fmpq_poly_t(), poly, prec);
853 fmpq_poly_cos_series(*r.get_fmpq_poly_t(), poly, prec);
859 fmpq_poly_tan_series(*r.get_fmpq_poly_t(), poly, prec);
865 fmpq_poly_asin_series(*r.get_fmpq_poly_t(), poly, prec);
871 fmpq_poly_atan_series(*r.get_fmpq_poly_t(), poly, prec);
877 fmpq_poly_sinh_series(*r.get_fmpq_poly_t(), poly, prec);
883 fmpq_poly_cosh_series(*r.get_fmpq_poly_t(), poly, prec);
889 fmpq_poly_tanh_series(*r.get_fmpq_poly_t(), poly, prec);
895 fmpq_poly_asinh_series(*r.get_fmpq_poly_t(), poly, prec);
901 fmpq_poly_atanh_series(*r.get_fmpq_poly_t(), poly, prec);
907 fmpq_poly_compose_series(*r.get_fmpq_poly_t(), poly,
908 *o.get_fmpq_poly_t(), prec);
913 fmpq_poly_zero(poly);
922 return fmpq_poly_equal(poly, *o.get_fmpq_poly_t()) != 0;
926 return fmpq_poly_cmp(poly, *o.get_fmpq_poly_t()) == -1;
933 fmpq_poly_add(*r.get_fmpq_poly_t(), *a.get_fmpq_poly_t(),
934 *o.get_fmpq_poly_t());
941 fmpq_poly_sub(*r.get_fmpq_poly_t(), *a.get_fmpq_poly_t(),
942 *o.get_fmpq_poly_t());
948 fmpq_poly_neg(*r.get_fmpq_poly_t(), *get_fmpq_poly_t());
955 fmpq_poly_scalar_mul_fmpq(*r.get_fmpq_poly_t(), *a.get_fmpq_poly_t(),
963 fmpq_poly_mul(*r.get_fmpq_poly_t(), *a.get_fmpq_poly_t(),
964 *o.get_fmpq_poly_t());
971 fmpq_poly_scalar_div_fmpq(*r.get_fmpq_poly_t(), *a.get_fmpq_poly_t(),
978 return fmpq_poly_divrem(*q.get_fmpq_poly_t(), *r.get_fmpq_poly_t(),
979 *get_fmpq_poly_t(), *b.get_fmpq_poly_t());
985 fmpq_poly_gcd(*r.get_fmpq_poly_t(), poly, *other.get_fmpq_poly_t());
991 fmpq_poly_lcm(*r.get_fmpq_poly_t(), poly, *other.get_fmpq_poly_t());
996 fmpq_poly_add(poly, poly, *o.get_fmpq_poly_t());
1000 fmpq_poly_sub(poly, poly, *o.get_fmpq_poly_t());
1004 fmpq_poly_mul(poly, poly, *o.get_fmpq_poly_t());
Main namespace for SymEngine package.