
(FPCore (x y z) :precision binary64 (- (+ (- x (* (+ y 0.5) (log y))) y) z))
double code(double x, double y, double z) {
return ((x - ((y + 0.5) * log(y))) + y) - z;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = ((x - ((y + 0.5d0) * log(y))) + y) - z
end function
public static double code(double x, double y, double z) {
return ((x - ((y + 0.5) * Math.log(y))) + y) - z;
}
def code(x, y, z): return ((x - ((y + 0.5) * math.log(y))) + y) - z
function code(x, y, z) return Float64(Float64(Float64(x - Float64(Float64(y + 0.5) * log(y))) + y) - z) end
function tmp = code(x, y, z) tmp = ((x - ((y + 0.5) * log(y))) + y) - z; end
code[x_, y_, z_] := N[(N[(N[(x - N[(N[(y + 0.5), $MachinePrecision] * N[Log[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + y), $MachinePrecision] - z), $MachinePrecision]
\begin{array}{l}
\\
\left(\left(x - \left(y + 0.5\right) \cdot \log y\right) + y\right) - z
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (- (+ (- x (* (+ y 0.5) (log y))) y) z))
double code(double x, double y, double z) {
return ((x - ((y + 0.5) * log(y))) + y) - z;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = ((x - ((y + 0.5d0) * log(y))) + y) - z
end function
public static double code(double x, double y, double z) {
return ((x - ((y + 0.5) * Math.log(y))) + y) - z;
}
def code(x, y, z): return ((x - ((y + 0.5) * math.log(y))) + y) - z
function code(x, y, z) return Float64(Float64(Float64(x - Float64(Float64(y + 0.5) * log(y))) + y) - z) end
function tmp = code(x, y, z) tmp = ((x - ((y + 0.5) * log(y))) + y) - z; end
code[x_, y_, z_] := N[(N[(N[(x - N[(N[(y + 0.5), $MachinePrecision] * N[Log[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + y), $MachinePrecision] - z), $MachinePrecision]
\begin{array}{l}
\\
\left(\left(x - \left(y + 0.5\right) \cdot \log y\right) + y\right) - z
\end{array}
(FPCore (x y z) :precision binary64 (- (+ x (fma (log y) (- -0.5 y) y)) z))
double code(double x, double y, double z) {
return (x + fma(log(y), (-0.5 - y), y)) - z;
}
function code(x, y, z) return Float64(Float64(x + fma(log(y), Float64(-0.5 - y), y)) - z) end
code[x_, y_, z_] := N[(N[(x + N[(N[Log[y], $MachinePrecision] * N[(-0.5 - y), $MachinePrecision] + y), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]
\begin{array}{l}
\\
\left(x + \mathsf{fma}\left(\log y, -0.5 - y, y\right)\right) - z
\end{array}
Initial program 99.8%
lift-+.f64N/A
lift--.f64N/A
sub-negN/A
associate-+l+N/A
lower-+.f64N/A
lift-*.f64N/A
*-commutativeN/A
distribute-rgt-neg-inN/A
lower-fma.f64N/A
lift-+.f64N/A
+-commutativeN/A
distribute-neg-inN/A
unsub-negN/A
lower--.f64N/A
metadata-eval99.8
Applied rewrites99.8%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (- (+ y (/ 1.0 (/ 1.0 x))) z))
(t_1 (- (+ y (- x (* (log y) (+ y 0.5)))) z)))
(if (<= t_1 -1e+30) t_0 (if (<= t_1 500.0) (* (log y) -0.5) t_0))))
double code(double x, double y, double z) {
double t_0 = (y + (1.0 / (1.0 / x))) - z;
double t_1 = (y + (x - (log(y) * (y + 0.5)))) - z;
double tmp;
if (t_1 <= -1e+30) {
tmp = t_0;
} else if (t_1 <= 500.0) {
tmp = log(y) * -0.5;
} else {
tmp = t_0;
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = (y + (1.0d0 / (1.0d0 / x))) - z
t_1 = (y + (x - (log(y) * (y + 0.5d0)))) - z
if (t_1 <= (-1d+30)) then
tmp = t_0
else if (t_1 <= 500.0d0) then
tmp = log(y) * (-0.5d0)
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = (y + (1.0 / (1.0 / x))) - z;
double t_1 = (y + (x - (Math.log(y) * (y + 0.5)))) - z;
double tmp;
if (t_1 <= -1e+30) {
tmp = t_0;
} else if (t_1 <= 500.0) {
tmp = Math.log(y) * -0.5;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = (y + (1.0 / (1.0 / x))) - z t_1 = (y + (x - (math.log(y) * (y + 0.5)))) - z tmp = 0 if t_1 <= -1e+30: tmp = t_0 elif t_1 <= 500.0: tmp = math.log(y) * -0.5 else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(Float64(y + Float64(1.0 / Float64(1.0 / x))) - z) t_1 = Float64(Float64(y + Float64(x - Float64(log(y) * Float64(y + 0.5)))) - z) tmp = 0.0 if (t_1 <= -1e+30) tmp = t_0; elseif (t_1 <= 500.0) tmp = Float64(log(y) * -0.5); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = (y + (1.0 / (1.0 / x))) - z; t_1 = (y + (x - (log(y) * (y + 0.5)))) - z; tmp = 0.0; if (t_1 <= -1e+30) tmp = t_0; elseif (t_1 <= 500.0) tmp = log(y) * -0.5; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(y + N[(1.0 / N[(1.0 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]}, Block[{t$95$1 = N[(N[(y + N[(x - N[(N[Log[y], $MachinePrecision] * N[(y + 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]}, If[LessEqual[t$95$1, -1e+30], t$95$0, If[LessEqual[t$95$1, 500.0], N[(N[Log[y], $MachinePrecision] * -0.5), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(y + \frac{1}{\frac{1}{x}}\right) - z\\
t_1 := \left(y + \left(x - \log y \cdot \left(y + 0.5\right)\right)\right) - z\\
\mathbf{if}\;t\_1 \leq -1 \cdot 10^{+30}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;t\_1 \leq 500:\\
\;\;\;\;\log y \cdot -0.5\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if (-.f64 (+.f64 (-.f64 x (*.f64 (+.f64 y #s(literal 1/2 binary64)) (log.f64 y))) y) z) < -1e30 or 500 < (-.f64 (+.f64 (-.f64 x (*.f64 (+.f64 y #s(literal 1/2 binary64)) (log.f64 y))) y) z) Initial program 99.8%
lift--.f64N/A
flip--N/A
clear-numN/A
lower-/.f64N/A
clear-numN/A
flip--N/A
lift--.f64N/A
lower-/.f6499.6
lift--.f64N/A
sub-negN/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
distribute-rgt-neg-inN/A
lower-fma.f64N/A
Applied rewrites99.6%
Taylor expanded in x around inf
lower-/.f6468.2
Applied rewrites68.2%
if -1e30 < (-.f64 (+.f64 (-.f64 x (*.f64 (+.f64 y #s(literal 1/2 binary64)) (log.f64 y))) y) z) < 500Initial program 100.0%
Taylor expanded in z around 0
+-commutativeN/A
associate--l+N/A
lower-+.f64N/A
sub-negN/A
+-commutativeN/A
distribute-rgt-neg-inN/A
lower-fma.f64N/A
lower-log.f64N/A
distribute-neg-inN/A
metadata-evalN/A
unsub-negN/A
lower--.f6497.3
Applied rewrites97.3%
Applied rewrites97.3%
Taylor expanded in y around 0
Applied rewrites88.9%
Taylor expanded in x around 0
Applied rewrites86.3%
Final simplification70.8%
(FPCore (x y z) :precision binary64 (let* ((t_0 (- (+ y (/ 1.0 (/ 1.0 x))) z))) (if (<= z -9e+48) t_0 (if (<= z 9.8e+20) (fma (log y) -0.5 x) t_0))))
double code(double x, double y, double z) {
double t_0 = (y + (1.0 / (1.0 / x))) - z;
double tmp;
if (z <= -9e+48) {
tmp = t_0;
} else if (z <= 9.8e+20) {
tmp = fma(log(y), -0.5, x);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(Float64(y + Float64(1.0 / Float64(1.0 / x))) - z) tmp = 0.0 if (z <= -9e+48) tmp = t_0; elseif (z <= 9.8e+20) tmp = fma(log(y), -0.5, x); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(y + N[(1.0 / N[(1.0 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]}, If[LessEqual[z, -9e+48], t$95$0, If[LessEqual[z, 9.8e+20], N[(N[Log[y], $MachinePrecision] * -0.5 + x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(y + \frac{1}{\frac{1}{x}}\right) - z\\
\mathbf{if}\;z \leq -9 \cdot 10^{+48}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 9.8 \cdot 10^{+20}:\\
\;\;\;\;\mathsf{fma}\left(\log y, -0.5, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -8.99999999999999991e48 or 9.8e20 < z Initial program 99.8%
lift--.f64N/A
flip--N/A
clear-numN/A
lower-/.f64N/A
clear-numN/A
flip--N/A
lift--.f64N/A
lower-/.f6499.7
lift--.f64N/A
sub-negN/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
distribute-rgt-neg-inN/A
lower-fma.f64N/A
Applied rewrites99.7%
Taylor expanded in x around inf
lower-/.f6481.4
Applied rewrites81.4%
if -8.99999999999999991e48 < z < 9.8e20Initial program 99.8%
Taylor expanded in z around 0
+-commutativeN/A
associate--l+N/A
lower-+.f64N/A
sub-negN/A
+-commutativeN/A
distribute-rgt-neg-inN/A
lower-fma.f64N/A
lower-log.f64N/A
distribute-neg-inN/A
metadata-evalN/A
unsub-negN/A
lower--.f6499.0
Applied rewrites99.0%
Taylor expanded in y around 0
Applied rewrites63.2%
Final simplification71.9%
(FPCore (x y z) :precision binary64 (if (<= y 1.15e+81) (- (fma (log y) -0.5 x) z) (+ x (fma (log y) (- y) y))))
double code(double x, double y, double z) {
double tmp;
if (y <= 1.15e+81) {
tmp = fma(log(y), -0.5, x) - z;
} else {
tmp = x + fma(log(y), -y, y);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (y <= 1.15e+81) tmp = Float64(fma(log(y), -0.5, x) - z); else tmp = Float64(x + fma(log(y), Float64(-y), y)); end return tmp end
code[x_, y_, z_] := If[LessEqual[y, 1.15e+81], N[(N[(N[Log[y], $MachinePrecision] * -0.5 + x), $MachinePrecision] - z), $MachinePrecision], N[(x + N[(N[Log[y], $MachinePrecision] * (-y) + y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.15 \cdot 10^{+81}:\\
\;\;\;\;\mathsf{fma}\left(\log y, -0.5, x\right) - z\\
\mathbf{else}:\\
\;\;\;\;x + \mathsf{fma}\left(\log y, -y, y\right)\\
\end{array}
\end{array}
if y < 1.1499999999999999e81Initial program 99.9%
Taylor expanded in y around 0
sub-negN/A
+-commutativeN/A
*-commutativeN/A
distribute-rgt-neg-inN/A
metadata-evalN/A
lower-fma.f64N/A
lower-log.f6494.3
Applied rewrites94.3%
if 1.1499999999999999e81 < y Initial program 99.5%
Taylor expanded in z around 0
+-commutativeN/A
associate--l+N/A
lower-+.f64N/A
sub-negN/A
+-commutativeN/A
distribute-rgt-neg-inN/A
lower-fma.f64N/A
lower-log.f64N/A
distribute-neg-inN/A
metadata-evalN/A
unsub-negN/A
lower--.f6486.2
Applied rewrites86.2%
Applied rewrites86.3%
Taylor expanded in y around inf
Applied rewrites86.3%
Final simplification91.6%
(FPCore (x y z) :precision binary64 (if (<= y 1.55e+152) (- (fma (log y) -0.5 x) z) (fma (log y) (- y) y)))
double code(double x, double y, double z) {
double tmp;
if (y <= 1.55e+152) {
tmp = fma(log(y), -0.5, x) - z;
} else {
tmp = fma(log(y), -y, y);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (y <= 1.55e+152) tmp = Float64(fma(log(y), -0.5, x) - z); else tmp = fma(log(y), Float64(-y), y); end return tmp end
code[x_, y_, z_] := If[LessEqual[y, 1.55e+152], N[(N[(N[Log[y], $MachinePrecision] * -0.5 + x), $MachinePrecision] - z), $MachinePrecision], N[(N[Log[y], $MachinePrecision] * (-y) + y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.55 \cdot 10^{+152}:\\
\;\;\;\;\mathsf{fma}\left(\log y, -0.5, x\right) - z\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\log y, -y, y\right)\\
\end{array}
\end{array}
if y < 1.55e152Initial program 99.9%
Taylor expanded in y around 0
sub-negN/A
+-commutativeN/A
*-commutativeN/A
distribute-rgt-neg-inN/A
metadata-evalN/A
lower-fma.f64N/A
lower-log.f6488.7
Applied rewrites88.7%
if 1.55e152 < y Initial program 99.4%
Taylor expanded in y around inf
sub-negN/A
mul-1-negN/A
remove-double-negN/A
+-commutativeN/A
distribute-rgt-inN/A
log-recN/A
distribute-lft-neg-inN/A
distribute-rgt-neg-inN/A
mul-1-negN/A
*-lft-identityN/A
lower-fma.f64N/A
lower-log.f64N/A
mul-1-negN/A
lower-neg.f6486.6
Applied rewrites86.6%
(FPCore (x y z) :precision binary64 (if (<= y 1.35e+152) (- (+ y (/ 1.0 (/ 1.0 x))) z) (fma (log y) (- y) y)))
double code(double x, double y, double z) {
double tmp;
if (y <= 1.35e+152) {
tmp = (y + (1.0 / (1.0 / x))) - z;
} else {
tmp = fma(log(y), -y, y);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (y <= 1.35e+152) tmp = Float64(Float64(y + Float64(1.0 / Float64(1.0 / x))) - z); else tmp = fma(log(y), Float64(-y), y); end return tmp end
code[x_, y_, z_] := If[LessEqual[y, 1.35e+152], N[(N[(y + N[(1.0 / N[(1.0 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision], N[(N[Log[y], $MachinePrecision] * (-y) + y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.35 \cdot 10^{+152}:\\
\;\;\;\;\left(y + \frac{1}{\frac{1}{x}}\right) - z\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\log y, -y, y\right)\\
\end{array}
\end{array}
if y < 1.35000000000000007e152Initial program 99.9%
lift--.f64N/A
flip--N/A
clear-numN/A
lower-/.f64N/A
clear-numN/A
flip--N/A
lift--.f64N/A
lower-/.f6499.7
lift--.f64N/A
sub-negN/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
distribute-rgt-neg-inN/A
lower-fma.f64N/A
Applied rewrites99.7%
Taylor expanded in x around inf
lower-/.f6472.2
Applied rewrites72.2%
if 1.35000000000000007e152 < y Initial program 99.4%
Taylor expanded in y around inf
sub-negN/A
mul-1-negN/A
remove-double-negN/A
+-commutativeN/A
distribute-rgt-inN/A
log-recN/A
distribute-lft-neg-inN/A
distribute-rgt-neg-inN/A
mul-1-negN/A
*-lft-identityN/A
lower-fma.f64N/A
lower-log.f64N/A
mul-1-negN/A
lower-neg.f6486.6
Applied rewrites86.6%
Final simplification75.2%
(FPCore (x y z) :precision binary64 (- (+ y (/ 1.0 (/ 1.0 x))) z))
double code(double x, double y, double z) {
return (y + (1.0 / (1.0 / x))) - z;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (y + (1.0d0 / (1.0d0 / x))) - z
end function
public static double code(double x, double y, double z) {
return (y + (1.0 / (1.0 / x))) - z;
}
def code(x, y, z): return (y + (1.0 / (1.0 / x))) - z
function code(x, y, z) return Float64(Float64(y + Float64(1.0 / Float64(1.0 / x))) - z) end
function tmp = code(x, y, z) tmp = (y + (1.0 / (1.0 / x))) - z; end
code[x_, y_, z_] := N[(N[(y + N[(1.0 / N[(1.0 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]
\begin{array}{l}
\\
\left(y + \frac{1}{\frac{1}{x}}\right) - z
\end{array}
Initial program 99.8%
lift--.f64N/A
flip--N/A
clear-numN/A
lower-/.f64N/A
clear-numN/A
flip--N/A
lift--.f64N/A
lower-/.f6499.7
lift--.f64N/A
sub-negN/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
distribute-rgt-neg-inN/A
lower-fma.f64N/A
Applied rewrites99.7%
Taylor expanded in x around inf
lower-/.f6459.1
Applied rewrites59.1%
Final simplification59.1%
(FPCore (x y z) :precision binary64 (- z))
double code(double x, double y, double z) {
return -z;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = -z
end function
public static double code(double x, double y, double z) {
return -z;
}
def code(x, y, z): return -z
function code(x, y, z) return Float64(-z) end
function tmp = code(x, y, z) tmp = -z; end
code[x_, y_, z_] := (-z)
\begin{array}{l}
\\
-z
\end{array}
Initial program 99.8%
Taylor expanded in z around inf
mul-1-negN/A
lower-neg.f6432.0
Applied rewrites32.0%
(FPCore (x y z) :precision binary64 (- (- (+ y x) z) (* (+ y 0.5) (log y))))
double code(double x, double y, double z) {
return ((y + x) - z) - ((y + 0.5) * log(y));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = ((y + x) - z) - ((y + 0.5d0) * log(y))
end function
public static double code(double x, double y, double z) {
return ((y + x) - z) - ((y + 0.5) * Math.log(y));
}
def code(x, y, z): return ((y + x) - z) - ((y + 0.5) * math.log(y))
function code(x, y, z) return Float64(Float64(Float64(y + x) - z) - Float64(Float64(y + 0.5) * log(y))) end
function tmp = code(x, y, z) tmp = ((y + x) - z) - ((y + 0.5) * log(y)); end
code[x_, y_, z_] := N[(N[(N[(y + x), $MachinePrecision] - z), $MachinePrecision] - N[(N[(y + 0.5), $MachinePrecision] * N[Log[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(\left(y + x\right) - z\right) - \left(y + 0.5\right) \cdot \log y
\end{array}
herbie shell --seed 2024221
(FPCore (x y z)
:name "Numeric.SpecFunctions:stirlingError from math-functions-0.1.5.2"
:precision binary64
:alt
(! :herbie-platform default (- (- (+ y x) z) (* (+ y 1/2) (log y))))
(- (+ (- x (* (+ y 0.5) (log y))) y) z))