
(FPCore (x) :precision binary64 (/ (exp x) (- (exp x) 1.0)))
double code(double x) {
return exp(x) / (exp(x) - 1.0);
}
real(8) function code(x)
real(8), intent (in) :: x
code = exp(x) / (exp(x) - 1.0d0)
end function
public static double code(double x) {
return Math.exp(x) / (Math.exp(x) - 1.0);
}
def code(x): return math.exp(x) / (math.exp(x) - 1.0)
function code(x) return Float64(exp(x) / Float64(exp(x) - 1.0)) end
function tmp = code(x) tmp = exp(x) / (exp(x) - 1.0); end
code[x_] := N[(N[Exp[x], $MachinePrecision] / N[(N[Exp[x], $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{e^{x}}{e^{x} - 1}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 14 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x) :precision binary64 (/ (exp x) (- (exp x) 1.0)))
double code(double x) {
return exp(x) / (exp(x) - 1.0);
}
real(8) function code(x)
real(8), intent (in) :: x
code = exp(x) / (exp(x) - 1.0d0)
end function
public static double code(double x) {
return Math.exp(x) / (Math.exp(x) - 1.0);
}
def code(x): return math.exp(x) / (math.exp(x) - 1.0)
function code(x) return Float64(exp(x) / Float64(exp(x) - 1.0)) end
function tmp = code(x) tmp = exp(x) / (exp(x) - 1.0); end
code[x_] := N[(N[Exp[x], $MachinePrecision] / N[(N[Exp[x], $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{e^{x}}{e^{x} - 1}
\end{array}
(FPCore (x) :precision binary64 (/ -1.0 (expm1 (- x))))
double code(double x) {
return -1.0 / expm1(-x);
}
public static double code(double x) {
return -1.0 / Math.expm1(-x);
}
def code(x): return -1.0 / math.expm1(-x)
function code(x) return Float64(-1.0 / expm1(Float64(-x))) end
code[x_] := N[(-1.0 / N[(Exp[(-x)] - 1), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{-1}{\mathsf{expm1}\left(-x\right)}
\end{array}
Initial program 39.8%
lift-/.f64N/A
clear-numN/A
frac-2negN/A
lower-/.f64N/A
metadata-evalN/A
distribute-neg-fracN/A
neg-sub0N/A
lift--.f64N/A
associate-+l-N/A
neg-sub0N/A
+-commutativeN/A
sub-negN/A
div-subN/A
lift-exp.f64N/A
rec-expN/A
*-inversesN/A
lower-expm1.f64N/A
lower-neg.f64100.0
Applied rewrites100.0%
(FPCore (x)
:precision binary64
(if (<= (exp x) 1e-101)
(/
-1.0
(* (* (fma (fma 0.041666666666666664 x -0.16666666666666666) x 0.5) x) x))
(fma
(fma (* x x) -0.001388888888888889 0.08333333333333333)
x
(+ (/ 1.0 x) 0.5))))
double code(double x) {
double tmp;
if (exp(x) <= 1e-101) {
tmp = -1.0 / ((fma(fma(0.041666666666666664, x, -0.16666666666666666), x, 0.5) * x) * x);
} else {
tmp = fma(fma((x * x), -0.001388888888888889, 0.08333333333333333), x, ((1.0 / x) + 0.5));
}
return tmp;
}
function code(x) tmp = 0.0 if (exp(x) <= 1e-101) tmp = Float64(-1.0 / Float64(Float64(fma(fma(0.041666666666666664, x, -0.16666666666666666), x, 0.5) * x) * x)); else tmp = fma(fma(Float64(x * x), -0.001388888888888889, 0.08333333333333333), x, Float64(Float64(1.0 / x) + 0.5)); end return tmp end
code[x_] := If[LessEqual[N[Exp[x], $MachinePrecision], 1e-101], N[(-1.0 / N[(N[(N[(N[(0.041666666666666664 * x + -0.16666666666666666), $MachinePrecision] * x + 0.5), $MachinePrecision] * x), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision], N[(N[(N[(x * x), $MachinePrecision] * -0.001388888888888889 + 0.08333333333333333), $MachinePrecision] * x + N[(N[(1.0 / x), $MachinePrecision] + 0.5), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;e^{x} \leq 10^{-101}:\\
\;\;\;\;\frac{-1}{\left(\mathsf{fma}\left(\mathsf{fma}\left(0.041666666666666664, x, -0.16666666666666666\right), x, 0.5\right) \cdot x\right) \cdot x}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(x \cdot x, -0.001388888888888889, 0.08333333333333333\right), x, \frac{1}{x} + 0.5\right)\\
\end{array}
\end{array}
if (exp.f64 x) < 1.00000000000000005e-101Initial program 100.0%
lift-/.f64N/A
clear-numN/A
frac-2negN/A
lower-/.f64N/A
metadata-evalN/A
distribute-neg-fracN/A
neg-sub0N/A
lift--.f64N/A
associate-+l-N/A
neg-sub0N/A
+-commutativeN/A
sub-negN/A
div-subN/A
lift-exp.f64N/A
rec-expN/A
*-inversesN/A
lower-expm1.f64N/A
lower-neg.f64100.0
Applied rewrites100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
sub-negN/A
*-commutativeN/A
metadata-evalN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
sub-negN/A
metadata-evalN/A
lower-fma.f6476.1
Applied rewrites76.1%
Taylor expanded in x around inf
Applied rewrites76.1%
if 1.00000000000000005e-101 < (exp.f64 x) Initial program 6.6%
Taylor expanded in x around 0
*-lft-identityN/A
associate-/l*N/A
associate-*l/N/A
distribute-lft-inN/A
*-commutativeN/A
associate-+r+N/A
distribute-lft-inN/A
associate-*l/N/A
*-lft-identityN/A
+-commutativeN/A
associate-*r*N/A
lft-mult-inverseN/A
*-lft-identityN/A
*-commutativeN/A
Applied rewrites98.3%
Final simplification90.4%
(FPCore (x)
:precision binary64
(if (<= (exp x) 1e-101)
(/ -1.0 (* (* (* (fma 0.041666666666666664 x -0.16666666666666666) x) x) x))
(fma
(fma (* x x) -0.001388888888888889 0.08333333333333333)
x
(+ (/ 1.0 x) 0.5))))
double code(double x) {
double tmp;
if (exp(x) <= 1e-101) {
tmp = -1.0 / (((fma(0.041666666666666664, x, -0.16666666666666666) * x) * x) * x);
} else {
tmp = fma(fma((x * x), -0.001388888888888889, 0.08333333333333333), x, ((1.0 / x) + 0.5));
}
return tmp;
}
function code(x) tmp = 0.0 if (exp(x) <= 1e-101) tmp = Float64(-1.0 / Float64(Float64(Float64(fma(0.041666666666666664, x, -0.16666666666666666) * x) * x) * x)); else tmp = fma(fma(Float64(x * x), -0.001388888888888889, 0.08333333333333333), x, Float64(Float64(1.0 / x) + 0.5)); end return tmp end
code[x_] := If[LessEqual[N[Exp[x], $MachinePrecision], 1e-101], N[(-1.0 / N[(N[(N[(N[(0.041666666666666664 * x + -0.16666666666666666), $MachinePrecision] * x), $MachinePrecision] * x), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision], N[(N[(N[(x * x), $MachinePrecision] * -0.001388888888888889 + 0.08333333333333333), $MachinePrecision] * x + N[(N[(1.0 / x), $MachinePrecision] + 0.5), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;e^{x} \leq 10^{-101}:\\
\;\;\;\;\frac{-1}{\left(\left(\mathsf{fma}\left(0.041666666666666664, x, -0.16666666666666666\right) \cdot x\right) \cdot x\right) \cdot x}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(x \cdot x, -0.001388888888888889, 0.08333333333333333\right), x, \frac{1}{x} + 0.5\right)\\
\end{array}
\end{array}
if (exp.f64 x) < 1.00000000000000005e-101Initial program 100.0%
lift-/.f64N/A
clear-numN/A
frac-2negN/A
lower-/.f64N/A
metadata-evalN/A
distribute-neg-fracN/A
neg-sub0N/A
lift--.f64N/A
associate-+l-N/A
neg-sub0N/A
+-commutativeN/A
sub-negN/A
div-subN/A
lift-exp.f64N/A
rec-expN/A
*-inversesN/A
lower-expm1.f64N/A
lower-neg.f64100.0
Applied rewrites100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
sub-negN/A
*-commutativeN/A
metadata-evalN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
sub-negN/A
metadata-evalN/A
lower-fma.f6476.1
Applied rewrites76.1%
Taylor expanded in x around inf
Applied rewrites76.1%
if 1.00000000000000005e-101 < (exp.f64 x) Initial program 6.6%
Taylor expanded in x around 0
*-lft-identityN/A
associate-/l*N/A
associate-*l/N/A
distribute-lft-inN/A
*-commutativeN/A
associate-+r+N/A
distribute-lft-inN/A
associate-*l/N/A
*-lft-identityN/A
+-commutativeN/A
associate-*r*N/A
lft-mult-inverseN/A
*-lft-identityN/A
*-commutativeN/A
Applied rewrites98.3%
Final simplification90.4%
(FPCore (x) :precision binary64 (if (<= (exp x) 1e-101) (/ -1.0 (* (* 0.5 x) x)) (fma 0.08333333333333333 x (+ (/ 1.0 x) 0.5))))
double code(double x) {
double tmp;
if (exp(x) <= 1e-101) {
tmp = -1.0 / ((0.5 * x) * x);
} else {
tmp = fma(0.08333333333333333, x, ((1.0 / x) + 0.5));
}
return tmp;
}
function code(x) tmp = 0.0 if (exp(x) <= 1e-101) tmp = Float64(-1.0 / Float64(Float64(0.5 * x) * x)); else tmp = fma(0.08333333333333333, x, Float64(Float64(1.0 / x) + 0.5)); end return tmp end
code[x_] := If[LessEqual[N[Exp[x], $MachinePrecision], 1e-101], N[(-1.0 / N[(N[(0.5 * x), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision], N[(0.08333333333333333 * x + N[(N[(1.0 / x), $MachinePrecision] + 0.5), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;e^{x} \leq 10^{-101}:\\
\;\;\;\;\frac{-1}{\left(0.5 \cdot x\right) \cdot x}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(0.08333333333333333, x, \frac{1}{x} + 0.5\right)\\
\end{array}
\end{array}
if (exp.f64 x) < 1.00000000000000005e-101Initial program 100.0%
lift-/.f64N/A
clear-numN/A
frac-2negN/A
lower-/.f64N/A
metadata-evalN/A
distribute-neg-fracN/A
neg-sub0N/A
lift--.f64N/A
associate-+l-N/A
neg-sub0N/A
+-commutativeN/A
sub-negN/A
div-subN/A
lift-exp.f64N/A
rec-expN/A
*-inversesN/A
lower-expm1.f64N/A
lower-neg.f64100.0
Applied rewrites100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
sub-negN/A
metadata-evalN/A
lower-fma.f6451.3
Applied rewrites51.3%
Taylor expanded in x around inf
Applied rewrites51.3%
if 1.00000000000000005e-101 < (exp.f64 x) Initial program 6.6%
Taylor expanded in x around 0
*-lft-identityN/A
associate-/l*N/A
associate-*l/N/A
distribute-lft-inN/A
*-commutativeN/A
associate-+r+N/A
distribute-rgt-inN/A
associate-/l*N/A
*-rgt-identityN/A
*-commutativeN/A
associate-*r*N/A
lft-mult-inverseN/A
*-lft-identityN/A
+-commutativeN/A
lower-fma.f64N/A
*-rgt-identityN/A
associate-/l*N/A
+-commutativeN/A
distribute-lft1-inN/A
lower-+.f64N/A
Applied rewrites98.2%
Final simplification81.5%
(FPCore (x)
:precision binary64
(/
-1.0
(*
(fma
(fma
(*
(fma (fma (fma 0.09375 x -0.375) x 1.5) x -6.0)
(- (fma 0.001736111111111111 (* x x) -0.027777777777777776)))
x
0.5)
x
-1.0)
x)))
double code(double x) {
return -1.0 / (fma(fma((fma(fma(fma(0.09375, x, -0.375), x, 1.5), x, -6.0) * -fma(0.001736111111111111, (x * x), -0.027777777777777776)), x, 0.5), x, -1.0) * x);
}
function code(x) return Float64(-1.0 / Float64(fma(fma(Float64(fma(fma(fma(0.09375, x, -0.375), x, 1.5), x, -6.0) * Float64(-fma(0.001736111111111111, Float64(x * x), -0.027777777777777776))), x, 0.5), x, -1.0) * x)) end
code[x_] := N[(-1.0 / N[(N[(N[(N[(N[(N[(N[(0.09375 * x + -0.375), $MachinePrecision] * x + 1.5), $MachinePrecision] * x + -6.0), $MachinePrecision] * (-N[(0.001736111111111111 * N[(x * x), $MachinePrecision] + -0.027777777777777776), $MachinePrecision])), $MachinePrecision] * x + 0.5), $MachinePrecision] * x + -1.0), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{-1}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.09375, x, -0.375\right), x, 1.5\right), x, -6\right) \cdot \left(-\mathsf{fma}\left(0.001736111111111111, x \cdot x, -0.027777777777777776\right)\right), x, 0.5\right), x, -1\right) \cdot x}
\end{array}
Initial program 39.8%
lift-/.f64N/A
clear-numN/A
frac-2negN/A
lower-/.f64N/A
metadata-evalN/A
distribute-neg-fracN/A
neg-sub0N/A
lift--.f64N/A
associate-+l-N/A
neg-sub0N/A
+-commutativeN/A
sub-negN/A
div-subN/A
lift-exp.f64N/A
rec-expN/A
*-inversesN/A
lower-expm1.f64N/A
lower-neg.f64100.0
Applied rewrites100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
sub-negN/A
*-commutativeN/A
metadata-evalN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
sub-negN/A
metadata-evalN/A
lower-fma.f6490.2
Applied rewrites90.2%
Applied rewrites90.2%
Taylor expanded in x around 0
Applied rewrites93.5%
Final simplification93.5%
(FPCore (x)
:precision binary64
(/
-1.0
(*
(fma
(fma
(*
(fma (fma -0.375 x 1.5) x -6.0)
(- (fma 0.001736111111111111 (* x x) -0.027777777777777776)))
x
0.5)
x
-1.0)
x)))
double code(double x) {
return -1.0 / (fma(fma((fma(fma(-0.375, x, 1.5), x, -6.0) * -fma(0.001736111111111111, (x * x), -0.027777777777777776)), x, 0.5), x, -1.0) * x);
}
function code(x) return Float64(-1.0 / Float64(fma(fma(Float64(fma(fma(-0.375, x, 1.5), x, -6.0) * Float64(-fma(0.001736111111111111, Float64(x * x), -0.027777777777777776))), x, 0.5), x, -1.0) * x)) end
code[x_] := N[(-1.0 / N[(N[(N[(N[(N[(N[(-0.375 * x + 1.5), $MachinePrecision] * x + -6.0), $MachinePrecision] * (-N[(0.001736111111111111 * N[(x * x), $MachinePrecision] + -0.027777777777777776), $MachinePrecision])), $MachinePrecision] * x + 0.5), $MachinePrecision] * x + -1.0), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{-1}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(-0.375, x, 1.5\right), x, -6\right) \cdot \left(-\mathsf{fma}\left(0.001736111111111111, x \cdot x, -0.027777777777777776\right)\right), x, 0.5\right), x, -1\right) \cdot x}
\end{array}
Initial program 39.8%
lift-/.f64N/A
clear-numN/A
frac-2negN/A
lower-/.f64N/A
metadata-evalN/A
distribute-neg-fracN/A
neg-sub0N/A
lift--.f64N/A
associate-+l-N/A
neg-sub0N/A
+-commutativeN/A
sub-negN/A
div-subN/A
lift-exp.f64N/A
rec-expN/A
*-inversesN/A
lower-expm1.f64N/A
lower-neg.f64100.0
Applied rewrites100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
sub-negN/A
*-commutativeN/A
metadata-evalN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
sub-negN/A
metadata-evalN/A
lower-fma.f6490.2
Applied rewrites90.2%
Applied rewrites90.2%
Taylor expanded in x around 0
Applied rewrites93.4%
Final simplification93.4%
(FPCore (x)
:precision binary64
(/
-1.0
(*
(fma
(fma
(*
(fma 1.5 x -6.0)
(- (fma 0.001736111111111111 (* x x) -0.027777777777777776)))
x
0.5)
x
-1.0)
x)))
double code(double x) {
return -1.0 / (fma(fma((fma(1.5, x, -6.0) * -fma(0.001736111111111111, (x * x), -0.027777777777777776)), x, 0.5), x, -1.0) * x);
}
function code(x) return Float64(-1.0 / Float64(fma(fma(Float64(fma(1.5, x, -6.0) * Float64(-fma(0.001736111111111111, Float64(x * x), -0.027777777777777776))), x, 0.5), x, -1.0) * x)) end
code[x_] := N[(-1.0 / N[(N[(N[(N[(N[(1.5 * x + -6.0), $MachinePrecision] * (-N[(0.001736111111111111 * N[(x * x), $MachinePrecision] + -0.027777777777777776), $MachinePrecision])), $MachinePrecision] * x + 0.5), $MachinePrecision] * x + -1.0), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{-1}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(1.5, x, -6\right) \cdot \left(-\mathsf{fma}\left(0.001736111111111111, x \cdot x, -0.027777777777777776\right)\right), x, 0.5\right), x, -1\right) \cdot x}
\end{array}
Initial program 39.8%
lift-/.f64N/A
clear-numN/A
frac-2negN/A
lower-/.f64N/A
metadata-evalN/A
distribute-neg-fracN/A
neg-sub0N/A
lift--.f64N/A
associate-+l-N/A
neg-sub0N/A
+-commutativeN/A
sub-negN/A
div-subN/A
lift-exp.f64N/A
rec-expN/A
*-inversesN/A
lower-expm1.f64N/A
lower-neg.f64100.0
Applied rewrites100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
sub-negN/A
*-commutativeN/A
metadata-evalN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
sub-negN/A
metadata-evalN/A
lower-fma.f6490.2
Applied rewrites90.2%
Applied rewrites90.2%
Taylor expanded in x around 0
Applied rewrites93.1%
Final simplification93.1%
(FPCore (x)
:precision binary64
(/
-1.0
(*
(fma
(fma
(* -6.0 (- (fma 0.001736111111111111 (* x x) -0.027777777777777776)))
x
0.5)
x
-1.0)
x)))
double code(double x) {
return -1.0 / (fma(fma((-6.0 * -fma(0.001736111111111111, (x * x), -0.027777777777777776)), x, 0.5), x, -1.0) * x);
}
function code(x) return Float64(-1.0 / Float64(fma(fma(Float64(-6.0 * Float64(-fma(0.001736111111111111, Float64(x * x), -0.027777777777777776))), x, 0.5), x, -1.0) * x)) end
code[x_] := N[(-1.0 / N[(N[(N[(N[(-6.0 * (-N[(0.001736111111111111 * N[(x * x), $MachinePrecision] + -0.027777777777777776), $MachinePrecision])), $MachinePrecision] * x + 0.5), $MachinePrecision] * x + -1.0), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{-1}{\mathsf{fma}\left(\mathsf{fma}\left(-6 \cdot \left(-\mathsf{fma}\left(0.001736111111111111, x \cdot x, -0.027777777777777776\right)\right), x, 0.5\right), x, -1\right) \cdot x}
\end{array}
Initial program 39.8%
lift-/.f64N/A
clear-numN/A
frac-2negN/A
lower-/.f64N/A
metadata-evalN/A
distribute-neg-fracN/A
neg-sub0N/A
lift--.f64N/A
associate-+l-N/A
neg-sub0N/A
+-commutativeN/A
sub-negN/A
div-subN/A
lift-exp.f64N/A
rec-expN/A
*-inversesN/A
lower-expm1.f64N/A
lower-neg.f64100.0
Applied rewrites100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
sub-negN/A
*-commutativeN/A
metadata-evalN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
sub-negN/A
metadata-evalN/A
lower-fma.f6490.2
Applied rewrites90.2%
Applied rewrites90.2%
Taylor expanded in x around 0
Applied rewrites91.2%
Final simplification91.2%
(FPCore (x) :precision binary64 (/ -1.0 (* (fma (fma (fma 0.041666666666666664 x -0.16666666666666666) x 0.5) x -1.0) x)))
double code(double x) {
return -1.0 / (fma(fma(fma(0.041666666666666664, x, -0.16666666666666666), x, 0.5), x, -1.0) * x);
}
function code(x) return Float64(-1.0 / Float64(fma(fma(fma(0.041666666666666664, x, -0.16666666666666666), x, 0.5), x, -1.0) * x)) end
code[x_] := N[(-1.0 / N[(N[(N[(N[(0.041666666666666664 * x + -0.16666666666666666), $MachinePrecision] * x + 0.5), $MachinePrecision] * x + -1.0), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{-1}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.041666666666666664, x, -0.16666666666666666\right), x, 0.5\right), x, -1\right) \cdot x}
\end{array}
Initial program 39.8%
lift-/.f64N/A
clear-numN/A
frac-2negN/A
lower-/.f64N/A
metadata-evalN/A
distribute-neg-fracN/A
neg-sub0N/A
lift--.f64N/A
associate-+l-N/A
neg-sub0N/A
+-commutativeN/A
sub-negN/A
div-subN/A
lift-exp.f64N/A
rec-expN/A
*-inversesN/A
lower-expm1.f64N/A
lower-neg.f64100.0
Applied rewrites100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
sub-negN/A
*-commutativeN/A
metadata-evalN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
sub-negN/A
metadata-evalN/A
lower-fma.f6490.2
Applied rewrites90.2%
(FPCore (x) :precision binary64 (if (<= x -3.45) (/ -1.0 (* (* (fma -0.16666666666666666 x 0.5) x) x)) (fma 0.08333333333333333 x (+ (/ 1.0 x) 0.5))))
double code(double x) {
double tmp;
if (x <= -3.45) {
tmp = -1.0 / ((fma(-0.16666666666666666, x, 0.5) * x) * x);
} else {
tmp = fma(0.08333333333333333, x, ((1.0 / x) + 0.5));
}
return tmp;
}
function code(x) tmp = 0.0 if (x <= -3.45) tmp = Float64(-1.0 / Float64(Float64(fma(-0.16666666666666666, x, 0.5) * x) * x)); else tmp = fma(0.08333333333333333, x, Float64(Float64(1.0 / x) + 0.5)); end return tmp end
code[x_] := If[LessEqual[x, -3.45], N[(-1.0 / N[(N[(N[(-0.16666666666666666 * x + 0.5), $MachinePrecision] * x), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision], N[(0.08333333333333333 * x + N[(N[(1.0 / x), $MachinePrecision] + 0.5), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.45:\\
\;\;\;\;\frac{-1}{\left(\mathsf{fma}\left(-0.16666666666666666, x, 0.5\right) \cdot x\right) \cdot x}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(0.08333333333333333, x, \frac{1}{x} + 0.5\right)\\
\end{array}
\end{array}
if x < -3.4500000000000002Initial program 100.0%
lift-/.f64N/A
clear-numN/A
frac-2negN/A
lower-/.f64N/A
metadata-evalN/A
distribute-neg-fracN/A
neg-sub0N/A
lift--.f64N/A
associate-+l-N/A
neg-sub0N/A
+-commutativeN/A
sub-negN/A
div-subN/A
lift-exp.f64N/A
rec-expN/A
*-inversesN/A
lower-expm1.f64N/A
lower-neg.f64100.0
Applied rewrites100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
sub-negN/A
*-commutativeN/A
metadata-evalN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
sub-negN/A
metadata-evalN/A
lower-fma.f6476.1
Applied rewrites76.1%
Taylor expanded in x around inf
Applied rewrites76.1%
Taylor expanded in x around 0
Applied rewrites69.8%
if -3.4500000000000002 < x Initial program 6.6%
Taylor expanded in x around 0
*-lft-identityN/A
associate-/l*N/A
associate-*l/N/A
distribute-lft-inN/A
*-commutativeN/A
associate-+r+N/A
distribute-rgt-inN/A
associate-/l*N/A
*-rgt-identityN/A
*-commutativeN/A
associate-*r*N/A
lft-mult-inverseN/A
*-lft-identityN/A
+-commutativeN/A
lower-fma.f64N/A
*-rgt-identityN/A
associate-/l*N/A
+-commutativeN/A
distribute-lft1-inN/A
lower-+.f64N/A
Applied rewrites98.2%
Final simplification88.1%
(FPCore (x) :precision binary64 (/ -1.0 (* (fma (fma -0.16666666666666666 x 0.5) x -1.0) x)))
double code(double x) {
return -1.0 / (fma(fma(-0.16666666666666666, x, 0.5), x, -1.0) * x);
}
function code(x) return Float64(-1.0 / Float64(fma(fma(-0.16666666666666666, x, 0.5), x, -1.0) * x)) end
code[x_] := N[(-1.0 / N[(N[(N[(-0.16666666666666666 * x + 0.5), $MachinePrecision] * x + -1.0), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{-1}{\mathsf{fma}\left(\mathsf{fma}\left(-0.16666666666666666, x, 0.5\right), x, -1\right) \cdot x}
\end{array}
Initial program 39.8%
lift-/.f64N/A
clear-numN/A
frac-2negN/A
lower-/.f64N/A
metadata-evalN/A
distribute-neg-fracN/A
neg-sub0N/A
lift--.f64N/A
associate-+l-N/A
neg-sub0N/A
+-commutativeN/A
sub-negN/A
div-subN/A
lift-exp.f64N/A
rec-expN/A
*-inversesN/A
lower-expm1.f64N/A
lower-neg.f64100.0
Applied rewrites100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
sub-negN/A
*-commutativeN/A
metadata-evalN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f6487.9
Applied rewrites87.9%
(FPCore (x) :precision binary64 (/ -1.0 (* (fma 0.5 x -1.0) x)))
double code(double x) {
return -1.0 / (fma(0.5, x, -1.0) * x);
}
function code(x) return Float64(-1.0 / Float64(fma(0.5, x, -1.0) * x)) end
code[x_] := N[(-1.0 / N[(N[(0.5 * x + -1.0), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{-1}{\mathsf{fma}\left(0.5, x, -1\right) \cdot x}
\end{array}
Initial program 39.8%
lift-/.f64N/A
clear-numN/A
frac-2negN/A
lower-/.f64N/A
metadata-evalN/A
distribute-neg-fracN/A
neg-sub0N/A
lift--.f64N/A
associate-+l-N/A
neg-sub0N/A
+-commutativeN/A
sub-negN/A
div-subN/A
lift-exp.f64N/A
rec-expN/A
*-inversesN/A
lower-expm1.f64N/A
lower-neg.f64100.0
Applied rewrites100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
sub-negN/A
metadata-evalN/A
lower-fma.f6481.0
Applied rewrites81.0%
(FPCore (x) :precision binary64 (/ 1.0 x))
double code(double x) {
return 1.0 / x;
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0 / x
end function
public static double code(double x) {
return 1.0 / x;
}
def code(x): return 1.0 / x
function code(x) return Float64(1.0 / x) end
function tmp = code(x) tmp = 1.0 / x; end
code[x_] := N[(1.0 / x), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{x}
\end{array}
Initial program 39.8%
Taylor expanded in x around 0
lower-/.f6464.5
Applied rewrites64.5%
(FPCore (x) :precision binary64 0.5)
double code(double x) {
return 0.5;
}
real(8) function code(x)
real(8), intent (in) :: x
code = 0.5d0
end function
public static double code(double x) {
return 0.5;
}
def code(x): return 0.5
function code(x) return 0.5 end
function tmp = code(x) tmp = 0.5; end
code[x_] := 0.5
\begin{array}{l}
\\
0.5
\end{array}
Initial program 39.8%
Taylor expanded in x around 0
*-rgt-identityN/A
associate-/l*N/A
+-commutativeN/A
distribute-lft1-inN/A
lower-+.f64N/A
associate-*l*N/A
rgt-mult-inverseN/A
metadata-evalN/A
lower-/.f6464.0
Applied rewrites64.0%
Taylor expanded in x around inf
Applied rewrites3.3%
(FPCore (x) :precision binary64 (/ (- 1.0) (expm1 (- x))))
double code(double x) {
return -1.0 / expm1(-x);
}
public static double code(double x) {
return -1.0 / Math.expm1(-x);
}
def code(x): return -1.0 / math.expm1(-x)
function code(x) return Float64(Float64(-1.0) / expm1(Float64(-x))) end
code[x_] := N[((-1.0) / N[(Exp[(-x)] - 1), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{-1}{\mathsf{expm1}\left(-x\right)}
\end{array}
herbie shell --seed 2024242
(FPCore (x)
:name "expq2 (section 3.11)"
:precision binary64
:pre (> 710.0 x)
:alt
(! :herbie-platform default (/ (- 1) (expm1 (- x))))
(/ (exp x) (- (exp x) 1.0)))