Average Error: 12.4 → 3.1
Time: 15.2s
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 r290255 = x;
        double r290256 = y;
        double r290257 = z;
        double r290258 = r290256 + r290257;
        double r290259 = r290255 * r290258;
        double r290260 = r290259 / r290257;
        return r290260;
}

double f(double x, double y, double z) {
        double r290261 = z;
        double r290262 = -7.49177814034441e-177;
        bool r290263 = r290261 <= r290262;
        double r290264 = y;
        double r290265 = r290264 / r290261;
        double r290266 = x;
        double r290267 = fma(r290265, r290266, r290266);
        double r290268 = 7.318632377525781e-214;
        bool r290269 = r290261 <= r290268;
        double r290270 = r290266 / r290261;
        double r290271 = fma(r290270, r290264, r290266);
        double r290272 = r290261 / r290264;
        double r290273 = r290266 / r290272;
        double r290274 = r290273 + r290266;
        double r290275 = r290269 ? r290271 : r290274;
        double r290276 = r290263 ? r290267 : r290275;
        return r290276;
}

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))