Average Error: 29.8 → 0.0
Time: 10.0s
Precision: binary64
Cost: 39940
\[\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.01:\\ \;\;\;\;0.002777777777777778 \cdot {x}^{6} + \left({x}^{2} + \left(0.08333333333333333 \cdot {x}^{4} + 4.96031746031746 \cdot 10^{-5} \cdot {x}^{8}\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.01)
     (+
      (* 0.002777777777777778 (pow x 6.0))
      (+
       (pow x 2.0)
       (+
        (* 0.08333333333333333 (pow x 4.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.01) {
		tmp = (0.002777777777777778 * pow(x, 6.0)) + (pow(x, 2.0) + ((0.08333333333333333 * pow(x, 4.0)) + (4.96031746031746e-5 * pow(x, 8.0))));
	} else {
		tmp = t_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) + (-2.0d0)) + exp(-x)
    if (t_0 <= 0.01d0) then
        tmp = (0.002777777777777778d0 * (x ** 6.0d0)) + ((x ** 2.0d0) + ((0.08333333333333333d0 * (x ** 4.0d0)) + (4.96031746031746d-5 * (x ** 8.0d0))))
    else
        tmp = t_0
    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) + -2.0) + Math.exp(-x);
	double tmp;
	if (t_0 <= 0.01) {
		tmp = (0.002777777777777778 * Math.pow(x, 6.0)) + (Math.pow(x, 2.0) + ((0.08333333333333333 * Math.pow(x, 4.0)) + (4.96031746031746e-5 * Math.pow(x, 8.0))));
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(x):
	return (math.exp(x) - 2.0) + math.exp(-x)
def code(x):
	t_0 = (math.exp(x) + -2.0) + math.exp(-x)
	tmp = 0
	if t_0 <= 0.01:
		tmp = (0.002777777777777778 * math.pow(x, 6.0)) + (math.pow(x, 2.0) + ((0.08333333333333333 * math.pow(x, 4.0)) + (4.96031746031746e-5 * math.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.01)
		tmp = Float64(Float64(0.002777777777777778 * (x ^ 6.0)) + Float64((x ^ 2.0) + Float64(Float64(0.08333333333333333 * (x ^ 4.0)) + Float64(4.96031746031746e-5 * (x ^ 8.0)))));
	else
		tmp = t_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) + -2.0) + exp(-x);
	tmp = 0.0;
	if (t_0 <= 0.01)
		tmp = (0.002777777777777778 * (x ^ 6.0)) + ((x ^ 2.0) + ((0.08333333333333333 * (x ^ 4.0)) + (4.96031746031746e-5 * (x ^ 8.0))));
	else
		tmp = t_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[(N[(N[Exp[x], $MachinePrecision] + -2.0), $MachinePrecision] + N[Exp[(-x)], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 0.01], N[(N[(0.002777777777777778 * N[Power[x, 6.0], $MachinePrecision]), $MachinePrecision] + N[(N[Power[x, 2.0], $MachinePrecision] + N[(N[(0.08333333333333333 * N[Power[x, 4.0], $MachinePrecision]), $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.01:\\
\;\;\;\;0.002777777777777778 \cdot {x}^{6} + \left({x}^{2} + \left(0.08333333333333333 \cdot {x}^{4} + 4.96031746031746 \cdot 10^{-5} \cdot {x}^{8}\right)\right)\\

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


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original29.8
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.0100000000000000002

    1. Initial program 30.2

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

      \[\leadsto \color{blue}{e^{x} + \left(e^{-x} + -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)} \]

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

    1. Initial program 0.4

      \[\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.01:\\ \;\;\;\;0.002777777777777778 \cdot {x}^{6} + \left({x}^{2} + \left(0.08333333333333333 \cdot {x}^{4} + 4.96031746031746 \cdot 10^{-5} \cdot {x}^{8}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(e^{x} + -2\right) + e^{-x}\\ \end{array} \]

Alternatives

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

Error

Reproduce

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