Loading...
Searching...
No Matches
flint_wrapper.h
1#ifndef SYMENGINE_FLINT_WRAPPER_H
2#define SYMENGINE_FLINT_WRAPPER_H
3
4#include <symengine/symengine_rcp.h>
5#include <gmp.h>
6
7#include <flint/fmpz.h>
8#include <flint/fmpq.h>
9#include <flint/fmpq_poly.h>
10
11namespace SymEngine
12{
13
15{
16private:
17 fmpz_t mp;
18
19public:
20 template <
21 typename T,
22 typename std::enable_if<
24 = 0>
25 inline fmpz_wrapper(const T i)
26 {
27 fmpz_init(mp);
28 fmpz_set_ui(mp, i);
29 }
30 template <
31 typename T,
32 typename std::enable_if<
34 = 0>
35 inline fmpz_wrapper(const T i)
36 {
37 fmpz_init(mp);
38 fmpz_set_si(mp, i);
39 }
40 inline fmpz_wrapper()
41 {
42 fmpz_init(mp);
43 }
44 inline fmpz_wrapper(const mpz_t m)
45 {
46 fmpz_init(mp);
47 fmpz_set_mpz(mp, m);
48 }
49 inline fmpz_wrapper(const fmpz_t m)
50 {
51 fmpz_init(mp);
52 fmpz_set(mp, m);
53 }
54 inline fmpz_wrapper(const std::string &s, unsigned base = 10)
55 {
56 fmpz_init(mp);
57 fmpz_set_str(mp, s.c_str(), base);
58 }
59 inline fmpz_wrapper(const fmpz_wrapper &other)
60 {
61 fmpz_init(mp);
62 fmpz_set(mp, other.get_fmpz_t());
63 }
64 inline fmpz_wrapper(fmpz_wrapper &&other) SYMENGINE_NOEXCEPT
65 {
66 fmpz_init(mp);
67 fmpz_swap(mp, other.get_fmpz_t());
68 }
69 inline fmpz_wrapper &operator=(const fmpz_wrapper &other)
70 {
71 fmpz_set(mp, other.get_fmpz_t());
72 return *this;
73 }
74 inline fmpz_wrapper &operator=(fmpz_wrapper &&other) SYMENGINE_NOEXCEPT
75 {
76 fmpz_swap(mp, other.get_fmpz_t());
77 return *this;
78 }
79 inline ~fmpz_wrapper() SYMENGINE_NOEXCEPT
80 {
81 fmpz_clear(mp);
82 }
83 inline fmpz *get_fmpz_t()
84 {
85 return mp;
86 }
87 inline const fmpz *get_fmpz_t() const
88 {
89 return mp;
90 }
91 inline friend fmpz_wrapper operator+(const fmpz_wrapper &a,
92 const fmpz_wrapper &b)
93 {
94 fmpz_wrapper res;
95 fmpz_add(res.get_fmpz_t(), a.get_fmpz_t(), b.get_fmpz_t());
96 return res;
97 }
98 inline fmpz_wrapper operator+=(const fmpz_wrapper &a)
99 {
100 fmpz_add(mp, mp, a.get_fmpz_t());
101 return *this;
102 }
103 inline friend fmpz_wrapper operator-(const fmpz_wrapper &a,
104 const fmpz_wrapper &b)
105 {
106 fmpz_wrapper res;
107 fmpz_sub(res.get_fmpz_t(), a.get_fmpz_t(), b.get_fmpz_t());
108 return res;
109 }
110 inline fmpz_wrapper operator-=(const fmpz_wrapper &a)
111 {
112 fmpz_sub(mp, mp, a.get_fmpz_t());
113 return *this;
114 }
115 inline fmpz_wrapper operator-() const
116 {
117 fmpz_wrapper res;
118 fmpz_neg(res.get_fmpz_t(), mp);
119 return res;
120 }
121 inline friend fmpz_wrapper operator*(const fmpz_wrapper &a,
122 const fmpz_wrapper &b)
123 {
124 fmpz_wrapper res;
125 fmpz_mul(res.get_fmpz_t(), a.get_fmpz_t(), b.get_fmpz_t());
126 return res;
127 }
128 inline fmpz_wrapper operator*=(const fmpz_wrapper &a)
129 {
130 fmpz_mul(mp, mp, a.get_fmpz_t());
131 return *this;
132 }
133 inline friend fmpz_wrapper operator/(const fmpz_wrapper &a,
134 const fmpz_wrapper &b)
135 {
136 fmpz_wrapper res;
137 fmpz_tdiv_q(res.get_fmpz_t(), a.get_fmpz_t(), b.get_fmpz_t());
138 return res;
139 }
140 inline fmpz_wrapper operator/=(const fmpz_wrapper &a)
141 {
142 fmpz_tdiv_q(mp, mp, a.get_fmpz_t());
143 return *this;
144 }
145 inline friend fmpz_wrapper operator%(const fmpz_wrapper &a,
146 const fmpz_wrapper &b)
147 {
148 fmpz_wrapper res, tmp;
149 fmpz_tdiv_qr(tmp.get_fmpz_t(), res.get_fmpz_t(), a.get_fmpz_t(),
150 b.get_fmpz_t());
151 return res;
152 }
153 inline fmpz_wrapper operator%=(const fmpz_wrapper &a)
154 {
155 fmpz_wrapper tmp;
156 fmpz_tdiv_qr(tmp.get_fmpz_t(), mp, mp, a.get_fmpz_t());
157 return *this;
158 }
159 inline fmpz_wrapper operator++()
160 {
161 fmpz_add_ui(mp, mp, 1);
162 return *this;
163 }
164 inline fmpz_wrapper operator++(int)
165 {
166 fmpz_wrapper orig = *this;
167 ++(*this);
168 return orig;
169 }
170 inline fmpz_wrapper operator--()
171 {
172 fmpz_sub_ui(mp, mp, 1);
173 return *this;
174 }
175 inline fmpz_wrapper operator--(int)
176 {
177 fmpz_wrapper orig = *this;
178 --(*this);
179 return orig;
180 }
181 inline friend bool operator==(const fmpz_wrapper &a, const fmpz_wrapper &b)
182 {
183 return fmpz_equal(a.get_fmpz_t(), b.get_fmpz_t()) == 1;
184 }
185 inline friend bool operator!=(const fmpz_wrapper &a, const fmpz_wrapper &b)
186 {
187 return fmpz_equal(a.get_fmpz_t(), b.get_fmpz_t()) != 1;
188 }
189 inline friend bool operator<(const fmpz_wrapper &a, const fmpz_wrapper &b)
190 {
191 return fmpz_cmp(a.get_fmpz_t(), b.get_fmpz_t()) < 0;
192 }
193 inline friend bool operator<=(const fmpz_wrapper &a, const fmpz_wrapper &b)
194 {
195 return fmpz_cmp(a.get_fmpz_t(), b.get_fmpz_t()) <= 0;
196 }
197 inline friend bool operator>(const fmpz_wrapper &a, const fmpz_wrapper &b)
198 {
199 return fmpz_cmp(a.get_fmpz_t(), b.get_fmpz_t()) > 0;
200 }
201 inline friend bool operator>=(const fmpz_wrapper &a, const fmpz_wrapper &b)
202 {
203 return fmpz_cmp(a.get_fmpz_t(), b.get_fmpz_t()) >= 0;
204 }
205 inline fmpz_wrapper operator<<=(unsigned long u)
206 {
207 fmpz_mul_2exp(mp, mp, u);
208 return *this;
209 }
210 inline fmpz_wrapper operator<<(unsigned long u) const
211 {
212 fmpz_wrapper res;
213 fmpz_mul_2exp(res.get_fmpz_t(), mp, u);
214 return res;
215 }
216 inline fmpz_wrapper operator>>=(unsigned long u)
217 {
218 fmpz_tdiv_q_2exp(mp, mp, u);
219 return *this;
220 }
221 inline fmpz_wrapper operator>>(unsigned long u) const
222 {
223 fmpz_wrapper res;
224 fmpz_tdiv_q_2exp(res.get_fmpz_t(), mp, u);
225 return res;
226 }
227 inline fmpz_wrapper root(unsigned int n) const
228 {
229 fmpz_wrapper res;
230 fmpz_root(res.get_fmpz_t(), mp, n);
231 return res;
232 }
233};
234
236{
237
238public:
240 {
241 if (!COEFF_IS_MPZ(*i.get_fmpz_t())) {
242 mpz_init_set_si(m, *i.get_fmpz_t());
243 } else {
244 ptr = COEFF_TO_PTR(*i.get_fmpz_t());
245 }
246 }
247 operator mpz_srcptr() const
248 {
249 if (ptr == nullptr)
250 return m;
251 return ptr;
252 }
254 {
255 if (ptr == nullptr)
256 mpz_clear(m);
257 }
258
259private:
260 mpz_srcptr ptr = nullptr;
261 mpz_t m;
262};
263
265{
266private:
267 fmpq_t mp;
268
269public:
270 fmpq *get_fmpq_t()
271 {
272 return mp;
273 }
274 const fmpq *get_fmpq_t() const
275 {
276 return mp;
277 }
279 {
280 fmpq_init(mp);
281 }
282 fmpq_wrapper(const mpz_t m)
283 {
284 fmpq_init(mp);
285 fmpz_set_mpz(fmpq_numref(mp), m);
286 }
287 fmpq_wrapper(const fmpz_t m)
288 {
289 fmpq_init(mp);
290 fmpz_set(fmpq_numref(mp), m);
291 }
292 fmpq_wrapper(const mpq_t m)
293 {
294 fmpq_init(mp);
295 fmpq_set_mpq(mp, m);
296 }
297 fmpq_wrapper(const fmpq_t m)
298 {
299 fmpq_init(mp);
300 fmpq_set(mp, m);
301 }
302 template <
303 typename T,
304 typename std::enable_if<
306 = 0>
307 fmpq_wrapper(const T i)
308 {
309 fmpq_init(mp);
310 fmpz_set_ui(fmpq_numref(mp), i);
311 }
312 template <
313 typename T,
314 typename std::enable_if<
316 = 0>
317 fmpq_wrapper(const T i)
318 {
319 fmpq_init(mp);
320 fmpz_set_si(fmpq_numref(mp), i);
321 }
322 fmpq_wrapper(const fmpz_wrapper &n, const fmpz_wrapper &d = 1)
323 {
324 fmpq_init(mp);
325 fmpz_set(fmpq_numref(mp), n.get_fmpz_t());
326 fmpz_set(fmpq_denref(mp), d.get_fmpz_t());
327 fmpq_canonicalise(mp);
328 }
329 fmpq_wrapper(const fmpq_wrapper &other)
330 {
331 fmpq_init(mp);
332 fmpq_set(mp, other.get_fmpq_t());
333 }
334 fmpq_wrapper(fmpq_wrapper &&other) SYMENGINE_NOEXCEPT
335 {
336 fmpq_init(mp);
337 fmpq_swap(mp, other.get_fmpq_t());
338 }
339 fmpq_wrapper &operator=(const fmpq_wrapper &other)
340 {
341 fmpq_set(mp, other.get_fmpq_t());
342 return *this;
343 }
344 fmpq_wrapper &operator=(fmpq_wrapper &&other) SYMENGINE_NOEXCEPT
345 {
346 fmpq_swap(mp, other.get_fmpq_t());
347 return *this;
348 }
349 ~fmpq_wrapper() SYMENGINE_NOEXCEPT
350 {
351 fmpq_clear(mp);
352 }
353 void canonicalise()
354 {
355 fmpq_canonicalise(mp);
356 }
357 const fmpz_wrapper &get_den() const
358 {
359 return reinterpret_cast<const fmpz_wrapper &>(*fmpq_denref(mp));
360 }
361 const fmpz_wrapper &get_num() const
362 {
363 return reinterpret_cast<const fmpz_wrapper &>(*fmpq_numref(mp));
364 }
365 fmpz_wrapper &get_den()
366 {
367 return reinterpret_cast<fmpz_wrapper &>(*fmpq_denref(mp));
368 }
369 fmpz_wrapper &get_num()
370 {
371 return reinterpret_cast<fmpz_wrapper &>(*fmpq_numref(mp));
372 }
373 friend fmpq_wrapper operator+(const fmpq_wrapper &a, const fmpq_wrapper &b)
374 {
375 fmpq_wrapper res;
376 fmpq_add(res.get_fmpq_t(), a.get_fmpq_t(), b.get_fmpq_t());
377 return res;
378 }
379 fmpq_wrapper operator+=(const fmpq_wrapper &a)
380 {
381 fmpq_add(mp, mp, a.get_fmpq_t());
382 return *this;
383 }
384 friend fmpq_wrapper operator-(const fmpq_wrapper &a, const fmpq_wrapper &b)
385 {
386 fmpq_wrapper res;
387 fmpq_sub(res.get_fmpq_t(), a.get_fmpq_t(), b.get_fmpq_t());
388 return res;
389 }
390 fmpq_wrapper operator-=(const fmpq_wrapper &a)
391 {
392 fmpq_sub(mp, mp, a.get_fmpq_t());
393 return *this;
394 }
395 fmpq_wrapper operator-() const
396 {
397 fmpq_wrapper res;
398 fmpq_neg(res.get_fmpq_t(), mp);
399 return res;
400 }
401 friend fmpq_wrapper operator*(const fmpq_wrapper &a, const fmpq_wrapper &b)
402 {
403 fmpq_wrapper res;
404 fmpq_mul(res.get_fmpq_t(), a.get_fmpq_t(), b.get_fmpq_t());
405 return res;
406 }
407 fmpq_wrapper operator*=(const fmpq_wrapper &a)
408 {
409 fmpq_mul(mp, mp, a.get_fmpq_t());
410 return *this;
411 }
412 friend fmpq_wrapper operator/(const fmpq_wrapper &a, const fmpq_wrapper &b)
413 {
414 fmpq_wrapper res;
415 fmpq_div(res.get_fmpq_t(), a.get_fmpq_t(), b.get_fmpq_t());
416 return res;
417 }
418 fmpq_wrapper operator/=(const fmpq_wrapper &a)
419 {
420 fmpq_div(mp, mp, a.get_fmpq_t());
421 return *this;
422 }
423 bool operator==(const fmpq_wrapper &other) const
424 {
425 return fmpq_equal(mp, other.get_fmpq_t());
426 }
427 bool operator!=(const fmpq_wrapper &other) const
428 {
429 return not(*this == other);
430 }
431 bool operator<(const fmpq_wrapper &other) const
432 {
433 return fmpq_cmp(mp, other.get_fmpq_t()) < 0;
434 }
435 bool operator<=(const fmpq_wrapper &other) const
436 {
437 return fmpq_cmp(mp, other.get_fmpq_t()) <= 0;
438 }
439 bool operator>(const fmpq_wrapper &other) const
440 {
441 return fmpq_cmp(mp, other.get_fmpq_t()) > 0;
442 }
443 bool operator>=(const fmpq_wrapper &other) const
444 {
445 return fmpq_cmp(mp, other.get_fmpq_t()) >= 0;
446 }
447 bool is_zero() const
448 {
449 return fmpq_is_zero(mp);
450 }
451 bool is_one() const
452 {
453 return fmpq_is_one(mp);
454 }
455};
456
458{
459
460public:
462 {
463 mpq_init(m);
464 fmpq_get_mpq(m, i.get_fmpq_t());
465 }
466 operator mpq_srcptr() const
467 {
468 return m;
469 }
471 {
472 mpq_clear(m);
473 }
474
475private:
476 mpq_t m;
477};
478
480{
481private:
482 fmpz_poly_factor_t fac;
483
484public:
486
488 {
489 fmpz_poly_factor_init(fac);
490 }
492 {
493 fmpz_poly_factor_init(fac);
494 fmpz_poly_factor_set(fac, other.get_fmpz_poly_factor_t());
495 }
497 {
498 fmpz_poly_factor_set(fac, other.get_fmpz_poly_factor_t());
499 return *this;
500 }
502 {
503 fmpz_poly_factor_clear(fac);
504 }
505
506 const fmpz_poly_factor_t &get_fmpz_poly_factor_t() const
507 {
508 return fac;
509 }
510 fmpz_poly_factor_t &get_fmpz_poly_factor_t()
511 {
512 return fac;
513 }
514};
515
517{
518private:
519 fmpz_poly_t poly;
520
521public:
523
525 {
526 fmpz_poly_init(poly);
527 }
528 fmpz_poly_wrapper(int i)
529 {
530 fmpz_poly_init(poly);
531 fmpz_poly_set_si(poly, i);
532 }
533 fmpz_poly_wrapper(const char *cp)
534 {
535 fmpz_poly_init(poly);
536 fmpz_poly_set_str(poly, cp);
537 }
539 {
540 fmpz_poly_init(poly);
541 fmpz_poly_set_fmpz(poly, z.get_fmpz_t());
542 }
544 {
545 fmpz_poly_init(poly);
546 fmpz_poly_set(poly, *other.get_fmpz_poly_t());
547 }
549 {
550 fmpz_poly_init(poly);
551 fmpz_poly_swap(poly, *other.get_fmpz_poly_t());
552 }
553 fmpz_poly_wrapper &operator=(const fmpz_poly_wrapper &other)
554 {
555 fmpz_poly_set(poly, *other.get_fmpz_poly_t());
556 return *this;
557 }
558 fmpz_poly_wrapper &operator=(fmpz_poly_wrapper &&other)
559 {
560 fmpz_poly_swap(poly, *other.get_fmpz_poly_t());
561 return *this;
562 }
563 void swap_fmpz_poly_t(fmpz_poly_struct &other)
564 {
565 fmpz_poly_swap(poly, &other);
566 }
568 {
569 fmpz_poly_clear(poly);
570 }
571 const fmpz_poly_t *get_fmpz_poly_t() const
572 {
573 return &poly;
574 }
575 fmpz_poly_t *get_fmpz_poly_t()
576 {
577 return &poly;
578 }
579 bool operator==(const fmpz_poly_wrapper &other) const
580 {
581 return fmpz_poly_equal(poly, *other.get_fmpz_poly_t()) == 1;
582 }
583 long degree() const
584 {
585 return fmpz_poly_degree(poly);
586 }
587 long length() const
588 {
589 return fmpz_poly_length(poly);
590 }
591 std::string to_string() const
592 {
593 return fmpz_poly_get_str(poly);
594 }
595 fmpz_wrapper get_coeff(unsigned int n) const
596 {
597 fmpz_wrapper z;
598 fmpz_poly_get_coeff_fmpz(z.get_fmpz_t(), poly, n);
599 return z;
600 }
601 void set_coeff(unsigned int n, const fmpz_wrapper &z)
602 {
603 fmpz_poly_set_coeff_fmpz(poly, n, z.get_fmpz_t());
604 }
605 fmpz_wrapper eval(const fmpz_wrapper &z) const
606 {
607 fmpz_wrapper r;
608 fmpz_poly_evaluate_fmpz(r.get_fmpz_t(), poly, z.get_fmpz_t());
609 return r;
610 }
611 void eval_vec(fmpz *ovec, fmpz *ivec, unsigned int n) const
612 {
613 fmpz_poly_evaluate_fmpz_vec(ovec, *get_fmpz_poly_t(), ivec, n);
614 }
615 fmpz_poly_wrapper operator-() const
616 {
618 fmpz_poly_neg(*r.get_fmpz_poly_t(), *get_fmpz_poly_t());
619 return r;
620 }
621 void operator+=(const fmpz_poly_wrapper &other)
622 {
623 fmpz_poly_add(*get_fmpz_poly_t(), *get_fmpz_poly_t(),
624 *other.get_fmpz_poly_t());
625 }
626 void operator-=(const fmpz_poly_wrapper &other)
627 {
628 fmpz_poly_sub(*get_fmpz_poly_t(), *get_fmpz_poly_t(),
629 *other.get_fmpz_poly_t());
630 }
631 void operator*=(const fmpz_poly_wrapper &other)
632 {
633 fmpz_poly_mul(*get_fmpz_poly_t(), *get_fmpz_poly_t(),
634 *other.get_fmpz_poly_t());
635 }
636
637 friend fmpz_poly_wrapper operator*(const fmpz_poly_wrapper &a,
638 const fmpz_poly_wrapper &b)
639 {
641 fmpz_poly_mul(*res.get_fmpz_poly_t(), *a.get_fmpz_poly_t(),
642 *b.get_fmpz_poly_t());
643 return res;
644 }
645
646 fmpz_poly_wrapper gcd(const fmpz_poly_wrapper &other) const
647 {
649 fmpz_poly_gcd(*r.get_fmpz_poly_t(), poly, *other.get_fmpz_poly_t());
650 return r;
651 }
652 fmpz_poly_wrapper lcm(const fmpz_poly_wrapper &other) const
653 {
655 fmpz_poly_lcm(*r.get_fmpz_poly_t(), poly, *other.get_fmpz_poly_t());
656 return r;
657 }
658 fmpz_poly_wrapper pow(unsigned int n) const
659 {
661 fmpz_poly_pow(*r.get_fmpz_poly_t(), poly, n);
662 return r;
663 }
664 void divrem(fmpz_poly_wrapper &q, fmpz_poly_wrapper &r,
665 const fmpz_poly_wrapper &b) const
666 {
667 return fmpz_poly_divrem(*q.get_fmpz_poly_t(), *r.get_fmpz_poly_t(),
668 *get_fmpz_poly_t(), *b.get_fmpz_poly_t());
669 }
670 fmpz_poly_factor_wrapper factors() const
671 {
673#if __FLINT_RELEASE > 20502
674 fmpz_poly_factor(r.get_fmpz_poly_factor_t(), poly);
675#else
676 throw std::runtime_error(
677 "FLINT's Version must be higher than 2.5.2 to obtain factors");
678#endif
679 return r;
680 }
681 fmpz_poly_wrapper derivative() const
682 {
684 fmpz_poly_derivative(*r.get_fmpz_poly_t(), poly);
685 return r;
686 }
687};
688
690{
691private:
692 fmpq_poly_t poly;
693
694public:
696
698 {
699 fmpq_poly_init(poly);
700 }
701 fmpq_poly_wrapper(int i)
702 {
703 fmpq_poly_init(poly);
704 fmpq_poly_set_si(poly, i);
705 }
706 fmpq_poly_wrapper(const char *cp)
707 {
708 fmpq_poly_init(poly);
709 fmpq_poly_set_str(poly, cp);
710 }
711 fmpq_poly_wrapper(const mpz_t z)
712 {
713 fmpq_poly_init(poly);
714 fmpq_poly_set_mpz(poly, z);
715 }
716 fmpq_poly_wrapper(const mpq_t q)
717 {
718 fmpq_poly_init(poly);
719 fmpq_poly_set_mpq(poly, q);
720 }
722 {
723 fmpq_poly_init(poly);
724 fmpq_poly_set_fmpq(poly, q.get_fmpq_t());
725 }
727 {
728 fmpq_poly_init(poly);
729 fmpq_poly_set(poly, *other.get_fmpq_poly_t());
730 }
732 {
733 fmpq_poly_init(poly);
734 fmpq_poly_swap(poly, *other.get_fmpq_poly_t());
735 }
736 fmpq_poly_wrapper &operator=(const fmpq_poly_wrapper &other)
737 {
738 fmpq_poly_set(poly, *other.get_fmpq_poly_t());
739 return *this;
740 }
741 fmpq_poly_wrapper &operator=(fmpq_poly_wrapper &&other)
742 {
743 fmpq_poly_swap(poly, *other.get_fmpq_poly_t());
744 return *this;
745 }
747 {
748 fmpq_poly_clear(poly);
749 }
750
751 const fmpq_poly_t *get_fmpq_poly_t() const
752 {
753 return &poly;
754 }
755 fmpq_poly_t *get_fmpq_poly_t()
756 {
757 return &poly;
758 }
759 std::string to_string() const
760 {
761 return fmpq_poly_get_str(poly);
762 }
763 long degree() const
764 {
765 return fmpq_poly_degree(poly);
766 }
767 long length() const
768 {
769 return fmpq_poly_length(poly);
770 }
771 void set_coeff(unsigned int n, const fmpq_wrapper &z)
772 {
773 fmpq_poly_set_coeff_fmpq(poly, n, z.get_fmpq_t());
774 }
775 fmpq_wrapper eval(const fmpq_wrapper &z) const
776 {
777 fmpq_wrapper r;
778 fmpq_poly_evaluate_fmpq(r.get_fmpq_t(), poly, z.get_fmpq_t());
779 return r;
780 }
781 fmpq_wrapper get_coeff(unsigned int deg) const
782 {
783 fmpq_wrapper q;
784 fmpq_poly_get_coeff_fmpq(q.get_fmpq_t(), poly, deg);
785 return q;
786 }
787
788 fmpq_poly_wrapper mullow(const fmpq_poly_wrapper &o,
789 unsigned int prec) const
790 {
792 fmpq_poly_mullow(*r.get_fmpq_poly_t(), poly, *o.get_fmpq_poly_t(),
793 prec);
794 return r;
795 }
796 fmpq_poly_wrapper pow(unsigned int n) const
797 {
799 fmpq_poly_pow(*r.get_fmpq_poly_t(), poly, n);
800 return r;
801 }
802 fmpq_poly_wrapper derivative() const
803 {
805 fmpq_poly_derivative(*r.get_fmpq_poly_t(), poly);
806 return r;
807 }
808 fmpq_poly_wrapper integral() const
809 {
811 fmpq_poly_integral(*r.get_fmpq_poly_t(), poly);
812 return r;
813 }
814
815 fmpq_poly_wrapper inv_series(unsigned int prec) const
816 {
818 fmpq_poly_inv_series(*r.get_fmpq_poly_t(), poly, prec);
819 return r;
820 }
821 fmpq_poly_wrapper revert_series(unsigned int prec) const
822 {
824 fmpq_poly_revert_series(*r.get_fmpq_poly_t(), poly, prec);
825 return r;
826 }
827 fmpq_poly_wrapper log_series(unsigned int prec) const
828 {
830 fmpq_poly_log_series(*r.get_fmpq_poly_t(), poly, prec);
831 return r;
832 }
833 fmpq_poly_wrapper exp_series(unsigned int prec) const
834 {
836 fmpq_poly_exp_series(*r.get_fmpq_poly_t(), poly, prec);
837 return r;
838 }
839 fmpq_poly_wrapper sin_series(unsigned int prec) const
840 {
842 fmpq_poly_sin_series(*r.get_fmpq_poly_t(), poly, prec);
843 return r;
844 }
845 fmpq_poly_wrapper cos_series(unsigned int prec) const
846 {
848 fmpq_poly_cos_series(*r.get_fmpq_poly_t(), poly, prec);
849 return r;
850 }
851 fmpq_poly_wrapper tan_series(unsigned int prec) const
852 {
854 fmpq_poly_tan_series(*r.get_fmpq_poly_t(), poly, prec);
855 return r;
856 }
857 fmpq_poly_wrapper asin_series(unsigned int prec) const
858 {
860 fmpq_poly_asin_series(*r.get_fmpq_poly_t(), poly, prec);
861 return r;
862 }
863 fmpq_poly_wrapper atan_series(unsigned int prec) const
864 {
866 fmpq_poly_atan_series(*r.get_fmpq_poly_t(), poly, prec);
867 return r;
868 }
869 fmpq_poly_wrapper sinh_series(unsigned int prec) const
870 {
872 fmpq_poly_sinh_series(*r.get_fmpq_poly_t(), poly, prec);
873 return r;
874 }
875 fmpq_poly_wrapper cosh_series(unsigned int prec) const
876 {
878 fmpq_poly_cosh_series(*r.get_fmpq_poly_t(), poly, prec);
879 return r;
880 }
881 fmpq_poly_wrapper tanh_series(unsigned int prec) const
882 {
884 fmpq_poly_tanh_series(*r.get_fmpq_poly_t(), poly, prec);
885 return r;
886 }
887 fmpq_poly_wrapper asinh_series(unsigned int prec) const
888 {
890 fmpq_poly_asinh_series(*r.get_fmpq_poly_t(), poly, prec);
891 return r;
892 }
893 fmpq_poly_wrapper atanh_series(unsigned int prec) const
894 {
896 fmpq_poly_atanh_series(*r.get_fmpq_poly_t(), poly, prec);
897 return r;
898 }
899 fmpq_poly_wrapper subs(const fmpq_poly_wrapper &o, unsigned int prec) const
900 {
902 fmpq_poly_compose_series(*r.get_fmpq_poly_t(), poly,
903 *o.get_fmpq_poly_t(), prec);
904 return r;
905 }
906 void set_zero()
907 {
908 fmpq_poly_zero(poly);
909 }
910 void set_one()
911 {
912 fmpq_poly_one(poly);
913 }
914
915 bool operator==(const fmpq_poly_wrapper &o) const
916 {
917 return fmpq_poly_equal(poly, *o.get_fmpq_poly_t()) != 0;
918 }
919 bool operator<(const fmpq_poly_wrapper &o) const
920 {
921 return fmpq_poly_cmp(poly, *o.get_fmpq_poly_t()) == -1;
922 }
923
924 friend fmpq_poly_wrapper operator+(const fmpq_poly_wrapper &a,
925 const fmpq_poly_wrapper &o)
926 {
928 fmpq_poly_add(*r.get_fmpq_poly_t(), *a.get_fmpq_poly_t(),
929 *o.get_fmpq_poly_t());
930 return r;
931 }
932 friend fmpq_poly_wrapper operator-(const fmpq_poly_wrapper &a,
933 const fmpq_poly_wrapper &o)
934 {
936 fmpq_poly_sub(*r.get_fmpq_poly_t(), *a.get_fmpq_poly_t(),
937 *o.get_fmpq_poly_t());
938 return r;
939 }
940 fmpq_poly_wrapper operator-() const
941 {
943 fmpq_poly_neg(*r.get_fmpq_poly_t(), *get_fmpq_poly_t());
944 return r;
945 }
946 friend fmpq_poly_wrapper operator*(const fmpq_poly_wrapper &a,
947 const fmpq_wrapper &q)
948 {
950 fmpq_poly_scalar_mul_fmpq(*r.get_fmpq_poly_t(), *a.get_fmpq_poly_t(),
951 q.get_fmpq_t());
952 return r;
953 }
954 friend fmpq_poly_wrapper operator*(const fmpq_poly_wrapper &a,
955 const fmpq_poly_wrapper &o)
956 {
958 fmpq_poly_mul(*r.get_fmpq_poly_t(), *a.get_fmpq_poly_t(),
959 *o.get_fmpq_poly_t());
960 return r;
961 }
962 friend fmpq_poly_wrapper operator/(const fmpq_poly_wrapper &a,
963 const fmpq_wrapper &q)
964 {
966 fmpq_poly_scalar_div_fmpq(*r.get_fmpq_poly_t(), *a.get_fmpq_poly_t(),
967 q.get_fmpq_t());
968 return r;
969 }
970 void divrem(fmpq_poly_wrapper &q, fmpq_poly_wrapper &r,
971 const fmpq_poly_wrapper &b) const
972 {
973 return fmpq_poly_divrem(*q.get_fmpq_poly_t(), *r.get_fmpq_poly_t(),
974 *get_fmpq_poly_t(), *b.get_fmpq_poly_t());
975 }
976
977 fmpq_poly_wrapper gcd(const fmpq_poly_wrapper &other) const
978 {
980 fmpq_poly_gcd(*r.get_fmpq_poly_t(), poly, *other.get_fmpq_poly_t());
981 return r;
982 }
983 fmpq_poly_wrapper lcm(const fmpq_poly_wrapper &other) const
984 {
986 fmpq_poly_lcm(*r.get_fmpq_poly_t(), poly, *other.get_fmpq_poly_t());
987 return r;
988 }
989 void operator+=(const fmpq_poly_wrapper &o)
990 {
991 fmpq_poly_add(poly, poly, *o.get_fmpq_poly_t());
992 }
993 void operator-=(const fmpq_poly_wrapper &o)
994 {
995 fmpq_poly_sub(poly, poly, *o.get_fmpq_poly_t());
996 }
997 void operator*=(const fmpq_poly_wrapper &o)
998 {
999 fmpq_poly_mul(poly, poly, *o.get_fmpq_poly_t());
1000 }
1001};
1002
1003} // namespace SymEngine
1004
1005#endif // SYMENGINE_FLINT_WRAPPER_H
T c_str(T... args)
Main namespace for SymEngine package.
Definition: add.cpp:19