
(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 6 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 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%
(FPCore (x y z)
:precision binary64
(if (<= z 1.45e-263)
(+ y (* y (log z)))
(if (<= z 2.2e-242)
(* x 0.5)
(if (<= z 1.6e-56) (* y (+ 1.0 (log z))) (- (* x 0.5) (* y z))))))
double code(double x, double y, double z) {
double tmp;
if (z <= 1.45e-263) {
tmp = y + (y * log(z));
} else if (z <= 2.2e-242) {
tmp = x * 0.5;
} else if (z <= 1.6e-56) {
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 <= 1.45d-263) then
tmp = y + (y * log(z))
else if (z <= 2.2d-242) then
tmp = x * 0.5d0
else if (z <= 1.6d-56) 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 <= 1.45e-263) {
tmp = y + (y * Math.log(z));
} else if (z <= 2.2e-242) {
tmp = x * 0.5;
} else if (z <= 1.6e-56) {
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 <= 1.45e-263: tmp = y + (y * math.log(z)) elif z <= 2.2e-242: tmp = x * 0.5 elif z <= 1.6e-56: 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 <= 1.45e-263) tmp = Float64(y + Float64(y * log(z))); elseif (z <= 2.2e-242) tmp = Float64(x * 0.5); elseif (z <= 1.6e-56) 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 <= 1.45e-263) tmp = y + (y * log(z)); elseif (z <= 2.2e-242) tmp = x * 0.5; elseif (z <= 1.6e-56) tmp = y * (1.0 + log(z)); else tmp = (x * 0.5) - (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, 1.45e-263], N[(y + N[(y * N[Log[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 2.2e-242], N[(x * 0.5), $MachinePrecision], If[LessEqual[z, 1.6e-56], 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 1.45 \cdot 10^{-263}:\\
\;\;\;\;y + y \cdot \log z\\
\mathbf{elif}\;z \leq 2.2 \cdot 10^{-242}:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{elif}\;z \leq 1.6 \cdot 10^{-56}:\\
\;\;\;\;y \cdot \left(1 + \log z\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot 0.5 - y \cdot z\\
\end{array}
\end{array}
if z < 1.45000000000000002e-263Initial program 99.6%
distribute-lft-in99.4%
Applied egg-rr99.4%
Taylor expanded in x around 0 71.0%
Taylor expanded in z around 0 71.0%
if 1.45000000000000002e-263 < z < 2.20000000000000002e-242Initial program 99.8%
Taylor expanded in x around inf 83.0%
if 2.20000000000000002e-242 < z < 1.59999999999999993e-56Initial program 99.8%
Taylor expanded in z around 0 99.8%
Taylor expanded in x around 0 61.9%
if 1.59999999999999993e-56 < z Initial program 100.0%
Taylor expanded in z around inf 93.0%
associate-*r*93.0%
neg-mul-193.0%
Simplified93.0%
fma-define93.0%
distribute-lft-neg-out93.0%
add-sqr-sqrt48.8%
sqrt-unprod60.0%
sqr-neg60.0%
sqrt-unprod18.0%
add-sqr-sqrt39.2%
fma-neg39.2%
add-sqr-sqrt18.0%
sqrt-unprod60.0%
sqr-neg60.0%
sqrt-unprod48.8%
add-sqr-sqrt93.0%
Applied egg-rr93.0%
Final simplification81.3%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* y (+ 1.0 (log z)))))
(if (<= z 2.25e-263)
t_0
(if (<= z 2.05e-241)
(* x 0.5)
(if (<= z 8.9e-57) t_0 (- (* x 0.5) (* y z)))))))
double code(double x, double y, double z) {
double t_0 = y * (1.0 + log(z));
double tmp;
if (z <= 2.25e-263) {
tmp = t_0;
} else if (z <= 2.05e-241) {
tmp = x * 0.5;
} else if (z <= 8.9e-57) {
tmp = t_0;
} 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) :: t_0
real(8) :: tmp
t_0 = y * (1.0d0 + log(z))
if (z <= 2.25d-263) then
tmp = t_0
else if (z <= 2.05d-241) then
tmp = x * 0.5d0
else if (z <= 8.9d-57) then
tmp = t_0
else
tmp = (x * 0.5d0) - (y * z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = y * (1.0 + Math.log(z));
double tmp;
if (z <= 2.25e-263) {
tmp = t_0;
} else if (z <= 2.05e-241) {
tmp = x * 0.5;
} else if (z <= 8.9e-57) {
tmp = t_0;
} else {
tmp = (x * 0.5) - (y * z);
}
return tmp;
}
def code(x, y, z): t_0 = y * (1.0 + math.log(z)) tmp = 0 if z <= 2.25e-263: tmp = t_0 elif z <= 2.05e-241: tmp = x * 0.5 elif z <= 8.9e-57: tmp = t_0 else: tmp = (x * 0.5) - (y * z) return tmp
function code(x, y, z) t_0 = Float64(y * Float64(1.0 + log(z))) tmp = 0.0 if (z <= 2.25e-263) tmp = t_0; elseif (z <= 2.05e-241) tmp = Float64(x * 0.5); elseif (z <= 8.9e-57) tmp = t_0; else tmp = Float64(Float64(x * 0.5) - Float64(y * z)); end return tmp end
function tmp_2 = code(x, y, z) t_0 = y * (1.0 + log(z)); tmp = 0.0; if (z <= 2.25e-263) tmp = t_0; elseif (z <= 2.05e-241) tmp = x * 0.5; elseif (z <= 8.9e-57) tmp = t_0; else tmp = (x * 0.5) - (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(y * N[(1.0 + N[Log[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, 2.25e-263], t$95$0, If[LessEqual[z, 2.05e-241], N[(x * 0.5), $MachinePrecision], If[LessEqual[z, 8.9e-57], t$95$0, N[(N[(x * 0.5), $MachinePrecision] - N[(y * z), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(1 + \log z\right)\\
\mathbf{if}\;z \leq 2.25 \cdot 10^{-263}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 2.05 \cdot 10^{-241}:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{elif}\;z \leq 8.9 \cdot 10^{-57}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;x \cdot 0.5 - y \cdot z\\
\end{array}
\end{array}
if z < 2.2499999999999999e-263 or 2.0499999999999999e-241 < z < 8.8999999999999997e-57Initial program 99.8%
Taylor expanded in z around 0 99.8%
Taylor expanded in x around 0 63.5%
if 2.2499999999999999e-263 < z < 2.0499999999999999e-241Initial program 99.8%
Taylor expanded in x around inf 83.0%
if 8.8999999999999997e-57 < z Initial program 100.0%
Taylor expanded in z around inf 93.0%
associate-*r*93.0%
neg-mul-193.0%
Simplified93.0%
fma-define93.0%
distribute-lft-neg-out93.0%
add-sqr-sqrt48.8%
sqrt-unprod60.0%
sqr-neg60.0%
sqrt-unprod18.0%
add-sqr-sqrt39.2%
fma-neg39.2%
add-sqr-sqrt18.0%
sqrt-unprod60.0%
sqr-neg60.0%
sqrt-unprod48.8%
add-sqr-sqrt93.0%
Applied egg-rr93.0%
Final simplification81.3%
(FPCore (x y z) :precision binary64 (if (<= z 1.46e-6) (+ (* x 0.5) (* y (+ 1.0 (log z)))) (- (* x 0.5) (* y z))))
double code(double x, double y, double z) {
double tmp;
if (z <= 1.46e-6) {
tmp = (x * 0.5) + (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 <= 1.46d-6) then
tmp = (x * 0.5d0) + (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 <= 1.46e-6) {
tmp = (x * 0.5) + (y * (1.0 + Math.log(z)));
} else {
tmp = (x * 0.5) - (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= 1.46e-6: tmp = (x * 0.5) + (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 <= 1.46e-6) tmp = Float64(Float64(x * 0.5) + 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 <= 1.46e-6) tmp = (x * 0.5) + (y * (1.0 + log(z))); else tmp = (x * 0.5) - (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, 1.46e-6], N[(N[(x * 0.5), $MachinePrecision] + N[(y * N[(1.0 + N[Log[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x * 0.5), $MachinePrecision] - N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 1.46 \cdot 10^{-6}:\\
\;\;\;\;x \cdot 0.5 + y \cdot \left(1 + \log z\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot 0.5 - y \cdot z\\
\end{array}
\end{array}
if z < 1.46e-6Initial program 99.8%
Taylor expanded in z around 0 99.7%
if 1.46e-6 < z Initial program 100.0%
Taylor expanded in z around inf 99.1%
associate-*r*99.1%
neg-mul-199.1%
Simplified99.1%
fma-define99.1%
distribute-lft-neg-out99.1%
add-sqr-sqrt49.9%
sqrt-unprod58.7%
sqr-neg58.7%
sqrt-unprod17.2%
add-sqr-sqrt33.3%
fma-neg33.3%
add-sqr-sqrt17.2%
sqrt-unprod58.7%
sqr-neg58.7%
sqrt-unprod49.9%
add-sqr-sqrt99.1%
Applied egg-rr99.1%
(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 71.3%
associate-*r*71.3%
neg-mul-171.3%
Simplified71.3%
fma-define71.3%
distribute-lft-neg-out71.3%
add-sqr-sqrt36.2%
sqrt-unprod51.3%
sqr-neg51.3%
sqrt-unprod19.7%
add-sqr-sqrt39.7%
fma-neg39.7%
add-sqr-sqrt19.7%
sqrt-unprod51.3%
sqr-neg51.3%
sqrt-unprod36.2%
add-sqr-sqrt71.3%
Applied egg-rr71.3%
(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 40.7%
Final simplification40.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 2024089
(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)))))