
(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 (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 99.9%
fma-def99.9%
fma-def99.9%
Simplified99.9%
Final simplification99.9%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (* y (* x y))) (t_2 (+ t (* y z))))
(if (<= y -1.02e+124)
t_1
(if (<= y 2.95e-5)
t_2
(if (<= y 5e+15) (* x (* y y)) (if (<= y 8e+175) t_2 t_1))))))
double code(double x, double y, double z, double t) {
double t_1 = y * (x * y);
double t_2 = t + (y * z);
double tmp;
if (y <= -1.02e+124) {
tmp = t_1;
} else if (y <= 2.95e-5) {
tmp = t_2;
} else if (y <= 5e+15) {
tmp = x * (y * y);
} else if (y <= 8e+175) {
tmp = t_2;
} else {
tmp = t_1;
}
return tmp;
}
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
real(8) :: t_1
real(8) :: t_2
real(8) :: tmp
t_1 = y * (x * y)
t_2 = t + (y * z)
if (y <= (-1.02d+124)) then
tmp = t_1
else if (y <= 2.95d-5) then
tmp = t_2
else if (y <= 5d+15) then
tmp = x * (y * y)
else if (y <= 8d+175) then
tmp = t_2
else
tmp = t_1
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double t_1 = y * (x * y);
double t_2 = t + (y * z);
double tmp;
if (y <= -1.02e+124) {
tmp = t_1;
} else if (y <= 2.95e-5) {
tmp = t_2;
} else if (y <= 5e+15) {
tmp = x * (y * y);
} else if (y <= 8e+175) {
tmp = t_2;
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z, t): t_1 = y * (x * y) t_2 = t + (y * z) tmp = 0 if y <= -1.02e+124: tmp = t_1 elif y <= 2.95e-5: tmp = t_2 elif y <= 5e+15: tmp = x * (y * y) elif y <= 8e+175: tmp = t_2 else: tmp = t_1 return tmp
function code(x, y, z, t) t_1 = Float64(y * Float64(x * y)) t_2 = Float64(t + Float64(y * z)) tmp = 0.0 if (y <= -1.02e+124) tmp = t_1; elseif (y <= 2.95e-5) tmp = t_2; elseif (y <= 5e+15) tmp = Float64(x * Float64(y * y)); elseif (y <= 8e+175) tmp = t_2; else tmp = t_1; end return tmp end
function tmp_2 = code(x, y, z, t) t_1 = y * (x * y); t_2 = t + (y * z); tmp = 0.0; if (y <= -1.02e+124) tmp = t_1; elseif (y <= 2.95e-5) tmp = t_2; elseif (y <= 5e+15) tmp = x * (y * y); elseif (y <= 8e+175) tmp = t_2; else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(y * N[(x * y), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(t + N[(y * z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -1.02e+124], t$95$1, If[LessEqual[y, 2.95e-5], t$95$2, If[LessEqual[y, 5e+15], N[(x * N[(y * y), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 8e+175], t$95$2, t$95$1]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := y \cdot \left(x \cdot y\right)\\
t_2 := t + y \cdot z\\
\mathbf{if}\;y \leq -1.02 \cdot 10^{+124}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;y \leq 2.95 \cdot 10^{-5}:\\
\;\;\;\;t_2\\
\mathbf{elif}\;y \leq 5 \cdot 10^{+15}:\\
\;\;\;\;x \cdot \left(y \cdot y\right)\\
\mathbf{elif}\;y \leq 8 \cdot 10^{+175}:\\
\;\;\;\;t_2\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}
\end{array}
if y < -1.01999999999999994e124 or 7.9999999999999995e175 < y Initial program 100.0%
Taylor expanded in t around 0 98.4%
Taylor expanded in y around inf 85.3%
*-commutative85.3%
unpow285.3%
associate-*r*90.4%
*-commutative90.4%
*-commutative90.4%
Simplified90.4%
if -1.01999999999999994e124 < y < 2.9499999999999999e-5 or 5e15 < y < 7.9999999999999995e175Initial program 99.9%
Taylor expanded in x around 0 82.7%
if 2.9499999999999999e-5 < y < 5e15Initial program 99.6%
Taylor expanded in t around 0 86.0%
Taylor expanded in y around inf 85.5%
*-commutative85.5%
unpow285.5%
Simplified85.5%
Final simplification84.9%
(FPCore (x y z t) :precision binary64 (if (or (<= y -4e+53) (not (<= y 1.55e-81))) (* y (+ z (* x y))) (+ t (* y z))))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -4e+53) || !(y <= 1.55e-81)) {
tmp = y * (z + (x * y));
} else {
tmp = t + (y * z);
}
return tmp;
}
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
real(8) :: tmp
if ((y <= (-4d+53)) .or. (.not. (y <= 1.55d-81))) then
tmp = y * (z + (x * y))
else
tmp = t + (y * z)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -4e+53) || !(y <= 1.55e-81)) {
tmp = y * (z + (x * y));
} else {
tmp = t + (y * z);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y <= -4e+53) or not (y <= 1.55e-81): tmp = y * (z + (x * y)) else: tmp = t + (y * z) return tmp
function code(x, y, z, t) tmp = 0.0 if ((y <= -4e+53) || !(y <= 1.55e-81)) tmp = Float64(y * Float64(z + Float64(x * y))); else tmp = Float64(t + Float64(y * z)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((y <= -4e+53) || ~((y <= 1.55e-81))) tmp = y * (z + (x * y)); else tmp = t + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -4e+53], N[Not[LessEqual[y, 1.55e-81]], $MachinePrecision]], N[(y * N[(z + N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t + N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4 \cdot 10^{+53} \lor \neg \left(y \leq 1.55 \cdot 10^{-81}\right):\\
\;\;\;\;y \cdot \left(z + x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;t + y \cdot z\\
\end{array}
\end{array}
if y < -4e53 or 1.54999999999999994e-81 < y Initial program 99.9%
Taylor expanded in t around 0 89.1%
if -4e53 < y < 1.54999999999999994e-81Initial program 100.0%
Taylor expanded in x around 0 91.4%
Final simplification90.1%
(FPCore (x y z t) :precision binary64 (if (or (<= y -4.2e+50) (not (<= y 5.1e-79))) (* x (* y y)) t))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -4.2e+50) || !(y <= 5.1e-79)) {
tmp = x * (y * y);
} else {
tmp = t;
}
return tmp;
}
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
real(8) :: tmp
if ((y <= (-4.2d+50)) .or. (.not. (y <= 5.1d-79))) then
tmp = x * (y * y)
else
tmp = t
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -4.2e+50) || !(y <= 5.1e-79)) {
tmp = x * (y * y);
} else {
tmp = t;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y <= -4.2e+50) or not (y <= 5.1e-79): tmp = x * (y * y) else: tmp = t return tmp
function code(x, y, z, t) tmp = 0.0 if ((y <= -4.2e+50) || !(y <= 5.1e-79)) tmp = Float64(x * Float64(y * y)); else tmp = t; end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((y <= -4.2e+50) || ~((y <= 5.1e-79))) tmp = x * (y * y); else tmp = t; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -4.2e+50], N[Not[LessEqual[y, 5.1e-79]], $MachinePrecision]], N[(x * N[(y * y), $MachinePrecision]), $MachinePrecision], t]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.2 \cdot 10^{+50} \lor \neg \left(y \leq 5.1 \cdot 10^{-79}\right):\\
\;\;\;\;x \cdot \left(y \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;t\\
\end{array}
\end{array}
if y < -4.1999999999999999e50 or 5.0999999999999999e-79 < y Initial program 99.9%
Taylor expanded in t around 0 89.0%
Taylor expanded in y around inf 65.4%
*-commutative65.4%
unpow265.4%
Simplified65.4%
if -4.1999999999999999e50 < y < 5.0999999999999999e-79Initial program 100.0%
Taylor expanded in y around 0 67.5%
Final simplification66.3%
(FPCore (x y z t) :precision binary64 (if (<= y -6.8e+55) (* y (* x y)) (if (<= y 5.1e-79) t (* x (* y y)))))
double code(double x, double y, double z, double t) {
double tmp;
if (y <= -6.8e+55) {
tmp = y * (x * y);
} else if (y <= 5.1e-79) {
tmp = t;
} else {
tmp = x * (y * y);
}
return tmp;
}
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
real(8) :: tmp
if (y <= (-6.8d+55)) then
tmp = y * (x * y)
else if (y <= 5.1d-79) then
tmp = t
else
tmp = x * (y * y)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (y <= -6.8e+55) {
tmp = y * (x * y);
} else if (y <= 5.1e-79) {
tmp = t;
} else {
tmp = x * (y * y);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if y <= -6.8e+55: tmp = y * (x * y) elif y <= 5.1e-79: tmp = t else: tmp = x * (y * y) return tmp
function code(x, y, z, t) tmp = 0.0 if (y <= -6.8e+55) tmp = Float64(y * Float64(x * y)); elseif (y <= 5.1e-79) tmp = t; else tmp = Float64(x * Float64(y * y)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (y <= -6.8e+55) tmp = y * (x * y); elseif (y <= 5.1e-79) tmp = t; else tmp = x * (y * y); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[y, -6.8e+55], N[(y * N[(x * y), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 5.1e-79], t, N[(x * N[(y * y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -6.8 \cdot 10^{+55}:\\
\;\;\;\;y \cdot \left(x \cdot y\right)\\
\mathbf{elif}\;y \leq 5.1 \cdot 10^{-79}:\\
\;\;\;\;t\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(y \cdot y\right)\\
\end{array}
\end{array}
if y < -6.7999999999999996e55Initial program 99.9%
Taylor expanded in t around 0 95.5%
Taylor expanded in y around inf 71.6%
*-commutative71.6%
unpow271.6%
associate-*r*77.9%
*-commutative77.9%
*-commutative77.9%
Simplified77.9%
if -6.7999999999999996e55 < y < 5.0999999999999999e-79Initial program 100.0%
Taylor expanded in y around 0 67.5%
if 5.0999999999999999e-79 < y Initial program 99.9%
Taylor expanded in t around 0 86.0%
Taylor expanded in y around inf 62.5%
*-commutative62.5%
unpow262.5%
Simplified62.5%
Final simplification67.4%
(FPCore (x y z t) :precision binary64 (+ t (* y (+ z (* x y)))))
double code(double x, double y, double z, double t) {
return t + (y * (z + (x * 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 = t + (y * (z + (x * y)))
end function
public static double code(double x, double y, double z, double t) {
return t + (y * (z + (x * y)));
}
def code(x, y, z, t): return t + (y * (z + (x * y)))
function code(x, y, z, t) return Float64(t + Float64(y * Float64(z + Float64(x * y)))) end
function tmp = code(x, y, z, t) tmp = t + (y * (z + (x * y))); end
code[x_, y_, z_, t_] := N[(t + N[(y * N[(z + N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
t + y \cdot \left(z + x \cdot y\right)
\end{array}
Initial program 99.9%
Final simplification99.9%
(FPCore (x y z t) :precision binary64 (if (<= z -1.25e+117) (* y z) (if (<= z 3.4e+132) t (* y z))))
double code(double x, double y, double z, double t) {
double tmp;
if (z <= -1.25e+117) {
tmp = y * z;
} else if (z <= 3.4e+132) {
tmp = t;
} else {
tmp = y * z;
}
return tmp;
}
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
real(8) :: tmp
if (z <= (-1.25d+117)) then
tmp = y * z
else if (z <= 3.4d+132) then
tmp = t
else
tmp = y * z
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (z <= -1.25e+117) {
tmp = y * z;
} else if (z <= 3.4e+132) {
tmp = t;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if z <= -1.25e+117: tmp = y * z elif z <= 3.4e+132: tmp = t else: tmp = y * z return tmp
function code(x, y, z, t) tmp = 0.0 if (z <= -1.25e+117) tmp = Float64(y * z); elseif (z <= 3.4e+132) tmp = t; else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (z <= -1.25e+117) tmp = y * z; elseif (z <= 3.4e+132) tmp = t; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[z, -1.25e+117], N[(y * z), $MachinePrecision], If[LessEqual[z, 3.4e+132], t, N[(y * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.25 \cdot 10^{+117}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 3.4 \cdot 10^{+132}:\\
\;\;\;\;t\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if z < -1.24999999999999996e117 or 3.40000000000000025e132 < z Initial program 100.0%
Taylor expanded in x around 0 84.2%
Taylor expanded in y around inf 64.4%
*-commutative64.4%
Simplified64.4%
if -1.24999999999999996e117 < z < 3.40000000000000025e132Initial program 99.9%
Taylor expanded in y around 0 44.3%
Final simplification49.7%
(FPCore (x y z t) :precision binary64 t)
double code(double x, double y, double z, double t) {
return 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 = t
end function
public static double code(double x, double y, double z, double t) {
return t;
}
def code(x, y, z, t): return t
function code(x, y, z, t) return t end
function tmp = code(x, y, z, t) tmp = t; end
code[x_, y_, z_, t_] := t
\begin{array}{l}
\\
t
\end{array}
Initial program 99.9%
Taylor expanded in y around 0 38.2%
Final simplification38.2%
herbie shell --seed 2023176
(FPCore (x y z t)
:name "Language.Haskell.HsColour.ColourHighlight:unbase from hscolour-1.23"
:precision binary64
(+ (* (+ (* x y) z) y) t))