Average Error: 28.8 → 0.1
Time: 30.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 r32713773 = x;
        double r32713774 = r32713773 * r32713773;
        double r32713775 = y;
        double r32713776 = r32713775 * r32713775;
        double r32713777 = r32713774 + r32713776;
        double r32713778 = z;
        double r32713779 = r32713778 * r32713778;
        double r32713780 = r32713777 - r32713779;
        double r32713781 = 2.0;
        double r32713782 = r32713775 * r32713781;
        double r32713783 = r32713780 / r32713782;
        return r32713783;
}

double f(double x, double y, double z) {
        double r32713784 = z;
        double r32713785 = x;
        double r32713786 = r32713784 + r32713785;
        double r32713787 = r32713785 - r32713784;
        double r32713788 = y;
        double r32713789 = r32713787 / r32713788;
        double r32713790 = fma(r32713786, r32713789, r32713788);
        double r32713791 = 2.0;
        double r32713792 = r32713790 / r32713791;
        return r32713792;
}

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