]> www.ginac.de Git - ginac.git/blob - ginac/pseries.h
describe ex_is_less and ex_is_equal
[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-2003 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 constructors
40 public:
41         pseries(const ex &rel_, const epvector &ops_);
42
43         // functions overriding virtual functions from base classes
44 public:
45         void print(const print_context & c, unsigned level = 0) const;
46         unsigned precedence() const {return 38;} // for clarity just below add::precedence
47         size_t nops() const;
48         ex op(size_t i) const;
49         int degree(const ex &s) const;
50         int ldegree(const ex &s) const;
51         ex coeff(const ex &s, int n = 1) const;
52         ex collect(const ex &s, bool distributed = false) const;
53         ex eval(int level=0) const;
54         ex evalf(int level=0) const;
55         ex series(const relational & r, int order, unsigned options = 0) const;
56         ex subs(const exmap & m, unsigned options = 0) const;
57         ex normal(exmap & repl, int level = 0) const;
58         ex expand(unsigned options = 0) const;
59 protected:
60         ex derivative(const symbol & s) const;
61
62         // non-virtual functions in this class
63 public:
64         /** Get the expansion variable. */
65         ex get_var() const {return var;}
66
67         /** Get the expansion point. */
68         ex get_point() const {return point;}
69
70         /** Convert the pseries object to an ordinary polynomial.
71          *
72          *  @param no_order flag: discard higher order terms */
73         ex convert_to_poly(bool no_order = false) const;
74
75         /** Check whether series is compatible to another series (expansion
76          *  variable and point are the same. */
77         bool is_compatible_to(const pseries &other) const {return var.is_equal(other.var) && point.is_equal(other.point);}
78
79         /** Check whether series has the value zero. */
80         bool is_zero() const {return seq.size() == 0;}
81
82         /** Returns true if there is no order term, i.e. the series terminates and
83          *  false otherwise. */
84         bool is_terminating() const;
85
86         ex add_series(const pseries &other) const;
87         ex mul_const(const numeric &other) const;
88         ex mul_series(const pseries &other) const;
89         ex power_const(const numeric &p, int deg) const;
90         pseries shift_exponents(int deg) const;
91
92 protected:
93         /** Vector of {coefficient, power} pairs */
94         epvector seq;
95
96         /** Series variable (holds a symbol) */
97         ex var;
98
99         /** Expansion point */
100         ex point;
101 };
102
103
104 // utility functions
105
106 /** Specialization of is_exactly_a<pseries>(obj) for pseries objects. */
107 template<> inline bool is_exactly_a<pseries>(const basic & obj)
108 {
109         return obj.tinfo()==TINFO_pseries;
110 }
111
112 /** Convert the pseries object embedded in an expression to an ordinary
113  *  polynomial in the expansion variable. The result is undefined if the
114  *  expression does not contain a pseries object at its top level.
115  *
116  *  @param e expression
117  *  @return polynomial expression
118  *  @see is_a<>
119  *  @see pseries::convert_to_poly */
120 inline ex series_to_poly(const ex &e)
121 {
122         return (ex_to<pseries>(e).convert_to_poly(true));
123 }
124
125 inline bool is_terminating(const pseries & s)
126 {
127         return s.is_terminating();
128 }
129
130 } // namespace GiNaC
131
132 #endif // ndef __GINAC_SERIES_H__