
(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 (fma (log y) x (- (- z) y)))
double code(double x, double y, double z) {
return fma(log(y), x, (-z - y));
}
function code(x, y, z) return fma(log(y), x, Float64(Float64(-z) - y)) end
code[x_, y_, z_] := N[(N[Log[y], $MachinePrecision] * x + N[((-z) - y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\log y, x, \left(-z\right) - y\right)
\end{array}
Initial program 99.8%
associate--l-99.8%
*-commutative99.8%
fma-neg99.8%
distribute-neg-in99.8%
add-cube-cbrt99.2%
distribute-lft-neg-in99.2%
cancel-sign-sub-inv99.2%
add-cube-cbrt99.8%
Applied egg-rr99.8%
Final simplification99.8%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (- (- z) y)) (t_1 (* (log y) x)))
(if (<= z -1.92e+25)
t_0
(if (<= z 1.16e+92) (- t_1 y) (if (<= z 2.3e+133) t_0 (- t_1 z))))))
double code(double x, double y, double z) {
double t_0 = -z - y;
double t_1 = log(y) * x;
double tmp;
if (z <= -1.92e+25) {
tmp = t_0;
} else if (z <= 1.16e+92) {
tmp = t_1 - y;
} else if (z <= 2.3e+133) {
tmp = t_0;
} else {
tmp = t_1 - 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) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = -z - y
t_1 = log(y) * x
if (z <= (-1.92d+25)) then
tmp = t_0
else if (z <= 1.16d+92) then
tmp = t_1 - y
else if (z <= 2.3d+133) then
tmp = t_0
else
tmp = t_1 - z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = -z - y;
double t_1 = Math.log(y) * x;
double tmp;
if (z <= -1.92e+25) {
tmp = t_0;
} else if (z <= 1.16e+92) {
tmp = t_1 - y;
} else if (z <= 2.3e+133) {
tmp = t_0;
} else {
tmp = t_1 - z;
}
return tmp;
}
def code(x, y, z): t_0 = -z - y t_1 = math.log(y) * x tmp = 0 if z <= -1.92e+25: tmp = t_0 elif z <= 1.16e+92: tmp = t_1 - y elif z <= 2.3e+133: tmp = t_0 else: tmp = t_1 - z return tmp
function code(x, y, z) t_0 = Float64(Float64(-z) - y) t_1 = Float64(log(y) * x) tmp = 0.0 if (z <= -1.92e+25) tmp = t_0; elseif (z <= 1.16e+92) tmp = Float64(t_1 - y); elseif (z <= 2.3e+133) tmp = t_0; else tmp = Float64(t_1 - z); end return tmp end
function tmp_2 = code(x, y, z) t_0 = -z - y; t_1 = log(y) * x; tmp = 0.0; if (z <= -1.92e+25) tmp = t_0; elseif (z <= 1.16e+92) tmp = t_1 - y; elseif (z <= 2.3e+133) tmp = t_0; else tmp = t_1 - z; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[((-z) - y), $MachinePrecision]}, Block[{t$95$1 = N[(N[Log[y], $MachinePrecision] * x), $MachinePrecision]}, If[LessEqual[z, -1.92e+25], t$95$0, If[LessEqual[z, 1.16e+92], N[(t$95$1 - y), $MachinePrecision], If[LessEqual[z, 2.3e+133], t$95$0, N[(t$95$1 - z), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(-z\right) - y\\
t_1 := \log y \cdot x\\
\mathbf{if}\;z \leq -1.92 \cdot 10^{+25}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq 1.16 \cdot 10^{+92}:\\
\;\;\;\;t_1 - y\\
\mathbf{elif}\;z \leq 2.3 \cdot 10^{+133}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;t_1 - z\\
\end{array}
\end{array}
if z < -1.9200000000000001e25 or 1.16000000000000006e92 < z < 2.2999999999999999e133Initial program 99.9%
Taylor expanded in x around 0 86.0%
mul-1-neg86.0%
Simplified86.0%
if -1.9200000000000001e25 < z < 1.16000000000000006e92Initial program 99.8%
Taylor expanded in x around inf 90.6%
if 2.2999999999999999e133 < z Initial program 99.9%
Taylor expanded in y around 0 97.3%
Final simplification90.4%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.92e+25) (not (<= z 4.8e+86))) (- (- z) y) (- (* (log y) x) y)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.92e+25) || !(z <= 4.8e+86)) {
tmp = -z - y;
} 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.92d+25)) .or. (.not. (z <= 4.8d+86))) then
tmp = -z - y
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.92e+25) || !(z <= 4.8e+86)) {
tmp = -z - y;
} else {
tmp = (Math.log(y) * x) - y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.92e+25) or not (z <= 4.8e+86): tmp = -z - y else: tmp = (math.log(y) * x) - y return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.92e+25) || !(z <= 4.8e+86)) tmp = Float64(Float64(-z) - y); 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.92e+25) || ~((z <= 4.8e+86))) tmp = -z - y; else tmp = (log(y) * x) - y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.92e+25], N[Not[LessEqual[z, 4.8e+86]], $MachinePrecision]], N[((-z) - y), $MachinePrecision], N[(N[(N[Log[y], $MachinePrecision] * x), $MachinePrecision] - y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.92 \cdot 10^{+25} \lor \neg \left(z \leq 4.8 \cdot 10^{+86}\right):\\
\;\;\;\;\left(-z\right) - y\\
\mathbf{else}:\\
\;\;\;\;\log y \cdot x - y\\
\end{array}
\end{array}
if z < -1.9200000000000001e25 or 4.8000000000000001e86 < z Initial program 99.9%
Taylor expanded in x around 0 82.2%
mul-1-neg82.2%
Simplified82.2%
if -1.9200000000000001e25 < z < 4.8000000000000001e86Initial program 99.8%
Taylor expanded in x around inf 90.6%
Final simplification87.0%
(FPCore (x y z) :precision binary64 (if (or (<= x -3.9e+102) (not (<= x 8.2e+160))) (* (log y) x) (- (- z) y)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -3.9e+102) || !(x <= 8.2e+160)) {
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 <= (-3.9d+102)) .or. (.not. (x <= 8.2d+160))) 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 <= -3.9e+102) || !(x <= 8.2e+160)) {
tmp = Math.log(y) * x;
} else {
tmp = -z - y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -3.9e+102) or not (x <= 8.2e+160): tmp = math.log(y) * x else: tmp = -z - y return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -3.9e+102) || !(x <= 8.2e+160)) 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 <= -3.9e+102) || ~((x <= 8.2e+160))) tmp = log(y) * x; else tmp = -z - y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -3.9e+102], N[Not[LessEqual[x, 8.2e+160]], $MachinePrecision]], N[(N[Log[y], $MachinePrecision] * x), $MachinePrecision], N[((-z) - y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.9 \cdot 10^{+102} \lor \neg \left(x \leq 8.2 \cdot 10^{+160}\right):\\
\;\;\;\;\log y \cdot x\\
\mathbf{else}:\\
\;\;\;\;\left(-z\right) - y\\
\end{array}
\end{array}
if x < -3.8999999999999998e102 or 8.19999999999999996e160 < x Initial program 99.6%
associate--l-99.6%
*-commutative99.6%
fma-neg99.6%
distribute-neg-in99.6%
add-cube-cbrt99.4%
distribute-lft-neg-in99.4%
cancel-sign-sub-inv99.4%
add-cube-cbrt99.6%
Applied egg-rr99.6%
Taylor expanded in x around inf 73.8%
if -3.8999999999999998e102 < x < 8.19999999999999996e160Initial program 99.9%
Taylor expanded in x around 0 82.4%
mul-1-neg82.4%
Simplified82.4%
Final simplification79.7%
(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.8%
Final simplification99.8%
(FPCore (x y z) :precision binary64 (if (<= y 3.2e+42) (- z) (- y)))
double code(double x, double y, double z) {
double tmp;
if (y <= 3.2e+42) {
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 <= 3.2d+42) 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 <= 3.2e+42) {
tmp = -z;
} else {
tmp = -y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= 3.2e+42: tmp = -z else: tmp = -y return tmp
function code(x, y, z) tmp = 0.0 if (y <= 3.2e+42) tmp = Float64(-z); else tmp = Float64(-y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= 3.2e+42) tmp = -z; else tmp = -y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, 3.2e+42], (-z), (-y)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 3.2 \cdot 10^{+42}:\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;-y\\
\end{array}
\end{array}
if y < 3.20000000000000002e42Initial program 99.8%
associate--l-99.8%
*-commutative99.8%
fma-neg99.8%
distribute-neg-in99.8%
add-cube-cbrt99.7%
distribute-lft-neg-in99.7%
cancel-sign-sub-inv99.7%
add-cube-cbrt99.8%
Applied egg-rr99.8%
Taylor expanded in z around inf 46.6%
mul-1-neg46.6%
Simplified46.6%
if 3.20000000000000002e42 < y Initial program 99.9%
Taylor expanded in y around inf 61.0%
mul-1-neg61.0%
Simplified61.0%
Final simplification53.0%
(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 63.8%
mul-1-neg63.8%
Simplified63.8%
Final simplification63.8%
(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 31.8%
mul-1-neg31.8%
Simplified31.8%
Final simplification31.8%
herbie shell --seed 2023301
(FPCore (x y z)
:name "Statistics.Distribution.Poisson:$clogProbability from math-functions-0.1.5.2"
:precision binary64
(- (- (* x (log y)) z) y))