expm1 (example 3.7)

Percentage Accurate: 8.2% → 100.0%
Time: 7.5s
Alternatives: 10
Speedup: 103.0×

Specification

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

\\
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: 8.2% accurate, 1.0× speedup?

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

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

Alternative 1: 100.0% accurate, 1.0× speedup?

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

\\
\mathsf{expm1}\left(x\right)
\end{array}
Derivation
  1. Initial program 8.1%

    \[e^{x} - 1 \]
  2. Step-by-step derivation
    1. expm1-defineN/A

      \[\leadsto \mathsf{expm1}\left(x\right) \]
    2. expm1-lowering-expm1.f64100.0%

      \[\leadsto \mathsf{expm1.f64}\left(x\right) \]
  3. Simplified100.0%

    \[\leadsto \color{blue}{\mathsf{expm1}\left(x\right)} \]
  4. Add Preprocessing
  5. Add Preprocessing

Alternative 2: 99.6% accurate, 2.2× speedup?

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

\\
\begin{array}{l}
t_0 := -0.5 + x \cdot 0.08333333333333333\\
t_1 := x \cdot t\_0\\
\frac{x}{1 + t\_1 \cdot \left(\left(x \cdot x\right) \cdot \left(t\_0 \cdot t\_0\right)\right)} \cdot \left(1 + t\_1 \cdot \left(t\_1 + -1\right)\right)
\end{array}
\end{array}
Derivation
  1. Initial program 8.1%

    \[e^{x} - 1 \]
  2. Step-by-step derivation
    1. expm1-defineN/A

      \[\leadsto \mathsf{expm1}\left(x\right) \]
    2. expm1-lowering-expm1.f64100.0%

      \[\leadsto \mathsf{expm1.f64}\left(x\right) \]
  3. Simplified100.0%

    \[\leadsto \color{blue}{\mathsf{expm1}\left(x\right)} \]
  4. Add Preprocessing
  5. Taylor expanded in x around 0

    \[\leadsto \color{blue}{x \cdot \left(1 + x \cdot \left(\frac{1}{2} + x \cdot \left(\frac{1}{6} + \frac{1}{24} \cdot x\right)\right)\right)} \]
  6. Step-by-step derivation
    1. *-lowering-*.f64N/A

      \[\leadsto \mathsf{*.f64}\left(x, \color{blue}{\left(1 + x \cdot \left(\frac{1}{2} + x \cdot \left(\frac{1}{6} + \frac{1}{24} \cdot x\right)\right)\right)}\right) \]
    2. +-lowering-+.f64N/A

      \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(1, \color{blue}{\left(x \cdot \left(\frac{1}{2} + x \cdot \left(\frac{1}{6} + \frac{1}{24} \cdot x\right)\right)\right)}\right)\right) \]
    3. *-lowering-*.f64N/A

      \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(x, \color{blue}{\left(\frac{1}{2} + x \cdot \left(\frac{1}{6} + \frac{1}{24} \cdot x\right)\right)}\right)\right)\right) \]
    4. +-lowering-+.f64N/A

      \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{2}, \color{blue}{\left(x \cdot \left(\frac{1}{6} + \frac{1}{24} \cdot x\right)\right)}\right)\right)\right)\right) \]
    5. *-lowering-*.f64N/A

      \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(x, \color{blue}{\left(\frac{1}{6} + \frac{1}{24} \cdot x\right)}\right)\right)\right)\right)\right) \]
    6. +-lowering-+.f64N/A

      \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{6}, \color{blue}{\left(\frac{1}{24} \cdot x\right)}\right)\right)\right)\right)\right)\right) \]
    7. *-commutativeN/A

      \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{6}, \left(x \cdot \color{blue}{\frac{1}{24}}\right)\right)\right)\right)\right)\right)\right) \]
    8. *-lowering-*.f6499.4%

      \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{6}, \mathsf{*.f64}\left(x, \color{blue}{\frac{1}{24}}\right)\right)\right)\right)\right)\right)\right) \]
  7. Simplified99.4%

    \[\leadsto \color{blue}{x \cdot \left(1 + x \cdot \left(0.5 + x \cdot \left(0.16666666666666666 + x \cdot 0.041666666666666664\right)\right)\right)} \]
  8. Step-by-step derivation
    1. distribute-lft-inN/A

      \[\leadsto x \cdot 1 + \color{blue}{x \cdot \left(x \cdot \left(\frac{1}{2} + x \cdot \left(\frac{1}{6} + x \cdot \frac{1}{24}\right)\right)\right)} \]
    2. flip3-+N/A

      \[\leadsto \frac{{\left(x \cdot 1\right)}^{3} + {\left(x \cdot \left(x \cdot \left(\frac{1}{2} + x \cdot \left(\frac{1}{6} + x \cdot \frac{1}{24}\right)\right)\right)\right)}^{3}}{\color{blue}{\left(x \cdot 1\right) \cdot \left(x \cdot 1\right) + \left(\left(x \cdot \left(x \cdot \left(\frac{1}{2} + x \cdot \left(\frac{1}{6} + x \cdot \frac{1}{24}\right)\right)\right)\right) \cdot \left(x \cdot \left(x \cdot \left(\frac{1}{2} + x \cdot \left(\frac{1}{6} + x \cdot \frac{1}{24}\right)\right)\right)\right) - \left(x \cdot 1\right) \cdot \left(x \cdot \left(x \cdot \left(\frac{1}{2} + x \cdot \left(\frac{1}{6} + x \cdot \frac{1}{24}\right)\right)\right)\right)\right)}} \]
    3. clear-numN/A

      \[\leadsto \frac{1}{\color{blue}{\frac{\left(x \cdot 1\right) \cdot \left(x \cdot 1\right) + \left(\left(x \cdot \left(x \cdot \left(\frac{1}{2} + x \cdot \left(\frac{1}{6} + x \cdot \frac{1}{24}\right)\right)\right)\right) \cdot \left(x \cdot \left(x \cdot \left(\frac{1}{2} + x \cdot \left(\frac{1}{6} + x \cdot \frac{1}{24}\right)\right)\right)\right) - \left(x \cdot 1\right) \cdot \left(x \cdot \left(x \cdot \left(\frac{1}{2} + x \cdot \left(\frac{1}{6} + x \cdot \frac{1}{24}\right)\right)\right)\right)\right)}{{\left(x \cdot 1\right)}^{3} + {\left(x \cdot \left(x \cdot \left(\frac{1}{2} + x \cdot \left(\frac{1}{6} + x \cdot \frac{1}{24}\right)\right)\right)\right)}^{3}}}} \]
    4. /-lowering-/.f64N/A

      \[\leadsto \mathsf{/.f64}\left(1, \color{blue}{\left(\frac{\left(x \cdot 1\right) \cdot \left(x \cdot 1\right) + \left(\left(x \cdot \left(x \cdot \left(\frac{1}{2} + x \cdot \left(\frac{1}{6} + x \cdot \frac{1}{24}\right)\right)\right)\right) \cdot \left(x \cdot \left(x \cdot \left(\frac{1}{2} + x \cdot \left(\frac{1}{6} + x \cdot \frac{1}{24}\right)\right)\right)\right) - \left(x \cdot 1\right) \cdot \left(x \cdot \left(x \cdot \left(\frac{1}{2} + x \cdot \left(\frac{1}{6} + x \cdot \frac{1}{24}\right)\right)\right)\right)\right)}{{\left(x \cdot 1\right)}^{3} + {\left(x \cdot \left(x \cdot \left(\frac{1}{2} + x \cdot \left(\frac{1}{6} + x \cdot \frac{1}{24}\right)\right)\right)\right)}^{3}}\right)}\right) \]
  9. Applied egg-rr32.3%

    \[\leadsto \color{blue}{\frac{1}{\frac{x \cdot x + \left(\left(\left(0.5 + x \cdot \left(0.16666666666666666 + x \cdot 0.041666666666666664\right)\right) \cdot \left(x \cdot x\right)\right) \cdot \left(\left(0.5 + x \cdot \left(0.16666666666666666 + x \cdot 0.041666666666666664\right)\right) \cdot \left(x \cdot x\right)\right) - x \cdot \left(\left(0.5 + x \cdot \left(0.16666666666666666 + x \cdot 0.041666666666666664\right)\right) \cdot \left(x \cdot x\right)\right)\right)}{x \cdot \left(x \cdot x\right) + \left(\left(0.5 + x \cdot \left(0.16666666666666666 + x \cdot 0.041666666666666664\right)\right) \cdot \left(x \cdot x\right)\right) \cdot \left(\left(\left(0.5 + x \cdot \left(0.16666666666666666 + x \cdot 0.041666666666666664\right)\right) \cdot \left(x \cdot x\right)\right) \cdot \left(\left(0.5 + x \cdot \left(0.16666666666666666 + x \cdot 0.041666666666666664\right)\right) \cdot \left(x \cdot x\right)\right)\right)}}} \]
  10. Taylor expanded in x around 0

    \[\leadsto \mathsf{/.f64}\left(1, \color{blue}{\left(\frac{1 + x \cdot \left(\frac{1}{12} \cdot x - \frac{1}{2}\right)}{x}\right)}\right) \]
  11. Step-by-step derivation
    1. /-lowering-/.f64N/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\left(1 + x \cdot \left(\frac{1}{12} \cdot x - \frac{1}{2}\right)\right), \color{blue}{x}\right)\right) \]
    2. +-lowering-+.f64N/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{+.f64}\left(1, \left(x \cdot \left(\frac{1}{12} \cdot x - \frac{1}{2}\right)\right)\right), x\right)\right) \]
    3. *-lowering-*.f64N/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(x, \left(\frac{1}{12} \cdot x - \frac{1}{2}\right)\right)\right), x\right)\right) \]
    4. sub-negN/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(x, \left(\frac{1}{12} \cdot x + \left(\mathsf{neg}\left(\frac{1}{2}\right)\right)\right)\right)\right), x\right)\right) \]
    5. metadata-evalN/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(x, \left(\frac{1}{12} \cdot x + \frac{-1}{2}\right)\right)\right), x\right)\right) \]
    6. +-commutativeN/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(x, \left(\frac{-1}{2} + \frac{1}{12} \cdot x\right)\right)\right), x\right)\right) \]
    7. +-lowering-+.f64N/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{-1}{2}, \left(\frac{1}{12} \cdot x\right)\right)\right)\right), x\right)\right) \]
    8. *-commutativeN/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{-1}{2}, \left(x \cdot \frac{1}{12}\right)\right)\right)\right), x\right)\right) \]
    9. *-lowering-*.f6499.1%

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{-1}{2}, \mathsf{*.f64}\left(x, \frac{1}{12}\right)\right)\right)\right), x\right)\right) \]
  12. Simplified99.1%

    \[\leadsto \frac{1}{\color{blue}{\frac{1 + x \cdot \left(-0.5 + x \cdot 0.08333333333333333\right)}{x}}} \]
  13. Step-by-step derivation
    1. clear-numN/A

      \[\leadsto \frac{x}{\color{blue}{1 + x \cdot \left(\frac{-1}{2} + x \cdot \frac{1}{12}\right)}} \]
    2. flip3-+N/A

      \[\leadsto \frac{x}{\frac{{1}^{3} + {\left(x \cdot \left(\frac{-1}{2} + x \cdot \frac{1}{12}\right)\right)}^{3}}{\color{blue}{1 \cdot 1 + \left(\left(x \cdot \left(\frac{-1}{2} + x \cdot \frac{1}{12}\right)\right) \cdot \left(x \cdot \left(\frac{-1}{2} + x \cdot \frac{1}{12}\right)\right) - 1 \cdot \left(x \cdot \left(\frac{-1}{2} + x \cdot \frac{1}{12}\right)\right)\right)}}} \]
    3. associate-/r/N/A

      \[\leadsto \frac{x}{{1}^{3} + {\left(x \cdot \left(\frac{-1}{2} + x \cdot \frac{1}{12}\right)\right)}^{3}} \cdot \color{blue}{\left(1 \cdot 1 + \left(\left(x \cdot \left(\frac{-1}{2} + x \cdot \frac{1}{12}\right)\right) \cdot \left(x \cdot \left(\frac{-1}{2} + x \cdot \frac{1}{12}\right)\right) - 1 \cdot \left(x \cdot \left(\frac{-1}{2} + x \cdot \frac{1}{12}\right)\right)\right)\right)} \]
    4. *-lowering-*.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\left(\frac{x}{{1}^{3} + {\left(x \cdot \left(\frac{-1}{2} + x \cdot \frac{1}{12}\right)\right)}^{3}}\right), \color{blue}{\left(1 \cdot 1 + \left(\left(x \cdot \left(\frac{-1}{2} + x \cdot \frac{1}{12}\right)\right) \cdot \left(x \cdot \left(\frac{-1}{2} + x \cdot \frac{1}{12}\right)\right) - 1 \cdot \left(x \cdot \left(\frac{-1}{2} + x \cdot \frac{1}{12}\right)\right)\right)\right)}\right) \]
  14. Applied egg-rr99.5%

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

    \[\leadsto \frac{x}{1 + \left(x \cdot \left(-0.5 + x \cdot 0.08333333333333333\right)\right) \cdot \left(\left(x \cdot x\right) \cdot \left(\left(-0.5 + x \cdot 0.08333333333333333\right) \cdot \left(-0.5 + x \cdot 0.08333333333333333\right)\right)\right)} \cdot \left(1 + \left(x \cdot \left(-0.5 + x \cdot 0.08333333333333333\right)\right) \cdot \left(x \cdot \left(-0.5 + x \cdot 0.08333333333333333\right) + -1\right)\right) \]
  16. Add Preprocessing

Alternative 3: 99.6% accurate, 3.6× speedup?

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

\\
\begin{array}{l}
t_0 := -0.5 + x \cdot 0.08333333333333333\\
\frac{x}{1 - \left(x \cdot x\right) \cdot \left(t\_0 \cdot t\_0\right)} \cdot \left(1 - x \cdot t\_0\right)
\end{array}
\end{array}
Derivation
  1. Initial program 8.1%

    \[e^{x} - 1 \]
  2. Step-by-step derivation
    1. expm1-defineN/A

      \[\leadsto \mathsf{expm1}\left(x\right) \]
    2. expm1-lowering-expm1.f64100.0%

      \[\leadsto \mathsf{expm1.f64}\left(x\right) \]
  3. Simplified100.0%

    \[\leadsto \color{blue}{\mathsf{expm1}\left(x\right)} \]
  4. Add Preprocessing
  5. Taylor expanded in x around 0

    \[\leadsto \color{blue}{x \cdot \left(1 + x \cdot \left(\frac{1}{2} + x \cdot \left(\frac{1}{6} + \frac{1}{24} \cdot x\right)\right)\right)} \]
  6. Step-by-step derivation
    1. *-lowering-*.f64N/A

      \[\leadsto \mathsf{*.f64}\left(x, \color{blue}{\left(1 + x \cdot \left(\frac{1}{2} + x \cdot \left(\frac{1}{6} + \frac{1}{24} \cdot x\right)\right)\right)}\right) \]
    2. +-lowering-+.f64N/A

      \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(1, \color{blue}{\left(x \cdot \left(\frac{1}{2} + x \cdot \left(\frac{1}{6} + \frac{1}{24} \cdot x\right)\right)\right)}\right)\right) \]
    3. *-lowering-*.f64N/A

      \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(x, \color{blue}{\left(\frac{1}{2} + x \cdot \left(\frac{1}{6} + \frac{1}{24} \cdot x\right)\right)}\right)\right)\right) \]
    4. +-lowering-+.f64N/A

      \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{2}, \color{blue}{\left(x \cdot \left(\frac{1}{6} + \frac{1}{24} \cdot x\right)\right)}\right)\right)\right)\right) \]
    5. *-lowering-*.f64N/A

      \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(x, \color{blue}{\left(\frac{1}{6} + \frac{1}{24} \cdot x\right)}\right)\right)\right)\right)\right) \]
    6. +-lowering-+.f64N/A

      \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{6}, \color{blue}{\left(\frac{1}{24} \cdot x\right)}\right)\right)\right)\right)\right)\right) \]
    7. *-commutativeN/A

      \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{6}, \left(x \cdot \color{blue}{\frac{1}{24}}\right)\right)\right)\right)\right)\right)\right) \]
    8. *-lowering-*.f6499.4%

      \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{6}, \mathsf{*.f64}\left(x, \color{blue}{\frac{1}{24}}\right)\right)\right)\right)\right)\right)\right) \]
  7. Simplified99.4%

    \[\leadsto \color{blue}{x \cdot \left(1 + x \cdot \left(0.5 + x \cdot \left(0.16666666666666666 + x \cdot 0.041666666666666664\right)\right)\right)} \]
  8. Step-by-step derivation
    1. distribute-lft-inN/A

      \[\leadsto x \cdot 1 + \color{blue}{x \cdot \left(x \cdot \left(\frac{1}{2} + x \cdot \left(\frac{1}{6} + x \cdot \frac{1}{24}\right)\right)\right)} \]
    2. flip3-+N/A

      \[\leadsto \frac{{\left(x \cdot 1\right)}^{3} + {\left(x \cdot \left(x \cdot \left(\frac{1}{2} + x \cdot \left(\frac{1}{6} + x \cdot \frac{1}{24}\right)\right)\right)\right)}^{3}}{\color{blue}{\left(x \cdot 1\right) \cdot \left(x \cdot 1\right) + \left(\left(x \cdot \left(x \cdot \left(\frac{1}{2} + x \cdot \left(\frac{1}{6} + x \cdot \frac{1}{24}\right)\right)\right)\right) \cdot \left(x \cdot \left(x \cdot \left(\frac{1}{2} + x \cdot \left(\frac{1}{6} + x \cdot \frac{1}{24}\right)\right)\right)\right) - \left(x \cdot 1\right) \cdot \left(x \cdot \left(x \cdot \left(\frac{1}{2} + x \cdot \left(\frac{1}{6} + x \cdot \frac{1}{24}\right)\right)\right)\right)\right)}} \]
    3. clear-numN/A

      \[\leadsto \frac{1}{\color{blue}{\frac{\left(x \cdot 1\right) \cdot \left(x \cdot 1\right) + \left(\left(x \cdot \left(x \cdot \left(\frac{1}{2} + x \cdot \left(\frac{1}{6} + x \cdot \frac{1}{24}\right)\right)\right)\right) \cdot \left(x \cdot \left(x \cdot \left(\frac{1}{2} + x \cdot \left(\frac{1}{6} + x \cdot \frac{1}{24}\right)\right)\right)\right) - \left(x \cdot 1\right) \cdot \left(x \cdot \left(x \cdot \left(\frac{1}{2} + x \cdot \left(\frac{1}{6} + x \cdot \frac{1}{24}\right)\right)\right)\right)\right)}{{\left(x \cdot 1\right)}^{3} + {\left(x \cdot \left(x \cdot \left(\frac{1}{2} + x \cdot \left(\frac{1}{6} + x \cdot \frac{1}{24}\right)\right)\right)\right)}^{3}}}} \]
    4. /-lowering-/.f64N/A

      \[\leadsto \mathsf{/.f64}\left(1, \color{blue}{\left(\frac{\left(x \cdot 1\right) \cdot \left(x \cdot 1\right) + \left(\left(x \cdot \left(x \cdot \left(\frac{1}{2} + x \cdot \left(\frac{1}{6} + x \cdot \frac{1}{24}\right)\right)\right)\right) \cdot \left(x \cdot \left(x \cdot \left(\frac{1}{2} + x \cdot \left(\frac{1}{6} + x \cdot \frac{1}{24}\right)\right)\right)\right) - \left(x \cdot 1\right) \cdot \left(x \cdot \left(x \cdot \left(\frac{1}{2} + x \cdot \left(\frac{1}{6} + x \cdot \frac{1}{24}\right)\right)\right)\right)\right)}{{\left(x \cdot 1\right)}^{3} + {\left(x \cdot \left(x \cdot \left(\frac{1}{2} + x \cdot \left(\frac{1}{6} + x \cdot \frac{1}{24}\right)\right)\right)\right)}^{3}}\right)}\right) \]
  9. Applied egg-rr32.3%

    \[\leadsto \color{blue}{\frac{1}{\frac{x \cdot x + \left(\left(\left(0.5 + x \cdot \left(0.16666666666666666 + x \cdot 0.041666666666666664\right)\right) \cdot \left(x \cdot x\right)\right) \cdot \left(\left(0.5 + x \cdot \left(0.16666666666666666 + x \cdot 0.041666666666666664\right)\right) \cdot \left(x \cdot x\right)\right) - x \cdot \left(\left(0.5 + x \cdot \left(0.16666666666666666 + x \cdot 0.041666666666666664\right)\right) \cdot \left(x \cdot x\right)\right)\right)}{x \cdot \left(x \cdot x\right) + \left(\left(0.5 + x \cdot \left(0.16666666666666666 + x \cdot 0.041666666666666664\right)\right) \cdot \left(x \cdot x\right)\right) \cdot \left(\left(\left(0.5 + x \cdot \left(0.16666666666666666 + x \cdot 0.041666666666666664\right)\right) \cdot \left(x \cdot x\right)\right) \cdot \left(\left(0.5 + x \cdot \left(0.16666666666666666 + x \cdot 0.041666666666666664\right)\right) \cdot \left(x \cdot x\right)\right)\right)}}} \]
  10. Taylor expanded in x around 0

    \[\leadsto \mathsf{/.f64}\left(1, \color{blue}{\left(\frac{1 + x \cdot \left(\frac{1}{12} \cdot x - \frac{1}{2}\right)}{x}\right)}\right) \]
  11. Step-by-step derivation
    1. /-lowering-/.f64N/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\left(1 + x \cdot \left(\frac{1}{12} \cdot x - \frac{1}{2}\right)\right), \color{blue}{x}\right)\right) \]
    2. +-lowering-+.f64N/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{+.f64}\left(1, \left(x \cdot \left(\frac{1}{12} \cdot x - \frac{1}{2}\right)\right)\right), x\right)\right) \]
    3. *-lowering-*.f64N/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(x, \left(\frac{1}{12} \cdot x - \frac{1}{2}\right)\right)\right), x\right)\right) \]
    4. sub-negN/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(x, \left(\frac{1}{12} \cdot x + \left(\mathsf{neg}\left(\frac{1}{2}\right)\right)\right)\right)\right), x\right)\right) \]
    5. metadata-evalN/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(x, \left(\frac{1}{12} \cdot x + \frac{-1}{2}\right)\right)\right), x\right)\right) \]
    6. +-commutativeN/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(x, \left(\frac{-1}{2} + \frac{1}{12} \cdot x\right)\right)\right), x\right)\right) \]
    7. +-lowering-+.f64N/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{-1}{2}, \left(\frac{1}{12} \cdot x\right)\right)\right)\right), x\right)\right) \]
    8. *-commutativeN/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{-1}{2}, \left(x \cdot \frac{1}{12}\right)\right)\right)\right), x\right)\right) \]
    9. *-lowering-*.f6499.1%

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{-1}{2}, \mathsf{*.f64}\left(x, \frac{1}{12}\right)\right)\right)\right), x\right)\right) \]
  12. Simplified99.1%

    \[\leadsto \frac{1}{\color{blue}{\frac{1 + x \cdot \left(-0.5 + x \cdot 0.08333333333333333\right)}{x}}} \]
  13. Step-by-step derivation
    1. clear-numN/A

      \[\leadsto \frac{x}{\color{blue}{1 + x \cdot \left(\frac{-1}{2} + x \cdot \frac{1}{12}\right)}} \]
    2. flip-+N/A

      \[\leadsto \frac{x}{\frac{1 \cdot 1 - \left(x \cdot \left(\frac{-1}{2} + x \cdot \frac{1}{12}\right)\right) \cdot \left(x \cdot \left(\frac{-1}{2} + x \cdot \frac{1}{12}\right)\right)}{\color{blue}{1 - x \cdot \left(\frac{-1}{2} + x \cdot \frac{1}{12}\right)}}} \]
    3. associate-/r/N/A

      \[\leadsto \frac{x}{1 \cdot 1 - \left(x \cdot \left(\frac{-1}{2} + x \cdot \frac{1}{12}\right)\right) \cdot \left(x \cdot \left(\frac{-1}{2} + x \cdot \frac{1}{12}\right)\right)} \cdot \color{blue}{\left(1 - x \cdot \left(\frac{-1}{2} + x \cdot \frac{1}{12}\right)\right)} \]
    4. *-lowering-*.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\left(\frac{x}{1 \cdot 1 - \left(x \cdot \left(\frac{-1}{2} + x \cdot \frac{1}{12}\right)\right) \cdot \left(x \cdot \left(\frac{-1}{2} + x \cdot \frac{1}{12}\right)\right)}\right), \color{blue}{\left(1 - x \cdot \left(\frac{-1}{2} + x \cdot \frac{1}{12}\right)\right)}\right) \]
  14. Applied egg-rr99.5%

    \[\leadsto \color{blue}{\frac{x}{1 - \left(x \cdot x\right) \cdot \left(\left(-0.5 + x \cdot 0.08333333333333333\right) \cdot \left(-0.5 + x \cdot 0.08333333333333333\right)\right)} \cdot \left(1 - x \cdot \left(-0.5 + x \cdot 0.08333333333333333\right)\right)} \]
  15. Add Preprocessing

Alternative 4: 99.6% accurate, 9.4× speedup?

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

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

    \[e^{x} - 1 \]
  2. Step-by-step derivation
    1. expm1-defineN/A

      \[\leadsto \mathsf{expm1}\left(x\right) \]
    2. expm1-lowering-expm1.f64100.0%

      \[\leadsto \mathsf{expm1.f64}\left(x\right) \]
  3. Simplified100.0%

    \[\leadsto \color{blue}{\mathsf{expm1}\left(x\right)} \]
  4. Add Preprocessing
  5. Taylor expanded in x around 0

    \[\leadsto \color{blue}{x \cdot \left(1 + x \cdot \left(\frac{1}{2} + x \cdot \left(\frac{1}{6} + \frac{1}{24} \cdot x\right)\right)\right)} \]
  6. Step-by-step derivation
    1. *-lowering-*.f64N/A

      \[\leadsto \mathsf{*.f64}\left(x, \color{blue}{\left(1 + x \cdot \left(\frac{1}{2} + x \cdot \left(\frac{1}{6} + \frac{1}{24} \cdot x\right)\right)\right)}\right) \]
    2. +-lowering-+.f64N/A

      \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(1, \color{blue}{\left(x \cdot \left(\frac{1}{2} + x \cdot \left(\frac{1}{6} + \frac{1}{24} \cdot x\right)\right)\right)}\right)\right) \]
    3. *-lowering-*.f64N/A

      \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(x, \color{blue}{\left(\frac{1}{2} + x \cdot \left(\frac{1}{6} + \frac{1}{24} \cdot x\right)\right)}\right)\right)\right) \]
    4. +-lowering-+.f64N/A

      \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{2}, \color{blue}{\left(x \cdot \left(\frac{1}{6} + \frac{1}{24} \cdot x\right)\right)}\right)\right)\right)\right) \]
    5. *-lowering-*.f64N/A

      \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(x, \color{blue}{\left(\frac{1}{6} + \frac{1}{24} \cdot x\right)}\right)\right)\right)\right)\right) \]
    6. +-lowering-+.f64N/A

      \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{6}, \color{blue}{\left(\frac{1}{24} \cdot x\right)}\right)\right)\right)\right)\right)\right) \]
    7. *-commutativeN/A

      \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{6}, \left(x \cdot \color{blue}{\frac{1}{24}}\right)\right)\right)\right)\right)\right)\right) \]
    8. *-lowering-*.f6499.4%

      \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{6}, \mathsf{*.f64}\left(x, \color{blue}{\frac{1}{24}}\right)\right)\right)\right)\right)\right)\right) \]
  7. Simplified99.4%

    \[\leadsto \color{blue}{x \cdot \left(1 + x \cdot \left(0.5 + x \cdot \left(0.16666666666666666 + x \cdot 0.041666666666666664\right)\right)\right)} \]
  8. Step-by-step derivation
    1. distribute-lft-inN/A

      \[\leadsto x \cdot 1 + \color{blue}{x \cdot \left(x \cdot \left(\frac{1}{2} + x \cdot \left(\frac{1}{6} + x \cdot \frac{1}{24}\right)\right)\right)} \]
    2. flip3-+N/A

      \[\leadsto \frac{{\left(x \cdot 1\right)}^{3} + {\left(x \cdot \left(x \cdot \left(\frac{1}{2} + x \cdot \left(\frac{1}{6} + x \cdot \frac{1}{24}\right)\right)\right)\right)}^{3}}{\color{blue}{\left(x \cdot 1\right) \cdot \left(x \cdot 1\right) + \left(\left(x \cdot \left(x \cdot \left(\frac{1}{2} + x \cdot \left(\frac{1}{6} + x \cdot \frac{1}{24}\right)\right)\right)\right) \cdot \left(x \cdot \left(x \cdot \left(\frac{1}{2} + x \cdot \left(\frac{1}{6} + x \cdot \frac{1}{24}\right)\right)\right)\right) - \left(x \cdot 1\right) \cdot \left(x \cdot \left(x \cdot \left(\frac{1}{2} + x \cdot \left(\frac{1}{6} + x \cdot \frac{1}{24}\right)\right)\right)\right)\right)}} \]
    3. clear-numN/A

      \[\leadsto \frac{1}{\color{blue}{\frac{\left(x \cdot 1\right) \cdot \left(x \cdot 1\right) + \left(\left(x \cdot \left(x \cdot \left(\frac{1}{2} + x \cdot \left(\frac{1}{6} + x \cdot \frac{1}{24}\right)\right)\right)\right) \cdot \left(x \cdot \left(x \cdot \left(\frac{1}{2} + x \cdot \left(\frac{1}{6} + x \cdot \frac{1}{24}\right)\right)\right)\right) - \left(x \cdot 1\right) \cdot \left(x \cdot \left(x \cdot \left(\frac{1}{2} + x \cdot \left(\frac{1}{6} + x \cdot \frac{1}{24}\right)\right)\right)\right)\right)}{{\left(x \cdot 1\right)}^{3} + {\left(x \cdot \left(x \cdot \left(\frac{1}{2} + x \cdot \left(\frac{1}{6} + x \cdot \frac{1}{24}\right)\right)\right)\right)}^{3}}}} \]
    4. /-lowering-/.f64N/A

      \[\leadsto \mathsf{/.f64}\left(1, \color{blue}{\left(\frac{\left(x \cdot 1\right) \cdot \left(x \cdot 1\right) + \left(\left(x \cdot \left(x \cdot \left(\frac{1}{2} + x \cdot \left(\frac{1}{6} + x \cdot \frac{1}{24}\right)\right)\right)\right) \cdot \left(x \cdot \left(x \cdot \left(\frac{1}{2} + x \cdot \left(\frac{1}{6} + x \cdot \frac{1}{24}\right)\right)\right)\right) - \left(x \cdot 1\right) \cdot \left(x \cdot \left(x \cdot \left(\frac{1}{2} + x \cdot \left(\frac{1}{6} + x \cdot \frac{1}{24}\right)\right)\right)\right)\right)}{{\left(x \cdot 1\right)}^{3} + {\left(x \cdot \left(x \cdot \left(\frac{1}{2} + x \cdot \left(\frac{1}{6} + x \cdot \frac{1}{24}\right)\right)\right)\right)}^{3}}\right)}\right) \]
  9. Applied egg-rr32.3%

    \[\leadsto \color{blue}{\frac{1}{\frac{x \cdot x + \left(\left(\left(0.5 + x \cdot \left(0.16666666666666666 + x \cdot 0.041666666666666664\right)\right) \cdot \left(x \cdot x\right)\right) \cdot \left(\left(0.5 + x \cdot \left(0.16666666666666666 + x \cdot 0.041666666666666664\right)\right) \cdot \left(x \cdot x\right)\right) - x \cdot \left(\left(0.5 + x \cdot \left(0.16666666666666666 + x \cdot 0.041666666666666664\right)\right) \cdot \left(x \cdot x\right)\right)\right)}{x \cdot \left(x \cdot x\right) + \left(\left(0.5 + x \cdot \left(0.16666666666666666 + x \cdot 0.041666666666666664\right)\right) \cdot \left(x \cdot x\right)\right) \cdot \left(\left(\left(0.5 + x \cdot \left(0.16666666666666666 + x \cdot 0.041666666666666664\right)\right) \cdot \left(x \cdot x\right)\right) \cdot \left(\left(0.5 + x \cdot \left(0.16666666666666666 + x \cdot 0.041666666666666664\right)\right) \cdot \left(x \cdot x\right)\right)\right)}}} \]
  10. Taylor expanded in x around 0

    \[\leadsto \mathsf{/.f64}\left(1, \color{blue}{\left(\frac{1 + x \cdot \left(\frac{1}{12} \cdot x - \frac{1}{2}\right)}{x}\right)}\right) \]
  11. Step-by-step derivation
    1. /-lowering-/.f64N/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\left(1 + x \cdot \left(\frac{1}{12} \cdot x - \frac{1}{2}\right)\right), \color{blue}{x}\right)\right) \]
    2. +-lowering-+.f64N/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{+.f64}\left(1, \left(x \cdot \left(\frac{1}{12} \cdot x - \frac{1}{2}\right)\right)\right), x\right)\right) \]
    3. *-lowering-*.f64N/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(x, \left(\frac{1}{12} \cdot x - \frac{1}{2}\right)\right)\right), x\right)\right) \]
    4. sub-negN/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(x, \left(\frac{1}{12} \cdot x + \left(\mathsf{neg}\left(\frac{1}{2}\right)\right)\right)\right)\right), x\right)\right) \]
    5. metadata-evalN/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(x, \left(\frac{1}{12} \cdot x + \frac{-1}{2}\right)\right)\right), x\right)\right) \]
    6. +-commutativeN/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(x, \left(\frac{-1}{2} + \frac{1}{12} \cdot x\right)\right)\right), x\right)\right) \]
    7. +-lowering-+.f64N/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{-1}{2}, \left(\frac{1}{12} \cdot x\right)\right)\right)\right), x\right)\right) \]
    8. *-commutativeN/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{-1}{2}, \left(x \cdot \frac{1}{12}\right)\right)\right)\right), x\right)\right) \]
    9. *-lowering-*.f6499.1%

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{-1}{2}, \mathsf{*.f64}\left(x, \frac{1}{12}\right)\right)\right)\right), x\right)\right) \]
  12. Simplified99.1%

    \[\leadsto \frac{1}{\color{blue}{\frac{1 + x \cdot \left(-0.5 + x \cdot 0.08333333333333333\right)}{x}}} \]
  13. Step-by-step derivation
    1. clear-numN/A

      \[\leadsto \frac{x}{\color{blue}{1 + x \cdot \left(\frac{-1}{2} + x \cdot \frac{1}{12}\right)}} \]
    2. /-lowering-/.f64N/A

      \[\leadsto \mathsf{/.f64}\left(x, \color{blue}{\left(1 + x \cdot \left(\frac{-1}{2} + x \cdot \frac{1}{12}\right)\right)}\right) \]
    3. +-lowering-+.f64N/A

      \[\leadsto \mathsf{/.f64}\left(x, \mathsf{+.f64}\left(1, \color{blue}{\left(x \cdot \left(\frac{-1}{2} + x \cdot \frac{1}{12}\right)\right)}\right)\right) \]
    4. *-lowering-*.f64N/A

      \[\leadsto \mathsf{/.f64}\left(x, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(x, \color{blue}{\left(\frac{-1}{2} + x \cdot \frac{1}{12}\right)}\right)\right)\right) \]
    5. +-lowering-+.f64N/A

      \[\leadsto \mathsf{/.f64}\left(x, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{-1}{2}, \color{blue}{\left(x \cdot \frac{1}{12}\right)}\right)\right)\right)\right) \]
    6. *-lowering-*.f6499.5%

      \[\leadsto \mathsf{/.f64}\left(x, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{-1}{2}, \mathsf{*.f64}\left(x, \color{blue}{\frac{1}{12}}\right)\right)\right)\right)\right) \]
  14. Applied egg-rr99.5%

    \[\leadsto \color{blue}{\frac{x}{1 + x \cdot \left(-0.5 + x \cdot 0.08333333333333333\right)}} \]
  15. Add Preprocessing

Alternative 5: 99.4% accurate, 9.4× speedup?

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

\\
x + x \cdot \left(x \cdot \left(0.5 + x \cdot 0.16666666666666666\right)\right)
\end{array}
Derivation
  1. Initial program 8.1%

    \[e^{x} - 1 \]
  2. Step-by-step derivation
    1. expm1-defineN/A

      \[\leadsto \mathsf{expm1}\left(x\right) \]
    2. expm1-lowering-expm1.f64100.0%

      \[\leadsto \mathsf{expm1.f64}\left(x\right) \]
  3. Simplified100.0%

    \[\leadsto \color{blue}{\mathsf{expm1}\left(x\right)} \]
  4. Add Preprocessing
  5. Taylor expanded in x around 0

    \[\leadsto \color{blue}{x \cdot \left(1 + x \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot x\right)\right)} \]
  6. Step-by-step derivation
    1. *-lowering-*.f64N/A

      \[\leadsto \mathsf{*.f64}\left(x, \color{blue}{\left(1 + x \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot x\right)\right)}\right) \]
    2. +-lowering-+.f64N/A

      \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(1, \color{blue}{\left(x \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot x\right)\right)}\right)\right) \]
    3. *-lowering-*.f64N/A

      \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(x, \color{blue}{\left(\frac{1}{2} + \frac{1}{6} \cdot x\right)}\right)\right)\right) \]
    4. +-lowering-+.f64N/A

      \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{2}, \color{blue}{\left(\frac{1}{6} \cdot x\right)}\right)\right)\right)\right) \]
    5. *-commutativeN/A

      \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{2}, \left(x \cdot \color{blue}{\frac{1}{6}}\right)\right)\right)\right)\right) \]
    6. *-lowering-*.f6499.1%

      \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(x, \color{blue}{\frac{1}{6}}\right)\right)\right)\right)\right) \]
  7. Simplified99.1%

    \[\leadsto \color{blue}{x \cdot \left(1 + x \cdot \left(0.5 + x \cdot 0.16666666666666666\right)\right)} \]
  8. Step-by-step derivation
    1. +-commutativeN/A

      \[\leadsto x \cdot \left(x \cdot \left(\frac{1}{2} + x \cdot \frac{1}{6}\right) + \color{blue}{1}\right) \]
    2. distribute-lft-inN/A

      \[\leadsto x \cdot \left(x \cdot \left(\frac{1}{2} + x \cdot \frac{1}{6}\right)\right) + \color{blue}{x \cdot 1} \]
    3. *-rgt-identityN/A

      \[\leadsto x \cdot \left(x \cdot \left(\frac{1}{2} + x \cdot \frac{1}{6}\right)\right) + x \]
    4. +-lowering-+.f64N/A

      \[\leadsto \mathsf{+.f64}\left(\left(x \cdot \left(x \cdot \left(\frac{1}{2} + x \cdot \frac{1}{6}\right)\right)\right), \color{blue}{x}\right) \]
    5. *-lowering-*.f64N/A

      \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, \left(x \cdot \left(\frac{1}{2} + x \cdot \frac{1}{6}\right)\right)\right), x\right) \]
    6. *-lowering-*.f64N/A

      \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \left(\frac{1}{2} + x \cdot \frac{1}{6}\right)\right)\right), x\right) \]
    7. +-lowering-+.f64N/A

      \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{2}, \left(x \cdot \frac{1}{6}\right)\right)\right)\right), x\right) \]
    8. *-lowering-*.f6499.1%

      \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(x, \frac{1}{6}\right)\right)\right)\right), x\right) \]
  9. Applied egg-rr99.1%

    \[\leadsto \color{blue}{x \cdot \left(x \cdot \left(0.5 + x \cdot 0.16666666666666666\right)\right) + x} \]
  10. Final simplification99.1%

    \[\leadsto x + x \cdot \left(x \cdot \left(0.5 + x \cdot 0.16666666666666666\right)\right) \]
  11. Add Preprocessing

Alternative 6: 99.4% accurate, 9.4× speedup?

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

\\
x \cdot \left(1 + x \cdot \left(0.5 + x \cdot 0.16666666666666666\right)\right)
\end{array}
Derivation
  1. Initial program 8.1%

    \[e^{x} - 1 \]
  2. Step-by-step derivation
    1. expm1-defineN/A

      \[\leadsto \mathsf{expm1}\left(x\right) \]
    2. expm1-lowering-expm1.f64100.0%

      \[\leadsto \mathsf{expm1.f64}\left(x\right) \]
  3. Simplified100.0%

    \[\leadsto \color{blue}{\mathsf{expm1}\left(x\right)} \]
  4. Add Preprocessing
  5. Taylor expanded in x around 0

    \[\leadsto \color{blue}{x \cdot \left(1 + x \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot x\right)\right)} \]
  6. Step-by-step derivation
    1. *-lowering-*.f64N/A

      \[\leadsto \mathsf{*.f64}\left(x, \color{blue}{\left(1 + x \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot x\right)\right)}\right) \]
    2. +-lowering-+.f64N/A

      \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(1, \color{blue}{\left(x \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot x\right)\right)}\right)\right) \]
    3. *-lowering-*.f64N/A

      \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(x, \color{blue}{\left(\frac{1}{2} + \frac{1}{6} \cdot x\right)}\right)\right)\right) \]
    4. +-lowering-+.f64N/A

      \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{2}, \color{blue}{\left(\frac{1}{6} \cdot x\right)}\right)\right)\right)\right) \]
    5. *-commutativeN/A

      \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{2}, \left(x \cdot \color{blue}{\frac{1}{6}}\right)\right)\right)\right)\right) \]
    6. *-lowering-*.f6499.1%

      \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(x, \color{blue}{\frac{1}{6}}\right)\right)\right)\right)\right) \]
  7. Simplified99.1%

    \[\leadsto \color{blue}{x \cdot \left(1 + x \cdot \left(0.5 + x \cdot 0.16666666666666666\right)\right)} \]
  8. Add Preprocessing

Alternative 7: 99.1% accurate, 14.7× speedup?

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

\\
\frac{x}{1 + x \cdot -0.5}
\end{array}
Derivation
  1. Initial program 8.1%

    \[e^{x} - 1 \]
  2. Step-by-step derivation
    1. expm1-defineN/A

      \[\leadsto \mathsf{expm1}\left(x\right) \]
    2. expm1-lowering-expm1.f64100.0%

      \[\leadsto \mathsf{expm1.f64}\left(x\right) \]
  3. Simplified100.0%

    \[\leadsto \color{blue}{\mathsf{expm1}\left(x\right)} \]
  4. Add Preprocessing
  5. Taylor expanded in x around 0

    \[\leadsto \color{blue}{x \cdot \left(1 + x \cdot \left(\frac{1}{2} + x \cdot \left(\frac{1}{6} + \frac{1}{24} \cdot x\right)\right)\right)} \]
  6. Step-by-step derivation
    1. *-lowering-*.f64N/A

      \[\leadsto \mathsf{*.f64}\left(x, \color{blue}{\left(1 + x \cdot \left(\frac{1}{2} + x \cdot \left(\frac{1}{6} + \frac{1}{24} \cdot x\right)\right)\right)}\right) \]
    2. +-lowering-+.f64N/A

      \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(1, \color{blue}{\left(x \cdot \left(\frac{1}{2} + x \cdot \left(\frac{1}{6} + \frac{1}{24} \cdot x\right)\right)\right)}\right)\right) \]
    3. *-lowering-*.f64N/A

      \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(x, \color{blue}{\left(\frac{1}{2} + x \cdot \left(\frac{1}{6} + \frac{1}{24} \cdot x\right)\right)}\right)\right)\right) \]
    4. +-lowering-+.f64N/A

      \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{2}, \color{blue}{\left(x \cdot \left(\frac{1}{6} + \frac{1}{24} \cdot x\right)\right)}\right)\right)\right)\right) \]
    5. *-lowering-*.f64N/A

      \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(x, \color{blue}{\left(\frac{1}{6} + \frac{1}{24} \cdot x\right)}\right)\right)\right)\right)\right) \]
    6. +-lowering-+.f64N/A

      \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{6}, \color{blue}{\left(\frac{1}{24} \cdot x\right)}\right)\right)\right)\right)\right)\right) \]
    7. *-commutativeN/A

      \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{6}, \left(x \cdot \color{blue}{\frac{1}{24}}\right)\right)\right)\right)\right)\right)\right) \]
    8. *-lowering-*.f6499.4%

      \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{6}, \mathsf{*.f64}\left(x, \color{blue}{\frac{1}{24}}\right)\right)\right)\right)\right)\right)\right) \]
  7. Simplified99.4%

    \[\leadsto \color{blue}{x \cdot \left(1 + x \cdot \left(0.5 + x \cdot \left(0.16666666666666666 + x \cdot 0.041666666666666664\right)\right)\right)} \]
  8. Step-by-step derivation
    1. distribute-lft-inN/A

      \[\leadsto x \cdot 1 + \color{blue}{x \cdot \left(x \cdot \left(\frac{1}{2} + x \cdot \left(\frac{1}{6} + x \cdot \frac{1}{24}\right)\right)\right)} \]
    2. flip3-+N/A

      \[\leadsto \frac{{\left(x \cdot 1\right)}^{3} + {\left(x \cdot \left(x \cdot \left(\frac{1}{2} + x \cdot \left(\frac{1}{6} + x \cdot \frac{1}{24}\right)\right)\right)\right)}^{3}}{\color{blue}{\left(x \cdot 1\right) \cdot \left(x \cdot 1\right) + \left(\left(x \cdot \left(x \cdot \left(\frac{1}{2} + x \cdot \left(\frac{1}{6} + x \cdot \frac{1}{24}\right)\right)\right)\right) \cdot \left(x \cdot \left(x \cdot \left(\frac{1}{2} + x \cdot \left(\frac{1}{6} + x \cdot \frac{1}{24}\right)\right)\right)\right) - \left(x \cdot 1\right) \cdot \left(x \cdot \left(x \cdot \left(\frac{1}{2} + x \cdot \left(\frac{1}{6} + x \cdot \frac{1}{24}\right)\right)\right)\right)\right)}} \]
    3. clear-numN/A

      \[\leadsto \frac{1}{\color{blue}{\frac{\left(x \cdot 1\right) \cdot \left(x \cdot 1\right) + \left(\left(x \cdot \left(x \cdot \left(\frac{1}{2} + x \cdot \left(\frac{1}{6} + x \cdot \frac{1}{24}\right)\right)\right)\right) \cdot \left(x \cdot \left(x \cdot \left(\frac{1}{2} + x \cdot \left(\frac{1}{6} + x \cdot \frac{1}{24}\right)\right)\right)\right) - \left(x \cdot 1\right) \cdot \left(x \cdot \left(x \cdot \left(\frac{1}{2} + x \cdot \left(\frac{1}{6} + x \cdot \frac{1}{24}\right)\right)\right)\right)\right)}{{\left(x \cdot 1\right)}^{3} + {\left(x \cdot \left(x \cdot \left(\frac{1}{2} + x \cdot \left(\frac{1}{6} + x \cdot \frac{1}{24}\right)\right)\right)\right)}^{3}}}} \]
    4. /-lowering-/.f64N/A

      \[\leadsto \mathsf{/.f64}\left(1, \color{blue}{\left(\frac{\left(x \cdot 1\right) \cdot \left(x \cdot 1\right) + \left(\left(x \cdot \left(x \cdot \left(\frac{1}{2} + x \cdot \left(\frac{1}{6} + x \cdot \frac{1}{24}\right)\right)\right)\right) \cdot \left(x \cdot \left(x \cdot \left(\frac{1}{2} + x \cdot \left(\frac{1}{6} + x \cdot \frac{1}{24}\right)\right)\right)\right) - \left(x \cdot 1\right) \cdot \left(x \cdot \left(x \cdot \left(\frac{1}{2} + x \cdot \left(\frac{1}{6} + x \cdot \frac{1}{24}\right)\right)\right)\right)\right)}{{\left(x \cdot 1\right)}^{3} + {\left(x \cdot \left(x \cdot \left(\frac{1}{2} + x \cdot \left(\frac{1}{6} + x \cdot \frac{1}{24}\right)\right)\right)\right)}^{3}}\right)}\right) \]
  9. Applied egg-rr32.3%

    \[\leadsto \color{blue}{\frac{1}{\frac{x \cdot x + \left(\left(\left(0.5 + x \cdot \left(0.16666666666666666 + x \cdot 0.041666666666666664\right)\right) \cdot \left(x \cdot x\right)\right) \cdot \left(\left(0.5 + x \cdot \left(0.16666666666666666 + x \cdot 0.041666666666666664\right)\right) \cdot \left(x \cdot x\right)\right) - x \cdot \left(\left(0.5 + x \cdot \left(0.16666666666666666 + x \cdot 0.041666666666666664\right)\right) \cdot \left(x \cdot x\right)\right)\right)}{x \cdot \left(x \cdot x\right) + \left(\left(0.5 + x \cdot \left(0.16666666666666666 + x \cdot 0.041666666666666664\right)\right) \cdot \left(x \cdot x\right)\right) \cdot \left(\left(\left(0.5 + x \cdot \left(0.16666666666666666 + x \cdot 0.041666666666666664\right)\right) \cdot \left(x \cdot x\right)\right) \cdot \left(\left(0.5 + x \cdot \left(0.16666666666666666 + x \cdot 0.041666666666666664\right)\right) \cdot \left(x \cdot x\right)\right)\right)}}} \]
  10. Taylor expanded in x around 0

    \[\leadsto \mathsf{/.f64}\left(1, \color{blue}{\left(\frac{1 + \frac{-1}{2} \cdot x}{x}\right)}\right) \]
  11. Step-by-step derivation
    1. /-lowering-/.f64N/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\left(1 + \frac{-1}{2} \cdot x\right), \color{blue}{x}\right)\right) \]
    2. +-lowering-+.f64N/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{+.f64}\left(1, \left(\frac{-1}{2} \cdot x\right)\right), x\right)\right) \]
    3. *-commutativeN/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{+.f64}\left(1, \left(x \cdot \frac{-1}{2}\right)\right), x\right)\right) \]
    4. *-lowering-*.f6498.5%

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(x, \frac{-1}{2}\right)\right), x\right)\right) \]
  12. Simplified98.5%

    \[\leadsto \frac{1}{\color{blue}{\frac{1 + x \cdot -0.5}{x}}} \]
  13. Step-by-step derivation
    1. clear-numN/A

      \[\leadsto \frac{x}{\color{blue}{1 + x \cdot \frac{-1}{2}}} \]
    2. /-lowering-/.f64N/A

      \[\leadsto \mathsf{/.f64}\left(x, \color{blue}{\left(1 + x \cdot \frac{-1}{2}\right)}\right) \]
    3. +-lowering-+.f64N/A

      \[\leadsto \mathsf{/.f64}\left(x, \mathsf{+.f64}\left(1, \color{blue}{\left(x \cdot \frac{-1}{2}\right)}\right)\right) \]
    4. *-lowering-*.f6498.9%

      \[\leadsto \mathsf{/.f64}\left(x, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(x, \color{blue}{\frac{-1}{2}}\right)\right)\right) \]
  14. Applied egg-rr98.9%

    \[\leadsto \color{blue}{\frac{x}{1 + x \cdot -0.5}} \]
  15. Add Preprocessing

Alternative 8: 99.1% accurate, 14.7× speedup?

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

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

    \[e^{x} - 1 \]
  2. Step-by-step derivation
    1. expm1-defineN/A

      \[\leadsto \mathsf{expm1}\left(x\right) \]
    2. expm1-lowering-expm1.f64100.0%

      \[\leadsto \mathsf{expm1.f64}\left(x\right) \]
  3. Simplified100.0%

    \[\leadsto \color{blue}{\mathsf{expm1}\left(x\right)} \]
  4. Add Preprocessing
  5. Taylor expanded in x around 0

    \[\leadsto \color{blue}{x \cdot \left(1 + \frac{1}{2} \cdot x\right)} \]
  6. Step-by-step derivation
    1. *-lowering-*.f64N/A

      \[\leadsto \mathsf{*.f64}\left(x, \color{blue}{\left(1 + \frac{1}{2} \cdot x\right)}\right) \]
    2. +-lowering-+.f64N/A

      \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(1, \color{blue}{\left(\frac{1}{2} \cdot x\right)}\right)\right) \]
    3. *-commutativeN/A

      \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(1, \left(x \cdot \color{blue}{\frac{1}{2}}\right)\right)\right) \]
    4. *-lowering-*.f6498.9%

      \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(x, \color{blue}{\frac{1}{2}}\right)\right)\right) \]
  7. Simplified98.9%

    \[\leadsto \color{blue}{x \cdot \left(1 + x \cdot 0.5\right)} \]
  8. Step-by-step derivation
    1. +-commutativeN/A

      \[\leadsto x \cdot \left(x \cdot \frac{1}{2} + \color{blue}{1}\right) \]
    2. distribute-lft-inN/A

      \[\leadsto x \cdot \left(x \cdot \frac{1}{2}\right) + \color{blue}{x \cdot 1} \]
    3. *-rgt-identityN/A

      \[\leadsto x \cdot \left(x \cdot \frac{1}{2}\right) + x \]
    4. +-lowering-+.f64N/A

      \[\leadsto \mathsf{+.f64}\left(\left(x \cdot \left(x \cdot \frac{1}{2}\right)\right), \color{blue}{x}\right) \]
    5. *-lowering-*.f64N/A

      \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, \left(x \cdot \frac{1}{2}\right)\right), x\right) \]
    6. *-lowering-*.f6498.9%

      \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, \mathsf{*.f64}\left(x, \frac{1}{2}\right)\right), x\right) \]
  9. Applied egg-rr98.9%

    \[\leadsto \color{blue}{x \cdot \left(x \cdot 0.5\right) + x} \]
  10. Final simplification98.9%

    \[\leadsto x + x \cdot \left(x \cdot 0.5\right) \]
  11. Add Preprocessing

Alternative 9: 99.1% accurate, 14.7× speedup?

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

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

    \[e^{x} - 1 \]
  2. Step-by-step derivation
    1. expm1-defineN/A

      \[\leadsto \mathsf{expm1}\left(x\right) \]
    2. expm1-lowering-expm1.f64100.0%

      \[\leadsto \mathsf{expm1.f64}\left(x\right) \]
  3. Simplified100.0%

    \[\leadsto \color{blue}{\mathsf{expm1}\left(x\right)} \]
  4. Add Preprocessing
  5. Taylor expanded in x around 0

    \[\leadsto \color{blue}{x \cdot \left(1 + \frac{1}{2} \cdot x\right)} \]
  6. Step-by-step derivation
    1. *-lowering-*.f64N/A

      \[\leadsto \mathsf{*.f64}\left(x, \color{blue}{\left(1 + \frac{1}{2} \cdot x\right)}\right) \]
    2. +-lowering-+.f64N/A

      \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(1, \color{blue}{\left(\frac{1}{2} \cdot x\right)}\right)\right) \]
    3. *-commutativeN/A

      \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(1, \left(x \cdot \color{blue}{\frac{1}{2}}\right)\right)\right) \]
    4. *-lowering-*.f6498.9%

      \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(x, \color{blue}{\frac{1}{2}}\right)\right)\right) \]
  7. Simplified98.9%

    \[\leadsto \color{blue}{x \cdot \left(1 + x \cdot 0.5\right)} \]
  8. Add Preprocessing

Alternative 10: 98.1% accurate, 103.0× speedup?

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

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

    \[e^{x} - 1 \]
  2. Step-by-step derivation
    1. expm1-defineN/A

      \[\leadsto \mathsf{expm1}\left(x\right) \]
    2. expm1-lowering-expm1.f64100.0%

      \[\leadsto \mathsf{expm1.f64}\left(x\right) \]
  3. Simplified100.0%

    \[\leadsto \color{blue}{\mathsf{expm1}\left(x\right)} \]
  4. Add Preprocessing
  5. Taylor expanded in x around 0

    \[\leadsto \color{blue}{x} \]
  6. Step-by-step derivation
    1. Simplified98.0%

      \[\leadsto \color{blue}{x} \]
    2. Add Preprocessing

    Developer Target 1: 100.0% accurate, 1.0× speedup?

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

    Reproduce

    ?
    herbie shell --seed 2024155 
    (FPCore (x)
      :name "expm1 (example 3.7)"
      :precision binary64
      :pre (<= (fabs x) 1.0)
    
      :alt
      (! :herbie-platform default (expm1 x))
    
      (- (exp x) 1.0))