
(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 10 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 (/ 1.0 (/ 1.0 (fma x (log y) (fma z (log1p (- y)) (- t))))))
double code(double x, double y, double z, double t) {
return 1.0 / (1.0 / fma(x, log(y), fma(z, log1p(-y), -t)));
}
function code(x, y, z, t) return Float64(1.0 / Float64(1.0 / fma(x, log(y), fma(z, log1p(Float64(-y)), Float64(-t))))) end
code[x_, y_, z_, t_] := N[(1.0 / N[(1.0 / N[(x * N[Log[y], $MachinePrecision] + N[(z * N[Log[1 + (-y)], $MachinePrecision] + (-t)), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\frac{1}{\mathsf{fma}\left(x, \log y, \mathsf{fma}\left(z, \mathsf{log1p}\left(-y\right), -t\right)\right)}}
\end{array}
Initial program 85.4%
flip--N/A
clear-numN/A
/-lowering-/.f64N/A
clear-numN/A
flip--N/A
/-lowering-/.f64N/A
associate--l+N/A
accelerator-lowering-fma.f64N/A
Applied egg-rr99.7%
(FPCore (x y z t) :precision binary64 (fma y (- (* (* y z) (fma y -0.3333333333333333 -0.5)) z) (fma x (log y) (- t))))
double code(double x, double y, double z, double t) {
return fma(y, (((y * z) * fma(y, -0.3333333333333333, -0.5)) - z), fma(x, log(y), -t));
}
function code(x, y, z, t) return fma(y, Float64(Float64(Float64(y * z) * fma(y, -0.3333333333333333, -0.5)) - z), fma(x, log(y), Float64(-t))) end
code[x_, y_, z_, t_] := N[(y * N[(N[(N[(y * z), $MachinePrecision] * N[(y * -0.3333333333333333 + -0.5), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision] + N[(x * N[Log[y], $MachinePrecision] + (-t)), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y, \left(y \cdot z\right) \cdot \mathsf{fma}\left(y, -0.3333333333333333, -0.5\right) - z, \mathsf{fma}\left(x, \log y, -t\right)\right)
\end{array}
Initial program 85.4%
Taylor expanded in y around 0
+-commutativeN/A
associate--l+N/A
accelerator-lowering-fma.f64N/A
Simplified99.6%
Final simplification99.6%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (- (* x (log y)) t)))
(if (<= x -2.5e+31)
t_1
(if (<= x 4.5e-7) (fma z (log1p (- y)) (- t)) t_1))))
double code(double x, double y, double z, double t) {
double t_1 = (x * log(y)) - t;
double tmp;
if (x <= -2.5e+31) {
tmp = t_1;
} else if (x <= 4.5e-7) {
tmp = fma(z, log1p(-y), -t);
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z, t) t_1 = Float64(Float64(x * log(y)) - t) tmp = 0.0 if (x <= -2.5e+31) tmp = t_1; elseif (x <= 4.5e-7) tmp = fma(z, log1p(Float64(-y)), Float64(-t)); else tmp = t_1; end return tmp end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[(x * N[Log[y], $MachinePrecision]), $MachinePrecision] - t), $MachinePrecision]}, If[LessEqual[x, -2.5e+31], t$95$1, If[LessEqual[x, 4.5e-7], N[(z * N[Log[1 + (-y)], $MachinePrecision] + (-t)), $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := x \cdot \log y - t\\
\mathbf{if}\;x \leq -2.5 \cdot 10^{+31}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;x \leq 4.5 \cdot 10^{-7}:\\
\;\;\;\;\mathsf{fma}\left(z, \mathsf{log1p}\left(-y\right), -t\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if x < -2.50000000000000013e31 or 4.4999999999999998e-7 < x Initial program 96.4%
Taylor expanded in x around inf
remove-double-negN/A
mul-1-negN/A
mul-1-negN/A
mul-1-negN/A
log-recN/A
*-lowering-*.f64N/A
log-recN/A
mul-1-negN/A
mul-1-negN/A
mul-1-negN/A
remove-double-negN/A
log-lowering-log.f6496.0
Simplified96.0%
if -2.50000000000000013e31 < x < 4.4999999999999998e-7Initial program 74.3%
Taylor expanded in x around 0
sub-negN/A
accelerator-lowering-fma.f64N/A
sub-negN/A
accelerator-lowering-log1p.f64N/A
neg-lowering-neg.f64N/A
neg-lowering-neg.f6489.9
Simplified89.9%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (- (* x (log y)) t)))
(if (<= x -1.6e+27)
t_1
(if (<= x 3.8e-7)
(fma z (* y (fma y (fma y -0.3333333333333333 -0.5) -1.0)) (- t))
t_1))))
double code(double x, double y, double z, double t) {
double t_1 = (x * log(y)) - t;
double tmp;
if (x <= -1.6e+27) {
tmp = t_1;
} else if (x <= 3.8e-7) {
tmp = fma(z, (y * fma(y, fma(y, -0.3333333333333333, -0.5), -1.0)), -t);
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z, t) t_1 = Float64(Float64(x * log(y)) - t) tmp = 0.0 if (x <= -1.6e+27) tmp = t_1; elseif (x <= 3.8e-7) tmp = fma(z, Float64(y * fma(y, fma(y, -0.3333333333333333, -0.5), -1.0)), Float64(-t)); else tmp = t_1; end return tmp end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[(x * N[Log[y], $MachinePrecision]), $MachinePrecision] - t), $MachinePrecision]}, If[LessEqual[x, -1.6e+27], t$95$1, If[LessEqual[x, 3.8e-7], N[(z * N[(y * N[(y * N[(y * -0.3333333333333333 + -0.5), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision] + (-t)), $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := x \cdot \log y - t\\
\mathbf{if}\;x \leq -1.6 \cdot 10^{+27}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;x \leq 3.8 \cdot 10^{-7}:\\
\;\;\;\;\mathsf{fma}\left(z, y \cdot \mathsf{fma}\left(y, \mathsf{fma}\left(y, -0.3333333333333333, -0.5\right), -1\right), -t\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if x < -1.60000000000000008e27 or 3.80000000000000015e-7 < x Initial program 96.4%
Taylor expanded in x around inf
remove-double-negN/A
mul-1-negN/A
mul-1-negN/A
mul-1-negN/A
log-recN/A
*-lowering-*.f64N/A
log-recN/A
mul-1-negN/A
mul-1-negN/A
mul-1-negN/A
remove-double-negN/A
log-lowering-log.f6496.0
Simplified96.0%
if -1.60000000000000008e27 < x < 3.80000000000000015e-7Initial program 74.3%
Taylor expanded in y around 0
+-commutativeN/A
associate--l+N/A
accelerator-lowering-fma.f64N/A
Simplified99.5%
Taylor expanded in x around 0
sub-negN/A
*-commutativeN/A
sub-negN/A
*-commutativeN/A
associate-*r*N/A
mul-1-negN/A
distribute-rgt-inN/A
metadata-evalN/A
sub-negN/A
associate-*l*N/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
Simplified89.4%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (* x (log y))))
(if (<= x -7e+92)
t_1
(if (<= x 4.7e+97)
(fma z (* y (fma y (fma y -0.3333333333333333 -0.5) -1.0)) (- t))
t_1))))
double code(double x, double y, double z, double t) {
double t_1 = x * log(y);
double tmp;
if (x <= -7e+92) {
tmp = t_1;
} else if (x <= 4.7e+97) {
tmp = fma(z, (y * fma(y, fma(y, -0.3333333333333333, -0.5), -1.0)), -t);
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z, t) t_1 = Float64(x * log(y)) tmp = 0.0 if (x <= -7e+92) tmp = t_1; elseif (x <= 4.7e+97) tmp = fma(z, Float64(y * fma(y, fma(y, -0.3333333333333333, -0.5), -1.0)), Float64(-t)); else tmp = t_1; end return tmp end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(x * N[Log[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -7e+92], t$95$1, If[LessEqual[x, 4.7e+97], N[(z * N[(y * N[(y * N[(y * -0.3333333333333333 + -0.5), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision] + (-t)), $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := x \cdot \log y\\
\mathbf{if}\;x \leq -7 \cdot 10^{+92}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;x \leq 4.7 \cdot 10^{+97}:\\
\;\;\;\;\mathsf{fma}\left(z, y \cdot \mathsf{fma}\left(y, \mathsf{fma}\left(y, -0.3333333333333333, -0.5\right), -1\right), -t\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if x < -6.99999999999999972e92 or 4.6999999999999997e97 < x Initial program 98.7%
Taylor expanded in x around inf
remove-double-negN/A
mul-1-negN/A
mul-1-negN/A
mul-1-negN/A
log-recN/A
*-lowering-*.f64N/A
log-recN/A
mul-1-negN/A
mul-1-negN/A
mul-1-negN/A
remove-double-negN/A
log-lowering-log.f6482.9
Simplified82.9%
if -6.99999999999999972e92 < x < 4.6999999999999997e97Initial program 77.3%
Taylor expanded in y around 0
+-commutativeN/A
associate--l+N/A
accelerator-lowering-fma.f64N/A
Simplified99.6%
Taylor expanded in x around 0
sub-negN/A
*-commutativeN/A
sub-negN/A
*-commutativeN/A
associate-*r*N/A
mul-1-negN/A
distribute-rgt-inN/A
metadata-evalN/A
sub-negN/A
associate-*l*N/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
Simplified82.4%
(FPCore (x y z t) :precision binary64 (- (* x (log y)) (fma z y t)))
double code(double x, double y, double z, double t) {
return (x * log(y)) - fma(z, y, t);
}
function code(x, y, z, t) return Float64(Float64(x * log(y)) - fma(z, y, t)) end
code[x_, y_, z_, t_] := N[(N[(x * N[Log[y], $MachinePrecision]), $MachinePrecision] - N[(z * y + t), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \log y - \mathsf{fma}\left(z, y, t\right)
\end{array}
Initial program 85.4%
Taylor expanded in y around 0
+-commutativeN/A
mul-1-negN/A
unsub-negN/A
remove-double-negN/A
mul-1-negN/A
distribute-rgt-neg-inN/A
neg-mul-1N/A
mul-1-negN/A
log-recN/A
associate--l-N/A
--lowering--.f64N/A
Simplified99.1%
(FPCore (x y z t) :precision binary64 (fma z (* y (fma y (fma y -0.3333333333333333 -0.5) -1.0)) (- t)))
double code(double x, double y, double z, double t) {
return fma(z, (y * fma(y, fma(y, -0.3333333333333333, -0.5), -1.0)), -t);
}
function code(x, y, z, t) return fma(z, Float64(y * fma(y, fma(y, -0.3333333333333333, -0.5), -1.0)), Float64(-t)) end
code[x_, y_, z_, t_] := N[(z * N[(y * N[(y * N[(y * -0.3333333333333333 + -0.5), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision] + (-t)), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(z, y \cdot \mathsf{fma}\left(y, \mathsf{fma}\left(y, -0.3333333333333333, -0.5\right), -1\right), -t\right)
\end{array}
Initial program 85.4%
Taylor expanded in y around 0
+-commutativeN/A
associate--l+N/A
accelerator-lowering-fma.f64N/A
Simplified99.6%
Taylor expanded in x around 0
sub-negN/A
*-commutativeN/A
sub-negN/A
*-commutativeN/A
associate-*r*N/A
mul-1-negN/A
distribute-rgt-inN/A
metadata-evalN/A
sub-negN/A
associate-*l*N/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
Simplified58.2%
(FPCore (x y z t) :precision binary64 (if (<= z 1.15e+156) (- t) (- (* y z))))
double code(double x, double y, double z, double t) {
double tmp;
if (z <= 1.15e+156) {
tmp = -t;
} else {
tmp = -(y * z);
}
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 <= 1.15d+156) then
tmp = -t
else
tmp = -(y * z)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (z <= 1.15e+156) {
tmp = -t;
} else {
tmp = -(y * z);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if z <= 1.15e+156: tmp = -t else: tmp = -(y * z) return tmp
function code(x, y, z, t) tmp = 0.0 if (z <= 1.15e+156) tmp = Float64(-t); else tmp = Float64(-Float64(y * z)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (z <= 1.15e+156) tmp = -t; else tmp = -(y * z); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[z, 1.15e+156], (-t), (-N[(y * z), $MachinePrecision])]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 1.15 \cdot 10^{+156}:\\
\;\;\;\;-t\\
\mathbf{else}:\\
\;\;\;\;-y \cdot z\\
\end{array}
\end{array}
if z < 1.1499999999999999e156Initial program 90.4%
Taylor expanded in t around inf
mul-1-negN/A
neg-lowering-neg.f6448.2
Simplified48.2%
if 1.1499999999999999e156 < z Initial program 56.2%
Taylor expanded in y around 0
+-commutativeN/A
mul-1-negN/A
unsub-negN/A
remove-double-negN/A
mul-1-negN/A
distribute-rgt-neg-inN/A
neg-mul-1N/A
mul-1-negN/A
log-recN/A
associate--l-N/A
--lowering--.f64N/A
Simplified97.8%
Taylor expanded in y around inf
mul-1-negN/A
*-commutativeN/A
distribute-rgt-neg-inN/A
mul-1-negN/A
*-lowering-*.f64N/A
mul-1-negN/A
neg-lowering-neg.f6443.7
Simplified43.7%
Final simplification47.5%
(FPCore (x y z t) :precision binary64 (- (fma z y t)))
double code(double x, double y, double z, double t) {
return -fma(z, y, t);
}
function code(x, y, z, t) return Float64(-fma(z, y, t)) end
code[x_, y_, z_, t_] := (-N[(z * y + t), $MachinePrecision])
\begin{array}{l}
\\
-\mathsf{fma}\left(z, y, t\right)
\end{array}
Initial program 85.4%
Taylor expanded in y around 0
+-commutativeN/A
mul-1-negN/A
unsub-negN/A
remove-double-negN/A
mul-1-negN/A
distribute-rgt-neg-inN/A
neg-mul-1N/A
mul-1-negN/A
log-recN/A
associate--l-N/A
--lowering--.f64N/A
Simplified99.1%
Taylor expanded in x around 0
mul-1-negN/A
neg-lowering-neg.f64N/A
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f6457.7
Simplified57.7%
(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.4%
Taylor expanded in t around inf
mul-1-negN/A
neg-lowering-neg.f6442.8
Simplified42.8%
(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 2024204
(FPCore (x y z t)
:name "Numeric.SpecFunctions:invIncompleteBetaWorker from math-functions-0.1.5.2, B"
:precision binary64
:alt
(! :herbie-platform default (- (* (- z) (+ (+ (* 1/2 (* y y)) y) (* (/ 1/3 (* 1 (* 1 1))) (* y (* y y))))) (- t (* x (log y)))))
(- (+ (* x (log y)) (* z (log (- 1.0 y)))) t))