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

Error

Target

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

Derivation

  1. Initial program 12.8

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

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

    [Start]12.8

    \[ \left(\left(x \cdot y - y \cdot y\right) + y \cdot y\right) - y \cdot z \]

    associate-+l- [=>]8.0

    \[ \color{blue}{\left(x \cdot y - \left(y \cdot y - y \cdot y\right)\right)} - y \cdot z \]

    associate--l- [=>]8.0

    \[ \color{blue}{x \cdot y - \left(\left(y \cdot y - y \cdot y\right) + y \cdot z\right)} \]

    +-inverses [=>]0.0

    \[ x \cdot y - \left(\color{blue}{0} + y \cdot z\right) \]

    +-lft-identity [=>]0.0

    \[ x \cdot y - \color{blue}{y \cdot z} \]

    *-commutative [=>]0.0

    \[ x \cdot y - \color{blue}{z \cdot y} \]

    distribute-rgt-out-- [=>]0.0

    \[ \color{blue}{y \cdot \left(x - z\right)} \]
  3. Applied egg-rr0.0

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

    \[\leadsto \color{blue}{y \cdot x - y \cdot z} \]
  5. Applied egg-rr0.0

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

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

Alternatives

Alternative 1
Error14.6
Cost521
\[\begin{array}{l} \mathbf{if}\;z \leq -2 \cdot 10^{-40} \lor \neg \left(z \leq 1.7 \cdot 10^{-32}\right):\\ \;\;\;\;y \cdot \left(-z\right)\\ \mathbf{else}:\\ \;\;\;\;y \cdot x\\ \end{array} \]
Alternative 2
Error0.0
Cost320
\[y \cdot \left(x - z\right) \]
Alternative 3
Error29.5
Cost192
\[y \cdot x \]

Error

Reproduce

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