Feedback It may be very difficult to make exponentiation efficient. 

Forum: Com Sci 12500, U Chicago, Autumn 2002, Discuss Classwork
Re: News Project step #5, deadline Monday 2 December (Mike O'Donnell)
Re: Question Error in exp_xreal? (Maris Goldmanis)
Re: Warning Something's wrong still... (Mark Kittisopikul)
Date: 2002, Nov 29
From: Mike O'Donnell <odonnell@cs.uchicago.edu>

I think and hope that I corrected the erroneous result in exp_xreal. But the very slow performance appears to be very hard to fix. I suggest that you first just concentrate on adding the cached interval to results of exp_xreal, and test it on small exponents where you don't mind waiting for the results. Small appears to mean something like <=3 with the current code. Anyone who wants to go further can try out ideas for speeding up exponentiation, and post them. There might be some ideas in the articles that I handed out.

In order to find out more about the slow performance, I instrumented refine_exp_xr->ratintvl to print out each successive scale value. Computing ((exp_xreal (rational->xreal 5)) 0.5), the scale runs up to 4096, with each scale value taking longer. I left the instrumentation code in version 3, but I commented the lines containing it. If you want to do experiments, you can copy my definition and remove the comment marks. I lost patience on 4096, and stopped the computation. From the huge rationals produced by smaller cases, and from the continual garbage collection reported by the system, it's clear that much if not all of the problem has to do with the huge multiprecision integers in the rationals. It's easy to see that scaling by 4096 leads to taking rationals to the 4096 power, which can produce huge numerators and denominators.

In the long run, part of the solution will certainly involve the use of lower complexity approximations to high-complexity rationals. The right time to work that out is probably after converting to a binary rational representation, in which you only need to give the exponent of 2 for the denominator (although it appears that numerators can still get troublingly long in this representation). That's probably too much to try to accomplish before doing the cache step, which appears to be a lot easier.

For the short run, it seems worthwhile to try to improve the approximation to e^x for small x (x in [-1,1]), since that can reduce the size of the scale values. I experimented briefly with raising the scale factor faster, but that's probably not a good idea, since it causes a lot of overshoot in the complexities of the rationals. To improve the approximation to e^x for small x, I just took more terms of the Taylor series. Notice that my lower bound 1+x <= e^x is just the 2-term Taylor series, and my upper bound e^x <= 1+x+x^2 is a rounded-up version of the 3-term Taylor series (1+x+x^2/2). For upper bounds, we have to increase the last coefficient, since prefixes of the Taylor series are always underestimating e^x. To keep the rounded-up Taylor series uniformly overestimating on negative x as well as positive x, I'll only use even-powered prefixes. I went up to the 6th power, and it appears to improve some smaller cases, but I still don't get interesting approximations to e^5.

I think that the upper bound is the important one to improve. The lower bound 1+x is exact in its values and in all of its derivatives at 0. But the upper bound is only exact at 0 to a number of derivatives determined by the highest power. But someone who wants to experiment might try using longer Taylor expansions as lower bounds.




Mike O'D.


to: "It may be very difficult to make exponentiation efficient."