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);
355 
357 CWRAPPER_OUTPUT_TYPE basic_atan2(basic s, const basic a, const basic b);
359 CWRAPPER_OUTPUT_TYPE basic_kronecker_delta(basic s, const basic a,
360  const basic b);
362 CWRAPPER_OUTPUT_TYPE basic_lowergamma(basic s, const basic a, const basic b);
364 CWRAPPER_OUTPUT_TYPE basic_uppergamma(basic s, const basic a, const basic b);
366 CWRAPPER_OUTPUT_TYPE basic_beta(basic s, const basic a, const basic b);
368 CWRAPPER_OUTPUT_TYPE basic_polygamma(basic s, const basic a, const basic b);
369 
371 char *basic_dumps(const basic s, unsigned long *size);
373 CWRAPPER_OUTPUT_TYPE basic_loads(basic s, const char *c, unsigned long size);
374 
376 char *basic_str(const basic s);
379 char *basic_str_julia(const basic s);
381 char *basic_str_mathml(const basic s);
383 char *basic_str_latex(const basic s);
385 char *basic_str_ccode(const basic s);
387 char *basic_str_jscode(const basic s);
389 void basic_str_free(char *s);
390 
392 void bool_set_true(basic s);
394 void bool_set_false(basic s);
395 
397 void basic_set_emptyset(basic s);
399 void basic_set_universalset(basic s);
401 void basic_set_complexes(basic s);
403 void basic_set_reals(basic s);
405 void basic_set_rationals(basic s);
407 void basic_set_integers(basic s);
409 CWRAPPER_OUTPUT_TYPE basic_set_interval(basic s, const basic start,
410  const basic end, int left_open,
411  int right_open);
413 CWRAPPER_OUTPUT_TYPE basic_set_finiteset(basic s, const CSetBasic *container);
415 CWRAPPER_OUTPUT_TYPE basic_set_union(basic s, const basic a, const basic b);
417 CWRAPPER_OUTPUT_TYPE basic_set_intersection(basic s, const basic a,
418  const basic b);
420 CWRAPPER_OUTPUT_TYPE basic_set_complement(basic s, const basic a,
421  const basic b);
423 CWRAPPER_OUTPUT_TYPE basic_set_contains(basic s, const basic a, const basic b);
425 int basic_set_is_subset(const basic a, const basic b);
427 int basic_set_is_proper_subset(const basic a, const basic b);
429 int basic_set_is_superset(const basic a, const basic b);
431 int basic_set_is_proper_superset(const basic a, const basic b);
433 CWRAPPER_OUTPUT_TYPE basic_set_inf(basic s, const basic a);
435 CWRAPPER_OUTPUT_TYPE basic_set_sup(basic s, const basic a);
437 CWRAPPER_OUTPUT_TYPE basic_set_boundary(basic s, const basic a);
439 CWRAPPER_OUTPUT_TYPE basic_set_interior(basic s, const basic a);
441 CWRAPPER_OUTPUT_TYPE basic_set_closure(basic s, const basic a);
442 
452 int symengine_have_component(const char *c);
453 
455 int is_a_Number(const basic s);
457 int is_a_Integer(const basic s);
459 int is_a_Rational(const basic s);
461 int is_a_Symbol(const basic s);
463 int is_a_Complex(const basic s);
465 int is_a_RealDouble(const basic c);
467 int is_a_ComplexDouble(const basic c);
469 int is_a_RealMPFR(const basic c);
471 int is_a_ComplexMPC(const basic c);
473 int is_a_Set(const basic c);
474 
476 
477 typedef struct CVectorInt CVectorInt;
478 
479 CVectorInt *vectorint_new(void);
480 
481 // 'data' must point to allocated memory of size 'size'. The function returns 0
482 // if std::vector<int> can be initialized using placement new into 'data',
483 // otherwise 1 if 'size' is too small or 2 if 'data' is not properly aligned.
484 // No memory is leaked either way. Use vectorint_placement_new_check() to check
485 // that the 'data' and 'size' is properly allocated and aligned. Use
486 // vectorint_placement_new() to do the actual allocation.
487 int vectorint_placement_new_check(void *data, size_t size);
488 CVectorInt *vectorint_placement_new(void *data);
489 
490 void vectorint_placement_free(CVectorInt *self);
491 
492 void vectorint_free(CVectorInt *self);
493 void vectorint_push_back(CVectorInt *self, int value);
494 int vectorint_get(CVectorInt *self, int n);
495 
497 
498 typedef struct CVecBasic CVecBasic;
499 
500 CVecBasic *vecbasic_new(void);
501 void vecbasic_free(CVecBasic *self);
502 CWRAPPER_OUTPUT_TYPE vecbasic_push_back(CVecBasic *self, const basic value);
503 CWRAPPER_OUTPUT_TYPE vecbasic_get(CVecBasic *self, size_t n, basic result);
504 CWRAPPER_OUTPUT_TYPE vecbasic_set(CVecBasic *self, size_t n, const basic s);
505 CWRAPPER_OUTPUT_TYPE vecbasic_erase(CVecBasic *self, size_t n);
506 size_t vecbasic_size(CVecBasic *self);
507 
509 CWRAPPER_OUTPUT_TYPE basic_max(basic s, const CVecBasic *d);
511 CWRAPPER_OUTPUT_TYPE basic_min(basic s, const CVecBasic *d);
513 CWRAPPER_OUTPUT_TYPE basic_add_vec(basic s, const CVecBasic *d);
514 
516 CWRAPPER_OUTPUT_TYPE basic_mul_vec(basic s, const CVecBasic *d);
517 
519 
520 typedef struct CDenseMatrix CDenseMatrix;
521 typedef struct CSparseMatrix CSparseMatrix;
522 
523 CDenseMatrix *dense_matrix_new(void);
524 CSparseMatrix *sparse_matrix_new(void);
525 
526 void dense_matrix_free(CDenseMatrix *self);
528 CDenseMatrix *dense_matrix_new_vec(unsigned rows, unsigned cols, CVecBasic *l);
530 CDenseMatrix *dense_matrix_new_rows_cols(unsigned r, unsigned c);
531 
532 void sparse_matrix_free(CSparseMatrix *self);
533 
535 CWRAPPER_OUTPUT_TYPE dense_matrix_set(CDenseMatrix *s, const CDenseMatrix *d);
536 
539 char *dense_matrix_str(const CDenseMatrix *s);
541 CWRAPPER_OUTPUT_TYPE dense_matrix_rows_cols(CDenseMatrix *mat, unsigned r,
542  unsigned c);
544 CWRAPPER_OUTPUT_TYPE dense_matrix_get_basic(basic s, const CDenseMatrix *mat,
545  unsigned long int r,
546  unsigned long int c);
548 CWRAPPER_OUTPUT_TYPE dense_matrix_set_basic(CDenseMatrix *mat,
549  unsigned long int r,
550  unsigned long int c, basic s);
552 CWRAPPER_OUTPUT_TYPE sparse_matrix_get_basic(basic s, const CSparseMatrix *mat,
553  unsigned long int r,
554  unsigned long int c);
556 CWRAPPER_OUTPUT_TYPE sparse_matrix_set_basic(CSparseMatrix *mat,
557  unsigned long int r,
558  unsigned long int c, basic s);
560 CWRAPPER_OUTPUT_TYPE dense_matrix_det(basic s, const CDenseMatrix *mat);
562 CWRAPPER_OUTPUT_TYPE dense_matrix_inv(CDenseMatrix *s, const CDenseMatrix *mat);
564 CWRAPPER_OUTPUT_TYPE dense_matrix_transpose(CDenseMatrix *s,
565  const CDenseMatrix *mat);
568 CWRAPPER_OUTPUT_TYPE
569 dense_matrix_submatrix(CDenseMatrix *s, const CDenseMatrix *mat,
570  unsigned long int r1, unsigned long int c1,
571  unsigned long int r2, unsigned long int c2,
572  unsigned long int r, unsigned long int c);
574 CWRAPPER_OUTPUT_TYPE dense_matrix_row_join(CDenseMatrix *A,
575  const CDenseMatrix *B);
577 CWRAPPER_OUTPUT_TYPE dense_matrix_col_join(CDenseMatrix *A,
578  const CDenseMatrix *B);
580 CWRAPPER_OUTPUT_TYPE dense_matrix_row_del(CDenseMatrix *C, unsigned k);
582 CWRAPPER_OUTPUT_TYPE dense_matrix_col_del(CDenseMatrix *C, unsigned k);
583 
585 unsigned long int dense_matrix_cols(const CDenseMatrix *s);
587 unsigned long int dense_matrix_rows(const CDenseMatrix *s);
589 CWRAPPER_OUTPUT_TYPE dense_matrix_add_matrix(CDenseMatrix *s,
590  const CDenseMatrix *matA,
591  const CDenseMatrix *matB);
593 CWRAPPER_OUTPUT_TYPE dense_matrix_mul_matrix(CDenseMatrix *s,
594  const CDenseMatrix *matA,
595  const CDenseMatrix *matB);
597 CWRAPPER_OUTPUT_TYPE dense_matrix_add_scalar(CDenseMatrix *s,
598  const CDenseMatrix *matA,
599  const basic b);
601 CWRAPPER_OUTPUT_TYPE dense_matrix_mul_scalar(CDenseMatrix *s,
602  const CDenseMatrix *matA,
603  const basic b);
605 CWRAPPER_OUTPUT_TYPE dense_matrix_LU(CDenseMatrix *l, CDenseMatrix *u,
606  const CDenseMatrix *mat);
608 CWRAPPER_OUTPUT_TYPE dense_matrix_LDL(CDenseMatrix *l, CDenseMatrix *d,
609  const CDenseMatrix *mat);
611 CWRAPPER_OUTPUT_TYPE dense_matrix_FFLU(CDenseMatrix *lu,
612  const CDenseMatrix *mat);
614 CWRAPPER_OUTPUT_TYPE dense_matrix_FFLDU(CDenseMatrix *l, CDenseMatrix *d,
615  CDenseMatrix *u,
616  const CDenseMatrix *mat);
618 CWRAPPER_OUTPUT_TYPE dense_matrix_LU_solve(CDenseMatrix *x,
619  const CDenseMatrix *A,
620  const CDenseMatrix *b);
622 CWRAPPER_OUTPUT_TYPE dense_matrix_ones(CDenseMatrix *s, unsigned long int r,
623  unsigned long int c);
625 CWRAPPER_OUTPUT_TYPE dense_matrix_zeros(CDenseMatrix *s, unsigned long int r,
626  unsigned long int c);
629 CWRAPPER_OUTPUT_TYPE dense_matrix_diag(CDenseMatrix *s, CVecBasic *d,
630  long int k);
632 CWRAPPER_OUTPUT_TYPE dense_matrix_eye(CDenseMatrix *s, unsigned long int N,
633  unsigned long int M, int k);
636 CWRAPPER_OUTPUT_TYPE dense_matrix_diff(CDenseMatrix *result,
637  const CDenseMatrix *A, basic const x);
639 CWRAPPER_OUTPUT_TYPE dense_matrix_jacobian(CDenseMatrix *result,
640  const CDenseMatrix *A,
641  const CDenseMatrix *x);
642 
644 void sparse_matrix_init(CSparseMatrix *s);
646 void sparse_matrix_rows_cols(CSparseMatrix *s, unsigned long int r,
647  unsigned long int c);
649 char *sparse_matrix_str(const CSparseMatrix *s);
650 
652 int is_a_DenseMatrix(const CDenseMatrix *c);
654 int is_a_SparseMatrix(const CSparseMatrix *c);
655 
657 int dense_matrix_eq(CDenseMatrix *lhs, CDenseMatrix *rhs);
659 int sparse_matrix_eq(CSparseMatrix *lhs, CSparseMatrix *rhs);
660 
662 
663 CSetBasic *setbasic_new(void);
664 void setbasic_free(CSetBasic *self);
667 int setbasic_insert(CSetBasic *self, const basic value);
668 void setbasic_get(CSetBasic *self, int n, basic result);
670 int setbasic_find(CSetBasic *self, basic value);
672 int setbasic_erase(CSetBasic *self, const basic value);
673 size_t setbasic_size(CSetBasic *self);
674 
676 
677 typedef struct CMapBasicBasic CMapBasicBasic;
678 
679 CMapBasicBasic *mapbasicbasic_new(void);
680 void mapbasicbasic_free(CMapBasicBasic *self);
681 void mapbasicbasic_insert(CMapBasicBasic *self, const basic key,
682  const basic mapped);
684 int mapbasicbasic_get(CMapBasicBasic *self, const basic key, basic mapped);
685 size_t mapbasicbasic_size(CMapBasicBasic *self);
686 
687 // -------------------------------------
688 
690 CWRAPPER_OUTPUT_TYPE basic_get_args(const basic self, CVecBasic *args);
692 CWRAPPER_OUTPUT_TYPE basic_free_symbols(const basic self, CSetBasic *symbols);
694 CWRAPPER_OUTPUT_TYPE basic_function_symbols(CSetBasic *symbols,
695  const basic self);
697 size_t basic_hash(const basic self);
700 CWRAPPER_OUTPUT_TYPE basic_subs(basic s, const basic e,
701  const CMapBasicBasic *mapbb);
704 CWRAPPER_OUTPUT_TYPE basic_subs2(basic s, const basic e, const basic a,
705  const basic b);
706 
709 CWRAPPER_OUTPUT_TYPE function_symbol_set(basic s, const char *c,
710  const CVecBasic *arg);
713 char *function_symbol_get_name(const basic b);
715 CWRAPPER_OUTPUT_TYPE basic_coeff(basic c, const basic b, const basic x,
716  const basic n);
717 
719 
721 CWRAPPER_OUTPUT_TYPE vecbasic_linsolve(CVecBasic *sol, const CVecBasic *sys,
722  const CVecBasic *sym);
724 CWRAPPER_OUTPUT_TYPE basic_solve_poly(CSetBasic *r, const basic f,
725  const basic s);
726 
728 
731 char *ascii_art_str(void);
732 
735 CWRAPPER_OUTPUT_TYPE ntheory_gcd(basic s, const basic a, const basic b);
737 CWRAPPER_OUTPUT_TYPE ntheory_lcm(basic s, const basic a, const basic b);
739 CWRAPPER_OUTPUT_TYPE ntheory_gcd_ext(basic g, basic s, basic t, const basic a,
740  const basic b);
742 CWRAPPER_OUTPUT_TYPE ntheory_nextprime(basic s, const basic a);
744 CWRAPPER_OUTPUT_TYPE ntheory_mod(basic s, const basic n, const basic d);
746 CWRAPPER_OUTPUT_TYPE ntheory_quotient(basic s, const basic n, const basic d);
748 CWRAPPER_OUTPUT_TYPE ntheory_quotient_mod(basic q, basic r, const basic n,
749  const basic d);
751 CWRAPPER_OUTPUT_TYPE ntheory_mod_f(basic s, const basic n, const basic d);
753 CWRAPPER_OUTPUT_TYPE ntheory_quotient_f(basic s, const basic n, const basic d);
755 CWRAPPER_OUTPUT_TYPE ntheory_quotient_mod_f(basic q, basic r, const basic n,
756  const basic d);
758 int ntheory_mod_inverse(basic b, const basic a, const basic m);
760 CWRAPPER_OUTPUT_TYPE ntheory_fibonacci(basic s, unsigned long a);
762 CWRAPPER_OUTPUT_TYPE ntheory_fibonacci2(basic g, basic s, unsigned long a);
764 CWRAPPER_OUTPUT_TYPE ntheory_lucas(basic s, unsigned long a);
766 CWRAPPER_OUTPUT_TYPE ntheory_lucas2(basic g, basic s, unsigned long a);
768 CWRAPPER_OUTPUT_TYPE ntheory_binomial(basic s, const basic a, unsigned long b);
770 CWRAPPER_OUTPUT_TYPE ntheory_factorial(basic s, unsigned long n);
772 CWRAPPER_OUTPUT_TYPE basic_evalf(basic s, const basic b, unsigned long bits,
773  int real);
774 
776 CWRAPPER_OUTPUT_TYPE basic_as_numer_denom(basic numer, basic denom,
777  const basic x);
778 
781 CLambdaRealDoubleVisitor *lambda_real_double_visitor_new(void);
782 void lambda_real_double_visitor_init(CLambdaRealDoubleVisitor *self,
783  const CVecBasic *args,
784  const CVecBasic *exprs, int perform_cse);
785 void lambda_real_double_visitor_call(CLambdaRealDoubleVisitor *self,
786  double *const outs,
787  const double *const inps);
788 void lambda_real_double_visitor_free(CLambdaRealDoubleVisitor *self);
789 
791 #ifdef HAVE_SYMENGINE_LLVM
792 // double
793 typedef struct CLLVMDoubleVisitor CLLVMDoubleVisitor;
794 CLLVMDoubleVisitor *llvm_double_visitor_new(void);
795 void llvm_double_visitor_init(CLLVMDoubleVisitor *self, const CVecBasic *args,
796  const CVecBasic *exprs, int perform_cse,
797  int opt_level);
798 void llvm_double_visitor_call(CLLVMDoubleVisitor *self, double *const outs,
799  const double *const inps);
800 void llvm_double_visitor_free(CLLVMDoubleVisitor *self);
801 // float
802 typedef struct CLLVMFloatVisitor CLLVMFloatVisitor;
803 CLLVMFloatVisitor *llvm_float_visitor_new(void);
804 void llvm_float_visitor_init(CLLVMFloatVisitor *self, const CVecBasic *args,
805  const CVecBasic *exprs, int perform_cse,
806  int opt_level);
807 void llvm_float_visitor_call(CLLVMFloatVisitor *self, float *const outs,
808  const float *const inps);
809 void llvm_float_visitor_free(CLLVMFloatVisitor *self);
810 
811 #ifdef SYMENGINE_HAVE_LLVM_LONG_DOUBLE
812 // long double
813 typedef struct CLLVMLongDoubleVisitor CLLVMLongDoubleVisitor;
814 CLLVMLongDoubleVisitor *llvm_long_double_visitor_new(void);
815 void llvm_long_double_visitor_init(CLLVMLongDoubleVisitor *self,
816  const CVecBasic *args,
817  const CVecBasic *exprs, int perform_cse,
818  int opt_level);
819 void llvm_long_double_visitor_call(CLLVMLongDoubleVisitor *self,
820  long double *const outs,
821  const long double *const inps);
822 void llvm_long_double_visitor_free(CLLVMLongDoubleVisitor *self);
823 #endif
824 #endif
825 
826 CWRAPPER_OUTPUT_TYPE basic_cse(CVecBasic *replacement_syms,
827  CVecBasic *replacement_exprs,
828  CVecBasic *reduced_exprs,
829  const CVecBasic *exprs);
830 
832 void symengine_print_stack_on_segfault(void);
833 
834 #ifdef __cplusplus
835 }
836 #endif
837 #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