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