exp2 (problem 3.3.7)

Percentage Accurate: 76.9% → 99.9%
Time: 8.5s
Alternatives: 10
Speedup: 18.6×

Specification

?
\[\begin{array}{l} \\ \left(e^{x} - 2\right) + e^{-x} \end{array} \]
(FPCore (x) :precision binary64 (+ (- (exp x) 2.0) (exp (- x))))
double code(double x) {
	return (exp(x) - 2.0) + exp(-x);
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = (exp(x) - 2.0d0) + exp(-x)
end function
public static double code(double x) {
	return (Math.exp(x) - 2.0) + Math.exp(-x);
}
def code(x):
	return (math.exp(x) - 2.0) + math.exp(-x)
function code(x)
	return Float64(Float64(exp(x) - 2.0) + exp(Float64(-x)))
end
function tmp = code(x)
	tmp = (exp(x) - 2.0) + exp(-x);
end
code[x_] := N[(N[(N[Exp[x], $MachinePrecision] - 2.0), $MachinePrecision] + N[Exp[(-x)], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\left(e^{x} - 2\right) + e^{-x}
\end{array}

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 10 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 76.9% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \left(e^{x} - 2\right) + e^{-x} \end{array} \]
(FPCore (x) :precision binary64 (+ (- (exp x) 2.0) (exp (- x))))
double code(double x) {
	return (exp(x) - 2.0) + exp(-x);
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = (exp(x) - 2.0d0) + exp(-x)
end function
public static double code(double x) {
	return (Math.exp(x) - 2.0) + Math.exp(-x);
}
def code(x):
	return (math.exp(x) - 2.0) + math.exp(-x)
function code(x)
	return Float64(Float64(exp(x) - 2.0) + exp(Float64(-x)))
end
function tmp = code(x)
	tmp = (exp(x) - 2.0) + exp(-x);
end
code[x_] := N[(N[(N[Exp[x], $MachinePrecision] - 2.0), $MachinePrecision] + N[Exp[(-x)], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\left(e^{x} - 2\right) + e^{-x}
\end{array}

Alternative 1: 99.9% accurate, 0.4× speedup?

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

\\
\begin{array}{l}
t_0 := \left(e^{x} - 2\right) + e^{-x}\\
\mathbf{if}\;t_0 \leq 2 \cdot 10^{-6}:\\
\;\;\;\;\mathsf{fma}\left(0.002777777777777778, {x}^{6}, x \cdot x + 0.08333333333333333 \cdot {x}^{4}\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (+.f64 (-.f64 (exp.f64 x) 2) (exp.f64 (neg.f64 x))) < 1.99999999999999991e-6

    1. Initial program 56.3%

      \[\left(e^{x} - 2\right) + e^{-x} \]
    2. 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)} \]
    3. Step-by-step derivation
      1. fma-def100.0%

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

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

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

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

    1. Initial program 100.0%

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

Alternative 2: 99.9% accurate, 0.5× speedup?

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

\\
\begin{array}{l}
t_0 := \left(e^{x} - 2\right) + e^{-x}\\
\mathbf{if}\;t_0 \leq 2 \cdot 10^{-6}:\\
\;\;\;\;x \cdot x + 0.08333333333333333 \cdot {x}^{4}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (+.f64 (-.f64 (exp.f64 x) 2) (exp.f64 (neg.f64 x))) < 1.99999999999999991e-6

    1. Initial program 56.3%

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

      \[\leadsto \color{blue}{{x}^{2} + 0.08333333333333333 \cdot {x}^{4}} \]
    3. Step-by-step derivation
      1. unpow299.9%

        \[\leadsto \color{blue}{x \cdot x} + 0.08333333333333333 \cdot {x}^{4} \]
    4. Simplified99.9%

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

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

    1. Initial program 100.0%

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

Alternative 3: 99.7% accurate, 1.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -2.6:\\ \;\;\;\;\mathsf{expm1}\left(-x\right)\\ \mathbf{elif}\;x \leq 2.6:\\ \;\;\;\;x \cdot x + 0.08333333333333333 \cdot {x}^{4}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{expm1}\left(x\right)\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (if (<= x -2.6)
   (expm1 (- x))
   (if (<= x 2.6) (+ (* x x) (* 0.08333333333333333 (pow x 4.0))) (expm1 x))))
double code(double x) {
	double tmp;
	if (x <= -2.6) {
		tmp = expm1(-x);
	} else if (x <= 2.6) {
		tmp = (x * x) + (0.08333333333333333 * pow(x, 4.0));
	} else {
		tmp = expm1(x);
	}
	return tmp;
}
public static double code(double x) {
	double tmp;
	if (x <= -2.6) {
		tmp = Math.expm1(-x);
	} else if (x <= 2.6) {
		tmp = (x * x) + (0.08333333333333333 * Math.pow(x, 4.0));
	} else {
		tmp = Math.expm1(x);
	}
	return tmp;
}
def code(x):
	tmp = 0
	if x <= -2.6:
		tmp = math.expm1(-x)
	elif x <= 2.6:
		tmp = (x * x) + (0.08333333333333333 * math.pow(x, 4.0))
	else:
		tmp = math.expm1(x)
	return tmp
function code(x)
	tmp = 0.0
	if (x <= -2.6)
		tmp = expm1(Float64(-x));
	elseif (x <= 2.6)
		tmp = Float64(Float64(x * x) + Float64(0.08333333333333333 * (x ^ 4.0)));
	else
		tmp = expm1(x);
	end
	return tmp
end
code[x_] := If[LessEqual[x, -2.6], N[(Exp[(-x)] - 1), $MachinePrecision], If[LessEqual[x, 2.6], N[(N[(x * x), $MachinePrecision] + N[(0.08333333333333333 * N[Power[x, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(Exp[x] - 1), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.6:\\
\;\;\;\;\mathsf{expm1}\left(-x\right)\\

\mathbf{elif}\;x \leq 2.6:\\
\;\;\;\;x \cdot x + 0.08333333333333333 \cdot {x}^{4}\\

\mathbf{else}:\\
\;\;\;\;\mathsf{expm1}\left(x\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < -2.60000000000000009

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{-1} + e^{-x} \]
    3. Taylor expanded in x around inf 100.0%

      \[\leadsto \color{blue}{e^{-x} - 1} \]
    4. Step-by-step derivation
      1. expm1-def100.0%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(-x\right)} \]
    5. Simplified100.0%

      \[\leadsto \color{blue}{\mathsf{expm1}\left(-x\right)} \]

    if -2.60000000000000009 < x < 2.60000000000000009

    1. Initial program 56.6%

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

      \[\leadsto \color{blue}{{x}^{2} + 0.08333333333333333 \cdot {x}^{4}} \]
    3. Step-by-step derivation
      1. unpow299.5%

        \[\leadsto \color{blue}{x \cdot x} + 0.08333333333333333 \cdot {x}^{4} \]
    4. Simplified99.5%

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

    if 2.60000000000000009 < x

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{-1} + e^{-x} \]
    3. Step-by-step derivation
      1. +-commutative0.7%

        \[\leadsto \color{blue}{e^{-x} + -1} \]
      2. add-sqr-sqrt0.7%

        \[\leadsto \color{blue}{\sqrt{e^{-x}} \cdot \sqrt{e^{-x}}} + -1 \]
      3. fma-def0.7%

        \[\leadsto \color{blue}{\mathsf{fma}\left(\sqrt{e^{-x}}, \sqrt{e^{-x}}, -1\right)} \]
      4. metadata-eval0.7%

        \[\leadsto \mathsf{fma}\left(\sqrt{e^{-x}}, \sqrt{e^{-x}}, \color{blue}{-1}\right) \]
      5. fma-neg0.7%

        \[\leadsto \color{blue}{\sqrt{e^{-x}} \cdot \sqrt{e^{-x}} - 1} \]
      6. add-sqr-sqrt0.7%

        \[\leadsto \color{blue}{e^{-x}} - 1 \]
      7. expm1-udef0.7%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(-x\right)} \]
      8. add-sqr-sqrt0.0%

        \[\leadsto \mathsf{expm1}\left(\color{blue}{\sqrt{-x} \cdot \sqrt{-x}}\right) \]
      9. sqrt-unprod100.0%

        \[\leadsto \mathsf{expm1}\left(\color{blue}{\sqrt{\left(-x\right) \cdot \left(-x\right)}}\right) \]
      10. sqr-neg100.0%

        \[\leadsto \mathsf{expm1}\left(\sqrt{\color{blue}{x \cdot x}}\right) \]
      11. sqrt-prod100.0%

        \[\leadsto \mathsf{expm1}\left(\color{blue}{\sqrt{x} \cdot \sqrt{x}}\right) \]
      12. add-sqr-sqrt100.0%

        \[\leadsto \mathsf{expm1}\left(\color{blue}{x}\right) \]
      13. expm1-udef100.0%

        \[\leadsto \color{blue}{e^{x} - 1} \]
    4. Applied egg-rr100.0%

      \[\leadsto \color{blue}{e^{x} - 1} \]
    5. Step-by-step derivation
      1. expm1-def100.0%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(x\right)} \]
    6. Simplified100.0%

      \[\leadsto \color{blue}{\mathsf{expm1}\left(x\right)} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification99.7%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -2.6:\\ \;\;\;\;\mathsf{expm1}\left(-x\right)\\ \mathbf{elif}\;x \leq 2.6:\\ \;\;\;\;x \cdot x + 0.08333333333333333 \cdot {x}^{4}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{expm1}\left(x\right)\\ \end{array} \]

Alternative 4: 93.6% accurate, 2.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -1.5:\\ \;\;\;\;\frac{\left(x \cdot x\right) \cdot \left(0.25 - x \cdot \left(x \cdot 0.027777777777777776\right)\right)}{0.5 + x \cdot 0.16666666666666666} - x\\ \mathbf{elif}\;x \leq 1.6:\\ \;\;\;\;x \cdot x\\ \mathbf{else}:\\ \;\;\;\;\mathsf{expm1}\left(x\right)\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (if (<= x -1.5)
   (-
    (/
     (* (* x x) (- 0.25 (* x (* x 0.027777777777777776))))
     (+ 0.5 (* x 0.16666666666666666)))
    x)
   (if (<= x 1.6) (* x x) (expm1 x))))
double code(double x) {
	double tmp;
	if (x <= -1.5) {
		tmp = (((x * x) * (0.25 - (x * (x * 0.027777777777777776)))) / (0.5 + (x * 0.16666666666666666))) - x;
	} else if (x <= 1.6) {
		tmp = x * x;
	} else {
		tmp = expm1(x);
	}
	return tmp;
}
public static double code(double x) {
	double tmp;
	if (x <= -1.5) {
		tmp = (((x * x) * (0.25 - (x * (x * 0.027777777777777776)))) / (0.5 + (x * 0.16666666666666666))) - x;
	} else if (x <= 1.6) {
		tmp = x * x;
	} else {
		tmp = Math.expm1(x);
	}
	return tmp;
}
def code(x):
	tmp = 0
	if x <= -1.5:
		tmp = (((x * x) * (0.25 - (x * (x * 0.027777777777777776)))) / (0.5 + (x * 0.16666666666666666))) - x
	elif x <= 1.6:
		tmp = x * x
	else:
		tmp = math.expm1(x)
	return tmp
function code(x)
	tmp = 0.0
	if (x <= -1.5)
		tmp = Float64(Float64(Float64(Float64(x * x) * Float64(0.25 - Float64(x * Float64(x * 0.027777777777777776)))) / Float64(0.5 + Float64(x * 0.16666666666666666))) - x);
	elseif (x <= 1.6)
		tmp = Float64(x * x);
	else
		tmp = expm1(x);
	end
	return tmp
end
code[x_] := If[LessEqual[x, -1.5], N[(N[(N[(N[(x * x), $MachinePrecision] * N[(0.25 - N[(x * N[(x * 0.027777777777777776), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(0.5 + N[(x * 0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - x), $MachinePrecision], If[LessEqual[x, 1.6], N[(x * x), $MachinePrecision], N[(Exp[x] - 1), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.5:\\
\;\;\;\;\frac{\left(x \cdot x\right) \cdot \left(0.25 - x \cdot \left(x \cdot 0.027777777777777776\right)\right)}{0.5 + x \cdot 0.16666666666666666} - x\\

\mathbf{elif}\;x \leq 1.6:\\
\;\;\;\;x \cdot x\\

\mathbf{else}:\\
\;\;\;\;\mathsf{expm1}\left(x\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < -1.5

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{-1} + e^{-x} \]
    3. Taylor expanded in x around 0 75.4%

      \[\leadsto \color{blue}{-0.16666666666666666 \cdot {x}^{3} + \left(0.5 \cdot {x}^{2} + -1 \cdot x\right)} \]
    4. Step-by-step derivation
      1. associate-+r+75.4%

        \[\leadsto \color{blue}{\left(-0.16666666666666666 \cdot {x}^{3} + 0.5 \cdot {x}^{2}\right) + -1 \cdot x} \]
      2. neg-mul-175.4%

        \[\leadsto \left(-0.16666666666666666 \cdot {x}^{3} + 0.5 \cdot {x}^{2}\right) + \color{blue}{\left(-x\right)} \]
      3. unsub-neg75.4%

        \[\leadsto \color{blue}{\left(-0.16666666666666666 \cdot {x}^{3} + 0.5 \cdot {x}^{2}\right) - x} \]
      4. +-commutative75.4%

        \[\leadsto \color{blue}{\left(0.5 \cdot {x}^{2} + -0.16666666666666666 \cdot {x}^{3}\right)} - x \]
      5. unpow275.4%

        \[\leadsto \left(0.5 \cdot \color{blue}{\left(x \cdot x\right)} + -0.16666666666666666 \cdot {x}^{3}\right) - x \]
      6. *-commutative75.4%

        \[\leadsto \left(\color{blue}{\left(x \cdot x\right) \cdot 0.5} + -0.16666666666666666 \cdot {x}^{3}\right) - x \]
      7. *-commutative75.4%

        \[\leadsto \left(\left(x \cdot x\right) \cdot 0.5 + \color{blue}{{x}^{3} \cdot -0.16666666666666666}\right) - x \]
      8. unpow375.4%

        \[\leadsto \left(\left(x \cdot x\right) \cdot 0.5 + \color{blue}{\left(\left(x \cdot x\right) \cdot x\right)} \cdot -0.16666666666666666\right) - x \]
      9. associate-*l*75.4%

        \[\leadsto \left(\left(x \cdot x\right) \cdot 0.5 + \color{blue}{\left(x \cdot x\right) \cdot \left(x \cdot -0.16666666666666666\right)}\right) - x \]
      10. distribute-lft-out75.4%

        \[\leadsto \color{blue}{\left(x \cdot x\right) \cdot \left(0.5 + x \cdot -0.16666666666666666\right)} - x \]
    5. Simplified75.4%

      \[\leadsto \color{blue}{\left(x \cdot x\right) \cdot \left(0.5 + x \cdot -0.16666666666666666\right) - x} \]
    6. Step-by-step derivation
      1. *-commutative75.4%

        \[\leadsto \color{blue}{\left(0.5 + x \cdot -0.16666666666666666\right) \cdot \left(x \cdot x\right)} - x \]
      2. flip-+75.4%

        \[\leadsto \color{blue}{\frac{0.5 \cdot 0.5 - \left(x \cdot -0.16666666666666666\right) \cdot \left(x \cdot -0.16666666666666666\right)}{0.5 - x \cdot -0.16666666666666666}} \cdot \left(x \cdot x\right) - x \]
      3. associate-*l/81.0%

        \[\leadsto \color{blue}{\frac{\left(0.5 \cdot 0.5 - \left(x \cdot -0.16666666666666666\right) \cdot \left(x \cdot -0.16666666666666666\right)\right) \cdot \left(x \cdot x\right)}{0.5 - x \cdot -0.16666666666666666}} - x \]
      4. metadata-eval81.0%

        \[\leadsto \frac{\left(\color{blue}{0.25} - \left(x \cdot -0.16666666666666666\right) \cdot \left(x \cdot -0.16666666666666666\right)\right) \cdot \left(x \cdot x\right)}{0.5 - x \cdot -0.16666666666666666} - x \]
      5. swap-sqr81.0%

        \[\leadsto \frac{\left(0.25 - \color{blue}{\left(x \cdot x\right) \cdot \left(-0.16666666666666666 \cdot -0.16666666666666666\right)}\right) \cdot \left(x \cdot x\right)}{0.5 - x \cdot -0.16666666666666666} - x \]
      6. metadata-eval81.0%

        \[\leadsto \frac{\left(0.25 - \left(x \cdot x\right) \cdot \color{blue}{0.027777777777777776}\right) \cdot \left(x \cdot x\right)}{0.5 - x \cdot -0.16666666666666666} - x \]
      7. *-commutative81.0%

        \[\leadsto \frac{\left(0.25 - \left(x \cdot x\right) \cdot 0.027777777777777776\right) \cdot \left(x \cdot x\right)}{0.5 - \color{blue}{-0.16666666666666666 \cdot x}} - x \]
      8. cancel-sign-sub-inv81.0%

        \[\leadsto \frac{\left(0.25 - \left(x \cdot x\right) \cdot 0.027777777777777776\right) \cdot \left(x \cdot x\right)}{\color{blue}{0.5 + \left(--0.16666666666666666\right) \cdot x}} - x \]
      9. metadata-eval81.0%

        \[\leadsto \frac{\left(0.25 - \left(x \cdot x\right) \cdot 0.027777777777777776\right) \cdot \left(x \cdot x\right)}{0.5 + \color{blue}{0.16666666666666666} \cdot x} - x \]
    7. Applied egg-rr81.0%

      \[\leadsto \color{blue}{\frac{\left(0.25 - \left(x \cdot x\right) \cdot 0.027777777777777776\right) \cdot \left(x \cdot x\right)}{0.5 + 0.16666666666666666 \cdot x}} - x \]
    8. Taylor expanded in x around 0 81.0%

      \[\leadsto \frac{\left(0.25 - \color{blue}{0.027777777777777776 \cdot {x}^{2}}\right) \cdot \left(x \cdot x\right)}{0.5 + 0.16666666666666666 \cdot x} - x \]
    9. Step-by-step derivation
      1. unpow281.0%

        \[\leadsto \frac{\left(0.25 - 0.027777777777777776 \cdot \color{blue}{\left(x \cdot x\right)}\right) \cdot \left(x \cdot x\right)}{0.5 + 0.16666666666666666 \cdot x} - x \]
      2. *-commutative81.0%

        \[\leadsto \frac{\left(0.25 - \color{blue}{\left(x \cdot x\right) \cdot 0.027777777777777776}\right) \cdot \left(x \cdot x\right)}{0.5 + 0.16666666666666666 \cdot x} - x \]
      3. associate-*r*81.0%

        \[\leadsto \frac{\left(0.25 - \color{blue}{x \cdot \left(x \cdot 0.027777777777777776\right)}\right) \cdot \left(x \cdot x\right)}{0.5 + 0.16666666666666666 \cdot x} - x \]
    10. Simplified81.0%

      \[\leadsto \frac{\left(0.25 - \color{blue}{x \cdot \left(x \cdot 0.027777777777777776\right)}\right) \cdot \left(x \cdot x\right)}{0.5 + 0.16666666666666666 \cdot x} - x \]

    if -1.5 < x < 1.6000000000000001

    1. Initial program 56.6%

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

      \[\leadsto \color{blue}{{x}^{2}} \]
    3. Step-by-step derivation
      1. unpow299.0%

        \[\leadsto \color{blue}{x \cdot x} \]
    4. Simplified99.0%

      \[\leadsto \color{blue}{x \cdot x} \]

    if 1.6000000000000001 < x

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{-1} + e^{-x} \]
    3. Step-by-step derivation
      1. +-commutative0.7%

        \[\leadsto \color{blue}{e^{-x} + -1} \]
      2. add-sqr-sqrt0.7%

        \[\leadsto \color{blue}{\sqrt{e^{-x}} \cdot \sqrt{e^{-x}}} + -1 \]
      3. fma-def0.7%

        \[\leadsto \color{blue}{\mathsf{fma}\left(\sqrt{e^{-x}}, \sqrt{e^{-x}}, -1\right)} \]
      4. metadata-eval0.7%

        \[\leadsto \mathsf{fma}\left(\sqrt{e^{-x}}, \sqrt{e^{-x}}, \color{blue}{-1}\right) \]
      5. fma-neg0.7%

        \[\leadsto \color{blue}{\sqrt{e^{-x}} \cdot \sqrt{e^{-x}} - 1} \]
      6. add-sqr-sqrt0.7%

        \[\leadsto \color{blue}{e^{-x}} - 1 \]
      7. expm1-udef0.7%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(-x\right)} \]
      8. add-sqr-sqrt0.0%

        \[\leadsto \mathsf{expm1}\left(\color{blue}{\sqrt{-x} \cdot \sqrt{-x}}\right) \]
      9. sqrt-unprod100.0%

        \[\leadsto \mathsf{expm1}\left(\color{blue}{\sqrt{\left(-x\right) \cdot \left(-x\right)}}\right) \]
      10. sqr-neg100.0%

        \[\leadsto \mathsf{expm1}\left(\sqrt{\color{blue}{x \cdot x}}\right) \]
      11. sqrt-prod100.0%

        \[\leadsto \mathsf{expm1}\left(\color{blue}{\sqrt{x} \cdot \sqrt{x}}\right) \]
      12. add-sqr-sqrt100.0%

        \[\leadsto \mathsf{expm1}\left(\color{blue}{x}\right) \]
      13. expm1-udef100.0%

        \[\leadsto \color{blue}{e^{x} - 1} \]
    4. Applied egg-rr100.0%

      \[\leadsto \color{blue}{e^{x} - 1} \]
    5. Step-by-step derivation
      1. expm1-def100.0%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(x\right)} \]
    6. Simplified100.0%

      \[\leadsto \color{blue}{\mathsf{expm1}\left(x\right)} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification94.7%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -1.5:\\ \;\;\;\;\frac{\left(x \cdot x\right) \cdot \left(0.25 - x \cdot \left(x \cdot 0.027777777777777776\right)\right)}{0.5 + x \cdot 0.16666666666666666} - x\\ \mathbf{elif}\;x \leq 1.6:\\ \;\;\;\;x \cdot x\\ \mathbf{else}:\\ \;\;\;\;\mathsf{expm1}\left(x\right)\\ \end{array} \]

Alternative 5: 99.4% accurate, 2.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -1.65:\\ \;\;\;\;\mathsf{expm1}\left(-x\right)\\ \mathbf{elif}\;x \leq 1.6:\\ \;\;\;\;x \cdot x\\ \mathbf{else}:\\ \;\;\;\;\mathsf{expm1}\left(x\right)\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (if (<= x -1.65) (expm1 (- x)) (if (<= x 1.6) (* x x) (expm1 x))))
double code(double x) {
	double tmp;
	if (x <= -1.65) {
		tmp = expm1(-x);
	} else if (x <= 1.6) {
		tmp = x * x;
	} else {
		tmp = expm1(x);
	}
	return tmp;
}
public static double code(double x) {
	double tmp;
	if (x <= -1.65) {
		tmp = Math.expm1(-x);
	} else if (x <= 1.6) {
		tmp = x * x;
	} else {
		tmp = Math.expm1(x);
	}
	return tmp;
}
def code(x):
	tmp = 0
	if x <= -1.65:
		tmp = math.expm1(-x)
	elif x <= 1.6:
		tmp = x * x
	else:
		tmp = math.expm1(x)
	return tmp
function code(x)
	tmp = 0.0
	if (x <= -1.65)
		tmp = expm1(Float64(-x));
	elseif (x <= 1.6)
		tmp = Float64(x * x);
	else
		tmp = expm1(x);
	end
	return tmp
end
code[x_] := If[LessEqual[x, -1.65], N[(Exp[(-x)] - 1), $MachinePrecision], If[LessEqual[x, 1.6], N[(x * x), $MachinePrecision], N[(Exp[x] - 1), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.65:\\
\;\;\;\;\mathsf{expm1}\left(-x\right)\\

\mathbf{elif}\;x \leq 1.6:\\
\;\;\;\;x \cdot x\\

\mathbf{else}:\\
\;\;\;\;\mathsf{expm1}\left(x\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < -1.6499999999999999

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{-1} + e^{-x} \]
    3. Taylor expanded in x around inf 100.0%

      \[\leadsto \color{blue}{e^{-x} - 1} \]
    4. Step-by-step derivation
      1. expm1-def100.0%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(-x\right)} \]
    5. Simplified100.0%

      \[\leadsto \color{blue}{\mathsf{expm1}\left(-x\right)} \]

    if -1.6499999999999999 < x < 1.6000000000000001

    1. Initial program 56.6%

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

      \[\leadsto \color{blue}{{x}^{2}} \]
    3. Step-by-step derivation
      1. unpow299.0%

        \[\leadsto \color{blue}{x \cdot x} \]
    4. Simplified99.0%

      \[\leadsto \color{blue}{x \cdot x} \]

    if 1.6000000000000001 < x

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{-1} + e^{-x} \]
    3. Step-by-step derivation
      1. +-commutative0.7%

        \[\leadsto \color{blue}{e^{-x} + -1} \]
      2. add-sqr-sqrt0.7%

        \[\leadsto \color{blue}{\sqrt{e^{-x}} \cdot \sqrt{e^{-x}}} + -1 \]
      3. fma-def0.7%

        \[\leadsto \color{blue}{\mathsf{fma}\left(\sqrt{e^{-x}}, \sqrt{e^{-x}}, -1\right)} \]
      4. metadata-eval0.7%

        \[\leadsto \mathsf{fma}\left(\sqrt{e^{-x}}, \sqrt{e^{-x}}, \color{blue}{-1}\right) \]
      5. fma-neg0.7%

        \[\leadsto \color{blue}{\sqrt{e^{-x}} \cdot \sqrt{e^{-x}} - 1} \]
      6. add-sqr-sqrt0.7%

        \[\leadsto \color{blue}{e^{-x}} - 1 \]
      7. expm1-udef0.7%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(-x\right)} \]
      8. add-sqr-sqrt0.0%

        \[\leadsto \mathsf{expm1}\left(\color{blue}{\sqrt{-x} \cdot \sqrt{-x}}\right) \]
      9. sqrt-unprod100.0%

        \[\leadsto \mathsf{expm1}\left(\color{blue}{\sqrt{\left(-x\right) \cdot \left(-x\right)}}\right) \]
      10. sqr-neg100.0%

        \[\leadsto \mathsf{expm1}\left(\sqrt{\color{blue}{x \cdot x}}\right) \]
      11. sqrt-prod100.0%

        \[\leadsto \mathsf{expm1}\left(\color{blue}{\sqrt{x} \cdot \sqrt{x}}\right) \]
      12. add-sqr-sqrt100.0%

        \[\leadsto \mathsf{expm1}\left(\color{blue}{x}\right) \]
      13. expm1-udef100.0%

        \[\leadsto \color{blue}{e^{x} - 1} \]
    4. Applied egg-rr100.0%

      \[\leadsto \color{blue}{e^{x} - 1} \]
    5. Step-by-step derivation
      1. expm1-def100.0%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(x\right)} \]
    6. Simplified100.0%

      \[\leadsto \color{blue}{\mathsf{expm1}\left(x\right)} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification99.5%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -1.65:\\ \;\;\;\;\mathsf{expm1}\left(-x\right)\\ \mathbf{elif}\;x \leq 1.6:\\ \;\;\;\;x \cdot x\\ \mathbf{else}:\\ \;\;\;\;\mathsf{expm1}\left(x\right)\\ \end{array} \]

Alternative 6: 86.8% accurate, 8.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -4.7:\\ \;\;\;\;\frac{x \cdot x}{\frac{-6}{x}} - x\\ \mathbf{elif}\;x \leq 5.6:\\ \;\;\;\;x \cdot x\\ \mathbf{else}:\\ \;\;\;\;\left(x \cdot x\right) \cdot \left(\left(0.25 - \left(x \cdot x\right) \cdot 0.027777777777777776\right) \cdot \left(2 + x \cdot -0.6666666666666666\right)\right) - x\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (if (<= x -4.7)
   (- (/ (* x x) (/ -6.0 x)) x)
   (if (<= x 5.6)
     (* x x)
     (-
      (*
       (* x x)
       (*
        (- 0.25 (* (* x x) 0.027777777777777776))
        (+ 2.0 (* x -0.6666666666666666))))
      x))))
double code(double x) {
	double tmp;
	if (x <= -4.7) {
		tmp = ((x * x) / (-6.0 / x)) - x;
	} else if (x <= 5.6) {
		tmp = x * x;
	} else {
		tmp = ((x * x) * ((0.25 - ((x * x) * 0.027777777777777776)) * (2.0 + (x * -0.6666666666666666)))) - x;
	}
	return tmp;
}
real(8) function code(x)
    real(8), intent (in) :: x
    real(8) :: tmp
    if (x <= (-4.7d0)) then
        tmp = ((x * x) / ((-6.0d0) / x)) - x
    else if (x <= 5.6d0) then
        tmp = x * x
    else
        tmp = ((x * x) * ((0.25d0 - ((x * x) * 0.027777777777777776d0)) * (2.0d0 + (x * (-0.6666666666666666d0))))) - x
    end if
    code = tmp
end function
public static double code(double x) {
	double tmp;
	if (x <= -4.7) {
		tmp = ((x * x) / (-6.0 / x)) - x;
	} else if (x <= 5.6) {
		tmp = x * x;
	} else {
		tmp = ((x * x) * ((0.25 - ((x * x) * 0.027777777777777776)) * (2.0 + (x * -0.6666666666666666)))) - x;
	}
	return tmp;
}
def code(x):
	tmp = 0
	if x <= -4.7:
		tmp = ((x * x) / (-6.0 / x)) - x
	elif x <= 5.6:
		tmp = x * x
	else:
		tmp = ((x * x) * ((0.25 - ((x * x) * 0.027777777777777776)) * (2.0 + (x * -0.6666666666666666)))) - x
	return tmp
function code(x)
	tmp = 0.0
	if (x <= -4.7)
		tmp = Float64(Float64(Float64(x * x) / Float64(-6.0 / x)) - x);
	elseif (x <= 5.6)
		tmp = Float64(x * x);
	else
		tmp = Float64(Float64(Float64(x * x) * Float64(Float64(0.25 - Float64(Float64(x * x) * 0.027777777777777776)) * Float64(2.0 + Float64(x * -0.6666666666666666)))) - x);
	end
	return tmp
end
function tmp_2 = code(x)
	tmp = 0.0;
	if (x <= -4.7)
		tmp = ((x * x) / (-6.0 / x)) - x;
	elseif (x <= 5.6)
		tmp = x * x;
	else
		tmp = ((x * x) * ((0.25 - ((x * x) * 0.027777777777777776)) * (2.0 + (x * -0.6666666666666666)))) - x;
	end
	tmp_2 = tmp;
end
code[x_] := If[LessEqual[x, -4.7], N[(N[(N[(x * x), $MachinePrecision] / N[(-6.0 / x), $MachinePrecision]), $MachinePrecision] - x), $MachinePrecision], If[LessEqual[x, 5.6], N[(x * x), $MachinePrecision], N[(N[(N[(x * x), $MachinePrecision] * N[(N[(0.25 - N[(N[(x * x), $MachinePrecision] * 0.027777777777777776), $MachinePrecision]), $MachinePrecision] * N[(2.0 + N[(x * -0.6666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - x), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.7:\\
\;\;\;\;\frac{x \cdot x}{\frac{-6}{x}} - x\\

\mathbf{elif}\;x \leq 5.6:\\
\;\;\;\;x \cdot x\\

\mathbf{else}:\\
\;\;\;\;\left(x \cdot x\right) \cdot \left(\left(0.25 - \left(x \cdot x\right) \cdot 0.027777777777777776\right) \cdot \left(2 + x \cdot -0.6666666666666666\right)\right) - x\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < -4.70000000000000018

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{-1} + e^{-x} \]
    3. Taylor expanded in x around 0 75.4%

      \[\leadsto \color{blue}{-0.16666666666666666 \cdot {x}^{3} + \left(0.5 \cdot {x}^{2} + -1 \cdot x\right)} \]
    4. Step-by-step derivation
      1. associate-+r+75.4%

        \[\leadsto \color{blue}{\left(-0.16666666666666666 \cdot {x}^{3} + 0.5 \cdot {x}^{2}\right) + -1 \cdot x} \]
      2. neg-mul-175.4%

        \[\leadsto \left(-0.16666666666666666 \cdot {x}^{3} + 0.5 \cdot {x}^{2}\right) + \color{blue}{\left(-x\right)} \]
      3. unsub-neg75.4%

        \[\leadsto \color{blue}{\left(-0.16666666666666666 \cdot {x}^{3} + 0.5 \cdot {x}^{2}\right) - x} \]
      4. +-commutative75.4%

        \[\leadsto \color{blue}{\left(0.5 \cdot {x}^{2} + -0.16666666666666666 \cdot {x}^{3}\right)} - x \]
      5. unpow275.4%

        \[\leadsto \left(0.5 \cdot \color{blue}{\left(x \cdot x\right)} + -0.16666666666666666 \cdot {x}^{3}\right) - x \]
      6. *-commutative75.4%

        \[\leadsto \left(\color{blue}{\left(x \cdot x\right) \cdot 0.5} + -0.16666666666666666 \cdot {x}^{3}\right) - x \]
      7. *-commutative75.4%

        \[\leadsto \left(\left(x \cdot x\right) \cdot 0.5 + \color{blue}{{x}^{3} \cdot -0.16666666666666666}\right) - x \]
      8. unpow375.4%

        \[\leadsto \left(\left(x \cdot x\right) \cdot 0.5 + \color{blue}{\left(\left(x \cdot x\right) \cdot x\right)} \cdot -0.16666666666666666\right) - x \]
      9. associate-*l*75.4%

        \[\leadsto \left(\left(x \cdot x\right) \cdot 0.5 + \color{blue}{\left(x \cdot x\right) \cdot \left(x \cdot -0.16666666666666666\right)}\right) - x \]
      10. distribute-lft-out75.4%

        \[\leadsto \color{blue}{\left(x \cdot x\right) \cdot \left(0.5 + x \cdot -0.16666666666666666\right)} - x \]
    5. Simplified75.4%

      \[\leadsto \color{blue}{\left(x \cdot x\right) \cdot \left(0.5 + x \cdot -0.16666666666666666\right) - x} \]
    6. Step-by-step derivation
      1. flip-+75.4%

        \[\leadsto \left(x \cdot x\right) \cdot \color{blue}{\frac{0.5 \cdot 0.5 - \left(x \cdot -0.16666666666666666\right) \cdot \left(x \cdot -0.16666666666666666\right)}{0.5 - x \cdot -0.16666666666666666}} - x \]
      2. associate-*r/81.0%

        \[\leadsto \color{blue}{\frac{\left(x \cdot x\right) \cdot \left(0.5 \cdot 0.5 - \left(x \cdot -0.16666666666666666\right) \cdot \left(x \cdot -0.16666666666666666\right)\right)}{0.5 - x \cdot -0.16666666666666666}} - x \]
      3. metadata-eval81.0%

        \[\leadsto \frac{\left(x \cdot x\right) \cdot \left(\color{blue}{0.25} - \left(x \cdot -0.16666666666666666\right) \cdot \left(x \cdot -0.16666666666666666\right)\right)}{0.5 - x \cdot -0.16666666666666666} - x \]
      4. swap-sqr81.0%

        \[\leadsto \frac{\left(x \cdot x\right) \cdot \left(0.25 - \color{blue}{\left(x \cdot x\right) \cdot \left(-0.16666666666666666 \cdot -0.16666666666666666\right)}\right)}{0.5 - x \cdot -0.16666666666666666} - x \]
      5. metadata-eval81.0%

        \[\leadsto \frac{\left(x \cdot x\right) \cdot \left(0.25 - \left(x \cdot x\right) \cdot \color{blue}{0.027777777777777776}\right)}{0.5 - x \cdot -0.16666666666666666} - x \]
      6. *-commutative81.0%

        \[\leadsto \frac{\left(x \cdot x\right) \cdot \left(0.25 - \left(x \cdot x\right) \cdot 0.027777777777777776\right)}{0.5 - \color{blue}{-0.16666666666666666 \cdot x}} - x \]
      7. cancel-sign-sub-inv81.0%

        \[\leadsto \frac{\left(x \cdot x\right) \cdot \left(0.25 - \left(x \cdot x\right) \cdot 0.027777777777777776\right)}{\color{blue}{0.5 + \left(--0.16666666666666666\right) \cdot x}} - x \]
      8. metadata-eval81.0%

        \[\leadsto \frac{\left(x \cdot x\right) \cdot \left(0.25 - \left(x \cdot x\right) \cdot 0.027777777777777776\right)}{0.5 + \color{blue}{0.16666666666666666} \cdot x} - x \]
    7. Applied egg-rr81.0%

      \[\leadsto \color{blue}{\frac{\left(x \cdot x\right) \cdot \left(0.25 - \left(x \cdot x\right) \cdot 0.027777777777777776\right)}{0.5 + 0.16666666666666666 \cdot x}} - x \]
    8. Step-by-step derivation
      1. associate-/l*75.4%

        \[\leadsto \color{blue}{\frac{x \cdot x}{\frac{0.5 + 0.16666666666666666 \cdot x}{0.25 - \left(x \cdot x\right) \cdot 0.027777777777777776}}} - x \]
      2. *-commutative75.4%

        \[\leadsto \frac{x \cdot x}{\frac{0.5 + \color{blue}{x \cdot 0.16666666666666666}}{0.25 - \left(x \cdot x\right) \cdot 0.027777777777777776}} - x \]
    9. Simplified75.4%

      \[\leadsto \color{blue}{\frac{x \cdot x}{\frac{0.5 + x \cdot 0.16666666666666666}{0.25 - \left(x \cdot x\right) \cdot 0.027777777777777776}}} - x \]
    10. Taylor expanded in x around inf 75.4%

      \[\leadsto \frac{x \cdot x}{\color{blue}{\frac{-6}{x}}} - x \]

    if -4.70000000000000018 < x < 5.5999999999999996

    1. Initial program 56.6%

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

      \[\leadsto \color{blue}{{x}^{2}} \]
    3. Step-by-step derivation
      1. unpow299.0%

        \[\leadsto \color{blue}{x \cdot x} \]
    4. Simplified99.0%

      \[\leadsto \color{blue}{x \cdot x} \]

    if 5.5999999999999996 < x

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{-1} + e^{-x} \]
    3. Taylor expanded in x around 0 0.2%

      \[\leadsto \color{blue}{-0.16666666666666666 \cdot {x}^{3} + \left(0.5 \cdot {x}^{2} + -1 \cdot x\right)} \]
    4. Step-by-step derivation
      1. associate-+r+0.2%

        \[\leadsto \color{blue}{\left(-0.16666666666666666 \cdot {x}^{3} + 0.5 \cdot {x}^{2}\right) + -1 \cdot x} \]
      2. neg-mul-10.2%

        \[\leadsto \left(-0.16666666666666666 \cdot {x}^{3} + 0.5 \cdot {x}^{2}\right) + \color{blue}{\left(-x\right)} \]
      3. unsub-neg0.2%

        \[\leadsto \color{blue}{\left(-0.16666666666666666 \cdot {x}^{3} + 0.5 \cdot {x}^{2}\right) - x} \]
      4. +-commutative0.2%

        \[\leadsto \color{blue}{\left(0.5 \cdot {x}^{2} + -0.16666666666666666 \cdot {x}^{3}\right)} - x \]
      5. unpow20.2%

        \[\leadsto \left(0.5 \cdot \color{blue}{\left(x \cdot x\right)} + -0.16666666666666666 \cdot {x}^{3}\right) - x \]
      6. *-commutative0.2%

        \[\leadsto \left(\color{blue}{\left(x \cdot x\right) \cdot 0.5} + -0.16666666666666666 \cdot {x}^{3}\right) - x \]
      7. *-commutative0.2%

        \[\leadsto \left(\left(x \cdot x\right) \cdot 0.5 + \color{blue}{{x}^{3} \cdot -0.16666666666666666}\right) - x \]
      8. unpow30.2%

        \[\leadsto \left(\left(x \cdot x\right) \cdot 0.5 + \color{blue}{\left(\left(x \cdot x\right) \cdot x\right)} \cdot -0.16666666666666666\right) - x \]
      9. associate-*l*0.2%

        \[\leadsto \left(\left(x \cdot x\right) \cdot 0.5 + \color{blue}{\left(x \cdot x\right) \cdot \left(x \cdot -0.16666666666666666\right)}\right) - x \]
      10. distribute-lft-out0.2%

        \[\leadsto \color{blue}{\left(x \cdot x\right) \cdot \left(0.5 + x \cdot -0.16666666666666666\right)} - x \]
    5. Simplified0.2%

      \[\leadsto \color{blue}{\left(x \cdot x\right) \cdot \left(0.5 + x \cdot -0.16666666666666666\right) - x} \]
    6. Step-by-step derivation
      1. flip-+0.2%

        \[\leadsto \left(x \cdot x\right) \cdot \color{blue}{\frac{0.5 \cdot 0.5 - \left(x \cdot -0.16666666666666666\right) \cdot \left(x \cdot -0.16666666666666666\right)}{0.5 - x \cdot -0.16666666666666666}} - x \]
      2. div-inv0.2%

        \[\leadsto \left(x \cdot x\right) \cdot \color{blue}{\left(\left(0.5 \cdot 0.5 - \left(x \cdot -0.16666666666666666\right) \cdot \left(x \cdot -0.16666666666666666\right)\right) \cdot \frac{1}{0.5 - x \cdot -0.16666666666666666}\right)} - x \]
      3. metadata-eval0.2%

        \[\leadsto \left(x \cdot x\right) \cdot \left(\left(\color{blue}{0.25} - \left(x \cdot -0.16666666666666666\right) \cdot \left(x \cdot -0.16666666666666666\right)\right) \cdot \frac{1}{0.5 - x \cdot -0.16666666666666666}\right) - x \]
      4. swap-sqr0.2%

        \[\leadsto \left(x \cdot x\right) \cdot \left(\left(0.25 - \color{blue}{\left(x \cdot x\right) \cdot \left(-0.16666666666666666 \cdot -0.16666666666666666\right)}\right) \cdot \frac{1}{0.5 - x \cdot -0.16666666666666666}\right) - x \]
      5. metadata-eval0.2%

        \[\leadsto \left(x \cdot x\right) \cdot \left(\left(0.25 - \left(x \cdot x\right) \cdot \color{blue}{0.027777777777777776}\right) \cdot \frac{1}{0.5 - x \cdot -0.16666666666666666}\right) - x \]
      6. *-commutative0.2%

        \[\leadsto \left(x \cdot x\right) \cdot \left(\left(0.25 - \left(x \cdot x\right) \cdot 0.027777777777777776\right) \cdot \frac{1}{0.5 - \color{blue}{-0.16666666666666666 \cdot x}}\right) - x \]
      7. cancel-sign-sub-inv0.2%

        \[\leadsto \left(x \cdot x\right) \cdot \left(\left(0.25 - \left(x \cdot x\right) \cdot 0.027777777777777776\right) \cdot \frac{1}{\color{blue}{0.5 + \left(--0.16666666666666666\right) \cdot x}}\right) - x \]
      8. metadata-eval0.2%

        \[\leadsto \left(x \cdot x\right) \cdot \left(\left(0.25 - \left(x \cdot x\right) \cdot 0.027777777777777776\right) \cdot \frac{1}{0.5 + \color{blue}{0.16666666666666666} \cdot x}\right) - x \]
    7. Applied egg-rr0.2%

      \[\leadsto \left(x \cdot x\right) \cdot \color{blue}{\left(\left(0.25 - \left(x \cdot x\right) \cdot 0.027777777777777776\right) \cdot \frac{1}{0.5 + 0.16666666666666666 \cdot x}\right)} - x \]
    8. Taylor expanded in x around 0 75.2%

      \[\leadsto \left(x \cdot x\right) \cdot \left(\left(0.25 - \left(x \cdot x\right) \cdot 0.027777777777777776\right) \cdot \color{blue}{\left(2 + -0.6666666666666666 \cdot x\right)}\right) - x \]
    9. Step-by-step derivation
      1. *-commutative75.2%

        \[\leadsto \left(x \cdot x\right) \cdot \left(\left(0.25 - \left(x \cdot x\right) \cdot 0.027777777777777776\right) \cdot \left(2 + \color{blue}{x \cdot -0.6666666666666666}\right)\right) - x \]
    10. Simplified75.2%

      \[\leadsto \left(x \cdot x\right) \cdot \left(\left(0.25 - \left(x \cdot x\right) \cdot 0.027777777777777776\right) \cdot \color{blue}{\left(2 + x \cdot -0.6666666666666666\right)}\right) - x \]
  3. Recombined 3 regimes into one program.
  4. Final simplification86.6%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -4.7:\\ \;\;\;\;\frac{x \cdot x}{\frac{-6}{x}} - x\\ \mathbf{elif}\;x \leq 5.6:\\ \;\;\;\;x \cdot x\\ \mathbf{else}:\\ \;\;\;\;\left(x \cdot x\right) \cdot \left(\left(0.25 - \left(x \cdot x\right) \cdot 0.027777777777777776\right) \cdot \left(2 + x \cdot -0.6666666666666666\right)\right) - x\\ \end{array} \]

Alternative 7: 88.8% accurate, 8.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -1.5:\\ \;\;\;\;\frac{\left(x \cdot x\right) \cdot \left(0.25 - x \cdot \left(x \cdot 0.027777777777777776\right)\right)}{0.5 + x \cdot 0.16666666666666666} - x\\ \mathbf{elif}\;x \leq 5.6:\\ \;\;\;\;x \cdot x\\ \mathbf{else}:\\ \;\;\;\;\left(x \cdot x\right) \cdot \left(\left(0.25 - \left(x \cdot x\right) \cdot 0.027777777777777776\right) \cdot \left(2 + x \cdot -0.6666666666666666\right)\right) - x\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (if (<= x -1.5)
   (-
    (/
     (* (* x x) (- 0.25 (* x (* x 0.027777777777777776))))
     (+ 0.5 (* x 0.16666666666666666)))
    x)
   (if (<= x 5.6)
     (* x x)
     (-
      (*
       (* x x)
       (*
        (- 0.25 (* (* x x) 0.027777777777777776))
        (+ 2.0 (* x -0.6666666666666666))))
      x))))
double code(double x) {
	double tmp;
	if (x <= -1.5) {
		tmp = (((x * x) * (0.25 - (x * (x * 0.027777777777777776)))) / (0.5 + (x * 0.16666666666666666))) - x;
	} else if (x <= 5.6) {
		tmp = x * x;
	} else {
		tmp = ((x * x) * ((0.25 - ((x * x) * 0.027777777777777776)) * (2.0 + (x * -0.6666666666666666)))) - x;
	}
	return tmp;
}
real(8) function code(x)
    real(8), intent (in) :: x
    real(8) :: tmp
    if (x <= (-1.5d0)) then
        tmp = (((x * x) * (0.25d0 - (x * (x * 0.027777777777777776d0)))) / (0.5d0 + (x * 0.16666666666666666d0))) - x
    else if (x <= 5.6d0) then
        tmp = x * x
    else
        tmp = ((x * x) * ((0.25d0 - ((x * x) * 0.027777777777777776d0)) * (2.0d0 + (x * (-0.6666666666666666d0))))) - x
    end if
    code = tmp
end function
public static double code(double x) {
	double tmp;
	if (x <= -1.5) {
		tmp = (((x * x) * (0.25 - (x * (x * 0.027777777777777776)))) / (0.5 + (x * 0.16666666666666666))) - x;
	} else if (x <= 5.6) {
		tmp = x * x;
	} else {
		tmp = ((x * x) * ((0.25 - ((x * x) * 0.027777777777777776)) * (2.0 + (x * -0.6666666666666666)))) - x;
	}
	return tmp;
}
def code(x):
	tmp = 0
	if x <= -1.5:
		tmp = (((x * x) * (0.25 - (x * (x * 0.027777777777777776)))) / (0.5 + (x * 0.16666666666666666))) - x
	elif x <= 5.6:
		tmp = x * x
	else:
		tmp = ((x * x) * ((0.25 - ((x * x) * 0.027777777777777776)) * (2.0 + (x * -0.6666666666666666)))) - x
	return tmp
function code(x)
	tmp = 0.0
	if (x <= -1.5)
		tmp = Float64(Float64(Float64(Float64(x * x) * Float64(0.25 - Float64(x * Float64(x * 0.027777777777777776)))) / Float64(0.5 + Float64(x * 0.16666666666666666))) - x);
	elseif (x <= 5.6)
		tmp = Float64(x * x);
	else
		tmp = Float64(Float64(Float64(x * x) * Float64(Float64(0.25 - Float64(Float64(x * x) * 0.027777777777777776)) * Float64(2.0 + Float64(x * -0.6666666666666666)))) - x);
	end
	return tmp
end
function tmp_2 = code(x)
	tmp = 0.0;
	if (x <= -1.5)
		tmp = (((x * x) * (0.25 - (x * (x * 0.027777777777777776)))) / (0.5 + (x * 0.16666666666666666))) - x;
	elseif (x <= 5.6)
		tmp = x * x;
	else
		tmp = ((x * x) * ((0.25 - ((x * x) * 0.027777777777777776)) * (2.0 + (x * -0.6666666666666666)))) - x;
	end
	tmp_2 = tmp;
end
code[x_] := If[LessEqual[x, -1.5], N[(N[(N[(N[(x * x), $MachinePrecision] * N[(0.25 - N[(x * N[(x * 0.027777777777777776), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(0.5 + N[(x * 0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - x), $MachinePrecision], If[LessEqual[x, 5.6], N[(x * x), $MachinePrecision], N[(N[(N[(x * x), $MachinePrecision] * N[(N[(0.25 - N[(N[(x * x), $MachinePrecision] * 0.027777777777777776), $MachinePrecision]), $MachinePrecision] * N[(2.0 + N[(x * -0.6666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - x), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.5:\\
\;\;\;\;\frac{\left(x \cdot x\right) \cdot \left(0.25 - x \cdot \left(x \cdot 0.027777777777777776\right)\right)}{0.5 + x \cdot 0.16666666666666666} - x\\

\mathbf{elif}\;x \leq 5.6:\\
\;\;\;\;x \cdot x\\

\mathbf{else}:\\
\;\;\;\;\left(x \cdot x\right) \cdot \left(\left(0.25 - \left(x \cdot x\right) \cdot 0.027777777777777776\right) \cdot \left(2 + x \cdot -0.6666666666666666\right)\right) - x\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < -1.5

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{-1} + e^{-x} \]
    3. Taylor expanded in x around 0 75.4%

      \[\leadsto \color{blue}{-0.16666666666666666 \cdot {x}^{3} + \left(0.5 \cdot {x}^{2} + -1 \cdot x\right)} \]
    4. Step-by-step derivation
      1. associate-+r+75.4%

        \[\leadsto \color{blue}{\left(-0.16666666666666666 \cdot {x}^{3} + 0.5 \cdot {x}^{2}\right) + -1 \cdot x} \]
      2. neg-mul-175.4%

        \[\leadsto \left(-0.16666666666666666 \cdot {x}^{3} + 0.5 \cdot {x}^{2}\right) + \color{blue}{\left(-x\right)} \]
      3. unsub-neg75.4%

        \[\leadsto \color{blue}{\left(-0.16666666666666666 \cdot {x}^{3} + 0.5 \cdot {x}^{2}\right) - x} \]
      4. +-commutative75.4%

        \[\leadsto \color{blue}{\left(0.5 \cdot {x}^{2} + -0.16666666666666666 \cdot {x}^{3}\right)} - x \]
      5. unpow275.4%

        \[\leadsto \left(0.5 \cdot \color{blue}{\left(x \cdot x\right)} + -0.16666666666666666 \cdot {x}^{3}\right) - x \]
      6. *-commutative75.4%

        \[\leadsto \left(\color{blue}{\left(x \cdot x\right) \cdot 0.5} + -0.16666666666666666 \cdot {x}^{3}\right) - x \]
      7. *-commutative75.4%

        \[\leadsto \left(\left(x \cdot x\right) \cdot 0.5 + \color{blue}{{x}^{3} \cdot -0.16666666666666666}\right) - x \]
      8. unpow375.4%

        \[\leadsto \left(\left(x \cdot x\right) \cdot 0.5 + \color{blue}{\left(\left(x \cdot x\right) \cdot x\right)} \cdot -0.16666666666666666\right) - x \]
      9. associate-*l*75.4%

        \[\leadsto \left(\left(x \cdot x\right) \cdot 0.5 + \color{blue}{\left(x \cdot x\right) \cdot \left(x \cdot -0.16666666666666666\right)}\right) - x \]
      10. distribute-lft-out75.4%

        \[\leadsto \color{blue}{\left(x \cdot x\right) \cdot \left(0.5 + x \cdot -0.16666666666666666\right)} - x \]
    5. Simplified75.4%

      \[\leadsto \color{blue}{\left(x \cdot x\right) \cdot \left(0.5 + x \cdot -0.16666666666666666\right) - x} \]
    6. Step-by-step derivation
      1. *-commutative75.4%

        \[\leadsto \color{blue}{\left(0.5 + x \cdot -0.16666666666666666\right) \cdot \left(x \cdot x\right)} - x \]
      2. flip-+75.4%

        \[\leadsto \color{blue}{\frac{0.5 \cdot 0.5 - \left(x \cdot -0.16666666666666666\right) \cdot \left(x \cdot -0.16666666666666666\right)}{0.5 - x \cdot -0.16666666666666666}} \cdot \left(x \cdot x\right) - x \]
      3. associate-*l/81.0%

        \[\leadsto \color{blue}{\frac{\left(0.5 \cdot 0.5 - \left(x \cdot -0.16666666666666666\right) \cdot \left(x \cdot -0.16666666666666666\right)\right) \cdot \left(x \cdot x\right)}{0.5 - x \cdot -0.16666666666666666}} - x \]
      4. metadata-eval81.0%

        \[\leadsto \frac{\left(\color{blue}{0.25} - \left(x \cdot -0.16666666666666666\right) \cdot \left(x \cdot -0.16666666666666666\right)\right) \cdot \left(x \cdot x\right)}{0.5 - x \cdot -0.16666666666666666} - x \]
      5. swap-sqr81.0%

        \[\leadsto \frac{\left(0.25 - \color{blue}{\left(x \cdot x\right) \cdot \left(-0.16666666666666666 \cdot -0.16666666666666666\right)}\right) \cdot \left(x \cdot x\right)}{0.5 - x \cdot -0.16666666666666666} - x \]
      6. metadata-eval81.0%

        \[\leadsto \frac{\left(0.25 - \left(x \cdot x\right) \cdot \color{blue}{0.027777777777777776}\right) \cdot \left(x \cdot x\right)}{0.5 - x \cdot -0.16666666666666666} - x \]
      7. *-commutative81.0%

        \[\leadsto \frac{\left(0.25 - \left(x \cdot x\right) \cdot 0.027777777777777776\right) \cdot \left(x \cdot x\right)}{0.5 - \color{blue}{-0.16666666666666666 \cdot x}} - x \]
      8. cancel-sign-sub-inv81.0%

        \[\leadsto \frac{\left(0.25 - \left(x \cdot x\right) \cdot 0.027777777777777776\right) \cdot \left(x \cdot x\right)}{\color{blue}{0.5 + \left(--0.16666666666666666\right) \cdot x}} - x \]
      9. metadata-eval81.0%

        \[\leadsto \frac{\left(0.25 - \left(x \cdot x\right) \cdot 0.027777777777777776\right) \cdot \left(x \cdot x\right)}{0.5 + \color{blue}{0.16666666666666666} \cdot x} - x \]
    7. Applied egg-rr81.0%

      \[\leadsto \color{blue}{\frac{\left(0.25 - \left(x \cdot x\right) \cdot 0.027777777777777776\right) \cdot \left(x \cdot x\right)}{0.5 + 0.16666666666666666 \cdot x}} - x \]
    8. Taylor expanded in x around 0 81.0%

      \[\leadsto \frac{\left(0.25 - \color{blue}{0.027777777777777776 \cdot {x}^{2}}\right) \cdot \left(x \cdot x\right)}{0.5 + 0.16666666666666666 \cdot x} - x \]
    9. Step-by-step derivation
      1. unpow281.0%

        \[\leadsto \frac{\left(0.25 - 0.027777777777777776 \cdot \color{blue}{\left(x \cdot x\right)}\right) \cdot \left(x \cdot x\right)}{0.5 + 0.16666666666666666 \cdot x} - x \]
      2. *-commutative81.0%

        \[\leadsto \frac{\left(0.25 - \color{blue}{\left(x \cdot x\right) \cdot 0.027777777777777776}\right) \cdot \left(x \cdot x\right)}{0.5 + 0.16666666666666666 \cdot x} - x \]
      3. associate-*r*81.0%

        \[\leadsto \frac{\left(0.25 - \color{blue}{x \cdot \left(x \cdot 0.027777777777777776\right)}\right) \cdot \left(x \cdot x\right)}{0.5 + 0.16666666666666666 \cdot x} - x \]
    10. Simplified81.0%

      \[\leadsto \frac{\left(0.25 - \color{blue}{x \cdot \left(x \cdot 0.027777777777777776\right)}\right) \cdot \left(x \cdot x\right)}{0.5 + 0.16666666666666666 \cdot x} - x \]

    if -1.5 < x < 5.5999999999999996

    1. Initial program 56.6%

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

      \[\leadsto \color{blue}{{x}^{2}} \]
    3. Step-by-step derivation
      1. unpow299.0%

        \[\leadsto \color{blue}{x \cdot x} \]
    4. Simplified99.0%

      \[\leadsto \color{blue}{x \cdot x} \]

    if 5.5999999999999996 < x

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{-1} + e^{-x} \]
    3. Taylor expanded in x around 0 0.2%

      \[\leadsto \color{blue}{-0.16666666666666666 \cdot {x}^{3} + \left(0.5 \cdot {x}^{2} + -1 \cdot x\right)} \]
    4. Step-by-step derivation
      1. associate-+r+0.2%

        \[\leadsto \color{blue}{\left(-0.16666666666666666 \cdot {x}^{3} + 0.5 \cdot {x}^{2}\right) + -1 \cdot x} \]
      2. neg-mul-10.2%

        \[\leadsto \left(-0.16666666666666666 \cdot {x}^{3} + 0.5 \cdot {x}^{2}\right) + \color{blue}{\left(-x\right)} \]
      3. unsub-neg0.2%

        \[\leadsto \color{blue}{\left(-0.16666666666666666 \cdot {x}^{3} + 0.5 \cdot {x}^{2}\right) - x} \]
      4. +-commutative0.2%

        \[\leadsto \color{blue}{\left(0.5 \cdot {x}^{2} + -0.16666666666666666 \cdot {x}^{3}\right)} - x \]
      5. unpow20.2%

        \[\leadsto \left(0.5 \cdot \color{blue}{\left(x \cdot x\right)} + -0.16666666666666666 \cdot {x}^{3}\right) - x \]
      6. *-commutative0.2%

        \[\leadsto \left(\color{blue}{\left(x \cdot x\right) \cdot 0.5} + -0.16666666666666666 \cdot {x}^{3}\right) - x \]
      7. *-commutative0.2%

        \[\leadsto \left(\left(x \cdot x\right) \cdot 0.5 + \color{blue}{{x}^{3} \cdot -0.16666666666666666}\right) - x \]
      8. unpow30.2%

        \[\leadsto \left(\left(x \cdot x\right) \cdot 0.5 + \color{blue}{\left(\left(x \cdot x\right) \cdot x\right)} \cdot -0.16666666666666666\right) - x \]
      9. associate-*l*0.2%

        \[\leadsto \left(\left(x \cdot x\right) \cdot 0.5 + \color{blue}{\left(x \cdot x\right) \cdot \left(x \cdot -0.16666666666666666\right)}\right) - x \]
      10. distribute-lft-out0.2%

        \[\leadsto \color{blue}{\left(x \cdot x\right) \cdot \left(0.5 + x \cdot -0.16666666666666666\right)} - x \]
    5. Simplified0.2%

      \[\leadsto \color{blue}{\left(x \cdot x\right) \cdot \left(0.5 + x \cdot -0.16666666666666666\right) - x} \]
    6. Step-by-step derivation
      1. flip-+0.2%

        \[\leadsto \left(x \cdot x\right) \cdot \color{blue}{\frac{0.5 \cdot 0.5 - \left(x \cdot -0.16666666666666666\right) \cdot \left(x \cdot -0.16666666666666666\right)}{0.5 - x \cdot -0.16666666666666666}} - x \]
      2. div-inv0.2%

        \[\leadsto \left(x \cdot x\right) \cdot \color{blue}{\left(\left(0.5 \cdot 0.5 - \left(x \cdot -0.16666666666666666\right) \cdot \left(x \cdot -0.16666666666666666\right)\right) \cdot \frac{1}{0.5 - x \cdot -0.16666666666666666}\right)} - x \]
      3. metadata-eval0.2%

        \[\leadsto \left(x \cdot x\right) \cdot \left(\left(\color{blue}{0.25} - \left(x \cdot -0.16666666666666666\right) \cdot \left(x \cdot -0.16666666666666666\right)\right) \cdot \frac{1}{0.5 - x \cdot -0.16666666666666666}\right) - x \]
      4. swap-sqr0.2%

        \[\leadsto \left(x \cdot x\right) \cdot \left(\left(0.25 - \color{blue}{\left(x \cdot x\right) \cdot \left(-0.16666666666666666 \cdot -0.16666666666666666\right)}\right) \cdot \frac{1}{0.5 - x \cdot -0.16666666666666666}\right) - x \]
      5. metadata-eval0.2%

        \[\leadsto \left(x \cdot x\right) \cdot \left(\left(0.25 - \left(x \cdot x\right) \cdot \color{blue}{0.027777777777777776}\right) \cdot \frac{1}{0.5 - x \cdot -0.16666666666666666}\right) - x \]
      6. *-commutative0.2%

        \[\leadsto \left(x \cdot x\right) \cdot \left(\left(0.25 - \left(x \cdot x\right) \cdot 0.027777777777777776\right) \cdot \frac{1}{0.5 - \color{blue}{-0.16666666666666666 \cdot x}}\right) - x \]
      7. cancel-sign-sub-inv0.2%

        \[\leadsto \left(x \cdot x\right) \cdot \left(\left(0.25 - \left(x \cdot x\right) \cdot 0.027777777777777776\right) \cdot \frac{1}{\color{blue}{0.5 + \left(--0.16666666666666666\right) \cdot x}}\right) - x \]
      8. metadata-eval0.2%

        \[\leadsto \left(x \cdot x\right) \cdot \left(\left(0.25 - \left(x \cdot x\right) \cdot 0.027777777777777776\right) \cdot \frac{1}{0.5 + \color{blue}{0.16666666666666666} \cdot x}\right) - x \]
    7. Applied egg-rr0.2%

      \[\leadsto \left(x \cdot x\right) \cdot \color{blue}{\left(\left(0.25 - \left(x \cdot x\right) \cdot 0.027777777777777776\right) \cdot \frac{1}{0.5 + 0.16666666666666666 \cdot x}\right)} - x \]
    8. Taylor expanded in x around 0 75.2%

      \[\leadsto \left(x \cdot x\right) \cdot \left(\left(0.25 - \left(x \cdot x\right) \cdot 0.027777777777777776\right) \cdot \color{blue}{\left(2 + -0.6666666666666666 \cdot x\right)}\right) - x \]
    9. Step-by-step derivation
      1. *-commutative75.2%

        \[\leadsto \left(x \cdot x\right) \cdot \left(\left(0.25 - \left(x \cdot x\right) \cdot 0.027777777777777776\right) \cdot \left(2 + \color{blue}{x \cdot -0.6666666666666666}\right)\right) - x \]
    10. Simplified75.2%

      \[\leadsto \left(x \cdot x\right) \cdot \left(\left(0.25 - \left(x \cdot x\right) \cdot 0.027777777777777776\right) \cdot \color{blue}{\left(2 + x \cdot -0.6666666666666666\right)}\right) - x \]
  3. Recombined 3 regimes into one program.
  4. Final simplification88.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -1.5:\\ \;\;\;\;\frac{\left(x \cdot x\right) \cdot \left(0.25 - x \cdot \left(x \cdot 0.027777777777777776\right)\right)}{0.5 + x \cdot 0.16666666666666666} - x\\ \mathbf{elif}\;x \leq 5.6:\\ \;\;\;\;x \cdot x\\ \mathbf{else}:\\ \;\;\;\;\left(x \cdot x\right) \cdot \left(\left(0.25 - \left(x \cdot x\right) \cdot 0.027777777777777776\right) \cdot \left(2 + x \cdot -0.6666666666666666\right)\right) - x\\ \end{array} \]

Alternative 8: 79.2% accurate, 18.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -4.7:\\ \;\;\;\;\frac{x \cdot x}{\frac{-6}{x}} - x\\ \mathbf{else}:\\ \;\;\;\;x \cdot x\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (if (<= x -4.7) (- (/ (* x x) (/ -6.0 x)) x) (* x x)))
double code(double x) {
	double tmp;
	if (x <= -4.7) {
		tmp = ((x * x) / (-6.0 / x)) - x;
	} else {
		tmp = x * x;
	}
	return tmp;
}
real(8) function code(x)
    real(8), intent (in) :: x
    real(8) :: tmp
    if (x <= (-4.7d0)) then
        tmp = ((x * x) / ((-6.0d0) / x)) - x
    else
        tmp = x * x
    end if
    code = tmp
end function
public static double code(double x) {
	double tmp;
	if (x <= -4.7) {
		tmp = ((x * x) / (-6.0 / x)) - x;
	} else {
		tmp = x * x;
	}
	return tmp;
}
def code(x):
	tmp = 0
	if x <= -4.7:
		tmp = ((x * x) / (-6.0 / x)) - x
	else:
		tmp = x * x
	return tmp
function code(x)
	tmp = 0.0
	if (x <= -4.7)
		tmp = Float64(Float64(Float64(x * x) / Float64(-6.0 / x)) - x);
	else
		tmp = Float64(x * x);
	end
	return tmp
end
function tmp_2 = code(x)
	tmp = 0.0;
	if (x <= -4.7)
		tmp = ((x * x) / (-6.0 / x)) - x;
	else
		tmp = x * x;
	end
	tmp_2 = tmp;
end
code[x_] := If[LessEqual[x, -4.7], N[(N[(N[(x * x), $MachinePrecision] / N[(-6.0 / x), $MachinePrecision]), $MachinePrecision] - x), $MachinePrecision], N[(x * x), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.7:\\
\;\;\;\;\frac{x \cdot x}{\frac{-6}{x}} - x\\

\mathbf{else}:\\
\;\;\;\;x \cdot x\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -4.70000000000000018

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{-1} + e^{-x} \]
    3. Taylor expanded in x around 0 75.4%

      \[\leadsto \color{blue}{-0.16666666666666666 \cdot {x}^{3} + \left(0.5 \cdot {x}^{2} + -1 \cdot x\right)} \]
    4. Step-by-step derivation
      1. associate-+r+75.4%

        \[\leadsto \color{blue}{\left(-0.16666666666666666 \cdot {x}^{3} + 0.5 \cdot {x}^{2}\right) + -1 \cdot x} \]
      2. neg-mul-175.4%

        \[\leadsto \left(-0.16666666666666666 \cdot {x}^{3} + 0.5 \cdot {x}^{2}\right) + \color{blue}{\left(-x\right)} \]
      3. unsub-neg75.4%

        \[\leadsto \color{blue}{\left(-0.16666666666666666 \cdot {x}^{3} + 0.5 \cdot {x}^{2}\right) - x} \]
      4. +-commutative75.4%

        \[\leadsto \color{blue}{\left(0.5 \cdot {x}^{2} + -0.16666666666666666 \cdot {x}^{3}\right)} - x \]
      5. unpow275.4%

        \[\leadsto \left(0.5 \cdot \color{blue}{\left(x \cdot x\right)} + -0.16666666666666666 \cdot {x}^{3}\right) - x \]
      6. *-commutative75.4%

        \[\leadsto \left(\color{blue}{\left(x \cdot x\right) \cdot 0.5} + -0.16666666666666666 \cdot {x}^{3}\right) - x \]
      7. *-commutative75.4%

        \[\leadsto \left(\left(x \cdot x\right) \cdot 0.5 + \color{blue}{{x}^{3} \cdot -0.16666666666666666}\right) - x \]
      8. unpow375.4%

        \[\leadsto \left(\left(x \cdot x\right) \cdot 0.5 + \color{blue}{\left(\left(x \cdot x\right) \cdot x\right)} \cdot -0.16666666666666666\right) - x \]
      9. associate-*l*75.4%

        \[\leadsto \left(\left(x \cdot x\right) \cdot 0.5 + \color{blue}{\left(x \cdot x\right) \cdot \left(x \cdot -0.16666666666666666\right)}\right) - x \]
      10. distribute-lft-out75.4%

        \[\leadsto \color{blue}{\left(x \cdot x\right) \cdot \left(0.5 + x \cdot -0.16666666666666666\right)} - x \]
    5. Simplified75.4%

      \[\leadsto \color{blue}{\left(x \cdot x\right) \cdot \left(0.5 + x \cdot -0.16666666666666666\right) - x} \]
    6. Step-by-step derivation
      1. flip-+75.4%

        \[\leadsto \left(x \cdot x\right) \cdot \color{blue}{\frac{0.5 \cdot 0.5 - \left(x \cdot -0.16666666666666666\right) \cdot \left(x \cdot -0.16666666666666666\right)}{0.5 - x \cdot -0.16666666666666666}} - x \]
      2. associate-*r/81.0%

        \[\leadsto \color{blue}{\frac{\left(x \cdot x\right) \cdot \left(0.5 \cdot 0.5 - \left(x \cdot -0.16666666666666666\right) \cdot \left(x \cdot -0.16666666666666666\right)\right)}{0.5 - x \cdot -0.16666666666666666}} - x \]
      3. metadata-eval81.0%

        \[\leadsto \frac{\left(x \cdot x\right) \cdot \left(\color{blue}{0.25} - \left(x \cdot -0.16666666666666666\right) \cdot \left(x \cdot -0.16666666666666666\right)\right)}{0.5 - x \cdot -0.16666666666666666} - x \]
      4. swap-sqr81.0%

        \[\leadsto \frac{\left(x \cdot x\right) \cdot \left(0.25 - \color{blue}{\left(x \cdot x\right) \cdot \left(-0.16666666666666666 \cdot -0.16666666666666666\right)}\right)}{0.5 - x \cdot -0.16666666666666666} - x \]
      5. metadata-eval81.0%

        \[\leadsto \frac{\left(x \cdot x\right) \cdot \left(0.25 - \left(x \cdot x\right) \cdot \color{blue}{0.027777777777777776}\right)}{0.5 - x \cdot -0.16666666666666666} - x \]
      6. *-commutative81.0%

        \[\leadsto \frac{\left(x \cdot x\right) \cdot \left(0.25 - \left(x \cdot x\right) \cdot 0.027777777777777776\right)}{0.5 - \color{blue}{-0.16666666666666666 \cdot x}} - x \]
      7. cancel-sign-sub-inv81.0%

        \[\leadsto \frac{\left(x \cdot x\right) \cdot \left(0.25 - \left(x \cdot x\right) \cdot 0.027777777777777776\right)}{\color{blue}{0.5 + \left(--0.16666666666666666\right) \cdot x}} - x \]
      8. metadata-eval81.0%

        \[\leadsto \frac{\left(x \cdot x\right) \cdot \left(0.25 - \left(x \cdot x\right) \cdot 0.027777777777777776\right)}{0.5 + \color{blue}{0.16666666666666666} \cdot x} - x \]
    7. Applied egg-rr81.0%

      \[\leadsto \color{blue}{\frac{\left(x \cdot x\right) \cdot \left(0.25 - \left(x \cdot x\right) \cdot 0.027777777777777776\right)}{0.5 + 0.16666666666666666 \cdot x}} - x \]
    8. Step-by-step derivation
      1. associate-/l*75.4%

        \[\leadsto \color{blue}{\frac{x \cdot x}{\frac{0.5 + 0.16666666666666666 \cdot x}{0.25 - \left(x \cdot x\right) \cdot 0.027777777777777776}}} - x \]
      2. *-commutative75.4%

        \[\leadsto \frac{x \cdot x}{\frac{0.5 + \color{blue}{x \cdot 0.16666666666666666}}{0.25 - \left(x \cdot x\right) \cdot 0.027777777777777776}} - x \]
    9. Simplified75.4%

      \[\leadsto \color{blue}{\frac{x \cdot x}{\frac{0.5 + x \cdot 0.16666666666666666}{0.25 - \left(x \cdot x\right) \cdot 0.027777777777777776}}} - x \]
    10. Taylor expanded in x around inf 75.4%

      \[\leadsto \frac{x \cdot x}{\color{blue}{\frac{-6}{x}}} - x \]

    if -4.70000000000000018 < x

    1. Initial program 72.3%

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

      \[\leadsto \color{blue}{{x}^{2}} \]
    3. Step-by-step derivation
      1. unpow279.1%

        \[\leadsto \color{blue}{x \cdot x} \]
    4. Simplified79.1%

      \[\leadsto \color{blue}{x \cdot x} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification78.2%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -4.7:\\ \;\;\;\;\frac{x \cdot x}{\frac{-6}{x}} - x\\ \mathbf{else}:\\ \;\;\;\;x \cdot x\\ \end{array} \]

Alternative 9: 75.4% accurate, 68.7× speedup?

\[\begin{array}{l} \\ x \cdot x \end{array} \]
(FPCore (x) :precision binary64 (* x x))
double code(double x) {
	return x * x;
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = x * x
end function
public static double code(double x) {
	return x * x;
}
def code(x):
	return x * x
function code(x)
	return Float64(x * x)
end
function tmp = code(x)
	tmp = x * x;
end
code[x_] := N[(x * x), $MachinePrecision]
\begin{array}{l}

\\
x \cdot x
\end{array}
Derivation
  1. Initial program 79.3%

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

    \[\leadsto \color{blue}{{x}^{2}} \]
  3. Step-by-step derivation
    1. unpow274.8%

      \[\leadsto \color{blue}{x \cdot x} \]
  4. Simplified74.8%

    \[\leadsto \color{blue}{x \cdot x} \]
  5. Final simplification74.8%

    \[\leadsto x \cdot x \]

Alternative 10: 26.2% accurate, 206.0× speedup?

\[\begin{array}{l} \\ 0 \end{array} \]
(FPCore (x) :precision binary64 0.0)
double code(double x) {
	return 0.0;
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = 0.0d0
end function
public static double code(double x) {
	return 0.0;
}
def code(x):
	return 0.0
function code(x)
	return 0.0
end
function tmp = code(x)
	tmp = 0.0;
end
code[x_] := 0.0
\begin{array}{l}

\\
0
\end{array}
Derivation
  1. Initial program 79.3%

    \[\left(e^{x} - 2\right) + e^{-x} \]
  2. Applied egg-rr27.1%

    \[\leadsto \color{blue}{0} \]
  3. Final simplification27.1%

    \[\leadsto 0 \]

Developer target: 100.0% accurate, 1.0× speedup?

\[\begin{array}{l} \\ 4 \cdot {\sinh \left(\frac{x}{2}\right)}^{2} \end{array} \]
(FPCore (x) :precision binary64 (* 4.0 (pow (sinh (/ x 2.0)) 2.0)))
double code(double x) {
	return 4.0 * pow(sinh((x / 2.0)), 2.0);
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = 4.0d0 * (sinh((x / 2.0d0)) ** 2.0d0)
end function
public static double code(double x) {
	return 4.0 * Math.pow(Math.sinh((x / 2.0)), 2.0);
}
def code(x):
	return 4.0 * math.pow(math.sinh((x / 2.0)), 2.0)
function code(x)
	return Float64(4.0 * (sinh(Float64(x / 2.0)) ^ 2.0))
end
function tmp = code(x)
	tmp = 4.0 * (sinh((x / 2.0)) ^ 2.0);
end
code[x_] := N[(4.0 * N[Power[N[Sinh[N[(x / 2.0), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
4 \cdot {\sinh \left(\frac{x}{2}\right)}^{2}
\end{array}

Reproduce

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