expm1 (example 3.7)

Percentage Accurate: 8.4% → 100.0%
Time: 7.2s
Alternatives: 9
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 9 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.4% 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 7.6%

    \[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, 1.6× speedup?

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

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

    \[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.8%

      \[\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.8%

    \[\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. +-commutativeN/A

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

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

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

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

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

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

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

    \[\leadsto x \cdot \color{blue}{\frac{1}{\frac{\left(0.5 + x \cdot \left(0.16666666666666666 + x \cdot 0.041666666666666664\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) + \left(1 - x \cdot \left(0.5 + x \cdot \left(0.16666666666666666 + x \cdot 0.041666666666666664\right)\right)\right)}{1 + \left(x \cdot \left(0.5 + x \cdot \left(0.16666666666666666 + x \cdot 0.041666666666666664\right)\right)\right) \cdot \left(\left(0.5 + x \cdot \left(0.16666666666666666 + x \cdot 0.041666666666666664\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(x, \mathsf{/.f64}\left(1, \color{blue}{\left(1 + x \cdot \left(\frac{1}{12} \cdot x - \frac{1}{2}\right)\right)}\right)\right) \]
  11. Step-by-step derivation
    1. +-lowering-+.f64N/A

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

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

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

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

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

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

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

      \[\leadsto \mathsf{*.f64}\left(x, \mathsf{/.f64}\left(1, \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)\right) \]
  12. Simplified99.8%

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

      \[\leadsto \mathsf{*.f64}\left(x, \left(\frac{1}{\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)}}}\right)\right) \]
    2. clear-numN/A

      \[\leadsto \mathsf{*.f64}\left(x, \left(\frac{1 - x \cdot \left(\frac{-1}{2} + x \cdot \frac{1}{12}\right)}{\color{blue}{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)\right) \]
    3. metadata-evalN/A

      \[\leadsto \mathsf{*.f64}\left(x, \left(\frac{1 - x \cdot \left(\frac{-1}{2} + x \cdot \frac{1}{12}\right)}{1 - \color{blue}{\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)\right) \]
    4. flip--N/A

      \[\leadsto \mathsf{*.f64}\left(x, \left(\frac{1 - x \cdot \left(\frac{-1}{2} + x \cdot \frac{1}{12}\right)}{\frac{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)\right) \cdot \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)\right)}{\color{blue}{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)\right) \]
    5. associate-/r/N/A

      \[\leadsto \mathsf{*.f64}\left(x, \left(\frac{1 - x \cdot \left(\frac{-1}{2} + x \cdot \frac{1}{12}\right)}{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)\right) \cdot \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)\right)} \cdot \color{blue}{\left(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)}\right)\right) \]
    6. *-lowering-*.f64N/A

      \[\leadsto \mathsf{*.f64}\left(x, \mathsf{*.f64}\left(\left(\frac{1 - x \cdot \left(\frac{-1}{2} + x \cdot \frac{1}{12}\right)}{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)\right) \cdot \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)\right)}\right), \color{blue}{\left(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)}\right)\right) \]
  14. Applied egg-rr99.9%

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

Alternative 3: 99.6% accurate, 6.9× speedup?

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

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

    \[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.8%

      \[\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.8%

    \[\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. +-commutativeN/A

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

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

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

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

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

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

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

    \[\leadsto x \cdot \color{blue}{\frac{1}{\frac{\left(0.5 + x \cdot \left(0.16666666666666666 + x \cdot 0.041666666666666664\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) + \left(1 - x \cdot \left(0.5 + x \cdot \left(0.16666666666666666 + x \cdot 0.041666666666666664\right)\right)\right)}{1 + \left(x \cdot \left(0.5 + x \cdot \left(0.16666666666666666 + x \cdot 0.041666666666666664\right)\right)\right) \cdot \left(\left(0.5 + x \cdot \left(0.16666666666666666 + x \cdot 0.041666666666666664\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(x, \mathsf{/.f64}\left(1, \color{blue}{\left(1 + x \cdot \left(\frac{1}{12} \cdot x - \frac{1}{2}\right)\right)}\right)\right) \]
  11. Step-by-step derivation
    1. +-lowering-+.f64N/A

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

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

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

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

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

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

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

      \[\leadsto \mathsf{*.f64}\left(x, \mathsf{/.f64}\left(1, \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)\right) \]
  12. Simplified99.8%

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

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

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

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

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

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

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

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

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

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

    \[\leadsto x \cdot \frac{1}{\color{blue}{\left(1 + x \cdot -0.5\right) + 0.08333333333333333 \cdot \left(x \cdot x\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 7.6%

    \[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.8%

      \[\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.8%

    \[\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. +-commutativeN/A

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

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

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

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

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

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

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

    \[\leadsto x \cdot \color{blue}{\frac{1}{\frac{\left(0.5 + x \cdot \left(0.16666666666666666 + x \cdot 0.041666666666666664\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) + \left(1 - x \cdot \left(0.5 + x \cdot \left(0.16666666666666666 + x \cdot 0.041666666666666664\right)\right)\right)}{1 + \left(x \cdot \left(0.5 + x \cdot \left(0.16666666666666666 + x \cdot 0.041666666666666664\right)\right)\right) \cdot \left(\left(0.5 + x \cdot \left(0.16666666666666666 + x \cdot 0.041666666666666664\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(x, \mathsf{/.f64}\left(1, \color{blue}{\left(1 + x \cdot \left(\frac{1}{12} \cdot x - \frac{1}{2}\right)\right)}\right)\right) \]
  11. Step-by-step derivation
    1. +-lowering-+.f64N/A

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

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

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

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

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

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

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

      \[\leadsto \mathsf{*.f64}\left(x, \mathsf{/.f64}\left(1, \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)\right) \]
  12. Simplified99.8%

    \[\leadsto x \cdot \frac{1}{\color{blue}{1 + x \cdot \left(-0.5 + x \cdot 0.08333333333333333\right)}} \]
  13. Step-by-step derivation
    1. un-div-invN/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.8%

      \[\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.8%

    \[\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 7.6%

    \[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.7%

      \[\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.7%

    \[\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.7%

      \[\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.7%

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

    \[\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 7.6%

    \[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.7%

      \[\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.7%

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

Alternative 7: 99.0% 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 7.6%

    \[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-*.f6499.6%

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

    \[\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-*.f6499.6%

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

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

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

Alternative 8: 99.0% 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 7.6%

    \[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-*.f6499.6%

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

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

Alternative 9: 98.0% 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 7.6%

    \[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.5%

      \[\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 2024158 
    (FPCore (x)
      :name "expm1 (example 3.7)"
      :precision binary64
      :pre (<= (fabs x) 1.0)
    
      :alt
      (! :herbie-platform default (expm1 x))
    
      (- (exp x) 1.0))