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");
151 static inline SymEngine::RCP<const SymEngine::Basic> &basic_rcp(
basic_struct *s)
153 return reinterpret_cast<CRCPBasic *
>(s)->m;
156 static inline const SymEngine::RCP<const SymEngine::Basic> &
159 return reinterpret_cast<const CRCPBasic *
>(s)->m;
163 void basic_new_stack(basic s)
168 void basic_free_stack(basic s)
183 const char *symengine_version()
185 return SYMENGINE_VERSION;
188 void basic_const_set(basic s,
const char *c)
193 void basic_const_zero(basic s)
195 basic_rcp(s) = SymEngine::zero;
198 void basic_const_one(basic s)
200 basic_rcp(s) = SymEngine::one;
203 void basic_const_minus_one(basic s)
205 basic_rcp(s) = SymEngine::minus_one;
208 void basic_const_I(basic s)
210 basic_rcp(s) = SymEngine::I;
213 void basic_const_pi(basic s)
215 basic_rcp(s) = SymEngine::pi;
218 void basic_const_E(basic s)
220 basic_rcp(s) = SymEngine::E;
223 void basic_const_EulerGamma(basic s)
225 basic_rcp(s) = SymEngine::EulerGamma;
228 void basic_const_Catalan(basic s)
230 basic_rcp(s) = SymEngine::Catalan;
233 void basic_const_GoldenRatio(basic s)
235 basic_rcp(s) = SymEngine::GoldenRatio;
238 void basic_const_infinity(basic s)
240 basic_rcp(s) = SymEngine::Inf;
243 void basic_const_neginfinity(basic s)
245 basic_rcp(s) = SymEngine::NegInf;
248 void basic_const_complex_infinity(basic s)
250 basic_rcp(s) = SymEngine::ComplexInf;
253 void basic_const_nan(basic s)
255 basic_rcp(s) = SymEngine::Nan;
258 TypeID basic_get_class_id(
const char *c)
260 static std::map<std::string, TypeID> names = {
261 #define SYMENGINE_INCLUDE_ALL
262 #define SYMENGINE_ENUM(type, Class) {xstr(Class), type},
263 #include "symengine/type_codes.inc"
264 #undef SYMENGINE_ENUM
265 #undef SYMENGINE_INCLUDE_ALL
266 {
"", SYMENGINE_TypeID_Count}};
268 return names[std::string(c)];
271 char *basic_get_class_from_id(TypeID
id)
273 static std::map<TypeID, std::string> names = {
274 #define SYMENGINE_INCLUDE_ALL
275 #define SYMENGINE_ENUM(type, Class) {type, xstr(Class)},
276 #include "symengine/type_codes.inc"
277 #undef SYMENGINE_ENUM
278 #undef SYMENGINE_INCLUDE_ALL
279 {SYMENGINE_TypeID_Count,
""}};
281 std::string name = names[id];
282 auto cc =
new char[name.length() + 1];
283 std::strcpy(cc, name.c_str());
287 TypeID basic_get_type(
const basic s)
289 return static_cast<TypeID
>(basic_rcp(s)->get_type_code());
292 CWRAPPER_OUTPUT_TYPE symbol_set(basic s,
const char *c)
299 int number_is_zero(
const basic s)
302 return (
int)((down_cast<const Number &>(*(basic_rcp(s)))).
is_zero());
305 int number_is_negative(
const basic s)
308 return (
int)((down_cast<const Number &>(*(basic_rcp(s)))).is_negative());
311 int number_is_positive(
const basic s)
314 return (
int)((down_cast<const Number &>(*(basic_rcp(s)))).is_positive());
317 int number_is_complex(
const basic s)
320 return (
int)((down_cast<const Number &>(*(basic_rcp(s)))).is_complex());
323 int basic_has_symbol(
const basic e,
const basic s)
325 return (
int)(has_symbol(*(basic_rcp(e)), *(basic_rcp(s))));
328 CWRAPPER_OUTPUT_TYPE integer_set_si(basic s,
long i)
335 CWRAPPER_OUTPUT_TYPE integer_set_ui(basic s,
unsigned long i)
342 #if SYMENGINE_INTEGER_CLASS != SYMENGINE_BOOSTMP
343 CWRAPPER_OUTPUT_TYPE integer_set_mpz(basic s,
const mpz_t i)
351 CWRAPPER_OUTPUT_TYPE integer_set_str(basic s,
const char *c)
358 CWRAPPER_OUTPUT_TYPE real_double_set_d(basic s,
double d)
361 basic_rcp(s) = SymEngine::real_double(d);
365 double real_double_get_d(
const basic s)
367 SYMENGINE_ASSERT(is_a<RealDouble>(*(basic_rcp(s))));
368 return (down_cast<const RealDouble &>(*(basic_rcp(s)))).as_double();
371 #ifdef HAVE_SYMENGINE_MPFR
373 CWRAPPER_OUTPUT_TYPE real_mpfr_set_d(basic s,
double d,
int prec)
376 mpfr_class mc = mpfr_class(prec);
377 mpfr_set_d(mc.get_mpfr_t(), d, MPFR_RNDN);
378 basic_rcp(s) = SymEngine::real_mpfr(std::move(mc));
382 CWRAPPER_OUTPUT_TYPE real_mpfr_set_str(basic s,
const char *c,
int prec)
385 basic_rcp(s) = SymEngine::real_mpfr(mpfr_class(c, prec, 10));
389 double real_mpfr_get_d(
const basic s)
391 SYMENGINE_ASSERT(is_a<RealMPFR>(*(basic_rcp(s))));
393 ((down_cast<const RealMPFR &>(*(basic_rcp(s)))).as_mpfr()).get_mpfr_t(),
397 CWRAPPER_OUTPUT_TYPE real_mpfr_set(basic s, mpfr_srcptr m)
400 basic_rcp(s) = SymEngine::real_mpfr(mpfr_class(m));
404 CWRAPPER_OUTPUT_TYPE real_mpfr_get(mpfr_ptr m,
const basic s)
407 SYMENGINE_ASSERT(is_a<RealMPFR>(*(basic_rcp(s))));
410 ((down_cast<const RealMPFR &>(*(basic_rcp(s)))).as_mpfr()).get_mpfr_t(),
415 mpfr_prec_t real_mpfr_get_prec(
const basic s)
417 SYMENGINE_ASSERT(is_a<RealMPFR>(*(basic_rcp(s))));
418 return ((down_cast<const RealMPFR &>(*(basic_rcp(s)))).as_mpfr())
424 CWRAPPER_OUTPUT_TYPE complex_base_real_part(basic s,
const basic com)
429 = (down_cast<const ComplexBase &>(*(basic_rcp(com)))).real_part();
433 CWRAPPER_OUTPUT_TYPE complex_base_imaginary_part(basic s,
const basic com)
438 = (down_cast<const ComplexBase &>(*(basic_rcp(com)))).imaginary_part();
442 signed long integer_get_si(
const basic s)
444 SYMENGINE_ASSERT(is_a<Integer>(*(basic_rcp(s))));
446 (down_cast<const Integer &>(*(basic_rcp(s)))).as_integer_class());
449 unsigned long integer_get_ui(
const basic s)
451 SYMENGINE_ASSERT(is_a<Integer>(*(basic_rcp(s))));
453 (down_cast<const Integer &>(*(basic_rcp(s)))).as_integer_class());
456 #if SYMENGINE_INTEGER_CLASS != SYMENGINE_BOOSTMP
457 CWRAPPER_OUTPUT_TYPE integer_get_mpz(mpz_t a,
const basic s)
460 SYMENGINE_ASSERT(is_a<Integer>(*(basic_rcp(s))));
464 (down_cast<const Integer &>(*(basic_rcp(s)))).as_integer_class()));
469 CWRAPPER_OUTPUT_TYPE rational_set_si(basic s,
long a,
long b)
476 CWRAPPER_OUTPUT_TYPE rational_set_ui(basic s,
unsigned long a,
unsigned long b)
483 CWRAPPER_OUTPUT_TYPE rational_set(basic s,
const basic a,
const basic b)
485 if (not is_a_Integer(a) or not is_a_Integer(b)) {
486 return SYMENGINE_RUNTIME_ERROR;
489 *(rcp_static_cast<const Integer>(basic_rcp(a))),
490 *(rcp_static_cast<const Integer>(basic_rcp(b))));
491 return SYMENGINE_NO_EXCEPTION;
494 #if SYMENGINE_INTEGER_CLASS != SYMENGINE_BOOSTMP
495 CWRAPPER_OUTPUT_TYPE rational_get_mpq(mpq_t a,
const basic s)
498 SYMENGINE_ASSERT(is_a<Rational>(*(basic_rcp(s))));
499 mpq_set(a, get_mpq_t((down_cast<const Rational &>(*(basic_rcp(s))))
500 .as_rational_class()));
504 CWRAPPER_OUTPUT_TYPE rational_set_mpq(basic s,
const mpq_t i)
512 CWRAPPER_OUTPUT_TYPE complex_set(basic s,
const basic re,
const basic im)
516 *(rcp_static_cast<const Number>(basic_rcp(re))),
517 *(rcp_static_cast<const Number>(basic_rcp(im))));
521 CWRAPPER_OUTPUT_TYPE complex_set_rat(basic s,
const basic re,
const basic im)
525 *(rcp_static_cast<const Rational>(basic_rcp(re))),
526 *(rcp_static_cast<const Rational>(basic_rcp(im))));
530 #if SYMENGINE_INTEGER_CLASS != SYMENGINE_BOOSTMP
531 CWRAPPER_OUTPUT_TYPE complex_set_mpq(basic s,
const mpq_t re,
const mpq_t im)
540 dcomplex complex_double_get(
const basic s)
542 SYMENGINE_ASSERT(is_a<ComplexDouble>(*(basic_rcp(s))));
544 d.real = (down_cast<const ComplexDouble &>(*(basic_rcp(s)))
545 .as_complex_double())
547 d.imag = (down_cast<const ComplexDouble &>(*(basic_rcp(s)))
548 .as_complex_double())
553 char *basic_dumps(
const basic s,
unsigned long *size)
555 std::string str = basic_rcp(s)->dumps();
556 *size = str.length();
557 auto cc =
new char[*size];
562 CWRAPPER_OUTPUT_TYPE basic_loads(basic s,
const char *c,
unsigned long size)
565 std::string data(c, size);
566 basic_rcp(s) = Basic::loads(data);
570 CWRAPPER_OUTPUT_TYPE basic_diff(basic s,
const basic expr, basic
const symbol)
572 if (not is_a_Symbol(
symbol))
573 return SYMENGINE_RUNTIME_ERROR;
575 basic_rcp(s) = basic_rcp(expr)->diff(
576 rcp_static_cast<const Symbol>(basic_rcp(
symbol)));
580 CWRAPPER_OUTPUT_TYPE basic_assign(basic a,
const basic b)
583 basic_rcp(a) = basic_rcp(b);
587 CWRAPPER_OUTPUT_TYPE basic_parse(basic b,
const char *str)
590 basic_rcp(b) = SymEngine::parse(str);
594 CWRAPPER_OUTPUT_TYPE basic_parse2(basic b,
const char *str,
int convert_xor)
597 if (convert_xor > 0) {
598 basic_rcp(b) = SymEngine::parse(str);
600 basic_rcp(b) = SymEngine::parse(str,
false);
605 CWRAPPER_OUTPUT_TYPE basic_add(basic s,
const basic a,
const basic b)
612 CWRAPPER_OUTPUT_TYPE basic_sub(basic s,
const basic a,
const basic b)
619 CWRAPPER_OUTPUT_TYPE basic_mul(basic s,
const basic a,
const basic b)
626 CWRAPPER_OUTPUT_TYPE basic_pow(basic s,
const basic a,
const basic b)
629 basic_rcp(s) = SymEngine::pow(basic_rcp(a), basic_rcp(b));
633 CWRAPPER_OUTPUT_TYPE basic_div(basic s,
const basic a,
const basic b)
640 int basic_eq(
const basic a,
const basic b)
642 return SymEngine::eq(*(basic_rcp(a)), *(basic_rcp(b))) ? 1 : 0;
645 int basic_neq(
const basic a,
const basic b)
650 #define IMPLEMENT_ONE_ARG_FUNC(func) \
651 CWRAPPER_OUTPUT_TYPE basic_##func(basic s, const basic a) \
654 basic_rcp(s) = SymEngine::func(basic_rcp(a)); \
658 IMPLEMENT_ONE_ARG_FUNC(
expand)
659 IMPLEMENT_ONE_ARG_FUNC(neg)
660 IMPLEMENT_ONE_ARG_FUNC(abs)
661 IMPLEMENT_ONE_ARG_FUNC(erf)
662 IMPLEMENT_ONE_ARG_FUNC(erfc)
663 IMPLEMENT_ONE_ARG_FUNC(sin)
664 IMPLEMENT_ONE_ARG_FUNC(cos)
665 IMPLEMENT_ONE_ARG_FUNC(tan)
666 IMPLEMENT_ONE_ARG_FUNC(csc)
667 IMPLEMENT_ONE_ARG_FUNC(sec)
668 IMPLEMENT_ONE_ARG_FUNC(cot)
669 IMPLEMENT_ONE_ARG_FUNC(asin)
670 IMPLEMENT_ONE_ARG_FUNC(acos)
671 IMPLEMENT_ONE_ARG_FUNC(asec)
672 IMPLEMENT_ONE_ARG_FUNC(acsc)
673 IMPLEMENT_ONE_ARG_FUNC(atan)
674 IMPLEMENT_ONE_ARG_FUNC(acot)
675 IMPLEMENT_ONE_ARG_FUNC(sinh)
676 IMPLEMENT_ONE_ARG_FUNC(cosh)
677 IMPLEMENT_ONE_ARG_FUNC(tanh)
678 IMPLEMENT_ONE_ARG_FUNC(csch)
679 IMPLEMENT_ONE_ARG_FUNC(sech)
680 IMPLEMENT_ONE_ARG_FUNC(coth)
681 IMPLEMENT_ONE_ARG_FUNC(asinh)
682 IMPLEMENT_ONE_ARG_FUNC(acosh)
683 IMPLEMENT_ONE_ARG_FUNC(asech)
684 IMPLEMENT_ONE_ARG_FUNC(acsch)
685 IMPLEMENT_ONE_ARG_FUNC(atanh)
686 IMPLEMENT_ONE_ARG_FUNC(acoth)
687 IMPLEMENT_ONE_ARG_FUNC(lambertw)
688 IMPLEMENT_ONE_ARG_FUNC(zeta)
689 IMPLEMENT_ONE_ARG_FUNC(dirichlet_eta)
690 IMPLEMENT_ONE_ARG_FUNC(gamma)
691 IMPLEMENT_ONE_ARG_FUNC(loggamma)
692 IMPLEMENT_ONE_ARG_FUNC(
sqrt)
693 IMPLEMENT_ONE_ARG_FUNC(
cbrt)
694 IMPLEMENT_ONE_ARG_FUNC(exp)
695 IMPLEMENT_ONE_ARG_FUNC(log)
696 IMPLEMENT_ONE_ARG_FUNC(floor)
697 IMPLEMENT_ONE_ARG_FUNC(ceiling)
698 IMPLEMENT_ONE_ARG_FUNC(sign)
700 #define IMPLEMENT_TWO_ARG_FUNC(func) \
701 CWRAPPER_OUTPUT_TYPE basic_##func(basic s, const basic a, const basic b) \
704 basic_rcp(s) = SymEngine::func(basic_rcp(a), basic_rcp(b)); \
708 IMPLEMENT_TWO_ARG_FUNC(atan2)
709 IMPLEMENT_TWO_ARG_FUNC(kronecker_delta)
710 IMPLEMENT_TWO_ARG_FUNC(lowergamma)
711 IMPLEMENT_TWO_ARG_FUNC(uppergamma)
712 IMPLEMENT_TWO_ARG_FUNC(beta)
713 IMPLEMENT_TWO_ARG_FUNC(polygamma)
715 #define IMPLEMENT_STR_CONVERSION(name, func) \
716 char *basic_##name(const basic s) \
720 str = func(*basic_rcp(s)); \
721 } catch (SymEngineException & e) { \
726 auto cc = new char[str.length() + 1]; \
727 std::strcpy(cc, str.c_str()); \
731 #define IMPLEMENT_STR_CONVERSION_SETTINGS(name, func) \
732 char *basic_##name(const basic s, \
733 const BasicCodePrinterSettings *settings) \
737 str = settings == nullptr \
738 ? func(*basic_rcp(s)) \
739 : func(*basic_rcp(s), \
740 to_code_printer_precision(settings)); \
741 } catch (SymEngineException & e) { \
746 auto cc = new char[str.length() + 1]; \
747 std::strcpy(cc, str.c_str()); \
751 IMPLEMENT_STR_CONVERSION(str, _str)
752 IMPLEMENT_STR_CONVERSION(str_julia, julia_str)
753 IMPLEMENT_STR_CONVERSION(str_mathml, mathml)
754 IMPLEMENT_STR_CONVERSION(str_latex, latex)
755 IMPLEMENT_STR_CONVERSION(str_jscode, jscode)
756 IMPLEMENT_STR_CONVERSION(str_ccode, ccode)
757 IMPLEMENT_STR_CONVERSION(str_cudacode, cudacode)
758 IMPLEMENT_STR_CONVERSION(str_metalcode, metalcode)
759 IMPLEMENT_STR_CONVERSION_SETTINGS(str_ccode_settings, ccode)
760 IMPLEMENT_STR_CONVERSION_SETTINGS(str_cudacode_settings, cudacode)
761 IMPLEMENT_STR_CONVERSION_SETTINGS(str_metalcode_settings, metalcode)
774 BasicCodePrinterPrecision prec)
776 self->precision =
static_cast<SymEngine::CodePrinterPrecision
>(prec);
779 void basic_str_free(
char *s)
784 void bool_set_true(basic s)
786 basic_rcp(s) = SymEngine::boolTrue;
789 void bool_set_false(basic s)
791 basic_rcp(s) = SymEngine::boolFalse;
794 CWRAPPER_OUTPUT_TYPE basic_set_interval(basic s,
const basic start,
795 const basic end,
int left_open,
798 SYMENGINE_ASSERT(
is_a_Number(*(basic_rcp(start))));
804 rcp_static_cast<const Number>(basic_rcp(end)),
805 (
bool)left_open, (
bool)right_open);
809 CWRAPPER_OUTPUT_TYPE basic_set_finiteset(basic s,
const CSetBasic *container)
816 void basic_set_emptyset(basic s)
821 void basic_set_universalset(basic s)
826 void basic_set_complexes(basic s)
831 void basic_set_reals(basic s)
836 void basic_set_rationals(basic s)
841 void basic_set_integers(basic s)
846 CWRAPPER_OUTPUT_TYPE basic_set_union(basic s,
const basic a,
const basic b)
849 basic_rcp(s) = rcp_static_cast<const Set>(basic_rcp(a))
850 ->set_union(rcp_static_cast<const Set>(basic_rcp(b)));
854 CWRAPPER_OUTPUT_TYPE basic_set_intersection(basic s,
const basic a,
859 = rcp_static_cast<const Set>(basic_rcp(a))
860 ->set_intersection(rcp_static_cast<const Set>(basic_rcp(b)));
864 CWRAPPER_OUTPUT_TYPE basic_set_complement(basic s,
const basic a,
const basic b)
868 = rcp_static_cast<const Set>(basic_rcp(a))
869 ->set_complement(rcp_static_cast<const Set>(basic_rcp(b)));
873 CWRAPPER_OUTPUT_TYPE basic_set_contains(basic s,
const basic a,
const basic b)
877 = rcp_static_cast<const Set>(basic_rcp(a))->contains(basic_rcp(b));
881 int basic_set_is_subset(
const basic a,
const basic b)
883 SYMENGINE_ASSERT(is_a_Set(*(basic_rcp(a))));
884 SYMENGINE_ASSERT(is_a_Set(*(basic_rcp(b))));
885 return rcp_static_cast<const Set>(basic_rcp(a))
886 ->is_subset(rcp_static_cast<const Set>(basic_rcp(b)));
889 int basic_set_is_proper_subset(
const basic a,
const basic b)
891 SYMENGINE_ASSERT(is_a_Set(*(basic_rcp(a))));
892 SYMENGINE_ASSERT(is_a_Set(*(basic_rcp(b))));
893 return rcp_static_cast<const Set>(basic_rcp(a))
894 ->is_proper_subset(rcp_static_cast<const Set>(basic_rcp(b)));
897 int basic_set_is_superset(
const basic a,
const basic b)
899 SYMENGINE_ASSERT(is_a_Set(*(basic_rcp(a))));
900 SYMENGINE_ASSERT(is_a_Set(*(basic_rcp(b))));
901 return rcp_static_cast<const Set>(basic_rcp(a))
902 ->is_superset(rcp_static_cast<const Set>(basic_rcp(b)));
905 int basic_set_is_proper_superset(
const basic a,
const basic b)
907 SYMENGINE_ASSERT(is_a_Set(*(basic_rcp(a))));
908 SYMENGINE_ASSERT(is_a_Set(*(basic_rcp(b))));
909 return rcp_static_cast<const Set>(basic_rcp(a))
910 ->is_proper_superset(rcp_static_cast<const Set>(basic_rcp(b)));
913 CWRAPPER_OUTPUT_TYPE basic_set_inf(basic s,
const basic a)
916 basic_rcp(s) = SymEngine::inf(*rcp_static_cast<const Set>(basic_rcp(a)));
920 CWRAPPER_OUTPUT_TYPE basic_set_sup(basic s,
const basic a)
923 basic_rcp(s) = SymEngine::sup(*rcp_static_cast<const Set>(basic_rcp(a)));
927 CWRAPPER_OUTPUT_TYPE basic_set_boundary(basic s,
const basic a)
931 = SymEngine::boundary(*rcp_static_cast<const Set>(basic_rcp(a)));
935 CWRAPPER_OUTPUT_TYPE basic_set_interior(basic s,
const basic a)
939 = SymEngine::interior(*rcp_static_cast<const Set>(basic_rcp(a)));
943 CWRAPPER_OUTPUT_TYPE basic_set_closure(basic s,
const basic a)
947 = SymEngine::closure(*rcp_static_cast<const Set>(basic_rcp(a)));
951 int symengine_have_component(
const char *c)
953 #ifdef HAVE_SYMENGINE_MPFR
954 if (std::strcmp(
"mpfr", c) == 0)
957 #ifdef HAVE_SYMENGINE_MPC
958 if (std::strcmp(
"mpc", c) == 0)
961 #ifdef HAVE_SYMENGINE_FLINT
962 if (std::strcmp(
"flint", c) == 0)
965 #ifdef HAVE_SYMENGINE_ARB
966 if (std::strcmp(
"arb", c) == 0)
969 #ifdef HAVE_SYMENGINE_ECM
970 if (std::strcmp(
"ecm", c) == 0)
973 #ifdef HAVE_SYMENGINE_PRIMESIEVE
974 if (std::strcmp(
"primesieve", c) == 0)
977 #ifdef HAVE_SYMENGINE_PIRANHA
978 if (std::strcmp(
"piranha", c) == 0)
981 #ifdef HAVE_SYMENGINE_BOOST
982 if (std::strcmp(
"boost", c) == 0)
985 #ifdef HAVE_SYMENGINE_PTHREAD
986 if (std::strcmp(
"pthread", c) == 0)
989 #ifdef HAVE_SYMENGINE_LLVM
990 if (std::strcmp(
"llvm", c) == 0)
993 #ifdef HAVE_SYMENGINE_LLVM_LONG_DOUBLE
994 if (std::strcmp(
"llvm_long_double", c) == 0)
1004 int is_a_Integer(
const basic c)
1006 return is_a<Integer>(*(basic_rcp(c)));
1008 int is_a_Rational(
const basic c)
1010 return is_a<Rational>(*(basic_rcp(c)));
1012 int is_a_Symbol(
const basic c)
1014 return is_a<Symbol>(*(basic_rcp(c)));
1018 return is_a<Complex>(*(basic_rcp(c)));
1020 int is_a_RealDouble(
const basic c)
1022 return is_a<RealDouble>(*(basic_rcp(c)));
1024 int is_a_ComplexDouble(
const basic c)
1026 return is_a<ComplexDouble>(*(basic_rcp(c)));
1028 int is_a_RealMPFR(
const basic c)
1030 #ifdef HAVE_SYMENGINE_MPFR
1031 return is_a<RealMPFR>(*(basic_rcp(c)));
1036 int is_a_ComplexMPC(
const basic c)
1038 #ifdef HAVE_SYMENGINE_MPC
1039 return is_a<ComplexMPC>(*(basic_rcp(c)));
1044 int is_a_Set(
const basic c)
1046 return SymEngine::is_a_Set(*(basic_rcp(c)));
1060 int vectorint_placement_new_check(
void *data,
size_t size)
1065 if (not SymEngine::is_aligned(
self))
1070 CVectorInt *vectorint_placement_new(
void *data)
1072 #if defined(WITH_SYMENGINE_ASSERT)
1075 SYMENGINE_ASSERT(SymEngine::is_aligned(
self));
1081 void vectorint_placement_free(
CVectorInt *
self)
1083 self->m.~vector<
int>();
1091 void vectorint_push_back(
CVectorInt *
self,
int value)
1093 self->m.push_back(value);
1104 SymEngine::vec_basic m;
1117 CWRAPPER_OUTPUT_TYPE vecbasic_push_back(
CVecBasic *
self,
const basic value)
1121 self->m.push_back(basic_rcp(value));
1126 CWRAPPER_OUTPUT_TYPE vecbasic_get(
CVecBasic *
self,
size_t n, basic result)
1130 SYMENGINE_ASSERT(n < self->m.size());
1131 basic_rcp(result) =
self->m[n];
1136 CWRAPPER_OUTPUT_TYPE vecbasic_set(
CVecBasic *
self,
size_t n,
const basic s)
1139 SYMENGINE_ASSERT(n < self->m.size());
1140 self->m[n] = basic_rcp(s);
1144 CWRAPPER_OUTPUT_TYPE vecbasic_erase(
CVecBasic *
self,
size_t n)
1147 SYMENGINE_ASSERT(n < self->m.size());
1148 self->m.erase(self->m.begin() + n);
1154 return self->m.size();
1157 CWRAPPER_OUTPUT_TYPE basic_max(basic s,
const CVecBasic *d)
1164 CWRAPPER_OUTPUT_TYPE basic_min(basic s,
const CVecBasic *d)
1171 CWRAPPER_OUTPUT_TYPE basic_add_vec(basic s,
const CVecBasic *d)
1178 CWRAPPER_OUTPUT_TYPE basic_mul_vec(basic s,
const CVecBasic *d)
1205 CDenseMatrix *dense_matrix_new_rows_cols(
unsigned rows,
unsigned cols)
1230 void sparse_matrix_rows_cols(
CSparseMatrix *s,
unsigned long int rows,
1231 unsigned long int cols)
1234 numeric_cast<unsigned>(cols));
1246 std::string str = s->m.__str__();
1247 auto cc =
new char[str.length() + 1];
1248 std::strcpy(cc, str.c_str());
1254 std::string str = s->m.__str__();
1255 auto cc =
new char[str.length() + 1];
1256 std::strcpy(cc, str.c_str());
1260 CWRAPPER_OUTPUT_TYPE dense_matrix_rows_cols(
CDenseMatrix *mat,
unsigned r,
1264 mat->m.resize(r, c);
1268 CWRAPPER_OUTPUT_TYPE dense_matrix_get_basic(basic s,
const CDenseMatrix *mat,
1269 unsigned long int r,
1270 unsigned long int c)
1274 = mat->m.get(numeric_cast<unsigned>(r), numeric_cast<unsigned>(c));
1278 CWRAPPER_OUTPUT_TYPE dense_matrix_set_basic(
CDenseMatrix *mat,
1279 unsigned long int r,
1280 unsigned long int c, basic s)
1283 mat->m.set(numeric_cast<unsigned>(r), numeric_cast<unsigned>(c),
1288 CWRAPPER_OUTPUT_TYPE sparse_matrix_get_basic(basic s,
const CSparseMatrix *mat,
1289 unsigned long int r,
1290 unsigned long int c)
1294 = mat->m.get(numeric_cast<unsigned>(r), numeric_cast<unsigned>(c));
1298 CWRAPPER_OUTPUT_TYPE sparse_matrix_set_basic(
CSparseMatrix *mat,
1299 unsigned long int r,
1300 unsigned long int c, basic s)
1303 mat->m.set(numeric_cast<unsigned>(r), numeric_cast<unsigned>(c),
1308 CWRAPPER_OUTPUT_TYPE dense_matrix_det(basic s,
const CDenseMatrix *mat)
1311 basic_rcp(s) = mat->m.det();
1317 dense_matrix_rows_cols(s, mat->m.nrows(), mat->m.ncols());
1321 CWRAPPER_OUTPUT_TYPE dense_matrix_transpose(
CDenseMatrix *s,
1325 dense_matrix_rows_cols(s, mat->m.ncols(), mat->m.nrows());
1326 mat->m.transpose(s->m);
1329 CWRAPPER_OUTPUT_TYPE
1331 unsigned long int r1,
unsigned long int c1,
1332 unsigned long int r2,
unsigned long int c2,
1333 unsigned long int r,
unsigned long int c)
1336 dense_matrix_rows_cols(s, numeric_cast<unsigned>(r2 - r1 + 1),
1337 numeric_cast<unsigned>(c2 - c1 + 1));
1338 mat->m.submatrix(s->m, numeric_cast<unsigned>(r1),
1339 numeric_cast<unsigned>(c1), numeric_cast<unsigned>(r2),
1340 numeric_cast<unsigned>(c2), numeric_cast<unsigned>(r),
1341 numeric_cast<unsigned>(c));
1345 CWRAPPER_OUTPUT_TYPE dense_matrix_row_join(
CDenseMatrix *A,
1349 A->m.row_join(B->m);
1353 CWRAPPER_OUTPUT_TYPE dense_matrix_col_join(
CDenseMatrix *A,
1357 A->m.col_join(B->m);
1361 CWRAPPER_OUTPUT_TYPE dense_matrix_row_del(
CDenseMatrix *A,
unsigned k)
1368 CWRAPPER_OUTPUT_TYPE dense_matrix_col_del(
CDenseMatrix *A,
unsigned k)
1375 unsigned long int dense_matrix_rows(
const CDenseMatrix *s)
1377 return s->m.nrows();
1380 unsigned long int dense_matrix_cols(
const CDenseMatrix *s)
1382 return s->m.ncols();
1385 CWRAPPER_OUTPUT_TYPE dense_matrix_add_matrix(
CDenseMatrix *s,
1390 dense_matrix_rows_cols(s, matA->m.nrows(), matA->m.ncols());
1391 matA->m.add_matrix(matB->m, s->m);
1395 CWRAPPER_OUTPUT_TYPE dense_matrix_mul_matrix(
CDenseMatrix *s,
1400 dense_matrix_rows_cols(s, matA->m.nrows(), matB->m.ncols());
1401 matA->m.mul_matrix(matB->m, s->m);
1405 CWRAPPER_OUTPUT_TYPE dense_matrix_add_scalar(
CDenseMatrix *s,
1410 dense_matrix_rows_cols(s, matA->m.nrows(), matA->m.ncols());
1411 matA->m.add_scalar(basic_rcp(b), s->m);
1415 CWRAPPER_OUTPUT_TYPE dense_matrix_mul_scalar(
CDenseMatrix *s,
1420 dense_matrix_rows_cols(s, matA->m.nrows(), matA->m.ncols());
1421 matA->m.mul_scalar(basic_rcp(b), s->m);
1429 dense_matrix_rows_cols(l, mat->m.nrows(), mat->m.ncols());
1430 dense_matrix_rows_cols(u, mat->m.nrows(), mat->m.ncols());
1431 mat->m.LU(l->m, u->m);
1439 dense_matrix_rows_cols(l, mat->m.nrows(), mat->m.ncols());
1440 dense_matrix_rows_cols(d, mat->m.nrows(), mat->m.ncols());
1441 mat->m.LDL(l->m, d->m);
1445 CWRAPPER_OUTPUT_TYPE dense_matrix_FFLU(
CDenseMatrix *lu,
1449 dense_matrix_rows_cols(lu, mat->m.nrows(), mat->m.ncols());
1459 dense_matrix_rows_cols(l, mat->m.nrows(), mat->m.ncols());
1460 dense_matrix_rows_cols(d, mat->m.nrows(), mat->m.ncols());
1461 dense_matrix_rows_cols(u, mat->m.nrows(), mat->m.ncols());
1462 mat->m.FFLDU(l->m, d->m, u->m);
1466 CWRAPPER_OUTPUT_TYPE dense_matrix_LU_solve(
CDenseMatrix *x,
1471 dense_matrix_rows_cols(x, A->m.ncols(), 1);
1472 A->m.LU_solve(b->m, x->m);
1476 CWRAPPER_OUTPUT_TYPE dense_matrix_ones(
CDenseMatrix *s,
unsigned long int r,
1477 unsigned long int c)
1480 dense_matrix_rows_cols(s, numeric_cast<unsigned>(r),
1481 numeric_cast<unsigned>(c));
1486 CWRAPPER_OUTPUT_TYPE dense_matrix_zeros(
CDenseMatrix *s,
unsigned long int r,
1487 unsigned long int c)
1490 dense_matrix_rows_cols(s, numeric_cast<unsigned>(r),
1491 numeric_cast<unsigned>(c));
1499 unsigned int vec_size = numeric_cast<unsigned>(vecbasic_size(d));
1500 dense_matrix_rows_cols(
1501 s, numeric_cast<unsigned>(vec_size + (k >= 0 ? k : -k)),
1502 numeric_cast<unsigned>(vec_size + (k >= 0 ? k : -k)));
1503 diag(s->m, d->m, numeric_cast<int>(k));
1507 CWRAPPER_OUTPUT_TYPE dense_matrix_eye(
CDenseMatrix *s,
unsigned long int N,
1508 unsigned long int M,
int k)
1511 dense_matrix_rows_cols(s, numeric_cast<unsigned>(N),
1512 numeric_cast<unsigned>(M));
1517 CWRAPPER_OUTPUT_TYPE dense_matrix_diff(
CDenseMatrix *result,
1520 if (not is_a_Symbol(x))
1521 return SYMENGINE_RUNTIME_ERROR;
1523 diff(A->m, rcp_static_cast<const Symbol>(basic_rcp(x)), result->m);
1527 CWRAPPER_OUTPUT_TYPE dense_matrix_jacobian(
CDenseMatrix *result,
1532 jacobian(A->m, x->m, result->m);
1538 return is_a<DenseMatrix>(c->m);
1543 return is_a<CSRMatrix>(c->m);
1548 return (lhs->m) == (rhs->m);
1553 return (lhs->m) == (rhs->m);
1568 int setbasic_insert(
CSetBasic *
self,
const basic value)
1570 return (self->m.insert(basic_rcp(value))).second ? 1 : 0;
1573 void setbasic_get(
CSetBasic *
self,
int n, basic result)
1575 basic_rcp(result) = *std::next((self->m).begin(), n);
1578 int setbasic_find(
CSetBasic *
self, basic value)
1580 return self->m.find(basic_rcp(value)) != (
self->m).end() ? 1 : 0;
1583 int setbasic_erase(
CSetBasic *
self,
const basic value)
1585 return (self->m.erase(basic_rcp(value))) ? 1 : 0;
1590 return self->m.size();
1596 SymEngine::map_basic_basic m;
1612 (
self->m)[basic_rcp(key)] = basic_rcp(mapped);
1615 int mapbasicbasic_get(
CMapBasicBasic *
self,
const basic key, basic mapped)
1617 auto it =
self->m.find(basic_rcp(key));
1618 if (it != self->m.end()) {
1619 basic_rcp(mapped) = it->second;
1627 return self->m.size();
1632 CWRAPPER_OUTPUT_TYPE basic_get_args(
const basic
self,
CVecBasic *args)
1635 args->m = basic_rcp(
self)->get_args();
1639 CWRAPPER_OUTPUT_TYPE basic_free_symbols(
const basic
self,
CSetBasic *symbols)
1642 symbols->m = SymEngine::free_symbols(*(basic_rcp(
self)));
1646 CWRAPPER_OUTPUT_TYPE basic_function_symbols(
CSetBasic *symbols,
1651 = SymEngine::atoms<SymEngine::FunctionSymbol>(*(basic_rcp(
self)));
1655 size_t basic_hash(
const basic
self)
1657 return static_cast<size_t>(basic_rcp(
self)->hash());
1660 CWRAPPER_OUTPUT_TYPE basic_subs(basic s,
const basic e,
1664 basic_rcp(s) = basic_rcp(e)->subs(mapbb->m);
1668 CWRAPPER_OUTPUT_TYPE basic_subs2(basic s,
const basic e,
const basic a,
1672 basic_rcp(s) = basic_rcp(e)->subs({{basic_rcp(a), basic_rcp(b)}});
1676 CWRAPPER_OUTPUT_TYPE function_symbol_set(basic s,
const char *c,
1680 basic_rcp(s) = function_symbol(c, arg->m);
1684 char *function_symbol_get_name(
const basic b)
1686 SYMENGINE_ASSERT(is_a<FunctionSymbol>(*(basic_rcp(b))));
1688 = down_cast<const FunctionSymbol &>(*(basic_rcp(b))).get_name();
1689 auto cc =
new char[str.length() + 1];
1690 std::strcpy(cc, str.c_str());
1694 CWRAPPER_OUTPUT_TYPE basic_coeff(basic c,
const basic b,
const basic x,
1699 = SymEngine::coeff(*(basic_rcp(b)), *(basic_rcp(x)), *(basic_rcp(n)));
1709 vec_basic vb = sym->m;
1711 std::all_of(vb.cbegin(), vb.cend(),
1712 [](RCP<const Basic> b) { return is_a<const Symbol>(*b); }));
1713 vec_sym vs(vb.size());
1714 for (
unsigned i = 0; i < vb.size(); i++)
1715 vs[i] = rcp_static_cast<const Symbol>(vb[i]);
1716 sol->m = SymEngine::linsolve(sys->m, vs);
1720 CWRAPPER_OUTPUT_TYPE basic_solve_poly(
CSetBasic *r,
const basic f,
1724 SYMENGINE_ASSERT(is_a<Symbol>(*(basic_rcp(s))));
1725 RCP<const Set> set = SymEngine::solve_poly(
1726 basic_rcp(f), rcp_static_cast<const Symbol>(basic_rcp(s)));
1727 if (not is_a<FiniteSet>(*set)) {
1728 return SYMENGINE_NOT_IMPLEMENTED;
1730 r->m = down_cast<const FiniteSet &>(*set).get_container();
1736 char *ascii_art_str()
1738 std::string str = SymEngine::ascii_art();
1739 auto cc =
new char[str.length() + 1];
1740 std::strcpy(cc, str.c_str());
1746 CWRAPPER_OUTPUT_TYPE ntheory_gcd(basic s,
const basic a,
const basic b)
1749 SYMENGINE_ASSERT(is_a<Integer>(*(basic_rcp(a))));
1750 SYMENGINE_ASSERT(is_a<Integer>(*(basic_rcp(b))));
1751 basic_rcp(s) =
SymEngine::gcd(down_cast<const Integer &>(*(basic_rcp(a))),
1752 down_cast<const Integer &>(*(basic_rcp(b))));
1756 CWRAPPER_OUTPUT_TYPE ntheory_lcm(basic s,
const basic a,
const basic b)
1759 SYMENGINE_ASSERT(is_a<Integer>(*(basic_rcp(a))));
1760 SYMENGINE_ASSERT(is_a<Integer>(*(basic_rcp(b))));
1761 basic_rcp(s) =
SymEngine::lcm(down_cast<const Integer &>(*(basic_rcp(a))),
1762 down_cast<const Integer &>(*(basic_rcp(b))));
1766 CWRAPPER_OUTPUT_TYPE ntheory_gcd_ext(basic g, basic s, basic t,
const basic a,
1770 SYMENGINE_ASSERT(is_a<Integer>(*(basic_rcp(a))));
1771 SYMENGINE_ASSERT(is_a<Integer>(*(basic_rcp(b))));
1772 SymEngine::RCP<const Integer> g_, s_, t_;
1774 SymEngine::outArg(t_),
1775 down_cast<const Integer &>(*(basic_rcp(a))),
1776 down_cast<const Integer &>(*(basic_rcp(b))));
1783 CWRAPPER_OUTPUT_TYPE ntheory_nextprime(basic s,
const basic a)
1786 SYMENGINE_ASSERT(is_a<Integer>(*(basic_rcp(a))));
1792 CWRAPPER_OUTPUT_TYPE ntheory_mod(basic s,
const basic n,
const basic d)
1795 SYMENGINE_ASSERT(is_a<Integer>(*(basic_rcp(n))));
1796 SYMENGINE_ASSERT(is_a<Integer>(*(basic_rcp(d))));
1797 basic_rcp(s) =
SymEngine::mod(down_cast<const Integer &>(*(basic_rcp(n))),
1798 down_cast<const Integer &>(*(basic_rcp(d))));
1802 CWRAPPER_OUTPUT_TYPE ntheory_quotient(basic s,
const basic n,
const basic d)
1805 SYMENGINE_ASSERT(is_a<Integer>(*(basic_rcp(n))));
1806 SYMENGINE_ASSERT(is_a<Integer>(*(basic_rcp(d))));
1809 down_cast<const Integer &>(*(basic_rcp(d))));
1813 CWRAPPER_OUTPUT_TYPE ntheory_quotient_mod(basic q, basic r,
const basic n,
1817 SYMENGINE_ASSERT(is_a<Integer>(*(basic_rcp(n))));
1818 SYMENGINE_ASSERT(is_a<Integer>(*(basic_rcp(d))));
1819 SymEngine::RCP<const Integer> q_, r_;
1821 down_cast<const Integer &>(*(basic_rcp(n))),
1822 down_cast<const Integer &>(*(basic_rcp(d))));
1828 CWRAPPER_OUTPUT_TYPE ntheory_mod_f(basic s,
const basic n,
const basic d)
1831 SYMENGINE_ASSERT(is_a<Integer>(*(basic_rcp(n))));
1832 SYMENGINE_ASSERT(is_a<Integer>(*(basic_rcp(d))));
1835 down_cast<const Integer &>(*(basic_rcp(d))));
1839 CWRAPPER_OUTPUT_TYPE ntheory_quotient_f(basic s,
const basic n,
const basic d)
1842 SYMENGINE_ASSERT(is_a<Integer>(*(basic_rcp(n))));
1843 SYMENGINE_ASSERT(is_a<Integer>(*(basic_rcp(d))));
1846 down_cast<const Integer &>(*(basic_rcp(d))));
1850 CWRAPPER_OUTPUT_TYPE ntheory_quotient_mod_f(basic q, basic r,
const basic n,
1854 SYMENGINE_ASSERT(is_a<Integer>(*(basic_rcp(n))));
1855 SYMENGINE_ASSERT(is_a<Integer>(*(basic_rcp(d))));
1856 SymEngine::RCP<const Integer> q_, r_;
1858 down_cast<const Integer &>(*(basic_rcp(n))),
1859 down_cast<const Integer &>(*(basic_rcp(d))));
1865 int ntheory_mod_inverse(basic b,
const basic a,
const basic m)
1868 SYMENGINE_ASSERT(is_a<Integer>(*(basic_rcp(a))));
1869 SYMENGINE_ASSERT(is_a<Integer>(*(basic_rcp(m))));
1870 SymEngine::RCP<const Integer> b_;
1872 SymEngine::outArg(b_), down_cast<const Integer &>(*(basic_rcp(a))),
1873 down_cast<const Integer &>(*(basic_rcp(m))));
1878 CWRAPPER_OUTPUT_TYPE ntheory_fibonacci(basic s,
unsigned long a)
1885 CWRAPPER_OUTPUT_TYPE ntheory_fibonacci2(basic g, basic s,
unsigned long a)
1888 SymEngine::RCP<const Integer> g_, s_;
1895 CWRAPPER_OUTPUT_TYPE ntheory_lucas(basic s,
unsigned long a)
1902 CWRAPPER_OUTPUT_TYPE ntheory_lucas2(basic g, basic s,
unsigned long a)
1905 SymEngine::RCP<const Integer> g_, s_;
1912 CWRAPPER_OUTPUT_TYPE ntheory_binomial(basic s,
const basic a,
unsigned long b)
1915 SYMENGINE_ASSERT(is_a<Integer>(*(basic_rcp(a))));
1921 CWRAPPER_OUTPUT_TYPE ntheory_factorial(basic s,
unsigned long n)
1929 CWRAPPER_OUTPUT_TYPE basic_evalf(basic s,
const basic b,
unsigned long bits,
1935 = SymEngine::evalf(*(basic_rcp(b)), bits, (SymEngine::EvalfDomain)real);
1939 CWRAPPER_OUTPUT_TYPE basic_as_numer_denom(basic numer, basic denom,
1943 SymEngine::as_numer_denom(basic_rcp(x), SymEngine::outArg(basic_rcp(numer)),
1944 SymEngine::outArg(basic_rcp(denom)));
1948 CWRAPPER_OUTPUT_TYPE basic_add_as_two_terms(basic term1, basic term2,
1952 SYMENGINE_ASSERT(is_a<Add>(*(basic_rcp(s))));
1953 rcp_static_cast<const Add>(basic_rcp(s))
1954 ->as_two_terms(SymEngine::outArg(basic_rcp(term1)),
1955 SymEngine::outArg(basic_rcp(term2)));
1959 CWRAPPER_OUTPUT_TYPE basic_mul_as_two_terms(basic term1, basic term2,
1963 SYMENGINE_ASSERT(is_a<Mul>(*(basic_rcp(s))));
1964 rcp_static_cast<const Mul>(basic_rcp(s))
1965 ->as_two_terms(SymEngine::outArg(basic_rcp(term1)),
1966 SymEngine::outArg(basic_rcp(term2)));
1981 const CVecBasic *exprs,
int perform_cse)
1983 self->m.init(args->m, exprs->m, perform_cse);
1988 const double *
const inps)
1990 self->m.call(outs, inps);
1998 #ifdef HAVE_SYMENGINE_LLVM
2000 struct CLLVMDoubleVisitor {
2001 SymEngine::LLVMDoubleVisitor m;
2004 CLLVMDoubleVisitor *llvm_double_visitor_new()
2006 return new CLLVMDoubleVisitor();
2009 void llvm_double_visitor_init(CLLVMDoubleVisitor *
self,
const CVecBasic *args,
2010 const CVecBasic *exprs,
int perform_cse,
2013 self->m.init(args->m, exprs->m, perform_cse, opt_level);
2016 void llvm_double_visitor_call(CLLVMDoubleVisitor *
self,
double *
const outs,
2017 const double *
const inps)
2019 self->m.call(outs, inps);
2022 void llvm_double_visitor_free(CLLVMDoubleVisitor *
self)
2027 struct CLLVMFloatVisitor {
2028 SymEngine::LLVMFloatVisitor m;
2031 CLLVMFloatVisitor *llvm_float_visitor_new()
2033 return new CLLVMFloatVisitor();
2036 void llvm_float_visitor_init(CLLVMFloatVisitor *
self,
const CVecBasic *args,
2037 const CVecBasic *exprs,
int perform_cse,
2040 self->m.init(args->m, exprs->m, perform_cse, opt_level);
2043 void llvm_float_visitor_call(CLLVMFloatVisitor *
self,
float *
const outs,
2044 const float *
const inps)
2046 self->m.call(outs, inps);
2049 void llvm_float_visitor_free(CLLVMFloatVisitor *
self)
2053 #ifdef SYMENGINE_HAVE_LLVM_LONG_DOUBLE
2055 struct CLLVMLongDoubleVisitor {
2056 SymEngine::LLVMLongDoubleVisitor m;
2059 CLLVMLongDoubleVisitor *llvm_long_double_visitor_new()
2061 return new CLLVMLongDoubleVisitor();
2064 void llvm_long_double_visitor_init(CLLVMLongDoubleVisitor *
self,
2066 const CVecBasic *exprs,
int perform_cse,
2069 self->m.init(args->m, exprs->m, perform_cse, opt_level);
2072 void llvm_long_double_visitor_call(CLLVMLongDoubleVisitor *
self,
2073 long double *
const outs,
2074 const long double *
const inps)
2076 self->m.call(outs, inps);
2079 void llvm_long_double_visitor_free(CLLVMLongDoubleVisitor *
self)
2086 CWRAPPER_OUTPUT_TYPE basic_cse(
CVecBasic *replacement_syms,
2091 vec_pair replacements;
2092 SymEngine::cse(replacements, reduced_exprs->m, exprs->m);
2093 for (
auto &p : replacements) {
2094 replacement_syms->m.push_back(p.first);
2095 replacement_exprs->m.push_back(p.second);
2100 void symengine_print_stack_on_segfault()
2102 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 > add(const RCP< const Basic > &a, const RCP< const Basic > &b)
Adds two objects (safely).
RCP< const Integer > gcd(const Integer &a, const Integer &b)
Greatest Common Divisor.
void fibonacci2(const Ptr< RCP< const Integer >> &g, const Ptr< RCP< const Integer >> &s, unsigned long n)
Fibonacci n and n-1.
SYMENGINE_EXPORT RCP< const Basic > cbrt(const RCP< const Basic > &arg)
RCP< const Complexes > complexes()
RCP< const Integer > quotient_f(const Integer &n, const Integer &d)
std::enable_if< std::is_integral< T >::value, RCP< const Integer > >::type integer(T i)
RCP< const Integer > mod_f(const Integer &n, const Integer &d)
modulo round toward -inf
RCP< const Symbol > symbol(const std::string &name)
inline version to return Symbol
RCP< const Reals > reals()
RCP< const EmptySet > emptyset()
RCP< const Integer > binomial(const Integer &n, unsigned long k)
Binomial Coefficient.
RCP< const Basic > mul(const RCP< const Basic > &a, const RCP< const Basic > &b)
Multiplication.
RCP< const Integer > nextprime(const Integer &a)
RCP< const Integer > quotient(const Integer &n, const Integer &d)
RCP< const Integers > integers()
SYMENGINE_EXPORT RCP< const Basic > sqrt(const RCP< const Basic > &arg)
RCP< const Basic > max(const vec_basic &arg)
Canonicalize Max:
void quotient_mod(const Ptr< RCP< const Integer >> &q, const Ptr< RCP< const Integer >> &r, const Integer &n, const Integer &d)
bool is_a(const Basic &b)
Templatised version to check is_a type.
RCP< const Integer > fibonacci(unsigned long n)
Fibonacci number.
RCP< const Integer > lucas(unsigned long n)
Lucas number.
void quotient_mod_f(const Ptr< RCP< const Integer >> &q, const Ptr< RCP< const Integer >> &r, const Integer &n, const Integer &d)
RCP< const Integer > factorial(unsigned long n)
Factorial.
bool eq(const Basic &a, const Basic &b)
Checks equality for a and b
RCP< const Basic > sub(const RCP< const Basic > &a, const RCP< const Basic > &b)
Substracts b from a.
bool neq(const Basic &a, const Basic &b)
Checks inequality for a and b
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.
void lucas2(const Ptr< RCP< const Integer >> &g, const Ptr< RCP< const Integer >> &s, unsigned long n)
Lucas number n and n-1.
RCP< const Constant > constant(const std::string &name)
inline version to return Constant
RCP< const Basic > div(const RCP< const Basic > &a, const RCP< const Basic > &b)
Division.
SYMENGINE_EXPORT tribool is_zero(const Basic &b, const Assumptions *assumptions=nullptr)
Check if a number is zero.
RCP< const Set > finiteset(const set_basic &container)
SYMENGINE_EXPORT RCP< const Basic > expand(const RCP< const Basic > &self, bool deep=true)
Expands self
bool is_a_Complex(const Basic &b)
RCP< const Basic > min(const vec_basic &arg)
Canonicalize Min:
RCP< const Rationals > rationals()
RCP< const Integer > mod(const Integer &n, const Integer &d)
modulo round toward zero
int mod_inverse(const Ptr< RCP< const Integer >> &b, const Integer &a, const Integer &m)
inverse modulo
RCP< const Integer > lcm(const Integer &a, const Integer &b)
Least Common Multiple.