]> www.ginac.de Git - ginac.git/blob - ginac/series.h
- introduced info_flags::cinteger, info_flags::crational,
[ginac.git] / ginac / series.h
1 /** @file series.h
2  *
3  *  Interface to class for extended truncated power series. */
4
5 /*
6  *  GiNaC Copyright (C) 1999 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 <ginac/basic.h>
27 #include <ginac/expairseq.h>
28
29 #ifndef NO_GINAC_NAMESPACE
30 namespace GiNaC {
31 #endif // ndef NO_GINAC_NAMESPACE
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 series : public basic
38 {
39     typedef basic inherited;
40
41     // default constructor, destructor, copy constructor, assignment operator and helpers
42 public:
43     series();
44     ~series();
45     series(series const &other);
46     series const &operator=(series const &other);
47 protected:
48     void copy(series const &other);
49     void destroy(bool call_parent);
50
51     // other constructors
52 public:
53     series(ex const &var_, ex const &point_, epvector const &ops_);
54
55     // functions overriding virtual functions from base classes
56 public:
57     basic *duplicate() const;
58     void print(ostream &os, unsigned upper_precedence=0) const;
59     void printraw(ostream &os) const;
60     int degree(symbol const &s) const;
61     int ldegree(symbol const &s) const;
62     ex coeff(symbol const &s, int const n=1) const;
63     ex eval(int level=0) const;
64     ex evalf(int level=0) const;
65     ex diff(symbol const & s) const;
66     ex normal(lst &sym_lst, lst &repl_lst, int level=0) const;
67
68     // non-virtual functions in this class
69 public:
70     ex convert_to_poly(bool no_order = false) const;
71     bool is_compatible_to(const series &other) const {return var.compare(other.var) == 0 && point.compare(other.point) == 0;}
72     bool is_zero(void) const {return seq.size() == 0;}
73     ex add_series(const series &other) const;
74     ex mul_const(const numeric &other) const;
75     ex mul_series(const series &other) const;
76     ex power_const(const numeric &p, 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
89 // global constants
90 extern const series some_series;
91 extern type_info const & typeid_series;
92
93 /** Return a reference to the series object embedded in an expression.
94  *  The result is undefined if the expression does not contain a series
95  *  object at its top level.
96  *
97  *  @param e expression
98  *  @return reference to series object
99  *  @see is_ex_of_type */
100 inline const series &ex_to_series(const ex &e)
101 {
102         return static_cast<const series &>(*e.bp);
103 }
104
105 /** Convert the series object embedded in an expression to an ordinary
106  *  polynomial in the expansion variable. The result is undefined if the
107  *  expression does not contain a series object at its top level.
108  *
109  *  @param e expression
110  *  @return polynomial expression
111  *  @see is_ex_of_type
112  *  @see series::convert_to_poly */
113 inline ex series_to_poly(const ex &e)
114 {
115         return (static_cast<const series &>(*e.bp).convert_to_poly(true));
116 }
117
118 #ifndef NO_GINAC_NAMESPACE
119 } // namespace GiNaC
120 #endif // ndef NO_GINAC_NAMESPACE
121
122 #endif // ndef __GINAC_SERIES_H__