Average Error: 39.7 → 0.4
Time: 7.8s
Precision: 64
Internal Precision: 128
\[\frac{e^{x} - 1}{x}\]
\[\begin{array}{l} \mathbf{if}\;x \le -0.00017454211774255434:\\ \;\;\;\;\frac{\left(\sqrt{e^{x}} - 1\right) \cdot \left(1 + \sqrt{e^{x}}\right)}{x}\\ \mathbf{else}:\\ \;\;\;\;\left(x \cdot \frac{1}{2} + \frac{1}{6} \cdot {x}^{2}\right) + 1\\ \end{array}\]

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original39.7
Target38.9
Herbie0.4
\[\begin{array}{l} \mathbf{if}\;x \lt 1 \land x \gt -1:\\ \;\;\;\;\frac{e^{x} - 1}{\log \left(e^{x}\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{e^{x} - 1}{x}\\ \end{array}\]

Derivation

  1. Split input into 2 regimes
  2. if x < -0.00017454211774255434

    1. Initial program 0.1

      \[\frac{e^{x} - 1}{x}\]
    2. Using strategy rm
    3. Applied add-sqr-sqrt0.1

      \[\leadsto \frac{\color{blue}{\sqrt{e^{x}} \cdot \sqrt{e^{x}}} - 1}{x}\]
    4. Applied difference-of-sqr-10.1

      \[\leadsto \frac{\color{blue}{\left(\sqrt{e^{x}} + 1\right) \cdot \left(\sqrt{e^{x}} - 1\right)}}{x}\]

    if -0.00017454211774255434 < x

    1. Initial program 60.0

      \[\frac{e^{x} - 1}{x}\]
    2. Taylor expanded around 0 0.5

      \[\leadsto \color{blue}{\frac{1}{2} \cdot x + \left(\frac{1}{6} \cdot {x}^{2} + 1\right)}\]
    3. Using strategy rm
    4. Applied associate-+r+0.5

      \[\leadsto \color{blue}{\left(\frac{1}{2} \cdot x + \frac{1}{6} \cdot {x}^{2}\right) + 1}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.4

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -0.00017454211774255434:\\ \;\;\;\;\frac{\left(\sqrt{e^{x}} - 1\right) \cdot \left(1 + \sqrt{e^{x}}\right)}{x}\\ \mathbf{else}:\\ \;\;\;\;\left(x \cdot \frac{1}{2} + \frac{1}{6} \cdot {x}^{2}\right) + 1\\ \end{array}\]

Reproduce

herbie shell --seed 2018362 
(FPCore (x)
  :name "Kahan's exp quotient"

  :herbie-target
  (if (and (< x 1) (> x -1)) (/ (- (exp x) 1) (log (exp x))) (/ (- (exp x) 1) x))

  (/ (- (exp x) 1) x))

Details

Time bar (total: 2.6s)Debug log

start112.0ms

Algorithm
intervals

setup55.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 45.6b

localize19.0ms

Local error

Found 2 expressions with local error:

5.4b
(- (exp x) 1)
0.0b
(/ (- (exp x) 1) x)

rewrite12.0ms

Algorithm
rewrite-expression-head
Counts
2 → 29
Calls

2 calls. Slowest were:

7.0ms
(/ (- (exp x) 1) x)
5.0ms
(- (exp x) 1)

series33.0ms

Counts
2 → 6
Calls

2 calls. Slowest were:

21.0ms
(/ (- (exp x) 1) x)
12.0ms
(- (exp x) 1)

simplify384.0ms

Counts
13 → 35
Calls

13 calls. Slowest were:

127.0ms
(+ x (+ (* 1/6 (pow x 3)) (* 1/2 (pow x 2))))
108.0ms
(* -1 (/ (- 1 (exp x)) x))
40.0ms
(+ (* 1/2 x) (+ (* 1/6 (pow x 2)) 1))

prune328.0ms

Pruning

4 alts after pruning (4 fresh and 0 done)

Merged error: 0.0b

localize18.0ms

Local error

Found 2 expressions with local error:

0.2b
(* 1/6 (pow x 2))
0.0b
(+ (* 1/2 x) (+ (* 1/6 (pow x 2)) 1))

rewrite6.0ms

Algorithm
rewrite-expression-head
Counts
2 → 24
Calls

2 calls. Slowest were:

5.0ms
(+ (* 1/2 x) (+ (* 1/6 (pow x 2)) 1))
1.0ms
(* 1/6 (pow x 2))

series22.0ms

Counts
2 → 6
Calls

2 calls. Slowest were:

11.0ms
(* 1/6 (pow x 2))
10.0ms
(+ (* 1/2 x) (+ (* 1/6 (pow x 2)) 1))

simplify141.0ms

Counts
10 → 30
Calls

10 calls. Slowest were:

62.0ms
(* (exp (* 1/2 x)) (exp (+ (* 1/6 (pow x 2)) 1)))
21.0ms
(+ (* 1/2 x) (+ (* 1/6 (pow x 2)) 1))
20.0ms
(+ (* 1/2 x) (+ (* 1/6 (pow x 2)) 1))

prune367.0ms

Pruning

3 alts after pruning (3 fresh and 0 done)

Merged error: 0.0b

localize6.0ms

Local error

Found 1 expressions with local error:

0.2b
(* 1/6 (pow x 2))

rewrite3.0ms

Algorithm
rewrite-expression-head
Counts
1 → 12
Calls

1 calls. Slowest were:

2.0ms
(* 1/6 (pow x 2))

series20.0ms

Counts
1 → 3
Calls

1 calls. Slowest were:

20.0ms
(* 1/6 (pow x 2))

simplify29.0ms

Counts
6 → 15
Calls

6 calls. Slowest were:

7.0ms
(* 1/6 (pow x 2))
7.0ms
(* 1/6 (pow x 2))
7.0ms
(* 1/6 (pow x 2))

prune199.0ms

Pruning

3 alts after pruning (2 fresh and 1 done)

Merged error: 0.0b

localize0.0ms

Local error

Found 2 expressions with local error:

5.4b
(- (exp x) 1)
0.0b
(/ (- (exp x) 1) x)

rewrite9.0ms

Algorithm
rewrite-expression-head
Counts
2 → 29
Calls

2 calls. Slowest were:

6.0ms
(/ (- (exp x) 1) x)
3.0ms
(- (exp x) 1)

series44.0ms

Counts
2 → 6
Calls

2 calls. Slowest were:

32.0ms
(/ (- (exp x) 1) x)
11.0ms
(- (exp x) 1)

simplify363.0ms

Counts
13 → 35
Calls

13 calls. Slowest were:

150.0ms
(+ x (+ (* 1/6 (pow x 3)) (* 1/2 (pow x 2))))
108.0ms
(* -1 (/ (- 1 (exp x)) x))
31.0ms
(+ (* 1/2 x) (+ (* 1/6 (pow x 2)) 1))

prune239.0ms

Pruning

3 alts after pruning (1 fresh and 2 done)

Merged error: 0.0b

regimes80.0ms

Accuracy

98.5% (0.3b remaining)

Error of 0.4b against oracle of 0.0b and baseline of 21.2b

bsearch79.0ms