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 r19292388 = x;
        double r19292389 = y;
        double r19292390 = z;
        double r19292391 = r19292389 + r19292390;
        double r19292392 = r19292388 * r19292391;
        double r19292393 = r19292392 / r19292390;
        return r19292393;
}

double f(double x, double y, double z) {
        double r19292394 = y;
        double r19292395 = z;
        double r19292396 = r19292394 + r19292395;
        double r19292397 = x;
        double r19292398 = r19292396 * r19292397;
        double r19292399 = r19292398 / r19292395;
        double r19292400 = -inf.0;
        bool r19292401 = r19292399 <= r19292400;
        double r19292402 = r19292397 / r19292395;
        double r19292403 = fma(r19292394, r19292402, r19292397);
        double r19292404 = -2.1060876273444035e-158;
        bool r19292405 = r19292399 <= r19292404;
        double r19292406 = 8.603937394135698e-249;
        bool r19292407 = r19292399 <= r19292406;
        double r19292408 = r19292396 / r19292395;
        double r19292409 = r19292397 * r19292408;
        double r19292410 = 6.697106070399062e+286;
        bool r19292411 = r19292399 <= r19292410;
        double r19292412 = r19292411 ? r19292399 : r19292409;
        double r19292413 = r19292407 ? r19292409 : r19292412;
        double r19292414 = r19292405 ? r19292399 : r19292413;
        double r19292415 = r19292401 ? r19292403 : r19292414;
        return r19292415;
}

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