
(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 -4.6e+102) (not (<= y 7800000000000.0))) (* y (+ z (* x y))) (+ t (* y z))))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -4.6e+102) || !(y <= 7800000000000.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 <= (-4.6d+102)) .or. (.not. (y <= 7800000000000.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 <= -4.6e+102) || !(y <= 7800000000000.0)) {
tmp = y * (z + (x * y));
} else {
tmp = t + (y * z);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y <= -4.6e+102) or not (y <= 7800000000000.0): tmp = y * (z + (x * y)) else: tmp = t + (y * z) return tmp
function code(x, y, z, t) tmp = 0.0 if ((y <= -4.6e+102) || !(y <= 7800000000000.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 <= -4.6e+102) || ~((y <= 7800000000000.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, -4.6e+102], N[Not[LessEqual[y, 7800000000000.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 -4.6 \cdot 10^{+102} \lor \neg \left(y \leq 7800000000000\right):\\
\;\;\;\;y \cdot \left(z + x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;t + y \cdot z\\
\end{array}
\end{array}
if y < -4.5999999999999998e102 or 7.8e12 < y Initial program 99.9%
Taylor expanded in t around 0 93.8%
if -4.5999999999999998e102 < y < 7.8e12Initial program 99.9%
Taylor expanded in x around 0 90.4%
Final simplification91.9%
(FPCore (x y z t) :precision binary64 (if (or (<= y -4.2e+87) (not (<= y 36000000000000.0))) (* x (* y y)) t))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -4.2e+87) || !(y <= 36000000000000.0)) {
tmp = x * (y * 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 <= (-4.2d+87)) .or. (.not. (y <= 36000000000000.0d0))) then
tmp = x * (y * 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 <= -4.2e+87) || !(y <= 36000000000000.0)) {
tmp = x * (y * y);
} else {
tmp = t;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y <= -4.2e+87) or not (y <= 36000000000000.0): tmp = x * (y * y) else: tmp = t return tmp
function code(x, y, z, t) tmp = 0.0 if ((y <= -4.2e+87) || !(y <= 36000000000000.0)) tmp = Float64(x * Float64(y * y)); else tmp = t; end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((y <= -4.2e+87) || ~((y <= 36000000000000.0))) tmp = x * (y * y); else tmp = t; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -4.2e+87], N[Not[LessEqual[y, 36000000000000.0]], $MachinePrecision]], N[(x * N[(y * y), $MachinePrecision]), $MachinePrecision], t]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.2 \cdot 10^{+87} \lor \neg \left(y \leq 36000000000000\right):\\
\;\;\;\;x \cdot \left(y \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;t\\
\end{array}
\end{array}
if y < -4.2e87 or 3.6e13 < y Initial program 99.9%
Taylor expanded in t around 0 93.9%
Taylor expanded in y around inf 71.6%
unpow271.6%
*-commutative71.6%
Simplified71.6%
if -4.2e87 < y < 3.6e13Initial program 99.9%
Taylor expanded in y around 0 64.3%
Final simplification67.6%
(FPCore (x y z t) :precision binary64 (if (or (<= y -4.2e+87) (not (<= y 9500000000000.0))) (* y (* x y)) t))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -4.2e+87) || !(y <= 9500000000000.0)) {
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 <= (-4.2d+87)) .or. (.not. (y <= 9500000000000.0d0))) 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 <= -4.2e+87) || !(y <= 9500000000000.0)) {
tmp = y * (x * y);
} else {
tmp = t;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y <= -4.2e+87) or not (y <= 9500000000000.0): tmp = y * (x * y) else: tmp = t return tmp
function code(x, y, z, t) tmp = 0.0 if ((y <= -4.2e+87) || !(y <= 9500000000000.0)) 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 <= -4.2e+87) || ~((y <= 9500000000000.0))) tmp = y * (x * y); else tmp = t; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -4.2e+87], N[Not[LessEqual[y, 9500000000000.0]], $MachinePrecision]], N[(y * N[(x * y), $MachinePrecision]), $MachinePrecision], t]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.2 \cdot 10^{+87} \lor \neg \left(y \leq 9500000000000\right):\\
\;\;\;\;y \cdot \left(x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;t\\
\end{array}
\end{array}
if y < -4.2e87 or 9.5e12 < y Initial program 99.9%
Taylor expanded in t around 0 93.9%
Taylor expanded in y around inf 78.7%
if -4.2e87 < y < 9.5e12Initial program 99.9%
Taylor expanded in y around 0 64.3%
Final simplification70.7%
(FPCore (x y z t) :precision binary64 (if (or (<= y -6e+102) (not (<= y 7.8e+24))) (* y (* x y)) (+ t (* y z))))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -6e+102) || !(y <= 7.8e+24)) {
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 <= (-6d+102)) .or. (.not. (y <= 7.8d+24))) 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 <= -6e+102) || !(y <= 7.8e+24)) {
tmp = y * (x * y);
} else {
tmp = t + (y * z);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y <= -6e+102) or not (y <= 7.8e+24): tmp = y * (x * y) else: tmp = t + (y * z) return tmp
function code(x, y, z, t) tmp = 0.0 if ((y <= -6e+102) || !(y <= 7.8e+24)) 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 <= -6e+102) || ~((y <= 7.8e+24))) tmp = y * (x * y); else tmp = t + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -6e+102], N[Not[LessEqual[y, 7.8e+24]], $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 -6 \cdot 10^{+102} \lor \neg \left(y \leq 7.8 \cdot 10^{+24}\right):\\
\;\;\;\;y \cdot \left(x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;t + y \cdot z\\
\end{array}
\end{array}
if y < -5.9999999999999996e102 or 7.7999999999999995e24 < y Initial program 99.9%
Taylor expanded in t around 0 93.7%
Taylor expanded in y around inf 79.9%
if -5.9999999999999996e102 < y < 7.7999999999999995e24Initial program 99.9%
Taylor expanded in x around 0 89.8%
Final simplification85.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 (if (<= t -4.2e-30) t (if (<= t 2.8e-18) (* y z) t)))
double code(double x, double y, double z, double t) {
double tmp;
if (t <= -4.2e-30) {
tmp = t;
} else if (t <= 2.8e-18) {
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 (t <= (-4.2d-30)) then
tmp = t
else if (t <= 2.8d-18) 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 (t <= -4.2e-30) {
tmp = t;
} else if (t <= 2.8e-18) {
tmp = y * z;
} else {
tmp = t;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if t <= -4.2e-30: tmp = t elif t <= 2.8e-18: tmp = y * z else: tmp = t return tmp
function code(x, y, z, t) tmp = 0.0 if (t <= -4.2e-30) tmp = t; elseif (t <= 2.8e-18) tmp = Float64(y * z); else tmp = t; end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (t <= -4.2e-30) tmp = t; elseif (t <= 2.8e-18) tmp = y * z; else tmp = t; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[t, -4.2e-30], t, If[LessEqual[t, 2.8e-18], N[(y * z), $MachinePrecision], t]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \leq -4.2 \cdot 10^{-30}:\\
\;\;\;\;t\\
\mathbf{elif}\;t \leq 2.8 \cdot 10^{-18}:\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\\
\end{array}
\end{array}
if t < -4.2000000000000004e-30 or 2.80000000000000012e-18 < t Initial program 99.9%
Taylor expanded in y around 0 63.2%
if -4.2000000000000004e-30 < t < 2.80000000000000012e-18Initial program 99.9%
Taylor expanded in x around 0 53.1%
Taylor expanded in z around inf 41.5%
Final simplification52.4%
(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.1%
Final simplification39.1%
herbie shell --seed 2023173
(FPCore (x y z t)
:name "Language.Haskell.HsColour.ColourHighlight:unbase from hscolour-1.23"
:precision binary64
(+ (* (+ (* x y) z) y) t))