Average Error: 12.1 → 1.5
Time: 13.8s
Precision: 64
\[\frac{x \cdot \left(y + z\right)}{z}\]
\[\begin{array}{l} \mathbf{if}\;x \le -0.003148510697704747472724928769594043842517:\\ \;\;\;\;x + \frac{y}{z} \cdot x\\ \mathbf{elif}\;x \le 8.021148315555671601231790533736466797254 \cdot 10^{-10}:\\ \;\;\;\;\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}\;x \le -0.003148510697704747472724928769594043842517:\\
\;\;\;\;x + \frac{y}{z} \cdot x\\

\mathbf{elif}\;x \le 8.021148315555671601231790533736466797254 \cdot 10^{-10}:\\
\;\;\;\;\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 r298758 = x;
        double r298759 = y;
        double r298760 = z;
        double r298761 = r298759 + r298760;
        double r298762 = r298758 * r298761;
        double r298763 = r298762 / r298760;
        return r298763;
}

double f(double x, double y, double z) {
        double r298764 = x;
        double r298765 = -0.0031485106977047475;
        bool r298766 = r298764 <= r298765;
        double r298767 = y;
        double r298768 = z;
        double r298769 = r298767 / r298768;
        double r298770 = r298769 * r298764;
        double r298771 = r298764 + r298770;
        double r298772 = 8.021148315555672e-10;
        bool r298773 = r298764 <= r298772;
        double r298774 = r298764 / r298768;
        double r298775 = fma(r298774, r298767, r298764);
        double r298776 = r298768 / r298767;
        double r298777 = r298764 / r298776;
        double r298778 = r298777 + r298764;
        double r298779 = r298773 ? r298775 : r298778;
        double r298780 = r298766 ? r298771 : r298779;
        return r298780;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original12.1
Target3.1
Herbie1.5
\[\frac{x}{\frac{z}{y + z}}\]

Derivation

  1. Split input into 3 regimes
  2. if x < -0.0031485106977047475

    1. Initial program 21.6

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

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

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

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

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

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

    if -0.0031485106977047475 < x < 8.021148315555672e-10

    1. Initial program 4.7

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

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

    if 8.021148315555672e-10 < x

    1. Initial program 22.1

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

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

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

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

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

Reproduce

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