expq2 (section 3.11)

Percentage Accurate: 37.9% → 99.4%
Time: 8.3s
Alternatives: 10
Speedup: 68.3×

Specification

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

\\
\frac{e^{x}}{e^{x} - 1}
\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: 37.9% accurate, 1.0× speedup?

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

\\
\frac{e^{x}}{e^{x} - 1}
\end{array}

Alternative 1: 99.4% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \frac{e^{x}}{\mathsf{expm1}\left(x\right)} \end{array} \]
(FPCore (x) :precision binary64 (/ (exp x) (expm1 x)))
double code(double x) {
	return exp(x) / expm1(x);
}
public static double code(double x) {
	return Math.exp(x) / Math.expm1(x);
}
def code(x):
	return math.exp(x) / math.expm1(x)
function code(x)
	return Float64(exp(x) / expm1(x))
end
code[x_] := N[(N[Exp[x], $MachinePrecision] / N[(Exp[x] - 1), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{e^{x}}{\mathsf{expm1}\left(x\right)}
\end{array}
Derivation
  1. Initial program 40.7%

    \[\frac{e^{x}}{e^{x} - 1} \]
  2. Step-by-step derivation
    1. expm1-def100.0%

      \[\leadsto \frac{e^{x}}{\color{blue}{\mathsf{expm1}\left(x\right)}} \]
  3. Simplified100.0%

    \[\leadsto \color{blue}{\frac{e^{x}}{\mathsf{expm1}\left(x\right)}} \]
  4. Final simplification100.0%

    \[\leadsto \frac{e^{x}}{\mathsf{expm1}\left(x\right)} \]

Alternative 2: 78.7% accurate, 1.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{1}{x} + 0.5\\ \mathbf{if}\;x \leq -3.8:\\ \;\;\;\;\frac{t_0 \cdot t_0 - x \cdot \left(x \cdot 0.006944444444444444\right)}{\frac{1}{x} + \left(0.5 - \langle \left( x \cdot 0.08333333333333333 \right)_{\text{binary32}} \rangle_{\text{binary64}}\right)}\\ \mathbf{else}:\\ \;\;\;\;0.5 + \left(-0.001388888888888889 \cdot {x}^{3} + \left(\frac{1}{x} + x \cdot 0.08333333333333333\right)\right)\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (let* ((t_0 (+ (/ 1.0 x) 0.5)))
   (if (<= x -3.8)
     (/
      (- (* t_0 t_0) (* x (* x 0.006944444444444444)))
      (+
       (/ 1.0 x)
       (- 0.5 (cast (! :precision binary32 (* x 0.08333333333333333))))))
     (+
      0.5
      (+
       (* -0.001388888888888889 (pow x 3.0))
       (+ (/ 1.0 x) (* x 0.08333333333333333)))))))
double code(double x) {
	double t_0 = (1.0 / x) + 0.5;
	double tmp_1;
	if (x <= -3.8) {
		float tmp_2 = x * 0.08333333333333333f;
		tmp_1 = ((t_0 * t_0) - (x * (x * 0.006944444444444444))) / ((1.0 / x) + (0.5 - ((double) ((double) tmp_2))));
	} else {
		tmp_1 = 0.5 + ((-0.001388888888888889 * pow(x, 3.0)) + ((1.0 / x) + (x * 0.08333333333333333)));
	}
	return tmp_1;
}
real(8) function code(x)
    real(8), intent (in) :: x
    real(8) :: t_0
    real(4) :: tmp
    real(8) :: tmp_1
    real(4) :: tmp_2
    t_0 = (1.0d0 / x) + 0.5d0
    if (x <= (-3.8d0)) then
        tmp_2 = x * 0.08333333333333333e0
        tmp_1 = ((t_0 * t_0) - (x * (x * 0.006944444444444444d0))) / ((1.0d0 / x) + (0.5d0 - real(real(tmp_2, 8), 8)))
    else
        tmp_1 = 0.5d0 + (((-0.001388888888888889d0) * (x ** 3.0d0)) + ((1.0d0 / x) + (x * 0.08333333333333333d0)))
    end if
    code = tmp_1
end function
function code(x)
	t_0 = Float64(Float64(1.0 / x) + 0.5)
	tmp_1 = 0.0
	if (x <= -3.8)
		tmp_2 = Float32(x * Float32(0.08333333333333333))
		tmp_1 = Float64(Float64(Float64(t_0 * t_0) - Float64(x * Float64(x * 0.006944444444444444))) / Float64(Float64(1.0 / x) + Float64(0.5 - Float64(Float64(tmp_2)))));
	else
		tmp_1 = Float64(0.5 + Float64(Float64(-0.001388888888888889 * (x ^ 3.0)) + Float64(Float64(1.0 / x) + Float64(x * 0.08333333333333333))));
	end
	return tmp_1
end
function tmp_4 = code(x)
	t_0 = (1.0 / x) + 0.5;
	tmp_2 = 0.0;
	if (x <= -3.8)
		tmp_3 = single((x * double(single(0.08333333333333333))));
		tmp_2 = ((t_0 * t_0) - (x * (x * 0.006944444444444444))) / ((1.0 / x) + (0.5 - double(double(tmp_3))));
	else
		tmp_2 = 0.5 + ((-0.001388888888888889 * (x ^ 3.0)) + ((1.0 / x) + (x * 0.08333333333333333)));
	end
	tmp_4 = tmp_2;
end
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{1}{x} + 0.5\\
\mathbf{if}\;x \leq -3.8:\\
\;\;\;\;\frac{t_0 \cdot t_0 - x \cdot \left(x \cdot 0.006944444444444444\right)}{\frac{1}{x} + \left(0.5 - \langle \left( x \cdot 0.08333333333333333 \right)_{\text{binary32}} \rangle_{\text{binary64}}\right)}\\

\mathbf{else}:\\
\;\;\;\;0.5 + \left(-0.001388888888888889 \cdot {x}^{3} + \left(\frac{1}{x} + x \cdot 0.08333333333333333\right)\right)\\


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

    1. Initial program 100.0%

      \[\frac{e^{x}}{e^{x} - 1} \]
    2. Step-by-step derivation
      1. expm1-def100.0%

        \[\leadsto \frac{e^{x}}{\color{blue}{\mathsf{expm1}\left(x\right)}} \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\frac{e^{x}}{\mathsf{expm1}\left(x\right)}} \]
    4. Taylor expanded in x around 0 2.5%

      \[\leadsto \color{blue}{0.5 + \left(0.08333333333333333 \cdot x + \frac{1}{x}\right)} \]
    5. Step-by-step derivation
      1. associate-+r+2.5%

        \[\leadsto \color{blue}{\left(0.5 + 0.08333333333333333 \cdot x\right) + \frac{1}{x}} \]
      2. +-commutative2.5%

        \[\leadsto \color{blue}{\frac{1}{x} + \left(0.5 + 0.08333333333333333 \cdot x\right)} \]
      3. +-commutative2.5%

        \[\leadsto \frac{1}{x} + \color{blue}{\left(0.08333333333333333 \cdot x + 0.5\right)} \]
      4. *-commutative2.5%

        \[\leadsto \frac{1}{x} + \left(\color{blue}{x \cdot 0.08333333333333333} + 0.5\right) \]
      5. fma-def2.5%

        \[\leadsto \frac{1}{x} + \color{blue}{\mathsf{fma}\left(x, 0.08333333333333333, 0.5\right)} \]
    6. Simplified2.5%

      \[\leadsto \color{blue}{\frac{1}{x} + \mathsf{fma}\left(x, 0.08333333333333333, 0.5\right)} \]
    7. Step-by-step derivation
      1. +-commutative2.5%

        \[\leadsto \color{blue}{\mathsf{fma}\left(x, 0.08333333333333333, 0.5\right) + \frac{1}{x}} \]
      2. fma-udef2.5%

        \[\leadsto \color{blue}{\left(x \cdot 0.08333333333333333 + 0.5\right)} + \frac{1}{x} \]
      3. *-commutative2.5%

        \[\leadsto \left(\color{blue}{0.08333333333333333 \cdot x} + 0.5\right) + \frac{1}{x} \]
      4. associate-+l+2.5%

        \[\leadsto \color{blue}{0.08333333333333333 \cdot x + \left(0.5 + \frac{1}{x}\right)} \]
      5. +-commutative2.5%

        \[\leadsto \color{blue}{\left(0.5 + \frac{1}{x}\right) + 0.08333333333333333 \cdot x} \]
      6. flip-+2.3%

        \[\leadsto \color{blue}{\frac{\left(0.5 + \frac{1}{x}\right) \cdot \left(0.5 + \frac{1}{x}\right) - \left(0.08333333333333333 \cdot x\right) \cdot \left(0.08333333333333333 \cdot x\right)}{\left(0.5 + \frac{1}{x}\right) - 0.08333333333333333 \cdot x}} \]
      7. +-commutative2.3%

        \[\leadsto \frac{\color{blue}{\left(\frac{1}{x} + 0.5\right)} \cdot \left(0.5 + \frac{1}{x}\right) - \left(0.08333333333333333 \cdot x\right) \cdot \left(0.08333333333333333 \cdot x\right)}{\left(0.5 + \frac{1}{x}\right) - 0.08333333333333333 \cdot x} \]
      8. +-commutative2.3%

        \[\leadsto \frac{\left(\frac{1}{x} + 0.5\right) \cdot \color{blue}{\left(\frac{1}{x} + 0.5\right)} - \left(0.08333333333333333 \cdot x\right) \cdot \left(0.08333333333333333 \cdot x\right)}{\left(0.5 + \frac{1}{x}\right) - 0.08333333333333333 \cdot x} \]
      9. swap-sqr2.3%

        \[\leadsto \frac{\left(\frac{1}{x} + 0.5\right) \cdot \left(\frac{1}{x} + 0.5\right) - \color{blue}{\left(0.08333333333333333 \cdot 0.08333333333333333\right) \cdot \left(x \cdot x\right)}}{\left(0.5 + \frac{1}{x}\right) - 0.08333333333333333 \cdot x} \]
      10. *-commutative2.3%

        \[\leadsto \frac{\left(\frac{1}{x} + 0.5\right) \cdot \left(\frac{1}{x} + 0.5\right) - \color{blue}{\left(x \cdot x\right) \cdot \left(0.08333333333333333 \cdot 0.08333333333333333\right)}}{\left(0.5 + \frac{1}{x}\right) - 0.08333333333333333 \cdot x} \]
      11. associate-*l*2.3%

        \[\leadsto \frac{\left(\frac{1}{x} + 0.5\right) \cdot \left(\frac{1}{x} + 0.5\right) - \color{blue}{x \cdot \left(x \cdot \left(0.08333333333333333 \cdot 0.08333333333333333\right)\right)}}{\left(0.5 + \frac{1}{x}\right) - 0.08333333333333333 \cdot x} \]
      12. metadata-eval2.3%

        \[\leadsto \frac{\left(\frac{1}{x} + 0.5\right) \cdot \left(\frac{1}{x} + 0.5\right) - x \cdot \left(x \cdot \color{blue}{0.006944444444444444}\right)}{\left(0.5 + \frac{1}{x}\right) - 0.08333333333333333 \cdot x} \]
      13. +-commutative2.3%

        \[\leadsto \frac{\left(\frac{1}{x} + 0.5\right) \cdot \left(\frac{1}{x} + 0.5\right) - x \cdot \left(x \cdot 0.006944444444444444\right)}{\color{blue}{\left(\frac{1}{x} + 0.5\right)} - 0.08333333333333333 \cdot x} \]
      14. *-commutative2.3%

        \[\leadsto \frac{\left(\frac{1}{x} + 0.5\right) \cdot \left(\frac{1}{x} + 0.5\right) - x \cdot \left(x \cdot 0.006944444444444444\right)}{\left(\frac{1}{x} + 0.5\right) - \color{blue}{x \cdot 0.08333333333333333}} \]
    8. Applied egg-rr2.3%

      \[\leadsto \color{blue}{\frac{\left(\frac{1}{x} + 0.5\right) \cdot \left(\frac{1}{x} + 0.5\right) - x \cdot \left(x \cdot 0.006944444444444444\right)}{\left(\frac{1}{x} + 0.5\right) - x \cdot 0.08333333333333333}} \]
    9. Step-by-step derivation
      1. cancel-sign-sub-inv2.3%

        \[\leadsto \frac{\left(\frac{1}{x} + 0.5\right) \cdot \left(\frac{1}{x} + 0.5\right) - x \cdot \left(x \cdot 0.006944444444444444\right)}{\color{blue}{\left(\frac{1}{x} + 0.5\right) + \left(-x\right) \cdot 0.08333333333333333}} \]
      2. associate-+l+2.3%

        \[\leadsto \frac{\left(\frac{1}{x} + 0.5\right) \cdot \left(\frac{1}{x} + 0.5\right) - x \cdot \left(x \cdot 0.006944444444444444\right)}{\color{blue}{\frac{1}{x} + \left(0.5 + \left(-x\right) \cdot 0.08333333333333333\right)}} \]
      3. cancel-sign-sub-inv2.3%

        \[\leadsto \frac{\left(\frac{1}{x} + 0.5\right) \cdot \left(\frac{1}{x} + 0.5\right) - x \cdot \left(x \cdot 0.006944444444444444\right)}{\frac{1}{x} + \color{blue}{\left(0.5 - x \cdot 0.08333333333333333\right)}} \]
    10. Simplified2.3%

      \[\leadsto \color{blue}{\frac{\left(\frac{1}{x} + 0.5\right) \cdot \left(\frac{1}{x} + 0.5\right) - x \cdot \left(x \cdot 0.006944444444444444\right)}{\frac{1}{x} + \left(0.5 - x \cdot 0.08333333333333333\right)}} \]
    11. Step-by-step derivation
      1. rewrite-binary64/binary3242.2%

        \[\leadsto \color{blue}{\frac{\left(\frac{1}{x} + 0.5\right) \cdot \left(\frac{1}{x} + 0.5\right) - x \cdot \left(x \cdot 0.006944444444444444\right)}{\frac{1}{x} + \left(0.5 - \langle \left( x \cdot 0.08333333333333333 \right)_{\text{binary32}} \rangle_{\text{binary64}}\right)}} \]
    12. Applied rewrite-once42.2%

      \[\leadsto \frac{\left(\frac{1}{x} + 0.5\right) \cdot \left(\frac{1}{x} + 0.5\right) - x \cdot \left(x \cdot 0.006944444444444444\right)}{\frac{1}{x} + \left(0.5 - \color{blue}{\langle \color{blue}{\left( \color{blue}{x \cdot 0.08333333333333333} \right)_{\text{binary32}}} \rangle_{\text{binary64}}}\right)} \]

    if -3.7999999999999998 < x

    1. Initial program 7.9%

      \[\frac{e^{x}}{e^{x} - 1} \]
    2. Step-by-step derivation
      1. expm1-def100.0%

        \[\leadsto \frac{e^{x}}{\color{blue}{\mathsf{expm1}\left(x\right)}} \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\frac{e^{x}}{\mathsf{expm1}\left(x\right)}} \]
    4. Taylor expanded in x around 0 99.5%

      \[\leadsto \color{blue}{0.5 + \left(-0.001388888888888889 \cdot {x}^{3} + \left(0.08333333333333333 \cdot x + \frac{1}{x}\right)\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification79.2%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -3.8:\\ \;\;\;\;\frac{\left(\frac{1}{x} + 0.5\right) \cdot \left(\frac{1}{x} + 0.5\right) - x \cdot \left(x \cdot 0.006944444444444444\right)}{\frac{1}{x} + \left(0.5 - \langle \left( x \cdot 0.08333333333333333 \right)_{\text{binary32}} \rangle_{\text{binary64}}\right)}\\ \mathbf{else}:\\ \;\;\;\;0.5 + \left(-0.001388888888888889 \cdot {x}^{3} + \left(\frac{1}{x} + x \cdot 0.08333333333333333\right)\right)\\ \end{array} \]

Alternative 3: 78.7% accurate, 1.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -3.8:\\ \;\;\;\;\frac{x \cdot \left(x \cdot -0.006944444444444444\right)}{0.5 - \langle \left( x \cdot 0.08333333333333333 \right)_{\text{binary32}} \rangle_{\text{binary64}}}\\ \mathbf{else}:\\ \;\;\;\;0.5 + \left(-0.001388888888888889 \cdot {x}^{3} + \left(\frac{1}{x} + x \cdot 0.08333333333333333\right)\right)\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (if (<= x -3.8)
   (/
    (* x (* x -0.006944444444444444))
    (- 0.5 (cast (! :precision binary32 (* x 0.08333333333333333)))))
   (+
    0.5
    (+
     (* -0.001388888888888889 (pow x 3.0))
     (+ (/ 1.0 x) (* x 0.08333333333333333))))))
double code(double x) {
	double tmp_1;
	if (x <= -3.8) {
		float tmp_2 = x * 0.08333333333333333f;
		tmp_1 = (x * (x * -0.006944444444444444)) / (0.5 - ((double) ((double) tmp_2)));
	} else {
		tmp_1 = 0.5 + ((-0.001388888888888889 * pow(x, 3.0)) + ((1.0 / x) + (x * 0.08333333333333333)));
	}
	return tmp_1;
}
real(8) function code(x)
    real(8), intent (in) :: x
    real(4) :: tmp
    real(8) :: tmp_1
    real(4) :: tmp_2
    if (x <= (-3.8d0)) then
        tmp_2 = x * 0.08333333333333333e0
        tmp_1 = (x * (x * (-0.006944444444444444d0))) / (0.5d0 - real(real(tmp_2, 8), 8))
    else
        tmp_1 = 0.5d0 + (((-0.001388888888888889d0) * (x ** 3.0d0)) + ((1.0d0 / x) + (x * 0.08333333333333333d0)))
    end if
    code = tmp_1
end function
function code(x)
	tmp_1 = 0.0
	if (x <= -3.8)
		tmp_2 = Float32(x * Float32(0.08333333333333333))
		tmp_1 = Float64(Float64(x * Float64(x * -0.006944444444444444)) / Float64(0.5 - Float64(Float64(tmp_2))));
	else
		tmp_1 = Float64(0.5 + Float64(Float64(-0.001388888888888889 * (x ^ 3.0)) + Float64(Float64(1.0 / x) + Float64(x * 0.08333333333333333))));
	end
	return tmp_1
end
function tmp_4 = code(x)
	tmp_2 = 0.0;
	if (x <= -3.8)
		tmp_3 = single((x * double(single(0.08333333333333333))));
		tmp_2 = (x * (x * -0.006944444444444444)) / (0.5 - double(double(tmp_3)));
	else
		tmp_2 = 0.5 + ((-0.001388888888888889 * (x ^ 3.0)) + ((1.0 / x) + (x * 0.08333333333333333)));
	end
	tmp_4 = tmp_2;
end
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.8:\\
\;\;\;\;\frac{x \cdot \left(x \cdot -0.006944444444444444\right)}{0.5 - \langle \left( x \cdot 0.08333333333333333 \right)_{\text{binary32}} \rangle_{\text{binary64}}}\\

\mathbf{else}:\\
\;\;\;\;0.5 + \left(-0.001388888888888889 \cdot {x}^{3} + \left(\frac{1}{x} + x \cdot 0.08333333333333333\right)\right)\\


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

    1. Initial program 100.0%

      \[\frac{e^{x}}{e^{x} - 1} \]
    2. Step-by-step derivation
      1. expm1-def100.0%

        \[\leadsto \frac{e^{x}}{\color{blue}{\mathsf{expm1}\left(x\right)}} \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\frac{e^{x}}{\mathsf{expm1}\left(x\right)}} \]
    4. Taylor expanded in x around 0 2.5%

      \[\leadsto \color{blue}{0.5 + \left(0.08333333333333333 \cdot x + \frac{1}{x}\right)} \]
    5. Step-by-step derivation
      1. associate-+r+2.5%

        \[\leadsto \color{blue}{\left(0.5 + 0.08333333333333333 \cdot x\right) + \frac{1}{x}} \]
      2. +-commutative2.5%

        \[\leadsto \color{blue}{\frac{1}{x} + \left(0.5 + 0.08333333333333333 \cdot x\right)} \]
      3. +-commutative2.5%

        \[\leadsto \frac{1}{x} + \color{blue}{\left(0.08333333333333333 \cdot x + 0.5\right)} \]
      4. *-commutative2.5%

        \[\leadsto \frac{1}{x} + \left(\color{blue}{x \cdot 0.08333333333333333} + 0.5\right) \]
      5. fma-def2.5%

        \[\leadsto \frac{1}{x} + \color{blue}{\mathsf{fma}\left(x, 0.08333333333333333, 0.5\right)} \]
    6. Simplified2.5%

      \[\leadsto \color{blue}{\frac{1}{x} + \mathsf{fma}\left(x, 0.08333333333333333, 0.5\right)} \]
    7. Step-by-step derivation
      1. +-commutative2.5%

        \[\leadsto \color{blue}{\mathsf{fma}\left(x, 0.08333333333333333, 0.5\right) + \frac{1}{x}} \]
      2. fma-udef2.5%

        \[\leadsto \color{blue}{\left(x \cdot 0.08333333333333333 + 0.5\right)} + \frac{1}{x} \]
      3. *-commutative2.5%

        \[\leadsto \left(\color{blue}{0.08333333333333333 \cdot x} + 0.5\right) + \frac{1}{x} \]
      4. associate-+l+2.5%

        \[\leadsto \color{blue}{0.08333333333333333 \cdot x + \left(0.5 + \frac{1}{x}\right)} \]
      5. +-commutative2.5%

        \[\leadsto \color{blue}{\left(0.5 + \frac{1}{x}\right) + 0.08333333333333333 \cdot x} \]
      6. flip-+2.3%

        \[\leadsto \color{blue}{\frac{\left(0.5 + \frac{1}{x}\right) \cdot \left(0.5 + \frac{1}{x}\right) - \left(0.08333333333333333 \cdot x\right) \cdot \left(0.08333333333333333 \cdot x\right)}{\left(0.5 + \frac{1}{x}\right) - 0.08333333333333333 \cdot x}} \]
      7. +-commutative2.3%

        \[\leadsto \frac{\color{blue}{\left(\frac{1}{x} + 0.5\right)} \cdot \left(0.5 + \frac{1}{x}\right) - \left(0.08333333333333333 \cdot x\right) \cdot \left(0.08333333333333333 \cdot x\right)}{\left(0.5 + \frac{1}{x}\right) - 0.08333333333333333 \cdot x} \]
      8. +-commutative2.3%

        \[\leadsto \frac{\left(\frac{1}{x} + 0.5\right) \cdot \color{blue}{\left(\frac{1}{x} + 0.5\right)} - \left(0.08333333333333333 \cdot x\right) \cdot \left(0.08333333333333333 \cdot x\right)}{\left(0.5 + \frac{1}{x}\right) - 0.08333333333333333 \cdot x} \]
      9. swap-sqr2.3%

        \[\leadsto \frac{\left(\frac{1}{x} + 0.5\right) \cdot \left(\frac{1}{x} + 0.5\right) - \color{blue}{\left(0.08333333333333333 \cdot 0.08333333333333333\right) \cdot \left(x \cdot x\right)}}{\left(0.5 + \frac{1}{x}\right) - 0.08333333333333333 \cdot x} \]
      10. *-commutative2.3%

        \[\leadsto \frac{\left(\frac{1}{x} + 0.5\right) \cdot \left(\frac{1}{x} + 0.5\right) - \color{blue}{\left(x \cdot x\right) \cdot \left(0.08333333333333333 \cdot 0.08333333333333333\right)}}{\left(0.5 + \frac{1}{x}\right) - 0.08333333333333333 \cdot x} \]
      11. associate-*l*2.3%

        \[\leadsto \frac{\left(\frac{1}{x} + 0.5\right) \cdot \left(\frac{1}{x} + 0.5\right) - \color{blue}{x \cdot \left(x \cdot \left(0.08333333333333333 \cdot 0.08333333333333333\right)\right)}}{\left(0.5 + \frac{1}{x}\right) - 0.08333333333333333 \cdot x} \]
      12. metadata-eval2.3%

        \[\leadsto \frac{\left(\frac{1}{x} + 0.5\right) \cdot \left(\frac{1}{x} + 0.5\right) - x \cdot \left(x \cdot \color{blue}{0.006944444444444444}\right)}{\left(0.5 + \frac{1}{x}\right) - 0.08333333333333333 \cdot x} \]
      13. +-commutative2.3%

        \[\leadsto \frac{\left(\frac{1}{x} + 0.5\right) \cdot \left(\frac{1}{x} + 0.5\right) - x \cdot \left(x \cdot 0.006944444444444444\right)}{\color{blue}{\left(\frac{1}{x} + 0.5\right)} - 0.08333333333333333 \cdot x} \]
      14. *-commutative2.3%

        \[\leadsto \frac{\left(\frac{1}{x} + 0.5\right) \cdot \left(\frac{1}{x} + 0.5\right) - x \cdot \left(x \cdot 0.006944444444444444\right)}{\left(\frac{1}{x} + 0.5\right) - \color{blue}{x \cdot 0.08333333333333333}} \]
    8. Applied egg-rr2.3%

      \[\leadsto \color{blue}{\frac{\left(\frac{1}{x} + 0.5\right) \cdot \left(\frac{1}{x} + 0.5\right) - x \cdot \left(x \cdot 0.006944444444444444\right)}{\left(\frac{1}{x} + 0.5\right) - x \cdot 0.08333333333333333}} \]
    9. Step-by-step derivation
      1. cancel-sign-sub-inv2.3%

        \[\leadsto \frac{\left(\frac{1}{x} + 0.5\right) \cdot \left(\frac{1}{x} + 0.5\right) - x \cdot \left(x \cdot 0.006944444444444444\right)}{\color{blue}{\left(\frac{1}{x} + 0.5\right) + \left(-x\right) \cdot 0.08333333333333333}} \]
      2. associate-+l+2.3%

        \[\leadsto \frac{\left(\frac{1}{x} + 0.5\right) \cdot \left(\frac{1}{x} + 0.5\right) - x \cdot \left(x \cdot 0.006944444444444444\right)}{\color{blue}{\frac{1}{x} + \left(0.5 + \left(-x\right) \cdot 0.08333333333333333\right)}} \]
      3. cancel-sign-sub-inv2.3%

        \[\leadsto \frac{\left(\frac{1}{x} + 0.5\right) \cdot \left(\frac{1}{x} + 0.5\right) - x \cdot \left(x \cdot 0.006944444444444444\right)}{\frac{1}{x} + \color{blue}{\left(0.5 - x \cdot 0.08333333333333333\right)}} \]
    10. Simplified2.3%

      \[\leadsto \color{blue}{\frac{\left(\frac{1}{x} + 0.5\right) \cdot \left(\frac{1}{x} + 0.5\right) - x \cdot \left(x \cdot 0.006944444444444444\right)}{\frac{1}{x} + \left(0.5 - x \cdot 0.08333333333333333\right)}} \]
    11. Step-by-step derivation
      1. rewrite-binary64/binary3242.2%

        \[\leadsto \color{blue}{\frac{\left(\frac{1}{x} + 0.5\right) \cdot \left(\frac{1}{x} + 0.5\right) - x \cdot \left(x \cdot 0.006944444444444444\right)}{\frac{1}{x} + \left(0.5 - \langle \left( x \cdot 0.08333333333333333 \right)_{\text{binary32}} \rangle_{\text{binary64}}\right)}} \]
    12. Applied rewrite-once42.2%

      \[\leadsto \frac{\left(\frac{1}{x} + 0.5\right) \cdot \left(\frac{1}{x} + 0.5\right) - x \cdot \left(x \cdot 0.006944444444444444\right)}{\frac{1}{x} + \left(0.5 - \color{blue}{\langle \color{blue}{\left( \color{blue}{x \cdot 0.08333333333333333} \right)_{\text{binary32}}} \rangle_{\text{binary64}}}\right)} \]
    13. Taylor expanded in x around inf 42.2%

      \[\leadsto \color{blue}{-0.006944444444444444 \cdot \frac{{x}^{2}}{0.5 - \langle \left( 0.08333333333333333 \cdot x \right)_{\text{binary32}} \rangle_{\text{binary64}}}} \]
    14. Step-by-step derivation
      1. associate-*r/42.2%

        \[\leadsto \color{blue}{\frac{-0.006944444444444444 \cdot {x}^{2}}{0.5 - \langle \left( 0.08333333333333333 \cdot x \right)_{\text{binary32}} \rangle_{\text{binary64}}}} \]
      2. unpow242.2%

        \[\leadsto \frac{-0.006944444444444444 \cdot \color{blue}{\left(x \cdot x\right)}}{0.5 - \langle \left( 0.08333333333333333 \cdot x \right)_{\text{binary32}} \rangle_{\text{binary64}}} \]
      3. *-commutative42.2%

        \[\leadsto \frac{\color{blue}{\left(x \cdot x\right) \cdot -0.006944444444444444}}{0.5 - \langle \left( 0.08333333333333333 \cdot x \right)_{\text{binary32}} \rangle_{\text{binary64}}} \]
      4. associate-*l*42.2%

        \[\leadsto \frac{\color{blue}{x \cdot \left(x \cdot -0.006944444444444444\right)}}{0.5 - \langle \left( 0.08333333333333333 \cdot x \right)_{\text{binary32}} \rangle_{\text{binary64}}} \]
    15. Simplified42.2%

      \[\leadsto \color{blue}{\frac{x \cdot \left(x \cdot -0.006944444444444444\right)}{0.5 - \langle \left( 0.08333333333333333 \cdot x \right)_{\text{binary32}} \rangle_{\text{binary64}}}} \]

    if -3.7999999999999998 < x

    1. Initial program 7.9%

      \[\frac{e^{x}}{e^{x} - 1} \]
    2. Step-by-step derivation
      1. expm1-def100.0%

        \[\leadsto \frac{e^{x}}{\color{blue}{\mathsf{expm1}\left(x\right)}} \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\frac{e^{x}}{\mathsf{expm1}\left(x\right)}} \]
    4. Taylor expanded in x around 0 99.5%

      \[\leadsto \color{blue}{0.5 + \left(-0.001388888888888889 \cdot {x}^{3} + \left(0.08333333333333333 \cdot x + \frac{1}{x}\right)\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification79.2%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -3.8:\\ \;\;\;\;\frac{x \cdot \left(x \cdot -0.006944444444444444\right)}{0.5 - \langle \left( x \cdot 0.08333333333333333 \right)_{\text{binary32}} \rangle_{\text{binary64}}}\\ \mathbf{else}:\\ \;\;\;\;0.5 + \left(-0.001388888888888889 \cdot {x}^{3} + \left(\frac{1}{x} + x \cdot 0.08333333333333333\right)\right)\\ \end{array} \]

Alternative 4: 71.5% accurate, 1.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{1}{x} + 0.5\\ \mathbf{if}\;x \leq -3.8:\\ \;\;\;\;\frac{t_0 \cdot t_0 - x \cdot \left(x \cdot 0.006944444444444444\right)}{\frac{1}{x} + \left(0.5 - \sqrt[3]{\left(x \cdot 0.08333333333333333\right) \cdot \left(\left(x \cdot 0.08333333333333333\right) \cdot \left(x \cdot 0.08333333333333333\right)\right)}\right)}\\ \mathbf{else}:\\ \;\;\;\;0.5 + \left(-0.001388888888888889 \cdot {x}^{3} + \left(\frac{1}{x} + x \cdot 0.08333333333333333\right)\right)\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (let* ((t_0 (+ (/ 1.0 x) 0.5)))
   (if (<= x -3.8)
     (/
      (- (* t_0 t_0) (* x (* x 0.006944444444444444)))
      (+
       (/ 1.0 x)
       (-
        0.5
        (cbrt
         (*
          (* x 0.08333333333333333)
          (* (* x 0.08333333333333333) (* x 0.08333333333333333)))))))
     (+
      0.5
      (+
       (* -0.001388888888888889 (pow x 3.0))
       (+ (/ 1.0 x) (* x 0.08333333333333333)))))))
double code(double x) {
	double t_0 = (1.0 / x) + 0.5;
	double tmp;
	if (x <= -3.8) {
		tmp = ((t_0 * t_0) - (x * (x * 0.006944444444444444))) / ((1.0 / x) + (0.5 - cbrt(((x * 0.08333333333333333) * ((x * 0.08333333333333333) * (x * 0.08333333333333333))))));
	} else {
		tmp = 0.5 + ((-0.001388888888888889 * pow(x, 3.0)) + ((1.0 / x) + (x * 0.08333333333333333)));
	}
	return tmp;
}
public static double code(double x) {
	double t_0 = (1.0 / x) + 0.5;
	double tmp;
	if (x <= -3.8) {
		tmp = ((t_0 * t_0) - (x * (x * 0.006944444444444444))) / ((1.0 / x) + (0.5 - Math.cbrt(((x * 0.08333333333333333) * ((x * 0.08333333333333333) * (x * 0.08333333333333333))))));
	} else {
		tmp = 0.5 + ((-0.001388888888888889 * Math.pow(x, 3.0)) + ((1.0 / x) + (x * 0.08333333333333333)));
	}
	return tmp;
}
function code(x)
	t_0 = Float64(Float64(1.0 / x) + 0.5)
	tmp = 0.0
	if (x <= -3.8)
		tmp = Float64(Float64(Float64(t_0 * t_0) - Float64(x * Float64(x * 0.006944444444444444))) / Float64(Float64(1.0 / x) + Float64(0.5 - cbrt(Float64(Float64(x * 0.08333333333333333) * Float64(Float64(x * 0.08333333333333333) * Float64(x * 0.08333333333333333)))))));
	else
		tmp = Float64(0.5 + Float64(Float64(-0.001388888888888889 * (x ^ 3.0)) + Float64(Float64(1.0 / x) + Float64(x * 0.08333333333333333))));
	end
	return tmp
end
code[x_] := Block[{t$95$0 = N[(N[(1.0 / x), $MachinePrecision] + 0.5), $MachinePrecision]}, If[LessEqual[x, -3.8], N[(N[(N[(t$95$0 * t$95$0), $MachinePrecision] - N[(x * N[(x * 0.006944444444444444), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(N[(1.0 / x), $MachinePrecision] + N[(0.5 - N[Power[N[(N[(x * 0.08333333333333333), $MachinePrecision] * N[(N[(x * 0.08333333333333333), $MachinePrecision] * N[(x * 0.08333333333333333), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 + N[(N[(-0.001388888888888889 * N[Power[x, 3.0], $MachinePrecision]), $MachinePrecision] + N[(N[(1.0 / x), $MachinePrecision] + N[(x * 0.08333333333333333), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{1}{x} + 0.5\\
\mathbf{if}\;x \leq -3.8:\\
\;\;\;\;\frac{t_0 \cdot t_0 - x \cdot \left(x \cdot 0.006944444444444444\right)}{\frac{1}{x} + \left(0.5 - \sqrt[3]{\left(x \cdot 0.08333333333333333\right) \cdot \left(\left(x \cdot 0.08333333333333333\right) \cdot \left(x \cdot 0.08333333333333333\right)\right)}\right)}\\

\mathbf{else}:\\
\;\;\;\;0.5 + \left(-0.001388888888888889 \cdot {x}^{3} + \left(\frac{1}{x} + x \cdot 0.08333333333333333\right)\right)\\


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

    1. Initial program 100.0%

      \[\frac{e^{x}}{e^{x} - 1} \]
    2. Step-by-step derivation
      1. expm1-def100.0%

        \[\leadsto \frac{e^{x}}{\color{blue}{\mathsf{expm1}\left(x\right)}} \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\frac{e^{x}}{\mathsf{expm1}\left(x\right)}} \]
    4. Taylor expanded in x around 0 2.5%

      \[\leadsto \color{blue}{0.5 + \left(0.08333333333333333 \cdot x + \frac{1}{x}\right)} \]
    5. Step-by-step derivation
      1. associate-+r+2.5%

        \[\leadsto \color{blue}{\left(0.5 + 0.08333333333333333 \cdot x\right) + \frac{1}{x}} \]
      2. +-commutative2.5%

        \[\leadsto \color{blue}{\frac{1}{x} + \left(0.5 + 0.08333333333333333 \cdot x\right)} \]
      3. +-commutative2.5%

        \[\leadsto \frac{1}{x} + \color{blue}{\left(0.08333333333333333 \cdot x + 0.5\right)} \]
      4. *-commutative2.5%

        \[\leadsto \frac{1}{x} + \left(\color{blue}{x \cdot 0.08333333333333333} + 0.5\right) \]
      5. fma-def2.5%

        \[\leadsto \frac{1}{x} + \color{blue}{\mathsf{fma}\left(x, 0.08333333333333333, 0.5\right)} \]
    6. Simplified2.5%

      \[\leadsto \color{blue}{\frac{1}{x} + \mathsf{fma}\left(x, 0.08333333333333333, 0.5\right)} \]
    7. Step-by-step derivation
      1. +-commutative2.5%

        \[\leadsto \color{blue}{\mathsf{fma}\left(x, 0.08333333333333333, 0.5\right) + \frac{1}{x}} \]
      2. fma-udef2.5%

        \[\leadsto \color{blue}{\left(x \cdot 0.08333333333333333 + 0.5\right)} + \frac{1}{x} \]
      3. *-commutative2.5%

        \[\leadsto \left(\color{blue}{0.08333333333333333 \cdot x} + 0.5\right) + \frac{1}{x} \]
      4. associate-+l+2.5%

        \[\leadsto \color{blue}{0.08333333333333333 \cdot x + \left(0.5 + \frac{1}{x}\right)} \]
      5. +-commutative2.5%

        \[\leadsto \color{blue}{\left(0.5 + \frac{1}{x}\right) + 0.08333333333333333 \cdot x} \]
      6. flip-+2.3%

        \[\leadsto \color{blue}{\frac{\left(0.5 + \frac{1}{x}\right) \cdot \left(0.5 + \frac{1}{x}\right) - \left(0.08333333333333333 \cdot x\right) \cdot \left(0.08333333333333333 \cdot x\right)}{\left(0.5 + \frac{1}{x}\right) - 0.08333333333333333 \cdot x}} \]
      7. +-commutative2.3%

        \[\leadsto \frac{\color{blue}{\left(\frac{1}{x} + 0.5\right)} \cdot \left(0.5 + \frac{1}{x}\right) - \left(0.08333333333333333 \cdot x\right) \cdot \left(0.08333333333333333 \cdot x\right)}{\left(0.5 + \frac{1}{x}\right) - 0.08333333333333333 \cdot x} \]
      8. +-commutative2.3%

        \[\leadsto \frac{\left(\frac{1}{x} + 0.5\right) \cdot \color{blue}{\left(\frac{1}{x} + 0.5\right)} - \left(0.08333333333333333 \cdot x\right) \cdot \left(0.08333333333333333 \cdot x\right)}{\left(0.5 + \frac{1}{x}\right) - 0.08333333333333333 \cdot x} \]
      9. swap-sqr2.3%

        \[\leadsto \frac{\left(\frac{1}{x} + 0.5\right) \cdot \left(\frac{1}{x} + 0.5\right) - \color{blue}{\left(0.08333333333333333 \cdot 0.08333333333333333\right) \cdot \left(x \cdot x\right)}}{\left(0.5 + \frac{1}{x}\right) - 0.08333333333333333 \cdot x} \]
      10. *-commutative2.3%

        \[\leadsto \frac{\left(\frac{1}{x} + 0.5\right) \cdot \left(\frac{1}{x} + 0.5\right) - \color{blue}{\left(x \cdot x\right) \cdot \left(0.08333333333333333 \cdot 0.08333333333333333\right)}}{\left(0.5 + \frac{1}{x}\right) - 0.08333333333333333 \cdot x} \]
      11. associate-*l*2.3%

        \[\leadsto \frac{\left(\frac{1}{x} + 0.5\right) \cdot \left(\frac{1}{x} + 0.5\right) - \color{blue}{x \cdot \left(x \cdot \left(0.08333333333333333 \cdot 0.08333333333333333\right)\right)}}{\left(0.5 + \frac{1}{x}\right) - 0.08333333333333333 \cdot x} \]
      12. metadata-eval2.3%

        \[\leadsto \frac{\left(\frac{1}{x} + 0.5\right) \cdot \left(\frac{1}{x} + 0.5\right) - x \cdot \left(x \cdot \color{blue}{0.006944444444444444}\right)}{\left(0.5 + \frac{1}{x}\right) - 0.08333333333333333 \cdot x} \]
      13. +-commutative2.3%

        \[\leadsto \frac{\left(\frac{1}{x} + 0.5\right) \cdot \left(\frac{1}{x} + 0.5\right) - x \cdot \left(x \cdot 0.006944444444444444\right)}{\color{blue}{\left(\frac{1}{x} + 0.5\right)} - 0.08333333333333333 \cdot x} \]
      14. *-commutative2.3%

        \[\leadsto \frac{\left(\frac{1}{x} + 0.5\right) \cdot \left(\frac{1}{x} + 0.5\right) - x \cdot \left(x \cdot 0.006944444444444444\right)}{\left(\frac{1}{x} + 0.5\right) - \color{blue}{x \cdot 0.08333333333333333}} \]
    8. Applied egg-rr2.3%

      \[\leadsto \color{blue}{\frac{\left(\frac{1}{x} + 0.5\right) \cdot \left(\frac{1}{x} + 0.5\right) - x \cdot \left(x \cdot 0.006944444444444444\right)}{\left(\frac{1}{x} + 0.5\right) - x \cdot 0.08333333333333333}} \]
    9. Step-by-step derivation
      1. cancel-sign-sub-inv2.3%

        \[\leadsto \frac{\left(\frac{1}{x} + 0.5\right) \cdot \left(\frac{1}{x} + 0.5\right) - x \cdot \left(x \cdot 0.006944444444444444\right)}{\color{blue}{\left(\frac{1}{x} + 0.5\right) + \left(-x\right) \cdot 0.08333333333333333}} \]
      2. associate-+l+2.3%

        \[\leadsto \frac{\left(\frac{1}{x} + 0.5\right) \cdot \left(\frac{1}{x} + 0.5\right) - x \cdot \left(x \cdot 0.006944444444444444\right)}{\color{blue}{\frac{1}{x} + \left(0.5 + \left(-x\right) \cdot 0.08333333333333333\right)}} \]
      3. cancel-sign-sub-inv2.3%

        \[\leadsto \frac{\left(\frac{1}{x} + 0.5\right) \cdot \left(\frac{1}{x} + 0.5\right) - x \cdot \left(x \cdot 0.006944444444444444\right)}{\frac{1}{x} + \color{blue}{\left(0.5 - x \cdot 0.08333333333333333\right)}} \]
    10. Simplified2.3%

      \[\leadsto \color{blue}{\frac{\left(\frac{1}{x} + 0.5\right) \cdot \left(\frac{1}{x} + 0.5\right) - x \cdot \left(x \cdot 0.006944444444444444\right)}{\frac{1}{x} + \left(0.5 - x \cdot 0.08333333333333333\right)}} \]
    11. Step-by-step derivation
      1. add-cbrt-cube_binary6418.7%

        \[\leadsto \color{blue}{\frac{\left(\frac{1}{x} + 0.5\right) \cdot \left(\frac{1}{x} + 0.5\right) - x \cdot \left(x \cdot 0.006944444444444444\right)}{\frac{1}{x} + \left(0.5 - \sqrt[3]{\left(\left(x \cdot 0.08333333333333333\right) \cdot \left(x \cdot 0.08333333333333333\right)\right) \cdot \left(x \cdot 0.08333333333333333\right)}\right)}} \]
    12. Applied rewrite-once18.7%

      \[\leadsto \frac{\left(\frac{1}{x} + 0.5\right) \cdot \left(\frac{1}{x} + 0.5\right) - x \cdot \left(x \cdot 0.006944444444444444\right)}{\frac{1}{x} + \left(0.5 - \color{blue}{\sqrt[3]{\left(\left(x \cdot 0.08333333333333333\right) \cdot \left(x \cdot 0.08333333333333333\right)\right) \cdot \left(x \cdot 0.08333333333333333\right)}}\right)} \]

    if -3.7999999999999998 < x

    1. Initial program 7.9%

      \[\frac{e^{x}}{e^{x} - 1} \]
    2. Step-by-step derivation
      1. expm1-def100.0%

        \[\leadsto \frac{e^{x}}{\color{blue}{\mathsf{expm1}\left(x\right)}} \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\frac{e^{x}}{\mathsf{expm1}\left(x\right)}} \]
    4. Taylor expanded in x around 0 99.5%

      \[\leadsto \color{blue}{0.5 + \left(-0.001388888888888889 \cdot {x}^{3} + \left(0.08333333333333333 \cdot x + \frac{1}{x}\right)\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification70.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -3.8:\\ \;\;\;\;\frac{\left(\frac{1}{x} + 0.5\right) \cdot \left(\frac{1}{x} + 0.5\right) - x \cdot \left(x \cdot 0.006944444444444444\right)}{\frac{1}{x} + \left(0.5 - \sqrt[3]{\left(x \cdot 0.08333333333333333\right) \cdot \left(\left(x \cdot 0.08333333333333333\right) \cdot \left(x \cdot 0.08333333333333333\right)\right)}\right)}\\ \mathbf{else}:\\ \;\;\;\;0.5 + \left(-0.001388888888888889 \cdot {x}^{3} + \left(\frac{1}{x} + x \cdot 0.08333333333333333\right)\right)\\ \end{array} \]

Alternative 5: 66.1% accurate, 1.8× speedup?

\[\begin{array}{l} \\ 0.5 + \left(-0.001388888888888889 \cdot {x}^{3} + \left(\frac{1}{x} + x \cdot 0.08333333333333333\right)\right) \end{array} \]
(FPCore (x)
 :precision binary64
 (+
  0.5
  (+
   (* -0.001388888888888889 (pow x 3.0))
   (+ (/ 1.0 x) (* x 0.08333333333333333)))))
double code(double x) {
	return 0.5 + ((-0.001388888888888889 * pow(x, 3.0)) + ((1.0 / x) + (x * 0.08333333333333333)));
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = 0.5d0 + (((-0.001388888888888889d0) * (x ** 3.0d0)) + ((1.0d0 / x) + (x * 0.08333333333333333d0)))
end function
public static double code(double x) {
	return 0.5 + ((-0.001388888888888889 * Math.pow(x, 3.0)) + ((1.0 / x) + (x * 0.08333333333333333)));
}
def code(x):
	return 0.5 + ((-0.001388888888888889 * math.pow(x, 3.0)) + ((1.0 / x) + (x * 0.08333333333333333)))
function code(x)
	return Float64(0.5 + Float64(Float64(-0.001388888888888889 * (x ^ 3.0)) + Float64(Float64(1.0 / x) + Float64(x * 0.08333333333333333))))
end
function tmp = code(x)
	tmp = 0.5 + ((-0.001388888888888889 * (x ^ 3.0)) + ((1.0 / x) + (x * 0.08333333333333333)));
end
code[x_] := N[(0.5 + N[(N[(-0.001388888888888889 * N[Power[x, 3.0], $MachinePrecision]), $MachinePrecision] + N[(N[(1.0 / x), $MachinePrecision] + N[(x * 0.08333333333333333), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
0.5 + \left(-0.001388888888888889 \cdot {x}^{3} + \left(\frac{1}{x} + x \cdot 0.08333333333333333\right)\right)
\end{array}
Derivation
  1. Initial program 40.7%

    \[\frac{e^{x}}{e^{x} - 1} \]
  2. Step-by-step derivation
    1. expm1-def100.0%

      \[\leadsto \frac{e^{x}}{\color{blue}{\mathsf{expm1}\left(x\right)}} \]
  3. Simplified100.0%

    \[\leadsto \color{blue}{\frac{e^{x}}{\mathsf{expm1}\left(x\right)}} \]
  4. Taylor expanded in x around 0 64.8%

    \[\leadsto \color{blue}{0.5 + \left(-0.001388888888888889 \cdot {x}^{3} + \left(0.08333333333333333 \cdot x + \frac{1}{x}\right)\right)} \]
  5. Final simplification64.8%

    \[\leadsto 0.5 + \left(-0.001388888888888889 \cdot {x}^{3} + \left(\frac{1}{x} + x \cdot 0.08333333333333333\right)\right) \]

Alternative 6: 66.3% accurate, 22.8× speedup?

\[\begin{array}{l} \\ 0.5 + \left(\frac{1}{x} + x \cdot 0.08333333333333333\right) \end{array} \]
(FPCore (x)
 :precision binary64
 (+ 0.5 (+ (/ 1.0 x) (* x 0.08333333333333333))))
double code(double x) {
	return 0.5 + ((1.0 / x) + (x * 0.08333333333333333));
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = 0.5d0 + ((1.0d0 / x) + (x * 0.08333333333333333d0))
end function
public static double code(double x) {
	return 0.5 + ((1.0 / x) + (x * 0.08333333333333333));
}
def code(x):
	return 0.5 + ((1.0 / x) + (x * 0.08333333333333333))
function code(x)
	return Float64(0.5 + Float64(Float64(1.0 / x) + Float64(x * 0.08333333333333333)))
end
function tmp = code(x)
	tmp = 0.5 + ((1.0 / x) + (x * 0.08333333333333333));
end
code[x_] := N[(0.5 + N[(N[(1.0 / x), $MachinePrecision] + N[(x * 0.08333333333333333), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
0.5 + \left(\frac{1}{x} + x \cdot 0.08333333333333333\right)
\end{array}
Derivation
  1. Initial program 40.7%

    \[\frac{e^{x}}{e^{x} - 1} \]
  2. Step-by-step derivation
    1. expm1-def100.0%

      \[\leadsto \frac{e^{x}}{\color{blue}{\mathsf{expm1}\left(x\right)}} \]
  3. Simplified100.0%

    \[\leadsto \color{blue}{\frac{e^{x}}{\mathsf{expm1}\left(x\right)}} \]
  4. Taylor expanded in x around 0 64.7%

    \[\leadsto \color{blue}{0.5 + \left(0.08333333333333333 \cdot x + \frac{1}{x}\right)} \]
  5. Final simplification64.7%

    \[\leadsto 0.5 + \left(\frac{1}{x} + x \cdot 0.08333333333333333\right) \]

Alternative 7: 66.1% accurate, 68.3× speedup?

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

\\
\frac{1}{x}
\end{array}
Derivation
  1. Initial program 40.7%

    \[\frac{e^{x}}{e^{x} - 1} \]
  2. Step-by-step derivation
    1. expm1-def100.0%

      \[\leadsto \frac{e^{x}}{\color{blue}{\mathsf{expm1}\left(x\right)}} \]
  3. Simplified100.0%

    \[\leadsto \color{blue}{\frac{e^{x}}{\mathsf{expm1}\left(x\right)}} \]
  4. Taylor expanded in x around 0 64.2%

    \[\leadsto \color{blue}{\frac{1}{x}} \]
  5. Final simplification64.2%

    \[\leadsto \frac{1}{x} \]

Alternative 8: 3.2% accurate, 205.0× speedup?

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

\\
-2
\end{array}
Derivation
  1. Initial program 40.7%

    \[\frac{e^{x}}{e^{x} - 1} \]
  2. Step-by-step derivation
    1. expm1-def100.0%

      \[\leadsto \frac{e^{x}}{\color{blue}{\mathsf{expm1}\left(x\right)}} \]
  3. Simplified100.0%

    \[\leadsto \color{blue}{\frac{e^{x}}{\mathsf{expm1}\left(x\right)}} \]
  4. Applied egg-rr3.1%

    \[\leadsto \color{blue}{-2} \]
  5. Final simplification3.1%

    \[\leadsto -2 \]

Alternative 9: 3.2% accurate, 205.0× speedup?

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

\\
-1
\end{array}
Derivation
  1. Initial program 40.7%

    \[\frac{e^{x}}{e^{x} - 1} \]
  2. Step-by-step derivation
    1. expm1-def100.0%

      \[\leadsto \frac{e^{x}}{\color{blue}{\mathsf{expm1}\left(x\right)}} \]
  3. Simplified100.0%

    \[\leadsto \color{blue}{\frac{e^{x}}{\mathsf{expm1}\left(x\right)}} \]
  4. Applied egg-rr3.1%

    \[\leadsto \color{blue}{-1} \]
  5. Final simplification3.1%

    \[\leadsto -1 \]

Alternative 10: 4.0% accurate, 205.0× speedup?

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

\\
1
\end{array}
Derivation
  1. Initial program 40.7%

    \[\frac{e^{x}}{e^{x} - 1} \]
  2. Step-by-step derivation
    1. expm1-def100.0%

      \[\leadsto \frac{e^{x}}{\color{blue}{\mathsf{expm1}\left(x\right)}} \]
  3. Simplified100.0%

    \[\leadsto \color{blue}{\frac{e^{x}}{\mathsf{expm1}\left(x\right)}} \]
  4. Applied egg-rr3.4%

    \[\leadsto \color{blue}{1} \]
  5. Final simplification3.4%

    \[\leadsto 1 \]

Developer target: 38.5% accurate, 1.9× speedup?

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

\\
\frac{1}{1 - e^{-x}}
\end{array}

Reproduce

?
herbie shell --seed 2023297 
(FPCore (x)
  :name "expq2 (section 3.11)"
  :precision binary64

  :herbie-target
  (/ 1.0 (- 1.0 (exp (- x))))

  (/ (exp x) (- (exp x) 1.0)))