Edit for clarity: How does Mathematica's function Series
know that Gamma[x]
has a pole at x=0
? When Series
is called to expand near x=0
, it gives the proper 1/x
term in its Laurent expansion. I need to copy this behavior of Series
to user-defined functions.
Series[Gamma[x],{x,0,1}]
1/x-EulerGamma+1/12 (6 EulerGamma^2+[Pi]^2) x+O[x]^2
In the package I'm writing I have several complicated functions that have simple poles near isolated points. These functions are to be evaluated only when its arguments are numerical. Otherwise, for the sake of brevity of the output, these functions remain unevaluated and is supposed to act like a special function.
Simple example: $$f(x) = \frac{\cos(x)}{x}$$
Task: I would like to be able to carry out a Series
expansion in $x$; especially around $x=0$ where it should yield the $1/x$ pole term in the Laurent series:
Here is what I did:
SetAttributes[f,NumericFunction];
f[x_?NumericQ] := 1/x Cos[x];
Derivative[n_][f][x_] := Derivative[n][1/# Cos[#] &][x];
So now, I test this, and try to obtain the expansion near $x=\pi/2$.
Series[f[x], {x, Pi/2, 2}]
which works, but around $x=0$,
Series[f[x], {x, 0, 2}]
I get an error. So, how can I tell Series
that at $x=0$, the function f
starts at $1/x$? I need Series
to behave just as it would if I gave it the full functional form explicitly:
Series[1/x Cos[x], {x, 0, 2}]
1/x Cos[x]
is just a simple example. In the application I'm developing, the expression is substantially more complicated. I would rather letf[x]
be an abbreviation for this complicated analytic expression, and let users be able work withf
instead of the complicated expression. $\endgroup$Hold
andReleaseHold
? $\endgroup$f
? $\endgroup$