Average Error: 27.0 → 0.1
Time: 21.9s
Precision: 64
\[\frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{y \cdot 2.0}\]
\[\frac{\mathsf{fma}\left(\frac{x - z}{y}, z + x, y\right)}{2.0}\]
\frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{y \cdot 2.0}
\frac{\mathsf{fma}\left(\frac{x - z}{y}, z + x, y\right)}{2.0}
double f(double x, double y, double z) {
        double r30942531 = x;
        double r30942532 = r30942531 * r30942531;
        double r30942533 = y;
        double r30942534 = r30942533 * r30942533;
        double r30942535 = r30942532 + r30942534;
        double r30942536 = z;
        double r30942537 = r30942536 * r30942536;
        double r30942538 = r30942535 - r30942537;
        double r30942539 = 2.0;
        double r30942540 = r30942533 * r30942539;
        double r30942541 = r30942538 / r30942540;
        return r30942541;
}

double f(double x, double y, double z) {
        double r30942542 = x;
        double r30942543 = z;
        double r30942544 = r30942542 - r30942543;
        double r30942545 = y;
        double r30942546 = r30942544 / r30942545;
        double r30942547 = r30942543 + r30942542;
        double r30942548 = fma(r30942546, r30942547, r30942545);
        double r30942549 = 2.0;
        double r30942550 = r30942548 / r30942549;
        return r30942550;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original27.0
Target0.2
Herbie0.1
\[y \cdot 0.5 - \left(\frac{0.5}{y} \cdot \left(z + x\right)\right) \cdot \left(z - x\right)\]

Derivation

  1. Initial program 27.0

    \[\frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{y \cdot 2.0}\]
  2. Simplified0.1

    \[\leadsto \color{blue}{\frac{\frac{x - z}{\frac{y}{z + x}} + y}{2.0}}\]
  3. Using strategy rm
  4. Applied associate-/r/0.1

    \[\leadsto \frac{\color{blue}{\frac{x - z}{y} \cdot \left(z + x\right)} + y}{2.0}\]
  5. Applied fma-def0.1

    \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(\frac{x - z}{y}, z + x, y\right)}}{2.0}\]
  6. Final simplification0.1

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

Reproduce

herbie shell --seed 2019168 +o rules:numerics
(FPCore (x y z)
  :name "Diagrams.TwoD.Apollonian:initialConfig from diagrams-contrib-1.3.0.5, A"

  :herbie-target
  (- (* y 0.5) (* (* (/ 0.5 y) (+ z x)) (- z x)))

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