cwrapper.h
1 #ifndef CWRAPPER_H
2 #define CWRAPPER_H
3 
4 #include <stdint.h>
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include "symengine/symengine_config.h"
8 
9 #ifdef HAVE_SYMENGINE_GMP
10 #include <gmp.h>
11 #endif
12 
13 #ifdef HAVE_SYMENGINE_MPFR
14 #include <mpfr.h>
15 #endif // HAVE_SYMENGINE_MPFR
16 
17 #include "symengine/symengine_exception.h"
18 
19 #ifdef __cplusplus
20 extern "C" {
21 #endif
22 
23 // Use SYMENGINE_C_ASSERT in C tests
24 #define SYMENGINE_C_ASSERT(cond) \
25  { \
26  if (0 == (cond)) { \
27  printf("SYMENGINE_C_ASSERT failed: %s \nfunction %s (), line " \
28  "number %d at\n%s\n", \
29  __FILE__, __func__, __LINE__, #cond); \
30  abort(); \
31  } \
32  }
33 
34 typedef symengine_exceptions_t CWRAPPER_OUTPUT_TYPE;
35 
37 typedef enum {
38  SYMENGINE_DOUBLE = 0,
39  SYMENGINE_FLOAT = 1,
40  SYMENGINE_HALF = 2,
41 } BasicCodePrinterPrecision;
44 
45 typedef enum {
46 #define SYMENGINE_INCLUDE_ALL
47 #define SYMENGINE_ENUM(type, Class) type,
48 #include "symengine/type_codes.inc"
49 #undef SYMENGINE_ENUM
50 #undef SYMENGINE_INCLUDE_ALL
51  SYMENGINE_TypeID_Count
52 } TypeID;
53 
56 typedef struct dcomplex {
57  double real;
58  double imag;
59 } dcomplex;
60 
61 // The size of 'CRCPBasic_C' must be the same as CRCPBasic (which contains a
62 // single RCP<const Basic> member) *and* they must have the same alignment
63 // (because we allocate CRCPBasic into the memory occupied by this struct in
64 // cwrapper.cpp). We cannot use C++ in this file, so we need to use C tools to
65 // arrive at the correct size and alignment. The size of the RCP object on
66 // most platforms (with WITH_SYMENGINE_RCP on) should be just the size of the
67 // 'T *ptr_' pointer that it contains (as there is no virtual function table)
68 // and the alignment should also be of a pointer. So we just put 'void *data'
69 // as the only member of the struct, that should have the correct size and
70 // alignment. With WITH_SYMENGINE_RCP off (i.e. using Teuchos::RCP), we have to
71 // add additional members into the structure.
72 //
73 // However, this is checked at compile time in cwrapper.cpp, so if the size or
74 // alignment is different on some platform, the compilation will fail --- in
75 // that case one needs to modify the contents of this struct to adjust its size
76 // and/or alignment.
77 struct CRCPBasic_C {
78  void *data;
79 #if !defined(WITH_SYMENGINE_RCP)
80  void *teuchos_handle;
81  int teuchos_strength;
82 #endif
83 };
84 
86 // CRCPBasic, which has the same size and alignment as RCP<const Basic> (see
87 // the above comment for details). That is then used by the user to allocate
88 // the memory needed for RCP<const Basic> on the stack. A 'basic' type should
89 // be initialized using basic_new_stack(), before any function is called.
90 // Assignment should be done only by using basic_assign(). Before the variable
91 // goes out of scope, basic_free_stack() must be called.
92 //
93 // For downstream projects, define a dummy struct with the right size, so
94 // that it can be allocated on the stack. When building the library in
95 // cwrapper.cpp, the CRCPBasic is declared in cwrapper.cpp which removes
96 // the need to cast the C struct to C++ struct every time.
97 #ifdef symengine_EXPORTS
98 typedef struct CRCPBasic basic_struct;
99 #else
100 typedef struct CRCPBasic_C basic_struct;
101 #endif
102 
103 typedef struct CSetBasic CSetBasic;
104 
107 typedef basic_struct basic[1];
108 
110 // 'basic' type, this function initializes an RCP<const Basic> on the stack
111 // allocated variable. The 's' variable must be freed using basic_free_stack()
112 void basic_new_stack(basic s);
114 void basic_free_stack(basic s);
115 
116 // Use these two functions to allocate and free 'basic' on a heap. The pointer
117 // can then be used in all the other methods below (i.e. the methods that
118 // accept 'basic s' work no matter if 's' is stack or heap allocated).
119 basic_struct *basic_new_heap(void);
120 void basic_free_heap(basic_struct *s);
121 
122 const char *symengine_version(void);
123 
125 
130 void basic_const_set(basic s, const char *c);
131 
132 void basic_const_zero(basic s);
133 void basic_const_one(basic s);
134 void basic_const_minus_one(basic s);
135 void basic_const_I(basic s);
136 
137 void basic_const_pi(basic s);
138 void basic_const_E(basic s);
139 void basic_const_EulerGamma(basic s);
140 void basic_const_Catalan(basic s);
141 void basic_const_GoldenRatio(basic s);
142 
145 void basic_const_infinity(basic s);
146 void basic_const_neginfinity(basic s);
147 void basic_const_complex_infinity(basic s);
148 
150 void basic_const_nan(basic s);
151 
153 CWRAPPER_OUTPUT_TYPE basic_assign(basic a, const basic b);
154 
156 CWRAPPER_OUTPUT_TYPE basic_parse(basic b, const char *str);
159 CWRAPPER_OUTPUT_TYPE basic_parse2(basic b, const char *str, int convert_xor);
160 
162 TypeID basic_get_type(const basic s);
164 TypeID basic_get_class_id(const char *c);
167 char *basic_get_class_from_id(TypeID id);
168 
172 CWRAPPER_OUTPUT_TYPE symbol_set(basic s, const char *c);
173 
175 int number_is_zero(const basic s);
177 int number_is_negative(const basic s);
179 int number_is_positive(const basic s);
181 int number_is_complex(const basic s);
182 
184 int basic_has_symbol(const basic e, const basic s);
185 
187 CWRAPPER_OUTPUT_TYPE integer_set_si(basic s, long i);
189 CWRAPPER_OUTPUT_TYPE integer_set_ui(basic s, unsigned long i);
191 #ifdef HAVE_SYMENGINE_GMP
192 CWRAPPER_OUTPUT_TYPE integer_set_mpz(basic s, const mpz_t i);
193 #endif
195 CWRAPPER_OUTPUT_TYPE integer_set_str(basic s, const char *c);
197 CWRAPPER_OUTPUT_TYPE real_double_set_d(basic s, double d);
199 double real_double_get_d(const basic s);
200 
201 #ifdef HAVE_SYMENGINE_MPFR
203 CWRAPPER_OUTPUT_TYPE real_mpfr_set_d(basic s, double d, int prec);
206 CWRAPPER_OUTPUT_TYPE real_mpfr_set_str(basic s, const char *c, int prec);
208 double real_mpfr_get_d(const basic s);
210 CWRAPPER_OUTPUT_TYPE real_mpfr_set(basic s, mpfr_srcptr m);
212 CWRAPPER_OUTPUT_TYPE real_mpfr_get(mpfr_ptr m, const basic s);
214 mpfr_prec_t real_mpfr_get_prec(const basic s);
215 #endif // HAVE_SYMENGINE_MPFR
216 
218 CWRAPPER_OUTPUT_TYPE complex_base_real_part(basic s, const basic com);
220 CWRAPPER_OUTPUT_TYPE complex_base_imaginary_part(basic s, const basic com);
221 
223 signed long integer_get_si(const basic s);
225 unsigned long integer_get_ui(const basic s);
227 #ifdef HAVE_SYMENGINE_GMP
228 CWRAPPER_OUTPUT_TYPE integer_get_mpz(mpz_t a, const basic s);
229 #endif
230 
233 CWRAPPER_OUTPUT_TYPE rational_set(basic s, const basic i, const basic j);
235 CWRAPPER_OUTPUT_TYPE rational_set_si(basic s, long i, long j);
237 CWRAPPER_OUTPUT_TYPE rational_set_ui(basic s, unsigned long i, unsigned long j);
238 #ifdef HAVE_SYMENGINE_GMP
240 CWRAPPER_OUTPUT_TYPE rational_get_mpq(mpq_t a, const basic s);
242 CWRAPPER_OUTPUT_TYPE rational_set_mpq(basic s, const mpq_t i);
243 #endif
244 
246 CWRAPPER_OUTPUT_TYPE complex_set(basic s, const basic re, const basic im);
248 CWRAPPER_OUTPUT_TYPE complex_set_rat(basic s, const basic re, const basic im);
249 #ifdef HAVE_SYMENGINE_GMP
251 CWRAPPER_OUTPUT_TYPE complex_set_mpq(basic s, const mpq_t re, const mpq_t im);
252 #endif
253 
256 dcomplex complex_double_get(const basic s);
257 
259 CWRAPPER_OUTPUT_TYPE basic_add(basic s, const basic a, const basic b);
261 CWRAPPER_OUTPUT_TYPE basic_sub(basic s, const basic a, const basic b);
263 CWRAPPER_OUTPUT_TYPE basic_mul(basic s, const basic a, const basic b);
265 CWRAPPER_OUTPUT_TYPE basic_div(basic s, const basic a, const basic b);
267 CWRAPPER_OUTPUT_TYPE basic_pow(basic s, const basic a, const basic b);
270 CWRAPPER_OUTPUT_TYPE basic_diff(basic s, const basic expr, const basic sym);
272 int basic_eq(const basic a, const basic b);
274 int basic_neq(const basic a, const basic b);
275 
277 CWRAPPER_OUTPUT_TYPE basic_expand(basic s, const basic a);
279 CWRAPPER_OUTPUT_TYPE basic_neg(basic s, const basic a);
280 
282 CWRAPPER_OUTPUT_TYPE basic_abs(basic s, const basic a);
283 
285 CWRAPPER_OUTPUT_TYPE basic_erf(basic s, const basic a);
287 CWRAPPER_OUTPUT_TYPE basic_erfc(basic s, const basic a);
288 
290 CWRAPPER_OUTPUT_TYPE basic_sin(basic s, const basic a);
292 CWRAPPER_OUTPUT_TYPE basic_cos(basic s, const basic a);
294 CWRAPPER_OUTPUT_TYPE basic_tan(basic s, const basic a);
295 
297 CWRAPPER_OUTPUT_TYPE basic_asin(basic s, const basic a);
299 CWRAPPER_OUTPUT_TYPE basic_acos(basic s, const basic a);
301 CWRAPPER_OUTPUT_TYPE basic_atan(basic s, const basic a);
302 
304 CWRAPPER_OUTPUT_TYPE basic_csc(basic s, const basic a);
306 CWRAPPER_OUTPUT_TYPE basic_sec(basic s, const basic a);
308 CWRAPPER_OUTPUT_TYPE basic_cot(basic s, const basic a);
309 
311 CWRAPPER_OUTPUT_TYPE basic_acsc(basic s, const basic a);
313 CWRAPPER_OUTPUT_TYPE basic_asec(basic s, const basic a);
315 CWRAPPER_OUTPUT_TYPE basic_acot(basic s, const basic a);
316 
318 CWRAPPER_OUTPUT_TYPE basic_sinh(basic s, const basic a);
320 CWRAPPER_OUTPUT_TYPE basic_cosh(basic s, const basic a);
322 CWRAPPER_OUTPUT_TYPE basic_tanh(basic s, const basic a);
323 
325 CWRAPPER_OUTPUT_TYPE basic_asinh(basic s, const basic a);
327 CWRAPPER_OUTPUT_TYPE basic_acosh(basic s, const basic a);
329 CWRAPPER_OUTPUT_TYPE basic_atanh(basic s, const basic a);
330 
332 CWRAPPER_OUTPUT_TYPE basic_csch(basic s, const basic a);
334 CWRAPPER_OUTPUT_TYPE basic_sech(basic s, const basic a);
336 CWRAPPER_OUTPUT_TYPE basic_coth(basic s, const basic a);
337 
339 CWRAPPER_OUTPUT_TYPE basic_acsch(basic s, const basic a);
341 CWRAPPER_OUTPUT_TYPE basic_asech(basic s, const basic a);
343 CWRAPPER_OUTPUT_TYPE basic_acoth(basic s, const basic a);
344 
346 CWRAPPER_OUTPUT_TYPE basic_lambertw(basic s, const basic a);
348 CWRAPPER_OUTPUT_TYPE basic_zeta(basic s, const basic a);
350 CWRAPPER_OUTPUT_TYPE basic_dirichlet_eta(basic s, const basic a);
352 CWRAPPER_OUTPUT_TYPE basic_gamma(basic s, const basic a);
354 CWRAPPER_OUTPUT_TYPE basic_loggamma(basic s, const basic a);
356 CWRAPPER_OUTPUT_TYPE basic_sqrt(basic s, const basic a);
358 CWRAPPER_OUTPUT_TYPE basic_cbrt(basic s, const basic a);
360 CWRAPPER_OUTPUT_TYPE basic_exp(basic s, const basic a);
362 CWRAPPER_OUTPUT_TYPE basic_log(basic s, const basic a);
364 CWRAPPER_OUTPUT_TYPE basic_floor(basic s, const basic a);
366 CWRAPPER_OUTPUT_TYPE basic_ceiling(basic s, const basic a);
368 CWRAPPER_OUTPUT_TYPE basic_sign(basic s, const basic a);
369 
371 CWRAPPER_OUTPUT_TYPE basic_atan2(basic s, const basic a, const basic b);
373 CWRAPPER_OUTPUT_TYPE basic_kronecker_delta(basic s, const basic a,
374  const basic b);
376 CWRAPPER_OUTPUT_TYPE basic_lowergamma(basic s, const basic a, const basic b);
378 CWRAPPER_OUTPUT_TYPE basic_uppergamma(basic s, const basic a, const basic b);
380 CWRAPPER_OUTPUT_TYPE basic_beta(basic s, const basic a, const basic b);
382 CWRAPPER_OUTPUT_TYPE basic_polygamma(basic s, const basic a, const basic b);
383 
385 char *basic_dumps(const basic s, unsigned long *size);
387 CWRAPPER_OUTPUT_TYPE basic_loads(basic s, const char *c, unsigned long size);
388 
390 BasicCodePrinterSettings *basic_code_printer_settings_new();
392 void basic_code_printer_settings_free(BasicCodePrinterSettings *self);
394 void basic_code_printer_settings_set_precision(BasicCodePrinterSettings *self,
395  BasicCodePrinterPrecision prec);
396 
398 char *basic_str(const basic s);
401 char *basic_str_julia(const basic s);
403 char *basic_str_mathml(const basic s);
405 char *basic_str_latex(const basic s);
407 char *basic_str_ccode(const basic s);
409 char *basic_str_ccode_settings(const basic s,
410  const BasicCodePrinterSettings *settings);
412 char *basic_str_cudacode(const basic s);
414 char *basic_str_cudacode_settings(const basic s,
415  const BasicCodePrinterSettings *settings);
417 char *basic_str_metalcode(const basic s);
419 char *basic_str_metalcode_settings(const basic s,
420  const BasicCodePrinterSettings *settings);
422 char *basic_str_jscode(const basic s);
424 void basic_str_free(char *s);
425 
427 void bool_set_true(basic s);
429 void bool_set_false(basic s);
430 
432 void basic_set_emptyset(basic s);
434 void basic_set_universalset(basic s);
436 void basic_set_complexes(basic s);
438 void basic_set_reals(basic s);
440 void basic_set_rationals(basic s);
442 void basic_set_integers(basic s);
444 CWRAPPER_OUTPUT_TYPE basic_set_interval(basic s, const basic start,
445  const basic end, int left_open,
446  int right_open);
448 CWRAPPER_OUTPUT_TYPE basic_set_finiteset(basic s, const CSetBasic *container);
450 CWRAPPER_OUTPUT_TYPE basic_set_union(basic s, const basic a, const basic b);
452 CWRAPPER_OUTPUT_TYPE basic_set_intersection(basic s, const basic a,
453  const basic b);
455 CWRAPPER_OUTPUT_TYPE basic_set_complement(basic s, const basic a,
456  const basic b);
458 CWRAPPER_OUTPUT_TYPE basic_set_contains(basic s, const basic a, const basic b);
460 int basic_set_is_subset(const basic a, const basic b);
462 int basic_set_is_proper_subset(const basic a, const basic b);
464 int basic_set_is_superset(const basic a, const basic b);
466 int basic_set_is_proper_superset(const basic a, const basic b);
468 CWRAPPER_OUTPUT_TYPE basic_set_inf(basic s, const basic a);
470 CWRAPPER_OUTPUT_TYPE basic_set_sup(basic s, const basic a);
472 CWRAPPER_OUTPUT_TYPE basic_set_boundary(basic s, const basic a);
474 CWRAPPER_OUTPUT_TYPE basic_set_interior(basic s, const basic a);
476 CWRAPPER_OUTPUT_TYPE basic_set_closure(basic s, const basic a);
477 
487 int symengine_have_component(const char *c);
488 
490 int is_a_Number(const basic s);
492 int is_a_Integer(const basic s);
494 int is_a_Rational(const basic s);
496 int is_a_Symbol(const basic s);
498 int is_a_Complex(const basic s);
500 int is_a_RealDouble(const basic c);
502 int is_a_ComplexDouble(const basic c);
504 int is_a_RealMPFR(const basic c);
506 int is_a_ComplexMPC(const basic c);
508 int is_a_Set(const basic c);
509 
511 
512 typedef struct CVectorInt CVectorInt;
513 
514 CVectorInt *vectorint_new(void);
515 
516 // 'data' must point to allocated memory of size 'size'. The function returns 0
517 // if std::vector<int> can be initialized using placement new into 'data',
518 // otherwise 1 if 'size' is too small or 2 if 'data' is not properly aligned.
519 // No memory is leaked either way. Use vectorint_placement_new_check() to check
520 // that the 'data' and 'size' is properly allocated and aligned. Use
521 // vectorint_placement_new() to do the actual allocation.
522 int vectorint_placement_new_check(void *data, size_t size);
523 CVectorInt *vectorint_placement_new(void *data);
524 
525 void vectorint_placement_free(CVectorInt *self);
526 
527 void vectorint_free(CVectorInt *self);
528 void vectorint_push_back(CVectorInt *self, int value);
529 int vectorint_get(CVectorInt *self, int n);
530 
532 
533 typedef struct CVecBasic CVecBasic;
534 
535 CVecBasic *vecbasic_new(void);
536 void vecbasic_free(CVecBasic *self);
537 CWRAPPER_OUTPUT_TYPE vecbasic_push_back(CVecBasic *self, const basic value);
538 CWRAPPER_OUTPUT_TYPE vecbasic_get(CVecBasic *self, size_t n, basic result);
539 CWRAPPER_OUTPUT_TYPE vecbasic_set(CVecBasic *self, size_t n, const basic s);
540 CWRAPPER_OUTPUT_TYPE vecbasic_erase(CVecBasic *self, size_t n);
541 size_t vecbasic_size(CVecBasic *self);
542 
544 CWRAPPER_OUTPUT_TYPE basic_max(basic s, const CVecBasic *d);
546 CWRAPPER_OUTPUT_TYPE basic_min(basic s, const CVecBasic *d);
548 CWRAPPER_OUTPUT_TYPE basic_add_vec(basic s, const CVecBasic *d);
549 
551 CWRAPPER_OUTPUT_TYPE basic_mul_vec(basic s, const CVecBasic *d);
552 
554 
555 typedef struct CDenseMatrix CDenseMatrix;
556 typedef struct CSparseMatrix CSparseMatrix;
557 
558 CDenseMatrix *dense_matrix_new(void);
559 CSparseMatrix *sparse_matrix_new(void);
560 
561 void dense_matrix_free(CDenseMatrix *self);
563 CDenseMatrix *dense_matrix_new_vec(unsigned rows, unsigned cols, CVecBasic *l);
565 CDenseMatrix *dense_matrix_new_rows_cols(unsigned r, unsigned c);
566 
567 void sparse_matrix_free(CSparseMatrix *self);
568 
570 CWRAPPER_OUTPUT_TYPE dense_matrix_set(CDenseMatrix *s, const CDenseMatrix *d);
571 
574 char *dense_matrix_str(const CDenseMatrix *s);
576 CWRAPPER_OUTPUT_TYPE dense_matrix_rows_cols(CDenseMatrix *mat, unsigned r,
577  unsigned c);
579 CWRAPPER_OUTPUT_TYPE dense_matrix_get_basic(basic s, const CDenseMatrix *mat,
580  unsigned long int r,
581  unsigned long int c);
583 CWRAPPER_OUTPUT_TYPE dense_matrix_set_basic(CDenseMatrix *mat,
584  unsigned long int r,
585  unsigned long int c, basic s);
587 CWRAPPER_OUTPUT_TYPE sparse_matrix_get_basic(basic s, const CSparseMatrix *mat,
588  unsigned long int r,
589  unsigned long int c);
591 CWRAPPER_OUTPUT_TYPE sparse_matrix_set_basic(CSparseMatrix *mat,
592  unsigned long int r,
593  unsigned long int c, basic s);
595 CWRAPPER_OUTPUT_TYPE dense_matrix_det(basic s, const CDenseMatrix *mat);
597 CWRAPPER_OUTPUT_TYPE dense_matrix_inv(CDenseMatrix *s, const CDenseMatrix *mat);
599 CWRAPPER_OUTPUT_TYPE dense_matrix_transpose(CDenseMatrix *s,
600  const CDenseMatrix *mat);
603 CWRAPPER_OUTPUT_TYPE
604 dense_matrix_submatrix(CDenseMatrix *s, const CDenseMatrix *mat,
605  unsigned long int r1, unsigned long int c1,
606  unsigned long int r2, unsigned long int c2,
607  unsigned long int r, unsigned long int c);
609 CWRAPPER_OUTPUT_TYPE dense_matrix_row_join(CDenseMatrix *A,
610  const CDenseMatrix *B);
612 CWRAPPER_OUTPUT_TYPE dense_matrix_col_join(CDenseMatrix *A,
613  const CDenseMatrix *B);
615 CWRAPPER_OUTPUT_TYPE dense_matrix_row_del(CDenseMatrix *C, unsigned k);
617 CWRAPPER_OUTPUT_TYPE dense_matrix_col_del(CDenseMatrix *C, unsigned k);
618 
620 unsigned long int dense_matrix_cols(const CDenseMatrix *s);
622 unsigned long int dense_matrix_rows(const CDenseMatrix *s);
624 CWRAPPER_OUTPUT_TYPE dense_matrix_add_matrix(CDenseMatrix *s,
625  const CDenseMatrix *matA,
626  const CDenseMatrix *matB);
628 CWRAPPER_OUTPUT_TYPE dense_matrix_mul_matrix(CDenseMatrix *s,
629  const CDenseMatrix *matA,
630  const CDenseMatrix *matB);
632 CWRAPPER_OUTPUT_TYPE dense_matrix_add_scalar(CDenseMatrix *s,
633  const CDenseMatrix *matA,
634  const basic b);
636 CWRAPPER_OUTPUT_TYPE dense_matrix_mul_scalar(CDenseMatrix *s,
637  const CDenseMatrix *matA,
638  const basic b);
640 CWRAPPER_OUTPUT_TYPE dense_matrix_LU(CDenseMatrix *l, CDenseMatrix *u,
641  const CDenseMatrix *mat);
643 CWRAPPER_OUTPUT_TYPE dense_matrix_LDL(CDenseMatrix *l, CDenseMatrix *d,
644  const CDenseMatrix *mat);
646 CWRAPPER_OUTPUT_TYPE dense_matrix_FFLU(CDenseMatrix *lu,
647  const CDenseMatrix *mat);
649 CWRAPPER_OUTPUT_TYPE dense_matrix_FFLDU(CDenseMatrix *l, CDenseMatrix *d,
650  CDenseMatrix *u,
651  const CDenseMatrix *mat);
653 CWRAPPER_OUTPUT_TYPE dense_matrix_LU_solve(CDenseMatrix *x,
654  const CDenseMatrix *A,
655  const CDenseMatrix *b);
657 CWRAPPER_OUTPUT_TYPE dense_matrix_ones(CDenseMatrix *s, unsigned long int r,
658  unsigned long int c);
660 CWRAPPER_OUTPUT_TYPE dense_matrix_zeros(CDenseMatrix *s, unsigned long int r,
661  unsigned long int c);
664 CWRAPPER_OUTPUT_TYPE dense_matrix_diag(CDenseMatrix *s, CVecBasic *d,
665  long int k);
667 CWRAPPER_OUTPUT_TYPE dense_matrix_eye(CDenseMatrix *s, unsigned long int N,
668  unsigned long int M, int k);
671 CWRAPPER_OUTPUT_TYPE dense_matrix_diff(CDenseMatrix *result,
672  const CDenseMatrix *A, basic const x);
674 CWRAPPER_OUTPUT_TYPE dense_matrix_jacobian(CDenseMatrix *result,
675  const CDenseMatrix *A,
676  const CDenseMatrix *x);
677 
679 void sparse_matrix_init(CSparseMatrix *s);
681 void sparse_matrix_rows_cols(CSparseMatrix *s, unsigned long int r,
682  unsigned long int c);
684 char *sparse_matrix_str(const CSparseMatrix *s);
685 
687 int is_a_DenseMatrix(const CDenseMatrix *c);
689 int is_a_SparseMatrix(const CSparseMatrix *c);
690 
692 int dense_matrix_eq(CDenseMatrix *lhs, CDenseMatrix *rhs);
694 int sparse_matrix_eq(CSparseMatrix *lhs, CSparseMatrix *rhs);
695 
697 
698 CSetBasic *setbasic_new(void);
699 void setbasic_free(CSetBasic *self);
702 int setbasic_insert(CSetBasic *self, const basic value);
703 void setbasic_get(CSetBasic *self, int n, basic result);
705 int setbasic_find(CSetBasic *self, basic value);
707 int setbasic_erase(CSetBasic *self, const basic value);
708 size_t setbasic_size(CSetBasic *self);
709 
711 
712 typedef struct CMapBasicBasic CMapBasicBasic;
713 
714 CMapBasicBasic *mapbasicbasic_new(void);
715 void mapbasicbasic_free(CMapBasicBasic *self);
716 void mapbasicbasic_insert(CMapBasicBasic *self, const basic key,
717  const basic mapped);
719 int mapbasicbasic_get(CMapBasicBasic *self, const basic key, basic mapped);
720 size_t mapbasicbasic_size(CMapBasicBasic *self);
721 
722 // -------------------------------------
723 
725 CWRAPPER_OUTPUT_TYPE basic_get_args(const basic self, CVecBasic *args);
727 CWRAPPER_OUTPUT_TYPE basic_free_symbols(const basic self, CSetBasic *symbols);
729 CWRAPPER_OUTPUT_TYPE basic_function_symbols(CSetBasic *symbols,
730  const basic self);
732 size_t basic_hash(const basic self);
735 CWRAPPER_OUTPUT_TYPE basic_subs(basic s, const basic e,
736  const CMapBasicBasic *mapbb);
739 CWRAPPER_OUTPUT_TYPE basic_subs2(basic s, const basic e, const basic a,
740  const basic b);
741 
744 CWRAPPER_OUTPUT_TYPE function_symbol_set(basic s, const char *c,
745  const CVecBasic *arg);
748 char *function_symbol_get_name(const basic b);
750 CWRAPPER_OUTPUT_TYPE basic_coeff(basic c, const basic b, const basic x,
751  const basic n);
752 
754 
756 CWRAPPER_OUTPUT_TYPE vecbasic_linsolve(CVecBasic *sol, const CVecBasic *sys,
757  const CVecBasic *sym);
759 CWRAPPER_OUTPUT_TYPE basic_solve_poly(CSetBasic *r, const basic f,
760  const basic s);
761 
763 
766 char *ascii_art_str(void);
767 
770 CWRAPPER_OUTPUT_TYPE ntheory_gcd(basic s, const basic a, const basic b);
772 CWRAPPER_OUTPUT_TYPE ntheory_lcm(basic s, const basic a, const basic b);
774 CWRAPPER_OUTPUT_TYPE ntheory_gcd_ext(basic g, basic s, basic t, const basic a,
775  const basic b);
777 CWRAPPER_OUTPUT_TYPE ntheory_nextprime(basic s, const basic a);
779 CWRAPPER_OUTPUT_TYPE ntheory_mod(basic s, const basic n, const basic d);
781 CWRAPPER_OUTPUT_TYPE ntheory_quotient(basic s, const basic n, const basic d);
783 CWRAPPER_OUTPUT_TYPE ntheory_quotient_mod(basic q, basic r, const basic n,
784  const basic d);
786 CWRAPPER_OUTPUT_TYPE ntheory_mod_f(basic s, const basic n, const basic d);
788 CWRAPPER_OUTPUT_TYPE ntheory_quotient_f(basic s, const basic n, const basic d);
790 CWRAPPER_OUTPUT_TYPE ntheory_quotient_mod_f(basic q, basic r, const basic n,
791  const basic d);
793 int ntheory_mod_inverse(basic b, const basic a, const basic m);
795 CWRAPPER_OUTPUT_TYPE ntheory_fibonacci(basic s, unsigned long a);
797 CWRAPPER_OUTPUT_TYPE ntheory_fibonacci2(basic g, basic s, unsigned long a);
799 CWRAPPER_OUTPUT_TYPE ntheory_lucas(basic s, unsigned long a);
801 CWRAPPER_OUTPUT_TYPE ntheory_lucas2(basic g, basic s, unsigned long a);
803 CWRAPPER_OUTPUT_TYPE ntheory_binomial(basic s, const basic a, unsigned long b);
805 CWRAPPER_OUTPUT_TYPE ntheory_factorial(basic s, unsigned long n);
807 CWRAPPER_OUTPUT_TYPE basic_evalf(basic s, const basic b, unsigned long bits,
808  int real);
809 
811 CWRAPPER_OUTPUT_TYPE basic_as_numer_denom(basic numer, basic denom,
812  const basic x);
814 CWRAPPER_OUTPUT_TYPE basic_add_as_two_terms(basic term1, basic term2,
815  const basic s);
817 CWRAPPER_OUTPUT_TYPE basic_mul_as_two_terms(basic term1, basic term2,
818  const basic s);
819 
822 CLambdaRealDoubleVisitor *lambda_real_double_visitor_new(void);
823 void lambda_real_double_visitor_init(CLambdaRealDoubleVisitor *self,
824  const CVecBasic *args,
825  const CVecBasic *exprs, int perform_cse);
826 void lambda_real_double_visitor_call(CLambdaRealDoubleVisitor *self,
827  double *const outs,
828  const double *const inps);
829 void lambda_real_double_visitor_free(CLambdaRealDoubleVisitor *self);
830 
832 #ifdef HAVE_SYMENGINE_LLVM
833 // double
834 typedef struct CLLVMDoubleVisitor CLLVMDoubleVisitor;
835 CLLVMDoubleVisitor *llvm_double_visitor_new(void);
836 void llvm_double_visitor_init(CLLVMDoubleVisitor *self, const CVecBasic *args,
837  const CVecBasic *exprs, int perform_cse,
838  int opt_level);
839 void llvm_double_visitor_call(CLLVMDoubleVisitor *self, double *const outs,
840  const double *const inps);
841 void llvm_double_visitor_free(CLLVMDoubleVisitor *self);
842 // float
843 typedef struct CLLVMFloatVisitor CLLVMFloatVisitor;
844 CLLVMFloatVisitor *llvm_float_visitor_new(void);
845 void llvm_float_visitor_init(CLLVMFloatVisitor *self, const CVecBasic *args,
846  const CVecBasic *exprs, int perform_cse,
847  int opt_level);
848 void llvm_float_visitor_call(CLLVMFloatVisitor *self, float *const outs,
849  const float *const inps);
850 void llvm_float_visitor_free(CLLVMFloatVisitor *self);
851 
852 #ifdef SYMENGINE_HAVE_LLVM_LONG_DOUBLE
853 // long double
854 typedef struct CLLVMLongDoubleVisitor CLLVMLongDoubleVisitor;
855 CLLVMLongDoubleVisitor *llvm_long_double_visitor_new(void);
856 void llvm_long_double_visitor_init(CLLVMLongDoubleVisitor *self,
857  const CVecBasic *args,
858  const CVecBasic *exprs, int perform_cse,
859  int opt_level);
860 void llvm_long_double_visitor_call(CLLVMLongDoubleVisitor *self,
861  long double *const outs,
862  const long double *const inps);
863 void llvm_long_double_visitor_free(CLLVMLongDoubleVisitor *self);
864 #endif
865 #endif
866 
867 CWRAPPER_OUTPUT_TYPE basic_cse(CVecBasic *replacement_syms,
868  CVecBasic *replacement_exprs,
869  CVecBasic *reduced_exprs,
870  const CVecBasic *exprs);
871 
873 void symengine_print_stack_on_segfault(void);
874 
875 #ifdef __cplusplus
876 }
877 #endif
878 #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