# exponential without exponential [duplicate]

Your goal is to calculate the exponential of a float (e**x) up to 2 decimal places for any float within 1 to 10. The accepted error range is 0.01.

However, you must not use the built-in exponential function or the logarithm function.

In fact, attempts to circumvent this by (2**x)**(1/ln(2)) are prohibited, even if you hardcode the ln(2).

Basically, the power function is fine, as long as the index is not derived from the input.

Shortest solution in bytes wins.

(You may include an extra solution which uses the built-in, but which does not affect the score in any way.)

## Specs

• Program or function
• Any reasonable input/output format

## Testcases

1 -> 2.71 or 2.72 or 2.73

• you must not use the built-in exponential function would seem to collide with the power function is fine – cat Apr 30 '16 at 11:57
• x** 3 is allowed while 3**x is not. – Leaky Nun Apr 30 '16 at 12:00
• What about 3 ^ 3, or x ^ y>? (I'm not suggesting hardcoding the output, I just don't get the difference) – cat Apr 30 '16 at 12:02
• The index cannot be any function of the input. – Leaky Nun Apr 30 '16 at 12:03
• We've calculated e^x and ln(x) before. codegolf.stackexchange.com/questions/9080/calculate-ex-and-lnx/… – miles Apr 30 '16 at 12:11

# Matlab, 17 bytes

@(x)(1+x/1e9)^1e9

• I'm deeply confused as to why this works. – Addison Crump Apr 30 '16 at 12:33
• exp(x) = limit (1+x/n)^n as n->infinity. As long as you only have a fixed range you just need to choose n big enough. – flawr Apr 30 '16 at 12:34
• OH. Welp. My Taylor series workings out are now useless. xD – Addison Crump Apr 30 '16 at 12:35
• The talyor series are also quite well known exp(x) = sum x^n / n! for n=0 upto inftinity, converges everywhere. – flawr Apr 30 '16 at 12:35
• Well, yeah - I meant porting it to AS. – Addison Crump Apr 30 '16 at 12:36

(**1e9).(1+).(/1e9)


or alternatively a named function:

f x=(1+x/1e9)**1e9


# AppleScript, 62 bytes

Okay, limit approximation of ex is better. ;P Thanks, flawr.

(1+(display dialog""default answer"")'s text returned/1e9)^1e9

# MATL, 9 bytes

1e9/Q1e9^


Try it Online

Explanation

        % Implicitly grab input as a number
1e9     % Number literal
/       % Divide the input by 1e9
1e9     % Number literal
^       % Exponent
% Implicitly display result


# AppleScript, 204 bytes

set x to(display dialog""default answer"")'s text returned
set r to 1
set i to 1
repeat 29
set r to r+(x^i)/f(i)
set i to i+1
end
return r
on f(a)
set x to a
repeat x-1
set a to a-1
set x to a*x
end
x
end

Yeah, it's kinda long. This uses the 30th term Taylor polynomial representation for e^x.

### How this works:

The Taylor series expansion for ex is: Now, according to the Lagrange error bound, I know that any given Taylor polynomial can get a precision to the first unused term of the Taylor series.

In more mathematical terms, I know that: where I will have a precision to ex of ak+1.

Since the OP specified that I must have a precision of 2 decimal places or better, ak+1 must be less than or equal to 1/100. I need to work out the point at which the maximum error of the function possible, located at 10 in this case is less than said error. After a little trial and error, I found that: Which means that: For as far as our precision is concerned. The code reflects this in that I will calculate: 