
(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-def100.0%
fma-def100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (* y (* x y))))
(if (<= y -9.2e+135)
t_1
(if (<= y -1.6e+89)
(* y z)
(if (<= y -1.24e-42)
t_1
(if (<= y 5.6e-126) t (if (<= y 1.8e+99) (* y z) t_1)))))))
double code(double x, double y, double z, double t) {
double t_1 = y * (x * y);
double tmp;
if (y <= -9.2e+135) {
tmp = t_1;
} else if (y <= -1.6e+89) {
tmp = y * z;
} else if (y <= -1.24e-42) {
tmp = t_1;
} else if (y <= 5.6e-126) {
tmp = t;
} else if (y <= 1.8e+99) {
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 <= (-9.2d+135)) then
tmp = t_1
else if (y <= (-1.6d+89)) then
tmp = y * z
else if (y <= (-1.24d-42)) then
tmp = t_1
else if (y <= 5.6d-126) then
tmp = t
else if (y <= 1.8d+99) 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 <= -9.2e+135) {
tmp = t_1;
} else if (y <= -1.6e+89) {
tmp = y * z;
} else if (y <= -1.24e-42) {
tmp = t_1;
} else if (y <= 5.6e-126) {
tmp = t;
} else if (y <= 1.8e+99) {
tmp = y * z;
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z, t): t_1 = y * (x * y) tmp = 0 if y <= -9.2e+135: tmp = t_1 elif y <= -1.6e+89: tmp = y * z elif y <= -1.24e-42: tmp = t_1 elif y <= 5.6e-126: tmp = t elif y <= 1.8e+99: 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 <= -9.2e+135) tmp = t_1; elseif (y <= -1.6e+89) tmp = Float64(y * z); elseif (y <= -1.24e-42) tmp = t_1; elseif (y <= 5.6e-126) tmp = t; elseif (y <= 1.8e+99) 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 <= -9.2e+135) tmp = t_1; elseif (y <= -1.6e+89) tmp = y * z; elseif (y <= -1.24e-42) tmp = t_1; elseif (y <= 5.6e-126) tmp = t; elseif (y <= 1.8e+99) 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, -9.2e+135], t$95$1, If[LessEqual[y, -1.6e+89], N[(y * z), $MachinePrecision], If[LessEqual[y, -1.24e-42], t$95$1, If[LessEqual[y, 5.6e-126], t, If[LessEqual[y, 1.8e+99], 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 -9.2 \cdot 10^{+135}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;y \leq -1.6 \cdot 10^{+89}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq -1.24 \cdot 10^{-42}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;y \leq 5.6 \cdot 10^{-126}:\\
\;\;\;\;t\\
\mathbf{elif}\;y \leq 1.8 \cdot 10^{+99}:\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}
\end{array}
if y < -9.2000000000000005e135 or -1.59999999999999994e89 < y < -1.24e-42 or 1.8000000000000001e99 < y Initial program 99.9%
Taylor expanded in t around 0 92.5%
Taylor expanded in y around inf 78.3%
if -9.2000000000000005e135 < y < -1.59999999999999994e89 or 5.59999999999999983e-126 < y < 1.8000000000000001e99Initial program 100.0%
Taylor expanded in t around 0 81.0%
Taylor expanded in y around 0 54.5%
if -1.24e-42 < y < 5.59999999999999983e-126Initial program 100.0%
Taylor expanded in y around 0 83.3%
Final simplification75.1%
(FPCore (x y z t)
:precision binary64
(if (or (<= y -9.5e+135)
(and (not (<= y -5.4e+83))
(or (<= y -1.22e+36) (not (<= y 2.5e+98)))))
(* y (* x y))
(+ t (* y z))))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -9.5e+135) || (!(y <= -5.4e+83) && ((y <= -1.22e+36) || !(y <= 2.5e+98)))) {
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 <= (-9.5d+135)) .or. (.not. (y <= (-5.4d+83))) .and. (y <= (-1.22d+36)) .or. (.not. (y <= 2.5d+98))) 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 <= -9.5e+135) || (!(y <= -5.4e+83) && ((y <= -1.22e+36) || !(y <= 2.5e+98)))) {
tmp = y * (x * y);
} else {
tmp = t + (y * z);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y <= -9.5e+135) or (not (y <= -5.4e+83) and ((y <= -1.22e+36) or not (y <= 2.5e+98))): tmp = y * (x * y) else: tmp = t + (y * z) return tmp
function code(x, y, z, t) tmp = 0.0 if ((y <= -9.5e+135) || (!(y <= -5.4e+83) && ((y <= -1.22e+36) || !(y <= 2.5e+98)))) 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 <= -9.5e+135) || (~((y <= -5.4e+83)) && ((y <= -1.22e+36) || ~((y <= 2.5e+98))))) tmp = y * (x * y); else tmp = t + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -9.5e+135], And[N[Not[LessEqual[y, -5.4e+83]], $MachinePrecision], Or[LessEqual[y, -1.22e+36], N[Not[LessEqual[y, 2.5e+98]], $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 -9.5 \cdot 10^{+135} \lor \neg \left(y \leq -5.4 \cdot 10^{+83}\right) \land \left(y \leq -1.22 \cdot 10^{+36} \lor \neg \left(y \leq 2.5 \cdot 10^{+98}\right)\right):\\
\;\;\;\;y \cdot \left(x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;t + y \cdot z\\
\end{array}
\end{array}
if y < -9.50000000000000036e135 or -5.40000000000000014e83 < y < -1.21999999999999995e36 or 2.4999999999999999e98 < y Initial program 99.9%
Taylor expanded in t around 0 96.5%
Taylor expanded in y around inf 84.0%
if -9.50000000000000036e135 < y < -5.40000000000000014e83 or -1.21999999999999995e36 < y < 2.4999999999999999e98Initial program 100.0%
Taylor expanded in x around 0 85.8%
Final simplification85.2%
(FPCore (x y z t) :precision binary64 (if (or (<= y -2.15e-42) (not (<= y 8.5e-38))) (* y (+ z (* x y))) (+ t (* y z))))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -2.15e-42) || !(y <= 8.5e-38)) {
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 <= (-2.15d-42)) .or. (.not. (y <= 8.5d-38))) 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 <= -2.15e-42) || !(y <= 8.5e-38)) {
tmp = y * (z + (x * y));
} else {
tmp = t + (y * z);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y <= -2.15e-42) or not (y <= 8.5e-38): tmp = y * (z + (x * y)) else: tmp = t + (y * z) return tmp
function code(x, y, z, t) tmp = 0.0 if ((y <= -2.15e-42) || !(y <= 8.5e-38)) 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 <= -2.15e-42) || ~((y <= 8.5e-38))) tmp = y * (z + (x * y)); else tmp = t + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -2.15e-42], N[Not[LessEqual[y, 8.5e-38]], $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 -2.15 \cdot 10^{-42} \lor \neg \left(y \leq 8.5 \cdot 10^{-38}\right):\\
\;\;\;\;y \cdot \left(z + x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;t + y \cdot z\\
\end{array}
\end{array}
if y < -2.1500000000000001e-42 or 8.50000000000000046e-38 < y Initial program 99.9%
Taylor expanded in t around 0 90.7%
if -2.1500000000000001e-42 < y < 8.50000000000000046e-38Initial program 100.0%
Taylor expanded in x around 0 95.3%
Final simplification92.7%
(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 (<= y -2.8e+73) (* y z) (if (<= y 6.4e-122) t (* y z))))
double code(double x, double y, double z, double t) {
double tmp;
if (y <= -2.8e+73) {
tmp = y * z;
} else if (y <= 6.4e-122) {
tmp = t;
} else {
tmp = 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 <= (-2.8d+73)) then
tmp = y * z
else if (y <= 6.4d-122) then
tmp = t
else
tmp = y * z
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (y <= -2.8e+73) {
tmp = y * z;
} else if (y <= 6.4e-122) {
tmp = t;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if y <= -2.8e+73: tmp = y * z elif y <= 6.4e-122: tmp = t else: tmp = y * z return tmp
function code(x, y, z, t) tmp = 0.0 if (y <= -2.8e+73) tmp = Float64(y * z); elseif (y <= 6.4e-122) tmp = t; else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (y <= -2.8e+73) tmp = y * z; elseif (y <= 6.4e-122) tmp = t; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[y, -2.8e+73], N[(y * z), $MachinePrecision], If[LessEqual[y, 6.4e-122], t, N[(y * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.8 \cdot 10^{+73}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 6.4 \cdot 10^{-122}:\\
\;\;\;\;t\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if y < -2.80000000000000008e73 or 6.4000000000000004e-122 < y Initial program 100.0%
Taylor expanded in t around 0 91.3%
Taylor expanded in y around 0 40.4%
if -2.80000000000000008e73 < y < 6.4000000000000004e-122Initial program 99.9%
Taylor expanded in y around 0 71.3%
Final simplification55.5%
(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 40.2%
Final simplification40.2%
herbie shell --seed 2023196
(FPCore (x y z t)
:name "Language.Haskell.HsColour.ColourHighlight:unbase from hscolour-1.23"
:precision binary64
(+ (* (+ (* x y) z) y) t))