Average Error: 17.3 → 0.0
Time: 18.1s
Precision: 64
\[\left(\left(x \cdot y - y \cdot z\right) - y \cdot y\right) + y \cdot y\]
\[\mathsf{fma}\left(y, x, \left(-y\right) \cdot z\right)\]
\left(\left(x \cdot y - y \cdot z\right) - y \cdot y\right) + y \cdot y
\mathsf{fma}\left(y, x, \left(-y\right) \cdot z\right)
double f(double x, double y, double z) {
        double r478211 = x;
        double r478212 = y;
        double r478213 = r478211 * r478212;
        double r478214 = z;
        double r478215 = r478212 * r478214;
        double r478216 = r478213 - r478215;
        double r478217 = r478212 * r478212;
        double r478218 = r478216 - r478217;
        double r478219 = r478218 + r478217;
        return r478219;
}

double f(double x, double y, double z) {
        double r478220 = y;
        double r478221 = x;
        double r478222 = -r478220;
        double r478223 = z;
        double r478224 = r478222 * r478223;
        double r478225 = fma(r478220, r478221, r478224);
        return r478225;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

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

Derivation

  1. Initial program 17.3

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

    \[\leadsto \color{blue}{y \cdot \left(x - z\right)}\]
  3. Using strategy rm
  4. Applied sub-neg0.0

    \[\leadsto y \cdot \color{blue}{\left(x + \left(-z\right)\right)}\]
  5. Applied distribute-lft-in0.0

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

    \[\leadsto y \cdot x + \color{blue}{\left(-y\right) \cdot z}\]
  7. Using strategy rm
  8. Applied fma-def0.0

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

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

Reproduce

herbie shell --seed 2019194 +o rules:numerics
(FPCore (x y z)
  :name "Linear.Quaternion:$c/ from linear-1.19.1.3, B"

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

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