
(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 6 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 7.9%
accelerator-lowering-expm1.f64100.0
Applied egg-rr100.0%
(FPCore (x) :precision binary64 (/ x (fma x (fma x 0.08333333333333333 -0.5) 1.0)))
double code(double x) {
return x / fma(x, fma(x, 0.08333333333333333, -0.5), 1.0);
}
function code(x) return Float64(x / fma(x, fma(x, 0.08333333333333333, -0.5), 1.0)) end
code[x_] := N[(x / N[(x * N[(x * 0.08333333333333333 + -0.5), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x}{\mathsf{fma}\left(x, \mathsf{fma}\left(x, 0.08333333333333333, -0.5\right), 1\right)}
\end{array}
Initial program 7.9%
Taylor expanded in x around 0
+-commutativeN/A
distribute-rgt-inN/A
*-lft-identityN/A
*-commutativeN/A
associate-*l*N/A
accelerator-lowering-fma.f64N/A
+-commutativeN/A
accelerator-lowering-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f6499.7
Simplified99.7%
flip-+N/A
clear-numN/A
/-lowering-/.f64N/A
clear-numN/A
flip-+N/A
/-lowering-/.f64N/A
*-commutativeN/A
Applied egg-rr99.4%
Taylor expanded in x around 0
/-lowering-/.f64N/A
+-commutativeN/A
accelerator-lowering-fma.f64N/A
sub-negN/A
*-commutativeN/A
metadata-evalN/A
accelerator-lowering-fma.f6499.4
Simplified99.4%
clear-numN/A
/-lowering-/.f64N/A
accelerator-lowering-fma.f64N/A
accelerator-lowering-fma.f6499.7
Applied egg-rr99.7%
(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 7.9%
Taylor expanded in x around 0
+-commutativeN/A
distribute-rgt-inN/A
*-commutativeN/A
associate-*l*N/A
*-lft-identityN/A
accelerator-lowering-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f6499.5
Simplified99.5%
(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(x, Float64(x * 0.5), x) end
code[x_] := N[(x * N[(x * 0.5), $MachinePrecision] + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x, x \cdot 0.5, x\right)
\end{array}
Initial program 7.9%
Taylor expanded in x around 0
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
accelerator-lowering-fma.f64N/A
*-commutativeN/A
*-lowering-*.f6499.2
Simplified99.2%
(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 7.9%
Taylor expanded in x around 0
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
accelerator-lowering-fma.f64N/A
*-commutativeN/A
*-lowering-*.f6499.2
Simplified99.2%
*-commutativeN/A
distribute-lft1-inN/A
*-lowering-*.f64N/A
accelerator-lowering-fma.f6499.2
Applied egg-rr99.2%
Final simplification99.2%
(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 7.9%
Taylor expanded in x around 0
Simplified98.3%
(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 2024199
(FPCore (x)
:name "expm1 (example 3.7)"
:precision binary64
:pre (<= (fabs x) 1.0)
:alt
(! :herbie-platform default (expm1 x))
(- (exp x) 1.0))