?

Average Error: 29.3 → 0.1
Time: 12.1s
Precision: binary64
Cost: 26436

?

\[\left(e^{x} - 2\right) + e^{-x} \]
\[\begin{array}{l} t_0 := \left(e^{x} + -2\right) + e^{-x}\\ \mathbf{if}\;t_0 \leq 4 \cdot 10^{-5}:\\ \;\;\;\;\mathsf{fma}\left(x, x, 0.08333333333333333 \cdot {x}^{4}\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 4e-5) (fma x x (* 0.08333333333333333 (pow x 4.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 <= 4e-5) {
		tmp = fma(x, x, (0.08333333333333333 * pow(x, 4.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 <= 4e-5)
		tmp = fma(x, x, Float64(0.08333333333333333 * (x ^ 4.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, 4e-5], N[(x * x + N[(0.08333333333333333 * N[Power[x, 4.0], $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 4 \cdot 10^{-5}:\\
\;\;\;\;\mathsf{fma}\left(x, x, 0.08333333333333333 \cdot {x}^{4}\right)\\

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


\end{array}

Error?

Target

Original29.3
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))) < 4.00000000000000033e-5

    1. Initial program 29.7

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

      \[\leadsto \color{blue}{e^{x} + \left(e^{-x} + -2\right)} \]
      Proof

      [Start]29.7

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

      associate-+l- [=>]29.7

      \[ \color{blue}{e^{x} - \left(2 - e^{-x}\right)} \]

      sub-neg [=>]29.7

      \[ \color{blue}{e^{x} + \left(-\left(2 - e^{-x}\right)\right)} \]

      neg-sub0 [=>]29.7

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

      associate--r- [=>]29.7

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

      metadata-eval [=>]29.7

      \[ e^{x} + \left(\color{blue}{-2} + e^{-x}\right) \]

      metadata-eval [<=]29.7

      \[ e^{x} + \left(\color{blue}{\left(-2\right)} + e^{-x}\right) \]

      +-commutative [=>]29.7

      \[ e^{x} + \color{blue}{\left(e^{-x} + \left(-2\right)\right)} \]

      metadata-eval [=>]29.7

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

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

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

      [Start]0.0

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

      fma-def [=>]0.0

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

      unpow2 [=>]0.0

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

      fma-def [=>]0.0

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

      fma-def [=>]0.0

      \[ \mathsf{fma}\left(0.002777777777777778, {x}^{6}, \mathsf{fma}\left(x, x, \color{blue}{\mathsf{fma}\left(0.08333333333333333, {x}^{4}, 4.96031746031746 \cdot 10^{-5} \cdot {x}^{8}\right)}\right)\right) \]
    5. Taylor expanded in x around 0 0.0

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

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

      [Start]0.0

      \[ {x}^{2} + 0.08333333333333333 \cdot {x}^{4} \]

      unpow2 [=>]0.0

      \[ \color{blue}{x \cdot x} + 0.08333333333333333 \cdot {x}^{4} \]

      fma-def [=>]0.0

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

    if 4.00000000000000033e-5 < (+.f64 (-.f64 (exp.f64 x) 2) (exp.f64 (neg.f64 x)))

    1. Initial program 3.5

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\left(e^{x} + -2\right) + e^{-x} \leq 4 \cdot 10^{-5}:\\ \;\;\;\;\mathsf{fma}\left(x, x, 0.08333333333333333 \cdot {x}^{4}\right)\\ \mathbf{else}:\\ \;\;\;\;\left(e^{x} + -2\right) + e^{-x}\\ \end{array} \]

Alternatives

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

Error

Reproduce?

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