Loading...
Searching...
No Matches
SymEngine::StrPrinter Class Reference
+ Inheritance diagram for SymEngine::StrPrinter:
+ Collaboration diagram for SymEngine::StrPrinter:

Public Member Functions

void bvisit (const Basic &x)
 
void bvisit (const Symbol &x)
 
void bvisit (const Integer &x)
 
void bvisit (const Rational &x)
 
void bvisit (const Complex &x)
 
void bvisit (const Interval &x)
 
void bvisit (const Complexes &x)
 
void bvisit (const Reals &x)
 
void bvisit (const Rationals &x)
 
void bvisit (const Integers &x)
 
void bvisit (const Naturals &x)
 
void bvisit (const Naturals0 &x)
 
void bvisit (const Piecewise &x)
 
void bvisit (const EmptySet &x)
 
void bvisit (const FiniteSet &x)
 
void bvisit (const UniversalSet &x)
 
void bvisit (const ConditionSet &x)
 
void bvisit (const Contains &x)
 
void bvisit (const BooleanAtom &x)
 
void bvisit (const And &x)
 
void bvisit (const Or &x)
 
void bvisit (const Xor &x)
 
void bvisit (const Not &x)
 
void bvisit (const Union &x)
 
void bvisit (const Complement &x)
 
void bvisit (const ImageSet &x)
 
void bvisit (const Add &x)
 
void bvisit (const Mul &x)
 
void bvisit (const Pow &x)
 
void bvisit (const UIntPoly &x)
 
void bvisit (const MIntPoly &x)
 
void bvisit (const URatPoly &x)
 
void bvisit (const UExprPoly &x)
 
void bvisit (const MExprPoly &x)
 
void bvisit (const GaloisField &x)
 
void bvisit (const Infty &x)
 
void bvisit (const NaN &x)
 
void bvisit (const UnivariateSeries &x)
 
void bvisit (const Constant &x)
 
void bvisit (const Function &x)
 
void bvisit (const FunctionSymbol &x)
 
void bvisit (const Derivative &x)
 
void bvisit (const Subs &x)
 
void bvisit (const RealDouble &x)
 
void bvisit (const ComplexDouble &x)
 
void bvisit (const Equality &x)
 
void bvisit (const Unequality &x)
 
void bvisit (const LessThan &x)
 
void bvisit (const StrictLessThan &x)
 
void bvisit (const NumberWrapper &x)
 
void bvisit (const Tuple &x)
 
std::string apply (const RCP< const Basic > &b)
 
std::string apply (const vec_basic &v)
 
std::string apply (const Basic &b)
 

Protected Member Functions

virtual std::string print_mul ()
 
virtual bool split_mul_coef ()
 
virtual void _print_pow (std::ostringstream &o, const RCP< const Basic > &a, const RCP< const Basic > &b)
 
virtual std::string print_div (const std::string &num, const std::string &den, bool paren)
 
virtual std::string get_imag_symbol ()
 
virtual std::string parenthesize (const std::string &expr)
 
std::string parenthesizeLT (const RCP< const Basic > &x, PrecedenceEnum precedenceEnum)
 
std::string parenthesizeLE (const RCP< const Basic > &x, PrecedenceEnum precedenceEnum)
 

Protected Attributes

std::string str_
 

Static Private Attributes

static const std::vector< std::stringnames_
 

Detailed Description

Definition at line 106 of file strprinter.h.

Member Function Documentation

◆ _print_pow()

void SymEngine::StrPrinter::_print_pow ( std::ostringstream o,
const RCP< const Basic > &  a,
const RCP< const Basic > &  b 
)
protectedvirtual

Definition at line 546 of file strprinter.cpp.

548{
549 if (eq(*a, *E)) {
550 o << "exp(" << apply(b) << ")";
551 } else if (eq(*b, *rational(1, 2))) {
552 o << "sqrt(" << apply(a) << ")";
553 } else {
554 o << parenthesizeLE(a, PrecedenceEnum::Pow);
555 o << "**";
556 o << parenthesizeLE(b, PrecedenceEnum::Pow);
557 }
558}
bool eq(const Basic &a, const Basic &b)
Checks equality for a and b
Definition: basic-inl.h:21
RCP< const Number > rational(long n, long d)
convenience creator from two longs
Definition: rational.h:328

◆ apply() [1/3]

std::string SymEngine::StrPrinter::apply ( const Basic b)

Definition at line 1056 of file strprinter.cpp.

1057{
1058 b.accept(*this);
1059 return str_;
1060}

◆ apply() [2/3]

std::string SymEngine::StrPrinter::apply ( const RCP< const Basic > &  b)

Definition at line 1050 of file strprinter.cpp.

1051{
1052 b->accept(*this);
1053 return str_;
1054}

◆ apply() [3/3]

std::string SymEngine::StrPrinter::apply ( const vec_basic v)

Definition at line 854 of file strprinter.cpp.

855{
857 for (auto p = d.begin(); p != d.end(); p++) {
858 if (p != d.begin()) {
859 o << ", ";
860 }
861 o << this->apply(*p);
862 }
863 return o.str();
864}
T str(T... args)

◆ bvisit() [1/51]

void SymEngine::StrPrinter::bvisit ( const Add x)

Definition at line 510 of file strprinter.cpp.

511{
513 bool first = true;
514 std::map<RCP<const Basic>, RCP<const Number>, PrinterBasicCmp> dict(
515 x.get_dict().begin(), x.get_dict().end());
516
517 if (neq(*(x.get_coef()), *zero)) {
518 o << this->apply(x.get_coef());
519 first = false;
520 }
521 for (const auto &p : dict) {
522 std::string t;
523 if (eq(*(p.second), *one)) {
524 t = parenthesizeLT(p.first, PrecedenceEnum::Add);
525 } else if (eq(*(p.second), *minus_one)) {
526 t = "-" + parenthesizeLT(p.first, PrecedenceEnum::Mul);
527 } else {
528 t = parenthesizeLT(p.second, PrecedenceEnum::Mul) + print_mul()
529 + parenthesizeLT(p.first, PrecedenceEnum::Mul);
530 }
531
532 if (not first) {
533 if (t[0] == '-') {
534 o << " - " << t.substr(1);
535 } else {
536 o << " + " << t;
537 }
538 } else {
539 o << t;
540 first = false;
541 }
542 }
543 str_ = o.str();
544}
bool neq(const Basic &a, const Basic &b)
Checks inequality for a and b
Definition: basic-inl.h:29
T substr(T... args)

◆ bvisit() [2/51]

void SymEngine::StrPrinter::bvisit ( const And x)

Definition at line 298 of file strprinter.cpp.

299{
301 auto container = x.get_container();
302 s << "And(";
303 s << apply(*container.begin());
304 for (auto it = ++(container.begin()); it != container.end(); ++it) {
305 s << ", " << apply(*it);
306 }
307 s << ")";
308 str_ = s.str();
309}

◆ bvisit() [3/51]

void SymEngine::StrPrinter::bvisit ( const Basic x)

Definition at line 133 of file strprinter.cpp.

134{
136 s << "<" << typeName<Basic>(x) << " instance at " << (const void *)this
137 << ">";
138 str_ = s.str();
139}

◆ bvisit() [4/51]

void SymEngine::StrPrinter::bvisit ( const BooleanAtom x)

Definition at line 289 of file strprinter.cpp.

290{
291 if (x.get_val()) {
292 str_ = "True";
293 } else {
294 str_ = "False";
295 }
296}

◆ bvisit() [5/51]

void SymEngine::StrPrinter::bvisit ( const Complement x)

Definition at line 421 of file strprinter.cpp.

422{
424 s << apply(*x.get_universe());
425 s << " \\ " << apply(*x.get_container());
426 str_ = s.str();
427}

◆ bvisit() [6/51]

void SymEngine::StrPrinter::bvisit ( const Complex x)

Definition at line 179 of file strprinter.cpp.

180{
182 if (x.real_ != 0) {
183 s << x.real_;
184 // Since Complex is in canonical form, imaginary_ is not 0.
185 if (mp_sign(x.imaginary_) == 1) {
186 s << " + ";
187 } else {
188 s << " - ";
189 }
190 // If imaginary_ is not 1 or -1, print the absolute value
191 if (x.imaginary_ != mp_sign(x.imaginary_)) {
192 s << mp_abs(x.imaginary_);
193 s << print_mul() << get_imag_symbol();
194 } else {
195 s << "I";
196 }
197 } else {
198 if (x.imaginary_ != mp_sign(x.imaginary_)) {
199 s << x.imaginary_;
200 s << print_mul() << get_imag_symbol();
201 } else {
202 if (mp_sign(x.imaginary_) == 1) {
203 s << get_imag_symbol();
204 } else {
205 s << "-" << get_imag_symbol();
206 }
207 }
208 }
209 str_ = s.str();
210}

◆ bvisit() [7/51]

void SymEngine::StrPrinter::bvisit ( const ComplexDouble x)

Definition at line 234 of file strprinter.cpp.

235{
236 str_ = print_double(x.i.real());
237 if (x.i.imag() < 0) {
238 str_ += " - " + print_double(-x.i.imag()) + print_mul()
239 + get_imag_symbol();
240 } else {
241 str_ += " + " + print_double(x.i.imag()) + print_mul()
242 + get_imag_symbol();
243 }
244}

◆ bvisit() [8/51]

void SymEngine::StrPrinter::bvisit ( const Complexes x)

Definition at line 375 of file strprinter.cpp.

376{
377 str_ = "Complexes";
378}

◆ bvisit() [9/51]

void SymEngine::StrPrinter::bvisit ( const ConditionSet x)

Definition at line 450 of file strprinter.cpp.

451{
453 s << "{" << apply(*x.get_symbol());
454 s << " | " << apply(x.get_condition()) << "}";
455 str_ = s.str();
456}

◆ bvisit() [10/51]

void SymEngine::StrPrinter::bvisit ( const Constant x)

Definition at line 849 of file strprinter.cpp.

850{
851 str_ = x.get_name();
852}

◆ bvisit() [11/51]

void SymEngine::StrPrinter::bvisit ( const Contains x)

Definition at line 344 of file strprinter.cpp.

345{
347 s << "Contains(" << apply(x.get_expr()) << ", " << apply(x.get_set())
348 << ")";
349 str_ = s.str();
350}

◆ bvisit() [12/51]

void SymEngine::StrPrinter::bvisit ( const Derivative x)

Definition at line 885 of file strprinter.cpp.

886{
888 o << "Derivative(" << this->apply(x.get_arg());
889 auto m1 = x.get_symbols();
890 for (const auto &elem : m1) {
891 o << ", " << this->apply(elem);
892 }
893 o << ")";
894 str_ = o.str();
895}

◆ bvisit() [13/51]

void SymEngine::StrPrinter::bvisit ( const EmptySet x)

Definition at line 405 of file strprinter.cpp.

406{
407 str_ = "EmptySet";
408}

◆ bvisit() [14/51]

void SymEngine::StrPrinter::bvisit ( const Equality x)

Definition at line 246 of file strprinter.cpp.

247{
249 s << apply(x.get_arg1()) << " == " << apply(x.get_arg2());
250 str_ = s.str();
251}

◆ bvisit() [15/51]

void SymEngine::StrPrinter::bvisit ( const FiniteSet x)

Definition at line 443 of file strprinter.cpp.

444{
446 s << x.get_container();
447 str_ = s.str();
448}

◆ bvisit() [16/51]

void SymEngine::StrPrinter::bvisit ( const Function x)

Definition at line 866 of file strprinter.cpp.

867{
868 static const std::vector<std::string> names_ = init_str_printer_names();
870 o << names_[x.get_type_code()];
871 vec_basic vec = x.get_args();
872 o << parenthesize(apply(vec));
873 str_ = o.str();
874}

◆ bvisit() [17/51]

void SymEngine::StrPrinter::bvisit ( const FunctionSymbol x)

Definition at line 876 of file strprinter.cpp.

877{
879 o << x.get_name();
880 vec_basic vec = x.get_args();
881 o << parenthesize(apply(vec));
882 str_ = o.str();
883}

◆ bvisit() [18/51]

void SymEngine::StrPrinter::bvisit ( const GaloisField x)

Definition at line 661 of file strprinter.cpp.

662{
664 // bool variable needed to take care of cases like -5, -x, -3*x etc.
665 bool first = true;
666 // we iterate over the map in reverse order so that highest degree gets
667 // printed first
668 auto dict = x.get_dict();
669 if (x.get_dict().size() == 0)
670 s << "0";
671 else {
672 for (auto it = dict.size(); it-- != 0;) {
673 if (dict[it] == 0)
674 continue;
675 // if exponent is 0, then print only coefficient
676 if (it == 0) {
677 if (first) {
678 s << dict[it];
679 } else {
680 s << " " << _print_sign(dict[it]) << " "
681 << mp_abs(dict[it]);
682 }
683 first = false;
684 break;
685 }
686 // if the coefficient of a term is +1 or -1
687 if (mp_abs(dict[it]) == 1) {
688 // in cases of -x, print -x
689 // in cases of x**2 - x, print - x
690 if (first) {
691 if (dict[it] == -1)
692 s << "-";
693 s << detail::poly_print(x.get_var());
694 } else {
695 s << " " << _print_sign(dict[it]) << " "
696 << detail::poly_print(x.get_var());
697 }
698 }
699 // same logic is followed as above
700 else {
701 // in cases of -2*x, print -2*x
702 // in cases of x**2 - 2*x, print - 2*x
703 if (first) {
704 s << dict[it] << "*" << detail::poly_print(x.get_var());
705 } else {
706 s << " " << _print_sign(dict[it]) << " " << mp_abs(dict[it])
707 << "*" << detail::poly_print(x.get_var());
708 }
709 }
710 // if exponent is not 1, print the exponent;
711 if (it != 1) {
712 s << "**" << it;
713 }
714 // corner cases of only first term handled successfully, switch the
715 // bool
716 first = false;
717 }
718 }
719 str_ = s.str();
720}

◆ bvisit() [19/51]

void SymEngine::StrPrinter::bvisit ( const ImageSet x)

Definition at line 429 of file strprinter.cpp.

430{
432 s << "{" << apply(*x.get_expr()) << " | ";
433 s << apply(*x.get_symbol());
434 s << " in " << apply(*x.get_baseset()) << "}";
435 str_ = s.str();
436}

◆ bvisit() [20/51]

void SymEngine::StrPrinter::bvisit ( const Infty x)

Definition at line 146 of file strprinter.cpp.

147{
149 if (x.is_negative_infinity())
150 s << "-oo";
151 else if (x.is_positive_infinity())
152 s << "oo";
153 else
154 s << "zoo";
155 str_ = s.str();
156}

◆ bvisit() [21/51]

void SymEngine::StrPrinter::bvisit ( const Integer x)

Definition at line 165 of file strprinter.cpp.

166{
168 s << x.as_integer_class();
169 str_ = s.str();
170}

◆ bvisit() [22/51]

void SymEngine::StrPrinter::bvisit ( const Integers x)

Definition at line 390 of file strprinter.cpp.

391{
392 str_ = "Integers";
393}

◆ bvisit() [23/51]

void SymEngine::StrPrinter::bvisit ( const Interval x)

Definition at line 274 of file strprinter.cpp.

275{
277 if (x.get_left_open())
278 s << "(";
279 else
280 s << "[";
281 s << *x.get_start() << ", " << *x.get_end();
282 if (x.get_right_open())
283 s << ")";
284 else
285 s << "]";
286 str_ = s.str();
287}

◆ bvisit() [24/51]

void SymEngine::StrPrinter::bvisit ( const LessThan x)

Definition at line 260 of file strprinter.cpp.

261{
263 s << apply(x.get_arg1()) << " <= " << apply(x.get_arg2());
264 str_ = s.str();
265}

◆ bvisit() [25/51]

void SymEngine::StrPrinter::bvisit ( const MExprPoly x)

Definition at line 966 of file strprinter.cpp.

967{
969 bool first = true; // is this the first term being printed out?
970 // To change the ordering in which the terms will print out, change
971 // vec_uint_compare in dict.h
972 std::vector<vec_int> v = sorted_keys(x.get_poly().dict_);
973
974 for (vec_int exps : v) {
975 Expression c = x.get_poly().dict_.find(exps)->second;
976 std::string t = parenthesizeLT(c.get_basic(), PrecedenceEnum::Mul);
977 if ('-' == t[0] && !first) {
978 s << " - ";
979 t = t.substr(1);
980 } else if (!first) {
981 s << " + ";
982 }
983 unsigned int i = 0;
985 bool first_var = true;
986 for (auto it : x.get_vars()) {
987 if (exps[i] != 0) {
988 if (!first_var) {
989 expr << "*";
990 }
991 expr << it->__str__();
992 if (exps[i] > 1 or exps[i] < 0)
993 expr << "**" << exps[i];
994 first_var = false;
995 }
996 i++;
997 }
998 if (c != 1 && c != -1) {
999 s << t;
1000 if (!expr.str().empty()) {
1001 s << "*";
1002 }
1003 } else if (expr.str().empty()) {
1004 s << "1";
1005 }
1006 s << expr.str();
1007 first = false;
1008 }
1009
1010 if (s.str().empty())
1011 s << "0";
1012 str_ = s.str();
1013}

◆ bvisit() [26/51]

void SymEngine::StrPrinter::bvisit ( const MIntPoly x)

Definition at line 918 of file strprinter.cpp.

919{
921 bool first = true; // is this the first term being printed out?
922 // To change the ordering in which the terms will print out, change
923 // vec_uint_compare in dict.h
924 std::vector<vec_uint> v = sorted_keys(x.get_poly().dict_);
925
926 for (vec_uint exps : v) {
927 integer_class c = x.get_poly().dict_.find(exps)->second;
928 if (!first) {
929 s << " " << _print_sign(c) << " ";
930 } else if (c < 0) {
931 s << "-";
932 }
933
934 unsigned int i = 0;
936 bool first_var = true;
937 for (auto it : x.get_vars()) {
938 if (exps[i] != 0) {
939 if (!first_var) {
940 expr << "*";
941 }
942 expr << it->__str__();
943 if (exps[i] > 1)
944 expr << "**" << exps[i];
945 first_var = false;
946 }
947 i++;
948 }
949 if (mp_abs(c) != 1) {
950 s << mp_abs(c);
951 if (!expr.str().empty()) {
952 s << "*";
953 }
954 } else if (expr.str().empty()) {
955 s << "1";
956 }
957 s << expr.str();
958 first = false;
959 }
960
961 if (s.str().empty())
962 s << "0";
963 str_ = s.str();
964}

◆ bvisit() [27/51]

void SymEngine::StrPrinter::bvisit ( const Mul x)

Definition at line 560 of file strprinter.cpp.

561{
562 std::ostringstream o, o2;
563 bool num = false;
564 unsigned den = 0;
565
566 if (eq(*(x.get_coef()), *minus_one)) {
567 o << "-";
568 } else if (neq(*(x.get_coef()), *one)) {
569 if (not split_mul_coef()) {
570 o << parenthesizeLT(x.get_coef(), PrecedenceEnum::Mul)
571 << print_mul();
572 num = true;
573 } else {
574 RCP<const Basic> numer, denom;
575 as_numer_denom(x.get_coef(), outArg(numer), outArg(denom));
576 if (neq(*numer, *one)) {
577 num = true;
578 o << parenthesizeLT(numer, PrecedenceEnum::Mul) << print_mul();
579 }
580 if (neq(*denom, *one)) {
581 den++;
582 o2 << parenthesizeLT(denom, PrecedenceEnum::Mul) << print_mul();
583 }
584 }
585 }
586
587 for (const auto &p : x.get_dict()) {
588 if ((is_a<Integer>(*p.second) or is_a<Rational>(*p.second))
589 and down_cast<const Number &>(*p.second).is_negative()
590 and neq(*(p.first), *E)) {
591 if (eq(*(p.second), *minus_one)) {
592 o2 << parenthesizeLT(p.first, PrecedenceEnum::Mul);
593 } else {
594 _print_pow(o2, p.first, neg(p.second));
595 }
596 o2 << print_mul();
597 den++;
598 } else {
599 if (eq(*(p.second), *one)) {
600 o << parenthesizeLT(p.first, PrecedenceEnum::Mul);
601 } else {
602 _print_pow(o, p.first, p.second);
603 }
604 o << print_mul();
605 num = true;
606 }
607 }
608
609 if (not num) {
610 o << "1" << print_mul();
611 }
612
613 std::string s = o.str();
614 s = s.substr(0, s.size() - 1);
615
616 if (den != 0) {
617 std::string s2 = o2.str();
618 s2 = s2.substr(0, s2.size() - 1);
619 if (den > 1) {
620 str_ = print_div(s, s2, true);
621 } else {
622 str_ = print_div(s, s2, false);
623 }
624 } else {
625 str_ = s;
626 }
627}
RCP< const Basic > neg(const RCP< const Basic > &a)
Negation.
Definition: mul.cpp:443
T size(T... args)

◆ bvisit() [28/51]

void SymEngine::StrPrinter::bvisit ( const NaN x)

Definition at line 158 of file strprinter.cpp.

159{
161 s << "nan";
162 str_ = s.str();
163}

◆ bvisit() [29/51]

void SymEngine::StrPrinter::bvisit ( const Naturals x)

Definition at line 395 of file strprinter.cpp.

396{
397 str_ = "Naturals";
398}

◆ bvisit() [30/51]

void SymEngine::StrPrinter::bvisit ( const Naturals0 x)

Definition at line 400 of file strprinter.cpp.

401{
402 str_ = "Naturals0";
403}

◆ bvisit() [31/51]

void SymEngine::StrPrinter::bvisit ( const Not x)

Definition at line 337 of file strprinter.cpp.

338{
340 s << "Not(" << *x.get_arg() << ")";
341 str_ = s.str();
342}

◆ bvisit() [32/51]

void SymEngine::StrPrinter::bvisit ( const NumberWrapper x)

Definition at line 913 of file strprinter.cpp.

914{
915 str_ = x.__str__();
916}

◆ bvisit() [33/51]

void SymEngine::StrPrinter::bvisit ( const Or x)

Definition at line 311 of file strprinter.cpp.

312{
314 auto container = x.get_container();
315 s << "Or(";
316 s << apply(*container.begin());
317 for (auto it = ++(container.begin()); it != container.end(); ++it) {
318 s << ", " << apply(*it);
319 }
320 s << ")";
321 str_ = s.str();
322}

◆ bvisit() [34/51]

void SymEngine::StrPrinter::bvisit ( const Piecewise x)

Definition at line 352 of file strprinter.cpp.

353{
355 auto vec = x.get_vec();
356 auto it = vec.begin();
357 s << "Piecewise(";
358 while (true) {
359 s << "(";
360 s << apply((*it).first);
361 s << ", ";
362 s << apply((*it).second);
363 s << ")";
364 ++it;
365 if (it != vec.end()) {
366 s << ", ";
367 } else {
368 break;
369 }
370 }
371 s << ")";
372 str_ = s.str();
373}

◆ bvisit() [35/51]

void SymEngine::StrPrinter::bvisit ( const Pow x)

Definition at line 644 of file strprinter.cpp.

645{
647 _print_pow(o, x.get_base(), x.get_exp());
648 str_ = o.str();
649}

◆ bvisit() [36/51]

void SymEngine::StrPrinter::bvisit ( const Rational x)

Definition at line 172 of file strprinter.cpp.

173{
175 s << x.as_rational_class();
176 str_ = s.str();
177}

◆ bvisit() [37/51]

void SymEngine::StrPrinter::bvisit ( const Rationals x)

Definition at line 385 of file strprinter.cpp.

386{
387 str_ = "Rationals";
388}

◆ bvisit() [38/51]

void SymEngine::StrPrinter::bvisit ( const RealDouble x)

Definition at line 229 of file strprinter.cpp.

230{
231 str_ = print_double(x.i);
232}

◆ bvisit() [39/51]

void SymEngine::StrPrinter::bvisit ( const Reals x)

Definition at line 380 of file strprinter.cpp.

381{
382 str_ = "Reals";
383}

◆ bvisit() [40/51]

void SymEngine::StrPrinter::bvisit ( const StrictLessThan x)

Definition at line 267 of file strprinter.cpp.

268{
270 s << apply(x.get_arg1()) << " < " << apply(x.get_arg2());
271 str_ = s.str();
272}

◆ bvisit() [41/51]

void SymEngine::StrPrinter::bvisit ( const Subs x)

Definition at line 897 of file strprinter.cpp.

898{
899 std::ostringstream o, vars, point;
900 for (auto p = x.get_dict().begin(); p != x.get_dict().end(); p++) {
901 if (p != x.get_dict().begin()) {
902 vars << ", ";
903 point << ", ";
904 }
905 vars << apply(p->first);
906 point << apply(p->second);
907 }
908 o << "Subs(" << apply(x.get_arg()) << ", (" << vars.str() << "), ("
909 << point.str() << "))";
910 str_ = o.str();
911}

◆ bvisit() [42/51]

void SymEngine::StrPrinter::bvisit ( const Symbol x)

Definition at line 141 of file strprinter.cpp.

142{
143 str_ = x.get_name();
144}

◆ bvisit() [43/51]

void SymEngine::StrPrinter::bvisit ( const Tuple x)

Definition at line 1015 of file strprinter.cpp.

1016{
1018 vec_basic vec = x.get_args();
1019 o << parenthesize(apply(vec));
1020 str_ = o.str();
1021}

◆ bvisit() [44/51]

void SymEngine::StrPrinter::bvisit ( const UExprPoly x)

Definition at line 814 of file strprinter.cpp.

815{
817 if (x.get_dict().size() == 0)
818 s << "0";
819 else
820 s << x.get_poly().__str__(detail::poly_print(x.get_var()));
821 str_ = s.str();
822}

◆ bvisit() [45/51]

void SymEngine::StrPrinter::bvisit ( const UIntPoly x)

Definition at line 780 of file strprinter.cpp.

781{
782 str_ = upoly_print<UIntPoly>(x);
783}

◆ bvisit() [46/51]

void SymEngine::StrPrinter::bvisit ( const Unequality x)

Definition at line 253 of file strprinter.cpp.

254{
256 s << apply(x.get_arg1()) << " != " << apply(x.get_arg2());
257 str_ = s.str();
258}

◆ bvisit() [47/51]

void SymEngine::StrPrinter::bvisit ( const Union x)

Definition at line 410 of file strprinter.cpp.

411{
413 s << apply(*x.get_container().begin());
414 for (auto it = ++(x.get_container().begin()); it != x.get_container().end();
415 ++it) {
416 s << " U " << apply(*it);
417 }
418 str_ = s.str();
419}

◆ bvisit() [48/51]

void SymEngine::StrPrinter::bvisit ( const UnivariateSeries x)

Definition at line 824 of file strprinter.cpp.

825{
827 o << x.get_poly().__str__(x.get_var()) << " + O(" << x.get_var() << "**"
828 << x.get_degree() << ")";
829 str_ = o.str();
830}

◆ bvisit() [49/51]

void SymEngine::StrPrinter::bvisit ( const UniversalSet x)

Definition at line 438 of file strprinter.cpp.

439{
440 str_ = "UniversalSet";
441}

◆ bvisit() [50/51]

void SymEngine::StrPrinter::bvisit ( const URatPoly x)

Definition at line 785 of file strprinter.cpp.

786{
787 str_ = upoly_print<URatPoly>(x);
788}

◆ bvisit() [51/51]

void SymEngine::StrPrinter::bvisit ( const Xor x)

Definition at line 324 of file strprinter.cpp.

325{
327 auto container = x.get_container();
328 s << "Xor(";
329 s << apply(*container.begin());
330 for (auto it = ++(container.begin()); it != container.end(); ++it) {
331 s << ", " << apply(*it);
332 }
333 s << ")";
334 str_ = s.str();
335}

◆ get_imag_symbol()

std::string SymEngine::StrPrinter::get_imag_symbol ( )
protectedvirtual

Definition at line 1174 of file strprinter.cpp.

1175{
1176 return "I";
1177}

◆ parenthesize()

std::string SymEngine::StrPrinter::parenthesize ( const std::string expr)
protectedvirtual

Definition at line 1045 of file strprinter.cpp.

1046{
1047 return "(" + x + ")";
1048}

◆ parenthesizeLE()

std::string SymEngine::StrPrinter::parenthesizeLE ( const RCP< const Basic > &  x,
PrecedenceEnum  precedenceEnum 
)
protected

Definition at line 1034 of file strprinter.cpp.

1036{
1037 Precedence prec;
1038 if (prec.getPrecedence(x) <= precedenceEnum) {
1039 return parenthesize(apply(x));
1040 } else {
1041 return apply(x);
1042 }
1043}

◆ parenthesizeLT()

std::string SymEngine::StrPrinter::parenthesizeLT ( const RCP< const Basic > &  x,
PrecedenceEnum  precedenceEnum 
)
protected

Definition at line 1023 of file strprinter.cpp.

1025{
1026 Precedence prec;
1027 if (prec.getPrecedence(x) < precedenceEnum) {
1028 return parenthesize(apply(x));
1029 } else {
1030 return apply(x);
1031 }
1032}

◆ print_div()

std::string SymEngine::StrPrinter::print_div ( const std::string num,
const std::string den,
bool  paren 
)
protectedvirtual

Definition at line 629 of file strprinter.cpp.

631{
632 if (paren) {
633 return num + "/" + parenthesize(den);
634 } else {
635 return num + "/" + den;
636 }
637}

◆ print_mul()

std::string SymEngine::StrPrinter::print_mul ( )
protectedvirtual

Definition at line 1120 of file strprinter.cpp.

1121{
1122 return "*";
1123}

◆ split_mul_coef()

bool SymEngine::StrPrinter::split_mul_coef ( )
protectedvirtual

Definition at line 639 of file strprinter.cpp.

640{
641 return false;
642}

Field Documentation

◆ names_

const std::vector<std::string> SymEngine::StrPrinter::names_
staticprivate

Definition at line 109 of file strprinter.h.

◆ str_

std::string SymEngine::StrPrinter::str_
protected

Definition at line 112 of file strprinter.h.


The documentation for this class was generated from the following files: