
(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 (+ (* y (+ z (* x y))) t))
double code(double x, double y, double z, double t) {
return (y * (z + (x * 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 = (y * (z + (x * y))) + t
end function
public static double code(double x, double y, double z, double t) {
return (y * (z + (x * y))) + t;
}
def code(x, y, z, t): return (y * (z + (x * y))) + t
function code(x, y, z, t) return Float64(Float64(y * Float64(z + Float64(x * y))) + t) end
function tmp = code(x, y, z, t) tmp = (y * (z + (x * y))) + t; end
code[x_, y_, z_, t_] := N[(N[(y * N[(z + N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + t), $MachinePrecision]
\begin{array}{l}
\\
y \cdot \left(z + x \cdot y\right) + t
\end{array}
Initial program 100.0%
Final simplification100.0%
(FPCore (x y z t) :precision binary64 (let* ((t_1 (* y (+ z (* x y)))) (t_2 (* y (fma y x z)))) (if (<= t_1 -2e+36) t_2 (if (<= t_1 2e+160) (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 <= -2e+36) {
tmp = t_2;
} else if (t_1 <= 2e+160) {
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 <= -2e+36) tmp = t_2; elseif (t_1 <= 2e+160) 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, -2e+36], t$95$2, If[LessEqual[t$95$1, 2e+160], 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 -2 \cdot 10^{+36}:\\
\;\;\;\;t\_2\\
\mathbf{elif}\;t\_1 \leq 2 \cdot 10^{+160}:\\
\;\;\;\;\mathsf{fma}\left(y, z, t\right)\\
\mathbf{else}:\\
\;\;\;\;t\_2\\
\end{array}
\end{array}
if (*.f64 (+.f64 (*.f64 x y) z) y) < -2.00000000000000008e36 or 2.00000000000000001e160 < (*.f64 (+.f64 (*.f64 x y) z) y) Initial program 99.9%
Taylor expanded in y around inf
Applied rewrites91.9%
if -2.00000000000000008e36 < (*.f64 (+.f64 (*.f64 x y) z) y) < 2.00000000000000001e160Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f6487.9
Applied rewrites87.9%
Final simplification90.0%
(FPCore (x y z t) :precision binary64 (let* ((t_1 (* y (+ z (* x y)))) (t_2 (* y (* x y)))) (if (<= t_1 -4e+246) t_2 (if (<= t_1 1e+221) (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 * (x * y);
double tmp;
if (t_1 <= -4e+246) {
tmp = t_2;
} else if (t_1 <= 1e+221) {
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 * Float64(x * y)) tmp = 0.0 if (t_1 <= -4e+246) tmp = t_2; elseif (t_1 <= 1e+221) 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[(x * y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, -4e+246], t$95$2, If[LessEqual[t$95$1, 1e+221], 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 \left(x \cdot y\right)\\
\mathbf{if}\;t\_1 \leq -4 \cdot 10^{+246}:\\
\;\;\;\;t\_2\\
\mathbf{elif}\;t\_1 \leq 10^{+221}:\\
\;\;\;\;\mathsf{fma}\left(y, z, t\right)\\
\mathbf{else}:\\
\;\;\;\;t\_2\\
\end{array}
\end{array}
if (*.f64 (+.f64 (*.f64 x y) z) y) < -4.00000000000000027e246 or 1e221 < (*.f64 (+.f64 (*.f64 x y) z) y) Initial program 100.0%
Taylor expanded in x around inf
unpow2N/A
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6482.2
Applied rewrites82.2%
if -4.00000000000000027e246 < (*.f64 (+.f64 (*.f64 x y) z) y) < 1e221Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f6483.1
Applied rewrites83.1%
Final simplification82.7%
(FPCore (x y z t) :precision binary64 (if (<= z -3.7e-42) (* y (fma y x z)) (if (<= z 2.7e+103) (fma y (* x y) t) (fma y z t))))
double code(double x, double y, double z, double t) {
double tmp;
if (z <= -3.7e-42) {
tmp = y * fma(y, x, z);
} else if (z <= 2.7e+103) {
tmp = fma(y, (x * y), t);
} else {
tmp = fma(y, z, t);
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (z <= -3.7e-42) tmp = Float64(y * fma(y, x, z)); elseif (z <= 2.7e+103) tmp = fma(y, Float64(x * y), t); else tmp = fma(y, z, t); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[z, -3.7e-42], N[(y * N[(y * x + z), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 2.7e+103], N[(y * N[(x * y), $MachinePrecision] + t), $MachinePrecision], N[(y * z + t), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.7 \cdot 10^{-42}:\\
\;\;\;\;y \cdot \mathsf{fma}\left(y, x, z\right)\\
\mathbf{elif}\;z \leq 2.7 \cdot 10^{+103}:\\
\;\;\;\;\mathsf{fma}\left(y, x \cdot y, t\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y, z, t\right)\\
\end{array}
\end{array}
if z < -3.7000000000000002e-42Initial program 100.0%
Taylor expanded in y around inf
Applied rewrites83.0%
if -3.7000000000000002e-42 < z < 2.69999999999999993e103Initial program 99.9%
Taylor expanded in z around 0
+-commutativeN/A
unpow2N/A
associate-*r*N/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6493.9
Applied rewrites93.9%
if 2.69999999999999993e103 < z Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f6494.6
Applied rewrites94.6%
Final simplification90.8%
(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.f6465.3
Applied rewrites65.3%
(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-*.f6429.7
Applied rewrites29.7%
herbie shell --seed 2024233
(FPCore (x y z t)
:name "Language.Haskell.HsColour.ColourHighlight:unbase from hscolour-1.23"
:precision binary64
(+ (* (+ (* x y) z) y) t))