Average Error: 13.1 → 0.0
Time: 4.7s
Precision: binary64
Cost: 6784
\[\left(\left(x \cdot y - y \cdot y\right) + y \cdot y\right) - y \cdot z \]
\[\mathsf{fma}\left(x, y, z \cdot \left(-y\right)\right) \]
(FPCore (x y z)
 :precision binary64
 (- (+ (- (* x y) (* y y)) (* y y)) (* y z)))
(FPCore (x y z) :precision binary64 (fma x y (* z (- y))))
double code(double x, double y, double z) {
	return (((x * y) - (y * y)) + (y * y)) - (y * z);
}
double code(double x, double y, double z) {
	return fma(x, y, (z * -y));
}
function code(x, y, z)
	return Float64(Float64(Float64(Float64(x * y) - Float64(y * y)) + Float64(y * y)) - Float64(y * z))
end
function code(x, y, z)
	return fma(x, y, Float64(z * Float64(-y)))
end
code[x_, y_, z_] := N[(N[(N[(N[(x * y), $MachinePrecision] - N[(y * y), $MachinePrecision]), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision] - N[(y * z), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_] := N[(x * y + N[(z * (-y)), $MachinePrecision]), $MachinePrecision]
\left(\left(x \cdot y - y \cdot y\right) + y \cdot y\right) - y \cdot z
\mathsf{fma}\left(x, y, z \cdot \left(-y\right)\right)

Error

Target

Original13.1
Target0.0
Herbie0.0
\[\left(x - z\right) \cdot y \]

Derivation

  1. Initial program 13.1

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

    \[\leadsto \color{blue}{\mathsf{fma}\left(x, y, y \cdot \left(-z\right)\right)} \]
    Proof
    (fma.f64 x y (*.f64 y (neg.f64 z))): 0 points increase in error, 0 points decrease in error
    (fma.f64 x y (Rewrite<= distribute-rgt-neg-in_binary64 (neg.f64 (*.f64 y z)))): 0 points increase in error, 0 points decrease in error
    (Rewrite<= fma-neg_binary64 (-.f64 (*.f64 x y) (*.f64 y z))): 3 points increase in error, 0 points decrease in error
    (-.f64 (Rewrite<= --rgt-identity_binary64 (-.f64 (*.f64 x y) 0)) (*.f64 y z)): 0 points increase in error, 0 points decrease in error
    (-.f64 (-.f64 (*.f64 x y) (Rewrite<= +-inverses_binary64 (-.f64 (*.f64 y y) (*.f64 y y)))) (*.f64 y z)): 30 points increase in error, 0 points decrease in error
    (-.f64 (Rewrite=> associate--r-_binary64 (+.f64 (-.f64 (*.f64 x y) (*.f64 y y)) (*.f64 y y))) (*.f64 y z)): 27 points increase in error, 0 points decrease in error
  3. Final simplification0.0

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

Alternatives

Alternative 1
Error14.9
Cost520
\[\begin{array}{l} t_0 := z \cdot \left(-y\right)\\ \mathbf{if}\;z \leq -9 \cdot 10^{-7}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 52000:\\ \;\;\;\;x \cdot y\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 2
Error0.0
Cost448
\[x \cdot y - y \cdot z \]
Alternative 3
Error0.0
Cost320
\[y \cdot \left(x - z\right) \]
Alternative 4
Error29.9
Cost192
\[x \cdot y \]

Error

Reproduce

herbie shell --seed 2022331 
(FPCore (x y z)
  :name "Linear.Quaternion:$c/ from linear-1.19.1.3, D"
  :precision binary64

  :herbie-target
  (* (- x z) y)

  (- (+ (- (* x y) (* y y)) (* y y)) (* y z)))