Average Error: 28.5 → 0.2
Time: 20.0s
Precision: 64
\[\frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{y \cdot 2}\]
\[\frac{\mathsf{fma}\left(-z, 1, z\right) \cdot \frac{x + z}{y} + \left(\left(\frac{x}{\frac{y}{x}} + y\right) - \frac{z}{\frac{y}{z}}\right)}{2}\]
\frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{y \cdot 2}
\frac{\mathsf{fma}\left(-z, 1, z\right) \cdot \frac{x + z}{y} + \left(\left(\frac{x}{\frac{y}{x}} + y\right) - \frac{z}{\frac{y}{z}}\right)}{2}
double f(double x, double y, double z) {
        double r26685811 = x;
        double r26685812 = r26685811 * r26685811;
        double r26685813 = y;
        double r26685814 = r26685813 * r26685813;
        double r26685815 = r26685812 + r26685814;
        double r26685816 = z;
        double r26685817 = r26685816 * r26685816;
        double r26685818 = r26685815 - r26685817;
        double r26685819 = 2.0;
        double r26685820 = r26685813 * r26685819;
        double r26685821 = r26685818 / r26685820;
        return r26685821;
}

double f(double x, double y, double z) {
        double r26685822 = z;
        double r26685823 = -r26685822;
        double r26685824 = 1.0;
        double r26685825 = fma(r26685823, r26685824, r26685822);
        double r26685826 = x;
        double r26685827 = r26685826 + r26685822;
        double r26685828 = y;
        double r26685829 = r26685827 / r26685828;
        double r26685830 = r26685825 * r26685829;
        double r26685831 = r26685828 / r26685826;
        double r26685832 = r26685826 / r26685831;
        double r26685833 = r26685832 + r26685828;
        double r26685834 = r26685828 / r26685822;
        double r26685835 = r26685822 / r26685834;
        double r26685836 = r26685833 - r26685835;
        double r26685837 = r26685830 + r26685836;
        double r26685838 = 2.0;
        double r26685839 = r26685837 / r26685838;
        return r26685839;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

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

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

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

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

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

    \[\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-rgt-in32.3

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

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

    \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(x - z, \frac{x + z}{y}, y\right)} + \mathsf{fma}\left(-z, 1, z \cdot 1\right) \cdot \frac{z + x}{y}}{2}\]
  10. Using strategy rm
  11. Applied div-inv0.2

    \[\leadsto \frac{\mathsf{fma}\left(x - z, \color{blue}{\left(x + z\right) \cdot \frac{1}{y}}, y\right) + \mathsf{fma}\left(-z, 1, z \cdot 1\right) \cdot \frac{z + x}{y}}{2}\]
  12. Taylor expanded around 0 12.7

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

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

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

Reproduce

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