From: Richard Kreckel Date: Mon, 15 Nov 1999 17:50:43 +0000 (+0000) Subject: - account for new GNU-automake built-scheme X-Git-Tag: release_0-5-0~168 X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?p=ginac.git;a=commitdiff_plain;h=59b06b8ea838fd1a5c55bfc41ee32bcb3a2f04e2 - account for new GNU-automake built-scheme - added example of computation of Pi using Mechain's formula --- diff --git a/doc/tutorial/tutorial.sgml.in b/doc/tutorial/tutorial.sgml.in index cd8b053b..44fd6af3 100644 --- a/doc/tutorial/tutorial.sgml.in +++ b/doc/tutorial/tutorial.sgml.in @@ -106,7 +106,7 @@ pointless) bivariate polynomial with some large coefficients: My first GiNaC program (a bivariate polynomial) -#include <GiNaC/ginac.h> +#include <ginac/ginac.h> int main() { @@ -136,7 +136,7 @@ variable. My second GiNaC program (Hermite polynomials) -#include <GiNaC/ginac.h> +#include <ginac/ginac.h> ex HermitePoly(symbol x, int deg) { @@ -338,15 +338,10 @@ with the --help option. The most important ones will be shortly described in what follows: - --enable-shared: When given, this option - switches on the build of a shared library, i.e. a - .so-file. A static libarary (i.e. a - .a-file) is still built. For this to succeed, - GNU libtool needs to be installed on your system. Hence, - configure checks if it can find an executable - libtool in the PATH. If it - doesn't this option is ignored and the default restored, which - means that only a static library will be build. + --disable-shared: When given, this option + switches off the build of a shared library, i.e. a + .so-file. This may be convenient when developing + because it considerably speeds up compilation. --prefix=PREFIX: The @@ -367,11 +362,11 @@ will be shortly described in what follows: --includedir=INCLUDEDIR: Use this option in case you want to have the header files installed in some other directory than - PREFIX/include/GiNaC/. For + PREFIX/include/ginac/. For instance, if you specify --includedir=/usr/include you will end up with the header files sitting in the directory - /usr/include/GiNaC/. Note that the subdirectory + /usr/include/ginac/. Note that the subdirectory GiNaC is enforced by this process in order to keep the header files separated from others. This avoids some clashes and allows for an easier deinstallation of GiNaC. This ought @@ -463,8 +458,8 @@ directories will be created if they don't already exist): All the header files will be installed into - PREFIX/include/GiNaC/ (or - INCLUDEDIR/GiNaC/, if + PREFIX/include/ginac/ (or + INCLUDEDIR/ginac/, if specified). @@ -543,7 +538,7 @@ the copying takes place as soon as you try to change the second. Consider the simple sequence of code: Simple copy-on-write semantics -#include <GiNaC/ginac.h> +#include <ginac/ginac.h> int main() { @@ -576,7 +571,7 @@ less trivial example of differentiation using the chain-rule should make clear how powerful this can be. Advanced copy-on-write semantics -#include <GiNaC/ginac.h> +#include <ginac/ginac.h> int main() { @@ -734,9 +729,9 @@ some useful constants. shows the four most important constructors: construction from C-integer, construction of fractions from two integers, construction from C-float and construction from a string. -Sample C++ program +Construction of numbers -#include <GiNaC/ginac.h> +#include <ginac/ginac.h> int main() { @@ -777,7 +772,7 @@ stored with a precision matching that number of decimal digits: Controlling the precision of floating point numbers #include -<GiNaC/ginac.h> +<ginac/ginac.h> void foo() { @@ -822,7 +817,7 @@ back to invocations of certain CLN functions.) with some multiple of its denominator and check what comes out: Sample test on objects of type numeric -#include <GiNaC/ginac.h> +#include <ginac/ginac.h> int main() { @@ -963,7 +958,7 @@ type add is called to hold the sum of that mul object and the number one: Construction of <literal>add</literal> and <literal>mul</literal> objects -#include <GiNaC/ginac.h> +#include <ginac/ginac.h> int main() { @@ -1060,7 +1055,7 @@ it, so you can alternatively call it in a functional way as shown in the simple example: Methods vs. wrapper functions -#include <GiNaC/ginac.h> +#include <ginac/ginac.h> int main() { @@ -1127,7 +1122,7 @@ a univariate polynomial in one of the variables with the coefficients being polynomials in the remaining variables. The method collect() accomplishes this task: - #include <GiNaC/ginac.h> + #include <ginac/ginac.h> ex ex::collect symbol const & s @@ -1135,7 +1130,7 @@ Note that the original polynomial needs to be in expanded form in order to be able to find the coefficients properly. The range of occuring coefficients can be checked using the two methods - #include <GiNaC/ginac.h> + #include <ginac/ginac.h> int ex::degree symbol const & s @@ -1150,7 +1145,7 @@ in the following example: Collecting expressions in multivariate polynomials -#include <GiNaC/ginac.h> +#include <ginac/ginac.h> int main() { @@ -1209,7 +1204,7 @@ and lcm(a,b) returns the product of a and b. Polynomal GCD/LCM -#include <GiNaC/ginac.h> +#include <ginac/ginac.h> int main() { @@ -1247,7 +1242,7 @@ just like .expand(). Simple polynomial differentiation -#include <GiNaC/ginac.h> +#include <ginac/ginac.h> int main() { @@ -1266,7 +1261,7 @@ int main() Differentiation with nontrivial functions -#include <GiNaC/ginac.h> +#include <ginac/ginac.h> int main() { @@ -1287,7 +1282,7 @@ class of its own for storing such series as well as a class for storing the order of the series. A sample program could read: Series expansion -#include <GiNaC/ginac.h> +#include <ginac/ginac.h> int main() { @@ -1297,10 +1292,10 @@ int main() ex MyExpr2 = 1/(x - pow(x, 2) - pow(x, 3)); ex MyTailor, MySeries; - MyTailor = MyExpr1.series(x, numZERO(), 5); + MyTailor = MyExpr1.series(x, point, 5); cout << MyExpr1 << " == " << MyTailor << " for small " << x << endl; - MySeries = MyExpr2.series(x, numZERO(), 7); + MySeries = MyExpr2.series(x, point, 7); cout << MyExpr2 << " == " << MySeries << " for small " << x << endl; \\ ... @@ -1309,6 +1304,55 @@ int main() +As an instructive application, let us calculate the numerical +value of Archimedes' constant (for which there already exists the +built-in constant Pi) using Méchain's +wonderful formula Pi==16*atan(1/5)-4*atan(1/239). +We may expand the arcus tangent around 0 and insert +the fractions 1/5 and 1/239. +But, as we have seen, a series in GiNaC carries an order term with it. +The preprocessor-macro series_to_poly may be used +to strip this off: +Series expansion using Méchain's formula + +#include <ginac/ginac.h> + +ex mechain_pi(int degr) +{ + symbol x("x"); + ex pi_expansion = series_to_poly(atan(x).series(x,0,degr)); + ex pi_approx = 16*pi_expansion.subs(x==numeric(1,5)) + -4*pi_expansion.subs(x==numeric(1,239)); + return pi_approx; +} + +int main() +{ + ex pi_frac; + for (int i=2; i<12; i+=2) { + pi_frac = mechain_pi(i); + cout << i << ":\t" << pi_frac << endl + << "\t" << pi_frac.evalf() << endl; + } + return 0; +} + +When you run this program, it will type out: + +2: 3804/1195 + 3.1832635983263598326 +4: 5359397032/1706489875 + 3.1405970293260603143 +6: 38279241713339684/12184551018734375 + 3.141621029325034425 +8: 76528487109180192540976/24359780855939418203125 + 3.141591772182177295 +10: 327853873402258685803048818236/104359128170408663038552734375 + 3.1415926824043995174 + + + +