
(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-def99.9%
Simplified99.9%
Final simplification99.9%
(FPCore (x y z t)
:precision binary64
(if (or (<= y -1.9e+23)
(not
(or (<= y -8.5e-122) (and (not (<= y -1e-144)) (<= y 1.12e+30)))))
(* y (+ z (* x y)))
(+ t (* y z))))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -1.9e+23) || !((y <= -8.5e-122) || (!(y <= -1e-144) && (y <= 1.12e+30)))) {
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.9d+23)) .or. (.not. (y <= (-8.5d-122)) .or. (.not. (y <= (-1d-144))) .and. (y <= 1.12d+30))) 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.9e+23) || !((y <= -8.5e-122) || (!(y <= -1e-144) && (y <= 1.12e+30)))) {
tmp = y * (z + (x * y));
} else {
tmp = t + (y * z);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y <= -1.9e+23) or not ((y <= -8.5e-122) or (not (y <= -1e-144) and (y <= 1.12e+30))): tmp = y * (z + (x * y)) else: tmp = t + (y * z) return tmp
function code(x, y, z, t) tmp = 0.0 if ((y <= -1.9e+23) || !((y <= -8.5e-122) || (!(y <= -1e-144) && (y <= 1.12e+30)))) 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.9e+23) || ~(((y <= -8.5e-122) || (~((y <= -1e-144)) && (y <= 1.12e+30))))) 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.9e+23], N[Not[Or[LessEqual[y, -8.5e-122], And[N[Not[LessEqual[y, -1e-144]], $MachinePrecision], LessEqual[y, 1.12e+30]]]], $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.9 \cdot 10^{+23} \lor \neg \left(y \leq -8.5 \cdot 10^{-122} \lor \neg \left(y \leq -1 \cdot 10^{-144}\right) \land y \leq 1.12 \cdot 10^{+30}\right):\\
\;\;\;\;y \cdot \left(z + x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;t + y \cdot z\\
\end{array}
\end{array}
if y < -1.89999999999999987e23 or -8.50000000000000003e-122 < y < -9.9999999999999995e-145 or 1.12e30 < y Initial program 99.9%
Taylor expanded in t around 0 92.5%
if -1.89999999999999987e23 < y < -8.50000000000000003e-122 or -9.9999999999999995e-145 < y < 1.12e30Initial program 100.0%
Taylor expanded in x around 0 89.1%
Final simplification90.9%
(FPCore (x y z t)
:precision binary64
(if (or (<= y -1850.0)
(not
(or (<= y -8.5e-122) (and (not (<= y -4.8e-145)) (<= y 1.65e+31)))))
(* y (* x y))
t))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -1850.0) || !((y <= -8.5e-122) || (!(y <= -4.8e-145) && (y <= 1.65e+31)))) {
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 <= (-1850.0d0)) .or. (.not. (y <= (-8.5d-122)) .or. (.not. (y <= (-4.8d-145))) .and. (y <= 1.65d+31))) 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 <= -1850.0) || !((y <= -8.5e-122) || (!(y <= -4.8e-145) && (y <= 1.65e+31)))) {
tmp = y * (x * y);
} else {
tmp = t;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y <= -1850.0) or not ((y <= -8.5e-122) or (not (y <= -4.8e-145) and (y <= 1.65e+31))): tmp = y * (x * y) else: tmp = t return tmp
function code(x, y, z, t) tmp = 0.0 if ((y <= -1850.0) || !((y <= -8.5e-122) || (!(y <= -4.8e-145) && (y <= 1.65e+31)))) 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 <= -1850.0) || ~(((y <= -8.5e-122) || (~((y <= -4.8e-145)) && (y <= 1.65e+31))))) tmp = y * (x * y); else tmp = t; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -1850.0], N[Not[Or[LessEqual[y, -8.5e-122], And[N[Not[LessEqual[y, -4.8e-145]], $MachinePrecision], LessEqual[y, 1.65e+31]]]], $MachinePrecision]], N[(y * N[(x * y), $MachinePrecision]), $MachinePrecision], t]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1850 \lor \neg \left(y \leq -8.5 \cdot 10^{-122} \lor \neg \left(y \leq -4.8 \cdot 10^{-145}\right) \land y \leq 1.65 \cdot 10^{+31}\right):\\
\;\;\;\;y \cdot \left(x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;t\\
\end{array}
\end{array}
if y < -1850 or -8.50000000000000003e-122 < y < -4.8000000000000003e-145 or 1.64999999999999996e31 < y Initial program 99.9%
Taylor expanded in t around 0 92.0%
Taylor expanded in z around 0 71.6%
*-commutative71.6%
Simplified71.6%
if -1850 < y < -8.50000000000000003e-122 or -4.8000000000000003e-145 < y < 1.64999999999999996e31Initial program 100.0%
Taylor expanded in y around 0 66.3%
Final simplification69.3%
(FPCore (x y z t)
:precision binary64
(if (or (<= y -5.8e+57)
(not (or (<= y -8.5e-122) (and (not (<= y -1e-144)) (<= y 8.5e+78)))))
(* y (* x y))
(+ t (* y z))))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -5.8e+57) || !((y <= -8.5e-122) || (!(y <= -1e-144) && (y <= 8.5e+78)))) {
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 <= (-5.8d+57)) .or. (.not. (y <= (-8.5d-122)) .or. (.not. (y <= (-1d-144))) .and. (y <= 8.5d+78))) 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 <= -5.8e+57) || !((y <= -8.5e-122) || (!(y <= -1e-144) && (y <= 8.5e+78)))) {
tmp = y * (x * y);
} else {
tmp = t + (y * z);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y <= -5.8e+57) or not ((y <= -8.5e-122) or (not (y <= -1e-144) and (y <= 8.5e+78))): tmp = y * (x * y) else: tmp = t + (y * z) return tmp
function code(x, y, z, t) tmp = 0.0 if ((y <= -5.8e+57) || !((y <= -8.5e-122) || (!(y <= -1e-144) && (y <= 8.5e+78)))) 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 <= -5.8e+57) || ~(((y <= -8.5e-122) || (~((y <= -1e-144)) && (y <= 8.5e+78))))) tmp = y * (x * y); else tmp = t + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -5.8e+57], N[Not[Or[LessEqual[y, -8.5e-122], And[N[Not[LessEqual[y, -1e-144]], $MachinePrecision], LessEqual[y, 8.5e+78]]]], $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 -5.8 \cdot 10^{+57} \lor \neg \left(y \leq -8.5 \cdot 10^{-122} \lor \neg \left(y \leq -1 \cdot 10^{-144}\right) \land y \leq 8.5 \cdot 10^{+78}\right):\\
\;\;\;\;y \cdot \left(x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;t + y \cdot z\\
\end{array}
\end{array}
if y < -5.8000000000000003e57 or -8.50000000000000003e-122 < y < -9.9999999999999995e-145 or 8.50000000000000079e78 < y Initial program 99.9%
Taylor expanded in t around 0 93.0%
Taylor expanded in z around 0 77.1%
*-commutative77.1%
Simplified77.1%
if -5.8000000000000003e57 < y < -8.50000000000000003e-122 or -9.9999999999999995e-145 < y < 8.50000000000000079e78Initial program 100.0%
Taylor expanded in x around 0 87.3%
Final simplification82.3%
(FPCore (x y z t) :precision binary64 (if (<= z -2.9e+102) (+ t (* y z)) (if (<= z 0.36) (+ t (* y (* x y))) (* y (+ z (* x y))))))
double code(double x, double y, double z, double t) {
double tmp;
if (z <= -2.9e+102) {
tmp = t + (y * z);
} else if (z <= 0.36) {
tmp = t + (y * (x * y));
} 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 (z <= (-2.9d+102)) then
tmp = t + (y * z)
else if (z <= 0.36d0) then
tmp = t + (y * (x * y))
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 (z <= -2.9e+102) {
tmp = t + (y * z);
} else if (z <= 0.36) {
tmp = t + (y * (x * y));
} else {
tmp = y * (z + (x * y));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if z <= -2.9e+102: tmp = t + (y * z) elif z <= 0.36: tmp = t + (y * (x * y)) else: tmp = y * (z + (x * y)) return tmp
function code(x, y, z, t) tmp = 0.0 if (z <= -2.9e+102) tmp = Float64(t + Float64(y * z)); elseif (z <= 0.36) tmp = Float64(t + Float64(y * Float64(x * y))); 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 (z <= -2.9e+102) tmp = t + (y * z); elseif (z <= 0.36) tmp = t + (y * (x * y)); else tmp = y * (z + (x * y)); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[z, -2.9e+102], N[(t + N[(y * z), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 0.36], N[(t + N[(y * N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(y * N[(z + N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.9 \cdot 10^{+102}:\\
\;\;\;\;t + y \cdot z\\
\mathbf{elif}\;z \leq 0.36:\\
\;\;\;\;t + y \cdot \left(x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(z + x \cdot y\right)\\
\end{array}
\end{array}
if z < -2.9000000000000002e102Initial program 100.0%
Taylor expanded in x around 0 85.8%
if -2.9000000000000002e102 < z < 0.35999999999999999Initial program 99.9%
Taylor expanded in x around inf 95.0%
*-commutative95.0%
Simplified95.0%
if 0.35999999999999999 < z Initial program 100.0%
Taylor expanded in t around 0 81.6%
Final simplification90.6%
(FPCore (x y z t) :precision binary64 (if (or (<= z -2.8e+102) (not (<= z 0.36))) (* y z) t))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -2.8e+102) || !(z <= 0.36)) {
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.8d+102)) .or. (.not. (z <= 0.36d0))) 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.8e+102) || !(z <= 0.36)) {
tmp = y * z;
} else {
tmp = t;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -2.8e+102) or not (z <= 0.36): tmp = y * z else: tmp = t return tmp
function code(x, y, z, t) tmp = 0.0 if ((z <= -2.8e+102) || !(z <= 0.36)) 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.8e+102) || ~((z <= 0.36))) tmp = y * z; else tmp = t; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -2.8e+102], N[Not[LessEqual[z, 0.36]], $MachinePrecision]], N[(y * z), $MachinePrecision], t]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.8 \cdot 10^{+102} \lor \neg \left(z \leq 0.36\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\\
\end{array}
\end{array}
if z < -2.80000000000000018e102 or 0.35999999999999999 < z Initial program 100.0%
Taylor expanded in t around 0 79.4%
Taylor expanded in z around inf 61.2%
if -2.80000000000000018e102 < z < 0.35999999999999999Initial program 99.9%
Taylor expanded in y around 0 42.0%
Final simplification49.4%
(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 34.4%
Final simplification34.4%
herbie shell --seed 2024027
(FPCore (x y z t)
:name "Language.Haskell.HsColour.ColourHighlight:unbase from hscolour-1.23"
:precision binary64
(+ (* (+ (* x y) z) y) t))