
(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 (+ (* y (+ (* x y) z)) t))
double code(double x, double y, double z, double t) {
return (y * ((x * y) + z)) + 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 = (y * ((x * y) + z)) + t
end function
public static double code(double x, double y, double z, double t) {
return (y * ((x * y) + z)) + t;
}
def code(x, y, z, t): return (y * ((x * y) + z)) + t
function code(x, y, z, t) return Float64(Float64(y * Float64(Float64(x * y) + z)) + t) end
function tmp = code(x, y, z, t) tmp = (y * ((x * y) + z)) + t; end
code[x_, y_, z_, t_] := N[(N[(y * N[(N[(x * y), $MachinePrecision] + z), $MachinePrecision]), $MachinePrecision] + t), $MachinePrecision]
\begin{array}{l}
\\
y \cdot \left(x \cdot y + z\right) + t
\end{array}
Initial program 99.9%
Final simplification99.9%
(FPCore (x y z t) :precision binary64 (let* ((t_1 (* y (+ (* x y) z))) (t_2 (* y (fma y x z)))) (if (<= t_1 -2e+80) t_2 (if (<= t_1 4e+161) (fma y z t) t_2))))
double code(double x, double y, double z, double t) {
double t_1 = y * ((x * y) + z);
double t_2 = y * fma(y, x, z);
double tmp;
if (t_1 <= -2e+80) {
tmp = t_2;
} else if (t_1 <= 4e+161) {
tmp = fma(y, z, t);
} else {
tmp = t_2;
}
return tmp;
}
function code(x, y, z, t) t_1 = Float64(y * Float64(Float64(x * y) + z)) t_2 = Float64(y * fma(y, x, z)) tmp = 0.0 if (t_1 <= -2e+80) tmp = t_2; elseif (t_1 <= 4e+161) tmp = fma(y, z, t); else tmp = t_2; end return tmp end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(y * N[(N[(x * y), $MachinePrecision] + z), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(y * N[(y * x + z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, -2e+80], t$95$2, If[LessEqual[t$95$1, 4e+161], N[(y * z + t), $MachinePrecision], t$95$2]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := y \cdot \left(x \cdot y + z\right)\\
t_2 := y \cdot \mathsf{fma}\left(y, x, z\right)\\
\mathbf{if}\;t\_1 \leq -2 \cdot 10^{+80}:\\
\;\;\;\;t\_2\\
\mathbf{elif}\;t\_1 \leq 4 \cdot 10^{+161}:\\
\;\;\;\;\mathsf{fma}\left(y, z, t\right)\\
\mathbf{else}:\\
\;\;\;\;t\_2\\
\end{array}
\end{array}
if (*.f64 (+.f64 (*.f64 x y) z) y) < -2e80 or 4.0000000000000002e161 < (*.f64 (+.f64 (*.f64 x y) z) y) Initial program 99.9%
Taylor expanded in y around inf
Simplified94.3%
if -2e80 < (*.f64 (+.f64 (*.f64 x y) z) y) < 4.0000000000000002e161Initial program 99.9%
Taylor expanded in x around 0
+-commutativeN/A
accelerator-lowering-fma.f6488.8
Simplified88.8%
Final simplification91.5%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (* y (+ (* x y) z))))
(if (<= t_1 -1e+222)
(* y (* x y))
(if (<= t_1 2e+177) (fma y z t) (* x (* y y))))))
double code(double x, double y, double z, double t) {
double t_1 = y * ((x * y) + z);
double tmp;
if (t_1 <= -1e+222) {
tmp = y * (x * y);
} else if (t_1 <= 2e+177) {
tmp = fma(y, z, t);
} else {
tmp = x * (y * y);
}
return tmp;
}
function code(x, y, z, t) t_1 = Float64(y * Float64(Float64(x * y) + z)) tmp = 0.0 if (t_1 <= -1e+222) tmp = Float64(y * Float64(x * y)); elseif (t_1 <= 2e+177) tmp = fma(y, z, t); else tmp = Float64(x * Float64(y * y)); end return tmp end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(y * N[(N[(x * y), $MachinePrecision] + z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, -1e+222], N[(y * N[(x * y), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 2e+177], N[(y * z + t), $MachinePrecision], N[(x * N[(y * y), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := y \cdot \left(x \cdot y + z\right)\\
\mathbf{if}\;t\_1 \leq -1 \cdot 10^{+222}:\\
\;\;\;\;y \cdot \left(x \cdot y\right)\\
\mathbf{elif}\;t\_1 \leq 2 \cdot 10^{+177}:\\
\;\;\;\;\mathsf{fma}\left(y, z, t\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(y \cdot y\right)\\
\end{array}
\end{array}
if (*.f64 (+.f64 (*.f64 x y) z) y) < -1e222Initial program 99.8%
Taylor expanded in x around inf
unpow2N/A
associate-*r*N/A
*-commutativeN/A
*-lowering-*.f64N/A
*-commutativeN/A
*-lowering-*.f6475.4
Simplified75.4%
if -1e222 < (*.f64 (+.f64 (*.f64 x y) z) y) < 2e177Initial program 99.9%
Taylor expanded in x around 0
+-commutativeN/A
accelerator-lowering-fma.f6486.1
Simplified86.1%
if 2e177 < (*.f64 (+.f64 (*.f64 x y) z) y) Initial program 99.9%
*-commutativeN/A
flip-+N/A
clear-numN/A
un-div-invN/A
/-lowering-/.f64N/A
clear-numN/A
flip-+N/A
/-lowering-/.f64N/A
accelerator-lowering-fma.f6499.8
Applied egg-rr99.8%
Taylor expanded in y around inf
*-lowering-*.f64N/A
unpow2N/A
*-lowering-*.f6479.2
Simplified79.2%
Final simplification82.7%
(FPCore (x y z t) :precision binary64 (let* ((t_1 (* y (+ (* x y) z))) (t_2 (* x (* y y)))) (if (<= t_1 -1e+222) t_2 (if (<= t_1 2e+177) (fma y z t) t_2))))
double code(double x, double y, double z, double t) {
double t_1 = y * ((x * y) + z);
double t_2 = x * (y * y);
double tmp;
if (t_1 <= -1e+222) {
tmp = t_2;
} else if (t_1 <= 2e+177) {
tmp = fma(y, z, t);
} else {
tmp = t_2;
}
return tmp;
}
function code(x, y, z, t) t_1 = Float64(y * Float64(Float64(x * y) + z)) t_2 = Float64(x * Float64(y * y)) tmp = 0.0 if (t_1 <= -1e+222) tmp = t_2; elseif (t_1 <= 2e+177) tmp = fma(y, z, t); else tmp = t_2; end return tmp end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(y * N[(N[(x * y), $MachinePrecision] + z), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(x * N[(y * y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, -1e+222], t$95$2, If[LessEqual[t$95$1, 2e+177], N[(y * z + t), $MachinePrecision], t$95$2]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := y \cdot \left(x \cdot y + z\right)\\
t_2 := x \cdot \left(y \cdot y\right)\\
\mathbf{if}\;t\_1 \leq -1 \cdot 10^{+222}:\\
\;\;\;\;t\_2\\
\mathbf{elif}\;t\_1 \leq 2 \cdot 10^{+177}:\\
\;\;\;\;\mathsf{fma}\left(y, z, t\right)\\
\mathbf{else}:\\
\;\;\;\;t\_2\\
\end{array}
\end{array}
if (*.f64 (+.f64 (*.f64 x y) z) y) < -1e222 or 2e177 < (*.f64 (+.f64 (*.f64 x y) z) y) Initial program 99.9%
*-commutativeN/A
flip-+N/A
clear-numN/A
un-div-invN/A
/-lowering-/.f64N/A
clear-numN/A
flip-+N/A
/-lowering-/.f64N/A
accelerator-lowering-fma.f6499.8
Applied egg-rr99.8%
Taylor expanded in y around inf
*-lowering-*.f64N/A
unpow2N/A
*-lowering-*.f6475.0
Simplified75.0%
if -1e222 < (*.f64 (+.f64 (*.f64 x y) z) y) < 2e177Initial program 99.9%
Taylor expanded in x around 0
+-commutativeN/A
accelerator-lowering-fma.f6486.1
Simplified86.1%
Final simplification81.8%
(FPCore (x y z t) :precision binary64 (let* ((t_1 (* y (+ (* x y) z)))) (if (<= t_1 -0.01) (* y z) (if (<= t_1 1e+42) t (* y z)))))
double code(double x, double y, double z, double t) {
double t_1 = y * ((x * y) + z);
double tmp;
if (t_1 <= -0.01) {
tmp = y * z;
} else if (t_1 <= 1e+42) {
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) :: t_1
real(8) :: tmp
t_1 = y * ((x * y) + z)
if (t_1 <= (-0.01d0)) then
tmp = y * z
else if (t_1 <= 1d+42) 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 t_1 = y * ((x * y) + z);
double tmp;
if (t_1 <= -0.01) {
tmp = y * z;
} else if (t_1 <= 1e+42) {
tmp = t;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z, t): t_1 = y * ((x * y) + z) tmp = 0 if t_1 <= -0.01: tmp = y * z elif t_1 <= 1e+42: tmp = t else: tmp = y * z return tmp
function code(x, y, z, t) t_1 = Float64(y * Float64(Float64(x * y) + z)) tmp = 0.0 if (t_1 <= -0.01) tmp = Float64(y * z); elseif (t_1 <= 1e+42) tmp = t; else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z, t) t_1 = y * ((x * y) + z); tmp = 0.0; if (t_1 <= -0.01) tmp = y * z; elseif (t_1 <= 1e+42) tmp = t; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(y * N[(N[(x * y), $MachinePrecision] + z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, -0.01], N[(y * z), $MachinePrecision], If[LessEqual[t$95$1, 1e+42], t, N[(y * z), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := y \cdot \left(x \cdot y + z\right)\\
\mathbf{if}\;t\_1 \leq -0.01:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;t\_1 \leq 10^{+42}:\\
\;\;\;\;t\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if (*.f64 (+.f64 (*.f64 x y) z) y) < -0.0100000000000000002 or 1.00000000000000004e42 < (*.f64 (+.f64 (*.f64 x y) z) y) Initial program 99.9%
Taylor expanded in z around inf
*-lowering-*.f6438.5
Simplified38.5%
if -0.0100000000000000002 < (*.f64 (+.f64 (*.f64 x y) z) y) < 1.00000000000000004e42Initial program 99.9%
Taylor expanded in y around 0
Simplified77.5%
Final simplification53.6%
(FPCore (x y z t) :precision binary64 (fma y z t))
double code(double x, double y, double z, double t) {
return fma(y, z, t);
}
function code(x, y, z, t) return fma(y, z, t) end
code[x_, y_, z_, t_] := N[(y * z + t), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y, z, t\right)
\end{array}
Initial program 99.9%
Taylor expanded in x around 0
+-commutativeN/A
accelerator-lowering-fma.f6464.3
Simplified64.3%
(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
Simplified36.7%
herbie shell --seed 2024205
(FPCore (x y z t)
:name "Language.Haskell.HsColour.ColourHighlight:unbase from hscolour-1.23"
:precision binary64
(+ (* (+ (* x y) z) y) t))