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 downstream projects, define a dummy struct with the right size, so
84 // that it can be allocated on the stack. When building the library in
85 // cwrapper.cpp, the CRCPBasic is declared in cwrapper.cpp which removes
86 // the need to cast the C struct to C++ struct every time.
87 #ifdef symengine_EXPORTS
88 typedef struct CRCPBasic basic_struct;
89 #else
90 typedef struct CRCPBasic_C basic_struct;
91 #endif
92 
93 typedef struct CSetBasic CSetBasic;
94 
97 typedef basic_struct basic[1];
98 
100 // 'basic' type, this function initializes an RCP<const Basic> on the stack
101 // allocated variable. The 's' variable must be freed using basic_free_stack()
102 void basic_new_stack(basic s);
104 void basic_free_stack(basic s);
105 
106 // Use these two functions to allocate and free 'basic' on a heap. The pointer
107 // can then be used in all the other methods below (i.e. the methods that
108 // accept 'basic s' work no matter if 's' is stack or heap allocated).
109 basic_struct *basic_new_heap(void);
110 void basic_free_heap(basic_struct *s);
111 
112 const char *symengine_version(void);
113 
115 
120 void basic_const_set(basic s, const char *c);
121 
122 void basic_const_zero(basic s);
123 void basic_const_one(basic s);
124 void basic_const_minus_one(basic s);
125 void basic_const_I(basic s);
126 
127 void basic_const_pi(basic s);
128 void basic_const_E(basic s);
129 void basic_const_EulerGamma(basic s);
130 void basic_const_Catalan(basic s);
131 void basic_const_GoldenRatio(basic s);
132 
135 void basic_const_infinity(basic s);
136 void basic_const_neginfinity(basic s);
137 void basic_const_complex_infinity(basic s);
138 
140 void basic_const_nan(basic s);
141 
143 CWRAPPER_OUTPUT_TYPE basic_assign(basic a, const basic b);
144 
146 CWRAPPER_OUTPUT_TYPE basic_parse(basic b, const char *str);
149 CWRAPPER_OUTPUT_TYPE basic_parse2(basic b, const char *str, int convert_xor);
150 
152 TypeID basic_get_type(const basic s);
154 TypeID basic_get_class_id(const char *c);
157 char *basic_get_class_from_id(TypeID id);
158 
162 CWRAPPER_OUTPUT_TYPE symbol_set(basic s, const char *c);
163 
165 int number_is_zero(const basic s);
167 int number_is_negative(const basic s);
169 int number_is_positive(const basic s);
171 int number_is_complex(const basic s);
172 
174 int basic_has_symbol(const basic e, const basic s);
175 
177 CWRAPPER_OUTPUT_TYPE integer_set_si(basic s, long i);
179 CWRAPPER_OUTPUT_TYPE integer_set_ui(basic s, unsigned long i);
181 #ifdef HAVE_SYMENGINE_GMP
182 CWRAPPER_OUTPUT_TYPE integer_set_mpz(basic s, const mpz_t i);
183 #endif
185 CWRAPPER_OUTPUT_TYPE integer_set_str(basic s, const char *c);
187 CWRAPPER_OUTPUT_TYPE real_double_set_d(basic s, double d);
189 double real_double_get_d(const basic s);
190 
191 #ifdef HAVE_SYMENGINE_MPFR
193 CWRAPPER_OUTPUT_TYPE real_mpfr_set_d(basic s, double d, int prec);
196 CWRAPPER_OUTPUT_TYPE real_mpfr_set_str(basic s, const char *c, int prec);
198 double real_mpfr_get_d(const basic s);
200 CWRAPPER_OUTPUT_TYPE real_mpfr_set(basic s, mpfr_srcptr m);
202 CWRAPPER_OUTPUT_TYPE real_mpfr_get(mpfr_ptr m, const basic s);
204 mpfr_prec_t real_mpfr_get_prec(const basic s);
205 #endif // HAVE_SYMENGINE_MPFR
206 
208 CWRAPPER_OUTPUT_TYPE complex_base_real_part(basic s, const basic com);
210 CWRAPPER_OUTPUT_TYPE complex_base_imaginary_part(basic s, const basic com);
211 
213 signed long integer_get_si(const basic s);
215 unsigned long integer_get_ui(const basic s);
217 #ifdef HAVE_SYMENGINE_GMP
218 CWRAPPER_OUTPUT_TYPE integer_get_mpz(mpz_t a, const basic s);
219 #endif
220 
223 CWRAPPER_OUTPUT_TYPE rational_set(basic s, const basic i, const basic j);
225 CWRAPPER_OUTPUT_TYPE rational_set_si(basic s, long i, long j);
227 CWRAPPER_OUTPUT_TYPE rational_set_ui(basic s, unsigned long i, unsigned long j);
228 #ifdef HAVE_SYMENGINE_GMP
230 CWRAPPER_OUTPUT_TYPE rational_get_mpq(mpq_t a, const basic s);
232 CWRAPPER_OUTPUT_TYPE rational_set_mpq(basic s, const mpq_t i);
233 #endif
234 
236 CWRAPPER_OUTPUT_TYPE complex_set(basic s, const basic re, const basic im);
238 CWRAPPER_OUTPUT_TYPE complex_set_rat(basic s, const basic re, const basic im);
239 #ifdef HAVE_SYMENGINE_GMP
241 CWRAPPER_OUTPUT_TYPE complex_set_mpq(basic s, const mpq_t re, const mpq_t im);
242 #endif
243 
246 dcomplex complex_double_get(const basic s);
247 
249 CWRAPPER_OUTPUT_TYPE basic_add(basic s, const basic a, const basic b);
251 CWRAPPER_OUTPUT_TYPE basic_sub(basic s, const basic a, const basic b);
253 CWRAPPER_OUTPUT_TYPE basic_mul(basic s, const basic a, const basic b);
255 CWRAPPER_OUTPUT_TYPE basic_div(basic s, const basic a, const basic b);
257 CWRAPPER_OUTPUT_TYPE basic_pow(basic s, const basic a, const basic b);
260 CWRAPPER_OUTPUT_TYPE basic_diff(basic s, const basic expr, const basic sym);
262 int basic_eq(const basic a, const basic b);
264 int basic_neq(const basic a, const basic b);
265 
267 CWRAPPER_OUTPUT_TYPE basic_expand(basic s, const basic a);
269 CWRAPPER_OUTPUT_TYPE basic_neg(basic s, const basic a);
270 
272 CWRAPPER_OUTPUT_TYPE basic_abs(basic s, const basic a);
273 
275 CWRAPPER_OUTPUT_TYPE basic_erf(basic s, const basic a);
277 CWRAPPER_OUTPUT_TYPE basic_erfc(basic s, const basic a);
278 
280 CWRAPPER_OUTPUT_TYPE basic_sin(basic s, const basic a);
282 CWRAPPER_OUTPUT_TYPE basic_cos(basic s, const basic a);
284 CWRAPPER_OUTPUT_TYPE basic_tan(basic s, const basic a);
285 
287 CWRAPPER_OUTPUT_TYPE basic_asin(basic s, const basic a);
289 CWRAPPER_OUTPUT_TYPE basic_acos(basic s, const basic a);
291 CWRAPPER_OUTPUT_TYPE basic_atan(basic s, const basic a);
292 
294 CWRAPPER_OUTPUT_TYPE basic_csc(basic s, const basic a);
296 CWRAPPER_OUTPUT_TYPE basic_sec(basic s, const basic a);
298 CWRAPPER_OUTPUT_TYPE basic_cot(basic s, const basic a);
299 
301 CWRAPPER_OUTPUT_TYPE basic_acsc(basic s, const basic a);
303 CWRAPPER_OUTPUT_TYPE basic_asec(basic s, const basic a);
305 CWRAPPER_OUTPUT_TYPE basic_acot(basic s, const basic a);
306 
308 CWRAPPER_OUTPUT_TYPE basic_sinh(basic s, const basic a);
310 CWRAPPER_OUTPUT_TYPE basic_cosh(basic s, const basic a);
312 CWRAPPER_OUTPUT_TYPE basic_tanh(basic s, const basic a);
313 
315 CWRAPPER_OUTPUT_TYPE basic_asinh(basic s, const basic a);
317 CWRAPPER_OUTPUT_TYPE basic_acosh(basic s, const basic a);
319 CWRAPPER_OUTPUT_TYPE basic_atanh(basic s, const basic a);
320 
322 CWRAPPER_OUTPUT_TYPE basic_csch(basic s, const basic a);
324 CWRAPPER_OUTPUT_TYPE basic_sech(basic s, const basic a);
326 CWRAPPER_OUTPUT_TYPE basic_coth(basic s, const basic a);
327 
329 CWRAPPER_OUTPUT_TYPE basic_acsch(basic s, const basic a);
331 CWRAPPER_OUTPUT_TYPE basic_asech(basic s, const basic a);
333 CWRAPPER_OUTPUT_TYPE basic_acoth(basic s, const basic a);
334 
336 CWRAPPER_OUTPUT_TYPE basic_lambertw(basic s, const basic a);
338 CWRAPPER_OUTPUT_TYPE basic_zeta(basic s, const basic a);
340 CWRAPPER_OUTPUT_TYPE basic_dirichlet_eta(basic s, const basic a);
342 CWRAPPER_OUTPUT_TYPE basic_gamma(basic s, const basic a);
344 CWRAPPER_OUTPUT_TYPE basic_loggamma(basic s, const basic a);
346 CWRAPPER_OUTPUT_TYPE basic_sqrt(basic s, const basic a);
348 CWRAPPER_OUTPUT_TYPE basic_cbrt(basic s, const basic a);
350 CWRAPPER_OUTPUT_TYPE basic_exp(basic s, const basic a);
352 CWRAPPER_OUTPUT_TYPE basic_log(basic s, const basic a);
354 CWRAPPER_OUTPUT_TYPE basic_floor(basic s, const basic a);
356 CWRAPPER_OUTPUT_TYPE basic_ceiling(basic s, const basic a);
358 CWRAPPER_OUTPUT_TYPE basic_sign(basic s, const basic a);
359 
361 CWRAPPER_OUTPUT_TYPE basic_atan2(basic s, const basic a, const basic b);
363 CWRAPPER_OUTPUT_TYPE basic_kronecker_delta(basic s, const basic a,
364  const basic b);
366 CWRAPPER_OUTPUT_TYPE basic_lowergamma(basic s, const basic a, const basic b);
368 CWRAPPER_OUTPUT_TYPE basic_uppergamma(basic s, const basic a, const basic b);
370 CWRAPPER_OUTPUT_TYPE basic_beta(basic s, const basic a, const basic b);
372 CWRAPPER_OUTPUT_TYPE basic_polygamma(basic s, const basic a, const basic b);
373 
375 char *basic_dumps(const basic s, unsigned long *size);
377 CWRAPPER_OUTPUT_TYPE basic_loads(basic s, const char *c, unsigned long size);
378 
380 char *basic_str(const basic s);
383 char *basic_str_julia(const basic s);
385 char *basic_str_mathml(const basic s);
387 char *basic_str_latex(const basic s);
389 char *basic_str_ccode(const basic s);
391 char *basic_str_jscode(const basic s);
393 void basic_str_free(char *s);
394 
396 void bool_set_true(basic s);
398 void bool_set_false(basic s);
399 
401 void basic_set_emptyset(basic s);
403 void basic_set_universalset(basic s);
405 void basic_set_complexes(basic s);
407 void basic_set_reals(basic s);
409 void basic_set_rationals(basic s);
411 void basic_set_integers(basic s);
413 CWRAPPER_OUTPUT_TYPE basic_set_interval(basic s, const basic start,
414  const basic end, int left_open,
415  int right_open);
417 CWRAPPER_OUTPUT_TYPE basic_set_finiteset(basic s, const CSetBasic *container);
419 CWRAPPER_OUTPUT_TYPE basic_set_union(basic s, const basic a, const basic b);
421 CWRAPPER_OUTPUT_TYPE basic_set_intersection(basic s, const basic a,
422  const basic b);
424 CWRAPPER_OUTPUT_TYPE basic_set_complement(basic s, const basic a,
425  const basic b);
427 CWRAPPER_OUTPUT_TYPE basic_set_contains(basic s, const basic a, const basic b);
429 int basic_set_is_subset(const basic a, const basic b);
431 int basic_set_is_proper_subset(const basic a, const basic b);
433 int basic_set_is_superset(const basic a, const basic b);
435 int basic_set_is_proper_superset(const basic a, const basic b);
437 CWRAPPER_OUTPUT_TYPE basic_set_inf(basic s, const basic a);
439 CWRAPPER_OUTPUT_TYPE basic_set_sup(basic s, const basic a);
441 CWRAPPER_OUTPUT_TYPE basic_set_boundary(basic s, const basic a);
443 CWRAPPER_OUTPUT_TYPE basic_set_interior(basic s, const basic a);
445 CWRAPPER_OUTPUT_TYPE basic_set_closure(basic s, const basic a);
446 
456 int symengine_have_component(const char *c);
457 
459 int is_a_Number(const basic s);
461 int is_a_Integer(const basic s);
463 int is_a_Rational(const basic s);
465 int is_a_Symbol(const basic s);
467 int is_a_Complex(const basic s);
469 int is_a_RealDouble(const basic c);
471 int is_a_ComplexDouble(const basic c);
473 int is_a_RealMPFR(const basic c);
475 int is_a_ComplexMPC(const basic c);
477 int is_a_Set(const basic c);
478 
480 
481 typedef struct CVectorInt CVectorInt;
482 
483 CVectorInt *vectorint_new(void);
484 
485 // 'data' must point to allocated memory of size 'size'. The function returns 0
486 // if std::vector<int> can be initialized using placement new into 'data',
487 // otherwise 1 if 'size' is too small or 2 if 'data' is not properly aligned.
488 // No memory is leaked either way. Use vectorint_placement_new_check() to check
489 // that the 'data' and 'size' is properly allocated and aligned. Use
490 // vectorint_placement_new() to do the actual allocation.
491 int vectorint_placement_new_check(void *data, size_t size);
492 CVectorInt *vectorint_placement_new(void *data);
493 
494 void vectorint_placement_free(CVectorInt *self);
495 
496 void vectorint_free(CVectorInt *self);
497 void vectorint_push_back(CVectorInt *self, int value);
498 int vectorint_get(CVectorInt *self, int n);
499 
501 
502 typedef struct CVecBasic CVecBasic;
503 
504 CVecBasic *vecbasic_new(void);
505 void vecbasic_free(CVecBasic *self);
506 CWRAPPER_OUTPUT_TYPE vecbasic_push_back(CVecBasic *self, const basic value);
507 CWRAPPER_OUTPUT_TYPE vecbasic_get(CVecBasic *self, size_t n, basic result);
508 CWRAPPER_OUTPUT_TYPE vecbasic_set(CVecBasic *self, size_t n, const basic s);
509 CWRAPPER_OUTPUT_TYPE vecbasic_erase(CVecBasic *self, size_t n);
510 size_t vecbasic_size(CVecBasic *self);
511 
513 CWRAPPER_OUTPUT_TYPE basic_max(basic s, const CVecBasic *d);
515 CWRAPPER_OUTPUT_TYPE basic_min(basic s, const CVecBasic *d);
517 CWRAPPER_OUTPUT_TYPE basic_add_vec(basic s, const CVecBasic *d);
518 
520 CWRAPPER_OUTPUT_TYPE basic_mul_vec(basic s, const CVecBasic *d);
521 
523 
524 typedef struct CDenseMatrix CDenseMatrix;
525 typedef struct CSparseMatrix CSparseMatrix;
526 
527 CDenseMatrix *dense_matrix_new(void);
528 CSparseMatrix *sparse_matrix_new(void);
529 
530 void dense_matrix_free(CDenseMatrix *self);
532 CDenseMatrix *dense_matrix_new_vec(unsigned rows, unsigned cols, CVecBasic *l);
534 CDenseMatrix *dense_matrix_new_rows_cols(unsigned r, unsigned c);
535 
536 void sparse_matrix_free(CSparseMatrix *self);
537 
539 CWRAPPER_OUTPUT_TYPE dense_matrix_set(CDenseMatrix *s, const CDenseMatrix *d);
540 
543 char *dense_matrix_str(const CDenseMatrix *s);
545 CWRAPPER_OUTPUT_TYPE dense_matrix_rows_cols(CDenseMatrix *mat, unsigned r,
546  unsigned c);
548 CWRAPPER_OUTPUT_TYPE dense_matrix_get_basic(basic s, const CDenseMatrix *mat,
549  unsigned long int r,
550  unsigned long int c);
552 CWRAPPER_OUTPUT_TYPE dense_matrix_set_basic(CDenseMatrix *mat,
553  unsigned long int r,
554  unsigned long int c, basic s);
556 CWRAPPER_OUTPUT_TYPE sparse_matrix_get_basic(basic s, const CSparseMatrix *mat,
557  unsigned long int r,
558  unsigned long int c);
560 CWRAPPER_OUTPUT_TYPE sparse_matrix_set_basic(CSparseMatrix *mat,
561  unsigned long int r,
562  unsigned long int c, basic s);
564 CWRAPPER_OUTPUT_TYPE dense_matrix_det(basic s, const CDenseMatrix *mat);
566 CWRAPPER_OUTPUT_TYPE dense_matrix_inv(CDenseMatrix *s, const CDenseMatrix *mat);
568 CWRAPPER_OUTPUT_TYPE dense_matrix_transpose(CDenseMatrix *s,
569  const CDenseMatrix *mat);
572 CWRAPPER_OUTPUT_TYPE
573 dense_matrix_submatrix(CDenseMatrix *s, const CDenseMatrix *mat,
574  unsigned long int r1, unsigned long int c1,
575  unsigned long int r2, unsigned long int c2,
576  unsigned long int r, unsigned long int c);
578 CWRAPPER_OUTPUT_TYPE dense_matrix_row_join(CDenseMatrix *A,
579  const CDenseMatrix *B);
581 CWRAPPER_OUTPUT_TYPE dense_matrix_col_join(CDenseMatrix *A,
582  const CDenseMatrix *B);
584 CWRAPPER_OUTPUT_TYPE dense_matrix_row_del(CDenseMatrix *C, unsigned k);
586 CWRAPPER_OUTPUT_TYPE dense_matrix_col_del(CDenseMatrix *C, unsigned k);
587 
589 unsigned long int dense_matrix_cols(const CDenseMatrix *s);
591 unsigned long int dense_matrix_rows(const CDenseMatrix *s);
593 CWRAPPER_OUTPUT_TYPE dense_matrix_add_matrix(CDenseMatrix *s,
594  const CDenseMatrix *matA,
595  const CDenseMatrix *matB);
597 CWRAPPER_OUTPUT_TYPE dense_matrix_mul_matrix(CDenseMatrix *s,
598  const CDenseMatrix *matA,
599  const CDenseMatrix *matB);
601 CWRAPPER_OUTPUT_TYPE dense_matrix_add_scalar(CDenseMatrix *s,
602  const CDenseMatrix *matA,
603  const basic b);
605 CWRAPPER_OUTPUT_TYPE dense_matrix_mul_scalar(CDenseMatrix *s,
606  const CDenseMatrix *matA,
607  const basic b);
609 CWRAPPER_OUTPUT_TYPE dense_matrix_LU(CDenseMatrix *l, CDenseMatrix *u,
610  const CDenseMatrix *mat);
612 CWRAPPER_OUTPUT_TYPE dense_matrix_LDL(CDenseMatrix *l, CDenseMatrix *d,
613  const CDenseMatrix *mat);
615 CWRAPPER_OUTPUT_TYPE dense_matrix_FFLU(CDenseMatrix *lu,
616  const CDenseMatrix *mat);
618 CWRAPPER_OUTPUT_TYPE dense_matrix_FFLDU(CDenseMatrix *l, CDenseMatrix *d,
619  CDenseMatrix *u,
620  const CDenseMatrix *mat);
622 CWRAPPER_OUTPUT_TYPE dense_matrix_LU_solve(CDenseMatrix *x,
623  const CDenseMatrix *A,
624  const CDenseMatrix *b);
626 CWRAPPER_OUTPUT_TYPE dense_matrix_ones(CDenseMatrix *s, unsigned long int r,
627  unsigned long int c);
629 CWRAPPER_OUTPUT_TYPE dense_matrix_zeros(CDenseMatrix *s, unsigned long int r,
630  unsigned long int c);
633 CWRAPPER_OUTPUT_TYPE dense_matrix_diag(CDenseMatrix *s, CVecBasic *d,
634  long int k);
636 CWRAPPER_OUTPUT_TYPE dense_matrix_eye(CDenseMatrix *s, unsigned long int N,
637  unsigned long int M, int k);
640 CWRAPPER_OUTPUT_TYPE dense_matrix_diff(CDenseMatrix *result,
641  const CDenseMatrix *A, basic const x);
643 CWRAPPER_OUTPUT_TYPE dense_matrix_jacobian(CDenseMatrix *result,
644  const CDenseMatrix *A,
645  const CDenseMatrix *x);
646 
648 void sparse_matrix_init(CSparseMatrix *s);
650 void sparse_matrix_rows_cols(CSparseMatrix *s, unsigned long int r,
651  unsigned long int c);
653 char *sparse_matrix_str(const CSparseMatrix *s);
654 
656 int is_a_DenseMatrix(const CDenseMatrix *c);
658 int is_a_SparseMatrix(const CSparseMatrix *c);
659 
661 int dense_matrix_eq(CDenseMatrix *lhs, CDenseMatrix *rhs);
663 int sparse_matrix_eq(CSparseMatrix *lhs, CSparseMatrix *rhs);
664 
666 
667 CSetBasic *setbasic_new(void);
668 void setbasic_free(CSetBasic *self);
671 int setbasic_insert(CSetBasic *self, const basic value);
672 void setbasic_get(CSetBasic *self, int n, basic result);
674 int setbasic_find(CSetBasic *self, basic value);
676 int setbasic_erase(CSetBasic *self, const basic value);
677 size_t setbasic_size(CSetBasic *self);
678 
680 
681 typedef struct CMapBasicBasic CMapBasicBasic;
682 
683 CMapBasicBasic *mapbasicbasic_new(void);
684 void mapbasicbasic_free(CMapBasicBasic *self);
685 void mapbasicbasic_insert(CMapBasicBasic *self, const basic key,
686  const basic mapped);
688 int mapbasicbasic_get(CMapBasicBasic *self, const basic key, basic mapped);
689 size_t mapbasicbasic_size(CMapBasicBasic *self);
690 
691 // -------------------------------------
692 
694 CWRAPPER_OUTPUT_TYPE basic_get_args(const basic self, CVecBasic *args);
696 CWRAPPER_OUTPUT_TYPE basic_free_symbols(const basic self, CSetBasic *symbols);
698 CWRAPPER_OUTPUT_TYPE basic_function_symbols(CSetBasic *symbols,
699  const basic self);
701 size_t basic_hash(const basic self);
704 CWRAPPER_OUTPUT_TYPE basic_subs(basic s, const basic e,
705  const CMapBasicBasic *mapbb);
708 CWRAPPER_OUTPUT_TYPE basic_subs2(basic s, const basic e, const basic a,
709  const basic b);
710 
713 CWRAPPER_OUTPUT_TYPE function_symbol_set(basic s, const char *c,
714  const CVecBasic *arg);
717 char *function_symbol_get_name(const basic b);
719 CWRAPPER_OUTPUT_TYPE basic_coeff(basic c, const basic b, const basic x,
720  const basic n);
721 
723 
725 CWRAPPER_OUTPUT_TYPE vecbasic_linsolve(CVecBasic *sol, const CVecBasic *sys,
726  const CVecBasic *sym);
728 CWRAPPER_OUTPUT_TYPE basic_solve_poly(CSetBasic *r, const basic f,
729  const basic s);
730 
732 
735 char *ascii_art_str(void);
736 
739 CWRAPPER_OUTPUT_TYPE ntheory_gcd(basic s, const basic a, const basic b);
741 CWRAPPER_OUTPUT_TYPE ntheory_lcm(basic s, const basic a, const basic b);
743 CWRAPPER_OUTPUT_TYPE ntheory_gcd_ext(basic g, basic s, basic t, const basic a,
744  const basic b);
746 CWRAPPER_OUTPUT_TYPE ntheory_nextprime(basic s, const basic a);
748 CWRAPPER_OUTPUT_TYPE ntheory_mod(basic s, const basic n, const basic d);
750 CWRAPPER_OUTPUT_TYPE ntheory_quotient(basic s, const basic n, const basic d);
752 CWRAPPER_OUTPUT_TYPE ntheory_quotient_mod(basic q, basic r, const basic n,
753  const basic d);
755 CWRAPPER_OUTPUT_TYPE ntheory_mod_f(basic s, const basic n, const basic d);
757 CWRAPPER_OUTPUT_TYPE ntheory_quotient_f(basic s, const basic n, const basic d);
759 CWRAPPER_OUTPUT_TYPE ntheory_quotient_mod_f(basic q, basic r, const basic n,
760  const basic d);
762 int ntheory_mod_inverse(basic b, const basic a, const basic m);
764 CWRAPPER_OUTPUT_TYPE ntheory_fibonacci(basic s, unsigned long a);
766 CWRAPPER_OUTPUT_TYPE ntheory_fibonacci2(basic g, basic s, unsigned long a);
768 CWRAPPER_OUTPUT_TYPE ntheory_lucas(basic s, unsigned long a);
770 CWRAPPER_OUTPUT_TYPE ntheory_lucas2(basic g, basic s, unsigned long a);
772 CWRAPPER_OUTPUT_TYPE ntheory_binomial(basic s, const basic a, unsigned long b);
774 CWRAPPER_OUTPUT_TYPE ntheory_factorial(basic s, unsigned long n);
776 CWRAPPER_OUTPUT_TYPE basic_evalf(basic s, const basic b, unsigned long bits,
777  int real);
778 
780 CWRAPPER_OUTPUT_TYPE basic_as_numer_denom(basic numer, basic denom,
781  const basic x);
783 CWRAPPER_OUTPUT_TYPE basic_add_as_two_terms(basic term1, basic term2,
784  const basic s);
786 CWRAPPER_OUTPUT_TYPE basic_mul_as_two_terms(basic term1, basic term2,
787  const basic s);
788 
791 CLambdaRealDoubleVisitor *lambda_real_double_visitor_new(void);
792 void lambda_real_double_visitor_init(CLambdaRealDoubleVisitor *self,
793  const CVecBasic *args,
794  const CVecBasic *exprs, int perform_cse);
795 void lambda_real_double_visitor_call(CLambdaRealDoubleVisitor *self,
796  double *const outs,
797  const double *const inps);
798 void lambda_real_double_visitor_free(CLambdaRealDoubleVisitor *self);
799 
801 #ifdef HAVE_SYMENGINE_LLVM
802 // double
803 typedef struct CLLVMDoubleVisitor CLLVMDoubleVisitor;
804 CLLVMDoubleVisitor *llvm_double_visitor_new(void);
805 void llvm_double_visitor_init(CLLVMDoubleVisitor *self, const CVecBasic *args,
806  const CVecBasic *exprs, int perform_cse,
807  int opt_level);
808 void llvm_double_visitor_call(CLLVMDoubleVisitor *self, double *const outs,
809  const double *const inps);
810 void llvm_double_visitor_free(CLLVMDoubleVisitor *self);
811 // float
812 typedef struct CLLVMFloatVisitor CLLVMFloatVisitor;
813 CLLVMFloatVisitor *llvm_float_visitor_new(void);
814 void llvm_float_visitor_init(CLLVMFloatVisitor *self, const CVecBasic *args,
815  const CVecBasic *exprs, int perform_cse,
816  int opt_level);
817 void llvm_float_visitor_call(CLLVMFloatVisitor *self, float *const outs,
818  const float *const inps);
819 void llvm_float_visitor_free(CLLVMFloatVisitor *self);
820 
821 #ifdef SYMENGINE_HAVE_LLVM_LONG_DOUBLE
822 // long double
823 typedef struct CLLVMLongDoubleVisitor CLLVMLongDoubleVisitor;
824 CLLVMLongDoubleVisitor *llvm_long_double_visitor_new(void);
825 void llvm_long_double_visitor_init(CLLVMLongDoubleVisitor *self,
826  const CVecBasic *args,
827  const CVecBasic *exprs, int perform_cse,
828  int opt_level);
829 void llvm_long_double_visitor_call(CLLVMLongDoubleVisitor *self,
830  long double *const outs,
831  const long double *const inps);
832 void llvm_long_double_visitor_free(CLLVMLongDoubleVisitor *self);
833 #endif
834 #endif
835 
836 CWRAPPER_OUTPUT_TYPE basic_cse(CVecBasic *replacement_syms,
837  CVecBasic *replacement_exprs,
838  CVecBasic *reduced_exprs,
839  const CVecBasic *exprs);
840 
842 void symengine_print_stack_on_segfault(void);
843 
844 #ifdef __cplusplus
845 }
846 #endif
847 #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
Code