Timeline for How can I implement dynamic programming for a function with more than one argument?
Current License: CC BY-SA 3.0
11 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Jan 19, 2012 at 6:34 | vote | accept | J. M.'s missing motivation♦ | ||
Jan 18, 2012 at 0:42 | comment | added | Leonid Shifrin | @Mike Well, I'd keep that, but as you wish of course. | |
Jan 18, 2012 at 0:38 | comment | added | Leonid Shifrin |
@Mike Thanks! I came up with this first about 5 years ago, when I needed it to compute functions with a huge number of terms. In those days, I wouldn't make a mistake with Simplify , but I got rusty since I quit Physics :)
|
|
Jan 18, 2012 at 0:26 | history | edited | Leonid Shifrin | CC BY-SA 3.0 |
Removed Simplify
|
Jan 18, 2012 at 0:25 | comment | added | Mike Bailey | @LeonidShifrin: Just for the record, the way you did this is very cool and borderline black magic. | |
Jan 18, 2012 at 0:19 | comment | added | Leonid Shifrin |
@Mike Good point, I will edit. Simplify was taking the most time, I should have tried Expand alone. As to your first point: since in my case you compute all the previous ones in the process, you need almost no time to compute say CharlierC[101, a, x] fully symbolically then.
|
|
Jan 18, 2012 at 0:14 | comment | added | J. M.'s missing motivation♦ | I also deal with polynomials with more than three arguments, like the Hahn polynomials, and I expect to be varying indices and parameters a lot. So, Leonid's proposal seems to be most expedient for me. | |
Jan 18, 2012 at 0:05 | comment | added | Mike Bailey |
@LeonidShifrin: If you want to vary a and x, you can simply evaluate it and attach it to a variable: poly = CharlierC[100, a, x] and then evaluate it for any arbitrary {a, x}. You just have to be careful to only evaluate CharlierC[n, a, x] for sybmolic a and x for my version, and always attach it to something beforehand.
|
|
Jan 18, 2012 at 0:04 | comment | added | Leonid Shifrin |
@Mike My code creates definitions for absolutely arbitrary a . Also, some time is spent on Expand and Simplify . It is slow the first run, but instant all the following runs. If your task is to vary a (say, plot when a is in some range), I only need to compute stuff once, and it will work for every value of a . If there is a single numerical a , then your code wins, but then arguably a is a constant rather than a true function argument, so the memoization is effectively 1D.
|
|
Jan 17, 2012 at 23:59 | comment | added | Mike Bailey | I timed both versions, and yours is significantly slower on my machine. 0.016 seconds (mine) vs 1.185 seconds (yours) for n = 20. Still, very cool idea you have. | |
Jan 17, 2012 at 23:52 | history | answered | Leonid Shifrin | CC BY-SA 3.0 |