symbol.h
Go to the documentation of this file.
1 
6 #ifndef SYMENGINE_SYMBOL_H
7 #define SYMENGINE_SYMBOL_H
8 
9 #include <symengine/basic.h>
10 
11 namespace SymEngine
12 {
13 
14 class Symbol : public Basic
15 {
16 private:
18  std::string name_;
19 
20 public:
21  IMPLEMENT_TYPEID(SYMENGINE_SYMBOL)
23  explicit Symbol(const std::string &name);
25  hash_t __hash__() const override;
30  bool __eq__(const Basic &o) const override;
31 
36  int compare(const Basic &o) const override;
38  inline const std::string &get_name() const
39  {
40  return name_;
41  }
42 
43  vec_basic get_args() const override
44  {
45  return {};
46  }
47  RCP<const Symbol> as_dummy() const;
48 };
49 
50 class Dummy : public Symbol
51 {
52 private:
54 #ifdef WITH_SYMENGINE_THREAD_SAFE
55  static std::atomic<size_t> count_;
56 #else
57  static size_t count_;
58 #endif
60  size_t dummy_index;
61 
62 public:
63  IMPLEMENT_TYPEID(SYMENGINE_DUMMY)
65  explicit Dummy();
66  explicit Dummy(const std::string &name);
67  Dummy(const std::string &name, size_t index);
69  hash_t __hash__() const override;
74  bool __eq__(const Basic &o) const override;
79  int compare(const Basic &o) const override;
80  size_t get_index() const
81  {
82  return dummy_index;
83  }
84 };
85 
87 inline RCP<const Symbol> symbol(const std::string &name)
88 {
89  return make_rcp<const Symbol>(name);
90 }
91 
93 inline RCP<const Dummy> dummy()
94 {
95  return make_rcp<const Dummy>();
96 }
97 
98 inline RCP<const Dummy> dummy(const std::string &name)
99 {
100  return make_rcp<const Dummy>(name);
101 }
102 
103 inline RCP<const Dummy> dummy(const std::string &name, size_t dummy_index)
104 {
105  return make_rcp<const Dummy>(name, dummy_index);
106 }
107 
108 inline bool is_a_Symbol(const Basic &b)
109 {
110  return b.get_type_code() == SYMENGINE_SYMBOL
111  || b.get_type_code() == SYMENGINE_DUMMY;
112 }
113 
114 } // namespace SymEngine
115 
116 #endif
The base class for SymEngine.
#define IMPLEMENT_TYPEID(SYMENGINE_ID)
Inline members and functions.
Definition: basic.h:340
The lowest unit of symbolic representation.
Definition: basic.h:97
Dummy()
Dummy Constructors.
Definition: symbol.cpp:44
int compare(const Basic &o) const override
Definition: symbol.cpp:76
hash_t __hash__() const override
Definition: symbol.cpp:60
size_t dummy_index
Dummy index.
Definition: symbol.h:60
static size_t count_
Dummy count.
Definition: symbol.h:57
bool __eq__(const Basic &o) const override
Definition: symbol.cpp:68
const std::string & get_name() const
Definition: symbol.h:38
Symbol(const std::string &name)
Symbol Constructor.
Definition: symbol.cpp:7
bool __eq__(const Basic &o) const override
Definition: symbol.cpp:17
std::string name_
name of Symbol
Definition: symbol.h:18
int compare(const Basic &o) const override
Definition: symbol.cpp:24
hash_t __hash__() const override
Definition: symbol.cpp:10
vec_basic get_args() const override
Returns the list of arguments.
Definition: symbol.h:43
Main namespace for SymEngine package.
Definition: add.cpp:19
RCP< const Dummy > dummy()
inline version to return Dummy
Definition: symbol.h:93
RCP< const Symbol > symbol(const std::string &name)
inline version to return Symbol
Definition: symbol.h:87