Average Error: 12.4 → 3.1
Time: 16.0s
Precision: 64
\[\frac{x \cdot \left(y + z\right)}{z}\]
\[\begin{array}{l} \mathbf{if}\;z \le -7.491778140344410199247807476987183548672 \cdot 10^{-177}:\\ \;\;\;\;\mathsf{fma}\left(\frac{y}{z}, x, x\right)\\ \mathbf{elif}\;z \le 7.318632377525780595545793146364737579954 \cdot 10^{-214}:\\ \;\;\;\;\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}\;z \le -7.491778140344410199247807476987183548672 \cdot 10^{-177}:\\
\;\;\;\;\mathsf{fma}\left(\frac{y}{z}, x, x\right)\\

\mathbf{elif}\;z \le 7.318632377525780595545793146364737579954 \cdot 10^{-214}:\\
\;\;\;\;\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 r297616 = x;
        double r297617 = y;
        double r297618 = z;
        double r297619 = r297617 + r297618;
        double r297620 = r297616 * r297619;
        double r297621 = r297620 / r297618;
        return r297621;
}

double f(double x, double y, double z) {
        double r297622 = z;
        double r297623 = -7.49177814034441e-177;
        bool r297624 = r297622 <= r297623;
        double r297625 = y;
        double r297626 = r297625 / r297622;
        double r297627 = x;
        double r297628 = fma(r297626, r297627, r297627);
        double r297629 = 7.318632377525781e-214;
        bool r297630 = r297622 <= r297629;
        double r297631 = r297627 / r297622;
        double r297632 = fma(r297631, r297625, r297627);
        double r297633 = r297622 / r297625;
        double r297634 = r297627 / r297633;
        double r297635 = r297634 + r297627;
        double r297636 = r297630 ? r297632 : r297635;
        double r297637 = r297624 ? r297628 : r297636;
        return r297637;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

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

Derivation

  1. Split input into 3 regimes
  2. if z < -7.49177814034441e-177

    1. Initial program 12.3

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

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

    if -7.49177814034441e-177 < z < 7.318632377525781e-214

    1. Initial program 11.6

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

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

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

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

    if 7.318632377525781e-214 < z

    1. Initial program 12.6

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

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

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

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

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

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

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

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

Reproduce

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