Average Error: 13.1 → 1.7
Time: 6.8s
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 r410281 = x;
        double r410282 = y;
        double r410283 = z;
        double r410284 = r410282 + r410283;
        double r410285 = r410281 * r410284;
        double r410286 = r410285 / r410283;
        return r410286;
}

double f(double x, double y, double z) {
        double r410287 = x;
        double r410288 = y;
        double r410289 = z;
        double r410290 = r410288 + r410289;
        double r410291 = r410287 * r410290;
        double r410292 = r410291 / r410289;
        double r410293 = -2.2289547856801053e+289;
        bool r410294 = r410292 <= r410293;
        double r410295 = r410288 / r410289;
        double r410296 = fma(r410287, r410295, r410287);
        double r410297 = -0.00021343488495698096;
        bool r410298 = r410292 <= r410297;
        double r410299 = 1.0;
        double r410300 = r410299 / r410289;
        double r410301 = r410299 / r410288;
        double r410302 = r410287 / r410301;
        double r410303 = fma(r410300, r410302, r410287);
        double r410304 = r410289 / r410288;
        double r410305 = r410287 / r410304;
        double r410306 = r410305 + r410287;
        double r410307 = r410298 ? r410303 : r410306;
        double r410308 = r410294 ? r410296 : r410307;
        return r410308;
}

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(y, \frac{x}{z}, x\right)}\]
    3. Using strategy rm
    4. Applied fma-udef2.8

      \[\leadsto \color{blue}{y \cdot \frac{x}{z} + 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(y, \frac{x}{z}, x\right)}\]
    3. Using strategy rm
    4. Applied fma-udef7.1

      \[\leadsto \color{blue}{y \cdot \frac{x}{z} + 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(y, \frac{x}{z}, x\right)}\]
    3. Using strategy rm
    4. Applied fma-udef4.1

      \[\leadsto \color{blue}{y \cdot \frac{x}{z} + 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))