Average Error: 29.9 → 0.7
Time: 10.6s
Precision: binary64
Cost: 7104
\[\left(e^{x} - 2\right) + e^{-x} \]
\[\mathsf{fma}\left(0.08333333333333333, \left(x \cdot x\right) \cdot \left(x \cdot x\right), x \cdot x\right) \]
(FPCore (x) :precision binary64 (+ (- (exp x) 2.0) (exp (- x))))
(FPCore (x)
 :precision binary64
 (fma 0.08333333333333333 (* (* x x) (* x x)) (* x x)))
double code(double x) {
	return (exp(x) - 2.0) + exp(-x);
}
double code(double x) {
	return fma(0.08333333333333333, ((x * x) * (x * x)), (x * x));
}
function code(x)
	return Float64(Float64(exp(x) - 2.0) + exp(Float64(-x)))
end
function code(x)
	return fma(0.08333333333333333, Float64(Float64(x * x) * Float64(x * x)), Float64(x * x))
end
code[x_] := N[(N[(N[Exp[x], $MachinePrecision] - 2.0), $MachinePrecision] + N[Exp[(-x)], $MachinePrecision]), $MachinePrecision]
code[x_] := N[(0.08333333333333333 * N[(N[(x * x), $MachinePrecision] * N[(x * x), $MachinePrecision]), $MachinePrecision] + N[(x * x), $MachinePrecision]), $MachinePrecision]
\left(e^{x} - 2\right) + e^{-x}
\mathsf{fma}\left(0.08333333333333333, \left(x \cdot x\right) \cdot \left(x \cdot x\right), x \cdot x\right)

Error

Target

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

Derivation

  1. Initial program 29.9

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

    \[\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.7

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

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

    \[\leadsto \mathsf{fma}\left(0.08333333333333333, \color{blue}{\left(x \cdot x\right) \cdot \left(x \cdot x\right)}, x \cdot x\right) \]
  6. Final simplification0.7

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

Alternatives

Alternative 1
Error1.1
Cost192
\[x \cdot x \]
Alternative 2
Error60.2
Cost128
\[-x \]
Alternative 3
Error60.2
Cost64
\[x \]

Error

Reproduce

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