Average Error: 12.4 → 3.2
Time: 16.6s
Precision: 64
\[\frac{x \cdot \left(y + z\right)}{z}\]
\[\begin{array}{l} \mathbf{if}\;x \le 3.887474187627610927514063365556824489489 \cdot 10^{-297}:\\ \;\;\;\;\frac{1}{\frac{z}{x \cdot y}} + x\\ \mathbf{elif}\;x \le 2.739468334789370649568254673285532362384 \cdot 10^{-99}:\\ \;\;\;\;\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}\;x \le 3.887474187627610927514063365556824489489 \cdot 10^{-297}:\\
\;\;\;\;\frac{1}{\frac{z}{x \cdot y}} + x\\

\mathbf{elif}\;x \le 2.739468334789370649568254673285532362384 \cdot 10^{-99}:\\
\;\;\;\;\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 r205928 = x;
        double r205929 = y;
        double r205930 = z;
        double r205931 = r205929 + r205930;
        double r205932 = r205928 * r205931;
        double r205933 = r205932 / r205930;
        return r205933;
}

double f(double x, double y, double z) {
        double r205934 = x;
        double r205935 = 3.887474187627611e-297;
        bool r205936 = r205934 <= r205935;
        double r205937 = 1.0;
        double r205938 = z;
        double r205939 = y;
        double r205940 = r205934 * r205939;
        double r205941 = r205938 / r205940;
        double r205942 = r205937 / r205941;
        double r205943 = r205942 + r205934;
        double r205944 = 2.7394683347893706e-99;
        bool r205945 = r205934 <= r205944;
        double r205946 = r205934 / r205938;
        double r205947 = fma(r205946, r205939, r205934);
        double r205948 = r205938 / r205939;
        double r205949 = r205934 / r205948;
        double r205950 = r205949 + r205934;
        double r205951 = r205945 ? r205947 : r205950;
        double r205952 = r205936 ? r205943 : r205951;
        return r205952;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original12.4
Target3.2
Herbie3.2
\[\frac{x}{\frac{z}{y + z}}\]

Derivation

  1. Split input into 3 regimes
  2. if x < 3.887474187627611e-297

    1. Initial program 12.2

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{y}{z}, x, x\right)}\]
    3. Taylor expanded around 0 4.7

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{x}{z}, y, x\right)}\]
    5. Using strategy rm
    6. Applied fma-udef4.9

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

      \[\leadsto \color{blue}{\frac{x \cdot y}{z}} + x\]
    8. Using strategy rm
    9. Applied clear-num4.8

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

    if 3.887474187627611e-297 < x < 2.7394683347893706e-99

    1. Initial program 6.3

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{y}{z}, x, x\right)}\]
    3. Taylor expanded around 0 3.5

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

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

    if 2.7394683347893706e-99 < x

    1. Initial program 16.5

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{y}{z}, x, x\right)}\]
    3. Taylor expanded around 0 5.2

      \[\leadsto \color{blue}{\frac{x \cdot y}{z} + x}\]
    4. Simplified5.6

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

      \[\leadsto \color{blue}{\frac{x}{z} \cdot y + x}\]
    7. Simplified5.2

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

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

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

Reproduce

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