
(FPCore (x y z) :precision binary64 (- (- (* x (log y)) z) y))
double code(double x, double y, double z) {
return ((x * log(y)) - z) - y;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = ((x * log(y)) - z) - y
end function
public static double code(double x, double y, double z) {
return ((x * Math.log(y)) - z) - y;
}
def code(x, y, z): return ((x * math.log(y)) - z) - y
function code(x, y, z) return Float64(Float64(Float64(x * log(y)) - z) - y) end
function tmp = code(x, y, z) tmp = ((x * log(y)) - z) - y; end
code[x_, y_, z_] := N[(N[(N[(x * N[Log[y], $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision] - y), $MachinePrecision]
\begin{array}{l}
\\
\left(x \cdot \log y - z\right) - y
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (- (- (* x (log y)) z) y))
double code(double x, double y, double z) {
return ((x * log(y)) - z) - y;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = ((x * log(y)) - z) - y
end function
public static double code(double x, double y, double z) {
return ((x * Math.log(y)) - z) - y;
}
def code(x, y, z): return ((x * math.log(y)) - z) - y
function code(x, y, z) return Float64(Float64(Float64(x * log(y)) - z) - y) end
function tmp = code(x, y, z) tmp = ((x * log(y)) - z) - y; end
code[x_, y_, z_] := N[(N[(N[(x * N[Log[y], $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision] - y), $MachinePrecision]
\begin{array}{l}
\\
\left(x \cdot \log y - z\right) - y
\end{array}
(FPCore (x y z) :precision binary64 (- (- (* x (log y)) z) y))
double code(double x, double y, double z) {
return ((x * log(y)) - z) - y;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = ((x * log(y)) - z) - y
end function
public static double code(double x, double y, double z) {
return ((x * Math.log(y)) - z) - y;
}
def code(x, y, z): return ((x * math.log(y)) - z) - y
function code(x, y, z) return Float64(Float64(Float64(x * log(y)) - z) - y) end
function tmp = code(x, y, z) tmp = ((x * log(y)) - z) - y; end
code[x_, y_, z_] := N[(N[(N[(x * N[Log[y], $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision] - y), $MachinePrecision]
\begin{array}{l}
\\
\left(x \cdot \log y - z\right) - y
\end{array}
Initial program 99.8%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (- (- (* x (log y)) z) y)))
(if (<= t_0 -1e+168)
(- (- z) y)
(if (<= t_0 -1e-74) (- (* (log y) x) y) (fma (log y) x (- z))))))
double code(double x, double y, double z) {
double t_0 = ((x * log(y)) - z) - y;
double tmp;
if (t_0 <= -1e+168) {
tmp = -z - y;
} else if (t_0 <= -1e-74) {
tmp = (log(y) * x) - y;
} else {
tmp = fma(log(y), x, -z);
}
return tmp;
}
function code(x, y, z) t_0 = Float64(Float64(Float64(x * log(y)) - z) - y) tmp = 0.0 if (t_0 <= -1e+168) tmp = Float64(Float64(-z) - y); elseif (t_0 <= -1e-74) tmp = Float64(Float64(log(y) * x) - y); else tmp = fma(log(y), x, Float64(-z)); end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(N[(x * N[Log[y], $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision] - y), $MachinePrecision]}, If[LessEqual[t$95$0, -1e+168], N[((-z) - y), $MachinePrecision], If[LessEqual[t$95$0, -1e-74], N[(N[(N[Log[y], $MachinePrecision] * x), $MachinePrecision] - y), $MachinePrecision], N[(N[Log[y], $MachinePrecision] * x + (-z)), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(x \cdot \log y - z\right) - y\\
\mathbf{if}\;t\_0 \leq -1 \cdot 10^{+168}:\\
\;\;\;\;\left(-z\right) - y\\
\mathbf{elif}\;t\_0 \leq -1 \cdot 10^{-74}:\\
\;\;\;\;\log y \cdot x - y\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\log y, x, -z\right)\\
\end{array}
\end{array}
if (-.f64 (-.f64 (*.f64 x (log.f64 y)) z) y) < -9.9999999999999993e167Initial program 99.9%
Taylor expanded in x around 0
mul-1-negN/A
lower-neg.f6485.2
Applied rewrites85.2%
if -9.9999999999999993e167 < (-.f64 (-.f64 (*.f64 x (log.f64 y)) z) y) < -9.99999999999999958e-75Initial program 99.9%
Taylor expanded in z around 0
*-lft-identityN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
*-commutativeN/A
lower-fma.f64N/A
lower-log.f64N/A
mul-1-negN/A
lower-neg.f6482.9
Applied rewrites82.9%
Applied rewrites82.9%
if -9.99999999999999958e-75 < (-.f64 (-.f64 (*.f64 x (log.f64 y)) z) y) Initial program 99.7%
Taylor expanded in y around inf
Applied rewrites73.5%
Taylor expanded in z around -inf
Applied rewrites62.5%
Taylor expanded in y around inf
Applied rewrites2.6%
Taylor expanded in y around 0
*-lft-identityN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
*-commutativeN/A
lower-fma.f64N/A
lower-log.f64N/A
mul-1-negN/A
lower-neg.f6497.8
Applied rewrites97.8%
Final simplification89.8%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (- (- (* x (log y)) z) y)))
(if (<= t_0 -1e+168)
(- (- z) y)
(if (<= t_0 -1e-74) (fma (log y) x (- y)) (fma (log y) x (- z))))))
double code(double x, double y, double z) {
double t_0 = ((x * log(y)) - z) - y;
double tmp;
if (t_0 <= -1e+168) {
tmp = -z - y;
} else if (t_0 <= -1e-74) {
tmp = fma(log(y), x, -y);
} else {
tmp = fma(log(y), x, -z);
}
return tmp;
}
function code(x, y, z) t_0 = Float64(Float64(Float64(x * log(y)) - z) - y) tmp = 0.0 if (t_0 <= -1e+168) tmp = Float64(Float64(-z) - y); elseif (t_0 <= -1e-74) tmp = fma(log(y), x, Float64(-y)); else tmp = fma(log(y), x, Float64(-z)); end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(N[(x * N[Log[y], $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision] - y), $MachinePrecision]}, If[LessEqual[t$95$0, -1e+168], N[((-z) - y), $MachinePrecision], If[LessEqual[t$95$0, -1e-74], N[(N[Log[y], $MachinePrecision] * x + (-y)), $MachinePrecision], N[(N[Log[y], $MachinePrecision] * x + (-z)), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(x \cdot \log y - z\right) - y\\
\mathbf{if}\;t\_0 \leq -1 \cdot 10^{+168}:\\
\;\;\;\;\left(-z\right) - y\\
\mathbf{elif}\;t\_0 \leq -1 \cdot 10^{-74}:\\
\;\;\;\;\mathsf{fma}\left(\log y, x, -y\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\log y, x, -z\right)\\
\end{array}
\end{array}
if (-.f64 (-.f64 (*.f64 x (log.f64 y)) z) y) < -9.9999999999999993e167Initial program 99.9%
Taylor expanded in x around 0
mul-1-negN/A
lower-neg.f6485.2
Applied rewrites85.2%
if -9.9999999999999993e167 < (-.f64 (-.f64 (*.f64 x (log.f64 y)) z) y) < -9.99999999999999958e-75Initial program 99.9%
Taylor expanded in z around 0
*-lft-identityN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
*-commutativeN/A
lower-fma.f64N/A
lower-log.f64N/A
mul-1-negN/A
lower-neg.f6482.9
Applied rewrites82.9%
if -9.99999999999999958e-75 < (-.f64 (-.f64 (*.f64 x (log.f64 y)) z) y) Initial program 99.7%
Taylor expanded in y around inf
Applied rewrites73.5%
Taylor expanded in z around -inf
Applied rewrites62.5%
Taylor expanded in y around inf
Applied rewrites2.6%
Taylor expanded in y around 0
*-lft-identityN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
*-commutativeN/A
lower-fma.f64N/A
lower-log.f64N/A
mul-1-negN/A
lower-neg.f6497.8
Applied rewrites97.8%
(FPCore (x y z) :precision binary64 (if (or (<= z -4600000.0) (not (<= z 1.8e+121))) (- (- z) y) (fma (log y) x (- y))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -4600000.0) || !(z <= 1.8e+121)) {
tmp = -z - y;
} else {
tmp = fma(log(y), x, -y);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((z <= -4600000.0) || !(z <= 1.8e+121)) tmp = Float64(Float64(-z) - y); else tmp = fma(log(y), x, Float64(-y)); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[z, -4600000.0], N[Not[LessEqual[z, 1.8e+121]], $MachinePrecision]], N[((-z) - y), $MachinePrecision], N[(N[Log[y], $MachinePrecision] * x + (-y)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -4600000 \lor \neg \left(z \leq 1.8 \cdot 10^{+121}\right):\\
\;\;\;\;\left(-z\right) - y\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\log y, x, -y\right)\\
\end{array}
\end{array}
if z < -4.6e6 or 1.79999999999999991e121 < z Initial program 99.9%
Taylor expanded in x around 0
mul-1-negN/A
lower-neg.f6479.8
Applied rewrites79.8%
if -4.6e6 < z < 1.79999999999999991e121Initial program 99.8%
Taylor expanded in z around 0
*-lft-identityN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
*-commutativeN/A
lower-fma.f64N/A
lower-log.f64N/A
mul-1-negN/A
lower-neg.f6489.6
Applied rewrites89.6%
Final simplification85.8%
(FPCore (x y z) :precision binary64 (if (or (<= x -2.8e+79) (not (<= x 2.9e+105))) (* (log y) x) (- (- z) y)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -2.8e+79) || !(x <= 2.9e+105)) {
tmp = log(y) * x;
} else {
tmp = -z - 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 ((x <= (-2.8d+79)) .or. (.not. (x <= 2.9d+105))) then
tmp = log(y) * x
else
tmp = -z - y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -2.8e+79) || !(x <= 2.9e+105)) {
tmp = Math.log(y) * x;
} else {
tmp = -z - y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -2.8e+79) or not (x <= 2.9e+105): tmp = math.log(y) * x else: tmp = -z - y return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -2.8e+79) || !(x <= 2.9e+105)) tmp = Float64(log(y) * x); else tmp = Float64(Float64(-z) - y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -2.8e+79) || ~((x <= 2.9e+105))) tmp = log(y) * x; else tmp = -z - y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -2.8e+79], N[Not[LessEqual[x, 2.9e+105]], $MachinePrecision]], N[(N[Log[y], $MachinePrecision] * x), $MachinePrecision], N[((-z) - y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.8 \cdot 10^{+79} \lor \neg \left(x \leq 2.9 \cdot 10^{+105}\right):\\
\;\;\;\;\log y \cdot x\\
\mathbf{else}:\\
\;\;\;\;\left(-z\right) - y\\
\end{array}
\end{array}
if x < -2.8000000000000001e79 or 2.9000000000000001e105 < x Initial program 99.7%
Taylor expanded in z around 0
*-lft-identityN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
*-commutativeN/A
lower-fma.f64N/A
lower-log.f64N/A
mul-1-negN/A
lower-neg.f6482.5
Applied rewrites82.5%
Applied rewrites53.1%
Taylor expanded in x around -inf
Applied rewrites70.4%
if -2.8000000000000001e79 < x < 2.9000000000000001e105Initial program 99.9%
Taylor expanded in x around 0
mul-1-negN/A
lower-neg.f6485.9
Applied rewrites85.9%
Final simplification80.4%
(FPCore (x y z) :precision binary64 (if (or (<= z -8000000.0) (not (<= z 2.3e+77))) (* -1.0 z) (- y)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -8000000.0) || !(z <= 2.3e+77)) {
tmp = -1.0 * z;
} else {
tmp = -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 ((z <= (-8000000.0d0)) .or. (.not. (z <= 2.3d+77))) then
tmp = (-1.0d0) * z
else
tmp = -y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -8000000.0) || !(z <= 2.3e+77)) {
tmp = -1.0 * z;
} else {
tmp = -y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -8000000.0) or not (z <= 2.3e+77): tmp = -1.0 * z else: tmp = -y return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -8000000.0) || !(z <= 2.3e+77)) tmp = Float64(-1.0 * z); else tmp = Float64(-y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -8000000.0) || ~((z <= 2.3e+77))) tmp = -1.0 * z; else tmp = -y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -8000000.0], N[Not[LessEqual[z, 2.3e+77]], $MachinePrecision]], N[(-1.0 * z), $MachinePrecision], (-y)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -8000000 \lor \neg \left(z \leq 2.3 \cdot 10^{+77}\right):\\
\;\;\;\;-1 \cdot z\\
\mathbf{else}:\\
\;\;\;\;-y\\
\end{array}
\end{array}
if z < -8e6 or 2.29999999999999995e77 < z Initial program 99.9%
Taylor expanded in y around inf
Applied rewrites74.5%
Taylor expanded in z around -inf
Applied rewrites89.1%
Taylor expanded in y around inf
Applied rewrites15.9%
Taylor expanded in z around inf
Applied rewrites62.9%
if -8e6 < z < 2.29999999999999995e77Initial program 99.8%
Taylor expanded in y around inf
mul-1-negN/A
lower-neg.f6449.7
Applied rewrites49.7%
Final simplification55.5%
(FPCore (x y z) :precision binary64 (- (- z) y))
double code(double x, double y, double z) {
return -z - y;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = -z - y
end function
public static double code(double x, double y, double z) {
return -z - y;
}
def code(x, y, z): return -z - y
function code(x, y, z) return Float64(Float64(-z) - y) end
function tmp = code(x, y, z) tmp = -z - y; end
code[x_, y_, z_] := N[((-z) - y), $MachinePrecision]
\begin{array}{l}
\\
\left(-z\right) - y
\end{array}
Initial program 99.8%
Taylor expanded in x around 0
mul-1-negN/A
lower-neg.f6465.5
Applied rewrites65.5%
(FPCore (x y z) :precision binary64 (- y))
double code(double x, double y, double z) {
return -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
end function
public static double code(double x, double y, double z) {
return -y;
}
def code(x, y, z): return -y
function code(x, y, z) return Float64(-y) end
function tmp = code(x, y, z) tmp = -y; end
code[x_, y_, z_] := (-y)
\begin{array}{l}
\\
-y
\end{array}
Initial program 99.8%
Taylor expanded in y around inf
mul-1-negN/A
lower-neg.f6434.6
Applied rewrites34.6%
herbie shell --seed 2024326
(FPCore (x y z)
:name "Statistics.Distribution.Poisson:$clogProbability from math-functions-0.1.5.2"
:precision binary64
(- (- (* x (log y)) z) y))