Average Error: 0.1 → 0.1
Time: 5.5s
Precision: binary64
Cost: 7104
\[\left(\left(x \cdot y + z \cdot z\right) + z \cdot z\right) + z \cdot z \]
\[\mathsf{fma}\left(z \cdot 2, z, z \cdot z\right) + x \cdot y \]
(FPCore (x y z)
 :precision binary64
 (+ (+ (+ (* x y) (* z z)) (* z z)) (* z z)))
(FPCore (x y z) :precision binary64 (+ (fma (* z 2.0) z (* z z)) (* x y)))
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 * 2.0), z, (z * z)) + (x * y);
}
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 Float64(fma(Float64(z * 2.0), z, Float64(z * z)) + Float64(x * y))
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[(N[(N[(z * 2.0), $MachinePrecision] * z + N[(z * z), $MachinePrecision]), $MachinePrecision] + N[(x * y), $MachinePrecision]), $MachinePrecision]
\left(\left(x \cdot y + z \cdot z\right) + z \cdot z\right) + z \cdot z
\mathsf{fma}\left(z \cdot 2, z, z \cdot z\right) + x \cdot y

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.0

    \[\leadsto \color{blue}{\mathsf{fma}\left(z, z, \mathsf{fma}\left(x, y, 2 \cdot \left(z \cdot z\right)\right)\right)} \]
    Proof
    (fma.f64 z z (fma.f64 x y (*.f64 2 (*.f64 z z)))): 0 points increase in error, 0 points decrease in error
    (fma.f64 z z (fma.f64 x y (Rewrite<= count-2_binary64 (+.f64 (*.f64 z z) (*.f64 z z))))): 0 points increase in error, 0 points decrease in error
    (fma.f64 z z (Rewrite<= fma-def_binary64 (+.f64 (*.f64 x y) (+.f64 (*.f64 z z) (*.f64 z z))))): 0 points increase in error, 0 points decrease in error
    (fma.f64 z z (Rewrite<= associate-+l+_binary64 (+.f64 (+.f64 (*.f64 x y) (*.f64 z z)) (*.f64 z z)))): 0 points increase in error, 0 points decrease in error
    (Rewrite<= fma-def_binary64 (+.f64 (*.f64 z z) (+.f64 (+.f64 (*.f64 x y) (*.f64 z z)) (*.f64 z z)))): 6 points increase in error, 0 points decrease in error
    (Rewrite<= +-commutative_binary64 (+.f64 (+.f64 (+.f64 (*.f64 x y) (*.f64 z z)) (*.f64 z z)) (*.f64 z z))): 0 points increase in error, 6 points decrease in error
  3. Applied egg-rr0.1

    \[\leadsto \color{blue}{\left(z \cdot z + 2 \cdot \left(z \cdot z\right)\right) + x \cdot y} \]
  4. Applied egg-rr0.1

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

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

Alternatives

Alternative 1
Error11.3
Cost585
\[\begin{array}{l} \mathbf{if}\;z \leq -9.5 \cdot 10^{-16} \lor \neg \left(z \leq 0.00335\right):\\ \;\;\;\;\left(z \cdot z\right) \cdot 3\\ \mathbf{else}:\\ \;\;\;\;x \cdot y\\ \end{array} \]
Alternative 2
Error11.3
Cost584
\[\begin{array}{l} \mathbf{if}\;z \leq -9 \cdot 10^{-16}:\\ \;\;\;\;\left(z \cdot z\right) \cdot 3\\ \mathbf{elif}\;z \leq 0.0028:\\ \;\;\;\;x \cdot y\\ \mathbf{else}:\\ \;\;\;\;z \cdot \left(z \cdot 3\right)\\ \end{array} \]
Alternative 3
Error0.1
Cost576
\[x \cdot y + z \cdot \left(z \cdot 3\right) \]
Alternative 4
Error23.9
Cost192
\[x \cdot y \]

Error

Reproduce

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