symbol.cpp
1 #include <symengine/constants.h>
2 #include <symengine/symengine_casts.h>
3 
4 namespace SymEngine
5 {
6 
8  : name_{name} {SYMENGINE_ASSIGN_TYPEID()}
9 
10  hash_t Symbol::__hash__() const
11 {
12  hash_t seed = 0;
13  hash_combine(seed, name_);
14  return seed;
15 }
16 
17 bool Symbol::__eq__(const Basic &o) const
18 {
19  if (is_a<Symbol>(o))
20  return name_ == down_cast<const Symbol &>(o).name_;
21  return false;
22 }
23 
24 int Symbol::compare(const Basic &o) const
25 {
26  SYMENGINE_ASSERT(is_a<Symbol>(o))
27  const Symbol &s = down_cast<const Symbol &>(o);
28  if (name_ == s.name_)
29  return 0;
30  return name_ < s.name_ ? -1 : 1;
31 }
32 
33 RCP<const Symbol> Symbol::as_dummy() const
34 {
35  return dummy(name_);
36 }
37 
38 size_t Dummy::count_ = 0;
39 
40 Dummy::Dummy() : Symbol("_Dummy_" + to_string(count_))
41 {
42  SYMENGINE_ASSIGN_TYPEID()
43  count_ += 1;
45 }
46 
47 Dummy::Dummy(const std::string &name) : Symbol("_" + name)
48 {
49  SYMENGINE_ASSIGN_TYPEID()
50  count_ += 1;
52 }
53 
54 hash_t Dummy::__hash__() const
55 {
56  hash_t seed = 0;
57  hash_combine(seed, get_name());
59  return seed;
60 }
61 
62 bool Dummy::__eq__(const Basic &o) const
63 {
64  if (is_a<Dummy>(o))
65  return ((get_name() == down_cast<const Dummy &>(o).get_name())
66  and (dummy_index == down_cast<const Dummy &>(o).get_index()));
67  return false;
68 }
69 
70 int Dummy::compare(const Basic &o) const
71 {
72  SYMENGINE_ASSERT(is_a<Dummy>(o))
73  const Dummy &s = down_cast<const Dummy &>(o);
74  if (get_name() == s.get_name()) {
75  if (dummy_index == s.get_index())
76  return 0;
77  return dummy_index < s.get_index() ? -1 : 1;
78  }
79  return get_name() < s.get_name() ? -1 : 1;
80 }
81 
82 } // namespace SymEngine
The lowest unit of symbolic representation.
Definition: basic.h:97
Dummy()
Dummy Constructors.
Definition: symbol.cpp:40
int compare(const Basic &o) const override
Definition: symbol.cpp:70
hash_t __hash__() const override
Definition: symbol.cpp:54
size_t dummy_index
Dummy index.
Definition: symbol.h:56
static size_t count_
Dummy count.
Definition: symbol.h:54
bool __eq__(const Basic &o) const override
Definition: symbol.cpp:62
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
Main namespace for SymEngine package.
Definition: add.cpp:19
RCP< const Dummy > dummy()
inline version to return Dummy
Definition: symbol.h:88
void hash_combine(hash_t &seed, const T &v)
Definition: basic-inl.h:95
std::string to_string(const T &value)
workaround for MinGW bug
Definition: basic-inl.h:111