Average Error: 0.0 → 0.0
Time: 5.6s
Precision: binary64
Cost: 13248
\[\left(x \cdot y + z \cdot t\right) + a \cdot b \]
\[\mathsf{fma}\left(x, y, \mathsf{fma}\left(a, b, z \cdot t\right)\right) \]
(FPCore (x y z t a b) :precision binary64 (+ (+ (* x y) (* z t)) (* a b)))
(FPCore (x y z t a b) :precision binary64 (fma x y (fma a b (* z t))))
double code(double x, double y, double z, double t, double a, double b) {
	return ((x * y) + (z * t)) + (a * b);
}
double code(double x, double y, double z, double t, double a, double b) {
	return fma(x, y, fma(a, b, (z * t)));
}
function code(x, y, z, t, a, b)
	return Float64(Float64(Float64(x * y) + Float64(z * t)) + Float64(a * b))
end
function code(x, y, z, t, a, b)
	return fma(x, y, fma(a, b, Float64(z * t)))
end
code[x_, y_, z_, t_, a_, b_] := N[(N[(N[(x * y), $MachinePrecision] + N[(z * t), $MachinePrecision]), $MachinePrecision] + N[(a * b), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_, a_, b_] := N[(x * y + N[(a * b + N[(z * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\left(x \cdot y + z \cdot t\right) + a \cdot b
\mathsf{fma}\left(x, y, \mathsf{fma}\left(a, b, z \cdot t\right)\right)

Error

Derivation

  1. Initial program 0.0

    \[\left(x \cdot y + z \cdot t\right) + a \cdot b \]
  2. Simplified0.0

    \[\leadsto \color{blue}{\mathsf{fma}\left(x, y, \mathsf{fma}\left(a, b, z \cdot t\right)\right)} \]
    Proof
    (fma.f64 x y (fma.f64 a b (*.f64 z t))): 0 points increase in error, 0 points decrease in error
    (fma.f64 x y (Rewrite<= fma-def_binary64 (+.f64 (*.f64 a b) (*.f64 z t)))): 3 points increase in error, 0 points decrease in error
    (fma.f64 x y (Rewrite<= +-commutative_binary64 (+.f64 (*.f64 z t) (*.f64 a b)))): 0 points increase in error, 0 points decrease in error
    (Rewrite<= fma-def_binary64 (+.f64 (*.f64 x y) (+.f64 (*.f64 z t) (*.f64 a b)))): 1 points increase in error, 0 points decrease in error
    (Rewrite<= associate-+l+_binary64 (+.f64 (+.f64 (*.f64 x y) (*.f64 z t)) (*.f64 a b))): 0 points increase in error, 0 points decrease in error
  3. Final simplification0.0

    \[\leadsto \mathsf{fma}\left(x, y, \mathsf{fma}\left(a, b, z \cdot t\right)\right) \]

Alternatives

Alternative 1
Error9.6
Cost1748
\[\begin{array}{l} t_1 := z \cdot t + x \cdot y\\ t_2 := a \cdot b + z \cdot t\\ \mathbf{if}\;a \cdot b \leq -6.8 \cdot 10^{+15}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;a \cdot b \leq 5.2 \cdot 10^{-88}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \cdot b \leq 8.5 \cdot 10^{-20}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;a \cdot b \leq 4.6 \cdot 10^{+21}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \cdot b \leq 4.6 \cdot 10^{+46}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;a \cdot b + x \cdot y\\ \end{array} \]
Alternative 2
Error37.5
Cost1380
\[\begin{array}{l} \mathbf{if}\;t \leq -5.8 \cdot 10^{-166}:\\ \;\;\;\;z \cdot t\\ \mathbf{elif}\;t \leq -2.5 \cdot 10^{-202}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;t \leq -4.9 \cdot 10^{-209}:\\ \;\;\;\;z \cdot t\\ \mathbf{elif}\;t \leq 7.2 \cdot 10^{-297}:\\ \;\;\;\;a \cdot b\\ \mathbf{elif}\;t \leq 3.65 \cdot 10^{-264}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;t \leq 7.8 \cdot 10^{-221}:\\ \;\;\;\;a \cdot b\\ \mathbf{elif}\;t \leq 4.5 \cdot 10^{-190}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;t \leq 2.02 \cdot 10^{+20}:\\ \;\;\;\;a \cdot b\\ \mathbf{elif}\;t \leq 4.3 \cdot 10^{+113}:\\ \;\;\;\;x \cdot y\\ \mathbf{else}:\\ \;\;\;\;z \cdot t\\ \end{array} \]
Alternative 3
Error31.0
Cost712
\[\begin{array}{l} \mathbf{if}\;a \cdot b \leq -7.8 \cdot 10^{+98}:\\ \;\;\;\;a \cdot b\\ \mathbf{elif}\;a \cdot b \leq 8.2 \cdot 10^{-83}:\\ \;\;\;\;z \cdot t\\ \mathbf{else}:\\ \;\;\;\;a \cdot b\\ \end{array} \]
Alternative 4
Error22.7
Cost712
\[\begin{array}{l} \mathbf{if}\;y \leq -5.8 \cdot 10^{-108}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;y \leq 7.8 \cdot 10^{+90}:\\ \;\;\;\;a \cdot b + z \cdot t\\ \mathbf{else}:\\ \;\;\;\;x \cdot y\\ \end{array} \]
Alternative 5
Error14.5
Cost712
\[\begin{array}{l} t_1 := a \cdot b + x \cdot y\\ \mathbf{if}\;y \leq -8.5 \cdot 10^{-113}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 3.5 \cdot 10^{-20}:\\ \;\;\;\;a \cdot b + z \cdot t\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 6
Error0.0
Cost704
\[a \cdot b + \left(z \cdot t + x \cdot y\right) \]
Alternative 7
Error41.9
Cost192
\[a \cdot b \]

Error

Reproduce

herbie shell --seed 2022332 
(FPCore (x y z t a b)
  :name "Linear.V3:$cdot from linear-1.19.1.3, B"
  :precision binary64
  (+ (+ (* x y) (* z t)) (* a b)))