Average Error: 12.6 → 1.9
Time: 2.3s
Precision: 64
\[\frac{x \cdot \left(y + z\right)}{z}\]
\[\begin{array}{l} \mathbf{if}\;x \le -6.4546096464274241 \cdot 10^{-105} \lor \neg \left(x \le 1.476702020789425 \cdot 10^{-74}\right):\\ \;\;\;\;\mathsf{fma}\left(\frac{y}{z}, x, x\right)\\ \mathbf{else}:\\ \;\;\;\;\left(y \cdot x\right) \cdot \frac{1}{z} + x\\ \end{array}\]
\frac{x \cdot \left(y + z\right)}{z}
\begin{array}{l}
\mathbf{if}\;x \le -6.4546096464274241 \cdot 10^{-105} \lor \neg \left(x \le 1.476702020789425 \cdot 10^{-74}\right):\\
\;\;\;\;\mathsf{fma}\left(\frac{y}{z}, x, x\right)\\

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

\end{array}
double f(double x, double y, double z) {
        double r441431 = x;
        double r441432 = y;
        double r441433 = z;
        double r441434 = r441432 + r441433;
        double r441435 = r441431 * r441434;
        double r441436 = r441435 / r441433;
        return r441436;
}

double f(double x, double y, double z) {
        double r441437 = x;
        double r441438 = -6.454609646427424e-105;
        bool r441439 = r441437 <= r441438;
        double r441440 = 1.4767020207894247e-74;
        bool r441441 = r441437 <= r441440;
        double r441442 = !r441441;
        bool r441443 = r441439 || r441442;
        double r441444 = y;
        double r441445 = z;
        double r441446 = r441444 / r441445;
        double r441447 = fma(r441446, r441437, r441437);
        double r441448 = r441444 * r441437;
        double r441449 = 1.0;
        double r441450 = r441449 / r441445;
        double r441451 = r441448 * r441450;
        double r441452 = r441451 + r441437;
        double r441453 = r441443 ? r441447 : r441452;
        return r441453;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original12.6
Target3.3
Herbie1.9
\[\frac{x}{\frac{z}{y + z}}\]

Derivation

  1. Split input into 2 regimes
  2. if x < -6.454609646427424e-105 or 1.4767020207894247e-74 < x

    1. Initial program 16.9

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

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

    if -6.454609646427424e-105 < x < 1.4767020207894247e-74

    1. Initial program 6.7

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

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

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

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

      \[\leadsto \color{blue}{y \cdot \left(\frac{1}{z} \cdot x\right)} + x\]
    8. Simplified3.4

      \[\leadsto y \cdot \color{blue}{\frac{x}{z}} + x\]
    9. Using strategy rm
    10. Applied div-inv3.4

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -6.4546096464274241 \cdot 10^{-105} \lor \neg \left(x \le 1.476702020789425 \cdot 10^{-74}\right):\\ \;\;\;\;\mathsf{fma}\left(\frac{y}{z}, x, x\right)\\ \mathbf{else}:\\ \;\;\;\;\left(y \cdot x\right) \cdot \frac{1}{z} + x\\ \end{array}\]

Reproduce

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