Average Error: 29.1 → 0.0
Time: 25.4s
Precision: 64
Internal Precision: 128
\[\frac{2}{1 + e^{-2 \cdot x}} - 1\]
\[\begin{array}{l} \mathbf{if}\;x \le -0.007531935859306163 \lor \neg \left(x \le 0.006834872945865455\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.007531935859306163 or 0.006834872945865455 < x

    1. Initial program 0.0

      \[\frac{2}{1 + e^{-2 \cdot x}} - 1\]
    2. Using strategy rm
    3. 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.007531935859306163 < x < 0.006834872945865455

    1. Initial program 58.9

      \[\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.007531935859306163 \lor \neg \left(x \le 0.006834872945865455\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 2019007 +o rules:numerics
(FPCore (x y)
  :name "Logistic function from Lakshay Garg"
  (- (/ 2 (+ 1 (exp (* -2 x)))) 1))

Details

Time bar (total: 25.0s)Debug log

sample95.0ms

Algorithm
intervals

simplify30.0ms

Counts
1 → 1
Calls

1 calls. Slowest were:

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

prune8.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 28.8b

localize14.0ms

Local error

Found 3 expressions with local error:

3.8b
(- (/ 2 (+ 1 (exp (* -2 x)))) 1)
0.0b
(+ 1 (exp (* -2 x)))
0.0b
(/ 2 (+ 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
(+ 1 (exp (* -2 x)))
1.0ms
(/ 2 (+ 1 (exp (* -2 x))))

series89.0ms

Counts
3 → 9
Calls

3 calls. Slowest were:

47.0ms
(- (/ 2 (+ 1 (exp (* -2 x)))) 1)
30.0ms
(/ 2 (+ 1 (exp (* -2 x))))
12.0ms
(+ 1 (exp (* -2 x)))

simplify699.0ms

Counts
20 → 59
Calls

20 calls. Slowest were:

192.0ms
(- (+ (* 2 (pow x 2)) 2) (* 2 x))
140.0ms
(+ (* 1 1) (- (* (exp (* -2 x)) (exp (* -2 x))) (* 1 (exp (* -2 x)))))
131.0ms
(- (+ x (* 2/15 (pow x 5))) (* 1/3 (pow x 3)))

prune492.0ms

Pruning

3 alts after pruning (3 fresh and 0 done)

Merged error: 0.0b

localize17.0ms

Local error

Found 4 expressions with local error:

3.8b
(- (* (/ 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
(+ 1 (exp (* -2 x)))
0.0b
(+ 1 (exp (* -2 x)))

rewrite22.0ms

Algorithm
rewrite-expression-head
Counts
4 → 72
Calls

4 calls. Slowest were:

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

series81.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

46.0ms
(- (* (/ 2 (+ 1 (exp (* -2 x)))) (/ 2 (+ 1 (exp (* -2 x))))) (* 1 1))
19.0ms
(* (/ 2 (+ 1 (exp (* -2 x)))) (/ 2 (+ 1 (exp (* -2 x)))))
8.0ms
(+ 1 (exp (* -2 x)))
8.0ms
(+ 1 (exp (* -2 x)))

simplify2.8s

Counts
38 → 84
Calls

38 calls. Slowest were:

984.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))))))
241.0ms
(- (+ (* 2 x) (pow x 2)) (* 2/3 (pow x 3)))
210.0ms
(- (+ (* 2 (pow x 2)) 2) (* 2 x))

prune708.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.1b
(- (+ 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))

rewrite13.0ms

Algorithm
rewrite-expression-head
Counts
3 → 49
Calls

3 calls. Slowest were:

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

series84.0ms

Counts
3 → 9
Calls

3 calls. Slowest were:

34.0ms
(* 2/15 (pow x 5))
26.0ms
(* 1/3 (pow x 3))
24.0ms
(- (+ x (* 2/15 (pow x 5))) (* 1/3 (pow x 3)))

simplify1.1s

Counts
25 → 58
Calls

25 calls. Slowest were:

168.0ms
(fma 1 (+ x (* 2/15 (pow x 5))) (- (* (pow x 3) 1/3)))
157.0ms
(fma (sqrt (+ x (* 2/15 (pow x 5)))) (sqrt (+ x (* 2/15 (pow x 5)))) (- (* (pow x 3) 1/3)))
143.0ms
(/ (exp (+ x (* 2/15 (pow x 5)))) (exp (* 1/3 (pow x 3))))

prune657.0ms

Pruning

3 alts after pruning (1 fresh and 2 done)

Merged error: 0.0b

localize53.0ms

Local error

Found 4 expressions with local error:

4.0b
(- (* (exp (* -2 x)) (exp (* -2 x))) (* 1 (exp (* -2 x))))
3.8b
(- (/ 2 (/ (+ (pow 1 3) (pow (exp (* -2 x)) 3)) (+ (* 1 1) (- (* (exp (* -2 x)) (exp (* -2 x))) (* 1 (exp (* -2 x))))))) 1)
0.2b
(/ (+ (pow 1 3) (pow (exp (* -2 x)) 3)) (+ (* 1 1) (- (* (exp (* -2 x)) (exp (* -2 x))) (* 1 (exp (* -2 x))))))
0.0b
(pow (exp (* -2 x)) 3)

rewrite95.0ms

Algorithm
rewrite-expression-head
Counts
4 → 111
Calls

4 calls. Slowest were:

62.0ms
(/ (+ (pow 1 3) (pow (exp (* -2 x)) 3)) (+ (* 1 1) (- (* (exp (* -2 x)) (exp (* -2 x))) (* 1 (exp (* -2 x))))))
22.0ms
(- (* (exp (* -2 x)) (exp (* -2 x))) (* 1 (exp (* -2 x))))
6.0ms
(- (/ 2 (/ (+ (pow 1 3) (pow (exp (* -2 x)) 3)) (+ (* 1 1) (- (* (exp (* -2 x)) (exp (* -2 x))) (* 1 (exp (* -2 x))))))) 1)

series460.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

311.0ms
(- (/ 2 (/ (+ (pow 1 3) (pow (exp (* -2 x)) 3)) (+ (* 1 1) (- (* (exp (* -2 x)) (exp (* -2 x))) (* 1 (exp (* -2 x))))))) 1)
85.0ms
(/ (+ (pow 1 3) (pow (exp (* -2 x)) 3)) (+ (* 1 1) (- (* (exp (* -2 x)) (exp (* -2 x))) (* 1 (exp (* -2 x))))))
39.0ms
(- (* (exp (* -2 x)) (exp (* -2 x))) (* 1 (exp (* -2 x))))
24.0ms
(pow (exp (* -2 x)) 3)

simplify12.4s

Counts
94 → 123
Calls

94 calls. Slowest were:

528.0ms
(- (+ (* 2 (/ (pow (exp (* -2 x)) 2) (+ (pow (exp (* -2 x)) 3) 1))) (* 2 (/ 1 (+ (pow (exp (* -2 x)) 3) 1)))) (+ (* 2 (/ (exp (* -2 x)) (+ (pow (exp (* -2 x)) 3) 1))) 1))
520.0ms
(- (+ (* 2 (/ (pow (exp (* -2 x)) 2) (+ (pow (exp (* -2 x)) 3) 1))) (* 2 (/ 1 (+ (pow (exp (* -2 x)) 3) 1)))) (+ (* 2 (/ (exp (* -2 x)) (+ (pow (exp (* -2 x)) 3) 1))) 1))
490.0ms
(* (cbrt (/ 2 (/ (+ (pow 1 3) (pow (exp (* -2 x)) 3)) (+ (* 1 1) (- (* (exp (* -2 x)) (exp (* -2 x))) (* 1 (exp (* -2 x)))))))) (cbrt (/ 2 (/ (+ (pow 1 3) (pow (exp (* -2 x)) 3)) (+ (* 1 1) (- (* (exp (* -2 x)) (exp (* -2 x))) (* 1 (exp (* -2 x)))))))))

prune1.7s

Pruning

3 alts after pruning (1 fresh and 2 done)

Merged error: 0.0b

regimes364.0ms

Accuracy

100% (0.0b remaining)

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

bsearch166.0ms

end0.0ms

sample2.8s

Algorithm
intervals