
(FPCore (x y z t) :precision binary64 (- (+ (* (- x 1.0) (log y)) (* (- z 1.0) (log (- 1.0 y)))) t))
double code(double x, double y, double z, double t) {
return (((x - 1.0) * log(y)) + ((z - 1.0) * log((1.0 - y)))) - t;
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = (((x - 1.0d0) * log(y)) + ((z - 1.0d0) * log((1.0d0 - y)))) - t
end function
public static double code(double x, double y, double z, double t) {
return (((x - 1.0) * Math.log(y)) + ((z - 1.0) * Math.log((1.0 - y)))) - t;
}
def code(x, y, z, t): return (((x - 1.0) * math.log(y)) + ((z - 1.0) * math.log((1.0 - y)))) - t
function code(x, y, z, t) return Float64(Float64(Float64(Float64(x - 1.0) * log(y)) + Float64(Float64(z - 1.0) * log(Float64(1.0 - y)))) - t) end
function tmp = code(x, y, z, t) tmp = (((x - 1.0) * log(y)) + ((z - 1.0) * log((1.0 - y)))) - t; end
code[x_, y_, z_, t_] := N[(N[(N[(N[(x - 1.0), $MachinePrecision] * N[Log[y], $MachinePrecision]), $MachinePrecision] + N[(N[(z - 1.0), $MachinePrecision] * N[Log[N[(1.0 - y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - t), $MachinePrecision]
\begin{array}{l}
\\
\left(\left(x - 1\right) \cdot \log y + \left(z - 1\right) \cdot \log \left(1 - y\right)\right) - t
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 9 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z t) :precision binary64 (- (+ (* (- x 1.0) (log y)) (* (- z 1.0) (log (- 1.0 y)))) t))
double code(double x, double y, double z, double t) {
return (((x - 1.0) * log(y)) + ((z - 1.0) * log((1.0 - y)))) - t;
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = (((x - 1.0d0) * log(y)) + ((z - 1.0d0) * log((1.0d0 - y)))) - t
end function
public static double code(double x, double y, double z, double t) {
return (((x - 1.0) * Math.log(y)) + ((z - 1.0) * Math.log((1.0 - y)))) - t;
}
def code(x, y, z, t): return (((x - 1.0) * math.log(y)) + ((z - 1.0) * math.log((1.0 - y)))) - t
function code(x, y, z, t) return Float64(Float64(Float64(Float64(x - 1.0) * log(y)) + Float64(Float64(z - 1.0) * log(Float64(1.0 - y)))) - t) end
function tmp = code(x, y, z, t) tmp = (((x - 1.0) * log(y)) + ((z - 1.0) * log((1.0 - y)))) - t; end
code[x_, y_, z_, t_] := N[(N[(N[(N[(x - 1.0), $MachinePrecision] * N[Log[y], $MachinePrecision]), $MachinePrecision] + N[(N[(z - 1.0), $MachinePrecision] * N[Log[N[(1.0 - y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - t), $MachinePrecision]
\begin{array}{l}
\\
\left(\left(x - 1\right) \cdot \log y + \left(z - 1\right) \cdot \log \left(1 - y\right)\right) - t
\end{array}
(FPCore (x y z t) :precision binary64 (if (<= y 1.1e-47) (- (- (* x (log y)) (log y)) t) (- (fma (+ x -1.0) (log y) (* (log1p (- y)) (+ -1.0 z))) t)))
double code(double x, double y, double z, double t) {
double tmp;
if (y <= 1.1e-47) {
tmp = ((x * log(y)) - log(y)) - t;
} else {
tmp = fma((x + -1.0), log(y), (log1p(-y) * (-1.0 + z))) - t;
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (y <= 1.1e-47) tmp = Float64(Float64(Float64(x * log(y)) - log(y)) - t); else tmp = Float64(fma(Float64(x + -1.0), log(y), Float64(log1p(Float64(-y)) * Float64(-1.0 + z))) - t); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[y, 1.1e-47], N[(N[(N[(x * N[Log[y], $MachinePrecision]), $MachinePrecision] - N[Log[y], $MachinePrecision]), $MachinePrecision] - t), $MachinePrecision], N[(N[(N[(x + -1.0), $MachinePrecision] * N[Log[y], $MachinePrecision] + N[(N[Log[1 + (-y)], $MachinePrecision] * N[(-1.0 + z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - t), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.1 \cdot 10^{-47}:\\
\;\;\;\;\left(x \cdot \log y - \log y\right) - t\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x + -1, \log y, \mathsf{log1p}\left(-y\right) \cdot \left(-1 + z\right)\right) - t\\
\end{array}
\end{array}
if y < 1.10000000000000009e-47Initial program 99.8%
Taylor expanded in x around 0 99.8%
Taylor expanded in x around inf 99.8%
+-commutative99.8%
mul-1-neg99.8%
unsub-neg99.8%
Applied egg-rr99.8%
if 1.10000000000000009e-47 < y Initial program 77.8%
fma-def77.8%
sub-neg77.8%
metadata-eval77.8%
sub-neg77.8%
metadata-eval77.8%
sub-neg77.8%
log1p-def94.8%
Simplified94.8%
Final simplification99.0%
(FPCore (x y z t) :precision binary64 (if (<= y 1.1e-47) (- (- (* x (log y)) (log y)) t) (- (- (* (log y) (+ x -1.0)) (* y (+ -1.0 z))) t)))
double code(double x, double y, double z, double t) {
double tmp;
if (y <= 1.1e-47) {
tmp = ((x * log(y)) - log(y)) - t;
} else {
tmp = ((log(y) * (x + -1.0)) - (y * (-1.0 + z))) - t;
}
return tmp;
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: tmp
if (y <= 1.1d-47) then
tmp = ((x * log(y)) - log(y)) - t
else
tmp = ((log(y) * (x + (-1.0d0))) - (y * ((-1.0d0) + z))) - t
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (y <= 1.1e-47) {
tmp = ((x * Math.log(y)) - Math.log(y)) - t;
} else {
tmp = ((Math.log(y) * (x + -1.0)) - (y * (-1.0 + z))) - t;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if y <= 1.1e-47: tmp = ((x * math.log(y)) - math.log(y)) - t else: tmp = ((math.log(y) * (x + -1.0)) - (y * (-1.0 + z))) - t return tmp
function code(x, y, z, t) tmp = 0.0 if (y <= 1.1e-47) tmp = Float64(Float64(Float64(x * log(y)) - log(y)) - t); else tmp = Float64(Float64(Float64(log(y) * Float64(x + -1.0)) - Float64(y * Float64(-1.0 + z))) - t); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (y <= 1.1e-47) tmp = ((x * log(y)) - log(y)) - t; else tmp = ((log(y) * (x + -1.0)) - (y * (-1.0 + z))) - t; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[y, 1.1e-47], N[(N[(N[(x * N[Log[y], $MachinePrecision]), $MachinePrecision] - N[Log[y], $MachinePrecision]), $MachinePrecision] - t), $MachinePrecision], N[(N[(N[(N[Log[y], $MachinePrecision] * N[(x + -1.0), $MachinePrecision]), $MachinePrecision] - N[(y * N[(-1.0 + z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - t), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.1 \cdot 10^{-47}:\\
\;\;\;\;\left(x \cdot \log y - \log y\right) - t\\
\mathbf{else}:\\
\;\;\;\;\left(\log y \cdot \left(x + -1\right) - y \cdot \left(-1 + z\right)\right) - t\\
\end{array}
\end{array}
if y < 1.10000000000000009e-47Initial program 99.8%
Taylor expanded in x around 0 99.8%
Taylor expanded in x around inf 99.8%
+-commutative99.8%
mul-1-neg99.8%
unsub-neg99.8%
Applied egg-rr99.8%
if 1.10000000000000009e-47 < y Initial program 77.8%
Taylor expanded in y around 0 91.4%
+-commutative91.4%
sub-neg91.4%
metadata-eval91.4%
fma-def91.4%
mul-1-neg91.4%
fma-neg91.4%
+-commutative91.4%
sub-neg91.4%
metadata-eval91.4%
+-commutative91.4%
Simplified91.4%
Final simplification98.5%
(FPCore (x y z t) :precision binary64 (let* ((t_1 (* (log y) (+ x -1.0)))) (if (<= y 5e-48) (- t_1 t) (- (- t_1 (* y (+ -1.0 z))) t))))
double code(double x, double y, double z, double t) {
double t_1 = log(y) * (x + -1.0);
double tmp;
if (y <= 5e-48) {
tmp = t_1 - t;
} else {
tmp = (t_1 - (y * (-1.0 + z))) - t;
}
return tmp;
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: t_1
real(8) :: tmp
t_1 = log(y) * (x + (-1.0d0))
if (y <= 5d-48) then
tmp = t_1 - t
else
tmp = (t_1 - (y * ((-1.0d0) + z))) - t
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double t_1 = Math.log(y) * (x + -1.0);
double tmp;
if (y <= 5e-48) {
tmp = t_1 - t;
} else {
tmp = (t_1 - (y * (-1.0 + z))) - t;
}
return tmp;
}
def code(x, y, z, t): t_1 = math.log(y) * (x + -1.0) tmp = 0 if y <= 5e-48: tmp = t_1 - t else: tmp = (t_1 - (y * (-1.0 + z))) - t return tmp
function code(x, y, z, t) t_1 = Float64(log(y) * Float64(x + -1.0)) tmp = 0.0 if (y <= 5e-48) tmp = Float64(t_1 - t); else tmp = Float64(Float64(t_1 - Float64(y * Float64(-1.0 + z))) - t); end return tmp end
function tmp_2 = code(x, y, z, t) t_1 = log(y) * (x + -1.0); tmp = 0.0; if (y <= 5e-48) tmp = t_1 - t; else tmp = (t_1 - (y * (-1.0 + z))) - t; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[Log[y], $MachinePrecision] * N[(x + -1.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, 5e-48], N[(t$95$1 - t), $MachinePrecision], N[(N[(t$95$1 - N[(y * N[(-1.0 + z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - t), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \log y \cdot \left(x + -1\right)\\
\mathbf{if}\;y \leq 5 \cdot 10^{-48}:\\
\;\;\;\;t\_1 - t\\
\mathbf{else}:\\
\;\;\;\;\left(t\_1 - y \cdot \left(-1 + z\right)\right) - t\\
\end{array}
\end{array}
if y < 4.9999999999999999e-48Initial program 99.8%
Taylor expanded in y around 0 99.8%
if 4.9999999999999999e-48 < y Initial program 77.8%
Taylor expanded in y around 0 91.4%
+-commutative91.4%
sub-neg91.4%
metadata-eval91.4%
fma-def91.4%
mul-1-neg91.4%
fma-neg91.4%
+-commutative91.4%
sub-neg91.4%
metadata-eval91.4%
+-commutative91.4%
Simplified91.4%
Final simplification98.5%
(FPCore (x y z t) :precision binary64 (if (or (<= x -1000.0) (not (<= x 5.8e-8))) (- (* x (log y)) t) (- (- (log y)) t)))
double code(double x, double y, double z, double t) {
double tmp;
if ((x <= -1000.0) || !(x <= 5.8e-8)) {
tmp = (x * log(y)) - t;
} else {
tmp = -log(y) - t;
}
return tmp;
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: tmp
if ((x <= (-1000.0d0)) .or. (.not. (x <= 5.8d-8))) then
tmp = (x * log(y)) - t
else
tmp = -log(y) - t
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((x <= -1000.0) || !(x <= 5.8e-8)) {
tmp = (x * Math.log(y)) - t;
} else {
tmp = -Math.log(y) - t;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (x <= -1000.0) or not (x <= 5.8e-8): tmp = (x * math.log(y)) - t else: tmp = -math.log(y) - t return tmp
function code(x, y, z, t) tmp = 0.0 if ((x <= -1000.0) || !(x <= 5.8e-8)) tmp = Float64(Float64(x * log(y)) - t); else tmp = Float64(Float64(-log(y)) - t); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((x <= -1000.0) || ~((x <= 5.8e-8))) tmp = (x * log(y)) - t; else tmp = -log(y) - t; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[x, -1000.0], N[Not[LessEqual[x, 5.8e-8]], $MachinePrecision]], N[(N[(x * N[Log[y], $MachinePrecision]), $MachinePrecision] - t), $MachinePrecision], N[((-N[Log[y], $MachinePrecision]) - t), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1000 \lor \neg \left(x \leq 5.8 \cdot 10^{-8}\right):\\
\;\;\;\;x \cdot \log y - t\\
\mathbf{else}:\\
\;\;\;\;\left(-\log y\right) - t\\
\end{array}
\end{array}
if x < -1e3 or 5.8000000000000003e-8 < x Initial program 97.1%
Taylor expanded in x around inf 95.6%
*-commutative95.6%
Simplified95.6%
if -1e3 < x < 5.8000000000000003e-8Initial program 95.5%
Taylor expanded in x around 0 95.5%
Taylor expanded in x around inf 94.5%
Taylor expanded in x around 0 94.2%
mul-1-neg94.2%
Simplified94.2%
Final simplification94.9%
(FPCore (x y z t) :precision binary64 (if (<= y 2.75e-45) (- (- (log y)) t) (- (* y (- 1.0 z)) t)))
double code(double x, double y, double z, double t) {
double tmp;
if (y <= 2.75e-45) {
tmp = -log(y) - t;
} else {
tmp = (y * (1.0 - z)) - t;
}
return tmp;
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: tmp
if (y <= 2.75d-45) then
tmp = -log(y) - t
else
tmp = (y * (1.0d0 - z)) - t
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (y <= 2.75e-45) {
tmp = -Math.log(y) - t;
} else {
tmp = (y * (1.0 - z)) - t;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if y <= 2.75e-45: tmp = -math.log(y) - t else: tmp = (y * (1.0 - z)) - t return tmp
function code(x, y, z, t) tmp = 0.0 if (y <= 2.75e-45) tmp = Float64(Float64(-log(y)) - t); else tmp = Float64(Float64(y * Float64(1.0 - z)) - t); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (y <= 2.75e-45) tmp = -log(y) - t; else tmp = (y * (1.0 - z)) - t; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[y, 2.75e-45], N[((-N[Log[y], $MachinePrecision]) - t), $MachinePrecision], N[(N[(y * N[(1.0 - z), $MachinePrecision]), $MachinePrecision] - t), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 2.75 \cdot 10^{-45}:\\
\;\;\;\;\left(-\log y\right) - t\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(1 - z\right) - t\\
\end{array}
\end{array}
if y < 2.75000000000000015e-45Initial program 99.8%
Taylor expanded in x around 0 99.8%
Taylor expanded in x around inf 99.8%
Taylor expanded in x around 0 62.9%
mul-1-neg62.9%
Simplified62.9%
if 2.75000000000000015e-45 < y Initial program 77.2%
Taylor expanded in y around 0 91.1%
+-commutative91.1%
sub-neg91.1%
metadata-eval91.1%
fma-def91.1%
mul-1-neg91.1%
fma-neg91.1%
+-commutative91.1%
sub-neg91.1%
metadata-eval91.1%
+-commutative91.1%
Simplified91.1%
*-commutative91.1%
+-commutative91.1%
flip-+72.4%
associate-*l/72.4%
metadata-eval72.4%
fma-neg72.4%
metadata-eval72.4%
sub-neg72.4%
metadata-eval72.4%
Applied egg-rr72.4%
Taylor expanded in y around inf 58.2%
Final simplification62.1%
(FPCore (x y z t) :precision binary64 (- (* (log y) (+ x -1.0)) t))
double code(double x, double y, double z, double t) {
return (log(y) * (x + -1.0)) - t;
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = (log(y) * (x + (-1.0d0))) - t
end function
public static double code(double x, double y, double z, double t) {
return (Math.log(y) * (x + -1.0)) - t;
}
def code(x, y, z, t): return (math.log(y) * (x + -1.0)) - t
function code(x, y, z, t) return Float64(Float64(log(y) * Float64(x + -1.0)) - t) end
function tmp = code(x, y, z, t) tmp = (log(y) * (x + -1.0)) - t; end
code[x_, y_, z_, t_] := N[(N[(N[Log[y], $MachinePrecision] * N[(x + -1.0), $MachinePrecision]), $MachinePrecision] - t), $MachinePrecision]
\begin{array}{l}
\\
\log y \cdot \left(x + -1\right) - t
\end{array}
Initial program 96.3%
Taylor expanded in y around 0 95.4%
Final simplification95.4%
(FPCore (x y z t) :precision binary64 (- (* y (- 1.0 z)) t))
double code(double x, double y, double z, double t) {
return (y * (1.0 - z)) - t;
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = (y * (1.0d0 - z)) - t
end function
public static double code(double x, double y, double z, double t) {
return (y * (1.0 - z)) - t;
}
def code(x, y, z, t): return (y * (1.0 - z)) - t
function code(x, y, z, t) return Float64(Float64(y * Float64(1.0 - z)) - t) end
function tmp = code(x, y, z, t) tmp = (y * (1.0 - z)) - t; end
code[x_, y_, z_, t_] := N[(N[(y * N[(1.0 - z), $MachinePrecision]), $MachinePrecision] - t), $MachinePrecision]
\begin{array}{l}
\\
y \cdot \left(1 - z\right) - t
\end{array}
Initial program 96.3%
Taylor expanded in y around 0 90.3%
+-commutative90.3%
sub-neg90.3%
metadata-eval90.3%
fma-def90.3%
mul-1-neg90.3%
fma-neg90.3%
+-commutative90.3%
sub-neg90.3%
metadata-eval90.3%
+-commutative90.3%
Simplified90.3%
*-commutative90.3%
+-commutative90.3%
flip-+69.0%
associate-*l/69.0%
metadata-eval69.0%
fma-neg69.0%
metadata-eval69.0%
sub-neg69.0%
metadata-eval69.0%
Applied egg-rr69.0%
Taylor expanded in y around inf 43.7%
Final simplification43.7%
(FPCore (x y z t) :precision binary64 (- (* y (- z)) t))
double code(double x, double y, double z, double t) {
return (y * -z) - t;
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = (y * -z) - t
end function
public static double code(double x, double y, double z, double t) {
return (y * -z) - t;
}
def code(x, y, z, t): return (y * -z) - t
function code(x, y, z, t) return Float64(Float64(y * Float64(-z)) - t) end
function tmp = code(x, y, z, t) tmp = (y * -z) - t; end
code[x_, y_, z_, t_] := N[(N[(y * (-z)), $MachinePrecision] - t), $MachinePrecision]
\begin{array}{l}
\\
y \cdot \left(-z\right) - t
\end{array}
Initial program 96.3%
Taylor expanded in y around 0 90.3%
+-commutative90.3%
sub-neg90.3%
metadata-eval90.3%
fma-def90.3%
mul-1-neg90.3%
fma-neg90.3%
+-commutative90.3%
sub-neg90.3%
metadata-eval90.3%
+-commutative90.3%
Simplified90.3%
Taylor expanded in z around inf 43.6%
associate-*r*43.6%
neg-mul-143.6%
Simplified43.6%
Final simplification43.6%
(FPCore (x y z t) :precision binary64 (- t))
double code(double x, double y, double z, double t) {
return -t;
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = -t
end function
public static double code(double x, double y, double z, double t) {
return -t;
}
def code(x, y, z, t): return -t
function code(x, y, z, t) return Float64(-t) end
function tmp = code(x, y, z, t) tmp = -t; end
code[x_, y_, z_, t_] := (-t)
\begin{array}{l}
\\
-t
\end{array}
Initial program 96.3%
Taylor expanded in t around inf 42.3%
neg-mul-142.3%
Simplified42.3%
Final simplification42.3%
herbie shell --seed 2024031
(FPCore (x y z t)
:name "Statistics.Distribution.Beta:$cdensity from math-functions-0.1.5.2"
:precision binary64
(- (+ (* (- x 1.0) (log y)) (* (- z 1.0) (log (- 1.0 y)))) t))