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