Average Error: 12.3 → 2.1
Time: 17.0s
Precision: 64
\[\frac{x \cdot \left(y + z\right)}{z}\]
\[\begin{array}{l} \mathbf{if}\;z \le -8.075781138440941892154872470930892635259 \cdot 10^{-16} \lor \neg \left(z \le 2.717641103527439173532310107215917032371 \cdot 10^{-184}\right):\\ \;\;\;\;x \cdot \frac{y}{z} + x\\ \mathbf{else}:\\ \;\;\;\;\left(x \cdot y\right) \cdot \frac{1}{z} + x\\ \end{array}\]
\frac{x \cdot \left(y + z\right)}{z}
\begin{array}{l}
\mathbf{if}\;z \le -8.075781138440941892154872470930892635259 \cdot 10^{-16} \lor \neg \left(z \le 2.717641103527439173532310107215917032371 \cdot 10^{-184}\right):\\
\;\;\;\;x \cdot \frac{y}{z} + x\\

\mathbf{else}:\\
\;\;\;\;\left(x \cdot y\right) \cdot \frac{1}{z} + x\\

\end{array}
double f(double x, double y, double z) {
        double r300749 = x;
        double r300750 = y;
        double r300751 = z;
        double r300752 = r300750 + r300751;
        double r300753 = r300749 * r300752;
        double r300754 = r300753 / r300751;
        return r300754;
}

double f(double x, double y, double z) {
        double r300755 = z;
        double r300756 = -8.075781138440942e-16;
        bool r300757 = r300755 <= r300756;
        double r300758 = 2.717641103527439e-184;
        bool r300759 = r300755 <= r300758;
        double r300760 = !r300759;
        bool r300761 = r300757 || r300760;
        double r300762 = x;
        double r300763 = y;
        double r300764 = r300763 / r300755;
        double r300765 = r300762 * r300764;
        double r300766 = r300765 + r300762;
        double r300767 = r300762 * r300763;
        double r300768 = 1.0;
        double r300769 = r300768 / r300755;
        double r300770 = r300767 * r300769;
        double r300771 = r300770 + r300762;
        double r300772 = r300761 ? r300766 : r300771;
        return r300772;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original12.3
Target3.2
Herbie2.1
\[\frac{x}{\frac{z}{y + z}}\]

Derivation

  1. Split input into 2 regimes
  2. if z < -8.075781138440942e-16 or 2.717641103527439e-184 < z

    1. Initial program 14.2

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

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

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

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

    if -8.075781138440942e-16 < z < 2.717641103527439e-184

    1. Initial program 7.6

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

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

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

      \[\leadsto \color{blue}{x \cdot \frac{y}{z}} + x\]
    6. Using strategy rm
    7. Applied div-inv9.7

      \[\leadsto x \cdot \color{blue}{\left(y \cdot \frac{1}{z}\right)} + x\]
    8. Applied associate-*r*4.6

      \[\leadsto \color{blue}{\left(x \cdot y\right) \cdot \frac{1}{z}} + x\]
  3. Recombined 2 regimes into one program.
  4. Final simplification2.1

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \le -8.075781138440941892154872470930892635259 \cdot 10^{-16} \lor \neg \left(z \le 2.717641103527439173532310107215917032371 \cdot 10^{-184}\right):\\ \;\;\;\;x \cdot \frac{y}{z} + x\\ \mathbf{else}:\\ \;\;\;\;\left(x \cdot y\right) \cdot \frac{1}{z} + x\\ \end{array}\]

Reproduce

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