Average Error: 28.8 → 0.1
Time: 46.0s
Precision: 64
\[\frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{y \cdot 2}\]
\[\frac{\mathsf{fma}\left(z + x, \frac{x - z}{y}, y\right)}{2}\]
\frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{y \cdot 2}
\frac{\mathsf{fma}\left(z + x, \frac{x - z}{y}, y\right)}{2}
double f(double x, double y, double z) {
        double r31004938 = x;
        double r31004939 = r31004938 * r31004938;
        double r31004940 = y;
        double r31004941 = r31004940 * r31004940;
        double r31004942 = r31004939 + r31004941;
        double r31004943 = z;
        double r31004944 = r31004943 * r31004943;
        double r31004945 = r31004942 - r31004944;
        double r31004946 = 2.0;
        double r31004947 = r31004940 * r31004946;
        double r31004948 = r31004945 / r31004947;
        return r31004948;
}

double f(double x, double y, double z) {
        double r31004949 = z;
        double r31004950 = x;
        double r31004951 = r31004949 + r31004950;
        double r31004952 = r31004950 - r31004949;
        double r31004953 = y;
        double r31004954 = r31004952 / r31004953;
        double r31004955 = fma(r31004951, r31004954, r31004953);
        double r31004956 = 2.0;
        double r31004957 = r31004955 / r31004956;
        return r31004957;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original28.8
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.8

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

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

    \[\leadsto \frac{y + \color{blue}{1 \cdot \frac{x - z}{\frac{y}{z + x}}}}{2}\]
  5. Applied *-un-lft-identity0.1

    \[\leadsto \frac{\color{blue}{1 \cdot y} + 1 \cdot \frac{x - z}{\frac{y}{z + x}}}{2}\]
  6. Applied distribute-lft-out0.1

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

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

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

Reproduce

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