
(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 5 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 (+ (* y (+ (- 1.0 z) (log z))) (* x 0.5)))
double code(double x, double y, double z) {
return (y * ((1.0 - z) + log(z))) + (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 = (y * ((1.0d0 - z) + log(z))) + (x * 0.5d0)
end function
public static double code(double x, double y, double z) {
return (y * ((1.0 - z) + Math.log(z))) + (x * 0.5);
}
def code(x, y, z): return (y * ((1.0 - z) + math.log(z))) + (x * 0.5)
function code(x, y, z) return Float64(Float64(y * Float64(Float64(1.0 - z) + log(z))) + Float64(x * 0.5)) end
function tmp = code(x, y, z) tmp = (y * ((1.0 - z) + log(z))) + (x * 0.5); end
code[x_, y_, z_] := N[(N[(y * N[(N[(1.0 - z), $MachinePrecision] + N[Log[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(x * 0.5), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
y \cdot \left(\left(1 - z\right) + \log z\right) + x \cdot 0.5
\end{array}
Initial program 99.9%
Final simplification99.9%
(FPCore (x y z)
:precision binary64
(if (<= z 1.2e-251)
(* x 0.5)
(if (or (<= z 1.7e-199) (and (not (<= z 4.8e-154)) (<= z 2.7e-109)))
(* y (+ 1.0 (log z)))
(- (* x 0.5) (* y z)))))
double code(double x, double y, double z) {
double tmp;
if (z <= 1.2e-251) {
tmp = x * 0.5;
} else if ((z <= 1.7e-199) || (!(z <= 4.8e-154) && (z <= 2.7e-109))) {
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.2d-251) then
tmp = x * 0.5d0
else if ((z <= 1.7d-199) .or. (.not. (z <= 4.8d-154)) .and. (z <= 2.7d-109)) 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.2e-251) {
tmp = x * 0.5;
} else if ((z <= 1.7e-199) || (!(z <= 4.8e-154) && (z <= 2.7e-109))) {
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.2e-251: tmp = x * 0.5 elif (z <= 1.7e-199) or (not (z <= 4.8e-154) and (z <= 2.7e-109)): 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.2e-251) tmp = Float64(x * 0.5); elseif ((z <= 1.7e-199) || (!(z <= 4.8e-154) && (z <= 2.7e-109))) 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.2e-251) tmp = x * 0.5; elseif ((z <= 1.7e-199) || (~((z <= 4.8e-154)) && (z <= 2.7e-109))) 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.2e-251], N[(x * 0.5), $MachinePrecision], If[Or[LessEqual[z, 1.7e-199], And[N[Not[LessEqual[z, 4.8e-154]], $MachinePrecision], LessEqual[z, 2.7e-109]]], 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.2 \cdot 10^{-251}:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{elif}\;z \leq 1.7 \cdot 10^{-199} \lor \neg \left(z \leq 4.8 \cdot 10^{-154}\right) \land z \leq 2.7 \cdot 10^{-109}:\\
\;\;\;\;y \cdot \left(1 + \log z\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot 0.5 - y \cdot z\\
\end{array}
\end{array}
if z < 1.19999999999999998e-251Initial program 99.9%
Taylor expanded in x around inf 69.1%
if 1.19999999999999998e-251 < z < 1.70000000000000003e-199 or 4.79999999999999974e-154 < z < 2.7e-109Initial program 99.6%
Taylor expanded in z around 0 99.6%
Taylor expanded in x around 0 74.8%
if 1.70000000000000003e-199 < z < 4.79999999999999974e-154 or 2.7e-109 < z Initial program 99.9%
Taylor expanded in z around inf 86.6%
associate-*r*86.6%
neg-mul-186.6%
Simplified86.6%
Taylor expanded in x around 0 86.6%
+-commutative86.6%
*-commutative86.6%
mul-1-neg86.6%
unsub-neg86.6%
*-commutative86.6%
Simplified86.6%
Final simplification83.2%
(FPCore (x y z) :precision binary64 (if (<= z 5.2e-11) (+ (* y (+ 1.0 (log z))) (* x 0.5)) (- (* x 0.5) (* y z))))
double code(double x, double y, double z) {
double tmp;
if (z <= 5.2e-11) {
tmp = (y * (1.0 + log(z))) + (x * 0.5);
} 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 <= 5.2d-11) then
tmp = (y * (1.0d0 + log(z))) + (x * 0.5d0)
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 <= 5.2e-11) {
tmp = (y * (1.0 + Math.log(z))) + (x * 0.5);
} else {
tmp = (x * 0.5) - (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= 5.2e-11: tmp = (y * (1.0 + math.log(z))) + (x * 0.5) else: tmp = (x * 0.5) - (y * z) return tmp
function code(x, y, z) tmp = 0.0 if (z <= 5.2e-11) tmp = Float64(Float64(y * Float64(1.0 + log(z))) + Float64(x * 0.5)); 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 <= 5.2e-11) tmp = (y * (1.0 + log(z))) + (x * 0.5); else tmp = (x * 0.5) - (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, 5.2e-11], N[(N[(y * N[(1.0 + N[Log[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(x * 0.5), $MachinePrecision]), $MachinePrecision], N[(N[(x * 0.5), $MachinePrecision] - N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 5.2 \cdot 10^{-11}:\\
\;\;\;\;y \cdot \left(1 + \log z\right) + x \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;x \cdot 0.5 - y \cdot z\\
\end{array}
\end{array}
if z < 5.2000000000000001e-11Initial program 99.8%
Taylor expanded in z around 0 99.4%
if 5.2000000000000001e-11 < z Initial program 100.0%
Taylor expanded in z around inf 99.0%
associate-*r*99.0%
neg-mul-199.0%
Simplified99.0%
Taylor expanded in x around 0 99.0%
+-commutative99.0%
*-commutative99.0%
mul-1-neg99.0%
unsub-neg99.0%
*-commutative99.0%
Simplified99.0%
Final simplification99.2%
(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 75.2%
associate-*r*75.2%
neg-mul-175.2%
Simplified75.2%
Taylor expanded in x around 0 75.2%
+-commutative75.2%
*-commutative75.2%
mul-1-neg75.2%
unsub-neg75.2%
*-commutative75.2%
Simplified75.2%
Final simplification75.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.9%
Taylor expanded in x around inf 42.4%
Final simplification42.4%
(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 2024024
(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)))))