exp2 (problem 3.3.7)

Percentage Accurate: 76.8% → 99.9%
Time: 4.3s
Alternatives: 8
Speedup: 1.9×

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 8 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.8% 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.5× speedup?

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

    1. Initial program 47.8%

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

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

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

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

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

    if 5.0000000000000001e-9 < (+.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 5 \cdot 10^{-9}:\\ \;\;\;\;\mathsf{fma}\left(x, 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 5 \cdot 10^{-9}:\\ \;\;\;\;0.08333333333333333 \cdot {x}^{4} + x \cdot x\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (let* ((t_0 (+ (- (exp x) 2.0) (exp (- x)))))
   (if (<= t_0 5e-9) (+ (* 0.08333333333333333 (pow x 4.0)) (* x x)) t_0)))
double code(double x) {
	double t_0 = (exp(x) - 2.0) + exp(-x);
	double tmp;
	if (t_0 <= 5e-9) {
		tmp = (0.08333333333333333 * pow(x, 4.0)) + (x * x);
	} 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 <= 5d-9) then
        tmp = (0.08333333333333333d0 * (x ** 4.0d0)) + (x * x)
    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 <= 5e-9) {
		tmp = (0.08333333333333333 * Math.pow(x, 4.0)) + (x * x);
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(x):
	t_0 = (math.exp(x) - 2.0) + math.exp(-x)
	tmp = 0
	if t_0 <= 5e-9:
		tmp = (0.08333333333333333 * math.pow(x, 4.0)) + (x * x)
	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 <= 5e-9)
		tmp = Float64(Float64(0.08333333333333333 * (x ^ 4.0)) + Float64(x * x));
	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 <= 5e-9)
		tmp = (0.08333333333333333 * (x ^ 4.0)) + (x * x);
	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, 5e-9], N[(N[(0.08333333333333333 * N[Power[x, 4.0], $MachinePrecision]), $MachinePrecision] + N[(x * x), $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 5 \cdot 10^{-9}:\\
\;\;\;\;0.08333333333333333 \cdot {x}^{4} + x \cdot x\\

\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))) < 5.0000000000000001e-9

    1. Initial program 47.8%

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

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

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

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

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

Alternative 3: 93.3% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq 5000000000000:\\ \;\;\;\;0.08333333333333333 \cdot {x}^{4} + x \cdot x\\ \mathbf{else}:\\ \;\;\;\;{\left(3.3489797668038406 \cdot 10^{-7} \cdot {x}^{24}\right)}^{0.16666666666666666}\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (if (<= x 5000000000000.0)
   (+ (* 0.08333333333333333 (pow x 4.0)) (* x x))
   (pow (* 3.3489797668038406e-7 (pow x 24.0)) 0.16666666666666666)))
double code(double x) {
	double tmp;
	if (x <= 5000000000000.0) {
		tmp = (0.08333333333333333 * pow(x, 4.0)) + (x * x);
	} else {
		tmp = pow((3.3489797668038406e-7 * pow(x, 24.0)), 0.16666666666666666);
	}
	return tmp;
}
real(8) function code(x)
    real(8), intent (in) :: x
    real(8) :: tmp
    if (x <= 5000000000000.0d0) then
        tmp = (0.08333333333333333d0 * (x ** 4.0d0)) + (x * x)
    else
        tmp = (3.3489797668038406d-7 * (x ** 24.0d0)) ** 0.16666666666666666d0
    end if
    code = tmp
end function
public static double code(double x) {
	double tmp;
	if (x <= 5000000000000.0) {
		tmp = (0.08333333333333333 * Math.pow(x, 4.0)) + (x * x);
	} else {
		tmp = Math.pow((3.3489797668038406e-7 * Math.pow(x, 24.0)), 0.16666666666666666);
	}
	return tmp;
}
def code(x):
	tmp = 0
	if x <= 5000000000000.0:
		tmp = (0.08333333333333333 * math.pow(x, 4.0)) + (x * x)
	else:
		tmp = math.pow((3.3489797668038406e-7 * math.pow(x, 24.0)), 0.16666666666666666)
	return tmp
function code(x)
	tmp = 0.0
	if (x <= 5000000000000.0)
		tmp = Float64(Float64(0.08333333333333333 * (x ^ 4.0)) + Float64(x * x));
	else
		tmp = Float64(3.3489797668038406e-7 * (x ^ 24.0)) ^ 0.16666666666666666;
	end
	return tmp
end
function tmp_2 = code(x)
	tmp = 0.0;
	if (x <= 5000000000000.0)
		tmp = (0.08333333333333333 * (x ^ 4.0)) + (x * x);
	else
		tmp = (3.3489797668038406e-7 * (x ^ 24.0)) ^ 0.16666666666666666;
	end
	tmp_2 = tmp;
end
code[x_] := If[LessEqual[x, 5000000000000.0], N[(N[(0.08333333333333333 * N[Power[x, 4.0], $MachinePrecision]), $MachinePrecision] + N[(x * x), $MachinePrecision]), $MachinePrecision], N[Power[N[(3.3489797668038406e-7 * N[Power[x, 24.0], $MachinePrecision]), $MachinePrecision], 0.16666666666666666], $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq 5000000000000:\\
\;\;\;\;0.08333333333333333 \cdot {x}^{4} + x \cdot x\\

\mathbf{else}:\\
\;\;\;\;{\left(3.3489797668038406 \cdot 10^{-7} \cdot {x}^{24}\right)}^{0.16666666666666666}\\


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

    1. Initial program 66.0%

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

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

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

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

    if 5e12 < x

    1. Initial program 100.0%

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

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

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

      \[\leadsto \color{blue}{x \cdot x + 0.08333333333333333 \cdot {x}^{4}} \]
    5. Taylor expanded in x around inf 79.9%

      \[\leadsto \color{blue}{0.08333333333333333 \cdot {x}^{4}} \]
    6. Step-by-step derivation
      1. add-cbrt-cube95.3%

        \[\leadsto \color{blue}{\sqrt[3]{\left(\left(0.08333333333333333 \cdot {x}^{4}\right) \cdot \left(0.08333333333333333 \cdot {x}^{4}\right)\right) \cdot \left(0.08333333333333333 \cdot {x}^{4}\right)}} \]
      2. pow395.3%

        \[\leadsto \sqrt[3]{\color{blue}{{\left(0.08333333333333333 \cdot {x}^{4}\right)}^{3}}} \]
      3. *-commutative95.3%

        \[\leadsto \sqrt[3]{{\color{blue}{\left({x}^{4} \cdot 0.08333333333333333\right)}}^{3}} \]
      4. unpow-prod-down95.3%

        \[\leadsto \sqrt[3]{\color{blue}{{\left({x}^{4}\right)}^{3} \cdot {0.08333333333333333}^{3}}} \]
      5. pow-pow95.3%

        \[\leadsto \sqrt[3]{\color{blue}{{x}^{\left(4 \cdot 3\right)}} \cdot {0.08333333333333333}^{3}} \]
      6. metadata-eval95.3%

        \[\leadsto \sqrt[3]{{x}^{\color{blue}{12}} \cdot {0.08333333333333333}^{3}} \]
      7. metadata-eval95.3%

        \[\leadsto \sqrt[3]{{x}^{12} \cdot \color{blue}{0.0005787037037037037}} \]
    7. Applied egg-rr95.3%

      \[\leadsto \color{blue}{\sqrt[3]{{x}^{12} \cdot 0.0005787037037037037}} \]
    8. Step-by-step derivation
      1. pow1/395.3%

        \[\leadsto \color{blue}{{\left({x}^{12} \cdot 0.0005787037037037037\right)}^{0.3333333333333333}} \]
      2. sqr-pow95.3%

        \[\leadsto \color{blue}{{\left({x}^{12} \cdot 0.0005787037037037037\right)}^{\left(\frac{0.3333333333333333}{2}\right)} \cdot {\left({x}^{12} \cdot 0.0005787037037037037\right)}^{\left(\frac{0.3333333333333333}{2}\right)}} \]
      3. pow-prod-down100.0%

        \[\leadsto \color{blue}{{\left(\left({x}^{12} \cdot 0.0005787037037037037\right) \cdot \left({x}^{12} \cdot 0.0005787037037037037\right)\right)}^{\left(\frac{0.3333333333333333}{2}\right)}} \]
      4. *-commutative100.0%

        \[\leadsto {\left(\color{blue}{\left(0.0005787037037037037 \cdot {x}^{12}\right)} \cdot \left({x}^{12} \cdot 0.0005787037037037037\right)\right)}^{\left(\frac{0.3333333333333333}{2}\right)} \]
      5. *-commutative100.0%

        \[\leadsto {\left(\left(0.0005787037037037037 \cdot {x}^{12}\right) \cdot \color{blue}{\left(0.0005787037037037037 \cdot {x}^{12}\right)}\right)}^{\left(\frac{0.3333333333333333}{2}\right)} \]
      6. swap-sqr100.0%

        \[\leadsto {\color{blue}{\left(\left(0.0005787037037037037 \cdot 0.0005787037037037037\right) \cdot \left({x}^{12} \cdot {x}^{12}\right)\right)}}^{\left(\frac{0.3333333333333333}{2}\right)} \]
      7. metadata-eval100.0%

        \[\leadsto {\left(\color{blue}{3.3489797668038406 \cdot 10^{-7}} \cdot \left({x}^{12} \cdot {x}^{12}\right)\right)}^{\left(\frac{0.3333333333333333}{2}\right)} \]
      8. pow-prod-up100.0%

        \[\leadsto {\left(3.3489797668038406 \cdot 10^{-7} \cdot \color{blue}{{x}^{\left(12 + 12\right)}}\right)}^{\left(\frac{0.3333333333333333}{2}\right)} \]
      9. metadata-eval100.0%

        \[\leadsto {\left(3.3489797668038406 \cdot 10^{-7} \cdot {x}^{\color{blue}{24}}\right)}^{\left(\frac{0.3333333333333333}{2}\right)} \]
      10. metadata-eval100.0%

        \[\leadsto {\left(3.3489797668038406 \cdot 10^{-7} \cdot {x}^{24}\right)}^{\color{blue}{0.16666666666666666}} \]
    9. Applied egg-rr100.0%

      \[\leadsto \color{blue}{{\left(3.3489797668038406 \cdot 10^{-7} \cdot {x}^{24}\right)}^{0.16666666666666666}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification93.6%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 5000000000000:\\ \;\;\;\;0.08333333333333333 \cdot {x}^{4} + x \cdot x\\ \mathbf{else}:\\ \;\;\;\;{\left(3.3489797668038406 \cdot 10^{-7} \cdot {x}^{24}\right)}^{0.16666666666666666}\\ \end{array} \]

Alternative 4: 92.3% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq 20000000000000:\\ \;\;\;\;0.08333333333333333 \cdot {x}^{4} + x \cdot x\\ \mathbf{else}:\\ \;\;\;\;\sqrt[3]{{x}^{12} \cdot 0.0005787037037037037}\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (if (<= x 20000000000000.0)
   (+ (* 0.08333333333333333 (pow x 4.0)) (* x x))
   (cbrt (* (pow x 12.0) 0.0005787037037037037))))
double code(double x) {
	double tmp;
	if (x <= 20000000000000.0) {
		tmp = (0.08333333333333333 * pow(x, 4.0)) + (x * x);
	} else {
		tmp = cbrt((pow(x, 12.0) * 0.0005787037037037037));
	}
	return tmp;
}
public static double code(double x) {
	double tmp;
	if (x <= 20000000000000.0) {
		tmp = (0.08333333333333333 * Math.pow(x, 4.0)) + (x * x);
	} else {
		tmp = Math.cbrt((Math.pow(x, 12.0) * 0.0005787037037037037));
	}
	return tmp;
}
function code(x)
	tmp = 0.0
	if (x <= 20000000000000.0)
		tmp = Float64(Float64(0.08333333333333333 * (x ^ 4.0)) + Float64(x * x));
	else
		tmp = cbrt(Float64((x ^ 12.0) * 0.0005787037037037037));
	end
	return tmp
end
code[x_] := If[LessEqual[x, 20000000000000.0], N[(N[(0.08333333333333333 * N[Power[x, 4.0], $MachinePrecision]), $MachinePrecision] + N[(x * x), $MachinePrecision]), $MachinePrecision], N[Power[N[(N[Power[x, 12.0], $MachinePrecision] * 0.0005787037037037037), $MachinePrecision], 1/3], $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq 20000000000000:\\
\;\;\;\;0.08333333333333333 \cdot {x}^{4} + x \cdot x\\

\mathbf{else}:\\
\;\;\;\;\sqrt[3]{{x}^{12} \cdot 0.0005787037037037037}\\


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

    1. Initial program 66.0%

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

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

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

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

    if 2e13 < x

    1. Initial program 100.0%

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

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

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

      \[\leadsto \color{blue}{x \cdot x + 0.08333333333333333 \cdot {x}^{4}} \]
    5. Taylor expanded in x around inf 79.9%

      \[\leadsto \color{blue}{0.08333333333333333 \cdot {x}^{4}} \]
    6. Step-by-step derivation
      1. add-cbrt-cube95.3%

        \[\leadsto \color{blue}{\sqrt[3]{\left(\left(0.08333333333333333 \cdot {x}^{4}\right) \cdot \left(0.08333333333333333 \cdot {x}^{4}\right)\right) \cdot \left(0.08333333333333333 \cdot {x}^{4}\right)}} \]
      2. pow395.3%

        \[\leadsto \sqrt[3]{\color{blue}{{\left(0.08333333333333333 \cdot {x}^{4}\right)}^{3}}} \]
      3. *-commutative95.3%

        \[\leadsto \sqrt[3]{{\color{blue}{\left({x}^{4} \cdot 0.08333333333333333\right)}}^{3}} \]
      4. unpow-prod-down95.3%

        \[\leadsto \sqrt[3]{\color{blue}{{\left({x}^{4}\right)}^{3} \cdot {0.08333333333333333}^{3}}} \]
      5. pow-pow95.3%

        \[\leadsto \sqrt[3]{\color{blue}{{x}^{\left(4 \cdot 3\right)}} \cdot {0.08333333333333333}^{3}} \]
      6. metadata-eval95.3%

        \[\leadsto \sqrt[3]{{x}^{\color{blue}{12}} \cdot {0.08333333333333333}^{3}} \]
      7. metadata-eval95.3%

        \[\leadsto \sqrt[3]{{x}^{12} \cdot \color{blue}{0.0005787037037037037}} \]
    7. Applied egg-rr95.3%

      \[\leadsto \color{blue}{\sqrt[3]{{x}^{12} \cdot 0.0005787037037037037}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification92.5%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 20000000000000:\\ \;\;\;\;0.08333333333333333 \cdot {x}^{4} + x \cdot x\\ \mathbf{else}:\\ \;\;\;\;\sqrt[3]{{x}^{12} \cdot 0.0005787037037037037}\\ \end{array} \]

Alternative 5: 88.5% accurate, 1.9× speedup?

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

\\
0.08333333333333333 \cdot {x}^{4} + x \cdot x
\end{array}
Derivation
  1. Initial program 74.1%

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

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

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

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

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

Alternative 6: 82.1% accurate, 1.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq 3.5:\\ \;\;\;\;x \cdot x\\ \mathbf{else}:\\ \;\;\;\;0.08333333333333333 \cdot {x}^{4}\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (if (<= x 3.5) (* x x) (* 0.08333333333333333 (pow x 4.0))))
double code(double x) {
	double tmp;
	if (x <= 3.5) {
		tmp = x * x;
	} else {
		tmp = 0.08333333333333333 * pow(x, 4.0);
	}
	return tmp;
}
real(8) function code(x)
    real(8), intent (in) :: x
    real(8) :: tmp
    if (x <= 3.5d0) then
        tmp = x * x
    else
        tmp = 0.08333333333333333d0 * (x ** 4.0d0)
    end if
    code = tmp
end function
public static double code(double x) {
	double tmp;
	if (x <= 3.5) {
		tmp = x * x;
	} else {
		tmp = 0.08333333333333333 * Math.pow(x, 4.0);
	}
	return tmp;
}
def code(x):
	tmp = 0
	if x <= 3.5:
		tmp = x * x
	else:
		tmp = 0.08333333333333333 * math.pow(x, 4.0)
	return tmp
function code(x)
	tmp = 0.0
	if (x <= 3.5)
		tmp = Float64(x * x);
	else
		tmp = Float64(0.08333333333333333 * (x ^ 4.0));
	end
	return tmp
end
function tmp_2 = code(x)
	tmp = 0.0;
	if (x <= 3.5)
		tmp = x * x;
	else
		tmp = 0.08333333333333333 * (x ^ 4.0);
	end
	tmp_2 = tmp;
end
code[x_] := If[LessEqual[x, 3.5], N[(x * x), $MachinePrecision], N[(0.08333333333333333 * N[Power[x, 4.0], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq 3.5:\\
\;\;\;\;x \cdot x\\

\mathbf{else}:\\
\;\;\;\;0.08333333333333333 \cdot {x}^{4}\\


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

    1. Initial program 65.6%

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

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

        \[\leadsto \color{blue}{x \cdot x} \]
    4. Simplified82.6%

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

    if 3.5 < x

    1. Initial program 100.0%

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

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

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

      \[\leadsto \color{blue}{x \cdot x + 0.08333333333333333 \cdot {x}^{4}} \]
    5. Taylor expanded in x around inf 77.5%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 3.5:\\ \;\;\;\;x \cdot x\\ \mathbf{else}:\\ \;\;\;\;0.08333333333333333 \cdot {x}^{4}\\ \end{array} \]

Alternative 7: 76.2% 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 74.1%

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

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

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

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

    \[\leadsto x \cdot x \]

Alternative 8: 26.5% 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 74.1%

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

    \[\leadsto \color{blue}{0} \]
  3. Final simplification24.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 2023201 
(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))))