Average Error: 29.7 → 0.0
Time: 15.6s
Precision: 64
Internal Precision: 128
\[\frac{2}{1 + e^{-2 \cdot x}} - 1\]
\[\begin{array}{l} \mathbf{if}\;x \le -0.007284216709661482:\\ \;\;\;\;\frac{2}{1 + e^{-2 \cdot x}} - 1\\ \mathbf{elif}\;x \le 0.005885669270588273:\\ \;\;\;\;\left(\frac{2}{15} \cdot {x}^{5} + x\right) - {x}^{3} \cdot \frac{1}{3}\\ \mathbf{else}:\\ \;\;\;\;\sqrt[3]{\left((\left(\frac{2}{e^{-6 \cdot x} + 1}\right) \cdot \left(1 + \left(e^{-2 \cdot x} \cdot e^{-2 \cdot x} - e^{-2 \cdot x}\right)\right) + -1)_* \cdot (\left(\frac{2}{e^{-6 \cdot x} + 1}\right) \cdot \left(1 + \left(e^{-2 \cdot x} \cdot e^{-2 \cdot x} - e^{-2 \cdot x}\right)\right) + -1)_*\right) \cdot (\left(\frac{2}{e^{-6 \cdot x} + 1}\right) \cdot \left(1 + \left(e^{-2 \cdot x} \cdot e^{-2 \cdot x} - e^{-2 \cdot x}\right)\right) + -1)_*}\\ \end{array}\]

Error

Bits error versus x

Bits error versus y

Derivation

  1. Split input into 3 regimes
  2. if x < -0.007284216709661482

    1. Initial program 0.0

      \[\frac{2}{1 + e^{-2 \cdot x}} - 1\]
    2. Taylor expanded around -inf 0.0

      \[\leadsto \frac{2}{\color{blue}{e^{-2 \cdot x} + 1}} - 1\]

    if -0.007284216709661482 < x < 0.005885669270588273

    1. Initial program 59.0

      \[\frac{2}{1 + e^{-2 \cdot x}} - 1\]
    2. Taylor expanded around -inf 59.0

      \[\leadsto \frac{2}{\color{blue}{e^{-2 \cdot x} + 1}} - 1\]
    3. Taylor expanded around 0 0.0

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

    if 0.005885669270588273 < x

    1. Initial program 0.0

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

      \[\leadsto \frac{2}{\color{blue}{\frac{{1}^{3} + {\left(e^{-2 \cdot x}\right)}^{3}}{1 \cdot 1 + \left(e^{-2 \cdot x} \cdot e^{-2 \cdot x} - 1 \cdot e^{-2 \cdot x}\right)}}} - 1\]
    4. Applied associate-/r/0.0

      \[\leadsto \color{blue}{\frac{2}{{1}^{3} + {\left(e^{-2 \cdot x}\right)}^{3}} \cdot \left(1 \cdot 1 + \left(e^{-2 \cdot x} \cdot e^{-2 \cdot x} - 1 \cdot e^{-2 \cdot x}\right)\right)} - 1\]
    5. Applied fma-neg0.0

      \[\leadsto \color{blue}{(\left(\frac{2}{{1}^{3} + {\left(e^{-2 \cdot x}\right)}^{3}}\right) \cdot \left(1 \cdot 1 + \left(e^{-2 \cdot x} \cdot e^{-2 \cdot x} - 1 \cdot e^{-2 \cdot x}\right)\right) + \left(-1\right))_*}\]
    6. Simplified0.0

      \[\leadsto (\color{blue}{\left(\frac{2}{1 + e^{x \cdot -6}}\right)} \cdot \left(1 \cdot 1 + \left(e^{-2 \cdot x} \cdot e^{-2 \cdot x} - 1 \cdot e^{-2 \cdot x}\right)\right) + \left(-1\right))_*\]
    7. Using strategy rm
    8. Applied add-cbrt-cube0.0

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -0.007284216709661482:\\ \;\;\;\;\frac{2}{1 + e^{-2 \cdot x}} - 1\\ \mathbf{elif}\;x \le 0.005885669270588273:\\ \;\;\;\;\left(\frac{2}{15} \cdot {x}^{5} + x\right) - {x}^{3} \cdot \frac{1}{3}\\ \mathbf{else}:\\ \;\;\;\;\sqrt[3]{\left((\left(\frac{2}{e^{-6 \cdot x} + 1}\right) \cdot \left(1 + \left(e^{-2 \cdot x} \cdot e^{-2 \cdot x} - e^{-2 \cdot x}\right)\right) + -1)_* \cdot (\left(\frac{2}{e^{-6 \cdot x} + 1}\right) \cdot \left(1 + \left(e^{-2 \cdot x} \cdot e^{-2 \cdot x} - e^{-2 \cdot x}\right)\right) + -1)_*\right) \cdot (\left(\frac{2}{e^{-6 \cdot x} + 1}\right) \cdot \left(1 + \left(e^{-2 \cdot x} \cdot e^{-2 \cdot x} - e^{-2 \cdot x}\right)\right) + -1)_*}\\ \end{array}\]

Reproduce

herbie shell --seed 2018365 +o rules:numerics
(FPCore (x y)
  :name "Logistic function from Lakshay Garg"
  (- (/ 2 (+ 1 (exp (* -2 x)))) 1))

Details

Time bar (total: 9.8s)Debug log

start93.0ms

Algorithm
intervals

setup20.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 28.6b

localize13.0ms

Local error

Found 3 expressions with local error:

3.6b
(- (/ 2 (+ 1 (exp (* -2 x)))) 1)
0.0b
(/ 2 (+ 1 (exp (* -2 x))))
0.0b
(+ 1 (exp (* -2 x)))

rewrite7.0ms

Algorithm
rewrite-expression-head
Counts
3 → 50
Calls

3 calls. Slowest were:

5.0ms
(- (/ 2 (+ 1 (exp (* -2 x)))) 1)
1.0ms
(/ 2 (+ 1 (exp (* -2 x))))
1.0ms
(+ 1 (exp (* -2 x)))

series85.0ms

Counts
3 → 9
Calls

3 calls. Slowest were:

44.0ms
(- (/ 2 (+ 1 (exp (* -2 x)))) 1)
26.0ms
(/ 2 (+ 1 (exp (* -2 x))))
13.0ms
(+ 1 (exp (* -2 x)))

simplify771.0ms

Counts
20 → 59
Calls

20 calls. Slowest were:

226.0ms
(- (+ (* 2 (pow x 2)) 2) (* 2 x))
124.0ms
(+ (* 1 1) (- (* (exp (* -2 x)) (exp (* -2 x))) (* 1 (exp (* -2 x)))))
101.0ms
(- (+ x (* 2/15 (pow x 5))) (* 1/3 (pow x 3)))

prune795.0ms

Pruning

3 alts after pruning (3 fresh and 0 done)

Merged error: 0.0b

localize8.0ms

Local error

Found 3 expressions with local error:

3.6b
(- (/ 2 (+ (exp (* -2 x)) 1)) 1)
0.0b
(+ (exp (* -2 x)) 1)
0.0b
(/ 2 (+ (exp (* -2 x)) 1))

rewrite15.0ms

Algorithm
rewrite-expression-head
Counts
3 → 53
Calls

3 calls. Slowest were:

9.0ms
(- (/ 2 (+ (exp (* -2 x)) 1)) 1)
4.0ms
(+ (exp (* -2 x)) 1)
2.0ms
(/ 2 (+ (exp (* -2 x)) 1))

series72.0ms

Counts
3 → 9
Calls

3 calls. Slowest were:

49.0ms
(- (/ 2 (+ (exp (* -2 x)) 1)) 1)
15.0ms
(/ 2 (+ (exp (* -2 x)) 1))
8.0ms
(+ (exp (* -2 x)) 1)

simplify726.0ms

Counts
22 → 62
Calls

22 calls. Slowest were:

171.0ms
(- (+ (* 2 (pow x 2)) 2) (* 2 x))
127.0ms
(- (+ x (* 2/15 (pow x 5))) (* 1/3 (pow x 3)))
111.0ms
(+ (* (exp (* -2 x)) (exp (* -2 x))) (- (* 1 1) (* (exp (* -2 x)) 1)))

prune782.0ms

Pruning

3 alts after pruning (2 fresh and 1 done)

Merged error: 0.0b

localize30.0ms

Local error

Found 3 expressions with local error:

19.4b
(- (+ x (* 2/15 (pow x 5))) (* 1/3 (pow x 3)))
0.3b
(* 1/3 (pow x 3))
0.1b
(* 2/15 (pow x 5))

rewrite9.0ms

Algorithm
rewrite-expression-head
Counts
3 → 49
Calls

3 calls. Slowest were:

5.0ms
(- (+ x (* 2/15 (pow x 5))) (* 1/3 (pow x 3)))
1.0ms
(* 2/15 (pow x 5))
1.0ms
(* 1/3 (pow x 3))

series73.0ms

Counts
3 → 9
Calls

3 calls. Slowest were:

31.0ms
(- (+ x (* 2/15 (pow x 5))) (* 1/3 (pow x 3)))
22.0ms
(* 1/3 (pow x 3))
20.0ms
(* 2/15 (pow x 5))

simplify1.1s

Counts
25 → 58
Calls

25 calls. Slowest were:

150.0ms
(/ (exp (+ x (* 2/15 (pow x 5)))) (exp (* 1/3 (pow x 3))))
142.0ms
(fma 1 (+ x (* 2/15 (pow x 5))) (- (* (pow x 3) 1/3)))
136.0ms
(- (+ x (* 2/15 (pow x 5))) (* 1/3 (pow x 3)))

prune915.0ms

Pruning

3 alts after pruning (1 fresh and 2 done)

Merged error: 0.0b

localize30.0ms

Local error

Found 4 expressions with local error:

3.5b
(- (* (exp (* -2 x)) (exp (* -2 x))) (* 1 (exp (* -2 x))))
3.5b
(fma (/ 2 (+ 1 (exp (* x -6)))) (+ (* 1 1) (- (* (exp (* -2 x)) (exp (* -2 x))) (* 1 (exp (* -2 x))))) (- 1))
0.0b
(* (exp (* -2 x)) (exp (* -2 x)))
0.0b
(+ 1 (exp (* x -6)))

rewrite15.0ms

Algorithm
rewrite-expression-head
Counts
4 → 63
Calls

4 calls. Slowest were:

8.0ms
(- (* (exp (* -2 x)) (exp (* -2 x))) (* 1 (exp (* -2 x))))
6.0ms
(* (exp (* -2 x)) (exp (* -2 x)))
1.0ms
(+ 1 (exp (* x -6)))

series175.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

121.0ms
(fma (/ 2 (+ 1 (exp (* x -6)))) (+ (* 1 1) (- (* (exp (* -2 x)) (exp (* -2 x))) (* 1 (exp (* -2 x))))) (- 1))
25.0ms
(- (* (exp (* -2 x)) (exp (* -2 x))) (* 1 (exp (* -2 x))))
15.0ms
(* (exp (* -2 x)) (exp (* -2 x)))
13.0ms
(+ 1 (exp (* x -6)))

simplify2.4s

Counts
32 → 75
Calls

32 calls. Slowest were:

631.0ms
(- (+ (* 2 (/ (pow (exp (* -2 x)) 2) (+ (exp (* -6 x)) 1))) (* 2 (/ 1 (+ (exp (* -6 x)) 1)))) (+ (* 2 (/ (exp (* -2 x)) (+ (exp (* -6 x)) 1))) 1))
599.0ms
(- (+ (* 2 (/ (pow (exp (* -2 x)) 2) (+ (exp (* -6 x)) 1))) (* 2 (/ 1 (+ (exp (* -6 x)) 1)))) (+ (* 2 (/ (exp (* -2 x)) (+ (exp (* -6 x)) 1))) 1))
368.0ms
(- (* 6 (pow x 2)) (+ (* 2 x) (* 28/3 (pow x 3))))

prune1.3s

Pruning

3 alts after pruning (1 fresh and 2 done)

Merged error: 0.0b

regimes193.0ms

Accuracy

100% (0.0b remaining)

Error of 0.0b against oracle of 0.0b and baseline of 29.7b

bsearch186.0ms