
(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 11 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 (fma (- (+ (log z) 1.0) z) y (* x 0.5)))
double code(double x, double y, double z) {
return fma(((log(z) + 1.0) - z), y, (x * 0.5));
}
function code(x, y, z) return fma(Float64(Float64(log(z) + 1.0) - z), y, Float64(x * 0.5)) end
code[x_, y_, z_] := N[(N[(N[(N[Log[z], $MachinePrecision] + 1.0), $MachinePrecision] - z), $MachinePrecision] * y + N[(x * 0.5), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\left(\log z + 1\right) - z, y, x \cdot 0.5\right)
\end{array}
Initial program 99.9%
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
+-commutativeN/A
associate-+r-N/A
--lowering--.f64N/A
+-lowering-+.f64N/A
log-lowering-log.f64N/A
*-lowering-*.f6499.9
Applied egg-rr99.9%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (fma (- z) y (* x 0.5))))
(if (<= (* x 0.5) -1e-88)
t_0
(if (<= (* x 0.5) 2e-11) (+ y (* y (- (log z) z))) t_0))))
double code(double x, double y, double z) {
double t_0 = fma(-z, y, (x * 0.5));
double tmp;
if ((x * 0.5) <= -1e-88) {
tmp = t_0;
} else if ((x * 0.5) <= 2e-11) {
tmp = y + (y * (log(z) - z));
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = fma(Float64(-z), y, Float64(x * 0.5)) tmp = 0.0 if (Float64(x * 0.5) <= -1e-88) tmp = t_0; elseif (Float64(x * 0.5) <= 2e-11) tmp = Float64(y + Float64(y * Float64(log(z) - z))); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[((-z) * y + N[(x * 0.5), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(x * 0.5), $MachinePrecision], -1e-88], t$95$0, If[LessEqual[N[(x * 0.5), $MachinePrecision], 2e-11], N[(y + N[(y * N[(N[Log[z], $MachinePrecision] - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(-z, y, x \cdot 0.5\right)\\
\mathbf{if}\;x \cdot 0.5 \leq -1 \cdot 10^{-88}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \cdot 0.5 \leq 2 \cdot 10^{-11}:\\
\;\;\;\;y + y \cdot \left(\log z - z\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if (*.f64 x #s(literal 1/2 binary64)) < -9.99999999999999934e-89 or 1.99999999999999988e-11 < (*.f64 x #s(literal 1/2 binary64)) Initial program 100.0%
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
+-commutativeN/A
associate-+r-N/A
--lowering--.f64N/A
+-lowering-+.f64N/A
log-lowering-log.f64N/A
*-lowering-*.f64100.0
Applied egg-rr100.0%
Taylor expanded in z around inf
mul-1-negN/A
neg-lowering-neg.f6488.1
Simplified88.1%
if -9.99999999999999934e-89 < (*.f64 x #s(literal 1/2 binary64)) < 1.99999999999999988e-11Initial program 99.8%
Taylor expanded in x around 0
sub-negN/A
associate-+r+N/A
mul-1-negN/A
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
accelerator-lowering-fma.f64N/A
mul-1-negN/A
sub-negN/A
--lowering--.f64N/A
log-lowering-log.f6492.7
Simplified92.7%
+-lowering-+.f64N/A
*-lowering-*.f64N/A
--lowering--.f64N/A
log-lowering-log.f6492.7
Applied egg-rr92.7%
Final simplification90.4%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (fma (- z) y (* x 0.5))))
(if (<= (* x 0.5) -1e-88)
t_0
(if (<= (* x 0.5) 2e-11) (fma y (- (log z) z) y) t_0))))
double code(double x, double y, double z) {
double t_0 = fma(-z, y, (x * 0.5));
double tmp;
if ((x * 0.5) <= -1e-88) {
tmp = t_0;
} else if ((x * 0.5) <= 2e-11) {
tmp = fma(y, (log(z) - z), y);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = fma(Float64(-z), y, Float64(x * 0.5)) tmp = 0.0 if (Float64(x * 0.5) <= -1e-88) tmp = t_0; elseif (Float64(x * 0.5) <= 2e-11) tmp = fma(y, Float64(log(z) - z), y); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[((-z) * y + N[(x * 0.5), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(x * 0.5), $MachinePrecision], -1e-88], t$95$0, If[LessEqual[N[(x * 0.5), $MachinePrecision], 2e-11], N[(y * N[(N[Log[z], $MachinePrecision] - z), $MachinePrecision] + y), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(-z, y, x \cdot 0.5\right)\\
\mathbf{if}\;x \cdot 0.5 \leq -1 \cdot 10^{-88}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \cdot 0.5 \leq 2 \cdot 10^{-11}:\\
\;\;\;\;\mathsf{fma}\left(y, \log z - z, y\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if (*.f64 x #s(literal 1/2 binary64)) < -9.99999999999999934e-89 or 1.99999999999999988e-11 < (*.f64 x #s(literal 1/2 binary64)) Initial program 100.0%
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
+-commutativeN/A
associate-+r-N/A
--lowering--.f64N/A
+-lowering-+.f64N/A
log-lowering-log.f64N/A
*-lowering-*.f64100.0
Applied egg-rr100.0%
Taylor expanded in z around inf
mul-1-negN/A
neg-lowering-neg.f6488.1
Simplified88.1%
if -9.99999999999999934e-89 < (*.f64 x #s(literal 1/2 binary64)) < 1.99999999999999988e-11Initial program 99.8%
Taylor expanded in x around 0
sub-negN/A
associate-+r+N/A
mul-1-negN/A
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
accelerator-lowering-fma.f64N/A
mul-1-negN/A
sub-negN/A
--lowering--.f64N/A
log-lowering-log.f6492.7
Simplified92.7%
(FPCore (x y z) :precision binary64 (if (<= z 0.27) (fma y (log z) (fma 0.5 x y)) (fma (- z) y (* x 0.5))))
double code(double x, double y, double z) {
double tmp;
if (z <= 0.27) {
tmp = fma(y, log(z), fma(0.5, x, y));
} else {
tmp = fma(-z, y, (x * 0.5));
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (z <= 0.27) tmp = fma(y, log(z), fma(0.5, x, y)); else tmp = fma(Float64(-z), y, Float64(x * 0.5)); end return tmp end
code[x_, y_, z_] := If[LessEqual[z, 0.27], N[(y * N[Log[z], $MachinePrecision] + N[(0.5 * x + y), $MachinePrecision]), $MachinePrecision], N[((-z) * y + N[(x * 0.5), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 0.27:\\
\;\;\;\;\mathsf{fma}\left(y, \log z, \mathsf{fma}\left(0.5, x, y\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(-z, y, x \cdot 0.5\right)\\
\end{array}
\end{array}
if z < 0.27000000000000002Initial program 99.8%
Taylor expanded in z around 0
distribute-lft-inN/A
*-rgt-identityN/A
associate-+r+N/A
+-commutativeN/A
accelerator-lowering-fma.f64N/A
log-lowering-log.f64N/A
accelerator-lowering-fma.f6498.2
Simplified98.2%
if 0.27000000000000002 < z Initial program 100.0%
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
+-commutativeN/A
associate-+r-N/A
--lowering--.f64N/A
+-lowering-+.f64N/A
log-lowering-log.f64N/A
*-lowering-*.f64100.0
Applied egg-rr100.0%
Taylor expanded in z around inf
mul-1-negN/A
neg-lowering-neg.f6499.1
Simplified99.1%
(FPCore (x y z) :precision binary64 (fma y (- (log z) z) (fma 0.5 x y)))
double code(double x, double y, double z) {
return fma(y, (log(z) - z), fma(0.5, x, y));
}
function code(x, y, z) return fma(y, Float64(log(z) - z), fma(0.5, x, y)) end
code[x_, y_, z_] := N[(y * N[(N[Log[z], $MachinePrecision] - z), $MachinePrecision] + N[(0.5 * x + y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y, \log z - z, \mathsf{fma}\left(0.5, x, y\right)\right)
\end{array}
Initial program 99.9%
Taylor expanded in x around 0
sub-negN/A
associate-+r+N/A
mul-1-negN/A
distribute-lft-inN/A
*-rgt-identityN/A
associate-+r+N/A
+-commutativeN/A
accelerator-lowering-fma.f64N/A
mul-1-negN/A
sub-negN/A
--lowering--.f64N/A
log-lowering-log.f64N/A
accelerator-lowering-fma.f6499.9
Simplified99.9%
(FPCore (x y z) :precision binary64 (if (<= z 8.6e-50) (fma y (log z) y) (fma (- z) y (* x 0.5))))
double code(double x, double y, double z) {
double tmp;
if (z <= 8.6e-50) {
tmp = fma(y, log(z), y);
} else {
tmp = fma(-z, y, (x * 0.5));
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (z <= 8.6e-50) tmp = fma(y, log(z), y); else tmp = fma(Float64(-z), y, Float64(x * 0.5)); end return tmp end
code[x_, y_, z_] := If[LessEqual[z, 8.6e-50], N[(y * N[Log[z], $MachinePrecision] + y), $MachinePrecision], N[((-z) * y + N[(x * 0.5), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 8.6 \cdot 10^{-50}:\\
\;\;\;\;\mathsf{fma}\left(y, \log z, y\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(-z, y, x \cdot 0.5\right)\\
\end{array}
\end{array}
if z < 8.59999999999999995e-50Initial program 99.7%
Taylor expanded in x around 0
sub-negN/A
associate-+r+N/A
mul-1-negN/A
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
accelerator-lowering-fma.f64N/A
mul-1-negN/A
sub-negN/A
--lowering--.f64N/A
log-lowering-log.f6460.1
Simplified60.1%
Taylor expanded in z around 0
+-commutativeN/A
accelerator-lowering-fma.f64N/A
log-lowering-log.f6460.1
Simplified60.1%
if 8.59999999999999995e-50 < z Initial program 100.0%
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
+-commutativeN/A
associate-+r-N/A
--lowering--.f64N/A
+-lowering-+.f64N/A
log-lowering-log.f64N/A
*-lowering-*.f64100.0
Applied egg-rr100.0%
Taylor expanded in z around inf
mul-1-negN/A
neg-lowering-neg.f6494.2
Simplified94.2%
(FPCore (x y z) :precision binary64 (if (<= z 1.45e+22) (* x 0.5) (fma y (- z) y)))
double code(double x, double y, double z) {
double tmp;
if (z <= 1.45e+22) {
tmp = x * 0.5;
} else {
tmp = fma(y, -z, y);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (z <= 1.45e+22) tmp = Float64(x * 0.5); else tmp = fma(y, Float64(-z), y); end return tmp end
code[x_, y_, z_] := If[LessEqual[z, 1.45e+22], N[(x * 0.5), $MachinePrecision], N[(y * (-z) + y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 1.45 \cdot 10^{+22}:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y, -z, y\right)\\
\end{array}
\end{array}
if z < 1.45e22Initial program 99.8%
Taylor expanded in x around inf
*-lowering-*.f6443.3
Simplified43.3%
if 1.45e22 < z Initial program 100.0%
Taylor expanded in x around 0
sub-negN/A
associate-+r+N/A
mul-1-negN/A
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
accelerator-lowering-fma.f64N/A
mul-1-negN/A
sub-negN/A
--lowering--.f64N/A
log-lowering-log.f6478.0
Simplified78.0%
Taylor expanded in z around inf
mul-1-negN/A
neg-lowering-neg.f6478.0
Simplified78.0%
Final simplification60.1%
(FPCore (x y z) :precision binary64 (if (<= z 2.6e+23) (* x 0.5) (* z (- y))))
double code(double x, double y, double z) {
double tmp;
if (z <= 2.6e+23) {
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 <= 2.6d+23) 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 <= 2.6e+23) {
tmp = x * 0.5;
} else {
tmp = z * -y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= 2.6e+23: tmp = x * 0.5 else: tmp = z * -y return tmp
function code(x, y, z) tmp = 0.0 if (z <= 2.6e+23) 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 <= 2.6e+23) tmp = x * 0.5; else tmp = z * -y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, 2.6e+23], N[(x * 0.5), $MachinePrecision], N[(z * (-y)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 2.6 \cdot 10^{+23}:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(-y\right)\\
\end{array}
\end{array}
if z < 2.59999999999999992e23Initial program 99.8%
Taylor expanded in x around inf
*-lowering-*.f6443.3
Simplified43.3%
if 2.59999999999999992e23 < z Initial program 100.0%
Taylor expanded in z around inf
mul-1-negN/A
distribute-rgt-neg-inN/A
*-lowering-*.f64N/A
neg-lowering-neg.f6478.0
Simplified78.0%
Final simplification60.1%
(FPCore (x y z) :precision binary64 (fma (- z) y (* x 0.5)))
double code(double x, double y, double z) {
return fma(-z, y, (x * 0.5));
}
function code(x, y, z) return fma(Float64(-z), y, Float64(x * 0.5)) end
code[x_, y_, z_] := N[((-z) * y + N[(x * 0.5), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(-z, y, x \cdot 0.5\right)
\end{array}
Initial program 99.9%
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
+-commutativeN/A
associate-+r-N/A
--lowering--.f64N/A
+-lowering-+.f64N/A
log-lowering-log.f64N/A
*-lowering-*.f6499.9
Applied egg-rr99.9%
Taylor expanded in z around inf
mul-1-negN/A
neg-lowering-neg.f6471.7
Simplified71.7%
(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
*-lowering-*.f6434.2
Simplified34.2%
Final simplification34.2%
(FPCore (x y z) :precision binary64 y)
double code(double x, double y, double z) {
return y;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = y
end function
public static double code(double x, double y, double z) {
return y;
}
def code(x, y, z): return y
function code(x, y, z) return y end
function tmp = code(x, y, z) tmp = y; end
code[x_, y_, z_] := y
\begin{array}{l}
\\
y
\end{array}
Initial program 99.9%
Taylor expanded in x around 0
sub-negN/A
associate-+r+N/A
mul-1-negN/A
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
accelerator-lowering-fma.f64N/A
mul-1-negN/A
sub-negN/A
--lowering--.f64N/A
log-lowering-log.f6467.8
Simplified67.8%
Taylor expanded in z around inf
mul-1-negN/A
neg-lowering-neg.f6439.2
Simplified39.2%
Taylor expanded in z around 0
Simplified1.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 2024199
(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)))))