
(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-def100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (* y (* x y))))
(if (<= y -3200000000000.0)
t_1
(if (<= y -2.4e-175)
t
(if (<= y -1.15e-239) (* y z) (if (<= y 5.1e+81) t t_1))))))
double code(double x, double y, double z, double t) {
double t_1 = y * (x * y);
double tmp;
if (y <= -3200000000000.0) {
tmp = t_1;
} else if (y <= -2.4e-175) {
tmp = t;
} else if (y <= -1.15e-239) {
tmp = y * z;
} else if (y <= 5.1e+81) {
tmp = t;
} 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) :: tmp
t_1 = y * (x * y)
if (y <= (-3200000000000.0d0)) then
tmp = t_1
else if (y <= (-2.4d-175)) then
tmp = t
else if (y <= (-1.15d-239)) then
tmp = y * z
else if (y <= 5.1d+81) then
tmp = t
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 tmp;
if (y <= -3200000000000.0) {
tmp = t_1;
} else if (y <= -2.4e-175) {
tmp = t;
} else if (y <= -1.15e-239) {
tmp = y * z;
} else if (y <= 5.1e+81) {
tmp = t;
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z, t): t_1 = y * (x * y) tmp = 0 if y <= -3200000000000.0: tmp = t_1 elif y <= -2.4e-175: tmp = t elif y <= -1.15e-239: tmp = y * z elif y <= 5.1e+81: tmp = t else: tmp = t_1 return tmp
function code(x, y, z, t) t_1 = Float64(y * Float64(x * y)) tmp = 0.0 if (y <= -3200000000000.0) tmp = t_1; elseif (y <= -2.4e-175) tmp = t; elseif (y <= -1.15e-239) tmp = Float64(y * z); elseif (y <= 5.1e+81) tmp = t; else tmp = t_1; end return tmp end
function tmp_2 = code(x, y, z, t) t_1 = y * (x * y); tmp = 0.0; if (y <= -3200000000000.0) tmp = t_1; elseif (y <= -2.4e-175) tmp = t; elseif (y <= -1.15e-239) tmp = y * z; elseif (y <= 5.1e+81) tmp = t; 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]}, If[LessEqual[y, -3200000000000.0], t$95$1, If[LessEqual[y, -2.4e-175], t, If[LessEqual[y, -1.15e-239], N[(y * z), $MachinePrecision], If[LessEqual[y, 5.1e+81], t, t$95$1]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := y \cdot \left(x \cdot y\right)\\
\mathbf{if}\;y \leq -3200000000000:\\
\;\;\;\;t_1\\
\mathbf{elif}\;y \leq -2.4 \cdot 10^{-175}:\\
\;\;\;\;t\\
\mathbf{elif}\;y \leq -1.15 \cdot 10^{-239}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 5.1 \cdot 10^{+81}:\\
\;\;\;\;t\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}
\end{array}
if y < -3.2e12 or 5.1000000000000003e81 < y Initial program 99.9%
Taylor expanded in t around 0 91.2%
Taylor expanded in y around inf 63.5%
if -3.2e12 < y < -2.4e-175 or -1.1499999999999999e-239 < y < 5.1000000000000003e81Initial program 99.9%
Taylor expanded in y around 0 63.1%
if -2.4e-175 < y < -1.1499999999999999e-239Initial program 100.0%
Taylor expanded in t around 0 69.1%
Taylor expanded in y around 0 69.0%
Final simplification63.5%
(FPCore (x y z t)
:precision binary64
(if (<= y -4200000000000.0)
(* y (* x y))
(if (<= y -2.4e-175)
t
(if (<= y -9.5e-240) (* y z) (if (<= y 5.1e+81) t (* x (* y y)))))))
double code(double x, double y, double z, double t) {
double tmp;
if (y <= -4200000000000.0) {
tmp = y * (x * y);
} else if (y <= -2.4e-175) {
tmp = t;
} else if (y <= -9.5e-240) {
tmp = y * z;
} else if (y <= 5.1e+81) {
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 <= (-4200000000000.0d0)) then
tmp = y * (x * y)
else if (y <= (-2.4d-175)) then
tmp = t
else if (y <= (-9.5d-240)) then
tmp = y * z
else if (y <= 5.1d+81) 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 <= -4200000000000.0) {
tmp = y * (x * y);
} else if (y <= -2.4e-175) {
tmp = t;
} else if (y <= -9.5e-240) {
tmp = y * z;
} else if (y <= 5.1e+81) {
tmp = t;
} else {
tmp = x * (y * y);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if y <= -4200000000000.0: tmp = y * (x * y) elif y <= -2.4e-175: tmp = t elif y <= -9.5e-240: tmp = y * z elif y <= 5.1e+81: tmp = t else: tmp = x * (y * y) return tmp
function code(x, y, z, t) tmp = 0.0 if (y <= -4200000000000.0) tmp = Float64(y * Float64(x * y)); elseif (y <= -2.4e-175) tmp = t; elseif (y <= -9.5e-240) tmp = Float64(y * z); elseif (y <= 5.1e+81) 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 <= -4200000000000.0) tmp = y * (x * y); elseif (y <= -2.4e-175) tmp = t; elseif (y <= -9.5e-240) tmp = y * z; elseif (y <= 5.1e+81) tmp = t; else tmp = x * (y * y); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[y, -4200000000000.0], N[(y * N[(x * y), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, -2.4e-175], t, If[LessEqual[y, -9.5e-240], N[(y * z), $MachinePrecision], If[LessEqual[y, 5.1e+81], t, N[(x * N[(y * y), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4200000000000:\\
\;\;\;\;y \cdot \left(x \cdot y\right)\\
\mathbf{elif}\;y \leq -2.4 \cdot 10^{-175}:\\
\;\;\;\;t\\
\mathbf{elif}\;y \leq -9.5 \cdot 10^{-240}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 5.1 \cdot 10^{+81}:\\
\;\;\;\;t\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(y \cdot y\right)\\
\end{array}
\end{array}
if y < -4.2e12Initial program 99.9%
Taylor expanded in t around 0 86.6%
Taylor expanded in y around inf 60.4%
if -4.2e12 < y < -2.4e-175 or -9.5000000000000005e-240 < y < 5.1000000000000003e81Initial program 99.9%
Taylor expanded in y around 0 63.1%
if -2.4e-175 < y < -9.5000000000000005e-240Initial program 100.0%
Taylor expanded in t around 0 69.1%
Taylor expanded in y around 0 69.0%
if 5.1000000000000003e81 < y Initial program 100.0%
Taylor expanded in x around inf 70.6%
flip-+7.7%
clear-num7.7%
*-commutative7.7%
associate-*l*3.5%
pow23.5%
*-commutative3.5%
associate-*l*3.4%
Applied egg-rr3.4%
Taylor expanded in x around inf 72.4%
unpow272.4%
associate-*l*66.8%
Simplified66.8%
remove-double-div66.8%
associate-*r*72.4%
Applied egg-rr72.4%
Final simplification64.7%
(FPCore (x y z t)
:precision binary64
(if (<= z -0.058)
(* y z)
(if (<= z 6.5e+71)
t
(if (<= z 6.2e+194) (* y z) (if (<= z 1.15e+223) t (* y z))))))
double code(double x, double y, double z, double t) {
double tmp;
if (z <= -0.058) {
tmp = y * z;
} else if (z <= 6.5e+71) {
tmp = t;
} else if (z <= 6.2e+194) {
tmp = y * z;
} else if (z <= 1.15e+223) {
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 <= (-0.058d0)) then
tmp = y * z
else if (z <= 6.5d+71) then
tmp = t
else if (z <= 6.2d+194) then
tmp = y * z
else if (z <= 1.15d+223) 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 <= -0.058) {
tmp = y * z;
} else if (z <= 6.5e+71) {
tmp = t;
} else if (z <= 6.2e+194) {
tmp = y * z;
} else if (z <= 1.15e+223) {
tmp = t;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if z <= -0.058: tmp = y * z elif z <= 6.5e+71: tmp = t elif z <= 6.2e+194: tmp = y * z elif z <= 1.15e+223: tmp = t else: tmp = y * z return tmp
function code(x, y, z, t) tmp = 0.0 if (z <= -0.058) tmp = Float64(y * z); elseif (z <= 6.5e+71) tmp = t; elseif (z <= 6.2e+194) tmp = Float64(y * z); elseif (z <= 1.15e+223) tmp = t; else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (z <= -0.058) tmp = y * z; elseif (z <= 6.5e+71) tmp = t; elseif (z <= 6.2e+194) tmp = y * z; elseif (z <= 1.15e+223) tmp = t; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[z, -0.058], N[(y * z), $MachinePrecision], If[LessEqual[z, 6.5e+71], t, If[LessEqual[z, 6.2e+194], N[(y * z), $MachinePrecision], If[LessEqual[z, 1.15e+223], t, N[(y * z), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -0.058:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 6.5 \cdot 10^{+71}:\\
\;\;\;\;t\\
\mathbf{elif}\;z \leq 6.2 \cdot 10^{+194}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 1.15 \cdot 10^{+223}:\\
\;\;\;\;t\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if z < -0.0580000000000000029 or 6.49999999999999954e71 < z < 6.1999999999999999e194 or 1.15000000000000002e223 < z Initial program 99.9%
Taylor expanded in t around 0 84.0%
Taylor expanded in y around 0 66.6%
if -0.0580000000000000029 < z < 6.49999999999999954e71 or 6.1999999999999999e194 < z < 1.15000000000000002e223Initial program 99.9%
Taylor expanded in y around 0 60.8%
Final simplification63.6%
(FPCore (x y z t) :precision binary64 (if (or (<= y -1750000000000.0) (not (<= y 5.1e+81))) (* y (+ z (* x y))) (+ t (* y z))))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -1750000000000.0) || !(y <= 5.1e+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 <= (-1750000000000.0d0)) .or. (.not. (y <= 5.1d+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 <= -1750000000000.0) || !(y <= 5.1e+81)) {
tmp = y * (z + (x * y));
} else {
tmp = t + (y * z);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y <= -1750000000000.0) or not (y <= 5.1e+81): tmp = y * (z + (x * y)) else: tmp = t + (y * z) return tmp
function code(x, y, z, t) tmp = 0.0 if ((y <= -1750000000000.0) || !(y <= 5.1e+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 <= -1750000000000.0) || ~((y <= 5.1e+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, -1750000000000.0], N[Not[LessEqual[y, 5.1e+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 -1750000000000 \lor \neg \left(y \leq 5.1 \cdot 10^{+81}\right):\\
\;\;\;\;y \cdot \left(z + x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;t + y \cdot z\\
\end{array}
\end{array}
if y < -1.75e12 or 5.1000000000000003e81 < y Initial program 99.9%
Taylor expanded in t around 0 91.2%
if -1.75e12 < y < 5.1000000000000003e81Initial program 99.9%
Taylor expanded in x around 0 91.6%
Final simplification91.4%
(FPCore (x y z t) :precision binary64 (if (<= y -3.3e+168) (* y (* x y)) (if (<= y 3.8e+192) (+ t (* y z)) (* x (* y y)))))
double code(double x, double y, double z, double t) {
double tmp;
if (y <= -3.3e+168) {
tmp = y * (x * y);
} else if (y <= 3.8e+192) {
tmp = t + (y * z);
} 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 <= (-3.3d+168)) then
tmp = y * (x * y)
else if (y <= 3.8d+192) then
tmp = t + (y * z)
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 <= -3.3e+168) {
tmp = y * (x * y);
} else if (y <= 3.8e+192) {
tmp = t + (y * z);
} else {
tmp = x * (y * y);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if y <= -3.3e+168: tmp = y * (x * y) elif y <= 3.8e+192: tmp = t + (y * z) else: tmp = x * (y * y) return tmp
function code(x, y, z, t) tmp = 0.0 if (y <= -3.3e+168) tmp = Float64(y * Float64(x * y)); elseif (y <= 3.8e+192) tmp = Float64(t + Float64(y * z)); else tmp = Float64(x * Float64(y * y)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (y <= -3.3e+168) tmp = y * (x * y); elseif (y <= 3.8e+192) tmp = t + (y * z); else tmp = x * (y * y); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[y, -3.3e+168], N[(y * N[(x * y), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 3.8e+192], N[(t + N[(y * z), $MachinePrecision]), $MachinePrecision], N[(x * N[(y * y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.3 \cdot 10^{+168}:\\
\;\;\;\;y \cdot \left(x \cdot y\right)\\
\mathbf{elif}\;y \leq 3.8 \cdot 10^{+192}:\\
\;\;\;\;t + y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(y \cdot y\right)\\
\end{array}
\end{array}
if y < -3.2999999999999999e168Initial program 100.0%
Taylor expanded in t around 0 100.0%
Taylor expanded in y around inf 85.7%
if -3.2999999999999999e168 < y < 3.7999999999999999e192Initial program 99.9%
Taylor expanded in x around 0 82.0%
if 3.7999999999999999e192 < y Initial program 100.0%
Taylor expanded in x around inf 88.4%
flip-+4.2%
clear-num4.2%
*-commutative4.2%
associate-*l*0.1%
pow20.1%
*-commutative0.1%
associate-*l*0.0%
Applied egg-rr0.0%
Taylor expanded in x around inf 92.2%
unpow292.2%
associate-*l*88.4%
Simplified88.4%
remove-double-div88.4%
associate-*r*92.2%
Applied egg-rr92.2%
Final simplification83.3%
(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 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 40.1%
Final simplification40.1%
herbie shell --seed 2023200
(FPCore (x y z t)
:name "Language.Haskell.HsColour.ColourHighlight:unbase from hscolour-1.23"
:precision binary64
(+ (* (+ (* x y) z) y) t))