3 * Interface to class for extended truncated power series. */
6 * GiNaC Copyright (C) 1999-2000 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #ifndef __GINAC_SERIES_H__
24 #define __GINAC_SERIES_H__
26 #include <ginac/basic.h>
27 #include <ginac/expairseq.h>
29 #ifndef NO_GINAC_NAMESPACE
31 #endif // ndef NO_GINAC_NAMESPACE
33 /** This class holds a extended truncated power series (positive and negative
34 * integer powers). It consists of expression coefficients (only non-zero
35 * coefficients are stored), an expansion variable and an expansion point.
36 * Other classes must provide members to convert into this type. */
37 class pseries : public basic
39 GINAC_DECLARE_REGISTERED_CLASS(pseries, basic)
41 // default constructor, destructor, copy constructor, assignment operator and helpers
45 pseries(const pseries &other);
46 const pseries &operator=(const pseries &other);
48 void copy(const pseries &other);
49 void destroy(bool call_parent);
53 pseries(const ex &var_, const ex &point_, const epvector &ops_);
55 // functions overriding virtual functions from base classes
57 basic *duplicate() const;
58 void print(ostream &os, unsigned upper_precedence=0) const;
59 void printraw(ostream &os) const;
60 unsigned nops(void) const;
63 int degree(const symbol &s) const;
64 int ldegree(const symbol &s) const;
65 ex coeff(const symbol &s, int n=1) const;
66 ex eval(int level=0) const;
67 ex evalf(int level=0) const;
68 ex normal(lst &sym_lst, lst &repl_lst, int level=0) const;
69 ex diff(const symbol & s) const;
70 ex subs(const lst & ls, const lst & lr) const;
72 // non-virtual functions in this class
74 ex convert_to_poly(bool no_order = false) const;
75 bool is_compatible_to(const pseries &other) const {return var.compare(other.var) == 0 && point.compare(other.point) == 0;}
76 bool is_zero(void) const {return seq.size() == 0;}
77 ex add_series(const pseries &other) const;
78 ex mul_const(const numeric &other) const;
79 ex mul_series(const pseries &other) const;
80 ex power_const(const numeric &p, int deg) const;
83 /** Vector of {coefficient, power} pairs */
86 /** Series variable (holds a symbol) */
89 /** Expansion point */
94 extern const pseries some_pseries;
95 extern const type_info & typeid_pseries;
97 /** Return a reference to the pseries object embedded in an expression.
98 * The result is undefined if the expression does not contain a pseries
99 * object at its top level.
101 * @param e expression
102 * @return reference to pseries object
103 * @see is_ex_of_type */
104 inline const pseries &ex_to_pseries(const ex &e)
106 return static_cast<const pseries &>(*e.bp);
109 /** Convert the pseries object embedded in an expression to an ordinary
110 * polynomial in the expansion variable. The result is undefined if the
111 * expression does not contain a pseries object at its top level.
113 * @param e expression
114 * @return polynomial expression
116 * @see pseries::convert_to_poly */
117 inline ex series_to_poly(const ex &e)
119 return (static_cast<const pseries &>(*e.bp).convert_to_poly(true));
122 #ifndef NO_GINAC_NAMESPACE
124 #endif // ndef NO_GINAC_NAMESPACE
126 #endif // ndef __GINAC_SERIES_H__