
(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%
Final simplification99.9%
(FPCore (x y z) :precision binary64 (if (or (<= (* x 0.5) -10000000.0) (not (<= (* x 0.5) 5e-120))) (- (* x 0.5) (* y z)) (* y (+ (- 1.0 z) (log z)))))
double code(double x, double y, double z) {
double tmp;
if (((x * 0.5) <= -10000000.0) || !((x * 0.5) <= 5e-120)) {
tmp = (x * 0.5) - (y * z);
} else {
tmp = y * ((1.0 - z) + 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) <= (-10000000.0d0)) .or. (.not. ((x * 0.5d0) <= 5d-120))) then
tmp = (x * 0.5d0) - (y * z)
else
tmp = y * ((1.0d0 - z) + log(z))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (((x * 0.5) <= -10000000.0) || !((x * 0.5) <= 5e-120)) {
tmp = (x * 0.5) - (y * z);
} else {
tmp = y * ((1.0 - z) + Math.log(z));
}
return tmp;
}
def code(x, y, z): tmp = 0 if ((x * 0.5) <= -10000000.0) or not ((x * 0.5) <= 5e-120): tmp = (x * 0.5) - (y * z) else: tmp = y * ((1.0 - z) + math.log(z)) return tmp
function code(x, y, z) tmp = 0.0 if ((Float64(x * 0.5) <= -10000000.0) || !(Float64(x * 0.5) <= 5e-120)) tmp = Float64(Float64(x * 0.5) - Float64(y * z)); else tmp = Float64(y * Float64(Float64(1.0 - z) + log(z))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (((x * 0.5) <= -10000000.0) || ~(((x * 0.5) <= 5e-120))) tmp = (x * 0.5) - (y * z); else tmp = y * ((1.0 - z) + log(z)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[N[(x * 0.5), $MachinePrecision], -10000000.0], N[Not[LessEqual[N[(x * 0.5), $MachinePrecision], 5e-120]], $MachinePrecision]], N[(N[(x * 0.5), $MachinePrecision] - N[(y * z), $MachinePrecision]), $MachinePrecision], N[(y * N[(N[(1.0 - z), $MachinePrecision] + N[Log[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot 0.5 \leq -10000000 \lor \neg \left(x \cdot 0.5 \leq 5 \cdot 10^{-120}\right):\\
\;\;\;\;x \cdot 0.5 - y \cdot z\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(\left(1 - z\right) + \log z\right)\\
\end{array}
\end{array}
if (*.f64 x 1/2) < -1e7 or 5.00000000000000007e-120 < (*.f64 x 1/2) Initial program 100.0%
Taylor expanded in z around inf 90.0%
associate-*r*90.0%
neg-mul-190.0%
Simplified90.0%
distribute-lft-neg-out90.0%
add-sqr-sqrt43.8%
sqrt-unprod69.3%
sqr-neg69.3%
sqrt-unprod30.1%
add-sqr-sqrt62.2%
sub-neg62.2%
*-commutative62.2%
add-sqr-sqrt30.1%
sqrt-unprod69.3%
sqr-neg69.3%
sqrt-unprod43.8%
add-sqr-sqrt90.0%
Applied egg-rr90.0%
if -1e7 < (*.f64 x 1/2) < 5.00000000000000007e-120Initial program 99.8%
+-commutative99.8%
distribute-lft-in99.8%
*-commutative99.8%
add-sqr-sqrt46.2%
associate-*r*46.2%
fma-def46.2%
Applied egg-rr46.2%
Taylor expanded in x around 0 90.4%
add-sqr-sqrt48.3%
pow248.3%
distribute-lft-out48.3%
Applied egg-rr48.3%
unpow248.3%
add-sqr-sqrt90.4%
*-commutative90.4%
Applied egg-rr90.4%
Final simplification90.2%
(FPCore (x y z) :precision binary64 (if (<= z 2.35e-5) (+ (* x 0.5) (* y (+ 1.0 (log z)))) (+ (* x 0.5) (* y (- 1.0 z)))))
double code(double x, double y, double z) {
double tmp;
if (z <= 2.35e-5) {
tmp = (x * 0.5) + (y * (1.0 + log(z)));
} else {
tmp = (x * 0.5) + (y * (1.0 - 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.35d-5) then
tmp = (x * 0.5d0) + (y * (1.0d0 + log(z)))
else
tmp = (x * 0.5d0) + (y * (1.0d0 - z))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= 2.35e-5) {
tmp = (x * 0.5) + (y * (1.0 + Math.log(z)));
} else {
tmp = (x * 0.5) + (y * (1.0 - z));
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= 2.35e-5: tmp = (x * 0.5) + (y * (1.0 + math.log(z))) else: tmp = (x * 0.5) + (y * (1.0 - z)) return tmp
function code(x, y, z) tmp = 0.0 if (z <= 2.35e-5) tmp = Float64(Float64(x * 0.5) + Float64(y * Float64(1.0 + log(z)))); else tmp = Float64(Float64(x * 0.5) + Float64(y * Float64(1.0 - z))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= 2.35e-5) tmp = (x * 0.5) + (y * (1.0 + log(z))); else tmp = (x * 0.5) + (y * (1.0 - z)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, 2.35e-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 * N[(1.0 - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 2.35 \cdot 10^{-5}:\\
\;\;\;\;x \cdot 0.5 + y \cdot \left(1 + \log z\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot 0.5 + y \cdot \left(1 - z\right)\\
\end{array}
\end{array}
if z < 2.34999999999999986e-5Initial program 99.8%
Taylor expanded in z around 0 99.5%
if 2.34999999999999986e-5 < z Initial program 100.0%
associate-+l-100.0%
Applied egg-rr100.0%
Taylor expanded in z around inf 99.1%
Final simplification99.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.9%
Taylor expanded in z around inf 76.6%
associate-*r*76.6%
neg-mul-176.6%
Simplified76.6%
distribute-lft-neg-out76.6%
add-sqr-sqrt37.1%
sqrt-unprod53.2%
sqr-neg53.2%
sqrt-unprod21.0%
add-sqr-sqrt42.5%
sub-neg42.5%
*-commutative42.5%
add-sqr-sqrt21.0%
sqrt-unprod53.2%
sqr-neg53.2%
sqrt-unprod37.1%
add-sqr-sqrt76.6%
Applied egg-rr76.6%
Final simplification76.6%
(FPCore (x y z) :precision binary64 (if (<= z 6.8e+43) (* x 0.5) (* y (- z))))
double code(double x, double y, double z) {
double tmp;
if (z <= 6.8e+43) {
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 <= 6.8d+43) 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 <= 6.8e+43) {
tmp = x * 0.5;
} else {
tmp = y * -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= 6.8e+43: tmp = x * 0.5 else: tmp = y * -z return tmp
function code(x, y, z) tmp = 0.0 if (z <= 6.8e+43) 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 <= 6.8e+43) tmp = x * 0.5; else tmp = y * -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, 6.8e+43], N[(x * 0.5), $MachinePrecision], N[(y * (-z)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 6.8 \cdot 10^{+43}:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(-z\right)\\
\end{array}
\end{array}
if z < 6.80000000000000024e43Initial program 99.8%
Taylor expanded in x around inf 54.4%
if 6.80000000000000024e43 < z Initial program 100.0%
Taylor expanded in z around inf 100.0%
associate-*r*100.0%
neg-mul-1100.0%
Simplified100.0%
distribute-lft-neg-out100.0%
add-sqr-sqrt44.2%
sqrt-unprod54.0%
sqr-neg54.0%
sqrt-unprod14.9%
add-sqr-sqrt26.3%
sub-neg26.3%
*-commutative26.3%
add-sqr-sqrt14.9%
sqrt-unprod54.0%
sqr-neg54.0%
sqrt-unprod44.2%
add-sqr-sqrt100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 73.5%
mul-1-neg73.5%
*-commutative73.5%
distribute-rgt-neg-in73.5%
Simplified73.5%
Final simplification62.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 43.4%
Final simplification43.4%
(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 2023334
(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)))))