
(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 9 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 (+ z (* x y)) y t))
double code(double x, double y, double z, double t) {
return fma((z + (x * y)), y, t);
}
function code(x, y, z, t) return fma(Float64(z + Float64(x * y)), y, t) end
code[x_, y_, z_, t_] := N[(N[(z + N[(x * y), $MachinePrecision]), $MachinePrecision] * y + t), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(z + x \cdot y, y, t\right)
\end{array}
Initial program 99.9%
accelerator-lowering-fma.f64N/A
accelerator-lowering-fma.f6499.9
Applied egg-rr99.9%
+-lowering-+.f64N/A
*-lowering-*.f6499.9
Applied egg-rr99.9%
Final simplification99.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 -1e+224) t_2 (if (<= t_1 5e+103) (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 <= -1e+224) {
tmp = t_2;
} else if (t_1 <= 5e+103) {
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 <= -1e+224) tmp = t_2; elseif (t_1 <= 5e+103) 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, -1e+224], t$95$2, If[LessEqual[t$95$1, 5e+103], 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 -1 \cdot 10^{+224}:\\
\;\;\;\;t\_2\\
\mathbf{elif}\;t\_1 \leq 5 \cdot 10^{+103}:\\
\;\;\;\;\mathsf{fma}\left(y, z, t\right)\\
\mathbf{else}:\\
\;\;\;\;t\_2\\
\end{array}
\end{array}
if (*.f64 (+.f64 (*.f64 x y) z) y) < -9.9999999999999997e223 or 5e103 < (*.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.f6498.8
Simplified98.8%
if -9.9999999999999997e223 < (*.f64 (+.f64 (*.f64 x y) z) y) < 5e103Initial program 99.9%
Taylor expanded in x around 0
+-commutativeN/A
accelerator-lowering-fma.f6484.9
Simplified84.9%
Final simplification91.0%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (* y (+ z (* x y)))))
(if (<= t_1 -2e+265)
(* x (* y y))
(if (<= t_1 2e+270) (fma y z t) (* y (* x y))))))
double code(double x, double y, double z, double t) {
double t_1 = y * (z + (x * y));
double tmp;
if (t_1 <= -2e+265) {
tmp = x * (y * y);
} else if (t_1 <= 2e+270) {
tmp = fma(y, z, t);
} else {
tmp = y * (x * y);
}
return tmp;
}
function code(x, y, z, t) t_1 = Float64(y * Float64(z + Float64(x * y))) tmp = 0.0 if (t_1 <= -2e+265) tmp = Float64(x * Float64(y * y)); elseif (t_1 <= 2e+270) tmp = fma(y, z, t); else tmp = Float64(y * Float64(x * 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, -2e+265], N[(x * N[(y * y), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 2e+270], N[(y * z + t), $MachinePrecision], N[(y * N[(x * y), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := y \cdot \left(z + x \cdot y\right)\\
\mathbf{if}\;t\_1 \leq -2 \cdot 10^{+265}:\\
\;\;\;\;x \cdot \left(y \cdot y\right)\\
\mathbf{elif}\;t\_1 \leq 2 \cdot 10^{+270}:\\
\;\;\;\;\mathsf{fma}\left(y, z, t\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(x \cdot y\right)\\
\end{array}
\end{array}
if (*.f64 (+.f64 (*.f64 x y) z) y) < -2.00000000000000013e265Initial program 99.9%
accelerator-lowering-fma.f64N/A
accelerator-lowering-fma.f6499.9
Applied egg-rr99.9%
+-lowering-+.f64N/A
*-lowering-*.f6499.9
Applied egg-rr99.9%
Taylor expanded in x around inf
*-lowering-*.f64N/A
unpow2N/A
*-lowering-*.f6485.1
Simplified85.1%
if -2.00000000000000013e265 < (*.f64 (+.f64 (*.f64 x y) z) y) < 2.0000000000000001e270Initial program 99.9%
Taylor expanded in x around 0
+-commutativeN/A
accelerator-lowering-fma.f6482.8
Simplified82.8%
if 2.0000000000000001e270 < (*.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
unpow2N/A
associate-*r*N/A
*-commutativeN/A
*-lowering-*.f64N/A
*-commutativeN/A
*-lowering-*.f6479.0
Simplified79.0%
Final simplification82.6%
(FPCore (x y z t) :precision binary64 (let* ((t_1 (* y (+ z (* x y)))) (t_2 (* x (* y y)))) (if (<= t_1 -2e+265) t_2 (if (<= t_1 2e+270) (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 <= -2e+265) {
tmp = t_2;
} else if (t_1 <= 2e+270) {
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 <= -2e+265) tmp = t_2; elseif (t_1 <= 2e+270) 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, -2e+265], t$95$2, If[LessEqual[t$95$1, 2e+270], 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 -2 \cdot 10^{+265}:\\
\;\;\;\;t\_2\\
\mathbf{elif}\;t\_1 \leq 2 \cdot 10^{+270}:\\
\;\;\;\;\mathsf{fma}\left(y, z, t\right)\\
\mathbf{else}:\\
\;\;\;\;t\_2\\
\end{array}
\end{array}
if (*.f64 (+.f64 (*.f64 x y) z) y) < -2.00000000000000013e265 or 2.0000000000000001e270 < (*.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%
+-lowering-+.f64N/A
*-lowering-*.f6499.9
Applied egg-rr99.9%
Taylor expanded in x around inf
*-lowering-*.f64N/A
unpow2N/A
*-lowering-*.f6481.2
Simplified81.2%
if -2.00000000000000013e265 < (*.f64 (+.f64 (*.f64 x y) z) y) < 2.0000000000000001e270Initial program 99.9%
Taylor expanded in x around 0
+-commutativeN/A
accelerator-lowering-fma.f6482.8
Simplified82.8%
Final simplification82.2%
(FPCore (x y z t) :precision binary64 (if (<= z -6.6e+115) (fma y z t) (if (<= z 3.2e+25) (fma (* x y) y t) (* y (fma y x z)))))
double code(double x, double y, double z, double t) {
double tmp;
if (z <= -6.6e+115) {
tmp = fma(y, z, t);
} else if (z <= 3.2e+25) {
tmp = fma((x * y), y, t);
} else {
tmp = y * fma(y, x, z);
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (z <= -6.6e+115) tmp = fma(y, z, t); elseif (z <= 3.2e+25) tmp = fma(Float64(x * y), y, t); else tmp = Float64(y * fma(y, x, z)); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[z, -6.6e+115], N[(y * z + t), $MachinePrecision], If[LessEqual[z, 3.2e+25], N[(N[(x * y), $MachinePrecision] * y + t), $MachinePrecision], N[(y * N[(y * x + z), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -6.6 \cdot 10^{+115}:\\
\;\;\;\;\mathsf{fma}\left(y, z, t\right)\\
\mathbf{elif}\;z \leq 3.2 \cdot 10^{+25}:\\
\;\;\;\;\mathsf{fma}\left(x \cdot y, y, t\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \mathsf{fma}\left(y, x, z\right)\\
\end{array}
\end{array}
if z < -6.6000000000000001e115Initial program 99.9%
Taylor expanded in x around 0
+-commutativeN/A
accelerator-lowering-fma.f6483.8
Simplified83.8%
if -6.6000000000000001e115 < z < 3.1999999999999999e25Initial program 99.9%
accelerator-lowering-fma.f64N/A
accelerator-lowering-fma.f6499.9
Applied egg-rr99.9%
Taylor expanded in x around inf
*-commutativeN/A
*-lowering-*.f6494.8
Simplified94.8%
if 3.1999999999999999e25 < z 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.f6487.4
Simplified87.4%
Final simplification91.5%
(FPCore (x y z t) :precision binary64 (if (<= z -1.3e+116) (* y z) (if (<= z 1.36e+28) t (* y z))))
double code(double x, double y, double z, double t) {
double tmp;
if (z <= -1.3e+116) {
tmp = y * z;
} else if (z <= 1.36e+28) {
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.3d+116)) then
tmp = y * z
else if (z <= 1.36d+28) 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.3e+116) {
tmp = y * z;
} else if (z <= 1.36e+28) {
tmp = t;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if z <= -1.3e+116: tmp = y * z elif z <= 1.36e+28: tmp = t else: tmp = y * z return tmp
function code(x, y, z, t) tmp = 0.0 if (z <= -1.3e+116) tmp = Float64(y * z); elseif (z <= 1.36e+28) 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.3e+116) tmp = y * z; elseif (z <= 1.36e+28) tmp = t; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[z, -1.3e+116], N[(y * z), $MachinePrecision], If[LessEqual[z, 1.36e+28], t, N[(y * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.3 \cdot 10^{+116}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 1.36 \cdot 10^{+28}:\\
\;\;\;\;t\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if z < -1.29999999999999993e116 or 1.36e28 < z Initial program 99.9%
accelerator-lowering-fma.f64N/A
accelerator-lowering-fma.f6499.9
Applied egg-rr99.9%
Taylor expanded in z around inf
*-lowering-*.f6463.4
Simplified63.4%
if -1.29999999999999993e116 < z < 1.36e28Initial program 99.9%
Taylor expanded in y around 0
Simplified50.6%
(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 (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.f6464.3
Simplified64.3%
(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
Simplified39.1%
herbie shell --seed 2024196
(FPCore (x y z t)
:name "Language.Haskell.HsColour.ColourHighlight:unbase from hscolour-1.23"
:precision binary64
(+ (* (+ (* x y) z) y) t))