3 * Interface to class for extended truncated power series. */
6 * GiNaC Copyright (C) 1999-2020 Johannes Gutenberg University Mainz, Germany
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 #ifndef GINAC_SERIES_H
24 #define GINAC_SERIES_H
27 #include "expairseq.h"
31 /** This class holds a extended truncated power series (positive and negative
32 * integer powers). It consists of expression coefficients (only non-zero
33 * coefficients are stored), an expansion variable and an expansion point.
34 * Other classes must provide members to convert into this type. */
35 class pseries : public basic
37 GINAC_DECLARE_REGISTERED_CLASS(pseries, basic)
41 pseries(const ex &rel_, const epvector &ops_);
42 pseries(const ex &rel_, epvector &&ops_);
44 // functions overriding virtual functions from base classes
46 unsigned precedence() const override {return 38;} // for clarity just below add::precedence
47 size_t nops() const override;
48 ex op(size_t i) const override;
49 int degree(const ex &s) const override;
50 int ldegree(const ex &s) const override;
51 ex coeff(const ex &s, int n = 1) const override;
52 ex collect(const ex &s, bool distributed = false) const override;
53 ex eval() const override;
54 ex evalf() const override;
55 ex series(const relational & r, int order, unsigned options = 0) const override;
56 ex subs(const exmap & m, unsigned options = 0) const override;
57 ex normal(exmap & repl, exmap & rev_lookup) const override;
58 ex expand(unsigned options = 0) const override;
59 ex conjugate() const override;
60 ex real_part() const override;
61 ex imag_part() const override;
62 ex eval_integ() const override;
63 ex evalm() const override;
64 /** Save (a.k.a. serialize) object into archive. */
65 void archive(archive_node& n) const override;
66 /** Read (a.k.a. deserialize) object from archive. */
67 void read_archive(const archive_node& n, lst& syms) override;
69 ex derivative(const symbol & s) const override;
71 // non-virtual functions in this class
73 /** Get the expansion variable. */
74 ex get_var() const {return var;}
76 /** Get the expansion point. */
77 ex get_point() const {return point;}
79 /** Convert the pseries object to an ordinary polynomial.
81 * @param no_order flag: discard higher order terms */
82 ex convert_to_poly(bool no_order = false) const;
84 /** Check whether series is compatible to another series (expansion
85 * variable and point are the same. */
86 bool is_compatible_to(const pseries &other) const {return var.is_equal(other.var) && point.is_equal(other.point);}
88 /** Check whether series has the value zero. */
89 bool is_zero() const {return seq.size() == 0;}
91 /** Returns true if there is no order term, i.e. the series terminates and
93 bool is_terminating() const;
95 /** Get coefficients and exponents. */
96 ex coeffop(size_t i) const;
97 ex exponop(size_t i) const;
99 ex add_series(const pseries &other) const;
100 ex mul_const(const numeric &other) const;
101 ex mul_series(const pseries &other) const;
102 ex power_const(const numeric &p, int deg) const;
103 pseries shift_exponents(int deg) const;
106 void print_series(const print_context & c, const char *openbrace, const char *closebrace, const char *mul_sym, const char *pow_sym, unsigned level) const;
107 void do_print(const print_context & c, unsigned level) const;
108 void do_print_latex(const print_latex & c, unsigned level) const;
109 void do_print_tree(const print_tree & c, unsigned level) const;
110 void do_print_python(const print_python & c, unsigned level) const;
111 void do_print_python_repr(const print_python_repr & c, unsigned level) const;
114 /** Vector of {coefficient, power} pairs */
117 /** Series variable (holds a symbol) */
120 /** Expansion point */
123 GINAC_DECLARE_UNARCHIVER(pseries);
128 /** Convert the pseries object embedded in an expression to an ordinary
129 * polynomial in the expansion variable. The result is undefined if the
130 * expression does not contain a pseries object at its top level.
132 * @param e expression
133 * @return polynomial expression
135 * @see pseries::convert_to_poly */
136 inline ex series_to_poly(const ex &e)
138 return (ex_to<pseries>(e).convert_to_poly(true));
141 inline bool is_terminating(const pseries & s)
143 return s.is_terminating();
148 #endif // ndef GINAC_SERIES_H