Average Error: 13.1 → 1.7
Time: 11.5s
Precision: 64
\[\frac{x \cdot \left(y + z\right)}{z}\]
\[\begin{array}{l} \mathbf{if}\;\frac{x \cdot \left(y + z\right)}{z} \le -2.2289547856801053 \cdot 10^{289}:\\ \;\;\;\;\mathsf{fma}\left(x, \frac{y}{z}, x\right)\\ \mathbf{elif}\;\frac{x \cdot \left(y + z\right)}{z} \le -2.13434884956980963 \cdot 10^{-4}:\\ \;\;\;\;\mathsf{fma}\left(\frac{1}{z}, \frac{x}{\frac{1}{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}\;\frac{x \cdot \left(y + z\right)}{z} \le -2.2289547856801053 \cdot 10^{289}:\\
\;\;\;\;\mathsf{fma}\left(x, \frac{y}{z}, x\right)\\

\mathbf{elif}\;\frac{x \cdot \left(y + z\right)}{z} \le -2.13434884956980963 \cdot 10^{-4}:\\
\;\;\;\;\mathsf{fma}\left(\frac{1}{z}, \frac{x}{\frac{1}{y}}, x\right)\\

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

\end{array}
double f(double x, double y, double z) {
        double r503285 = x;
        double r503286 = y;
        double r503287 = z;
        double r503288 = r503286 + r503287;
        double r503289 = r503285 * r503288;
        double r503290 = r503289 / r503287;
        return r503290;
}

double f(double x, double y, double z) {
        double r503291 = x;
        double r503292 = y;
        double r503293 = z;
        double r503294 = r503292 + r503293;
        double r503295 = r503291 * r503294;
        double r503296 = r503295 / r503293;
        double r503297 = -2.2289547856801053e+289;
        bool r503298 = r503296 <= r503297;
        double r503299 = r503292 / r503293;
        double r503300 = fma(r503291, r503299, r503291);
        double r503301 = -0.00021343488495698096;
        bool r503302 = r503296 <= r503301;
        double r503303 = 1.0;
        double r503304 = r503303 / r503293;
        double r503305 = r503303 / r503292;
        double r503306 = r503291 / r503305;
        double r503307 = fma(r503304, r503306, r503291);
        double r503308 = r503293 / r503292;
        double r503309 = r503291 / r503308;
        double r503310 = r503309 + r503291;
        double r503311 = r503302 ? r503307 : r503310;
        double r503312 = r503298 ? r503300 : r503311;
        return r503312;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original13.1
Target2.9
Herbie1.7
\[\frac{x}{\frac{z}{y + z}}\]

Derivation

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

    1. Initial program 56.6

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

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

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

      \[\leadsto \color{blue}{\frac{x \cdot y}{z}} + x\]
    6. Using strategy rm
    7. Applied *-un-lft-identity17.4

      \[\leadsto \frac{x \cdot y}{\color{blue}{1 \cdot z}} + x\]
    8. Applied times-frac1.9

      \[\leadsto \color{blue}{\frac{x}{1} \cdot \frac{y}{z}} + x\]
    9. Applied fma-def1.9

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

    if -2.2289547856801053e+289 < (/ (* x (+ y z)) z) < -0.00021343488495698096

    1. Initial program 0.2

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

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

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

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

      \[\leadsto \color{blue}{\frac{x}{\frac{z}{y}}} + x\]
    8. Using strategy rm
    9. Applied div-inv6.2

      \[\leadsto \frac{x}{\color{blue}{z \cdot \frac{1}{y}}} + x\]
    10. Applied *-un-lft-identity6.2

      \[\leadsto \frac{\color{blue}{1 \cdot x}}{z \cdot \frac{1}{y}} + x\]
    11. Applied times-frac0.3

      \[\leadsto \color{blue}{\frac{1}{z} \cdot \frac{x}{\frac{1}{y}}} + x\]
    12. Applied fma-def0.3

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

    if -0.00021343488495698096 < (/ (* x (+ y z)) z)

    1. Initial program 11.6

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

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

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

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

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

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

Reproduce

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