
(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 (* (- (log z) z) y))))
double code(double x, double y, double z) {
return (x * 0.5) + (y + ((log(z) - 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) - z) * y))
end function
public static double code(double x, double y, double z) {
return (x * 0.5) + (y + ((Math.log(z) - z) * y));
}
def code(x, y, z): return (x * 0.5) + (y + ((math.log(z) - z) * y))
function code(x, y, z) return Float64(Float64(x * 0.5) + Float64(y + Float64(Float64(log(z) - z) * y))) end
function tmp = code(x, y, z) tmp = (x * 0.5) + (y + ((log(z) - z) * y)); end
code[x_, y_, z_] := N[(N[(x * 0.5), $MachinePrecision] + N[(y + N[(N[(N[Log[z], $MachinePrecision] - z), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot 0.5 + \left(y + \left(\log z - z\right) \cdot y\right)
\end{array}
Initial program 99.9%
+-commutative99.9%
sub-neg99.9%
+-commutative99.9%
associate-+l+99.9%
sub-neg99.9%
distribute-rgt-in99.9%
*-un-lft-identity99.9%
Applied egg-rr99.9%
Final simplification99.9%
(FPCore (x y z) :precision binary64 (if (or (<= y -130000000.0) (not (<= y 3.3e+80))) (+ y (* (- (log z) z) y)) (- (* x 0.5) (* z y))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -130000000.0) || !(y <= 3.3e+80)) {
tmp = y + ((log(z) - z) * y);
} 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 ((y <= (-130000000.0d0)) .or. (.not. (y <= 3.3d+80))) then
tmp = y + ((log(z) - z) * y)
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 ((y <= -130000000.0) || !(y <= 3.3e+80)) {
tmp = y + ((Math.log(z) - z) * y);
} else {
tmp = (x * 0.5) - (z * y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -130000000.0) or not (y <= 3.3e+80): tmp = y + ((math.log(z) - z) * y) else: tmp = (x * 0.5) - (z * y) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -130000000.0) || !(y <= 3.3e+80)) tmp = Float64(y + Float64(Float64(log(z) - z) * y)); 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 ((y <= -130000000.0) || ~((y <= 3.3e+80))) tmp = y + ((log(z) - z) * y); else tmp = (x * 0.5) - (z * y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -130000000.0], N[Not[LessEqual[y, 3.3e+80]], $MachinePrecision]], N[(y + N[(N[(N[Log[z], $MachinePrecision] - z), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision], N[(N[(x * 0.5), $MachinePrecision] - N[(z * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -130000000 \lor \neg \left(y \leq 3.3 \cdot 10^{+80}\right):\\
\;\;\;\;y + \left(\log z - z\right) \cdot y\\
\mathbf{else}:\\
\;\;\;\;x \cdot 0.5 - z \cdot y\\
\end{array}
\end{array}
if y < -1.3e8 or 3.29999999999999991e80 < y Initial program 99.8%
+-commutative99.8%
sub-neg99.8%
+-commutative99.8%
associate-+l+99.8%
sub-neg99.8%
distribute-rgt-in99.8%
*-un-lft-identity99.8%
Applied egg-rr99.8%
Taylor expanded in x around 0 87.5%
if -1.3e8 < y < 3.29999999999999991e80Initial program 99.9%
Taylor expanded in z around inf 89.7%
mul-1-neg89.7%
distribute-rgt-neg-out89.7%
Simplified89.7%
distribute-rgt-neg-out89.7%
unsub-neg89.7%
Applied egg-rr89.7%
Final simplification88.7%
(FPCore (x y z) :precision binary64 (if (<= z 0.56) (+ (* x 0.5) (* y (+ (log z) 1.0))) (+ (* x 0.5) (* y (- 1.0 z)))))
double code(double x, double y, double z) {
double tmp;
if (z <= 0.56) {
tmp = (x * 0.5) + (y * (log(z) + 1.0));
} else {
tmp = (x * 0.5) + (y * (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 (z <= 0.56d0) then
tmp = (x * 0.5d0) + (y * (log(z) + 1.0d0))
else
tmp = (x * 0.5d0) + (y * (1.0d0 - z))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= 0.56) {
tmp = (x * 0.5) + (y * (Math.log(z) + 1.0));
} else {
tmp = (x * 0.5) + (y * (1.0 - z));
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= 0.56: tmp = (x * 0.5) + (y * (math.log(z) + 1.0)) else: tmp = (x * 0.5) + (y * (1.0 - z)) return tmp
function code(x, y, z) tmp = 0.0 if (z <= 0.56) tmp = Float64(Float64(x * 0.5) + Float64(y * Float64(log(z) + 1.0))); else tmp = Float64(Float64(x * 0.5) + Float64(y * Float64(1.0 - z))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= 0.56) tmp = (x * 0.5) + (y * (log(z) + 1.0)); else tmp = (x * 0.5) + (y * (1.0 - z)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, 0.56], N[(N[(x * 0.5), $MachinePrecision] + N[(y * N[(N[Log[z], $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x * 0.5), $MachinePrecision] + N[(y * N[(1.0 - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 0.56:\\
\;\;\;\;x \cdot 0.5 + y \cdot \left(\log z + 1\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot 0.5 + y \cdot \left(1 - z\right)\\
\end{array}
\end{array}
if z < 0.56000000000000005Initial program 99.7%
Taylor expanded in z around 0 98.1%
if 0.56000000000000005 < z Initial program 100.0%
+-commutative100.0%
sub-neg100.0%
+-commutative100.0%
associate-+l+100.0%
sub-neg100.0%
distribute-rgt-in100.0%
*-un-lft-identity100.0%
Applied egg-rr100.0%
flip--47.3%
clear-num47.3%
*-un-lft-identity47.3%
associate-/l*47.3%
flip--71.1%
Applied egg-rr99.9%
Taylor expanded in z around inf 99.4%
mul-1-neg70.6%
Simplified99.4%
Taylor expanded in z around 0 99.4%
remove-double-neg99.4%
neg-mul-199.4%
neg-mul-199.4%
associate-*r*99.4%
metadata-eval99.4%
*-commutative99.4%
associate-*r*99.4%
distribute-rgt-in99.4%
mul-1-neg99.4%
sub-neg99.4%
Simplified99.4%
Final simplification98.8%
(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 (<= z 5e+89) (* x 0.5) (- y (* z y))))
double code(double x, double y, double z) {
double tmp;
if (z <= 5e+89) {
tmp = x * 0.5;
} else {
tmp = y - (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 <= 5d+89) then
tmp = x * 0.5d0
else
tmp = y - (z * y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= 5e+89) {
tmp = x * 0.5;
} else {
tmp = y - (z * y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= 5e+89: tmp = x * 0.5 else: tmp = y - (z * y) return tmp
function code(x, y, z) tmp = 0.0 if (z <= 5e+89) tmp = Float64(x * 0.5); else tmp = Float64(y - Float64(z * y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= 5e+89) tmp = x * 0.5; else tmp = y - (z * y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, 5e+89], N[(x * 0.5), $MachinePrecision], N[(y - N[(z * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 5 \cdot 10^{+89}:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;y - z \cdot y\\
\end{array}
\end{array}
if z < 4.99999999999999983e89Initial program 99.8%
Taylor expanded in x around inf 53.9%
if 4.99999999999999983e89 < z Initial program 100.0%
+-commutative100.0%
sub-neg100.0%
+-commutative100.0%
associate-+l+100.0%
sub-neg100.0%
distribute-rgt-in100.0%
*-un-lft-identity100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 81.4%
flip--51.0%
clear-num50.9%
*-un-lft-identity50.9%
associate-/l*50.9%
flip--81.3%
Applied egg-rr81.3%
Taylor expanded in z around inf 81.4%
mul-1-neg81.4%
Simplified81.4%
Final simplification64.9%
(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 76.3%
mul-1-neg76.3%
distribute-rgt-neg-out76.3%
Simplified76.3%
distribute-rgt-neg-out76.3%
unsub-neg76.3%
Applied egg-rr76.3%
Final simplification76.3%
(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 40.0%
Final simplification40.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 2023301
(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)))))