Average Error: 12.0 → 0.4
Time: 13.9s
Precision: 64
\[\frac{x \cdot \left(y + z\right)}{z}\]
\[\begin{array}{l} \mathbf{if}\;\frac{\left(y + z\right) \cdot x}{z} = -\infty:\\ \;\;\;\;\mathsf{fma}\left(y, \frac{x}{z}, x\right)\\ \mathbf{elif}\;\frac{\left(y + z\right) \cdot x}{z} \le -2.1060876273444035 \cdot 10^{-158}:\\ \;\;\;\;\frac{\left(y + z\right) \cdot x}{z}\\ \mathbf{elif}\;\frac{\left(y + z\right) \cdot x}{z} \le 8.603937394135698 \cdot 10^{-249}:\\ \;\;\;\;x \cdot \frac{y + z}{z}\\ \mathbf{elif}\;\frac{\left(y + z\right) \cdot x}{z} \le 6.697106070399062 \cdot 10^{+286}:\\ \;\;\;\;\frac{\left(y + z\right) \cdot x}{z}\\ \mathbf{else}:\\ \;\;\;\;x \cdot \frac{y + z}{z}\\ \end{array}\]
\frac{x \cdot \left(y + z\right)}{z}
\begin{array}{l}
\mathbf{if}\;\frac{\left(y + z\right) \cdot x}{z} = -\infty:\\
\;\;\;\;\mathsf{fma}\left(y, \frac{x}{z}, x\right)\\

\mathbf{elif}\;\frac{\left(y + z\right) \cdot x}{z} \le -2.1060876273444035 \cdot 10^{-158}:\\
\;\;\;\;\frac{\left(y + z\right) \cdot x}{z}\\

\mathbf{elif}\;\frac{\left(y + z\right) \cdot x}{z} \le 8.603937394135698 \cdot 10^{-249}:\\
\;\;\;\;x \cdot \frac{y + z}{z}\\

\mathbf{elif}\;\frac{\left(y + z\right) \cdot x}{z} \le 6.697106070399062 \cdot 10^{+286}:\\
\;\;\;\;\frac{\left(y + z\right) \cdot x}{z}\\

\mathbf{else}:\\
\;\;\;\;x \cdot \frac{y + z}{z}\\

\end{array}
double f(double x, double y, double z) {
        double r18083438 = x;
        double r18083439 = y;
        double r18083440 = z;
        double r18083441 = r18083439 + r18083440;
        double r18083442 = r18083438 * r18083441;
        double r18083443 = r18083442 / r18083440;
        return r18083443;
}

double f(double x, double y, double z) {
        double r18083444 = y;
        double r18083445 = z;
        double r18083446 = r18083444 + r18083445;
        double r18083447 = x;
        double r18083448 = r18083446 * r18083447;
        double r18083449 = r18083448 / r18083445;
        double r18083450 = -inf.0;
        bool r18083451 = r18083449 <= r18083450;
        double r18083452 = r18083447 / r18083445;
        double r18083453 = fma(r18083444, r18083452, r18083447);
        double r18083454 = -2.1060876273444035e-158;
        bool r18083455 = r18083449 <= r18083454;
        double r18083456 = 8.603937394135698e-249;
        bool r18083457 = r18083449 <= r18083456;
        double r18083458 = r18083446 / r18083445;
        double r18083459 = r18083447 * r18083458;
        double r18083460 = 6.697106070399062e+286;
        bool r18083461 = r18083449 <= r18083460;
        double r18083462 = r18083461 ? r18083449 : r18083459;
        double r18083463 = r18083457 ? r18083459 : r18083462;
        double r18083464 = r18083455 ? r18083449 : r18083463;
        double r18083465 = r18083451 ? r18083453 : r18083464;
        return r18083465;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original12.0
Target2.9
Herbie0.4
\[\frac{x}{\frac{z}{y + z}}\]

Derivation

  1. Split input into 3 regimes
  2. if (/ (* x (+ y z)) z) < -inf.0

    1. Initial program 59.9

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

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

    if -inf.0 < (/ (* x (+ y z)) z) < -2.1060876273444035e-158 or 8.603937394135698e-249 < (/ (* x (+ y z)) z) < 6.697106070399062e+286

    1. Initial program 0.3

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

    if -2.1060876273444035e-158 < (/ (* x (+ y z)) z) < 8.603937394135698e-249 or 6.697106070399062e+286 < (/ (* x (+ y z)) z)

    1. Initial program 31.4

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

      \[\leadsto \frac{x \cdot \left(y + z\right)}{\color{blue}{1 \cdot z}}\]
    4. Applied times-frac0.8

      \[\leadsto \color{blue}{\frac{x}{1} \cdot \frac{y + z}{z}}\]
    5. Simplified0.8

      \[\leadsto \color{blue}{x} \cdot \frac{y + z}{z}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification0.4

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{\left(y + z\right) \cdot x}{z} = -\infty:\\ \;\;\;\;\mathsf{fma}\left(y, \frac{x}{z}, x\right)\\ \mathbf{elif}\;\frac{\left(y + z\right) \cdot x}{z} \le -2.1060876273444035 \cdot 10^{-158}:\\ \;\;\;\;\frac{\left(y + z\right) \cdot x}{z}\\ \mathbf{elif}\;\frac{\left(y + z\right) \cdot x}{z} \le 8.603937394135698 \cdot 10^{-249}:\\ \;\;\;\;x \cdot \frac{y + z}{z}\\ \mathbf{elif}\;\frac{\left(y + z\right) \cdot x}{z} \le 6.697106070399062 \cdot 10^{+286}:\\ \;\;\;\;\frac{\left(y + z\right) \cdot x}{z}\\ \mathbf{else}:\\ \;\;\;\;x \cdot \frac{y + z}{z}\\ \end{array}\]

Reproduce

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