
(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 9 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 (fma (log y) x (- (- y) z)))
double code(double x, double y, double z) {
return fma(log(y), x, (-y - z));
}
function code(x, y, z) return fma(log(y), x, Float64(Float64(-y) - z)) end
code[x_, y_, z_] := N[(N[Log[y], $MachinePrecision] * x + N[((-y) - z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\log y, x, \left(-y\right) - z\right)
\end{array}
Initial program 99.9%
sub-neg99.9%
associate-+l-99.9%
*-commutative99.9%
add-sqr-sqrt0.0%
sqrt-unprod62.1%
sqr-neg62.1%
sqrt-unprod69.4%
add-sqr-sqrt69.4%
fma-neg69.5%
add-cube-cbrt68.8%
fma-neg68.8%
add-sqr-sqrt0.0%
sqrt-unprod73.7%
sqr-neg73.7%
sqrt-unprod99.0%
add-sqr-sqrt99.2%
fma-define99.2%
add-cube-cbrt99.9%
+-commutative99.9%
Applied egg-rr99.9%
Final simplification99.9%
(FPCore (x y z) :precision binary64 (- (fma x (log y) (- y)) z))
double code(double x, double y, double z) {
return fma(x, log(y), -y) - z;
}
function code(x, y, z) return Float64(fma(x, log(y), Float64(-y)) - z) end
code[x_, y_, z_] := N[(N[(x * N[Log[y], $MachinePrecision] + (-y)), $MachinePrecision] - z), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x, \log y, -y\right) - z
\end{array}
Initial program 99.9%
associate--l-99.9%
+-commutative99.9%
associate--r+99.9%
fma-neg99.9%
Simplified99.9%
Final simplification99.9%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* (log y) x)) (t_1 (- t_0 z)) (t_2 (- (- y) z)))
(if (<= z -1.15e+116)
t_1
(if (<= z -64000000000000.0)
t_2
(if (<= z -1.35e-40) t_1 (if (<= z 1.65e+24) (- t_0 y) t_2))))))
double code(double x, double y, double z) {
double t_0 = log(y) * x;
double t_1 = t_0 - z;
double t_2 = -y - z;
double tmp;
if (z <= -1.15e+116) {
tmp = t_1;
} else if (z <= -64000000000000.0) {
tmp = t_2;
} else if (z <= -1.35e-40) {
tmp = t_1;
} else if (z <= 1.65e+24) {
tmp = t_0 - y;
} else {
tmp = t_2;
}
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) :: t_2
real(8) :: tmp
t_0 = log(y) * x
t_1 = t_0 - z
t_2 = -y - z
if (z <= (-1.15d+116)) then
tmp = t_1
else if (z <= (-64000000000000.0d0)) then
tmp = t_2
else if (z <= (-1.35d-40)) then
tmp = t_1
else if (z <= 1.65d+24) then
tmp = t_0 - y
else
tmp = t_2
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = Math.log(y) * x;
double t_1 = t_0 - z;
double t_2 = -y - z;
double tmp;
if (z <= -1.15e+116) {
tmp = t_1;
} else if (z <= -64000000000000.0) {
tmp = t_2;
} else if (z <= -1.35e-40) {
tmp = t_1;
} else if (z <= 1.65e+24) {
tmp = t_0 - y;
} else {
tmp = t_2;
}
return tmp;
}
def code(x, y, z): t_0 = math.log(y) * x t_1 = t_0 - z t_2 = -y - z tmp = 0 if z <= -1.15e+116: tmp = t_1 elif z <= -64000000000000.0: tmp = t_2 elif z <= -1.35e-40: tmp = t_1 elif z <= 1.65e+24: tmp = t_0 - y else: tmp = t_2 return tmp
function code(x, y, z) t_0 = Float64(log(y) * x) t_1 = Float64(t_0 - z) t_2 = Float64(Float64(-y) - z) tmp = 0.0 if (z <= -1.15e+116) tmp = t_1; elseif (z <= -64000000000000.0) tmp = t_2; elseif (z <= -1.35e-40) tmp = t_1; elseif (z <= 1.65e+24) tmp = Float64(t_0 - y); else tmp = t_2; end return tmp end
function tmp_2 = code(x, y, z) t_0 = log(y) * x; t_1 = t_0 - z; t_2 = -y - z; tmp = 0.0; if (z <= -1.15e+116) tmp = t_1; elseif (z <= -64000000000000.0) tmp = t_2; elseif (z <= -1.35e-40) tmp = t_1; elseif (z <= 1.65e+24) tmp = t_0 - y; else tmp = t_2; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[Log[y], $MachinePrecision] * x), $MachinePrecision]}, Block[{t$95$1 = N[(t$95$0 - z), $MachinePrecision]}, Block[{t$95$2 = N[((-y) - z), $MachinePrecision]}, If[LessEqual[z, -1.15e+116], t$95$1, If[LessEqual[z, -64000000000000.0], t$95$2, If[LessEqual[z, -1.35e-40], t$95$1, If[LessEqual[z, 1.65e+24], N[(t$95$0 - y), $MachinePrecision], t$95$2]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \log y \cdot x\\
t_1 := t\_0 - z\\
t_2 := \left(-y\right) - z\\
\mathbf{if}\;z \leq -1.15 \cdot 10^{+116}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;z \leq -64000000000000:\\
\;\;\;\;t\_2\\
\mathbf{elif}\;z \leq -1.35 \cdot 10^{-40}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;z \leq 1.65 \cdot 10^{+24}:\\
\;\;\;\;t\_0 - y\\
\mathbf{else}:\\
\;\;\;\;t\_2\\
\end{array}
\end{array}
if z < -1.14999999999999997e116 or -6.4e13 < z < -1.35e-40Initial program 100.0%
Taylor expanded in y around 0 92.7%
if -1.14999999999999997e116 < z < -6.4e13 or 1.6499999999999999e24 < z Initial program 99.9%
Taylor expanded in x around 0 92.6%
neg-mul-192.6%
Simplified92.6%
if -1.35e-40 < z < 1.6499999999999999e24Initial program 99.8%
Taylor expanded in z around 0 95.0%
Final simplification93.8%
(FPCore (x y z)
:precision binary64
(if (or (<= x -4.15e+126)
(and (not (<= x -1.1e+95))
(or (<= x -3.5e+41) (not (<= x 7.2e+125)))))
(* (log y) x)
(- (- y) z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -4.15e+126) || (!(x <= -1.1e+95) && ((x <= -3.5e+41) || !(x <= 7.2e+125)))) {
tmp = log(y) * x;
} else {
tmp = -y - z;
}
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 <= (-4.15d+126)) .or. (.not. (x <= (-1.1d+95))) .and. (x <= (-3.5d+41)) .or. (.not. (x <= 7.2d+125))) then
tmp = log(y) * x
else
tmp = -y - z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -4.15e+126) || (!(x <= -1.1e+95) && ((x <= -3.5e+41) || !(x <= 7.2e+125)))) {
tmp = Math.log(y) * x;
} else {
tmp = -y - z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -4.15e+126) or (not (x <= -1.1e+95) and ((x <= -3.5e+41) or not (x <= 7.2e+125))): tmp = math.log(y) * x else: tmp = -y - z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -4.15e+126) || (!(x <= -1.1e+95) && ((x <= -3.5e+41) || !(x <= 7.2e+125)))) tmp = Float64(log(y) * x); else tmp = Float64(Float64(-y) - z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -4.15e+126) || (~((x <= -1.1e+95)) && ((x <= -3.5e+41) || ~((x <= 7.2e+125))))) tmp = log(y) * x; else tmp = -y - z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -4.15e+126], And[N[Not[LessEqual[x, -1.1e+95]], $MachinePrecision], Or[LessEqual[x, -3.5e+41], N[Not[LessEqual[x, 7.2e+125]], $MachinePrecision]]]], N[(N[Log[y], $MachinePrecision] * x), $MachinePrecision], N[((-y) - z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.15 \cdot 10^{+126} \lor \neg \left(x \leq -1.1 \cdot 10^{+95}\right) \land \left(x \leq -3.5 \cdot 10^{+41} \lor \neg \left(x \leq 7.2 \cdot 10^{+125}\right)\right):\\
\;\;\;\;\log y \cdot x\\
\mathbf{else}:\\
\;\;\;\;\left(-y\right) - z\\
\end{array}
\end{array}
if x < -4.14999999999999995e126 or -1.0999999999999999e95 < x < -3.4999999999999999e41 or 7.2000000000000007e125 < x Initial program 99.8%
sub-neg99.8%
associate-+l-99.8%
*-commutative99.8%
add-sqr-sqrt0.0%
sqrt-unprod68.9%
sqr-neg68.9%
sqrt-unprod83.5%
add-sqr-sqrt83.5%
fma-neg83.5%
add-cube-cbrt83.3%
fma-neg83.3%
add-sqr-sqrt0.0%
sqrt-unprod73.2%
sqr-neg73.2%
sqrt-unprod99.5%
add-sqr-sqrt99.6%
fma-define99.6%
add-cube-cbrt99.8%
+-commutative99.8%
Applied egg-rr99.8%
Taylor expanded in x around inf 74.0%
if -4.14999999999999995e126 < x < -1.0999999999999999e95 or -3.4999999999999999e41 < x < 7.2000000000000007e125Initial program 99.9%
Taylor expanded in x around 0 86.4%
neg-mul-186.4%
Simplified86.4%
Final simplification81.4%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.25e-52) (not (<= z 1.4e+24))) (- (- y) z) (- (* (log y) x) y)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.25e-52) || !(z <= 1.4e+24)) {
tmp = -y - z;
} else {
tmp = (log(y) * x) - 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 <= (-1.25d-52)) .or. (.not. (z <= 1.4d+24))) then
tmp = -y - z
else
tmp = (log(y) * x) - y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -1.25e-52) || !(z <= 1.4e+24)) {
tmp = -y - z;
} else {
tmp = (Math.log(y) * x) - y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.25e-52) or not (z <= 1.4e+24): tmp = -y - z else: tmp = (math.log(y) * x) - y return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.25e-52) || !(z <= 1.4e+24)) tmp = Float64(Float64(-y) - z); else tmp = Float64(Float64(log(y) * x) - y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -1.25e-52) || ~((z <= 1.4e+24))) tmp = -y - z; else tmp = (log(y) * x) - y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.25e-52], N[Not[LessEqual[z, 1.4e+24]], $MachinePrecision]], N[((-y) - z), $MachinePrecision], N[(N[(N[Log[y], $MachinePrecision] * x), $MachinePrecision] - y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.25 \cdot 10^{-52} \lor \neg \left(z \leq 1.4 \cdot 10^{+24}\right):\\
\;\;\;\;\left(-y\right) - z\\
\mathbf{else}:\\
\;\;\;\;\log y \cdot x - y\\
\end{array}
\end{array}
if z < -1.25e-52 or 1.4000000000000001e24 < z Initial program 99.9%
Taylor expanded in x around 0 84.4%
neg-mul-184.4%
Simplified84.4%
if -1.25e-52 < z < 1.4000000000000001e24Initial program 99.8%
Taylor expanded in z around 0 95.6%
Final simplification90.2%
(FPCore (x y z) :precision binary64 (- (- (* (log y) x) z) y))
double code(double x, double y, double z) {
return ((log(y) * x) - 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 = ((log(y) * x) - z) - y
end function
public static double code(double x, double y, double z) {
return ((Math.log(y) * x) - z) - y;
}
def code(x, y, z): return ((math.log(y) * x) - z) - y
function code(x, y, z) return Float64(Float64(Float64(log(y) * x) - z) - y) end
function tmp = code(x, y, z) tmp = ((log(y) * x) - z) - y; end
code[x_, y_, z_] := N[(N[(N[(N[Log[y], $MachinePrecision] * x), $MachinePrecision] - z), $MachinePrecision] - y), $MachinePrecision]
\begin{array}{l}
\\
\left(\log y \cdot x - z\right) - y
\end{array}
Initial program 99.9%
Final simplification99.9%
(FPCore (x y z) :precision binary64 (if (<= y 11200000.0) (- z) (- y)))
double code(double x, double y, double z) {
double tmp;
if (y <= 11200000.0) {
tmp = -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 (y <= 11200000.0d0) then
tmp = -z
else
tmp = -y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= 11200000.0) {
tmp = -z;
} else {
tmp = -y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= 11200000.0: tmp = -z else: tmp = -y return tmp
function code(x, y, z) tmp = 0.0 if (y <= 11200000.0) tmp = Float64(-z); else tmp = Float64(-y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= 11200000.0) tmp = -z; else tmp = -y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, 11200000.0], (-z), (-y)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 11200000:\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;-y\\
\end{array}
\end{array}
if y < 1.12e7Initial program 99.8%
sub-neg99.8%
associate-+l-99.8%
*-commutative99.8%
add-sqr-sqrt0.0%
sqrt-unprod92.5%
sqr-neg92.5%
sqrt-unprod92.5%
add-sqr-sqrt92.5%
fma-neg92.5%
add-cube-cbrt91.5%
fma-neg91.5%
add-sqr-sqrt0.0%
sqrt-unprod96.9%
sqr-neg96.9%
sqrt-unprod98.8%
add-sqr-sqrt98.9%
fma-define98.9%
add-cube-cbrt99.9%
+-commutative99.9%
Applied egg-rr99.9%
Taylor expanded in z around inf 47.8%
neg-mul-147.8%
Simplified47.8%
if 1.12e7 < y Initial program 99.9%
Taylor expanded in y around inf 55.2%
mul-1-neg55.2%
Simplified55.2%
Final simplification51.2%
(FPCore (x y z) :precision binary64 (- (- y) z))
double code(double x, double y, double z) {
return -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 = -y - z
end function
public static double code(double x, double y, double z) {
return -y - z;
}
def code(x, y, z): return -y - z
function code(x, y, z) return Float64(Float64(-y) - z) end
function tmp = code(x, y, z) tmp = -y - z; end
code[x_, y_, z_] := N[((-y) - z), $MachinePrecision]
\begin{array}{l}
\\
\left(-y\right) - z
\end{array}
Initial program 99.9%
Taylor expanded in x around 0 61.9%
neg-mul-161.9%
Simplified61.9%
Final simplification61.9%
(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.9%
Taylor expanded in y around inf 30.3%
mul-1-neg30.3%
Simplified30.3%
Final simplification30.3%
herbie shell --seed 2024039
(FPCore (x y z)
:name "Statistics.Distribution.Poisson:$clogProbability from math-functions-0.1.5.2"
:precision binary64
(- (- (* x (log y)) z) y))