11 #ifndef SYMENGINE_BASIC_H
12 #define SYMENGINE_BASIC_H
20 #include <unordered_map>
21 #include <unordered_set>
26 #include <type_traits>
30 #include <symengine/symengine_config.h>
31 #include <symengine/symengine_exception.h>
33 #ifdef WITH_SYMENGINE_THREAD_SAFE
44 #define SYMENGINE_INCLUDE_ALL
45 #define SYMENGINE_ENUM(type, Class) type,
46 #include "symengine/type_codes.inc"
48 #undef SYMENGINE_INCLUDE_ALL
55 SYMENGINE_EXPORT std::string type_code_name(TypeID
id);
57 #include "basic-methods.inc"
104 #if defined(WITH_SYMENGINE_THREAD_SAFE)
105 mutable std::atomic<hash_t> hash_;
110 #ifdef WITH_SYMENGINE_VIRTUAL_TYPEID
111 virtual TypeID get_type_code()
const = 0;
114 inline TypeID get_type_code()
const
153 inline hash_t hash()
const;
168 bool __neq__(
const Basic &o)
const;
171 int __cmp__(
const Basic &o)
const;
182 std::string __str__()
const;
185 std::string dumps()
const;
188 static RCP<const Basic> loads(
const std::string &);
191 RCP<const Basic> subs(
const map_basic_basic &subs_dict)
const;
193 RCP<const Basic>
xreplace(
const map_basic_basic &subs_dict)
const;
198 throw NotImplementedError(
"Not Implemented");
204 SYMENGINE_INCLUDE_METHODS_BASE()
206 RCP<const
Basic> diff(const RCP<const
Symbol> &x,
bool cache = true) const;
214 return static_cast<size_t>(k->hash());
221 bool operator()(
const RCP<const Basic> &x,
const RCP<const Basic> &y)
const
230 bool operator()(
const RCP<const Basic> &x,
const RCP<const Basic> &y)
const
232 hash_t xh = x->hash(), yh = y->hash();
237 return x->__cmp__(*y) == -1;
243 inline bool eq(
const Basic &a,
const Basic &b);
246 SYMENGINE_EXPORT
bool neq(
const Basic &a,
const Basic &b);
252 bool is_a(
const Basic &b);
255 SYMENGINE_EXPORT
bool is_a_Atom(
const Basic &b);
270 SYMENGINE_EXPORT RCP<const Basic>
expand(
const RCP<const Basic> &
self,
272 SYMENGINE_EXPORT
void as_numer_denom(
const RCP<const Basic> &x,
273 const Ptr<RCP<const Basic>> &numer,
274 const Ptr<RCP<const Basic>> &denom);
276 SYMENGINE_EXPORT
void as_real_imag(
const RCP<const Basic> &x,
277 const Ptr<RCP<const Basic>> &real,
278 const Ptr<RCP<const Basic>> &imag);
280 SYMENGINE_EXPORT RCP<const Basic> rewrite_as_exp(
const RCP<const Basic> &x);
281 SYMENGINE_EXPORT RCP<const Basic> rewrite_as_sin(
const RCP<const Basic> &x);
282 SYMENGINE_EXPORT RCP<const Basic> rewrite_as_cos(
const RCP<const Basic> &x);
287 void cse(vec_pair &replacements, vec_basic &reduced_exprs,
288 const vec_basic &exprs);
296 SYMENGINE_EXPORT std::ostream &
operator<<(std::ostream &out,
317 SYMENGINE_EXPORT
const char *get_version();
329 #include "basic-inl.h"
330 #include <symengine/tribool.h>
333 #ifdef WITH_SYMENGINE_VIRTUAL_TYPEID
334 #define IMPLEMENT_TYPEID(SYMENGINE_ID) \
336 const static TypeID type_code_id = SYMENGINE_ID; \
338 virtual TypeID get_type_code() const \
340 return type_code_id; \
342 SYMENGINE_INCLUDE_METHODS_DERIVED()
344 #define IMPLEMENT_TYPEID(SYMENGINE_ID) \
346 const static TypeID type_code_id = SYMENGINE_ID; \
347 SYMENGINE_INCLUDE_METHODS_DERIVED()
350 #ifdef WITH_SYMENGINE_VIRTUAL_TYPEID
351 #define SYMENGINE_ASSIGN_TYPEID()
353 #define SYMENGINE_ASSIGN_TYPEID() this->type_code_ = type_code_id;
The lowest unit of symbolic representation.
Basic(Basic &&)=delete
Delete the move constructor and assignment.
virtual RCP< const Basic > expand_as_exp() const
expands the special function in terms of exp function
virtual vec_basic get_args() const =0
Returns the list of arguments.
Basic & operator=(const Basic &)=delete
Assignment operator in continuation with above.
Basic(const Basic &)=delete
Delete the copy constructor and assignment.
virtual bool __eq__(const Basic &o) const =0
Test equality.
virtual hash_t __hash__() const =0
hash_t hash_
Private variables.
virtual int compare(const Basic &o) const =0
Basic & operator=(Basic &&)=delete
Assignment operator in continuation with above.
Main namespace for SymEngine package.
bool is_a_sub(const Basic &b)
void hash_combine(hash_t &seed, const T &v)
bool is_a(const Basic &b)
Templatised version to check is_a type.
bool is_a_Atom(const Basic &b)
Returns true if b is an atom. i.e. b.get_args returns an empty vector.
bool eq(const Basic &a, const Basic &b)
Checks equality for a and b
bool is_same_type(const Basic &a, const Basic &b)
Returns true if a and b are exactly the same type T.
std::ostream & operator<<(std::ostream &out, const SymEngine::Basic &p)
<< Operator
bool neq(const Basic &a, const Basic &b)
Checks inequality for a and b
SYMENGINE_EXPORT RCP< const Basic > xreplace(const RCP< const Basic > &x, const map_basic_basic &subs_dict, bool cache=true)
Mappings in the subs_dict are applied to the expression tree of x
SYMENGINE_EXPORT RCP< const Basic > expand(const RCP< const Basic > &self, bool deep=true)
Expands self
size_t operator()(const RCP< const Basic > &k) const
Returns the hashed value.
bool operator()(const RCP< const Basic > &x, const RCP< const Basic > &y) const
Comparison Operator ==
bool operator()(const RCP< const Basic > &x, const RCP< const Basic > &y) const
true if x < y, false otherwise