]> www.ginac.de Git - ginac.git/blob - ginac/pseries.h
Prepare for release 1.7.3.
[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-2018 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  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         pseries(const ex &rel_, epvector &&ops_);
43
44         // functions overriding virtual functions from base classes
45 public:
46         unsigned precedence() const override {return 38;} // for clarity just below add::precedence
47         size_t nops() const override;
48         ex op(size_t i) const override;
49         int degree(const ex &s) const override;
50         int ldegree(const ex &s) const override;
51         ex coeff(const ex &s, int n = 1) const override;
52         ex collect(const ex &s, bool distributed = false) const override;
53         ex eval() const override;
54         ex evalf() const override;
55         ex series(const relational & r, int order, unsigned options = 0) const override;
56         ex subs(const exmap & m, unsigned options = 0) const override;
57         ex normal(exmap & repl, exmap & rev_lookup) const override;
58         ex expand(unsigned options = 0) const override;
59         ex conjugate() const override;
60         ex real_part() const override;
61         ex imag_part() const override;
62         ex eval_integ() const override;
63         ex evalm() const override;
64         /** Save (a.k.a. serialize) object into archive. */
65         void archive(archive_node& n) const override;
66         /** Read (a.k.a. deserialize) object from archive. */
67         void read_archive(const archive_node& n, lst& syms) override;
68 protected:
69         ex derivative(const symbol & s) const override;
70
71         // non-virtual functions in this class
72 public:
73         /** Get the expansion variable. */
74         ex get_var() const {return var;}
75
76         /** Get the expansion point. */
77         ex get_point() const {return point;}
78
79         /** Convert the pseries object to an ordinary polynomial.
80          *
81          *  @param no_order flag: discard higher order terms */
82         ex convert_to_poly(bool no_order = false) const;
83
84         /** Check whether series is compatible to another series (expansion
85          *  variable and point are the same. */
86         bool is_compatible_to(const pseries &other) const {return var.is_equal(other.var) && point.is_equal(other.point);}
87
88         /** Check whether series has the value zero. */
89         bool is_zero() const {return seq.size() == 0;}
90
91         /** Returns true if there is no order term, i.e. the series terminates and
92          *  false otherwise. */
93         bool is_terminating() const;
94
95         /** Get coefficients and exponents. */
96         ex coeffop(size_t i) const;
97         ex exponop(size_t i) const;
98
99         ex add_series(const pseries &other) const;
100         ex mul_const(const numeric &other) const;
101         ex mul_series(const pseries &other) const;
102         ex power_const(const numeric &p, int deg) const;
103         pseries shift_exponents(int deg) const;
104
105 protected:
106         void print_series(const print_context & c, const char *openbrace, const char *closebrace, const char *mul_sym, const char *pow_sym, unsigned level) const;
107         void do_print(const print_context & c, unsigned level) const;
108         void do_print_latex(const print_latex & c, unsigned level) const;
109         void do_print_tree(const print_tree & c, unsigned level) const;
110         void do_print_python(const print_python & c, unsigned level) const;
111         void do_print_python_repr(const print_python_repr & c, unsigned level) const;
112
113 protected:
114         /** Vector of {coefficient, power} pairs */
115         epvector seq;
116
117         /** Series variable (holds a symbol) */
118         ex var;
119
120         /** Expansion point */
121         ex point;
122 };
123 GINAC_DECLARE_UNARCHIVER(pseries); 
124
125
126 // utility functions
127
128 /** Convert the pseries object embedded in an expression to an ordinary
129  *  polynomial in the expansion variable. The result is undefined if the
130  *  expression does not contain a pseries object at its top level.
131  *
132  *  @param e expression
133  *  @return polynomial expression
134  *  @see is_a<>
135  *  @see pseries::convert_to_poly */
136 inline ex series_to_poly(const ex &e)
137 {
138         return (ex_to<pseries>(e).convert_to_poly(true));
139 }
140
141 inline bool is_terminating(const pseries & s)
142 {
143         return s.is_terminating();
144 }
145
146 } // namespace GiNaC
147
148 #endif // ndef GINAC_SERIES_H