
(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)))) (if (<= t_1 -5e+53) (* y z) (if (<= t_1 2e-83) 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 <= -5e+53) {
tmp = y * z;
} else if (t_1 <= 2e-83) {
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 <= (-5d+53)) then
tmp = y * z
else if (t_1 <= 2d-83) 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 <= -5e+53) {
tmp = y * z;
} else if (t_1 <= 2e-83) {
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 <= -5e+53: tmp = y * z elif t_1 <= 2e-83: 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 <= -5e+53) tmp = Float64(y * z); elseif (t_1 <= 2e-83) 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 <= -5e+53) tmp = y * z; elseif (t_1 <= 2e-83) 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, -5e+53], N[(y * z), $MachinePrecision], If[LessEqual[t$95$1, 2e-83], 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 -5 \cdot 10^{+53}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;t\_1 \leq 2 \cdot 10^{-83}:\\
\;\;\;\;t\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if (*.f64 (+.f64 (*.f64 x y) z) y) < -5.0000000000000004e53 or 2.0000000000000001e-83 < (*.f64 (+.f64 (*.f64 x y) z) y) Initial program 99.9%
Taylor expanded in z around inf
*-lowering-*.f6440.5
Simplified40.5%
if -5.0000000000000004e53 < (*.f64 (+.f64 (*.f64 x y) z) y) < 2.0000000000000001e-83Initial program 99.9%
Taylor expanded in y around 0
Simplified80.3%
Final simplification54.0%
(FPCore (x y z t) :precision binary64 (if (<= y -45000000000000.0) (* y (fma y x z)) (if (<= y 4.5e-72) (fma y z t) (* y (+ (* x y) z)))))
double code(double x, double y, double z, double t) {
double tmp;
if (y <= -45000000000000.0) {
tmp = y * fma(y, x, z);
} else if (y <= 4.5e-72) {
tmp = fma(y, z, t);
} else {
tmp = y * ((x * y) + z);
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (y <= -45000000000000.0) tmp = Float64(y * fma(y, x, z)); elseif (y <= 4.5e-72) tmp = fma(y, z, t); else tmp = Float64(y * Float64(Float64(x * y) + z)); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[y, -45000000000000.0], N[(y * N[(y * x + z), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 4.5e-72], N[(y * z + t), $MachinePrecision], N[(y * N[(N[(x * y), $MachinePrecision] + z), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -45000000000000:\\
\;\;\;\;y \cdot \mathsf{fma}\left(y, x, z\right)\\
\mathbf{elif}\;y \leq 4.5 \cdot 10^{-72}:\\
\;\;\;\;\mathsf{fma}\left(y, z, t\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(x \cdot y + z\right)\\
\end{array}
\end{array}
if y < -4.5e13Initial program 99.8%
Taylor expanded in y around inf
Simplified97.2%
if -4.5e13 < y < 4.5e-72Initial program 99.9%
Taylor expanded in x around 0
+-commutativeN/A
accelerator-lowering-fma.f6495.9
Simplified95.9%
if 4.5e-72 < y Initial program 99.9%
Taylor expanded in y around inf
Simplified84.8%
*-commutativeN/A
+-lowering-+.f64N/A
*-commutativeN/A
*-lowering-*.f6484.8
Applied egg-rr84.8%
Final simplification93.1%
(FPCore (x y z t) :precision binary64 (let* ((t_1 (* y (fma y x z)))) (if (<= y -15500000000.0) t_1 (if (<= y 4.5e-72) (fma y z t) t_1))))
double code(double x, double y, double z, double t) {
double t_1 = y * fma(y, x, z);
double tmp;
if (y <= -15500000000.0) {
tmp = t_1;
} else if (y <= 4.5e-72) {
tmp = fma(y, z, t);
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z, t) t_1 = Float64(y * fma(y, x, z)) tmp = 0.0 if (y <= -15500000000.0) tmp = t_1; elseif (y <= 4.5e-72) tmp = fma(y, z, t); else tmp = t_1; end return tmp end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(y * N[(y * x + z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -15500000000.0], t$95$1, If[LessEqual[y, 4.5e-72], N[(y * z + t), $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := y \cdot \mathsf{fma}\left(y, x, z\right)\\
\mathbf{if}\;y \leq -15500000000:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;y \leq 4.5 \cdot 10^{-72}:\\
\;\;\;\;\mathsf{fma}\left(y, z, t\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if y < -1.55e10 or 4.5e-72 < y Initial program 99.9%
Taylor expanded in y around inf
Simplified90.6%
if -1.55e10 < y < 4.5e-72Initial program 99.9%
Taylor expanded in x around 0
+-commutativeN/A
accelerator-lowering-fma.f6495.9
Simplified95.9%
(FPCore (x y z t) :precision binary64 (let* ((t_1 (* x (* y y)))) (if (<= y -2.7e+21) t_1 (if (<= y 8.8e+173) (fma y z t) t_1))))
double code(double x, double y, double z, double t) {
double t_1 = x * (y * y);
double tmp;
if (y <= -2.7e+21) {
tmp = t_1;
} else if (y <= 8.8e+173) {
tmp = fma(y, z, t);
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z, t) t_1 = Float64(x * Float64(y * y)) tmp = 0.0 if (y <= -2.7e+21) tmp = t_1; elseif (y <= 8.8e+173) tmp = fma(y, z, t); else tmp = t_1; end return tmp end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(x * N[(y * y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -2.7e+21], t$95$1, If[LessEqual[y, 8.8e+173], N[(y * z + t), $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := x \cdot \left(y \cdot y\right)\\
\mathbf{if}\;y \leq -2.7 \cdot 10^{+21}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;y \leq 8.8 \cdot 10^{+173}:\\
\;\;\;\;\mathsf{fma}\left(y, z, t\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if y < -2.7e21 or 8.7999999999999999e173 < y Initial program 99.9%
*-commutativeN/A
+-commutativeN/A
distribute-lft-inN/A
associate-+l+N/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
*-commutativeN/A
associate-*l*N/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f6487.0
Applied egg-rr87.0%
Taylor expanded in y around inf
*-lowering-*.f64N/A
unpow2N/A
*-lowering-*.f6477.6
Simplified77.6%
if -2.7e21 < y < 8.7999999999999999e173Initial program 99.9%
Taylor expanded in x around 0
+-commutativeN/A
accelerator-lowering-fma.f6485.0
Simplified85.0%
(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.f6465.9
Simplified65.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
Simplified35.6%
herbie shell --seed 2024199
(FPCore (x y z t)
:name "Language.Haskell.HsColour.ColourHighlight:unbase from hscolour-1.23"
:precision binary64
(+ (* (+ (* x y) z) y) t))