cwrapper.h
1 #ifndef CWRAPPER_H
2 #define CWRAPPER_H
3 
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include "symengine/symengine_config.h"
7 
8 #ifdef HAVE_SYMENGINE_GMP
9 #include <gmp.h>
10 #endif
11 
12 #ifdef HAVE_SYMENGINE_MPFR
13 #include <mpfr.h>
14 #endif // HAVE_SYMENGINE_MPFR
15 
16 #include "symengine/symengine_exception.h"
17 
18 #ifdef __cplusplus
19 extern "C" {
20 #endif
21 
22 // Use SYMENGINE_C_ASSERT in C tests
23 #define SYMENGINE_C_ASSERT(cond) \
24  { \
25  if (0 == (cond)) { \
26  printf("SYMENGINE_C_ASSERT failed: %s \nfunction %s (), line " \
27  "number %d at\n%s\n", \
28  __FILE__, __func__, __LINE__, #cond); \
29  abort(); \
30  } \
31  }
32 
33 typedef symengine_exceptions_t CWRAPPER_OUTPUT_TYPE;
34 
35 typedef enum {
36 #define SYMENGINE_INCLUDE_ALL
37 #define SYMENGINE_ENUM(type, Class) type,
38 #include "symengine/type_codes.inc"
39 #undef SYMENGINE_ENUM
40 #undef SYMENGINE_INCLUDE_ALL
41  SYMENGINE_TypeID_Count
42 } TypeID;
43 
46 typedef struct dcomplex {
47  double real;
48  double imag;
49 } dcomplex;
50 
51 // The size of 'CRCPBasic_C' must be the same as CRCPBasic (which contains a
52 // single RCP<const Basic> member) *and* they must have the same alignment
53 // (because we allocate CRCPBasic into the memory occupied by this struct in
54 // cwrapper.cpp). We cannot use C++ in this file, so we need to use C tools to
55 // arrive at the correct size and alignment. The size of the RCP object on
56 // most platforms (with WITH_SYMENGINE_RCP on) should be just the size of the
57 // 'T *ptr_' pointer that it contains (as there is no virtual function table)
58 // and the alignment should also be of a pointer. So we just put 'void *data'
59 // as the only member of the struct, that should have the correct size and
60 // alignment. With WITH_SYMENGINE_RCP off (i.e. using Teuchos::RCP), we have to
61 // add additional members into the structure.
62 //
63 // However, this is checked at compile time in cwrapper.cpp, so if the size or
64 // alignment is different on some platform, the compilation will fail --- in
65 // that case one needs to modify the contents of this struct to adjust its size
66 // and/or alignment.
67 struct CRCPBasic_C {
68  void *data;
69 #if !defined(WITH_SYMENGINE_RCP)
70  void *teuchos_handle;
71  int teuchos_strength;
72 #endif
73 };
74 
76 // CRCPBasic, which has the same size and alignment as RCP<const Basic> (see
77 // the above comment for details). That is then used by the user to allocate
78 // the memory needed for RCP<const Basic> on the stack. A 'basic' type should
79 // be initialized using basic_new_stack(), before any function is called.
80 // Assignment should be done only by using basic_assign(). Before the variable
81 // goes out of scope, basic_free_stack() must be called.
82 //
83 // For C, define a dummy struct with the right size, so that it can be
84 // allocated on the stack. For C++, the CRCPBasic is declared in cwrapper.cpp.
85 #ifdef __cplusplus
86 typedef struct CRCPBasic basic_struct;
87 #else
88 typedef struct CRCPBasic_C basic_struct;
89 #endif
90 
91 typedef struct CSetBasic CSetBasic;
92 
95 typedef basic_struct basic[1];
96 
98 // 'basic' type, this function initializes an RCP<const Basic> on the stack
99 // allocated variable. The 's' variable must be freed using basic_free_stack()
100 void basic_new_stack(basic s);
102 void basic_free_stack(basic s);
103 
104 // Use these two functions to allocate and free 'basic' on a heap. The pointer
105 // can then be used in all the other methods below (i.e. the methods that
106 // accept 'basic s' work no matter if 's' is stack or heap allocated).
107 basic_struct *basic_new_heap(void);
108 void basic_free_heap(basic_struct *s);
109 
110 const char *symengine_version(void);
111 
113 
118 void basic_const_set(basic s, const char *c);
119 
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);
124 
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);
130 
133 void basic_const_infinity(basic s);
134 void basic_const_neginfinity(basic s);
135 void basic_const_complex_infinity(basic s);
136 
138 void basic_const_nan(basic s);
139 
141 CWRAPPER_OUTPUT_TYPE basic_assign(basic a, const basic b);
142 
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);
148 
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);
156 
160 CWRAPPER_OUTPUT_TYPE symbol_set(basic s, const char *c);
161 
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);
170 
172 int basic_has_symbol(const basic e, const basic s);
173 
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);
181 #endif
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);
188 
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);
203 #endif // HAVE_SYMENGINE_MPFR
204 
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);
209 
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);
217 #endif
218 
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);
231 #endif
232 
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);
240 #endif
241 
244 dcomplex complex_double_get(const basic s);
245 
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);
263 
265 CWRAPPER_OUTPUT_TYPE basic_expand(basic s, const basic a);
267 CWRAPPER_OUTPUT_TYPE basic_neg(basic s, const basic a);
268 
270 CWRAPPER_OUTPUT_TYPE basic_abs(basic s, const basic a);
271 
273 CWRAPPER_OUTPUT_TYPE basic_erf(basic s, const basic a);
275 CWRAPPER_OUTPUT_TYPE basic_erfc(basic s, const basic a);
276 
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);
283 
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);
290 
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);
297 
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);
304 
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);
311 
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);
318 
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);
325 
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);
332 
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);
357 
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,
362  const basic b);
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);
371 
373 char *basic_dumps(const basic s, unsigned long *size);
375 CWRAPPER_OUTPUT_TYPE basic_loads(basic s, const char *c, unsigned long size);
376 
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);
392 
394 void bool_set_true(basic s);
396 void bool_set_false(basic s);
397 
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,
413  int right_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,
420  const basic b);
422 CWRAPPER_OUTPUT_TYPE basic_set_complement(basic s, const basic a,
423  const basic b);
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);
444 
454 int symengine_have_component(const char *c);
455 
457 int is_a_Number(const basic s);
459 int is_a_Integer(const basic s);
461 int is_a_Rational(const basic s);
463 int is_a_Symbol(const basic s);
465 int is_a_Complex(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);
476 
478 
479 typedef struct CVectorInt CVectorInt;
480 
481 CVectorInt *vectorint_new(void);
482 
483 // 'data' must point to allocated memory of size 'size'. The function returns 0
484 // if std::vector<int> can be initialized using placement new into 'data',
485 // otherwise 1 if 'size' is too small or 2 if 'data' is not properly aligned.
486 // No memory is leaked either way. Use vectorint_placement_new_check() to check
487 // that the 'data' and 'size' is properly allocated and aligned. Use
488 // vectorint_placement_new() to do the actual allocation.
489 int vectorint_placement_new_check(void *data, size_t size);
490 CVectorInt *vectorint_placement_new(void *data);
491 
492 void vectorint_placement_free(CVectorInt *self);
493 
494 void vectorint_free(CVectorInt *self);
495 void vectorint_push_back(CVectorInt *self, int value);
496 int vectorint_get(CVectorInt *self, int n);
497 
499 
500 typedef struct CVecBasic CVecBasic;
501 
502 CVecBasic *vecbasic_new(void);
503 void vecbasic_free(CVecBasic *self);
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);
508 size_t vecbasic_size(CVecBasic *self);
509 
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);
516 
518 CWRAPPER_OUTPUT_TYPE basic_mul_vec(basic s, const CVecBasic *d);
519 
521 
522 typedef struct CDenseMatrix CDenseMatrix;
523 typedef struct CSparseMatrix CSparseMatrix;
524 
525 CDenseMatrix *dense_matrix_new(void);
526 CSparseMatrix *sparse_matrix_new(void);
527 
528 void dense_matrix_free(CDenseMatrix *self);
530 CDenseMatrix *dense_matrix_new_vec(unsigned rows, unsigned cols, CVecBasic *l);
532 CDenseMatrix *dense_matrix_new_rows_cols(unsigned r, unsigned c);
533 
534 void sparse_matrix_free(CSparseMatrix *self);
535 
537 CWRAPPER_OUTPUT_TYPE dense_matrix_set(CDenseMatrix *s, const CDenseMatrix *d);
538 
541 char *dense_matrix_str(const CDenseMatrix *s);
543 CWRAPPER_OUTPUT_TYPE dense_matrix_rows_cols(CDenseMatrix *mat, unsigned r,
544  unsigned c);
546 CWRAPPER_OUTPUT_TYPE dense_matrix_get_basic(basic s, const CDenseMatrix *mat,
547  unsigned long int r,
548  unsigned long int c);
550 CWRAPPER_OUTPUT_TYPE dense_matrix_set_basic(CDenseMatrix *mat,
551  unsigned long int r,
552  unsigned long int c, basic s);
554 CWRAPPER_OUTPUT_TYPE sparse_matrix_get_basic(basic s, const CSparseMatrix *mat,
555  unsigned long int r,
556  unsigned long int c);
558 CWRAPPER_OUTPUT_TYPE sparse_matrix_set_basic(CSparseMatrix *mat,
559  unsigned long int r,
560  unsigned long int c, basic s);
562 CWRAPPER_OUTPUT_TYPE dense_matrix_det(basic s, const CDenseMatrix *mat);
564 CWRAPPER_OUTPUT_TYPE dense_matrix_inv(CDenseMatrix *s, const CDenseMatrix *mat);
566 CWRAPPER_OUTPUT_TYPE dense_matrix_transpose(CDenseMatrix *s,
567  const CDenseMatrix *mat);
570 CWRAPPER_OUTPUT_TYPE
571 dense_matrix_submatrix(CDenseMatrix *s, const CDenseMatrix *mat,
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,
577  const CDenseMatrix *B);
579 CWRAPPER_OUTPUT_TYPE dense_matrix_col_join(CDenseMatrix *A,
580  const CDenseMatrix *B);
582 CWRAPPER_OUTPUT_TYPE dense_matrix_row_del(CDenseMatrix *C, unsigned k);
584 CWRAPPER_OUTPUT_TYPE dense_matrix_col_del(CDenseMatrix *C, unsigned k);
585 
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,
592  const CDenseMatrix *matA,
593  const CDenseMatrix *matB);
595 CWRAPPER_OUTPUT_TYPE dense_matrix_mul_matrix(CDenseMatrix *s,
596  const CDenseMatrix *matA,
597  const CDenseMatrix *matB);
599 CWRAPPER_OUTPUT_TYPE dense_matrix_add_scalar(CDenseMatrix *s,
600  const CDenseMatrix *matA,
601  const basic b);
603 CWRAPPER_OUTPUT_TYPE dense_matrix_mul_scalar(CDenseMatrix *s,
604  const CDenseMatrix *matA,
605  const basic b);
607 CWRAPPER_OUTPUT_TYPE dense_matrix_LU(CDenseMatrix *l, CDenseMatrix *u,
608  const CDenseMatrix *mat);
610 CWRAPPER_OUTPUT_TYPE dense_matrix_LDL(CDenseMatrix *l, CDenseMatrix *d,
611  const CDenseMatrix *mat);
613 CWRAPPER_OUTPUT_TYPE dense_matrix_FFLU(CDenseMatrix *lu,
614  const CDenseMatrix *mat);
616 CWRAPPER_OUTPUT_TYPE dense_matrix_FFLDU(CDenseMatrix *l, CDenseMatrix *d,
617  CDenseMatrix *u,
618  const CDenseMatrix *mat);
620 CWRAPPER_OUTPUT_TYPE dense_matrix_LU_solve(CDenseMatrix *x,
621  const CDenseMatrix *A,
622  const CDenseMatrix *b);
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);
631 CWRAPPER_OUTPUT_TYPE dense_matrix_diag(CDenseMatrix *s, CVecBasic *d,
632  long int k);
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,
639  const CDenseMatrix *A, basic const x);
641 CWRAPPER_OUTPUT_TYPE dense_matrix_jacobian(CDenseMatrix *result,
642  const CDenseMatrix *A,
643  const CDenseMatrix *x);
644 
646 void sparse_matrix_init(CSparseMatrix *s);
648 void sparse_matrix_rows_cols(CSparseMatrix *s, unsigned long int r,
649  unsigned long int c);
651 char *sparse_matrix_str(const CSparseMatrix *s);
652 
654 int is_a_DenseMatrix(const CDenseMatrix *c);
656 int is_a_SparseMatrix(const CSparseMatrix *c);
657 
659 int dense_matrix_eq(CDenseMatrix *lhs, CDenseMatrix *rhs);
661 int sparse_matrix_eq(CSparseMatrix *lhs, CSparseMatrix *rhs);
662 
664 
665 CSetBasic *setbasic_new(void);
666 void setbasic_free(CSetBasic *self);
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);
675 size_t setbasic_size(CSetBasic *self);
676 
678 
679 typedef struct CMapBasicBasic CMapBasicBasic;
680 
681 CMapBasicBasic *mapbasicbasic_new(void);
682 void mapbasicbasic_free(CMapBasicBasic *self);
683 void mapbasicbasic_insert(CMapBasicBasic *self, const basic key,
684  const basic mapped);
686 int mapbasicbasic_get(CMapBasicBasic *self, const basic key, basic mapped);
687 size_t mapbasicbasic_size(CMapBasicBasic *self);
688 
689 // -------------------------------------
690 
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,
697  const basic self);
699 size_t basic_hash(const basic self);
702 CWRAPPER_OUTPUT_TYPE basic_subs(basic s, const basic e,
703  const CMapBasicBasic *mapbb);
706 CWRAPPER_OUTPUT_TYPE basic_subs2(basic s, const basic e, const basic a,
707  const basic b);
708 
711 CWRAPPER_OUTPUT_TYPE function_symbol_set(basic s, const char *c,
712  const CVecBasic *arg);
715 char *function_symbol_get_name(const basic b);
717 CWRAPPER_OUTPUT_TYPE basic_coeff(basic c, const basic b, const basic x,
718  const basic n);
719 
721 
723 CWRAPPER_OUTPUT_TYPE vecbasic_linsolve(CVecBasic *sol, const CVecBasic *sys,
724  const CVecBasic *sym);
726 CWRAPPER_OUTPUT_TYPE basic_solve_poly(CSetBasic *r, const basic f,
727  const basic s);
728 
730 
733 char *ascii_art_str(void);
734 
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,
742  const basic b);
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,
751  const basic d);
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,
758  const basic d);
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,
775  int real);
776 
778 CWRAPPER_OUTPUT_TYPE basic_as_numer_denom(basic numer, basic denom,
779  const basic x);
781 CWRAPPER_OUTPUT_TYPE basic_add_as_two_terms(basic term1, basic term2,
782  const basic s);
784 CWRAPPER_OUTPUT_TYPE basic_mul_as_two_terms(basic term1, basic term2,
785  const basic s);
786 
789 CLambdaRealDoubleVisitor *lambda_real_double_visitor_new(void);
790 void lambda_real_double_visitor_init(CLambdaRealDoubleVisitor *self,
791  const CVecBasic *args,
792  const CVecBasic *exprs, int perform_cse);
793 void lambda_real_double_visitor_call(CLambdaRealDoubleVisitor *self,
794  double *const outs,
795  const double *const inps);
796 void lambda_real_double_visitor_free(CLambdaRealDoubleVisitor *self);
797 
799 #ifdef HAVE_SYMENGINE_LLVM
800 // double
801 typedef struct CLLVMDoubleVisitor CLLVMDoubleVisitor;
802 CLLVMDoubleVisitor *llvm_double_visitor_new(void);
803 void llvm_double_visitor_init(CLLVMDoubleVisitor *self, const CVecBasic *args,
804  const CVecBasic *exprs, int perform_cse,
805  int opt_level);
806 void llvm_double_visitor_call(CLLVMDoubleVisitor *self, double *const outs,
807  const double *const inps);
808 void llvm_double_visitor_free(CLLVMDoubleVisitor *self);
809 // float
810 typedef struct CLLVMFloatVisitor CLLVMFloatVisitor;
811 CLLVMFloatVisitor *llvm_float_visitor_new(void);
812 void llvm_float_visitor_init(CLLVMFloatVisitor *self, const CVecBasic *args,
813  const CVecBasic *exprs, int perform_cse,
814  int opt_level);
815 void llvm_float_visitor_call(CLLVMFloatVisitor *self, float *const outs,
816  const float *const inps);
817 void llvm_float_visitor_free(CLLVMFloatVisitor *self);
818 
819 #ifdef SYMENGINE_HAVE_LLVM_LONG_DOUBLE
820 // long double
821 typedef struct CLLVMLongDoubleVisitor CLLVMLongDoubleVisitor;
822 CLLVMLongDoubleVisitor *llvm_long_double_visitor_new(void);
823 void llvm_long_double_visitor_init(CLLVMLongDoubleVisitor *self,
824  const CVecBasic *args,
825  const CVecBasic *exprs, int perform_cse,
826  int opt_level);
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);
831 #endif
832 #endif
833 
834 CWRAPPER_OUTPUT_TYPE basic_cse(CVecBasic *replacement_syms,
835  CVecBasic *replacement_exprs,
836  CVecBasic *reduced_exprs,
837  const CVecBasic *exprs);
838 
840 void symengine_print_stack_on_segfault(void);
841 
842 #ifdef __cplusplus
843 }
844 #endif
845 #endif
bool is_a_Number(const Basic &b)
Definition: number.h:130
TypeID
Definition: basic.h:43
bool is_a_Complex(const Basic &b)
Definition: complex.h:24