Average Error: 12.2 → 3.6
Time: 33.0s
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 r19330830 = x;
        double r19330831 = y;
        double r19330832 = z;
        double r19330833 = r19330831 + r19330832;
        double r19330834 = r19330830 * r19330833;
        double r19330835 = r19330834 / r19330832;
        return r19330835;
}

double f(double x, double y, double z) {
        double r19330836 = x;
        double r19330837 = y;
        double r19330838 = z;
        double r19330839 = r19330837 / r19330838;
        double r19330840 = fma(r19330836, r19330839, r19330836);
        return r19330840;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original12.2
Target3.3
Herbie3.6
\[\frac{x}{\frac{z}{y + z}}\]

Derivation

  1. Initial program 12.2

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

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

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

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

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

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

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

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

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