constants.cpp
1 #include <symengine/complex.h>
2 #include <symengine/add.h>
3 #include <symengine/infinity.h>
4 #include <symengine/pow.h>
5 #include <symengine/nan.h>
6 
7 namespace SymEngine
8 {
9 
11  : name_{name} {SYMENGINE_ASSIGN_TYPEID()}
12 
13  hash_t Constant::__hash__() const
14 {
15  hash_t seed = SYMENGINE_CONSTANT;
16  hash_combine<std::string>(seed, name_);
17  return seed;
18 }
19 
20 bool Constant::__eq__(const Basic &o) const
21 {
22  if (is_a<Constant>(o))
23  return name_ == down_cast<const Constant &>(o).name_;
24  return false;
25 }
26 
27 int Constant::compare(const Basic &o) const
28 {
29  SYMENGINE_ASSERT(is_a<Constant>(o))
30  const Constant &s = down_cast<const Constant &>(o);
31  if (name_ == s.name_)
32  return 0;
33  return name_ < s.name_ ? -1 : 1;
34 }
35 
36 RCP<const Integer> zero = integer(0);
37 RCP<const Integer> one = integer(1);
38 RCP<const Integer> minus_one = integer(-1);
39 RCP<const Integer> two = integer(2);
40 RCP<const Number> I = Complex::from_two_nums(*zero, *one);
41 
42 RCP<const Constant> pi = constant("pi");
43 RCP<const Constant> E = constant("E");
44 RCP<const Constant> EulerGamma = constant("EulerGamma");
45 RCP<const Constant> Catalan = constant("Catalan");
46 RCP<const Constant> GoldenRatio = constant("GoldenRatio");
47 
48 RCP<const Infty> Inf = Infty::from_int(1);
49 RCP<const Infty> NegInf = Infty::from_int(-1);
50 RCP<const Infty> ComplexInf = Infty::from_int(0);
51 
52 RCP<const NaN> Nan = make_rcp<NaN>();
53 
54 // Global variables declared in functions.cpp
55 // Look over https://github.com/sympy/symengine/issues/272
56 // for further details
57 RCP<const Basic> i2 = integer(2);
58 
59 namespace
60 {
61 RCP<const Basic> sqrt_(const RCP<const Basic> &arg)
62 {
63  return pow(arg, div(one, i2));
64 }
65 } // namespace
66 
67 RCP<const Basic> i3 = integer(3);
68 RCP<const Basic> i5 = integer(5);
69 RCP<const Basic> im2 = integer(-2);
70 RCP<const Basic> im3 = integer(-3);
71 RCP<const Basic> im5 = integer(-5);
72 
73 RCP<const Basic> sq3 = sqrt_(i3);
74 RCP<const Basic> sq2 = sqrt_(i2);
75 RCP<const Basic> sq5 = sqrt_(i5);
76 
77 RCP<const Basic> C0 = div(sub(sq3, one), mul(i2, sq2));
78 RCP<const Basic> C1 = div(one, i2);
79 RCP<const Basic> C2 = div(sq2, i2);
80 RCP<const Basic> C3 = div(sq3, i2);
81 RCP<const Basic> C4 = div(add(sq3, one), mul(i2, sq2));
82 RCP<const Basic> C5 = div(sqrt_(sub(i5, sqrt_(i5))), integer(8));
83 RCP<const Basic> C6 = div(sub(sqrt_(i5), one), integer(4));
84 
85 RCP<const Basic> mC0 = mul(minus_one, C0);
86 RCP<const Basic> mC1 = mul(minus_one, C1);
87 RCP<const Basic> mC2 = mul(minus_one, C2);
88 RCP<const Basic> mC3 = mul(minus_one, C3);
89 RCP<const Basic> mC4 = mul(minus_one, C4);
90 RCP<const Basic> mC5 = mul(minus_one, C5);
91 RCP<const Basic> mC6 = mul(minus_one, C6);
92 
93 // sin_table[n] represents the value of sin(pi*n/12) for n = 0..23
94 RCP<const Basic> sin_table[]
95  = {zero, C0, C1, C2, C3, C4, one, C4, C3, C2, C1, C0,
96  zero, mC0, mC1, mC2, mC3, mC4, minus_one, mC4, mC3, mC2, mC1, mC0};
97 
98 umap_basic_basic inverse_cst = {
99  {C3, i3},
100  {mC3, im3},
101  {C2, mul(i2, i2)},
102  {mC2, mul(im2, i2)},
103  {C4, integer(12)},
104  {mC4, integer(-12)},
105  {C5, i5},
106  {mC5, im5},
107  {C6, integer(10)},
108  {mC6, integer(-10)},
109  {div(one, i2), integer(6)},
110  {div(minus_one, i2), integer(-6)},
111 };
112 
113 umap_basic_basic inverse_tct = {
114  {div(one, sq3), mul(i2, i3)},
115  {div(minus_one, sq3), mul(im2, i3)},
116  {sq3, i3},
117  {mul(minus_one, sq3), im3},
118  {add(one, sq2), div(pow(i2, i3), i3)},
119  {mul(minus_one, add(one, sq2)), div(pow(i2, i3), im3)},
120  {sub(sq2, one), pow(i2, i3)},
121  {sub(one, sq2), pow(im2, i3)},
122  {sub(i2, sq3), mul(mul(i2, i2), i3)},
123  {sub(sq3, i2), mul(mul(im2, i2), i3)},
124  {sqrt(add(i5, mul(i2, sqrt(i5)))), div(i5, i2)},
125  {mul(minus_one, sqrt(add(i5, mul(i2, sqrt(i5))))), div(im5, i2)},
126  {one, pow(i2, i2)},
127  {minus_one, mul(minus_one, pow(i2, i2))},
128 };
129 
130 } // namespace SymEngine
Classes and functions relating to the binary operation of addition.
The lowest unit of symbolic representation.
Definition: basic.h:95
static RCP< const Number > from_two_nums(const Number &re, const Number &im)
Definition: complex.cpp:109
std::string name_
name of Constant
Definition: constants.h:22
virtual hash_t __hash__() const
Definition: constants.cpp:13
virtual bool __eq__(const Basic &o) const
Definition: constants.cpp:20
Constant(const std::string &name)
Constant Constructor.
Definition: constants.cpp:10
virtual int compare(const Basic &o) const
Definition: constants.cpp:27
static RCP< const Infty > from_int(const int val)
Constructs Infty using sign of val
Definition: infinity.cpp:33
Main namespace for SymEngine package.
Definition: add.cpp:19
RCP< const Basic > div(const RCP< const Basic > &a, const RCP< const Basic > &b)
Division.
Definition: mul.cpp:426
std::enable_if< std::is_integral< T >::value, RCP< const Integer > >::type integer(T i)
Definition: integer.h:200
RCP< const Basic > sub(const RCP< const Basic > &a, const RCP< const Basic > &b)
Substracts b from a.
Definition: add.cpp:495
RCP< const Basic > mul(const RCP< const Basic > &a, const RCP< const Basic > &b)
Multiplication.
Definition: mul.cpp:347
RCP< const Basic > add(const RCP< const Basic > &a, const RCP< const Basic > &b)
Adds two objects (safely).
Definition: add.cpp:425
RCP< const Constant > constant(const std::string &name)
inline version to return Constant
Definition: constants.h:53
T pow(T... args)
T sqrt(T... args)