Average Error: 29.3 → 0.6
Time: 10.8s
Precision: binary64
Cost: 13184
\[\left(e^{x} - 2\right) + e^{-x} \]
\[\mathsf{fma}\left(x, x, {x}^{4} \cdot 0.08333333333333333\right) \]
(FPCore (x) :precision binary64 (+ (- (exp x) 2.0) (exp (- x))))
(FPCore (x) :precision binary64 (fma x x (* (pow x 4.0) 0.08333333333333333)))
double code(double x) {
	return (exp(x) - 2.0) + exp(-x);
}
double code(double x) {
	return fma(x, x, (pow(x, 4.0) * 0.08333333333333333));
}
function code(x)
	return Float64(Float64(exp(x) - 2.0) + exp(Float64(-x)))
end
function code(x)
	return fma(x, x, Float64((x ^ 4.0) * 0.08333333333333333))
end
code[x_] := N[(N[(N[Exp[x], $MachinePrecision] - 2.0), $MachinePrecision] + N[Exp[(-x)], $MachinePrecision]), $MachinePrecision]
code[x_] := N[(x * x + N[(N[Power[x, 4.0], $MachinePrecision] * 0.08333333333333333), $MachinePrecision]), $MachinePrecision]
\left(e^{x} - 2\right) + e^{-x}
\mathsf{fma}\left(x, x, {x}^{4} \cdot 0.08333333333333333\right)

Error

Target

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

Derivation

  1. Initial program 29.3

    \[\left(e^{x} - 2\right) + e^{-x} \]
  2. Applied egg-rr30.1

    \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(e^{x} + -2\right)\right)} + e^{-x} \]
  3. Taylor expanded in x around 0 0.6

    \[\leadsto \color{blue}{{x}^{2} + 0.08333333333333333 \cdot {x}^{4}} \]
  4. Simplified0.6

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

    \[\leadsto \mathsf{fma}\left(x, x, {x}^{4} \cdot 0.08333333333333333\right) \]

Alternatives

Alternative 1
Error0.6
Cost6912
\[{x}^{4} \cdot 0.08333333333333333 + x \cdot x \]
Alternative 2
Error1.0
Cost192
\[x \cdot x \]
Alternative 3
Error60.2
Cost128
\[-x \]

Error

Reproduce

herbie shell --seed 2022311 
(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))))