Average Error: 28.9 → 0.2
Time: 41.7s
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 r31215609 = x;
        double r31215610 = r31215609 * r31215609;
        double r31215611 = y;
        double r31215612 = r31215611 * r31215611;
        double r31215613 = r31215610 + r31215612;
        double r31215614 = z;
        double r31215615 = r31215614 * r31215614;
        double r31215616 = r31215613 - r31215615;
        double r31215617 = 2.0;
        double r31215618 = r31215611 * r31215617;
        double r31215619 = r31215616 / r31215618;
        return r31215619;
}

double f(double x, double y, double z) {
        double r31215620 = x;
        double r31215621 = z;
        double r31215622 = r31215620 - r31215621;
        double r31215623 = y;
        double r31215624 = r31215622 / r31215623;
        double r31215625 = r31215621 + r31215620;
        double r31215626 = fma(r31215624, r31215625, r31215623);
        double r31215627 = 2.0;
        double r31215628 = r31215626 / r31215627;
        return r31215628;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

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

Derivation

  1. Initial program 28.9

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

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

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

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

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

Reproduce

herbie shell --seed 2019165 +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)))