Average Error: 12.5 → 2.0
Time: 17.6s
Precision: 64
\[\frac{x \cdot \left(y + z\right)}{z}\]
\[\begin{array}{l} \mathbf{if}\;x \le -3.886651371922916370197370769697320772553 \cdot 10^{-63}:\\ \;\;\;\;\frac{x}{\frac{z}{z + y}}\\ \mathbf{elif}\;x \le 1.831106028469388203387362914551274921711 \cdot 10^{-30}:\\ \;\;\;\;\mathsf{fma}\left(\frac{x}{z}, y, x\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{\frac{z}{z + y}}\\ \end{array}\]
\frac{x \cdot \left(y + z\right)}{z}
\begin{array}{l}
\mathbf{if}\;x \le -3.886651371922916370197370769697320772553 \cdot 10^{-63}:\\
\;\;\;\;\frac{x}{\frac{z}{z + y}}\\

\mathbf{elif}\;x \le 1.831106028469388203387362914551274921711 \cdot 10^{-30}:\\
\;\;\;\;\mathsf{fma}\left(\frac{x}{z}, y, x\right)\\

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

\end{array}
double f(double x, double y, double z) {
        double r21009579 = x;
        double r21009580 = y;
        double r21009581 = z;
        double r21009582 = r21009580 + r21009581;
        double r21009583 = r21009579 * r21009582;
        double r21009584 = r21009583 / r21009581;
        return r21009584;
}

double f(double x, double y, double z) {
        double r21009585 = x;
        double r21009586 = -3.8866513719229164e-63;
        bool r21009587 = r21009585 <= r21009586;
        double r21009588 = z;
        double r21009589 = y;
        double r21009590 = r21009588 + r21009589;
        double r21009591 = r21009588 / r21009590;
        double r21009592 = r21009585 / r21009591;
        double r21009593 = 1.8311060284693882e-30;
        bool r21009594 = r21009585 <= r21009593;
        double r21009595 = r21009585 / r21009588;
        double r21009596 = fma(r21009595, r21009589, r21009585);
        double r21009597 = r21009594 ? r21009596 : r21009592;
        double r21009598 = r21009587 ? r21009592 : r21009597;
        return r21009598;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original12.5
Target2.9
Herbie2.0
\[\frac{x}{\frac{z}{y + z}}\]

Derivation

  1. Split input into 2 regimes
  2. if x < -3.8866513719229164e-63 or 1.8311060284693882e-30 < x

    1. Initial program 18.8

      \[\frac{x \cdot \left(y + z\right)}{z}\]
    2. Using strategy rm
    3. Applied associate-/l*0.3

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

    if -3.8866513719229164e-63 < x < 1.8311060284693882e-30

    1. Initial program 6.0

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{x}{z}, y, x\right)}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification2.0

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -3.886651371922916370197370769697320772553 \cdot 10^{-63}:\\ \;\;\;\;\frac{x}{\frac{z}{z + y}}\\ \mathbf{elif}\;x \le 1.831106028469388203387362914551274921711 \cdot 10^{-30}:\\ \;\;\;\;\mathsf{fma}\left(\frac{x}{z}, y, x\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{\frac{z}{z + y}}\\ \end{array}\]

Reproduce

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