Average Error: 12.1 → 2.3
Time: 8.6s
Precision: 64
\[\frac{x \cdot \left(y + z\right)}{z}\]
\[\begin{array}{l} \mathbf{if}\;y \le -9.08005395530494447 \cdot 10^{51}:\\ \;\;\;\;\mathsf{fma}\left(\frac{x}{z}, y, x\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{\frac{z}{y}} + x\\ \end{array}\]
\frac{x \cdot \left(y + z\right)}{z}
\begin{array}{l}
\mathbf{if}\;y \le -9.08005395530494447 \cdot 10^{51}:\\
\;\;\;\;\mathsf{fma}\left(\frac{x}{z}, y, x\right)\\

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

\end{array}
double f(double x, double y, double z) {
        double r654644 = x;
        double r654645 = y;
        double r654646 = z;
        double r654647 = r654645 + r654646;
        double r654648 = r654644 * r654647;
        double r654649 = r654648 / r654646;
        return r654649;
}

double f(double x, double y, double z) {
        double r654650 = y;
        double r654651 = -9.080053955304944e+51;
        bool r654652 = r654650 <= r654651;
        double r654653 = x;
        double r654654 = z;
        double r654655 = r654653 / r654654;
        double r654656 = fma(r654655, r654650, r654653);
        double r654657 = r654654 / r654650;
        double r654658 = r654653 / r654657;
        double r654659 = r654658 + r654653;
        double r654660 = r654652 ? r654656 : r654659;
        return r654660;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original12.1
Target3.1
Herbie2.3
\[\frac{x}{\frac{z}{y + z}}\]

Derivation

  1. Split input into 2 regimes
  2. if y < -9.080053955304944e+51

    1. Initial program 11.9

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

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

    if -9.080053955304944e+51 < y

    1. Initial program 12.1

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

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

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

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

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

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

Reproduce

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

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

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