
(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 (+ (* x 0.5) (- (* y (+ 1.0 (log z))) (* y z))))
double code(double x, double y, double z) {
return (x * 0.5) + ((y * (1.0 + log(z))) - (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 * (1.0d0 + log(z))) - (y * z))
end function
public static double code(double x, double y, double z) {
return (x * 0.5) + ((y * (1.0 + Math.log(z))) - (y * z));
}
def code(x, y, z): return (x * 0.5) + ((y * (1.0 + math.log(z))) - (y * z))
function code(x, y, z) return Float64(Float64(x * 0.5) + Float64(Float64(y * Float64(1.0 + log(z))) - Float64(y * z))) end
function tmp = code(x, y, z) tmp = (x * 0.5) + ((y * (1.0 + log(z))) - (y * z)); end
code[x_, y_, z_] := N[(N[(x * 0.5), $MachinePrecision] + N[(N[(y * N[(1.0 + N[Log[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot 0.5 + \left(y \cdot \left(1 + \log z\right) - y \cdot z\right)
\end{array}
Initial program 99.8%
Taylor expanded in z around 0 99.9%
Final simplification99.9%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* y (+ 1.0 (log z)))))
(if (<= z 1.95e-289)
t_0
(if (<= z 2.45e-259)
(- (* x 0.5) (* y z))
(if (<= z 0.044) t_0 (fma y (- z) (* x 0.5)))))))
double code(double x, double y, double z) {
double t_0 = y * (1.0 + log(z));
double tmp;
if (z <= 1.95e-289) {
tmp = t_0;
} else if (z <= 2.45e-259) {
tmp = (x * 0.5) - (y * z);
} else if (z <= 0.044) {
tmp = t_0;
} else {
tmp = fma(y, -z, (x * 0.5));
}
return tmp;
}
function code(x, y, z) t_0 = Float64(y * Float64(1.0 + log(z))) tmp = 0.0 if (z <= 1.95e-289) tmp = t_0; elseif (z <= 2.45e-259) tmp = Float64(Float64(x * 0.5) - Float64(y * z)); elseif (z <= 0.044) tmp = t_0; else tmp = fma(y, Float64(-z), Float64(x * 0.5)); end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(y * N[(1.0 + N[Log[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, 1.95e-289], t$95$0, If[LessEqual[z, 2.45e-259], N[(N[(x * 0.5), $MachinePrecision] - N[(y * z), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 0.044], t$95$0, N[(y * (-z) + N[(x * 0.5), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(1 + \log z\right)\\
\mathbf{if}\;z \leq 1.95 \cdot 10^{-289}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 2.45 \cdot 10^{-259}:\\
\;\;\;\;x \cdot 0.5 - y \cdot z\\
\mathbf{elif}\;z \leq 0.044:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y, -z, x \cdot 0.5\right)\\
\end{array}
\end{array}
if z < 1.9499999999999999e-289 or 2.45000000000000011e-259 < z < 0.043999999999999997Initial program 99.7%
Taylor expanded in x around inf 83.3%
associate-/l*83.2%
+-commutative83.2%
associate--l+83.2%
Simplified83.2%
Taylor expanded in x around 0 61.3%
Taylor expanded in z around 0 59.5%
if 1.9499999999999999e-289 < z < 2.45000000000000011e-259Initial program 99.7%
Taylor expanded in z around inf 70.9%
associate-*r*70.9%
mul-1-neg70.9%
Simplified70.9%
distribute-lft-neg-out70.9%
unsub-neg70.9%
Applied egg-rr70.9%
if 0.043999999999999997 < z Initial program 100.0%
+-commutative100.0%
fma-define100.0%
Simplified100.0%
Taylor expanded in z around inf 98.9%
mul-1-neg98.9%
Simplified98.9%
Final simplification79.4%
(FPCore (x y z) :precision binary64 (if (or (<= z 7.5e-289) (and (not (<= z 2.6e-259)) (<= z 0.044))) (* y (+ 1.0 (log z))) (- (* x 0.5) (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((z <= 7.5e-289) || (!(z <= 2.6e-259) && (z <= 0.044))) {
tmp = y * (1.0 + log(z));
} else {
tmp = (x * 0.5) - (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 <= 7.5d-289) .or. (.not. (z <= 2.6d-259)) .and. (z <= 0.044d0)) then
tmp = y * (1.0d0 + log(z))
else
tmp = (x * 0.5d0) - (y * z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= 7.5e-289) || (!(z <= 2.6e-259) && (z <= 0.044))) {
tmp = y * (1.0 + Math.log(z));
} else {
tmp = (x * 0.5) - (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= 7.5e-289) or (not (z <= 2.6e-259) and (z <= 0.044)): tmp = y * (1.0 + math.log(z)) else: tmp = (x * 0.5) - (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= 7.5e-289) || (!(z <= 2.6e-259) && (z <= 0.044))) tmp = Float64(y * Float64(1.0 + log(z))); else tmp = Float64(Float64(x * 0.5) - Float64(y * z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= 7.5e-289) || (~((z <= 2.6e-259)) && (z <= 0.044))) tmp = y * (1.0 + log(z)); else tmp = (x * 0.5) - (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, 7.5e-289], And[N[Not[LessEqual[z, 2.6e-259]], $MachinePrecision], LessEqual[z, 0.044]]], N[(y * N[(1.0 + N[Log[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x * 0.5), $MachinePrecision] - N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 7.5 \cdot 10^{-289} \lor \neg \left(z \leq 2.6 \cdot 10^{-259}\right) \land z \leq 0.044:\\
\;\;\;\;y \cdot \left(1 + \log z\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot 0.5 - y \cdot z\\
\end{array}
\end{array}
if z < 7.49999999999999998e-289 or 2.60000000000000001e-259 < z < 0.043999999999999997Initial program 99.7%
Taylor expanded in x around inf 83.3%
associate-/l*83.2%
+-commutative83.2%
associate--l+83.2%
Simplified83.2%
Taylor expanded in x around 0 61.3%
Taylor expanded in z around 0 59.5%
if 7.49999999999999998e-289 < z < 2.60000000000000001e-259 or 0.043999999999999997 < z Initial program 99.9%
Taylor expanded in z around inf 95.3%
associate-*r*95.3%
mul-1-neg95.3%
Simplified95.3%
distribute-lft-neg-out95.3%
unsub-neg95.3%
Applied egg-rr95.3%
Final simplification79.4%
(FPCore (x y z) :precision binary64 (if (or (<= y -0.45) (not (<= y 1.38e+48))) (* y (- (+ 1.0 (log z)) z)) (fma y (- z) (* x 0.5))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -0.45) || !(y <= 1.38e+48)) {
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 <= -0.45) || !(y <= 1.38e+48)) 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, -0.45], N[Not[LessEqual[y, 1.38e+48]], $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 -0.45 \lor \neg \left(y \leq 1.38 \cdot 10^{+48}\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 < -0.450000000000000011 or 1.3800000000000001e48 < y Initial program 99.8%
Taylor expanded in x around inf 79.5%
associate-/l*79.5%
+-commutative79.5%
associate--l+79.5%
Simplified79.5%
Taylor expanded in x around 0 86.1%
if -0.450000000000000011 < y < 1.3800000000000001e48Initial program 99.9%
+-commutative99.9%
fma-define99.9%
Simplified99.9%
Taylor expanded in z around inf 92.0%
mul-1-neg92.0%
Simplified92.0%
Final simplification88.9%
(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.2%
if 0.28000000000000003 < z Initial program 100.0%
+-commutative100.0%
fma-define100.0%
Simplified100.0%
Taylor expanded in z around inf 98.9%
mul-1-neg98.9%
Simplified98.9%
Final simplification98.5%
(FPCore (x y z) :precision binary64 (+ (* x 0.5) (* y (+ (log z) (- 1.0 z)))))
double code(double x, double y, double z) {
return (x * 0.5) + (y * (log(z) + (1.0 - 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 * (log(z) + (1.0d0 - z)))
end function
public static double code(double x, double y, double z) {
return (x * 0.5) + (y * (Math.log(z) + (1.0 - z)));
}
def code(x, y, z): return (x * 0.5) + (y * (math.log(z) + (1.0 - z)))
function code(x, y, z) return Float64(Float64(x * 0.5) + Float64(y * Float64(log(z) + Float64(1.0 - z)))) end
function tmp = code(x, y, z) tmp = (x * 0.5) + (y * (log(z) + (1.0 - z))); end
code[x_, y_, z_] := N[(N[(x * 0.5), $MachinePrecision] + N[(y * N[(N[Log[z], $MachinePrecision] + N[(1.0 - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot 0.5 + y \cdot \left(\log z + \left(1 - z\right)\right)
\end{array}
Initial program 99.8%
Final simplification99.8%
(FPCore (x y z) :precision binary64 (if (<= z 3e+14) (* x 0.5) (* z (- y))))
double code(double x, double y, double z) {
double tmp;
if (z <= 3e+14) {
tmp = x * 0.5;
} else {
tmp = z * -y;
}
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 <= 3d+14) then
tmp = x * 0.5d0
else
tmp = z * -y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= 3e+14) {
tmp = x * 0.5;
} else {
tmp = z * -y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= 3e+14: tmp = x * 0.5 else: tmp = z * -y return tmp
function code(x, y, z) tmp = 0.0 if (z <= 3e+14) tmp = Float64(x * 0.5); else tmp = Float64(z * Float64(-y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= 3e+14) tmp = x * 0.5; else tmp = z * -y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, 3e+14], N[(x * 0.5), $MachinePrecision], N[(z * (-y)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 3 \cdot 10^{+14}:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(-y\right)\\
\end{array}
\end{array}
if z < 3e14Initial program 99.7%
Taylor expanded in x around inf 44.9%
if 3e14 < z Initial program 100.0%
Taylor expanded in x around inf 90.5%
associate-/l*82.4%
+-commutative82.4%
associate--l+82.4%
Simplified82.4%
Taylor expanded in x around 0 69.3%
Taylor expanded in z around inf 69.2%
neg-mul-169.2%
Simplified69.2%
Final simplification56.3%
(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 71.5%
associate-*r*71.5%
mul-1-neg71.5%
Simplified71.5%
distribute-lft-neg-out71.5%
unsub-neg71.5%
Applied egg-rr71.5%
Final simplification71.5%
(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 38.7%
Final simplification38.7%
(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 2024079
(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)))))