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())) {
244 mpz_init_set_si(m, *i.get_fmpz_t());
246 ptr = COEFF_TO_PTR(*i.get_fmpz_t());
249 operator mpz_srcptr()
const
262 mpz_srcptr ptr =
nullptr;
276 const fmpq *get_fmpq_t()
const
287 fmpz_set_mpz(fmpq_numref(mp), m);
292 fmpz_set(fmpq_numref(mp), m);
312 fmpz_set_ui(fmpq_numref(mp), i);
322 fmpz_set_si(fmpq_numref(mp), i);
327 fmpz_set(fmpq_numref(mp), n.get_fmpz_t());
328 fmpz_set(fmpq_denref(mp), d.get_fmpz_t());
329 fmpq_canonicalise(mp);
334 fmpq_set(mp, other.get_fmpq_t());
339 fmpq_swap(mp, other.get_fmpq_t());
343 fmpq_set(mp, other.get_fmpq_t());
348 fmpq_swap(mp, other.get_fmpq_t());
357 fmpq_canonicalise(mp);
361 return reinterpret_cast<const fmpz_wrapper &
>(*fmpq_denref(mp));
365 return reinterpret_cast<const fmpz_wrapper &
>(*fmpq_numref(mp));
369 return reinterpret_cast<fmpz_wrapper &
>(*fmpq_denref(mp));
373 return reinterpret_cast<fmpz_wrapper &
>(*fmpq_numref(mp));
378 fmpq_add(res.get_fmpq_t(), a.get_fmpq_t(), b.get_fmpq_t());
383 fmpq_add(mp, mp, a.get_fmpq_t());
389 fmpq_sub(res.get_fmpq_t(), a.get_fmpq_t(), b.get_fmpq_t());
394 fmpq_sub(mp, mp, a.get_fmpq_t());
400 fmpq_neg(res.get_fmpq_t(), mp);
406 fmpq_mul(res.get_fmpq_t(), a.get_fmpq_t(), b.get_fmpq_t());
411 fmpq_mul(mp, mp, a.get_fmpq_t());
417 fmpq_div(res.get_fmpq_t(), a.get_fmpq_t(), b.get_fmpq_t());
422 fmpq_div(mp, mp, a.get_fmpq_t());
427 return fmpq_equal(mp, other.get_fmpq_t());
431 return not(*
this == other);
435 return fmpq_cmp(mp, other.get_fmpq_t()) < 0;
439 return fmpq_cmp(mp, other.get_fmpq_t()) <= 0;
443 return fmpq_cmp(mp, other.get_fmpq_t()) > 0;
447 return fmpq_cmp(mp, other.get_fmpq_t()) >= 0;
451 return fmpq_is_zero(mp);
455 return fmpq_is_one(mp);
466 fmpq_get_mpq(m, i.get_fmpq_t());
468 operator mpq_srcptr()
const
484 fmpz_poly_factor_t fac;
491 fmpz_poly_factor_init(fac);
495 fmpz_poly_factor_init(fac);
496 fmpz_poly_factor_set(fac, other.get_fmpz_poly_factor_t());
500 fmpz_poly_factor_set(fac, other.get_fmpz_poly_factor_t());
505 fmpz_poly_factor_clear(fac);
508 const fmpz_poly_factor_t &get_fmpz_poly_factor_t()
const
512 fmpz_poly_factor_t &get_fmpz_poly_factor_t()
528 fmpz_poly_init(poly);
532 fmpz_poly_init(poly);
533 fmpz_poly_set_si(poly, i);
537 fmpz_poly_init(poly);
538 fmpz_poly_set_str(poly, cp);
542 fmpz_poly_init(poly);
543 fmpz_poly_set_fmpz(poly, z.get_fmpz_t());
547 fmpz_poly_init(poly);
548 fmpz_poly_set(poly, *other.get_fmpz_poly_t());
552 fmpz_poly_init(poly);
553 fmpz_poly_swap(poly, *other.get_fmpz_poly_t());
557 fmpz_poly_set(poly, *other.get_fmpz_poly_t());
562 fmpz_poly_swap(poly, *other.get_fmpz_poly_t());
565 void swap_fmpz_poly_t(fmpz_poly_struct &other)
567 fmpz_poly_swap(poly, &other);
571 fmpz_poly_clear(poly);
573 const fmpz_poly_t *get_fmpz_poly_t()
const
577 fmpz_poly_t *get_fmpz_poly_t()
583 return fmpz_poly_equal(poly, *other.get_fmpz_poly_t()) == 1;
587 return fmpz_poly_degree(poly);
591 return fmpz_poly_length(poly);
595 return fmpz_poly_get_str(poly);
600 fmpz_poly_get_coeff_fmpz(z.get_fmpz_t(), poly, n);
605 fmpz_poly_set_coeff_fmpz(poly, n, z.get_fmpz_t());
610 fmpz_poly_evaluate_fmpz(r.get_fmpz_t(), poly, z.get_fmpz_t());
613 void eval_vec(fmpz *ovec, fmpz *ivec,
unsigned int n)
const
615 fmpz_poly_evaluate_fmpz_vec(ovec, *get_fmpz_poly_t(), ivec, n);
620 fmpz_poly_neg(*r.get_fmpz_poly_t(), *get_fmpz_poly_t());
625 fmpz_poly_add(*get_fmpz_poly_t(), *get_fmpz_poly_t(),
626 *other.get_fmpz_poly_t());
630 fmpz_poly_sub(*get_fmpz_poly_t(), *get_fmpz_poly_t(),
631 *other.get_fmpz_poly_t());
635 fmpz_poly_mul(*get_fmpz_poly_t(), *get_fmpz_poly_t(),
636 *other.get_fmpz_poly_t());
643 fmpz_poly_mul(*res.get_fmpz_poly_t(), *a.get_fmpz_poly_t(),
644 *b.get_fmpz_poly_t());
651 fmpz_poly_gcd(*r.get_fmpz_poly_t(), poly, *other.get_fmpz_poly_t());
657 fmpz_poly_lcm(*r.get_fmpz_poly_t(), poly, *other.get_fmpz_poly_t());
663 fmpz_poly_pow(*r.get_fmpz_poly_t(), poly, n);
669 return fmpz_poly_divrem(*q.get_fmpz_poly_t(), *r.get_fmpz_poly_t(),
670 *get_fmpz_poly_t(), *b.get_fmpz_poly_t());
675 #if __FLINT_RELEASE > 20502
676 fmpz_poly_factor(r.get_fmpz_poly_factor_t(), poly);
679 "FLINT's Version must be higher than 2.5.2 to obtain factors");
686 fmpz_poly_derivative(*r.get_fmpz_poly_t(), poly);
701 fmpq_poly_init(poly);
705 fmpq_poly_init(poly);
706 fmpq_poly_set_si(poly, i);
710 fmpq_poly_init(poly);
711 fmpq_poly_set_str(poly, cp);
716 fmpq_poly_init(poly);
717 fmpq_poly_set_fmpz(poly, fz.get_fmpz_t());
722 fmpq_poly_init(poly);
723 fmpq_poly_set_fmpq(poly, fq.get_fmpq_t());
727 fmpq_poly_init(poly);
728 fmpq_poly_set_fmpq(poly, q.get_fmpq_t());
732 fmpq_poly_init(poly);
733 fmpq_poly_set(poly, *other.get_fmpq_poly_t());
737 fmpq_poly_init(poly);
738 fmpq_poly_swap(poly, *other.get_fmpq_poly_t());
742 fmpq_poly_set(poly, *other.get_fmpq_poly_t());
747 fmpq_poly_swap(poly, *other.get_fmpq_poly_t());
752 fmpq_poly_clear(poly);
755 const fmpq_poly_t *get_fmpq_poly_t()
const
759 fmpq_poly_t *get_fmpq_poly_t()
765 return fmpq_poly_get_str(poly);
769 return fmpq_poly_degree(poly);
773 return fmpq_poly_length(poly);
777 fmpq_poly_set_coeff_fmpq(poly, n, z.get_fmpq_t());
782 fmpq_poly_evaluate_fmpq(r.get_fmpq_t(), poly, z.get_fmpq_t());
788 fmpq_poly_get_coeff_fmpq(q.get_fmpq_t(), poly, deg);
793 unsigned int prec)
const
796 fmpq_poly_mullow(*r.get_fmpq_poly_t(), poly, *o.get_fmpq_poly_t(),
803 fmpq_poly_pow(*r.get_fmpq_poly_t(), poly, n);
809 fmpq_poly_derivative(*r.get_fmpq_poly_t(), poly);
815 fmpq_poly_integral(*r.get_fmpq_poly_t(), poly);
822 fmpq_poly_inv_series(*r.get_fmpq_poly_t(), poly, prec);
828 fmpq_poly_revert_series(*r.get_fmpq_poly_t(), poly, prec);
834 fmpq_poly_log_series(*r.get_fmpq_poly_t(), poly, prec);
840 fmpq_poly_exp_series(*r.get_fmpq_poly_t(), poly, prec);
846 fmpq_poly_sin_series(*r.get_fmpq_poly_t(), poly, prec);
852 fmpq_poly_cos_series(*r.get_fmpq_poly_t(), poly, prec);
858 fmpq_poly_tan_series(*r.get_fmpq_poly_t(), poly, prec);
864 fmpq_poly_asin_series(*r.get_fmpq_poly_t(), poly, prec);
870 fmpq_poly_atan_series(*r.get_fmpq_poly_t(), poly, prec);
876 fmpq_poly_sinh_series(*r.get_fmpq_poly_t(), poly, prec);
882 fmpq_poly_cosh_series(*r.get_fmpq_poly_t(), poly, prec);
888 fmpq_poly_tanh_series(*r.get_fmpq_poly_t(), poly, prec);
894 fmpq_poly_asinh_series(*r.get_fmpq_poly_t(), poly, prec);
900 fmpq_poly_atanh_series(*r.get_fmpq_poly_t(), poly, prec);
906 fmpq_poly_compose_series(*r.get_fmpq_poly_t(), poly,
907 *o.get_fmpq_poly_t(), prec);
912 fmpq_poly_zero(poly);
921 return fmpq_poly_equal(poly, *o.get_fmpq_poly_t()) != 0;
925 return fmpq_poly_cmp(poly, *o.get_fmpq_poly_t()) == -1;
932 fmpq_poly_add(*r.get_fmpq_poly_t(), *a.get_fmpq_poly_t(),
933 *o.get_fmpq_poly_t());
940 fmpq_poly_sub(*r.get_fmpq_poly_t(), *a.get_fmpq_poly_t(),
941 *o.get_fmpq_poly_t());
947 fmpq_poly_neg(*r.get_fmpq_poly_t(), *get_fmpq_poly_t());
954 fmpq_poly_scalar_mul_fmpq(*r.get_fmpq_poly_t(), *a.get_fmpq_poly_t(),
962 fmpq_poly_mul(*r.get_fmpq_poly_t(), *a.get_fmpq_poly_t(),
963 *o.get_fmpq_poly_t());
970 fmpq_poly_scalar_div_fmpq(*r.get_fmpq_poly_t(), *a.get_fmpq_poly_t(),
977 return fmpq_poly_divrem(*q.get_fmpq_poly_t(), *r.get_fmpq_poly_t(),
978 *get_fmpq_poly_t(), *b.get_fmpq_poly_t());
984 fmpq_poly_gcd(*r.get_fmpq_poly_t(), poly, *other.get_fmpq_poly_t());
990 fmpq_poly_lcm(*r.get_fmpq_poly_t(), poly, *other.get_fmpq_poly_t());
995 fmpq_poly_add(poly, poly, *o.get_fmpq_poly_t());
999 fmpq_poly_sub(poly, poly, *o.get_fmpq_poly_t());
1003 fmpq_poly_mul(poly, poly, *o.get_fmpq_poly_t());
Main namespace for SymEngine package.