
(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 6 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 (* x (* y y)))) (if (<= t_1 (- INFINITY)) t_2 (if (<= t_1 5e+304) (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 = x * (y * y);
double tmp;
if (t_1 <= -((double) INFINITY)) {
tmp = t_2;
} else if (t_1 <= 5e+304) {
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(x * Float64(y * y)) tmp = 0.0 if (t_1 <= Float64(-Inf)) tmp = t_2; elseif (t_1 <= 5e+304) 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[(x * N[(y * y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, (-Infinity)], t$95$2, If[LessEqual[t$95$1, 5e+304], 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 := x \cdot \left(y \cdot y\right)\\
\mathbf{if}\;t\_1 \leq -\infty:\\
\;\;\;\;t\_2\\
\mathbf{elif}\;t\_1 \leq 5 \cdot 10^{+304}:\\
\;\;\;\;\mathsf{fma}\left(y, z, t\right)\\
\mathbf{else}:\\
\;\;\;\;t\_2\\
\end{array}
\end{array}
if (*.f64 (+.f64 (*.f64 x y) z) y) < -inf.0 or 4.9999999999999997e304 < (*.f64 (+.f64 (*.f64 x y) z) y) Initial program 100.0%
accelerator-lowering-fma.f64N/A
accelerator-lowering-fma.f64100.0
Applied egg-rr100.0%
Taylor expanded in x around inf
*-lowering-*.f64N/A
unpow2N/A
*-lowering-*.f6485.7
Simplified85.7%
if -inf.0 < (*.f64 (+.f64 (*.f64 x y) z) y) < 4.9999999999999997e304Initial program 99.9%
Taylor expanded in x around 0
+-commutativeN/A
accelerator-lowering-fma.f6481.2
Simplified81.2%
Final simplification82.5%
(FPCore (x y z t) :precision binary64 (let* ((t_1 (* y (fma y x z)))) (if (<= y -8.4e-15) t_1 (if (<= y 3.6e+112) (fma y z t) t_1))))
double code(double x, double y, double z, double t) {
double t_1 = y * fma(y, x, z);
double tmp;
if (y <= -8.4e-15) {
tmp = t_1;
} else if (y <= 3.6e+112) {
tmp = fma(y, z, t);
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z, t) t_1 = Float64(y * fma(y, x, z)) tmp = 0.0 if (y <= -8.4e-15) tmp = t_1; elseif (y <= 3.6e+112) tmp = fma(y, z, t); else tmp = t_1; end return tmp end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(y * N[(y * x + z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -8.4e-15], t$95$1, If[LessEqual[y, 3.6e+112], N[(y * z + t), $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := y \cdot \mathsf{fma}\left(y, x, z\right)\\
\mathbf{if}\;y \leq -8.4 \cdot 10^{-15}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;y \leq 3.6 \cdot 10^{+112}:\\
\;\;\;\;\mathsf{fma}\left(y, z, t\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if y < -8.39999999999999923e-15 or 3.6e112 < 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.f6494.6
Simplified94.6%
if -8.39999999999999923e-15 < y < 3.6e112Initial program 99.9%
Taylor expanded in x around 0
+-commutativeN/A
accelerator-lowering-fma.f6487.1
Simplified87.1%
(FPCore (x y z t) :precision binary64 (if (<= z -320000000.0) (* y z) (if (<= z 9.5e-10) t (* y z))))
double code(double x, double y, double z, double t) {
double tmp;
if (z <= -320000000.0) {
tmp = y * z;
} else if (z <= 9.5e-10) {
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 <= (-320000000.0d0)) then
tmp = y * z
else if (z <= 9.5d-10) 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 <= -320000000.0) {
tmp = y * z;
} else if (z <= 9.5e-10) {
tmp = t;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if z <= -320000000.0: tmp = y * z elif z <= 9.5e-10: tmp = t else: tmp = y * z return tmp
function code(x, y, z, t) tmp = 0.0 if (z <= -320000000.0) tmp = Float64(y * z); elseif (z <= 9.5e-10) tmp = t; else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (z <= -320000000.0) tmp = y * z; elseif (z <= 9.5e-10) tmp = t; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[z, -320000000.0], N[(y * z), $MachinePrecision], If[LessEqual[z, 9.5e-10], t, N[(y * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -320000000:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 9.5 \cdot 10^{-10}:\\
\;\;\;\;t\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if z < -3.2e8 or 9.50000000000000028e-10 < 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-*.f6453.8
Simplified53.8%
if -3.2e8 < z < 9.50000000000000028e-10Initial program 99.8%
Taylor expanded in y around 0
Simplified50.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.f6466.1
Simplified66.1%
(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
Simplified37.4%
herbie shell --seed 2024195
(FPCore (x y z t)
:name "Language.Haskell.HsColour.ColourHighlight:unbase from hscolour-1.23"
:precision binary64
(+ (* (+ (* x y) z) y) t))