Average Error: 29.6 → 0.6
Time: 9.2s
Precision: binary64
Cost: 39168
\[\left(e^{x} - 2\right) + e^{-x} \]
\[\mathsf{fma}\left(x, x, \mathsf{fma}\left(0.08333333333333333, {x}^{4}, \mathsf{fma}\left(0.002777777777777778, {x}^{6}, 4.96031746031746 \cdot 10^{-5} \cdot {x}^{8}\right)\right)\right) \]
(FPCore (x) :precision binary64 (+ (- (exp x) 2.0) (exp (- x))))
(FPCore (x)
 :precision binary64
 (fma
  x
  x
  (fma
   0.08333333333333333
   (pow x 4.0)
   (fma
    0.002777777777777778
    (pow x 6.0)
    (* 4.96031746031746e-5 (pow x 8.0))))))
double code(double x) {
	return (exp(x) - 2.0) + exp(-x);
}
double code(double x) {
	return fma(x, x, fma(0.08333333333333333, pow(x, 4.0), fma(0.002777777777777778, pow(x, 6.0), (4.96031746031746e-5 * pow(x, 8.0)))));
}
function code(x)
	return Float64(Float64(exp(x) - 2.0) + exp(Float64(-x)))
end
function code(x)
	return fma(x, x, fma(0.08333333333333333, (x ^ 4.0), fma(0.002777777777777778, (x ^ 6.0), Float64(4.96031746031746e-5 * (x ^ 8.0)))))
end
code[x_] := N[(N[(N[Exp[x], $MachinePrecision] - 2.0), $MachinePrecision] + N[Exp[(-x)], $MachinePrecision]), $MachinePrecision]
code[x_] := N[(x * x + N[(0.08333333333333333 * N[Power[x, 4.0], $MachinePrecision] + N[(0.002777777777777778 * N[Power[x, 6.0], $MachinePrecision] + N[(4.96031746031746e-5 * N[Power[x, 8.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\left(e^{x} - 2\right) + e^{-x}
\mathsf{fma}\left(x, x, \mathsf{fma}\left(0.08333333333333333, {x}^{4}, \mathsf{fma}\left(0.002777777777777778, {x}^{6}, 4.96031746031746 \cdot 10^{-5} \cdot {x}^{8}\right)\right)\right)

Error

Target

Original29.6
Target0.0
Herbie0.6
\[4 \cdot {\sinh \left(\frac{x}{2}\right)}^{2} \]

Derivation

  1. Initial program 29.6

    \[\left(e^{x} - 2\right) + e^{-x} \]
  2. Simplified29.7

    \[\leadsto \color{blue}{-2 + \left(e^{x} + e^{-x}\right)} \]
    Proof
    (+.f64 -2 (+.f64 (exp.f64 x) (exp.f64 (neg.f64 x)))): 0 points increase in error, 0 points decrease in error
    (+.f64 (Rewrite<= metadata-eval (neg.f64 2)) (+.f64 (exp.f64 x) (exp.f64 (neg.f64 x)))): 0 points increase in error, 0 points decrease in error
    (Rewrite<= associate-+l+_binary64 (+.f64 (+.f64 (neg.f64 2) (exp.f64 x)) (exp.f64 (neg.f64 x)))): 3 points increase in error, 3 points decrease in error
    (+.f64 (Rewrite<= +-commutative_binary64 (+.f64 (exp.f64 x) (neg.f64 2))) (exp.f64 (neg.f64 x))): 0 points increase in error, 0 points decrease in error
    (+.f64 (Rewrite<= sub-neg_binary64 (-.f64 (exp.f64 x) 2)) (exp.f64 (neg.f64 x))): 0 points increase in error, 0 points decrease in error
  3. Taylor expanded in x around 0 0.6

    \[\leadsto \color{blue}{0.002777777777777778 \cdot {x}^{6} + \left({x}^{2} + \left(0.08333333333333333 \cdot {x}^{4} + 4.96031746031746 \cdot 10^{-5} \cdot {x}^{8}\right)\right)} \]
  4. Simplified0.6

    \[\leadsto \color{blue}{\mathsf{fma}\left(x, x, \mathsf{fma}\left(0.08333333333333333, {x}^{4}, \mathsf{fma}\left(0.002777777777777778, {x}^{6}, 4.96031746031746 \cdot 10^{-5} \cdot {x}^{8}\right)\right)\right)} \]
    Proof
    (fma.f64 x x (fma.f64 1/12 (pow.f64 x 4) (fma.f64 1/360 (pow.f64 x 6) (*.f64 1/20160 (pow.f64 x 8))))): 0 points increase in error, 0 points decrease in error
    (fma.f64 x x (fma.f64 1/12 (pow.f64 x 4) (Rewrite<= fma-def_binary64 (+.f64 (*.f64 1/360 (pow.f64 x 6)) (*.f64 1/20160 (pow.f64 x 8)))))): 1 points increase in error, 0 points decrease in error
    (fma.f64 x x (fma.f64 1/12 (pow.f64 x 4) (Rewrite<= +-commutative_binary64 (+.f64 (*.f64 1/20160 (pow.f64 x 8)) (*.f64 1/360 (pow.f64 x 6)))))): 0 points increase in error, 0 points decrease in error
    (fma.f64 x x (Rewrite<= fma-def_binary64 (+.f64 (*.f64 1/12 (pow.f64 x 4)) (+.f64 (*.f64 1/20160 (pow.f64 x 8)) (*.f64 1/360 (pow.f64 x 6)))))): 0 points increase in error, 0 points decrease in error
    (fma.f64 x x (Rewrite<= associate-+l+_binary64 (+.f64 (+.f64 (*.f64 1/12 (pow.f64 x 4)) (*.f64 1/20160 (pow.f64 x 8))) (*.f64 1/360 (pow.f64 x 6))))): 0 points increase in error, 0 points decrease in error
    (Rewrite<= fma-def_binary64 (+.f64 (*.f64 x x) (+.f64 (+.f64 (*.f64 1/12 (pow.f64 x 4)) (*.f64 1/20160 (pow.f64 x 8))) (*.f64 1/360 (pow.f64 x 6))))): 1 points increase in error, 0 points decrease in error
    (+.f64 (Rewrite<= unpow2_binary64 (pow.f64 x 2)) (+.f64 (+.f64 (*.f64 1/12 (pow.f64 x 4)) (*.f64 1/20160 (pow.f64 x 8))) (*.f64 1/360 (pow.f64 x 6)))): 0 points increase in error, 0 points decrease in error
    (Rewrite<= associate-+l+_binary64 (+.f64 (+.f64 (pow.f64 x 2) (+.f64 (*.f64 1/12 (pow.f64 x 4)) (*.f64 1/20160 (pow.f64 x 8)))) (*.f64 1/360 (pow.f64 x 6)))): 0 points increase in error, 0 points decrease in error
    (Rewrite<= +-commutative_binary64 (+.f64 (*.f64 1/360 (pow.f64 x 6)) (+.f64 (pow.f64 x 2) (+.f64 (*.f64 1/12 (pow.f64 x 4)) (*.f64 1/20160 (pow.f64 x 8)))))): 0 points increase in error, 0 points decrease in error
  5. Final simplification0.6

    \[\leadsto \mathsf{fma}\left(x, x, \mathsf{fma}\left(0.08333333333333333, {x}^{4}, \mathsf{fma}\left(0.002777777777777778, {x}^{6}, 4.96031746031746 \cdot 10^{-5} \cdot {x}^{8}\right)\right)\right) \]

Alternatives

Alternative 1
Error0.6
Cost26624
\[\mathsf{fma}\left(x, x, 0.002777777777777778 \cdot {x}^{6} + \left(4.96031746031746 \cdot 10^{-5} \cdot {x}^{8} + 0.08333333333333333 \cdot {x}^{4}\right)\right) \]
Alternative 2
Error0.6
Cost13568
\[\mathsf{fma}\left(x, x, {x}^{4} \cdot \left(0.08333333333333333 + 0.002777777777777778 \cdot \left(x \cdot x\right)\right)\right) \]
Alternative 3
Error0.8
Cost6912
\[0.08333333333333333 \cdot {x}^{4} + x \cdot x \]
Alternative 4
Error1.1
Cost192
\[x \cdot x \]

Error

Reproduce

herbie shell --seed 2022295 
(FPCore (x)
  :name "exp2 (problem 3.3.7)"
  :precision binary64

  :herbie-target
  (* 4.0 (pow (sinh (/ x 2.0)) 2.0))

  (+ (- (exp x) 2.0) (exp (- x))))