Average Error: 12.6 → 0.2
Time: 2.4s
Precision: 64
\[\frac{x \cdot \left(y + z\right)}{z}\]
\[\begin{array}{l} \mathbf{if}\;\frac{x \cdot \left(y + z\right)}{z} = -\infty \lor \neg \left(\frac{x \cdot \left(y + z\right)}{z} \le -5.36585091453369265 \cdot 10^{29} \lor \neg \left(\frac{x \cdot \left(y + z\right)}{z} \le 4.7357356704441813 \cdot 10^{-60} \lor \neg \left(\frac{x \cdot \left(y + z\right)}{z} \le 4.83290498311523521 \cdot 10^{302}\right)\right)\right):\\ \;\;\;\;\mathsf{fma}\left(\frac{y}{z}, x, x\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot \left(y + z\right)}{z}\\ \end{array}\]
\frac{x \cdot \left(y + z\right)}{z}
\begin{array}{l}
\mathbf{if}\;\frac{x \cdot \left(y + z\right)}{z} = -\infty \lor \neg \left(\frac{x \cdot \left(y + z\right)}{z} \le -5.36585091453369265 \cdot 10^{29} \lor \neg \left(\frac{x \cdot \left(y + z\right)}{z} \le 4.7357356704441813 \cdot 10^{-60} \lor \neg \left(\frac{x \cdot \left(y + z\right)}{z} \le 4.83290498311523521 \cdot 10^{302}\right)\right)\right):\\
\;\;\;\;\mathsf{fma}\left(\frac{y}{z}, x, x\right)\\

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

\end{array}
double f(double x, double y, double z) {
        double r374611 = x;
        double r374612 = y;
        double r374613 = z;
        double r374614 = r374612 + r374613;
        double r374615 = r374611 * r374614;
        double r374616 = r374615 / r374613;
        return r374616;
}

double f(double x, double y, double z) {
        double r374617 = x;
        double r374618 = y;
        double r374619 = z;
        double r374620 = r374618 + r374619;
        double r374621 = r374617 * r374620;
        double r374622 = r374621 / r374619;
        double r374623 = -inf.0;
        bool r374624 = r374622 <= r374623;
        double r374625 = -5.3658509145336926e+29;
        bool r374626 = r374622 <= r374625;
        double r374627 = 4.7357356704441813e-60;
        bool r374628 = r374622 <= r374627;
        double r374629 = 4.832904983115235e+302;
        bool r374630 = r374622 <= r374629;
        double r374631 = !r374630;
        bool r374632 = r374628 || r374631;
        double r374633 = !r374632;
        bool r374634 = r374626 || r374633;
        double r374635 = !r374634;
        bool r374636 = r374624 || r374635;
        double r374637 = r374618 / r374619;
        double r374638 = fma(r374637, r374617, r374617);
        double r374639 = r374636 ? r374638 : r374622;
        return r374639;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original12.6
Target2.9
Herbie0.2
\[\frac{x}{\frac{z}{y + z}}\]

Derivation

  1. Split input into 2 regimes
  2. if (/ (* x (+ y z)) z) < -inf.0 or -5.3658509145336926e+29 < (/ (* x (+ y z)) z) < 4.7357356704441813e-60 or 4.832904983115235e+302 < (/ (* x (+ y z)) z)

    1. Initial program 22.2

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

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

    if -inf.0 < (/ (* x (+ y z)) z) < -5.3658509145336926e+29 or 4.7357356704441813e-60 < (/ (* x (+ y z)) z) < 4.832904983115235e+302

    1. Initial program 0.2

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{x \cdot \left(y + z\right)}{z} = -\infty \lor \neg \left(\frac{x \cdot \left(y + z\right)}{z} \le -5.36585091453369265 \cdot 10^{29} \lor \neg \left(\frac{x \cdot \left(y + z\right)}{z} \le 4.7357356704441813 \cdot 10^{-60} \lor \neg \left(\frac{x \cdot \left(y + z\right)}{z} \le 4.83290498311523521 \cdot 10^{302}\right)\right)\right):\\ \;\;\;\;\mathsf{fma}\left(\frac{y}{z}, x, x\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot \left(y + z\right)}{z}\\ \end{array}\]

Reproduce

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