Average Error: 12.5 → 1.8
Time: 13.8s
Precision: 64
\[\frac{x \cdot \left(y + z\right)}{z}\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.822759390725086618216460148861945165436 \cdot 10^{53} \lor \neg \left(x \le 8.624506499054229675094641740339480857407 \cdot 10^{-72}\right):\\ \;\;\;\;\mathsf{fma}\left(x, \frac{y}{z}, x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{x}{z}, y, x\right)\\ \end{array}\]
\frac{x \cdot \left(y + z\right)}{z}
\begin{array}{l}
\mathbf{if}\;x \le -1.822759390725086618216460148861945165436 \cdot 10^{53} \lor \neg \left(x \le 8.624506499054229675094641740339480857407 \cdot 10^{-72}\right):\\
\;\;\;\;\mathsf{fma}\left(x, \frac{y}{z}, x\right)\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{x}{z}, y, x\right)\\

\end{array}
double f(double x, double y, double z) {
        double r324378 = x;
        double r324379 = y;
        double r324380 = z;
        double r324381 = r324379 + r324380;
        double r324382 = r324378 * r324381;
        double r324383 = r324382 / r324380;
        return r324383;
}

double f(double x, double y, double z) {
        double r324384 = x;
        double r324385 = -1.8227593907250866e+53;
        bool r324386 = r324384 <= r324385;
        double r324387 = 8.62450649905423e-72;
        bool r324388 = r324384 <= r324387;
        double r324389 = !r324388;
        bool r324390 = r324386 || r324389;
        double r324391 = y;
        double r324392 = z;
        double r324393 = r324391 / r324392;
        double r324394 = fma(r324384, r324393, r324384);
        double r324395 = r324384 / r324392;
        double r324396 = fma(r324395, r324391, r324384);
        double r324397 = r324390 ? r324394 : r324396;
        return r324397;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

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

Derivation

  1. Split input into 2 regimes
  2. if x < -1.8227593907250866e+53 or 8.62450649905423e-72 < x

    1. Initial program 21.2

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

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

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

      \[\leadsto \color{blue}{\frac{x \cdot y}{z}} + x\]
    6. Using strategy rm
    7. Applied *-un-lft-identity7.2

      \[\leadsto \frac{x \cdot y}{\color{blue}{1 \cdot z}} + x\]
    8. Applied times-frac0.3

      \[\leadsto \color{blue}{\frac{x}{1} \cdot \frac{y}{z}} + x\]
    9. Applied fma-def0.3

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

    if -1.8227593907250866e+53 < x < 8.62450649905423e-72

    1. Initial program 5.7

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{x}{z}, y, x\right)}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification1.8

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -1.822759390725086618216460148861945165436 \cdot 10^{53} \lor \neg \left(x \le 8.624506499054229675094641740339480857407 \cdot 10^{-72}\right):\\ \;\;\;\;\mathsf{fma}\left(x, \frac{y}{z}, x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{x}{z}, y, x\right)\\ \end{array}\]

Reproduce

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