
(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 100.0%
lift-*.f64N/A
lift-+.f64N/A
lower-fma.f64100.0
lift-+.f64N/A
lift-*.f64N/A
lower-fma.f64100.0
Applied rewrites100.0%
(FPCore (x y z t) :precision binary64 (let* ((t_1 (+ t (* y (+ z (* x y))))) (t_2 (* x (* y y)))) (if (<= t_1 -1e+263) t_2 (if (<= t_1 INFINITY) (fma y z t) t_2))))
double code(double x, double y, double z, double t) {
double t_1 = t + (y * (z + (x * y)));
double t_2 = x * (y * y);
double tmp;
if (t_1 <= -1e+263) {
tmp = t_2;
} else if (t_1 <= ((double) INFINITY)) {
tmp = fma(y, z, t);
} else {
tmp = t_2;
}
return tmp;
}
function code(x, y, z, t) t_1 = Float64(t + Float64(y * Float64(z + Float64(x * y)))) t_2 = Float64(x * Float64(y * y)) tmp = 0.0 if (t_1 <= -1e+263) tmp = t_2; elseif (t_1 <= Inf) tmp = fma(y, z, t); else tmp = t_2; end return tmp end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(t + N[(y * N[(z + N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(x * N[(y * y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, -1e+263], t$95$2, If[LessEqual[t$95$1, Infinity], N[(y * z + t), $MachinePrecision], t$95$2]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := t + y \cdot \left(z + x \cdot y\right)\\
t_2 := x \cdot \left(y \cdot y\right)\\
\mathbf{if}\;t\_1 \leq -1 \cdot 10^{+263}:\\
\;\;\;\;t\_2\\
\mathbf{elif}\;t\_1 \leq \infty:\\
\;\;\;\;\mathsf{fma}\left(y, z, t\right)\\
\mathbf{else}:\\
\;\;\;\;t\_2\\
\end{array}
\end{array}
if (+.f64 (*.f64 (+.f64 (*.f64 x y) z) y) t) < -1.00000000000000002e263 or +inf.0 < (+.f64 (*.f64 (+.f64 (*.f64 x y) z) y) t) Initial program 99.9%
Taylor expanded in x around inf
unpow2N/A
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6480.6
Applied rewrites80.6%
associate-*r*N/A
lower-*.f64N/A
lower-*.f6480.8
Applied rewrites80.8%
if -1.00000000000000002e263 < (+.f64 (*.f64 (+.f64 (*.f64 x y) z) y) t) < +inf.0Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f6476.5
Applied rewrites76.5%
Final simplification77.4%
(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+108) t_2 (if (<= t_1 6e+118) (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+108) {
tmp = t_2;
} else if (t_1 <= 6e+118) {
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+108) tmp = t_2; elseif (t_1 <= 6e+118) 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+108], t$95$2, If[LessEqual[t$95$1, 6e+118], 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^{+108}:\\
\;\;\;\;t\_2\\
\mathbf{elif}\;t\_1 \leq 6 \cdot 10^{+118}:\\
\;\;\;\;\mathsf{fma}\left(y, z, t\right)\\
\mathbf{else}:\\
\;\;\;\;t\_2\\
\end{array}
\end{array}
if (*.f64 (+.f64 (*.f64 x y) z) y) < -1e108 or 6e118 < (*.f64 (+.f64 (*.f64 x y) z) y) Initial program 99.9%
Taylor expanded in y around inf
Applied rewrites95.6%
if -1e108 < (*.f64 (+.f64 (*.f64 x y) z) y) < 6e118Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f6492.1
Applied rewrites92.1%
Final simplification93.8%
(FPCore (x y z t) :precision binary64 (let* ((t_1 (* y (* x y)))) (if (<= y -1.8e+138) t_1 (if (<= y 14.0) (fma y z t) t_1))))
double code(double x, double y, double z, double t) {
double t_1 = y * (x * y);
double tmp;
if (y <= -1.8e+138) {
tmp = t_1;
} else if (y <= 14.0) {
tmp = fma(y, z, t);
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z, t) t_1 = Float64(y * Float64(x * y)) tmp = 0.0 if (y <= -1.8e+138) tmp = t_1; elseif (y <= 14.0) 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[(x * y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -1.8e+138], t$95$1, If[LessEqual[y, 14.0], N[(y * z + t), $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := y \cdot \left(x \cdot y\right)\\
\mathbf{if}\;y \leq -1.8 \cdot 10^{+138}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;y \leq 14:\\
\;\;\;\;\mathsf{fma}\left(y, z, t\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if y < -1.8000000000000001e138 or 14 < y Initial program 99.9%
Taylor expanded in x around inf
unpow2N/A
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6475.7
Applied rewrites75.7%
if -1.8000000000000001e138 < y < 14Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f6488.1
Applied rewrites88.1%
Final simplification83.1%
(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 100.0%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f6468.2
Applied rewrites68.2%
(FPCore (x y z t) :precision binary64 (* y z))
double code(double x, double y, double z, double t) {
return y * z;
}
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 = y * z
end function
public static double code(double x, double y, double z, double t) {
return y * z;
}
def code(x, y, z, t): return y * z
function code(x, y, z, t) return Float64(y * z) end
function tmp = code(x, y, z, t) tmp = y * z; end
code[x_, y_, z_, t_] := N[(y * z), $MachinePrecision]
\begin{array}{l}
\\
y \cdot z
\end{array}
Initial program 100.0%
Taylor expanded in z around inf
lower-*.f6430.8
Applied rewrites30.8%
herbie shell --seed 2024214
(FPCore (x y z t)
:name "Language.Haskell.HsColour.ColourHighlight:unbase from hscolour-1.23"
:precision binary64
(+ (* (+ (* x y) z) y) t))