
(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
(if (or (<= z -3.2e+97)
(not
(or (<= z -2.35e+70) (and (not (<= z -5.7e+23)) (<= z 2.8e+68)))))
(- (- z) y)
(- (* (log y) x) y)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -3.2e+97) || !((z <= -2.35e+70) || (!(z <= -5.7e+23) && (z <= 2.8e+68)))) {
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 <= (-3.2d+97)) .or. (.not. (z <= (-2.35d+70)) .or. (.not. (z <= (-5.7d+23))) .and. (z <= 2.8d+68))) 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 <= -3.2e+97) || !((z <= -2.35e+70) || (!(z <= -5.7e+23) && (z <= 2.8e+68)))) {
tmp = -z - y;
} else {
tmp = (Math.log(y) * x) - y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -3.2e+97) or not ((z <= -2.35e+70) or (not (z <= -5.7e+23) and (z <= 2.8e+68))): tmp = -z - y else: tmp = (math.log(y) * x) - y return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -3.2e+97) || !((z <= -2.35e+70) || (!(z <= -5.7e+23) && (z <= 2.8e+68)))) 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 <= -3.2e+97) || ~(((z <= -2.35e+70) || (~((z <= -5.7e+23)) && (z <= 2.8e+68))))) tmp = -z - y; else tmp = (log(y) * x) - y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -3.2e+97], N[Not[Or[LessEqual[z, -2.35e+70], And[N[Not[LessEqual[z, -5.7e+23]], $MachinePrecision], LessEqual[z, 2.8e+68]]]], $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 -3.2 \cdot 10^{+97} \lor \neg \left(z \leq -2.35 \cdot 10^{+70} \lor \neg \left(z \leq -5.7 \cdot 10^{+23}\right) \land z \leq 2.8 \cdot 10^{+68}\right):\\
\;\;\;\;\left(-z\right) - y\\
\mathbf{else}:\\
\;\;\;\;\log y \cdot x - y\\
\end{array}
\end{array}
if z < -3.20000000000000016e97 or -2.3499999999999999e70 < z < -5.7e23 or 2.8e68 < z Initial program 100.0%
Taylor expanded in x around 0 84.5%
neg-mul-184.5%
Simplified84.5%
if -3.20000000000000016e97 < z < -2.3499999999999999e70 or -5.7e23 < z < 2.8e68Initial program 99.7%
Taylor expanded in z around 0 90.4%
Final simplification88.2%
(FPCore (x y z) :precision binary64 (if (or (<= x -2.3e+119) (not (<= x 3.8e+115))) (* (log y) x) (- (- z) y)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -2.3e+119) || !(x <= 3.8e+115)) {
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 <= (-2.3d+119)) .or. (.not. (x <= 3.8d+115))) 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 <= -2.3e+119) || !(x <= 3.8e+115)) {
tmp = Math.log(y) * x;
} else {
tmp = -z - y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -2.3e+119) or not (x <= 3.8e+115): tmp = math.log(y) * x else: tmp = -z - y return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -2.3e+119) || !(x <= 3.8e+115)) 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 <= -2.3e+119) || ~((x <= 3.8e+115))) tmp = log(y) * x; else tmp = -z - y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -2.3e+119], N[Not[LessEqual[x, 3.8e+115]], $MachinePrecision]], N[(N[Log[y], $MachinePrecision] * x), $MachinePrecision], N[((-z) - y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.3 \cdot 10^{+119} \lor \neg \left(x \leq 3.8 \cdot 10^{+115}\right):\\
\;\;\;\;\log y \cdot x\\
\mathbf{else}:\\
\;\;\;\;\left(-z\right) - y\\
\end{array}
\end{array}
if x < -2.3000000000000001e119 or 3.8000000000000001e115 < 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.9%
if -2.3000000000000001e119 < x < 3.8000000000000001e115Initial program 99.9%
Taylor expanded in x around 0 82.0%
neg-mul-182.0%
Simplified82.0%
Final simplification79.6%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* (log y) x))) (if (<= y 1.2e+20) (- t_0 z) (- t_0 y))))
double code(double x, double y, double z) {
double t_0 = log(y) * x;
double tmp;
if (y <= 1.2e+20) {
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 <= 1.2d+20) 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 <= 1.2e+20) {
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 <= 1.2e+20: 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 <= 1.2e+20) 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 <= 1.2e+20) 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, 1.2e+20], 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 1.2 \cdot 10^{+20}:\\
\;\;\;\;t\_0 - z\\
\mathbf{else}:\\
\;\;\;\;t\_0 - y\\
\end{array}
\end{array}
if y < 1.2e20Initial program 99.7%
Taylor expanded in y around 0 89.2%
if 1.2e20 < y Initial program 99.9%
Taylor expanded in z around 0 83.2%
Final simplification86.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 3800000000000.0) (- z) (- y)))
double code(double x, double y, double z) {
double tmp;
if (y <= 3800000000000.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 <= 3800000000000.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 <= 3800000000000.0) {
tmp = -z;
} else {
tmp = -y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= 3800000000000.0: tmp = -z else: tmp = -y return tmp
function code(x, y, z) tmp = 0.0 if (y <= 3800000000000.0) tmp = Float64(-z); else tmp = Float64(-y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= 3800000000000.0) tmp = -z; else tmp = -y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, 3800000000000.0], (-z), (-y)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 3800000000000:\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;-y\\
\end{array}
\end{array}
if y < 3.8e12Initial 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 43.9%
mul-1-neg43.9%
Simplified43.9%
if 3.8e12 < y Initial program 99.9%
Taylor expanded in y around inf 62.5%
neg-mul-162.5%
Simplified62.5%
Final simplification53.2%
(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 66.2%
neg-mul-166.2%
Simplified66.2%
Final simplification66.2%
(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 37.1%
neg-mul-137.1%
Simplified37.1%
Final simplification37.1%
herbie shell --seed 2024130
(FPCore (x y z)
:name "Statistics.Distribution.Poisson:$clogProbability from math-functions-0.1.5.2"
:precision binary64
(- (- (* x (log y)) z) y))