
(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 (<= y -2.45e+47) (not (<= y 82000.0))) (* y (- (+ 1.0 (log z)) z)) (- (* x 0.5) (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -2.45e+47) || !(y <= 82000.0)) {
tmp = y * ((1.0 + log(z)) - 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 ((y <= (-2.45d+47)) .or. (.not. (y <= 82000.0d0))) then
tmp = y * ((1.0d0 + log(z)) - 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 ((y <= -2.45e+47) || !(y <= 82000.0)) {
tmp = y * ((1.0 + Math.log(z)) - z);
} else {
tmp = (x * 0.5) - (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -2.45e+47) or not (y <= 82000.0): tmp = y * ((1.0 + math.log(z)) - z) else: tmp = (x * 0.5) - (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -2.45e+47) || !(y <= 82000.0)) tmp = Float64(y * Float64(Float64(1.0 + log(z)) - 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 ((y <= -2.45e+47) || ~((y <= 82000.0))) tmp = y * ((1.0 + log(z)) - z); else tmp = (x * 0.5) - (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -2.45e+47], N[Not[LessEqual[y, 82000.0]], $MachinePrecision]], N[(y * N[(N[(1.0 + N[Log[z], $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]), $MachinePrecision], N[(N[(x * 0.5), $MachinePrecision] - N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.45 \cdot 10^{+47} \lor \neg \left(y \leq 82000\right):\\
\;\;\;\;y \cdot \left(\left(1 + \log z\right) - z\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot 0.5 - y \cdot z\\
\end{array}
\end{array}
if y < -2.4500000000000001e47 or 82000 < y Initial program 99.9%
add-cube-cbrt98.9%
pow398.9%
*-commutative98.9%
Applied egg-rr98.9%
Taylor expanded in x around inf 85.4%
Taylor expanded in x around 0 89.3%
if -2.4500000000000001e47 < y < 82000Initial program 100.0%
Taylor expanded in z around inf 88.4%
associate-*r*88.4%
mul-1-neg88.4%
Simplified88.4%
distribute-lft-neg-out88.4%
unsub-neg88.4%
add-sqr-sqrt42.3%
sqrt-unprod67.3%
sqr-neg67.3%
sqrt-unprod29.5%
add-sqr-sqrt57.8%
*-commutative57.8%
add-sqr-sqrt29.5%
sqrt-unprod67.3%
sqr-neg67.3%
sqrt-unprod42.3%
add-sqr-sqrt88.4%
Applied egg-rr88.4%
Final simplification88.9%
(FPCore (x y z) :precision binary64 (if (<= z 0.27) (+ (* 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 <= 0.27) {
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 <= 0.27d0) 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 <= 0.27) {
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 <= 0.27: 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 <= 0.27) 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 <= 0.27) 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, 0.27], 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 0.27:\\
\;\;\;\;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 < 0.27000000000000002Initial program 99.8%
Taylor expanded in z around 0 98.8%
*-commutative98.8%
Simplified98.8%
if 0.27000000000000002 < z Initial program 100.0%
Taylor expanded in z around inf 98.7%
associate-*r*98.7%
mul-1-neg98.7%
Simplified98.7%
distribute-lft-neg-out98.7%
unsub-neg98.7%
add-sqr-sqrt53.5%
sqrt-unprod60.4%
sqr-neg60.4%
sqrt-unprod14.3%
add-sqr-sqrt30.5%
*-commutative30.5%
add-sqr-sqrt14.3%
sqrt-unprod60.4%
sqr-neg60.4%
sqrt-unprod53.5%
add-sqr-sqrt98.7%
Applied egg-rr98.7%
Final simplification98.8%
(FPCore (x y z) :precision binary64 (if (<= z 7e-41) (* y (+ 1.0 (log z))) (- (* x 0.5) (* y z))))
double code(double x, double y, double z) {
double tmp;
if (z <= 7e-41) {
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 <= 7d-41) 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 <= 7e-41) {
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 <= 7e-41: 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 <= 7e-41) 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 <= 7e-41) 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, 7e-41], 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 \cdot 10^{-41}:\\
\;\;\;\;y \cdot \left(1 + \log z\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot 0.5 - y \cdot z\\
\end{array}
\end{array}
if z < 6.9999999999999999e-41Initial program 99.8%
add-cube-cbrt98.6%
pow398.7%
*-commutative98.7%
Applied egg-rr98.7%
Taylor expanded in x around inf 89.5%
Taylor expanded in z around 0 89.5%
associate-/l*88.6%
Simplified88.6%
Taylor expanded in x around 0 63.1%
if 6.9999999999999999e-41 < z Initial program 100.0%
Taylor expanded in z around inf 95.9%
associate-*r*95.9%
mul-1-neg95.9%
Simplified95.9%
distribute-lft-neg-out95.9%
unsub-neg95.9%
add-sqr-sqrt52.6%
sqrt-unprod59.6%
sqr-neg59.6%
sqrt-unprod14.1%
add-sqr-sqrt31.3%
*-commutative31.3%
add-sqr-sqrt14.1%
sqrt-unprod59.6%
sqr-neg59.6%
sqrt-unprod52.6%
add-sqr-sqrt95.9%
Applied egg-rr95.9%
Final simplification83.1%
(FPCore (x y z) :precision binary64 (if (<= z 4.4e+65) (* x 0.5) (* y (- z))))
double code(double x, double y, double z) {
double tmp;
if (z <= 4.4e+65) {
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 <= 4.4d+65) 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 <= 4.4e+65) {
tmp = x * 0.5;
} else {
tmp = y * -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= 4.4e+65: tmp = x * 0.5 else: tmp = y * -z return tmp
function code(x, y, z) tmp = 0.0 if (z <= 4.4e+65) 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 <= 4.4e+65) tmp = x * 0.5; else tmp = y * -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, 4.4e+65], N[(x * 0.5), $MachinePrecision], N[(y * (-z)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 4.4 \cdot 10^{+65}:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(-z\right)\\
\end{array}
\end{array}
if z < 4.3999999999999997e65Initial program 99.8%
Taylor expanded in z around inf 52.1%
associate-*r*52.1%
mul-1-neg52.1%
Simplified52.1%
Taylor expanded in x around inf 42.8%
if 4.3999999999999997e65 < z Initial program 100.0%
Taylor expanded in z around inf 100.0%
associate-*r*100.0%
mul-1-neg100.0%
Simplified100.0%
Taylor expanded in y around inf 94.2%
neg-mul-194.2%
+-commutative94.2%
unsub-neg94.2%
Simplified94.2%
Taylor expanded in y around inf 76.4%
mul-1-neg76.4%
*-commutative76.4%
distribute-rgt-neg-in76.4%
Simplified76.4%
Final simplification57.9%
(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 73.6%
associate-*r*73.6%
mul-1-neg73.6%
Simplified73.6%
distribute-lft-neg-out73.6%
unsub-neg73.6%
add-sqr-sqrt38.2%
sqrt-unprod49.5%
sqr-neg49.5%
sqrt-unprod17.3%
add-sqr-sqrt33.8%
*-commutative33.8%
add-sqr-sqrt17.3%
sqrt-unprod49.5%
sqr-neg49.5%
sqrt-unprod38.2%
add-sqr-sqrt73.6%
Applied egg-rr73.6%
Final simplification73.6%
(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 z around inf 73.6%
associate-*r*73.6%
mul-1-neg73.6%
Simplified73.6%
Taylor expanded in x around inf 34.8%
Final simplification34.8%
(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 2024180
(FPCore (x y z)
:name "System.Random.MWC.Distributions:gamma from mwc-random-0.13.3.2"
:precision binary64
:alt
(! :herbie-platform default (- (+ y (* 1/2 x)) (* y (- z (log z)))))
(+ (* x 0.5) (* y (+ (- 1.0 z) (log z)))))