
(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 (fma y (+ (- 1.0 z) (log z)) (* x 0.5)))
double code(double x, double y, double z) {
return fma(y, ((1.0 - z) + log(z)), (x * 0.5));
}
function code(x, y, z) return fma(y, Float64(Float64(1.0 - z) + log(z)), Float64(x * 0.5)) end
code[x_, y_, z_] := N[(y * N[(N[(1.0 - z), $MachinePrecision] + N[Log[z], $MachinePrecision]), $MachinePrecision] + N[(x * 0.5), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y, \left(1 - z\right) + \log z, x \cdot 0.5\right)
\end{array}
Initial program 99.9%
+-commutative99.9%
fma-def99.9%
Simplified99.9%
Final simplification99.9%
(FPCore (x y z)
:precision binary64
(if (<= (* x 0.5) -500.0)
(fma y (- z) (* x 0.5))
(if (<= (* x 0.5) 1e-79)
(* y (+ (- 1.0 z) (log z)))
(- (* x 0.5) (* y z)))))
double code(double x, double y, double z) {
double tmp;
if ((x * 0.5) <= -500.0) {
tmp = fma(y, -z, (x * 0.5));
} else if ((x * 0.5) <= 1e-79) {
tmp = y * ((1.0 - z) + log(z));
} else {
tmp = (x * 0.5) - (y * z);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (Float64(x * 0.5) <= -500.0) tmp = fma(y, Float64(-z), Float64(x * 0.5)); elseif (Float64(x * 0.5) <= 1e-79) tmp = Float64(y * Float64(Float64(1.0 - z) + log(z))); else tmp = Float64(Float64(x * 0.5) - Float64(y * z)); end return tmp end
code[x_, y_, z_] := If[LessEqual[N[(x * 0.5), $MachinePrecision], -500.0], N[(y * (-z) + N[(x * 0.5), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(x * 0.5), $MachinePrecision], 1e-79], N[(y * N[(N[(1.0 - z), $MachinePrecision] + 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}\;x \cdot 0.5 \leq -500:\\
\;\;\;\;\mathsf{fma}\left(y, -z, x \cdot 0.5\right)\\
\mathbf{elif}\;x \cdot 0.5 \leq 10^{-79}:\\
\;\;\;\;y \cdot \left(\left(1 - z\right) + \log z\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot 0.5 - y \cdot z\\
\end{array}
\end{array}
if (*.f64 x 1/2) < -500Initial program 99.9%
+-commutative99.9%
fma-def99.9%
Simplified99.9%
Taylor expanded in z around inf 87.9%
mul-1-neg87.9%
Simplified87.9%
if -500 < (*.f64 x 1/2) < 1e-79Initial program 99.8%
Taylor expanded in z around 0 99.0%
Taylor expanded in x around 0 91.3%
+-commutative91.3%
+-commutative91.3%
distribute-lft-in91.3%
*-rgt-identity91.3%
associate-*r*91.3%
neg-mul-191.3%
*-commutative91.3%
associate-+l+91.3%
*-un-lft-identity91.3%
distribute-rgt-neg-out91.3%
distribute-lft-neg-in91.3%
distribute-rgt-in91.2%
sub-neg91.2%
+-commutative91.2%
distribute-lft-out92.1%
Applied egg-rr92.1%
if 1e-79 < (*.f64 x 1/2) Initial program 99.9%
Taylor expanded in z around inf 85.1%
mul-1-neg85.1%
*-commutative85.1%
distribute-rgt-neg-in85.1%
Simplified85.1%
*-commutative85.1%
neg-mul-185.1%
associate-*r*85.1%
mul-1-neg85.1%
unsub-neg85.1%
Applied egg-rr85.1%
Final simplification89.2%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* y (+ 1.0 (log z)))) (t_1 (- (* x 0.5) (* y z))))
(if (<= z 5.8e-274)
t_1
(if (<= z 1.9e-127)
t_0
(if (<= z 8.5e-116)
t_1
(if (<= z 2.8e-72) 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 t_1 = (x * 0.5) - (y * z);
double tmp;
if (z <= 5.8e-274) {
tmp = t_1;
} else if (z <= 1.9e-127) {
tmp = t_0;
} else if (z <= 8.5e-116) {
tmp = t_1;
} else if (z <= 2.8e-72) {
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))) t_1 = Float64(Float64(x * 0.5) - Float64(y * z)) tmp = 0.0 if (z <= 5.8e-274) tmp = t_1; elseif (z <= 1.9e-127) tmp = t_0; elseif (z <= 8.5e-116) tmp = t_1; elseif (z <= 2.8e-72) 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]}, Block[{t$95$1 = N[(N[(x * 0.5), $MachinePrecision] - N[(y * z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, 5.8e-274], t$95$1, If[LessEqual[z, 1.9e-127], t$95$0, If[LessEqual[z, 8.5e-116], t$95$1, If[LessEqual[z, 2.8e-72], 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)\\
t_1 := x \cdot 0.5 - y \cdot z\\
\mathbf{if}\;z \leq 5.8 \cdot 10^{-274}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;z \leq 1.9 \cdot 10^{-127}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq 8.5 \cdot 10^{-116}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;z \leq 2.8 \cdot 10^{-72}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y, -z, x \cdot 0.5\right)\\
\end{array}
\end{array}
if z < 5.79999999999999952e-274 or 1.90000000000000001e-127 < z < 8.4999999999999995e-116Initial program 99.9%
Taylor expanded in z around inf 73.5%
mul-1-neg73.5%
*-commutative73.5%
distribute-rgt-neg-in73.5%
Simplified73.5%
*-commutative73.5%
neg-mul-173.5%
associate-*r*73.5%
mul-1-neg73.5%
unsub-neg73.5%
Applied egg-rr73.5%
if 5.79999999999999952e-274 < z < 1.90000000000000001e-127 or 8.4999999999999995e-116 < z < 2.7999999999999998e-72Initial program 99.7%
Taylor expanded in z around 0 99.7%
Taylor expanded in x around 0 67.5%
Taylor expanded in z around 0 67.5%
if 2.7999999999999998e-72 < z Initial program 99.9%
+-commutative99.9%
fma-def99.9%
Simplified99.9%
Taylor expanded in z around inf 92.0%
mul-1-neg92.0%
Simplified92.0%
Final simplification82.5%
(FPCore (x y z)
:precision binary64
(if (or (<= z 1.7e-273)
(not
(or (<= z 2.6e-127) (and (not (<= z 2.55e-113)) (<= z 6.2e-73)))))
(- (* x 0.5) (* y z))
(* y (+ 1.0 (log z)))))
double code(double x, double y, double z) {
double tmp;
if ((z <= 1.7e-273) || !((z <= 2.6e-127) || (!(z <= 2.55e-113) && (z <= 6.2e-73)))) {
tmp = (x * 0.5) - (y * z);
} else {
tmp = y * (1.0 + 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 ((z <= 1.7d-273) .or. (.not. (z <= 2.6d-127) .or. (.not. (z <= 2.55d-113)) .and. (z <= 6.2d-73))) then
tmp = (x * 0.5d0) - (y * z)
else
tmp = y * (1.0d0 + log(z))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= 1.7e-273) || !((z <= 2.6e-127) || (!(z <= 2.55e-113) && (z <= 6.2e-73)))) {
tmp = (x * 0.5) - (y * z);
} else {
tmp = y * (1.0 + Math.log(z));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= 1.7e-273) or not ((z <= 2.6e-127) or (not (z <= 2.55e-113) and (z <= 6.2e-73))): tmp = (x * 0.5) - (y * z) else: tmp = y * (1.0 + math.log(z)) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= 1.7e-273) || !((z <= 2.6e-127) || (!(z <= 2.55e-113) && (z <= 6.2e-73)))) tmp = Float64(Float64(x * 0.5) - Float64(y * z)); else tmp = Float64(y * Float64(1.0 + log(z))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= 1.7e-273) || ~(((z <= 2.6e-127) || (~((z <= 2.55e-113)) && (z <= 6.2e-73))))) tmp = (x * 0.5) - (y * z); else tmp = y * (1.0 + log(z)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, 1.7e-273], N[Not[Or[LessEqual[z, 2.6e-127], And[N[Not[LessEqual[z, 2.55e-113]], $MachinePrecision], LessEqual[z, 6.2e-73]]]], $MachinePrecision]], N[(N[(x * 0.5), $MachinePrecision] - N[(y * z), $MachinePrecision]), $MachinePrecision], N[(y * N[(1.0 + N[Log[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 1.7 \cdot 10^{-273} \lor \neg \left(z \leq 2.6 \cdot 10^{-127} \lor \neg \left(z \leq 2.55 \cdot 10^{-113}\right) \land z \leq 6.2 \cdot 10^{-73}\right):\\
\;\;\;\;x \cdot 0.5 - y \cdot z\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(1 + \log z\right)\\
\end{array}
\end{array}
if z < 1.69999999999999996e-273 or 2.59999999999999991e-127 < z < 2.54999999999999989e-113 or 6.19999999999999938e-73 < z Initial program 99.9%
Taylor expanded in z around inf 89.8%
mul-1-neg89.8%
*-commutative89.8%
distribute-rgt-neg-in89.8%
Simplified89.8%
*-commutative89.8%
neg-mul-189.8%
associate-*r*89.8%
mul-1-neg89.8%
unsub-neg89.8%
Applied egg-rr89.8%
if 1.69999999999999996e-273 < z < 2.59999999999999991e-127 or 2.54999999999999989e-113 < z < 6.19999999999999938e-73Initial program 99.7%
Taylor expanded in z around 0 99.7%
Taylor expanded in x around 0 67.5%
Taylor expanded in z around 0 67.5%
Final simplification82.5%
(FPCore (x y z) :precision binary64 (if (<= z 0.07) (+ (* 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.07) {
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.07) 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.07], 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.07:\\
\;\;\;\;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.070000000000000007Initial program 99.7%
Taylor expanded in z around 0 97.8%
if 0.070000000000000007 < z Initial program 100.0%
+-commutative100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in z around inf 99.5%
mul-1-neg99.5%
Simplified99.5%
Final simplification98.6%
(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 (- (* 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.9%
mul-1-neg71.9%
*-commutative71.9%
distribute-rgt-neg-in71.9%
Simplified71.9%
*-commutative71.9%
neg-mul-171.9%
associate-*r*71.9%
mul-1-neg71.9%
unsub-neg71.9%
Applied egg-rr71.9%
Final simplification71.9%
(FPCore (x y z) :precision binary64 (if (<= z 5e+48) (* x 0.5) (* y (- z))))
double code(double x, double y, double z) {
double tmp;
if (z <= 5e+48) {
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 <= 5d+48) 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 <= 5e+48) {
tmp = x * 0.5;
} else {
tmp = y * -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= 5e+48: tmp = x * 0.5 else: tmp = y * -z return tmp
function code(x, y, z) tmp = 0.0 if (z <= 5e+48) 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 <= 5e+48) tmp = x * 0.5; else tmp = y * -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, 5e+48], N[(x * 0.5), $MachinePrecision], N[(y * (-z)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 5 \cdot 10^{+48}:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(-z\right)\\
\end{array}
\end{array}
if z < 4.99999999999999973e48Initial program 99.7%
Taylor expanded in x around inf 44.1%
if 4.99999999999999973e48 < z Initial program 100.0%
Taylor expanded in z around inf 100.0%
mul-1-neg100.0%
*-commutative100.0%
distribute-rgt-neg-in100.0%
Simplified100.0%
*-commutative100.0%
neg-mul-1100.0%
associate-*r*100.0%
mul-1-neg100.0%
unsub-neg100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 73.8%
associate-*r*73.8%
neg-mul-173.8%
Simplified73.8%
Final simplification58.0%
(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 36.2%
Final simplification36.2%
(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 2023314
(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)))))