
(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%
Final simplification99.8%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* (log y) x)) (t_1 (- t_0 y)))
(if (<= x -1.55e+43)
t_1
(if (<= x -8.5e-19)
(- t_0 z)
(if (<= x 1060000000000.0) (- (- z) y) t_1)))))
double code(double x, double y, double z) {
double t_0 = log(y) * x;
double t_1 = t_0 - y;
double tmp;
if (x <= -1.55e+43) {
tmp = t_1;
} else if (x <= -8.5e-19) {
tmp = t_0 - z;
} else if (x <= 1060000000000.0) {
tmp = -z - y;
} else {
tmp = t_1;
}
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 = log(y) * x
t_1 = t_0 - y
if (x <= (-1.55d+43)) then
tmp = t_1
else if (x <= (-8.5d-19)) then
tmp = t_0 - z
else if (x <= 1060000000000.0d0) then
tmp = -z - y
else
tmp = t_1
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 - y;
double tmp;
if (x <= -1.55e+43) {
tmp = t_1;
} else if (x <= -8.5e-19) {
tmp = t_0 - z;
} else if (x <= 1060000000000.0) {
tmp = -z - y;
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z): t_0 = math.log(y) * x t_1 = t_0 - y tmp = 0 if x <= -1.55e+43: tmp = t_1 elif x <= -8.5e-19: tmp = t_0 - z elif x <= 1060000000000.0: tmp = -z - y else: tmp = t_1 return tmp
function code(x, y, z) t_0 = Float64(log(y) * x) t_1 = Float64(t_0 - y) tmp = 0.0 if (x <= -1.55e+43) tmp = t_1; elseif (x <= -8.5e-19) tmp = Float64(t_0 - z); elseif (x <= 1060000000000.0) tmp = Float64(Float64(-z) - y); else tmp = t_1; end return tmp end
function tmp_2 = code(x, y, z) t_0 = log(y) * x; t_1 = t_0 - y; tmp = 0.0; if (x <= -1.55e+43) tmp = t_1; elseif (x <= -8.5e-19) tmp = t_0 - z; elseif (x <= 1060000000000.0) tmp = -z - y; else tmp = t_1; 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 - y), $MachinePrecision]}, If[LessEqual[x, -1.55e+43], t$95$1, If[LessEqual[x, -8.5e-19], N[(t$95$0 - z), $MachinePrecision], If[LessEqual[x, 1060000000000.0], N[((-z) - y), $MachinePrecision], t$95$1]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \log y \cdot x\\
t_1 := t\_0 - y\\
\mathbf{if}\;x \leq -1.55 \cdot 10^{+43}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;x \leq -8.5 \cdot 10^{-19}:\\
\;\;\;\;t\_0 - z\\
\mathbf{elif}\;x \leq 1060000000000:\\
\;\;\;\;\left(-z\right) - y\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if x < -1.5500000000000001e43 or 1.06e12 < x Initial program 99.7%
Taylor expanded in z around 0 89.0%
if -1.5500000000000001e43 < x < -8.50000000000000003e-19Initial program 100.0%
Taylor expanded in y around 0 89.8%
if -8.50000000000000003e-19 < x < 1.06e12Initial program 99.9%
Taylor expanded in x around 0 91.7%
neg-mul-191.7%
Simplified91.7%
Final simplification90.4%
(FPCore (x y z) :precision binary64 (if (or (<= x -3.3e-18) (not (<= x 1020000000000.0))) (- (* (log y) x) y) (- (- z) y)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -3.3e-18) || !(x <= 1020000000000.0)) {
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 <= (-3.3d-18)) .or. (.not. (x <= 1020000000000.0d0))) 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 <= -3.3e-18) || !(x <= 1020000000000.0)) {
tmp = (Math.log(y) * x) - y;
} else {
tmp = -z - y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -3.3e-18) or not (x <= 1020000000000.0): tmp = (math.log(y) * x) - y else: tmp = -z - y return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -3.3e-18) || !(x <= 1020000000000.0)) 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 <= -3.3e-18) || ~((x <= 1020000000000.0))) tmp = (log(y) * x) - y; else tmp = -z - y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -3.3e-18], N[Not[LessEqual[x, 1020000000000.0]], $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 -3.3 \cdot 10^{-18} \lor \neg \left(x \leq 1020000000000\right):\\
\;\;\;\;\log y \cdot x - y\\
\mathbf{else}:\\
\;\;\;\;\left(-z\right) - y\\
\end{array}
\end{array}
if x < -3.3000000000000002e-18 or 1.02e12 < x Initial program 99.7%
Taylor expanded in z around 0 85.7%
if -3.3000000000000002e-18 < x < 1.02e12Initial program 99.9%
Taylor expanded in x around 0 91.7%
neg-mul-191.7%
Simplified91.7%
Final simplification88.7%
(FPCore (x y z) :precision binary64 (if (or (<= x -3.6e+97) (not (<= x 2e+58))) (* (log y) x) (- (- z) y)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -3.6e+97) || !(x <= 2e+58)) {
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.6d+97)) .or. (.not. (x <= 2d+58))) 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.6e+97) || !(x <= 2e+58)) {
tmp = Math.log(y) * x;
} else {
tmp = -z - y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -3.6e+97) or not (x <= 2e+58): tmp = math.log(y) * x else: tmp = -z - y return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -3.6e+97) || !(x <= 2e+58)) 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.6e+97) || ~((x <= 2e+58))) tmp = log(y) * x; else tmp = -z - y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -3.6e+97], N[Not[LessEqual[x, 2e+58]], $MachinePrecision]], N[(N[Log[y], $MachinePrecision] * x), $MachinePrecision], N[((-z) - y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.6 \cdot 10^{+97} \lor \neg \left(x \leq 2 \cdot 10^{+58}\right):\\
\;\;\;\;\log y \cdot x\\
\mathbf{else}:\\
\;\;\;\;\left(-z\right) - y\\
\end{array}
\end{array}
if x < -3.59999999999999966e97 or 1.99999999999999989e58 < x Initial program 99.6%
sub-neg99.6%
associate--l+99.6%
*-commutative99.6%
fma-define99.6%
Applied egg-rr99.6%
Taylor expanded in x around inf 72.8%
if -3.59999999999999966e97 < x < 1.99999999999999989e58Initial program 99.9%
Taylor expanded in x around 0 86.0%
neg-mul-186.0%
Simplified86.0%
Final simplification81.3%
(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 9.8e+57) (- z) (- y)))
double code(double x, double y, double z) {
double tmp;
if (y <= 9.8e+57) {
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 <= 9.8d+57) 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 <= 9.8e+57) {
tmp = -z;
} else {
tmp = -y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= 9.8e+57: tmp = -z else: tmp = -y return tmp
function code(x, y, z) tmp = 0.0 if (y <= 9.8e+57) tmp = Float64(-z); else tmp = Float64(-y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= 9.8e+57) tmp = -z; else tmp = -y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, 9.8e+57], (-z), (-y)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 9.8 \cdot 10^{+57}:\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;-y\\
\end{array}
\end{array}
if y < 9.7999999999999998e57Initial program 99.7%
sub-neg99.7%
associate--l+99.7%
*-commutative99.7%
fma-define99.8%
Applied egg-rr99.8%
Taylor expanded in z around inf 41.4%
mul-1-neg41.4%
Simplified41.4%
if 9.7999999999999998e57 < y Initial program 99.9%
Taylor expanded in y around inf 66.3%
neg-mul-166.3%
Simplified66.3%
Final simplification51.6%
(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.5%
neg-mul-165.5%
Simplified65.5%
Final simplification65.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 34.3%
neg-mul-134.3%
Simplified34.3%
Final simplification34.3%
herbie shell --seed 2024055
(FPCore (x y z)
:name "Statistics.Distribution.Poisson:$clogProbability from math-functions-0.1.5.2"
:precision binary64
(- (- (* x (log y)) z) y))