
(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 y x z) y t))
double code(double x, double y, double z, double t) {
return fma(fma(y, x, z), y, t);
}
function code(x, y, z, t) return fma(fma(y, x, z), y, t) end
code[x_, y_, z_, t_] := N[(N[(y * x + z), $MachinePrecision] * y + t), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\mathsf{fma}\left(y, x, 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
*-commutativeN/A
lower-fma.f64100.0
Applied rewrites100.0%
(FPCore (x y z t) :precision binary64 (let* ((t_1 (* (+ (* x y) z) y)) (t_2 (* (fma x y z) y))) (if (<= t_1 -1e+79) t_2 (if (<= t_1 1e+197) (fma z y t) t_2))))
double code(double x, double y, double z, double t) {
double t_1 = ((x * y) + z) * y;
double t_2 = fma(x, y, z) * y;
double tmp;
if (t_1 <= -1e+79) {
tmp = t_2;
} else if (t_1 <= 1e+197) {
tmp = fma(z, y, t);
} else {
tmp = t_2;
}
return tmp;
}
function code(x, y, z, t) t_1 = Float64(Float64(Float64(x * y) + z) * y) t_2 = Float64(fma(x, y, z) * y) tmp = 0.0 if (t_1 <= -1e+79) tmp = t_2; elseif (t_1 <= 1e+197) tmp = fma(z, y, t); else tmp = t_2; end return tmp end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[(N[(x * y), $MachinePrecision] + z), $MachinePrecision] * y), $MachinePrecision]}, Block[{t$95$2 = N[(N[(x * y + z), $MachinePrecision] * y), $MachinePrecision]}, If[LessEqual[t$95$1, -1e+79], t$95$2, If[LessEqual[t$95$1, 1e+197], N[(z * y + t), $MachinePrecision], t$95$2]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \left(x \cdot y + z\right) \cdot y\\
t_2 := \mathsf{fma}\left(x, y, z\right) \cdot y\\
\mathbf{if}\;t\_1 \leq -1 \cdot 10^{+79}:\\
\;\;\;\;t\_2\\
\mathbf{elif}\;t\_1 \leq 10^{+197}:\\
\;\;\;\;\mathsf{fma}\left(z, y, t\right)\\
\mathbf{else}:\\
\;\;\;\;t\_2\\
\end{array}
\end{array}
if (*.f64 (+.f64 (*.f64 x y) z) y) < -9.99999999999999967e78 or 9.9999999999999995e196 < (*.f64 (+.f64 (*.f64 x y) z) y) Initial program 100.0%
Taylor expanded in t around 0
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-fma.f6497.2
Applied rewrites97.2%
if -9.99999999999999967e78 < (*.f64 (+.f64 (*.f64 x y) z) y) < 9.9999999999999995e196Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6493.4
Applied rewrites93.4%
(FPCore (x y z t) :precision binary64 (let* ((t_1 (* (+ (* x y) z) y)) (t_2 (* (* y y) x))) (if (<= t_1 (- INFINITY)) t_2 (if (<= t_1 1e+197) (fma z y t) t_2))))
double code(double x, double y, double z, double t) {
double t_1 = ((x * y) + z) * y;
double t_2 = (y * y) * x;
double tmp;
if (t_1 <= -((double) INFINITY)) {
tmp = t_2;
} else if (t_1 <= 1e+197) {
tmp = fma(z, y, t);
} else {
tmp = t_2;
}
return tmp;
}
function code(x, y, z, t) t_1 = Float64(Float64(Float64(x * y) + z) * y) t_2 = Float64(Float64(y * y) * x) tmp = 0.0 if (t_1 <= Float64(-Inf)) tmp = t_2; elseif (t_1 <= 1e+197) tmp = fma(z, y, t); else tmp = t_2; end return tmp end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[(N[(x * y), $MachinePrecision] + z), $MachinePrecision] * y), $MachinePrecision]}, Block[{t$95$2 = N[(N[(y * y), $MachinePrecision] * x), $MachinePrecision]}, If[LessEqual[t$95$1, (-Infinity)], t$95$2, If[LessEqual[t$95$1, 1e+197], N[(z * y + t), $MachinePrecision], t$95$2]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \left(x \cdot y + z\right) \cdot y\\
t_2 := \left(y \cdot y\right) \cdot x\\
\mathbf{if}\;t\_1 \leq -\infty:\\
\;\;\;\;t\_2\\
\mathbf{elif}\;t\_1 \leq 10^{+197}:\\
\;\;\;\;\mathsf{fma}\left(z, y, t\right)\\
\mathbf{else}:\\
\;\;\;\;t\_2\\
\end{array}
\end{array}
if (*.f64 (+.f64 (*.f64 x y) z) y) < -inf.0 or 9.9999999999999995e196 < (*.f64 (+.f64 (*.f64 x y) z) y) Initial program 100.0%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f64N/A
unpow2N/A
lower-*.f6478.8
Applied rewrites78.8%
if -inf.0 < (*.f64 (+.f64 (*.f64 x y) z) y) < 9.9999999999999995e196Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6488.3
Applied rewrites88.3%
(FPCore (x y z t) :precision binary64 (let* ((t_1 (* (+ (* x y) z) y)) (t_2 (* (* x y) y))) (if (<= t_1 (- INFINITY)) t_2 (if (<= t_1 1e+197) (fma z y t) t_2))))
double code(double x, double y, double z, double t) {
double t_1 = ((x * y) + z) * y;
double t_2 = (x * y) * y;
double tmp;
if (t_1 <= -((double) INFINITY)) {
tmp = t_2;
} else if (t_1 <= 1e+197) {
tmp = fma(z, y, t);
} else {
tmp = t_2;
}
return tmp;
}
function code(x, y, z, t) t_1 = Float64(Float64(Float64(x * y) + z) * y) t_2 = Float64(Float64(x * y) * y) tmp = 0.0 if (t_1 <= Float64(-Inf)) tmp = t_2; elseif (t_1 <= 1e+197) tmp = fma(z, y, t); else tmp = t_2; end return tmp end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[(N[(x * y), $MachinePrecision] + z), $MachinePrecision] * y), $MachinePrecision]}, Block[{t$95$2 = N[(N[(x * y), $MachinePrecision] * y), $MachinePrecision]}, If[LessEqual[t$95$1, (-Infinity)], t$95$2, If[LessEqual[t$95$1, 1e+197], N[(z * y + t), $MachinePrecision], t$95$2]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \left(x \cdot y + z\right) \cdot y\\
t_2 := \left(x \cdot y\right) \cdot y\\
\mathbf{if}\;t\_1 \leq -\infty:\\
\;\;\;\;t\_2\\
\mathbf{elif}\;t\_1 \leq 10^{+197}:\\
\;\;\;\;\mathsf{fma}\left(z, y, t\right)\\
\mathbf{else}:\\
\;\;\;\;t\_2\\
\end{array}
\end{array}
if (*.f64 (+.f64 (*.f64 x y) z) y) < -inf.0 or 9.9999999999999995e196 < (*.f64 (+.f64 (*.f64 x y) z) y) Initial program 100.0%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f64N/A
unpow2N/A
lower-*.f6478.8
Applied rewrites78.8%
Applied rewrites77.8%
if -inf.0 < (*.f64 (+.f64 (*.f64 x y) z) y) < 9.9999999999999995e196Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6488.3
Applied rewrites88.3%
(FPCore (x y z t) :precision binary64 (fma z y t))
double code(double x, double y, double z, double t) {
return fma(z, y, t);
}
function code(x, y, z, t) return fma(z, y, t) end
code[x_, y_, z_, t_] := N[(z * y + t), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(z, y, t\right)
\end{array}
Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6469.8
Applied rewrites69.8%
(FPCore (x y z t) :precision binary64 (* z y))
double code(double x, double y, double z, double t) {
return z * y;
}
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 = z * y
end function
public static double code(double x, double y, double z, double t) {
return z * y;
}
def code(x, y, z, t): return z * y
function code(x, y, z, t) return Float64(z * y) end
function tmp = code(x, y, z, t) tmp = z * y; end
code[x_, y_, z_, t_] := N[(z * y), $MachinePrecision]
\begin{array}{l}
\\
z \cdot y
\end{array}
Initial program 100.0%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f6433.0
Applied rewrites33.0%
herbie shell --seed 2024270
(FPCore (x y z t)
:name "Language.Haskell.HsColour.ColourHighlight:unbase from hscolour-1.23"
:precision binary64
(+ (* (+ (* x y) z) y) t))