]> www.ginac.de Git - ginac.git/blob - ginac/pseries.h
fbff5135720fcbc84622b7fb1216695da8428cc1
[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 #ifndef NO_NAMESPACE_GINAC
30 namespace GiNaC {
31 #endif // ndef NO_NAMESPACE_GINAC
32
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
38 {
39         GINAC_DECLARE_REGISTERED_CLASS(pseries, basic)
40
41         // default constructor, destructor, copy constructor, assignment operator and helpers
42 public:
43         pseries();
44         ~pseries();
45         pseries(const pseries &other);
46         const pseries &operator=(const pseries &other);
47 protected:
48         void copy(const pseries &other);
49         void destroy(bool call_parent);
50
51         // other constructors
52 public:
53         pseries(const ex &rel_, const epvector &ops_);
54
55         // functions overriding virtual functions from base classes
56 public:
57         basic *duplicate() const;
58         void print(std::ostream &os, unsigned upper_precedence = 0) const;
59         void printraw(std::ostream &os) const;
60         void printtree(std::ostream & os, unsigned indent) const;
61         unsigned nops(void) const;
62         ex op(int i) const;
63         ex &let_op(int i);
64         int degree(const symbol &s) const;
65         int ldegree(const symbol &s) const;
66         ex coeff(const symbol &s, int n = 1) const;
67         ex collect(const symbol &s) const;
68         ex eval(int level=0) const;
69         ex evalf(int level=0) const;
70         ex series(const relational & r, int order, unsigned options = 0) const;
71         ex subs(const lst & ls, const lst & lr) const;
72         ex normal(lst &sym_lst, lst &repl_lst, int level = 0) const;
73         ex expand(unsigned options = 0) const;
74 protected:
75         ex derivative(const symbol & s) const;
76
77         // non-virtual functions in this class
78 public:
79         ex convert_to_poly(bool no_order = false) const;
80         bool is_compatible_to(const pseries &other) const {return var.compare(other.var) == 0 && point.compare(other.point) == 0;}
81         bool is_zero(void) const {return seq.size() == 0;}
82         bool is_terminating(void) const;
83         ex add_series(const pseries &other) const;
84         ex mul_const(const numeric &other) const;
85         ex mul_series(const pseries &other) const;
86         ex power_const(const numeric &p, int deg) const;
87         pseries shift_exponents(int deg) const;
88
89 protected:
90         /** Vector of {coefficient, power} pairs */
91         epvector seq;
92
93         /** Series variable (holds a symbol) */
94         ex var;
95
96         /** Expansion point */
97         ex point;
98         static unsigned precedence;
99 };
100
101 // global constants
102 extern const pseries some_pseries;
103 extern const std::type_info & typeid_pseries;
104
105 /** Return a reference to the pseries object embedded in an expression.
106  *  The result is undefined if the expression does not contain a pseries
107  *  object at its top level.
108  *
109  *  @param e expression
110  *  @return reference to pseries object
111  *  @see is_ex_of_type */
112 inline const pseries &ex_to_pseries(const ex &e)
113 {
114         return static_cast<const pseries &>(*e.bp);
115 }
116
117 /** Convert the pseries object embedded in an expression to an ordinary
118  *  polynomial in the expansion variable. The result is undefined if the
119  *  expression does not contain a pseries object at its top level.
120  *
121  *  @param e expression
122  *  @return polynomial expression
123  *  @see is_ex_of_type
124  *  @see pseries::convert_to_poly */
125 inline ex series_to_poly(const ex &e)
126 {
127         return (static_cast<const pseries &>(*e.bp).convert_to_poly(true));
128 }
129
130 inline bool is_terminating(const pseries & s)
131 {
132         return s.is_terminating();
133 }
134
135 #ifndef NO_NAMESPACE_GINAC
136 } // namespace GiNaC
137 #endif // ndef NO_NAMESPACE_GINAC
138
139 #endif // ndef __GINAC_SERIES_H__