
(FPCore (x y z) :precision binary64 (+ (+ (/ x 2.0) (* y x)) z))
double code(double x, double y, double z) {
return ((x / 2.0) + (y * x)) + 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 / 2.0d0) + (y * x)) + z
end function
public static double code(double x, double y, double z) {
return ((x / 2.0) + (y * x)) + z;
}
def code(x, y, z): return ((x / 2.0) + (y * x)) + z
function code(x, y, z) return Float64(Float64(Float64(x / 2.0) + Float64(y * x)) + z) end
function tmp = code(x, y, z) tmp = ((x / 2.0) + (y * x)) + z; end
code[x_, y_, z_] := N[(N[(N[(x / 2.0), $MachinePrecision] + N[(y * x), $MachinePrecision]), $MachinePrecision] + z), $MachinePrecision]
\begin{array}{l}
\\
\left(\frac{x}{2} + y \cdot x\right) + z
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ (+ (/ x 2.0) (* y x)) z))
double code(double x, double y, double z) {
return ((x / 2.0) + (y * x)) + 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 / 2.0d0) + (y * x)) + z
end function
public static double code(double x, double y, double z) {
return ((x / 2.0) + (y * x)) + z;
}
def code(x, y, z): return ((x / 2.0) + (y * x)) + z
function code(x, y, z) return Float64(Float64(Float64(x / 2.0) + Float64(y * x)) + z) end
function tmp = code(x, y, z) tmp = ((x / 2.0) + (y * x)) + z; end
code[x_, y_, z_] := N[(N[(N[(x / 2.0), $MachinePrecision] + N[(y * x), $MachinePrecision]), $MachinePrecision] + z), $MachinePrecision]
\begin{array}{l}
\\
\left(\frac{x}{2} + y \cdot x\right) + z
\end{array}
(FPCore (x y z) :precision binary64 (fma (+ y 0.5) x z))
double code(double x, double y, double z) {
return fma((y + 0.5), x, z);
}
function code(x, y, z) return fma(Float64(y + 0.5), x, z) end
code[x_, y_, z_] := N[(N[(y + 0.5), $MachinePrecision] * x + z), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y + 0.5, x, z\right)
\end{array}
Initial program 100.0%
div-invN/A
*-commutativeN/A
distribute-lft-outN/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
+-commutativeN/A
+-lowering-+.f64N/A
metadata-eval100.0
Applied egg-rr100.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (+ (* y x) (/ x 2.0))))
(if (<= t_0 -2e+66)
(* y x)
(if (<= t_0 1000000000000.0) z (if (<= t_0 4e+246) (* 0.5 x) (* y x))))))
double code(double x, double y, double z) {
double t_0 = (y * x) + (x / 2.0);
double tmp;
if (t_0 <= -2e+66) {
tmp = y * x;
} else if (t_0 <= 1000000000000.0) {
tmp = z;
} else if (t_0 <= 4e+246) {
tmp = 0.5 * x;
} else {
tmp = y * x;
}
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 * x) + (x / 2.0d0)
if (t_0 <= (-2d+66)) then
tmp = y * x
else if (t_0 <= 1000000000000.0d0) then
tmp = z
else if (t_0 <= 4d+246) then
tmp = 0.5d0 * x
else
tmp = y * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = (y * x) + (x / 2.0);
double tmp;
if (t_0 <= -2e+66) {
tmp = y * x;
} else if (t_0 <= 1000000000000.0) {
tmp = z;
} else if (t_0 <= 4e+246) {
tmp = 0.5 * x;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y, z): t_0 = (y * x) + (x / 2.0) tmp = 0 if t_0 <= -2e+66: tmp = y * x elif t_0 <= 1000000000000.0: tmp = z elif t_0 <= 4e+246: tmp = 0.5 * x else: tmp = y * x return tmp
function code(x, y, z) t_0 = Float64(Float64(y * x) + Float64(x / 2.0)) tmp = 0.0 if (t_0 <= -2e+66) tmp = Float64(y * x); elseif (t_0 <= 1000000000000.0) tmp = z; elseif (t_0 <= 4e+246) tmp = Float64(0.5 * x); else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y, z) t_0 = (y * x) + (x / 2.0); tmp = 0.0; if (t_0 <= -2e+66) tmp = y * x; elseif (t_0 <= 1000000000000.0) tmp = z; elseif (t_0 <= 4e+246) tmp = 0.5 * x; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(y * x), $MachinePrecision] + N[(x / 2.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -2e+66], N[(y * x), $MachinePrecision], If[LessEqual[t$95$0, 1000000000000.0], z, If[LessEqual[t$95$0, 4e+246], N[(0.5 * x), $MachinePrecision], N[(y * x), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot x + \frac{x}{2}\\
\mathbf{if}\;t\_0 \leq -2 \cdot 10^{+66}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;t\_0 \leq 1000000000000:\\
\;\;\;\;z\\
\mathbf{elif}\;t\_0 \leq 4 \cdot 10^{+246}:\\
\;\;\;\;0.5 \cdot x\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if (+.f64 (/.f64 x #s(literal 2 binary64)) (*.f64 y x)) < -1.99999999999999989e66 or 4.00000000000000027e246 < (+.f64 (/.f64 x #s(literal 2 binary64)) (*.f64 y x)) Initial program 100.0%
Taylor expanded in y around inf
*-lowering-*.f6468.7
Simplified68.7%
if -1.99999999999999989e66 < (+.f64 (/.f64 x #s(literal 2 binary64)) (*.f64 y x)) < 1e12Initial program 100.0%
Taylor expanded in x around 0
Simplified74.8%
if 1e12 < (+.f64 (/.f64 x #s(literal 2 binary64)) (*.f64 y x)) < 4.00000000000000027e246Initial program 100.0%
Taylor expanded in x around inf
*-lowering-*.f64N/A
+-lowering-+.f6479.6
Simplified79.6%
Taylor expanded in y around 0
Simplified50.8%
Final simplification68.3%
(FPCore (x y z) :precision binary64 (if (<= y -2100.0) (fma y x z) (if (<= y 0.5) (fma x 0.5 z) (fma y x z))))
double code(double x, double y, double z) {
double tmp;
if (y <= -2100.0) {
tmp = fma(y, x, z);
} else if (y <= 0.5) {
tmp = fma(x, 0.5, z);
} else {
tmp = fma(y, x, z);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (y <= -2100.0) tmp = fma(y, x, z); elseif (y <= 0.5) tmp = fma(x, 0.5, z); else tmp = fma(y, x, z); end return tmp end
code[x_, y_, z_] := If[LessEqual[y, -2100.0], N[(y * x + z), $MachinePrecision], If[LessEqual[y, 0.5], N[(x * 0.5 + z), $MachinePrecision], N[(y * x + z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2100:\\
\;\;\;\;\mathsf{fma}\left(y, x, z\right)\\
\mathbf{elif}\;y \leq 0.5:\\
\;\;\;\;\mathsf{fma}\left(x, 0.5, z\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y, x, z\right)\\
\end{array}
\end{array}
if y < -2100 or 0.5 < y Initial program 100.0%
div-invN/A
*-commutativeN/A
distribute-lft-outN/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
+-commutativeN/A
+-lowering-+.f64N/A
metadata-eval100.0
Applied egg-rr100.0%
Taylor expanded in y around inf
Simplified99.3%
if -2100 < y < 0.5Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f6498.9
Simplified98.9%
(FPCore (x y z) :precision binary64 (if (<= y -1.28e+67) (* y x) (if (<= y 1.3e+72) (fma x 0.5 z) (* y x))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.28e+67) {
tmp = y * x;
} else if (y <= 1.3e+72) {
tmp = fma(x, 0.5, z);
} else {
tmp = y * x;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (y <= -1.28e+67) tmp = Float64(y * x); elseif (y <= 1.3e+72) tmp = fma(x, 0.5, z); else tmp = Float64(y * x); end return tmp end
code[x_, y_, z_] := If[LessEqual[y, -1.28e+67], N[(y * x), $MachinePrecision], If[LessEqual[y, 1.3e+72], N[(x * 0.5 + z), $MachinePrecision], N[(y * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.28 \cdot 10^{+67}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq 1.3 \cdot 10^{+72}:\\
\;\;\;\;\mathsf{fma}\left(x, 0.5, z\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if y < -1.28e67 or 1.29999999999999991e72 < y Initial program 100.0%
Taylor expanded in y around inf
*-lowering-*.f6481.0
Simplified81.0%
if -1.28e67 < y < 1.29999999999999991e72Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f6492.2
Simplified92.2%
Final simplification87.4%
(FPCore (x y z) :precision binary64 (if (<= z -3e-45) z (if (<= z 35000000000000.0) (* 0.5 x) z)))
double code(double x, double y, double z) {
double tmp;
if (z <= -3e-45) {
tmp = z;
} else if (z <= 35000000000000.0) {
tmp = 0.5 * x;
} else {
tmp = 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 <= (-3d-45)) then
tmp = z
else if (z <= 35000000000000.0d0) then
tmp = 0.5d0 * x
else
tmp = z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -3e-45) {
tmp = z;
} else if (z <= 35000000000000.0) {
tmp = 0.5 * x;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -3e-45: tmp = z elif z <= 35000000000000.0: tmp = 0.5 * x else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -3e-45) tmp = z; elseif (z <= 35000000000000.0) tmp = Float64(0.5 * x); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -3e-45) tmp = z; elseif (z <= 35000000000000.0) tmp = 0.5 * x; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -3e-45], z, If[LessEqual[z, 35000000000000.0], N[(0.5 * x), $MachinePrecision], z]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3 \cdot 10^{-45}:\\
\;\;\;\;z\\
\mathbf{elif}\;z \leq 35000000000000:\\
\;\;\;\;0.5 \cdot x\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if z < -3.00000000000000011e-45 or 3.5e13 < z Initial program 100.0%
Taylor expanded in x around 0
Simplified61.3%
if -3.00000000000000011e-45 < z < 3.5e13Initial program 100.0%
Taylor expanded in x around inf
*-lowering-*.f64N/A
+-lowering-+.f6487.2
Simplified87.2%
Taylor expanded in y around 0
Simplified40.0%
Final simplification51.4%
(FPCore (x y z) :precision binary64 z)
double code(double x, double y, double z) {
return z;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = z
end function
public static double code(double x, double y, double z) {
return z;
}
def code(x, y, z): return z
function code(x, y, z) return z end
function tmp = code(x, y, z) tmp = z; end
code[x_, y_, z_] := z
\begin{array}{l}
\\
z
\end{array}
Initial program 100.0%
Taylor expanded in x around 0
Simplified40.1%
herbie shell --seed 2024205
(FPCore (x y z)
:name "Data.Histogram.Bin.BinF:$cfromIndex from histogram-fill-0.8.4.1"
:precision binary64
(+ (+ (/ x 2.0) (* y x)) z))