RE: Can Factorial[] be compiled?
- To: mathgroup at smc.vnet.net
- Subject: [mg15023] RE: [mg14990] Can Factorial[] be compiled?
- From: "Ersek, Ted R" <ErsekTR at navair.navy.mil>
- Date: Sat, 5 Dec 1998 01:30:25 -0500
- Sender: owner-wri-mathgroup at wolfram.com
Compile can't convert Factorial[i] into pseudocode. You can get a list of all constants and functions that Compile can convert to pseudocode if you search for Compile at: http://www.wolfram.com/support/Kernel/Symbols/ To get your Compiled function to work well you need to replace Factorial and Sum with lower level functions. The following should work nicely: In[1]:= f = Compile[{{m, _Real}, {n, _Real}}, Plus@@Table[ (m^i*Sqrt[i])/Times@@Range[i],{i, 1.0, n,1.0} ]/E^m]; ____________________ Below we see the CompiledFunction for (f) is all pseudocode. In[2]:= f[[3]] Out[6]= {{1,2},{4,1,0},{4,2,1},{15,1.,11},{15,1.,12},{14,1,2},{42,11,13},{34,1,13,13 },{45,12,14},{38,13,14,13},{83,13,3},{33,2,3,2},{108,2,1,3,1},{14,0,3},{24,3 ,15},{38,15,12,15},{34,11,15,15},{20,15,13},{131,3,2,24},{50,0,13,15},{52,13 ,16},{38,15,16,15},{83,13,6},{108,6,1,2,3},{14,0,8},{19,8,7},{131,7,6,3},{10 9,7,3},{91,-2},{14,1,6},{107,3,8},{14,0,9},{131,9,8,5},{114,3,9,10},{37,6,10 ,10},{19,10,6},{91,-4},{24,6,16},{45,16,17},{38,15,17,15},{109,15,1},{91,-27 },{15,0.,9},{107,1,3},{14,0,4},{131,4,3,5},{114,1,4,10},{34,9,10,10},{20,10, 9},{91,-4},{53,0,10},{45,10,11},{38,9,11,2},{9,2}} Cheers, Ted Ersek ___________________________ I'm trying to compile the function below, but Mathematica refuses to compile the i!; notice the term {31, Function[{m, n}, i!], {i, 3, 0, 15, Block}, 3, 0, 19} in the InputForm of the compiled function. Does anyone have a suggestion on how to fix this? Thanks in advance. Wagner Truppel f = Compile[{{m, _Real}, {n, _Real}}, Sum[(m^i*Sqrt[i])/i!, {i, 1.0, n, 1.0}]/E^m]; InputForm[f] InputForm[CompiledFunction[{_Real, _Real}, {0, 5, 21, 0, 2}, {{1, 2}, {4, 1, 0}, {4, 2, 1}, {42, 0, 2}, {53, 2, 3}, {15, 1., 13}, {15, 1., 14}, {14, 1, 2}, {42, 13, 15}, {34, 1, 15, 15}, {45, 14, 16}, {38, 15, 16, 15}, {83, 15, 3}, {33, 2, 3, 2}, {108, 2, 1, 3, 1}, {14, 0, 3}, {24, 3, 17}, {38, 17, 14, 17}, {34, 13, 17, 17}, {20, 17, 15}, {131, 3, 2, 8}, {50, 0, 15, 17}, {52, 15, 18}, {31, Function[{m, n}, i!], {i, 3, 0, 15, Block}, 3, 0, 19}, {45, 19, 20}, {38, 17, 18, 20, 17}, {109, 17, 1}, {91, -11}, {15, 0, 11}, {107, 1, 3}, {14, 0, 4}, {131, 4, 3, 5}, {114, 1, 4, 12}, {34, 11, 12, 12}, {20, 12, 11}, {91, -4}, {38, 3, 11, 2}, {9, 2}}, Function[{m, n}, Sum[(m^i*Sqrt[i])/i!, {i, 1.0, n, 1.0}]/E^m]]]