Average Error: 25.9 → 0.2
Time: 18.8s
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 r27472348 = x;
        double r27472349 = r27472348 * r27472348;
        double r27472350 = y;
        double r27472351 = r27472350 * r27472350;
        double r27472352 = r27472349 + r27472351;
        double r27472353 = z;
        double r27472354 = r27472353 * r27472353;
        double r27472355 = r27472352 - r27472354;
        double r27472356 = 2.0;
        double r27472357 = r27472350 * r27472356;
        double r27472358 = r27472355 / r27472357;
        return r27472358;
}

double f(double x, double y, double z) {
        double r27472359 = x;
        double r27472360 = z;
        double r27472361 = r27472359 - r27472360;
        double r27472362 = y;
        double r27472363 = r27472361 / r27472362;
        double r27472364 = r27472360 + r27472359;
        double r27472365 = fma(r27472363, r27472364, r27472362);
        double r27472366 = 2.0;
        double r27472367 = r27472365 / r27472366;
        return r27472367;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original25.9
Target0.2
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 25.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 2019158 +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)))