
(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 11 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) (fma (- 1.0 z) y (* y (log z)))))
double code(double x, double y, double z) {
return (x * 0.5) + fma((1.0 - z), y, (y * log(z)));
}
function code(x, y, z) return Float64(Float64(x * 0.5) + fma(Float64(1.0 - z), y, Float64(y * log(z)))) end
code[x_, y_, z_] := N[(N[(x * 0.5), $MachinePrecision] + N[(N[(1.0 - z), $MachinePrecision] * y + N[(y * N[Log[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot 0.5 + \mathsf{fma}\left(1 - z, y, y \cdot \log z\right)
\end{array}
Initial program 99.9%
distribute-rgt-in99.9%
fma-define99.9%
Applied egg-rr99.9%
Final simplification99.9%
(FPCore (x y z) :precision binary64 (if (<= z 0.049) (+ (* x 0.5) (+ y (* y (log z)))) (fma y (- z) (* x 0.5))))
double code(double x, double y, double z) {
double tmp;
if (z <= 0.049) {
tmp = (x * 0.5) + (y + (y * log(z)));
} else {
tmp = fma(y, -z, (x * 0.5));
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (z <= 0.049) tmp = Float64(Float64(x * 0.5) + Float64(y + Float64(y * log(z)))); else tmp = fma(y, Float64(-z), Float64(x * 0.5)); end return tmp end
code[x_, y_, z_] := If[LessEqual[z, 0.049], N[(N[(x * 0.5), $MachinePrecision] + N[(y + N[(y * 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.049:\\
\;\;\;\;x \cdot 0.5 + \left(y + y \cdot \log z\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y, -z, x \cdot 0.5\right)\\
\end{array}
\end{array}
if z < 0.049000000000000002Initial program 99.8%
distribute-rgt-in99.8%
fma-define99.8%
Applied egg-rr99.8%
Taylor expanded in z around 0 98.8%
if 0.049000000000000002 < z Initial program 100.0%
+-commutative100.0%
fma-define100.0%
Simplified100.0%
Taylor expanded in z around inf 99.4%
neg-mul-199.4%
Simplified99.4%
(FPCore (x y z) :precision binary64 (if (<= z 0.049) (+ (* 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.049) {
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.049) 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.049], 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.049:\\
\;\;\;\;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.049000000000000002Initial program 99.8%
Taylor expanded in z around 0 98.8%
*-commutative98.8%
Simplified98.8%
if 0.049000000000000002 < z Initial program 100.0%
+-commutative100.0%
fma-define100.0%
Simplified100.0%
Taylor expanded in z around inf 99.4%
neg-mul-199.4%
Simplified99.4%
Final simplification99.1%
(FPCore (x y z) :precision binary64 (+ (* x 0.5) (+ (* y (log z)) (* (- 1.0 z) y))))
double code(double x, double y, double z) {
return (x * 0.5) + ((y * log(z)) + ((1.0 - z) * y));
}
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 * log(z)) + ((1.0d0 - z) * y))
end function
public static double code(double x, double y, double z) {
return (x * 0.5) + ((y * Math.log(z)) + ((1.0 - z) * y));
}
def code(x, y, z): return (x * 0.5) + ((y * math.log(z)) + ((1.0 - z) * y))
function code(x, y, z) return Float64(Float64(x * 0.5) + Float64(Float64(y * log(z)) + Float64(Float64(1.0 - z) * y))) end
function tmp = code(x, y, z) tmp = (x * 0.5) + ((y * log(z)) + ((1.0 - z) * y)); end
code[x_, y_, z_] := N[(N[(x * 0.5), $MachinePrecision] + N[(N[(y * N[Log[z], $MachinePrecision]), $MachinePrecision] + N[(N[(1.0 - z), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot 0.5 + \left(y \cdot \log z + \left(1 - z\right) \cdot y\right)
\end{array}
Initial program 99.9%
distribute-rgt-in99.9%
Applied egg-rr99.9%
Final simplification99.9%
(FPCore (x y z) :precision binary64 (if (<= z 1e-23) (+ y (* y (log z))) (fma y (- z) (* x 0.5))))
double code(double x, double y, double z) {
double tmp;
if (z <= 1e-23) {
tmp = y + (y * log(z));
} else {
tmp = fma(y, -z, (x * 0.5));
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (z <= 1e-23) tmp = Float64(y + Float64(y * log(z))); else tmp = fma(y, Float64(-z), Float64(x * 0.5)); end return tmp end
code[x_, y_, z_] := If[LessEqual[z, 1e-23], N[(y + N[(y * N[Log[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(y * (-z) + N[(x * 0.5), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 10^{-23}:\\
\;\;\;\;y + y \cdot \log z\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y, -z, x \cdot 0.5\right)\\
\end{array}
\end{array}
if z < 9.9999999999999996e-24Initial program 99.8%
distribute-rgt-in99.8%
fma-define99.8%
Applied egg-rr99.8%
Taylor expanded in z around 0 99.8%
Taylor expanded in x around 0 58.2%
if 9.9999999999999996e-24 < z Initial program 100.0%
+-commutative100.0%
fma-define100.0%
Simplified100.0%
Taylor expanded in z around inf 97.4%
neg-mul-197.4%
Simplified97.4%
(FPCore (x y z) :precision binary64 (+ (* x 0.5) (* y (- (+ 1.0 (log z)) z))))
double code(double x, double y, double z) {
return (x * 0.5) + (y * ((1.0 + log(z)) - 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 + log(z)) - z))
end function
public static double code(double x, double y, double z) {
return (x * 0.5) + (y * ((1.0 + Math.log(z)) - z));
}
def code(x, y, z): return (x * 0.5) + (y * ((1.0 + math.log(z)) - z))
function code(x, y, z) return Float64(Float64(x * 0.5) + Float64(y * Float64(Float64(1.0 + log(z)) - z))) end
function tmp = code(x, y, z) tmp = (x * 0.5) + (y * ((1.0 + log(z)) - z)); end
code[x_, y_, z_] := N[(N[(x * 0.5), $MachinePrecision] + N[(y * N[(N[(1.0 + N[Log[z], $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot 0.5 + y \cdot \left(\left(1 + \log z\right) - z\right)
\end{array}
Initial program 99.9%
+-commutative99.9%
associate-+r-99.9%
Applied egg-rr99.9%
Final simplification99.9%
(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 2.05e-22) (+ y (* y (log z))) (- (* x 0.5) (* z y))))
double code(double x, double y, double z) {
double tmp;
if (z <= 2.05e-22) {
tmp = y + (y * log(z));
} else {
tmp = (x * 0.5) - (z * y);
}
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.05d-22) then
tmp = y + (y * log(z))
else
tmp = (x * 0.5d0) - (z * y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= 2.05e-22) {
tmp = y + (y * Math.log(z));
} else {
tmp = (x * 0.5) - (z * y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= 2.05e-22: tmp = y + (y * math.log(z)) else: tmp = (x * 0.5) - (z * y) return tmp
function code(x, y, z) tmp = 0.0 if (z <= 2.05e-22) tmp = Float64(y + Float64(y * log(z))); else tmp = Float64(Float64(x * 0.5) - Float64(z * y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= 2.05e-22) tmp = y + (y * log(z)); else tmp = (x * 0.5) - (z * y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, 2.05e-22], N[(y + N[(y * N[Log[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x * 0.5), $MachinePrecision] - N[(z * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 2.05 \cdot 10^{-22}:\\
\;\;\;\;y + y \cdot \log z\\
\mathbf{else}:\\
\;\;\;\;x \cdot 0.5 - z \cdot y\\
\end{array}
\end{array}
if z < 2.05e-22Initial program 99.8%
distribute-rgt-in99.8%
fma-define99.8%
Applied egg-rr99.8%
Taylor expanded in z around 0 99.8%
Taylor expanded in x around 0 58.2%
if 2.05e-22 < z Initial program 100.0%
Taylor expanded in z around inf 97.4%
associate-*r*97.4%
mul-1-neg97.4%
Simplified97.4%
fma-define97.4%
distribute-lft-neg-out97.4%
fmm-undef97.4%
Applied egg-rr97.4%
Final simplification78.4%
(FPCore (x y z) :precision binary64 (if (<= z 4.5e+64) (* x 0.5) (* z (- y))))
double code(double x, double y, double z) {
double tmp;
if (z <= 4.5e+64) {
tmp = x * 0.5;
} else {
tmp = z * -y;
}
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.5d+64) then
tmp = x * 0.5d0
else
tmp = z * -y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= 4.5e+64) {
tmp = x * 0.5;
} else {
tmp = z * -y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= 4.5e+64: tmp = x * 0.5 else: tmp = z * -y return tmp
function code(x, y, z) tmp = 0.0 if (z <= 4.5e+64) tmp = Float64(x * 0.5); else tmp = Float64(z * Float64(-y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= 4.5e+64) tmp = x * 0.5; else tmp = z * -y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, 4.5e+64], N[(x * 0.5), $MachinePrecision], N[(z * (-y)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 4.5 \cdot 10^{+64}:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(-y\right)\\
\end{array}
\end{array}
if z < 4.49999999999999973e64Initial program 99.8%
+-commutative99.8%
fma-define99.8%
Simplified99.8%
Taylor expanded in x around inf 86.7%
Taylor expanded in y around 0 45.0%
if 4.49999999999999973e64 < 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 z around inf 100.0%
neg-mul-1100.0%
+-commutative100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in z around inf 82.8%
mul-1-neg82.8%
distribute-lft-neg-out82.8%
*-commutative82.8%
Simplified82.8%
(FPCore (x y z) :precision binary64 (- (* x 0.5) (* z y)))
double code(double x, double y, double z) {
return (x * 0.5) - (z * y);
}
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) - (z * y)
end function
public static double code(double x, double y, double z) {
return (x * 0.5) - (z * y);
}
def code(x, y, z): return (x * 0.5) - (z * y)
function code(x, y, z) return Float64(Float64(x * 0.5) - Float64(z * y)) end
function tmp = code(x, y, z) tmp = (x * 0.5) - (z * y); end
code[x_, y_, z_] := N[(N[(x * 0.5), $MachinePrecision] - N[(z * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot 0.5 - z \cdot y
\end{array}
Initial program 99.9%
Taylor expanded in z around inf 71.4%
associate-*r*71.4%
mul-1-neg71.4%
Simplified71.4%
fma-define71.4%
distribute-lft-neg-out71.4%
fmm-undef71.4%
Applied egg-rr71.4%
Final simplification71.4%
(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%
+-commutative99.9%
fma-define99.9%
Simplified99.9%
Taylor expanded in x around inf 88.5%
Taylor expanded in y around 0 35.0%
(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 2024157
(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)))))