
(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 9 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 (+ t (* y (fma y x z))))
double code(double x, double y, double z, double t) {
return t + (y * fma(y, x, z));
}
function code(x, y, z, t) return Float64(t + Float64(y * fma(y, x, z))) end
code[x_, y_, z_, t_] := N[(t + N[(y * N[(y * x + z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
t + y \cdot \mathsf{fma}\left(y, x, z\right)
\end{array}
Initial program 99.9%
Taylor expanded in x around 0 99.9%
+-commutative99.9%
*-commutative99.9%
fma-udef99.9%
Simplified99.9%
Final simplification99.9%
(FPCore (x y z t)
:precision binary64
(if (or (<= z -4.7e+83)
(not (or (<= z -9e+30) (and (not (<= z -7.2e+18)) (<= z 9e+91)))))
(* y z)
t))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -4.7e+83) || !((z <= -9e+30) || (!(z <= -7.2e+18) && (z <= 9e+91)))) {
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 <= (-4.7d+83)) .or. (.not. (z <= (-9d+30)) .or. (.not. (z <= (-7.2d+18))) .and. (z <= 9d+91))) 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 <= -4.7e+83) || !((z <= -9e+30) || (!(z <= -7.2e+18) && (z <= 9e+91)))) {
tmp = y * z;
} else {
tmp = t;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -4.7e+83) or not ((z <= -9e+30) or (not (z <= -7.2e+18) and (z <= 9e+91))): tmp = y * z else: tmp = t return tmp
function code(x, y, z, t) tmp = 0.0 if ((z <= -4.7e+83) || !((z <= -9e+30) || (!(z <= -7.2e+18) && (z <= 9e+91)))) tmp = Float64(y * z); else tmp = t; end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((z <= -4.7e+83) || ~(((z <= -9e+30) || (~((z <= -7.2e+18)) && (z <= 9e+91))))) tmp = y * z; else tmp = t; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -4.7e+83], N[Not[Or[LessEqual[z, -9e+30], And[N[Not[LessEqual[z, -7.2e+18]], $MachinePrecision], LessEqual[z, 9e+91]]]], $MachinePrecision]], N[(y * z), $MachinePrecision], t]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -4.7 \cdot 10^{+83} \lor \neg \left(z \leq -9 \cdot 10^{+30} \lor \neg \left(z \leq -7.2 \cdot 10^{+18}\right) \land z \leq 9 \cdot 10^{+91}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\\
\end{array}
\end{array}
if z < -4.6999999999999999e83 or -8.9999999999999999e30 < z < -7.2e18 or 9e91 < z Initial program 100.0%
Taylor expanded in t around 0 81.1%
Taylor expanded in z around inf 59.5%
if -4.6999999999999999e83 < z < -8.9999999999999999e30 or -7.2e18 < z < 9e91Initial program 99.9%
Taylor expanded in y around 0 50.7%
Final simplification54.0%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (* y (* x y))))
(if (<= y -3.2e-15)
t_1
(if (<= y 7e-28) t (if (<= y 2.3e+44) (* y z) t_1)))))
double code(double x, double y, double z, double t) {
double t_1 = y * (x * y);
double tmp;
if (y <= -3.2e-15) {
tmp = t_1;
} else if (y <= 7e-28) {
tmp = t;
} else if (y <= 2.3e+44) {
tmp = 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 * (x * y)
if (y <= (-3.2d-15)) then
tmp = t_1
else if (y <= 7d-28) then
tmp = t
else if (y <= 2.3d+44) then
tmp = 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 * (x * y);
double tmp;
if (y <= -3.2e-15) {
tmp = t_1;
} else if (y <= 7e-28) {
tmp = t;
} else if (y <= 2.3e+44) {
tmp = y * z;
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z, t): t_1 = y * (x * y) tmp = 0 if y <= -3.2e-15: tmp = t_1 elif y <= 7e-28: tmp = t elif y <= 2.3e+44: tmp = y * z else: tmp = t_1 return tmp
function code(x, y, z, t) t_1 = Float64(y * Float64(x * y)) tmp = 0.0 if (y <= -3.2e-15) tmp = t_1; elseif (y <= 7e-28) tmp = t; elseif (y <= 2.3e+44) tmp = Float64(y * z); 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 <= -3.2e-15) tmp = t_1; elseif (y <= 7e-28) tmp = t; elseif (y <= 2.3e+44) tmp = y * z; 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, -3.2e-15], t$95$1, If[LessEqual[y, 7e-28], t, If[LessEqual[y, 2.3e+44], N[(y * z), $MachinePrecision], t$95$1]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := y \cdot \left(x \cdot y\right)\\
\mathbf{if}\;y \leq -3.2 \cdot 10^{-15}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;y \leq 7 \cdot 10^{-28}:\\
\;\;\;\;t\\
\mathbf{elif}\;y \leq 2.3 \cdot 10^{+44}:\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}
\end{array}
if y < -3.1999999999999999e-15 or 2.30000000000000004e44 < y Initial program 99.9%
Taylor expanded in t around 0 89.2%
Taylor expanded in z around 0 73.2%
*-commutative73.2%
Simplified73.2%
if -3.1999999999999999e-15 < y < 6.9999999999999999e-28Initial program 100.0%
Taylor expanded in y around 0 67.6%
if 6.9999999999999999e-28 < y < 2.30000000000000004e44Initial program 99.8%
Taylor expanded in t around 0 71.1%
Taylor expanded in z around inf 63.1%
Final simplification69.9%
(FPCore (x y z t) :precision binary64 (if (or (<= y -1.4e-14) (not (<= y 4.9e+36))) (* y (+ z (* x y))) (+ t (* y z))))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -1.4e-14) || !(y <= 4.9e+36)) {
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.4d-14)) .or. (.not. (y <= 4.9d+36))) 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.4e-14) || !(y <= 4.9e+36)) {
tmp = y * (z + (x * y));
} else {
tmp = t + (y * z);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y <= -1.4e-14) or not (y <= 4.9e+36): tmp = y * (z + (x * y)) else: tmp = t + (y * z) return tmp
function code(x, y, z, t) tmp = 0.0 if ((y <= -1.4e-14) || !(y <= 4.9e+36)) 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.4e-14) || ~((y <= 4.9e+36))) 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.4e-14], N[Not[LessEqual[y, 4.9e+36]], $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.4 \cdot 10^{-14} \lor \neg \left(y \leq 4.9 \cdot 10^{+36}\right):\\
\;\;\;\;y \cdot \left(z + x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;t + y \cdot z\\
\end{array}
\end{array}
if y < -1.4e-14 or 4.89999999999999981e36 < y Initial program 99.9%
Taylor expanded in t around 0 89.5%
if -1.4e-14 < y < 4.89999999999999981e36Initial program 100.0%
Taylor expanded in x around 0 90.6%
Final simplification90.1%
(FPCore (x y z t) :precision binary64 (if (<= y -1.36e+14) (+ t (* y (* x y))) (if (<= y 3.2e+35) (+ t (* y z)) (* y (+ z (* x y))))))
double code(double x, double y, double z, double t) {
double tmp;
if (y <= -1.36e+14) {
tmp = t + (y * (x * y));
} else if (y <= 3.2e+35) {
tmp = t + (y * z);
} else {
tmp = y * (z + (x * 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 <= (-1.36d+14)) then
tmp = t + (y * (x * y))
else if (y <= 3.2d+35) then
tmp = t + (y * z)
else
tmp = y * (z + (x * y))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (y <= -1.36e+14) {
tmp = t + (y * (x * y));
} else if (y <= 3.2e+35) {
tmp = t + (y * z);
} else {
tmp = y * (z + (x * y));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if y <= -1.36e+14: tmp = t + (y * (x * y)) elif y <= 3.2e+35: tmp = t + (y * z) else: tmp = y * (z + (x * y)) return tmp
function code(x, y, z, t) tmp = 0.0 if (y <= -1.36e+14) tmp = Float64(t + Float64(y * Float64(x * y))); elseif (y <= 3.2e+35) tmp = Float64(t + Float64(y * z)); else tmp = Float64(y * Float64(z + Float64(x * y))); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (y <= -1.36e+14) tmp = t + (y * (x * y)); elseif (y <= 3.2e+35) tmp = t + (y * z); else tmp = y * (z + (x * y)); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[y, -1.36e+14], N[(t + N[(y * N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 3.2e+35], N[(t + N[(y * z), $MachinePrecision]), $MachinePrecision], N[(y * N[(z + N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.36 \cdot 10^{+14}:\\
\;\;\;\;t + y \cdot \left(x \cdot y\right)\\
\mathbf{elif}\;y \leq 3.2 \cdot 10^{+35}:\\
\;\;\;\;t + y \cdot z\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(z + x \cdot y\right)\\
\end{array}
\end{array}
if y < -1.36e14Initial program 99.9%
Taylor expanded in x around inf 86.9%
*-commutative86.9%
Simplified86.9%
if -1.36e14 < y < 3.19999999999999983e35Initial program 99.9%
Taylor expanded in x around 0 89.5%
if 3.19999999999999983e35 < y Initial program 99.9%
Taylor expanded in t around 0 93.9%
Final simplification90.1%
(FPCore (x y z t) :precision binary64 (if (or (<= y -1.65e+94) (not (<= y 5.5e+47))) (* y (* x y)) (+ t (* y z))))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -1.65e+94) || !(y <= 5.5e+47)) {
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 <= (-1.65d+94)) .or. (.not. (y <= 5.5d+47))) 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 <= -1.65e+94) || !(y <= 5.5e+47)) {
tmp = y * (x * y);
} else {
tmp = t + (y * z);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y <= -1.65e+94) or not (y <= 5.5e+47): tmp = y * (x * y) else: tmp = t + (y * z) return tmp
function code(x, y, z, t) tmp = 0.0 if ((y <= -1.65e+94) || !(y <= 5.5e+47)) 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 <= -1.65e+94) || ~((y <= 5.5e+47))) tmp = y * (x * y); else tmp = t + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -1.65e+94], N[Not[LessEqual[y, 5.5e+47]], $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 -1.65 \cdot 10^{+94} \lor \neg \left(y \leq 5.5 \cdot 10^{+47}\right):\\
\;\;\;\;y \cdot \left(x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;t + y \cdot z\\
\end{array}
\end{array}
if y < -1.65e94 or 5.4999999999999998e47 < y Initial program 100.0%
Taylor expanded in t around 0 92.3%
Taylor expanded in z around 0 79.9%
*-commutative79.9%
Simplified79.9%
if -1.65e94 < y < 5.4999999999999998e47Initial program 99.9%
Taylor expanded in x around 0 87.2%
Final simplification84.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 39.6%
Final simplification39.6%
herbie shell --seed 2024010
(FPCore (x y z t)
:name "Language.Haskell.HsColour.ColourHighlight:unbase from hscolour-1.23"
:precision binary64
(+ (* (+ (* x y) z) y) t))