Re: question for compiling a function
- To: mathgroup at smc.vnet.net
- Subject: [mg113184] Re: question for compiling a function
- From: Ray Koopman <koopman at sfu.ca>
- Date: Sun, 17 Oct 2010 06:05:52 -0400 (EDT)
- References: <i95tjc$65h$1@smc.vnet.net> <i9a55i$nfq$1@smc.vnet.net>
On Oct 15, 11:05 am, Ramiro <ramiro.barran... at gmail.com>
> I got feedback from two people and it worked great:
>
> My new function based on the suggestions is the following:
>
> example2 =
> Compile[{{n, _Real, 1}, {a, _Real}, {b, _Real}, {t, _Real, 1}},
> Gamma[Total[n] + a]/(Times @@ (Gamma[n + 1])* Gamma[a])*b^a*
> Times @@ (t^n)/(Total[t] + b)^(Total[n] + a)]
>
> However, over certain inputs I get the following:
>
> example2[{97.6203, 8.4788, 21.4204, 46.1755}, 1, 1,
> {39.9342, 7.5820, 5.8656, 10.0553}]
>
> During evaluation of In[277]:= CompiledFunction::cfse: Compiled
> expression 1.33128164105707197950410345`12.920368310128088*^315
> should be a machine-size real number. >>
>
> During evaluation of In[277]:= CompiledFunction::cfex: Could not
> complete external evaluation at instruction 4; proceeding with
> uncompiled evaluation. >>
>
> What can I do?
>
> Thank you,
> Ramiro
Changing Gamma[x] to (x-1)!, and moving b^a
from the first line to the second, we have
(Tr@n+a-1)!/(Times@@(n!)*(a-1)!) *
b^a * Times@@(t^n) / (Tr@t+b)^(Tr@n+a)
The first line = Multinomial@@Append[n,a-1].
The second line = Times@@((Append[t,b]/(Tr@t+b))^Append[n,a]).
With[{n = {97.6203, 8.4788, 21.4204, 46.1755}, a = 1, b = 1,
t = {39.9342, 7.5820, 5.8656, 10.0553} },
Multinomial@@Append[n,a-1] *
Times@@((Append[t,b]/(Tr@t+b))^Append[n,a]) ]
1.06265*^-11