
(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:
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(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}
(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}
Initial program 8.9%
accelerator-lowering-expm1.f64100.0
Applied egg-rr100.0%
(FPCore (x)
:precision binary64
(/
(*
x
(-
(* 0.027777777777777776 (* x (* x (* x x))))
(* (fma x 0.5 1.0) (fma x 0.5 1.0))))
(fma x (fma x (fma x 0.041666666666666664 0.16666666666666666) -0.5) -1.0)))
double code(double x) {
return (x * ((0.027777777777777776 * (x * (x * (x * x)))) - (fma(x, 0.5, 1.0) * fma(x, 0.5, 1.0)))) / fma(x, fma(x, fma(x, 0.041666666666666664, 0.16666666666666666), -0.5), -1.0);
}
function code(x) return Float64(Float64(x * Float64(Float64(0.027777777777777776 * Float64(x * Float64(x * Float64(x * x)))) - Float64(fma(x, 0.5, 1.0) * fma(x, 0.5, 1.0)))) / fma(x, fma(x, fma(x, 0.041666666666666664, 0.16666666666666666), -0.5), -1.0)) end
code[x_] := N[(N[(x * N[(N[(0.027777777777777776 * N[(x * N[(x * N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(N[(x * 0.5 + 1.0), $MachinePrecision] * N[(x * 0.5 + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(x * N[(x * N[(x * 0.041666666666666664 + 0.16666666666666666), $MachinePrecision] + -0.5), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x \cdot \left(0.027777777777777776 \cdot \left(x \cdot \left(x \cdot \left(x \cdot x\right)\right)\right) - \mathsf{fma}\left(x, 0.5, 1\right) \cdot \mathsf{fma}\left(x, 0.5, 1\right)\right)}{\mathsf{fma}\left(x, \mathsf{fma}\left(x, \mathsf{fma}\left(x, 0.041666666666666664, 0.16666666666666666\right), -0.5\right), -1\right)}
\end{array}
Initial program 8.9%
Taylor expanded in x around 0
*-lowering-*.f64N/A
+-commutativeN/A
accelerator-lowering-fma.f64N/A
+-commutativeN/A
accelerator-lowering-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f6499.5
Simplified99.5%
distribute-lft-inN/A
associate-+l+N/A
flip-+N/A
/-lowering-/.f64N/A
Applied egg-rr99.5%
Taylor expanded in x around 0
*-lowering-*.f64N/A
metadata-evalN/A
pow-sqrN/A
*-lowering-*.f64N/A
unpow2N/A
*-lowering-*.f64N/A
unpow2N/A
*-lowering-*.f6499.5
Simplified99.5%
associate-*r/N/A
/-lowering-/.f64N/A
Applied egg-rr99.5%
(FPCore (x) :precision binary64 (* x (fma x (fma x (fma x 0.041666666666666664 0.16666666666666666) 0.5) 1.0)))
double code(double x) {
return x * fma(x, fma(x, fma(x, 0.041666666666666664, 0.16666666666666666), 0.5), 1.0);
}
function code(x) return Float64(x * fma(x, fma(x, fma(x, 0.041666666666666664, 0.16666666666666666), 0.5), 1.0)) end
code[x_] := N[(x * N[(x * N[(x * N[(x * 0.041666666666666664 + 0.16666666666666666), $MachinePrecision] + 0.5), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \mathsf{fma}\left(x, \mathsf{fma}\left(x, \mathsf{fma}\left(x, 0.041666666666666664, 0.16666666666666666\right), 0.5\right), 1\right)
\end{array}
Initial program 8.9%
Taylor expanded in x around 0
*-lowering-*.f64N/A
+-commutativeN/A
accelerator-lowering-fma.f64N/A
+-commutativeN/A
accelerator-lowering-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f6499.5
Simplified99.5%
(FPCore (x) :precision binary64 (fma (fma x 0.16666666666666666 0.5) (* x x) x))
double code(double x) {
return fma(fma(x, 0.16666666666666666, 0.5), (x * x), x);
}
function code(x) return fma(fma(x, 0.16666666666666666, 0.5), Float64(x * x), x) end
code[x_] := N[(N[(x * 0.16666666666666666 + 0.5), $MachinePrecision] * N[(x * x), $MachinePrecision] + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\mathsf{fma}\left(x, 0.16666666666666666, 0.5\right), x \cdot x, x\right)
\end{array}
Initial program 8.9%
Taylor expanded in x around 0
*-lowering-*.f64N/A
+-commutativeN/A
accelerator-lowering-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f6499.1
Simplified99.1%
distribute-rgt-inN/A
*-commutativeN/A
associate-*l*N/A
*-lft-identityN/A
accelerator-lowering-fma.f64N/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f6499.2
Applied egg-rr99.2%
(FPCore (x) :precision binary64 (* x (fma x (fma x 0.16666666666666666 0.5) 1.0)))
double code(double x) {
return x * fma(x, fma(x, 0.16666666666666666, 0.5), 1.0);
}
function code(x) return Float64(x * fma(x, fma(x, 0.16666666666666666, 0.5), 1.0)) end
code[x_] := N[(x * N[(x * N[(x * 0.16666666666666666 + 0.5), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \mathsf{fma}\left(x, \mathsf{fma}\left(x, 0.16666666666666666, 0.5\right), 1\right)
\end{array}
Initial program 8.9%
Taylor expanded in x around 0
*-lowering-*.f64N/A
+-commutativeN/A
accelerator-lowering-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f6499.1
Simplified99.1%
(FPCore (x) :precision binary64 (fma (* x x) 0.5 x))
double code(double x) {
return fma((x * x), 0.5, x);
}
function code(x) return fma(Float64(x * x), 0.5, x) end
code[x_] := N[(N[(x * x), $MachinePrecision] * 0.5 + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x \cdot x, 0.5, x\right)
\end{array}
Initial program 8.9%
Taylor expanded in x around 0
*-lowering-*.f64N/A
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f6498.8
Simplified98.8%
distribute-lft-inN/A
associate-*r*N/A
*-rgt-identityN/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f6498.8
Applied egg-rr98.8%
(FPCore (x) :precision binary64 (* x (fma x 0.5 1.0)))
double code(double x) {
return x * fma(x, 0.5, 1.0);
}
function code(x) return Float64(x * fma(x, 0.5, 1.0)) end
code[x_] := N[(x * N[(x * 0.5 + 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \mathsf{fma}\left(x, 0.5, 1\right)
\end{array}
Initial program 8.9%
Taylor expanded in x around 0
*-lowering-*.f64N/A
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f6498.8
Simplified98.8%
(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}
Initial program 8.9%
Taylor expanded in x around 0
Simplified97.5%
(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}
herbie shell --seed 2024198
(FPCore (x)
:name "expm1 (example 3.7)"
:precision binary64
:pre (<= (fabs x) 1.0)
:alt
(! :herbie-platform default (expm1 x))
(- (exp x) 1.0))