
(FPCore (x y z t) :precision binary64 (+ (* (+ (* x y) z) y) t))
double code(double x, double y, double z, double t) {
return (((x * y) + z) * y) + t;
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = (((x * y) + z) * y) + t
end function
public static double code(double x, double y, double z, double t) {
return (((x * y) + z) * y) + t;
}
def code(x, y, z, t): return (((x * y) + z) * y) + t
function code(x, y, z, t) return Float64(Float64(Float64(Float64(x * y) + z) * y) + t) end
function tmp = code(x, y, z, t) tmp = (((x * y) + z) * y) + t; end
code[x_, y_, z_, t_] := N[(N[(N[(N[(x * y), $MachinePrecision] + z), $MachinePrecision] * y), $MachinePrecision] + t), $MachinePrecision]
\begin{array}{l}
\\
\left(x \cdot y + z\right) \cdot y + t
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z t) :precision binary64 (+ (* (+ (* x y) z) y) t))
double code(double x, double y, double z, double t) {
return (((x * y) + z) * y) + t;
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = (((x * y) + z) * y) + t
end function
public static double code(double x, double y, double z, double t) {
return (((x * y) + z) * y) + t;
}
def code(x, y, z, t): return (((x * y) + z) * y) + t
function code(x, y, z, t) return Float64(Float64(Float64(Float64(x * y) + z) * y) + t) end
function tmp = code(x, y, z, t) tmp = (((x * y) + z) * y) + t; end
code[x_, y_, z_, t_] := N[(N[(N[(N[(x * y), $MachinePrecision] + z), $MachinePrecision] * y), $MachinePrecision] + t), $MachinePrecision]
\begin{array}{l}
\\
\left(x \cdot y + z\right) \cdot y + t
\end{array}
(FPCore (x y z t) :precision binary64 (fma (fma x y z) y t))
double code(double x, double y, double z, double t) {
return fma(fma(x, y, z), y, t);
}
function code(x, y, z, t) return fma(fma(x, y, z), y, t) end
code[x_, y_, z_, t_] := N[(N[(x * y + z), $MachinePrecision] * y + t), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\mathsf{fma}\left(x, y, z\right), y, t\right)
\end{array}
Initial program 99.9%
accelerator-lowering-fma.f64N/A
accelerator-lowering-fma.f6499.9
Applied egg-rr99.9%
(FPCore (x y z t) :precision binary64 (let* ((t_1 (* y (+ z (* x y)))) (t_2 (* y (fma y x z)))) (if (<= t_1 -2e+164) t_2 (if (<= t_1 1e+172) (fma y z t) t_2))))
double code(double x, double y, double z, double t) {
double t_1 = y * (z + (x * y));
double t_2 = y * fma(y, x, z);
double tmp;
if (t_1 <= -2e+164) {
tmp = t_2;
} else if (t_1 <= 1e+172) {
tmp = fma(y, z, t);
} else {
tmp = t_2;
}
return tmp;
}
function code(x, y, z, t) t_1 = Float64(y * Float64(z + Float64(x * y))) t_2 = Float64(y * fma(y, x, z)) tmp = 0.0 if (t_1 <= -2e+164) tmp = t_2; elseif (t_1 <= 1e+172) tmp = fma(y, z, t); else tmp = t_2; end return tmp end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(y * N[(z + N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(y * N[(y * x + z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, -2e+164], t$95$2, If[LessEqual[t$95$1, 1e+172], N[(y * z + t), $MachinePrecision], t$95$2]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := y \cdot \left(z + x \cdot y\right)\\
t_2 := y \cdot \mathsf{fma}\left(y, x, z\right)\\
\mathbf{if}\;t\_1 \leq -2 \cdot 10^{+164}:\\
\;\;\;\;t\_2\\
\mathbf{elif}\;t\_1 \leq 10^{+172}:\\
\;\;\;\;\mathsf{fma}\left(y, z, t\right)\\
\mathbf{else}:\\
\;\;\;\;t\_2\\
\end{array}
\end{array}
if (*.f64 (+.f64 (*.f64 x y) z) y) < -2e164 or 1.0000000000000001e172 < (*.f64 (+.f64 (*.f64 x y) z) y) Initial program 99.9%
accelerator-lowering-fma.f64N/A
accelerator-lowering-fma.f6499.9
Applied egg-rr99.9%
Taylor expanded in t around 0
*-lowering-*.f64N/A
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f6496.0
Simplified96.0%
if -2e164 < (*.f64 (+.f64 (*.f64 x y) z) y) < 1.0000000000000001e172Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
accelerator-lowering-fma.f6489.0
Simplified89.0%
Final simplification92.4%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (* y (+ z (* x y)))))
(if (<= t_1 -5e+297)
(* y (* x y))
(if (<= t_1 1e+181) (fma y z t) (* x (* y y))))))
double code(double x, double y, double z, double t) {
double t_1 = y * (z + (x * y));
double tmp;
if (t_1 <= -5e+297) {
tmp = y * (x * y);
} else if (t_1 <= 1e+181) {
tmp = fma(y, z, t);
} else {
tmp = x * (y * y);
}
return tmp;
}
function code(x, y, z, t) t_1 = Float64(y * Float64(z + Float64(x * y))) tmp = 0.0 if (t_1 <= -5e+297) tmp = Float64(y * Float64(x * y)); elseif (t_1 <= 1e+181) tmp = fma(y, z, t); else tmp = Float64(x * Float64(y * y)); end return tmp end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(y * N[(z + N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, -5e+297], N[(y * N[(x * y), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 1e+181], N[(y * z + t), $MachinePrecision], N[(x * N[(y * y), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := y \cdot \left(z + x \cdot y\right)\\
\mathbf{if}\;t\_1 \leq -5 \cdot 10^{+297}:\\
\;\;\;\;y \cdot \left(x \cdot y\right)\\
\mathbf{elif}\;t\_1 \leq 10^{+181}:\\
\;\;\;\;\mathsf{fma}\left(y, z, t\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(y \cdot y\right)\\
\end{array}
\end{array}
if (*.f64 (+.f64 (*.f64 x y) z) y) < -4.9999999999999998e297Initial program 99.9%
accelerator-lowering-fma.f64N/A
accelerator-lowering-fma.f6499.9
Applied egg-rr99.9%
Taylor expanded in x around inf
+-rgt-identityN/A
accelerator-lowering-fma.f64N/A
unpow2N/A
*-lowering-*.f6486.0
Simplified86.0%
+-rgt-identityN/A
associate-*r*N/A
*-lowering-*.f64N/A
*-lowering-*.f6487.7
Applied egg-rr87.7%
if -4.9999999999999998e297 < (*.f64 (+.f64 (*.f64 x y) z) y) < 9.9999999999999992e180Initial program 99.9%
Taylor expanded in x around 0
+-commutativeN/A
accelerator-lowering-fma.f6485.7
Simplified85.7%
if 9.9999999999999992e180 < (*.f64 (+.f64 (*.f64 x y) z) y) Initial program 99.9%
accelerator-lowering-fma.f64N/A
accelerator-lowering-fma.f6499.9
Applied egg-rr99.9%
Taylor expanded in x around inf
+-rgt-identityN/A
accelerator-lowering-fma.f64N/A
unpow2N/A
*-lowering-*.f6484.7
Simplified84.7%
+-rgt-identityN/A
*-commutativeN/A
*-lowering-*.f64N/A
*-lowering-*.f6484.7
Applied egg-rr84.7%
Final simplification85.8%
(FPCore (x y z t) :precision binary64 (let* ((t_1 (* y (+ z (* x y)))) (t_2 (* y (* x y)))) (if (<= t_1 -5e+297) t_2 (if (<= t_1 2e+244) (fma y z t) t_2))))
double code(double x, double y, double z, double t) {
double t_1 = y * (z + (x * y));
double t_2 = y * (x * y);
double tmp;
if (t_1 <= -5e+297) {
tmp = t_2;
} else if (t_1 <= 2e+244) {
tmp = fma(y, z, t);
} else {
tmp = t_2;
}
return tmp;
}
function code(x, y, z, t) t_1 = Float64(y * Float64(z + Float64(x * y))) t_2 = Float64(y * Float64(x * y)) tmp = 0.0 if (t_1 <= -5e+297) tmp = t_2; elseif (t_1 <= 2e+244) tmp = fma(y, z, t); else tmp = t_2; end return tmp end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(y * N[(z + N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(y * N[(x * y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, -5e+297], t$95$2, If[LessEqual[t$95$1, 2e+244], N[(y * z + t), $MachinePrecision], t$95$2]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := y \cdot \left(z + x \cdot y\right)\\
t_2 := y \cdot \left(x \cdot y\right)\\
\mathbf{if}\;t\_1 \leq -5 \cdot 10^{+297}:\\
\;\;\;\;t\_2\\
\mathbf{elif}\;t\_1 \leq 2 \cdot 10^{+244}:\\
\;\;\;\;\mathsf{fma}\left(y, z, t\right)\\
\mathbf{else}:\\
\;\;\;\;t\_2\\
\end{array}
\end{array}
if (*.f64 (+.f64 (*.f64 x y) z) y) < -4.9999999999999998e297 or 2.00000000000000015e244 < (*.f64 (+.f64 (*.f64 x y) z) y) Initial program 99.9%
accelerator-lowering-fma.f64N/A
accelerator-lowering-fma.f6499.9
Applied egg-rr99.9%
Taylor expanded in x around inf
+-rgt-identityN/A
accelerator-lowering-fma.f64N/A
unpow2N/A
*-lowering-*.f6487.5
Simplified87.5%
+-rgt-identityN/A
associate-*r*N/A
*-lowering-*.f64N/A
*-lowering-*.f6488.2
Applied egg-rr88.2%
if -4.9999999999999998e297 < (*.f64 (+.f64 (*.f64 x y) z) y) < 2.00000000000000015e244Initial program 99.9%
Taylor expanded in x around 0
+-commutativeN/A
accelerator-lowering-fma.f6484.4
Simplified84.4%
Final simplification85.8%
(FPCore (x y z t) :precision binary64 (if (<= z -1.32e+88) (* y z) (if (<= z 9.8e+134) t (* y z))))
double code(double x, double y, double z, double t) {
double tmp;
if (z <= -1.32e+88) {
tmp = y * z;
} else if (z <= 9.8e+134) {
tmp = t;
} else {
tmp = y * z;
}
return tmp;
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: tmp
if (z <= (-1.32d+88)) then
tmp = y * z
else if (z <= 9.8d+134) then
tmp = t
else
tmp = y * z
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (z <= -1.32e+88) {
tmp = y * z;
} else if (z <= 9.8e+134) {
tmp = t;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if z <= -1.32e+88: tmp = y * z elif z <= 9.8e+134: tmp = t else: tmp = y * z return tmp
function code(x, y, z, t) tmp = 0.0 if (z <= -1.32e+88) tmp = Float64(y * z); elseif (z <= 9.8e+134) tmp = t; else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (z <= -1.32e+88) tmp = y * z; elseif (z <= 9.8e+134) tmp = t; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[z, -1.32e+88], N[(y * z), $MachinePrecision], If[LessEqual[z, 9.8e+134], t, N[(y * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.32 \cdot 10^{+88}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 9.8 \cdot 10^{+134}:\\
\;\;\;\;t\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if z < -1.3200000000000001e88 or 9.79999999999999992e134 < z Initial program 100.0%
accelerator-lowering-fma.f64N/A
accelerator-lowering-fma.f64100.0
Applied egg-rr100.0%
Taylor expanded in z around inf
*-lowering-*.f6460.4
Simplified60.4%
if -1.3200000000000001e88 < z < 9.79999999999999992e134Initial program 99.9%
Taylor expanded in y around 0
Simplified47.3%
(FPCore (x y z t) :precision binary64 (fma y z t))
double code(double x, double y, double z, double t) {
return fma(y, z, t);
}
function code(x, y, z, t) return fma(y, z, t) end
code[x_, y_, z_, t_] := N[(y * z + t), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y, z, t\right)
\end{array}
Initial program 99.9%
Taylor expanded in x around 0
+-commutativeN/A
accelerator-lowering-fma.f6462.9
Simplified62.9%
(FPCore (x y z t) :precision binary64 t)
double code(double x, double y, double z, double t) {
return t;
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = t
end function
public static double code(double x, double y, double z, double t) {
return t;
}
def code(x, y, z, t): return t
function code(x, y, z, t) return t end
function tmp = code(x, y, z, t) tmp = t; end
code[x_, y_, z_, t_] := t
\begin{array}{l}
\\
t
\end{array}
Initial program 99.9%
Taylor expanded in y around 0
Simplified38.3%
herbie shell --seed 2024198
(FPCore (x y z t)
:name "Language.Haskell.HsColour.ColourHighlight:unbase from hscolour-1.23"
:precision binary64
(+ (* (+ (* x y) z) y) t))