]> www.ginac.de Git - ginac.git/blob - ginac/pseries.h
1dd37ffda21d4e0ece86327c0ee533b7ef13f26f
[ginac.git] / ginac / pseries.h
1 /** @file pseries.h
2  *
3  *  Interface to class for extended truncated power series. */
4
5 /*
6  *  GiNaC Copyright (C) 1999-2001 Johannes Gutenberg University Mainz, Germany
7  *
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.
12  *
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.
17  *
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
21  */
22
23 #ifndef __GINAC_SERIES_H__
24 #define __GINAC_SERIES_H__
25
26 #include "basic.h"
27 #include "expairseq.h"
28
29 namespace GiNaC {
30
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
36 {
37         GINAC_DECLARE_REGISTERED_CLASS(pseries, basic)
38
39         // other ctors
40 public:
41         pseries(const ex &rel_, const epvector &ops_);
42
43         // functions overriding virtual functions from base classes
44 public:
45         void print(std::ostream &os, unsigned upper_precedence = 0) const;
46         void printraw(std::ostream &os) const;
47         void printtree(std::ostream & os, unsigned indent) const;
48         unsigned nops(void) const;
49         ex op(int i) const;
50         ex &let_op(int i);
51         int degree(const ex &s) const;
52         int ldegree(const ex &s) const;
53         ex coeff(const ex &s, int n = 1) const;
54         ex collect(const ex &s) const;
55         ex eval(int level=0) const;
56         ex evalf(int level=0) const;
57         ex series(const relational & r, int order, unsigned options = 0) const;
58         ex subs(const lst & ls, const lst & lr) const;
59         ex normal(lst &sym_lst, lst &repl_lst, int level = 0) const;
60         ex expand(unsigned options = 0) const;
61 protected:
62         ex derivative(const symbol & s) const;
63
64         // non-virtual functions in this class
65 public:
66         ex convert_to_poly(bool no_order = false) const;
67         bool is_compatible_to(const pseries &other) const {return var.compare(other.var) == 0 && point.compare(other.point) == 0;}
68         bool is_zero(void) const {return seq.size() == 0;}
69         bool is_terminating(void) const;
70         ex add_series(const pseries &other) const;
71         ex mul_const(const numeric &other) const;
72         ex mul_series(const pseries &other) const;
73         ex power_const(const numeric &p, int deg) const;
74         pseries shift_exponents(int deg) const;
75
76 protected:
77         /** Vector of {coefficient, power} pairs */
78         epvector seq;
79
80         /** Series variable (holds a symbol) */
81         ex var;
82
83         /** Expansion point */
84         ex point;
85
86         static unsigned precedence;
87 };
88
89 /** Return a reference to the pseries object embedded in an expression.
90  *  The result is undefined if the expression does not contain a pseries
91  *  object at its top level.
92  *
93  *  @param e expression
94  *  @return reference to pseries object
95  *  @see is_ex_of_type */
96 inline const pseries &ex_to_pseries(const ex &e)
97 {
98         return static_cast<const pseries &>(*e.bp);
99 }
100
101 /** Convert the pseries object embedded in an expression to an ordinary
102  *  polynomial in the expansion variable. The result is undefined if the
103  *  expression does not contain a pseries object at its top level.
104  *
105  *  @param e expression
106  *  @return polynomial expression
107  *  @see is_ex_of_type
108  *  @see pseries::convert_to_poly */
109 inline ex series_to_poly(const ex &e)
110 {
111         return (static_cast<const pseries &>(*e.bp).convert_to_poly(true));
112 }
113
114 inline bool is_terminating(const pseries & s)
115 {
116         return s.is_terminating();
117 }
118
119 } // namespace GiNaC
120
121 #endif // ndef __GINAC_SERIES_H__