
(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 (log (* z E))) (* y z))))
double code(double x, double y, double z) {
return (x * 0.5) + ((y * log((z * ((double) M_E)))) - (y * z));
}
public static double code(double x, double y, double z) {
return (x * 0.5) + ((y * Math.log((z * Math.E))) - (y * z));
}
def code(x, y, z): return (x * 0.5) + ((y * math.log((z * math.e))) - (y * z))
function code(x, y, z) return Float64(Float64(x * 0.5) + Float64(Float64(y * log(Float64(z * exp(1)))) - Float64(y * z))) end
function tmp = code(x, y, z) tmp = (x * 0.5) + ((y * log((z * 2.71828182845904523536))) - (y * z)); end
code[x_, y_, z_] := N[(N[(x * 0.5), $MachinePrecision] + N[(N[(y * N[Log[N[(z * E), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot 0.5 + \left(y \cdot \log \left(z \cdot e\right) - y \cdot z\right)
\end{array}
Initial program 99.9%
Taylor expanded in z around 0 99.9%
+-commutative99.9%
add-log-exp99.9%
exp-sum99.9%
add-exp-log99.9%
Applied egg-rr99.9%
exp-1-e99.9%
Simplified99.9%
Final simplification99.9%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* y (log (* z E)))))
(if (<= z 4.1e-188)
t_0
(if (<= z 7.2e-168)
(* x 0.5)
(if (<= z 8.5e-71) t_0 (fma y (- z) (* x 0.5)))))))
double code(double x, double y, double z) {
double t_0 = y * log((z * ((double) M_E)));
double tmp;
if (z <= 4.1e-188) {
tmp = t_0;
} else if (z <= 7.2e-168) {
tmp = x * 0.5;
} else if (z <= 8.5e-71) {
tmp = t_0;
} else {
tmp = fma(y, -z, (x * 0.5));
}
return tmp;
}
function code(x, y, z) t_0 = Float64(y * log(Float64(z * exp(1)))) tmp = 0.0 if (z <= 4.1e-188) tmp = t_0; elseif (z <= 7.2e-168) tmp = Float64(x * 0.5); elseif (z <= 8.5e-71) tmp = t_0; else tmp = fma(y, Float64(-z), Float64(x * 0.5)); end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(y * N[Log[N[(z * E), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, 4.1e-188], t$95$0, If[LessEqual[z, 7.2e-168], N[(x * 0.5), $MachinePrecision], If[LessEqual[z, 8.5e-71], t$95$0, N[(y * (-z) + N[(x * 0.5), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \log \left(z \cdot e\right)\\
\mathbf{if}\;z \leq 4.1 \cdot 10^{-188}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 7.2 \cdot 10^{-168}:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{elif}\;z \leq 8.5 \cdot 10^{-71}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y, -z, x \cdot 0.5\right)\\
\end{array}
\end{array}
if z < 4.09999999999999982e-188 or 7.1999999999999998e-168 < z < 8.49999999999999988e-71Initial program 99.7%
Taylor expanded in z around 0 99.7%
+-commutative99.7%
add-log-exp99.7%
exp-sum99.7%
add-exp-log99.7%
Applied egg-rr99.7%
exp-1-e99.7%
Simplified99.7%
Taylor expanded in x around 0 60.6%
if 4.09999999999999982e-188 < z < 7.1999999999999998e-168Initial program 100.0%
Taylor expanded in x around inf 95.8%
if 8.49999999999999988e-71 < z Initial program 99.9%
+-commutative99.9%
fma-define99.9%
Simplified99.9%
Taylor expanded in z around inf 86.5%
mul-1-neg86.5%
Simplified86.5%
Final simplification78.4%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* y (log (* z E)))))
(if (<= z 5.5e-187)
t_0
(if (<= z 3.3e-167)
(* x 0.5)
(if (<= z 1.35e-75) t_0 (- (* x 0.5) (* y z)))))))
double code(double x, double y, double z) {
double t_0 = y * log((z * ((double) M_E)));
double tmp;
if (z <= 5.5e-187) {
tmp = t_0;
} else if (z <= 3.3e-167) {
tmp = x * 0.5;
} else if (z <= 1.35e-75) {
tmp = t_0;
} else {
tmp = (x * 0.5) - (y * z);
}
return tmp;
}
public static double code(double x, double y, double z) {
double t_0 = y * Math.log((z * Math.E));
double tmp;
if (z <= 5.5e-187) {
tmp = t_0;
} else if (z <= 3.3e-167) {
tmp = x * 0.5;
} else if (z <= 1.35e-75) {
tmp = t_0;
} else {
tmp = (x * 0.5) - (y * z);
}
return tmp;
}
def code(x, y, z): t_0 = y * math.log((z * math.e)) tmp = 0 if z <= 5.5e-187: tmp = t_0 elif z <= 3.3e-167: tmp = x * 0.5 elif z <= 1.35e-75: tmp = t_0 else: tmp = (x * 0.5) - (y * z) return tmp
function code(x, y, z) t_0 = Float64(y * log(Float64(z * exp(1)))) tmp = 0.0 if (z <= 5.5e-187) tmp = t_0; elseif (z <= 3.3e-167) tmp = Float64(x * 0.5); elseif (z <= 1.35e-75) tmp = t_0; else tmp = Float64(Float64(x * 0.5) - Float64(y * z)); end return tmp end
function tmp_2 = code(x, y, z) t_0 = y * log((z * 2.71828182845904523536)); tmp = 0.0; if (z <= 5.5e-187) tmp = t_0; elseif (z <= 3.3e-167) tmp = x * 0.5; elseif (z <= 1.35e-75) tmp = t_0; else tmp = (x * 0.5) - (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(y * N[Log[N[(z * E), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, 5.5e-187], t$95$0, If[LessEqual[z, 3.3e-167], N[(x * 0.5), $MachinePrecision], If[LessEqual[z, 1.35e-75], t$95$0, N[(N[(x * 0.5), $MachinePrecision] - N[(y * z), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \log \left(z \cdot e\right)\\
\mathbf{if}\;z \leq 5.5 \cdot 10^{-187}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 3.3 \cdot 10^{-167}:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{elif}\;z \leq 1.35 \cdot 10^{-75}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;x \cdot 0.5 - y \cdot z\\
\end{array}
\end{array}
if z < 5.50000000000000033e-187 or 3.29999999999999995e-167 < z < 1.3499999999999999e-75Initial program 99.7%
Taylor expanded in z around 0 99.7%
+-commutative99.7%
add-log-exp99.7%
exp-sum99.7%
add-exp-log99.7%
Applied egg-rr99.7%
exp-1-e99.7%
Simplified99.7%
Taylor expanded in x around 0 60.6%
if 5.50000000000000033e-187 < z < 3.29999999999999995e-167Initial program 100.0%
Taylor expanded in x around inf 95.8%
if 1.3499999999999999e-75 < z Initial program 99.9%
Taylor expanded in z around inf 86.5%
associate-*r*86.5%
mul-1-neg86.5%
Simplified86.5%
distribute-lft-neg-out86.5%
unsub-neg86.5%
*-commutative86.5%
Applied egg-rr86.5%
Final simplification78.3%
(FPCore (x y z) :precision binary64 (if (or (<= y -2400.0) (not (<= y 6.8e+48))) (* y (- (+ 1.0 (log z)) z)) (- (* x 0.5) (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -2400.0) || !(y <= 6.8e+48)) {
tmp = y * ((1.0 + log(z)) - 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 ((y <= (-2400.0d0)) .or. (.not. (y <= 6.8d+48))) then
tmp = y * ((1.0d0 + log(z)) - 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 ((y <= -2400.0) || !(y <= 6.8e+48)) {
tmp = y * ((1.0 + Math.log(z)) - z);
} else {
tmp = (x * 0.5) - (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -2400.0) or not (y <= 6.8e+48): tmp = y * ((1.0 + math.log(z)) - z) else: tmp = (x * 0.5) - (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -2400.0) || !(y <= 6.8e+48)) tmp = Float64(y * Float64(Float64(1.0 + log(z)) - 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 ((y <= -2400.0) || ~((y <= 6.8e+48))) tmp = y * ((1.0 + log(z)) - z); else tmp = (x * 0.5) - (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -2400.0], N[Not[LessEqual[y, 6.8e+48]], $MachinePrecision]], N[(y * N[(N[(1.0 + N[Log[z], $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]), $MachinePrecision], N[(N[(x * 0.5), $MachinePrecision] - N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2400 \lor \neg \left(y \leq 6.8 \cdot 10^{+48}\right):\\
\;\;\;\;y \cdot \left(\left(1 + \log z\right) - z\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot 0.5 - y \cdot z\\
\end{array}
\end{array}
if y < -2400 or 6.8000000000000006e48 < y Initial program 99.8%
Taylor expanded in x around inf 80.1%
associate-/l*80.0%
+-commutative80.0%
associate--l+80.0%
Simplified80.0%
Taylor expanded in x around 0 85.6%
if -2400 < y < 6.8000000000000006e48Initial program 99.9%
Taylor expanded in z around inf 83.0%
associate-*r*83.0%
mul-1-neg83.0%
Simplified83.0%
distribute-lft-neg-out83.0%
unsub-neg83.0%
*-commutative83.0%
Applied egg-rr83.0%
Final simplification84.2%
(FPCore (x y z) :precision binary64 (if (<= z 0.235) (+ (* x 0.5) (* y (log (* z E)))) (fma y (- z) (* x 0.5))))
double code(double x, double y, double z) {
double tmp;
if (z <= 0.235) {
tmp = (x * 0.5) + (y * log((z * ((double) M_E))));
} else {
tmp = fma(y, -z, (x * 0.5));
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (z <= 0.235) tmp = Float64(Float64(x * 0.5) + Float64(y * log(Float64(z * exp(1))))); else tmp = fma(y, Float64(-z), Float64(x * 0.5)); end return tmp end
code[x_, y_, z_] := If[LessEqual[z, 0.235], N[(N[(x * 0.5), $MachinePrecision] + N[(y * N[Log[N[(z * E), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(y * (-z) + N[(x * 0.5), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 0.235:\\
\;\;\;\;x \cdot 0.5 + y \cdot \log \left(z \cdot e\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y, -z, x \cdot 0.5\right)\\
\end{array}
\end{array}
if z < 0.23499999999999999Initial program 99.8%
Taylor expanded in z around 0 98.5%
+-commutative99.8%
add-log-exp99.8%
exp-sum99.8%
add-exp-log99.8%
Applied egg-rr98.5%
exp-1-e99.8%
Simplified98.5%
if 0.23499999999999999 < z Initial program 99.9%
+-commutative99.9%
fma-define100.0%
Simplified100.0%
Taylor expanded in z around inf 97.2%
mul-1-neg97.2%
Simplified97.2%
Final simplification97.9%
(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.9%
Final simplification99.9%
(FPCore (x y z) :precision binary64 (if (<= z 22000.0) (* x 0.5) (* z (- y))))
double code(double x, double y, double z) {
double tmp;
if (z <= 22000.0) {
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 <= 22000.0d0) 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 <= 22000.0) {
tmp = x * 0.5;
} else {
tmp = z * -y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= 22000.0: tmp = x * 0.5 else: tmp = z * -y return tmp
function code(x, y, z) tmp = 0.0 if (z <= 22000.0) 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 <= 22000.0) tmp = x * 0.5; else tmp = z * -y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, 22000.0], N[(x * 0.5), $MachinePrecision], N[(z * (-y)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 22000:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(-y\right)\\
\end{array}
\end{array}
if z < 22000Initial program 99.8%
Taylor expanded in x around inf 49.4%
if 22000 < z Initial program 99.9%
Taylor expanded in z around 0 100.0%
Taylor expanded in x around 0 76.3%
Taylor expanded in z around inf 73.5%
associate-*r*73.5%
mul-1-neg73.5%
Simplified73.5%
Final simplification60.6%
(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 72.2%
associate-*r*72.2%
mul-1-neg72.2%
Simplified72.2%
distribute-lft-neg-out72.2%
unsub-neg72.2%
*-commutative72.2%
Applied egg-rr72.2%
Final simplification72.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 38.7%
Final simplification38.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 2024053
(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)))))