?

Average Accuracy: 98.2% → 99.4%
Time: 7.7s
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, z \cdot \left(z + 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 (* z (+ 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, (z * (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(z * 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[(z * 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, z \cdot \left(z + z\right)\right)\right)

Error?

Bogosity?

Bogosity

Target

Original98.2%
Target98.2%
Herbie99.4%
\[\left(3 \cdot z\right) \cdot z + y \cdot x \]

Derivation?

  1. Initial program 99.1%

    \[\left(\left(x \cdot y + z \cdot z\right) + z \cdot z\right) + z \cdot z \]
  2. Simplified100.0%

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

    [Start]99.1

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

    +-commutative [=>]99.1

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

    fma-def [=>]99.2

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

    associate-+l+ [=>]99.2

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

    fma-def [=>]100.0

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

    distribute-lft-out [=>]100.0

    \[ \mathsf{fma}\left(z, z, \mathsf{fma}\left(x, y, \color{blue}{z \cdot \left(z + z\right)}\right)\right) \]
  3. Final simplification100.0%

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

Alternatives

Alternative 1
Accuracy99.4%
Cost6848
\[\mathsf{fma}\left(x, y, z \cdot \left(z \cdot 3\right)\right) \]
Alternative 2
Accuracy81.6%
Cost1115
\[\begin{array}{l} \mathbf{if}\;z \leq -2.05 \cdot 10^{+133} \lor \neg \left(z \leq -3.6 \cdot 10^{+49}\right) \land \left(z \leq -2.2 \cdot 10^{-18} \lor \neg \left(z \leq 5.8 \cdot 10^{-38}\right) \land \left(z \leq 2.1 \cdot 10^{-17} \lor \neg \left(z \leq 1.25 \cdot 10^{+21}\right)\right)\right):\\ \;\;\;\;3 \cdot \left(z \cdot z\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot y\\ \end{array} \]
Alternative 3
Accuracy81.7%
Cost1112
\[\begin{array}{l} t_0 := z \cdot \left(z \cdot 3\right)\\ t_1 := 3 \cdot \left(z \cdot z\right)\\ \mathbf{if}\;z \leq -2.05 \cdot 10^{+133}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -2.8 \cdot 10^{+52}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;z \leq -8 \cdot 10^{-18}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 1.4 \cdot 10^{-37}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;z \leq 5.8 \cdot 10^{-18}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 1.25 \cdot 10^{+21}:\\ \;\;\;\;x \cdot y\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 4
Accuracy98.2%
Cost960
\[z \cdot z + \left(z \cdot z + \left(z \cdot z + x \cdot y\right)\right) \]
Alternative 5
Accuracy98.2%
Cost576
\[z \cdot \left(z \cdot 3\right) + x \cdot y \]
Alternative 6
Accuracy52.5%
Cost192
\[x \cdot y \]

Error

Reproduce?

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