Average Error: 29.2 → 0.0
Time: 5.7s
Precision: binary64
\[\left(e^{x} - 2\right) + e^{-x} \]
\[\begin{array}{l} t_0 := \left(e^{x} + -2\right) + e^{-x}\\ \mathbf{if}\;t_0 \leq 0.004179448245660966:\\ \;\;\;\;\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)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
(FPCore (x) :precision binary64 (+ (- (exp x) 2.0) (exp (- x))))
(FPCore (x)
 :precision binary64
 (let* ((t_0 (+ (+ (exp x) -2.0) (exp (- x)))))
   (if (<= t_0 0.004179448245660966)
     (fma
      x
      x
      (fma
       0.08333333333333333
       (pow x 4.0)
       (fma
        0.002777777777777778
        (pow x 6.0)
        (* 4.96031746031746e-5 (pow x 8.0)))))
     t_0)))
double code(double x) {
	return (exp(x) - 2.0) + exp(-x);
}
double code(double x) {
	double t_0 = (exp(x) + -2.0) + exp(-x);
	double tmp;
	if (t_0 <= 0.004179448245660966) {
		tmp = fma(x, x, fma(0.08333333333333333, pow(x, 4.0), fma(0.002777777777777778, pow(x, 6.0), (4.96031746031746e-5 * pow(x, 8.0)))));
	} else {
		tmp = t_0;
	}
	return tmp;
}
function code(x)
	return Float64(Float64(exp(x) - 2.0) + exp(Float64(-x)))
end
function code(x)
	t_0 = Float64(Float64(exp(x) + -2.0) + exp(Float64(-x)))
	tmp = 0.0
	if (t_0 <= 0.004179448245660966)
		tmp = fma(x, x, fma(0.08333333333333333, (x ^ 4.0), fma(0.002777777777777778, (x ^ 6.0), Float64(4.96031746031746e-5 * (x ^ 8.0)))));
	else
		tmp = t_0;
	end
	return tmp
end
code[x_] := N[(N[(N[Exp[x], $MachinePrecision] - 2.0), $MachinePrecision] + N[Exp[(-x)], $MachinePrecision]), $MachinePrecision]
code[x_] := Block[{t$95$0 = N[(N[(N[Exp[x], $MachinePrecision] + -2.0), $MachinePrecision] + N[Exp[(-x)], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 0.004179448245660966], 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], t$95$0]]
\left(e^{x} - 2\right) + e^{-x}
\begin{array}{l}
t_0 := \left(e^{x} + -2\right) + e^{-x}\\
\mathbf{if}\;t_0 \leq 0.004179448245660966:\\
\;\;\;\;\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)\\

\mathbf{else}:\\
\;\;\;\;t_0\\


\end{array}

Error

Bits error versus x

Target

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

Derivation

  1. Split input into 2 regimes
  2. if (+.f64 (-.f64 (exp.f64 x) 2) (exp.f64 (neg.f64 x))) < 0.004179448245660966

    1. Initial program 29.6

      \[\left(e^{x} - 2\right) + e^{-x} \]
    2. Taylor expanded in x around 0 0.0

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

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

    if 0.004179448245660966 < (+.f64 (-.f64 (exp.f64 x) 2) (exp.f64 (neg.f64 x)))

    1. Initial program 1.1

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\left(e^{x} + -2\right) + e^{-x} \leq 0.004179448245660966:\\ \;\;\;\;\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)\\ \mathbf{else}:\\ \;\;\;\;\left(e^{x} + -2\right) + e^{-x}\\ \end{array} \]

Reproduce

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