[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
4.10 Mathematical functions
There are quite a number of useful functions hard-wired into GiNaC. For instance, all trigonometric and hyperbolic functions are implemented (See section Predefined mathematical functions, for a complete list).
These functions (better called pseudofunctions) are all objects
of class function
. They accept one or more expressions as
arguments and return one expression. If the arguments are not
numerical, the evaluation of the function may be halted, as it does in
the next example, showing how a function returns itself twice and
finally an expression that may be really useful:
... symbol x("x"), y("y"); ex foo = x+y/2; cout << tgamma(foo) << endl; // -> tgamma(x+(1/2)*y) ex bar = foo.subs(y==1); cout << tgamma(bar) << endl; // -> tgamma(x+1/2) ex foobar = bar.subs(x==7); cout << tgamma(foobar) << endl; // -> (135135/128)*Pi^(1/2) ... |
Besides evaluation most of these functions allow differentiation, series expansion and so on. Read the next chapter in order to learn more about this.
It must be noted that these pseudofunctions are created by inline
functions, where the argument list is templated. This means that
whenever you call GiNaC::sin(1)
it is equivalent to
sin(ex(1))
and will therefore not result in a floating point
number. Unless of course the function prototype is explicitly
overridden – which is the case for arguments of type numeric
(not wrapped inside an ex
). Hence, in order to obtain a floating
point number of class numeric
you should call
sin(numeric(1))
. This is almost the same as calling
sin(1).evalf()
except that the latter will return a numeric
wrapped inside an ex
.