
(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 6 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 100.0%
Final simplification100.0%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (* y (+ (* x y) z))))
(if (<= t_1 (- INFINITY))
(* x (* y y))
(if (<= t_1 5e+178) (fma y z t) (* y (* x y))))))
double code(double x, double y, double z, double t) {
double t_1 = y * ((x * y) + z);
double tmp;
if (t_1 <= -((double) INFINITY)) {
tmp = x * (y * y);
} else if (t_1 <= 5e+178) {
tmp = fma(y, z, t);
} else {
tmp = y * (x * y);
}
return tmp;
}
function code(x, y, z, t) t_1 = Float64(y * Float64(Float64(x * y) + z)) tmp = 0.0 if (t_1 <= Float64(-Inf)) tmp = Float64(x * Float64(y * y)); elseif (t_1 <= 5e+178) tmp = fma(y, z, t); else tmp = Float64(y * Float64(x * 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, (-Infinity)], N[(x * N[(y * y), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 5e+178], N[(y * z + t), $MachinePrecision], N[(y * N[(x * y), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := y \cdot \left(x \cdot y + z\right)\\
\mathbf{if}\;t\_1 \leq -\infty:\\
\;\;\;\;x \cdot \left(y \cdot y\right)\\
\mathbf{elif}\;t\_1 \leq 5 \cdot 10^{+178}:\\
\;\;\;\;\mathsf{fma}\left(y, z, t\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(x \cdot y\right)\\
\end{array}
\end{array}
if (*.f64 (+.f64 (*.f64 x y) z) y) < -inf.0Initial program 100.0%
Taylor expanded in x around inf
unpow2N/A
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6483.1
Applied rewrites83.1%
Applied rewrites86.4%
if -inf.0 < (*.f64 (+.f64 (*.f64 x y) z) y) < 4.9999999999999999e178Initial program 99.9%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f6482.0
Applied rewrites82.0%
if 4.9999999999999999e178 < (*.f64 (+.f64 (*.f64 x y) z) y) Initial program 99.9%
Taylor expanded in x around inf
unpow2N/A
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6470.9
Applied rewrites70.9%
Final simplification80.2%
herbie shell --seed 2024228
(FPCore (x y z t)
:name "Language.Haskell.HsColour.ColourHighlight:unbase from hscolour-1.23"
:precision binary64
(+ (* (+ (* x y) z) y) t))