
(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 9 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%
Taylor expanded in z around 0 99.9%
Final simplification99.9%
(FPCore (x y z) :precision binary64 (if (or (<= (* x 0.5) -5e-68) (not (<= (* x 0.5) 2e-97))) (- (* 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) <= -5e-68) || !((x * 0.5) <= 2e-97)) {
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) <= (-5d-68)) .or. (.not. ((x * 0.5d0) <= 2d-97))) 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) <= -5e-68) || !((x * 0.5) <= 2e-97)) {
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) <= -5e-68) or not ((x * 0.5) <= 2e-97): 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) <= -5e-68) || !(Float64(x * 0.5) <= 2e-97)) 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) <= -5e-68) || ~(((x * 0.5) <= 2e-97))) 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], -5e-68], N[Not[LessEqual[N[(x * 0.5), $MachinePrecision], 2e-97]], $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 -5 \cdot 10^{-68} \lor \neg \left(x \cdot 0.5 \leq 2 \cdot 10^{-97}\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 1/2) < -4.99999999999999971e-68 or 2.00000000000000007e-97 < (*.f64 x 1/2) Initial program 99.9%
Taylor expanded in z around inf 87.7%
mul-1-neg87.7%
distribute-rgt-neg-out87.7%
Simplified87.7%
if -4.99999999999999971e-68 < (*.f64 x 1/2) < 2.00000000000000007e-97Initial program 99.8%
sub-neg99.8%
associate-+l+99.8%
distribute-lft-in99.7%
*-rgt-identity99.7%
associate-+r+99.7%
fma-def99.7%
+-commutative99.7%
unsub-neg99.7%
Simplified99.7%
Taylor expanded in y around -inf 89.7%
mul-1-neg89.7%
distribute-rgt-neg-in89.7%
sub-neg89.7%
mul-1-neg89.7%
sub-neg89.7%
+-commutative89.7%
distribute-neg-in89.7%
remove-double-neg89.7%
sub-neg89.7%
metadata-eval89.7%
+-commutative89.7%
Simplified89.7%
Taylor expanded in y around 0 89.7%
Final simplification88.5%
(FPCore (x y z) :precision binary64 (if (<= z 0.28) (+ (* y (log z)) (+ (* x 0.5) y)) (- (* x 0.5) (* y z))))
double code(double x, double y, double z) {
double tmp;
if (z <= 0.28) {
tmp = (y * log(z)) + ((x * 0.5) + y);
} 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 * log(z)) + ((x * 0.5d0) + y)
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 * Math.log(z)) + ((x * 0.5) + y);
} else {
tmp = (x * 0.5) - (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= 0.28: tmp = (y * math.log(z)) + ((x * 0.5) + y) 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 * log(z)) + Float64(Float64(x * 0.5) + y)); 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 <= 0.28) tmp = (y * log(z)) + ((x * 0.5) + y); 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[Log[z], $MachinePrecision]), $MachinePrecision] + N[(N[(x * 0.5), $MachinePrecision] + y), $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 \log z + \left(x \cdot 0.5 + y\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot 0.5 - y \cdot z\\
\end{array}
\end{array}
if z < 0.28000000000000003Initial program 99.8%
sub-neg99.8%
associate-+l+99.8%
distribute-lft-in99.7%
*-rgt-identity99.7%
associate-+r+99.7%
fma-def99.7%
+-commutative99.7%
unsub-neg99.7%
Simplified99.7%
Taylor expanded in z around 0 98.9%
if 0.28000000000000003 < z Initial program 100.0%
Taylor expanded in z around inf 97.1%
mul-1-neg97.1%
distribute-rgt-neg-out97.1%
Simplified97.1%
Final simplification98.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 (<= z 1.7e-210) (* y (+ 1.0 (log z))) (- (* x 0.5) (* y z))))
double code(double x, double y, double z) {
double tmp;
if (z <= 1.7e-210) {
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 <= 1.7d-210) 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 <= 1.7e-210) {
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 <= 1.7e-210: 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 <= 1.7e-210) 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 <= 1.7e-210) tmp = 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.7e-210], 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 1.7 \cdot 10^{-210}:\\
\;\;\;\;y \cdot \left(1 + \log z\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot 0.5 - y \cdot z\\
\end{array}
\end{array}
if z < 1.69999999999999987e-210Initial program 99.8%
+-commutative99.8%
*-commutative99.8%
fma-def99.8%
sub-neg99.8%
associate-+l+99.8%
+-commutative99.8%
sub-neg99.8%
Applied egg-rr99.8%
Taylor expanded in z around 0 99.8%
Taylor expanded in y around inf 62.4%
if 1.69999999999999987e-210 < z Initial program 99.9%
Taylor expanded in z around inf 81.8%
mul-1-neg81.8%
distribute-rgt-neg-out81.8%
Simplified81.8%
Final simplification78.7%
(FPCore (x y z) :precision binary64 (if (<= z 8e+38) (* x 0.5) (* y (- 1.0 z))))
double code(double x, double y, double z) {
double tmp;
if (z <= 8e+38) {
tmp = x * 0.5;
} else {
tmp = 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 <= 8d+38) then
tmp = x * 0.5d0
else
tmp = y * (1.0d0 - z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= 8e+38) {
tmp = x * 0.5;
} else {
tmp = y * (1.0 - z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= 8e+38: tmp = x * 0.5 else: tmp = y * (1.0 - z) return tmp
function code(x, y, z) tmp = 0.0 if (z <= 8e+38) tmp = Float64(x * 0.5); else tmp = Float64(y * Float64(1.0 - z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= 8e+38) tmp = x * 0.5; else tmp = y * (1.0 - z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, 8e+38], N[(x * 0.5), $MachinePrecision], N[(y * N[(1.0 - z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 8 \cdot 10^{+38}:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(1 - z\right)\\
\end{array}
\end{array}
if z < 7.99999999999999982e38Initial program 99.8%
Taylor expanded in x around inf 51.2%
if 7.99999999999999982e38 < z Initial program 100.0%
sub-neg100.0%
associate-+l+100.0%
distribute-lft-in100.0%
*-rgt-identity100.0%
associate-+r+100.0%
fma-def100.0%
+-commutative100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in y around -inf 73.9%
mul-1-neg73.9%
distribute-rgt-neg-in73.9%
sub-neg73.9%
mul-1-neg73.9%
sub-neg73.9%
+-commutative73.9%
distribute-neg-in73.9%
remove-double-neg73.9%
sub-neg73.9%
metadata-eval73.9%
+-commutative73.9%
Simplified73.9%
Taylor expanded in z around inf 73.9%
Taylor expanded in y around 0 73.9%
Final simplification61.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%
Taylor expanded in z around inf 74.6%
mul-1-neg74.6%
distribute-rgt-neg-out74.6%
Simplified74.6%
Final simplification74.6%
(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.5%
Final simplification40.5%
(FPCore (x y z) :precision binary64 y)
double code(double x, double y, double z) {
return y;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = y
end function
public static double code(double x, double y, double z) {
return y;
}
def code(x, y, z): return y
function code(x, y, z) return y end
function tmp = code(x, y, z) tmp = y; end
code[x_, y_, z_] := y
\begin{array}{l}
\\
y
\end{array}
Initial program 99.9%
sub-neg99.9%
associate-+l+99.9%
distribute-lft-in99.8%
*-rgt-identity99.8%
associate-+r+99.8%
fma-def99.8%
+-commutative99.8%
unsub-neg99.8%
Simplified99.8%
Taylor expanded in y around -inf 60.1%
mul-1-neg60.1%
distribute-rgt-neg-in60.1%
sub-neg60.1%
mul-1-neg60.1%
sub-neg60.1%
+-commutative60.1%
distribute-neg-in60.1%
remove-double-neg60.1%
sub-neg60.1%
metadata-eval60.1%
+-commutative60.1%
Simplified60.1%
Taylor expanded in z around inf 35.2%
Taylor expanded in y around 0 35.2%
Taylor expanded in z around 0 1.7%
Final simplification1.7%
(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 2023214
(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)))))