Average Error: 28.5 → 0.1
Time: 22.5s
Precision: 64
\[\frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{y \cdot 2}\]
\[\frac{\mathsf{fma}\left(x - z, \frac{z + x}{y}, y\right) + \frac{z + x}{y} \cdot \mathsf{fma}\left(-z, 1, z\right)}{2}\]
\frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{y \cdot 2}
\frac{\mathsf{fma}\left(x - z, \frac{z + x}{y}, y\right) + \frac{z + x}{y} \cdot \mathsf{fma}\left(-z, 1, z\right)}{2}
double f(double x, double y, double z) {
        double r498388 = x;
        double r498389 = r498388 * r498388;
        double r498390 = y;
        double r498391 = r498390 * r498390;
        double r498392 = r498389 + r498391;
        double r498393 = z;
        double r498394 = r498393 * r498393;
        double r498395 = r498392 - r498394;
        double r498396 = 2.0;
        double r498397 = r498390 * r498396;
        double r498398 = r498395 / r498397;
        return r498398;
}

double f(double x, double y, double z) {
        double r498399 = x;
        double r498400 = z;
        double r498401 = r498399 - r498400;
        double r498402 = r498400 + r498399;
        double r498403 = y;
        double r498404 = r498402 / r498403;
        double r498405 = fma(r498401, r498404, r498403);
        double r498406 = -r498400;
        double r498407 = 1.0;
        double r498408 = fma(r498406, r498407, r498400);
        double r498409 = r498404 * r498408;
        double r498410 = r498405 + r498409;
        double r498411 = 2.0;
        double r498412 = r498410 / r498411;
        return r498412;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original28.5
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 28.5

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

    \[\leadsto \color{blue}{\frac{y + \frac{z + x}{y} \cdot \left(x - z\right)}{2}}\]
  3. Using strategy rm
  4. Applied *-un-lft-identity0.1

    \[\leadsto \frac{y + \frac{z + x}{y} \cdot \left(x - \color{blue}{1 \cdot z}\right)}{2}\]
  5. Applied add-sqr-sqrt31.6

    \[\leadsto \frac{y + \frac{z + x}{y} \cdot \left(\color{blue}{\sqrt{x} \cdot \sqrt{x}} - 1 \cdot z\right)}{2}\]
  6. Applied prod-diff31.6

    \[\leadsto \frac{y + \frac{z + x}{y} \cdot \color{blue}{\left(\mathsf{fma}\left(\sqrt{x}, \sqrt{x}, -z \cdot 1\right) + \mathsf{fma}\left(-z, 1, z \cdot 1\right)\right)}}{2}\]
  7. Applied distribute-lft-in31.6

    \[\leadsto \frac{y + \color{blue}{\left(\frac{z + x}{y} \cdot \mathsf{fma}\left(\sqrt{x}, \sqrt{x}, -z \cdot 1\right) + \frac{z + x}{y} \cdot \mathsf{fma}\left(-z, 1, z \cdot 1\right)\right)}}{2}\]
  8. Applied associate-+r+31.6

    \[\leadsto \frac{\color{blue}{\left(y + \frac{z + x}{y} \cdot \mathsf{fma}\left(\sqrt{x}, \sqrt{x}, -z \cdot 1\right)\right) + \frac{z + x}{y} \cdot \mathsf{fma}\left(-z, 1, z \cdot 1\right)}}{2}\]
  9. Simplified0.1

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

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

Reproduce

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