Average Error: 11.7 → 0.5
Time: 12.2s
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 -3.0719468564861416 \cdot 10^{-106}:\\ \;\;\;\;\frac{\left(y + z\right) \cdot x}{z}\\ \mathbf{elif}\;\frac{\left(y + z\right) \cdot x}{z} \le 2.739367360965913 \cdot 10^{+16}:\\ \;\;\;\;x \cdot \frac{y + z}{z}\\ \mathbf{elif}\;\frac{\left(y + z\right) \cdot x}{z} \le 1.597998240181167 \cdot 10^{+270}:\\ \;\;\;\;\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 -3.0719468564861416 \cdot 10^{-106}:\\
\;\;\;\;\frac{\left(y + z\right) \cdot x}{z}\\

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

\mathbf{elif}\;\frac{\left(y + z\right) \cdot x}{z} \le 1.597998240181167 \cdot 10^{+270}:\\
\;\;\;\;\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 r20553892 = x;
        double r20553893 = y;
        double r20553894 = z;
        double r20553895 = r20553893 + r20553894;
        double r20553896 = r20553892 * r20553895;
        double r20553897 = r20553896 / r20553894;
        return r20553897;
}

double f(double x, double y, double z) {
        double r20553898 = y;
        double r20553899 = z;
        double r20553900 = r20553898 + r20553899;
        double r20553901 = x;
        double r20553902 = r20553900 * r20553901;
        double r20553903 = r20553902 / r20553899;
        double r20553904 = -inf.0;
        bool r20553905 = r20553903 <= r20553904;
        double r20553906 = r20553901 / r20553899;
        double r20553907 = fma(r20553898, r20553906, r20553901);
        double r20553908 = -3.0719468564861416e-106;
        bool r20553909 = r20553903 <= r20553908;
        double r20553910 = 2.739367360965913e+16;
        bool r20553911 = r20553903 <= r20553910;
        double r20553912 = r20553900 / r20553899;
        double r20553913 = r20553901 * r20553912;
        double r20553914 = 1.597998240181167e+270;
        bool r20553915 = r20553903 <= r20553914;
        double r20553916 = r20553915 ? r20553903 : r20553913;
        double r20553917 = r20553911 ? r20553913 : r20553916;
        double r20553918 = r20553909 ? r20553903 : r20553917;
        double r20553919 = r20553905 ? r20553907 : r20553918;
        return r20553919;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original11.7
Target2.9
Herbie0.5
\[\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) < -3.0719468564861416e-106 or 2.739367360965913e+16 < (/ (* x (+ y z)) z) < 1.597998240181167e+270

    1. Initial program 0.2

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

    if -3.0719468564861416e-106 < (/ (* x (+ y z)) z) < 2.739367360965913e+16 or 1.597998240181167e+270 < (/ (* x (+ y z)) z)

    1. Initial program 15.7

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

      \[\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.5

    \[\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 -3.0719468564861416 \cdot 10^{-106}:\\ \;\;\;\;\frac{\left(y + z\right) \cdot x}{z}\\ \mathbf{elif}\;\frac{\left(y + z\right) \cdot x}{z} \le 2.739367360965913 \cdot 10^{+16}:\\ \;\;\;\;x \cdot \frac{y + z}{z}\\ \mathbf{elif}\;\frac{\left(y + z\right) \cdot x}{z} \le 1.597998240181167 \cdot 10^{+270}:\\ \;\;\;\;\frac{\left(y + z\right) \cdot x}{z}\\ \mathbf{else}:\\ \;\;\;\;x \cdot \frac{y + z}{z}\\ \end{array}\]

Reproduce

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