?

Average Accuracy: 52.9% → 100.0%
Time: 14.9s
Precision: binary64
Cost: 33156

?

\[\left(e^{x} - 2\right) + e^{-x} \]
\[\begin{array}{l} t_0 := e^{-x}\\ \mathbf{if}\;\left(e^{x} + -2\right) + t_0 \leq 0.0001:\\ \;\;\;\;\mathsf{fma}\left(x, x, 0.002777777777777778 \cdot {x}^{6}\right) + 0.08333333333333333 \cdot {x}^{4}\\ \mathbf{else}:\\ \;\;\;\;e^{x} + \left(t_0 + -2\right)\\ \end{array} \]
(FPCore (x) :precision binary64 (+ (- (exp x) 2.0) (exp (- x))))
(FPCore (x)
 :precision binary64
 (let* ((t_0 (exp (- x))))
   (if (<= (+ (+ (exp x) -2.0) t_0) 0.0001)
     (+
      (fma x x (* 0.002777777777777778 (pow x 6.0)))
      (* 0.08333333333333333 (pow x 4.0)))
     (+ (exp x) (+ t_0 -2.0)))))
double code(double x) {
	return (exp(x) - 2.0) + exp(-x);
}
double code(double x) {
	double t_0 = exp(-x);
	double tmp;
	if (((exp(x) + -2.0) + t_0) <= 0.0001) {
		tmp = fma(x, x, (0.002777777777777778 * pow(x, 6.0))) + (0.08333333333333333 * pow(x, 4.0));
	} else {
		tmp = exp(x) + (t_0 + -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))
	tmp = 0.0
	if (Float64(Float64(exp(x) + -2.0) + t_0) <= 0.0001)
		tmp = Float64(fma(x, x, Float64(0.002777777777777778 * (x ^ 6.0))) + Float64(0.08333333333333333 * (x ^ 4.0)));
	else
		tmp = Float64(exp(x) + Float64(t_0 + -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[(-x)], $MachinePrecision]}, If[LessEqual[N[(N[(N[Exp[x], $MachinePrecision] + -2.0), $MachinePrecision] + t$95$0), $MachinePrecision], 0.0001], N[(N[(x * x + N[(0.002777777777777778 * N[Power[x, 6.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(0.08333333333333333 * N[Power[x, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Exp[x], $MachinePrecision] + N[(t$95$0 + -2.0), $MachinePrecision]), $MachinePrecision]]]
\left(e^{x} - 2\right) + e^{-x}
\begin{array}{l}
t_0 := e^{-x}\\
\mathbf{if}\;\left(e^{x} + -2\right) + t_0 \leq 0.0001:\\
\;\;\;\;\mathsf{fma}\left(x, x, 0.002777777777777778 \cdot {x}^{6}\right) + 0.08333333333333333 \cdot {x}^{4}\\

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


\end{array}

Error?

Target

Original52.9%
Target99.9%
Herbie100.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))) < 1.00000000000000005e-4

    1. Initial program 52.2%

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

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

      [Start]52.2

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

      associate-+l- [=>]52.2

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

      sub-neg [=>]52.2

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

      neg-sub0 [=>]52.2

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

      associate--r- [=>]52.2

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

      metadata-eval [=>]52.2

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

      metadata-eval [<=]52.2

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

      +-commutative [=>]52.2

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

      metadata-eval [=>]52.2

      \[ e^{x} + \left(e^{-x} + \color{blue}{-2}\right) \]
    3. Taylor expanded in x around 0 100.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. Simplified100.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]100.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 [=>]100.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 [=>]100.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 [=>]100.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 [=>]100.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 100.0%

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

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

      [Start]100.0

      \[ 0.002777777777777778 \cdot {x}^{6} + \left({x}^{2} + 0.08333333333333333 \cdot {x}^{4}\right) \]

      associate-+r+ [=>]100.0

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

      unpow2 [=>]100.0

      \[ \left(0.002777777777777778 \cdot {x}^{6} + \color{blue}{x \cdot x}\right) + 0.08333333333333333 \cdot {x}^{4} \]

      +-commutative [<=]100.0

      \[ \color{blue}{\left(x \cdot x + 0.002777777777777778 \cdot {x}^{6}\right)} + 0.08333333333333333 \cdot {x}^{4} \]

      +-commutative [=>]100.0

      \[ \color{blue}{0.08333333333333333 \cdot {x}^{4} + \left(x \cdot x + 0.002777777777777778 \cdot {x}^{6}\right)} \]

      fma-def [=>]100.0

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

      fma-def [=>]100.0

      \[ \mathsf{fma}\left(0.08333333333333333, {x}^{4}, \color{blue}{\mathsf{fma}\left(x, x, 0.002777777777777778 \cdot {x}^{6}\right)}\right) \]
    7. Applied egg-rr100.0%

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

      [Start]100.0

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

      fma-udef [=>]100.0

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

      +-commutative [=>]100.0

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

    if 1.00000000000000005e-4 < (+.f64 (-.f64 (exp.f64 x) 2) (exp.f64 (neg.f64 x)))

    1. Initial program 97.4%

      \[\left(e^{x} - 2\right) + e^{-x} \]
    2. Simplified97.5%

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

      [Start]97.4

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

      associate-+l- [=>]97.5

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

      sub-neg [=>]97.5

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

      neg-sub0 [=>]97.5

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

      associate--r- [=>]97.5

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

      metadata-eval [=>]97.5

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

      metadata-eval [<=]97.5

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

      +-commutative [=>]97.5

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

      metadata-eval [=>]97.5

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

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

Alternatives

Alternative 1
Accuracy99.9%
Cost27012
\[\begin{array}{l} t_0 := e^{-x}\\ \mathbf{if}\;\left(e^{x} + -2\right) + t_0 \leq 0.0001:\\ \;\;\;\;0.08333333333333333 \cdot {x}^{4} + \left(0.002777777777777778 \cdot {x}^{4} + 1\right) \cdot \left(x \cdot x\right)\\ \mathbf{else}:\\ \;\;\;\;e^{x} + \left(t_0 + -2\right)\\ \end{array} \]
Alternative 2
Accuracy99.9%
Cost26884
\[\begin{array}{l} t_0 := e^{-x}\\ \mathbf{if}\;\left(e^{x} + -2\right) + t_0 \leq 0.0001:\\ \;\;\;\;0.08333333333333333 \cdot {x}^{4} + \left(0.002777777777777778 \cdot {x}^{6} + x \cdot x\right)\\ \mathbf{else}:\\ \;\;\;\;e^{x} + \left(t_0 + -2\right)\\ \end{array} \]
Alternative 3
Accuracy99.8%
Cost26436
\[\begin{array}{l} t_0 := e^{-x}\\ \mathbf{if}\;\left(e^{x} + -2\right) + t_0 \leq 5 \cdot 10^{-7}:\\ \;\;\;\;0.08333333333333333 \cdot {x}^{4} + x \cdot x\\ \mathbf{else}:\\ \;\;\;\;e^{x} + \left(t_0 + -2\right)\\ \end{array} \]
Alternative 4
Accuracy99.8%
Cost26436
\[\begin{array}{l} t_0 := e^{-x}\\ \mathbf{if}\;\left(e^{x} + -2\right) + t_0 \leq 5 \cdot 10^{-7}:\\ \;\;\;\;\mathsf{fma}\left(x, x, 0.08333333333333333 \cdot {x}^{4}\right)\\ \mathbf{else}:\\ \;\;\;\;e^{x} + \left(t_0 + -2\right)\\ \end{array} \]
Alternative 5
Accuracy98.7%
Cost6912
\[0.08333333333333333 \cdot {x}^{4} + x \cdot x \]
Alternative 6
Accuracy98.1%
Cost192
\[x \cdot x \]
Alternative 7
Accuracy5.9%
Cost128
\[-x \]

Error

Reproduce?

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