
(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 8 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
(let* ((t_0 (* y (+ 1.0 (log z)))))
(if (<= z 3.3e-220)
t_0
(if (<= z 3e-199)
(- (* x 0.5) (* y z))
(if (<= z 9.8e-74) 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 tmp;
if (z <= 3.3e-220) {
tmp = t_0;
} else if (z <= 3e-199) {
tmp = (x * 0.5) - (y * z);
} else if (z <= 9.8e-74) {
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))) tmp = 0.0 if (z <= 3.3e-220) tmp = t_0; elseif (z <= 3e-199) tmp = Float64(Float64(x * 0.5) - Float64(y * z)); elseif (z <= 9.8e-74) 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]}, If[LessEqual[z, 3.3e-220], t$95$0, If[LessEqual[z, 3e-199], N[(N[(x * 0.5), $MachinePrecision] - N[(y * z), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 9.8e-74], 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)\\
\mathbf{if}\;z \leq 3.3 \cdot 10^{-220}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 3 \cdot 10^{-199}:\\
\;\;\;\;x \cdot 0.5 - y \cdot z\\
\mathbf{elif}\;z \leq 9.8 \cdot 10^{-74}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y, -z, x \cdot 0.5\right)\\
\end{array}
\end{array}
if z < 3.29999999999999999e-220 or 2.99999999999999983e-199 < z < 9.8000000000000006e-74Initial program 99.8%
Taylor expanded in z around inf 55.7%
Taylor expanded in x around 0 42.6%
+-commutative42.6%
associate-/l*41.4%
+-commutative41.4%
log-rec41.4%
fma-undefine41.4%
*-commutative41.4%
distribute-lft-out41.4%
fma-undefine41.4%
distribute-rgt-neg-in41.4%
neg-mul-141.4%
remove-double-neg41.4%
+-commutative41.4%
Simplified41.4%
Taylor expanded in z around 0 66.2%
if 3.29999999999999999e-220 < z < 2.99999999999999983e-199Initial program 100.0%
Taylor expanded in z around inf 78.4%
associate-*r*78.4%
mul-1-neg78.4%
Simplified78.4%
fma-define78.4%
distribute-lft-neg-out78.4%
fmm-undef78.4%
Applied egg-rr78.4%
if 9.8000000000000006e-74 < z Initial program 99.9%
+-commutative99.9%
fma-define100.0%
Simplified100.0%
Taylor expanded in z around inf 93.0%
mul-1-neg93.0%
Simplified93.0%
Final simplification82.2%
(FPCore (x y z) :precision binary64 (if (or (<= (* x 0.5) -1e+50) (not (<= (* x 0.5) 2e-91))) (- (* 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) <= -1e+50) || !((x * 0.5) <= 2e-91)) {
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) <= (-1d+50)) .or. (.not. ((x * 0.5d0) <= 2d-91))) 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) <= -1e+50) || !((x * 0.5) <= 2e-91)) {
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) <= -1e+50) or not ((x * 0.5) <= 2e-91): 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) <= -1e+50) || !(Float64(x * 0.5) <= 2e-91)) 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) <= -1e+50) || ~(((x * 0.5) <= 2e-91))) 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], -1e+50], N[Not[LessEqual[N[(x * 0.5), $MachinePrecision], 2e-91]], $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 -1 \cdot 10^{+50} \lor \neg \left(x \cdot 0.5 \leq 2 \cdot 10^{-91}\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)) < -1.0000000000000001e50 or 2.00000000000000004e-91 < (*.f64 x #s(literal 1/2 binary64)) Initial program 100.0%
Taylor expanded in z around inf 86.1%
associate-*r*86.1%
mul-1-neg86.1%
Simplified86.1%
fma-define86.1%
distribute-lft-neg-out86.1%
fmm-undef86.1%
Applied egg-rr86.1%
if -1.0000000000000001e50 < (*.f64 x #s(literal 1/2 binary64)) < 2.00000000000000004e-91Initial program 99.8%
distribute-lft-in99.7%
Applied egg-rr99.7%
Taylor expanded in x around 0 88.1%
Taylor expanded in y around 0 88.2%
Final simplification87.1%
(FPCore (x y z) :precision binary64 (if (or (<= z 2.9e-220) (and (not (<= z 6.5e-199)) (<= z 9.8e-74))) (* y (+ 1.0 (log z))) (- (* x 0.5) (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((z <= 2.9e-220) || (!(z <= 6.5e-199) && (z <= 9.8e-74))) {
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 <= 2.9d-220) .or. (.not. (z <= 6.5d-199)) .and. (z <= 9.8d-74)) 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 <= 2.9e-220) || (!(z <= 6.5e-199) && (z <= 9.8e-74))) {
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 <= 2.9e-220) or (not (z <= 6.5e-199) and (z <= 9.8e-74)): 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 <= 2.9e-220) || (!(z <= 6.5e-199) && (z <= 9.8e-74))) 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 <= 2.9e-220) || (~((z <= 6.5e-199)) && (z <= 9.8e-74))) 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, 2.9e-220], And[N[Not[LessEqual[z, 6.5e-199]], $MachinePrecision], LessEqual[z, 9.8e-74]]], 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 2.9 \cdot 10^{-220} \lor \neg \left(z \leq 6.5 \cdot 10^{-199}\right) \land z \leq 9.8 \cdot 10^{-74}:\\
\;\;\;\;y \cdot \left(1 + \log z\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot 0.5 - y \cdot z\\
\end{array}
\end{array}
if z < 2.8999999999999998e-220 or 6.50000000000000017e-199 < z < 9.8000000000000006e-74Initial program 99.8%
Taylor expanded in z around inf 55.7%
Taylor expanded in x around 0 42.6%
+-commutative42.6%
associate-/l*41.4%
+-commutative41.4%
log-rec41.4%
fma-undefine41.4%
*-commutative41.4%
distribute-lft-out41.4%
fma-undefine41.4%
distribute-rgt-neg-in41.4%
neg-mul-141.4%
remove-double-neg41.4%
+-commutative41.4%
Simplified41.4%
Taylor expanded in z around 0 66.2%
if 2.8999999999999998e-220 < z < 6.50000000000000017e-199 or 9.8000000000000006e-74 < z Initial program 100.0%
Taylor expanded in z around inf 91.8%
associate-*r*91.8%
mul-1-neg91.8%
Simplified91.8%
fma-define91.8%
distribute-lft-neg-out91.8%
fmm-undef91.8%
Applied egg-rr91.8%
Final simplification82.2%
(FPCore (x y z) :precision binary64 (if (<= z 1.3e-5) (+ (* 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 <= 1.3e-5) {
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 <= 1.3e-5) 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, 1.3e-5], 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 1.3 \cdot 10^{-5}:\\
\;\;\;\;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 < 1.29999999999999992e-5Initial program 99.8%
Taylor expanded in z around 0 99.2%
if 1.29999999999999992e-5 < z Initial program 100.0%
+-commutative100.0%
fma-define100.0%
Simplified100.0%
Taylor expanded in z around inf 98.8%
mul-1-neg98.8%
Simplified98.8%
Final simplification99.0%
(FPCore (x y z) :precision binary64 (if (or (<= z 2e+26) (and (not (<= z 4.3e+101)) (<= z 3.8e+113))) (* x 0.5) (* y (- z))))
double code(double x, double y, double z) {
double tmp;
if ((z <= 2e+26) || (!(z <= 4.3e+101) && (z <= 3.8e+113))) {
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 <= 2d+26) .or. (.not. (z <= 4.3d+101)) .and. (z <= 3.8d+113)) 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 <= 2e+26) || (!(z <= 4.3e+101) && (z <= 3.8e+113))) {
tmp = x * 0.5;
} else {
tmp = y * -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= 2e+26) or (not (z <= 4.3e+101) and (z <= 3.8e+113)): tmp = x * 0.5 else: tmp = y * -z return tmp
function code(x, y, z) tmp = 0.0 if ((z <= 2e+26) || (!(z <= 4.3e+101) && (z <= 3.8e+113))) 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 <= 2e+26) || (~((z <= 4.3e+101)) && (z <= 3.8e+113))) tmp = x * 0.5; else tmp = y * -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, 2e+26], And[N[Not[LessEqual[z, 4.3e+101]], $MachinePrecision], LessEqual[z, 3.8e+113]]], N[(x * 0.5), $MachinePrecision], N[(y * (-z)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 2 \cdot 10^{+26} \lor \neg \left(z \leq 4.3 \cdot 10^{+101}\right) \land z \leq 3.8 \cdot 10^{+113}:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(-z\right)\\
\end{array}
\end{array}
if z < 2.0000000000000001e26 or 4.3000000000000001e101 < z < 3.8000000000000003e113Initial program 99.8%
Taylor expanded in x around inf 49.5%
if 2.0000000000000001e26 < z < 4.3000000000000001e101 or 3.8000000000000003e113 < z Initial program 100.0%
Taylor expanded in z around inf 99.9%
clear-num99.9%
inv-pow99.9%
+-commutative99.9%
fma-define99.9%
log-rec99.9%
Applied egg-rr99.9%
unpow-199.9%
associate-/r*99.9%
fma-undefine99.9%
distribute-rgt-neg-in99.9%
neg-mul-199.9%
remove-double-neg99.9%
+-commutative99.9%
Simplified99.9%
Taylor expanded in z around inf 78.8%
mul-1-neg78.8%
*-commutative78.8%
distribute-rgt-neg-in78.8%
Simplified78.8%
Final simplification61.5%
(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 70.9%
associate-*r*70.9%
mul-1-neg70.9%
Simplified70.9%
fma-define70.9%
distribute-lft-neg-out70.9%
fmm-undef70.9%
Applied egg-rr70.9%
Final simplification70.9%
(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 38.4%
Final simplification38.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 2024095
(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)))))