
(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 9 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.2%
lower-expm1.f64100.0
Applied rewrites100.0%
(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 8.2%
Taylor expanded in x around 0
+-commutativeN/A
distribute-rgt-inN/A
*-lft-identityN/A
*-commutativeN/A
associate-*l*N/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-*.f6499.9
Applied rewrites99.9%
(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.2%
Taylor expanded in x around 0
+-commutativeN/A
distribute-rgt-inN/A
*-lft-identityN/A
*-commutativeN/A
associate-*l*N/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-*.f6499.9
Applied rewrites99.9%
lift-fma.f64N/A
lift-fma.f64N/A
lift-*.f64N/A
lift-*.f64N/A
associate-*r*N/A
distribute-lft1-inN/A
lower-*.f64N/A
*-commutativeN/A
lower-fma.f6499.9
Applied rewrites99.9%
Final simplification99.9%
(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.2%
Taylor expanded in x around 0
+-commutativeN/A
distribute-rgt-inN/A
*-commutativeN/A
associate-*l*N/A
*-lft-identityN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-*.f6499.7
Applied rewrites99.7%
(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.2%
Taylor expanded in x around 0
+-commutativeN/A
distribute-rgt-inN/A
*-commutativeN/A
associate-*l*N/A
*-lft-identityN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-*.f6499.7
Applied rewrites99.7%
lift-fma.f64N/A
lift-*.f64N/A
lift-*.f64N/A
associate-*r*N/A
distribute-lft1-inN/A
lower-*.f64N/A
*-commutativeN/A
lower-fma.f6499.7
Applied rewrites99.7%
Final simplification99.7%
(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 8.2%
Taylor expanded in x around 0
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6499.1
Applied rewrites99.1%
(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.2%
Taylor expanded in x around 0
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6499.1
Applied rewrites99.1%
lift-*.f64N/A
*-commutativeN/A
distribute-lft1-inN/A
lower-*.f64N/A
lift-*.f64N/A
lower-fma.f6499.1
Applied rewrites99.1%
Final simplification99.1%
(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.2%
Taylor expanded in x around 0
+-commutativeN/A
distribute-rgt-inN/A
*-lft-identityN/A
*-commutativeN/A
associate-*l*N/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-*.f6499.9
Applied rewrites99.9%
lift-fma.f64N/A
lift-fma.f64N/A
lift-*.f64N/A
lift-*.f64N/A
associate-*r*N/A
distribute-lft1-inN/A
lower-*.f64N/A
*-commutativeN/A
lower-fma.f6499.9
Applied rewrites99.9%
Taylor expanded in x around 0
Applied rewrites98.2%
*-lft-identity98.2
Applied rewrites98.2%
(FPCore (x) :precision binary64 0.0)
double code(double x) {
return 0.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = 0.0d0
end function
public static double code(double x) {
return 0.0;
}
def code(x): return 0.0
function code(x) return 0.0 end
function tmp = code(x) tmp = 0.0; end
code[x_] := 0.0
\begin{array}{l}
\\
0
\end{array}
Initial program 8.2%
Taylor expanded in x around 0
Applied rewrites5.4%
metadata-eval5.4
Applied rewrites5.4%
(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 2024216
(FPCore (x)
:name "expm1 (example 3.7)"
:precision binary64
:pre (<= (fabs x) 1.0)
:alt
(! :herbie-platform default (expm1 x))
(- (exp x) 1.0))