
(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 7 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 (+ 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
(let* ((t_1 (* x (* y y))))
(if (<= y -2e+71)
t_1
(if (<= y -8.2e+39)
(* y z)
(if (<= y -3.5e-19)
t_1
(if (<= y 4.9e-108)
t
(if (<= y 1.1e-89) (* y z) (if (<= y 2.25e-13) t t_1))))))))
double code(double x, double y, double z, double t) {
double t_1 = x * (y * y);
double tmp;
if (y <= -2e+71) {
tmp = t_1;
} else if (y <= -8.2e+39) {
tmp = y * z;
} else if (y <= -3.5e-19) {
tmp = t_1;
} else if (y <= 4.9e-108) {
tmp = t;
} else if (y <= 1.1e-89) {
tmp = y * z;
} else if (y <= 2.25e-13) {
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 = x * (y * y)
if (y <= (-2d+71)) then
tmp = t_1
else if (y <= (-8.2d+39)) then
tmp = y * z
else if (y <= (-3.5d-19)) then
tmp = t_1
else if (y <= 4.9d-108) then
tmp = t
else if (y <= 1.1d-89) then
tmp = y * z
else if (y <= 2.25d-13) 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 = x * (y * y);
double tmp;
if (y <= -2e+71) {
tmp = t_1;
} else if (y <= -8.2e+39) {
tmp = y * z;
} else if (y <= -3.5e-19) {
tmp = t_1;
} else if (y <= 4.9e-108) {
tmp = t;
} else if (y <= 1.1e-89) {
tmp = y * z;
} else if (y <= 2.25e-13) {
tmp = t;
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z, t): t_1 = x * (y * y) tmp = 0 if y <= -2e+71: tmp = t_1 elif y <= -8.2e+39: tmp = y * z elif y <= -3.5e-19: tmp = t_1 elif y <= 4.9e-108: tmp = t elif y <= 1.1e-89: tmp = y * z elif y <= 2.25e-13: tmp = t else: tmp = t_1 return tmp
function code(x, y, z, t) t_1 = Float64(x * Float64(y * y)) tmp = 0.0 if (y <= -2e+71) tmp = t_1; elseif (y <= -8.2e+39) tmp = Float64(y * z); elseif (y <= -3.5e-19) tmp = t_1; elseif (y <= 4.9e-108) tmp = t; elseif (y <= 1.1e-89) tmp = Float64(y * z); elseif (y <= 2.25e-13) tmp = t; else tmp = t_1; end return tmp end
function tmp_2 = code(x, y, z, t) t_1 = x * (y * y); tmp = 0.0; if (y <= -2e+71) tmp = t_1; elseif (y <= -8.2e+39) tmp = y * z; elseif (y <= -3.5e-19) tmp = t_1; elseif (y <= 4.9e-108) tmp = t; elseif (y <= 1.1e-89) tmp = y * z; elseif (y <= 2.25e-13) tmp = t; else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(x * N[(y * y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -2e+71], t$95$1, If[LessEqual[y, -8.2e+39], N[(y * z), $MachinePrecision], If[LessEqual[y, -3.5e-19], t$95$1, If[LessEqual[y, 4.9e-108], t, If[LessEqual[y, 1.1e-89], N[(y * z), $MachinePrecision], If[LessEqual[y, 2.25e-13], t, t$95$1]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := x \cdot \left(y \cdot y\right)\\
\mathbf{if}\;y \leq -2 \cdot 10^{+71}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;y \leq -8.2 \cdot 10^{+39}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq -3.5 \cdot 10^{-19}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;y \leq 4.9 \cdot 10^{-108}:\\
\;\;\;\;t\\
\mathbf{elif}\;y \leq 1.1 \cdot 10^{-89}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 2.25 \cdot 10^{-13}:\\
\;\;\;\;t\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}
\end{array}
if y < -2.0000000000000001e71 or -8.20000000000000008e39 < y < -3.50000000000000015e-19 or 2.25e-13 < y Initial program 99.9%
Taylor expanded in t around 0 90.9%
Taylor expanded in y around inf 71.0%
Taylor expanded in y around 0 69.4%
unpow269.4%
*-commutative69.4%
Simplified69.4%
if -2.0000000000000001e71 < y < -8.20000000000000008e39 or 4.8999999999999998e-108 < y < 1.10000000000000006e-89Initial program 100.0%
Taylor expanded in x around 0 100.0%
Taylor expanded in z around inf 100.0%
if -3.50000000000000015e-19 < y < 4.8999999999999998e-108 or 1.10000000000000006e-89 < y < 2.25e-13Initial program 99.9%
Taylor expanded in y around 0 71.6%
Final simplification71.7%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (* y (* x y))))
(if (<= y -5.1e+73)
t_1
(if (<= y -5.9e+38)
(* y z)
(if (<= y -4.5e-19)
t_1
(if (<= y 4.9e-108)
t
(if (<= y 4.2e-91) (* y z) (if (<= y 3.1e-13) t t_1))))))))
double code(double x, double y, double z, double t) {
double t_1 = y * (x * y);
double tmp;
if (y <= -5.1e+73) {
tmp = t_1;
} else if (y <= -5.9e+38) {
tmp = y * z;
} else if (y <= -4.5e-19) {
tmp = t_1;
} else if (y <= 4.9e-108) {
tmp = t;
} else if (y <= 4.2e-91) {
tmp = y * z;
} else if (y <= 3.1e-13) {
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 <= (-5.1d+73)) then
tmp = t_1
else if (y <= (-5.9d+38)) then
tmp = y * z
else if (y <= (-4.5d-19)) then
tmp = t_1
else if (y <= 4.9d-108) then
tmp = t
else if (y <= 4.2d-91) then
tmp = y * z
else if (y <= 3.1d-13) 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 <= -5.1e+73) {
tmp = t_1;
} else if (y <= -5.9e+38) {
tmp = y * z;
} else if (y <= -4.5e-19) {
tmp = t_1;
} else if (y <= 4.9e-108) {
tmp = t;
} else if (y <= 4.2e-91) {
tmp = y * z;
} else if (y <= 3.1e-13) {
tmp = t;
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z, t): t_1 = y * (x * y) tmp = 0 if y <= -5.1e+73: tmp = t_1 elif y <= -5.9e+38: tmp = y * z elif y <= -4.5e-19: tmp = t_1 elif y <= 4.9e-108: tmp = t elif y <= 4.2e-91: tmp = y * z elif y <= 3.1e-13: 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 <= -5.1e+73) tmp = t_1; elseif (y <= -5.9e+38) tmp = Float64(y * z); elseif (y <= -4.5e-19) tmp = t_1; elseif (y <= 4.9e-108) tmp = t; elseif (y <= 4.2e-91) tmp = Float64(y * z); elseif (y <= 3.1e-13) 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 <= -5.1e+73) tmp = t_1; elseif (y <= -5.9e+38) tmp = y * z; elseif (y <= -4.5e-19) tmp = t_1; elseif (y <= 4.9e-108) tmp = t; elseif (y <= 4.2e-91) tmp = y * z; elseif (y <= 3.1e-13) 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, -5.1e+73], t$95$1, If[LessEqual[y, -5.9e+38], N[(y * z), $MachinePrecision], If[LessEqual[y, -4.5e-19], t$95$1, If[LessEqual[y, 4.9e-108], t, If[LessEqual[y, 4.2e-91], N[(y * z), $MachinePrecision], If[LessEqual[y, 3.1e-13], t, t$95$1]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := y \cdot \left(x \cdot y\right)\\
\mathbf{if}\;y \leq -5.1 \cdot 10^{+73}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;y \leq -5.9 \cdot 10^{+38}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq -4.5 \cdot 10^{-19}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;y \leq 4.9 \cdot 10^{-108}:\\
\;\;\;\;t\\
\mathbf{elif}\;y \leq 4.2 \cdot 10^{-91}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 3.1 \cdot 10^{-13}:\\
\;\;\;\;t\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}
\end{array}
if y < -5.10000000000000024e73 or -5.89999999999999981e38 < y < -4.50000000000000013e-19 or 3.0999999999999999e-13 < y Initial program 99.9%
Taylor expanded in t around 0 90.9%
Taylor expanded in y around inf 71.0%
if -5.10000000000000024e73 < y < -5.89999999999999981e38 or 4.8999999999999998e-108 < y < 4.1999999999999998e-91Initial program 100.0%
Taylor expanded in x around 0 100.0%
Taylor expanded in z around inf 100.0%
if -4.50000000000000013e-19 < y < 4.8999999999999998e-108 or 4.1999999999999998e-91 < y < 3.0999999999999999e-13Initial program 99.9%
Taylor expanded in y around 0 71.6%
Final simplification72.4%
(FPCore (x y z t)
:precision binary64
(if (or (<= y -2.1e+71)
(and (not (<= y 6.4e+43))
(or (<= y 1.65e+90) (not (<= y 1.16e+175)))))
(* y (* x y))
(+ t (* y z))))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -2.1e+71) || (!(y <= 6.4e+43) && ((y <= 1.65e+90) || !(y <= 1.16e+175)))) {
tmp = y * (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 <= (-2.1d+71)) .or. (.not. (y <= 6.4d+43)) .and. (y <= 1.65d+90) .or. (.not. (y <= 1.16d+175))) then
tmp = y * (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 <= -2.1e+71) || (!(y <= 6.4e+43) && ((y <= 1.65e+90) || !(y <= 1.16e+175)))) {
tmp = y * (x * y);
} else {
tmp = t + (y * z);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y <= -2.1e+71) or (not (y <= 6.4e+43) and ((y <= 1.65e+90) or not (y <= 1.16e+175))): tmp = y * (x * y) else: tmp = t + (y * z) return tmp
function code(x, y, z, t) tmp = 0.0 if ((y <= -2.1e+71) || (!(y <= 6.4e+43) && ((y <= 1.65e+90) || !(y <= 1.16e+175)))) tmp = Float64(y * 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 <= -2.1e+71) || (~((y <= 6.4e+43)) && ((y <= 1.65e+90) || ~((y <= 1.16e+175))))) tmp = y * (x * y); else tmp = t + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -2.1e+71], And[N[Not[LessEqual[y, 6.4e+43]], $MachinePrecision], Or[LessEqual[y, 1.65e+90], N[Not[LessEqual[y, 1.16e+175]], $MachinePrecision]]]], N[(y * N[(x * y), $MachinePrecision]), $MachinePrecision], N[(t + N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.1 \cdot 10^{+71} \lor \neg \left(y \leq 6.4 \cdot 10^{+43}\right) \land \left(y \leq 1.65 \cdot 10^{+90} \lor \neg \left(y \leq 1.16 \cdot 10^{+175}\right)\right):\\
\;\;\;\;y \cdot \left(x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;t + y \cdot z\\
\end{array}
\end{array}
if y < -2.09999999999999989e71 or 6.40000000000000029e43 < y < 1.65000000000000004e90 or 1.16e175 < y Initial program 99.9%
Taylor expanded in t around 0 98.6%
Taylor expanded in y around inf 88.7%
if -2.09999999999999989e71 < y < 6.40000000000000029e43 or 1.65000000000000004e90 < y < 1.16e175Initial program 99.9%
Taylor expanded in x around 0 81.9%
Final simplification83.7%
(FPCore (x y z t) :precision binary64 (if (or (<= y -3e-25) (not (<= y 7.5e-13))) (* y (+ z (* x y))) (+ t (* y z))))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -3e-25) || !(y <= 7.5e-13)) {
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 <= (-3d-25)) .or. (.not. (y <= 7.5d-13))) 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 <= -3e-25) || !(y <= 7.5e-13)) {
tmp = y * (z + (x * y));
} else {
tmp = t + (y * z);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y <= -3e-25) or not (y <= 7.5e-13): tmp = y * (z + (x * y)) else: tmp = t + (y * z) return tmp
function code(x, y, z, t) tmp = 0.0 if ((y <= -3e-25) || !(y <= 7.5e-13)) 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 <= -3e-25) || ~((y <= 7.5e-13))) tmp = y * (z + (x * y)); else tmp = t + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -3e-25], N[Not[LessEqual[y, 7.5e-13]], $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 -3 \cdot 10^{-25} \lor \neg \left(y \leq 7.5 \cdot 10^{-13}\right):\\
\;\;\;\;y \cdot \left(z + x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;t + y \cdot z\\
\end{array}
\end{array}
if y < -2.9999999999999998e-25 or 7.5000000000000004e-13 < y Initial program 99.9%
Taylor expanded in t around 0 90.8%
if -2.9999999999999998e-25 < y < 7.5000000000000004e-13Initial program 100.0%
Taylor expanded in x around 0 92.3%
Final simplification91.5%
(FPCore (x y z t) :precision binary64 (if (<= z -2.35e+43) (* y z) (if (<= z 3.5e+90) t (* y z))))
double code(double x, double y, double z, double t) {
double tmp;
if (z <= -2.35e+43) {
tmp = y * z;
} else if (z <= 3.5e+90) {
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 <= (-2.35d+43)) then
tmp = y * z
else if (z <= 3.5d+90) 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 <= -2.35e+43) {
tmp = y * z;
} else if (z <= 3.5e+90) {
tmp = t;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if z <= -2.35e+43: tmp = y * z elif z <= 3.5e+90: tmp = t else: tmp = y * z return tmp
function code(x, y, z, t) tmp = 0.0 if (z <= -2.35e+43) tmp = Float64(y * z); elseif (z <= 3.5e+90) tmp = t; else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (z <= -2.35e+43) tmp = y * z; elseif (z <= 3.5e+90) tmp = t; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[z, -2.35e+43], N[(y * z), $MachinePrecision], If[LessEqual[z, 3.5e+90], t, N[(y * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.35 \cdot 10^{+43}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 3.5 \cdot 10^{+90}:\\
\;\;\;\;t\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if z < -2.34999999999999999e43 or 3.4999999999999998e90 < z Initial program 100.0%
Taylor expanded in x around 0 80.9%
Taylor expanded in z around inf 57.2%
if -2.34999999999999999e43 < z < 3.4999999999999998e90Initial program 99.9%
Taylor expanded in y around 0 49.7%
Final simplification52.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 39.2%
Final simplification39.2%
herbie shell --seed 2023181
(FPCore (x y z t)
:name "Language.Haskell.HsColour.ColourHighlight:unbase from hscolour-1.23"
:precision binary64
(+ (* (+ (* x y) z) y) t))