* methods for series expansion. */
/*
- * GiNaC Copyright (C) 1999-2003 Johannes Gutenberg University Mainz, Germany
+ * GiNaC Copyright (C) 1999-2004 Johannes Gutenberg University Mainz, Germany
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#include "relational.h"
#include "operators.h"
#include "symbol.h"
-#include "print.h"
#include "archive.h"
#include "utils.h"
namespace GiNaC {
-GINAC_IMPLEMENT_REGISTERED_CLASS(pseries, basic)
+GINAC_IMPLEMENT_REGISTERED_CLASS_OPT(pseries, basic,
+ print_func<print_context>(&pseries::do_print).
+ print_func<print_latex>(&pseries::do_print_latex).
+ print_func<print_tree>(&pseries::do_print_tree).
+ print_func<print_python>(&pseries::do_print_python).
+ print_func<print_python_repr>(&pseries::do_print_python_repr))
/*
// functions overriding virtual functions from base classes
//////////
-void pseries::print(const print_context & c, unsigned level) const
+void pseries::print_series(const print_context & c, const char *openbrace, const char *closebrace, const char *mul_sym, const char *pow_sym, unsigned level) const
{
- if (is_a<print_tree>(c)) {
+ if (precedence() <= level)
+ c.s << '(';
+
+ // objects of type pseries must not have any zero entries, so the
+ // trivial (zero) pseries needs a special treatment here:
+ if (seq.empty())
+ c.s << '0';
- c.s << std::string(level, ' ') << class_name()
- << std::hex << ", hash=0x" << hashvalue << ", flags=0x" << flags << std::dec
- << std::endl;
- unsigned delta_indent = static_cast<const print_tree &>(c).delta_indent;
- size_t num = seq.size();
- for (size_t i=0; i<num; ++i) {
- seq[i].rest.print(c, level + delta_indent);
- seq[i].coeff.print(c, level + delta_indent);
- c.s << std::string(level + delta_indent, ' ') << "-----" << std::endl;
- }
- var.print(c, level + delta_indent);
- point.print(c, level + delta_indent);
+ epvector::const_iterator i = seq.begin(), end = seq.end();
+ while (i != end) {
- } else if (is_a<print_python_repr>(c)) {
- c.s << class_name() << "(relational(";
- var.print(c);
- c.s << ',';
- point.print(c);
- c.s << "),[";
- size_t num = seq.size();
- for (size_t i=0; i<num; ++i) {
- if (i)
- c.s << ',';
- c.s << '(';
- seq[i].rest.print(c);
- c.s << ',';
- seq[i].coeff.print(c);
- c.s << ')';
- }
- c.s << "])";
- } else {
+ // print a sign, if needed
+ if (i != seq.begin())
+ c.s << '+';
- if (precedence() <= level)
- c.s << "(";
-
- std::string par_open = is_a<print_latex>(c) ? "{(" : "(";
- std::string par_close = is_a<print_latex>(c) ? ")}" : ")";
-
- // objects of type pseries must not have any zero entries, so the
- // trivial (zero) pseries needs a special treatment here:
- if (seq.empty())
- c.s << '0';
- epvector::const_iterator i = seq.begin(), end = seq.end();
- while (i != end) {
- // print a sign, if needed
- if (i != seq.begin())
- c.s << '+';
- if (!is_order_function(i->rest)) {
- // print 'rest', i.e. the expansion coefficient
- if (i->rest.info(info_flags::numeric) &&
- i->rest.info(info_flags::positive)) {
- i->rest.print(c);
- } else {
- c.s << par_open;
- i->rest.print(c);
- c.s << par_close;
- }
- // print 'coeff', something like (x-1)^42
- if (!i->coeff.is_zero()) {
- if (is_a<print_latex>(c))
- c.s << ' ';
- else
- c.s << '*';
- if (!point.is_zero()) {
- c.s << par_open;
- (var-point).print(c);
- c.s << par_close;
+ if (!is_order_function(i->rest)) {
+
+ // print 'rest', i.e. the expansion coefficient
+ if (i->rest.info(info_flags::numeric) &&
+ i->rest.info(info_flags::positive)) {
+ i->rest.print(c);
+ } else {
+ c.s << openbrace << '(';
+ i->rest.print(c);
+ c.s << ')' << closebrace;
+ }
+
+ // print 'coeff', something like (x-1)^42
+ if (!i->coeff.is_zero()) {
+ c.s << mul_sym;
+ if (!point.is_zero()) {
+ c.s << openbrace << '(';
+ (var-point).print(c);
+ c.s << ')' << closebrace;
+ } else
+ var.print(c);
+ if (i->coeff.compare(_ex1)) {
+ c.s << pow_sym;
+ c.s << openbrace;
+ if (i->coeff.info(info_flags::negative)) {
+ c.s << '(';
+ i->coeff.print(c);
+ c.s << ')';
} else
- var.print(c);
- if (i->coeff.compare(_ex1)) {
- if (is_a<print_python>(c))
- c.s << "**";
- else
- c.s << '^';
- if (i->coeff.info(info_flags::negative)) {
- c.s << par_open;
- i->coeff.print(c);
- c.s << par_close;
- } else {
- if (is_a<print_latex>(c)) {
- c.s << '{';
- i->coeff.print(c);
- c.s << '}';
- } else
- i->coeff.print(c);
- }
- }
+ i->coeff.print(c);
+ c.s << closebrace;
}
- } else
- Order(power(var-point,i->coeff)).print(c);
- ++i;
- }
+ }
+ } else
+ Order(power(var-point,i->coeff)).print(c);
+ ++i;
+ }
+
+ if (precedence() <= level)
+ c.s << ')';
+}
- if (precedence() <= level)
- c.s << ")";
+void pseries::do_print(const print_context & c, unsigned level) const
+{
+ print_series(c, "", "", "*", "^", level);
+}
+
+void pseries::do_print_latex(const print_latex & c, unsigned level) const
+{
+ print_series(c, "{", "}", " ", "^", level);
+}
+
+void pseries::do_print_python(const print_python & c, unsigned level) const
+{
+ print_series(c, "", "", "*", "**", level);
+}
+
+void pseries::do_print_tree(const print_tree & c, unsigned level) const
+{
+ c.s << std::string(level, ' ') << class_name() << " @" << this
+ << std::hex << ", hash=0x" << hashvalue << ", flags=0x" << flags << std::dec
+ << std::endl;
+ size_t num = seq.size();
+ for (size_t i=0; i<num; ++i) {
+ seq[i].rest.print(c, level + c.delta_indent);
+ seq[i].coeff.print(c, level + c.delta_indent);
+ c.s << std::string(level + c.delta_indent, ' ') << "-----" << std::endl;
+ }
+ var.print(c, level + c.delta_indent);
+ point.print(c, level + c.delta_indent);
+}
+
+void pseries::do_print_python_repr(const print_python_repr & c, unsigned level) const
+{
+ c.s << class_name() << "(relational(";
+ var.print(c);
+ c.s << ',';
+ point.print(c);
+ c.s << "),[";
+ size_t num = seq.size();
+ for (size_t i=0; i<num; ++i) {
+ if (i)
+ c.s << ',';
+ c.s << '(';
+ seq[i].rest.print(c);
+ c.s << ',';
+ seq[i].coeff.print(c);
+ c.s << ')';
}
+ c.s << "])";
}
int pseries::compare_same_type(const basic & other) const
return (new pseries(relational(var,point), new_seq))->setflag(status_flags::dynallocated | status_flags::evaluated);
}
+ex pseries::conjugate() const
+{
+ epvector * newseq = conjugateepvector(seq);
+ ex newvar = var.conjugate();
+ ex newpoint = point.conjugate();
+
+ if (!newseq && are_ex_trivially_equal(newvar, var) && are_ex_trivially_equal(point, newpoint)) {
+ return *this;
+ }
+
+ ex result = (new pseries(newvar==newpoint, newseq ? *newseq : seq))->setflag(status_flags::dynallocated);
+ if (newseq) {
+ delete newseq;
+ }
+ return result;
+}
+
ex pseries::subs(const exmap & m, unsigned options) const
{
// If expansion variable is being substituted, convert the series to a
epvector seq;
numeric fac = 1;
ex deriv = *this;
- ex coeff = deriv.subs(r);
+ ex coeff = deriv.subs(r, subs_options::no_pattern);
const symbol &s = ex_to<symbol>(r.lhs());
if (!coeff.is_zero())
if (deriv.is_zero()) // Series terminates
return pseries(r, seq);
- coeff = deriv.subs(r);
+ coeff = deriv.subs(r, subs_options::no_pattern);
if (!coeff.is_zero())
seq.push_back(expair(fac.inverse() * coeff, n));
}
// Basis is not a series, may there be a singularity?
bool must_expand_basis = false;
try {
- basis.subs(r);
+ basis.subs(r, subs_options::no_pattern);
} catch (pole_error) {
must_expand_basis = true;
}
return basic::series(r, order, options);
// Is the expression of type 0^something?
- if (!must_expand_basis && !basis.subs(r).is_zero())
+ if (!must_expand_basis && !basis.subs(r, subs_options::no_pattern).is_zero())
return basic::series(r, order, options);
// Singularity encountered, is the basis equal to (var - point)?