
(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 (fma (- -0.5 y) (log y) (+ (- y z) x)))
double code(double x, double y, double z) {
return fma((-0.5 - y), log(y), ((y - z) + x));
}
function code(x, y, z) return fma(Float64(-0.5 - y), log(y), Float64(Float64(y - z) + x)) end
code[x_, y_, z_] := N[(N[(-0.5 - y), $MachinePrecision] * N[Log[y], $MachinePrecision] + N[(N[(y - z), $MachinePrecision] + x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(-0.5 - y, \log y, \left(y - z\right) + x\right)
\end{array}
Initial program 99.8%
lift--.f64N/A
lift-+.f64N/A
associate--l+N/A
lift--.f64N/A
sub-negN/A
+-commutativeN/A
associate-+l+N/A
lift-*.f64N/A
distribute-lft-neg-inN/A
lower-fma.f64N/A
lift-+.f64N/A
+-commutativeN/A
distribute-neg-inN/A
unsub-negN/A
lower--.f64N/A
metadata-evalN/A
lower-+.f64N/A
lower--.f6499.9
Applied rewrites99.9%
Final simplification99.9%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (- (+ (* 1.0 x) y) z)) (t_1 (+ (- x (* (+ 0.5 y) (log y))) y)))
(if (<= t_1 -1e+168)
(* (- 1.0 (log y)) y)
(if (<= t_1 -2e+34) t_0 (if (<= t_1 349.0) (- (* (log y) -0.5) z) t_0)))))
double code(double x, double y, double z) {
double t_0 = ((1.0 * x) + y) - z;
double t_1 = (x - ((0.5 + y) * log(y))) + y;
double tmp;
if (t_1 <= -1e+168) {
tmp = (1.0 - log(y)) * y;
} else if (t_1 <= -2e+34) {
tmp = t_0;
} else if (t_1 <= 349.0) {
tmp = (log(y) * -0.5) - z;
} 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 = ((1.0d0 * x) + y) - z
t_1 = (x - ((0.5d0 + y) * log(y))) + y
if (t_1 <= (-1d+168)) then
tmp = (1.0d0 - log(y)) * y
else if (t_1 <= (-2d+34)) then
tmp = t_0
else if (t_1 <= 349.0d0) then
tmp = (log(y) * (-0.5d0)) - z
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = ((1.0 * x) + y) - z;
double t_1 = (x - ((0.5 + y) * Math.log(y))) + y;
double tmp;
if (t_1 <= -1e+168) {
tmp = (1.0 - Math.log(y)) * y;
} else if (t_1 <= -2e+34) {
tmp = t_0;
} else if (t_1 <= 349.0) {
tmp = (Math.log(y) * -0.5) - z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = ((1.0 * x) + y) - z t_1 = (x - ((0.5 + y) * math.log(y))) + y tmp = 0 if t_1 <= -1e+168: tmp = (1.0 - math.log(y)) * y elif t_1 <= -2e+34: tmp = t_0 elif t_1 <= 349.0: tmp = (math.log(y) * -0.5) - z else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(Float64(Float64(1.0 * x) + y) - z) t_1 = Float64(Float64(x - Float64(Float64(0.5 + y) * log(y))) + y) tmp = 0.0 if (t_1 <= -1e+168) tmp = Float64(Float64(1.0 - log(y)) * y); elseif (t_1 <= -2e+34) tmp = t_0; elseif (t_1 <= 349.0) tmp = Float64(Float64(log(y) * -0.5) - z); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = ((1.0 * x) + y) - z; t_1 = (x - ((0.5 + y) * log(y))) + y; tmp = 0.0; if (t_1 <= -1e+168) tmp = (1.0 - log(y)) * y; elseif (t_1 <= -2e+34) tmp = t_0; elseif (t_1 <= 349.0) tmp = (log(y) * -0.5) - z; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(N[(1.0 * x), $MachinePrecision] + y), $MachinePrecision] - z), $MachinePrecision]}, Block[{t$95$1 = N[(N[(x - N[(N[(0.5 + y), $MachinePrecision] * N[Log[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + y), $MachinePrecision]}, If[LessEqual[t$95$1, -1e+168], N[(N[(1.0 - N[Log[y], $MachinePrecision]), $MachinePrecision] * y), $MachinePrecision], If[LessEqual[t$95$1, -2e+34], t$95$0, If[LessEqual[t$95$1, 349.0], N[(N[(N[Log[y], $MachinePrecision] * -0.5), $MachinePrecision] - z), $MachinePrecision], t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(1 \cdot x + y\right) - z\\
t_1 := \left(x - \left(0.5 + y\right) \cdot \log y\right) + y\\
\mathbf{if}\;t\_1 \leq -1 \cdot 10^{+168}:\\
\;\;\;\;\left(1 - \log y\right) \cdot y\\
\mathbf{elif}\;t\_1 \leq -2 \cdot 10^{+34}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;t\_1 \leq 349:\\
\;\;\;\;\log y \cdot -0.5 - z\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if (+.f64 (-.f64 x (*.f64 (+.f64 y #s(literal 1/2 binary64)) (log.f64 y))) y) < -9.9999999999999993e167Initial program 99.7%
Taylor expanded in y around inf
*-commutativeN/A
mul-1-negN/A
log-recN/A
remove-double-negN/A
lower-*.f64N/A
lower--.f64N/A
lower-log.f6467.7
Applied rewrites67.7%
if -9.9999999999999993e167 < (+.f64 (-.f64 x (*.f64 (+.f64 y #s(literal 1/2 binary64)) (log.f64 y))) y) < -1.99999999999999989e34 or 349 < (+.f64 (-.f64 x (*.f64 (+.f64 y #s(literal 1/2 binary64)) (log.f64 y))) y) Initial 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
distribute-lft-neg-inN/A
lower-fma.f64N/A
Applied rewrites99.7%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
mul-1-negN/A
associate-/l*N/A
*-commutativeN/A
distribute-lft-neg-inN/A
lower-fma.f64N/A
distribute-neg-fracN/A
lower-/.f64N/A
distribute-neg-inN/A
metadata-evalN/A
unsub-negN/A
lower--.f64N/A
lower-log.f6494.5
Applied rewrites94.5%
Taylor expanded in x around inf
Applied rewrites81.7%
if -1.99999999999999989e34 < (+.f64 (-.f64 x (*.f64 (+.f64 y #s(literal 1/2 binary64)) (log.f64 y))) y) < 349Initial program 100.0%
Taylor expanded in y around 0
sub-negN/A
+-commutativeN/A
distribute-lft-neg-inN/A
metadata-evalN/A
lower-fma.f64N/A
lower-log.f6498.1
Applied rewrites98.1%
Taylor expanded in x around 0
Applied rewrites97.6%
Final simplification81.3%
(FPCore (x y z) :precision binary64 (if (<= y 2.25e+42) (- (fma -0.5 (log y) x) z) (fma (- y) (log y) (- y z))))
double code(double x, double y, double z) {
double tmp;
if (y <= 2.25e+42) {
tmp = fma(-0.5, log(y), x) - z;
} else {
tmp = fma(-y, log(y), (y - z));
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (y <= 2.25e+42) tmp = Float64(fma(-0.5, log(y), x) - z); else tmp = fma(Float64(-y), log(y), Float64(y - z)); end return tmp end
code[x_, y_, z_] := If[LessEqual[y, 2.25e+42], N[(N[(-0.5 * N[Log[y], $MachinePrecision] + x), $MachinePrecision] - z), $MachinePrecision], N[((-y) * N[Log[y], $MachinePrecision] + N[(y - z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 2.25 \cdot 10^{+42}:\\
\;\;\;\;\mathsf{fma}\left(-0.5, \log y, x\right) - z\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(-y, \log y, y - z\right)\\
\end{array}
\end{array}
if y < 2.25000000000000006e42Initial program 100.0%
Taylor expanded in y around 0
sub-negN/A
+-commutativeN/A
distribute-lft-neg-inN/A
metadata-evalN/A
lower-fma.f64N/A
lower-log.f6497.8
Applied rewrites97.8%
if 2.25000000000000006e42 < y Initial program 99.7%
lift--.f64N/A
lift-+.f64N/A
associate--l+N/A
lift--.f64N/A
sub-negN/A
+-commutativeN/A
associate-+l+N/A
lift-*.f64N/A
distribute-lft-neg-inN/A
lower-fma.f64N/A
lift-+.f64N/A
+-commutativeN/A
distribute-neg-inN/A
unsub-negN/A
lower--.f64N/A
metadata-evalN/A
lower-+.f64N/A
lower--.f6499.7
Applied rewrites99.7%
Taylor expanded in x around 0
lower--.f6485.4
Applied rewrites85.4%
Taylor expanded in y around inf
mul-1-negN/A
lower-neg.f6485.4
Applied rewrites85.4%
(FPCore (x y z) :precision binary64 (if (<= y 2.25e+42) (- (fma -0.5 (log y) x) z) (- (* (- 1.0 (log y)) y) z)))
double code(double x, double y, double z) {
double tmp;
if (y <= 2.25e+42) {
tmp = fma(-0.5, log(y), x) - z;
} else {
tmp = ((1.0 - log(y)) * y) - z;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (y <= 2.25e+42) tmp = Float64(fma(-0.5, log(y), x) - z); else tmp = Float64(Float64(Float64(1.0 - log(y)) * y) - z); end return tmp end
code[x_, y_, z_] := If[LessEqual[y, 2.25e+42], N[(N[(-0.5 * N[Log[y], $MachinePrecision] + x), $MachinePrecision] - z), $MachinePrecision], N[(N[(N[(1.0 - N[Log[y], $MachinePrecision]), $MachinePrecision] * y), $MachinePrecision] - z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 2.25 \cdot 10^{+42}:\\
\;\;\;\;\mathsf{fma}\left(-0.5, \log y, x\right) - z\\
\mathbf{else}:\\
\;\;\;\;\left(1 - \log y\right) \cdot y - z\\
\end{array}
\end{array}
if y < 2.25000000000000006e42Initial program 100.0%
Taylor expanded in y around 0
sub-negN/A
+-commutativeN/A
distribute-lft-neg-inN/A
metadata-evalN/A
lower-fma.f64N/A
lower-log.f6497.8
Applied rewrites97.8%
if 2.25000000000000006e42 < y Initial program 99.7%
Taylor expanded in y around inf
*-commutativeN/A
mul-1-negN/A
log-recN/A
remove-double-negN/A
lower-*.f64N/A
lower--.f64N/A
lower-log.f6485.4
Applied rewrites85.4%
(FPCore (x y z) :precision binary64 (if (<= y 8.2e+160) (- (fma -0.5 (log y) x) z) (fma (- -0.5 y) (log y) y)))
double code(double x, double y, double z) {
double tmp;
if (y <= 8.2e+160) {
tmp = fma(-0.5, log(y), x) - z;
} else {
tmp = fma((-0.5 - y), log(y), y);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (y <= 8.2e+160) tmp = Float64(fma(-0.5, log(y), x) - z); else tmp = fma(Float64(-0.5 - y), log(y), y); end return tmp end
code[x_, y_, z_] := If[LessEqual[y, 8.2e+160], N[(N[(-0.5 * N[Log[y], $MachinePrecision] + x), $MachinePrecision] - z), $MachinePrecision], N[(N[(-0.5 - y), $MachinePrecision] * N[Log[y], $MachinePrecision] + y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 8.2 \cdot 10^{+160}:\\
\;\;\;\;\mathsf{fma}\left(-0.5, \log y, x\right) - z\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(-0.5 - y, \log y, y\right)\\
\end{array}
\end{array}
if y < 8.19999999999999996e160Initial program 99.9%
Taylor expanded in y around 0
sub-negN/A
+-commutativeN/A
distribute-lft-neg-inN/A
metadata-evalN/A
lower-fma.f64N/A
lower-log.f6491.4
Applied rewrites91.4%
if 8.19999999999999996e160 < y Initial program 99.7%
Taylor expanded in x around 0
lower--.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-+.f64N/A
lower-log.f6488.7
Applied rewrites88.7%
Taylor expanded in z around 0
Applied rewrites81.6%
(FPCore (x y z) :precision binary64 (if (<= y 8.2e+158) (- (+ (* 1.0 x) y) z) (* (- 1.0 (log y)) y)))
double code(double x, double y, double z) {
double tmp;
if (y <= 8.2e+158) {
tmp = ((1.0 * x) + y) - z;
} else {
tmp = (1.0 - log(y)) * y;
}
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) :: tmp
if (y <= 8.2d+158) then
tmp = ((1.0d0 * x) + y) - z
else
tmp = (1.0d0 - log(y)) * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= 8.2e+158) {
tmp = ((1.0 * x) + y) - z;
} else {
tmp = (1.0 - Math.log(y)) * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= 8.2e+158: tmp = ((1.0 * x) + y) - z else: tmp = (1.0 - math.log(y)) * y return tmp
function code(x, y, z) tmp = 0.0 if (y <= 8.2e+158) tmp = Float64(Float64(Float64(1.0 * x) + y) - z); else tmp = Float64(Float64(1.0 - log(y)) * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= 8.2e+158) tmp = ((1.0 * x) + y) - z; else tmp = (1.0 - log(y)) * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, 8.2e+158], N[(N[(N[(1.0 * x), $MachinePrecision] + y), $MachinePrecision] - z), $MachinePrecision], N[(N[(1.0 - N[Log[y], $MachinePrecision]), $MachinePrecision] * y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 8.2 \cdot 10^{+158}:\\
\;\;\;\;\left(1 \cdot x + y\right) - z\\
\mathbf{else}:\\
\;\;\;\;\left(1 - \log y\right) \cdot y\\
\end{array}
\end{array}
if y < 8.20000000000000008e158Initial 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
distribute-lft-neg-inN/A
lower-fma.f64N/A
Applied rewrites99.7%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
mul-1-negN/A
associate-/l*N/A
*-commutativeN/A
distribute-lft-neg-inN/A
lower-fma.f64N/A
distribute-neg-fracN/A
lower-/.f64N/A
distribute-neg-inN/A
metadata-evalN/A
unsub-negN/A
lower--.f64N/A
lower-log.f6496.6
Applied rewrites96.6%
Taylor expanded in x around inf
Applied rewrites74.3%
if 8.20000000000000008e158 < y Initial program 99.7%
Taylor expanded in y around inf
*-commutativeN/A
mul-1-negN/A
log-recN/A
remove-double-negN/A
lower-*.f64N/A
lower--.f64N/A
lower-log.f6481.6
Applied rewrites81.6%
(FPCore (x y z) :precision binary64 (- (+ (* 1.0 x) y) z))
double code(double x, double y, double z) {
return ((1.0 * x) + 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 = ((1.0d0 * x) + y) - z
end function
public static double code(double x, double y, double z) {
return ((1.0 * x) + y) - z;
}
def code(x, y, z): return ((1.0 * x) + y) - z
function code(x, y, z) return Float64(Float64(Float64(1.0 * x) + y) - z) end
function tmp = code(x, y, z) tmp = ((1.0 * x) + y) - z; end
code[x_, y_, z_] := N[(N[(N[(1.0 * x), $MachinePrecision] + y), $MachinePrecision] - z), $MachinePrecision]
\begin{array}{l}
\\
\left(1 \cdot x + y\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
distribute-lft-neg-inN/A
lower-fma.f64N/A
Applied rewrites99.7%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
mul-1-negN/A
associate-/l*N/A
*-commutativeN/A
distribute-lft-neg-inN/A
lower-fma.f64N/A
distribute-neg-fracN/A
lower-/.f64N/A
distribute-neg-inN/A
metadata-evalN/A
unsub-negN/A
lower--.f64N/A
lower-log.f6488.9
Applied rewrites88.9%
Taylor expanded in x around inf
Applied rewrites57.3%
(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.f6434.1
Applied rewrites34.1%
(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 2024268
(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))