Average Error: 0.1 → 0.0
Time: 5.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 + z, \mathsf{fma}\left(x, y, 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 z (+ z z) (fma x y (* 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 + z), fma(x, y, (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, Float64(z + z), fma(x, y, 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 * N[(z + z), $MachinePrecision] + N[(x * y + 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(z, z + z, \mathsf{fma}\left(x, y, z \cdot z\right)\right)

Error

Target

Original0.1
Target0.1
Herbie0.0
\[\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. Applied egg-rr0.0

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

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

Alternatives

Alternative 1
Error11.2
Cost584
\[\begin{array}{l} t_0 := z \cdot \left(z \cdot 3\right)\\ \mathbf{if}\;z \leq -6.819898332061482 \cdot 10^{-21}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 7473805.325304773:\\ \;\;\;\;x \cdot y\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 2
Error11.2
Cost584
\[\begin{array}{l} \mathbf{if}\;z \leq -6.819898332061482 \cdot 10^{-21}:\\ \;\;\;\;\left(z \cdot z\right) \cdot 3\\ \mathbf{elif}\;z \leq 7473805.325304773:\\ \;\;\;\;x \cdot y\\ \mathbf{else}:\\ \;\;\;\;z \cdot \left(z \cdot 3\right)\\ \end{array} \]
Alternative 3
Error0.1
Cost576
\[z \cdot \left(z \cdot 3\right) + x \cdot y \]
Alternative 4
Error23.8
Cost192
\[x \cdot y \]

Error

Reproduce

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