?

Average Error: 0.1 → 0.1
Time: 9.4s
Precision: binary64
Cost: 6848

?

\[\left(\left(x \cdot y + z \cdot z\right) + z \cdot z\right) + z \cdot z \]
\[\mathsf{fma}\left(x, y, 3 \cdot \left(z \cdot z\right)\right) \]
(FPCore (x y z)
 :precision binary64
 (+ (+ (+ (* x y) (* z z)) (* z z)) (* z z)))
(FPCore (x y z) :precision binary64 (fma x y (* 3.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(x, y, (3.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(x, y, Float64(3.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[(x * y + N[(3.0 * N[(z * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\left(\left(x \cdot y + z \cdot z\right) + z \cdot z\right) + z \cdot z
\mathsf{fma}\left(x, y, 3 \cdot \left(z \cdot z\right)\right)

Error?

Target

Original0.1
Target0.1
Herbie0.1
\[\left(3 \cdot z\right) \cdot z + y \cdot x \]

Derivation?

  1. Initial program 0.1

    \[\left(\left(x \cdot y + z \cdot z\right) + z \cdot z\right) + z \cdot z \]
  2. Simplified0.1

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

    [Start]0.1

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

    associate-+l+ [=>]0.1

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

    associate-+l+ [=>]0.1

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

    fma-def [=>]0.1

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

    count-2 [=>]0.1

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

    distribute-rgt1-in [=>]0.1

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

    metadata-eval [=>]0.1

    \[ \mathsf{fma}\left(x, y, \color{blue}{3} \cdot \left(z \cdot z\right)\right) \]
  3. Final simplification0.1

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

Alternatives

Alternative 1
Error10.6
Cost712
\[\begin{array}{l} \mathbf{if}\;z \leq -6400000:\\ \;\;\;\;3 \cdot \left(z \cdot z\right)\\ \mathbf{elif}\;z \leq 2.9 \cdot 10^{-61}:\\ \;\;\;\;z \cdot z + x \cdot y\\ \mathbf{else}:\\ \;\;\;\;z \cdot \left(3 \cdot z\right)\\ \end{array} \]
Alternative 2
Error11.3
Cost585
\[\begin{array}{l} \mathbf{if}\;z \leq -4500000 \lor \neg \left(z \leq 2.9 \cdot 10^{-61}\right):\\ \;\;\;\;3 \cdot \left(z \cdot z\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot y\\ \end{array} \]
Alternative 3
Error11.3
Cost584
\[\begin{array}{l} \mathbf{if}\;z \leq -2050000:\\ \;\;\;\;3 \cdot \left(z \cdot z\right)\\ \mathbf{elif}\;z \leq 2.9 \cdot 10^{-61}:\\ \;\;\;\;x \cdot y\\ \mathbf{else}:\\ \;\;\;\;z \cdot \left(3 \cdot z\right)\\ \end{array} \]
Alternative 4
Error0.1
Cost576
\[3 \cdot \left(z \cdot z\right) + x \cdot y \]
Alternative 5
Error23.3
Cost452
\[\begin{array}{l} \mathbf{if}\;z \cdot z \leq 5.5 \cdot 10^{+166}:\\ \;\;\;\;x \cdot y\\ \mathbf{else}:\\ \;\;\;\;z \cdot z\\ \end{array} \]
Alternative 6
Error24.0
Cost192
\[x \cdot y \]

Error

Reproduce?

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