Average Error: 29.5 → 0.0
Time: 17.4s
Precision: 64
Internal Precision: 128
\[\frac{2}{1 + e^{-2 \cdot x}} - 1\]
\[\begin{array}{l} \mathbf{if}\;x \le -0.007185451780055169:\\ \;\;\;\;\frac{2}{e^{-2 \cdot x} + 1} - 1\\ \mathbf{elif}\;x \le 0.007491583784597752:\\ \;\;\;\;\left(\frac{2}{15} \cdot {x}^{5} + x\right) - {x}^{3} \cdot \frac{1}{3}\\ \mathbf{else}:\\ \;\;\;\;\frac{{\left(\frac{2}{e^{-2 \cdot x} + 1}\right)}^{3} - 1}{\left(\frac{2}{e^{-2 \cdot x} + 1} + 1\right) + \frac{2}{e^{-2 \cdot x} + 1} \cdot \frac{2}{e^{-2 \cdot x} + 1}}\\ \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 3 regimes
  2. if x < -0.007185451780055169

    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}\]

    if -0.007185451780055169 < x < 0.007491583784597752

    1. Initial program 59.0

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

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

      \[\leadsto \color{blue}{\frac{2}{1 + e^{-2 \cdot x}} - 1}\]
    4. 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.007491583784597752 < x

    1. Initial program 0.0

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

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

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

Reproduce

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

Details

Time bar (total: 16.9s)Debug log

sample90.0ms

Algorithm
intervals
Results
32.0ms60×body1280valid
28.0ms37×body640valid
11.0ms137×body80valid
4.0ms16×body320valid
1.0msbody160valid

simplify14.0ms

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

prune8.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 28.1b

localize23.0ms

Local error

Found 1 expressions with local error:

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

rewrite7.0ms

Algorithm
rewrite-expression-head
Rules
add-sqr-sqrt
add-log-exp
flip--
add-cube-cbrt
add-exp-log
difference-of-sqr-1
add-cbrt-cube
flip3--
*-un-lft-identity
sub-neg
pow1
Counts
1 → 12
Calls
1 calls:
Slowest
7.0ms
(- (/ 2 (+ 1 (exp (* -2 x)))) 1)

series55.0ms

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

simplify141.0ms

Counts
4 → 15
Calls
4 calls:
Slowest
90.0ms
(- (+ x (* 2/15 (pow x 5))) (* 1/3 (pow x 3)))
21.0ms
(- (* 2 (/ 1 (+ (exp (* -2 x)) 1))) 1)
20.0ms
(- (* 2 (/ 1 (+ (exp (* -2 x)) 1))) 1)
9.0ms
(+ (sqrt (/ 2 (+ 1 (exp (* -2 x))))) 1)

prune140.0ms

Pruning

3 alts after pruning (3 fresh and 0 done)

Merged error: 0b

localize49.0ms

Local error

Found 4 expressions with local error:

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

rewrite48.0ms

Algorithm
rewrite-expression-head
Rules
14×add-sqr-sqrt
11×add-log-exp
11×*-un-lft-identity
10×pow1
flip-+
add-cube-cbrt
associate-/r/
flip3-+
add-exp-log
cube-prod
add-cbrt-cube
unpow-prod-down
frac-add
associate-*l*
associate-*r*
div-inv
difference-of-squares
associate-*r/
associate-*l/
sum-log
frac-times
distribute-lft-out--
cube-mult
rem-cube-cbrt
flip--
cbrt-unprod
pow-prod-up
*-commutative
prod-exp
pow-exp
pow-prod-down
unpow3
diff-log
flip3--
pow-plus
pow-pow
sub-neg
associate-+r+
+-commutative
difference-cubes
pow-to-exp
pow2
cube-div
Counts
4 → 92
Calls
4 calls:
Slowest
20.0ms
(- (pow (/ 2 (+ 1 (exp (* -2 x)))) 3) (pow 1 3))
16.0ms
(+ (* (/ 2 (+ 1 (exp (* -2 x)))) (/ 2 (+ 1 (exp (* -2 x))))) (+ (* 1 1) (* (/ 2 (+ 1 (exp (* -2 x)))) 1)))
7.0ms
(* (/ 2 (+ 1 (exp (* -2 x)))) (/ 2 (+ 1 (exp (* -2 x)))))
3.0ms
(pow (/ 2 (+ 1 (exp (* -2 x)))) 3)

series205.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
76.0ms
(- (pow (/ 2 (+ 1 (exp (* -2 x)))) 3) (pow 1 3))
72.0ms
(+ (* (/ 2 (+ 1 (exp (* -2 x)))) (/ 2 (+ 1 (exp (* -2 x))))) (+ (* 1 1) (* (/ 2 (+ 1 (exp (* -2 x)))) 1)))
38.0ms
(pow (/ 2 (+ 1 (exp (* -2 x)))) 3)
20.0ms
(* (/ 2 (+ 1 (exp (* -2 x)))) (/ 2 (+ 1 (exp (* -2 x)))))

simplify10.2s

Counts
74 → 104
Calls
74 calls:
Slowest
956.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))))))
629.0ms
(+ (* (* 2 (/ 2 (+ 1 (exp (* -2 x))))) (- (* 1 1) (* (/ 2 (+ 1 (exp (* -2 x)))) 1))) (* (+ 1 (exp (* -2 x))) (- (* (* 1 1) (* 1 1)) (* (* (/ 2 (+ 1 (exp (* -2 x)))) 1) (* (/ 2 (+ 1 (exp (* -2 x)))) 1)))))
524.0ms
(pow (/ 2 (- (* 1 1) (* (exp (* -2 x)) (exp (* -2 x))))) 3)
518.0ms
(pow (/ 2 (- (* 1 1) (* (exp (* -2 x)) (exp (* -2 x))))) 3)
513.0ms
(+ (* (* (/ 2 (+ 1 (exp (* -2 x)))) 2) (- (* 1 1) (* (/ 2 (+ 1 (exp (* -2 x)))) 1))) (* (+ 1 (exp (* -2 x))) (- (* (* 1 1) (* 1 1)) (* (* (/ 2 (+ 1 (exp (* -2 x)))) 1) (* (/ 2 (+ 1 (exp (* -2 x)))) 1)))))

prune1.4s

Pruning

3 alts after pruning (2 fresh and 1 done)

Merged error: 0b

localize0.0ms

Local error

Found 1 expressions with local error:

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

rewrite4.0ms

Algorithm
rewrite-expression-head
Rules
add-sqr-sqrt
add-log-exp
flip--
add-cube-cbrt
add-exp-log
difference-of-sqr-1
add-cbrt-cube
flip3--
*-un-lft-identity
sub-neg
pow1
Counts
1 → 12
Calls
1 calls:
Slowest
4.0ms
(- (/ 2 (+ 1 (exp (* -2 x)))) 1)

series35.0ms

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

simplify144.0ms

Counts
4 → 15
Calls
4 calls:
Slowest
64.0ms
(- (+ x (* 2/15 (pow x 5))) (* 1/3 (pow x 3)))
40.0ms
(- (* 2 (/ 1 (+ (exp (* -2 x)) 1))) 1)
30.0ms
(- (* 2 (/ 1 (+ (exp (* -2 x)) 1))) 1)
9.0ms
(+ (sqrt (/ 2 (+ 1 (exp (* -2 x))))) 1)

prune140.0ms

Pruning

3 alts after pruning (1 fresh and 2 done)

Merged error: 0b

localize35.0ms

Local error

Found 4 expressions with local error:

19.1b
(- (+ x (* 2/15 (pow x 5))) (* 1/3 (pow x 3)))
0.2b
(* 2/15 (pow x 5))
0.1b
(* 1/3 (pow x 3))
0.0b
(+ x (* 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
add-exp-log
add-cbrt-cube
pow1
*-commutative
flip--
flip-+
associate--l+
unpow3
diff-log
flip3--
flip3-+
sub-neg
+-commutative
cube-mult
Counts
4 → 47
Calls
4 calls:
Slowest
8.0ms
(- (+ x (* 2/15 (pow x 5))) (* 1/3 (pow x 3)))
2.0ms
(* 1/3 (pow x 3))
2.0ms
(* 2/15 (pow x 5))
2.0ms
(+ x (* 2/15 (pow x 5)))

series166.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
69.0ms
(+ x (* 2/15 (pow x 5)))
36.0ms
(- (+ x (* 2/15 (pow x 5))) (* 1/3 (pow x 3)))
33.0ms
(* 2/15 (pow x 5))
26.0ms
(* 1/3 (pow x 3))

simplify421.0ms

Counts
20 → 59
Calls
20 calls:
Slowest
144.0ms
(/ (exp (+ x (* 2/15 (pow x 5)))) (exp (* 1/3 (pow x 3))))
75.0ms
(- (+ x (* 2/15 (pow x 5))) (* 1/3 (pow x 3)))
73.0ms
(- (+ x (* 2/15 (pow x 5))) (* 1/3 (pow x 3)))
68.0ms
(- (+ x (* 2/15 (pow x 5))) (* 1/3 (pow x 3)))
10.0ms
(* 1/3 (pow x 3))

prune557.0ms

Pruning

3 alts after pruning (0 fresh and 3 done)

Merged error: 0b

regimes381.0ms

Accuracy

100% (0.0b remaining)

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

bsearch168.0ms

end0.0ms

sample2.6s

Algorithm
intervals
Results
953.0ms1714×body1280valid
822.0ms1261×body640valid
448.0ms4078×body80valid
154.0ms639×body320valid
51.0ms308×body160valid