
(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 (+ t (* (+ z (* y x)) y)))
double code(double x, double y, double z, double t) {
return t + ((z + (y * 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 + ((z + (y * x)) * y)
end function
public static double code(double x, double y, double z, double t) {
return t + ((z + (y * x)) * y);
}
def code(x, y, z, t): return t + ((z + (y * x)) * y)
function code(x, y, z, t) return Float64(t + Float64(Float64(z + Float64(y * x)) * y)) end
function tmp = code(x, y, z, t) tmp = t + ((z + (y * x)) * y); end
code[x_, y_, z_, t_] := N[(t + N[(N[(z + N[(y * x), $MachinePrecision]), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
t + \left(z + y \cdot x\right) \cdot y
\end{array}
Initial program 100.0%
Final simplification100.0%
(FPCore (x y z t) :precision binary64 (let* ((t_1 (* (+ z (* y x)) y)) (t_2 (* (* y y) x))) (if (<= t_1 -2e+262) t_2 (if (<= t_1 2e+298) (fma z y t) t_2))))
double code(double x, double y, double z, double t) {
double t_1 = (z + (y * x)) * y;
double t_2 = (y * y) * x;
double tmp;
if (t_1 <= -2e+262) {
tmp = t_2;
} else if (t_1 <= 2e+298) {
tmp = fma(z, y, t);
} else {
tmp = t_2;
}
return tmp;
}
function code(x, y, z, t) t_1 = Float64(Float64(z + Float64(y * x)) * y) t_2 = Float64(Float64(y * y) * x) tmp = 0.0 if (t_1 <= -2e+262) tmp = t_2; elseif (t_1 <= 2e+298) tmp = fma(z, y, t); else tmp = t_2; end return tmp end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[(z + N[(y * x), $MachinePrecision]), $MachinePrecision] * y), $MachinePrecision]}, Block[{t$95$2 = N[(N[(y * y), $MachinePrecision] * x), $MachinePrecision]}, If[LessEqual[t$95$1, -2e+262], t$95$2, If[LessEqual[t$95$1, 2e+298], N[(z * y + t), $MachinePrecision], t$95$2]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \left(z + y \cdot x\right) \cdot y\\
t_2 := \left(y \cdot y\right) \cdot x\\
\mathbf{if}\;t\_1 \leq -2 \cdot 10^{+262}:\\
\;\;\;\;t\_2\\
\mathbf{elif}\;t\_1 \leq 2 \cdot 10^{+298}:\\
\;\;\;\;\mathsf{fma}\left(z, y, t\right)\\
\mathbf{else}:\\
\;\;\;\;t\_2\\
\end{array}
\end{array}
if (*.f64 (+.f64 (*.f64 x y) z) y) < -2e262 or 1.9999999999999999e298 < (*.f64 (+.f64 (*.f64 x y) z) y) Initial program 100.0%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f64N/A
unpow2N/A
lower-*.f6478.5
Applied rewrites78.5%
if -2e262 < (*.f64 (+.f64 (*.f64 x y) z) y) < 1.9999999999999999e298Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6487.7
Applied rewrites87.7%
Final simplification84.6%
(FPCore (x y z t) :precision binary64 (let* ((t_1 (* (+ z (* y x)) y)) (t_2 (* (* y x) y))) (if (<= t_1 -2e+262) t_2 (if (<= t_1 2e+298) (fma z y t) t_2))))
double code(double x, double y, double z, double t) {
double t_1 = (z + (y * x)) * y;
double t_2 = (y * x) * y;
double tmp;
if (t_1 <= -2e+262) {
tmp = t_2;
} else if (t_1 <= 2e+298) {
tmp = fma(z, y, t);
} else {
tmp = t_2;
}
return tmp;
}
function code(x, y, z, t) t_1 = Float64(Float64(z + Float64(y * x)) * y) t_2 = Float64(Float64(y * x) * y) tmp = 0.0 if (t_1 <= -2e+262) tmp = t_2; elseif (t_1 <= 2e+298) tmp = fma(z, y, t); else tmp = t_2; end return tmp end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[(z + N[(y * x), $MachinePrecision]), $MachinePrecision] * y), $MachinePrecision]}, Block[{t$95$2 = N[(N[(y * x), $MachinePrecision] * y), $MachinePrecision]}, If[LessEqual[t$95$1, -2e+262], t$95$2, If[LessEqual[t$95$1, 2e+298], N[(z * y + t), $MachinePrecision], t$95$2]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \left(z + y \cdot x\right) \cdot y\\
t_2 := \left(y \cdot x\right) \cdot y\\
\mathbf{if}\;t\_1 \leq -2 \cdot 10^{+262}:\\
\;\;\;\;t\_2\\
\mathbf{elif}\;t\_1 \leq 2 \cdot 10^{+298}:\\
\;\;\;\;\mathsf{fma}\left(z, y, t\right)\\
\mathbf{else}:\\
\;\;\;\;t\_2\\
\end{array}
\end{array}
if (*.f64 (+.f64 (*.f64 x y) z) y) < -2e262 or 1.9999999999999999e298 < (*.f64 (+.f64 (*.f64 x y) z) y) Initial program 100.0%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f64N/A
unpow2N/A
lower-*.f6478.5
Applied rewrites78.5%
Applied rewrites77.8%
if -2e262 < (*.f64 (+.f64 (*.f64 x y) z) y) < 1.9999999999999999e298Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6487.7
Applied rewrites87.7%
Final simplification84.4%
(FPCore (x y z t) :precision binary64 (let* ((t_1 (* (+ z (* y x)) y))) (if (<= t_1 -1e+40) (* z y) (if (<= t_1 2e+107) (* 1.0 t) (* z y)))))
double code(double x, double y, double z, double t) {
double t_1 = (z + (y * x)) * y;
double tmp;
if (t_1 <= -1e+40) {
tmp = z * y;
} else if (t_1 <= 2e+107) {
tmp = 1.0 * t;
} else {
tmp = z * 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) :: t_1
real(8) :: tmp
t_1 = (z + (y * x)) * y
if (t_1 <= (-1d+40)) then
tmp = z * y
else if (t_1 <= 2d+107) then
tmp = 1.0d0 * t
else
tmp = z * y
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double t_1 = (z + (y * x)) * y;
double tmp;
if (t_1 <= -1e+40) {
tmp = z * y;
} else if (t_1 <= 2e+107) {
tmp = 1.0 * t;
} else {
tmp = z * y;
}
return tmp;
}
def code(x, y, z, t): t_1 = (z + (y * x)) * y tmp = 0 if t_1 <= -1e+40: tmp = z * y elif t_1 <= 2e+107: tmp = 1.0 * t else: tmp = z * y return tmp
function code(x, y, z, t) t_1 = Float64(Float64(z + Float64(y * x)) * y) tmp = 0.0 if (t_1 <= -1e+40) tmp = Float64(z * y); elseif (t_1 <= 2e+107) tmp = Float64(1.0 * t); else tmp = Float64(z * y); end return tmp end
function tmp_2 = code(x, y, z, t) t_1 = (z + (y * x)) * y; tmp = 0.0; if (t_1 <= -1e+40) tmp = z * y; elseif (t_1 <= 2e+107) tmp = 1.0 * t; else tmp = z * y; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[(z + N[(y * x), $MachinePrecision]), $MachinePrecision] * y), $MachinePrecision]}, If[LessEqual[t$95$1, -1e+40], N[(z * y), $MachinePrecision], If[LessEqual[t$95$1, 2e+107], N[(1.0 * t), $MachinePrecision], N[(z * y), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \left(z + y \cdot x\right) \cdot y\\
\mathbf{if}\;t\_1 \leq -1 \cdot 10^{+40}:\\
\;\;\;\;z \cdot y\\
\mathbf{elif}\;t\_1 \leq 2 \cdot 10^{+107}:\\
\;\;\;\;1 \cdot t\\
\mathbf{else}:\\
\;\;\;\;z \cdot y\\
\end{array}
\end{array}
if (*.f64 (+.f64 (*.f64 x y) z) y) < -1.00000000000000003e40 or 1.9999999999999999e107 < (*.f64 (+.f64 (*.f64 x y) z) y) Initial program 100.0%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f6439.9
Applied rewrites39.9%
if -1.00000000000000003e40 < (*.f64 (+.f64 (*.f64 x y) z) y) < 1.9999999999999999e107Initial program 100.0%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f6417.1
Applied rewrites17.1%
Taylor expanded in t around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f6493.0
Applied rewrites93.0%
Taylor expanded in t around inf
Applied rewrites78.9%
Final simplification59.0%
(FPCore (x y z t) :precision binary64 (let* ((t_1 (* (fma x y z) y))) (if (<= y -9.5e+39) t_1 (if (<= y 2.5e+38) (fma z y t) t_1))))
double code(double x, double y, double z, double t) {
double t_1 = fma(x, y, z) * y;
double tmp;
if (y <= -9.5e+39) {
tmp = t_1;
} else if (y <= 2.5e+38) {
tmp = fma(z, y, t);
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z, t) t_1 = Float64(fma(x, y, z) * y) tmp = 0.0 if (y <= -9.5e+39) tmp = t_1; elseif (y <= 2.5e+38) tmp = fma(z, y, t); else tmp = t_1; end return tmp end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[(x * y + z), $MachinePrecision] * y), $MachinePrecision]}, If[LessEqual[y, -9.5e+39], t$95$1, If[LessEqual[y, 2.5e+38], N[(z * y + t), $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \mathsf{fma}\left(x, y, z\right) \cdot y\\
\mathbf{if}\;y \leq -9.5 \cdot 10^{+39}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;y \leq 2.5 \cdot 10^{+38}:\\
\;\;\;\;\mathsf{fma}\left(z, y, t\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if y < -9.50000000000000011e39 or 2.49999999999999985e38 < y Initial program 99.9%
Taylor expanded in t around 0
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-fma.f6496.5
Applied rewrites96.5%
if -9.50000000000000011e39 < y < 2.49999999999999985e38Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6492.6
Applied rewrites92.6%
(FPCore (x y z t) :precision binary64 (fma z y t))
double code(double x, double y, double z, double t) {
return fma(z, y, t);
}
function code(x, y, z, t) return fma(z, y, t) end
code[x_, y_, z_, t_] := N[(z * y + t), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(z, y, t\right)
\end{array}
Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6469.3
Applied rewrites69.3%
(FPCore (x y z t) :precision binary64 (* z y))
double code(double x, double y, double z, double t) {
return z * 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 = z * y
end function
public static double code(double x, double y, double z, double t) {
return z * y;
}
def code(x, y, z, t): return z * y
function code(x, y, z, t) return Float64(z * y) end
function tmp = code(x, y, z, t) tmp = z * y; end
code[x_, y_, z_, t_] := N[(z * y), $MachinePrecision]
\begin{array}{l}
\\
z \cdot y
\end{array}
Initial program 100.0%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f6428.8
Applied rewrites28.8%
herbie shell --seed 2024268
(FPCore (x y z t)
:name "Language.Haskell.HsColour.ColourHighlight:unbase from hscolour-1.23"
:precision binary64
(+ (* (+ (* x y) z) y) t))