1 #ifndef SYMENGINE_STR_PRINTER_H
2 #define SYMENGINE_STR_PRINTER_H
5 #include <symengine/printers.h>
13 enum class PrecedenceEnum { Relational, Add, Mul, Pow, Atom };
18 PrecedenceEnum precedence;
21 void bvisit(
const Add &x);
22 void bvisit(
const Mul &x);
24 void bvisit(
const Pow &x);
25 template <
typename Poly>
26 void bvisit_upoly(
const Poly &x)
28 if (x.end() == ++x.begin()) {
30 precedence = PrecedenceEnum::Atom;
31 if (it->second == 1) {
32 if (it->first == 0 or it->first == 1) {
33 precedence = PrecedenceEnum::Atom;
35 precedence = PrecedenceEnum::Pow;
41 precedence = PrecedenceEnum::Mul;
44 }
else if (x.begin() == x.end()) {
45 precedence = PrecedenceEnum::Atom;
47 precedence = PrecedenceEnum::Add;
51 template <
typename Container,
typename Poly>
54 bvisit_upoly(down_cast<const Poly &>(x));
59 template <
typename Container,
typename Poly>
62 if (0 == x.get_poly().dict_.size()) {
63 precedence = PrecedenceEnum::Atom;
64 }
else if (1 == x.get_poly().dict_.size()) {
65 auto iter = x.get_poly().dict_.begin();
66 precedence = PrecedenceEnum::Atom;
69 for (
unsigned int exp : iter->first) {
72 precedence = PrecedenceEnum::Pow;
74 precedence = PrecedenceEnum::Mul;
79 if (iter->second != 1)
80 precedence = PrecedenceEnum::Mul;
83 precedence = PrecedenceEnum::Add;
91 #ifdef HAVE_SYMENGINE_PIRANHA
92 void bvisit(
const URatPSeriesPiranha &x);
93 void bvisit(
const UPSeriesPiranha &x);
96 #ifdef HAVE_SYMENGINE_MPFR
99 #ifdef HAVE_SYMENGINE_MPC
102 void bvisit(
const Basic &x);
103 PrecedenceEnum getPrecedence(
const RCP<const Basic> &x);
114 virtual bool split_mul_coef();
116 const RCP<const Basic> &b);
121 std::string parenthesizeLT(
const RCP<const Basic> &x,
122 PrecedenceEnum precedenceEnum);
123 std::string parenthesizeLE(
const RCP<const Basic> &x,
124 PrecedenceEnum precedenceEnum);
127 void bvisit(
const Basic &x);
128 void bvisit(
const Symbol &x);
134 void bvisit(
const Reals &x);
146 void bvisit(
const And &x);
147 void bvisit(
const Or &x);
148 void bvisit(
const Xor &x);
149 void bvisit(
const Not &x);
150 void bvisit(
const Union &x);
154 void bvisit(
const Add &x);
155 void bvisit(
const Mul &x);
156 void bvisit(
const Pow &x);
160 #ifdef HAVE_SYMENGINE_FLINT
161 void bvisit(
const UIntPolyFlint &x);
162 void bvisit(
const URatPolyFlint &x);
167 void bvisit(
const Infty &x);
168 void bvisit(
const NaN &x);
170 #ifdef HAVE_SYMENGINE_PIRANHA
171 void bvisit(
const URatPSeriesPiranha &x);
172 void bvisit(
const UPSeriesPiranha &x);
173 void bvisit(
const UIntPolyPiranha &x);
174 void bvisit(
const URatPolyPiranha &x);
180 void bvisit(
const Subs &x);
187 #ifdef HAVE_SYMENGINE_MPFR
190 #ifdef HAVE_SYMENGINE_MPC
194 void bvisit(
const Tuple &x);
206 using StrPrinter::bvisit;
208 const RCP<const Basic> &b)
override;
211 void bvisit(
const NaN &x);
212 void bvisit(
const Infty &x);
The base class for representing addition in symbolic expressions.
The lowest unit of symbolic representation.
Complex Double Class to hold std::complex<double> values.
const RCP< const Basic > & get_basic() const
Method to get Basic from Expression.
RealDouble Class to hold double values.
Main namespace for SymEngine package.
RCP< const Basic > exp(const RCP< const Basic > &x)
Returns the natural exponential function E**x = pow(E, x)