Average Error: 0.1 → 0.0
Time: 16.6s
Precision: binary64
Cost: 13440
\[\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 \cdot 4, z, -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 y x (fma (* z 4.0) 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 * 4.0), 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(Float64(z * 4.0), z, Float64(-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[(N[(z * 4.0), $MachinePrecision] * z + (-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(y, x, \mathsf{fma}\left(z \cdot 4, z, -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. Simplified0.1

    \[\leadsto \color{blue}{\mathsf{fma}\left(y, x, z \cdot \left(z + \left(z + z\right)\right)\right)} \]
    Proof
  3. Applied egg-rr0.1

    \[\leadsto \mathsf{fma}\left(y, x, \color{blue}{\mathsf{fma}\left(1, 4 \cdot \left(z \cdot z\right), -z \cdot z\right)}\right) \]
  4. Simplified0.0

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

Alternatives

Alternative 1
Error0.1
Cost832
\[\left(z \cdot \left(z + z\right) + x \cdot y\right) + z \cdot z \]
Alternative 2
Error11.4
Cost584
\[\begin{array}{l} t_0 := 3 \cdot \left(z \cdot z\right)\\ \mathbf{if}\;z \leq -4.6 \cdot 10^{-42}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 1.35 \cdot 10^{-74}:\\ \;\;\;\;y \cdot x\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 3
Error0.1
Cost576
\[z \cdot \left(z \cdot 3\right) + y \cdot x \]
Alternative 4
Error0.1
Cost576
\[y \cdot x - \left(z \cdot z\right) \cdot -3 \]
Alternative 5
Error24.1
Cost192
\[y \cdot x \]

Error

Reproduce

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