Average Error: 12.6 → 4.9
Time: 16.3s
Precision: 64
\[\frac{x \cdot \left(y + z\right)}{z}\]
\[\mathsf{fma}\left(y \cdot x, \frac{1}{z}, x\right)\]
\frac{x \cdot \left(y + z\right)}{z}
\mathsf{fma}\left(y \cdot x, \frac{1}{z}, x\right)
double f(double x, double y, double z) {
        double r386886 = x;
        double r386887 = y;
        double r386888 = z;
        double r386889 = r386887 + r386888;
        double r386890 = r386886 * r386889;
        double r386891 = r386890 / r386888;
        return r386891;
}

double f(double x, double y, double z) {
        double r386892 = y;
        double r386893 = x;
        double r386894 = r386892 * r386893;
        double r386895 = 1.0;
        double r386896 = z;
        double r386897 = r386895 / r386896;
        double r386898 = fma(r386894, r386897, r386893);
        return r386898;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original12.6
Target2.9
Herbie4.9
\[\frac{x}{\frac{z}{y + z}}\]

Derivation

  1. Initial program 12.6

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

    \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{y}{z}, x, x\right)}\]
  3. Using strategy rm
  4. Applied fma-udef3.2

    \[\leadsto \color{blue}{\frac{y}{z} \cdot x + x}\]
  5. Simplified3.2

    \[\leadsto \color{blue}{x \cdot \frac{y}{z}} + x\]
  6. Using strategy rm
  7. Applied pow13.2

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

    \[\leadsto \color{blue}{{x}^{1}} \cdot {\left(\frac{y}{z}\right)}^{1} + x\]
  9. Applied pow-prod-down3.2

    \[\leadsto \color{blue}{{\left(x \cdot \frac{y}{z}\right)}^{1}} + x\]
  10. Simplified4.9

    \[\leadsto {\color{blue}{\left(\frac{x \cdot y}{z}\right)}}^{1} + x\]
  11. Using strategy rm
  12. Applied div-inv4.9

    \[\leadsto {\color{blue}{\left(\left(x \cdot y\right) \cdot \frac{1}{z}\right)}}^{1} + x\]
  13. Applied unpow-prod-down4.9

    \[\leadsto \color{blue}{{\left(x \cdot y\right)}^{1} \cdot {\left(\frac{1}{z}\right)}^{1}} + x\]
  14. Applied fma-def4.9

    \[\leadsto \color{blue}{\mathsf{fma}\left({\left(x \cdot y\right)}^{1}, {\left(\frac{1}{z}\right)}^{1}, x\right)}\]
  15. Final simplification4.9

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

Reproduce

herbie shell --seed 2019306 +o rules:numerics
(FPCore (x y z)
  :name "Numeric.SpecFunctions:choose from math-functions-0.1.5.2"
  :precision binary64

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

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