Computing exponentials and Trig functions
mr.janus at mac.com
mr.janus at mac.com
Thu Dec 6 18:47:52 CET 2007
No i agree, there isn't much need to store variables for the real exp(x).
But for exp(x + i*y) things get a bit more complicated when you have to call sin and cos. I'm sure that with some careful thought i could optimise these functions, at the moment they are optimised to the point where they work. i.e as soon as i got them working they were left with no clever optimisations at all. I'm not quite at the point that i am saving every variable every loop of the iteration but beyond that the code isn't exactly streamlined.
The reason i am using global scratch to dump variables in is because i have to calculate the complex exp of 2-d matrices which are about 1024 elements square. I felt that a single malloc of sufficient storage (just a few variables for storing intermediary values) would be better than creating, initialising then freeing a few variables a million times.
Many thanks for your help
Huw
On Thursday, December 06, 2007, at 05:23PM, "Fredrik Johansson" <fredrik.johansson at gmail.com> wrote:
>On Dec 6, 2007 6:15 PM, <mr.janus at mac.com> wrote:
>> Thanks for the quick response.
>>
>> I have already done the modulo pi/2 trick to speed things up. I think the biggest part of my problem is that each time i call a trig function i create storage for the temporary calculations. I am currently modifying the code so there is a global 'scratch' matrix that i can just dump data into without having to ask malloc for more space and initialise each time. Hopefully this will speed things up nicely.
>
>There shouldn't be a need for a lot of temporary storage. Are you
>computing each term from scratch? To compute exp(x) (for example), you
>should only need two variables besides the input: one variable s to
>store the accumulated sum and one temporary variable t:
>
>t = 1
>s = t
>t = t * x / 1
>s += t
>t = t * x / 2
>s += t
>t = t * x / 3
>s += t
>t = t * x / 4
>s += t
>etc
>
>Fredrik
>
>
More information about the gmp-discuss
mailing list