
(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 (- (+ (* (- 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}
Initial program 88.9%
(FPCore (x y z t) :precision binary64 (if (<= t -2.3e+79) (- (log y) t) (if (<= t 8e+68) (* (- x 1.0) (log y)) (- (log (- 1.0 y)) t))))
double code(double x, double y, double z, double t) {
double tmp;
if (t <= -2.3e+79) {
tmp = log(y) - t;
} else if (t <= 8e+68) {
tmp = (x - 1.0) * log(y);
} else {
tmp = log((1.0 - 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 (t <= (-2.3d+79)) then
tmp = log(y) - t
else if (t <= 8d+68) then
tmp = (x - 1.0d0) * log(y)
else
tmp = log((1.0d0 - y)) - t
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (t <= -2.3e+79) {
tmp = Math.log(y) - t;
} else if (t <= 8e+68) {
tmp = (x - 1.0) * Math.log(y);
} else {
tmp = Math.log((1.0 - y)) - t;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if t <= -2.3e+79: tmp = math.log(y) - t elif t <= 8e+68: tmp = (x - 1.0) * math.log(y) else: tmp = math.log((1.0 - y)) - t return tmp
function code(x, y, z, t) tmp = 0.0 if (t <= -2.3e+79) tmp = Float64(log(y) - t); elseif (t <= 8e+68) tmp = Float64(Float64(x - 1.0) * log(y)); else tmp = Float64(log(Float64(1.0 - y)) - t); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (t <= -2.3e+79) tmp = log(y) - t; elseif (t <= 8e+68) tmp = (x - 1.0) * log(y); else tmp = log((1.0 - y)) - t; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[t, -2.3e+79], N[(N[Log[y], $MachinePrecision] - t), $MachinePrecision], If[LessEqual[t, 8e+68], N[(N[(x - 1.0), $MachinePrecision] * N[Log[y], $MachinePrecision]), $MachinePrecision], N[(N[Log[N[(1.0 - y), $MachinePrecision]], $MachinePrecision] - t), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \leq -2.3 \cdot 10^{+79}:\\
\;\;\;\;\log y - t\\
\mathbf{elif}\;t \leq 8 \cdot 10^{+68}:\\
\;\;\;\;\left(x - 1\right) \cdot \log y\\
\mathbf{else}:\\
\;\;\;\;\log \left(1 - y\right) - t\\
\end{array}
\end{array}
if t < -2.3e79Initial program 95.8%
Taylor expanded in x around 0
Applied rewrites72.1%
Taylor expanded in x around inf
Applied rewrites72.5%
if -2.3e79 < t < 7.99999999999999962e68Initial program 82.9%
Taylor expanded in x around 0
Applied rewrites78.1%
Taylor expanded in x around 0
Applied rewrites76.4%
if 7.99999999999999962e68 < t Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites100.0%
Taylor expanded in x around inf
Applied rewrites84.8%
(FPCore (x y z t) :precision binary64 (- (* (- x 1.0) (log y)) t))
double code(double x, double y, double z, double t) {
return ((x - 1.0) * 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 - 1.0d0) * log(y)) - t
end function
public static double code(double x, double y, double z, double t) {
return ((x - 1.0) * Math.log(y)) - t;
}
def code(x, y, z, t): return ((x - 1.0) * math.log(y)) - t
function code(x, y, z, t) return Float64(Float64(Float64(x - 1.0) * log(y)) - t) end
function tmp = code(x, y, z, t) tmp = ((x - 1.0) * log(y)) - t; end
code[x_, y_, z_, t_] := N[(N[(N[(x - 1.0), $MachinePrecision] * N[Log[y], $MachinePrecision]), $MachinePrecision] - t), $MachinePrecision]
\begin{array}{l}
\\
\left(x - 1\right) \cdot \log y - t
\end{array}
Initial program 88.9%
Taylor expanded in x around 0
Applied rewrites87.5%
(FPCore (x y z t) :precision binary64 (- (log (- 1.0 y)) t))
double code(double x, double y, double z, double t) {
return 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 = log((1.0d0 - y)) - t
end function
public static double code(double x, double y, double z, double t) {
return Math.log((1.0 - y)) - t;
}
def code(x, y, z, t): return math.log((1.0 - y)) - t
function code(x, y, z, t) return Float64(log(Float64(1.0 - y)) - t) end
function tmp = code(x, y, z, t) tmp = log((1.0 - y)) - t; end
code[x_, y_, z_, t_] := N[(N[Log[N[(1.0 - y), $MachinePrecision]], $MachinePrecision] - t), $MachinePrecision]
\begin{array}{l}
\\
\log \left(1 - y\right) - t
\end{array}
Initial program 88.9%
Taylor expanded in x around 0
Applied rewrites87.5%
Taylor expanded in x around inf
Applied rewrites35.2%
(FPCore (x y z t) :precision binary64 (- (log y) t))
double code(double x, double y, double z, double t) {
return 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 = log(y) - t
end function
public static double code(double x, double y, double z, double t) {
return Math.log(y) - t;
}
def code(x, y, z, t): return math.log(y) - t
function code(x, y, z, t) return Float64(log(y) - t) end
function tmp = code(x, y, z, t) tmp = log(y) - t; end
code[x_, y_, z_, t_] := N[(N[Log[y], $MachinePrecision] - t), $MachinePrecision]
\begin{array}{l}
\\
\log y - t
\end{array}
Initial program 88.9%
Taylor expanded in x around 0
Applied rewrites34.2%
Taylor expanded in x around inf
Applied rewrites35.0%
(FPCore (x y z t) :precision binary64 (- (- x 1.0) t))
double code(double x, double y, double z, double t) {
return (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 = (x - 1.0d0) - t
end function
public static double code(double x, double y, double z, double t) {
return (x - 1.0) - t;
}
def code(x, y, z, t): return (x - 1.0) - t
function code(x, y, z, t) return Float64(Float64(x - 1.0) - t) end
function tmp = code(x, y, z, t) tmp = (x - 1.0) - t; end
code[x_, y_, z_, t_] := N[(N[(x - 1.0), $MachinePrecision] - t), $MachinePrecision]
\begin{array}{l}
\\
\left(x - 1\right) - t
\end{array}
Initial program 88.9%
Taylor expanded in x around 0
Applied rewrites34.2%
(FPCore (x y z t) :precision binary64 (- 1.0 y))
double code(double x, double y, double z, double t) {
return 1.0 - y;
}
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 = 1.0d0 - y
end function
public static double code(double x, double y, double z, double t) {
return 1.0 - y;
}
def code(x, y, z, t): return 1.0 - y
function code(x, y, z, t) return Float64(1.0 - y) end
function tmp = code(x, y, z, t) tmp = 1.0 - y; end
code[x_, y_, z_, t_] := N[(1.0 - y), $MachinePrecision]
\begin{array}{l}
\\
1 - y
\end{array}
Initial program 88.9%
Taylor expanded in x around 0
Applied rewrites87.5%
Taylor expanded in x around 0
Applied rewrites59.8%
Taylor expanded in y around 0
Applied rewrites5.0%
(FPCore (x y z t) :precision binary64 (- x 1.0))
double code(double x, double y, double z, double t) {
return x - 1.0;
}
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
end function
public static double code(double x, double y, double z, double t) {
return x - 1.0;
}
def code(x, y, z, t): return x - 1.0
function code(x, y, z, t) return Float64(x - 1.0) end
function tmp = code(x, y, z, t) tmp = x - 1.0; end
code[x_, y_, z_, t_] := N[(x - 1.0), $MachinePrecision]
\begin{array}{l}
\\
x - 1
\end{array}
Initial program 88.9%
Taylor expanded in x around 0
Applied rewrites55.9%
Taylor expanded in x around 0
Applied rewrites2.0%
herbie shell --seed 2024321
(FPCore (x y z t)
:name "Statistics.Distribution.Beta:$cdensity from math-functions-0.1.5.2"
:precision binary64
:pre (TRUE)
(- (+ (* (- x 1.0) (log y)) (* (- z 1.0) (log (- 1.0 y)))) t))