optimization of an order n^3- routine



Hi -

don't know, whether this is the appropriate newsgroup for
this algorithmic question; - anyway, here it goes.

To evaluate f(b,x) = b^b^b^x I've a routine, which uses
conversion of f(b,x) into
sum {k=0..inf} g(b)^k * h(x,k)
where h(x,k) is a routine of quadratic order but is
independent of b, so -assumed constant x (for simpliness
x=1 may be assumed) I could store the values for h(x,k)
in a vector of sufficient length. Sufficient means here,
because h(x,k) is convergent for k->inf, and even approaches
zero faster than g(b)^k diverges, some couple of hundred
entries for say, k<500.

I could principally use a matrix, but a matrix of 500x500
seems to be too big for my purposes. So I ask here for
possibly better implementation of dynamic computation, possibly
keeping few vectors of length ~ 500 in memory.

The function goes like this
\\ most inner loop
t3s2(x,r0,r1) = sum(r2=0,r1, (r0-r1)^(r1-r2) / (r1-r2)! * (r1-r2)^r2 / r2! * x^r2 )
\\ second inner loop
t3s1(x,r0) = sum(r1=0,r0, 1 / (r0-r1)! * t3s2(x,r0,r1))
\\ outer loop
t3s0(b,x,r0max)=local(lb=log(b)); sum(r0=0,r0max, lb^r0 * t3s1(x,r0))

Then, for b=1.5 or b=2.0 (x=1.0) I need 40 or 60 terms to get convergence
and approximation up to 10 or 12 digits

for(k=1,50,print(k," ",t3s0(1.5,1.0,k))); \\ b=1.5 40 Terms
for(k=1,70,print(k," ",t3s0(2.0,1.0,k))); \\ b=2.0 60 Terms

It is obvious, that at least the factorials could be precomputed
and stored in a vector of length r0max. The powers (r0-r1)^(r1-r2)
could be precomputed as well and stored in a matrix - but this
needed then the size of r0max * r0max , which I don't want.

To accelerate I tried to rewrite this, using binomials and extracting
constant terms as much out as possible, so I have this other version:

\\ Alternative (only sketch: the (r0-r1)=0 -case is not yet properly respected in t3s2)
t3s2(x,r0,r1) = sum(r2=0,r1, (r1-r2)^r2 * binomial(r1,r2) * (x/(r0-r1))^r2 )
t3s1(x,r0) = sum(r1=0,r0, (r0-r1)^r1 * binomial(r0,r1) * t3s2(x,r0,r1) )

t3s0(b,x,r0max)=local(lb=log(b));
sum(r0=0,r0max, lb^r0/r0! * t3s1(x,r0))

Does someone see a better optimization?

Gottfried



--
---

Gottfried Helms, Kassel
.



Relevant Pages

  • Re: Any problems with massive loop unrolling on 8088?
    ... > project, and my decompression inner loop, while as simple as I can make ... > it, is out of registers (yes, I'm using BP, and no, I can't halt ... > interrupts and use SS or SP because this routine has to coexist with an ... Using a state machine style layout, with direct jumps from one routine ...
    (comp.lang.asm.x86)
  • Re: Problem using ForeignToRTF32
    ... There are issues with permissions on ... not DCOM. ... and the conversion always works without a problem. ... exactly the same arguments to the routine from both programs. ...
    (microsoft.public.word.conversions)
  • Re: Date formats
    ... The origin of the Lilian date terminology has nothing to do with COBOL. ... We had a widely used installation date routine that pre-dated my arrival ... avoided the need for ndifferent conversion routines by having many ...
    (bit.listserv.ibm-main)
  • Re: Possible Feature
    ... Just done a series of big DB changes and needed to recompile all the SPL ... I use 'LIKE' for the input parameters and local variables but you ... Having internal variables within a routine that are defined LIKE table.column is fine as these are used internally and if you modify the table the routine will be recompiled the next time it is run so no problems. ... the routine recompiles and the ESQL/C or ODBC library makes the appropriate automatic conversion from CHARto INTEGER. ...
    (comp.databases.informix)
  • Re: Converting a bitmap from 24 bits format to 8 bits format
    ... First you need to create an empty folder somewhere and then unzip the contents of the zip file that you downloaded into that folder. ... So far the program has performed the conversion but it hasn't saved the result. ... bytes for the pixel data itself with the remaining thousand or so bytes being the header data and the palette data. ... buttons into the "Private Sub cmdConvert_Click" routine and you could hard code an output filename into the "Private Sub cmdSave_Click" routine and comment out the bits that show the save dialog. ...
    (microsoft.public.vb.general.discussion)