
(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 7 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 (or (<= z 9.5e-243)
(and (not (<= z 6.2e-178))
(or (<= z 3.2e-156) (and (not (<= z 2.2e-66)) (<= z 6.7e-40)))))
(* y (+ 1.0 (log z)))
(- (* x 0.5) (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((z <= 9.5e-243) || (!(z <= 6.2e-178) && ((z <= 3.2e-156) || (!(z <= 2.2e-66) && (z <= 6.7e-40))))) {
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 <= 9.5d-243) .or. (.not. (z <= 6.2d-178)) .and. (z <= 3.2d-156) .or. (.not. (z <= 2.2d-66)) .and. (z <= 6.7d-40)) 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 <= 9.5e-243) || (!(z <= 6.2e-178) && ((z <= 3.2e-156) || (!(z <= 2.2e-66) && (z <= 6.7e-40))))) {
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 <= 9.5e-243) or (not (z <= 6.2e-178) and ((z <= 3.2e-156) or (not (z <= 2.2e-66) and (z <= 6.7e-40)))): 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 <= 9.5e-243) || (!(z <= 6.2e-178) && ((z <= 3.2e-156) || (!(z <= 2.2e-66) && (z <= 6.7e-40))))) 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 <= 9.5e-243) || (~((z <= 6.2e-178)) && ((z <= 3.2e-156) || (~((z <= 2.2e-66)) && (z <= 6.7e-40))))) 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, 9.5e-243], And[N[Not[LessEqual[z, 6.2e-178]], $MachinePrecision], Or[LessEqual[z, 3.2e-156], And[N[Not[LessEqual[z, 2.2e-66]], $MachinePrecision], LessEqual[z, 6.7e-40]]]]], 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 9.5 \cdot 10^{-243} \lor \neg \left(z \leq 6.2 \cdot 10^{-178}\right) \land \left(z \leq 3.2 \cdot 10^{-156} \lor \neg \left(z \leq 2.2 \cdot 10^{-66}\right) \land z \leq 6.7 \cdot 10^{-40}\right):\\
\;\;\;\;y \cdot \left(1 + \log z\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot 0.5 - y \cdot z\\
\end{array}
\end{array}
if z < 9.5000000000000005e-243 or 6.1999999999999999e-178 < z < 3.19999999999999982e-156 or 2.2000000000000001e-66 < z < 6.6999999999999998e-40Initial program 99.7%
Taylor expanded in z around 0 99.7%
Taylor expanded in x around 0 69.3%
if 9.5000000000000005e-243 < z < 6.1999999999999999e-178 or 3.19999999999999982e-156 < z < 2.2000000000000001e-66 or 6.6999999999999998e-40 < z Initial program 100.0%
Taylor expanded in z around inf 88.3%
associate-*r*88.3%
mul-1-neg88.3%
Simplified88.3%
distribute-lft-neg-out88.3%
unsub-neg88.3%
add-sqr-sqrt44.7%
sqrt-unprod59.9%
sqr-neg59.9%
sqrt-unprod21.9%
add-sqr-sqrt43.2%
*-commutative43.2%
add-sqr-sqrt21.9%
sqrt-unprod59.9%
sqr-neg59.9%
sqrt-unprod44.7%
add-sqr-sqrt88.3%
Applied egg-rr88.3%
Final simplification84.1%
(FPCore (x y z) :precision binary64 (if (or (<= (* x 0.5) -5e-37) (not (<= (* x 0.5) 5e+23))) (- (* x 0.5) (* y z)) (* y (- (+ 1.0 (log z)) z))))
double code(double x, double y, double z) {
double tmp;
if (((x * 0.5) <= -5e-37) || !((x * 0.5) <= 5e+23)) {
tmp = (x * 0.5) - (y * z);
} else {
tmp = y * ((1.0 + log(z)) - 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-37)) .or. (.not. ((x * 0.5d0) <= 5d+23))) then
tmp = (x * 0.5d0) - (y * z)
else
tmp = y * ((1.0d0 + log(z)) - z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (((x * 0.5) <= -5e-37) || !((x * 0.5) <= 5e+23)) {
tmp = (x * 0.5) - (y * z);
} else {
tmp = y * ((1.0 + Math.log(z)) - z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if ((x * 0.5) <= -5e-37) or not ((x * 0.5) <= 5e+23): tmp = (x * 0.5) - (y * z) else: tmp = y * ((1.0 + math.log(z)) - z) return tmp
function code(x, y, z) tmp = 0.0 if ((Float64(x * 0.5) <= -5e-37) || !(Float64(x * 0.5) <= 5e+23)) tmp = Float64(Float64(x * 0.5) - Float64(y * z)); else tmp = Float64(y * Float64(Float64(1.0 + log(z)) - z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (((x * 0.5) <= -5e-37) || ~(((x * 0.5) <= 5e+23))) tmp = (x * 0.5) - (y * z); else tmp = y * ((1.0 + log(z)) - z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[N[(x * 0.5), $MachinePrecision], -5e-37], N[Not[LessEqual[N[(x * 0.5), $MachinePrecision], 5e+23]], $MachinePrecision]], N[(N[(x * 0.5), $MachinePrecision] - N[(y * z), $MachinePrecision]), $MachinePrecision], N[(y * N[(N[(1.0 + N[Log[z], $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot 0.5 \leq -5 \cdot 10^{-37} \lor \neg \left(x \cdot 0.5 \leq 5 \cdot 10^{+23}\right):\\
\;\;\;\;x \cdot 0.5 - y \cdot z\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(\left(1 + \log z\right) - z\right)\\
\end{array}
\end{array}
if (*.f64 x #s(literal 1/2 binary64)) < -4.9999999999999997e-37 or 4.9999999999999999e23 < (*.f64 x #s(literal 1/2 binary64)) Initial program 99.9%
Taylor expanded in z around inf 88.7%
associate-*r*88.7%
mul-1-neg88.7%
Simplified88.7%
distribute-lft-neg-out88.7%
unsub-neg88.7%
add-sqr-sqrt44.2%
sqrt-unprod75.0%
sqr-neg75.0%
sqrt-unprod34.0%
add-sqr-sqrt66.3%
*-commutative66.3%
add-sqr-sqrt34.0%
sqrt-unprod75.0%
sqr-neg75.0%
sqrt-unprod44.2%
add-sqr-sqrt88.7%
Applied egg-rr88.7%
if -4.9999999999999997e-37 < (*.f64 x #s(literal 1/2 binary64)) < 4.9999999999999999e23Initial program 99.9%
Taylor expanded in x around inf 72.0%
Taylor expanded in y around inf 51.9%
*-commutative51.9%
associate-*r*70.0%
*-commutative70.0%
associate-*l*61.1%
associate--l+61.1%
Simplified61.1%
Taylor expanded in x around 0 85.9%
Final simplification87.3%
(FPCore (x y z) :precision binary64 (if (<= z 2.4e-5) (+ (* 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 <= 2.4e-5) {
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 <= 2.4d-5) 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 <= 2.4e-5) {
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 <= 2.4e-5: 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 <= 2.4e-5) 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 <= 2.4e-5) 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, 2.4e-5], 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 2.4 \cdot 10^{-5}:\\
\;\;\;\;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 < 2.4000000000000001e-5Initial program 99.8%
Taylor expanded in z around 0 99.5%
if 2.4000000000000001e-5 < z Initial program 100.0%
Taylor expanded in z around inf 99.4%
associate-*r*99.4%
mul-1-neg99.4%
Simplified99.4%
distribute-lft-neg-out99.4%
unsub-neg99.4%
add-sqr-sqrt51.6%
sqrt-unprod58.5%
sqr-neg58.5%
sqrt-unprod14.9%
add-sqr-sqrt31.1%
*-commutative31.1%
add-sqr-sqrt14.9%
sqrt-unprod58.5%
sqr-neg58.5%
sqrt-unprod51.6%
add-sqr-sqrt99.4%
Applied egg-rr99.4%
Final simplification99.4%
(FPCore (x y z) :precision binary64 (if (<= z 1.02e+24) (* x 0.5) (* y (- z))))
double code(double x, double y, double z) {
double tmp;
if (z <= 1.02e+24) {
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 <= 1.02d+24) 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 <= 1.02e+24) {
tmp = x * 0.5;
} else {
tmp = y * -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= 1.02e+24: tmp = x * 0.5 else: tmp = y * -z return tmp
function code(x, y, z) tmp = 0.0 if (z <= 1.02e+24) 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 <= 1.02e+24) tmp = x * 0.5; else tmp = y * -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, 1.02e+24], N[(x * 0.5), $MachinePrecision], N[(y * (-z)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 1.02 \cdot 10^{+24}:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(-z\right)\\
\end{array}
\end{array}
if z < 1.02000000000000004e24Initial program 99.8%
Taylor expanded in x around inf 52.8%
if 1.02000000000000004e24 < z Initial program 100.0%
Taylor expanded in z around inf 100.0%
associate-*r*100.0%
mul-1-neg100.0%
Simplified100.0%
distribute-lft-neg-out100.0%
unsub-neg100.0%
add-sqr-sqrt51.5%
sqrt-unprod57.1%
sqr-neg57.1%
sqrt-unprod13.7%
add-sqr-sqrt27.2%
*-commutative27.2%
add-sqr-sqrt13.7%
sqrt-unprod57.1%
sqr-neg57.1%
sqrt-unprod51.5%
add-sqr-sqrt100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 72.0%
associate-*r*72.0%
neg-mul-172.0%
*-commutative72.0%
Simplified72.0%
Final simplification61.8%
(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 76.2%
associate-*r*76.2%
mul-1-neg76.2%
Simplified76.2%
distribute-lft-neg-out76.2%
unsub-neg76.2%
add-sqr-sqrt39.3%
sqrt-unprod53.8%
sqr-neg53.8%
sqrt-unprod19.8%
add-sqr-sqrt40.6%
*-commutative40.6%
add-sqr-sqrt19.8%
sqrt-unprod53.8%
sqr-neg53.8%
sqrt-unprod39.3%
add-sqr-sqrt76.2%
Applied egg-rr76.2%
Final simplification76.2%
(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 41.6%
Final simplification41.6%
(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 2024091
(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)))))