Average Error: 12.0 → 0.4
Time: 12.1s
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(\frac{x}{z}, y, 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}:\\ \;\;\;\;\mathsf{fma}\left(\frac{y}{z}, x, x\right)\\ \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}:\\ \;\;\;\;\mathsf{fma}\left(\frac{y}{z}, x, 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} = -\infty:\\
\;\;\;\;\mathsf{fma}\left(\frac{x}{z}, y, 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}:\\
\;\;\;\;\mathsf{fma}\left(\frac{y}{z}, x, x\right)\\

\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}:\\
\;\;\;\;\mathsf{fma}\left(\frac{y}{z}, x, x\right)\\

\end{array}
double f(double x, double y, double z) {
        double r21201038 = x;
        double r21201039 = y;
        double r21201040 = z;
        double r21201041 = r21201039 + r21201040;
        double r21201042 = r21201038 * r21201041;
        double r21201043 = r21201042 / r21201040;
        return r21201043;
}

double f(double x, double y, double z) {
        double r21201044 = y;
        double r21201045 = z;
        double r21201046 = r21201044 + r21201045;
        double r21201047 = x;
        double r21201048 = r21201046 * r21201047;
        double r21201049 = r21201048 / r21201045;
        double r21201050 = -inf.0;
        bool r21201051 = r21201049 <= r21201050;
        double r21201052 = r21201047 / r21201045;
        double r21201053 = fma(r21201052, r21201044, r21201047);
        double r21201054 = -2.1060876273444035e-158;
        bool r21201055 = r21201049 <= r21201054;
        double r21201056 = 8.603937394135698e-249;
        bool r21201057 = r21201049 <= r21201056;
        double r21201058 = r21201044 / r21201045;
        double r21201059 = fma(r21201058, r21201047, r21201047);
        double r21201060 = 6.697106070399062e+286;
        bool r21201061 = r21201049 <= r21201060;
        double r21201062 = r21201061 ? r21201049 : r21201059;
        double r21201063 = r21201057 ? r21201059 : r21201062;
        double r21201064 = r21201055 ? r21201049 : r21201063;
        double r21201065 = r21201051 ? r21201053 : r21201064;
        return r21201065;
}

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. Taylor expanded around 0 21.2

      \[\leadsto \color{blue}{\frac{x \cdot y}{z} + x}\]
    3. Simplified0.0

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{x}{z}, y, 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. Simplified0.8

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{y}{z}, x, x\right)}\]
  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(\frac{x}{z}, y, 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}:\\ \;\;\;\;\mathsf{fma}\left(\frac{y}{z}, x, x\right)\\ \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}:\\ \;\;\;\;\mathsf{fma}\left(\frac{y}{z}, x, x\right)\\ \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))