?

Average Error: 0.0 → 0.0
Time: 6.2s
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, t \cdot z\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 (* t z))))
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, (t * z)));
}
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(t * z)))
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[(t * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\left(x \cdot y + z \cdot t\right) + a \cdot b
\mathsf{fma}\left(x, y, \mathsf{fma}\left(a, b, t \cdot z\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(z, t, a \cdot b\right)\right)} \]
    Proof

    [Start]0.0

    \[ \left(x \cdot y + z \cdot t\right) + a \cdot b \]

    associate-+l+ [=>]0.0

    \[ \color{blue}{x \cdot y + \left(z \cdot t + a \cdot b\right)} \]

    fma-def [=>]0.0

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

    fma-def [=>]0.0

    \[ \mathsf{fma}\left(x, y, \color{blue}{\mathsf{fma}\left(z, t, a \cdot b\right)}\right) \]
  3. Taylor expanded in z around 0 0.0

    \[\leadsto \mathsf{fma}\left(x, y, \color{blue}{a \cdot b + t \cdot z}\right) \]
  4. Simplified0.0

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

    [Start]0.0

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

    *-commutative [=>]0.0

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

    fma-def [=>]0.0

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

    *-commutative [<=]0.0

    \[ \mathsf{fma}\left(x, y, \mathsf{fma}\left(a, b, \color{blue}{t \cdot z}\right)\right) \]
  5. Final simplification0.0

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

Alternatives

Alternative 1
Error0.0
Cost6976
\[\mathsf{fma}\left(x, y, t \cdot z\right) + a \cdot b \]
Alternative 2
Error31.9
Cost2272
\[\begin{array}{l} \mathbf{if}\;a \cdot b \leq -1.22 \cdot 10^{+123}:\\ \;\;\;\;a \cdot b\\ \mathbf{elif}\;a \cdot b \leq -580000000000:\\ \;\;\;\;t \cdot z\\ \mathbf{elif}\;a \cdot b \leq -2.5 \cdot 10^{-50}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;a \cdot b \leq -4.2 \cdot 10^{-134}:\\ \;\;\;\;t \cdot z\\ \mathbf{elif}\;a \cdot b \leq -3.2 \cdot 10^{-219}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;a \cdot b \leq 7 \cdot 10^{-111}:\\ \;\;\;\;t \cdot z\\ \mathbf{elif}\;a \cdot b \leq 1.55 \cdot 10^{+57}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;a \cdot b \leq 2.65 \cdot 10^{+97}:\\ \;\;\;\;t \cdot z\\ \mathbf{else}:\\ \;\;\;\;a \cdot b\\ \end{array} \]
Alternative 3
Error20.0
Cost1243
\[\begin{array}{l} \mathbf{if}\;y \leq -8.5 \cdot 10^{-14} \lor \neg \left(y \leq 1.5 \cdot 10^{+29}\right) \land \left(y \leq 2.2 \cdot 10^{+34} \lor \neg \left(y \leq 1.4 \cdot 10^{+90}\right) \land \left(y \leq 1.04 \cdot 10^{+105} \lor \neg \left(y \leq 2.3 \cdot 10^{+173}\right)\right)\right):\\ \;\;\;\;x \cdot y\\ \mathbf{else}:\\ \;\;\;\;t \cdot z + a \cdot b\\ \end{array} \]
Alternative 4
Error16.4
Cost1240
\[\begin{array}{l} t_1 := t \cdot z + a \cdot b\\ t_2 := a \cdot b + x \cdot y\\ \mathbf{if}\;y \leq -1.06 \cdot 10^{-165}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq 1.52 \cdot 10^{+29}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 2.2 \cdot 10^{+34}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;y \leq 3.2 \cdot 10^{+93}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 1.6 \cdot 10^{+105}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;y \leq 6 \cdot 10^{+161}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 5
Error9.6
Cost969
\[\begin{array}{l} \mathbf{if}\;a \cdot b \leq -4.3 \cdot 10^{+61} \lor \neg \left(a \cdot b \leq 5.3 \cdot 10^{+43}\right):\\ \;\;\;\;t \cdot z + a \cdot b\\ \mathbf{else}:\\ \;\;\;\;t \cdot z + x \cdot y\\ \end{array} \]
Alternative 6
Error31.6
Cost712
\[\begin{array}{l} \mathbf{if}\;a \cdot b \leq -1.3 \cdot 10^{+122}:\\ \;\;\;\;a \cdot b\\ \mathbf{elif}\;a \cdot b \leq 8.5 \cdot 10^{+98}:\\ \;\;\;\;t \cdot z\\ \mathbf{else}:\\ \;\;\;\;a \cdot b\\ \end{array} \]
Alternative 7
Error0.0
Cost704
\[a \cdot b + \left(t \cdot z + x \cdot y\right) \]
Alternative 8
Error41.6
Cost192
\[a \cdot b \]

Error

Reproduce?

herbie shell --seed 2023055 
(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)))