UPDATED PORTION OF QUESTION AT THE BOTTOM
First, let me apologize for two things: 1) I'm very new to Mathematica, so this question is certainly very stupid, 2) I looked for the solution to this both on this site, as well as in the tutorial and website help documents. I'm sure the answer is there somewhere, but I fear I don't know enough about the software to fully understand what I'm looking for.
What I'm trying to do is nest one function inside of another, but not by using the "Nest" command (note, I'm going into detail in each step in case there are any additional errors I'm making, but just not noticing):
The first function is a relatively simple probability calculation for the chance of getting $h$ heads in $f$ flips, so I have:
prob[h_, f_ ] := (f!/(h! (f - h)!))/(2^f)
Now, I'd like to transform that probability by a transformation function $fp$:
fp[prob_] := 2 prob - prob^2
However, this doesn't seem to be working. Additionally, I'd like to be able to evaluate the $fp$ function for given values of $h$ and $f$- if anyone has any insights they'd be much appreciated!!
Thank you guys so much for your time!!!
Note: This seems to work alright (thanks to @kglr for pointing that out haha), but is directly related to the following updated question:
UPDATED:
I was hoping the case above would be a bit more generalizable, but I'm still having difficulty in a related (though slightly different) example:
I have a function $u$ that I would like to perform a basic transformation of the form:
u[z_] := -E^(-z)
I'd then like to call on the function $u$ in a new function $ud$ such that it takes any given number of heads $h$, transforms that number $h$ by the function $u$, and then multiply the result by the transformed probability for that number of heads $fp$. What I have to accomplish this is:
ud[fp_, u_, h_, f_] := u[h]fp[h,f]
But this isn't returning the desired result. That said, I'm not 100% sure I properly know how to feed in specific numbers to the aforementioned function, so the problem could be at a very basic level haha.
Thanks again!!!!
EDIT 2:
At the (wise) suggestion of @jjc385 my overall code is:
Clear[prob, h, f, fp, u, z, ud]
prob[h_, f_] := (f!/(h! (f - h)!))/(2^f)
(*prob[2, 2] +++ Just a check for the probability function *)
fp[prob_] := 2 prob - prob^2
u[z_] := -E^(-z)
ud[fp_, u_, prob_, h_, f_] := u[h] fp[prob[h, f]]
ud[fp, u, prob, 1, 2]
Which I actually think is working. Is there anything that immediately jumps out as incorrect? Otherwise, I think my issues are pretty much resolved!
On that note, though, I'd love it if one of you guys would post their comments as an answer so I can give it the credit/reputation that's well deserved!! Just going through it in response to the comments (such as the proper syntax for nesting functions in @kglr's comment, and the recommendation of @jjc385 for what to try, was (I think) what was needed!!
Thanks again guys! (Should I just edit a [CLOSED] into the Qustion Title, or is there another method to properly close a question? Again, If someone would like, I'd be more than happy to choose a top answer to close it too!)
fp[prob[5, 10]]gives28287/65536as it should, no? – kglr Sep 08 '17 at 16:58Binomial[]is built-in? – J. M.'s missing motivation Sep 08 '17 at 17:09ud[fp,u,5,10]? – jjc385 Sep 08 '17 at 17:25ud[h_, f_] := u[h] fp[prob[h, f]]rather than having to specify the functions (u,fp,prob) to use every time you callud. This may or may not be more convenient, depending on your needs. – jjc385 Sep 08 '17 at 20:23