The Math Forum

Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Math Forum » Discussions » Inactive » comp.soft-sys.math.mathematica

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: Help on compiling a function
Replies: 6   Last Post: Jan 19, 2011 5:24 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]

Posts: 26
Registered: 9/18/07
Help on compiling a function
Posted: Jan 16, 2011 5:55 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

Hi everyone,

I had written about this but wanted to revisit the problem in light of
the latest Mathematica options for compiling (C and parallelization),
which I was hoping to try to use on this function, which is the main
arithmetic and time-consuming part of my simulation.

I have the following code:

example1 =
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)];

but under input such as the following it breaks:

example1[{97.6203, 8.4788, 21.4204, 46.1755}, 1, 1, {39.9342, 7.5820,
5.8656, 10.0553}]
CompiledFunction::cfse: Compiled expression
1.33128164105722332870399207`12.920368310128136*^315 should be a
machine-size real number. >>
CompiledFunction::cfex: Could not complete external evaluation at
instruction 4; proceeding with uncompiled evaluation. >>

the problem is just that in the calculation Gamma ends up being really
big, larger than $MaxMachineNumber so it complains.

Anybody see a way around this? This is the workhorse function of my
simulation, so any gain in speed helps a lot

Thanks in advance,

Longer explanation (if interested):

example =
Compile[{{n, _Real, 1}, {a, _Real}, {b, _Real}, {t, _Real, 1}},
Module[{totaln, totalt, gammanp1times, tpowntimes, times1, div1,
times2, times3, pow1, gammatotnpa}, totaln = Total[n];
totalt = Total[t];
gammanp1times = Apply[Times, Gamma[n + 1]];
tpowntimes = Apply[Times, t^n];
times1 = Times[gammanp1times, Gamma[a]];
gammatotnpa = Gamma[totaln + a];
div1 = Divide[gammatotnpa, times1];
times2 = Times[div1, b^a];
times3 = Times[times2, tpowntimes];
pow1 = Power[totalt + b, totaln + a];
Divide[times3, pow1]]
example[{97.6203, 8.4788, 21.4204, 46.1755}, 1, 1, {39.9342, 7.5820,
5.8656, 10.0553}]

the result of gammatotnpa is greater than 10^315 which is greater than
$MaxMachineNumber on my machine. Any suggestions?

Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.