Average Error: 39.3 → 0.4
Time: 9.6s
Precision: 64
Internal Precision: 128
\[\frac{e^{x} - 1}{x}\]
\[\begin{array}{l} \mathbf{if}\;x \le -0.0001003945160317758:\\ \;\;\;\;\frac{\frac{{\left(e^{x}\right)}^{3} - 1}{\left(e^{x} + 1\right) + e^{x} \cdot e^{x}}}{x}\\ \mathbf{else}:\\ \;\;\;\;\left(x \cdot \frac{1}{2} + {x}^{2} \cdot \frac{1}{6}\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.3
Target38.3
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.0001003945160317758

    1. Initial program 0.1

      \[\frac{e^{x} - 1}{x}\]
    2. Using strategy rm
    3. Applied flip3--0.1

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

    if -0.0001003945160317758 < x

    1. Initial program 59.8

      \[\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.0001003945160317758:\\ \;\;\;\;\frac{\frac{{\left(e^{x}\right)}^{3} - 1}{\left(e^{x} + 1\right) + e^{x} \cdot e^{x}}}{x}\\ \mathbf{else}:\\ \;\;\;\;\left(x \cdot \frac{1}{2} + {x}^{2} \cdot \frac{1}{6}\right) + 1\\ \end{array}\]

Reproduce

herbie shell --seed 2019016 
(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: 9.1s)Debug log

sample90.0ms

Algorithm
intervals
Results
316×(pre true 80)
168×(body real 80)
64×(body real 1280)
46×(body real 640)
26×(body real 320)
12×(body real 160)

simplify14.0ms

Counts
1 → 1
Calls
1 calls:
Slowest
14.0ms
(/ (- (exp x) 1) x)

prune8.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 36.0b

localize17.0ms

Local error

Found 2 expressions with local error:

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

rewrite20.0ms

Algorithm
rewrite-expression-head
Rules
add-sqr-sqrt
associate-/l*
add-cube-cbrt
*-un-lft-identity
associate-/l/
add-log-exp
flip--
add-exp-log
difference-of-sqr-1
add-cbrt-cube
flip3--
pow1
div-inv
div-sub
frac-2neg
sub-neg
clear-num
Counts
2 → 29
Calls
2 calls:
Slowest
14.0ms
(/ (- (exp x) 1) x)
6.0ms
(- (exp x) 1)

series69.0ms

Counts
2 → 6
Calls
2 calls:
Slowest
50.0ms
(/ (- (exp x) 1) x)
19.0ms
(- (exp x) 1)

simplify357.0ms

Counts
13 → 35
Calls
13 calls:
Slowest
145.0ms
(+ x (+ (* 1/6 (pow x 3)) (* 1/2 (pow x 2))))
87.0ms
(* -1 (/ (- 1 (exp x)) x))
30.0ms
(- (* (exp x) (exp x)) (* 1 1))
27.0ms
(+ (* 1/2 x) (+ (* 1/6 (pow x 2)) 1))
17.0ms
(- (pow (exp x) 3) (pow 1 3))

prune317.0ms

Pruning

3 alts after pruning (3 fresh and 0 done)

Merged error: 0.1b

localize14.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))

rewrite7.0ms

Algorithm
rewrite-expression-head
Rules
add-log-exp
associate-*r*
add-cube-cbrt
*-un-lft-identity
add-sqr-sqrt
add-exp-log
add-cbrt-cube
pow1
unpow2
flip-+
*-commutative
flip3-+
sum-log
associate-+r+
+-commutative
Counts
2 → 24
Calls
2 calls:
Slowest
6.0ms
(+ (* 1/2 x) (+ (* 1/6 (pow x 2)) 1))
1.0ms
(* 1/6 (pow x 2))

series28.0ms

Counts
2 → 6
Calls
2 calls:
Slowest
18.0ms
(* 1/6 (pow x 2))
10.0ms
(+ (* 1/2 x) (+ (* 1/6 (pow x 2)) 1))

simplify181.0ms

Counts
10 → 30
Calls
10 calls:
Slowest
65.0ms
(* (exp (* 1/2 x)) (exp (+ (* 1/6 (pow x 2)) 1)))
43.0ms
(+ (* 1/2 x) (+ (* 1/6 (pow x 2)) 1))
35.0ms
(+ (* 1/2 x) (+ (* 1/6 (pow x 2)) 1))
23.0ms
(+ (* 1/2 x) (+ (* 1/6 (pow x 2)) 1))
4.0ms
(* 1/6 (pow x 2))

prune218.0ms

Pruning

4 alts after pruning (4 fresh and 0 done)

Merged error: 0.1b

localize6.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)))

rewrite4.0ms

Algorithm
rewrite-expression-head
Rules
add-log-exp
associate-*r*
add-cube-cbrt
*-un-lft-identity
add-sqr-sqrt
add-exp-log
add-cbrt-cube
pow1
unpow2
flip-+
*-commutative
flip3-+
sum-log
+-commutative
Counts
2 → 23
Calls
2 calls:
Slowest
3.0ms
(+ (* 1/2 x) (* 1/6 (pow x 2)))
1.0ms
(* 1/6 (pow x 2))

series73.0ms

Counts
2 → 6
Calls
2 calls:
Slowest
54.0ms
(+ (* 1/2 x) (* 1/6 (pow x 2)))
19.0ms
(* 1/6 (pow x 2))

simplify117.0ms

Counts
10 → 29
Calls
10 calls:
Slowest
39.0ms
(* (exp (* 1/2 x)) (exp (* 1/6 (pow x 2))))
26.0ms
(+ (* 1/2 x) (* 1/6 (pow x 2)))
13.0ms
(+ (* 1/2 x) (* 1/6 (pow x 2)))
13.0ms
(+ (* 1/2 x) (* 1/6 (pow x 2)))
6.0ms
(* 1/6 (pow x 2))

prune256.0ms

Pruning

4 alts after pruning (3 fresh and 1 done)

Merged error: 0.1b

localize20.0ms

Local error

Found 4 expressions with local error:

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

rewrite22.0ms

Algorithm
rewrite-expression-head
Rules
cbrt-prod
add-cube-cbrt
*-un-lft-identity
add-sqr-sqrt
cbrt-div
add-log-exp
add-exp-log
associate-*r*
add-cbrt-cube
pow1
flip-+
pow1/3
flip3-+
unpow2
*-commutative
Counts
4 → 51
Calls
4 calls:
Slowest
11.0ms
(cbrt (+ (* 1/2 x) (+ (* 1/6 (pow x 2)) 1)))
4.0ms
(cbrt (+ (* 1/2 x) (+ (* 1/6 (pow x 2)) 1)))
4.0ms
(cbrt (+ (* 1/2 x) (+ (* 1/6 (pow x 2)) 1)))
1.0ms
(* 1/6 (pow x 2))

series194.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
67.0ms
(cbrt (+ (* 1/2 x) (+ (* 1/6 (pow x 2)) 1)))
65.0ms
(cbrt (+ (* 1/2 x) (+ (* 1/6 (pow x 2)) 1)))
51.0ms
(cbrt (+ (* 1/2 x) (+ (* 1/6 (pow x 2)) 1)))
11.0ms
(* 1/6 (pow x 2))

simplify3.5s

Counts
30 → 63
Calls
30 calls:
Slowest
487.0ms
(cbrt (+ (pow (* 1/2 x) 3) (pow (+ (* 1/6 (pow x 2)) 1) 3)))
449.0ms
(cbrt (+ (pow (* 1/2 x) 3) (pow (+ (* 1/6 (pow x 2)) 1) 3)))
413.0ms
(cbrt (+ (pow (* 1/2 x) 3) (pow (+ (* 1/6 (pow x 2)) 1) 3)))
285.0ms
(+ (/ (exp (* 1/3 (- (log 1/6) (* 2 (log (/ -1 x)))))) x) (+ (/ (exp (* 1/3 (- (log 1/6) (* 2 (log (/ -1 x)))))) (pow x 2)) (exp (* 1/3 (- (log 1/6) (* 2 (log (/ -1 x))))))))
264.0ms
(+ (/ (exp (* 1/3 (- (log 1/6) (* 2 (log (/ -1 x)))))) x) (+ (/ (exp (* 1/3 (- (log 1/6) (* 2 (log (/ -1 x)))))) (pow x 2)) (exp (* 1/3 (- (log 1/6) (* 2 (log (/ -1 x))))))))

prune620.0ms

Pruning

5 alts after pruning (4 fresh and 1 done)

Merged error: 0.0b

regimes48.0ms

Accuracy

98.7% (0.3b remaining)

Error of 0.4b against oracle of 0.1b and baseline of 21.5b

bsearch77.0ms

end0.0ms

sample2.8s

Algorithm
intervals
Results
10628×(pre true 80)
5514×(body real 80)
2240×(body real 1280)
1669×(body real 640)
789×(body real 320)
416×(body real 160)