
(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 (+ 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 99.9%
Final simplification99.9%
(FPCore (x y z t) :precision binary64 (let* ((t_1 (* (+ z (* y x)) y)) (t_2 (* (fma x y z) y))) (if (<= t_1 -5e+135) t_2 (if (<= t_1 2e+235) (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 = fma(x, y, z) * y;
double tmp;
if (t_1 <= -5e+135) {
tmp = t_2;
} else if (t_1 <= 2e+235) {
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(fma(x, y, z) * y) tmp = 0.0 if (t_1 <= -5e+135) tmp = t_2; elseif (t_1 <= 2e+235) 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[(x * y + z), $MachinePrecision] * y), $MachinePrecision]}, If[LessEqual[t$95$1, -5e+135], t$95$2, If[LessEqual[t$95$1, 2e+235], 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 := \mathsf{fma}\left(x, y, z\right) \cdot y\\
\mathbf{if}\;t\_1 \leq -5 \cdot 10^{+135}:\\
\;\;\;\;t\_2\\
\mathbf{elif}\;t\_1 \leq 2 \cdot 10^{+235}:\\
\;\;\;\;\mathsf{fma}\left(z, y, t\right)\\
\mathbf{else}:\\
\;\;\;\;t\_2\\
\end{array}
\end{array}
if (*.f64 (+.f64 (*.f64 x y) z) y) < -5.00000000000000029e135 or 2.0000000000000001e235 < (*.f64 (+.f64 (*.f64 x y) z) y) Initial program 99.9%
Taylor expanded in y around inf
Applied rewrites95.9%
if -5.00000000000000029e135 < (*.f64 (+.f64 (*.f64 x y) z) y) < 2.0000000000000001e235Initial program 99.9%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6485.4
Applied rewrites85.4%
Final simplification89.9%
herbie shell --seed 2024230
(FPCore (x y z t)
:name "Language.Haskell.HsColour.ColourHighlight:unbase from hscolour-1.23"
:precision binary64
(+ (* (+ (* x y) z) y) t))