
(FPCore (x y z t) :precision binary64 (- (+ (* x (log y)) (* z (log (- 1.0 y)))) t))
double code(double x, double y, double z, double t) {
return ((x * log(y)) + (z * 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 * log(y)) + (z * log((1.0d0 - y)))) - t
end function
public static double code(double x, double y, double z, double t) {
return ((x * Math.log(y)) + (z * Math.log((1.0 - y)))) - t;
}
def code(x, y, z, t): return ((x * math.log(y)) + (z * math.log((1.0 - y)))) - t
function code(x, y, z, t) return Float64(Float64(Float64(x * log(y)) + Float64(z * log(Float64(1.0 - y)))) - t) end
function tmp = code(x, y, z, t) tmp = ((x * log(y)) + (z * log((1.0 - y)))) - t; end
code[x_, y_, z_, t_] := N[(N[(N[(x * N[Log[y], $MachinePrecision]), $MachinePrecision] + N[(z * N[Log[N[(1.0 - y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - t), $MachinePrecision]
\begin{array}{l}
\\
\left(x \cdot \log y + z \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 (log y)) (* z (log (- 1.0 y)))) t))
double code(double x, double y, double z, double t) {
return ((x * log(y)) + (z * 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 * log(y)) + (z * log((1.0d0 - y)))) - t
end function
public static double code(double x, double y, double z, double t) {
return ((x * Math.log(y)) + (z * Math.log((1.0 - y)))) - t;
}
def code(x, y, z, t): return ((x * math.log(y)) + (z * math.log((1.0 - y)))) - t
function code(x, y, z, t) return Float64(Float64(Float64(x * log(y)) + Float64(z * log(Float64(1.0 - y)))) - t) end
function tmp = code(x, y, z, t) tmp = ((x * log(y)) + (z * log((1.0 - y)))) - t; end
code[x_, y_, z_, t_] := N[(N[(N[(x * N[Log[y], $MachinePrecision]), $MachinePrecision] + N[(z * N[Log[N[(1.0 - y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - t), $MachinePrecision]
\begin{array}{l}
\\
\left(x \cdot \log y + z \cdot \log \left(1 - y\right)\right) - t
\end{array}
(FPCore (x y z t) :precision binary64 (fma z (log1p (- y)) (fma x (log y) (- t))))
double code(double x, double y, double z, double t) {
return fma(z, log1p(-y), fma(x, log(y), -t));
}
function code(x, y, z, t) return fma(z, log1p(Float64(-y)), fma(x, log(y), Float64(-t))) end
code[x_, y_, z_, t_] := N[(z * N[Log[1 + (-y)], $MachinePrecision] + N[(x * N[Log[y], $MachinePrecision] + (-t)), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(z, \mathsf{log1p}\left(-y\right), \mathsf{fma}\left(x, \log y, -t\right)\right)
\end{array}
Initial program 85.8%
+-commutative85.8%
associate--l+85.8%
fma-def85.8%
sub-neg85.8%
log1p-def99.8%
fma-neg99.8%
Simplified99.8%
Final simplification99.8%
(FPCore (x y z t) :precision binary64 (fma z (log1p (- y)) (- (* x (log y)) t)))
double code(double x, double y, double z, double t) {
return fma(z, log1p(-y), ((x * log(y)) - t));
}
function code(x, y, z, t) return fma(z, log1p(Float64(-y)), Float64(Float64(x * log(y)) - t)) end
code[x_, y_, z_, t_] := N[(z * N[Log[1 + (-y)], $MachinePrecision] + N[(N[(x * N[Log[y], $MachinePrecision]), $MachinePrecision] - t), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(z, \mathsf{log1p}\left(-y\right), x \cdot \log y - t\right)
\end{array}
Initial program 85.8%
+-commutative85.8%
associate--l+85.8%
fma-def85.8%
sub-neg85.8%
log1p-def99.8%
Simplified99.8%
Final simplification99.8%
(FPCore (x y z t) :precision binary64 (if (or (<= z -7e+169) (not (<= z 4.8e+156))) (- (- t) (* z y)) (- (* x (log y)) t)))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -7e+169) || !(z <= 4.8e+156)) {
tmp = -t - (z * y);
} else {
tmp = (x * 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 ((z <= (-7d+169)) .or. (.not. (z <= 4.8d+156))) then
tmp = -t - (z * y)
else
tmp = (x * log(y)) - t
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -7e+169) || !(z <= 4.8e+156)) {
tmp = -t - (z * y);
} else {
tmp = (x * Math.log(y)) - t;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -7e+169) or not (z <= 4.8e+156): tmp = -t - (z * y) else: tmp = (x * math.log(y)) - t return tmp
function code(x, y, z, t) tmp = 0.0 if ((z <= -7e+169) || !(z <= 4.8e+156)) tmp = Float64(Float64(-t) - Float64(z * y)); else tmp = Float64(Float64(x * log(y)) - t); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((z <= -7e+169) || ~((z <= 4.8e+156))) tmp = -t - (z * y); else tmp = (x * log(y)) - t; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -7e+169], N[Not[LessEqual[z, 4.8e+156]], $MachinePrecision]], N[((-t) - N[(z * y), $MachinePrecision]), $MachinePrecision], N[(N[(x * N[Log[y], $MachinePrecision]), $MachinePrecision] - t), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -7 \cdot 10^{+169} \lor \neg \left(z \leq 4.8 \cdot 10^{+156}\right):\\
\;\;\;\;\left(-t\right) - z \cdot y\\
\mathbf{else}:\\
\;\;\;\;x \cdot \log y - t\\
\end{array}
\end{array}
if z < -7.00000000000000038e169 or 4.8000000000000002e156 < z Initial program 47.3%
flip3--47.2%
log-div47.2%
metadata-eval47.2%
pow347.2%
sub-neg47.2%
distribute-rgt-neg-out47.2%
add-sqr-sqrt0.0%
sqrt-unprod47.2%
sqr-neg47.2%
sqrt-unprod47.2%
add-sqr-sqrt47.2%
log1p-udef47.2%
pow347.2%
metadata-eval47.2%
log1p-udef99.9%
*-un-lft-identity99.9%
fma-def99.9%
Applied egg-rr99.9%
Taylor expanded in y around 0 99.9%
Taylor expanded in x around 0 34.9%
log1p-def87.3%
+-commutative87.3%
unpow287.3%
fma-udef87.3%
Simplified87.3%
Taylor expanded in y around 0 86.6%
mul-1-neg86.6%
Simplified86.6%
if -7.00000000000000038e169 < z < 4.8000000000000002e156Initial program 96.3%
Taylor expanded in y around 0 95.8%
Final simplification93.8%
(FPCore (x y z t) :precision binary64 (if (or (<= x -5.2e+56) (not (<= x 4.8e+41))) (* x (log y)) (- (- t) (* z y))))
double code(double x, double y, double z, double t) {
double tmp;
if ((x <= -5.2e+56) || !(x <= 4.8e+41)) {
tmp = x * log(y);
} else {
tmp = -t - (z * y);
}
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 <= (-5.2d+56)) .or. (.not. (x <= 4.8d+41))) then
tmp = x * log(y)
else
tmp = -t - (z * y)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((x <= -5.2e+56) || !(x <= 4.8e+41)) {
tmp = x * Math.log(y);
} else {
tmp = -t - (z * y);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (x <= -5.2e+56) or not (x <= 4.8e+41): tmp = x * math.log(y) else: tmp = -t - (z * y) return tmp
function code(x, y, z, t) tmp = 0.0 if ((x <= -5.2e+56) || !(x <= 4.8e+41)) tmp = Float64(x * log(y)); else tmp = Float64(Float64(-t) - Float64(z * y)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((x <= -5.2e+56) || ~((x <= 4.8e+41))) tmp = x * log(y); else tmp = -t - (z * y); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[x, -5.2e+56], N[Not[LessEqual[x, 4.8e+41]], $MachinePrecision]], N[(x * N[Log[y], $MachinePrecision]), $MachinePrecision], N[((-t) - N[(z * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.2 \cdot 10^{+56} \lor \neg \left(x \leq 4.8 \cdot 10^{+41}\right):\\
\;\;\;\;x \cdot \log y\\
\mathbf{else}:\\
\;\;\;\;\left(-t\right) - z \cdot y\\
\end{array}
\end{array}
if x < -5.20000000000000022e56 or 4.8000000000000003e41 < x Initial program 97.4%
Taylor expanded in y around 0 99.1%
+-commutative99.1%
mul-1-neg99.1%
unsub-neg99.1%
Simplified99.1%
Taylor expanded in x around inf 79.6%
if -5.20000000000000022e56 < x < 4.8000000000000003e41Initial program 78.6%
flip3--78.6%
log-div78.6%
metadata-eval78.6%
pow378.6%
sub-neg78.6%
distribute-rgt-neg-out78.6%
add-sqr-sqrt0.0%
sqrt-unprod78.4%
sqr-neg78.4%
sqrt-unprod78.4%
add-sqr-sqrt78.4%
log1p-udef78.4%
pow378.4%
metadata-eval78.4%
log1p-udef99.7%
*-un-lft-identity99.7%
fma-def99.7%
Applied egg-rr99.7%
Taylor expanded in y around 0 99.7%
Taylor expanded in x around 0 64.6%
log1p-def85.4%
+-commutative85.4%
unpow285.4%
fma-udef85.4%
Simplified85.4%
Taylor expanded in y around 0 85.3%
mul-1-neg85.3%
Simplified85.3%
Final simplification83.1%
(FPCore (x y z t) :precision binary64 (- (- (* x (log y)) (* z y)) t))
double code(double x, double y, double z, double t) {
return ((x * log(y)) - (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 = ((x * log(y)) - (z * y)) - t
end function
public static double code(double x, double y, double z, double t) {
return ((x * Math.log(y)) - (z * y)) - t;
}
def code(x, y, z, t): return ((x * math.log(y)) - (z * y)) - t
function code(x, y, z, t) return Float64(Float64(Float64(x * log(y)) - Float64(z * y)) - t) end
function tmp = code(x, y, z, t) tmp = ((x * log(y)) - (z * y)) - t; end
code[x_, y_, z_, t_] := N[(N[(N[(x * N[Log[y], $MachinePrecision]), $MachinePrecision] - N[(z * y), $MachinePrecision]), $MachinePrecision] - t), $MachinePrecision]
\begin{array}{l}
\\
\left(x \cdot \log y - z \cdot y\right) - t
\end{array}
Initial program 85.8%
Taylor expanded in y around 0 99.4%
+-commutative99.4%
mul-1-neg99.4%
unsub-neg99.4%
Simplified99.4%
Final simplification99.4%
(FPCore (x y z t) :precision binary64 (if (or (<= t -8.2e-153) (not (<= t 3.6e-98))) (- t) (* z (- y))))
double code(double x, double y, double z, double t) {
double tmp;
if ((t <= -8.2e-153) || !(t <= 3.6e-98)) {
tmp = -t;
} else {
tmp = z * -y;
}
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 <= (-8.2d-153)) .or. (.not. (t <= 3.6d-98))) then
tmp = -t
else
tmp = z * -y
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((t <= -8.2e-153) || !(t <= 3.6e-98)) {
tmp = -t;
} else {
tmp = z * -y;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (t <= -8.2e-153) or not (t <= 3.6e-98): tmp = -t else: tmp = z * -y return tmp
function code(x, y, z, t) tmp = 0.0 if ((t <= -8.2e-153) || !(t <= 3.6e-98)) tmp = Float64(-t); else tmp = Float64(z * Float64(-y)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((t <= -8.2e-153) || ~((t <= 3.6e-98))) tmp = -t; else tmp = z * -y; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[t, -8.2e-153], N[Not[LessEqual[t, 3.6e-98]], $MachinePrecision]], (-t), N[(z * (-y)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \leq -8.2 \cdot 10^{-153} \lor \neg \left(t \leq 3.6 \cdot 10^{-98}\right):\\
\;\;\;\;-t\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(-y\right)\\
\end{array}
\end{array}
if t < -8.2e-153 or 3.6000000000000002e-98 < t Initial program 93.6%
Taylor expanded in t around inf 62.3%
mul-1-neg62.3%
Simplified62.3%
if -8.2e-153 < t < 3.6000000000000002e-98Initial program 67.6%
Taylor expanded in z around inf 4.6%
sub-neg4.6%
mul-1-neg4.6%
log1p-def36.0%
mul-1-neg36.0%
Simplified36.0%
Taylor expanded in y around 0 35.3%
associate-*r*35.3%
mul-1-neg35.3%
Simplified35.3%
Final simplification54.2%
(FPCore (x y z t) :precision binary64 (- (- t) (* z y)))
double code(double x, double y, double z, double t) {
return -t - (z * 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 = -t - (z * y)
end function
public static double code(double x, double y, double z, double t) {
return -t - (z * y);
}
def code(x, y, z, t): return -t - (z * y)
function code(x, y, z, t) return Float64(Float64(-t) - Float64(z * y)) end
function tmp = code(x, y, z, t) tmp = -t - (z * y); end
code[x_, y_, z_, t_] := N[((-t) - N[(z * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(-t\right) - z \cdot y
\end{array}
Initial program 85.8%
flip3--85.7%
log-div85.7%
metadata-eval85.7%
pow385.7%
sub-neg85.7%
distribute-rgt-neg-out85.7%
add-sqr-sqrt0.0%
sqrt-unprod85.7%
sqr-neg85.7%
sqrt-unprod85.7%
add-sqr-sqrt85.7%
log1p-udef85.6%
pow385.6%
metadata-eval85.6%
log1p-udef99.6%
*-un-lft-identity99.6%
fma-def99.6%
Applied egg-rr99.6%
Taylor expanded in y around 0 99.6%
Taylor expanded in x around 0 46.8%
log1p-def60.6%
+-commutative60.6%
unpow260.6%
fma-udef60.6%
Simplified60.6%
Taylor expanded in y around 0 60.4%
mul-1-neg60.4%
Simplified60.4%
Final simplification60.4%
(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 85.8%
Taylor expanded in t around inf 46.3%
mul-1-neg46.3%
Simplified46.3%
Final simplification46.3%
(FPCore (x y z t)
:precision binary64
(-
(*
(- z)
(+
(+ (* 0.5 (* y y)) y)
(* (/ 0.3333333333333333 (* 1.0 (* 1.0 1.0))) (* y (* y y)))))
(- t (* x (log y)))))
double code(double x, double y, double z, double t) {
return (-z * (((0.5 * (y * y)) + y) + ((0.3333333333333333 / (1.0 * (1.0 * 1.0))) * (y * (y * y))))) - (t - (x * log(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 = (-z * (((0.5d0 * (y * y)) + y) + ((0.3333333333333333d0 / (1.0d0 * (1.0d0 * 1.0d0))) * (y * (y * y))))) - (t - (x * log(y)))
end function
public static double code(double x, double y, double z, double t) {
return (-z * (((0.5 * (y * y)) + y) + ((0.3333333333333333 / (1.0 * (1.0 * 1.0))) * (y * (y * y))))) - (t - (x * Math.log(y)));
}
def code(x, y, z, t): return (-z * (((0.5 * (y * y)) + y) + ((0.3333333333333333 / (1.0 * (1.0 * 1.0))) * (y * (y * y))))) - (t - (x * math.log(y)))
function code(x, y, z, t) return Float64(Float64(Float64(-z) * Float64(Float64(Float64(0.5 * Float64(y * y)) + y) + Float64(Float64(0.3333333333333333 / Float64(1.0 * Float64(1.0 * 1.0))) * Float64(y * Float64(y * y))))) - Float64(t - Float64(x * log(y)))) end
function tmp = code(x, y, z, t) tmp = (-z * (((0.5 * (y * y)) + y) + ((0.3333333333333333 / (1.0 * (1.0 * 1.0))) * (y * (y * y))))) - (t - (x * log(y))); end
code[x_, y_, z_, t_] := N[(N[((-z) * N[(N[(N[(0.5 * N[(y * y), $MachinePrecision]), $MachinePrecision] + y), $MachinePrecision] + N[(N[(0.3333333333333333 / N[(1.0 * N[(1.0 * 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(y * N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(t - N[(x * N[Log[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(-z\right) \cdot \left(\left(0.5 \cdot \left(y \cdot y\right) + y\right) + \frac{0.3333333333333333}{1 \cdot \left(1 \cdot 1\right)} \cdot \left(y \cdot \left(y \cdot y\right)\right)\right) - \left(t - x \cdot \log y\right)
\end{array}
herbie shell --seed 2024020
(FPCore (x y z t)
:name "Numeric.SpecFunctions:invIncompleteBetaWorker from math-functions-0.1.5.2, B"
:precision binary64
:herbie-target
(- (* (- z) (+ (+ (* 0.5 (* y y)) y) (* (/ 0.3333333333333333 (* 1.0 (* 1.0 1.0))) (* y (* y y))))) (- t (* x (log y))))
(- (+ (* x (log y)) (* z (log (- 1.0 y)))) t))