X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?p=ginac.git;a=blobdiff_plain;f=check%2Fexam_pseries.cpp;h=052868edb27d9c41e15cc8bee15c9ecda8bdac59;hp=7b4473469a2a14c6c075a3812f45aa118bbe58cc;hb=cca88b51436e4b654d16a4d60cd0d1c66fcf5dd6;hpb=846e62e85c483f74d1e253c7841050ea11d70451 diff --git a/check/exam_pseries.cpp b/check/exam_pseries.cpp index 7b447346..052868ed 100644 --- a/check/exam_pseries.cpp +++ b/check/exam_pseries.cpp @@ -3,7 +3,7 @@ * Series expansion test (Laurent and Taylor series). */ /* - * GiNaC Copyright (C) 1999-2004 Johannes Gutenberg University Mainz, Germany + * GiNaC Copyright (C) 1999-2014 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 @@ -17,10 +17,14 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include "exams.h" +#include "ginac.h" +using namespace GiNaC; + +#include +using namespace std; static symbol x("x"); @@ -43,9 +47,15 @@ static unsigned exam_series1() { using GiNaC::log; + symbol a("a"); + symbol b("b"); unsigned result = 0; ex e, d; + e = pow(a+b, x); + d = 1 + Order(pow(x, 1)); + result += check_series(e, 0, d, 1); + 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, 0, d); @@ -115,11 +125,22 @@ static unsigned exam_series1() + Order(pow(x, 2)); result += check_series(e, 0, d, 2); - symbol a("a"); + e = sqrt(1+x*x) * sqrt(1+2*x*x); + d = 1 + Order(pow(x, 2)); + result += check_series(e, 0, d, 2); + e = pow(x, 4) * sin(a) + pow(x, 2); d = pow(x, 2) + Order(pow(x, 3)); result += check_series(e, 0, d, 3); + e = log(a*x + b*x*x*log(x)); + d = log(a*x) + b/a*log(x)*x - pow(b/a, 2)/2*pow(log(x)*x, 2) + Order(pow(x, 3)); + result += check_series(e, 0, d, 3); + + e = pow((x+a), b); + d = pow(a, b) + (pow(a, b)*b/a)*x + (pow(a, b)*b*b/a/a/2 - pow(a, b)*b/a/a/2)*pow(x, 2) + Order(pow(x, 3)); + result += check_series(e, 0, d, 3); + return result; } @@ -152,6 +173,7 @@ static unsigned exam_series3() // Series exponentiation static unsigned exam_series4() { + using GiNaC::tgamma; unsigned result = 0; ex e, d; @@ -190,6 +212,7 @@ static unsigned exam_series5() // Series expansion of tgamma(-1) static unsigned exam_series6() { + using GiNaC::tgamma; ex e = tgamma(2*x); ex d = pow(x+1,-1)*numeric(1,4) + pow(x+1,0)*(numeric(3,4) - @@ -307,6 +330,7 @@ static unsigned exam_series11() static unsigned exam_series12() { using GiNaC::log; + using GiNaC::atanh; unsigned result = 0; ex e, d; @@ -331,13 +355,42 @@ static unsigned exam_series12() return result; } +// Test of the patch of Stefan Weinzierl that prevents an infinite loop if +// a factor in a product is a complicated way of writing zero. +static unsigned exam_series13() +{ + unsigned result = 0; + + ex e = (new mul(pow(2,x), (1/x*(-(1+x)/(1-x)) + (1+x)/x/(1-x))) + )->setflag(status_flags::evaluated); + ex d = Order(x); + result += check_series(e,0,d,1); + + return result; +} + +// Test if (1+x)^(1/x) can be expanded. +static unsigned exam_series14() +{ + unsigned result = 0; + + ex e = pow(1+x, sin(x)/x); + ex d = 1 + x - pow(x,3)/6 + Order(pow(x,4)); + try { + result += check_series(e,0,d,4); + } catch (const pole_error& err) { + clog << "series expansion of " << e << " at 0 raised an exception." << endl; + ++result; + } + + return result; +} unsigned exam_pseries() { unsigned result = 0; cout << "examining series expansion" << flush; - clog << "----------series expansion:" << endl; result += exam_series1(); cout << '.' << flush; result += exam_series2(); cout << '.' << flush; @@ -351,12 +404,13 @@ unsigned exam_pseries() result += exam_series10(); cout << '.' << flush; result += exam_series11(); cout << '.' << flush; result += exam_series12(); cout << '.' << flush; + result += exam_series13(); cout << '.' << flush; + result += exam_series14(); cout << '.' << flush; - if (!result) { - cout << " passed " << endl; - clog << "(no output)" << endl; - } else { - cout << " failed " << endl; - } return result; } + +int main(int argc, char** argv) +{ + return exam_pseries(); +}