How do you compute an exponent with irrational values?

In summary: It was also used in the basic language I learned in high-school. It is not used so much today. It is very limited. It is only used to specify the exponent, and the base is implied. It is not used to do an exponentiation. So, if you type 2**3, that is 2 to the power 3, and it equals 8. But if you type 2**3+4, it is (2 to the power 3) plus 4, which is 12.
  • #1
Arnoldjavs3
191
3

Homework Statement


Let's say I want to compute ##2^{2.4134}##. We know that the base is a rational number and the power is an irrational number. Please keep in mind that I have not taken too many math classes yet and I am self-studying right now by making a calculator and respective algorithms.

Homework Equations

The Attempt at a Solution


I'm aware of the fact that:

##a^{x}=e^{x\ln(a)}##

However, this will just end up returning me to my initial issue. How do I actually compute this given the applied scenario?

My guess is that you would end up wanting to use something to approximate and 'converge' to an estimation based off whatever accuracy you would like(similar to babylonians or Newton method), but I am not sure how I would go about this.

I found this interesting segment online:

##e^{x}=\sum_{n=0}^{\infty}\frac{x^{n}}{n!}(**)##

But my question is, what is the ** operators mean here? Also, I'm assuming I'm wrong, but would I just rely on this to compute for only rational numbers? Then I would have to figure out how to compute exponents with rational numbers I'm assuming?
 
Last edited by a moderator:
Physics news on Phys.org
  • #2
Arnoldjavs3 said:
But my question is, what is the ** operators mean here?
I don't think the (**) is part of the equation, which is true without them. Perhaps they refer to a footnote on the page where you found the formula.

The formula applies to any sort of numbers - rational, real or even complex.

In practice, when doing calculations on a computer with actual decimal numbers, a rational number is always used instead of an irrational number. The decimal expansion is just terminated after a sufficient number of digits.

When calculating with pencil and paper, this need to approximate can sometimes be avoided. For instance if ##x=\sqrt 2## in every term of even ##n## the square root sign disappears and the odd-numbered terms can be written as a rational number times ##\sqrt 2##.
 
  • Like
Likes Arnoldjavs3
  • #3
I'm not sure what the best algorithms are. They are often different from the mathematical series which you quoted and what mathematicians use. Here we have
$$
e^x = \exp(x) = \sum_{n=0}^{\infty} \frac{x^n}{n!} = 1+x+\frac{x^2}{1\cdot 2} + \frac{x^3}{1 \cdot 2 \cdot 3}+\frac{x^4}{1\cdot 2 \cdot 3 \cdot 4}+ \ldots
$$
and
$$
\operatorname{ln}(1+x)= \sum_{n=1}^{\infty} (-1)^{n+1}\frac{x^n}{n} = x- \frac{x^2}{2} + \frac{x^3}{3} - \frac{x^4}{4} +-\ldots
$$
The ##(**)## doesn't belong to the formula. It is probably a mark to refer to this formula within the text. For the purpose of practice you can use these formulas and the precision depends on where you stop the summation. But as you might see, for large ##x## you'll have to trick a little bit, because the higher summands are still important. I assume there are better algorithms, space or time optimized and with good approximations of the remainder term (the rest after the algorithm stopped).
 
  • Like
Likes Arnoldjavs3
  • #4
fresh_42 said:
I'm not sure what the best algorithms are. They are often different from the mathematical series which you quoted and what mathematicians use. Here we have
$$
e^x = \exp(x) = \sum_{n=0}^{\infty} \frac{x^n}{n!} = 1+x+\frac{x^2}{1\cdot 2} + \frac{x^3}{1 \cdot 2 \cdot 3}+\frac{x^4}{1\cdot 2 \cdot 3 \cdot 4}+ \ldots
$$
and
$$
\operatorname{ln}(1+x)= \sum_{n=1}^{\infty} (-1)^{n+1}\frac{x^n}{n} = x- \frac{x^2}{2} + \frac{x^3}{3} - \frac{x^4}{4} +-\ldots
$$
The ##(**)## doesn't belong to the formula. It is probably a mark to refer to this formula within the text. For the purpose of practice you can use these formulas and the precision depends on where you stop the summation. But as you might see, for large ##x## you'll have to trick a little bit, because the higher summands are still important. I assume there are better algorithms, space or time optimized and with good approximations of the remainder term (the rest after the algorithm stopped).

Never would have thought that programming would get me more excited to do math! Too cool. I am not too worried about optimization of algorithms for now rather than just getting a proper calculator working.

Edit: Ok abck to my original problem.

So using the summation I mentioned above I get that ##e^{1.67} = 2^{2.41}## However... this goes back to my initial problem which is how do I actually end up computing ##e^{1.67}##?

Also, what would the second formula be useful for? I have a working algorithm to solve for ln(x), but how would this help me here(excuse my ignorance where necessary)?
 
  • #5
Are you allowed to use just plain old log tables to the base 10?
 
  • #6
Arnoldjavs3 said:
Never would have thought that programming would get me more excited to do math! Too cool. I am not too worried about optimization of algorithms for now rather than just getting a proper calculator working.

Edit: Ok abck to my original problem.

So using the summation I mentioned above I get that ##e^{1.67} = 2^{2.41}## However... this goes back to my initial problem which is how do I actually end up computing ##e^{1.67}##?

Also, what would the second formula be useful for? I have a working algorithm to solve for ln(x), but how would this help me here(excuse my ignorance where necessary)?
You wrote ##a^x=e^{x \operatorname{ln}a}##. So with the second formula you can calculate ##\operatorname{ln} (a) = \operatorname{ln}(1+(a-1))## and with the first in a second step ##e^{x \operatorname{ln}(a)}##. So it solves your problem at least in theory. That's why I said, there might be better algorithms.
 
  • #7
Arnoldjavs3 said:

Homework Statement


Let's say I want to compute ##2^{2.4134}##. We know that the base is a rational number and the power is an irrational number. Please keep in mind that I have not taken too many math classes yet and I am self-studying right now by making a calculator and respective algorithms.
The exponent you wrote, 2.4134, is a rational number. If you had written ##2^{\sqrt 2}##, that exponent would be an irrational number, but 2.4134 is the same as ##\frac{24134}{10000}## and is therefore rational.
Arnoldjavs3 said:
But my question is, what is the ** operators mean here? Also, I'm assuming I'm wrong, but would I just rely on this to compute for only rational numbers? Then I would have to figure out how to compute exponents with rational numbers I'm assuming?
** is the Fortran exponent operator, and it is also used in Python for the same purpose.
 
  • #8
Chestermiller said:
Are you allowed to use just plain old log tables to the base 10?

I suppose I could use some tables. I figured if I had a table of ##e^x## I could interpolate up to a certain point. Not sure to what degree though.
 
  • #9
If you are going to use a truncated power series approximation to the exponential and the log, I suggest that you use the approximations given in Abramowitz and Stegun, which have their error estimate bounded for you. If you are going to evaluate the series on the computer, I very strongly suggest you use nesting in a loop (to avoid roundoff error).
 
  • #10
Arnoldjavs3 said:

Homework Statement


Let's say I want to compute ##2^{2.4134}##. We know that the base is a rational number and the power is an irrational number. Please keep in mind that I have not taken too many math classes yet and I am self-studying right now by making a calculator and respective algorithms.

Homework Equations

The Attempt at a Solution


I'm aware of the fact that:

##a^{\x}=e^{\x\ln(a)}##

However, this will just end up returning me to my initial issue. How do I actually compute this given the applied scenario?

My guess is that you would end up wanting to use something to approximate and 'converge' to an estimation based off whatever accuracy you would like(similar to babylonians or Newton method), but I am not sure how I would go about this.

I found this interesting segment online:

##e^{x}=\sum_{n=0}^{\infty}\frac{x^{n}}{n!}(**)##

But my question is, what is the ** operators mean here? Also, I'm assuming I'm wrong, but would I just rely on this to compute for only rational numbers? Then I would have to figure out how to compute exponents with rational numbers I'm assuming?

First of all: you said that the base is rational and the power is irrational; it is not: 2.4134 is a perfectly good rational number. (Nevertheless, it is not a "convenient" rational number, so your question still makes perfectly good sense,)

Typically, we would compute ##2^x## by computing ##e^{x \ln 2}##. For ##x = 2.4134## you should keep as many digits as possible in your preliminary computation of ##2.4134\, \ln 2##. For example, keeping 4 decimal places gives ##2.4134 \ln 2 \approx 1.6728## and ##e^{1.6728} = 5.3271## (to 4 places), but keeping 10 places gives ## 2.4134 \ln 2 \approx 1.672841406## and ##e^{1.672841406} = 5.3273## (to 4 places). The two answers differ in the4th decimal place.

So, we should keep as many decimal places as we can during our intermediate calculations and so we go with ##e^{1.672841406}##. We should probably not use the series expansion ##e^y = \sum_{n=0}^{\infty} y^n/n!##, because getting an accurate estimate of the sum could involve taking a large number of terms. It would be better to use the fact that ##e^{1.672841406} = e \times e^{0.672841406}##. We could use an accurate value of ##e## and the series for ##e^{0.672841406}##. This would involve significantly fewer terms than the original expansion. Even better might be to write ##1.672841406 = 2 - 0.327158594,## so that ##e^{1.672841406} = e^2 \times e^{- 0.327158594}##. The series for the latter is "alternating", of the form + - + - + - ... with terms that grow small rapidly. That means that we can keep even fewer terms and furthemore, can have a computable bound on the error we make by truncating the infinite series at a finite place. We can even monitor the error "on the fly" and so can tell when it is safe to stop including any more terms. As long as we are careful to implement the summation in a way to minimize subtractive round-off errors, we will likely find the latter method to be the best.

Some people have suggested using ##e^x = \cosh(x)+\sinh(x)##, then computing ##\cosh## and ##\sinh## using CORDIC methods. (Typically, CORDIC is used in scientific hand-held calculators!) Note, however, that most CORDIC implementations are oriented to machine-level operations, where we actually go in and manipulate the individual bits when computing an answer. Of course, nothing stops you from implementing the CORDIC steps at a "higher" level, or even by hand on paper. See, eg., https://en.wikipedia.org/wiki/CORDIC.

Finally, problems of computing things like ##e^x## with pre-assigned worst-case errors are well-studied, and people have developed numerous approximate formulas that work in limited ##x##-ranges. Surprisingly, some methods compute ##e^x## by converting it to ##2^{x / \ln(2)}## and then implementing methods for getting ##2^y## for non-integer values of ##y##. Of course, that was actually your original question! See, eg.,
http://perso.citi-lab.fr/fdedinec/recherche/publis/2005-FPT.pdf
 
  • Like
Likes Arnoldjavs3
  • #11
Ray Vickson said:
First of all: you said that the base is rational and the power is irrational; it is not: 2.4134 is a perfectly good rational number. (Nevertheless, it is not a "convenient" rational number, so your question still makes perfectly good sense,)

Typically, we would compute ##2^x## by computing ##e^{x \ln 2}##. For ##x = 2.4134## you should keep as many digits as possible in your preliminary computation of ##2.4134\, \ln 2##. For example, keeping 4 decimal places gives ##2.4134 \ln 2 \approx 1.6728## and ##e^{1.6728} = 5.3271## (to 4 places), but keeping 10 places gives ## 2.4134 \ln 2 \approx 1.672841406## and ##e^{1.672841406} = 5.3273## (to 4 places). The two answers differ in the4th decimal place.

So, we should keep as many decimal places as we can during our intermediate calculations and so we go with ##e^{1.672841406}##. We should probably not use the series expansion ##e^y = \sum_{n=0}^{\infty} y^n/n!##, because getting an accurate estimate of the sum could involve taking a large number of terms. It would be better to use the fact that ##e^{1.672841406} = e \times e^{0.672841406}##. We could use an accurate value of ##e## and the series for ##e^{0.672841406}##. This would involve significantly fewer terms than the original expansion. Even better might be to write ##1.672841406 = 2 - 0.327158594,## so that ##e^{1.672841406} = e^2 \times e^{- 0.327158594}##. The series for the latter is "alternating", of the form + - + - + - ... with terms that grow small rapidly. That means that we can keep even fewer terms and furthemore, can have a computable bound on the error we make by truncating the infinite series at a finite place. We can even monitor the error "on the fly" and so can tell when it is safe to stop including any more terms. As long as we are careful to implement the summation in a way to minimize subtractive round-off errors, we will likely find the latter method to be the best.

Some people have suggested using ##e^x = \cosh(x)+\sinh(x)##, then computing ##\cosh## and ##\sinh## using CORDIC methods. (Typically, CORDIC is used in scientific hand-held calculators!) Note, however, that most CORDIC implementations are oriented to machine-level operations, where we actually go in and manipulate the individual bits when computing an answer. Of course, nothing stops you from implementing the CORDIC steps at a "higher" level, or even by hand on paper. See, eg., https://en.wikipedia.org/wiki/CORDIC.

Finally, problems of computing things like ##e^x## with pre-assigned worst-case errors are well-studied, and people have developed numerous approximate formulas that work in limited ##x##-ranges. Surprisingly, some methods compute ##e^x## by converting it to ##2^{x / \ln(2)}## and then implementing methods for getting ##2^y## for non-integer values of ##y##. Of course, that was actually your original question! See, eg.,
http://perso.citi-lab.fr/fdedinec/recherche/publis/2005-FPT.pdf

This was very informative, thank you. I was well aware of how a pocket hand-held calculator performed operations but did not bother to actually consider implementing their logic(since I'm implementing this calculator as an android app)

I will read into both the paper you linked and implementations of CORDIC algorithms and decide for myself which one will be of lower complexity.

Edit: For anyone interested in CORDIC algorithm in my question, here is a useful paper:

http://www-pequan.lip6.fr/~bajard/MesPublis/Spie1999.pdf
 
Last edited:
  • #12
Arnoldjavs3 said:
This was very informative, thank you. I was well aware of how a pocket hand-held calculator performed operations but did not bother to actually consider implementing their logic(since I'm implementing this calculator as an android app)

I will read into both the paper you linked and implementations of CORDIC algorithms and decide for myself which one will be of lower complexity.

Edit: For anyone interested in CORDIC algorithm in my question, here is a useful paper:

http://www-pequan.lip6.fr/~bajard/MesPublis/Spie1999.pdf

My computer refuses to load that pdf file; it says "Dangerous website blocked."
 
  • #13
Ray Vickson said:
My computer refuses to load that pdf file; it says "Dangerous website blocked."

I uploaded the file here if you're interested:

http://www.filedropper.com/spie19991

Not sure why your browser is flagging that site... Loaded for me fine. Proceed at own risk though, lol.

Also, back to your original suggestion. I have a question about computing ##e^x## where ##0<x<1##. How do you put this into the series? As in, how do I account for the factorial part where ##x## is not a whole integer(here is my lack of math kicking in). I read something called the Gamma function. Would i implement that here to find the factorial?
 
  • #14
Arnoldjavs3 said:
I uploaded the file here if you're interested:

http://www.filedropper.com/spie19991

Not sure why your browser is flagging that site... Loaded for me fine. Proceed at own risk though, lol.

Also, back to your original suggestion. I have a question about computing ##e^x## where ##0<x<1##. How do you put this into the series? As in, how do I account for the factorial part where ##x## is not a whole integer(here is my lack of math kicking in). I read something called the Gamma function. Would i implement that here to find the factorial?

For ##0 < x < 1## you can use the series
$$ e^x = \sum_{n=0}^{\infty} \frac{x^n}{n!} = 1 + \frac{x}{1} + \frac{x^2}{2 \cdot 1} + \frac{x^3}{3 \cdot 2 \cdot 1} + \cdots $$
Only positive integer values of ##n!## are involved, so there is no need for anything fancy. The best way of computing your approximation is to do it recursively, in something like the following.
(1) ##S = 1##, ##n = 1##
(2) ##t = x/n##, ##S = S + t##, ##n = n+1##
(3) ##t = t*x/n##, ##S=S + t##, ##n = n+1##
(4) while ##t \geq \epsilon## repeat step (3), else stop.
Here, ##\epsilon > 0## is some stopping criterion, so that we stop summing when the newest term is ##< \epsilon##. The final value of ##S## is our approximation to ##e^x##, and should have an error not much larger than ##\epsilon##.

On the other hand, if you have some reasonable pre-specified accuracy you want to achieve, there are numerous more easily-implemented methods with known error bounds available. For example, on page 71 of "Handbook of Mathematical Functions", by Ambramowitz and Stegun (Dover Publications) there are several apprximations of various degrees of accuracy. The subsection 4.2.45 gives the polynomial formula
$$e^{-x} = 1 + a_1 x + a_2 x^2 + a_3 x^3+a^4 x^4 + a_5 x^5 + a_6 x^6 + a_7 x^7 + \epsilon(x),$$
where numerical values are given for ##a_1, a_2, \ldots, a_7## and the error is known to satisfy
$$|\epsilon(x)| \leq 2 \times 10^{-10}$$
for ##0 \leq x \leq \ln 2 \approx 0.693##.
Note that the ##a_i## are not just ##(-1)^i/i!## as would appear in the series; they are fancier values, based on extensive numerical analysis and testing. (The values of the ##a_i## are not greatly different from ##(-1)^i /! ##, but deviate from these after about the 5th decimal place.)

If you are satisfied with a worst-case error of about ##10^{-10}## you could use that polynomial. Probably it would be best to limit ##x## to values ##\leq 0.5## in the polynomial, which you could easily do by (1) pre-computing and storing an accurate value for ##e^{0.5}##, then (2) using ##e^x = e^{0.5} \, e^{x-0.5} ## for ##.5 < x < 1##. Compute the approximate value of ##e^{x-.5}## using the polynomial approximation for ##e^{-(x-.5)} = e^{.5 - x}## and then computing ##e^z## as ##1/e^{-z}##. Of course, for ##0 < x \leq 0.5## you compute ##e^x = 1/e^{-x}## directly, using the polynomial to evaluate ##e^{-x}##.

Newer sources contain a wide variety of other schemes; many people seem to favor the use of Pade approximants, which are essentially rational functions rather than simple polynomials.
 
  • Like
Likes Arnoldjavs3
  • #15
Ray Vickson said:
For ##0 < x < 1## you can use the series
$$ e^x = \sum_{n=0}^{\infty} \frac{x^n}{n!} = 1 + \frac{x}{1} + \frac{x^2}{2 \cdot 1} + \frac{x^3}{3 \cdot 2 \cdot 1} + \cdots $$
Only positive integer values of ##n!## are involved, so there is no need for anything fancy. The best way of computing your approximation is to do it recursively, in something like the following.
(1) ##S = 1##, ##n = 1##
(2) ##t = x/n##, ##S = S + t##, ##n = n+1##
(3) ##t = t*x/n##, ##S=S + t##, ##n = n+1##
(4) while ##t \geq \epsilon## repeat step (3), else stop.
Here, ##\epsilon > 0## is some stopping criterion, so that we stop summing when the newest term is ##< \epsilon##. The final value of ##S## is our approximation to ##e^x##, and should have an error not much larger than ##\epsilon##.

On the other hand, if you have some reasonable pre-specified accuracy you want to achieve, there are numerous more easily-implemented methods with known error bounds available. For example, on page 71 of "Handbook of Mathematical Functions", by Ambramowitz and Stegun (Dover Publications) there are several apprximations of various degrees of accuracy. The subsection 4.2.45 gives the polynomial formula
$$e^{-x} = 1 + a_1 x + a_2 x^2 + a_3 x^3+a^4 x^4 + a_5 x^5 + a_6 x^6 + a_7 x^7 + \epsilon(x),$$
where numerical values are given for ##a_1, a_2, \ldots, a_7## and the error is known to satisfy
$$|\epsilon(x)| \leq 2 \times 10^{-10}$$
for ##0 \leq x \leq \ln 2 \approx 0.693##.
Note that the ##a_i## are not just ##(-1)^i/i!## as would appear in the series; they are fancier values, based on extensive numerical analysis and testing. (The values of the ##a_i## are not greatly different from ##(-1)^i /! ##, but deviate from these after about the 5th decimal place.)

If you are satisfied with a worst-case error of about ##10^{-10}## you could use that polynomial. Probably it would be best to limit ##x## to values ##\leq 0.5## in the polynomial, which you could easily do by (1) pre-computing and storing an accurate value for ##e^{0.5}##, then (2) using ##e^x = e^{0.5} \, e^{x-0.5} ## for ##.5 < x < 1##. Compute the approximate value of ##e^{x-.5}## using the polynomial approximation for ##e^{-(x-.5)} = e^{.5 - x}## and then computing ##e^z## as ##1/e^{-z}##. Of course, for ##0 < x \leq 0.5## you compute ##e^x = 1/e^{-x}## directly, using the polynomial to evaluate ##e^{-x}##.

Newer sources contain a wide variety of other schemes; many people seem to favor the use of Pade approximants, which are essentially rational functions rather than simple polynomials.

This has been really informative, thank you! I think once I've implemented a properly working algorithm for this, I can move on to implementations of trigonometric functions. Do you have any suggestions on other methods to look at for approximations?

For now, I'm not too concerned about accuracy or optimization. I think it is in my best interest to experiment and see how things are connected. I didn't think I'd end up appreciating math more through programming.
 

FAQ: How do you compute an exponent with irrational values?

1. What is an exponent?

An exponent is a mathematical operation that represents repeated multiplication. It is written as a superscript number after a base number and indicates how many times the base number should be multiplied by itself.

2. How do you compute an exponent with irrational values?

To compute an exponent with irrational values, you can use a calculator or a software program that has the capability to handle irrational numbers. You can also use mathematical techniques such as logarithms or power series to approximate the value.

3. What is an irrational value?

An irrational value is a real number that cannot be represented as a ratio of two integers. These numbers have an infinite number of non-repeating decimal places, such as pi or the square root of 2.

4. Can you compute an exponent with imaginary numbers?

Yes, you can compute an exponent with imaginary numbers. The process is similar to computing an exponent with real numbers, but you may need to use complex numbers and their properties to simplify the calculation.

5. What are some applications of computing exponents with irrational values?

Computing exponents with irrational values is used in various fields, such as physics, engineering, and finance. It is also essential in solving complex mathematical problems and in developing advanced technologies, such as cryptography and signal processing.

Back
Top