
(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 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 fma(x, log(y), Float64(Float64(-y) - z)) end
code[x_, y_, z_] := N[(x * N[Log[y], $MachinePrecision] + N[((-y) - z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x, \log y, \left(-y\right) - z\right)
\end{array}
Initial program 99.8%
associate--l-99.8%
fma-neg99.9%
distribute-neg-in99.9%
+-commutative99.9%
sub-neg99.9%
Simplified99.9%
Final simplification99.9%
(FPCore (x y z)
:precision binary64
(if (or (<= x -3.8e+108)
(not (or (<= x -4e+34) (and (not (<= x -9.8e-5)) (<= x 2.75e+110)))))
(* x (log y))
(- (- y) z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -3.8e+108) || !((x <= -4e+34) || (!(x <= -9.8e-5) && (x <= 2.75e+110)))) {
tmp = x * log(y);
} 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 <= (-3.8d+108)) .or. (.not. (x <= (-4d+34)) .or. (.not. (x <= (-9.8d-5))) .and. (x <= 2.75d+110))) then
tmp = x * log(y)
else
tmp = -y - z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -3.8e+108) || !((x <= -4e+34) || (!(x <= -9.8e-5) && (x <= 2.75e+110)))) {
tmp = x * Math.log(y);
} else {
tmp = -y - z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -3.8e+108) or not ((x <= -4e+34) or (not (x <= -9.8e-5) and (x <= 2.75e+110))): tmp = x * math.log(y) else: tmp = -y - z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -3.8e+108) || !((x <= -4e+34) || (!(x <= -9.8e-5) && (x <= 2.75e+110)))) tmp = Float64(x * log(y)); else tmp = Float64(Float64(-y) - z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -3.8e+108) || ~(((x <= -4e+34) || (~((x <= -9.8e-5)) && (x <= 2.75e+110))))) tmp = x * log(y); else tmp = -y - z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -3.8e+108], N[Not[Or[LessEqual[x, -4e+34], And[N[Not[LessEqual[x, -9.8e-5]], $MachinePrecision], LessEqual[x, 2.75e+110]]]], $MachinePrecision]], N[(x * N[Log[y], $MachinePrecision]), $MachinePrecision], N[((-y) - z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.8 \cdot 10^{+108} \lor \neg \left(x \leq -4 \cdot 10^{+34} \lor \neg \left(x \leq -9.8 \cdot 10^{-5}\right) \land x \leq 2.75 \cdot 10^{+110}\right):\\
\;\;\;\;x \cdot \log y\\
\mathbf{else}:\\
\;\;\;\;\left(-y\right) - z\\
\end{array}
\end{array}
if x < -3.80000000000000008e108 or -3.99999999999999978e34 < x < -9.8e-5 or 2.74999999999999998e110 < x Initial program 99.6%
Taylor expanded in z around 0 88.3%
Taylor expanded in x around inf 78.9%
if -3.80000000000000008e108 < x < -3.99999999999999978e34 or -9.8e-5 < x < 2.74999999999999998e110Initial program 100.0%
Taylor expanded in x around 0 88.8%
mul-1-neg88.8%
+-commutative88.8%
distribute-neg-in88.8%
sub-neg88.8%
Simplified88.8%
Final simplification85.3%
(FPCore (x y z) :precision binary64 (if (or (<= z -6e+16) (not (<= z 7.4e+120))) (- (- y) z) (- (* x (log y)) y)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -6e+16) || !(z <= 7.4e+120)) {
tmp = -y - z;
} else {
tmp = (x * log(y)) - 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 <= (-6d+16)) .or. (.not. (z <= 7.4d+120))) then
tmp = -y - z
else
tmp = (x * log(y)) - y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -6e+16) || !(z <= 7.4e+120)) {
tmp = -y - z;
} else {
tmp = (x * Math.log(y)) - y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -6e+16) or not (z <= 7.4e+120): tmp = -y - z else: tmp = (x * math.log(y)) - y return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -6e+16) || !(z <= 7.4e+120)) tmp = Float64(Float64(-y) - z); else tmp = Float64(Float64(x * log(y)) - y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -6e+16) || ~((z <= 7.4e+120))) tmp = -y - z; else tmp = (x * log(y)) - y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -6e+16], N[Not[LessEqual[z, 7.4e+120]], $MachinePrecision]], N[((-y) - z), $MachinePrecision], N[(N[(x * N[Log[y], $MachinePrecision]), $MachinePrecision] - y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -6 \cdot 10^{+16} \lor \neg \left(z \leq 7.4 \cdot 10^{+120}\right):\\
\;\;\;\;\left(-y\right) - z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \log y - y\\
\end{array}
\end{array}
if z < -6e16 or 7.40000000000000048e120 < z Initial program 100.0%
Taylor expanded in x around 0 87.7%
mul-1-neg87.7%
+-commutative87.7%
distribute-neg-in87.7%
sub-neg87.7%
Simplified87.7%
if -6e16 < z < 7.40000000000000048e120Initial program 99.8%
Taylor expanded in z around 0 92.0%
Final simplification90.3%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* x (log y)))) (if (or (<= z -9.4e+42) (not (<= z 1.55e+38))) (- t_0 z) (- t_0 y))))
double code(double x, double y, double z) {
double t_0 = x * log(y);
double tmp;
if ((z <= -9.4e+42) || !(z <= 1.55e+38)) {
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 = x * log(y)
if ((z <= (-9.4d+42)) .or. (.not. (z <= 1.55d+38))) 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 = x * Math.log(y);
double tmp;
if ((z <= -9.4e+42) || !(z <= 1.55e+38)) {
tmp = t_0 - z;
} else {
tmp = t_0 - y;
}
return tmp;
}
def code(x, y, z): t_0 = x * math.log(y) tmp = 0 if (z <= -9.4e+42) or not (z <= 1.55e+38): tmp = t_0 - z else: tmp = t_0 - y return tmp
function code(x, y, z) t_0 = Float64(x * log(y)) tmp = 0.0 if ((z <= -9.4e+42) || !(z <= 1.55e+38)) tmp = Float64(t_0 - z); else tmp = Float64(t_0 - y); end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * log(y); tmp = 0.0; if ((z <= -9.4e+42) || ~((z <= 1.55e+38))) tmp = t_0 - z; else tmp = t_0 - y; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[Log[y], $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[z, -9.4e+42], N[Not[LessEqual[z, 1.55e+38]], $MachinePrecision]], N[(t$95$0 - z), $MachinePrecision], N[(t$95$0 - y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \log y\\
\mathbf{if}\;z \leq -9.4 \cdot 10^{+42} \lor \neg \left(z \leq 1.55 \cdot 10^{+38}\right):\\
\;\;\;\;t_0 - z\\
\mathbf{else}:\\
\;\;\;\;t_0 - y\\
\end{array}
\end{array}
if z < -9.39999999999999971e42 or 1.55000000000000009e38 < z Initial program 99.9%
Taylor expanded in y around 0 89.0%
if -9.39999999999999971e42 < z < 1.55000000000000009e38Initial program 99.8%
Taylor expanded in z around 0 93.2%
Final simplification91.4%
(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%
Final simplification99.8%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.85e+39) (not (<= z 7.4e+120))) (- z) (- y)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.85e+39) || !(z <= 7.4e+120)) {
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 ((z <= (-1.85d+39)) .or. (.not. (z <= 7.4d+120))) 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 ((z <= -1.85e+39) || !(z <= 7.4e+120)) {
tmp = -z;
} else {
tmp = -y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.85e+39) or not (z <= 7.4e+120): tmp = -z else: tmp = -y return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.85e+39) || !(z <= 7.4e+120)) tmp = Float64(-z); else tmp = Float64(-y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -1.85e+39) || ~((z <= 7.4e+120))) tmp = -z; else tmp = -y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.85e+39], N[Not[LessEqual[z, 7.4e+120]], $MachinePrecision]], (-z), (-y)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.85 \cdot 10^{+39} \lor \neg \left(z \leq 7.4 \cdot 10^{+120}\right):\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;-y\\
\end{array}
\end{array}
if z < -1.85000000000000006e39 or 7.40000000000000048e120 < z Initial program 100.0%
Taylor expanded in z around inf 78.7%
neg-mul-178.7%
Simplified78.7%
if -1.85000000000000006e39 < z < 7.40000000000000048e120Initial program 99.8%
Taylor expanded in y around inf 44.3%
mul-1-neg44.3%
Simplified44.3%
Final simplification57.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.8%
Taylor expanded in x around 0 65.4%
mul-1-neg65.4%
+-commutative65.4%
distribute-neg-in65.4%
sub-neg65.4%
Simplified65.4%
Final simplification65.4%
(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.7%
mul-1-neg31.7%
Simplified31.7%
Final simplification31.7%
herbie shell --seed 2023315
(FPCore (x y z)
:name "Statistics.Distribution.Poisson:$clogProbability from math-functions-0.1.5.2"
:precision binary64
(- (- (* x (log y)) z) y))