
(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 (log z))) (* y z))))
double code(double x, double y, double z) {
return (x * 0.5) - ((y * (-1.0 - log(z))) + (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 * ((-1.0d0) - log(z))) + (y * z))
end function
public static double code(double x, double y, double z) {
return (x * 0.5) - ((y * (-1.0 - Math.log(z))) + (y * z));
}
def code(x, y, z): return (x * 0.5) - ((y * (-1.0 - math.log(z))) + (y * z))
function code(x, y, z) return Float64(Float64(x * 0.5) - Float64(Float64(y * Float64(-1.0 - log(z))) + Float64(y * z))) end
function tmp = code(x, y, z) tmp = (x * 0.5) - ((y * (-1.0 - log(z))) + (y * z)); end
code[x_, y_, z_] := N[(N[(x * 0.5), $MachinePrecision] - N[(N[(y * N[(-1.0 - N[Log[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot 0.5 - \left(y \cdot \left(-1 - \log z\right) + y \cdot z\right)
\end{array}
Initial program 99.9%
cancel-sign-sub99.9%
*-commutative99.9%
*-commutative99.9%
distribute-lft-neg-out99.9%
distribute-rgt-neg-in99.9%
distribute-neg-in99.9%
unsub-neg99.9%
neg-sub099.9%
associate--r-99.9%
metadata-eval99.9%
+-commutative99.9%
associate--l+99.9%
Simplified99.9%
+-commutative99.9%
distribute-lft-in99.9%
Applied egg-rr99.9%
Final simplification99.9%
(FPCore (x y z) :precision binary64 (if (or (<= (* x 0.5) -5e-32) (not (<= (* x 0.5) 5e-16))) (- (* x 0.5) (* y z)) (* y (- (+ (log z) 1.0) z))))
double code(double x, double y, double z) {
double tmp;
if (((x * 0.5) <= -5e-32) || !((x * 0.5) <= 5e-16)) {
tmp = (x * 0.5) - (y * z);
} else {
tmp = y * ((log(z) + 1.0) - 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) <= (-5d-32)) .or. (.not. ((x * 0.5d0) <= 5d-16))) then
tmp = (x * 0.5d0) - (y * z)
else
tmp = y * ((log(z) + 1.0d0) - z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (((x * 0.5) <= -5e-32) || !((x * 0.5) <= 5e-16)) {
tmp = (x * 0.5) - (y * z);
} else {
tmp = y * ((Math.log(z) + 1.0) - z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if ((x * 0.5) <= -5e-32) or not ((x * 0.5) <= 5e-16): tmp = (x * 0.5) - (y * z) else: tmp = y * ((math.log(z) + 1.0) - z) return tmp
function code(x, y, z) tmp = 0.0 if ((Float64(x * 0.5) <= -5e-32) || !(Float64(x * 0.5) <= 5e-16)) tmp = Float64(Float64(x * 0.5) - Float64(y * z)); else tmp = Float64(y * Float64(Float64(log(z) + 1.0) - z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (((x * 0.5) <= -5e-32) || ~(((x * 0.5) <= 5e-16))) tmp = (x * 0.5) - (y * z); else tmp = y * ((log(z) + 1.0) - z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[N[(x * 0.5), $MachinePrecision], -5e-32], N[Not[LessEqual[N[(x * 0.5), $MachinePrecision], 5e-16]], $MachinePrecision]], N[(N[(x * 0.5), $MachinePrecision] - N[(y * z), $MachinePrecision]), $MachinePrecision], N[(y * N[(N[(N[Log[z], $MachinePrecision] + 1.0), $MachinePrecision] - z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot 0.5 \leq -5 \cdot 10^{-32} \lor \neg \left(x \cdot 0.5 \leq 5 \cdot 10^{-16}\right):\\
\;\;\;\;x \cdot 0.5 - y \cdot z\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(\left(\log z + 1\right) - z\right)\\
\end{array}
\end{array}
if (*.f64 x 1/2) < -5e-32 or 5.0000000000000004e-16 < (*.f64 x 1/2) Initial program 100.0%
cancel-sign-sub100.0%
*-commutative100.0%
*-commutative100.0%
distribute-lft-neg-out100.0%
distribute-rgt-neg-in100.0%
distribute-neg-in100.0%
unsub-neg100.0%
neg-sub0100.0%
associate--r-100.0%
metadata-eval100.0%
+-commutative100.0%
associate--l+100.0%
Simplified100.0%
Taylor expanded in z around inf 89.3%
if -5e-32 < (*.f64 x 1/2) < 5.0000000000000004e-16Initial program 99.8%
cancel-sign-sub99.8%
*-commutative99.8%
*-commutative99.8%
distribute-lft-neg-out99.8%
distribute-rgt-neg-in99.8%
distribute-neg-in99.8%
unsub-neg99.8%
neg-sub099.8%
associate--r-99.8%
metadata-eval99.8%
+-commutative99.8%
associate--l+99.8%
Simplified99.8%
Taylor expanded in y around inf 90.0%
Final simplification89.6%
(FPCore (x y z) :precision binary64 (if (<= z 1.04e-10) (- (* 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 <= 1.04e-10) {
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 <= 1.04d-10) 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 <= 1.04e-10) {
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 <= 1.04e-10: 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 <= 1.04e-10) 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 <= 1.04e-10) 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, 1.04e-10], 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 1.04 \cdot 10^{-10}:\\
\;\;\;\;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 < 1.04e-10Initial program 99.9%
cancel-sign-sub99.9%
*-commutative99.9%
*-commutative99.9%
distribute-lft-neg-out99.9%
distribute-rgt-neg-in99.9%
distribute-neg-in99.9%
unsub-neg99.9%
neg-sub099.9%
associate--r-99.9%
metadata-eval99.9%
+-commutative99.9%
associate--l+99.9%
Simplified99.9%
Taylor expanded in z around 0 99.7%
mul-1-neg99.7%
distribute-rgt-neg-in99.7%
mul-1-neg99.7%
distribute-lft-in99.7%
metadata-eval99.7%
neg-mul-199.7%
sub-neg99.7%
Simplified99.7%
if 1.04e-10 < z Initial program 99.9%
cancel-sign-sub99.9%
*-commutative99.9%
*-commutative99.9%
distribute-lft-neg-out99.9%
distribute-rgt-neg-in99.9%
distribute-neg-in99.9%
unsub-neg99.9%
neg-sub099.9%
associate--r-99.9%
metadata-eval99.9%
+-commutative99.9%
associate--l+99.9%
Simplified99.9%
Taylor expanded in z around inf 98.4%
Final simplification99.0%
(FPCore (x y z) :precision binary64 (+ (* x 0.5) (* y (+ (log z) (- 1.0 z)))))
double code(double x, double y, double z) {
return (x * 0.5) + (y * (log(z) + (1.0 - 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 * (log(z) + (1.0d0 - z)))
end function
public static double code(double x, double y, double z) {
return (x * 0.5) + (y * (Math.log(z) + (1.0 - z)));
}
def code(x, y, z): return (x * 0.5) + (y * (math.log(z) + (1.0 - z)))
function code(x, y, z) return Float64(Float64(x * 0.5) + Float64(y * Float64(log(z) + Float64(1.0 - z)))) end
function tmp = code(x, y, z) tmp = (x * 0.5) + (y * (log(z) + (1.0 - z))); end
code[x_, y_, z_] := N[(N[(x * 0.5), $MachinePrecision] + N[(y * N[(N[Log[z], $MachinePrecision] + N[(1.0 - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot 0.5 + y \cdot \left(\log z + \left(1 - z\right)\right)
\end{array}
Initial program 99.9%
Final simplification99.9%
(FPCore (x y z) :precision binary64 (if (or (<= z 95000000.0) (and (not (<= z 9e+45)) (<= z 7.6e+73))) (* x 0.5) (* z (- y))))
double code(double x, double y, double z) {
double tmp;
if ((z <= 95000000.0) || (!(z <= 9e+45) && (z <= 7.6e+73))) {
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 <= 95000000.0d0) .or. (.not. (z <= 9d+45)) .and. (z <= 7.6d+73)) 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 <= 95000000.0) || (!(z <= 9e+45) && (z <= 7.6e+73))) {
tmp = x * 0.5;
} else {
tmp = z * -y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= 95000000.0) or (not (z <= 9e+45) and (z <= 7.6e+73)): tmp = x * 0.5 else: tmp = z * -y return tmp
function code(x, y, z) tmp = 0.0 if ((z <= 95000000.0) || (!(z <= 9e+45) && (z <= 7.6e+73))) 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 <= 95000000.0) || (~((z <= 9e+45)) && (z <= 7.6e+73))) tmp = x * 0.5; else tmp = z * -y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, 95000000.0], And[N[Not[LessEqual[z, 9e+45]], $MachinePrecision], LessEqual[z, 7.6e+73]]], N[(x * 0.5), $MachinePrecision], N[(z * (-y)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 95000000 \lor \neg \left(z \leq 9 \cdot 10^{+45}\right) \land z \leq 7.6 \cdot 10^{+73}:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(-y\right)\\
\end{array}
\end{array}
if z < 9.5e7 or 8.9999999999999997e45 < z < 7.60000000000000044e73Initial program 99.8%
cancel-sign-sub99.8%
*-commutative99.8%
*-commutative99.8%
distribute-lft-neg-out99.8%
distribute-rgt-neg-in99.8%
distribute-neg-in99.8%
unsub-neg99.8%
neg-sub099.8%
associate--r-99.8%
metadata-eval99.8%
+-commutative99.8%
associate--l+99.8%
Simplified99.8%
Taylor expanded in x around inf 57.6%
if 9.5e7 < z < 8.9999999999999997e45 or 7.60000000000000044e73 < z Initial program 100.0%
cancel-sign-sub100.0%
*-commutative100.0%
*-commutative100.0%
distribute-lft-neg-out100.0%
distribute-rgt-neg-in100.0%
distribute-neg-in100.0%
unsub-neg100.0%
neg-sub0100.0%
associate--r-100.0%
metadata-eval100.0%
+-commutative100.0%
associate--l+100.0%
Simplified100.0%
Taylor expanded in z around inf 75.4%
associate-*r*75.4%
neg-mul-175.4%
Simplified75.4%
Final simplification66.1%
(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%
cancel-sign-sub99.9%
*-commutative99.9%
*-commutative99.9%
distribute-lft-neg-out99.9%
distribute-rgt-neg-in99.9%
distribute-neg-in99.9%
unsub-neg99.9%
neg-sub099.9%
associate--r-99.9%
metadata-eval99.9%
+-commutative99.9%
associate--l+99.9%
Simplified99.9%
Taylor expanded in z around inf 78.9%
Final simplification78.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%
cancel-sign-sub99.9%
*-commutative99.9%
*-commutative99.9%
distribute-lft-neg-out99.9%
distribute-rgt-neg-in99.9%
distribute-neg-in99.9%
unsub-neg99.9%
neg-sub099.9%
associate--r-99.9%
metadata-eval99.9%
+-commutative99.9%
associate--l+99.9%
Simplified99.9%
Taylor expanded in x around inf 42.1%
Final simplification42.1%
(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 2024048
(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)))))