
(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 (- (fma (+ z -1.0) (log1p (- y)) (* (log y) (+ -1.0 x))) t))
double code(double x, double y, double z, double t) {
return fma((z + -1.0), log1p(-y), (log(y) * (-1.0 + x))) - t;
}
function code(x, y, z, t) return Float64(fma(Float64(z + -1.0), log1p(Float64(-y)), Float64(log(y) * Float64(-1.0 + x))) - t) end
code[x_, y_, z_, t_] := N[(N[(N[(z + -1.0), $MachinePrecision] * N[Log[1 + (-y)], $MachinePrecision] + N[(N[Log[y], $MachinePrecision] * N[(-1.0 + x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - t), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(z + -1, \mathsf{log1p}\left(-y\right), \log y \cdot \left(-1 + x\right)\right) - t
\end{array}
Initial program 88.8%
+-commutative88.8%
fma-def88.8%
sub-neg88.8%
metadata-eval88.8%
sub-neg88.8%
log1p-def99.8%
sub-neg99.8%
metadata-eval99.8%
Simplified99.8%
Final simplification99.8%
(FPCore (x y z t) :precision binary64 (- (+ (* (log y) (+ -1.0 x)) (* z (log1p (- y)))) t))
double code(double x, double y, double z, double t) {
return ((log(y) * (-1.0 + x)) + (z * log1p(-y))) - t;
}
public static double code(double x, double y, double z, double t) {
return ((Math.log(y) * (-1.0 + x)) + (z * Math.log1p(-y))) - t;
}
def code(x, y, z, t): return ((math.log(y) * (-1.0 + x)) + (z * math.log1p(-y))) - t
function code(x, y, z, t) return Float64(Float64(Float64(log(y) * Float64(-1.0 + x)) + Float64(z * log1p(Float64(-y)))) - t) end
code[x_, y_, z_, t_] := N[(N[(N[(N[Log[y], $MachinePrecision] * N[(-1.0 + x), $MachinePrecision]), $MachinePrecision] + N[(z * N[Log[1 + (-y)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - t), $MachinePrecision]
\begin{array}{l}
\\
\left(\log y \cdot \left(-1 + x\right) + z \cdot \mathsf{log1p}\left(-y\right)\right) - t
\end{array}
Initial program 88.8%
Taylor expanded in z around inf 88.3%
*-commutative88.3%
sub-neg88.3%
mul-1-neg88.3%
log1p-def99.3%
mul-1-neg99.3%
Simplified99.3%
Final simplification99.3%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (* (log y) (+ -1.0 x))))
(if (<= x -4.5e-7)
(- t_1 t)
(if (<= x 2e-39) (- (- (* z (- y)) (log y)) t) (- (+ y t_1) t)))))
double code(double x, double y, double z, double t) {
double t_1 = log(y) * (-1.0 + x);
double tmp;
if (x <= -4.5e-7) {
tmp = t_1 - t;
} else if (x <= 2e-39) {
tmp = ((z * -y) - log(y)) - t;
} else {
tmp = (y + t_1) - 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) * ((-1.0d0) + x)
if (x <= (-4.5d-7)) then
tmp = t_1 - t
else if (x <= 2d-39) then
tmp = ((z * -y) - log(y)) - t
else
tmp = (y + t_1) - 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) * (-1.0 + x);
double tmp;
if (x <= -4.5e-7) {
tmp = t_1 - t;
} else if (x <= 2e-39) {
tmp = ((z * -y) - Math.log(y)) - t;
} else {
tmp = (y + t_1) - t;
}
return tmp;
}
def code(x, y, z, t): t_1 = math.log(y) * (-1.0 + x) tmp = 0 if x <= -4.5e-7: tmp = t_1 - t elif x <= 2e-39: tmp = ((z * -y) - math.log(y)) - t else: tmp = (y + t_1) - t return tmp
function code(x, y, z, t) t_1 = Float64(log(y) * Float64(-1.0 + x)) tmp = 0.0 if (x <= -4.5e-7) tmp = Float64(t_1 - t); elseif (x <= 2e-39) tmp = Float64(Float64(Float64(z * Float64(-y)) - log(y)) - t); else tmp = Float64(Float64(y + t_1) - t); end return tmp end
function tmp_2 = code(x, y, z, t) t_1 = log(y) * (-1.0 + x); tmp = 0.0; if (x <= -4.5e-7) tmp = t_1 - t; elseif (x <= 2e-39) tmp = ((z * -y) - log(y)) - t; else tmp = (y + t_1) - t; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[Log[y], $MachinePrecision] * N[(-1.0 + x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -4.5e-7], N[(t$95$1 - t), $MachinePrecision], If[LessEqual[x, 2e-39], N[(N[(N[(z * (-y)), $MachinePrecision] - N[Log[y], $MachinePrecision]), $MachinePrecision] - t), $MachinePrecision], N[(N[(y + t$95$1), $MachinePrecision] - t), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \log y \cdot \left(-1 + x\right)\\
\mathbf{if}\;x \leq -4.5 \cdot 10^{-7}:\\
\;\;\;\;t\_1 - t\\
\mathbf{elif}\;x \leq 2 \cdot 10^{-39}:\\
\;\;\;\;\left(z \cdot \left(-y\right) - \log y\right) - t\\
\mathbf{else}:\\
\;\;\;\;\left(y + t\_1\right) - t\\
\end{array}
\end{array}
if x < -4.4999999999999998e-7Initial program 93.2%
+-commutative93.2%
fma-def93.2%
sub-neg93.2%
metadata-eval93.2%
sub-neg93.2%
log1p-def99.6%
sub-neg99.6%
metadata-eval99.6%
Simplified99.6%
Taylor expanded in y around 0 93.2%
if -4.4999999999999998e-7 < x < 1.99999999999999986e-39Initial program 82.1%
Taylor expanded in z around inf 81.5%
*-commutative81.5%
sub-neg81.5%
mul-1-neg81.5%
log1p-def99.3%
mul-1-neg99.3%
Simplified99.3%
Taylor expanded in y around 0 98.9%
+-commutative98.9%
sub-neg98.9%
metadata-eval98.9%
*-commutative98.9%
mul-1-neg98.9%
unsub-neg98.9%
*-commutative98.9%
+-commutative98.9%
Simplified98.9%
Taylor expanded in x around 0 98.9%
neg-mul-198.9%
Simplified98.9%
if 1.99999999999999986e-39 < x Initial program 95.5%
Taylor expanded in y around 0 98.3%
mul-1-neg98.3%
Simplified98.3%
Taylor expanded in z around 0 93.7%
Final simplification96.0%
(FPCore (x y z t) :precision binary64 (if (or (<= x -3e-8) (not (<= x 7.1e-28))) (- (* (log y) (+ -1.0 x)) t) (- (- (* z (- y)) (log y)) t)))
double code(double x, double y, double z, double t) {
double tmp;
if ((x <= -3e-8) || !(x <= 7.1e-28)) {
tmp = (log(y) * (-1.0 + x)) - t;
} else {
tmp = ((z * -y) - 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 <= (-3d-8)) .or. (.not. (x <= 7.1d-28))) then
tmp = (log(y) * ((-1.0d0) + x)) - t
else
tmp = ((z * -y) - 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 <= -3e-8) || !(x <= 7.1e-28)) {
tmp = (Math.log(y) * (-1.0 + x)) - t;
} else {
tmp = ((z * -y) - Math.log(y)) - t;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (x <= -3e-8) or not (x <= 7.1e-28): tmp = (math.log(y) * (-1.0 + x)) - t else: tmp = ((z * -y) - math.log(y)) - t return tmp
function code(x, y, z, t) tmp = 0.0 if ((x <= -3e-8) || !(x <= 7.1e-28)) tmp = Float64(Float64(log(y) * Float64(-1.0 + x)) - t); else tmp = Float64(Float64(Float64(z * Float64(-y)) - log(y)) - t); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((x <= -3e-8) || ~((x <= 7.1e-28))) tmp = (log(y) * (-1.0 + x)) - t; else tmp = ((z * -y) - log(y)) - t; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[x, -3e-8], N[Not[LessEqual[x, 7.1e-28]], $MachinePrecision]], N[(N[(N[Log[y], $MachinePrecision] * N[(-1.0 + x), $MachinePrecision]), $MachinePrecision] - t), $MachinePrecision], N[(N[(N[(z * (-y)), $MachinePrecision] - N[Log[y], $MachinePrecision]), $MachinePrecision] - t), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3 \cdot 10^{-8} \lor \neg \left(x \leq 7.1 \cdot 10^{-28}\right):\\
\;\;\;\;\log y \cdot \left(-1 + x\right) - t\\
\mathbf{else}:\\
\;\;\;\;\left(z \cdot \left(-y\right) - \log y\right) - t\\
\end{array}
\end{array}
if x < -2.99999999999999973e-8 or 7.09999999999999981e-28 < x Initial program 94.4%
+-commutative94.4%
fma-def94.4%
sub-neg94.4%
metadata-eval94.4%
sub-neg94.4%
log1p-def99.6%
sub-neg99.6%
metadata-eval99.6%
Simplified99.6%
Taylor expanded in y around 0 93.4%
if -2.99999999999999973e-8 < x < 7.09999999999999981e-28Initial program 82.4%
Taylor expanded in z around inf 81.5%
*-commutative81.5%
sub-neg81.5%
mul-1-neg81.5%
log1p-def99.0%
mul-1-neg99.0%
Simplified99.0%
Taylor expanded in y around 0 98.6%
+-commutative98.6%
sub-neg98.6%
metadata-eval98.6%
*-commutative98.6%
mul-1-neg98.6%
unsub-neg98.6%
*-commutative98.6%
+-commutative98.6%
Simplified98.6%
Taylor expanded in x around 0 98.6%
neg-mul-198.6%
Simplified98.6%
Final simplification95.8%
(FPCore (x y z t) :precision binary64 (- (- (* (log y) (+ -1.0 x)) (* y (+ z -1.0))) t))
double code(double x, double y, double z, double t) {
return ((log(y) * (-1.0 + x)) - (y * (z + -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) * ((-1.0d0) + x)) - (y * (z + (-1.0d0)))) - t
end function
public static double code(double x, double y, double z, double t) {
return ((Math.log(y) * (-1.0 + x)) - (y * (z + -1.0))) - t;
}
def code(x, y, z, t): return ((math.log(y) * (-1.0 + x)) - (y * (z + -1.0))) - t
function code(x, y, z, t) return Float64(Float64(Float64(log(y) * Float64(-1.0 + x)) - Float64(y * Float64(z + -1.0))) - t) end
function tmp = code(x, y, z, t) tmp = ((log(y) * (-1.0 + x)) - (y * (z + -1.0))) - t; end
code[x_, y_, z_, t_] := N[(N[(N[(N[Log[y], $MachinePrecision] * N[(-1.0 + x), $MachinePrecision]), $MachinePrecision] - N[(y * N[(z + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - t), $MachinePrecision]
\begin{array}{l}
\\
\left(\log y \cdot \left(-1 + x\right) - y \cdot \left(z + -1\right)\right) - t
\end{array}
Initial program 88.8%
Taylor expanded in y around 0 98.9%
mul-1-neg98.9%
Simplified98.9%
Final simplification98.9%
(FPCore (x y z t) :precision binary64 (- (- (* (log y) (+ -1.0 x)) (* z y)) t))
double code(double x, double y, double z, double t) {
return ((log(y) * (-1.0 + x)) - (z * 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 = ((log(y) * ((-1.0d0) + x)) - (z * y)) - t
end function
public static double code(double x, double y, double z, double t) {
return ((Math.log(y) * (-1.0 + x)) - (z * y)) - t;
}
def code(x, y, z, t): return ((math.log(y) * (-1.0 + x)) - (z * y)) - t
function code(x, y, z, t) return Float64(Float64(Float64(log(y) * Float64(-1.0 + x)) - Float64(z * y)) - t) end
function tmp = code(x, y, z, t) tmp = ((log(y) * (-1.0 + x)) - (z * y)) - t; end
code[x_, y_, z_, t_] := N[(N[(N[(N[Log[y], $MachinePrecision] * N[(-1.0 + x), $MachinePrecision]), $MachinePrecision] - N[(z * y), $MachinePrecision]), $MachinePrecision] - t), $MachinePrecision]
\begin{array}{l}
\\
\left(\log y \cdot \left(-1 + x\right) - z \cdot y\right) - t
\end{array}
Initial program 88.8%
Taylor expanded in z around inf 88.3%
*-commutative88.3%
sub-neg88.3%
mul-1-neg88.3%
log1p-def99.3%
mul-1-neg99.3%
Simplified99.3%
Taylor expanded in y around 0 98.7%
+-commutative98.7%
sub-neg98.7%
metadata-eval98.7%
*-commutative98.7%
mul-1-neg98.7%
unsub-neg98.7%
*-commutative98.7%
+-commutative98.7%
Simplified98.7%
Final simplification98.7%
(FPCore (x y z t) :precision binary64 (- (* (log y) (+ -1.0 x)) t))
double code(double x, double y, double z, double t) {
return (log(y) * (-1.0 + x)) - 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) * ((-1.0d0) + x)) - t
end function
public static double code(double x, double y, double z, double t) {
return (Math.log(y) * (-1.0 + x)) - t;
}
def code(x, y, z, t): return (math.log(y) * (-1.0 + x)) - t
function code(x, y, z, t) return Float64(Float64(log(y) * Float64(-1.0 + x)) - t) end
function tmp = code(x, y, z, t) tmp = (log(y) * (-1.0 + x)) - t; end
code[x_, y_, z_, t_] := N[(N[(N[Log[y], $MachinePrecision] * N[(-1.0 + x), $MachinePrecision]), $MachinePrecision] - t), $MachinePrecision]
\begin{array}{l}
\\
\log y \cdot \left(-1 + x\right) - t
\end{array}
Initial program 88.8%
+-commutative88.8%
fma-def88.8%
sub-neg88.8%
metadata-eval88.8%
sub-neg88.8%
log1p-def99.8%
sub-neg99.8%
metadata-eval99.8%
Simplified99.8%
Taylor expanded in y around 0 87.4%
Final simplification87.4%
(FPCore (x y z t) :precision binary64 (- (* x (log y)) t))
double code(double x, double y, double z, double t) {
return (x * log(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 * log(y)) - t
end function
public static double code(double x, double y, double z, double t) {
return (x * Math.log(y)) - t;
}
def code(x, y, z, t): return (x * math.log(y)) - t
function code(x, y, z, t) return Float64(Float64(x * log(y)) - t) end
function tmp = code(x, y, z, t) tmp = (x * log(y)) - t; end
code[x_, y_, z_, t_] := N[(N[(x * N[Log[y], $MachinePrecision]), $MachinePrecision] - t), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \log y - t
\end{array}
Initial program 88.8%
Taylor expanded in z around inf 88.3%
*-commutative88.3%
sub-neg88.3%
mul-1-neg88.3%
log1p-def99.3%
mul-1-neg99.3%
Simplified99.3%
Taylor expanded in x around inf 69.9%
*-commutative69.9%
Simplified69.9%
Final simplification69.9%
(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 88.8%
+-commutative88.8%
fma-def88.8%
sub-neg88.8%
metadata-eval88.8%
sub-neg88.8%
log1p-def99.8%
sub-neg99.8%
metadata-eval99.8%
Simplified99.8%
Taylor expanded in t around inf 37.4%
neg-mul-137.4%
Simplified37.4%
Final simplification37.4%
herbie shell --seed 2024036
(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))