?

Average Accuracy: 53.9% → 99.8%
Time: 9.8s
Precision: binary64
Cost: 26436

?

\[\left(e^{x} - 2\right) + e^{-x} \]
\[\begin{array}{l} t_0 := e^{-x}\\ \mathbf{if}\;\left(e^{x} + -2\right) + t_0 \leq 2 \cdot 10^{-8}:\\ \;\;\;\;x \cdot x + 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) 2e-8)
     (+ (* x x) (* 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) <= 2e-8) {
		tmp = (x * x) + (0.08333333333333333 * pow(x, 4.0));
	} else {
		tmp = exp(x) + (t_0 + -2.0);
	}
	return tmp;
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = (exp(x) - 2.0d0) + exp(-x)
end function
real(8) function code(x)
    real(8), intent (in) :: x
    real(8) :: t_0
    real(8) :: tmp
    t_0 = exp(-x)
    if (((exp(x) + (-2.0d0)) + t_0) <= 2d-8) then
        tmp = (x * x) + (0.08333333333333333d0 * (x ** 4.0d0))
    else
        tmp = exp(x) + (t_0 + (-2.0d0))
    end if
    code = tmp
end function
public static double code(double x) {
	return (Math.exp(x) - 2.0) + Math.exp(-x);
}
public static double code(double x) {
	double t_0 = Math.exp(-x);
	double tmp;
	if (((Math.exp(x) + -2.0) + t_0) <= 2e-8) {
		tmp = (x * x) + (0.08333333333333333 * Math.pow(x, 4.0));
	} else {
		tmp = Math.exp(x) + (t_0 + -2.0);
	}
	return tmp;
}
def code(x):
	return (math.exp(x) - 2.0) + math.exp(-x)
def code(x):
	t_0 = math.exp(-x)
	tmp = 0
	if ((math.exp(x) + -2.0) + t_0) <= 2e-8:
		tmp = (x * x) + (0.08333333333333333 * math.pow(x, 4.0))
	else:
		tmp = math.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) <= 2e-8)
		tmp = Float64(Float64(x * x) + Float64(0.08333333333333333 * (x ^ 4.0)));
	else
		tmp = Float64(exp(x) + Float64(t_0 + -2.0));
	end
	return tmp
end
function tmp = code(x)
	tmp = (exp(x) - 2.0) + exp(-x);
end
function tmp_2 = code(x)
	t_0 = exp(-x);
	tmp = 0.0;
	if (((exp(x) + -2.0) + t_0) <= 2e-8)
		tmp = (x * x) + (0.08333333333333333 * (x ^ 4.0));
	else
		tmp = exp(x) + (t_0 + -2.0);
	end
	tmp_2 = 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], 2e-8], N[(N[(x * x), $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 2 \cdot 10^{-8}:\\
\;\;\;\;x \cdot x + 0.08333333333333333 \cdot {x}^{4}\\

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


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original53.9%
Target99.9%
Herbie99.8%
\[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))) < 2e-8

    1. Initial program 53.2%

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

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

      [Start]53.2

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

      associate-+l- [=>]53.2

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

      sub-neg [=>]53.2

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

      neg-sub0 [=>]53.2

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

      associate--r- [=>]53.2

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

      metadata-eval [=>]53.2

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

      metadata-eval [<=]53.2

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

      +-commutative [=>]53.2

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

      metadata-eval [=>]53.2

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

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

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

      [Start]100.0

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

      unpow2 [=>]100.0

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

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

    1. Initial program 90.0%

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

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

      [Start]90.0

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

      associate-+l- [=>]89.9

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

      sub-neg [=>]89.9

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

      neg-sub0 [=>]89.9

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

      associate--r- [=>]89.9

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

      metadata-eval [=>]89.9

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

      metadata-eval [<=]89.9

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

      +-commutative [=>]89.9

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

      metadata-eval [=>]89.9

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

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

Alternatives

Alternative 1
Accuracy99.1%
Cost39168
\[\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) \]
Alternative 2
Accuracy98.9%
Cost6912
\[x \cdot x + 0.08333333333333333 \cdot {x}^{4} \]
Alternative 3
Accuracy98.4%
Cost192
\[x \cdot x \]
Alternative 4
Accuracy5.9%
Cost128
\[-x \]
Alternative 5
Accuracy5.9%
Cost64
\[x \]

Error

Reproduce?

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