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

Public Member Functions

void _print_pow (std::ostringstream &o, const RCP< const Basic > &a, const RCP< const Basic > &b) override
 
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 Piecewise &x)
 
void bvisit (const Infty &x)
 
void bvisit (const Constant &x)
 
void bvisit (const Function &x)
 
std::string apply (const RCP< const Basic > &b)
 
std::string apply (const vec_basic &v)
 
std::string apply (const Basic &b)
 
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 Intersection &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)
 
void bvisit (const IdentityMatrix &x)
 
void bvisit (const ZeroMatrix &x)
 
- Public Member Functions inherited from SymEngine::StrPrinter
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 Intersection &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)
 
void bvisit (const IdentityMatrix &x)
 
void bvisit (const ZeroMatrix &x)
 
std::string apply (const RCP< const Basic > &b)
 
std::string apply (const vec_basic &v)
 
std::string apply (const Basic &b)
 

Static Public Attributes

static const std::vector< std::stringnames_
 

Additional Inherited Members

- Protected Member Functions inherited from SymEngine::StrPrinter
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 inherited from SymEngine::StrPrinter
std::string str_
 

Detailed Description

Definition at line 10 of file sbml.h.

Member Function Documentation

◆ _print_pow()

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

Reimplemented from SymEngine::StrPrinter.

Definition at line 26 of file sbml.cpp.

28{
29 if (eq(*a, *E)) {
30 o << "exp(" << apply(b) << ")";
31 } else if (eq(*b, *rational(1, 2))) {
32 o << "sqrt(" << apply(a) << ")";
33 } else {
34 o << parenthesizeLE(a, PrecedenceEnum::Pow);
35 o << "^";
36 o << parenthesizeLE(b, PrecedenceEnum::Pow);
37 }
38}
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 200 of file strprinter.cpp.

1074{
1075 b.accept(*this);
1076 return str_;
1077}

◆ apply() [2/3]

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

Definition at line 198 of file strprinter.cpp.

1068{
1069 b->accept(*this);
1070 return str_;
1071}

◆ apply() [3/3]

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

Definition at line 199 of file strprinter.cpp.

862{
864 for (auto p = d.begin(); p != d.end(); p++) {
865 if (p != d.begin()) {
866 o << ", ";
867 }
868 o << this->apply(*p);
869 }
870 return o.str();
871}
T str(T... args)

◆ bvisit() [1/63]

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

Definition at line 154 of file strprinter.cpp.

518{
520 bool first = true;
521 std::map<RCP<const Basic>, RCP<const Number>, PrinterBasicCmp> dict(
522 x.get_dict().begin(), x.get_dict().end());
523
524 if (neq(*(x.get_coef()), *zero)) {
525 o << this->apply(x.get_coef());
526 first = false;
527 }
528 for (const auto &p : dict) {
529 std::string t;
530 if (eq(*(p.second), *one)) {
531 t = parenthesizeLT(p.first, PrecedenceEnum::Add);
532 } else if (eq(*(p.second), *minus_one)) {
533 t = "-" + parenthesizeLT(p.first, PrecedenceEnum::Mul);
534 } else {
535 t = parenthesizeLT(p.second, PrecedenceEnum::Mul) + print_mul()
536 + parenthesizeLT(p.first, PrecedenceEnum::Mul);
537 }
538
539 if (not first) {
540 if (t[0] == '-') {
541 o << " - " << t.substr(1);
542 } else {
543 o << " + " << t;
544 }
545 } else {
546 o << t;
547 first = false;
548 }
549 }
550 str_ = o.str();
551}
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/63]

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

Definition at line 146 of file strprinter.cpp.

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

◆ bvisit() [3/63]

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

Definition at line 49 of file sbml.cpp.

50{
52 const auto &container = x.get_container();
53 s << "and(";
54 s << apply(*container.begin());
55 for (auto it = ++(container.begin()); it != container.end(); ++it) {
56 s << ", " << apply(*it);
57 }
58 s << ")";
59 str_ = s.str();
60}

◆ bvisit() [4/63]

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

Definition at line 127 of file strprinter.cpp.

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

◆ bvisit() [5/63]

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

Definition at line 145 of file strprinter.cpp.

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

◆ bvisit() [6/63]

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

Definition at line 40 of file sbml.cpp.

41{
42 if (x.get_val()) {
43 str_ = "true";
44 } else {
45 str_ = "false";
46 }
47}

◆ bvisit() [7/63]

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

Definition at line 152 of file strprinter.cpp.

429{
431 s << apply(*x.get_universe());
432 s << " \\ " << apply(*x.get_container());
433 str_ = s.str();
434}

◆ bvisit() [8/63]

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

Definition at line 131 of file strprinter.cpp.

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

◆ bvisit() [9/63]

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

Definition at line 182 of file strprinter.cpp.

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

◆ bvisit() [10/63]

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

Definition at line 133 of file strprinter.cpp.

374{
375 str_ = "Complexes";
376}

◆ bvisit() [11/63]

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

Definition at line 143 of file strprinter.cpp.

458{
460 s << "{" << apply(*x.get_symbol());
461 s << " | " << apply(x.get_condition()) << "}";
462 str_ = s.str();
463}

◆ bvisit() [12/63]

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

Definition at line 176 of file strprinter.cpp.

857{
858 str_ = x.get_name();
859}

◆ bvisit() [13/63]

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

Definition at line 119 of file sbml.cpp.

120{
121 if (eq(x, *E)) {
122 str_ = "exponentiale";
123 } else {
124 str_ = x.get_name();
125 std::transform(str_.begin(), str_.end(), str_.begin(), ::tolower);
126 }
127}
T begin(T... args)
T end(T... args)
T transform(T... args)

◆ bvisit() [14/63]

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

Definition at line 144 of file strprinter.cpp.

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

◆ bvisit() [15/63]

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

Definition at line 179 of file strprinter.cpp.

893{
895 o << "Derivative(" << this->apply(x.get_arg());
896 auto m1 = x.get_symbols();
897 for (const auto &elem : m1) {
898 o << ", " << this->apply(elem);
899 }
900 o << ")";
901 str_ = o.str();
902}

◆ bvisit() [16/63]

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

Definition at line 140 of file strprinter.cpp.

404{
405 str_ = "EmptySet";
406}

◆ bvisit() [17/63]

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

Definition at line 183 of file strprinter.cpp.

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

◆ bvisit() [18/63]

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

Definition at line 141 of file strprinter.cpp.

451{
453 s << x.get_container();
454 str_ = s.str();
455}

◆ bvisit() [19/63]

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

Definition at line 177 of file strprinter.cpp.

874{
875 static const std::vector<std::string> names_ = init_str_printer_names();
877 o << names_[x.get_type_code()];
878 vec_basic vec = x.get_args();
879 o << parenthesize(apply(vec));
880 str_ = o.str();
881}

◆ bvisit() [20/63]

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

Definition at line 129 of file sbml.cpp.

130{
131 static const std::vector<std::string> names_ = init_sbml_printer_names();
133 vec_basic vec = x.get_args();
134 if (x.get_type_code() == SYMENGINE_GAMMA) {
135 // sbml only has factorial, no gamma function
136 o << "factorial(" << apply(vec) << " - 1)";
137 } else if (x.get_type_code() == SYMENGINE_LOG && vec.size() == 2) {
138 // sbml log has order of arguments inverted
139 o << "log(" << apply(vec[1]) << ", " << apply(vec[0]) << ")";
140 } else {
141 o << names_[x.get_type_code()];
142 o << parenthesize(apply(vec));
143 }
144 str_ = o.str();
145}

◆ bvisit() [21/63]

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

Definition at line 178 of file strprinter.cpp.

884{
886 o << x.get_name();
887 vec_basic vec = x.get_args();
888 o << parenthesize(apply(vec));
889 str_ = o.str();
890}

◆ bvisit() [22/63]

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

Definition at line 166 of file strprinter.cpp.

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

◆ bvisit() [23/63]

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

Definition at line 195 of file strprinter.cpp.

1031{
1032 str_ = "I";
1033}

◆ bvisit() [24/63]

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

Definition at line 153 of file strprinter.cpp.

437{
439 s << "{" << apply(*x.get_expr()) << " | ";
440 s << apply(*x.get_symbol());
441 s << " in " << apply(*x.get_baseset()) << "}";
442 str_ = s.str();
443}

◆ bvisit() [25/63]

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

Definition at line 167 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() [26/63]

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

Definition at line 114 of file sbml.cpp.

115{
116 str_ = "inf";
117}

◆ bvisit() [27/63]

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

Definition at line 129 of file strprinter.cpp.

164{
166 s << x.as_integer_class();
167 str_ = s.str();
168}

◆ bvisit() [28/63]

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

Definition at line 136 of file strprinter.cpp.

389{
390 str_ = "Integers";
391}

◆ bvisit() [29/63]

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

Definition at line 151 of file strprinter.cpp.

420{
422 vec_basic vec = x.get_args();
423 s << "Intersection";
424 s << parenthesize(apply(vec));
425 str_ = s.str();
426}

◆ bvisit() [30/63]

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

Definition at line 132 of file strprinter.cpp.

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

◆ bvisit() [31/63]

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

Definition at line 185 of file strprinter.cpp.

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

◆ bvisit() [32/63]

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

Definition at line 165 of file strprinter.cpp.

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

◆ bvisit() [33/63]

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

Definition at line 158 of file strprinter.cpp.

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

◆ bvisit() [34/63]

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

Definition at line 155 of file strprinter.cpp.

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

◆ bvisit() [35/63]

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

Definition at line 168 of file strprinter.cpp.

159{
160 str_ = "nan";
161}

◆ bvisit() [36/63]

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

Definition at line 137 of file strprinter.cpp.

394{
395 str_ = "Naturals";
396}

◆ bvisit() [37/63]

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

Definition at line 138 of file strprinter.cpp.

399{
400 str_ = "Naturals0";
401}

◆ bvisit() [38/63]

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

Definition at line 149 of file strprinter.cpp.

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

◆ bvisit() [39/63]

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

Definition at line 88 of file sbml.cpp.

89{
91 s << "not(" << *x.get_arg() << ")";
92 str_ = s.str();
93}

◆ bvisit() [40/63]

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

Definition at line 193 of file strprinter.cpp.

921{
922 str_ = x.__str__();
923}

◆ bvisit() [41/63]

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

Definition at line 147 of file strprinter.cpp.

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

◆ bvisit() [42/63]

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

Definition at line 62 of file sbml.cpp.

63{
65 const auto &container = x.get_container();
66 s << "or(";
67 s << apply(*container.begin());
68 for (auto it = ++(container.begin()); it != container.end(); ++it) {
69 s << ", " << apply(*it);
70 }
71 s << ")";
72 str_ = s.str();
73}

◆ bvisit() [43/63]

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

Definition at line 139 of file strprinter.cpp.

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

◆ bvisit() [44/63]

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

Definition at line 95 of file sbml.cpp.

96{
98 auto vec = x.get_vec();
99 auto it = vec.begin();
100 s << "piecewise(";
101 while (it != vec.end()) {
102 s << apply((*it).first);
103 s << ", ";
104 s << apply((*it).second);
105 ++it;
106 if (it != vec.end()) {
107 s << ", ";
108 }
109 }
110 s << ")";
111 str_ = s.str();
112}

◆ bvisit() [45/63]

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

Definition at line 156 of file strprinter.cpp.

652{
654 _print_pow(o, x.get_base(), x.get_exp());
655 str_ = o.str();
656}

◆ bvisit() [46/63]

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

Definition at line 130 of file strprinter.cpp.

171{
173 s << x.as_rational_class();
174 str_ = s.str();
175}

◆ bvisit() [47/63]

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

Definition at line 135 of file strprinter.cpp.

384{
385 str_ = "Rationals";
386}

◆ bvisit() [48/63]

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

Definition at line 181 of file strprinter.cpp.

228{
229 str_ = print_double(x.i);
230}

◆ bvisit() [49/63]

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

Definition at line 134 of file strprinter.cpp.

379{
380 str_ = "Reals";
381}

◆ bvisit() [50/63]

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

Definition at line 186 of file strprinter.cpp.

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

◆ bvisit() [51/63]

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

Definition at line 180 of file strprinter.cpp.

905{
906 std::ostringstream o, vars, point;
907 for (auto p = x.get_dict().begin(); p != x.get_dict().end(); p++) {
908 if (p != x.get_dict().begin()) {
909 vars << ", ";
910 point << ", ";
911 }
912 vars << apply(p->first);
913 point << apply(p->second);
914 }
915 o << "Subs(" << apply(x.get_arg()) << ", (" << vars.str() << "), ("
916 << point.str() << "))";
917 str_ = o.str();
918}

◆ bvisit() [52/63]

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

Definition at line 128 of file strprinter.cpp.

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

◆ bvisit() [53/63]

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

Definition at line 194 of file strprinter.cpp.

1023{
1025 vec_basic vec = x.get_args();
1026 o << parenthesize(apply(vec));
1027 str_ = o.str();
1028}

◆ bvisit() [54/63]

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

Definition at line 164 of file strprinter.cpp.

822{
824 if (x.get_dict().size() == 0)
825 s << "0";
826 else
827 s << x.get_poly().__str__(detail::poly_print(x.get_var()));
828 str_ = s.str();
829}

◆ bvisit() [55/63]

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

Definition at line 157 of file strprinter.cpp.

788{
789 str_ = upoly_print<UIntPoly>(x);
790}

◆ bvisit() [56/63]

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

Definition at line 184 of file strprinter.cpp.

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

◆ bvisit() [57/63]

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

Definition at line 150 of file strprinter.cpp.

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

◆ bvisit() [58/63]

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

Definition at line 169 of file strprinter.cpp.

832{
834 o << x.get_poly().__str__(x.get_var()) << " + O(" << x.get_var() << "**"
835 << x.get_degree() << ")";
836 str_ = o.str();
837}

◆ bvisit() [59/63]

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

Definition at line 142 of file strprinter.cpp.

446{
447 str_ = "UniversalSet";
448}

◆ bvisit() [60/63]

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

Definition at line 159 of file strprinter.cpp.

793{
794 str_ = upoly_print<URatPoly>(x);
795}

◆ bvisit() [61/63]

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

Definition at line 148 of file strprinter.cpp.

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

◆ bvisit() [62/63]

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

Definition at line 75 of file sbml.cpp.

76{
78 const auto &container = x.get_container();
79 s << "xor(";
80 s << apply(*container.begin());
81 for (auto it = ++(container.begin()); it != container.end(); ++it) {
82 s << ", " << apply(*it);
83 }
84 s << ")";
85 str_ = s.str();
86}

◆ bvisit() [63/63]

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

Definition at line 196 of file strprinter.cpp.

1036{
1037 str_ = "0";
1038}

Field Documentation

◆ names_

const std::vector<std::string> SymEngine::SbmlPrinter::names_
static

Definition at line 15 of file sbml.h.


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