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::metalcode;
77 using SymEngine::mp_get_si;
78 using SymEngine::mp_get_ui;
79 using SymEngine::numeric_cast;
80 using SymEngine::ones;
81 using SymEngine::parse;
82 using SymEngine::SymEngineException;
83 using SymEngine::zeros;
89 inline bool is_aligned(T *p,
size_t n =
alignof(T))
91 return 0 ==
reinterpret_cast<uintptr_t
>(p) % n;
94 static std::string _str(
const Basic &a)
102 SymEngine::CodePrinterPrecision precision;
109 SymEngine::CodePrinterPrecision
112 if (settings ==
nullptr) {
113 return SymEngine::CodePrinterPrecision::Double;
115 return settings->precision;
122 #define CWRAPPER_BEGIN try {
124 #define CWRAPPER_END \
125 return SYMENGINE_NO_EXCEPTION; \
127 catch (SymEngineException & e) \
129 return e.error_code(); \
133 return SYMENGINE_RUNTIME_ERROR; \
137 SymEngine::RCP<const SymEngine::Basic> m;
141 SymEngine::set_basic m;
145 "Size of 'basic' is not correct");
146 static_assert(std::alignment_of<CRCPBasic>::value
147 == std::alignment_of<CRCPBasic_C>::value,
148 "Alignment of 'basic' is not correct");
150 void basic_new_stack(basic s)
155 void basic_free_stack(basic s)
170 const char *symengine_version()
172 return SYMENGINE_VERSION;
175 void basic_const_set(basic s,
const char *c)
180 void basic_const_zero(basic s)
182 s->m = SymEngine::zero;
185 void basic_const_one(basic s)
187 s->m = SymEngine::one;
190 void basic_const_minus_one(basic s)
192 s->m = SymEngine::minus_one;
195 void basic_const_I(basic s)
200 void basic_const_pi(basic s)
202 s->m = SymEngine::pi;
205 void basic_const_E(basic s)
210 void basic_const_EulerGamma(basic s)
212 s->m = SymEngine::EulerGamma;
215 void basic_const_Catalan(basic s)
217 s->m = SymEngine::Catalan;
220 void basic_const_GoldenRatio(basic s)
222 s->m = SymEngine::GoldenRatio;
225 void basic_const_infinity(basic s)
227 s->m = SymEngine::Inf;
230 void basic_const_neginfinity(basic s)
232 s->m = SymEngine::NegInf;
235 void basic_const_complex_infinity(basic s)
237 s->m = SymEngine::ComplexInf;
240 void basic_const_nan(basic s)
242 s->m = SymEngine::Nan;
245 TypeID basic_get_class_id(
const char *c)
247 static std::map<std::string, TypeID> names = {
248 #define SYMENGINE_INCLUDE_ALL
249 #define SYMENGINE_ENUM(type, Class) {xstr(Class), type},
250 #include "symengine/type_codes.inc"
251 #undef SYMENGINE_ENUM
252 #undef SYMENGINE_INCLUDE_ALL
253 {
"", SYMENGINE_TypeID_Count}};
255 return names[std::string(c)];
258 char *basic_get_class_from_id(TypeID
id)
260 static std::map<TypeID, std::string> names = {
261 #define SYMENGINE_INCLUDE_ALL
262 #define SYMENGINE_ENUM(type, Class) {type, xstr(Class)},
263 #include "symengine/type_codes.inc"
264 #undef SYMENGINE_ENUM
265 #undef SYMENGINE_INCLUDE_ALL
266 {SYMENGINE_TypeID_Count,
""}};
268 std::string name = names[id];
269 auto cc =
new char[name.length() + 1];
270 std::strcpy(cc, name.c_str());
274 TypeID basic_get_type(
const basic s)
276 return static_cast<TypeID
>(s->m->get_type_code());
279 CWRAPPER_OUTPUT_TYPE symbol_set(basic s,
const char *c)
286 int number_is_zero(
const basic s)
289 return (
int)((down_cast<const Number &>(*(s->m))).
is_zero());
292 int number_is_negative(
const basic s)
295 return (
int)((down_cast<const Number &>(*(s->m))).is_negative());
298 int number_is_positive(
const basic s)
301 return (
int)((down_cast<const Number &>(*(s->m))).is_positive());
304 int number_is_complex(
const basic s)
307 return (
int)((down_cast<const Number &>(*(s->m))).is_complex());
310 int basic_has_symbol(
const basic e,
const basic s)
312 return (
int)(has_symbol(*(e->m), *(s->m)));
315 CWRAPPER_OUTPUT_TYPE integer_set_si(basic s,
long i)
322 CWRAPPER_OUTPUT_TYPE integer_set_ui(basic s,
unsigned long i)
329 #if SYMENGINE_INTEGER_CLASS != SYMENGINE_BOOSTMP
330 CWRAPPER_OUTPUT_TYPE integer_set_mpz(basic s,
const mpz_t i)
338 CWRAPPER_OUTPUT_TYPE integer_set_str(basic s,
const char *c)
345 CWRAPPER_OUTPUT_TYPE real_double_set_d(basic s,
double d)
348 s->m = SymEngine::real_double(d);
352 double real_double_get_d(
const basic s)
354 SYMENGINE_ASSERT(is_a<RealDouble>(*(s->m)));
355 return (down_cast<const RealDouble &>(*(s->m))).as_double();
358 #ifdef HAVE_SYMENGINE_MPFR
360 CWRAPPER_OUTPUT_TYPE real_mpfr_set_d(basic s,
double d,
int prec)
363 mpfr_class mc = mpfr_class(prec);
364 mpfr_set_d(mc.get_mpfr_t(), d, MPFR_RNDN);
365 s->m = SymEngine::real_mpfr(std::move(mc));
369 CWRAPPER_OUTPUT_TYPE real_mpfr_set_str(basic s,
const char *c,
int prec)
372 s->m = SymEngine::real_mpfr(mpfr_class(c, prec, 10));
376 double real_mpfr_get_d(
const basic s)
378 SYMENGINE_ASSERT(is_a<RealMPFR>(*(s->m)));
380 ((down_cast<const RealMPFR &>(*(s->m))).as_mpfr()).get_mpfr_t(),
384 CWRAPPER_OUTPUT_TYPE real_mpfr_set(basic s, mpfr_srcptr m)
387 s->m = SymEngine::real_mpfr(mpfr_class(m));
391 CWRAPPER_OUTPUT_TYPE real_mpfr_get(mpfr_ptr m,
const basic s)
394 SYMENGINE_ASSERT(is_a<RealMPFR>(*(s->m)));
395 mpfr_set(m, ((down_cast<const RealMPFR &>(*(s->m))).as_mpfr()).get_mpfr_t(),
400 mpfr_prec_t real_mpfr_get_prec(
const basic s)
402 SYMENGINE_ASSERT(is_a<RealMPFR>(*(s->m)));
403 return ((down_cast<const RealMPFR &>(*(s->m))).as_mpfr()).get_prec();
408 CWRAPPER_OUTPUT_TYPE complex_base_real_part(basic s,
const basic com)
412 s->m = (down_cast<const ComplexBase &>(*(com->m))).real_part();
416 CWRAPPER_OUTPUT_TYPE complex_base_imaginary_part(basic s,
const basic com)
420 s->m = (down_cast<const ComplexBase &>(*(com->m))).imaginary_part();
424 signed long integer_get_si(
const basic s)
426 SYMENGINE_ASSERT(is_a<Integer>(*(s->m)));
427 return mp_get_si((down_cast<const Integer &>(*(s->m))).as_integer_class());
430 unsigned long integer_get_ui(
const basic s)
432 SYMENGINE_ASSERT(is_a<Integer>(*(s->m)));
433 return mp_get_ui((down_cast<const Integer &>(*(s->m))).as_integer_class());
436 #if SYMENGINE_INTEGER_CLASS != SYMENGINE_BOOSTMP
437 CWRAPPER_OUTPUT_TYPE integer_get_mpz(mpz_t a,
const basic s)
440 SYMENGINE_ASSERT(is_a<Integer>(*(s->m)));
442 a, get_mpz_t((down_cast<const Integer &>(*(s->m))).as_integer_class()));
447 CWRAPPER_OUTPUT_TYPE rational_set_si(basic s,
long a,
long b)
454 CWRAPPER_OUTPUT_TYPE rational_set_ui(basic s,
unsigned long a,
unsigned long b)
461 CWRAPPER_OUTPUT_TYPE rational_set(basic s,
const basic a,
const basic b)
463 if (not is_a_Integer(a) or not is_a_Integer(b)) {
464 return SYMENGINE_RUNTIME_ERROR;
467 *(rcp_static_cast<const Integer>(a->m)),
468 *(rcp_static_cast<const Integer>(b->m)));
469 return SYMENGINE_NO_EXCEPTION;
472 #if SYMENGINE_INTEGER_CLASS != SYMENGINE_BOOSTMP
473 CWRAPPER_OUTPUT_TYPE rational_get_mpq(mpq_t a,
const basic s)
476 SYMENGINE_ASSERT(is_a<Rational>(*(s->m)));
477 mpq_set(a, get_mpq_t(
478 (down_cast<const Rational &>(*(s->m))).as_rational_class()));
482 CWRAPPER_OUTPUT_TYPE rational_set_mpq(basic s,
const mpq_t i)
490 CWRAPPER_OUTPUT_TYPE complex_set(basic s,
const basic re,
const basic im)
494 *(rcp_static_cast<const Number>(re->m)),
495 *(rcp_static_cast<const Number>(im->m)));
499 CWRAPPER_OUTPUT_TYPE complex_set_rat(basic s,
const basic re,
const basic im)
503 *(rcp_static_cast<const Rational>(re->m)),
504 *(rcp_static_cast<const Rational>(im->m)));
508 #if SYMENGINE_INTEGER_CLASS != SYMENGINE_BOOSTMP
509 CWRAPPER_OUTPUT_TYPE complex_set_mpq(basic s,
const mpq_t re,
const mpq_t im)
517 dcomplex complex_double_get(
const basic s)
519 SYMENGINE_ASSERT(is_a<ComplexDouble>(*(s->m)));
521 d.real = (down_cast<const ComplexDouble &>(*(s->m)).as_complex_double())
523 d.imag = (down_cast<const ComplexDouble &>(*(s->m)).as_complex_double())
528 char *basic_dumps(
const basic s,
unsigned long *size)
530 std::string str = s->m->dumps();
531 *size = str.length();
532 auto cc =
new char[*size];
537 CWRAPPER_OUTPUT_TYPE basic_loads(basic s,
const char *c,
unsigned long size)
540 std::string data(c, size);
541 s->m = Basic::loads(data);
545 CWRAPPER_OUTPUT_TYPE basic_diff(basic s,
const basic expr, basic
const symbol)
547 if (not is_a_Symbol(
symbol))
548 return SYMENGINE_RUNTIME_ERROR;
550 s->m = expr->m->diff(rcp_static_cast<const Symbol>(
symbol->m));
554 CWRAPPER_OUTPUT_TYPE basic_assign(basic a,
const basic b)
561 CWRAPPER_OUTPUT_TYPE basic_parse(basic b,
const char *str)
564 b->m = SymEngine::parse(str);
568 CWRAPPER_OUTPUT_TYPE basic_parse2(basic b,
const char *str,
int convert_xor)
571 if (convert_xor > 0) {
572 b->m = SymEngine::parse(str);
574 b->m = SymEngine::parse(str,
false);
579 CWRAPPER_OUTPUT_TYPE basic_add(basic s,
const basic a,
const basic b)
586 CWRAPPER_OUTPUT_TYPE basic_sub(basic s,
const basic a,
const basic b)
593 CWRAPPER_OUTPUT_TYPE basic_mul(basic s,
const basic a,
const basic b)
600 CWRAPPER_OUTPUT_TYPE basic_pow(basic s,
const basic a,
const basic b)
603 s->m = SymEngine::pow(a->m, b->m);
607 CWRAPPER_OUTPUT_TYPE basic_div(basic s,
const basic a,
const basic b)
614 int basic_eq(
const basic a,
const basic b)
619 int basic_neq(
const basic a,
const basic b)
624 #define IMPLEMENT_ONE_ARG_FUNC(func) \
625 CWRAPPER_OUTPUT_TYPE basic_##func(basic s, const basic a) \
628 s->m = SymEngine::func(a->m); \
632 IMPLEMENT_ONE_ARG_FUNC(
expand)
633 IMPLEMENT_ONE_ARG_FUNC(neg)
634 IMPLEMENT_ONE_ARG_FUNC(abs)
635 IMPLEMENT_ONE_ARG_FUNC(erf)
636 IMPLEMENT_ONE_ARG_FUNC(erfc)
637 IMPLEMENT_ONE_ARG_FUNC(sin)
638 IMPLEMENT_ONE_ARG_FUNC(cos)
639 IMPLEMENT_ONE_ARG_FUNC(tan)
640 IMPLEMENT_ONE_ARG_FUNC(csc)
641 IMPLEMENT_ONE_ARG_FUNC(sec)
642 IMPLEMENT_ONE_ARG_FUNC(cot)
643 IMPLEMENT_ONE_ARG_FUNC(asin)
644 IMPLEMENT_ONE_ARG_FUNC(acos)
645 IMPLEMENT_ONE_ARG_FUNC(asec)
646 IMPLEMENT_ONE_ARG_FUNC(acsc)
647 IMPLEMENT_ONE_ARG_FUNC(atan)
648 IMPLEMENT_ONE_ARG_FUNC(acot)
649 IMPLEMENT_ONE_ARG_FUNC(sinh)
650 IMPLEMENT_ONE_ARG_FUNC(cosh)
651 IMPLEMENT_ONE_ARG_FUNC(tanh)
652 IMPLEMENT_ONE_ARG_FUNC(csch)
653 IMPLEMENT_ONE_ARG_FUNC(sech)
654 IMPLEMENT_ONE_ARG_FUNC(coth)
655 IMPLEMENT_ONE_ARG_FUNC(asinh)
656 IMPLEMENT_ONE_ARG_FUNC(acosh)
657 IMPLEMENT_ONE_ARG_FUNC(asech)
658 IMPLEMENT_ONE_ARG_FUNC(acsch)
659 IMPLEMENT_ONE_ARG_FUNC(atanh)
660 IMPLEMENT_ONE_ARG_FUNC(acoth)
661 IMPLEMENT_ONE_ARG_FUNC(lambertw)
662 IMPLEMENT_ONE_ARG_FUNC(zeta)
663 IMPLEMENT_ONE_ARG_FUNC(dirichlet_eta)
664 IMPLEMENT_ONE_ARG_FUNC(gamma)
665 IMPLEMENT_ONE_ARG_FUNC(loggamma)
666 IMPLEMENT_ONE_ARG_FUNC(
sqrt)
667 IMPLEMENT_ONE_ARG_FUNC(
cbrt)
668 IMPLEMENT_ONE_ARG_FUNC(exp)
669 IMPLEMENT_ONE_ARG_FUNC(log)
670 IMPLEMENT_ONE_ARG_FUNC(floor)
671 IMPLEMENT_ONE_ARG_FUNC(ceiling)
672 IMPLEMENT_ONE_ARG_FUNC(sign)
674 #define IMPLEMENT_TWO_ARG_FUNC(func) \
675 CWRAPPER_OUTPUT_TYPE basic_##func(basic s, const basic a, const basic b) \
678 s->m = SymEngine::func(a->m, b->m); \
682 IMPLEMENT_TWO_ARG_FUNC(atan2)
683 IMPLEMENT_TWO_ARG_FUNC(kronecker_delta)
684 IMPLEMENT_TWO_ARG_FUNC(lowergamma)
685 IMPLEMENT_TWO_ARG_FUNC(uppergamma)
686 IMPLEMENT_TWO_ARG_FUNC(beta)
687 IMPLEMENT_TWO_ARG_FUNC(polygamma)
689 #define IMPLEMENT_STR_CONVERSION(name, func) \
690 char *basic_##name(const basic s) \
695 } catch (SymEngineException & e) { \
700 auto cc = new char[str.length() + 1]; \
701 std::strcpy(cc, str.c_str()); \
705 #define IMPLEMENT_STR_CONVERSION_SETTINGS(name, func) \
706 char *basic_##name(const basic s, \
707 const BasicCodePrinterSettings *settings) \
711 str = settings == nullptr \
713 : func(*s->m, to_code_printer_precision(settings)); \
714 } catch (SymEngineException & e) { \
719 auto cc = new char[str.length() + 1]; \
720 std::strcpy(cc, str.c_str()); \
724 IMPLEMENT_STR_CONVERSION(str, _str)
725 IMPLEMENT_STR_CONVERSION(str_julia, julia_str)
726 IMPLEMENT_STR_CONVERSION(str_mathml, mathml)
727 IMPLEMENT_STR_CONVERSION(str_latex, latex)
728 IMPLEMENT_STR_CONVERSION(str_jscode, jscode)
729 IMPLEMENT_STR_CONVERSION(str_ccode, ccode)
730 IMPLEMENT_STR_CONVERSION(str_cudacode, cudacode)
731 IMPLEMENT_STR_CONVERSION(str_metalcode, metalcode)
732 IMPLEMENT_STR_CONVERSION_SETTINGS(str_ccode_settings, ccode)
733 IMPLEMENT_STR_CONVERSION_SETTINGS(str_cudacode_settings, cudacode)
734 IMPLEMENT_STR_CONVERSION_SETTINGS(str_metalcode_settings, metalcode)
747 BasicCodePrinterPrecision prec)
749 self->precision =
static_cast<SymEngine::CodePrinterPrecision
>(prec);
752 void basic_str_free(
char *s)
757 void bool_set_true(basic s)
759 s->m = SymEngine::boolTrue;
762 void bool_set_false(basic s)
764 s->m = SymEngine::boolFalse;
767 CWRAPPER_OUTPUT_TYPE basic_set_interval(basic s,
const basic start,
768 const basic end,
int left_open,
776 rcp_static_cast<const Number>(end->m),
777 (
bool)left_open, (
bool)right_open);
781 CWRAPPER_OUTPUT_TYPE basic_set_finiteset(basic s,
const CSetBasic *container)
788 void basic_set_emptyset(basic s)
793 void basic_set_universalset(basic s)
798 void basic_set_complexes(basic s)
803 void basic_set_reals(basic s)
808 void basic_set_rationals(basic s)
813 void basic_set_integers(basic s)
818 CWRAPPER_OUTPUT_TYPE basic_set_union(basic s,
const basic a,
const basic b)
821 s->m = rcp_static_cast<const Set>(a->m)->set_union(
822 rcp_static_cast<const Set>(b->m));
826 CWRAPPER_OUTPUT_TYPE basic_set_intersection(basic s,
const basic a,
830 s->m = rcp_static_cast<const Set>(a->m)->set_intersection(
831 rcp_static_cast<const Set>(b->m));
835 CWRAPPER_OUTPUT_TYPE basic_set_complement(basic s,
const basic a,
const basic b)
838 s->m = rcp_static_cast<const Set>(a->m)->set_complement(
839 rcp_static_cast<const Set>(b->m));
843 CWRAPPER_OUTPUT_TYPE basic_set_contains(basic s,
const basic a,
const basic b)
846 s->m = rcp_static_cast<const Set>(a->m)->contains(b->m);
850 int basic_set_is_subset(
const basic a,
const basic b)
852 SYMENGINE_ASSERT(is_a_Set(*(a->m)));
853 SYMENGINE_ASSERT(is_a_Set(*(b->m)));
854 return rcp_static_cast<const Set>(a->m)->is_subset(
855 rcp_static_cast<const Set>(b->m));
858 int basic_set_is_proper_subset(
const basic a,
const basic b)
860 SYMENGINE_ASSERT(is_a_Set(*(a->m)));
861 SYMENGINE_ASSERT(is_a_Set(*(b->m)));
862 return rcp_static_cast<const Set>(a->m)->is_proper_subset(
863 rcp_static_cast<const Set>(b->m));
866 int basic_set_is_superset(
const basic a,
const basic b)
868 SYMENGINE_ASSERT(is_a_Set(*(a->m)));
869 SYMENGINE_ASSERT(is_a_Set(*(b->m)));
870 return rcp_static_cast<const Set>(a->m)->is_superset(
871 rcp_static_cast<const Set>(b->m));
874 int basic_set_is_proper_superset(
const basic a,
const basic b)
876 SYMENGINE_ASSERT(is_a_Set(*(a->m)));
877 SYMENGINE_ASSERT(is_a_Set(*(b->m)));
878 return rcp_static_cast<const Set>(a->m)->is_proper_superset(
879 rcp_static_cast<const Set>(b->m));
882 CWRAPPER_OUTPUT_TYPE basic_set_inf(basic s,
const basic a)
885 s->m = SymEngine::inf(*rcp_static_cast<const Set>(a->m));
889 CWRAPPER_OUTPUT_TYPE basic_set_sup(basic s,
const basic a)
892 s->m = SymEngine::sup(*rcp_static_cast<const Set>(a->m));
896 CWRAPPER_OUTPUT_TYPE basic_set_boundary(basic s,
const basic a)
899 s->m = SymEngine::boundary(*rcp_static_cast<const Set>(a->m));
903 CWRAPPER_OUTPUT_TYPE basic_set_interior(basic s,
const basic a)
906 s->m = SymEngine::interior(*rcp_static_cast<const Set>(a->m));
910 CWRAPPER_OUTPUT_TYPE basic_set_closure(basic s,
const basic a)
913 s->m = SymEngine::closure(*rcp_static_cast<const Set>(a->m));
917 int symengine_have_component(
const char *c)
919 #ifdef HAVE_SYMENGINE_MPFR
920 if (std::strcmp(
"mpfr", c) == 0)
923 #ifdef HAVE_SYMENGINE_MPC
924 if (std::strcmp(
"mpc", c) == 0)
927 #ifdef HAVE_SYMENGINE_FLINT
928 if (std::strcmp(
"flint", c) == 0)
931 #ifdef HAVE_SYMENGINE_ARB
932 if (std::strcmp(
"arb", c) == 0)
935 #ifdef HAVE_SYMENGINE_ECM
936 if (std::strcmp(
"ecm", c) == 0)
939 #ifdef HAVE_SYMENGINE_PRIMESIEVE
940 if (std::strcmp(
"primesieve", c) == 0)
943 #ifdef HAVE_SYMENGINE_PIRANHA
944 if (std::strcmp(
"piranha", c) == 0)
947 #ifdef HAVE_SYMENGINE_BOOST
948 if (std::strcmp(
"boost", c) == 0)
951 #ifdef HAVE_SYMENGINE_PTHREAD
952 if (std::strcmp(
"pthread", c) == 0)
955 #ifdef HAVE_SYMENGINE_LLVM
956 if (std::strcmp(
"llvm", c) == 0)
959 #ifdef HAVE_SYMENGINE_LLVM_LONG_DOUBLE
960 if (std::strcmp(
"llvm_long_double", c) == 0)
970 int is_a_Integer(
const basic c)
972 return is_a<Integer>(*(c->m));
974 int is_a_Rational(
const basic c)
976 return is_a<Rational>(*(c->m));
978 int is_a_Symbol(
const basic c)
980 return is_a<Symbol>(*(c->m));
984 return is_a<Complex>(*(c->m));
986 int is_a_RealDouble(
const basic c)
988 return is_a<RealDouble>(*(c->m));
990 int is_a_ComplexDouble(
const basic c)
992 return is_a<ComplexDouble>(*(c->m));
994 int is_a_RealMPFR(
const basic c)
996 #ifdef HAVE_SYMENGINE_MPFR
997 return is_a<RealMPFR>(*(c->m));
1002 int is_a_ComplexMPC(
const basic c)
1004 #ifdef HAVE_SYMENGINE_MPC
1005 return is_a<ComplexMPC>(*(c->m));
1010 int is_a_Set(
const basic c)
1012 return SymEngine::is_a_Set(*(c->m));
1026 int vectorint_placement_new_check(
void *data,
size_t size)
1031 if (not SymEngine::is_aligned(
self))
1036 CVectorInt *vectorint_placement_new(
void *data)
1038 #if defined(WITH_SYMENGINE_ASSERT)
1041 SYMENGINE_ASSERT(SymEngine::is_aligned(
self));
1047 void vectorint_placement_free(
CVectorInt *
self)
1049 self->m.~vector<
int>();
1057 void vectorint_push_back(
CVectorInt *
self,
int value)
1059 self->m.push_back(value);
1070 SymEngine::vec_basic m;
1083 CWRAPPER_OUTPUT_TYPE vecbasic_push_back(
CVecBasic *
self,
const basic value)
1087 self->m.push_back(value->m);
1092 CWRAPPER_OUTPUT_TYPE vecbasic_get(
CVecBasic *
self,
size_t n, basic result)
1096 SYMENGINE_ASSERT(n < self->m.size());
1097 result->m =
self->m[n];
1102 CWRAPPER_OUTPUT_TYPE vecbasic_set(
CVecBasic *
self,
size_t n,
const basic s)
1105 SYMENGINE_ASSERT(n < self->m.size());
1110 CWRAPPER_OUTPUT_TYPE vecbasic_erase(
CVecBasic *
self,
size_t n)
1113 SYMENGINE_ASSERT(n < self->m.size());
1114 self->m.erase(self->m.begin() + n);
1120 return self->m.size();
1123 CWRAPPER_OUTPUT_TYPE basic_max(basic s,
const CVecBasic *d)
1130 CWRAPPER_OUTPUT_TYPE basic_min(basic s,
const CVecBasic *d)
1137 CWRAPPER_OUTPUT_TYPE basic_add_vec(basic s,
const CVecBasic *d)
1144 CWRAPPER_OUTPUT_TYPE basic_mul_vec(basic s,
const CVecBasic *d)
1171 CDenseMatrix *dense_matrix_new_rows_cols(
unsigned rows,
unsigned cols)
1196 void sparse_matrix_rows_cols(
CSparseMatrix *s,
unsigned long int rows,
1197 unsigned long int cols)
1200 numeric_cast<unsigned>(cols));
1212 std::string str = s->m.__str__();
1213 auto cc =
new char[str.length() + 1];
1214 std::strcpy(cc, str.c_str());
1220 std::string str = s->m.__str__();
1221 auto cc =
new char[str.length() + 1];
1222 std::strcpy(cc, str.c_str());
1226 CWRAPPER_OUTPUT_TYPE dense_matrix_rows_cols(
CDenseMatrix *mat,
unsigned r,
1230 mat->m.resize(r, c);
1234 CWRAPPER_OUTPUT_TYPE dense_matrix_get_basic(basic s,
const CDenseMatrix *mat,
1235 unsigned long int r,
1236 unsigned long int c)
1239 s->m = mat->m.get(numeric_cast<unsigned>(r), numeric_cast<unsigned>(c));
1243 CWRAPPER_OUTPUT_TYPE dense_matrix_set_basic(
CDenseMatrix *mat,
1244 unsigned long int r,
1245 unsigned long int c, basic s)
1248 mat->m.set(numeric_cast<unsigned>(r), numeric_cast<unsigned>(c), s->m);
1252 CWRAPPER_OUTPUT_TYPE sparse_matrix_get_basic(basic s,
const CSparseMatrix *mat,
1253 unsigned long int r,
1254 unsigned long int c)
1257 s->m = mat->m.get(numeric_cast<unsigned>(r), numeric_cast<unsigned>(c));
1261 CWRAPPER_OUTPUT_TYPE sparse_matrix_set_basic(
CSparseMatrix *mat,
1262 unsigned long int r,
1263 unsigned long int c, basic s)
1266 mat->m.set(numeric_cast<unsigned>(r), numeric_cast<unsigned>(c), s->m);
1270 CWRAPPER_OUTPUT_TYPE dense_matrix_det(basic s,
const CDenseMatrix *mat)
1273 s->m = mat->m.det();
1279 dense_matrix_rows_cols(s, mat->m.nrows(), mat->m.ncols());
1283 CWRAPPER_OUTPUT_TYPE dense_matrix_transpose(
CDenseMatrix *s,
1287 dense_matrix_rows_cols(s, mat->m.ncols(), mat->m.nrows());
1288 mat->m.transpose(s->m);
1291 CWRAPPER_OUTPUT_TYPE
1293 unsigned long int r1,
unsigned long int c1,
1294 unsigned long int r2,
unsigned long int c2,
1295 unsigned long int r,
unsigned long int c)
1298 dense_matrix_rows_cols(s, numeric_cast<unsigned>(r2 - r1 + 1),
1299 numeric_cast<unsigned>(c2 - c1 + 1));
1300 mat->m.submatrix(s->m, numeric_cast<unsigned>(r1),
1301 numeric_cast<unsigned>(c1), numeric_cast<unsigned>(r2),
1302 numeric_cast<unsigned>(c2), numeric_cast<unsigned>(r),
1303 numeric_cast<unsigned>(c));
1307 CWRAPPER_OUTPUT_TYPE dense_matrix_row_join(
CDenseMatrix *A,
1311 A->m.row_join(B->m);
1315 CWRAPPER_OUTPUT_TYPE dense_matrix_col_join(
CDenseMatrix *A,
1319 A->m.col_join(B->m);
1323 CWRAPPER_OUTPUT_TYPE dense_matrix_row_del(
CDenseMatrix *A,
unsigned k)
1330 CWRAPPER_OUTPUT_TYPE dense_matrix_col_del(
CDenseMatrix *A,
unsigned k)
1337 unsigned long int dense_matrix_rows(
const CDenseMatrix *s)
1339 return s->m.nrows();
1342 unsigned long int dense_matrix_cols(
const CDenseMatrix *s)
1344 return s->m.ncols();
1347 CWRAPPER_OUTPUT_TYPE dense_matrix_add_matrix(
CDenseMatrix *s,
1352 dense_matrix_rows_cols(s, matA->m.nrows(), matA->m.ncols());
1353 matA->m.add_matrix(matB->m, s->m);
1357 CWRAPPER_OUTPUT_TYPE dense_matrix_mul_matrix(
CDenseMatrix *s,
1362 dense_matrix_rows_cols(s, matA->m.nrows(), matB->m.ncols());
1363 matA->m.mul_matrix(matB->m, s->m);
1367 CWRAPPER_OUTPUT_TYPE dense_matrix_add_scalar(
CDenseMatrix *s,
1372 dense_matrix_rows_cols(s, matA->m.nrows(), matA->m.ncols());
1373 matA->m.add_scalar(b->m, s->m);
1377 CWRAPPER_OUTPUT_TYPE dense_matrix_mul_scalar(
CDenseMatrix *s,
1382 dense_matrix_rows_cols(s, matA->m.nrows(), matA->m.ncols());
1383 matA->m.mul_scalar(b->m, s->m);
1391 dense_matrix_rows_cols(l, mat->m.nrows(), mat->m.ncols());
1392 dense_matrix_rows_cols(u, mat->m.nrows(), mat->m.ncols());
1393 mat->m.LU(l->m, u->m);
1401 dense_matrix_rows_cols(l, mat->m.nrows(), mat->m.ncols());
1402 dense_matrix_rows_cols(d, mat->m.nrows(), mat->m.ncols());
1403 mat->m.LDL(l->m, d->m);
1407 CWRAPPER_OUTPUT_TYPE dense_matrix_FFLU(
CDenseMatrix *lu,
1411 dense_matrix_rows_cols(lu, mat->m.nrows(), mat->m.ncols());
1421 dense_matrix_rows_cols(l, mat->m.nrows(), mat->m.ncols());
1422 dense_matrix_rows_cols(d, mat->m.nrows(), mat->m.ncols());
1423 dense_matrix_rows_cols(u, mat->m.nrows(), mat->m.ncols());
1424 mat->m.FFLDU(l->m, d->m, u->m);
1428 CWRAPPER_OUTPUT_TYPE dense_matrix_LU_solve(
CDenseMatrix *x,
1433 dense_matrix_rows_cols(x, A->m.ncols(), 1);
1434 A->m.LU_solve(b->m, x->m);
1438 CWRAPPER_OUTPUT_TYPE dense_matrix_ones(
CDenseMatrix *s,
unsigned long int r,
1439 unsigned long int c)
1442 dense_matrix_rows_cols(s, numeric_cast<unsigned>(r),
1443 numeric_cast<unsigned>(c));
1448 CWRAPPER_OUTPUT_TYPE dense_matrix_zeros(
CDenseMatrix *s,
unsigned long int r,
1449 unsigned long int c)
1452 dense_matrix_rows_cols(s, numeric_cast<unsigned>(r),
1453 numeric_cast<unsigned>(c));
1461 unsigned int vec_size = numeric_cast<unsigned>(vecbasic_size(d));
1462 dense_matrix_rows_cols(
1463 s, numeric_cast<unsigned>(vec_size + (k >= 0 ? k : -k)),
1464 numeric_cast<unsigned>(vec_size + (k >= 0 ? k : -k)));
1465 diag(s->m, d->m, numeric_cast<int>(k));
1469 CWRAPPER_OUTPUT_TYPE dense_matrix_eye(
CDenseMatrix *s,
unsigned long int N,
1470 unsigned long int M,
int k)
1473 dense_matrix_rows_cols(s, numeric_cast<unsigned>(N),
1474 numeric_cast<unsigned>(M));
1479 CWRAPPER_OUTPUT_TYPE dense_matrix_diff(
CDenseMatrix *result,
1482 if (not is_a_Symbol(x))
1483 return SYMENGINE_RUNTIME_ERROR;
1485 diff(A->m, rcp_static_cast<const Symbol>(x->m), result->m);
1489 CWRAPPER_OUTPUT_TYPE dense_matrix_jacobian(
CDenseMatrix *result,
1494 jacobian(A->m, x->m, result->m);
1500 return is_a<DenseMatrix>(c->m);
1505 return is_a<CSRMatrix>(c->m);
1510 return (lhs->m) == (rhs->m);
1515 return (lhs->m) == (rhs->m);
1530 int setbasic_insert(
CSetBasic *
self,
const basic value)
1532 return (self->m.insert(value->m)).second ? 1 : 0;
1535 void setbasic_get(
CSetBasic *
self,
int n, basic result)
1537 result->m = *std::next((self->m).begin(), n);
1540 int setbasic_find(
CSetBasic *
self, basic value)
1542 return self->m.find(value->m) != (
self->m).end() ? 1 : 0;
1545 int setbasic_erase(
CSetBasic *
self,
const basic value)
1547 return (self->m.erase(value->m)) ? 1 : 0;
1552 return self->m.size();
1558 SymEngine::map_basic_basic m;
1574 (
self->m)[key->m] = mapped->m;
1577 int mapbasicbasic_get(
CMapBasicBasic *
self,
const basic key, basic mapped)
1579 auto it =
self->m.find(key->m);
1580 if (it != self->m.end()) {
1581 mapped->m = it->second;
1589 return self->m.size();
1594 CWRAPPER_OUTPUT_TYPE basic_get_args(
const basic
self,
CVecBasic *args)
1597 args->m =
self->m->get_args();
1601 CWRAPPER_OUTPUT_TYPE basic_free_symbols(
const basic
self,
CSetBasic *symbols)
1604 symbols->m = SymEngine::free_symbols(*(self->m));
1608 CWRAPPER_OUTPUT_TYPE basic_function_symbols(
CSetBasic *symbols,
1612 symbols->m = SymEngine::atoms<SymEngine::FunctionSymbol>(*(self->m));
1616 size_t basic_hash(
const basic
self)
1618 return static_cast<size_t>(
self->m->hash());
1621 CWRAPPER_OUTPUT_TYPE basic_subs(basic s,
const basic e,
1625 s->m = e->m->subs(mapbb->m);
1629 CWRAPPER_OUTPUT_TYPE basic_subs2(basic s,
const basic e,
const basic a,
1633 s->m = e->m->subs({{a->m, b->m}});
1637 CWRAPPER_OUTPUT_TYPE function_symbol_set(basic s,
const char *c,
1641 s->m = function_symbol(c, arg->m);
1645 char *function_symbol_get_name(
const basic b)
1647 SYMENGINE_ASSERT(is_a<FunctionSymbol>(*(b->m)));
1648 std::string str = down_cast<const FunctionSymbol &>(*(b->m)).get_name();
1649 auto cc =
new char[str.length() + 1];
1650 std::strcpy(cc, str.c_str());
1654 CWRAPPER_OUTPUT_TYPE basic_coeff(basic c,
const basic b,
const basic x,
1658 c->m = SymEngine::coeff(*(b->m), *(x->m), *(n->m));
1668 vec_basic vb = sym->m;
1670 std::all_of(vb.cbegin(), vb.cend(),
1671 [](RCP<const Basic> b) { return is_a<const Symbol>(*b); }));
1672 vec_sym vs(vb.size());
1673 for (
unsigned i = 0; i < vb.size(); i++)
1674 vs[i] = rcp_static_cast<const Symbol>(vb[i]);
1675 sol->m = SymEngine::linsolve(sys->m, vs);
1679 CWRAPPER_OUTPUT_TYPE basic_solve_poly(
CSetBasic *r,
const basic f,
1683 SYMENGINE_ASSERT(is_a<Symbol>(*(s->m)));
1685 = SymEngine::solve_poly(f->m, rcp_static_cast<const Symbol>(s->m));
1686 if (not is_a<FiniteSet>(*set)) {
1687 return SYMENGINE_NOT_IMPLEMENTED;
1689 r->m = down_cast<const FiniteSet &>(*set).get_container();
1695 char *ascii_art_str()
1697 std::string str = SymEngine::ascii_art();
1698 auto cc =
new char[str.length() + 1];
1699 std::strcpy(cc, str.c_str());
1705 CWRAPPER_OUTPUT_TYPE ntheory_gcd(basic s,
const basic a,
const basic b)
1708 SYMENGINE_ASSERT(is_a<Integer>(*(a->m)));
1709 SYMENGINE_ASSERT(is_a<Integer>(*(b->m)));
1711 down_cast<const Integer &>(*(b->m)));
1715 CWRAPPER_OUTPUT_TYPE ntheory_lcm(basic s,
const basic a,
const basic b)
1718 SYMENGINE_ASSERT(is_a<Integer>(*(a->m)));
1719 SYMENGINE_ASSERT(is_a<Integer>(*(b->m)));
1721 down_cast<const Integer &>(*(b->m)));
1725 CWRAPPER_OUTPUT_TYPE ntheory_gcd_ext(basic g, basic s, basic t,
const basic a,
1729 SYMENGINE_ASSERT(is_a<Integer>(*(a->m)));
1730 SYMENGINE_ASSERT(is_a<Integer>(*(b->m)));
1731 SymEngine::RCP<const Integer> g_, s_, t_;
1733 SymEngine::outArg(t_),
1734 down_cast<const Integer &>(*(a->m)),
1735 down_cast<const Integer &>(*(b->m)));
1742 CWRAPPER_OUTPUT_TYPE ntheory_nextprime(basic s,
const basic a)
1745 SYMENGINE_ASSERT(is_a<Integer>(*(a->m)));
1750 CWRAPPER_OUTPUT_TYPE ntheory_mod(basic s,
const basic n,
const basic d)
1753 SYMENGINE_ASSERT(is_a<Integer>(*(n->m)));
1754 SYMENGINE_ASSERT(is_a<Integer>(*(d->m)));
1756 down_cast<const Integer &>(*(d->m)));
1760 CWRAPPER_OUTPUT_TYPE ntheory_quotient(basic s,
const basic n,
const basic d)
1763 SYMENGINE_ASSERT(is_a<Integer>(*(n->m)));
1764 SYMENGINE_ASSERT(is_a<Integer>(*(d->m)));
1766 down_cast<const Integer &>(*(d->m)));
1770 CWRAPPER_OUTPUT_TYPE ntheory_quotient_mod(basic q, basic r,
const basic n,
1774 SYMENGINE_ASSERT(is_a<Integer>(*(n->m)));
1775 SYMENGINE_ASSERT(is_a<Integer>(*(d->m)));
1776 SymEngine::RCP<const Integer> q_, r_;
1778 down_cast<const Integer &>(*(n->m)),
1779 down_cast<const Integer &>(*(d->m)));
1785 CWRAPPER_OUTPUT_TYPE ntheory_mod_f(basic s,
const basic n,
const basic d)
1788 SYMENGINE_ASSERT(is_a<Integer>(*(n->m)));
1789 SYMENGINE_ASSERT(is_a<Integer>(*(d->m)));
1791 down_cast<const Integer &>(*(d->m)));
1795 CWRAPPER_OUTPUT_TYPE ntheory_quotient_f(basic s,
const basic n,
const basic d)
1798 SYMENGINE_ASSERT(is_a<Integer>(*(n->m)));
1799 SYMENGINE_ASSERT(is_a<Integer>(*(d->m)));
1801 down_cast<const Integer &>(*(d->m)));
1805 CWRAPPER_OUTPUT_TYPE ntheory_quotient_mod_f(basic q, basic r,
const basic n,
1809 SYMENGINE_ASSERT(is_a<Integer>(*(n->m)));
1810 SYMENGINE_ASSERT(is_a<Integer>(*(d->m)));
1811 SymEngine::RCP<const Integer> q_, r_;
1813 down_cast<const Integer &>(*(n->m)),
1814 down_cast<const Integer &>(*(d->m)));
1820 int ntheory_mod_inverse(basic b,
const basic a,
const basic m)
1823 SYMENGINE_ASSERT(is_a<Integer>(*(a->m)));
1824 SYMENGINE_ASSERT(is_a<Integer>(*(m->m)));
1825 SymEngine::RCP<const Integer> b_;
1827 down_cast<const Integer &>(*(a->m)),
1828 down_cast<const Integer &>(*(m->m)));
1833 CWRAPPER_OUTPUT_TYPE ntheory_fibonacci(basic s,
unsigned long a)
1840 CWRAPPER_OUTPUT_TYPE ntheory_fibonacci2(basic g, basic s,
unsigned long a)
1843 SymEngine::RCP<const Integer> g_, s_;
1850 CWRAPPER_OUTPUT_TYPE ntheory_lucas(basic s,
unsigned long a)
1857 CWRAPPER_OUTPUT_TYPE ntheory_lucas2(basic g, basic s,
unsigned long a)
1860 SymEngine::RCP<const Integer> g_, s_;
1867 CWRAPPER_OUTPUT_TYPE ntheory_binomial(basic s,
const basic a,
unsigned long b)
1870 SYMENGINE_ASSERT(is_a<Integer>(*(a->m)));
1875 CWRAPPER_OUTPUT_TYPE ntheory_factorial(basic s,
unsigned long n)
1883 CWRAPPER_OUTPUT_TYPE basic_evalf(basic s,
const basic b,
unsigned long bits,
1888 s->m = SymEngine::evalf(*(b->m), bits, (SymEngine::EvalfDomain)real);
1892 CWRAPPER_OUTPUT_TYPE basic_as_numer_denom(basic numer, basic denom,
1896 SymEngine::as_numer_denom(x->m, SymEngine::outArg(numer->m),
1897 SymEngine::outArg(denom->m));
1901 CWRAPPER_OUTPUT_TYPE basic_add_as_two_terms(basic term1, basic term2,
1905 SYMENGINE_ASSERT(is_a<Add>(*(s->m)));
1906 rcp_static_cast<const Add>(s->m)->as_two_terms(SymEngine::outArg(term1->m),
1907 SymEngine::outArg(term2->m));
1911 CWRAPPER_OUTPUT_TYPE basic_mul_as_two_terms(basic term1, basic term2,
1915 SYMENGINE_ASSERT(is_a<Mul>(*(s->m)));
1916 rcp_static_cast<const Mul>(s->m)->as_two_terms(SymEngine::outArg(term1->m),
1917 SymEngine::outArg(term2->m));
1932 const CVecBasic *exprs,
int perform_cse)
1934 self->m.init(args->m, exprs->m, perform_cse);
1939 const double *
const inps)
1941 self->m.call(outs, inps);
1949 #ifdef HAVE_SYMENGINE_LLVM
1951 struct CLLVMDoubleVisitor {
1952 SymEngine::LLVMDoubleVisitor m;
1955 CLLVMDoubleVisitor *llvm_double_visitor_new()
1957 return new CLLVMDoubleVisitor();
1960 void llvm_double_visitor_init(CLLVMDoubleVisitor *
self,
const CVecBasic *args,
1961 const CVecBasic *exprs,
int perform_cse,
1964 self->m.init(args->m, exprs->m, perform_cse, opt_level);
1967 void llvm_double_visitor_call(CLLVMDoubleVisitor *
self,
double *
const outs,
1968 const double *
const inps)
1970 self->m.call(outs, inps);
1973 void llvm_double_visitor_free(CLLVMDoubleVisitor *
self)
1978 struct CLLVMFloatVisitor {
1979 SymEngine::LLVMFloatVisitor m;
1982 CLLVMFloatVisitor *llvm_float_visitor_new()
1984 return new CLLVMFloatVisitor();
1987 void llvm_float_visitor_init(CLLVMFloatVisitor *
self,
const CVecBasic *args,
1988 const CVecBasic *exprs,
int perform_cse,
1991 self->m.init(args->m, exprs->m, perform_cse, opt_level);
1994 void llvm_float_visitor_call(CLLVMFloatVisitor *
self,
float *
const outs,
1995 const float *
const inps)
1997 self->m.call(outs, inps);
2000 void llvm_float_visitor_free(CLLVMFloatVisitor *
self)
2004 #ifdef SYMENGINE_HAVE_LLVM_LONG_DOUBLE
2006 struct CLLVMLongDoubleVisitor {
2007 SymEngine::LLVMLongDoubleVisitor m;
2010 CLLVMLongDoubleVisitor *llvm_long_double_visitor_new()
2012 return new CLLVMLongDoubleVisitor();
2015 void llvm_long_double_visitor_init(CLLVMLongDoubleVisitor *
self,
2017 const CVecBasic *exprs,
int perform_cse,
2020 self->m.init(args->m, exprs->m, perform_cse, opt_level);
2023 void llvm_long_double_visitor_call(CLLVMLongDoubleVisitor *
self,
2024 long double *
const outs,
2025 const long double *
const inps)
2027 self->m.call(outs, inps);
2030 void llvm_long_double_visitor_free(CLLVMLongDoubleVisitor *
self)
2037 CWRAPPER_OUTPUT_TYPE basic_cse(
CVecBasic *replacement_syms,
2042 vec_pair replacements;
2043 SymEngine::cse(replacements, reduced_exprs->m, exprs->m);
2044 for (
auto &p : replacements) {
2045 replacement_syms->m.push_back(p.first);
2046 replacement_exprs->m.push_back(p.second);
2051 void symengine_print_stack_on_segfault()
2053 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.