Average Error: 11.6 → 3.4
Time: 14.3s
Precision: 64
\[\frac{x \cdot \left(y + z\right)}{z}\]
\[\mathsf{fma}\left(x, \frac{y}{z}, x\right)\]
\frac{x \cdot \left(y + z\right)}{z}
\mathsf{fma}\left(x, \frac{y}{z}, x\right)
double f(double x, double y, double z) {
        double r23169607 = x;
        double r23169608 = y;
        double r23169609 = z;
        double r23169610 = r23169608 + r23169609;
        double r23169611 = r23169607 * r23169610;
        double r23169612 = r23169611 / r23169609;
        return r23169612;
}

double f(double x, double y, double z) {
        double r23169613 = x;
        double r23169614 = y;
        double r23169615 = z;
        double r23169616 = r23169614 / r23169615;
        double r23169617 = fma(r23169613, r23169616, r23169613);
        return r23169617;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original11.6
Target3.1
Herbie3.4
\[\frac{x}{\frac{z}{y + z}}\]

Derivation

  1. Initial program 11.6

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

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

    \[\leadsto \color{blue}{y \cdot \frac{x}{z} + x}\]
  5. Using strategy rm
  6. Applied associate-*r/4.5

    \[\leadsto \color{blue}{\frac{y \cdot x}{z}} + x\]
  7. Using strategy rm
  8. Applied *-un-lft-identity4.5

    \[\leadsto \frac{y \cdot x}{z} + \color{blue}{1 \cdot x}\]
  9. Applied *-un-lft-identity4.5

    \[\leadsto \color{blue}{1 \cdot \frac{y \cdot x}{z}} + 1 \cdot x\]
  10. Applied distribute-lft-out4.5

    \[\leadsto \color{blue}{1 \cdot \left(\frac{y \cdot x}{z} + x\right)}\]
  11. Simplified3.4

    \[\leadsto 1 \cdot \color{blue}{\mathsf{fma}\left(x, \frac{y}{z}, x\right)}\]
  12. Final simplification3.4

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

Reproduce

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

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

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