
(FPCore (x y z) :precision binary64 (+ (* x 0.5) (* y (+ (- 1.0 z) (log z)))))
double code(double x, double y, double z) {
return (x * 0.5) + (y * ((1.0 - z) + log(z)));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x * 0.5d0) + (y * ((1.0d0 - z) + log(z)))
end function
public static double code(double x, double y, double z) {
return (x * 0.5) + (y * ((1.0 - z) + Math.log(z)));
}
def code(x, y, z): return (x * 0.5) + (y * ((1.0 - z) + math.log(z)))
function code(x, y, z) return Float64(Float64(x * 0.5) + Float64(y * Float64(Float64(1.0 - z) + log(z)))) end
function tmp = code(x, y, z) tmp = (x * 0.5) + (y * ((1.0 - z) + log(z))); end
code[x_, y_, z_] := N[(N[(x * 0.5), $MachinePrecision] + N[(y * N[(N[(1.0 - z), $MachinePrecision] + N[Log[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot 0.5 + y \cdot \left(\left(1 - z\right) + \log z\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 10 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ (* x 0.5) (* y (+ (- 1.0 z) (log z)))))
double code(double x, double y, double z) {
return (x * 0.5) + (y * ((1.0 - z) + log(z)));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x * 0.5d0) + (y * ((1.0d0 - z) + log(z)))
end function
public static double code(double x, double y, double z) {
return (x * 0.5) + (y * ((1.0 - z) + Math.log(z)));
}
def code(x, y, z): return (x * 0.5) + (y * ((1.0 - z) + math.log(z)))
function code(x, y, z) return Float64(Float64(x * 0.5) + Float64(y * Float64(Float64(1.0 - z) + log(z)))) end
function tmp = code(x, y, z) tmp = (x * 0.5) + (y * ((1.0 - z) + log(z))); end
code[x_, y_, z_] := N[(N[(x * 0.5), $MachinePrecision] + N[(y * N[(N[(1.0 - z), $MachinePrecision] + N[Log[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot 0.5 + y \cdot \left(\left(1 - z\right) + \log z\right)
\end{array}
(FPCore (x y z) :precision binary64 (fma y (+ (- 1.0 z) (log z)) (* x 0.5)))
double code(double x, double y, double z) {
return fma(y, ((1.0 - z) + log(z)), (x * 0.5));
}
function code(x, y, z) return fma(y, Float64(Float64(1.0 - z) + log(z)), Float64(x * 0.5)) end
code[x_, y_, z_] := N[(y * N[(N[(1.0 - z), $MachinePrecision] + N[Log[z], $MachinePrecision]), $MachinePrecision] + N[(x * 0.5), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y, \left(1 - z\right) + \log z, x \cdot 0.5\right)
\end{array}
Initial program 99.8%
+-commutative99.8%
fma-def99.8%
Simplified99.8%
Final simplification99.8%
(FPCore (x y z) :precision binary64 (if (or (<= (* x 0.5) -5e-209) (not (<= (* x 0.5) 1e-276))) (fma y (- z) (* x 0.5)) (* y (+ 1.0 (log z)))))
double code(double x, double y, double z) {
double tmp;
if (((x * 0.5) <= -5e-209) || !((x * 0.5) <= 1e-276)) {
tmp = fma(y, -z, (x * 0.5));
} else {
tmp = y * (1.0 + log(z));
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((Float64(x * 0.5) <= -5e-209) || !(Float64(x * 0.5) <= 1e-276)) tmp = fma(y, Float64(-z), Float64(x * 0.5)); else tmp = Float64(y * Float64(1.0 + log(z))); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[N[(x * 0.5), $MachinePrecision], -5e-209], N[Not[LessEqual[N[(x * 0.5), $MachinePrecision], 1e-276]], $MachinePrecision]], N[(y * (-z) + N[(x * 0.5), $MachinePrecision]), $MachinePrecision], N[(y * N[(1.0 + N[Log[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot 0.5 \leq -5 \cdot 10^{-209} \lor \neg \left(x \cdot 0.5 \leq 10^{-276}\right):\\
\;\;\;\;\mathsf{fma}\left(y, -z, x \cdot 0.5\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(1 + \log z\right)\\
\end{array}
\end{array}
if (*.f64 x 1/2) < -5.0000000000000005e-209 or 1e-276 < (*.f64 x 1/2) Initial program 99.9%
+-commutative99.9%
fma-def99.9%
Simplified99.9%
Taylor expanded in z around inf 79.2%
mul-1-neg79.2%
Simplified79.2%
if -5.0000000000000005e-209 < (*.f64 x 1/2) < 1e-276Initial program 99.5%
sub-neg99.5%
associate-+l+99.5%
distribute-rgt-in99.4%
*-lft-identity99.4%
associate-+r+99.4%
neg-sub099.4%
associate-+l-99.4%
neg-sub099.4%
distribute-lft-neg-out99.4%
unsub-neg99.4%
fma-def99.4%
*-commutative99.4%
Simplified99.4%
Taylor expanded in y around -inf 98.7%
mul-1-neg98.7%
sub-neg98.7%
associate-+l-98.7%
rem-cube-cbrt97.5%
Applied egg-rr97.5%
Taylor expanded in z around 0 72.0%
*-commutative72.0%
Simplified72.0%
Final simplification78.5%
(FPCore (x y z) :precision binary64 (if (or (<= (* x 0.5) -5e-209) (not (<= (* x 0.5) 1e-276))) (- (* x 0.5) (* y z)) (* y (+ 1.0 (log z)))))
double code(double x, double y, double z) {
double tmp;
if (((x * 0.5) <= -5e-209) || !((x * 0.5) <= 1e-276)) {
tmp = (x * 0.5) - (y * z);
} else {
tmp = y * (1.0 + log(z));
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if (((x * 0.5d0) <= (-5d-209)) .or. (.not. ((x * 0.5d0) <= 1d-276))) then
tmp = (x * 0.5d0) - (y * z)
else
tmp = y * (1.0d0 + log(z))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (((x * 0.5) <= -5e-209) || !((x * 0.5) <= 1e-276)) {
tmp = (x * 0.5) - (y * z);
} else {
tmp = y * (1.0 + Math.log(z));
}
return tmp;
}
def code(x, y, z): tmp = 0 if ((x * 0.5) <= -5e-209) or not ((x * 0.5) <= 1e-276): tmp = (x * 0.5) - (y * z) else: tmp = y * (1.0 + math.log(z)) return tmp
function code(x, y, z) tmp = 0.0 if ((Float64(x * 0.5) <= -5e-209) || !(Float64(x * 0.5) <= 1e-276)) tmp = Float64(Float64(x * 0.5) - Float64(y * z)); else tmp = Float64(y * Float64(1.0 + log(z))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (((x * 0.5) <= -5e-209) || ~(((x * 0.5) <= 1e-276))) tmp = (x * 0.5) - (y * z); else tmp = y * (1.0 + log(z)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[N[(x * 0.5), $MachinePrecision], -5e-209], N[Not[LessEqual[N[(x * 0.5), $MachinePrecision], 1e-276]], $MachinePrecision]], N[(N[(x * 0.5), $MachinePrecision] - N[(y * z), $MachinePrecision]), $MachinePrecision], N[(y * N[(1.0 + N[Log[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot 0.5 \leq -5 \cdot 10^{-209} \lor \neg \left(x \cdot 0.5 \leq 10^{-276}\right):\\
\;\;\;\;x \cdot 0.5 - y \cdot z\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(1 + \log z\right)\\
\end{array}
\end{array}
if (*.f64 x 1/2) < -5.0000000000000005e-209 or 1e-276 < (*.f64 x 1/2) Initial program 99.9%
Taylor expanded in z around inf 79.1%
associate-*r*79.1%
neg-mul-179.1%
Simplified79.1%
if -5.0000000000000005e-209 < (*.f64 x 1/2) < 1e-276Initial program 99.5%
sub-neg99.5%
associate-+l+99.5%
distribute-rgt-in99.4%
*-lft-identity99.4%
associate-+r+99.4%
neg-sub099.4%
associate-+l-99.4%
neg-sub099.4%
distribute-lft-neg-out99.4%
unsub-neg99.4%
fma-def99.4%
*-commutative99.4%
Simplified99.4%
Taylor expanded in y around -inf 98.7%
mul-1-neg98.7%
sub-neg98.7%
associate-+l-98.7%
rem-cube-cbrt97.5%
Applied egg-rr97.5%
Taylor expanded in z around 0 72.0%
*-commutative72.0%
Simplified72.0%
Final simplification78.5%
(FPCore (x y z) :precision binary64 (if (or (<= y -7.2e+27) (not (<= y 1.1e+154))) (* y (+ (- 1.0 z) (log z))) (fma y (- z) (* x 0.5))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -7.2e+27) || !(y <= 1.1e+154)) {
tmp = y * ((1.0 - z) + log(z));
} else {
tmp = fma(y, -z, (x * 0.5));
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((y <= -7.2e+27) || !(y <= 1.1e+154)) tmp = Float64(y * Float64(Float64(1.0 - z) + log(z))); else tmp = fma(y, Float64(-z), Float64(x * 0.5)); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[y, -7.2e+27], N[Not[LessEqual[y, 1.1e+154]], $MachinePrecision]], N[(y * N[(N[(1.0 - z), $MachinePrecision] + N[Log[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(y * (-z) + N[(x * 0.5), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -7.2 \cdot 10^{+27} \lor \neg \left(y \leq 1.1 \cdot 10^{+154}\right):\\
\;\;\;\;y \cdot \left(\left(1 - z\right) + \log z\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y, -z, x \cdot 0.5\right)\\
\end{array}
\end{array}
if y < -7.19999999999999966e27 or 1.1000000000000001e154 < y Initial program 99.7%
sub-neg99.7%
associate-+l+99.7%
distribute-rgt-in99.6%
*-lft-identity99.6%
associate-+r+99.5%
neg-sub099.5%
associate-+l-99.5%
neg-sub099.5%
distribute-lft-neg-out99.5%
unsub-neg99.5%
fma-def99.5%
*-commutative99.5%
Simplified99.5%
Taylor expanded in y around -inf 89.1%
Taylor expanded in z around 0 89.1%
neg-mul-189.1%
associate-+r+89.1%
+-commutative89.1%
associate-+l+89.1%
sub-neg89.1%
Simplified89.1%
if -7.19999999999999966e27 < y < 1.1000000000000001e154Initial program 99.9%
+-commutative99.9%
fma-def99.9%
Simplified99.9%
Taylor expanded in z around inf 85.0%
mul-1-neg85.0%
Simplified85.0%
Final simplification86.5%
(FPCore (x y z) :precision binary64 (if (<= z 0.28) (+ (* x 0.5) (* y (+ 1.0 (log z)))) (fma y (- z) (* x 0.5))))
double code(double x, double y, double z) {
double tmp;
if (z <= 0.28) {
tmp = (x * 0.5) + (y * (1.0 + log(z)));
} else {
tmp = fma(y, -z, (x * 0.5));
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (z <= 0.28) tmp = Float64(Float64(x * 0.5) + Float64(y * Float64(1.0 + log(z)))); else tmp = fma(y, Float64(-z), Float64(x * 0.5)); end return tmp end
code[x_, y_, z_] := If[LessEqual[z, 0.28], N[(N[(x * 0.5), $MachinePrecision] + N[(y * N[(1.0 + N[Log[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(y * (-z) + N[(x * 0.5), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 0.28:\\
\;\;\;\;x \cdot 0.5 + y \cdot \left(1 + \log z\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y, -z, x \cdot 0.5\right)\\
\end{array}
\end{array}
if z < 0.28000000000000003Initial program 99.7%
Taylor expanded in z around 0 98.7%
if 0.28000000000000003 < z Initial program 100.0%
+-commutative100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in z around inf 99.3%
mul-1-neg99.3%
Simplified99.3%
Final simplification99.0%
(FPCore (x y z) :precision binary64 (+ (* x 0.5) (* y (+ (- 1.0 z) (log z)))))
double code(double x, double y, double z) {
return (x * 0.5) + (y * ((1.0 - z) + log(z)));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x * 0.5d0) + (y * ((1.0d0 - z) + log(z)))
end function
public static double code(double x, double y, double z) {
return (x * 0.5) + (y * ((1.0 - z) + Math.log(z)));
}
def code(x, y, z): return (x * 0.5) + (y * ((1.0 - z) + math.log(z)))
function code(x, y, z) return Float64(Float64(x * 0.5) + Float64(y * Float64(Float64(1.0 - z) + log(z)))) end
function tmp = code(x, y, z) tmp = (x * 0.5) + (y * ((1.0 - z) + log(z))); end
code[x_, y_, z_] := N[(N[(x * 0.5), $MachinePrecision] + N[(y * N[(N[(1.0 - z), $MachinePrecision] + N[Log[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot 0.5 + y \cdot \left(\left(1 - z\right) + \log z\right)
\end{array}
Initial program 99.8%
Final simplification99.8%
(FPCore (x y z) :precision binary64 (if (or (<= z 6e+21) (and (not (<= z 1.9e+89)) (<= z 3.2e+120))) (* x 0.5) (* y (- z))))
double code(double x, double y, double z) {
double tmp;
if ((z <= 6e+21) || (!(z <= 1.9e+89) && (z <= 3.2e+120))) {
tmp = x * 0.5;
} else {
tmp = y * -z;
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if ((z <= 6d+21) .or. (.not. (z <= 1.9d+89)) .and. (z <= 3.2d+120)) then
tmp = x * 0.5d0
else
tmp = y * -z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= 6e+21) || (!(z <= 1.9e+89) && (z <= 3.2e+120))) {
tmp = x * 0.5;
} else {
tmp = y * -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= 6e+21) or (not (z <= 1.9e+89) and (z <= 3.2e+120)): tmp = x * 0.5 else: tmp = y * -z return tmp
function code(x, y, z) tmp = 0.0 if ((z <= 6e+21) || (!(z <= 1.9e+89) && (z <= 3.2e+120))) tmp = Float64(x * 0.5); else tmp = Float64(y * Float64(-z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= 6e+21) || (~((z <= 1.9e+89)) && (z <= 3.2e+120))) tmp = x * 0.5; else tmp = y * -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, 6e+21], And[N[Not[LessEqual[z, 1.9e+89]], $MachinePrecision], LessEqual[z, 3.2e+120]]], N[(x * 0.5), $MachinePrecision], N[(y * (-z)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 6 \cdot 10^{+21} \lor \neg \left(z \leq 1.9 \cdot 10^{+89}\right) \land z \leq 3.2 \cdot 10^{+120}:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(-z\right)\\
\end{array}
\end{array}
if z < 6e21 or 1.90000000000000012e89 < z < 3.19999999999999982e120Initial program 99.7%
Taylor expanded in x around inf 54.7%
if 6e21 < z < 1.90000000000000012e89 or 3.19999999999999982e120 < z Initial program 100.0%
sub-neg100.0%
associate-+l+100.0%
distribute-rgt-in100.0%
*-lft-identity100.0%
associate-+r+100.0%
neg-sub0100.0%
associate-+l-100.0%
neg-sub0100.0%
distribute-lft-neg-out100.0%
unsub-neg100.0%
fma-def100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in y around -inf 75.9%
Taylor expanded in z around inf 75.9%
neg-mul-175.9%
Simplified75.9%
Final simplification63.2%
(FPCore (x y z) :precision binary64 (- (* x 0.5) (* y z)))
double code(double x, double y, double z) {
return (x * 0.5) - (y * z);
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x * 0.5d0) - (y * z)
end function
public static double code(double x, double y, double z) {
return (x * 0.5) - (y * z);
}
def code(x, y, z): return (x * 0.5) - (y * z)
function code(x, y, z) return Float64(Float64(x * 0.5) - Float64(y * z)) end
function tmp = code(x, y, z) tmp = (x * 0.5) - (y * z); end
code[x_, y_, z_] := N[(N[(x * 0.5), $MachinePrecision] - N[(y * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot 0.5 - y \cdot z
\end{array}
Initial program 99.8%
Taylor expanded in z around inf 74.9%
associate-*r*74.9%
neg-mul-174.9%
Simplified74.9%
Final simplification74.9%
(FPCore (x y z) :precision binary64 (* x 0.5))
double code(double x, double y, double z) {
return x * 0.5;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x * 0.5d0
end function
public static double code(double x, double y, double z) {
return x * 0.5;
}
def code(x, y, z): return x * 0.5
function code(x, y, z) return Float64(x * 0.5) end
function tmp = code(x, y, z) tmp = x * 0.5; end
code[x_, y_, z_] := N[(x * 0.5), $MachinePrecision]
\begin{array}{l}
\\
x \cdot 0.5
\end{array}
Initial program 99.8%
Taylor expanded in x around inf 42.2%
Final simplification42.2%
(FPCore (x y z) :precision binary64 y)
double code(double x, double y, double z) {
return y;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = y
end function
public static double code(double x, double y, double z) {
return y;
}
def code(x, y, z): return y
function code(x, y, z) return y end
function tmp = code(x, y, z) tmp = y; end
code[x_, y_, z_] := y
\begin{array}{l}
\\
y
\end{array}
Initial program 99.8%
sub-neg99.8%
associate-+l+99.8%
distribute-rgt-in99.8%
*-lft-identity99.8%
associate-+r+99.8%
neg-sub099.8%
associate-+l-99.8%
neg-sub099.8%
distribute-lft-neg-out99.8%
unsub-neg99.8%
fma-def99.8%
*-commutative99.8%
Simplified99.8%
Taylor expanded in y around -inf 58.2%
Taylor expanded in z around inf 33.2%
Taylor expanded in z around 0 1.9%
Final simplification1.9%
(FPCore (x y z) :precision binary64 (- (+ y (* 0.5 x)) (* y (- z (log z)))))
double code(double x, double y, double z) {
return (y + (0.5 * x)) - (y * (z - log(z)));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (y + (0.5d0 * x)) - (y * (z - log(z)))
end function
public static double code(double x, double y, double z) {
return (y + (0.5 * x)) - (y * (z - Math.log(z)));
}
def code(x, y, z): return (y + (0.5 * x)) - (y * (z - math.log(z)))
function code(x, y, z) return Float64(Float64(y + Float64(0.5 * x)) - Float64(y * Float64(z - log(z)))) end
function tmp = code(x, y, z) tmp = (y + (0.5 * x)) - (y * (z - log(z))); end
code[x_, y_, z_] := N[(N[(y + N[(0.5 * x), $MachinePrecision]), $MachinePrecision] - N[(y * N[(z - N[Log[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(y + 0.5 \cdot x\right) - y \cdot \left(z - \log z\right)
\end{array}
herbie shell --seed 2023271
(FPCore (x y z)
:name "System.Random.MWC.Distributions:gamma from mwc-random-0.13.3.2"
:precision binary64
:herbie-target
(- (+ y (* 0.5 x)) (* y (- z (log z))))
(+ (* x 0.5) (* y (+ (- 1.0 z) (log z)))))