
(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 8 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) 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(Float64(log(z) + 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[(N[Log[z], $MachinePrecision] + 1.0), $MachinePrecision] - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot 0.5 + y \cdot \left(\left(\log z + 1\right) - z\right)
\end{array}
Initial program 99.9%
+-commutative99.9%
associate-+r-99.9%
Applied egg-rr99.9%
(FPCore (x y z) :precision binary64 (if (or (<= z 2.6e-253) (and (not (<= z 3.15e-167)) (<= z 1.85e-139))) (+ y (* y (log z))) (- (* x 0.5) (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((z <= 2.6e-253) || (!(z <= 3.15e-167) && (z <= 1.85e-139))) {
tmp = 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 <= 2.6d-253) .or. (.not. (z <= 3.15d-167)) .and. (z <= 1.85d-139)) then
tmp = 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 <= 2.6e-253) || (!(z <= 3.15e-167) && (z <= 1.85e-139))) {
tmp = y + (y * Math.log(z));
} else {
tmp = (x * 0.5) - (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= 2.6e-253) or (not (z <= 3.15e-167) and (z <= 1.85e-139)): tmp = y + (y * math.log(z)) else: tmp = (x * 0.5) - (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= 2.6e-253) || (!(z <= 3.15e-167) && (z <= 1.85e-139))) tmp = 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 <= 2.6e-253) || (~((z <= 3.15e-167)) && (z <= 1.85e-139))) tmp = y + (y * log(z)); else tmp = (x * 0.5) - (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, 2.6e-253], And[N[Not[LessEqual[z, 3.15e-167]], $MachinePrecision], LessEqual[z, 1.85e-139]]], N[(y + N[(y * 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 2.6 \cdot 10^{-253} \lor \neg \left(z \leq 3.15 \cdot 10^{-167}\right) \land z \leq 1.85 \cdot 10^{-139}:\\
\;\;\;\;y + y \cdot \log z\\
\mathbf{else}:\\
\;\;\;\;x \cdot 0.5 - y \cdot z\\
\end{array}
\end{array}
if z < 2.6e-253 or 3.1500000000000001e-167 < z < 1.85000000000000003e-139Initial program 99.7%
distribute-rgt-in99.7%
Applied egg-rr99.7%
Taylor expanded in x around 0 71.4%
Taylor expanded in z around 0 71.4%
if 2.6e-253 < z < 3.1500000000000001e-167 or 1.85000000000000003e-139 < z Initial program 99.9%
Taylor expanded in z around inf 86.6%
associate-*r*86.6%
mul-1-neg86.6%
Simplified86.6%
distribute-lft-neg-out86.6%
unsub-neg86.6%
add-sqr-sqrt45.5%
sqrt-unprod60.1%
sqr-neg60.1%
sqrt-unprod21.7%
add-sqr-sqrt45.4%
*-commutative45.4%
add-sqr-sqrt21.7%
sqrt-unprod60.1%
sqr-neg60.1%
sqrt-unprod45.5%
add-sqr-sqrt86.6%
Applied egg-rr86.6%
Final simplification84.4%
(FPCore (x y z) :precision binary64 (if (or (<= y -8.1e+111) (not (<= y 2.6e+32))) (* y (- (+ (log z) 1.0) z)) (- (* x 0.5) (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -8.1e+111) || !(y <= 2.6e+32)) {
tmp = y * ((log(z) + 1.0) - 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 <= (-8.1d+111)) .or. (.not. (y <= 2.6d+32))) then
tmp = y * ((log(z) + 1.0d0) - 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 <= -8.1e+111) || !(y <= 2.6e+32)) {
tmp = y * ((Math.log(z) + 1.0) - z);
} else {
tmp = (x * 0.5) - (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -8.1e+111) or not (y <= 2.6e+32): tmp = y * ((math.log(z) + 1.0) - z) else: tmp = (x * 0.5) - (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -8.1e+111) || !(y <= 2.6e+32)) tmp = Float64(y * Float64(Float64(log(z) + 1.0) - 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 <= -8.1e+111) || ~((y <= 2.6e+32))) tmp = y * ((log(z) + 1.0) - z); else tmp = (x * 0.5) - (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -8.1e+111], N[Not[LessEqual[y, 2.6e+32]], $MachinePrecision]], N[(y * N[(N[(N[Log[z], $MachinePrecision] + 1.0), $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 -8.1 \cdot 10^{+111} \lor \neg \left(y \leq 2.6 \cdot 10^{+32}\right):\\
\;\;\;\;y \cdot \left(\left(\log z + 1\right) - z\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot 0.5 - y \cdot z\\
\end{array}
\end{array}
if y < -8.09999999999999969e111 or 2.6000000000000002e32 < y Initial program 99.9%
Taylor expanded in x around -inf 81.1%
mul-1-neg81.1%
distribute-rgt-neg-in81.1%
sub-neg81.1%
metadata-eval81.1%
+-commutative81.1%
mul-1-neg81.1%
unsub-neg81.1%
*-commutative81.1%
+-commutative81.1%
associate--l+81.1%
+-commutative81.1%
associate-/l*81.0%
+-commutative81.0%
Simplified81.0%
clear-num80.9%
un-div-inv81.1%
+-commutative81.1%
Applied egg-rr81.1%
+-commutative81.1%
associate--l+81.1%
+-commutative81.1%
Simplified81.1%
Taylor expanded in x around 0 88.4%
if -8.09999999999999969e111 < y < 2.6000000000000002e32Initial program 99.9%
Taylor expanded in z around inf 87.1%
associate-*r*87.1%
mul-1-neg87.1%
Simplified87.1%
distribute-lft-neg-out87.1%
unsub-neg87.1%
add-sqr-sqrt43.2%
sqrt-unprod68.3%
sqr-neg68.3%
sqrt-unprod28.8%
add-sqr-sqrt59.2%
*-commutative59.2%
add-sqr-sqrt28.8%
sqrt-unprod68.3%
sqr-neg68.3%
sqrt-unprod43.2%
add-sqr-sqrt87.1%
Applied egg-rr87.1%
Final simplification87.6%
(FPCore (x y z) :precision binary64 (if (<= z 0.28) (+ (* x 0.5) (* y (+ (log z) 1.0))) (- (* x 0.5) (* y z))))
double code(double x, double y, double z) {
double tmp;
if (z <= 0.28) {
tmp = (x * 0.5) + (y * (log(z) + 1.0));
} 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 = (x * 0.5d0) + (y * (log(z) + 1.0d0))
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 = (x * 0.5) + (y * (Math.log(z) + 1.0));
} else {
tmp = (x * 0.5) - (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= 0.28: tmp = (x * 0.5) + (y * (math.log(z) + 1.0)) else: tmp = (x * 0.5) - (y * z) return tmp
function code(x, y, z) tmp = 0.0 if (z <= 0.28) tmp = Float64(Float64(x * 0.5) + Float64(y * Float64(log(z) + 1.0))); 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 = (x * 0.5) + (y * (log(z) + 1.0)); else tmp = (x * 0.5) - (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, 0.28], 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 * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 0.28:\\
\;\;\;\;x \cdot 0.5 + y \cdot \left(\log z + 1\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot 0.5 - y \cdot z\\
\end{array}
\end{array}
if z < 0.28000000000000003Initial program 99.8%
Taylor expanded in z around 0 99.2%
*-commutative99.2%
Simplified99.2%
if 0.28000000000000003 < z Initial program 100.0%
Taylor expanded in z around inf 99.7%
associate-*r*99.7%
mul-1-neg99.7%
Simplified99.7%
distribute-lft-neg-out99.7%
unsub-neg99.7%
add-sqr-sqrt48.8%
sqrt-unprod59.7%
sqr-neg59.7%
sqrt-unprod19.0%
add-sqr-sqrt32.2%
*-commutative32.2%
add-sqr-sqrt19.0%
sqrt-unprod59.7%
sqr-neg59.7%
sqrt-unprod48.8%
add-sqr-sqrt99.7%
Applied egg-rr99.7%
Final simplification99.4%
(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 420000000000.0) (* x 0.5) (* y (- z))))
double code(double x, double y, double z) {
double tmp;
if (z <= 420000000000.0) {
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 <= 420000000000.0d0) 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 <= 420000000000.0) {
tmp = x * 0.5;
} else {
tmp = y * -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= 420000000000.0: tmp = x * 0.5 else: tmp = y * -z return tmp
function code(x, y, z) tmp = 0.0 if (z <= 420000000000.0) 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 <= 420000000000.0) tmp = x * 0.5; else tmp = y * -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, 420000000000.0], N[(x * 0.5), $MachinePrecision], N[(y * (-z)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 420000000000:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(-z\right)\\
\end{array}
\end{array}
if z < 4.2e11Initial program 99.8%
Taylor expanded in z around inf 55.2%
associate-*r*55.2%
mul-1-neg55.2%
Simplified55.2%
Taylor expanded in x around inf 54.5%
if 4.2e11 < z Initial program 100.0%
Taylor expanded in z around inf 99.7%
associate-*r*99.7%
mul-1-neg99.7%
Simplified99.7%
Taylor expanded in y around inf 87.5%
neg-mul-187.5%
+-commutative87.5%
unsub-neg87.5%
Simplified87.5%
Taylor expanded in x around 0 68.7%
neg-mul-168.7%
Simplified68.7%
Final simplification61.7%
(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 77.8%
associate-*r*77.8%
mul-1-neg77.8%
Simplified77.8%
distribute-lft-neg-out77.8%
unsub-neg77.8%
add-sqr-sqrt41.0%
sqrt-unprod55.1%
sqr-neg55.1%
sqrt-unprod20.1%
add-sqr-sqrt42.4%
*-commutative42.4%
add-sqr-sqrt20.1%
sqrt-unprod55.1%
sqr-neg55.1%
sqrt-unprod41.0%
add-sqr-sqrt77.8%
Applied egg-rr77.8%
Final simplification77.8%
(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 z around inf 77.8%
associate-*r*77.8%
mul-1-neg77.8%
Simplified77.8%
Taylor expanded in x around inf 43.5%
Final simplification43.5%
(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 2024191
(FPCore (x y z)
:name "System.Random.MWC.Distributions:gamma from mwc-random-0.13.3.2"
:precision binary64
:alt
(! :herbie-platform default (- (+ y (* 1/2 x)) (* y (- z (log z)))))
(+ (* x 0.5) (* y (+ (- 1.0 z) (log z)))))