X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?p=ginac.git;a=blobdiff_plain;f=check%2Fseries_expansion.cpp;h=4cd169706d0dd4ca418f5ccdd6c70cd5e68ff9f7;hp=b67705d7a3a5e1b567b4bf66688f2c3fe68faa2c;hb=ff50f412bb89eed2c78adffa0f390341753e8792;hpb=26741891dadf23162799009b6fd57b4984bd4ce5;ds=sidebyside diff --git a/check/series_expansion.cpp b/check/series_expansion.cpp index b67705d7..4cd16970 100644 --- a/check/series_expansion.cpp +++ b/check/series_expansion.cpp @@ -3,7 +3,7 @@ * Series expansion test (Laurent and Taylor series). */ /* - * GiNaC Copyright (C) 1999 Johannes Gutenberg University Mainz, Germany + * GiNaC Copyright (C) 1999-2000 Johannes Gutenberg University Mainz, Germany * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -20,19 +20,19 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include +#include "ginac.h" -#ifndef NO_GINAC_NAMESPACE +#ifndef NO_NAMESPACE_GINAC using namespace GiNaC; -#endif // ndef NO_GINAC_NAMESPACE +#endif // ndef NO_NAMESPACE_GINAC static symbol x("x"); static unsigned check_series(const ex &e, const ex &point, const ex &d, int order = 8) { ex es = e.series(x, point, order); - ex ep = static_cast(es.bp)->convert_to_poly(); - if ((ep - d).compare(exZERO()) != 0) { + ex ep = ex_to_pseries(es).convert_to_poly(); + if (!(ep - d).is_zero()) { clog << "series expansion of " << e << " at " << point << " erroneously returned " << ep << " (instead of " << d << ")" << endl; @@ -50,57 +50,57 @@ static unsigned series1(void) e = sin(x); d = x - pow(x, 3) / 6 + pow(x, 5) / 120 - pow(x, 7) / 5040 + Order(pow(x, 8)); - result += check_series(e, exZERO(), d); + result += check_series(e, 0, d); e = cos(x); d = 1 - pow(x, 2) / 2 + pow(x, 4) / 24 - pow(x, 6) / 720 + Order(pow(x, 8)); - result += check_series(e, exZERO(), d); + result += check_series(e, 0, d); e = exp(x); d = 1 + x + pow(x, 2) / 2 + pow(x, 3) / 6 + pow(x, 4) / 24 + pow(x, 5) / 120 + pow(x, 6) / 720 + pow(x, 7) / 5040 + Order(pow(x, 8)); - result += check_series(e, exZERO(), d); + result += check_series(e, 0, d); e = pow(1 - x, -1); d = 1 + x + pow(x, 2) + pow(x, 3) + pow(x, 4) + pow(x, 5) + pow(x, 6) + pow(x, 7) + Order(pow(x, 8)); - result += check_series(e, exZERO(), d); + result += check_series(e, 0, d); e = x + pow(x, -1); d = x + pow(x, -1); - result += check_series(e, exZERO(), d); + result += check_series(e, 0, d); e = x + pow(x, -1); d = 2 + pow(x-1, 2) - pow(x-1, 3) + pow(x-1, 4) - pow(x-1, 5) + pow(x-1, 6) - pow(x-1, 7) + Order(pow(x-1, 8)); - result += check_series(e, exONE(), d); + result += check_series(e, 1, d); e = pow(x + pow(x, 3), -1); d = pow(x, -1) - x + pow(x, 3) - pow(x, 5) + Order(pow(x, 7)); - result += check_series(e, exZERO(), d); + result += check_series(e, 0, d); e = pow(pow(x, 2) + pow(x, 4), -1); d = pow(x, -2) - 1 + pow(x, 2) - pow(x, 4) + Order(pow(x, 6)); - result += check_series(e, exZERO(), d); + result += check_series(e, 0, d); e = pow(sin(x), -2); d = pow(x, -2) + numeric(1,3) + pow(x, 2) / 15 + pow(x, 4) * 2/189 + Order(pow(x, 5)); - result += check_series(e, exZERO(), d); + result += check_series(e, 0, d); e = sin(x) / cos(x); d = x + pow(x, 3) / 3 + pow(x, 5) * 2/15 + pow(x, 7) * 17/315 + Order(pow(x, 8)); - result += check_series(e, exZERO(), d); + result += check_series(e, 0, d); e = cos(x) / sin(x); d = pow(x, -1) - x / 3 - pow(x, 3) / 45 - pow(x, 5) * 2/945 + Order(pow(x, 6)); - result += check_series(e, exZERO(), d); + result += check_series(e, 0, d); e = pow(numeric(2), x); ex t = log(ex(2)) * x; d = 1 + t + pow(t, 2) / 2 + pow(t, 3) / 6 + pow(t, 4) / 24 + pow(t, 5) / 120 + pow(t, 6) / 720 + pow(t, 7) / 5040 + Order(pow(x, 8)); - result += check_series(e, exZERO(), d.expand()); + result += check_series(e, 0, d.expand()); e = pow(Pi, x); t = log(Pi) * x; d = 1 + t + pow(t, 2) / 2 + pow(t, 3) / 6 + pow(t, 4) / 24 + pow(t, 5) / 120 + pow(t, 6) / 720 + pow(t, 7) / 5040 + Order(pow(x, 8)); - result += check_series(e, exZERO(), d.expand()); + result += check_series(e, 0, d.expand()); return result; } @@ -111,9 +111,9 @@ static unsigned series2(void) unsigned result = 0; ex e, d; - e = pow(sin(x), -1).series(x, exZERO(), 8) + pow(sin(-x), -1).series(x, exZERO(), 12); + e = pow(sin(x), -1).series(x, 0, 8) + pow(sin(-x), -1).series(x, 0, 12); d = Order(pow(x, 6)); - result += check_series(e, exZERO(), d); + result += check_series(e, 0, d); return result; } @@ -124,19 +124,40 @@ static unsigned series3(void) unsigned result = 0; ex e, d; - e = sin(x).series(x, exZERO(), 8) * pow(sin(x), -1).series(x, exZERO(), 12); + e = sin(x).series(x, 0, 8) * pow(sin(x), -1).series(x, 0, 12); d = 1 + Order(pow(x, 7)); - result += check_series(e, exZERO(), d); + result += check_series(e, 0, d); return result; } -// Series of special functions +// Order term handling static unsigned series4(void) +{ + unsigned result = 0; + ex e, d; + + e = 1 + x + pow(x, 2) + pow(x, 3); + d = Order(1); + result += check_series(e, 0, d, 0); + d = 1 + Order(x); + result += check_series(e, 0, d, 1); + d = 1 + x + Order(pow(x, 2)); + result += check_series(e, 0, d, 2); + d = 1 + x + pow(x, 2) + Order(pow(x, 3)); + result += check_series(e, 0, d, 3); + d = 1 + x + pow(x, 2) + pow(x, 3); + result += check_series(e, 0, d, 4); + return result; +} + +// Series of special functions +static unsigned series5(void) { unsigned result = 0; ex e, d; + // gamma(-1): e = gamma(2*x); d = pow(x+1,-1)*numeric(1,4) + pow(x+1,0)*(numeric(3,4) - @@ -165,6 +186,7 @@ static unsigned series4(void) Order(pow(x+1,4)); result += check_series(e, -1, d, 4); + // tan(Pi/2) e = tan(x*Pi/2); d = pow(x-1,-1)/Pi*(-2) + pow(x-1,1)*Pi/6 + @@ -188,6 +210,7 @@ unsigned series_expansion(void) result += series2(); result += series3(); result += series4(); + result += series5(); if (!result) { cout << " passed ";