Average Error: 0.1 → 0.0
Time: 7.2s
Precision: binary64
Cost: 13376
\[\left(\left(x \cdot y + z \cdot z\right) + z \cdot z\right) + z \cdot z \]
\[\mathsf{fma}\left(y, x, \mathsf{fma}\left(z, z, 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 y x (fma z z (* 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(y, x, fma(z, z, (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(y, x, fma(z, z, 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[(y * x + N[(z * z + 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(y, x, \mathsf{fma}\left(z, z, z \cdot \left(z + z\right)\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(y, x, \mathsf{fma}\left(z, z, z \cdot \left(z + z\right)\right)\right)} \]
  3. Final simplification0.0

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

Alternatives

Alternative 1
Error0.1
Cost7104
\[\mathsf{fma}\left(z, z, z \cdot \left(z + z\right) + y \cdot x\right) \]
Alternative 2
Error12.8
Cost976
\[\begin{array}{l} t_0 := \left(z \cdot z\right) \cdot 3\\ t_1 := z \cdot z + y \cdot x\\ \mathbf{if}\;z \leq -27689.12722169995:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -1.487393591883637 \cdot 10^{-57}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -1.0093204801178489 \cdot 10^{-117}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 9.92149702785056 \cdot 10^{+50}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 3
Error13.4
Cost848
\[\begin{array}{l} t_0 := \left(z \cdot z\right) \cdot 3\\ \mathbf{if}\;z \leq -27689.12722169995:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -1.487393591883637 \cdot 10^{-57}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;z \leq -1.0093204801178489 \cdot 10^{-117}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 6.206492760354703 \cdot 10^{+28}:\\ \;\;\;\;y \cdot x\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 4
Error0.1
Cost832
\[\left(z \cdot \left(z + z\right) + y \cdot x\right) + z \cdot z \]
Alternative 5
Error0.1
Cost576
\[z \cdot \left(z \cdot 3\right) + y \cdot x \]
Alternative 6
Error23.4
Cost324
\[\begin{array}{l} \mathbf{if}\;z \leq 9.92149702785056 \cdot 10^{+50}:\\ \;\;\;\;y \cdot x\\ \mathbf{else}:\\ \;\;\;\;z \cdot z\\ \end{array} \]
Alternative 7
Error55.5
Cost192
\[z \cdot z \]

Error

Reproduce

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