]> www.ginac.de Git - ginac.git/blob - ginac/pseries.cpp
- print 0 without parens.
[ginac.git] / ginac / pseries.cpp
1 /** @file pseries.cpp
2  *
3  *  Implementation of class for extended truncated power series and
4  *  methods for series expansion. */
5
6 /*
7  *  GiNaC Copyright (C) 1999-2000 Johannes Gutenberg University Mainz, Germany
8  *
9  *  This program is free software; you can redistribute it and/or modify
10  *  it under the terms of the GNU General Public License as published by
11  *  the Free Software Foundation; either version 2 of the License, or
12  *  (at your option) any later version.
13  *
14  *  This program is distributed in the hope that it will be useful,
15  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  *  GNU General Public License for more details.
18  *
19  *  You should have received a copy of the GNU General Public License
20  *  along with this program; if not, write to the Free Software
21  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
22  */
23
24 #include <stdexcept>
25
26 #include "pseries.h"
27 #include "add.h"
28 #include "inifcns.h"
29 #include "lst.h"
30 #include "mul.h"
31 #include "power.h"
32 #include "relational.h"
33 #include "symbol.h"
34 #include "archive.h"
35 #include "utils.h"
36 #include "debugmsg.h"
37
38 #ifndef NO_NAMESPACE_GINAC
39 namespace GiNaC {
40 #endif // ndef NO_NAMESPACE_GINAC
41
42 GINAC_IMPLEMENT_REGISTERED_CLASS(pseries, basic)
43
44 /*
45  *  Default constructor, destructor, copy constructor, assignment operator and helpers
46  */
47
48 pseries::pseries() : basic(TINFO_pseries)
49 {
50     debugmsg("pseries default constructor", LOGLEVEL_CONSTRUCT);
51 }
52
53 pseries::~pseries()
54 {
55     debugmsg("pseries destructor", LOGLEVEL_DESTRUCT);
56     destroy(false);
57 }
58
59 pseries::pseries(const pseries &other)
60 {
61     debugmsg("pseries copy constructor", LOGLEVEL_CONSTRUCT);
62     copy(other);
63 }
64
65 const pseries &pseries::operator=(const pseries & other)
66 {
67     debugmsg("pseries operator=", LOGLEVEL_ASSIGNMENT);
68     if (this != &other) {
69         destroy(true);
70         copy(other);
71     }
72     return *this;
73 }
74
75 void pseries::copy(const pseries &other)
76 {
77     inherited::copy(other);
78     seq = other.seq;
79     var = other.var;
80     point = other.point;
81 }
82
83 void pseries::destroy(bool call_parent)
84 {
85     if (call_parent)
86         inherited::destroy(call_parent);
87 }
88
89
90 /*
91  *  Other constructors
92  */
93
94 /** Construct pseries from a vector of coefficients and powers.
95  *  expair.rest holds the coefficient, expair.coeff holds the power.
96  *  The powers must be integers (positive or negative) and in ascending order;
97  *  the last coefficient can be Order(_ex1()) to represent a truncated,
98  *  non-terminating series.
99  *
100  *  @param var_  series variable (must hold a symbol)
101  *  @param point_  expansion point
102  *  @param ops_  vector of {coefficient, power} pairs (coefficient must not be zero)
103  *  @return newly constructed pseries */
104 pseries::pseries(const ex &var_, const ex &point_, const epvector &ops_)
105     : basic(TINFO_pseries), seq(ops_), var(var_), point(point_)
106 {
107     debugmsg("pseries constructor from ex,ex,epvector", LOGLEVEL_CONSTRUCT);
108     GINAC_ASSERT(is_ex_exactly_of_type(var_, symbol));
109 }
110
111
112 /*
113  *  Archiving
114  */
115
116 /** Construct object from archive_node. */
117 pseries::pseries(const archive_node &n, const lst &sym_lst) : inherited(n, sym_lst)
118 {
119     debugmsg("pseries constructor from archive_node", LOGLEVEL_CONSTRUCT);
120     for (unsigned int i=0; true; i++) {
121         ex rest;
122         ex coeff;
123         if (n.find_ex("coeff", rest, sym_lst, i) && n.find_ex("power", coeff, sym_lst, i))
124             seq.push_back(expair(rest, coeff));
125         else
126             break;
127     }
128     n.find_ex("var", var, sym_lst);
129     n.find_ex("point", point, sym_lst);
130 }
131
132 /** Unarchive the object. */
133 ex pseries::unarchive(const archive_node &n, const lst &sym_lst)
134 {
135     return (new pseries(n, sym_lst))->setflag(status_flags::dynallocated);
136 }
137
138 /** Archive the object. */
139 void pseries::archive(archive_node &n) const
140 {
141     inherited::archive(n);
142     epvector::const_iterator i = seq.begin(), iend = seq.end();
143     while (i != iend) {
144         n.add_ex("coeff", i->rest);
145         n.add_ex("power", i->coeff);
146         i++;
147     }
148     n.add_ex("var", var);
149     n.add_ex("point", point);
150 }
151
152
153 /*
154  *  Functions overriding virtual functions from base classes
155  */
156
157 basic *pseries::duplicate() const
158 {
159     debugmsg("pseries duplicate", LOGLEVEL_DUPLICATE);
160     return new pseries(*this);
161 }
162
163 void pseries::print(ostream &os, unsigned upper_precedence) const
164 {
165     debugmsg("pseries print", LOGLEVEL_PRINT);
166     convert_to_poly().print(os, upper_precedence);
167 }
168
169 void pseries::printraw(ostream &os) const
170 {
171         debugmsg("pseries printraw", LOGLEVEL_PRINT);
172         os << "pseries(" << var << ";" << point << ";";
173         for (epvector::const_iterator i=seq.begin(); i!=seq.end(); i++) {
174                 os << "(" << (*i).rest << "," << (*i).coeff << "),";
175         }
176         os << ")";
177 }
178
179 unsigned pseries::nops(void) const
180 {
181     return seq.size();
182 }
183
184 ex pseries::op(int i) const
185 {
186     if (i < 0 || unsigned(i) >= seq.size())
187         throw (std::out_of_range("op() out of range"));
188     return seq[i].rest * power(var - point, seq[i].coeff);
189 }
190
191 ex &pseries::let_op(int i)
192 {
193     throw (std::logic_error("let_op not defined for pseries"));
194 }
195
196 int pseries::degree(const symbol &s) const
197 {
198     if (var.is_equal(s)) {
199         // Return last exponent
200         if (seq.size())
201             return ex_to_numeric((*(seq.end() - 1)).coeff).to_int();
202         else
203             return 0;
204     } else {
205         epvector::const_iterator it = seq.begin(), itend = seq.end();
206         if (it == itend)
207             return 0;
208         int max_pow = INT_MIN;
209         while (it != itend) {
210             int pow = it->rest.degree(s);
211             if (pow > max_pow)
212                 max_pow = pow;
213             it++;
214         }
215         return max_pow;
216     }
217 }
218
219 int pseries::ldegree(const symbol &s) const
220 {
221     if (var.is_equal(s)) {
222         // Return first exponent
223         if (seq.size())
224             return ex_to_numeric((*(seq.begin())).coeff).to_int();
225         else
226             return 0;
227     } else {
228         epvector::const_iterator it = seq.begin(), itend = seq.end();
229         if (it == itend)
230             return 0;
231         int min_pow = INT_MAX;
232         while (it != itend) {
233             int pow = it->rest.ldegree(s);
234             if (pow < min_pow)
235                 min_pow = pow;
236             it++;
237         }
238         return min_pow;
239     }
240 }
241
242 ex pseries::coeff(const symbol &s, int n) const
243 {
244     if (var.is_equal(s)) {
245                 if (seq.size() == 0)
246                         return _ex0();
247
248                 // Binary search in sequence for given power
249                 numeric looking_for = numeric(n);
250                 int lo = 0, hi = seq.size() - 1;
251                 while (lo <= hi) {
252                         int mid = (lo + hi) / 2;
253                         GINAC_ASSERT(is_ex_exactly_of_type(seq[mid].coeff, numeric));
254                         int cmp = ex_to_numeric(seq[mid].coeff).compare(looking_for);
255                         switch (cmp) {
256                                 case -1:
257                                         lo = mid + 1;
258                                         break;
259                                 case 0:
260                                         return seq[mid].rest;
261                                 case 1:
262                                         hi = mid - 1;
263                                         break;
264                                 default:
265                                         throw(std::logic_error("pseries::coeff: compare() didn't return -1, 0 or 1"));
266                         }
267                 }
268                 return _ex0();
269     } else
270         return convert_to_poly().coeff(s, n);
271 }
272
273 ex pseries::collect(const symbol &s) const
274 {
275         return *this;
276 }
277
278 /** Evaluate coefficients. */
279 ex pseries::eval(int level) const
280 {
281     if (level == 1)
282         return this->hold();
283
284         if (level == -max_recursion_level)
285                 throw (std::runtime_error("pseries::eval(): recursion limit exceeded"));
286     
287     // Construct a new series with evaluated coefficients
288     epvector new_seq;
289     new_seq.reserve(seq.size());
290     epvector::const_iterator it = seq.begin(), itend = seq.end();
291     while (it != itend) {
292         new_seq.push_back(expair(it->rest.eval(level-1), it->coeff));
293         it++;
294     }
295     return (new pseries(var, point, new_seq))->setflag(status_flags::dynallocated | status_flags::evaluated);
296 }
297
298 /** Evaluate coefficients numerically. */
299 ex pseries::evalf(int level) const
300 {
301         if (level == 1)
302                 return *this;
303
304         if (level == -max_recursion_level)
305                 throw (std::runtime_error("pseries::evalf(): recursion limit exceeded"));
306
307     // Construct a new series with evaluated coefficients
308     epvector new_seq;
309     new_seq.reserve(seq.size());
310     epvector::const_iterator it = seq.begin(), itend = seq.end();
311     while (it != itend) {
312         new_seq.push_back(expair(it->rest.evalf(level-1), it->coeff));
313         it++;
314     }
315     return (new pseries(var, point, new_seq))->setflag(status_flags::dynallocated | status_flags::evaluated);
316 }
317
318 ex pseries::subs(const lst & ls, const lst & lr) const
319 {
320         // If expansion variable is being substituted, convert the series to a
321         // polynomial and do the substitution there because the result might
322         // no longer be a power series
323         if (ls.has(var))
324                 return convert_to_poly(true).subs(ls, lr);
325
326         // Otherwise construct a new series with substituted coefficients and
327         // expansion point
328         epvector new_seq;
329         new_seq.reserve(seq.size());
330         epvector::const_iterator it = seq.begin(), itend = seq.end();
331         while (it != itend) {
332                 new_seq.push_back(expair(it->rest.subs(ls, lr), it->coeff));
333                 it++;
334         }
335     return (new pseries(var, point.subs(ls, lr), new_seq))->setflag(status_flags::dynallocated);
336 }
337
338 /** Implementation of ex::diff() for a power series.  It treats the series as a
339  *  polynomial.
340  *  @see ex::diff */
341 ex pseries::derivative(const symbol & s) const
342 {
343     if (s == var) {
344         epvector new_seq;
345         epvector::const_iterator it = seq.begin(), itend = seq.end();
346         
347         // FIXME: coeff might depend on var
348         while (it != itend) {
349             if (is_order_function(it->rest)) {
350                 new_seq.push_back(expair(it->rest, it->coeff - 1));
351             } else {
352                 ex c = it->rest * it->coeff;
353                 if (!c.is_zero())
354                     new_seq.push_back(expair(c, it->coeff - 1));
355             }
356             it++;
357         }
358         return pseries(var, point, new_seq);
359     } else {
360         return *this;
361     }
362 }
363
364
365 /*
366  *  Construct ordinary polynomial out of series
367  */
368
369 /** Convert a pseries object to an ordinary polynomial.
370  *
371  *  @param no_order flag: discard higher order terms */
372 ex pseries::convert_to_poly(bool no_order) const
373 {
374     ex e;
375     epvector::const_iterator it = seq.begin(), itend = seq.end();
376     
377     while (it != itend) {
378         if (is_order_function(it->rest)) {
379             if (!no_order)
380                 e += Order(power(var - point, it->coeff));
381         } else
382             e += it->rest * power(var - point, it->coeff);
383         it++;
384     }
385     return e;
386 }
387
388
389 /*
390  *  Implementation of series expansion
391  */
392
393 /** Default implementation of ex::series(). This performs Taylor expansion.
394  *  @see ex::series */
395 ex basic::series(const symbol & s, const ex & point, int order) const
396 {
397     epvector seq;
398     numeric fac(1);
399     ex deriv = *this;
400     ex coeff = deriv.subs(s == point);
401     if (!coeff.is_zero())
402         seq.push_back(expair(coeff, numeric(0)));
403     
404     int n;
405     for (n=1; n<order; n++) {
406         fac = fac.mul(numeric(n));
407         deriv = deriv.diff(s).expand();
408         if (deriv.is_zero()) {
409             // Series terminates
410             return pseries(s, point, seq);
411         }
412         coeff = fac.inverse() * deriv.subs(s == point);
413         if (!coeff.is_zero())
414             seq.push_back(expair(coeff, numeric(n)));
415     }
416     
417     // Higher-order terms, if present
418     deriv = deriv.diff(s);
419     if (!deriv.is_zero())
420         seq.push_back(expair(Order(_ex1()), numeric(n)));
421     return pseries(s, point, seq);
422 }
423
424
425 /** Implementation of ex::series() for symbols.
426  *  @see ex::series */
427 ex symbol::series(const symbol & s, const ex & point, int order) const
428 {
429         epvector seq;
430         if (is_equal(s)) {
431                 if (order > 0 && !point.is_zero())
432                         seq.push_back(expair(point, _ex0()));
433                 if (order > 1)
434                         seq.push_back(expair(_ex1(), _ex1()));
435                 else
436                         seq.push_back(expair(Order(_ex1()), numeric(order)));
437         } else
438                 seq.push_back(expair(*this, _ex0()));
439         return pseries(s, point, seq);
440 }
441
442
443 /** Add one series object to another, producing a pseries object that
444  *  represents the sum.
445  *
446  *  @param other  pseries object to add with
447  *  @return the sum as a pseries */
448 ex pseries::add_series(const pseries &other) const
449 {
450     // Adding two series with different variables or expansion points
451     // results in an empty (constant) series 
452     if (!is_compatible_to(other)) {
453         epvector nul;
454         nul.push_back(expair(Order(_ex1()), _ex0()));
455         return pseries(var, point, nul);
456     }
457     
458     // Series addition
459     epvector new_seq;
460     epvector::const_iterator a = seq.begin();
461     epvector::const_iterator b = other.seq.begin();
462     epvector::const_iterator a_end = seq.end();
463     epvector::const_iterator b_end = other.seq.end();
464     int pow_a = INT_MAX, pow_b = INT_MAX;
465     for (;;) {
466         // If a is empty, fill up with elements from b and stop
467         if (a == a_end) {
468             while (b != b_end) {
469                 new_seq.push_back(*b);
470                 b++;
471             }
472             break;
473         } else
474             pow_a = ex_to_numeric((*a).coeff).to_int();
475         
476         // If b is empty, fill up with elements from a and stop
477         if (b == b_end) {
478             while (a != a_end) {
479                 new_seq.push_back(*a);
480                 a++;
481             }
482             break;
483         } else
484             pow_b = ex_to_numeric((*b).coeff).to_int();
485         
486         // a and b are non-empty, compare powers
487         if (pow_a < pow_b) {
488             // a has lesser power, get coefficient from a
489             new_seq.push_back(*a);
490             if (is_order_function((*a).rest))
491                 break;
492             a++;
493         } else if (pow_b < pow_a) {
494             // b has lesser power, get coefficient from b
495             new_seq.push_back(*b);
496             if (is_order_function((*b).rest))
497                 break;
498             b++;
499         } else {
500             // Add coefficient of a and b
501             if (is_order_function((*a).rest) || is_order_function((*b).rest)) {
502                 new_seq.push_back(expair(Order(_ex1()), (*a).coeff));
503                 break;  // Order term ends the sequence
504             } else {
505                 ex sum = (*a).rest + (*b).rest;
506                 if (!(sum.is_zero()))
507                     new_seq.push_back(expair(sum, numeric(pow_a)));
508                 a++;
509                 b++;
510             }
511         }
512     }
513     return pseries(var, point, new_seq);
514 }
515
516
517 /** Implementation of ex::series() for sums. This performs series addition when
518  *  adding pseries objects.
519  *  @see ex::series */
520 ex add::series(const symbol & s, const ex & point, int order) const
521 {
522     ex acc; // Series accumulator
523     
524     // Get first term from overall_coeff
525     acc = overall_coeff.series(s, point, order);
526
527     // Add remaining terms
528     epvector::const_iterator it = seq.begin();
529     epvector::const_iterator itend = seq.end();
530     for (; it!=itend; it++) {
531         ex op;
532         if (is_ex_exactly_of_type(it->rest, pseries))
533             op = it->rest;
534         else
535             op = it->rest.series(s, point, order);
536         if (!it->coeff.is_equal(_ex1()))
537             op = ex_to_pseries(op).mul_const(ex_to_numeric(it->coeff));
538         
539         // Series addition
540         acc = ex_to_pseries(acc).add_series(ex_to_pseries(op));
541     }
542     return acc;
543 }
544
545
546 /** Multiply a pseries object with a numeric constant, producing a pseries
547  *  object that represents the product.
548  *
549  *  @param other  constant to multiply with
550  *  @return the product as a pseries */
551 ex pseries::mul_const(const numeric &other) const
552 {
553     epvector new_seq;
554     new_seq.reserve(seq.size());
555     
556     epvector::const_iterator it = seq.begin(), itend = seq.end();
557     while (it != itend) {
558         if (!is_order_function(it->rest))
559             new_seq.push_back(expair(it->rest * other, it->coeff));
560         else
561             new_seq.push_back(*it);
562         it++;
563     }
564     return pseries(var, point, new_seq);
565 }
566
567
568 /** Multiply one pseries object to another, producing a pseries object that
569  *  represents the product.
570  *
571  *  @param other  pseries object to multiply with
572  *  @return the product as a pseries */
573 ex pseries::mul_series(const pseries &other) const
574 {
575     // Multiplying two series with different variables or expansion points
576     // results in an empty (constant) series 
577     if (!is_compatible_to(other)) {
578         epvector nul;
579         nul.push_back(expair(Order(_ex1()), _ex0()));
580         return pseries(var, point, nul);
581     }
582
583     // Series multiplication
584     epvector new_seq;
585     
586     const symbol *s = static_cast<symbol *>(var.bp);
587     int a_max = degree(*s);
588     int b_max = other.degree(*s);
589     int a_min = ldegree(*s);
590     int b_min = other.ldegree(*s);
591     int cdeg_min = a_min + b_min;
592     int cdeg_max = a_max + b_max;
593     
594     int higher_order_a = INT_MAX;
595     int higher_order_b = INT_MAX;
596     if (is_order_function(coeff(*s, a_max)))
597         higher_order_a = a_max + b_min;
598     if (is_order_function(other.coeff(*s, b_max)))
599         higher_order_b = b_max + a_min;
600     int higher_order_c = min(higher_order_a, higher_order_b);
601     if (cdeg_max >= higher_order_c)
602         cdeg_max = higher_order_c - 1;
603     
604     for (int cdeg=cdeg_min; cdeg<=cdeg_max; cdeg++) {
605         ex co = _ex0();
606         // c(i)=a(0)b(i)+...+a(i)b(0)
607         for (int i=a_min; cdeg-i>=b_min; i++) {
608             ex a_coeff = coeff(*s, i);
609             ex b_coeff = other.coeff(*s, cdeg-i);
610             if (!is_order_function(a_coeff) && !is_order_function(b_coeff))
611                 co += coeff(*s, i) * other.coeff(*s, cdeg-i);
612         }
613         if (!co.is_zero())
614             new_seq.push_back(expair(co, numeric(cdeg)));
615     }
616     if (higher_order_c < INT_MAX)
617         new_seq.push_back(expair(Order(_ex1()), numeric(higher_order_c)));
618     return pseries(var, point, new_seq);
619 }
620
621
622 /** Implementation of ex::series() for product. This performs series
623  *  multiplication when multiplying series.
624  *  @see ex::series */
625 ex mul::series(const symbol & s, const ex & point, int order) const
626 {
627     ex acc; // Series accumulator
628     
629     // Get first term from overall_coeff
630     acc = overall_coeff.series(s, point, order);
631     
632     // Multiply with remaining terms
633     epvector::const_iterator it = seq.begin();
634     epvector::const_iterator itend = seq.end();
635     for (; it!=itend; it++) {
636         ex op = it->rest;
637         if (op.info(info_flags::numeric)) {
638             // series * const (special case, faster)
639             ex f = power(op, it->coeff);
640             acc = ex_to_pseries(acc).mul_const(ex_to_numeric(f));
641             continue;
642         } else if (!is_ex_exactly_of_type(op, pseries))
643             op = op.series(s, point, order);
644         if (!it->coeff.is_equal(_ex1()))
645             op = ex_to_pseries(op).power_const(ex_to_numeric(it->coeff), order);
646
647         // Series multiplication
648         acc = ex_to_pseries(acc).mul_series(ex_to_pseries(op));
649     }
650     return acc;
651 }
652
653
654 /** Compute the p-th power of a series.
655  *
656  *  @param p  power to compute
657  *  @param deg  truncation order of series calculation */
658 ex pseries::power_const(const numeric &p, int deg) const
659 {
660     int i;
661     const symbol *s = static_cast<symbol *>(var.bp);
662     int ldeg = ldegree(*s);
663     
664     // Calculate coefficients of powered series
665     exvector co;
666     co.reserve(deg);
667     ex co0;
668     co.push_back(co0 = power(coeff(*s, ldeg), p));
669     bool all_sums_zero = true;
670     for (i=1; i<deg; i++) {
671         ex sum = _ex0();
672         for (int j=1; j<=i; j++) {
673             ex c = coeff(*s, j + ldeg);
674             if (is_order_function(c)) {
675                 co.push_back(Order(_ex1()));
676                 break;
677             } else
678                 sum += (p * j - (i - j)) * co[i - j] * c;
679         }
680         if (!sum.is_zero())
681             all_sums_zero = false;
682         co.push_back(co0 * sum / numeric(i));
683     }
684     
685     // Construct new series (of non-zero coefficients)
686     epvector new_seq;
687     bool higher_order = false;
688     for (i=0; i<deg; i++) {
689         if (!co[i].is_zero())
690             new_seq.push_back(expair(co[i], numeric(i) + p * ldeg));
691         if (is_order_function(co[i])) {
692             higher_order = true;
693             break;
694         }
695     }
696     if (!higher_order && !all_sums_zero)
697         new_seq.push_back(expair(Order(_ex1()), numeric(deg) + p * ldeg));
698     return pseries(var, point, new_seq);
699 }
700
701
702 /** Implementation of ex::series() for powers. This performs Laurent expansion
703  *  of reciprocals of series at singularities.
704  *  @see ex::series */
705 ex power::series(const symbol & s, const ex & point, int order) const
706 {
707     ex e;
708     if (!is_ex_exactly_of_type(basis, pseries)) {
709         // Basis is not a series, may there be a singulary?
710         if (!exponent.info(info_flags::negint))
711             return basic::series(s, point, order);
712         
713         // Expression is of type something^(-int), check for singularity
714         if (!basis.subs(s == point).is_zero())
715             return basic::series(s, point, order);
716         
717         // Singularity encountered, expand basis into series
718         e = basis.series(s, point, order);
719     } else {
720         // Basis is a series
721         e = basis;
722     }
723     
724     // Power e
725     return ex_to_pseries(e).power_const(ex_to_numeric(exponent), order);
726 }
727
728
729 /** Re-expansion of a pseries object. */
730 ex pseries::series(const symbol & s, const ex & p, int order) const
731 {
732         if (var.is_equal(s) && point.is_equal(p)) {
733                 if (order > degree(s))
734                         return *this;
735                 else {
736                 epvector new_seq;
737                 epvector::const_iterator it = seq.begin(), itend = seq.end();
738                         while (it != itend) {
739                                 int o = ex_to_numeric(it->coeff).to_int();
740                                 if (o >= order) {
741                                         new_seq.push_back(expair(Order(_ex1()), o));
742                                         break;
743                                 }
744                                 new_seq.push_back(*it);
745                                 it++;
746                         }
747                         return pseries(var, point, new_seq);
748                 }
749         } else
750                 return convert_to_poly().series(s, p, order);
751 }
752
753
754 /** Compute the truncated series expansion of an expression.
755  *  This function returns an expression containing an object of class pseries to
756  *  represent the series. If the series does not terminate within the given
757  *  truncation order, the last term of the series will be an order term.
758  *
759  *  @param s  expansion variable
760  *  @param point  expansion point
761  *  @param order  truncation order of series calculations
762  *  @return an expression holding a pseries object */
763 ex ex::series(const symbol &s, const ex &point, int order) const
764 {
765     GINAC_ASSERT(bp!=0);
766         ex e;
767         try {
768             e = bp->series(s, point, order);
769         } catch (exception &x) {
770                 throw (std::logic_error(string("unable to compute series (") + x.what() + ")"));
771         }
772         return e;
773 }
774
775
776 // Global constants
777 const pseries some_pseries;
778 const type_info & typeid_pseries = typeid(some_pseries);
779
780 #ifndef NO_NAMESPACE_GINAC
781 } // namespace GiNaC
782 #endif // ndef NO_NAMESPACE_GINAC