Average Error: 28.4 → 0.1
Time: 3.9s
Precision: 64
\[\frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{y \cdot 2}\]
\[0.5 \cdot \left(1 \cdot \mathsf{fma}\left(\frac{{x}^{1}}{y}, x, y\right) - z \cdot \frac{z}{y}\right)\]
\frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{y \cdot 2}
0.5 \cdot \left(1 \cdot \mathsf{fma}\left(\frac{{x}^{1}}{y}, x, y\right) - z \cdot \frac{z}{y}\right)
double f(double x, double y, double z) {
        double r624803 = x;
        double r624804 = r624803 * r624803;
        double r624805 = y;
        double r624806 = r624805 * r624805;
        double r624807 = r624804 + r624806;
        double r624808 = z;
        double r624809 = r624808 * r624808;
        double r624810 = r624807 - r624809;
        double r624811 = 2.0;
        double r624812 = r624805 * r624811;
        double r624813 = r624810 / r624812;
        return r624813;
}

double f(double x, double y, double z) {
        double r624814 = 0.5;
        double r624815 = 1.0;
        double r624816 = x;
        double r624817 = pow(r624816, r624815);
        double r624818 = y;
        double r624819 = r624817 / r624818;
        double r624820 = fma(r624819, r624816, r624818);
        double r624821 = r624815 * r624820;
        double r624822 = z;
        double r624823 = r624822 / r624818;
        double r624824 = r624822 * r624823;
        double r624825 = r624821 - r624824;
        double r624826 = r624814 * r624825;
        return r624826;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

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

    \[\frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{y \cdot 2}\]
  2. Taylor expanded around 0 12.2

    \[\leadsto \color{blue}{\left(0.5 \cdot y + 0.5 \cdot \frac{{x}^{2}}{y}\right) - 0.5 \cdot \frac{{z}^{2}}{y}}\]
  3. Simplified12.2

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

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

    \[\leadsto 0.5 \cdot \left(\left(y + \frac{{x}^{2}}{y}\right) - \frac{{\color{blue}{\left(\sqrt{z} \cdot \sqrt{z}\right)}}^{2}}{1 \cdot y}\right)\]
  7. Applied unpow-prod-down38.0

    \[\leadsto 0.5 \cdot \left(\left(y + \frac{{x}^{2}}{y}\right) - \frac{\color{blue}{{\left(\sqrt{z}\right)}^{2} \cdot {\left(\sqrt{z}\right)}^{2}}}{1 \cdot y}\right)\]
  8. Applied times-frac35.1

    \[\leadsto 0.5 \cdot \left(\left(y + \frac{{x}^{2}}{y}\right) - \color{blue}{\frac{{\left(\sqrt{z}\right)}^{2}}{1} \cdot \frac{{\left(\sqrt{z}\right)}^{2}}{y}}\right)\]
  9. Simplified35.1

    \[\leadsto 0.5 \cdot \left(\left(y + \frac{{x}^{2}}{y}\right) - \color{blue}{z} \cdot \frac{{\left(\sqrt{z}\right)}^{2}}{y}\right)\]
  10. Simplified6.6

    \[\leadsto 0.5 \cdot \left(\left(y + \frac{{x}^{2}}{y}\right) - z \cdot \color{blue}{\frac{z}{y}}\right)\]
  11. Using strategy rm
  12. Applied sqr-pow6.6

    \[\leadsto 0.5 \cdot \left(\left(y + \frac{\color{blue}{{x}^{\left(\frac{2}{2}\right)} \cdot {x}^{\left(\frac{2}{2}\right)}}}{y}\right) - z \cdot \frac{z}{y}\right)\]
  13. Applied associate-/l*0.1

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

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

    \[\leadsto 0.5 \cdot \left(\left(y + \color{blue}{1 \cdot \frac{{x}^{\left(\frac{2}{2}\right)}}{\frac{y}{x}}}\right) - z \cdot \frac{z}{y}\right)\]
  17. Applied *-un-lft-identity0.1

    \[\leadsto 0.5 \cdot \left(\left(\color{blue}{1 \cdot y} + 1 \cdot \frac{{x}^{\left(\frac{2}{2}\right)}}{\frac{y}{x}}\right) - z \cdot \frac{z}{y}\right)\]
  18. Applied distribute-lft-out0.1

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

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

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

Reproduce

herbie shell --seed 2020064 +o rules:numerics
(FPCore (x y z)
  :name "Diagrams.TwoD.Apollonian:initialConfig from diagrams-contrib-1.3.0.5, A"
  :precision binary64

  :herbie-target
  (- (* y 0.5) (* (* (/ 0.5 y) (+ z x)) (- z x)))

  (/ (- (+ (* x x) (* y y)) (* z z)) (* y 2)))