
(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 (+ (* (+ (* 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 99.9%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (* (+ (* x y) z) y)))
(if (or (<= t_1 -1e+67) (not (<= t_1 5e+137)))
(* (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 <= -1e+67) || !(t_1 <= 5e+137)) {
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 <= -1e+67) || !(t_1 <= 5e+137)) 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, -1e+67], N[Not[LessEqual[t$95$1, 5e+137]], $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 -1 \cdot 10^{+67} \lor \neg \left(t\_1 \leq 5 \cdot 10^{+137}\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) < -9.99999999999999983e66 or 5.0000000000000002e137 < (*.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 rewrites93.7%
if -9.99999999999999983e66 < (*.f64 (+.f64 (*.f64 x y) z) y) < 5.0000000000000002e137Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6492.4
Applied rewrites92.4%
Final simplification93.1%
(FPCore (x y z t) :precision binary64 (let* ((t_1 (* (+ (* x y) z) y))) (if (or (<= t_1 -2e+259) (not (<= t_1 5e+178))) (* (* 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+259) || !(t_1 <= 5e+178)) {
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+259) || !(t_1 <= 5e+178)) 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+259], N[Not[LessEqual[t$95$1, 5e+178]], $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^{+259} \lor \neg \left(t\_1 \leq 5 \cdot 10^{+178}\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) < -2e259 or 4.9999999999999999e178 < (*.f64 (+.f64 (*.f64 x y) z) y) Initial program 99.9%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
unpow2N/A
lower-*.f6477.0
Applied rewrites77.0%
Applied rewrites77.7%
if -2e259 < (*.f64 (+.f64 (*.f64 x y) z) y) < 4.9999999999999999e178Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6485.6
Applied rewrites85.6%
Final simplification82.4%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (* (+ (* x y) z) y)))
(if (<= t_1 -2e+259)
(* (* x y) y)
(if (<= t_1 5e+178) (fma z y t) (* (* y y) x)))))
double code(double x, double y, double z, double t) {
double t_1 = ((x * y) + z) * y;
double tmp;
if (t_1 <= -2e+259) {
tmp = (x * y) * y;
} else if (t_1 <= 5e+178) {
tmp = fma(z, y, t);
} else {
tmp = (y * y) * x;
}
return tmp;
}
function code(x, y, z, t) t_1 = Float64(Float64(Float64(x * y) + z) * y) tmp = 0.0 if (t_1 <= -2e+259) tmp = Float64(Float64(x * y) * y); elseif (t_1 <= 5e+178) tmp = fma(z, y, t); else tmp = Float64(Float64(y * y) * x); 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+259], N[(N[(x * y), $MachinePrecision] * y), $MachinePrecision], If[LessEqual[t$95$1, 5e+178], N[(z * y + t), $MachinePrecision], N[(N[(y * y), $MachinePrecision] * x), $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^{+259}:\\
\;\;\;\;\left(x \cdot y\right) \cdot y\\
\mathbf{elif}\;t\_1 \leq 5 \cdot 10^{+178}:\\
\;\;\;\;\mathsf{fma}\left(z, y, t\right)\\
\mathbf{else}:\\
\;\;\;\;\left(y \cdot y\right) \cdot x\\
\end{array}
\end{array}
if (*.f64 (+.f64 (*.f64 x y) z) y) < -2e259Initial program 99.9%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
unpow2N/A
lower-*.f6479.1
Applied rewrites79.1%
Applied rewrites80.6%
if -2e259 < (*.f64 (+.f64 (*.f64 x y) z) y) < 4.9999999999999999e178Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6485.6
Applied rewrites85.6%
if 4.9999999999999999e178 < (*.f64 (+.f64 (*.f64 x y) z) y) Initial program 99.8%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
unpow2N/A
lower-*.f6474.6
Applied rewrites74.6%
(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 99.9%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6466.3
Applied rewrites66.3%
(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 99.9%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
unpow2N/A
lower-*.f6440.6
Applied rewrites40.6%
Applied rewrites41.7%
Taylor expanded in t around -inf
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f64N/A
sub-negN/A
associate-/l*N/A
associate-*r*N/A
metadata-evalN/A
lower-fma.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f6484.5
Applied rewrites84.5%
Taylor expanded in z around inf
Applied rewrites30.7%
Final simplification30.7%
herbie shell --seed 2024313
(FPCore (x y z t)
:name "Language.Haskell.HsColour.ColourHighlight:unbase from hscolour-1.23"
:precision binary64
(+ (* (+ (* x y) z) y) t))