
(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))) (* y (log z))))
double code(double x, double y, double z) {
return ((x * 0.5) + (y * (1.0 - z))) + (y * 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))) + (y * log(z))
end function
public static double code(double x, double y, double z) {
return ((x * 0.5) + (y * (1.0 - z))) + (y * Math.log(z));
}
def code(x, y, z): return ((x * 0.5) + (y * (1.0 - z))) + (y * math.log(z))
function code(x, y, z) return Float64(Float64(Float64(x * 0.5) + Float64(y * Float64(1.0 - z))) + Float64(y * log(z))) end
function tmp = code(x, y, z) tmp = ((x * 0.5) + (y * (1.0 - z))) + (y * log(z)); end
code[x_, y_, z_] := N[(N[(N[(x * 0.5), $MachinePrecision] + N[(y * N[(1.0 - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(y * N[Log[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x \cdot 0.5 + y \cdot \left(1 - z\right)\right) + y \cdot \log z
\end{array}
Initial program 99.9%
Applied egg-rr0
(FPCore (x y z)
:precision binary64
(let* ((t_0 (+ (* x 0.5) (* y (- z)))))
(if (<= (* x 0.5) -5e-101)
t_0
(if (<= (* x 0.5) 5e-44) (* y (+ 1.0 (- (log z) z))) t_0))))
double code(double x, double y, double z) {
double t_0 = (x * 0.5) + (y * -z);
double tmp;
if ((x * 0.5) <= -5e-101) {
tmp = t_0;
} else if ((x * 0.5) <= 5e-44) {
tmp = y * (1.0 + (log(z) - z));
} else {
tmp = t_0;
}
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) :: t_0
real(8) :: tmp
t_0 = (x * 0.5d0) + (y * -z)
if ((x * 0.5d0) <= (-5d-101)) then
tmp = t_0
else if ((x * 0.5d0) <= 5d-44) then
tmp = y * (1.0d0 + (log(z) - z))
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = (x * 0.5) + (y * -z);
double tmp;
if ((x * 0.5) <= -5e-101) {
tmp = t_0;
} else if ((x * 0.5) <= 5e-44) {
tmp = y * (1.0 + (Math.log(z) - z));
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = (x * 0.5) + (y * -z) tmp = 0 if (x * 0.5) <= -5e-101: tmp = t_0 elif (x * 0.5) <= 5e-44: tmp = y * (1.0 + (math.log(z) - z)) else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(Float64(x * 0.5) + Float64(y * Float64(-z))) tmp = 0.0 if (Float64(x * 0.5) <= -5e-101) tmp = t_0; elseif (Float64(x * 0.5) <= 5e-44) tmp = Float64(y * Float64(1.0 + Float64(log(z) - z))); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = (x * 0.5) + (y * -z); tmp = 0.0; if ((x * 0.5) <= -5e-101) tmp = t_0; elseif ((x * 0.5) <= 5e-44) tmp = y * (1.0 + (log(z) - z)); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(x * 0.5), $MachinePrecision] + N[(y * (-z)), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(x * 0.5), $MachinePrecision], -5e-101], t$95$0, If[LessEqual[N[(x * 0.5), $MachinePrecision], 5e-44], N[(y * N[(1.0 + N[(N[Log[z], $MachinePrecision] - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot 0.5 + y \cdot \left(-z\right)\\
\mathbf{if}\;x \cdot 0.5 \leq -5 \cdot 10^{-101}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \cdot 0.5 \leq 5 \cdot 10^{-44}:\\
\;\;\;\;y \cdot \left(1 + \left(\log z - z\right)\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if (*.f64 x #s(literal 1/2 binary64)) < -5.0000000000000001e-101 or 5.00000000000000039e-44 < (*.f64 x #s(literal 1/2 binary64)) Initial program 100.0%
Applied egg-rr0
Taylor expanded in z around inf 0
Simplified0
Taylor expanded in z around inf 0
Simplified0
if -5.0000000000000001e-101 < (*.f64 x #s(literal 1/2 binary64)) < 5.00000000000000039e-44Initial program 99.7%
Taylor expanded in x around 0 0
Simplified0
(FPCore (x y z)
:precision binary64
(let* ((t_0 (+ (* x 0.5) (* y (- z)))))
(if (<= (* x 0.5) 2e-223)
t_0
(if (<= (* x 0.5) 4e-200) (* y (+ (log z) 1.0)) t_0))))
double code(double x, double y, double z) {
double t_0 = (x * 0.5) + (y * -z);
double tmp;
if ((x * 0.5) <= 2e-223) {
tmp = t_0;
} else if ((x * 0.5) <= 4e-200) {
tmp = y * (log(z) + 1.0);
} else {
tmp = t_0;
}
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) :: t_0
real(8) :: tmp
t_0 = (x * 0.5d0) + (y * -z)
if ((x * 0.5d0) <= 2d-223) then
tmp = t_0
else if ((x * 0.5d0) <= 4d-200) then
tmp = y * (log(z) + 1.0d0)
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = (x * 0.5) + (y * -z);
double tmp;
if ((x * 0.5) <= 2e-223) {
tmp = t_0;
} else if ((x * 0.5) <= 4e-200) {
tmp = y * (Math.log(z) + 1.0);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = (x * 0.5) + (y * -z) tmp = 0 if (x * 0.5) <= 2e-223: tmp = t_0 elif (x * 0.5) <= 4e-200: tmp = y * (math.log(z) + 1.0) else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(Float64(x * 0.5) + Float64(y * Float64(-z))) tmp = 0.0 if (Float64(x * 0.5) <= 2e-223) tmp = t_0; elseif (Float64(x * 0.5) <= 4e-200) tmp = Float64(y * Float64(log(z) + 1.0)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = (x * 0.5) + (y * -z); tmp = 0.0; if ((x * 0.5) <= 2e-223) tmp = t_0; elseif ((x * 0.5) <= 4e-200) tmp = y * (log(z) + 1.0); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(x * 0.5), $MachinePrecision] + N[(y * (-z)), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(x * 0.5), $MachinePrecision], 2e-223], t$95$0, If[LessEqual[N[(x * 0.5), $MachinePrecision], 4e-200], N[(y * N[(N[Log[z], $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot 0.5 + y \cdot \left(-z\right)\\
\mathbf{if}\;x \cdot 0.5 \leq 2 \cdot 10^{-223}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \cdot 0.5 \leq 4 \cdot 10^{-200}:\\
\;\;\;\;y \cdot \left(\log z + 1\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if (*.f64 x #s(literal 1/2 binary64)) < 1.9999999999999999e-223 or 3.9999999999999999e-200 < (*.f64 x #s(literal 1/2 binary64)) Initial program 99.9%
Applied egg-rr0
Taylor expanded in z around inf 0
Simplified0
Taylor expanded in z around inf 0
Simplified0
if 1.9999999999999999e-223 < (*.f64 x #s(literal 1/2 binary64)) < 3.9999999999999999e-200Initial program 100.0%
Taylor expanded in z around 0 0
Simplified0
Taylor expanded in y around inf 0
Simplified0
(FPCore (x y z) :precision binary64 (if (<= z 0.28) (+ (* y (+ 1.0 (log z))) (* 0.5 x)) (+ (* x 0.5) (* y (- z)))))
double code(double x, double y, double z) {
double tmp;
if (z <= 0.28) {
tmp = (y * (1.0 + log(z))) + (0.5 * x);
} 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.28d0) then
tmp = (y * (1.0d0 + log(z))) + (0.5d0 * x)
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.28) {
tmp = (y * (1.0 + Math.log(z))) + (0.5 * x);
} else {
tmp = (x * 0.5) + (y * -z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= 0.28: tmp = (y * (1.0 + math.log(z))) + (0.5 * x) else: tmp = (x * 0.5) + (y * -z) return tmp
function code(x, y, z) tmp = 0.0 if (z <= 0.28) tmp = Float64(Float64(y * Float64(1.0 + log(z))) + Float64(0.5 * x)); else tmp = Float64(Float64(x * 0.5) + Float64(y * Float64(-z))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= 0.28) tmp = (y * (1.0 + log(z))) + (0.5 * x); else tmp = (x * 0.5) + (y * -z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, 0.28], N[(N[(y * N[(1.0 + N[Log[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(0.5 * x), $MachinePrecision]), $MachinePrecision], N[(N[(x * 0.5), $MachinePrecision] + N[(y * (-z)), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 0.28:\\
\;\;\;\;y \cdot \left(1 + \log z\right) + 0.5 \cdot x\\
\mathbf{else}:\\
\;\;\;\;x \cdot 0.5 + y \cdot \left(-z\right)\\
\end{array}
\end{array}
if z < 0.28000000000000003Initial program 99.8%
Taylor expanded in z around 0 0
Simplified0
if 0.28000000000000003 < z Initial program 100.0%
Applied egg-rr0
Taylor expanded in z around inf 0
Simplified0
Taylor expanded in z around inf 0
Simplified0
(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 (<= z 13500000000000.0) (* 0.5 x) (- (* y z))))
double code(double x, double y, double z) {
double tmp;
if (z <= 13500000000000.0) {
tmp = 0.5 * x;
} 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 <= 13500000000000.0d0) then
tmp = 0.5d0 * x
else
tmp = -(y * z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= 13500000000000.0) {
tmp = 0.5 * x;
} else {
tmp = -(y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= 13500000000000.0: tmp = 0.5 * x else: tmp = -(y * z) return tmp
function code(x, y, z) tmp = 0.0 if (z <= 13500000000000.0) tmp = Float64(0.5 * x); else tmp = Float64(-Float64(y * z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= 13500000000000.0) tmp = 0.5 * x; else tmp = -(y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, 13500000000000.0], N[(0.5 * x), $MachinePrecision], (-N[(y * z), $MachinePrecision])]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 13500000000000:\\
\;\;\;\;0.5 \cdot x\\
\mathbf{else}:\\
\;\;\;\;-y \cdot z\\
\end{array}
\end{array}
if z < 1.35e13Initial program 99.8%
Taylor expanded in x around inf 0
Simplified0
if 1.35e13 < z Initial program 100.0%
Taylor expanded in z around inf 0
Simplified0
Applied egg-rr0
(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 * Float64(-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 \left(-z\right)
\end{array}
Initial program 99.9%
Applied egg-rr0
Taylor expanded in z around inf 0
Simplified0
Taylor expanded in z around inf 0
Simplified0
(FPCore (x y z) :precision binary64 (* 0.5 x))
double code(double x, double y, double z) {
return 0.5 * x;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = 0.5d0 * x
end function
public static double code(double x, double y, double z) {
return 0.5 * x;
}
def code(x, y, z): return 0.5 * x
function code(x, y, z) return Float64(0.5 * x) end
function tmp = code(x, y, z) tmp = 0.5 * x; end
code[x_, y_, z_] := N[(0.5 * x), $MachinePrecision]
\begin{array}{l}
\\
0.5 \cdot x
\end{array}
Initial program 99.9%
Taylor expanded in x around inf 0
Simplified0
(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 2024110
(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)))))