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

Error

Bits error versus x

Bits error versus y

Derivation

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

    1. Initial program 0.0

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

      \[\leadsto \color{blue}{\frac{2}{e^{-2 \cdot x} + 1}} - 1\]
    3. Using strategy rm
    4. Applied add-cube-cbrt0.0

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

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

    if -0.008862770794215684 < x < 0.006326539173242781

    1. Initial program 59.1

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

      \[\leadsto \color{blue}{\frac{2}{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}}\]
    4. Using strategy rm
    5. Applied associate--l+0.0

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

    if 0.006326539173242781 < x

    1. Initial program 0.0

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

      \[\leadsto \color{blue}{\frac{2}{e^{-2 \cdot x} + 1}} - 1\]
  3. Recombined 3 regimes into one program.
  4. Final simplification0.0

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

Reproduce

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

Details

Time bar (total: 8.4s)Debug log

sample103.0ms

Algorithm
intervals

simplify15.0ms

Counts
1 → 1
Calls
1 calls:
Slowest
15.0ms
(- (/ 2 (+ 1 (exp (* -2 x)))) 1)

prune10.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 30.0b

localize28.0ms

Local error

Found 3 expressions with local error:

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

rewrite13.0ms

Algorithm
rewrite-expression-head
Rules
fma-neg
add-sqr-sqrt
add-cube-cbrt
*-un-lft-identity
associate-/r/
add-exp-log
add-log-exp
log1p-expm1-u
flip-+
add-cbrt-cube
flip3-+
associate-/r*
pow1
expm1-log1p-u
div-inv
flip--
difference-of-sqr-1
flip3--
frac-2neg
sub-neg
clear-num
expm1-def
+-commutative
Counts
3 → 50
Calls
3 calls:
Slowest
9.0ms
(- (/ 2 (+ 1 (exp (* -2 x)))) 1)
2.0ms
(+ 1 (exp (* -2 x)))
1.0ms
(/ 2 (+ 1 (exp (* -2 x))))

series85.0ms

Counts
3 → 9
Calls
3 calls:
Slowest
49.0ms
(- (/ 2 (+ 1 (exp (* -2 x)))) 1)
28.0ms
(/ 2 (+ 1 (exp (* -2 x))))
8.0ms
(+ 1 (exp (* -2 x)))

simplify636.0ms

Counts
20 → 59
Calls
20 calls:
Slowest
181.0ms
(- (+ (* 2 (pow x 2)) 2) (* 2 x))
132.0ms
(+ (* 1 1) (- (* (exp (* -2 x)) (exp (* -2 x))) (* 1 (exp (* -2 x)))))
93.0ms
(- (+ x (* 2/15 (pow x 5))) (* 1/3 (pow x 3)))
45.0ms
(- (+ x 1) (* 1/3 (pow x 3)))
38.0ms
(/ 2 (+ (pow 1 3) (pow (exp (* -2 x)) 3)))

prune587.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:

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

rewrite34.0ms

Algorithm
rewrite-expression-head
Rules
add-sqr-sqrt
add-cube-cbrt
fma-neg
*-un-lft-identity
associate-/r/
add-exp-log
add-log-exp
log1p-expm1-u
flip-+
add-cbrt-cube
flip3-+
fma-def
associate-/r*
pow1
expm1-log1p-u
div-inv
flip--
difference-of-sqr-1
flip3--
frac-2neg
sub-neg
clear-num
expm1-def
+-commutative
Counts
3 → 53
Calls
3 calls:
Slowest
20.0ms
(- (/ 2 (+ (exp (* -2 x)) 1)) 1)
8.0ms
(+ (exp (* -2 x)) 1)
5.0ms
(/ 2 (+ (exp (* -2 x)) 1))

series80.0ms

Counts
3 → 9
Calls
3 calls:
Slowest
56.0ms
(- (/ 2 (+ (exp (* -2 x)) 1)) 1)
16.0ms
(/ 2 (+ (exp (* -2 x)) 1))
8.0ms
(+ (exp (* -2 x)) 1)

simplify587.0ms

Counts
22 → 62
Calls
22 calls:
Slowest
187.0ms
(- (+ (* 2 (pow x 2)) 2) (* 2 x))
73.0ms
(- (+ x (* 2/15 (pow x 5))) (* 1/3 (pow x 3)))
68.0ms
(- (+ x 1) (* 1/3 (pow x 3)))
65.0ms
(+ (* (exp (* -2 x)) (exp (* -2 x))) (- (* 1 1) (* (exp (* -2 x)) 1)))
44.0ms
(/ 2 (- (* (exp (* -2 x)) (exp (* -2 x))) (* 1 1)))

prune524.0ms

Pruning

3 alts after pruning (2 fresh and 1 done)

Merged error: 0.0b

localize36.0ms

Local error

Found 3 expressions with local error:

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

rewrite17.0ms

Algorithm
rewrite-expression-head
Rules
associate-*r*
add-cube-cbrt
*-un-lft-identity
add-sqr-sqrt
add-log-exp
log1p-expm1-u
add-exp-log
prod-diff
fma-neg
add-cbrt-cube
pow1
expm1-log1p-u
*-commutative
flip--
associate--l+
unpow3
diff-log
flip3--
sub-neg
cube-mult
Counts
3 → 49
Calls
3 calls:
Slowest
11.0ms
(- (+ x (* 2/15 (pow x 5))) (* 1/3 (pow x 3)))
3.0ms
(* 2/15 (pow x 5))
2.0ms
(* 1/3 (pow x 3))

series95.0ms

Counts
3 → 9
Calls
3 calls:
Slowest
37.0ms
(- (+ x (* 2/15 (pow x 5))) (* 1/3 (pow x 3)))
32.0ms
(* 2/15 (pow x 5))
26.0ms
(* 1/3 (pow x 3))

simplify992.0ms

Counts
25 → 58
Calls
25 calls:
Slowest
149.0ms
(fma 1 (+ x (* 2/15 (pow x 5))) (- (* (pow x 3) 1/3)))
136.0ms
(/ (exp (+ x (* 2/15 (pow x 5)))) (exp (* 1/3 (pow x 3))))
130.0ms
(- (+ x (* 2/15 (pow x 5))) (* 1/3 (pow x 3)))
110.0ms
(- (+ x (* 2/15 (pow x 5))) (* 1/3 (pow x 3)))
101.0ms
(- (+ x (* 2/15 (pow x 5))) (* 1/3 (pow x 3)))

prune528.0ms

Pruning

3 alts after pruning (2 fresh and 1 done)

Merged error: 0.0b

localize12.0ms

Local error

Found 3 expressions with local error:

20.3b
(- (* 2/15 (pow x 5)) (* 1/3 (pow x 3)))
0.1b
(* 1/3 (pow x 3))
0.1b
(* 2/15 (pow x 5))

rewrite15.0ms

Algorithm
rewrite-expression-head
Rules
associate-*r*
add-log-exp
add-cube-cbrt
*-un-lft-identity
add-sqr-sqrt
log1p-expm1-u
add-exp-log
add-cbrt-cube
pow1
expm1-log1p-u
*-commutative
flip--
prod-diff
unpow3
diff-log
fma-neg
flip3--
sub-neg
cube-mult
Counts
3 → 44
Calls
3 calls:
Slowest
7.0ms
(- (* 2/15 (pow x 5)) (* 1/3 (pow x 3)))
4.0ms
(* 2/15 (pow x 5))
2.0ms
(* 1/3 (pow x 3))

series149.0ms

Counts
3 → 9
Calls
3 calls:
Slowest
94.0ms
(- (* 2/15 (pow x 5)) (* 1/3 (pow x 3)))
28.0ms
(* 2/15 (pow x 5))
27.0ms
(* 1/3 (pow x 3))

simplify353.0ms

Counts
19 → 53
Calls
19 calls:
Slowest
115.0ms
(/ (exp (* 2/15 (pow x 5))) (exp (* 1/3 (pow x 3))))
54.0ms
(- (* 2/15 (pow x 5)) (* 1/3 (pow x 3)))
47.0ms
(fma (- (pow x 3)) 1/3 (* (pow x 3) 1/3))
35.0ms
(fma 2/15 (pow x 5) (- (* (pow x 3) 1/3)))
32.0ms
(- (* 2/15 (pow x 5)) (* 1/3 (pow x 3)))

prune582.0ms

Pruning

3 alts after pruning (1 fresh and 2 done)

Merged error: 0.0b

regimes215.0ms

Accuracy

100% (0.0b remaining)

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

bsearch161.0ms

end0.0ms

sample2.6s

Algorithm
intervals