
(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 8 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.2%
+-commutative88.2%
fma-def88.2%
sub-neg88.2%
metadata-eval88.2%
sub-neg88.2%
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.2%
Taylor expanded in z around inf 88.1%
*-commutative88.1%
sub-neg88.1%
mul-1-neg88.1%
log1p-def99.8%
mul-1-neg99.8%
Simplified99.8%
Final simplification99.8%
(FPCore (x y z t) :precision binary64 (- (+ (* (log y) (+ -1.0 x)) (* y (- 1.0 z))) t))
double code(double x, double y, double z, double t) {
return ((log(y) * (-1.0 + x)) + (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 = ((log(y) * ((-1.0d0) + x)) + (y * (1.0d0 - z))) - t
end function
public static double code(double x, double y, double z, double t) {
return ((Math.log(y) * (-1.0 + x)) + (y * (1.0 - z))) - t;
}
def code(x, y, z, t): return ((math.log(y) * (-1.0 + x)) + (y * (1.0 - z))) - t
function code(x, y, z, t) return Float64(Float64(Float64(log(y) * Float64(-1.0 + x)) + Float64(y * Float64(1.0 - z))) - t) end
function tmp = code(x, y, z, t) tmp = ((log(y) * (-1.0 + x)) + (y * (1.0 - z))) - t; end
code[x_, y_, z_, t_] := N[(N[(N[(N[Log[y], $MachinePrecision] * N[(-1.0 + x), $MachinePrecision]), $MachinePrecision] + N[(y * N[(1.0 - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - t), $MachinePrecision]
\begin{array}{l}
\\
\left(\log y \cdot \left(-1 + x\right) + y \cdot \left(1 - z\right)\right) - t
\end{array}
Initial program 88.2%
Taylor expanded in y around 0 99.3%
mul-1-neg99.3%
sub-neg99.3%
metadata-eval99.3%
distribute-rgt-neg-in99.3%
mul-1-neg99.3%
+-commutative99.3%
distribute-lft-in99.3%
metadata-eval99.3%
neg-mul-199.3%
unsub-neg99.3%
Simplified99.3%
Final simplification99.3%
(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.2%
Taylor expanded in z around inf 88.1%
*-commutative88.1%
sub-neg88.1%
mul-1-neg88.1%
log1p-def99.8%
mul-1-neg99.8%
Simplified99.8%
Taylor expanded in y around 0 99.2%
+-commutative99.2%
sub-neg99.2%
metadata-eval99.2%
*-commutative99.2%
mul-1-neg99.2%
unsub-neg99.2%
*-commutative99.2%
+-commutative99.2%
Simplified99.2%
Final simplification99.2%
(FPCore (x y z t) :precision binary64 (if (or (<= x -1.25e-18) (not (<= x 6e-17))) (- (* x (log y)) t) (- (/ (log y) -1.0) t)))
double code(double x, double y, double z, double t) {
double tmp;
if ((x <= -1.25e-18) || !(x <= 6e-17)) {
tmp = (x * log(y)) - t;
} else {
tmp = (log(y) / -1.0) - 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 <= (-1.25d-18)) .or. (.not. (x <= 6d-17))) then
tmp = (x * log(y)) - t
else
tmp = (log(y) / (-1.0d0)) - t
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((x <= -1.25e-18) || !(x <= 6e-17)) {
tmp = (x * Math.log(y)) - t;
} else {
tmp = (Math.log(y) / -1.0) - t;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (x <= -1.25e-18) or not (x <= 6e-17): tmp = (x * math.log(y)) - t else: tmp = (math.log(y) / -1.0) - t return tmp
function code(x, y, z, t) tmp = 0.0 if ((x <= -1.25e-18) || !(x <= 6e-17)) tmp = Float64(Float64(x * log(y)) - t); else tmp = Float64(Float64(log(y) / -1.0) - t); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((x <= -1.25e-18) || ~((x <= 6e-17))) tmp = (x * log(y)) - t; else tmp = (log(y) / -1.0) - t; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[x, -1.25e-18], N[Not[LessEqual[x, 6e-17]], $MachinePrecision]], N[(N[(x * N[Log[y], $MachinePrecision]), $MachinePrecision] - t), $MachinePrecision], N[(N[(N[Log[y], $MachinePrecision] / -1.0), $MachinePrecision] - t), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.25 \cdot 10^{-18} \lor \neg \left(x \leq 6 \cdot 10^{-17}\right):\\
\;\;\;\;x \cdot \log y - t\\
\mathbf{else}:\\
\;\;\;\;\frac{\log y}{-1} - t\\
\end{array}
\end{array}
if x < -1.25000000000000009e-18 or 6.00000000000000012e-17 < x Initial program 91.2%
Taylor expanded in z around inf 91.2%
*-commutative91.2%
sub-neg91.2%
mul-1-neg91.2%
log1p-def99.7%
mul-1-neg99.7%
Simplified99.7%
Taylor expanded in x around inf 90.7%
*-commutative90.7%
Simplified90.7%
if -1.25000000000000009e-18 < x < 6.00000000000000012e-17Initial program 85.3%
Taylor expanded in z around inf 85.2%
*-commutative85.2%
sub-neg85.2%
mul-1-neg85.2%
log1p-def99.8%
mul-1-neg99.8%
Simplified99.8%
*-commutative99.8%
sub-neg99.8%
metadata-eval99.8%
flip-+99.8%
associate-*r/99.8%
metadata-eval99.8%
fma-neg99.8%
metadata-eval99.8%
sub-neg99.8%
metadata-eval99.8%
+-commutative99.8%
Applied egg-rr99.8%
associate-/l*99.8%
Simplified99.8%
Taylor expanded in y around 0 83.7%
associate-/l*83.7%
+-commutative83.7%
unpow283.7%
fma-neg83.7%
metadata-eval83.7%
Simplified83.7%
Taylor expanded in x around 0 83.7%
Final simplification87.1%
(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.2%
+-commutative88.2%
fma-def88.2%
sub-neg88.2%
metadata-eval88.2%
sub-neg88.2%
log1p-def99.8%
sub-neg99.8%
metadata-eval99.8%
Simplified99.8%
Taylor expanded in y around 0 87.3%
Final simplification87.3%
(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.2%
Taylor expanded in z around inf 88.1%
*-commutative88.1%
sub-neg88.1%
mul-1-neg88.1%
log1p-def99.8%
mul-1-neg99.8%
Simplified99.8%
Taylor expanded in x around inf 68.2%
*-commutative68.2%
Simplified68.2%
Final simplification68.2%
(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.2%
+-commutative88.2%
fma-def88.2%
sub-neg88.2%
metadata-eval88.2%
sub-neg88.2%
log1p-def99.8%
sub-neg99.8%
metadata-eval99.8%
Simplified99.8%
Taylor expanded in t around inf 37.8%
neg-mul-137.8%
Simplified37.8%
Final simplification37.8%
herbie shell --seed 2023322
(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))