
(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%
sub-neg99.8%
associate--l+99.8%
*-commutative99.8%
fma-define99.8%
Applied egg-rr99.8%
(FPCore (x y z)
:precision binary64
(if (or (<= x -7.8e+220)
(not
(or (<= x -2.2e+194) (and (not (<= x -1.12e+64)) (<= x 3.8e+151)))))
(* (log y) x)
(- (- z) y)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -7.8e+220) || !((x <= -2.2e+194) || (!(x <= -1.12e+64) && (x <= 3.8e+151)))) {
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 <= (-7.8d+220)) .or. (.not. (x <= (-2.2d+194)) .or. (.not. (x <= (-1.12d+64))) .and. (x <= 3.8d+151))) 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 <= -7.8e+220) || !((x <= -2.2e+194) || (!(x <= -1.12e+64) && (x <= 3.8e+151)))) {
tmp = Math.log(y) * x;
} else {
tmp = -z - y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -7.8e+220) or not ((x <= -2.2e+194) or (not (x <= -1.12e+64) and (x <= 3.8e+151))): tmp = math.log(y) * x else: tmp = -z - y return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -7.8e+220) || !((x <= -2.2e+194) || (!(x <= -1.12e+64) && (x <= 3.8e+151)))) 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 <= -7.8e+220) || ~(((x <= -2.2e+194) || (~((x <= -1.12e+64)) && (x <= 3.8e+151))))) tmp = log(y) * x; else tmp = -z - y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -7.8e+220], N[Not[Or[LessEqual[x, -2.2e+194], And[N[Not[LessEqual[x, -1.12e+64]], $MachinePrecision], LessEqual[x, 3.8e+151]]]], $MachinePrecision]], N[(N[Log[y], $MachinePrecision] * x), $MachinePrecision], N[((-z) - y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -7.8 \cdot 10^{+220} \lor \neg \left(x \leq -2.2 \cdot 10^{+194} \lor \neg \left(x \leq -1.12 \cdot 10^{+64}\right) \land x \leq 3.8 \cdot 10^{+151}\right):\\
\;\;\;\;\log y \cdot x\\
\mathbf{else}:\\
\;\;\;\;\left(-z\right) - y\\
\end{array}
\end{array}
if x < -7.80000000000000032e220 or -2.2000000000000001e194 < x < -1.11999999999999995e64 or 3.8e151 < x Initial program 99.6%
Taylor expanded in y around inf 67.3%
sub-neg67.3%
mul-1-neg67.3%
*-commutative67.3%
associate-/l*67.4%
distribute-lft-neg-in67.4%
log-rec67.4%
remove-double-neg67.4%
distribute-neg-in67.4%
metadata-eval67.4%
unsub-neg67.4%
Simplified67.4%
Taylor expanded in x around inf 75.7%
if -7.80000000000000032e220 < x < -2.2000000000000001e194 or -1.11999999999999995e64 < x < 3.8e151Initial program 99.9%
Taylor expanded in x around 0 85.4%
neg-mul-185.4%
Simplified85.4%
Final simplification82.2%
(FPCore (x y z) :precision binary64 (if (or (<= x -7.6e+63) (not (<= x 1.75e-13))) (- (* (log y) x) y) (- (- z) y)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -7.6e+63) || !(x <= 1.75e-13)) {
tmp = (log(y) * x) - y;
} 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 <= (-7.6d+63)) .or. (.not. (x <= 1.75d-13))) then
tmp = (log(y) * x) - y
else
tmp = -z - y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -7.6e+63) || !(x <= 1.75e-13)) {
tmp = (Math.log(y) * x) - y;
} else {
tmp = -z - y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -7.6e+63) or not (x <= 1.75e-13): tmp = (math.log(y) * x) - y else: tmp = -z - y return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -7.6e+63) || !(x <= 1.75e-13)) tmp = Float64(Float64(log(y) * x) - y); else tmp = Float64(Float64(-z) - y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -7.6e+63) || ~((x <= 1.75e-13))) tmp = (log(y) * x) - y; else tmp = -z - y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -7.6e+63], N[Not[LessEqual[x, 1.75e-13]], $MachinePrecision]], N[(N[(N[Log[y], $MachinePrecision] * x), $MachinePrecision] - y), $MachinePrecision], N[((-z) - y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -7.6 \cdot 10^{+63} \lor \neg \left(x \leq 1.75 \cdot 10^{-13}\right):\\
\;\;\;\;\log y \cdot x - y\\
\mathbf{else}:\\
\;\;\;\;\left(-z\right) - y\\
\end{array}
\end{array}
if x < -7.6000000000000002e63 or 1.7500000000000001e-13 < x Initial program 99.7%
Taylor expanded in z around 0 84.4%
if -7.6000000000000002e63 < x < 1.7500000000000001e-13Initial program 99.9%
Taylor expanded in x around 0 90.4%
neg-mul-190.4%
Simplified90.4%
Final simplification87.6%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* (log y) x))) (if (<= y 0.65) (- t_0 z) (- t_0 y))))
double code(double x, double y, double z) {
double t_0 = log(y) * x;
double tmp;
if (y <= 0.65) {
tmp = t_0 - z;
} else {
tmp = t_0 - 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) :: t_0
real(8) :: tmp
t_0 = log(y) * x
if (y <= 0.65d0) then
tmp = t_0 - z
else
tmp = t_0 - y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = Math.log(y) * x;
double tmp;
if (y <= 0.65) {
tmp = t_0 - z;
} else {
tmp = t_0 - y;
}
return tmp;
}
def code(x, y, z): t_0 = math.log(y) * x tmp = 0 if y <= 0.65: tmp = t_0 - z else: tmp = t_0 - y return tmp
function code(x, y, z) t_0 = Float64(log(y) * x) tmp = 0.0 if (y <= 0.65) tmp = Float64(t_0 - z); else tmp = Float64(t_0 - y); end return tmp end
function tmp_2 = code(x, y, z) t_0 = log(y) * x; tmp = 0.0; if (y <= 0.65) tmp = t_0 - z; else tmp = t_0 - y; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[Log[y], $MachinePrecision] * x), $MachinePrecision]}, If[LessEqual[y, 0.65], N[(t$95$0 - z), $MachinePrecision], N[(t$95$0 - y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \log y \cdot x\\
\mathbf{if}\;y \leq 0.65:\\
\;\;\;\;t\_0 - z\\
\mathbf{else}:\\
\;\;\;\;t\_0 - y\\
\end{array}
\end{array}
if y < 0.650000000000000022Initial program 99.7%
Taylor expanded in y around inf 60.4%
sub-neg60.4%
mul-1-neg60.4%
*-commutative60.4%
associate-/l*60.4%
distribute-lft-neg-in60.4%
log-rec60.4%
remove-double-neg60.4%
distribute-neg-in60.4%
metadata-eval60.4%
unsub-neg60.4%
Simplified60.4%
Taylor expanded in y around 0 95.3%
if 0.650000000000000022 < y Initial program 99.9%
Taylor expanded in z around 0 86.9%
Final simplification90.9%
(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 7e+41) (- z) (- y)))
double code(double x, double y, double z) {
double tmp;
if (y <= 7e+41) {
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 <= 7d+41) 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 <= 7e+41) {
tmp = -z;
} else {
tmp = -y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= 7e+41: tmp = -z else: tmp = -y return tmp
function code(x, y, z) tmp = 0.0 if (y <= 7e+41) tmp = Float64(-z); else tmp = Float64(-y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= 7e+41) tmp = -z; else tmp = -y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, 7e+41], (-z), (-y)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 7 \cdot 10^{+41}:\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;-y\\
\end{array}
\end{array}
if y < 6.9999999999999998e41Initial program 99.8%
Taylor expanded in y around inf 64.4%
sub-neg64.4%
mul-1-neg64.4%
*-commutative64.4%
associate-/l*64.4%
distribute-lft-neg-in64.4%
log-rec64.4%
remove-double-neg64.4%
distribute-neg-in64.4%
metadata-eval64.4%
unsub-neg64.4%
Simplified64.4%
Taylor expanded in z around inf 46.9%
neg-mul-146.9%
Simplified46.9%
if 6.9999999999999998e41 < y Initial program 99.9%
Taylor expanded in y around inf 67.3%
neg-mul-167.3%
Simplified67.3%
(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 65.3%
neg-mul-165.3%
Simplified65.3%
(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 35.9%
neg-mul-135.9%
Simplified35.9%
herbie shell --seed 2024111
(FPCore (x y z)
:name "Statistics.Distribution.Poisson:$clogProbability from math-functions-0.1.5.2"
:precision binary64
(- (- (* x (log y)) z) y))