3
$\begingroup$

Possible Duplicate:
How can I calculate non-integer exponents?

What is the most efficient way to estimate $a^b$ ($a > 0$) numerically?
My goal is not to use built-in math functions (like $e^x$ or $\log x$), i.e. only using +-*/.

I successfully accomplished this task by estimating $e^x$ and $\log x$ (below), because $a^b=e^{b\log a}$.

What I have done so far is estimated $e^x$ using the Taylor's series expansion:

$$e^x=\sum_{k=0}^{\infty}\frac{x^k}{k!}$$

$x^k$ can be found simply by multiplying $1$ by $x$ by $k$ times (because $k$ is an integer).

I then proceeded to estimate $\log$:

$$\log (z) = 2\operatorname{artanh}\,\frac{z-1}{z+1} = 2\sum_{n=0}^\infty\frac{1}{2n+1}\left(\frac{z-1}{z+1}\right)^{2n+1}$$

Putting these estimations together: $a^b=e^{b\log a}$, giving us an estimate that we can make to whatever accuracy is needed.

This method works to estimate exponents, but are there better and more efficient ways of doing this?

  • 0
    I would think the binomial series would make for a tidier estimate...2012-04-19
  • 0
    @J.M. How would that extend to non-integral $b$?2012-04-19
  • 1
    @Alex, Not too hard: $$(1+x)^{\alpha}=\sum_{k=0}^{\infty} \frac{(-x)^k}{k!} \prod_{j=0}^{k-1} (j-\alpha)$$2012-04-19
  • 0
    @Ah, I see. I like it.2012-04-19
  • 0
    You could check the difficult-to-read code of function pow(x,y), which computes $x^y$, included in standard C libary here: http://pastebin.com/LDjS5mAR2012-04-19
  • 0
    I can't vouch that this is *the most* efficient method, but here's how I'd proceed: To estimate $a^b$ numerically, you're gonna have to find a rational approximation for $b$, say, by continued fractions or whatever. So let $b\approx \hat{b}=n/m$. You can calculate $c:=a^n$ efficiently by repeated squaring, though you'll have to watch out for overflow. Then you'll have to calculate $c^{1/m}$. This can be done efficiently via Newton's method, though you might get a failure of convergence.2012-04-19
  • 0
    @J.M. The question you posted and my question are asking different things. The question asked in the link is about how non-integer exponents work and can be found. I am aware of how to find non-integer exponents, and even added a method in my post. I am trying to ask about efficient methods of estimation using a computer.2012-04-19
  • 0
    Yes, and I gave one such method in the answer to that question... so?2012-04-19
  • 0
    @J.M. Right... but it is not the same question, and your answer may not be the best for this question.2012-04-19
  • 0
    What part of it seems difficult for you? If you could say what you're going for, I can repurpose some of the things there as an answer here.2012-04-20

0 Answers 0