
(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 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.8%
Final simplification99.8%
(FPCore (x y z) :precision binary64 (if (or (<= (* x 0.5) -1e-66) (not (<= (* x 0.5) 1e-26))) (- (* x 0.5) (* y z)) (* y (+ (- 1.0 z) (log z)))))
double code(double x, double y, double z) {
double tmp;
if (((x * 0.5) <= -1e-66) || !((x * 0.5) <= 1e-26)) {
tmp = (x * 0.5) - (y * z);
} else {
tmp = y * ((1.0 - z) + log(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) <= (-1d-66)) .or. (.not. ((x * 0.5d0) <= 1d-26))) then
tmp = (x * 0.5d0) - (y * z)
else
tmp = y * ((1.0d0 - z) + log(z))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (((x * 0.5) <= -1e-66) || !((x * 0.5) <= 1e-26)) {
tmp = (x * 0.5) - (y * z);
} else {
tmp = y * ((1.0 - z) + Math.log(z));
}
return tmp;
}
def code(x, y, z): tmp = 0 if ((x * 0.5) <= -1e-66) or not ((x * 0.5) <= 1e-26): tmp = (x * 0.5) - (y * z) else: tmp = y * ((1.0 - z) + math.log(z)) return tmp
function code(x, y, z) tmp = 0.0 if ((Float64(x * 0.5) <= -1e-66) || !(Float64(x * 0.5) <= 1e-26)) tmp = Float64(Float64(x * 0.5) - Float64(y * z)); else tmp = Float64(y * Float64(Float64(1.0 - z) + log(z))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (((x * 0.5) <= -1e-66) || ~(((x * 0.5) <= 1e-26))) tmp = (x * 0.5) - (y * z); else tmp = y * ((1.0 - z) + log(z)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[N[(x * 0.5), $MachinePrecision], -1e-66], N[Not[LessEqual[N[(x * 0.5), $MachinePrecision], 1e-26]], $MachinePrecision]], N[(N[(x * 0.5), $MachinePrecision] - N[(y * z), $MachinePrecision]), $MachinePrecision], N[(y * N[(N[(1.0 - z), $MachinePrecision] + N[Log[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot 0.5 \leq -1 \cdot 10^{-66} \lor \neg \left(x \cdot 0.5 \leq 10^{-26}\right):\\
\;\;\;\;x \cdot 0.5 - y \cdot z\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(\left(1 - z\right) + \log z\right)\\
\end{array}
\end{array}
if (*.f64 x 1/2) < -9.9999999999999998e-67 or 1e-26 < (*.f64 x 1/2) Initial program 99.9%
Taylor expanded in z around inf 85.7%
mul-1-neg85.7%
distribute-rgt-neg-out85.7%
Simplified85.7%
if -9.9999999999999998e-67 < (*.f64 x 1/2) < 1e-26Initial program 99.7%
+-commutative99.7%
*-commutative99.7%
fma-def99.8%
sub-neg99.8%
associate-+l+99.7%
+-commutative99.7%
sub-neg99.7%
Applied egg-rr99.7%
Taylor expanded in y around inf 91.3%
+-commutative91.3%
associate--l+91.4%
Simplified91.4%
Final simplification88.3%
(FPCore (x y z)
:precision binary64
(if (or (<= z 1.9e-199)
(not
(or (<= z 1.35e-155) (and (not (<= z 1.5e-107)) (<= z 3.8e-31)))))
(- (* x 0.5) (* y z))
(* y (+ 1.0 (log z)))))
double code(double x, double y, double z) {
double tmp;
if ((z <= 1.9e-199) || !((z <= 1.35e-155) || (!(z <= 1.5e-107) && (z <= 3.8e-31)))) {
tmp = (x * 0.5) - (y * z);
} else {
tmp = y * (1.0 + log(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.9d-199) .or. (.not. (z <= 1.35d-155) .or. (.not. (z <= 1.5d-107)) .and. (z <= 3.8d-31))) then
tmp = (x * 0.5d0) - (y * z)
else
tmp = y * (1.0d0 + log(z))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= 1.9e-199) || !((z <= 1.35e-155) || (!(z <= 1.5e-107) && (z <= 3.8e-31)))) {
tmp = (x * 0.5) - (y * z);
} else {
tmp = y * (1.0 + Math.log(z));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= 1.9e-199) or not ((z <= 1.35e-155) or (not (z <= 1.5e-107) and (z <= 3.8e-31))): tmp = (x * 0.5) - (y * z) else: tmp = y * (1.0 + math.log(z)) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= 1.9e-199) || !((z <= 1.35e-155) || (!(z <= 1.5e-107) && (z <= 3.8e-31)))) tmp = Float64(Float64(x * 0.5) - Float64(y * z)); else tmp = Float64(y * Float64(1.0 + log(z))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= 1.9e-199) || ~(((z <= 1.35e-155) || (~((z <= 1.5e-107)) && (z <= 3.8e-31))))) tmp = (x * 0.5) - (y * z); else tmp = y * (1.0 + log(z)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, 1.9e-199], N[Not[Or[LessEqual[z, 1.35e-155], And[N[Not[LessEqual[z, 1.5e-107]], $MachinePrecision], LessEqual[z, 3.8e-31]]]], $MachinePrecision]], N[(N[(x * 0.5), $MachinePrecision] - N[(y * z), $MachinePrecision]), $MachinePrecision], N[(y * N[(1.0 + N[Log[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 1.9 \cdot 10^{-199} \lor \neg \left(z \leq 1.35 \cdot 10^{-155} \lor \neg \left(z \leq 1.5 \cdot 10^{-107}\right) \land z \leq 3.8 \cdot 10^{-31}\right):\\
\;\;\;\;x \cdot 0.5 - y \cdot z\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(1 + \log z\right)\\
\end{array}
\end{array}
if z < 1.8999999999999999e-199 or 1.34999999999999991e-155 < z < 1.4999999999999999e-107 or 3.8e-31 < z Initial program 99.9%
Taylor expanded in z around inf 84.2%
mul-1-neg84.2%
distribute-rgt-neg-out84.2%
Simplified84.2%
if 1.8999999999999999e-199 < z < 1.34999999999999991e-155 or 1.4999999999999999e-107 < z < 3.8e-31Initial program 99.6%
sub-neg99.6%
associate-+l+99.6%
distribute-lft-in99.6%
*-rgt-identity99.6%
associate-+r+99.6%
fma-def99.6%
+-commutative99.6%
unsub-neg99.6%
Simplified99.6%
Taylor expanded in z around 0 99.6%
Taylor expanded in y around inf 67.1%
Final simplification80.7%
(FPCore (x y z) :precision binary64 (if (<= z 0.27) (+ (* x 0.5) (+ y (* y (log z)))) (- (* x 0.5) (* y z))))
double code(double x, double y, double z) {
double tmp;
if (z <= 0.27) {
tmp = (x * 0.5) + (y + (y * 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 <= 0.27d0) then
tmp = (x * 0.5d0) + (y + (y * 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 <= 0.27) {
tmp = (x * 0.5) + (y + (y * Math.log(z)));
} else {
tmp = (x * 0.5) - (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= 0.27: tmp = (x * 0.5) + (y + (y * math.log(z))) else: tmp = (x * 0.5) - (y * z) return tmp
function code(x, y, z) tmp = 0.0 if (z <= 0.27) tmp = Float64(Float64(x * 0.5) + Float64(y + Float64(y * 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 <= 0.27) tmp = (x * 0.5) + (y + (y * log(z))); else tmp = (x * 0.5) - (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, 0.27], N[(N[(x * 0.5), $MachinePrecision] + N[(y + N[(y * 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 0.27:\\
\;\;\;\;x \cdot 0.5 + \left(y + y \cdot \log z\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot 0.5 - y \cdot z\\
\end{array}
\end{array}
if z < 0.27000000000000002Initial program 99.7%
Taylor expanded in z around 0 98.4%
*-commutative98.4%
distribute-lft-in98.4%
*-rgt-identity98.4%
Simplified98.4%
if 0.27000000000000002 < z Initial program 99.9%
Taylor expanded in z around inf 98.4%
mul-1-neg98.4%
distribute-rgt-neg-out98.4%
Simplified98.4%
Final simplification98.4%
(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.8%
Taylor expanded in z around inf 73.1%
mul-1-neg73.1%
distribute-rgt-neg-out73.1%
Simplified73.1%
Final simplification73.1%
(FPCore (x y z) :precision binary64 (if (<= z 1.3e+43) (* x 0.5) (* y (- z))))
double code(double x, double y, double z) {
double tmp;
if (z <= 1.3e+43) {
tmp = x * 0.5;
} 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 <= 1.3d+43) then
tmp = x * 0.5d0
else
tmp = y * -z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= 1.3e+43) {
tmp = x * 0.5;
} else {
tmp = y * -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= 1.3e+43: tmp = x * 0.5 else: tmp = y * -z return tmp
function code(x, y, z) tmp = 0.0 if (z <= 1.3e+43) tmp = Float64(x * 0.5); else tmp = Float64(y * Float64(-z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= 1.3e+43) tmp = x * 0.5; else tmp = y * -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, 1.3e+43], N[(x * 0.5), $MachinePrecision], N[(y * (-z)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 1.3 \cdot 10^{+43}:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(-z\right)\\
\end{array}
\end{array}
if z < 1.3000000000000001e43Initial program 99.7%
Taylor expanded in x around inf 48.9%
if 1.3000000000000001e43 < z Initial program 100.0%
+-commutative100.0%
*-commutative100.0%
fma-def100.0%
sub-neg100.0%
associate-+l+100.0%
+-commutative100.0%
sub-neg100.0%
Applied egg-rr100.0%
Taylor expanded in z around inf 80.8%
mul-1-neg80.8%
*-commutative80.8%
distribute-rgt-neg-in80.8%
Simplified80.8%
Final simplification63.2%
(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.8%
Taylor expanded in x around inf 36.8%
Final simplification36.8%
(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 2023255
(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)))))