Average Error: 29.2 → 0.0
Time: 7.9s
Precision: 64
Internal Precision: 128
\[\frac{2}{1 + e^{-2 \cdot x}} - 1\]
\[\begin{array}{l} \mathbf{if}\;x \le -0.006392313756824013 \lor \neg \left(x \le 0.006923448538232147\right):\\ \;\;\;\;\frac{2}{1 + e^{-2 \cdot x}} - 1\\ \mathbf{else}:\\ \;\;\;\;\left(\frac{2}{15} \cdot {x}^{5} + x\right) - {x}^{3} \cdot \frac{1}{3}\\ \end{array}\]

Error

Bits error versus x

Bits error versus y

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

  1. Split input into 2 regimes
  2. if x < -0.006392313756824013 or 0.006923448538232147 < 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\]

    if -0.006392313756824013 < x < 0.006923448538232147

    1. Initial program 58.8

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

      \[\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}}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.0

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -0.006392313756824013 \lor \neg \left(x \le 0.006923448538232147\right):\\ \;\;\;\;\frac{2}{1 + e^{-2 \cdot x}} - 1\\ \mathbf{else}:\\ \;\;\;\;\left(\frac{2}{15} \cdot {x}^{5} + x\right) - {x}^{3} \cdot \frac{1}{3}\\ \end{array}\]

Reproduce

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

Details

Time bar (total: 7.5s)Debug log

sample89.0ms

Algorithm
intervals
Results
256×(pre true 80)
141×(body real 80)
48×(body real 1280)
38×(body real 640)
20×(body real 320)
(body real 160)

simplify7.0ms

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

prune5.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 27.3b

localize16.0ms

Local error

Found 2 expressions with local error:

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

rewrite12.0ms

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

series82.0ms

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

simplify498.0ms

Counts
17 → 44
Calls
17 calls:
Slowest
117.0ms
(+ (* 1 1) (- (* (exp (* -2 x)) (exp (* -2 x))) (* 1 (exp (* -2 x)))))
97.0ms
(- (+ x (* 2/15 (pow x 5))) (* 1/3 (pow x 3)))
76.0ms
(- (+ x 1) (* 1/3 (pow x 3)))
43.0ms
(- (* 2 (/ 1 (+ (exp (* -2 x)) 1))) 1)
43.0ms
(/ 2 (+ (pow 1 3) (pow (exp (* -2 x)) 3)))

prune400.0ms

Pruning

2 alts after pruning (2 fresh and 0 done)

Merged error: 0b

localize9.0ms

Local error

Found 2 expressions with local error:

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

rewrite16.0ms

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

series74.0ms

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

simplify588.0ms

Counts
17 → 44
Calls
17 calls:
Slowest
147.0ms
(- (+ x (* 2/15 (pow x 5))) (* 1/3 (pow x 3)))
107.0ms
(+ (* (exp (* -2 x)) (exp (* -2 x))) (- (* 1 1) (* (exp (* -2 x)) 1)))
59.0ms
(- (+ x 1) (* 1/3 (pow x 3)))
58.0ms
(/ 2 (- (* (exp (* -2 x)) (exp (* -2 x))) (* 1 1)))
53.0ms
(/ 2 (+ (pow (exp (* -2 x)) 3) (pow 1 3)))

prune475.0ms

Pruning

2 alts after pruning (1 fresh and 1 done)

Merged error: 0b

localize20.0ms

Local error

Found 3 expressions with local error:

21.2b
(- (+ 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))

rewrite8.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
5.0ms
(- (+ x (* 2/15 (pow x 5))) (* 1/3 (pow x 3)))
1.0ms
(* 1/3 (pow x 3))
1.0ms
(* 2/15 (pow x 5))

series85.0ms

Counts
3 → 9
Calls
3 calls:
Slowest
35.0ms
(* 2/15 (pow x 5))
34.0ms
(- (+ x (* 2/15 (pow x 5))) (* 1/3 (pow x 3)))
16.0ms
(* 1/3 (pow x 3))

simplify987.0ms

Counts
25 → 58
Calls
25 calls:
Slowest
173.0ms
(/ (exp (+ x (* 2/15 (pow x 5)))) (exp (* 1/3 (pow x 3))))
134.0ms
(fma 1 (+ x (* 2/15 (pow x 5))) (- (* (pow x 3) 1/3)))
122.0ms
(- (+ x (* 2/15 (pow x 5))) (* 1/3 (pow x 3)))
113.0ms
(fma (sqrt (+ x (* 2/15 (pow x 5)))) (sqrt (+ x (* 2/15 (pow x 5)))) (- (* (pow x 3) 1/3)))
110.0ms
(- (+ x (* 2/15 (pow x 5))) (* 1/3 (pow x 3)))

prune639.0ms

Pruning

2 alts after pruning (0 fresh and 2 done)

Merged error: 0b

regimes150.0ms

Accuracy

100% (0.0b remaining)

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

bsearch150.0ms

end0.0ms

sample3.2s

Algorithm
intervals
Results
8000×(pre true 80)
4116×(body real 80)
1682×(body real 1280)
1264×(body real 640)
617×(body real 320)
321×(body real 160)