Average Error: 28.8 → 0.1
Time: 42.2s
Precision: 64
\[\frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{y \cdot 2}\]
\[\frac{\mathsf{fma}\left(\frac{x - z}{y}, z + x, y\right)}{2}\]
\frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{y \cdot 2}
\frac{\mathsf{fma}\left(\frac{x - z}{y}, z + x, y\right)}{2}
double f(double x, double y, double z) {
        double r32399682 = x;
        double r32399683 = r32399682 * r32399682;
        double r32399684 = y;
        double r32399685 = r32399684 * r32399684;
        double r32399686 = r32399683 + r32399685;
        double r32399687 = z;
        double r32399688 = r32399687 * r32399687;
        double r32399689 = r32399686 - r32399688;
        double r32399690 = 2.0;
        double r32399691 = r32399684 * r32399690;
        double r32399692 = r32399689 / r32399691;
        return r32399692;
}

double f(double x, double y, double z) {
        double r32399693 = x;
        double r32399694 = z;
        double r32399695 = r32399693 - r32399694;
        double r32399696 = y;
        double r32399697 = r32399695 / r32399696;
        double r32399698 = r32399694 + r32399693;
        double r32399699 = fma(r32399697, r32399698, r32399696);
        double r32399700 = 2.0;
        double r32399701 = r32399699 / r32399700;
        return r32399701;
}

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{\frac{x - z}{\frac{y}{z + x}} + y}{2}}\]
  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}\]
  5. Applied fma-def0.1

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

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

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)))