I have a function myFunc which I is to be displayed cleanly if arguments are symbolic, but which can also be numerically evaluated. I do this by defining a complicated auxiliary function pR which is evaluated only if its arguments are numerical (probably not a good idea?).
kin[a_, b_, c_] = a^2 + b^2 + c^2 - 2 a b - 2 a c - 2 b c;
pR[s_?NumericQ, m0_?NumericQ, m1_?NumericQ] :=
1/s*Sqrt[kin[s, m0^2, m1^2]]*Log[(2 m0 m1)/(-s + m0^2 + m1^2 - Sqrt[kin[s, m0^2, m1^2]])]
The function (watered-down) I wish to define is
myFunc[n_?IntegerQ, s_, m0_, m1_] :=
Sum[
Binomial[n + 1, 2 idx3 + 1]*((s + m0^2 - m1^2)/(2 s))^(n - 2 idx3)
*(kin[s, m0^2, m1^2]/(4 s^2))^idx3, {idx3, 0, (n + 1)/2}] pR[s, m0, m1];
So for example:
myFunc[4,s,m,m]//Simplify
(* ((m^4 - 3 m^2 s + s^2) pR[s, m, m])/s^2 *)
and the complicated mess is in pR.
The problem I'm running into is:
- I don't know how to code it so that the user can forcibly display the function
pRin its entirety -- even if its arguments are symbolic, overriding the?NumericQ. - I would like to be able to take derivatives (
D),Limits, and perform a TaylorSeriesexpansion onmyFuncappropriately handling the auxiliary functionpR. This should trigger the override in the previous point.
Any ideas? Thanks!
?NumericQat all here. Why did you use it? – Szabolcs Jan 08 '13 at 20:59?NumericQ, then the output of my examplemyFunc[4,s,m,m]would be drastically more complicated. – QuantumDot Jan 08 '13 at 21:12pR. If you need the full expression (for numeric evaluation, series expansion, etc.), justReplaceAllthat inert head withpR:expr /. someHead -> pR. – Szabolcs Jan 08 '13 at 21:26expandPRwhich contains the definition ofpR. I find that unnecessarily complicated. – Szabolcs Jan 08 '13 at 21:29Formated; potentially confusing) something understandable. You still need two symbols either way, right? – Mr.Wizard Jan 08 '13 at 21:34Formator anything complicated at all. Just don't putpRinmyFunc. PutinertpRinstead. Then when you need to have the full expression, just do... /. inertpR -> pR. Usually this can be done either before before or after doing operations like taking derivatives, series expansion or substituting numerical values. Instead of having an auxiliary functionexpandPR, we have a short one liner (/. inertpR -> pR), so it's easy to be flexible about naming that head. Also, we can usepRwhenever we want without needing to apply... – Szabolcs Jan 08 '13 at 21:52expandPRin addition. Of course whether to put the function definition into a rule or replace the function head instead is a matter of preference and there's no point in writing another full answer for this. – Szabolcs Jan 08 '13 at 21:52