Average Error: 11.1 → 1.7
Time: 6.2s
Precision: 64
\[\frac{x \cdot \left(y + z\right)}{z}\]
\[\begin{array}{l} \mathbf{if}\;\frac{\left(y + z\right) \cdot x}{z} \le 1.2164222642491233 \cdot 10^{-71}:\\ \;\;\;\;x \cdot \frac{y + z}{z}\\ \mathbf{elif}\;\frac{\left(y + z\right) \cdot x}{z} \le 4.7576076920553454 \cdot 10^{+303}:\\ \;\;\;\;\frac{\left(y + z\right) \cdot x}{z}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(y, \frac{x}{z}, x\right)\\ \end{array}\]
\frac{x \cdot \left(y + z\right)}{z}
\begin{array}{l}
\mathbf{if}\;\frac{\left(y + z\right) \cdot x}{z} \le 1.2164222642491233 \cdot 10^{-71}:\\
\;\;\;\;x \cdot \frac{y + z}{z}\\

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

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y, \frac{x}{z}, x\right)\\

\end{array}
double f(double x, double y, double z) {
        double r6970431 = x;
        double r6970432 = y;
        double r6970433 = z;
        double r6970434 = r6970432 + r6970433;
        double r6970435 = r6970431 * r6970434;
        double r6970436 = r6970435 / r6970433;
        return r6970436;
}

double f(double x, double y, double z) {
        double r6970437 = y;
        double r6970438 = z;
        double r6970439 = r6970437 + r6970438;
        double r6970440 = x;
        double r6970441 = r6970439 * r6970440;
        double r6970442 = r6970441 / r6970438;
        double r6970443 = 1.2164222642491233e-71;
        bool r6970444 = r6970442 <= r6970443;
        double r6970445 = r6970439 / r6970438;
        double r6970446 = r6970440 * r6970445;
        double r6970447 = 4.7576076920553454e+303;
        bool r6970448 = r6970442 <= r6970447;
        double r6970449 = r6970440 / r6970438;
        double r6970450 = fma(r6970437, r6970449, r6970440);
        double r6970451 = r6970448 ? r6970442 : r6970450;
        double r6970452 = r6970444 ? r6970446 : r6970451;
        return r6970452;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original11.1
Target3.0
Herbie1.7
\[\frac{x}{\frac{z}{y + z}}\]

Derivation

  1. Split input into 3 regimes
  2. if (/ (* x (+ y z)) z) < 1.2164222642491233e-71

    1. Initial program 10.6

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

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

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

      \[\leadsto \color{blue}{x} \cdot \frac{y + z}{z}\]

    if 1.2164222642491233e-71 < (/ (* x (+ y z)) z) < 4.7576076920553454e+303

    1. Initial program 0.2

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

    if 4.7576076920553454e+303 < (/ (* x (+ y z)) z)

    1. Initial program 57.9

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(y, \frac{x}{z}, x\right)}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification1.7

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{\left(y + z\right) \cdot x}{z} \le 1.2164222642491233 \cdot 10^{-71}:\\ \;\;\;\;x \cdot \frac{y + z}{z}\\ \mathbf{elif}\;\frac{\left(y + z\right) \cdot x}{z} \le 4.7576076920553454 \cdot 10^{+303}:\\ \;\;\;\;\frac{\left(y + z\right) \cdot x}{z}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(y, \frac{x}{z}, x\right)\\ \end{array}\]

Reproduce

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