
(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 x (fma x 0.5 z)))
double code(double x, double y, double z) {
return fma(y, x, fma(x, 0.5, z));
}
function code(x, y, z) return fma(y, x, fma(x, 0.5, z)) end
code[x_, y_, z_] := N[(y * x + N[(x * 0.5 + z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y, x, \mathsf{fma}\left(x, 0.5, z\right)\right)
\end{array}
Initial program 100.0%
+-commutativeN/A
associate-+l+N/A
accelerator-lowering-fma.f64N/A
div-invN/A
accelerator-lowering-fma.f64N/A
metadata-eval100.0
Applied egg-rr100.0%
(FPCore (x y z) :precision binary64 (if (<= y -8.4e+81) (* y x) (if (<= y 1.25e-149) z (if (<= y 0.5) (* x 0.5) (* y x)))))
double code(double x, double y, double z) {
double tmp;
if (y <= -8.4e+81) {
tmp = y * x;
} else if (y <= 1.25e-149) {
tmp = z;
} else if (y <= 0.5) {
tmp = x * 0.5;
} 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) :: tmp
if (y <= (-8.4d+81)) then
tmp = y * x
else if (y <= 1.25d-149) then
tmp = z
else if (y <= 0.5d0) then
tmp = x * 0.5d0
else
tmp = y * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -8.4e+81) {
tmp = y * x;
} else if (y <= 1.25e-149) {
tmp = z;
} else if (y <= 0.5) {
tmp = x * 0.5;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -8.4e+81: tmp = y * x elif y <= 1.25e-149: tmp = z elif y <= 0.5: tmp = x * 0.5 else: tmp = y * x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -8.4e+81) tmp = Float64(y * x); elseif (y <= 1.25e-149) tmp = z; elseif (y <= 0.5) tmp = Float64(x * 0.5); else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -8.4e+81) tmp = y * x; elseif (y <= 1.25e-149) tmp = z; elseif (y <= 0.5) tmp = x * 0.5; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -8.4e+81], N[(y * x), $MachinePrecision], If[LessEqual[y, 1.25e-149], z, If[LessEqual[y, 0.5], N[(x * 0.5), $MachinePrecision], N[(y * x), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -8.4 \cdot 10^{+81}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq 1.25 \cdot 10^{-149}:\\
\;\;\;\;z\\
\mathbf{elif}\;y \leq 0.5:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if y < -8.3999999999999994e81 or 0.5 < y Initial program 100.0%
Taylor expanded in y around inf
*-lowering-*.f6475.9
Simplified75.9%
if -8.3999999999999994e81 < y < 1.24999999999999992e-149Initial program 100.0%
Taylor expanded in x around 0
Simplified58.1%
if 1.24999999999999992e-149 < y < 0.5Initial program 100.0%
Taylor expanded in x around inf
*-lowering-*.f64N/A
+-lowering-+.f6466.4
Simplified66.4%
Taylor expanded in y around 0
Simplified60.8%
Final simplification66.3%
(FPCore (x y z) :precision binary64 (if (<= y -0.5) (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 <= -0.5) {
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 <= -0.5) 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, -0.5], 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 -0.5:\\
\;\;\;\;\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 < -0.5 or 0.5 < y Initial program 100.0%
+-commutativeN/A
associate-+l+N/A
accelerator-lowering-fma.f64N/A
div-invN/A
accelerator-lowering-fma.f64N/A
metadata-eval100.0
Applied egg-rr100.0%
Taylor expanded in x around 0
Simplified97.8%
if -0.5 < y < 0.5Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f6498.5
Simplified98.5%
(FPCore (x y z) :precision binary64 (if (<= y -1.5e+81) (* y x) (if (<= y 0.94) (fma x 0.5 z) (* y x))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.5e+81) {
tmp = y * x;
} else if (y <= 0.94) {
tmp = fma(x, 0.5, z);
} else {
tmp = y * x;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (y <= -1.5e+81) tmp = Float64(y * x); elseif (y <= 0.94) tmp = fma(x, 0.5, z); else tmp = Float64(y * x); end return tmp end
code[x_, y_, z_] := If[LessEqual[y, -1.5e+81], N[(y * x), $MachinePrecision], If[LessEqual[y, 0.94], N[(x * 0.5 + z), $MachinePrecision], N[(y * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.5 \cdot 10^{+81}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq 0.94:\\
\;\;\;\;\mathsf{fma}\left(x, 0.5, z\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if y < -1.49999999999999999e81 or 0.93999999999999995 < y Initial program 100.0%
Taylor expanded in y around inf
*-lowering-*.f6475.9
Simplified75.9%
if -1.49999999999999999e81 < y < 0.93999999999999995Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f6493.8
Simplified93.8%
Final simplification85.9%
(FPCore (x y z) :precision binary64 (if (<= z -1.7e-71) z (if (<= z 1.15e-95) (* x 0.5) z)))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.7e-71) {
tmp = z;
} else if (z <= 1.15e-95) {
tmp = x * 0.5;
} 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 <= (-1.7d-71)) then
tmp = z
else if (z <= 1.15d-95) then
tmp = x * 0.5d0
else
tmp = z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -1.7e-71) {
tmp = z;
} else if (z <= 1.15e-95) {
tmp = x * 0.5;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.7e-71: tmp = z elif z <= 1.15e-95: tmp = x * 0.5 else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.7e-71) tmp = z; elseif (z <= 1.15e-95) tmp = Float64(x * 0.5); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -1.7e-71) tmp = z; elseif (z <= 1.15e-95) tmp = x * 0.5; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.7e-71], z, If[LessEqual[z, 1.15e-95], N[(x * 0.5), $MachinePrecision], z]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.7 \cdot 10^{-71}:\\
\;\;\;\;z\\
\mathbf{elif}\;z \leq 1.15 \cdot 10^{-95}:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if z < -1.70000000000000002e-71 or 1.15e-95 < z Initial program 100.0%
Taylor expanded in x around 0
Simplified57.9%
if -1.70000000000000002e-71 < z < 1.15e-95Initial program 100.0%
Taylor expanded in x around inf
*-lowering-*.f64N/A
+-lowering-+.f6489.3
Simplified89.3%
Taylor expanded in y around 0
Simplified47.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.5%
herbie shell --seed 2024204
(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))