
(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 (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
(if (or (<= y -3.5e+76)
(not
(or (<= y -4.9e+32) (and (not (<= y -3.2e-21)) (<= y 8.6e+102)))))
(* y (* x y))
(+ t (* y z))))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -3.5e+76) || !((y <= -4.9e+32) || (!(y <= -3.2e-21) && (y <= 8.6e+102)))) {
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 <= (-3.5d+76)) .or. (.not. (y <= (-4.9d+32)) .or. (.not. (y <= (-3.2d-21))) .and. (y <= 8.6d+102))) 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 <= -3.5e+76) || !((y <= -4.9e+32) || (!(y <= -3.2e-21) && (y <= 8.6e+102)))) {
tmp = y * (x * y);
} else {
tmp = t + (y * z);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y <= -3.5e+76) or not ((y <= -4.9e+32) or (not (y <= -3.2e-21) and (y <= 8.6e+102))): tmp = y * (x * y) else: tmp = t + (y * z) return tmp
function code(x, y, z, t) tmp = 0.0 if ((y <= -3.5e+76) || !((y <= -4.9e+32) || (!(y <= -3.2e-21) && (y <= 8.6e+102)))) 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 <= -3.5e+76) || ~(((y <= -4.9e+32) || (~((y <= -3.2e-21)) && (y <= 8.6e+102))))) tmp = y * (x * y); else tmp = t + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -3.5e+76], N[Not[Or[LessEqual[y, -4.9e+32], And[N[Not[LessEqual[y, -3.2e-21]], $MachinePrecision], LessEqual[y, 8.6e+102]]]], $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 -3.5 \cdot 10^{+76} \lor \neg \left(y \leq -4.9 \cdot 10^{+32} \lor \neg \left(y \leq -3.2 \cdot 10^{-21}\right) \land y \leq 8.6 \cdot 10^{+102}\right):\\
\;\;\;\;y \cdot \left(x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;t + y \cdot z\\
\end{array}
\end{array}
if y < -3.5e76 or -4.9000000000000001e32 < y < -3.2000000000000002e-21 or 8.6000000000000002e102 < y Initial program 99.9%
Taylor expanded in z around inf 94.4%
associate-/l*90.8%
Simplified90.8%
Taylor expanded in t around 0 92.6%
associate-/l*89.9%
Applied egg-rr89.9%
associate-*r/92.6%
*-commutative92.6%
associate-*r/92.6%
Simplified92.6%
Taylor expanded in z around 0 81.8%
if -3.5e76 < y < -4.9000000000000001e32 or -3.2000000000000002e-21 < y < 8.6000000000000002e102Initial program 99.9%
Taylor expanded in x around 0 89.9%
Final simplification86.7%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (* y (* x y))))
(if (<= y -3.8e-30)
t_1
(if (<= y 9.5e-114) t (if (<= y 5.1e+101) (* 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.8e-30) {
tmp = t_1;
} else if (y <= 9.5e-114) {
tmp = t;
} else if (y <= 5.1e+101) {
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.8d-30)) then
tmp = t_1
else if (y <= 9.5d-114) then
tmp = t
else if (y <= 5.1d+101) 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.8e-30) {
tmp = t_1;
} else if (y <= 9.5e-114) {
tmp = t;
} else if (y <= 5.1e+101) {
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.8e-30: tmp = t_1 elif y <= 9.5e-114: tmp = t elif y <= 5.1e+101: 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.8e-30) tmp = t_1; elseif (y <= 9.5e-114) tmp = t; elseif (y <= 5.1e+101) 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.8e-30) tmp = t_1; elseif (y <= 9.5e-114) tmp = t; elseif (y <= 5.1e+101) 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.8e-30], t$95$1, If[LessEqual[y, 9.5e-114], t, If[LessEqual[y, 5.1e+101], 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.8 \cdot 10^{-30}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;y \leq 9.5 \cdot 10^{-114}:\\
\;\;\;\;t\\
\mathbf{elif}\;y \leq 5.1 \cdot 10^{+101}:\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if y < -3.8000000000000003e-30 or 5.09999999999999995e101 < y Initial program 99.9%
Taylor expanded in z around inf 94.9%
associate-/l*91.7%
Simplified91.7%
Taylor expanded in t around 0 89.1%
associate-/l*86.7%
Applied egg-rr86.7%
associate-*r/89.1%
*-commutative89.1%
associate-*r/89.1%
Simplified89.1%
Taylor expanded in z around 0 76.0%
if -3.8000000000000003e-30 < y < 9.49999999999999958e-114Initial program 100.0%
Taylor expanded in y around 0 71.8%
if 9.49999999999999958e-114 < y < 5.09999999999999995e101Initial program 99.8%
Taylor expanded in x around 0 76.0%
Taylor expanded in z around inf 65.2%
Taylor expanded in y around inf 47.6%
Final simplification70.4%
(FPCore (x y z t) :precision binary64 (if (or (<= y -7.8e-30) (not (<= y 9.2e-60))) (* y (+ z (* x y))) (+ t (* y z))))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -7.8e-30) || !(y <= 9.2e-60)) {
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 <= (-7.8d-30)) .or. (.not. (y <= 9.2d-60))) 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 <= -7.8e-30) || !(y <= 9.2e-60)) {
tmp = y * (z + (x * y));
} else {
tmp = t + (y * z);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y <= -7.8e-30) or not (y <= 9.2e-60): tmp = y * (z + (x * y)) else: tmp = t + (y * z) return tmp
function code(x, y, z, t) tmp = 0.0 if ((y <= -7.8e-30) || !(y <= 9.2e-60)) 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 <= -7.8e-30) || ~((y <= 9.2e-60))) tmp = y * (z + (x * y)); else tmp = t + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -7.8e-30], N[Not[LessEqual[y, 9.2e-60]], $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 -7.8 \cdot 10^{-30} \lor \neg \left(y \leq 9.2 \cdot 10^{-60}\right):\\
\;\;\;\;y \cdot \left(z + x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;t + y \cdot z\\
\end{array}
\end{array}
if y < -7.8000000000000007e-30 or 9.2000000000000005e-60 < y Initial program 99.8%
Taylor expanded in z around inf 93.5%
associate-/l*90.8%
Simplified90.8%
Taylor expanded in t around 0 86.4%
associate-/l*84.3%
Applied egg-rr84.3%
associate-*r/86.4%
*-commutative86.4%
associate-*r/86.4%
Simplified86.4%
Taylor expanded in z around 0 90.7%
if -7.8000000000000007e-30 < y < 9.2000000000000005e-60Initial program 100.0%
Taylor expanded in x around 0 95.1%
Final simplification92.7%
(FPCore (x y z t) :precision binary64 (if (or (<= z -3.4e+16) (not (<= z 1.32e+114))) (* y z) t))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -3.4e+16) || !(z <= 1.32e+114)) {
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 <= (-3.4d+16)) .or. (.not. (z <= 1.32d+114))) 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 <= -3.4e+16) || !(z <= 1.32e+114)) {
tmp = y * z;
} else {
tmp = t;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -3.4e+16) or not (z <= 1.32e+114): tmp = y * z else: tmp = t return tmp
function code(x, y, z, t) tmp = 0.0 if ((z <= -3.4e+16) || !(z <= 1.32e+114)) tmp = Float64(y * z); else tmp = t; end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((z <= -3.4e+16) || ~((z <= 1.32e+114))) tmp = y * z; else tmp = t; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -3.4e+16], N[Not[LessEqual[z, 1.32e+114]], $MachinePrecision]], N[(y * z), $MachinePrecision], t]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.4 \cdot 10^{+16} \lor \neg \left(z \leq 1.32 \cdot 10^{+114}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\\
\end{array}
\end{array}
if z < -3.4e16 or 1.3200000000000001e114 < z Initial program 99.9%
Taylor expanded in x around 0 80.3%
Taylor expanded in z around inf 80.3%
Taylor expanded in y around inf 60.5%
if -3.4e16 < z < 1.3200000000000001e114Initial program 99.9%
Taylor expanded in y around 0 47.7%
Final simplification52.5%
(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 38.2%
herbie shell --seed 2024087
(FPCore (x y z t)
:name "Language.Haskell.HsColour.ColourHighlight:unbase from hscolour-1.23"
:precision binary64
(+ (* (+ (* x y) z) y) t))