Average Error: 13.1 → 1.7
Time: 9.4s
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} \lor \neg \left(\frac{x \cdot \left(y + z\right)}{z} \le -2.13434884956980963 \cdot 10^{-4}\right):\\ \;\;\;\;\frac{x}{\frac{z}{y}} + x\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{1}{z}, \frac{x}{\frac{1}{y}}, x\right)\\ \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} \lor \neg \left(\frac{x \cdot \left(y + z\right)}{z} \le -2.13434884956980963 \cdot 10^{-4}\right):\\
\;\;\;\;\frac{x}{\frac{z}{y}} + x\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{1}{z}, \frac{x}{\frac{1}{y}}, x\right)\\

\end{array}
double f(double x, double y, double z) {
        double r399788 = x;
        double r399789 = y;
        double r399790 = z;
        double r399791 = r399789 + r399790;
        double r399792 = r399788 * r399791;
        double r399793 = r399792 / r399790;
        return r399793;
}

double f(double x, double y, double z) {
        double r399794 = x;
        double r399795 = y;
        double r399796 = z;
        double r399797 = r399795 + r399796;
        double r399798 = r399794 * r399797;
        double r399799 = r399798 / r399796;
        double r399800 = -2.2289547856801053e+289;
        bool r399801 = r399799 <= r399800;
        double r399802 = -0.00021343488495698096;
        bool r399803 = r399799 <= r399802;
        double r399804 = !r399803;
        bool r399805 = r399801 || r399804;
        double r399806 = r399796 / r399795;
        double r399807 = r399794 / r399806;
        double r399808 = r399807 + r399794;
        double r399809 = 1.0;
        double r399810 = r399809 / r399796;
        double r399811 = r399809 / r399795;
        double r399812 = r399794 / r399811;
        double r399813 = fma(r399810, r399812, r399794);
        double r399814 = r399805 ? r399808 : r399813;
        return r399814;
}

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 2 regimes
  2. if (/ (* x (+ y z)) z) < -2.2289547856801053e+289 or -0.00021343488495698096 < (/ (* x (+ y z)) z)

    1. Initial program 16.5

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

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

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

      \[\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\]

    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)}\]
  3. Recombined 2 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} \lor \neg \left(\frac{x \cdot \left(y + z\right)}{z} \le -2.13434884956980963 \cdot 10^{-4}\right):\\ \;\;\;\;\frac{x}{\frac{z}{y}} + x\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{1}{z}, \frac{x}{\frac{1}{y}}, x\right)\\ \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))