Average Error: 29.8 → 0.0
Time: 12.0s
Precision: 64
Internal Precision: 128
\[\frac{2}{1 + e^{-2 \cdot x}} - 1\]
\[\begin{array}{l} \mathbf{if}\;x \le -0.007287118496474421 \lor \neg \left(x \le 0.004923808475551174\right):\\ \;\;\;\;\frac{\frac{2}{e^{-2 \cdot x} + 1} \cdot \frac{2}{e^{-2 \cdot x} + 1} - 1}{1 + \frac{2}{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.007287118496474421 or 0.004923808475551174 < x

    1. Initial program 0.0

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

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

      \[\leadsto \color{blue}{\frac{2}{1 + e^{-2 \cdot x}} - 1}\]
    4. Using strategy rm
    5. Applied flip--0.0

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

    if -0.007287118496474421 < x < 0.004923808475551174

    1. Initial program 59.1

      \[\frac{2}{1 + e^{-2 \cdot x}} - 1\]
    2. 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.007287118496474421 \lor \neg \left(x \le 0.004923808475551174\right):\\ \;\;\;\;\frac{\frac{2}{e^{-2 \cdot x} + 1} \cdot \frac{2}{e^{-2 \cdot x} + 1} - 1}{1 + \frac{2}{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 2019002 +o rules:numerics
(FPCore (x y)
  :name "Logistic function from Lakshay Garg"
  (- (/ 2 (+ 1 (exp (* -2 x)))) 1))

Details

Time bar (total: 11.5s)Debug log

sample98.0ms

Algorithm
intervals

simplify7.0ms

Counts
1 → 1
Calls

1 calls. Slowest were:

7.0ms
(- (/ 2 (+ 1 (exp (* -2 x)))) 1)

prune5.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 30.9b

localize36.0ms

Local error

Found 2 expressions with local error:

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

rewrite12.0ms

Algorithm
rewrite-expression-head
Counts
2 → 38
Calls

2 calls. Slowest were:

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

series89.0ms

Counts
2 → 6
Calls

2 calls. Slowest were:

61.0ms
(- (/ 2 (+ 1 (exp (* -2 x)))) 1)
28.0ms
(/ 2 (+ 1 (exp (* -2 x))))

simplify527.0ms

Counts
17 → 44
Calls

17 calls. Slowest were:

122.0ms
(- (+ x (* 2/15 (pow x 5))) (* 1/3 (pow x 3)))
110.0ms
(+ (* 1 1) (- (* (exp (* -2 x)) (exp (* -2 x))) (* 1 (exp (* -2 x)))))
67.0ms
(- (+ x 1) (* 1/3 (pow x 3)))

prune478.0ms

Pruning

3 alts after pruning (3 fresh and 0 done)

Merged error: 0.0b

localize28.0ms

Local error

Found 4 expressions with local error:

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

rewrite9.0ms

Algorithm
rewrite-expression-head
Counts
4 → 61
Calls

4 calls. Slowest were:

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

series156.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

84.0ms
(+ x (* 2/15 (pow x 5)))
35.0ms
(- (+ x (* 2/15 (pow x 5))) (* 1/3 (pow x 3)))
21.0ms
(* 2/15 (pow x 5))
15.0ms
(* 1/3 (pow x 3))

simplify1.2s

Counts
28 → 73
Calls

28 calls. Slowest were:

179.0ms
(/ (exp (+ x (* 2/15 (pow x 5)))) (exp (* 1/3 (pow x 3))))
161.0ms
(fma (sqrt (+ x (* 2/15 (pow x 5)))) (sqrt (+ x (* 2/15 (pow x 5)))) (- (* (pow x 3) 1/3)))
148.0ms
(- (+ x (* 2/15 (pow x 5))) (* 1/3 (pow x 3)))

prune808.0ms

Pruning

4 alts after pruning (3 fresh and 1 done)

Merged error: 0b

localize1.0ms

Local error

Found 2 expressions with local error:

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

rewrite12.0ms

Algorithm
rewrite-expression-head
Counts
2 → 38
Calls

2 calls. Slowest were:

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

series78.0ms

Counts
2 → 6
Calls

2 calls. Slowest were:

60.0ms
(- (/ 2 (+ 1 (exp (* -2 x)))) 1)
18.0ms
(/ 2 (+ 1 (exp (* -2 x))))

simplify528.0ms

Counts
17 → 44
Calls

17 calls. Slowest were:

121.0ms
(- (+ x (* 2/15 (pow x 5))) (* 1/3 (pow x 3)))
107.0ms
(+ (* 1 1) (- (* (exp (* -2 x)) (exp (* -2 x))) (* 1 (exp (* -2 x)))))
75.0ms
(- (+ x 1) (* 1/3 (pow x 3)))

prune420.0ms

Pruning

3 alts after pruning (2 fresh and 1 done)

Merged error: 0b

localize14.0ms

Local error

Found 4 expressions with local error:

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

rewrite15.0ms

Algorithm
rewrite-expression-head
Counts
4 → 83
Calls

4 calls. Slowest were:

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

series132.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

49.0ms
(- (* (/ 2 (+ 1 (exp (* -2 x)))) (/ 2 (+ 1 (exp (* -2 x))))) (* 1 1))
34.0ms
(* (/ 2 (+ 1 (exp (* -2 x)))) (/ 2 (+ 1 (exp (* -2 x)))))
32.0ms
(+ (/ 2 (+ 1 (exp (* -2 x)))) 1)
17.0ms
(/ 2 (+ 1 (exp (* -2 x))))

simplify3.1s

Counts
47 → 95
Calls

47 calls. Slowest were:

943.0ms
(* (* (* (/ 2 (+ 1 (exp (* -2 x)))) (/ 2 (+ 1 (exp (* -2 x))))) (/ 2 (+ 1 (exp (* -2 x))))) (* (* (/ 2 (+ 1 (exp (* -2 x)))) (/ 2 (+ 1 (exp (* -2 x))))) (/ 2 (+ 1 (exp (* -2 x))))))
283.0ms
(- (+ (* 2 x) (pow x 2)) (* 2/3 (pow x 3)))
184.0ms
(* (+ 1 (exp (* -2 x))) (+ 1 (exp (* -2 x))))

prune993.0ms

Pruning

3 alts after pruning (1 fresh and 2 done)

Merged error: 0b

regimes157.0ms

Accuracy

100% (0.0b remaining)

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

bsearch151.0ms

end0.0ms

sample2.5s

Algorithm
intervals