?

Average Accuracy: 99.8% → 99.9%
Time: 10.5s
Precision: binary64
Cost: 13376

?

\[\left(\left(x \cdot y + z \cdot z\right) + z \cdot z\right) + z \cdot z \]
\[\mathsf{fma}\left(z, z, \mathsf{fma}\left(x, y, 2 \cdot \left(z \cdot z\right)\right)\right) \]
(FPCore (x y z)
 :precision binary64
 (+ (+ (+ (* x y) (* z z)) (* z z)) (* z z)))
(FPCore (x y z) :precision binary64 (fma z z (fma x y (* 2.0 (* z z)))))
double code(double x, double y, double z) {
	return (((x * y) + (z * z)) + (z * z)) + (z * z);
}
double code(double x, double y, double z) {
	return fma(z, z, fma(x, y, (2.0 * (z * z))));
}
function code(x, y, z)
	return Float64(Float64(Float64(Float64(x * y) + Float64(z * z)) + Float64(z * z)) + Float64(z * z))
end
function code(x, y, z)
	return fma(z, z, fma(x, y, Float64(2.0 * Float64(z * z))))
end
code[x_, y_, z_] := N[(N[(N[(N[(x * y), $MachinePrecision] + N[(z * z), $MachinePrecision]), $MachinePrecision] + N[(z * z), $MachinePrecision]), $MachinePrecision] + N[(z * z), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_] := N[(z * z + N[(x * y + N[(2.0 * N[(z * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\left(\left(x \cdot y + z \cdot z\right) + z \cdot z\right) + z \cdot z
\mathsf{fma}\left(z, z, \mathsf{fma}\left(x, y, 2 \cdot \left(z \cdot z\right)\right)\right)

Error?

Target

Original99.8%
Target99.8%
Herbie99.9%
\[\left(3 \cdot z\right) \cdot z + y \cdot x \]

Derivation?

  1. Initial program 99.8%

    \[\left(\left(x \cdot y + z \cdot z\right) + z \cdot z\right) + z \cdot z \]
  2. Simplified99.9%

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

    [Start]99.8

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

    +-commutative [=>]99.8

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

    fma-def [=>]99.9

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

    associate-+l+ [=>]99.9

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

    fma-def [=>]99.9

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

    count-2 [=>]99.9

    \[ \mathsf{fma}\left(z, z, \mathsf{fma}\left(x, y, \color{blue}{2 \cdot \left(z \cdot z\right)}\right)\right) \]
  3. Final simplification99.9%

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

Alternatives

Alternative 1
Accuracy99.8%
Cost6848
\[\mathsf{fma}\left(3, z \cdot z, x \cdot y\right) \]
Alternative 2
Accuracy99.8%
Cost6848
\[\mathsf{fma}\left(x, y, z \cdot \left(z \cdot 3\right)\right) \]
Alternative 3
Accuracy82.3%
Cost976
\[\begin{array}{l} t_0 := \left(z \cdot z\right) \cdot 3\\ t_1 := z \cdot z + x \cdot y\\ \mathbf{if}\;z \leq -4.6 \cdot 10^{-33}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 1.15 \cdot 10^{-33}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 7 \cdot 10^{-20}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 4.8 \cdot 10^{+29}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;z \cdot \left(z \cdot 3\right)\\ \end{array} \]
Alternative 4
Accuracy81.4%
Cost850
\[\begin{array}{l} \mathbf{if}\;z \leq -3.5 \cdot 10^{-36} \lor \neg \left(z \leq 8.6 \cdot 10^{-32} \lor \neg \left(z \leq 5.5 \cdot 10^{-20}\right) \land z \leq 1.8 \cdot 10^{+16}\right):\\ \;\;\;\;\left(z \cdot z\right) \cdot 3\\ \mathbf{else}:\\ \;\;\;\;x \cdot y\\ \end{array} \]
Alternative 5
Accuracy81.3%
Cost848
\[\begin{array}{l} t_0 := \left(z \cdot z\right) \cdot 3\\ \mathbf{if}\;z \leq -1.65 \cdot 10^{-33}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 1.7 \cdot 10^{-32}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;z \leq 1.5 \cdot 10^{-19}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 1.75 \cdot 10^{+16}:\\ \;\;\;\;x \cdot y\\ \mathbf{else}:\\ \;\;\;\;z \cdot \left(z \cdot 3\right)\\ \end{array} \]
Alternative 6
Accuracy99.8%
Cost576
\[x \cdot y + \left(z \cdot z\right) \cdot 3 \]
Alternative 7
Accuracy62.6%
Cost452
\[\begin{array}{l} \mathbf{if}\;z \cdot z \leq 2.9 \cdot 10^{+79}:\\ \;\;\;\;x \cdot y\\ \mathbf{else}:\\ \;\;\;\;z \cdot z\\ \end{array} \]
Alternative 8
Accuracy62.3%
Cost192
\[x \cdot y \]

Error

Reproduce?

herbie shell --seed 2023122 
(FPCore (x y z)
  :name "Linear.Quaternion:$c/ from linear-1.19.1.3, A"
  :precision binary64

  :herbie-target
  (+ (* (* 3.0 z) z) (* y x))

  (+ (+ (+ (* x y) (* z z)) (* z z)) (* z z)))