6 #include "symengine/symengine_config.h"
8 #ifdef HAVE_SYMENGINE_GMP
12 #ifdef HAVE_SYMENGINE_MPFR
16 #include "symengine/symengine_exception.h"
23 #define SYMENGINE_C_ASSERT(cond) \
26 printf("SYMENGINE_C_ASSERT failed: %s \nfunction %s (), line " \
27 "number %d at\n%s\n", \
28 __FILE__, __func__, __LINE__, #cond); \
33 typedef symengine_exceptions_t CWRAPPER_OUTPUT_TYPE;
36 #define SYMENGINE_INCLUDE_ALL
37 #define SYMENGINE_ENUM(type, Class) type,
38 #include "symengine/type_codes.inc"
40 #undef SYMENGINE_INCLUDE_ALL
41 SYMENGINE_TypeID_Count
69 #if !defined(WITH_SYMENGINE_RCP)
100 void basic_new_stack(basic s);
102 void basic_free_stack(basic s);
110 const char *symengine_version(
void);
118 void basic_const_set(basic s,
const char *c);
120 void basic_const_zero(basic s);
121 void basic_const_one(basic s);
122 void basic_const_minus_one(basic s);
123 void basic_const_I(basic s);
125 void basic_const_pi(basic s);
126 void basic_const_E(basic s);
127 void basic_const_EulerGamma(basic s);
128 void basic_const_Catalan(basic s);
129 void basic_const_GoldenRatio(basic s);
133 void basic_const_infinity(basic s);
134 void basic_const_neginfinity(basic s);
135 void basic_const_complex_infinity(basic s);
138 void basic_const_nan(basic s);
141 CWRAPPER_OUTPUT_TYPE basic_assign(basic a,
const basic b);
144 CWRAPPER_OUTPUT_TYPE basic_parse(basic b,
const char *str);
147 CWRAPPER_OUTPUT_TYPE basic_parse2(basic b,
const char *str,
int convert_xor);
150 TypeID basic_get_type(
const basic s);
152 TypeID basic_get_class_id(
const char *c);
155 char *basic_get_class_from_id(TypeID
id);
160 CWRAPPER_OUTPUT_TYPE symbol_set(basic s,
const char *c);
163 int number_is_zero(
const basic s);
165 int number_is_negative(
const basic s);
167 int number_is_positive(
const basic s);
169 int number_is_complex(
const basic s);
172 int basic_has_symbol(
const basic e,
const basic s);
175 CWRAPPER_OUTPUT_TYPE integer_set_si(basic s,
long i);
177 CWRAPPER_OUTPUT_TYPE integer_set_ui(basic s,
unsigned long i);
179 #ifdef HAVE_SYMENGINE_GMP
180 CWRAPPER_OUTPUT_TYPE integer_set_mpz(basic s,
const mpz_t i);
183 CWRAPPER_OUTPUT_TYPE integer_set_str(basic s,
const char *c);
185 CWRAPPER_OUTPUT_TYPE real_double_set_d(basic s,
double d);
187 double real_double_get_d(
const basic s);
189 #ifdef HAVE_SYMENGINE_MPFR
191 CWRAPPER_OUTPUT_TYPE real_mpfr_set_d(basic s,
double d,
int prec);
194 CWRAPPER_OUTPUT_TYPE real_mpfr_set_str(basic s,
const char *c,
int prec);
196 double real_mpfr_get_d(
const basic s);
198 CWRAPPER_OUTPUT_TYPE real_mpfr_set(basic s, mpfr_srcptr m);
200 CWRAPPER_OUTPUT_TYPE real_mpfr_get(mpfr_ptr m,
const basic s);
202 mpfr_prec_t real_mpfr_get_prec(
const basic s);
206 CWRAPPER_OUTPUT_TYPE complex_base_real_part(basic s,
const basic com);
208 CWRAPPER_OUTPUT_TYPE complex_base_imaginary_part(basic s,
const basic com);
211 signed long integer_get_si(
const basic s);
213 unsigned long integer_get_ui(
const basic s);
215 #ifdef HAVE_SYMENGINE_GMP
216 CWRAPPER_OUTPUT_TYPE integer_get_mpz(mpz_t a,
const basic s);
221 CWRAPPER_OUTPUT_TYPE rational_set(basic s,
const basic i,
const basic j);
223 CWRAPPER_OUTPUT_TYPE rational_set_si(basic s,
long i,
long j);
225 CWRAPPER_OUTPUT_TYPE rational_set_ui(basic s,
unsigned long i,
unsigned long j);
226 #ifdef HAVE_SYMENGINE_GMP
228 CWRAPPER_OUTPUT_TYPE rational_get_mpq(mpq_t a,
const basic s);
230 CWRAPPER_OUTPUT_TYPE rational_set_mpq(basic s,
const mpq_t i);
234 CWRAPPER_OUTPUT_TYPE complex_set(basic s,
const basic re,
const basic im);
236 CWRAPPER_OUTPUT_TYPE complex_set_rat(basic s,
const basic re,
const basic im);
237 #ifdef HAVE_SYMENGINE_GMP
239 CWRAPPER_OUTPUT_TYPE complex_set_mpq(basic s,
const mpq_t re,
const mpq_t im);
244 dcomplex complex_double_get(
const basic s);
247 CWRAPPER_OUTPUT_TYPE basic_add(basic s,
const basic a,
const basic b);
249 CWRAPPER_OUTPUT_TYPE basic_sub(basic s,
const basic a,
const basic b);
251 CWRAPPER_OUTPUT_TYPE basic_mul(basic s,
const basic a,
const basic b);
253 CWRAPPER_OUTPUT_TYPE basic_div(basic s,
const basic a,
const basic b);
255 CWRAPPER_OUTPUT_TYPE basic_pow(basic s,
const basic a,
const basic b);
258 CWRAPPER_OUTPUT_TYPE basic_diff(basic s,
const basic expr,
const basic sym);
260 int basic_eq(
const basic a,
const basic b);
262 int basic_neq(
const basic a,
const basic b);
265 CWRAPPER_OUTPUT_TYPE basic_expand(basic s,
const basic a);
267 CWRAPPER_OUTPUT_TYPE basic_neg(basic s,
const basic a);
270 CWRAPPER_OUTPUT_TYPE basic_abs(basic s,
const basic a);
273 CWRAPPER_OUTPUT_TYPE basic_erf(basic s,
const basic a);
275 CWRAPPER_OUTPUT_TYPE basic_erfc(basic s,
const basic a);
278 CWRAPPER_OUTPUT_TYPE basic_sin(basic s,
const basic a);
280 CWRAPPER_OUTPUT_TYPE basic_cos(basic s,
const basic a);
282 CWRAPPER_OUTPUT_TYPE basic_tan(basic s,
const basic a);
285 CWRAPPER_OUTPUT_TYPE basic_asin(basic s,
const basic a);
287 CWRAPPER_OUTPUT_TYPE basic_acos(basic s,
const basic a);
289 CWRAPPER_OUTPUT_TYPE basic_atan(basic s,
const basic a);
292 CWRAPPER_OUTPUT_TYPE basic_csc(basic s,
const basic a);
294 CWRAPPER_OUTPUT_TYPE basic_sec(basic s,
const basic a);
296 CWRAPPER_OUTPUT_TYPE basic_cot(basic s,
const basic a);
299 CWRAPPER_OUTPUT_TYPE basic_acsc(basic s,
const basic a);
301 CWRAPPER_OUTPUT_TYPE basic_asec(basic s,
const basic a);
303 CWRAPPER_OUTPUT_TYPE basic_acot(basic s,
const basic a);
306 CWRAPPER_OUTPUT_TYPE basic_sinh(basic s,
const basic a);
308 CWRAPPER_OUTPUT_TYPE basic_cosh(basic s,
const basic a);
310 CWRAPPER_OUTPUT_TYPE basic_tanh(basic s,
const basic a);
313 CWRAPPER_OUTPUT_TYPE basic_asinh(basic s,
const basic a);
315 CWRAPPER_OUTPUT_TYPE basic_acosh(basic s,
const basic a);
317 CWRAPPER_OUTPUT_TYPE basic_atanh(basic s,
const basic a);
320 CWRAPPER_OUTPUT_TYPE basic_csch(basic s,
const basic a);
322 CWRAPPER_OUTPUT_TYPE basic_sech(basic s,
const basic a);
324 CWRAPPER_OUTPUT_TYPE basic_coth(basic s,
const basic a);
327 CWRAPPER_OUTPUT_TYPE basic_acsch(basic s,
const basic a);
329 CWRAPPER_OUTPUT_TYPE basic_asech(basic s,
const basic a);
331 CWRAPPER_OUTPUT_TYPE basic_acoth(basic s,
const basic a);
334 CWRAPPER_OUTPUT_TYPE basic_lambertw(basic s,
const basic a);
336 CWRAPPER_OUTPUT_TYPE basic_zeta(basic s,
const basic a);
338 CWRAPPER_OUTPUT_TYPE basic_dirichlet_eta(basic s,
const basic a);
340 CWRAPPER_OUTPUT_TYPE basic_gamma(basic s,
const basic a);
342 CWRAPPER_OUTPUT_TYPE basic_loggamma(basic s,
const basic a);
344 CWRAPPER_OUTPUT_TYPE basic_sqrt(basic s,
const basic a);
346 CWRAPPER_OUTPUT_TYPE basic_cbrt(basic s,
const basic a);
348 CWRAPPER_OUTPUT_TYPE basic_exp(basic s,
const basic a);
350 CWRAPPER_OUTPUT_TYPE basic_log(basic s,
const basic a);
352 CWRAPPER_OUTPUT_TYPE basic_floor(basic s,
const basic a);
354 CWRAPPER_OUTPUT_TYPE basic_ceiling(basic s,
const basic a);
356 CWRAPPER_OUTPUT_TYPE basic_sign(basic s,
const basic a);
359 CWRAPPER_OUTPUT_TYPE basic_atan2(basic s,
const basic a,
const basic b);
361 CWRAPPER_OUTPUT_TYPE basic_kronecker_delta(basic s,
const basic a,
364 CWRAPPER_OUTPUT_TYPE basic_lowergamma(basic s,
const basic a,
const basic b);
366 CWRAPPER_OUTPUT_TYPE basic_uppergamma(basic s,
const basic a,
const basic b);
368 CWRAPPER_OUTPUT_TYPE basic_beta(basic s,
const basic a,
const basic b);
370 CWRAPPER_OUTPUT_TYPE basic_polygamma(basic s,
const basic a,
const basic b);
373 char *basic_dumps(
const basic s,
unsigned long *size);
375 CWRAPPER_OUTPUT_TYPE basic_loads(basic s,
const char *c,
unsigned long size);
378 char *basic_str(
const basic s);
381 char *basic_str_julia(
const basic s);
383 char *basic_str_mathml(
const basic s);
385 char *basic_str_latex(
const basic s);
387 char *basic_str_ccode(
const basic s);
389 char *basic_str_jscode(
const basic s);
391 void basic_str_free(
char *s);
394 void bool_set_true(basic s);
396 void bool_set_false(basic s);
399 void basic_set_emptyset(basic s);
401 void basic_set_universalset(basic s);
403 void basic_set_complexes(basic s);
405 void basic_set_reals(basic s);
407 void basic_set_rationals(basic s);
409 void basic_set_integers(basic s);
411 CWRAPPER_OUTPUT_TYPE basic_set_interval(basic s,
const basic start,
412 const basic end,
int left_open,
415 CWRAPPER_OUTPUT_TYPE basic_set_finiteset(basic s,
const CSetBasic *container);
417 CWRAPPER_OUTPUT_TYPE basic_set_union(basic s,
const basic a,
const basic b);
419 CWRAPPER_OUTPUT_TYPE basic_set_intersection(basic s,
const basic a,
422 CWRAPPER_OUTPUT_TYPE basic_set_complement(basic s,
const basic a,
425 CWRAPPER_OUTPUT_TYPE basic_set_contains(basic s,
const basic a,
const basic b);
427 int basic_set_is_subset(
const basic a,
const basic b);
429 int basic_set_is_proper_subset(
const basic a,
const basic b);
431 int basic_set_is_superset(
const basic a,
const basic b);
433 int basic_set_is_proper_superset(
const basic a,
const basic b);
435 CWRAPPER_OUTPUT_TYPE basic_set_inf(basic s,
const basic a);
437 CWRAPPER_OUTPUT_TYPE basic_set_sup(basic s,
const basic a);
439 CWRAPPER_OUTPUT_TYPE basic_set_boundary(basic s,
const basic a);
441 CWRAPPER_OUTPUT_TYPE basic_set_interior(basic s,
const basic a);
443 CWRAPPER_OUTPUT_TYPE basic_set_closure(basic s,
const basic a);
454 int symengine_have_component(
const char *c);
459 int is_a_Integer(
const basic s);
461 int is_a_Rational(
const basic s);
463 int is_a_Symbol(
const basic s);
467 int is_a_RealDouble(
const basic c);
469 int is_a_ComplexDouble(
const basic c);
471 int is_a_RealMPFR(
const basic c);
473 int is_a_ComplexMPC(
const basic c);
475 int is_a_Set(
const basic c);
489 int vectorint_placement_new_check(
void *data,
size_t size);
490 CVectorInt *vectorint_placement_new(
void *data);
492 void vectorint_placement_free(
CVectorInt *
self);
495 void vectorint_push_back(
CVectorInt *
self,
int value);
504 CWRAPPER_OUTPUT_TYPE vecbasic_push_back(
CVecBasic *
self,
const basic value);
505 CWRAPPER_OUTPUT_TYPE vecbasic_get(
CVecBasic *
self,
size_t n, basic result);
506 CWRAPPER_OUTPUT_TYPE vecbasic_set(
CVecBasic *
self,
size_t n,
const basic s);
507 CWRAPPER_OUTPUT_TYPE vecbasic_erase(
CVecBasic *
self,
size_t n);
511 CWRAPPER_OUTPUT_TYPE basic_max(basic s,
const CVecBasic *d);
513 CWRAPPER_OUTPUT_TYPE basic_min(basic s,
const CVecBasic *d);
515 CWRAPPER_OUTPUT_TYPE basic_add_vec(basic s,
const CVecBasic *d);
518 CWRAPPER_OUTPUT_TYPE basic_mul_vec(basic s,
const CVecBasic *d);
532 CDenseMatrix *dense_matrix_new_rows_cols(
unsigned r,
unsigned c);
543 CWRAPPER_OUTPUT_TYPE dense_matrix_rows_cols(
CDenseMatrix *mat,
unsigned r,
546 CWRAPPER_OUTPUT_TYPE dense_matrix_get_basic(basic s,
const CDenseMatrix *mat,
548 unsigned long int c);
550 CWRAPPER_OUTPUT_TYPE dense_matrix_set_basic(
CDenseMatrix *mat,
552 unsigned long int c, basic s);
554 CWRAPPER_OUTPUT_TYPE sparse_matrix_get_basic(basic s,
const CSparseMatrix *mat,
556 unsigned long int c);
558 CWRAPPER_OUTPUT_TYPE sparse_matrix_set_basic(
CSparseMatrix *mat,
560 unsigned long int c, basic s);
562 CWRAPPER_OUTPUT_TYPE dense_matrix_det(basic s,
const CDenseMatrix *mat);
566 CWRAPPER_OUTPUT_TYPE dense_matrix_transpose(
CDenseMatrix *s,
572 unsigned long int r1,
unsigned long int c1,
573 unsigned long int r2,
unsigned long int c2,
574 unsigned long int r,
unsigned long int c);
576 CWRAPPER_OUTPUT_TYPE dense_matrix_row_join(
CDenseMatrix *A,
579 CWRAPPER_OUTPUT_TYPE dense_matrix_col_join(
CDenseMatrix *A,
582 CWRAPPER_OUTPUT_TYPE dense_matrix_row_del(
CDenseMatrix *C,
unsigned k);
584 CWRAPPER_OUTPUT_TYPE dense_matrix_col_del(
CDenseMatrix *C,
unsigned k);
587 unsigned long int dense_matrix_cols(
const CDenseMatrix *s);
589 unsigned long int dense_matrix_rows(
const CDenseMatrix *s);
591 CWRAPPER_OUTPUT_TYPE dense_matrix_add_matrix(
CDenseMatrix *s,
595 CWRAPPER_OUTPUT_TYPE dense_matrix_mul_matrix(
CDenseMatrix *s,
599 CWRAPPER_OUTPUT_TYPE dense_matrix_add_scalar(
CDenseMatrix *s,
603 CWRAPPER_OUTPUT_TYPE dense_matrix_mul_scalar(
CDenseMatrix *s,
613 CWRAPPER_OUTPUT_TYPE dense_matrix_FFLU(
CDenseMatrix *lu,
620 CWRAPPER_OUTPUT_TYPE dense_matrix_LU_solve(
CDenseMatrix *x,
624 CWRAPPER_OUTPUT_TYPE dense_matrix_ones(
CDenseMatrix *s,
unsigned long int r,
625 unsigned long int c);
627 CWRAPPER_OUTPUT_TYPE dense_matrix_zeros(
CDenseMatrix *s,
unsigned long int r,
628 unsigned long int c);
634 CWRAPPER_OUTPUT_TYPE dense_matrix_eye(
CDenseMatrix *s,
unsigned long int N,
635 unsigned long int M,
int k);
638 CWRAPPER_OUTPUT_TYPE dense_matrix_diff(
CDenseMatrix *result,
641 CWRAPPER_OUTPUT_TYPE dense_matrix_jacobian(
CDenseMatrix *result,
648 void sparse_matrix_rows_cols(
CSparseMatrix *s,
unsigned long int r,
649 unsigned long int c);
669 int setbasic_insert(
CSetBasic *
self,
const basic value);
670 void setbasic_get(
CSetBasic *
self,
int n, basic result);
672 int setbasic_find(
CSetBasic *
self, basic value);
674 int setbasic_erase(
CSetBasic *
self,
const basic value);
686 int mapbasicbasic_get(
CMapBasicBasic *
self,
const basic key, basic mapped);
692 CWRAPPER_OUTPUT_TYPE basic_get_args(
const basic
self,
CVecBasic *args);
694 CWRAPPER_OUTPUT_TYPE basic_free_symbols(
const basic
self,
CSetBasic *symbols);
696 CWRAPPER_OUTPUT_TYPE basic_function_symbols(
CSetBasic *symbols,
699 size_t basic_hash(
const basic
self);
702 CWRAPPER_OUTPUT_TYPE basic_subs(basic s,
const basic e,
706 CWRAPPER_OUTPUT_TYPE basic_subs2(basic s,
const basic e,
const basic a,
711 CWRAPPER_OUTPUT_TYPE function_symbol_set(basic s,
const char *c,
715 char *function_symbol_get_name(
const basic b);
717 CWRAPPER_OUTPUT_TYPE basic_coeff(basic c,
const basic b,
const basic x,
726 CWRAPPER_OUTPUT_TYPE basic_solve_poly(
CSetBasic *r,
const basic f,
733 char *ascii_art_str(
void);
737 CWRAPPER_OUTPUT_TYPE ntheory_gcd(basic s,
const basic a,
const basic b);
739 CWRAPPER_OUTPUT_TYPE ntheory_lcm(basic s,
const basic a,
const basic b);
741 CWRAPPER_OUTPUT_TYPE ntheory_gcd_ext(basic g, basic s, basic t,
const basic a,
744 CWRAPPER_OUTPUT_TYPE ntheory_nextprime(basic s,
const basic a);
746 CWRAPPER_OUTPUT_TYPE ntheory_mod(basic s,
const basic n,
const basic d);
748 CWRAPPER_OUTPUT_TYPE ntheory_quotient(basic s,
const basic n,
const basic d);
750 CWRAPPER_OUTPUT_TYPE ntheory_quotient_mod(basic q, basic r,
const basic n,
753 CWRAPPER_OUTPUT_TYPE ntheory_mod_f(basic s,
const basic n,
const basic d);
755 CWRAPPER_OUTPUT_TYPE ntheory_quotient_f(basic s,
const basic n,
const basic d);
757 CWRAPPER_OUTPUT_TYPE ntheory_quotient_mod_f(basic q, basic r,
const basic n,
760 int ntheory_mod_inverse(basic b,
const basic a,
const basic m);
762 CWRAPPER_OUTPUT_TYPE ntheory_fibonacci(basic s,
unsigned long a);
764 CWRAPPER_OUTPUT_TYPE ntheory_fibonacci2(basic g, basic s,
unsigned long a);
766 CWRAPPER_OUTPUT_TYPE ntheory_lucas(basic s,
unsigned long a);
768 CWRAPPER_OUTPUT_TYPE ntheory_lucas2(basic g, basic s,
unsigned long a);
770 CWRAPPER_OUTPUT_TYPE ntheory_binomial(basic s,
const basic a,
unsigned long b);
772 CWRAPPER_OUTPUT_TYPE ntheory_factorial(basic s,
unsigned long n);
774 CWRAPPER_OUTPUT_TYPE basic_evalf(basic s,
const basic b,
unsigned long bits,
778 CWRAPPER_OUTPUT_TYPE basic_as_numer_denom(basic numer, basic denom,
781 CWRAPPER_OUTPUT_TYPE basic_add_as_two_terms(basic term1, basic term2,
784 CWRAPPER_OUTPUT_TYPE basic_mul_as_two_terms(basic term1, basic term2,
792 const CVecBasic *exprs,
int perform_cse);
795 const double *
const inps);
799 #ifdef HAVE_SYMENGINE_LLVM
801 typedef struct CLLVMDoubleVisitor CLLVMDoubleVisitor;
802 CLLVMDoubleVisitor *llvm_double_visitor_new(
void);
803 void llvm_double_visitor_init(CLLVMDoubleVisitor *
self,
const CVecBasic *args,
806 void llvm_double_visitor_call(CLLVMDoubleVisitor *
self,
double *
const outs,
807 const double *
const inps);
808 void llvm_double_visitor_free(CLLVMDoubleVisitor *
self);
810 typedef struct CLLVMFloatVisitor CLLVMFloatVisitor;
811 CLLVMFloatVisitor *llvm_float_visitor_new(
void);
812 void llvm_float_visitor_init(CLLVMFloatVisitor *
self,
const CVecBasic *args,
815 void llvm_float_visitor_call(CLLVMFloatVisitor *
self,
float *
const outs,
816 const float *
const inps);
817 void llvm_float_visitor_free(CLLVMFloatVisitor *
self);
819 #ifdef SYMENGINE_HAVE_LLVM_LONG_DOUBLE
821 typedef struct CLLVMLongDoubleVisitor CLLVMLongDoubleVisitor;
822 CLLVMLongDoubleVisitor *llvm_long_double_visitor_new(
void);
823 void llvm_long_double_visitor_init(CLLVMLongDoubleVisitor *
self,
827 void llvm_long_double_visitor_call(CLLVMLongDoubleVisitor *
self,
828 long double *
const outs,
829 const long double *
const inps);
830 void llvm_long_double_visitor_free(CLLVMLongDoubleVisitor *
self);
834 CWRAPPER_OUTPUT_TYPE basic_cse(
CVecBasic *replacement_syms,
840 void symengine_print_stack_on_segfault(
void);
bool is_a_Number(const Basic &b)
bool is_a_Complex(const Basic &b)