
(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 (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
mul-1-negN/A
associate-+r+N/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 (let* ((t_0 (* y (+ (log z) (- 1.0 z)))) (t_1 (* y (- 0.0 z)))) (if (<= t_0 -200000.0) t_1 (if (<= t_0 5e+99) (* 0.5 x) t_1))))
double code(double x, double y, double z) {
double t_0 = y * (log(z) + (1.0 - z));
double t_1 = y * (0.0 - z);
double tmp;
if (t_0 <= -200000.0) {
tmp = t_1;
} else if (t_0 <= 5e+99) {
tmp = 0.5 * x;
} else {
tmp = t_1;
}
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) :: t_1
real(8) :: tmp
t_0 = y * (log(z) + (1.0d0 - z))
t_1 = y * (0.0d0 - z)
if (t_0 <= (-200000.0d0)) then
tmp = t_1
else if (t_0 <= 5d+99) then
tmp = 0.5d0 * x
else
tmp = t_1
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = y * (Math.log(z) + (1.0 - z));
double t_1 = y * (0.0 - z);
double tmp;
if (t_0 <= -200000.0) {
tmp = t_1;
} else if (t_0 <= 5e+99) {
tmp = 0.5 * x;
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z): t_0 = y * (math.log(z) + (1.0 - z)) t_1 = y * (0.0 - z) tmp = 0 if t_0 <= -200000.0: tmp = t_1 elif t_0 <= 5e+99: tmp = 0.5 * x else: tmp = t_1 return tmp
function code(x, y, z) t_0 = Float64(y * Float64(log(z) + Float64(1.0 - z))) t_1 = Float64(y * Float64(0.0 - z)) tmp = 0.0 if (t_0 <= -200000.0) tmp = t_1; elseif (t_0 <= 5e+99) tmp = Float64(0.5 * x); else tmp = t_1; end return tmp end
function tmp_2 = code(x, y, z) t_0 = y * (log(z) + (1.0 - z)); t_1 = y * (0.0 - z); tmp = 0.0; if (t_0 <= -200000.0) tmp = t_1; elseif (t_0 <= 5e+99) tmp = 0.5 * x; else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(y * N[(N[Log[z], $MachinePrecision] + N[(1.0 - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(y * N[(0.0 - z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -200000.0], t$95$1, If[LessEqual[t$95$0, 5e+99], N[(0.5 * x), $MachinePrecision], t$95$1]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(\log z + \left(1 - z\right)\right)\\
t_1 := y \cdot \left(0 - z\right)\\
\mathbf{if}\;t\_0 \leq -200000:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t\_0 \leq 5 \cdot 10^{+99}:\\
\;\;\;\;0.5 \cdot x\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (*.f64 y (+.f64 (-.f64 #s(literal 1 binary64) z) (log.f64 z))) < -2e5 or 5.00000000000000008e99 < (*.f64 y (+.f64 (-.f64 #s(literal 1 binary64) z) (log.f64 z))) Initial program 99.9%
Taylor expanded in z around inf
mul-1-negN/A
neg-sub0N/A
--lowering--.f64N/A
*-lowering-*.f6454.3
Simplified54.3%
if -2e5 < (*.f64 y (+.f64 (-.f64 #s(literal 1 binary64) z) (log.f64 z))) < 5.00000000000000008e99Initial program 100.0%
Taylor expanded in x around inf
+-rgt-identityN/A
accelerator-lowering-fma.f6474.9
Simplified74.9%
+-rgt-identityN/A
*-commutativeN/A
*-lowering-*.f6474.9
Applied egg-rr74.9%
Final simplification63.9%
(FPCore (x y z) :precision binary64 (let* ((t_0 (fma y (- (log z) z) y))) (if (<= y -3.3e+81) t_0 (if (<= y 1.05e-6) (- (* 0.5 x) (* y z)) t_0))))
double code(double x, double y, double z) {
double t_0 = fma(y, (log(z) - z), y);
double tmp;
if (y <= -3.3e+81) {
tmp = t_0;
} else if (y <= 1.05e-6) {
tmp = (0.5 * x) - (y * z);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = fma(y, Float64(log(z) - z), y) tmp = 0.0 if (y <= -3.3e+81) tmp = t_0; elseif (y <= 1.05e-6) tmp = Float64(Float64(0.5 * x) - Float64(y * z)); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(y * N[(N[Log[z], $MachinePrecision] - z), $MachinePrecision] + y), $MachinePrecision]}, If[LessEqual[y, -3.3e+81], t$95$0, If[LessEqual[y, 1.05e-6], N[(N[(0.5 * x), $MachinePrecision] - N[(y * z), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(y, \log z - z, y\right)\\
\mathbf{if}\;y \leq -3.3 \cdot 10^{+81}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 1.05 \cdot 10^{-6}:\\
\;\;\;\;0.5 \cdot x - y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -3.3e81 or 1.0499999999999999e-6 < y Initial program 99.8%
Taylor expanded in x around 0
sub-negN/A
mul-1-negN/A
associate-+r+N/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.f6491.4
Simplified91.4%
if -3.3e81 < y < 1.0499999999999999e-6Initial program 100.0%
Taylor expanded in z around inf
mul-1-negN/A
neg-sub0N/A
--lowering--.f64N/A
*-lowering-*.f6490.3
Simplified90.3%
Taylor expanded in x around 0
--lowering--.f64N/A
*-lowering-*.f64N/A
*-lowering-*.f6490.3
Simplified90.3%
(FPCore (x y z) :precision binary64 (if (<= z 4.4e-20) (fma y (log z) (fma 0.5 x y)) (fma y (- (log z) z) (* 0.5 x))))
double code(double x, double y, double z) {
double tmp;
if (z <= 4.4e-20) {
tmp = fma(y, log(z), fma(0.5, x, y));
} else {
tmp = fma(y, (log(z) - z), (0.5 * x));
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (z <= 4.4e-20) tmp = fma(y, log(z), fma(0.5, x, y)); else tmp = fma(y, Float64(log(z) - z), Float64(0.5 * x)); end return tmp end
code[x_, y_, z_] := If[LessEqual[z, 4.4e-20], N[(y * N[Log[z], $MachinePrecision] + N[(0.5 * x + y), $MachinePrecision]), $MachinePrecision], N[(y * N[(N[Log[z], $MachinePrecision] - z), $MachinePrecision] + N[(0.5 * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 4.4 \cdot 10^{-20}:\\
\;\;\;\;\mathsf{fma}\left(y, \log z, \mathsf{fma}\left(0.5, x, y\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y, \log z - z, 0.5 \cdot x\right)\\
\end{array}
\end{array}
if z < 4.39999999999999982e-20Initial program 99.9%
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.f6499.9
Simplified99.9%
if 4.39999999999999982e-20 < z Initial program 100.0%
Taylor expanded in x around 0
sub-negN/A
mul-1-negN/A
associate-+r+N/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.f64100.0
Simplified100.0%
Taylor expanded in x around inf
*-lowering-*.f6498.5
Simplified98.5%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (fma y (log z) y)))
(if (<= y -5.5e+169)
t_0
(if (<= y 8e+276) (fma y (- 0.0 z) (* 0.5 x)) t_0))))
double code(double x, double y, double z) {
double t_0 = fma(y, log(z), y);
double tmp;
if (y <= -5.5e+169) {
tmp = t_0;
} else if (y <= 8e+276) {
tmp = fma(y, (0.0 - z), (0.5 * x));
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = fma(y, log(z), y) tmp = 0.0 if (y <= -5.5e+169) tmp = t_0; elseif (y <= 8e+276) tmp = fma(y, Float64(0.0 - z), Float64(0.5 * x)); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(y * N[Log[z], $MachinePrecision] + y), $MachinePrecision]}, If[LessEqual[y, -5.5e+169], t$95$0, If[LessEqual[y, 8e+276], N[(y * N[(0.0 - z), $MachinePrecision] + N[(0.5 * x), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(y, \log z, y\right)\\
\mathbf{if}\;y \leq -5.5 \cdot 10^{+169}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 8 \cdot 10^{+276}:\\
\;\;\;\;\mathsf{fma}\left(y, 0 - z, 0.5 \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -5.49999999999999972e169 or 8.0000000000000004e276 < y Initial program 99.7%
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.f6481.3
Simplified81.3%
Taylor expanded in x around 0
Simplified77.5%
if -5.49999999999999972e169 < y < 8.0000000000000004e276Initial program 100.0%
Taylor expanded in x around 0
sub-negN/A
mul-1-negN/A
associate-+r+N/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.f64100.0
Simplified100.0%
Taylor expanded in x around inf
*-lowering-*.f6488.9
Simplified88.9%
Taylor expanded in z around inf
mul-1-negN/A
neg-sub0N/A
--lowering--.f6484.9
Simplified84.9%
(FPCore (x y z) :precision binary64 (if (<= z 4.4e-20) (fma y (log z) (fma 0.5 x y)) (fma y (- 0.0 z) (fma 0.5 x y))))
double code(double x, double y, double z) {
double tmp;
if (z <= 4.4e-20) {
tmp = fma(y, log(z), fma(0.5, x, y));
} else {
tmp = fma(y, (0.0 - z), fma(0.5, x, y));
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (z <= 4.4e-20) tmp = fma(y, log(z), fma(0.5, x, y)); else tmp = fma(y, Float64(0.0 - z), fma(0.5, x, y)); end return tmp end
code[x_, y_, z_] := If[LessEqual[z, 4.4e-20], N[(y * N[Log[z], $MachinePrecision] + N[(0.5 * x + y), $MachinePrecision]), $MachinePrecision], N[(y * N[(0.0 - z), $MachinePrecision] + N[(0.5 * x + y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 4.4 \cdot 10^{-20}:\\
\;\;\;\;\mathsf{fma}\left(y, \log z, \mathsf{fma}\left(0.5, x, y\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y, 0 - z, \mathsf{fma}\left(0.5, x, y\right)\right)\\
\end{array}
\end{array}
if z < 4.39999999999999982e-20Initial program 99.9%
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.f6499.9
Simplified99.9%
if 4.39999999999999982e-20 < z Initial program 100.0%
Taylor expanded in x around 0
sub-negN/A
mul-1-negN/A
associate-+r+N/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.f64100.0
Simplified100.0%
Taylor expanded in z around inf
mul-1-negN/A
neg-sub0N/A
--lowering--.f6498.3
Simplified98.3%
(FPCore (x y z) :precision binary64 (fma y (- 0.0 z) (* 0.5 x)))
double code(double x, double y, double z) {
return fma(y, (0.0 - z), (0.5 * x));
}
function code(x, y, z) return fma(y, Float64(0.0 - z), Float64(0.5 * x)) end
code[x_, y_, z_] := N[(y * N[(0.0 - z), $MachinePrecision] + N[(0.5 * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y, 0 - z, 0.5 \cdot x\right)
\end{array}
Initial program 99.9%
Taylor expanded in x around 0
sub-negN/A
mul-1-negN/A
associate-+r+N/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%
Taylor expanded in x around inf
*-lowering-*.f6482.6
Simplified82.6%
Taylor expanded in z around inf
mul-1-negN/A
neg-sub0N/A
--lowering--.f6475.8
Simplified75.8%
(FPCore (x y z) :precision binary64 (- (* 0.5 x) (* y z)))
double code(double x, double y, double z) {
return (0.5 * x) - (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 = (0.5d0 * x) - (y * z)
end function
public static double code(double x, double y, double z) {
return (0.5 * x) - (y * z);
}
def code(x, y, z): return (0.5 * x) - (y * z)
function code(x, y, z) return Float64(Float64(0.5 * x) - Float64(y * z)) end
function tmp = code(x, y, z) tmp = (0.5 * x) - (y * z); end
code[x_, y_, z_] := N[(N[(0.5 * x), $MachinePrecision] - N[(y * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.5 \cdot x - y \cdot z
\end{array}
Initial program 99.9%
Taylor expanded in z around inf
mul-1-negN/A
neg-sub0N/A
--lowering--.f64N/A
*-lowering-*.f6475.8
Simplified75.8%
Taylor expanded in x around 0
--lowering--.f64N/A
*-lowering-*.f64N/A
*-lowering-*.f6475.8
Simplified75.8%
(FPCore (x y z) :precision binary64 (* 0.5 x))
double code(double x, double y, double z) {
return 0.5 * x;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = 0.5d0 * x
end function
public static double code(double x, double y, double z) {
return 0.5 * x;
}
def code(x, y, z): return 0.5 * x
function code(x, y, z) return Float64(0.5 * x) end
function tmp = code(x, y, z) tmp = 0.5 * x; end
code[x_, y_, z_] := N[(0.5 * x), $MachinePrecision]
\begin{array}{l}
\\
0.5 \cdot x
\end{array}
Initial program 99.9%
Taylor expanded in x around inf
+-rgt-identityN/A
accelerator-lowering-fma.f6442.5
Simplified42.5%
+-rgt-identityN/A
*-commutativeN/A
*-lowering-*.f6442.5
Applied egg-rr42.5%
Final simplification42.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 2024195
(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)))))