X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?p=ginac.git;a=blobdiff_plain;f=ginac%2Fpseries.cpp;h=1477449c0bf3233f6f829549c14ad46cf3515f15;hp=a4f96d97113e4a51d4bc449f1aa915d09fd12774;hb=a4294a62590d45ad81e66ce59101982dc83dba51;hpb=06eb6b761f4b9d9eed4decd8ed50d94b40b94a0e diff --git a/ginac/pseries.cpp b/ginac/pseries.cpp index a4f96d97..1477449c 100644 --- a/ginac/pseries.cpp +++ b/ginac/pseries.cpp @@ -142,9 +142,12 @@ void pseries::print(const print_context & c, unsigned level) const } else { - if (precedence <= level) + if (precedence() <= level) c.s << "("; - + + std::string par_open = is_of_type(c, print_latex) ? "{(" : "("; + std::string par_close = is_of_type(c, print_latex) ? ")}" : ")"; + // objects of type pseries must not have any zero entries, so the // trivial (zero) pseries needs a special treatment here: if (seq.size() == 0) @@ -159,34 +162,43 @@ void pseries::print(const print_context & c, unsigned level) const i->rest.info(info_flags::positive)) { i->rest.print(c); } else { - c.s << '('; + c.s << par_open; i->rest.print(c); - c.s << ')'; + c.s << par_close; } // print 'coeff', something like (x-1)^42 if (!i->coeff.is_zero()) { - c.s << '*'; + if (is_of_type(c, print_latex)) + c.s << ' '; + else + c.s << '*'; if (!point.is_zero()) { - c.s << '('; + c.s << par_open; (var-point).print(c); - c.s << ')'; + c.s << par_close; } else var.print(c); if (i->coeff.compare(_ex1())) { c.s << '^'; if (i->coeff.info(info_flags::negative)) { - c.s << '('; - i->coeff.print(c); - c.s << ')'; - } else + c.s << par_open; i->coeff.print(c); + c.s << par_close; + } else { + if (is_of_type(c, print_latex)) { + c.s << '{'; + i->coeff.print(c); + c.s << '}'; + } else + i->coeff.print(c); + } } } } else Order(power(var-point,i->coeff)).print(c); } - if (precedence <= level) + if (precedence() <= level) c.s << ")"; } } @@ -230,7 +242,6 @@ unsigned pseries::nops(void) const return seq.size(); } - /** Return the ith term in the series when represented as a sum. */ ex pseries::op(int i) const { @@ -239,13 +250,11 @@ ex pseries::op(int i) const return seq[i].rest * power(var - point, seq[i].coeff); } - ex &pseries::let_op(int i) { throw (std::logic_error("let_op not defined for pseries")); } - /** Return degree of highest power of the series. This is usually the exponent * of the Order term. If s is not the expansion variable of the series, the * series is examined termwise. */ @@ -339,12 +348,11 @@ ex pseries::coeff(const ex &s, int n) const } /** Does nothing. */ -ex pseries::collect(const ex &s) const +ex pseries::collect(const ex &s, bool distributed) const { return *this; } - /** Evaluate coefficients. */ ex pseries::eval(int level) const { @@ -365,7 +373,6 @@ ex pseries::eval(int level) const return (new pseries(relational(var,point), new_seq))->setflag(status_flags::dynallocated | status_flags::evaluated); } - /** Evaluate coefficients numerically. */ ex pseries::evalf(int level) const { @@ -386,14 +393,13 @@ ex pseries::evalf(int level) const return (new pseries(relational(var,point), new_seq))->setflag(status_flags::dynallocated | status_flags::evaluated); } - -ex pseries::subs(const lst & ls, const lst & lr) const +ex pseries::subs(const lst & ls, const lst & lr, bool no_pattern) const { // If expansion variable is being substituted, convert the series to a // polynomial and do the substitution there because the result might // no longer be a power series if (ls.has(var)) - return convert_to_poly(true).subs(ls, lr); + return convert_to_poly(true).subs(ls, lr, no_pattern); // Otherwise construct a new series with substituted coefficients and // expansion point @@ -401,13 +407,12 @@ ex pseries::subs(const lst & ls, const lst & lr) const newseq.reserve(seq.size()); epvector::const_iterator it = seq.begin(), itend = seq.end(); while (it != itend) { - newseq.push_back(expair(it->rest.subs(ls, lr), it->coeff)); + newseq.push_back(expair(it->rest.subs(ls, lr, no_pattern), it->coeff)); ++it; } - return (new pseries(relational(var,point.subs(ls, lr)), newseq))->setflag(status_flags::dynallocated); + return (new pseries(relational(var,point.subs(ls, lr, no_pattern)), newseq))->setflag(status_flags::dynallocated); } - /** Implementation of ex::expand() for a power series. It expands all the * terms individually and returns the resulting series as a new pseries. */ ex pseries::expand(unsigned options) const @@ -422,7 +427,6 @@ ex pseries::expand(unsigned options) const ->setflag(status_flags::dynallocated | status_flags::expanded); } - /** Implementation of ex::diff() for a power series. It treats the series as a * polynomial. * @see ex::diff */ @@ -449,10 +453,6 @@ ex pseries::derivative(const symbol & s) const } } - -/** Convert a pseries object to an ordinary polynomial. - * - * @param no_order flag: discard higher order terms */ ex pseries::convert_to_poly(bool no_order) const { ex e; @@ -469,9 +469,6 @@ ex pseries::convert_to_poly(bool no_order) const return e; } - -/** Returns true if there is no order term, i.e. the series terminates and - * false otherwise. */ bool pseries::is_terminating(void) const { return seq.size() == 0 || !is_order_function((seq.end()-1)->rest); @@ -493,7 +490,7 @@ ex basic::series(const relational & r, int order, unsigned options) const const symbol &s = static_cast(*r.lhs().bp); if (!coeff.is_zero()) - seq.push_back(expair(coeff, numeric(0))); + seq.push_back(expair(coeff, _ex0())); int n; for (n=1; n