
(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-define99.9%
fma-define99.9%
Simplified99.9%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (* y (+ z (* x y)))))
(if (<= y -2.4e+62)
t_1
(if (<= y -2.7e-22)
(+ t (* y (* x y)))
(if (<= y 40000000.0) (+ t (* y z)) t_1)))))
double code(double x, double y, double z, double t) {
double t_1 = y * (z + (x * y));
double tmp;
if (y <= -2.4e+62) {
tmp = t_1;
} else if (y <= -2.7e-22) {
tmp = t + (y * (x * y));
} else if (y <= 40000000.0) {
tmp = t + (y * z);
} 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 * (z + (x * y))
if (y <= (-2.4d+62)) then
tmp = t_1
else if (y <= (-2.7d-22)) then
tmp = t + (y * (x * y))
else if (y <= 40000000.0d0) then
tmp = t + (y * z)
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 * (z + (x * y));
double tmp;
if (y <= -2.4e+62) {
tmp = t_1;
} else if (y <= -2.7e-22) {
tmp = t + (y * (x * y));
} else if (y <= 40000000.0) {
tmp = t + (y * z);
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z, t): t_1 = y * (z + (x * y)) tmp = 0 if y <= -2.4e+62: tmp = t_1 elif y <= -2.7e-22: tmp = t + (y * (x * y)) elif y <= 40000000.0: tmp = t + (y * z) else: tmp = t_1 return tmp
function code(x, y, z, t) t_1 = Float64(y * Float64(z + Float64(x * y))) tmp = 0.0 if (y <= -2.4e+62) tmp = t_1; elseif (y <= -2.7e-22) tmp = Float64(t + Float64(y * Float64(x * y))); elseif (y <= 40000000.0) tmp = Float64(t + Float64(y * z)); else tmp = t_1; end return tmp end
function tmp_2 = code(x, y, z, t) t_1 = y * (z + (x * y)); tmp = 0.0; if (y <= -2.4e+62) tmp = t_1; elseif (y <= -2.7e-22) tmp = t + (y * (x * y)); elseif (y <= 40000000.0) tmp = t + (y * z); else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(y * N[(z + N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -2.4e+62], t$95$1, If[LessEqual[y, -2.7e-22], N[(t + N[(y * N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 40000000.0], N[(t + N[(y * z), $MachinePrecision]), $MachinePrecision], t$95$1]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := y \cdot \left(z + x \cdot y\right)\\
\mathbf{if}\;y \leq -2.4 \cdot 10^{+62}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;y \leq -2.7 \cdot 10^{-22}:\\
\;\;\;\;t + y \cdot \left(x \cdot y\right)\\
\mathbf{elif}\;y \leq 40000000:\\
\;\;\;\;t + y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if y < -2.4e62 or 4e7 < y Initial program 99.9%
fma-define99.9%
add-cube-cbrt99.5%
associate-*l*99.5%
fma-define99.5%
pow299.5%
Applied egg-rr99.5%
Taylor expanded in t around 0 92.7%
if -2.4e62 < y < -2.7000000000000002e-22Initial program 99.8%
Taylor expanded in x around inf 94.5%
*-commutative94.5%
Simplified94.5%
if -2.7000000000000002e-22 < y < 4e7Initial program 100.0%
Taylor expanded in x around 0 93.7%
Final simplification93.3%
(FPCore (x y z t) :precision binary64 (if (or (<= y -1.45e-40) (not (<= y 370.0))) (* y (+ z (* x y))) (+ t (* y z))))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -1.45e-40) || !(y <= 370.0)) {
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 <= (-1.45d-40)) .or. (.not. (y <= 370.0d0))) 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 <= -1.45e-40) || !(y <= 370.0)) {
tmp = y * (z + (x * y));
} else {
tmp = t + (y * z);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y <= -1.45e-40) or not (y <= 370.0): tmp = y * (z + (x * y)) else: tmp = t + (y * z) return tmp
function code(x, y, z, t) tmp = 0.0 if ((y <= -1.45e-40) || !(y <= 370.0)) 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 <= -1.45e-40) || ~((y <= 370.0))) tmp = y * (z + (x * y)); else tmp = t + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -1.45e-40], N[Not[LessEqual[y, 370.0]], $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 -1.45 \cdot 10^{-40} \lor \neg \left(y \leq 370\right):\\
\;\;\;\;y \cdot \left(z + x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;t + y \cdot z\\
\end{array}
\end{array}
if y < -1.4499999999999999e-40 or 370 < y Initial program 99.9%
fma-define99.9%
add-cube-cbrt99.4%
associate-*l*99.4%
fma-define99.4%
pow299.4%
Applied egg-rr99.4%
Taylor expanded in t around 0 87.2%
if -1.4499999999999999e-40 < y < 370Initial program 100.0%
Taylor expanded in x around 0 94.3%
Final simplification90.7%
(FPCore (x y z t) :precision binary64 (if (or (<= y -8e+68) (not (<= y 6.2e+75))) (* y (* x y)) (+ t (* y z))))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -8e+68) || !(y <= 6.2e+75)) {
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 <= (-8d+68)) .or. (.not. (y <= 6.2d+75))) 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 <= -8e+68) || !(y <= 6.2e+75)) {
tmp = y * (x * y);
} else {
tmp = t + (y * z);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y <= -8e+68) or not (y <= 6.2e+75): tmp = y * (x * y) else: tmp = t + (y * z) return tmp
function code(x, y, z, t) tmp = 0.0 if ((y <= -8e+68) || !(y <= 6.2e+75)) 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 <= -8e+68) || ~((y <= 6.2e+75))) tmp = y * (x * y); else tmp = t + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -8e+68], N[Not[LessEqual[y, 6.2e+75]], $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 -8 \cdot 10^{+68} \lor \neg \left(y \leq 6.2 \cdot 10^{+75}\right):\\
\;\;\;\;y \cdot \left(x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;t + y \cdot z\\
\end{array}
\end{array}
if y < -7.99999999999999962e68 or 6.2000000000000002e75 < y Initial program 99.9%
fma-define99.9%
add-cube-cbrt99.6%
associate-*l*99.6%
fma-define99.6%
pow299.6%
Applied egg-rr99.6%
Taylor expanded in t around 0 93.9%
Taylor expanded in z around 0 77.9%
*-commutative77.9%
Simplified77.9%
if -7.99999999999999962e68 < y < 6.2000000000000002e75Initial program 99.9%
Taylor expanded in x around 0 87.3%
Final simplification83.7%
(FPCore (x y z t) :precision binary64 (if (or (<= y -1.35e-40) (not (<= y 1.92))) (* y (* x y)) t))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -1.35e-40) || !(y <= 1.92)) {
tmp = y * (x * 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 <= (-1.35d-40)) .or. (.not. (y <= 1.92d0))) then
tmp = y * (x * 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 <= -1.35e-40) || !(y <= 1.92)) {
tmp = y * (x * y);
} else {
tmp = t;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y <= -1.35e-40) or not (y <= 1.92): tmp = y * (x * y) else: tmp = t return tmp
function code(x, y, z, t) tmp = 0.0 if ((y <= -1.35e-40) || !(y <= 1.92)) tmp = Float64(y * Float64(x * y)); else tmp = t; end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((y <= -1.35e-40) || ~((y <= 1.92))) tmp = y * (x * y); else tmp = t; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -1.35e-40], N[Not[LessEqual[y, 1.92]], $MachinePrecision]], N[(y * N[(x * y), $MachinePrecision]), $MachinePrecision], t]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.35 \cdot 10^{-40} \lor \neg \left(y \leq 1.92\right):\\
\;\;\;\;y \cdot \left(x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;t\\
\end{array}
\end{array}
if y < -1.35e-40 or 1.9199999999999999 < y Initial program 99.9%
fma-define99.9%
add-cube-cbrt99.4%
associate-*l*99.4%
fma-define99.4%
pow299.4%
Applied egg-rr99.4%
Taylor expanded in t around 0 87.2%
Taylor expanded in z around 0 70.3%
*-commutative70.3%
Simplified70.3%
if -1.35e-40 < y < 1.9199999999999999Initial program 100.0%
Taylor expanded in y around 0 68.7%
Final simplification69.5%
(FPCore (x y z t) :precision binary64 (if (or (<= z -2.3e+105) (not (<= z 6e+54))) (* y z) t))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -2.3e+105) || !(z <= 6e+54)) {
tmp = y * z;
} 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 ((z <= (-2.3d+105)) .or. (.not. (z <= 6d+54))) then
tmp = y * z
else
tmp = t
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -2.3e+105) || !(z <= 6e+54)) {
tmp = y * z;
} else {
tmp = t;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -2.3e+105) or not (z <= 6e+54): tmp = y * z else: tmp = t return tmp
function code(x, y, z, t) tmp = 0.0 if ((z <= -2.3e+105) || !(z <= 6e+54)) tmp = Float64(y * z); else tmp = t; end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((z <= -2.3e+105) || ~((z <= 6e+54))) tmp = y * z; else tmp = t; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -2.3e+105], N[Not[LessEqual[z, 6e+54]], $MachinePrecision]], N[(y * z), $MachinePrecision], t]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.3 \cdot 10^{+105} \lor \neg \left(z \leq 6 \cdot 10^{+54}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\\
\end{array}
\end{array}
if z < -2.2999999999999998e105 or 5.9999999999999998e54 < z Initial program 99.9%
fma-define99.9%
add-cube-cbrt99.1%
associate-*l*99.1%
fma-define99.1%
pow299.1%
Applied egg-rr99.1%
Taylor expanded in z around inf 62.8%
*-commutative62.8%
Simplified62.8%
if -2.2999999999999998e105 < z < 5.9999999999999998e54Initial program 99.9%
Taylor expanded in y around 0 54.8%
Final simplification57.8%
(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 41.1%
herbie shell --seed 2024091
(FPCore (x y z t)
:name "Language.Haskell.HsColour.ColourHighlight:unbase from hscolour-1.23"
:precision binary64
(+ (* (+ (* x y) z) y) t))