From b4be7b0f30fbb6178cf4ee83e1b3952e084bd8ca Mon Sep 17 00:00:00 2001 From: Christian Bauer Date: Wed, 13 Aug 2003 20:44:07 +0000 Subject: [PATCH] use new-style print methods --- ginac/clifford.cpp | 1 - ginac/color.cpp | 1 - ginac/constant.cpp | 1 - ginac/expairseq.cpp | 155 ++++++++++++++------------- ginac/expairseq.h | 3 +- ginac/fail.cpp | 1 - ginac/fderivative.cpp | 60 ++++++----- ginac/fderivative.h | 6 +- ginac/idx.cpp | 1 - ginac/indexed.cpp | 1 - ginac/matrix.cpp | 2 +- ginac/matrix.h | 2 +- ginac/ncmul.cpp | 33 +++--- ginac/ncmul.h | 3 +- ginac/numeric.cpp | 237 ++++++++++++++++++++++-------------------- ginac/numeric.h | 10 +- ginac/power.cpp | 169 ++++++++++++++++-------------- ginac/power.h | 8 +- ginac/pseries.cpp | 1 - ginac/symbol.cpp | 1 - ginac/symmetry.cpp | 1 - ginac/tensor.cpp | 1 - ginac/wildcard.cpp | 1 - 23 files changed, 362 insertions(+), 337 deletions(-) diff --git a/ginac/clifford.cpp b/ginac/clifford.cpp index ff834bce..3dbad50f 100644 --- a/ginac/clifford.cpp +++ b/ginac/clifford.cpp @@ -34,7 +34,6 @@ #include "relational.h" #include "operators.h" #include "mul.h" -#include "print.h" #include "archive.h" #include "utils.h" diff --git a/ginac/color.cpp b/ginac/color.cpp index 1fb8e97d..e84dcdba 100644 --- a/ginac/color.cpp +++ b/ginac/color.cpp @@ -32,7 +32,6 @@ #include "mul.h" #include "power.h" // for sqrt() #include "symbol.h" -#include "print.h" #include "archive.h" #include "utils.h" diff --git a/ginac/constant.cpp b/ginac/constant.cpp index baf10805..c8c93040 100644 --- a/ginac/constant.cpp +++ b/ginac/constant.cpp @@ -27,7 +27,6 @@ #include "constant.h" #include "numeric.h" #include "ex.h" -#include "print.h" #include "archive.h" #include "utils.h" diff --git a/ginac/expairseq.cpp b/ginac/expairseq.cpp index fe096814..d2ff8fb5 100644 --- a/ginac/expairseq.cpp +++ b/ginac/expairseq.cpp @@ -31,7 +31,6 @@ #include "power.h" #include "relational.h" #include "wildcard.h" -#include "print.h" #include "archive.h" #include "operators.h" #include "utils.h" @@ -43,7 +42,10 @@ namespace GiNaC { -GINAC_IMPLEMENT_REGISTERED_CLASS(expairseq, basic) +GINAC_IMPLEMENT_REGISTERED_CLASS_OPT(expairseq, basic, + print_func(&expairseq::do_print). + print_func(&expairseq::do_print_tree)) + ////////// // helper classes @@ -177,88 +179,85 @@ DEFAULT_UNARCHIVE(expairseq) // public -void expairseq::print(const print_context &c, unsigned level) const +void expairseq::do_print(const print_context & c, unsigned level) const { - if (is_a(c)) { - - unsigned delta_indent = static_cast(c).delta_indent; - - c.s << std::string(level, ' ') << class_name() - << std::hex << ", hash=0x" << hashvalue << ", flags=0x" << flags << std::dec - << ", nops=" << nops() - << std::endl; - size_t num = seq.size(); - for (size_t i=0; i 0) { - c.s << std::string(level + delta_indent, ' ') - << "bin " << i << " with entries "; - for (epplist::const_iterator it=hashtab[i].begin(); - it!=hashtab[i].end(); ++it) { - c.s << *it-seq.begin() << " "; - ++this_bin_fill; - } - c.s << std::endl; - cum_fill += this_bin_fill; - cum_fill_sq += this_bin_fill*this_bin_fill; + unsigned count[MAXCOUNT+1]; + for (int i=0; i 0) { + c.s << std::string(level + c.delta_indent, ' ') + << "bin " << i << " with entries "; + for (epplist::const_iterator it=hashtab[i].begin(); + it!=hashtab[i].end(); ++it) { + c.s << *it-seq.begin() << " "; + ++this_bin_fill; } - if (this_bin_fill0) - fact *= k; - double prob = std::pow(lambda,k)/fact * std::exp(-lambda); - cum_prob += prob; - c.s << std::string(level + delta_indent, ' ') << "bins with " << k << " entries: " - << int(1000.0*count[k]/hashtabsize)/10.0 << "% (expected: " - << int(prob*1000)/10.0 << ")" << std::endl; + c.s << std::endl; + cum_fill += this_bin_fill; + cum_fill_sq += this_bin_fill*this_bin_fill; } - c.s << std::string(level + delta_indent, ' ') << "bins with more entries: " - << int(1000.0*count[MAXCOUNT]/hashtabsize)/10.0 << "% (expected: " - << int((1-cum_prob)*1000)/10.0 << ")" << std::endl; - - c.s << std::string(level + delta_indent, ' ') << "variance: " - << 1.0/hashtabsize*cum_fill_sq-(1.0/hashtabsize*cum_fill)*(1.0/hashtabsize*cum_fill) - << std::endl; - c.s << std::string(level + delta_indent, ' ') << "average fill: " - << (1.0*cum_fill)/hashtabsize - << " (should be equal to " << (1.0*seq.size())/hashtabsize << ")" << std::endl; -#endif // EXPAIRSEQ_USE_HASHTAB - - } else { - c.s << "[["; - printseq(c, ',', precedence(), level); - c.s << "]]"; + if (this_bin_fill0) + fact *= k; + double prob = std::pow(lambda,k)/fact * std::exp(-lambda); + cum_prob += prob; + c.s << std::string(level + c.delta_indent, ' ') << "bins with " << k << " entries: " + << int(1000.0*count[k]/hashtabsize)/10.0 << "% (expected: " + << int(prob*1000)/10.0 << ")" << std::endl; } + c.s << std::string(level + c.delta_indent, ' ') << "bins with more entries: " + << int(1000.0*count[MAXCOUNT]/hashtabsize)/10.0 << "% (expected: " + << int((1-cum_prob)*1000)/10.0 << ")" << std::endl; + + c.s << std::string(level + c.delta_indent, ' ') << "variance: " + << 1.0/hashtabsize*cum_fill_sq-(1.0/hashtabsize*cum_fill)*(1.0/hashtabsize*cum_fill) + << std::endl; + c.s << std::string(level + c.delta_indent, ' ') << "average fill: " + << (1.0*cum_fill)/hashtabsize + << " (should be equal to " << (1.0*seq.size())/hashtabsize << ")" << std::endl; +#endif // EXPAIRSEQ_USE_HASHTAB } bool expairseq::info(unsigned inf) const diff --git a/ginac/expairseq.h b/ginac/expairseq.h index b6f9bc7e..6f099b40 100644 --- a/ginac/expairseq.h +++ b/ginac/expairseq.h @@ -70,7 +70,6 @@ public: // functions overriding virtual functions from base classes public: - void print(const print_context & c, unsigned level = 0) const; unsigned precedence() const {return 10;} bool info(unsigned inf) const; size_t nops() const; @@ -110,6 +109,8 @@ protected: // non-virtual functions in this class protected: + void do_print(const print_context & c, unsigned level) const; + void do_print_tree(const print_tree & c, unsigned level) const; void construct_from_2_ex_via_exvector(const ex & lh, const ex & rh); void construct_from_2_ex(const ex & lh, const ex & rh); void construct_from_2_expairseq(const expairseq & s1, diff --git a/ginac/fail.cpp b/ginac/fail.cpp index 08ee89aa..ab109d70 100644 --- a/ginac/fail.cpp +++ b/ginac/fail.cpp @@ -24,7 +24,6 @@ #include #include "fail.h" -#include "print.h" #include "archive.h" #include "utils.h" diff --git a/ginac/fderivative.cpp b/ginac/fderivative.cpp index 4a93de49..1c766996 100644 --- a/ginac/fderivative.cpp +++ b/ginac/fderivative.cpp @@ -24,13 +24,14 @@ #include "fderivative.h" #include "operators.h" -#include "print.h" #include "archive.h" #include "utils.h" namespace GiNaC { -GINAC_IMPLEMENT_REGISTERED_CLASS(fderivative, function) +GINAC_IMPLEMENT_REGISTERED_CLASS_OPT(fderivative, function, + print_func(&fderivative::do_print). + print_func(&fderivative::do_print_tree)) ////////// // default constructor @@ -94,35 +95,32 @@ DEFAULT_UNARCHIVE(fderivative) // functions overriding virtual functions from base classes ////////// -void fderivative::print(const print_context & c, unsigned level) const -{ - if (is_a(c)) { - - c.s << std::string(level, ' ') << class_name() << " " - << registered_functions()[serial].name - << std::hex << ", hash=0x" << hashvalue << ", flags=0x" << flags << std::dec - << ", nops=" << nops() - << ", params="; - paramset::const_iterator i = parameter_set.begin(), end = parameter_set.end(); - --end; - while (i != end) - c.s << *i++ << ","; - c.s << *i << std::endl; - unsigned delta_indent = static_cast(c).delta_indent; - for (size_t i=0; i(&ncmul::do_print). + print_func(&basic::do_print_tree). + print_func(&ncmul::do_print_csrc). + print_func(&ncmul::do_print_csrc)) + ////////// // default constructor @@ -102,26 +106,15 @@ DEFAULT_ARCHIVING(ncmul) // public -void ncmul::print(const print_context & c, unsigned level) const +void ncmul::do_print(const print_context & c, unsigned level) const { - if (is_a(c)) { - - inherited::print(c, level); - - } else if (is_a(c) || is_a(c)) { - - c.s << class_name() << "("; - exvector::const_iterator it = seq.begin(), itend = seq.end()-1; - while (it != itend) { - it->print(c, precedence()); - c.s << ","; - it++; - } - it->print(c, precedence()); - c.s << ")"; + printseq(c, '(', '*', ')', precedence(), level); +} - } else - printseq(c, '(', '*', ')', precedence(), level); +void ncmul::do_print_csrc(const print_context & c, unsigned level) const +{ + c.s << class_name(); + printseq(c, '(', ',', ')', precedence(), precedence()); } bool ncmul::info(unsigned inf) const diff --git a/ginac/ncmul.h b/ginac/ncmul.h index 072ebfbb..57cb08c7 100644 --- a/ginac/ncmul.h +++ b/ginac/ncmul.h @@ -53,7 +53,6 @@ public: // functions overriding virtual functions from base classes public: - void print(const print_context & c, unsigned level = 0) const; unsigned precedence() const {return 50;} bool info(unsigned inf) const; int degree(const ex & s) const; @@ -76,6 +75,8 @@ protected: // non-virtual functions in this class protected: + void do_print(const print_context & c, unsigned level) const; + void do_print_csrc(const print_context & c, unsigned level) const; size_t count_factors(const ex & e) const; void append_factors(exvector & v, const ex & e) const; exvector expandchildren(unsigned options) const; diff --git a/ginac/numeric.cpp b/ginac/numeric.cpp index c69a117d..6074aeaf 100644 --- a/ginac/numeric.cpp +++ b/ginac/numeric.cpp @@ -34,7 +34,6 @@ #include "numeric.h" #include "ex.h" -#include "print.h" #include "operators.h" #include "archive.h" #include "tostring.h" @@ -61,7 +60,13 @@ namespace GiNaC { -GINAC_IMPLEMENT_REGISTERED_CLASS(numeric, basic) +GINAC_IMPLEMENT_REGISTERED_CLASS_OPT(numeric, basic, + print_func(&numeric::do_print). + print_func(&numeric::do_print_latex). + print_func(&numeric::do_print_csrc). + print_func(&numeric::do_print_csrc_cl_N). + print_func(&numeric::do_print_tree). + print_func(&numeric::do_print_python_repr)) ////////// // default constructor @@ -410,140 +415,148 @@ static void print_real_cl_N(const print_context & c, const cln::cl_R & x) } } -/** This method adds to the output so it blends more consistently together - * with the other routines and produces something compatible to ginsh input. - * - * @see print_real_number() */ -void numeric::print(const print_context & c, unsigned level) const +void numeric::print_numeric(const print_context & c, const char *par_open, const char *par_close, const char *imag_sym, const char *mul_sym, unsigned level) const { - if (is_a(c)) { + const cln::cl_R r = cln::realpart(cln::the(value)); + const cln::cl_R i = cln::imagpart(cln::the(value)); - c.s << std::string(level, ' ') << cln::the(value) - << " (" << class_name() << ")" - << std::hex << ", hash=0x" << hashvalue << ", flags=0x" << flags << std::dec - << std::endl; + if (cln::zerop(i)) { - } else if (is_a(c)) { + // case 1, real: x or -x + if ((precedence() <= level) && (!this->is_nonneg_integer())) { + c.s << par_open; + print_real_number(c, r); + c.s << par_close; + } else { + print_real_number(c, r); + } - // CLN output - if (this->is_real()) { + } else { + if (cln::zerop(r)) { - // Real number - print_real_cl_N(c, cln::the(value)); + // case 2, imaginary: y*I or -y*I + if (i == 1) + c.s << imag_sym; + else { + if (precedence()<=level) + c.s << par_open; + if (i == -1) + c.s << "-" << imag_sym; + else { + print_real_number(c, i); + c.s << mul_sym << imag_sym; + } + if (precedence()<=level) + c.s << par_close; + } } else { - // Complex number - c.s << "cln::complex("; - print_real_cl_N(c, cln::realpart(cln::the(value))); - c.s << ","; - print_real_cl_N(c, cln::imagpart(cln::the(value))); - c.s << ")"; + // case 3, complex: x+y*I or x-y*I or -x+y*I or -x-y*I + if (precedence() <= level) + c.s << par_open; + print_real_number(c, r); + if (i < 0) { + if (i == -1) { + c.s << "-" << imag_sym; + } else { + print_real_number(c, i); + c.s << mul_sym << imag_sym; + } + } else { + if (i == 1) { + c.s << "+" << imag_sym; + } else { + c.s << "+"; + print_real_number(c, i); + c.s << mul_sym << imag_sym; + } + } + if (precedence() <= level) + c.s << par_close; } + } +} - } else if (is_a(c)) { +void numeric::do_print(const print_context & c, unsigned level) const +{ + print_numeric(c, "(", ")", "I", "*", level); +} - // C++ source output - std::ios::fmtflags oldflags = c.s.flags(); - c.s.setf(std::ios::scientific); - int oldprec = c.s.precision(); +void numeric::do_print_latex(const print_latex & c, unsigned level) const +{ + print_numeric(c, "{(", ")}", "i", " ", level); +} - // Set precision - if (is_a(c)) - c.s.precision(std::numeric_limits::digits10 + 1); - else - c.s.precision(std::numeric_limits::digits10 + 1); +void numeric::do_print_csrc(const print_csrc & c, unsigned level) const +{ + std::ios::fmtflags oldflags = c.s.flags(); + c.s.setf(std::ios::scientific); + int oldprec = c.s.precision(); - if (this->is_real()) { + // Set precision + if (is_a(c)) + c.s.precision(std::numeric_limits::digits10 + 1); + else + c.s.precision(std::numeric_limits::digits10 + 1); - // Real number - print_real_csrc(c, cln::the(value)); + if (this->is_real()) { - } else { + // Real number + print_real_csrc(c, cln::the(value)); - // Complex number - c.s << "std::complex<"; - if (is_a(c)) - c.s << "double>("; - else - c.s << "float>("; + } else { - print_real_csrc(c, cln::realpart(cln::the(value))); - c.s << ","; - print_real_csrc(c, cln::imagpart(cln::the(value))); - c.s << ")"; - } + // Complex number + c.s << "std::complex<"; + if (is_a(c)) + c.s << "double>("; + else + c.s << "float>("; + + print_real_csrc(c, cln::realpart(cln::the(value))); + c.s << ","; + print_real_csrc(c, cln::imagpart(cln::the(value))); + c.s << ")"; + } + + c.s.flags(oldflags); + c.s.precision(oldprec); +} - c.s.flags(oldflags); - c.s.precision(oldprec); +void numeric::do_print_csrc_cl_N(const print_csrc_cl_N & c, unsigned level) const +{ + if (this->is_real()) { + + // Real number + print_real_cl_N(c, cln::the(value)); } else { - const std::string par_open = is_a(c) ? "{(" : "("; - const std::string par_close = is_a(c) ? ")}" : ")"; - const std::string imag_sym = is_a(c) ? "i" : "I"; - const std::string mul_sym = is_a(c) ? " " : "*"; - const cln::cl_R r = cln::realpart(cln::the(value)); - const cln::cl_R i = cln::imagpart(cln::the(value)); - - if (is_a(c)) - c.s << class_name() << "('"; - if (cln::zerop(i)) { - // case 1, real: x or -x - if ((precedence() <= level) && (!this->is_nonneg_integer())) { - c.s << par_open; - print_real_number(c, r); - c.s << par_close; - } else { - print_real_number(c, r); - } - } else { - if (cln::zerop(r)) { - // case 2, imaginary: y*I or -y*I - if (i==1) - c.s << imag_sym; - else { - if (precedence()<=level) - c.s << par_open; - if (i == -1) - c.s << "-" << imag_sym; - else { - print_real_number(c, i); - c.s << mul_sym+imag_sym; - } - if (precedence()<=level) - c.s << par_close; - } - } else { - // case 3, complex: x+y*I or x-y*I or -x+y*I or -x-y*I - if (precedence() <= level) - c.s << par_open; - print_real_number(c, r); - if (i < 0) { - if (i == -1) { - c.s << "-"+imag_sym; - } else { - print_real_number(c, i); - c.s << mul_sym+imag_sym; - } - } else { - if (i == 1) { - c.s << "+"+imag_sym; - } else { - c.s << "+"; - print_real_number(c, i); - c.s << mul_sym+imag_sym; - } - } - if (precedence() <= level) - c.s << par_close; - } - } - if (is_a(c)) - c.s << "')"; + // Complex number + c.s << "cln::complex("; + print_real_cl_N(c, cln::realpart(cln::the(value))); + c.s << ","; + print_real_cl_N(c, cln::imagpart(cln::the(value))); + c.s << ")"; } } +void numeric::do_print_tree(const print_tree & c, unsigned level) const +{ + c.s << std::string(level, ' ') << cln::the(value) + << " (" << class_name() << ")" + << std::hex << ", hash=0x" << hashvalue << ", flags=0x" << flags << std::dec + << std::endl; +} + +void numeric::do_print_python_repr(const print_python_repr & c, unsigned level) const +{ + c.s << class_name() << "('"; + print_numeric(c, "(", ")", "I", "*", level); + c.s << "')"; +} + bool numeric::info(unsigned inf) const { switch (inf) { diff --git a/ginac/numeric.h b/ginac/numeric.h index 691d7de5..b7c1e37d 100644 --- a/ginac/numeric.h +++ b/ginac/numeric.h @@ -95,7 +95,6 @@ public: // functions overriding virtual functions from base classes public: - void print(const print_context & c, unsigned level = 0) const; unsigned precedence() const {return 30;} bool info(unsigned inf) const; int degree(const ex & s) const; @@ -174,6 +173,15 @@ public: // converting routines for interfacing with CLN: numeric(const cln::cl_N &z); +protected: + void print_numeric(const print_context & c, const char *par_open, const char *par_close, const char *imag_sym, const char *mul_sym, unsigned level) const; + void do_print(const print_context & c, unsigned level) const; + void do_print_latex(const print_latex & c, unsigned level) const; + void do_print_csrc(const print_csrc & c, unsigned level) const; + void do_print_csrc_cl_N(const print_csrc_cl_N & c, unsigned level) const; + void do_print_tree(const print_tree & c, unsigned level) const; + void do_print_python_repr(const print_python_repr & c, unsigned level) const; + // member variables protected: diff --git a/ginac/power.cpp b/ginac/power.cpp index fab41d83..1aade2e6 100644 --- a/ginac/power.cpp +++ b/ginac/power.cpp @@ -38,13 +38,17 @@ #include "indexed.h" #include "symbol.h" #include "lst.h" -#include "print.h" #include "archive.h" #include "utils.h" namespace GiNaC { -GINAC_IMPLEMENT_REGISTERED_CLASS(power, basic) +GINAC_IMPLEMENT_REGISTERED_CLASS_OPT(power, basic, + print_func(&power::do_print_dflt). + print_func(&power::do_print_latex). + print_func(&power::do_print_csrc). + print_func(&power::do_print_python). + print_func(&power::do_print_python_repr)) typedef std::vector intvector; @@ -85,6 +89,53 @@ DEFAULT_UNARCHIVE(power) // public +void power::print_power(const print_context & c, const char *powersymbol, const char *openbrace, const char *closebrace, unsigned level) const +{ + // Ordinary output of powers using '^' or '**' + if (precedence() <= level) + c.s << openbrace << '('; + basis.print(c, precedence()); + c.s << powersymbol; + c.s << openbrace; + exponent.print(c, precedence()); + c.s << closebrace; + if (precedence() <= level) + c.s << closebrace << ')'; +} + +void power::do_print_dflt(const print_dflt & c, unsigned level) const +{ + if (exponent.is_equal(_ex1_2)) { + + // Square roots are printed in a special way + c.s << "sqrt("; + basis.print(c); + c.s << ')'; + + } else + print_power(c, "^", "", "", level); +} + +void power::do_print_latex(const print_latex & c, unsigned level) const +{ + if (is_exactly_a(exponent) && ex_to(exponent).is_negative()) { + + // Powers with negative numeric exponents are printed as fractions + c.s << "\\frac{1}{"; + power(basis, -exponent).eval().print(c); + c.s << '}'; + + } else if (exponent.is_equal(_ex1_2)) { + + // Square roots are printed in a special way + c.s << "\\sqrt{"; + basis.print(c); + c.s << '}'; + + } else + print_power(c, "^", "{", "}", level); +} + static void print_sym_pow(const print_context & c, const symbol &x, int exp) { // Optimal output of integer powers of symbols to aid compiler CSE. @@ -109,96 +160,58 @@ static void print_sym_pow(const print_context & c, const symbol &x, int exp) } } -void power::print(const print_context & c, unsigned level) const +void power::do_print_csrc(const print_csrc & c, unsigned level) const { - if (is_a(c)) { - - inherited::print(c, level); - - } else if (is_a(c)) { - - // Integer powers of symbols are printed in a special, optimized way - if (exponent.info(info_flags::integer) - && (is_a(basis) || is_a(basis))) { - int exp = ex_to(exponent).to_int(); - if (exp > 0) - c.s << '('; - else { - exp = -exp; - if (is_a(c)) - c.s << "recip("; - else - c.s << "1.0/("; - } - print_sym_pow(c, ex_to(basis), exp); - c.s << ')'; - - // ^-1 is printed as "1.0/" or with the recip() function of CLN - } else if (exponent.is_equal(_ex_1)) { + // Integer powers of symbols are printed in a special, optimized way + if (exponent.info(info_flags::integer) + && (is_a(basis) || is_a(basis))) { + int exp = ex_to(exponent).to_int(); + if (exp > 0) + c.s << '('; + else { + exp = -exp; if (is_a(c)) c.s << "recip("; else c.s << "1.0/("; - basis.print(c); - c.s << ')'; - - // Otherwise, use the pow() or expt() (CLN) functions - } else { - if (is_a(c)) - c.s << "expt("; - else - c.s << "pow("; - basis.print(c); - c.s << ','; - exponent.print(c); - c.s << ')'; } + print_sym_pow(c, ex_to(basis), exp); + c.s << ')'; - } else if (is_a(c)) { + // ^-1 is printed as "1.0/" or with the recip() function of CLN + } else if (exponent.is_equal(_ex_1)) { + if (is_a(c)) + c.s << "recip("; + else + c.s << "1.0/("; + basis.print(c); + c.s << ')'; - c.s << class_name() << '('; + // Otherwise, use the pow() or expt() (CLN) functions + } else { + if (is_a(c)) + c.s << "expt("; + else + c.s << "pow("; basis.print(c); c.s << ','; exponent.print(c); c.s << ')'; + } +} - } else { - - bool is_tex = is_a(c); - - if (is_tex && is_exactly_a(exponent) && ex_to(exponent).is_negative()) { - - // Powers with negative numeric exponents are printed as fractions in TeX - c.s << "\\frac{1}{"; - power(basis, -exponent).eval().print(c); - c.s << "}"; - - } else if (exponent.is_equal(_ex1_2)) { - - // Square roots are printed in a special way - c.s << (is_tex ? "\\sqrt{" : "sqrt("); - basis.print(c); - c.s << (is_tex ? '}' : ')'); - - } else { +void power::do_print_python(const print_python & c, unsigned level) const +{ + print_power(c, "**", "", "", level); +} - // Ordinary output of powers using '^' or '**' - if (precedence() <= level) - c.s << (is_tex ? "{(" : "("); - basis.print(c, precedence()); - if (is_a(c)) - c.s << "**"; - else - c.s << '^'; - if (is_tex) - c.s << '{'; - exponent.print(c, precedence()); - if (is_tex) - c.s << '}'; - if (precedence() <= level) - c.s << (is_tex ? ")}" : ")"); - } - } +void power::do_print_python_repr(const print_python_repr & c, unsigned level) const +{ + c.s << class_name() << '('; + basis.print(c); + c.s << ','; + exponent.print(c); + c.s << ')'; } bool power::info(unsigned inf) const diff --git a/ginac/power.h b/ginac/power.h index f808f97f..4fdbf44d 100644 --- a/ginac/power.h +++ b/ginac/power.h @@ -48,7 +48,6 @@ public: // functions overriding virtual functions from base classes public: - void print(const print_context & c, unsigned level = 0) const; unsigned precedence() const {return 60;} bool info(unsigned inf) const; size_t nops() const; @@ -78,6 +77,13 @@ protected: // non-virtual functions in this class protected: + void print_power(const print_context & c, const char *powersymbol, const char *openbrace, const char *closebrace, unsigned level) const; + void do_print_dflt(const print_dflt & c, unsigned level) const; + void do_print_latex(const print_latex & c, unsigned level) const; + void do_print_csrc(const print_csrc & c, unsigned level) const; + void do_print_python(const print_python & c, unsigned level) const; + void do_print_python_repr(const print_python_repr & c, unsigned level) const; + ex expand_add(const add & a, int n) const; ex expand_add_2(const add & a) const; ex expand_mul(const mul & m, const numeric & n) const; diff --git a/ginac/pseries.cpp b/ginac/pseries.cpp index 48dfa1eb..224d28dc 100644 --- a/ginac/pseries.cpp +++ b/ginac/pseries.cpp @@ -33,7 +33,6 @@ #include "relational.h" #include "operators.h" #include "symbol.h" -#include "print.h" #include "archive.h" #include "utils.h" diff --git a/ginac/symbol.cpp b/ginac/symbol.cpp index 1ed94f3d..31fc1d66 100644 --- a/ginac/symbol.cpp +++ b/ginac/symbol.cpp @@ -25,7 +25,6 @@ #include "symbol.h" #include "lst.h" -#include "print.h" #include "archive.h" #include "tostring.h" #include "utils.h" diff --git a/ginac/symmetry.cpp b/ginac/symmetry.cpp index 6a50fe1d..7828c273 100644 --- a/ginac/symmetry.cpp +++ b/ginac/symmetry.cpp @@ -28,7 +28,6 @@ #include "lst.h" #include "numeric.h" // for factorial() #include "operators.h" -#include "print.h" #include "archive.h" #include "utils.h" diff --git a/ginac/tensor.cpp b/ginac/tensor.cpp index a682f2dd..07605e7a 100644 --- a/ginac/tensor.cpp +++ b/ginac/tensor.cpp @@ -33,7 +33,6 @@ #include "lst.h" #include "numeric.h" #include "matrix.h" -#include "print.h" #include "archive.h" #include "utils.h" diff --git a/ginac/wildcard.cpp b/ginac/wildcard.cpp index a0d59349..a538838b 100644 --- a/ginac/wildcard.cpp +++ b/ginac/wildcard.cpp @@ -23,7 +23,6 @@ #include #include "wildcard.h" -#include "print.h" #include "archive.h" #include "utils.h" -- 2.44.0