Average Error: 29.4 → 0.1
Time: 23.8s
Precision: binary64
Cost: 39428
\[\left(e^{x} - 2\right) + e^{-x} \]
\[\begin{array}{l} t_0 := e^{\frac{x}{-2}}\\ \mathbf{if}\;\left(e^{x} - 2\right) + e^{-x} \leq 5 \cdot 10^{-6}:\\ \;\;\;\;\mathsf{fma}\left(0.002777777777777778, {x}^{6}, \mathsf{fma}\left(x, x, 0.08333333333333333 \cdot {x}^{4}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(t_0, t_0, e^{x} + -2\right)\\ \end{array} \]
(FPCore (x) :precision binary64 (+ (- (exp x) 2.0) (exp (- x))))
(FPCore (x)
 :precision binary64
 (let* ((t_0 (exp (/ x -2.0))))
   (if (<= (+ (- (exp x) 2.0) (exp (- x))) 5e-6)
     (fma
      0.002777777777777778
      (pow x 6.0)
      (fma x x (* 0.08333333333333333 (pow x 4.0))))
     (fma t_0 t_0 (+ (exp x) -2.0)))))
double code(double x) {
	return (exp(x) - 2.0) + exp(-x);
}
double code(double x) {
	double t_0 = exp((x / -2.0));
	double tmp;
	if (((exp(x) - 2.0) + exp(-x)) <= 5e-6) {
		tmp = fma(0.002777777777777778, pow(x, 6.0), fma(x, x, (0.08333333333333333 * pow(x, 4.0))));
	} else {
		tmp = fma(t_0, t_0, (exp(x) + -2.0));
	}
	return tmp;
}
function code(x)
	return Float64(Float64(exp(x) - 2.0) + exp(Float64(-x)))
end
function code(x)
	t_0 = exp(Float64(x / -2.0))
	tmp = 0.0
	if (Float64(Float64(exp(x) - 2.0) + exp(Float64(-x))) <= 5e-6)
		tmp = fma(0.002777777777777778, (x ^ 6.0), fma(x, x, Float64(0.08333333333333333 * (x ^ 4.0))));
	else
		tmp = fma(t_0, t_0, Float64(exp(x) + -2.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[Exp[N[(x / -2.0), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[N[(N[(N[Exp[x], $MachinePrecision] - 2.0), $MachinePrecision] + N[Exp[(-x)], $MachinePrecision]), $MachinePrecision], 5e-6], N[(0.002777777777777778 * N[Power[x, 6.0], $MachinePrecision] + N[(x * x + N[(0.08333333333333333 * N[Power[x, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t$95$0 * t$95$0 + N[(N[Exp[x], $MachinePrecision] + -2.0), $MachinePrecision]), $MachinePrecision]]]
\left(e^{x} - 2\right) + e^{-x}
\begin{array}{l}
t_0 := e^{\frac{x}{-2}}\\
\mathbf{if}\;\left(e^{x} - 2\right) + e^{-x} \leq 5 \cdot 10^{-6}:\\
\;\;\;\;\mathsf{fma}\left(0.002777777777777778, {x}^{6}, \mathsf{fma}\left(x, x, 0.08333333333333333 \cdot {x}^{4}\right)\right)\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(t_0, t_0, e^{x} + -2\right)\\


\end{array}

Error

Target

Original29.4
Target0.0
Herbie0.1
\[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))) < 5.00000000000000041e-6

    1. Initial program 29.9

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

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

      \[\leadsto \color{blue}{0.002777777777777778 \cdot {x}^{6} + \left({x}^{2} + 0.08333333333333333 \cdot {x}^{4}\right)} \]
    4. Simplified0.0

      \[\leadsto \color{blue}{\mathsf{fma}\left(0.002777777777777778, {x}^{6}, x \cdot x + 0.08333333333333333 \cdot {x}^{4}\right)} \]
      Proof
    5. Applied egg-rr0.0

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

    if 5.00000000000000041e-6 < (+.f64 (-.f64 (exp.f64 x) 2) (exp.f64 (neg.f64 x)))

    1. Initial program 3.9

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

      \[\leadsto \color{blue}{\left(-2 + e^{-x}\right) + e^{x}} \]
      Proof
    3. Applied egg-rr4.3

      \[\leadsto \color{blue}{\mathsf{fma}\left(\sqrt{e^{-x}}, \sqrt{e^{-x}}, e^{x} + -2\right)} \]
    4. Applied egg-rr4.2

      \[\leadsto \mathsf{fma}\left(\sqrt{e^{-x}}, \color{blue}{e^{\frac{x}{-2}}}, e^{x} + -2\right) \]
    5. Applied egg-rr4.2

      \[\leadsto \mathsf{fma}\left(\color{blue}{e^{\frac{x}{-2}}}, e^{\frac{x}{-2}}, e^{x} + -2\right) \]
  3. Recombined 2 regimes into one program.

Alternatives

Alternative 1
Error0.1
Cost39428
\[\begin{array}{l} t_0 := \left(e^{x} - 2\right) + e^{-x}\\ \mathbf{if}\;t_0 \leq 5 \cdot 10^{-6}:\\ \;\;\;\;\mathsf{fma}\left(0.002777777777777778, {x}^{6}, \mathsf{fma}\left(x, x, 0.08333333333333333 \cdot {x}^{4}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 2
Error0.1
Cost26436
\[\begin{array}{l} t_0 := \left(e^{x} - 2\right) + e^{-x}\\ \mathbf{if}\;t_0 \leq 5 \cdot 10^{-6}:\\ \;\;\;\;\left(x + \left(x \cdot x\right) \cdot \left(x \cdot 0.08333333333333333\right)\right) \cdot x + 0.002777777777777778 \cdot {x}^{6}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 3
Error0.7
Cost7424
\[\left(x + \left(x \cdot x\right) \cdot \left(x \cdot 0.08333333333333333\right)\right) \cdot x + 0.002777777777777778 \cdot {x}^{6} \]
Alternative 4
Error0.8
Cost704
\[\left(0.08333333333333333 \cdot \left(x \cdot x\right) + 1\right) \cdot \left(x \cdot x\right) \]
Alternative 5
Error1.2
Cost192
\[x \cdot x \]
Alternative 6
Error60.2
Cost128
\[-x \]
Alternative 7
Error60.2
Cost64
\[x \]

Error

Reproduce

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