I am not sure if what I want to do can be done, but I thought to ask anyway.
Note: I already have in hand a workaround, I was just wondering for the power/simplicity that Mathematica may provide.
Problem: Suppose that I have in hand a polynomial in x, y, z
and only products between x,, z
and y, z
occur, e.g.
p = Pi x*z + Zeta[9] x^2*z + 123/7 z + 1/2 x + 5 y + 9/2 y*z + 3 y^5*z + 1/Pi* z^4
,
where I put some random constant coefficients in front of every term.
Now suppose, I have a homemade function that only executes "stuff" on numerical/numbers such as Zeta[3]
or 19/2
. If I apply that function (e.g. myF
) to p
(myF /@ p
) then it doesn't do "the job" because it can't handle the variables x,y,z
.
Is there a way when I do myF /@ p
to actually get
myF /@ p = myF[Pi] x*z + myF[Zeta[9]] x^2*z + myF[123/7] z + myF[1/2] x + myF[5] y + myF[9/2] y*z + myF[3] y^5*z + myF[1/Pi]* z^4
I know that the build in function N
, has attribute NHoldAll
and this is how it performs a similar to the problem, job.
Comment: No I will not give you more information (!) about the function myF
because I want this to be as generic as it gets. If it has a solution, it is nice to be known and applied to any kind of "home-brewed" function since I can think of a big class of functions that would a enjoy such an attribute.
Thank you!
Distribute[]
? $\endgroup$2
inx^2
in the second term. I suppose you mean to operate only on the numerical coefficients? Might nonnumerical coefficients arise? Are the polynomials always expanded as in the example? I suppose the coefficient zero should be mapped to zero, notmyF[0]
? $\endgroup$1
? $\endgroup$x^2
was to be treated as a1
. Which way do you want it,x^2
becomesmyF[1] x^2
or it remainsx^2
? $\endgroup$