
(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 8 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 (+ (* (+ (* 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}
Initial program 100.0%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (* (+ (* x y) z) y)))
(if (or (<= t_1 -2e+93) (not (<= t_1 5e+195)))
(* (fma y x z) y)
(fma z y t))))
double code(double x, double y, double z, double t) {
double t_1 = ((x * y) + z) * y;
double tmp;
if ((t_1 <= -2e+93) || !(t_1 <= 5e+195)) {
tmp = fma(y, x, z) * y;
} else {
tmp = fma(z, y, t);
}
return tmp;
}
function code(x, y, z, t) t_1 = Float64(Float64(Float64(x * y) + z) * y) tmp = 0.0 if ((t_1 <= -2e+93) || !(t_1 <= 5e+195)) tmp = Float64(fma(y, x, z) * y); else tmp = fma(z, y, t); end return tmp end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[(N[(x * y), $MachinePrecision] + z), $MachinePrecision] * y), $MachinePrecision]}, If[Or[LessEqual[t$95$1, -2e+93], N[Not[LessEqual[t$95$1, 5e+195]], $MachinePrecision]], N[(N[(y * x + z), $MachinePrecision] * y), $MachinePrecision], N[(z * y + t), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \left(x \cdot y + z\right) \cdot y\\
\mathbf{if}\;t\_1 \leq -2 \cdot 10^{+93} \lor \neg \left(t\_1 \leq 5 \cdot 10^{+195}\right):\\
\;\;\;\;\mathsf{fma}\left(y, x, z\right) \cdot y\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(z, y, t\right)\\
\end{array}
\end{array}
if (*.f64 (+.f64 (*.f64 x y) z) y) < -2.00000000000000009e93 or 4.9999999999999998e195 < (*.f64 (+.f64 (*.f64 x y) z) y) Initial program 99.9%
Taylor expanded in y around inf
remove-double-negN/A
mul-1-negN/A
distribute-lft-outN/A
distribute-rgt-neg-outN/A
neg-sub0N/A
unsub-negN/A
mul0-rgtN/A
distribute-rgt-neg-outN/A
distribute-lft-outN/A
mul-1-negN/A
remove-double-negN/A
unpow2N/A
associate-*l*N/A
distribute-lft-inN/A
+-lft-identityN/A
distribute-rgt-inN/A
cancel-sign-subN/A
mul-1-negN/A
Applied rewrites96.3%
if -2.00000000000000009e93 < (*.f64 (+.f64 (*.f64 x y) z) y) < 4.9999999999999998e195Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6488.6
Applied rewrites88.6%
Final simplification92.5%
(FPCore (x y z t) :precision binary64 (let* ((t_1 (* (+ (* x y) z) y))) (if (or (<= t_1 -2e+292) (not (<= t_1 1e+218))) (* (* x y) y) (fma z y t))))
double code(double x, double y, double z, double t) {
double t_1 = ((x * y) + z) * y;
double tmp;
if ((t_1 <= -2e+292) || !(t_1 <= 1e+218)) {
tmp = (x * y) * y;
} else {
tmp = fma(z, y, t);
}
return tmp;
}
function code(x, y, z, t) t_1 = Float64(Float64(Float64(x * y) + z) * y) tmp = 0.0 if ((t_1 <= -2e+292) || !(t_1 <= 1e+218)) tmp = Float64(Float64(x * y) * y); else tmp = fma(z, y, t); end return tmp end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[(N[(x * y), $MachinePrecision] + z), $MachinePrecision] * y), $MachinePrecision]}, If[Or[LessEqual[t$95$1, -2e+292], N[Not[LessEqual[t$95$1, 1e+218]], $MachinePrecision]], N[(N[(x * y), $MachinePrecision] * y), $MachinePrecision], N[(z * y + t), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \left(x \cdot y + z\right) \cdot y\\
\mathbf{if}\;t\_1 \leq -2 \cdot 10^{+292} \lor \neg \left(t\_1 \leq 10^{+218}\right):\\
\;\;\;\;\left(x \cdot y\right) \cdot y\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(z, y, t\right)\\
\end{array}
\end{array}
if (*.f64 (+.f64 (*.f64 x y) z) y) < -2e292 or 1.00000000000000008e218 < (*.f64 (+.f64 (*.f64 x y) z) y) Initial program 100.0%
Taylor expanded in y around inf
remove-double-negN/A
mul-1-negN/A
distribute-lft-outN/A
distribute-rgt-neg-outN/A
neg-sub0N/A
unsub-negN/A
mul0-rgtN/A
distribute-rgt-neg-outN/A
distribute-lft-outN/A
mul-1-negN/A
remove-double-negN/A
unpow2N/A
associate-*l*N/A
distribute-lft-inN/A
+-lft-identityN/A
distribute-rgt-inN/A
cancel-sign-subN/A
mul-1-negN/A
Applied rewrites99.9%
Taylor expanded in x around inf
Applied rewrites75.1%
if -2e292 < (*.f64 (+.f64 (*.f64 x y) z) y) < 1.00000000000000008e218Initial program 99.9%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6482.4
Applied rewrites82.4%
Final simplification79.7%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (* (+ (* x y) z) y)))
(if (<= t_1 -2e+292)
(* (* y y) x)
(if (<= t_1 1e+218) (fma z y t) (* (* x y) y)))))
double code(double x, double y, double z, double t) {
double t_1 = ((x * y) + z) * y;
double tmp;
if (t_1 <= -2e+292) {
tmp = (y * y) * x;
} else if (t_1 <= 1e+218) {
tmp = fma(z, y, t);
} else {
tmp = (x * y) * y;
}
return tmp;
}
function code(x, y, z, t) t_1 = Float64(Float64(Float64(x * y) + z) * y) tmp = 0.0 if (t_1 <= -2e+292) tmp = Float64(Float64(y * y) * x); elseif (t_1 <= 1e+218) tmp = fma(z, y, t); else tmp = Float64(Float64(x * y) * y); end return tmp end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[(N[(x * y), $MachinePrecision] + z), $MachinePrecision] * y), $MachinePrecision]}, If[LessEqual[t$95$1, -2e+292], N[(N[(y * y), $MachinePrecision] * x), $MachinePrecision], If[LessEqual[t$95$1, 1e+218], N[(z * y + t), $MachinePrecision], N[(N[(x * y), $MachinePrecision] * y), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \left(x \cdot y + z\right) \cdot y\\
\mathbf{if}\;t\_1 \leq -2 \cdot 10^{+292}:\\
\;\;\;\;\left(y \cdot y\right) \cdot x\\
\mathbf{elif}\;t\_1 \leq 10^{+218}:\\
\;\;\;\;\mathsf{fma}\left(z, y, t\right)\\
\mathbf{else}:\\
\;\;\;\;\left(x \cdot y\right) \cdot y\\
\end{array}
\end{array}
if (*.f64 (+.f64 (*.f64 x y) z) y) < -2e292Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
unpow2N/A
lower-*.f6478.2
Applied rewrites78.2%
if -2e292 < (*.f64 (+.f64 (*.f64 x y) z) y) < 1.00000000000000008e218Initial program 99.9%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6482.4
Applied rewrites82.4%
if 1.00000000000000008e218 < (*.f64 (+.f64 (*.f64 x y) z) y) Initial program 99.9%
Taylor expanded in y around inf
remove-double-negN/A
mul-1-negN/A
distribute-lft-outN/A
distribute-rgt-neg-outN/A
neg-sub0N/A
unsub-negN/A
mul0-rgtN/A
distribute-rgt-neg-outN/A
distribute-lft-outN/A
mul-1-negN/A
remove-double-negN/A
unpow2N/A
associate-*l*N/A
distribute-lft-inN/A
+-lft-identityN/A
distribute-rgt-inN/A
cancel-sign-subN/A
mul-1-negN/A
Applied rewrites99.9%
Taylor expanded in x around inf
Applied rewrites72.3%
(FPCore (x y z t)
:precision binary64
(if (<= z -1.95e+147)
(fma z y t)
(if (<= z -1.3e+14)
(fma z y (* (* x y) y))
(if (<= z 3.9e+46) (fma (* y x) y t) (fma z y t)))))
double code(double x, double y, double z, double t) {
double tmp;
if (z <= -1.95e+147) {
tmp = fma(z, y, t);
} else if (z <= -1.3e+14) {
tmp = fma(z, y, ((x * y) * y));
} else if (z <= 3.9e+46) {
tmp = fma((y * x), y, t);
} else {
tmp = fma(z, y, t);
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (z <= -1.95e+147) tmp = fma(z, y, t); elseif (z <= -1.3e+14) tmp = fma(z, y, Float64(Float64(x * y) * y)); elseif (z <= 3.9e+46) tmp = fma(Float64(y * x), y, t); else tmp = fma(z, y, t); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[z, -1.95e+147], N[(z * y + t), $MachinePrecision], If[LessEqual[z, -1.3e+14], N[(z * y + N[(N[(x * y), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 3.9e+46], N[(N[(y * x), $MachinePrecision] * y + t), $MachinePrecision], N[(z * y + t), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.95 \cdot 10^{+147}:\\
\;\;\;\;\mathsf{fma}\left(z, y, t\right)\\
\mathbf{elif}\;z \leq -1.3 \cdot 10^{+14}:\\
\;\;\;\;\mathsf{fma}\left(z, y, \left(x \cdot y\right) \cdot y\right)\\
\mathbf{elif}\;z \leq 3.9 \cdot 10^{+46}:\\
\;\;\;\;\mathsf{fma}\left(y \cdot x, y, t\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(z, y, t\right)\\
\end{array}
\end{array}
if z < -1.95000000000000008e147 or 3.89999999999999995e46 < z Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6490.4
Applied rewrites90.4%
if -1.95000000000000008e147 < z < -1.3e14Initial program 100.0%
Taylor expanded in y around inf
remove-double-negN/A
mul-1-negN/A
distribute-lft-outN/A
distribute-rgt-neg-outN/A
neg-sub0N/A
unsub-negN/A
mul0-rgtN/A
distribute-rgt-neg-outN/A
distribute-lft-outN/A
mul-1-negN/A
remove-double-negN/A
unpow2N/A
associate-*l*N/A
distribute-lft-inN/A
+-lft-identityN/A
distribute-rgt-inN/A
cancel-sign-subN/A
mul-1-negN/A
Applied rewrites94.0%
Applied rewrites94.0%
if -1.3e14 < z < 3.89999999999999995e46Initial program 99.9%
Taylor expanded in z around 0
+-commutativeN/A
unpow2N/A
associate-*r*N/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6497.3
Applied rewrites97.3%
(FPCore (x y z t)
:precision binary64
(if (<= z -1.95e+147)
(fma z y t)
(if (<= z -1.3e+14)
(* (fma y x z) y)
(if (<= z 3.9e+46) (fma (* y x) y t) (fma z y t)))))
double code(double x, double y, double z, double t) {
double tmp;
if (z <= -1.95e+147) {
tmp = fma(z, y, t);
} else if (z <= -1.3e+14) {
tmp = fma(y, x, z) * y;
} else if (z <= 3.9e+46) {
tmp = fma((y * x), y, t);
} else {
tmp = fma(z, y, t);
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (z <= -1.95e+147) tmp = fma(z, y, t); elseif (z <= -1.3e+14) tmp = Float64(fma(y, x, z) * y); elseif (z <= 3.9e+46) tmp = fma(Float64(y * x), y, t); else tmp = fma(z, y, t); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[z, -1.95e+147], N[(z * y + t), $MachinePrecision], If[LessEqual[z, -1.3e+14], N[(N[(y * x + z), $MachinePrecision] * y), $MachinePrecision], If[LessEqual[z, 3.9e+46], N[(N[(y * x), $MachinePrecision] * y + t), $MachinePrecision], N[(z * y + t), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.95 \cdot 10^{+147}:\\
\;\;\;\;\mathsf{fma}\left(z, y, t\right)\\
\mathbf{elif}\;z \leq -1.3 \cdot 10^{+14}:\\
\;\;\;\;\mathsf{fma}\left(y, x, z\right) \cdot y\\
\mathbf{elif}\;z \leq 3.9 \cdot 10^{+46}:\\
\;\;\;\;\mathsf{fma}\left(y \cdot x, y, t\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(z, y, t\right)\\
\end{array}
\end{array}
if z < -1.95000000000000008e147 or 3.89999999999999995e46 < z Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6490.4
Applied rewrites90.4%
if -1.95000000000000008e147 < z < -1.3e14Initial program 100.0%
Taylor expanded in y around inf
remove-double-negN/A
mul-1-negN/A
distribute-lft-outN/A
distribute-rgt-neg-outN/A
neg-sub0N/A
unsub-negN/A
mul0-rgtN/A
distribute-rgt-neg-outN/A
distribute-lft-outN/A
mul-1-negN/A
remove-double-negN/A
unpow2N/A
associate-*l*N/A
distribute-lft-inN/A
+-lft-identityN/A
distribute-rgt-inN/A
cancel-sign-subN/A
mul-1-negN/A
Applied rewrites94.0%
if -1.3e14 < z < 3.89999999999999995e46Initial program 99.9%
Taylor expanded in z around 0
+-commutativeN/A
unpow2N/A
associate-*r*N/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6497.3
Applied rewrites97.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 x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6467.1
Applied rewrites67.1%
(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 y around inf
remove-double-negN/A
mul-1-negN/A
distribute-lft-outN/A
distribute-rgt-neg-outN/A
neg-sub0N/A
unsub-negN/A
mul0-rgtN/A
distribute-rgt-neg-outN/A
distribute-lft-outN/A
mul-1-negN/A
remove-double-negN/A
unpow2N/A
associate-*l*N/A
distribute-lft-inN/A
+-lft-identityN/A
distribute-rgt-inN/A
cancel-sign-subN/A
mul-1-negN/A
Applied rewrites65.2%
Taylor expanded in x around 0
Applied rewrites32.5%
herbie shell --seed 2024324
(FPCore (x y z t)
:name "Language.Haskell.HsColour.ColourHighlight:unbase from hscolour-1.23"
:precision binary64
(+ (* (+ (* x y) z) y) t))