
(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 9 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.9%
+-commutative99.9%
fma-define99.9%
Simplified99.9%
Final simplification99.9%
(FPCore (x y z) :precision binary64 (if (or (<= y -5.2e+146) (not (<= y 7.5e+40))) (* y (- (+ 1.0 (log z)) z)) (fma y (- z) (* x 0.5))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -5.2e+146) || !(y <= 7.5e+40)) {
tmp = y * ((1.0 + log(z)) - z);
} else {
tmp = fma(y, -z, (x * 0.5));
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((y <= -5.2e+146) || !(y <= 7.5e+40)) tmp = Float64(y * Float64(Float64(1.0 + log(z)) - z)); else tmp = fma(y, Float64(-z), Float64(x * 0.5)); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[y, -5.2e+146], N[Not[LessEqual[y, 7.5e+40]], $MachinePrecision]], N[(y * N[(N[(1.0 + N[Log[z], $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]), $MachinePrecision], N[(y * (-z) + N[(x * 0.5), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5.2 \cdot 10^{+146} \lor \neg \left(y \leq 7.5 \cdot 10^{+40}\right):\\
\;\;\;\;y \cdot \left(\left(1 + \log z\right) - z\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y, -z, x \cdot 0.5\right)\\
\end{array}
\end{array}
if y < -5.20000000000000028e146 or 7.4999999999999996e40 < y Initial program 99.8%
distribute-lft-in99.7%
Applied egg-rr99.7%
Taylor expanded in x around 0 88.0%
Taylor expanded in y around 0 88.0%
if -5.20000000000000028e146 < y < 7.4999999999999996e40Initial program 99.9%
+-commutative99.9%
fma-define99.9%
Simplified99.9%
Taylor expanded in z around inf 88.2%
mul-1-neg88.2%
Simplified88.2%
Final simplification88.1%
(FPCore (x y z) :precision binary64 (if (<= z 1.3e-6) (+ (* 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 <= 1.3e-6) {
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 <= 1.3e-6) 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, 1.3e-6], 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 1.3 \cdot 10^{-6}:\\
\;\;\;\;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 < 1.30000000000000005e-6Initial program 99.8%
Taylor expanded in z around 0 99.7%
if 1.30000000000000005e-6 < z Initial program 100.0%
+-commutative100.0%
fma-define100.0%
Simplified100.0%
Taylor expanded in z around inf 97.7%
mul-1-neg97.7%
Simplified97.7%
Final simplification98.7%
(FPCore (x y z) :precision binary64 (if (<= y 3.5e+276) (fma y (- z) (* x 0.5)) (+ y (* y (log z)))))
double code(double x, double y, double z) {
double tmp;
if (y <= 3.5e+276) {
tmp = fma(y, -z, (x * 0.5));
} else {
tmp = y + (y * log(z));
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (y <= 3.5e+276) tmp = fma(y, Float64(-z), Float64(x * 0.5)); else tmp = Float64(y + Float64(y * log(z))); end return tmp end
code[x_, y_, z_] := If[LessEqual[y, 3.5e+276], N[(y * (-z) + N[(x * 0.5), $MachinePrecision]), $MachinePrecision], N[(y + N[(y * N[Log[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 3.5 \cdot 10^{+276}:\\
\;\;\;\;\mathsf{fma}\left(y, -z, x \cdot 0.5\right)\\
\mathbf{else}:\\
\;\;\;\;y + y \cdot \log z\\
\end{array}
\end{array}
if y < 3.49999999999999981e276Initial program 99.9%
+-commutative99.9%
fma-define99.9%
Simplified99.9%
Taylor expanded in z around inf 80.3%
mul-1-neg80.3%
Simplified80.3%
if 3.49999999999999981e276 < y Initial program 99.4%
distribute-lft-in99.7%
Applied egg-rr99.7%
Taylor expanded in x around 0 99.7%
Taylor expanded in z around 0 99.7%
Final simplification80.7%
(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.9%
Final simplification99.9%
(FPCore (x y z) :precision binary64 (if (<= y 1.35e+275) (- (* x 0.5) (* y z)) (+ y (* y (log z)))))
double code(double x, double y, double z) {
double tmp;
if (y <= 1.35e+275) {
tmp = (x * 0.5) - (y * z);
} else {
tmp = y + (y * 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 (y <= 1.35d+275) then
tmp = (x * 0.5d0) - (y * z)
else
tmp = y + (y * log(z))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= 1.35e+275) {
tmp = (x * 0.5) - (y * z);
} else {
tmp = y + (y * Math.log(z));
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= 1.35e+275: tmp = (x * 0.5) - (y * z) else: tmp = y + (y * math.log(z)) return tmp
function code(x, y, z) tmp = 0.0 if (y <= 1.35e+275) tmp = Float64(Float64(x * 0.5) - Float64(y * z)); else tmp = Float64(y + Float64(y * log(z))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= 1.35e+275) tmp = (x * 0.5) - (y * z); else tmp = y + (y * log(z)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, 1.35e+275], N[(N[(x * 0.5), $MachinePrecision] - N[(y * z), $MachinePrecision]), $MachinePrecision], N[(y + N[(y * N[Log[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.35 \cdot 10^{+275}:\\
\;\;\;\;x \cdot 0.5 - y \cdot z\\
\mathbf{else}:\\
\;\;\;\;y + y \cdot \log z\\
\end{array}
\end{array}
if y < 1.35000000000000008e275Initial program 99.9%
Taylor expanded in z around inf 80.3%
associate-*r*80.3%
mul-1-neg80.3%
Simplified80.3%
fma-define80.3%
distribute-lft-neg-out80.3%
add-sqr-sqrt37.1%
sqrt-unprod57.9%
sqr-neg57.9%
sqrt-unprod26.8%
add-sqr-sqrt46.4%
fma-neg46.4%
add-sqr-sqrt26.8%
sqrt-unprod57.9%
sqr-neg57.9%
sqrt-unprod37.1%
add-sqr-sqrt80.3%
Applied egg-rr80.3%
if 1.35000000000000008e275 < y Initial program 99.4%
distribute-lft-in99.7%
Applied egg-rr99.7%
Taylor expanded in x around 0 99.7%
Taylor expanded in z around 0 99.7%
Final simplification80.7%
(FPCore (x y z) :precision binary64 (if (or (<= z 350000000.0) (and (not (<= z 2.85e+61)) (<= z 5.6e+128))) (* x 0.5) (* y (- z))))
double code(double x, double y, double z) {
double tmp;
if ((z <= 350000000.0) || (!(z <= 2.85e+61) && (z <= 5.6e+128))) {
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 <= 350000000.0d0) .or. (.not. (z <= 2.85d+61)) .and. (z <= 5.6d+128)) 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 <= 350000000.0) || (!(z <= 2.85e+61) && (z <= 5.6e+128))) {
tmp = x * 0.5;
} else {
tmp = y * -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= 350000000.0) or (not (z <= 2.85e+61) and (z <= 5.6e+128)): tmp = x * 0.5 else: tmp = y * -z return tmp
function code(x, y, z) tmp = 0.0 if ((z <= 350000000.0) || (!(z <= 2.85e+61) && (z <= 5.6e+128))) 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 <= 350000000.0) || (~((z <= 2.85e+61)) && (z <= 5.6e+128))) tmp = x * 0.5; else tmp = y * -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, 350000000.0], And[N[Not[LessEqual[z, 2.85e+61]], $MachinePrecision], LessEqual[z, 5.6e+128]]], N[(x * 0.5), $MachinePrecision], N[(y * (-z)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 350000000 \lor \neg \left(z \leq 2.85 \cdot 10^{+61}\right) \land z \leq 5.6 \cdot 10^{+128}:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(-z\right)\\
\end{array}
\end{array}
if z < 3.5e8 or 2.85000000000000011e61 < z < 5.59999999999999965e128Initial program 99.8%
Taylor expanded in x around inf 60.9%
if 3.5e8 < z < 2.85000000000000011e61 or 5.59999999999999965e128 < z Initial program 99.9%
Taylor expanded in z around inf 98.4%
associate-*r*98.4%
mul-1-neg98.4%
Simplified98.4%
Taylor expanded in z around inf 98.3%
+-commutative98.3%
mul-1-neg98.3%
unsub-neg98.3%
associate-*r/98.3%
Simplified98.3%
Taylor expanded in x around 0 77.6%
neg-mul-177.6%
Simplified77.6%
Final simplification67.0%
(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.9%
Taylor expanded in z around inf 78.8%
associate-*r*78.8%
mul-1-neg78.8%
Simplified78.8%
fma-define78.8%
distribute-lft-neg-out78.8%
add-sqr-sqrt36.5%
sqrt-unprod57.0%
sqr-neg57.0%
sqrt-unprod26.3%
add-sqr-sqrt45.5%
fma-neg45.5%
add-sqr-sqrt26.3%
sqrt-unprod57.0%
sqr-neg57.0%
sqrt-unprod36.5%
add-sqr-sqrt78.8%
Applied egg-rr78.8%
Final simplification78.8%
(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.9%
Taylor expanded in x around inf 46.5%
Final simplification46.5%
(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 2024055
(FPCore (x y z)
:name "System.Random.MWC.Distributions:gamma from mwc-random-0.13.3.2"
:precision binary64
:alt
(- (+ y (* 0.5 x)) (* y (- z (log z))))
(+ (* x 0.5) (* y (+ (- 1.0 z) (log z)))))