6 #include <symengine/cwrapper.h>
7 #include <symengine/printers.h>
8 #include <symengine/matrix.h>
10 #include <symengine/parser.h>
11 #include <symengine/lambda_double.h>
13 #ifdef HAVE_SYMENGINE_LLVM
14 #include <symengine/llvm_double.h>
15 using SymEngine::LLVMDoubleVisitor;
16 using SymEngine::LLVMFloatVisitor;
17 #ifdef HAVE_SYMENGINE_LLVM_LONG_DOUBLE
18 using SymEngine::LLVMLongDoubleVisitor;
22 #define xstr(s) ystr(s)
32 using SymEngine::down_cast;
33 using SymEngine::function_symbol;
35 using SymEngine::has_symbol;
37 using SymEngine::integer_class;
42 using SymEngine::rational_class;
46 using SymEngine::zero;
47 #ifdef HAVE_SYMENGINE_MPFR
48 using SymEngine::mpfr_class;
51 #ifdef HAVE_SYMENGINE_MPC
56 using SymEngine::rcp_static_cast;
59 using SymEngine::set_basic;
60 using SymEngine::vec_basic;
61 using SymEngine::vec_pair;
62 using SymEngine::vec_sym;
63 #if SYMENGINE_INTEGER_CLASS != SYMENGINE_BOOSTMP
64 using SymEngine::get_mpq_t;
65 using SymEngine::get_mpz_t;
67 using SymEngine::ccode;
68 using SymEngine::CodePrinterPrecision;
69 using SymEngine::cudacode;
70 using SymEngine::diag;
72 using SymEngine::jscode;
73 using SymEngine::julia_str;
74 using SymEngine::latex;
75 using SymEngine::mathml;
76 using SymEngine::mp_get_si;
77 using SymEngine::mp_get_ui;
78 using SymEngine::numeric_cast;
79 using SymEngine::ones;
80 using SymEngine::parse;
81 using SymEngine::SymEngineException;
82 using SymEngine::zeros;
88 inline bool is_aligned(T *p,
size_t n =
alignof(T))
90 return 0 ==
reinterpret_cast<uintptr_t
>(p) % n;
93 static std::string _str(
const Basic &a)
101 SymEngine::CodePrinterPrecision precision;
108 SymEngine::CodePrinterPrecision
111 if (settings ==
nullptr) {
112 return SymEngine::CodePrinterPrecision::Double;
114 return settings->precision;
121 #define CWRAPPER_BEGIN try {
123 #define CWRAPPER_END \
124 return SYMENGINE_NO_EXCEPTION; \
126 catch (SymEngineException & e) \
128 return e.error_code(); \
132 return SYMENGINE_RUNTIME_ERROR; \
136 SymEngine::RCP<const SymEngine::Basic> m;
140 SymEngine::set_basic m;
144 "Size of 'basic' is not correct");
145 static_assert(std::alignment_of<CRCPBasic>::value
146 == std::alignment_of<CRCPBasic_C>::value,
147 "Alignment of 'basic' is not correct");
149 void basic_new_stack(basic s)
154 void basic_free_stack(basic s)
169 const char *symengine_version()
171 return SYMENGINE_VERSION;
174 void basic_const_set(basic s,
const char *c)
179 void basic_const_zero(basic s)
181 s->m = SymEngine::zero;
184 void basic_const_one(basic s)
186 s->m = SymEngine::one;
189 void basic_const_minus_one(basic s)
191 s->m = SymEngine::minus_one;
194 void basic_const_I(basic s)
199 void basic_const_pi(basic s)
201 s->m = SymEngine::pi;
204 void basic_const_E(basic s)
209 void basic_const_EulerGamma(basic s)
211 s->m = SymEngine::EulerGamma;
214 void basic_const_Catalan(basic s)
216 s->m = SymEngine::Catalan;
219 void basic_const_GoldenRatio(basic s)
221 s->m = SymEngine::GoldenRatio;
224 void basic_const_infinity(basic s)
226 s->m = SymEngine::Inf;
229 void basic_const_neginfinity(basic s)
231 s->m = SymEngine::NegInf;
234 void basic_const_complex_infinity(basic s)
236 s->m = SymEngine::ComplexInf;
239 void basic_const_nan(basic s)
241 s->m = SymEngine::Nan;
244 TypeID basic_get_class_id(
const char *c)
246 static std::map<std::string, TypeID> names = {
247 #define SYMENGINE_INCLUDE_ALL
248 #define SYMENGINE_ENUM(type, Class) {xstr(Class), type},
249 #include "symengine/type_codes.inc"
250 #undef SYMENGINE_ENUM
251 #undef SYMENGINE_INCLUDE_ALL
252 {
"", SYMENGINE_TypeID_Count}};
254 return names[std::string(c)];
257 char *basic_get_class_from_id(TypeID
id)
259 static std::map<TypeID, std::string> names = {
260 #define SYMENGINE_INCLUDE_ALL
261 #define SYMENGINE_ENUM(type, Class) {type, xstr(Class)},
262 #include "symengine/type_codes.inc"
263 #undef SYMENGINE_ENUM
264 #undef SYMENGINE_INCLUDE_ALL
265 {SYMENGINE_TypeID_Count,
""}};
267 std::string name = names[id];
268 auto cc =
new char[name.length() + 1];
269 std::strcpy(cc, name.c_str());
273 TypeID basic_get_type(
const basic s)
275 return static_cast<TypeID
>(s->m->get_type_code());
278 CWRAPPER_OUTPUT_TYPE symbol_set(basic s,
const char *c)
285 int number_is_zero(
const basic s)
288 return (
int)((down_cast<const Number &>(*(s->m))).
is_zero());
291 int number_is_negative(
const basic s)
294 return (
int)((down_cast<const Number &>(*(s->m))).is_negative());
297 int number_is_positive(
const basic s)
300 return (
int)((down_cast<const Number &>(*(s->m))).is_positive());
303 int number_is_complex(
const basic s)
306 return (
int)((down_cast<const Number &>(*(s->m))).is_complex());
309 int basic_has_symbol(
const basic e,
const basic s)
311 return (
int)(has_symbol(*(e->m), *(s->m)));
314 CWRAPPER_OUTPUT_TYPE integer_set_si(basic s,
long i)
321 CWRAPPER_OUTPUT_TYPE integer_set_ui(basic s,
unsigned long i)
328 #if SYMENGINE_INTEGER_CLASS != SYMENGINE_BOOSTMP
329 CWRAPPER_OUTPUT_TYPE integer_set_mpz(basic s,
const mpz_t i)
337 CWRAPPER_OUTPUT_TYPE integer_set_str(basic s,
const char *c)
344 CWRAPPER_OUTPUT_TYPE real_double_set_d(basic s,
double d)
347 s->m = SymEngine::real_double(d);
351 double real_double_get_d(
const basic s)
353 SYMENGINE_ASSERT(is_a<RealDouble>(*(s->m)));
354 return (down_cast<const RealDouble &>(*(s->m))).as_double();
357 #ifdef HAVE_SYMENGINE_MPFR
359 CWRAPPER_OUTPUT_TYPE real_mpfr_set_d(basic s,
double d,
int prec)
362 mpfr_class mc = mpfr_class(prec);
363 mpfr_set_d(mc.get_mpfr_t(), d, MPFR_RNDN);
364 s->m = SymEngine::real_mpfr(std::move(mc));
368 CWRAPPER_OUTPUT_TYPE real_mpfr_set_str(basic s,
const char *c,
int prec)
371 s->m = SymEngine::real_mpfr(mpfr_class(c, prec, 10));
375 double real_mpfr_get_d(
const basic s)
377 SYMENGINE_ASSERT(is_a<RealMPFR>(*(s->m)));
379 ((down_cast<const RealMPFR &>(*(s->m))).as_mpfr()).get_mpfr_t(),
383 CWRAPPER_OUTPUT_TYPE real_mpfr_set(basic s, mpfr_srcptr m)
386 s->m = SymEngine::real_mpfr(mpfr_class(m));
390 CWRAPPER_OUTPUT_TYPE real_mpfr_get(mpfr_ptr m,
const basic s)
393 SYMENGINE_ASSERT(is_a<RealMPFR>(*(s->m)));
394 mpfr_set(m, ((down_cast<const RealMPFR &>(*(s->m))).as_mpfr()).get_mpfr_t(),
399 mpfr_prec_t real_mpfr_get_prec(
const basic s)
401 SYMENGINE_ASSERT(is_a<RealMPFR>(*(s->m)));
402 return ((down_cast<const RealMPFR &>(*(s->m))).as_mpfr()).get_prec();
407 CWRAPPER_OUTPUT_TYPE complex_base_real_part(basic s,
const basic com)
411 s->m = (down_cast<const ComplexBase &>(*(com->m))).real_part();
415 CWRAPPER_OUTPUT_TYPE complex_base_imaginary_part(basic s,
const basic com)
419 s->m = (down_cast<const ComplexBase &>(*(com->m))).imaginary_part();
423 signed long integer_get_si(
const basic s)
425 SYMENGINE_ASSERT(is_a<Integer>(*(s->m)));
426 return mp_get_si((down_cast<const Integer &>(*(s->m))).as_integer_class());
429 unsigned long integer_get_ui(
const basic s)
431 SYMENGINE_ASSERT(is_a<Integer>(*(s->m)));
432 return mp_get_ui((down_cast<const Integer &>(*(s->m))).as_integer_class());
435 #if SYMENGINE_INTEGER_CLASS != SYMENGINE_BOOSTMP
436 CWRAPPER_OUTPUT_TYPE integer_get_mpz(mpz_t a,
const basic s)
439 SYMENGINE_ASSERT(is_a<Integer>(*(s->m)));
441 a, get_mpz_t((down_cast<const Integer &>(*(s->m))).as_integer_class()));
446 CWRAPPER_OUTPUT_TYPE rational_set_si(basic s,
long a,
long b)
453 CWRAPPER_OUTPUT_TYPE rational_set_ui(basic s,
unsigned long a,
unsigned long b)
460 CWRAPPER_OUTPUT_TYPE rational_set(basic s,
const basic a,
const basic b)
462 if (not is_a_Integer(a) or not is_a_Integer(b)) {
463 return SYMENGINE_RUNTIME_ERROR;
466 *(rcp_static_cast<const Integer>(a->m)),
467 *(rcp_static_cast<const Integer>(b->m)));
468 return SYMENGINE_NO_EXCEPTION;
471 #if SYMENGINE_INTEGER_CLASS != SYMENGINE_BOOSTMP
472 CWRAPPER_OUTPUT_TYPE rational_get_mpq(mpq_t a,
const basic s)
475 SYMENGINE_ASSERT(is_a<Rational>(*(s->m)));
476 mpq_set(a, get_mpq_t(
477 (down_cast<const Rational &>(*(s->m))).as_rational_class()));
481 CWRAPPER_OUTPUT_TYPE rational_set_mpq(basic s,
const mpq_t i)
489 CWRAPPER_OUTPUT_TYPE complex_set(basic s,
const basic re,
const basic im)
493 *(rcp_static_cast<const Number>(re->m)),
494 *(rcp_static_cast<const Number>(im->m)));
498 CWRAPPER_OUTPUT_TYPE complex_set_rat(basic s,
const basic re,
const basic im)
502 *(rcp_static_cast<const Rational>(re->m)),
503 *(rcp_static_cast<const Rational>(im->m)));
507 #if SYMENGINE_INTEGER_CLASS != SYMENGINE_BOOSTMP
508 CWRAPPER_OUTPUT_TYPE complex_set_mpq(basic s,
const mpq_t re,
const mpq_t im)
516 dcomplex complex_double_get(
const basic s)
518 SYMENGINE_ASSERT(is_a<ComplexDouble>(*(s->m)));
520 d.real = (down_cast<const ComplexDouble &>(*(s->m)).as_complex_double())
522 d.imag = (down_cast<const ComplexDouble &>(*(s->m)).as_complex_double())
527 char *basic_dumps(
const basic s,
unsigned long *size)
529 std::string str = s->m->dumps();
530 *size = str.length();
531 auto cc =
new char[*size];
536 CWRAPPER_OUTPUT_TYPE basic_loads(basic s,
const char *c,
unsigned long size)
539 std::string data(c, size);
540 s->m = Basic::loads(data);
544 CWRAPPER_OUTPUT_TYPE basic_diff(basic s,
const basic expr, basic
const symbol)
546 if (not is_a_Symbol(
symbol))
547 return SYMENGINE_RUNTIME_ERROR;
549 s->m = expr->m->diff(rcp_static_cast<const Symbol>(
symbol->m));
553 CWRAPPER_OUTPUT_TYPE basic_assign(basic a,
const basic b)
560 CWRAPPER_OUTPUT_TYPE basic_parse(basic b,
const char *str)
563 b->m = SymEngine::parse(str);
567 CWRAPPER_OUTPUT_TYPE basic_parse2(basic b,
const char *str,
int convert_xor)
570 if (convert_xor > 0) {
571 b->m = SymEngine::parse(str);
573 b->m = SymEngine::parse(str,
false);
578 CWRAPPER_OUTPUT_TYPE basic_add(basic s,
const basic a,
const basic b)
585 CWRAPPER_OUTPUT_TYPE basic_sub(basic s,
const basic a,
const basic b)
592 CWRAPPER_OUTPUT_TYPE basic_mul(basic s,
const basic a,
const basic b)
599 CWRAPPER_OUTPUT_TYPE basic_pow(basic s,
const basic a,
const basic b)
602 s->m = SymEngine::pow(a->m, b->m);
606 CWRAPPER_OUTPUT_TYPE basic_div(basic s,
const basic a,
const basic b)
613 int basic_eq(
const basic a,
const basic b)
618 int basic_neq(
const basic a,
const basic b)
623 #define IMPLEMENT_ONE_ARG_FUNC(func) \
624 CWRAPPER_OUTPUT_TYPE basic_##func(basic s, const basic a) \
627 s->m = SymEngine::func(a->m); \
631 IMPLEMENT_ONE_ARG_FUNC(
expand)
632 IMPLEMENT_ONE_ARG_FUNC(neg)
633 IMPLEMENT_ONE_ARG_FUNC(abs)
634 IMPLEMENT_ONE_ARG_FUNC(erf)
635 IMPLEMENT_ONE_ARG_FUNC(erfc)
636 IMPLEMENT_ONE_ARG_FUNC(sin)
637 IMPLEMENT_ONE_ARG_FUNC(cos)
638 IMPLEMENT_ONE_ARG_FUNC(tan)
639 IMPLEMENT_ONE_ARG_FUNC(csc)
640 IMPLEMENT_ONE_ARG_FUNC(sec)
641 IMPLEMENT_ONE_ARG_FUNC(cot)
642 IMPLEMENT_ONE_ARG_FUNC(asin)
643 IMPLEMENT_ONE_ARG_FUNC(acos)
644 IMPLEMENT_ONE_ARG_FUNC(asec)
645 IMPLEMENT_ONE_ARG_FUNC(acsc)
646 IMPLEMENT_ONE_ARG_FUNC(atan)
647 IMPLEMENT_ONE_ARG_FUNC(acot)
648 IMPLEMENT_ONE_ARG_FUNC(sinh)
649 IMPLEMENT_ONE_ARG_FUNC(cosh)
650 IMPLEMENT_ONE_ARG_FUNC(tanh)
651 IMPLEMENT_ONE_ARG_FUNC(csch)
652 IMPLEMENT_ONE_ARG_FUNC(sech)
653 IMPLEMENT_ONE_ARG_FUNC(coth)
654 IMPLEMENT_ONE_ARG_FUNC(asinh)
655 IMPLEMENT_ONE_ARG_FUNC(acosh)
656 IMPLEMENT_ONE_ARG_FUNC(asech)
657 IMPLEMENT_ONE_ARG_FUNC(acsch)
658 IMPLEMENT_ONE_ARG_FUNC(atanh)
659 IMPLEMENT_ONE_ARG_FUNC(acoth)
660 IMPLEMENT_ONE_ARG_FUNC(lambertw)
661 IMPLEMENT_ONE_ARG_FUNC(zeta)
662 IMPLEMENT_ONE_ARG_FUNC(dirichlet_eta)
663 IMPLEMENT_ONE_ARG_FUNC(gamma)
664 IMPLEMENT_ONE_ARG_FUNC(loggamma)
665 IMPLEMENT_ONE_ARG_FUNC(
sqrt)
666 IMPLEMENT_ONE_ARG_FUNC(
cbrt)
667 IMPLEMENT_ONE_ARG_FUNC(exp)
668 IMPLEMENT_ONE_ARG_FUNC(log)
669 IMPLEMENT_ONE_ARG_FUNC(floor)
670 IMPLEMENT_ONE_ARG_FUNC(ceiling)
671 IMPLEMENT_ONE_ARG_FUNC(sign)
673 #define IMPLEMENT_TWO_ARG_FUNC(func) \
674 CWRAPPER_OUTPUT_TYPE basic_##func(basic s, const basic a, const basic b) \
677 s->m = SymEngine::func(a->m, b->m); \
681 IMPLEMENT_TWO_ARG_FUNC(atan2)
682 IMPLEMENT_TWO_ARG_FUNC(kronecker_delta)
683 IMPLEMENT_TWO_ARG_FUNC(lowergamma)
684 IMPLEMENT_TWO_ARG_FUNC(uppergamma)
685 IMPLEMENT_TWO_ARG_FUNC(beta)
686 IMPLEMENT_TWO_ARG_FUNC(polygamma)
688 #define IMPLEMENT_STR_CONVERSION(name, func) \
689 char *basic_##name(const basic s) \
694 } catch (SymEngineException & e) { \
699 auto cc = new char[str.length() + 1]; \
700 std::strcpy(cc, str.c_str()); \
704 #define IMPLEMENT_STR_CONVERSION_SETTINGS(name, func) \
705 char *basic_##name(const basic s, \
706 const BasicCodePrinterSettings *settings) \
710 str = func(*s->m, to_code_printer_precision(settings)); \
711 } catch (SymEngineException & e) { \
716 auto cc = new char[str.length() + 1]; \
717 std::strcpy(cc, str.c_str()); \
721 IMPLEMENT_STR_CONVERSION(str, _str)
722 IMPLEMENT_STR_CONVERSION(str_julia, julia_str)
723 IMPLEMENT_STR_CONVERSION(str_mathml, mathml)
724 IMPLEMENT_STR_CONVERSION(str_latex, latex)
725 IMPLEMENT_STR_CONVERSION(str_jscode, jscode)
726 IMPLEMENT_STR_CONVERSION(str_ccode, ccode)
727 IMPLEMENT_STR_CONVERSION(str_cudacode, cudacode)
728 IMPLEMENT_STR_CONVERSION_SETTINGS(str_ccode_settings, ccode)
729 IMPLEMENT_STR_CONVERSION_SETTINGS(str_cudacode_settings, cudacode)
742 BasicCodePrinterPrecision prec)
744 self->precision =
static_cast<SymEngine::CodePrinterPrecision
>(prec);
747 void basic_str_free(
char *s)
752 void bool_set_true(basic s)
754 s->m = SymEngine::boolTrue;
757 void bool_set_false(basic s)
759 s->m = SymEngine::boolFalse;
762 CWRAPPER_OUTPUT_TYPE basic_set_interval(basic s,
const basic start,
763 const basic end,
int left_open,
771 rcp_static_cast<const Number>(end->m),
772 (
bool)left_open, (
bool)right_open);
776 CWRAPPER_OUTPUT_TYPE basic_set_finiteset(basic s,
const CSetBasic *container)
783 void basic_set_emptyset(basic s)
788 void basic_set_universalset(basic s)
793 void basic_set_complexes(basic s)
798 void basic_set_reals(basic s)
803 void basic_set_rationals(basic s)
808 void basic_set_integers(basic s)
813 CWRAPPER_OUTPUT_TYPE basic_set_union(basic s,
const basic a,
const basic b)
816 s->m = rcp_static_cast<const Set>(a->m)->set_union(
817 rcp_static_cast<const Set>(b->m));
821 CWRAPPER_OUTPUT_TYPE basic_set_intersection(basic s,
const basic a,
825 s->m = rcp_static_cast<const Set>(a->m)->set_intersection(
826 rcp_static_cast<const Set>(b->m));
830 CWRAPPER_OUTPUT_TYPE basic_set_complement(basic s,
const basic a,
const basic b)
833 s->m = rcp_static_cast<const Set>(a->m)->set_complement(
834 rcp_static_cast<const Set>(b->m));
838 CWRAPPER_OUTPUT_TYPE basic_set_contains(basic s,
const basic a,
const basic b)
841 s->m = rcp_static_cast<const Set>(a->m)->contains(b->m);
845 int basic_set_is_subset(
const basic a,
const basic b)
847 SYMENGINE_ASSERT(is_a_Set(*(a->m)));
848 SYMENGINE_ASSERT(is_a_Set(*(b->m)));
849 return rcp_static_cast<const Set>(a->m)->is_subset(
850 rcp_static_cast<const Set>(b->m));
853 int basic_set_is_proper_subset(
const basic a,
const basic b)
855 SYMENGINE_ASSERT(is_a_Set(*(a->m)));
856 SYMENGINE_ASSERT(is_a_Set(*(b->m)));
857 return rcp_static_cast<const Set>(a->m)->is_proper_subset(
858 rcp_static_cast<const Set>(b->m));
861 int basic_set_is_superset(
const basic a,
const basic b)
863 SYMENGINE_ASSERT(is_a_Set(*(a->m)));
864 SYMENGINE_ASSERT(is_a_Set(*(b->m)));
865 return rcp_static_cast<const Set>(a->m)->is_superset(
866 rcp_static_cast<const Set>(b->m));
869 int basic_set_is_proper_superset(
const basic a,
const basic b)
871 SYMENGINE_ASSERT(is_a_Set(*(a->m)));
872 SYMENGINE_ASSERT(is_a_Set(*(b->m)));
873 return rcp_static_cast<const Set>(a->m)->is_proper_superset(
874 rcp_static_cast<const Set>(b->m));
877 CWRAPPER_OUTPUT_TYPE basic_set_inf(basic s,
const basic a)
880 s->m = SymEngine::inf(*rcp_static_cast<const Set>(a->m));
884 CWRAPPER_OUTPUT_TYPE basic_set_sup(basic s,
const basic a)
887 s->m = SymEngine::sup(*rcp_static_cast<const Set>(a->m));
891 CWRAPPER_OUTPUT_TYPE basic_set_boundary(basic s,
const basic a)
894 s->m = SymEngine::boundary(*rcp_static_cast<const Set>(a->m));
898 CWRAPPER_OUTPUT_TYPE basic_set_interior(basic s,
const basic a)
901 s->m = SymEngine::interior(*rcp_static_cast<const Set>(a->m));
905 CWRAPPER_OUTPUT_TYPE basic_set_closure(basic s,
const basic a)
908 s->m = SymEngine::closure(*rcp_static_cast<const Set>(a->m));
912 int symengine_have_component(
const char *c)
914 #ifdef HAVE_SYMENGINE_MPFR
915 if (std::strcmp(
"mpfr", c) == 0)
918 #ifdef HAVE_SYMENGINE_MPC
919 if (std::strcmp(
"mpc", c) == 0)
922 #ifdef HAVE_SYMENGINE_FLINT
923 if (std::strcmp(
"flint", c) == 0)
926 #ifdef HAVE_SYMENGINE_ARB
927 if (std::strcmp(
"arb", c) == 0)
930 #ifdef HAVE_SYMENGINE_ECM
931 if (std::strcmp(
"ecm", c) == 0)
934 #ifdef HAVE_SYMENGINE_PRIMESIEVE
935 if (std::strcmp(
"primesieve", c) == 0)
938 #ifdef HAVE_SYMENGINE_PIRANHA
939 if (std::strcmp(
"piranha", c) == 0)
942 #ifdef HAVE_SYMENGINE_BOOST
943 if (std::strcmp(
"boost", c) == 0)
946 #ifdef HAVE_SYMENGINE_PTHREAD
947 if (std::strcmp(
"pthread", c) == 0)
950 #ifdef HAVE_SYMENGINE_LLVM
951 if (std::strcmp(
"llvm", c) == 0)
954 #ifdef HAVE_SYMENGINE_LLVM_LONG_DOUBLE
955 if (std::strcmp(
"llvm_long_double", c) == 0)
965 int is_a_Integer(
const basic c)
967 return is_a<Integer>(*(c->m));
969 int is_a_Rational(
const basic c)
971 return is_a<Rational>(*(c->m));
973 int is_a_Symbol(
const basic c)
975 return is_a<Symbol>(*(c->m));
979 return is_a<Complex>(*(c->m));
981 int is_a_RealDouble(
const basic c)
983 return is_a<RealDouble>(*(c->m));
985 int is_a_ComplexDouble(
const basic c)
987 return is_a<ComplexDouble>(*(c->m));
989 int is_a_RealMPFR(
const basic c)
991 #ifdef HAVE_SYMENGINE_MPFR
992 return is_a<RealMPFR>(*(c->m));
997 int is_a_ComplexMPC(
const basic c)
999 #ifdef HAVE_SYMENGINE_MPC
1000 return is_a<ComplexMPC>(*(c->m));
1005 int is_a_Set(
const basic c)
1007 return SymEngine::is_a_Set(*(c->m));
1021 int vectorint_placement_new_check(
void *data,
size_t size)
1026 if (not SymEngine::is_aligned(
self))
1031 CVectorInt *vectorint_placement_new(
void *data)
1033 #if defined(WITH_SYMENGINE_ASSERT)
1036 SYMENGINE_ASSERT(SymEngine::is_aligned(
self));
1042 void vectorint_placement_free(
CVectorInt *
self)
1044 self->m.~vector<
int>();
1052 void vectorint_push_back(
CVectorInt *
self,
int value)
1054 self->m.push_back(value);
1065 SymEngine::vec_basic m;
1078 CWRAPPER_OUTPUT_TYPE vecbasic_push_back(
CVecBasic *
self,
const basic value)
1082 self->m.push_back(value->m);
1087 CWRAPPER_OUTPUT_TYPE vecbasic_get(
CVecBasic *
self,
size_t n, basic result)
1091 SYMENGINE_ASSERT(n < self->m.size());
1092 result->m =
self->m[n];
1097 CWRAPPER_OUTPUT_TYPE vecbasic_set(
CVecBasic *
self,
size_t n,
const basic s)
1100 SYMENGINE_ASSERT(n < self->m.size());
1105 CWRAPPER_OUTPUT_TYPE vecbasic_erase(
CVecBasic *
self,
size_t n)
1108 SYMENGINE_ASSERT(n < self->m.size());
1109 self->m.erase(self->m.begin() + n);
1115 return self->m.size();
1118 CWRAPPER_OUTPUT_TYPE basic_max(basic s,
const CVecBasic *d)
1125 CWRAPPER_OUTPUT_TYPE basic_min(basic s,
const CVecBasic *d)
1132 CWRAPPER_OUTPUT_TYPE basic_add_vec(basic s,
const CVecBasic *d)
1139 CWRAPPER_OUTPUT_TYPE basic_mul_vec(basic s,
const CVecBasic *d)
1166 CDenseMatrix *dense_matrix_new_rows_cols(
unsigned rows,
unsigned cols)
1191 void sparse_matrix_rows_cols(
CSparseMatrix *s,
unsigned long int rows,
1192 unsigned long int cols)
1195 numeric_cast<unsigned>(cols));
1207 std::string str = s->m.__str__();
1208 auto cc =
new char[str.length() + 1];
1209 std::strcpy(cc, str.c_str());
1215 std::string str = s->m.__str__();
1216 auto cc =
new char[str.length() + 1];
1217 std::strcpy(cc, str.c_str());
1221 CWRAPPER_OUTPUT_TYPE dense_matrix_rows_cols(
CDenseMatrix *mat,
unsigned r,
1225 mat->m.resize(r, c);
1229 CWRAPPER_OUTPUT_TYPE dense_matrix_get_basic(basic s,
const CDenseMatrix *mat,
1230 unsigned long int r,
1231 unsigned long int c)
1234 s->m = mat->m.get(numeric_cast<unsigned>(r), numeric_cast<unsigned>(c));
1238 CWRAPPER_OUTPUT_TYPE dense_matrix_set_basic(
CDenseMatrix *mat,
1239 unsigned long int r,
1240 unsigned long int c, basic s)
1243 mat->m.set(numeric_cast<unsigned>(r), numeric_cast<unsigned>(c), s->m);
1247 CWRAPPER_OUTPUT_TYPE sparse_matrix_get_basic(basic s,
const CSparseMatrix *mat,
1248 unsigned long int r,
1249 unsigned long int c)
1252 s->m = mat->m.get(numeric_cast<unsigned>(r), numeric_cast<unsigned>(c));
1256 CWRAPPER_OUTPUT_TYPE sparse_matrix_set_basic(
CSparseMatrix *mat,
1257 unsigned long int r,
1258 unsigned long int c, basic s)
1261 mat->m.set(numeric_cast<unsigned>(r), numeric_cast<unsigned>(c), s->m);
1265 CWRAPPER_OUTPUT_TYPE dense_matrix_det(basic s,
const CDenseMatrix *mat)
1268 s->m = mat->m.det();
1274 dense_matrix_rows_cols(s, mat->m.nrows(), mat->m.ncols());
1278 CWRAPPER_OUTPUT_TYPE dense_matrix_transpose(
CDenseMatrix *s,
1282 dense_matrix_rows_cols(s, mat->m.ncols(), mat->m.nrows());
1283 mat->m.transpose(s->m);
1286 CWRAPPER_OUTPUT_TYPE
1288 unsigned long int r1,
unsigned long int c1,
1289 unsigned long int r2,
unsigned long int c2,
1290 unsigned long int r,
unsigned long int c)
1293 dense_matrix_rows_cols(s, numeric_cast<unsigned>(r2 - r1 + 1),
1294 numeric_cast<unsigned>(c2 - c1 + 1));
1295 mat->m.submatrix(s->m, numeric_cast<unsigned>(r1),
1296 numeric_cast<unsigned>(c1), numeric_cast<unsigned>(r2),
1297 numeric_cast<unsigned>(c2), numeric_cast<unsigned>(r),
1298 numeric_cast<unsigned>(c));
1302 CWRAPPER_OUTPUT_TYPE dense_matrix_row_join(
CDenseMatrix *A,
1306 A->m.row_join(B->m);
1310 CWRAPPER_OUTPUT_TYPE dense_matrix_col_join(
CDenseMatrix *A,
1314 A->m.col_join(B->m);
1318 CWRAPPER_OUTPUT_TYPE dense_matrix_row_del(
CDenseMatrix *A,
unsigned k)
1325 CWRAPPER_OUTPUT_TYPE dense_matrix_col_del(
CDenseMatrix *A,
unsigned k)
1332 unsigned long int dense_matrix_rows(
const CDenseMatrix *s)
1334 return s->m.nrows();
1337 unsigned long int dense_matrix_cols(
const CDenseMatrix *s)
1339 return s->m.ncols();
1342 CWRAPPER_OUTPUT_TYPE dense_matrix_add_matrix(
CDenseMatrix *s,
1347 dense_matrix_rows_cols(s, matA->m.nrows(), matA->m.ncols());
1348 matA->m.add_matrix(matB->m, s->m);
1352 CWRAPPER_OUTPUT_TYPE dense_matrix_mul_matrix(
CDenseMatrix *s,
1357 dense_matrix_rows_cols(s, matA->m.nrows(), matB->m.ncols());
1358 matA->m.mul_matrix(matB->m, s->m);
1362 CWRAPPER_OUTPUT_TYPE dense_matrix_add_scalar(
CDenseMatrix *s,
1367 dense_matrix_rows_cols(s, matA->m.nrows(), matA->m.ncols());
1368 matA->m.add_scalar(b->m, s->m);
1372 CWRAPPER_OUTPUT_TYPE dense_matrix_mul_scalar(
CDenseMatrix *s,
1377 dense_matrix_rows_cols(s, matA->m.nrows(), matA->m.ncols());
1378 matA->m.mul_scalar(b->m, s->m);
1386 dense_matrix_rows_cols(l, mat->m.nrows(), mat->m.ncols());
1387 dense_matrix_rows_cols(u, mat->m.nrows(), mat->m.ncols());
1388 mat->m.LU(l->m, u->m);
1396 dense_matrix_rows_cols(l, mat->m.nrows(), mat->m.ncols());
1397 dense_matrix_rows_cols(d, mat->m.nrows(), mat->m.ncols());
1398 mat->m.LDL(l->m, d->m);
1402 CWRAPPER_OUTPUT_TYPE dense_matrix_FFLU(
CDenseMatrix *lu,
1406 dense_matrix_rows_cols(lu, mat->m.nrows(), mat->m.ncols());
1416 dense_matrix_rows_cols(l, mat->m.nrows(), mat->m.ncols());
1417 dense_matrix_rows_cols(d, mat->m.nrows(), mat->m.ncols());
1418 dense_matrix_rows_cols(u, mat->m.nrows(), mat->m.ncols());
1419 mat->m.FFLDU(l->m, d->m, u->m);
1423 CWRAPPER_OUTPUT_TYPE dense_matrix_LU_solve(
CDenseMatrix *x,
1428 dense_matrix_rows_cols(x, A->m.ncols(), 1);
1429 A->m.LU_solve(b->m, x->m);
1433 CWRAPPER_OUTPUT_TYPE dense_matrix_ones(
CDenseMatrix *s,
unsigned long int r,
1434 unsigned long int c)
1437 dense_matrix_rows_cols(s, numeric_cast<unsigned>(r),
1438 numeric_cast<unsigned>(c));
1443 CWRAPPER_OUTPUT_TYPE dense_matrix_zeros(
CDenseMatrix *s,
unsigned long int r,
1444 unsigned long int c)
1447 dense_matrix_rows_cols(s, numeric_cast<unsigned>(r),
1448 numeric_cast<unsigned>(c));
1456 unsigned int vec_size = numeric_cast<unsigned>(vecbasic_size(d));
1457 dense_matrix_rows_cols(
1458 s, numeric_cast<unsigned>(vec_size + (k >= 0 ? k : -k)),
1459 numeric_cast<unsigned>(vec_size + (k >= 0 ? k : -k)));
1460 diag(s->m, d->m, numeric_cast<int>(k));
1464 CWRAPPER_OUTPUT_TYPE dense_matrix_eye(
CDenseMatrix *s,
unsigned long int N,
1465 unsigned long int M,
int k)
1468 dense_matrix_rows_cols(s, numeric_cast<unsigned>(N),
1469 numeric_cast<unsigned>(M));
1474 CWRAPPER_OUTPUT_TYPE dense_matrix_diff(
CDenseMatrix *result,
1477 if (not is_a_Symbol(x))
1478 return SYMENGINE_RUNTIME_ERROR;
1480 diff(A->m, rcp_static_cast<const Symbol>(x->m), result->m);
1484 CWRAPPER_OUTPUT_TYPE dense_matrix_jacobian(
CDenseMatrix *result,
1489 jacobian(A->m, x->m, result->m);
1495 return is_a<DenseMatrix>(c->m);
1500 return is_a<CSRMatrix>(c->m);
1505 return (lhs->m) == (rhs->m);
1510 return (lhs->m) == (rhs->m);
1525 int setbasic_insert(
CSetBasic *
self,
const basic value)
1527 return (self->m.insert(value->m)).second ? 1 : 0;
1530 void setbasic_get(
CSetBasic *
self,
int n, basic result)
1532 result->m = *std::next((self->m).begin(), n);
1535 int setbasic_find(
CSetBasic *
self, basic value)
1537 return self->m.find(value->m) != (
self->m).end() ? 1 : 0;
1540 int setbasic_erase(
CSetBasic *
self,
const basic value)
1542 return (self->m.erase(value->m)) ? 1 : 0;
1547 return self->m.size();
1553 SymEngine::map_basic_basic m;
1569 (
self->m)[key->m] = mapped->m;
1572 int mapbasicbasic_get(
CMapBasicBasic *
self,
const basic key, basic mapped)
1574 auto it =
self->m.find(key->m);
1575 if (it != self->m.end()) {
1576 mapped->m = it->second;
1584 return self->m.size();
1589 CWRAPPER_OUTPUT_TYPE basic_get_args(
const basic
self,
CVecBasic *args)
1592 args->m =
self->m->get_args();
1596 CWRAPPER_OUTPUT_TYPE basic_free_symbols(
const basic
self,
CSetBasic *symbols)
1599 symbols->m = SymEngine::free_symbols(*(self->m));
1603 CWRAPPER_OUTPUT_TYPE basic_function_symbols(
CSetBasic *symbols,
1607 symbols->m = SymEngine::atoms<SymEngine::FunctionSymbol>(*(self->m));
1611 size_t basic_hash(
const basic
self)
1613 return static_cast<size_t>(
self->m->hash());
1616 CWRAPPER_OUTPUT_TYPE basic_subs(basic s,
const basic e,
1620 s->m = e->m->subs(mapbb->m);
1624 CWRAPPER_OUTPUT_TYPE basic_subs2(basic s,
const basic e,
const basic a,
1628 s->m = e->m->subs({{a->m, b->m}});
1632 CWRAPPER_OUTPUT_TYPE function_symbol_set(basic s,
const char *c,
1636 s->m = function_symbol(c, arg->m);
1640 char *function_symbol_get_name(
const basic b)
1642 SYMENGINE_ASSERT(is_a<FunctionSymbol>(*(b->m)));
1643 std::string str = down_cast<const FunctionSymbol &>(*(b->m)).get_name();
1644 auto cc =
new char[str.length() + 1];
1645 std::strcpy(cc, str.c_str());
1649 CWRAPPER_OUTPUT_TYPE basic_coeff(basic c,
const basic b,
const basic x,
1653 c->m = SymEngine::coeff(*(b->m), *(x->m), *(n->m));
1663 vec_basic vb = sym->m;
1665 std::all_of(vb.cbegin(), vb.cend(),
1666 [](RCP<const Basic> b) { return is_a<const Symbol>(*b); }));
1667 vec_sym vs(vb.size());
1668 for (
unsigned i = 0; i < vb.size(); i++)
1669 vs[i] = rcp_static_cast<const Symbol>(vb[i]);
1670 sol->m = SymEngine::linsolve(sys->m, vs);
1674 CWRAPPER_OUTPUT_TYPE basic_solve_poly(
CSetBasic *r,
const basic f,
1678 SYMENGINE_ASSERT(is_a<Symbol>(*(s->m)));
1680 = SymEngine::solve_poly(f->m, rcp_static_cast<const Symbol>(s->m));
1681 if (not is_a<FiniteSet>(*set)) {
1682 return SYMENGINE_NOT_IMPLEMENTED;
1684 r->m = down_cast<const FiniteSet &>(*set).get_container();
1690 char *ascii_art_str()
1692 std::string str = SymEngine::ascii_art();
1693 auto cc =
new char[str.length() + 1];
1694 std::strcpy(cc, str.c_str());
1700 CWRAPPER_OUTPUT_TYPE ntheory_gcd(basic s,
const basic a,
const basic b)
1703 SYMENGINE_ASSERT(is_a<Integer>(*(a->m)));
1704 SYMENGINE_ASSERT(is_a<Integer>(*(b->m)));
1706 down_cast<const Integer &>(*(b->m)));
1710 CWRAPPER_OUTPUT_TYPE ntheory_lcm(basic s,
const basic a,
const basic b)
1713 SYMENGINE_ASSERT(is_a<Integer>(*(a->m)));
1714 SYMENGINE_ASSERT(is_a<Integer>(*(b->m)));
1716 down_cast<const Integer &>(*(b->m)));
1720 CWRAPPER_OUTPUT_TYPE ntheory_gcd_ext(basic g, basic s, basic t,
const basic a,
1724 SYMENGINE_ASSERT(is_a<Integer>(*(a->m)));
1725 SYMENGINE_ASSERT(is_a<Integer>(*(b->m)));
1726 SymEngine::RCP<const Integer> g_, s_, t_;
1728 SymEngine::outArg(t_),
1729 down_cast<const Integer &>(*(a->m)),
1730 down_cast<const Integer &>(*(b->m)));
1737 CWRAPPER_OUTPUT_TYPE ntheory_nextprime(basic s,
const basic a)
1740 SYMENGINE_ASSERT(is_a<Integer>(*(a->m)));
1745 CWRAPPER_OUTPUT_TYPE ntheory_mod(basic s,
const basic n,
const basic d)
1748 SYMENGINE_ASSERT(is_a<Integer>(*(n->m)));
1749 SYMENGINE_ASSERT(is_a<Integer>(*(d->m)));
1751 down_cast<const Integer &>(*(d->m)));
1755 CWRAPPER_OUTPUT_TYPE ntheory_quotient(basic s,
const basic n,
const basic d)
1758 SYMENGINE_ASSERT(is_a<Integer>(*(n->m)));
1759 SYMENGINE_ASSERT(is_a<Integer>(*(d->m)));
1761 down_cast<const Integer &>(*(d->m)));
1765 CWRAPPER_OUTPUT_TYPE ntheory_quotient_mod(basic q, basic r,
const basic n,
1769 SYMENGINE_ASSERT(is_a<Integer>(*(n->m)));
1770 SYMENGINE_ASSERT(is_a<Integer>(*(d->m)));
1771 SymEngine::RCP<const Integer> q_, r_;
1773 down_cast<const Integer &>(*(n->m)),
1774 down_cast<const Integer &>(*(d->m)));
1780 CWRAPPER_OUTPUT_TYPE ntheory_mod_f(basic s,
const basic n,
const basic d)
1783 SYMENGINE_ASSERT(is_a<Integer>(*(n->m)));
1784 SYMENGINE_ASSERT(is_a<Integer>(*(d->m)));
1786 down_cast<const Integer &>(*(d->m)));
1790 CWRAPPER_OUTPUT_TYPE ntheory_quotient_f(basic s,
const basic n,
const basic d)
1793 SYMENGINE_ASSERT(is_a<Integer>(*(n->m)));
1794 SYMENGINE_ASSERT(is_a<Integer>(*(d->m)));
1796 down_cast<const Integer &>(*(d->m)));
1800 CWRAPPER_OUTPUT_TYPE ntheory_quotient_mod_f(basic q, basic r,
const basic n,
1804 SYMENGINE_ASSERT(is_a<Integer>(*(n->m)));
1805 SYMENGINE_ASSERT(is_a<Integer>(*(d->m)));
1806 SymEngine::RCP<const Integer> q_, r_;
1808 down_cast<const Integer &>(*(n->m)),
1809 down_cast<const Integer &>(*(d->m)));
1815 int ntheory_mod_inverse(basic b,
const basic a,
const basic m)
1818 SYMENGINE_ASSERT(is_a<Integer>(*(a->m)));
1819 SYMENGINE_ASSERT(is_a<Integer>(*(m->m)));
1820 SymEngine::RCP<const Integer> b_;
1822 down_cast<const Integer &>(*(a->m)),
1823 down_cast<const Integer &>(*(m->m)));
1828 CWRAPPER_OUTPUT_TYPE ntheory_fibonacci(basic s,
unsigned long a)
1835 CWRAPPER_OUTPUT_TYPE ntheory_fibonacci2(basic g, basic s,
unsigned long a)
1838 SymEngine::RCP<const Integer> g_, s_;
1845 CWRAPPER_OUTPUT_TYPE ntheory_lucas(basic s,
unsigned long a)
1852 CWRAPPER_OUTPUT_TYPE ntheory_lucas2(basic g, basic s,
unsigned long a)
1855 SymEngine::RCP<const Integer> g_, s_;
1862 CWRAPPER_OUTPUT_TYPE ntheory_binomial(basic s,
const basic a,
unsigned long b)
1865 SYMENGINE_ASSERT(is_a<Integer>(*(a->m)));
1870 CWRAPPER_OUTPUT_TYPE ntheory_factorial(basic s,
unsigned long n)
1878 CWRAPPER_OUTPUT_TYPE basic_evalf(basic s,
const basic b,
unsigned long bits,
1883 s->m = SymEngine::evalf(*(b->m), bits, (SymEngine::EvalfDomain)real);
1887 CWRAPPER_OUTPUT_TYPE basic_as_numer_denom(basic numer, basic denom,
1891 SymEngine::as_numer_denom(x->m, SymEngine::outArg(numer->m),
1892 SymEngine::outArg(denom->m));
1896 CWRAPPER_OUTPUT_TYPE basic_add_as_two_terms(basic term1, basic term2,
1900 SYMENGINE_ASSERT(is_a<Add>(*(s->m)));
1901 rcp_static_cast<const Add>(s->m)->as_two_terms(SymEngine::outArg(term1->m),
1902 SymEngine::outArg(term2->m));
1906 CWRAPPER_OUTPUT_TYPE basic_mul_as_two_terms(basic term1, basic term2,
1910 SYMENGINE_ASSERT(is_a<Mul>(*(s->m)));
1911 rcp_static_cast<const Mul>(s->m)->as_two_terms(SymEngine::outArg(term1->m),
1912 SymEngine::outArg(term2->m));
1927 const CVecBasic *exprs,
int perform_cse)
1929 self->m.init(args->m, exprs->m, perform_cse);
1934 const double *
const inps)
1936 self->m.call(outs, inps);
1944 #ifdef HAVE_SYMENGINE_LLVM
1946 struct CLLVMDoubleVisitor {
1947 SymEngine::LLVMDoubleVisitor m;
1950 CLLVMDoubleVisitor *llvm_double_visitor_new()
1952 return new CLLVMDoubleVisitor();
1955 void llvm_double_visitor_init(CLLVMDoubleVisitor *
self,
const CVecBasic *args,
1956 const CVecBasic *exprs,
int perform_cse,
1959 self->m.init(args->m, exprs->m, perform_cse, opt_level);
1962 void llvm_double_visitor_call(CLLVMDoubleVisitor *
self,
double *
const outs,
1963 const double *
const inps)
1965 self->m.call(outs, inps);
1968 void llvm_double_visitor_free(CLLVMDoubleVisitor *
self)
1973 struct CLLVMFloatVisitor {
1974 SymEngine::LLVMFloatVisitor m;
1977 CLLVMFloatVisitor *llvm_float_visitor_new()
1979 return new CLLVMFloatVisitor();
1982 void llvm_float_visitor_init(CLLVMFloatVisitor *
self,
const CVecBasic *args,
1983 const CVecBasic *exprs,
int perform_cse,
1986 self->m.init(args->m, exprs->m, perform_cse, opt_level);
1989 void llvm_float_visitor_call(CLLVMFloatVisitor *
self,
float *
const outs,
1990 const float *
const inps)
1992 self->m.call(outs, inps);
1995 void llvm_float_visitor_free(CLLVMFloatVisitor *
self)
1999 #ifdef SYMENGINE_HAVE_LLVM_LONG_DOUBLE
2001 struct CLLVMLongDoubleVisitor {
2002 SymEngine::LLVMLongDoubleVisitor m;
2005 CLLVMLongDoubleVisitor *llvm_long_double_visitor_new()
2007 return new CLLVMLongDoubleVisitor();
2010 void llvm_long_double_visitor_init(CLLVMLongDoubleVisitor *
self,
2012 const CVecBasic *exprs,
int perform_cse,
2015 self->m.init(args->m, exprs->m, perform_cse, opt_level);
2018 void llvm_long_double_visitor_call(CLLVMLongDoubleVisitor *
self,
2019 long double *
const outs,
2020 const long double *
const inps)
2022 self->m.call(outs, inps);
2025 void llvm_long_double_visitor_free(CLLVMLongDoubleVisitor *
self)
2032 CWRAPPER_OUTPUT_TYPE basic_cse(
CVecBasic *replacement_syms,
2037 vec_pair replacements;
2038 SymEngine::cse(replacements, reduced_exprs->m, exprs->m);
2039 for (
auto &p : replacements) {
2040 replacement_syms->m.push_back(p.first);
2041 replacement_exprs->m.push_back(p.second);
2046 void symengine_print_stack_on_segfault()
2048 SymEngine::print_stack_on_segfault();
The base class for representing addition in symbolic expressions.
The lowest unit of symbolic representation.
std::string __str__() const
ComplexBase Class for deriving all complex classes.
Complex Double Class to hold std::complex<double> values.
static RCP< const Number > from_mpq(const rational_class re, const rational_class im)
static RCP< const Number > from_two_rats(const Rational &re, const Rational &im)
static RCP< const Number > from_two_nums(const Number &re, const Number &im)
static RCP< const Number > from_mpq(const rational_class &i)
static RCP< const Number > from_two_ints(const Integer &n, const Integer &d)
RealDouble Class to hold double values.
Main namespace for SymEngine package.
bool is_a_Number(const Basic &b)
RCP< const Set > interval(const RCP< const Number > &start, const RCP< const Number > &end, const bool left_open=false, const bool right_open=false)
RCP< const Basic > cbrt(const RCP< const Basic > &arg)
RCP< const Complexes > complexes()
RCP< const Integer > nextprime(const Integer &a)
void fibonacci2(const Ptr< RCP< const Integer >> &g, const Ptr< RCP< const Integer >> &s, unsigned long n)
Fibonacci n and n-1.
RCP< const Basic > div(const RCP< const Basic > &a, const RCP< const Basic > &b)
Division.
std::enable_if< std::is_integral< T >::value, RCP< const Integer > >::type integer(T i)
RCP< const Symbol > symbol(const std::string &name)
inline version to return Symbol
RCP< const Reals > reals()
RCP< const Integer > gcd(const Integer &a, const Integer &b)
Greatest Common Divisor.
RCP< const Basic > max(const vec_basic &arg)
Canonicalize Max:
bool eq(const Basic &a, const Basic &b)
Checks equality for a and b
RCP< const Integer > mod(const Integer &n, const Integer &d)
modulo round toward zero
RCP< const EmptySet > emptyset()
RCP< const Integers > integers()
RCP< const Basic > sqrt(const RCP< const Basic > &arg)
RCP< const Integer > lucas(unsigned long n)
Lucas number.
RCP< const Integer > quotient_f(const Integer &n, const Integer &d)
RCP< const Integer > fibonacci(unsigned long n)
Fibonacci number.
RCP< const Basic > sub(const RCP< const Basic > &a, const RCP< const Basic > &b)
Substracts b from a.
RCP< const Integer > mod_f(const Integer &n, const Integer &d)
modulo round toward -inf
RCP< const Integer > quotient(const Integer &n, const Integer &d)
int mod_inverse(const Ptr< RCP< const Integer >> &b, const Integer &a, const Integer &m)
inverse modulo
bool is_a(const Basic &b)
Templatised version to check is_a type.
RCP< const Integer > lcm(const Integer &a, const Integer &b)
Least Common Multiple.
RCP< const Integer > binomial(const Integer &n, unsigned long k)
Binomial Coefficient.
void quotient_mod_f(const Ptr< RCP< const Integer >> &q, const Ptr< RCP< const Integer >> &r, const Integer &n, const Integer &d)
RCP< const Basic > mul(const RCP< const Basic > &a, const RCP< const Basic > &b)
Multiplication.
RCP< const Integer > factorial(unsigned long n)
Factorial.
RCP< const Basic > add(const RCP< const Basic > &a, const RCP< const Basic > &b)
Adds two objects (safely).
RCP< const Constant > constant(const std::string &name)
inline version to return Constant
tribool is_zero(const Basic &b, const Assumptions *assumptions=nullptr)
Check if a number is zero.
void gcd_ext(const Ptr< RCP< const Integer >> &g, const Ptr< RCP< const Integer >> &s, const Ptr< RCP< const Integer >> &t, const Integer &a, const Integer &b)
Extended GCD.
RCP< const Set > finiteset(const set_basic &container)
bool neq(const Basic &a, const Basic &b)
Checks inequality for a and b
RCP< const Basic > expand(const RCP< const Basic > &self, bool deep=true)
Expands self
RCP< const Basic > min(const vec_basic &arg)
Canonicalize Min:
bool is_a_Complex(const Basic &b)
RCP< const Rationals > rationals()
void quotient_mod(const Ptr< RCP< const Integer >> &q, const Ptr< RCP< const Integer >> &r, const Integer &n, const Integer &d)
void lucas2(const Ptr< RCP< const Integer >> &g, const Ptr< RCP< const Integer >> &s, unsigned long n)
Lucas number n and n-1.