
(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 (+ 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%
mul-1-neg99.9%
Applied egg-rr99.9%
Final simplification99.9%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (+ y (* y (log z)))))
(if (<= z 9.5e-235)
t_0
(if (<= z 2.5e-138)
(* x (- 0.5 (* z (/ y x))))
(if (<= z 0.047) t_0 (+ (* x 0.5) (* y (- 1.0 z))))))))
double code(double x, double y, double z) {
double t_0 = y + (y * log(z));
double tmp;
if (z <= 9.5e-235) {
tmp = t_0;
} else if (z <= 2.5e-138) {
tmp = x * (0.5 - (z * (y / x)));
} else if (z <= 0.047) {
tmp = t_0;
} else {
tmp = (x * 0.5) + (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) :: t_0
real(8) :: tmp
t_0 = y + (y * log(z))
if (z <= 9.5d-235) then
tmp = t_0
else if (z <= 2.5d-138) then
tmp = x * (0.5d0 - (z * (y / x)))
else if (z <= 0.047d0) then
tmp = t_0
else
tmp = (x * 0.5d0) + (y * (1.0d0 - z))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = y + (y * Math.log(z));
double tmp;
if (z <= 9.5e-235) {
tmp = t_0;
} else if (z <= 2.5e-138) {
tmp = x * (0.5 - (z * (y / x)));
} else if (z <= 0.047) {
tmp = t_0;
} else {
tmp = (x * 0.5) + (y * (1.0 - z));
}
return tmp;
}
def code(x, y, z): t_0 = y + (y * math.log(z)) tmp = 0 if z <= 9.5e-235: tmp = t_0 elif z <= 2.5e-138: tmp = x * (0.5 - (z * (y / x))) elif z <= 0.047: tmp = t_0 else: tmp = (x * 0.5) + (y * (1.0 - z)) return tmp
function code(x, y, z) t_0 = Float64(y + Float64(y * log(z))) tmp = 0.0 if (z <= 9.5e-235) tmp = t_0; elseif (z <= 2.5e-138) tmp = Float64(x * Float64(0.5 - Float64(z * Float64(y / x)))); elseif (z <= 0.047) tmp = t_0; else tmp = Float64(Float64(x * 0.5) + Float64(y * Float64(1.0 - z))); end return tmp end
function tmp_2 = code(x, y, z) t_0 = y + (y * log(z)); tmp = 0.0; if (z <= 9.5e-235) tmp = t_0; elseif (z <= 2.5e-138) tmp = x * (0.5 - (z * (y / x))); elseif (z <= 0.047) tmp = t_0; else tmp = (x * 0.5) + (y * (1.0 - z)); end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(y + N[(y * N[Log[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, 9.5e-235], t$95$0, If[LessEqual[z, 2.5e-138], N[(x * N[(0.5 - N[(z * N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 0.047], t$95$0, N[(N[(x * 0.5), $MachinePrecision] + N[(y * N[(1.0 - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y + y \cdot \log z\\
\mathbf{if}\;z \leq 9.5 \cdot 10^{-235}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 2.5 \cdot 10^{-138}:\\
\;\;\;\;x \cdot \left(0.5 - z \cdot \frac{y}{x}\right)\\
\mathbf{elif}\;z \leq 0.047:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;x \cdot 0.5 + y \cdot \left(1 - z\right)\\
\end{array}
\end{array}
if z < 9.4999999999999996e-235 or 2.49999999999999994e-138 < z < 0.047Initial program 99.7%
distribute-rgt-in99.6%
Applied egg-rr99.6%
Taylor expanded in z around 0 96.7%
Taylor expanded in x around inf 80.7%
associate-/l*80.8%
Simplified80.8%
Taylor expanded in x around 0 62.5%
if 9.4999999999999996e-235 < z < 2.49999999999999994e-138Initial program 99.9%
Taylor expanded in z around inf 63.5%
associate-*r*63.5%
mul-1-neg63.5%
Simplified63.5%
Taylor expanded in y around inf 53.3%
neg-mul-153.3%
+-commutative53.3%
unsub-neg53.3%
associate-*r/53.3%
Simplified53.3%
Taylor expanded in x around inf 63.5%
mul-1-neg63.5%
unsub-neg63.5%
*-commutative63.5%
associate-/l*63.5%
Simplified63.5%
if 0.047 < z Initial program 100.0%
Taylor expanded in z around inf 100.0%
sub-neg100.0%
metadata-eval100.0%
+-commutative100.0%
+-commutative100.0%
mul-1-neg100.0%
distribute-frac-neg100.0%
log-rec100.0%
remove-double-neg100.0%
Simplified100.0%
Taylor expanded in z around inf 100.0%
+-commutative100.0%
log-rec100.0%
associate-*r/100.0%
mul-1-neg100.0%
remove-double-neg100.0%
associate--l+100.0%
distribute-lft-in100.0%
rgt-mult-inverse100.0%
sub-neg100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in z around inf 99.4%
Final simplification80.5%
(FPCore (x y z) :precision binary64 (if (<= z 0.56) (+ (* x 0.5) (* y (+ 1.0 (log z)))) (+ (* x 0.5) (* y (- 1.0 z)))))
double code(double x, double y, double z) {
double tmp;
if (z <= 0.56) {
tmp = (x * 0.5) + (y * (1.0 + log(z)));
} else {
tmp = (x * 0.5) + (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 <= 0.56d0) then
tmp = (x * 0.5d0) + (y * (1.0d0 + log(z)))
else
tmp = (x * 0.5d0) + (y * (1.0d0 - z))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= 0.56) {
tmp = (x * 0.5) + (y * (1.0 + Math.log(z)));
} else {
tmp = (x * 0.5) + (y * (1.0 - z));
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= 0.56: tmp = (x * 0.5) + (y * (1.0 + math.log(z))) else: tmp = (x * 0.5) + (y * (1.0 - z)) return tmp
function code(x, y, z) tmp = 0.0 if (z <= 0.56) tmp = Float64(Float64(x * 0.5) + Float64(y * Float64(1.0 + log(z)))); else tmp = Float64(Float64(x * 0.5) + Float64(y * Float64(1.0 - z))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= 0.56) tmp = (x * 0.5) + (y * (1.0 + log(z))); else tmp = (x * 0.5) + (y * (1.0 - z)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, 0.56], N[(N[(x * 0.5), $MachinePrecision] + N[(y * N[(1.0 + N[Log[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x * 0.5), $MachinePrecision] + N[(y * N[(1.0 - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 0.56:\\
\;\;\;\;x \cdot 0.5 + y \cdot \left(1 + \log z\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot 0.5 + y \cdot \left(1 - z\right)\\
\end{array}
\end{array}
if z < 0.56000000000000005Initial program 99.8%
Taylor expanded in z around 0 98.1%
*-commutative98.1%
Simplified98.1%
if 0.56000000000000005 < z Initial program 100.0%
Taylor expanded in z around inf 100.0%
sub-neg100.0%
metadata-eval100.0%
+-commutative100.0%
+-commutative100.0%
mul-1-neg100.0%
distribute-frac-neg100.0%
log-rec100.0%
remove-double-neg100.0%
Simplified100.0%
Taylor expanded in z around inf 100.0%
+-commutative100.0%
log-rec100.0%
associate-*r/100.0%
mul-1-neg100.0%
remove-double-neg100.0%
associate--l+100.0%
distribute-lft-in100.0%
rgt-mult-inverse100.0%
sub-neg100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in z around inf 99.4%
Final simplification98.7%
(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 8e+16) (* x 0.5) (* y (- z))))
double code(double x, double y, double z) {
double tmp;
if (z <= 8e+16) {
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 <= 8d+16) 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 <= 8e+16) {
tmp = x * 0.5;
} else {
tmp = y * -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= 8e+16: tmp = x * 0.5 else: tmp = y * -z return tmp
function code(x, y, z) tmp = 0.0 if (z <= 8e+16) 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 <= 8e+16) tmp = x * 0.5; else tmp = y * -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, 8e+16], N[(x * 0.5), $MachinePrecision], N[(y * (-z)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 8 \cdot 10^{+16}:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(-z\right)\\
\end{array}
\end{array}
if z < 8e16Initial program 99.8%
Taylor expanded in z around inf 50.6%
associate-*r*50.6%
mul-1-neg50.6%
Simplified50.6%
Taylor expanded in x around inf 49.3%
if 8e16 < z Initial program 100.0%
Taylor expanded in z around inf 100.0%
associate-*r*100.0%
mul-1-neg100.0%
Simplified100.0%
Taylor expanded in x around 0 81.0%
neg-mul-181.0%
distribute-lft-neg-in81.0%
Simplified81.0%
Final simplification63.8%
(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 73.2%
associate-*r*73.2%
mul-1-neg73.2%
Simplified73.2%
fma-define73.2%
distribute-lft-neg-out73.2%
add-sqr-sqrt37.1%
sqrt-unprod46.7%
sqr-neg46.7%
sqrt-unprod14.9%
add-sqr-sqrt35.2%
fma-neg35.2%
add-sqr-sqrt14.9%
sqrt-unprod46.7%
sqr-neg46.7%
sqrt-unprod37.1%
add-sqr-sqrt73.2%
Applied egg-rr73.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 z around inf 73.2%
associate-*r*73.2%
mul-1-neg73.2%
Simplified73.2%
Taylor expanded in x around inf 36.3%
Final simplification36.3%
(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 73.2%
associate-*r*73.2%
mul-1-neg73.2%
Simplified73.2%
Taylor expanded in y around inf 64.3%
neg-mul-164.3%
+-commutative64.3%
unsub-neg64.3%
associate-*r/64.3%
Simplified64.3%
div-inv64.2%
frac-2neg64.2%
metadata-eval64.2%
mul-1-neg64.2%
add-sqr-sqrt30.8%
sqrt-unprod42.8%
mul-1-neg42.8%
mul-1-neg42.8%
sqr-neg42.8%
sqrt-unprod17.5%
add-sqr-sqrt38.8%
Applied egg-rr38.8%
associate-*r/38.8%
*-commutative38.8%
*-rgt-identity38.8%
neg-mul-138.8%
distribute-rgt-neg-in38.8%
times-frac38.8%
metadata-eval38.8%
associate-*r/38.8%
distribute-neg-frac38.8%
/-rgt-identity38.8%
distribute-rgt-neg-in38.8%
*-commutative38.8%
distribute-rgt-neg-in38.8%
associate-*r/38.8%
metadata-eval38.8%
distribute-neg-frac38.8%
metadata-eval38.8%
Simplified38.8%
Taylor expanded in y around 0 2.3%
Final simplification2.3%
(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 2024146
(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)))))