Average Error: 12.6 → 1.8
Time: 16.2s
Precision: 64
\[\frac{x \cdot \left(y + z\right)}{z}\]
\[\begin{array}{l} \mathbf{if}\;x \le -6.7211027786086989 \cdot 10^{76} \lor \neg \left(x \le 4.2219806557969334 \cdot 10^{-26}\right):\\ \;\;\;\;\frac{x}{\frac{z}{y}} + x\\ \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 -6.7211027786086989 \cdot 10^{76} \lor \neg \left(x \le 4.2219806557969334 \cdot 10^{-26}\right):\\
\;\;\;\;\frac{x}{\frac{z}{y}} + x\\

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

\end{array}
double f(double x, double y, double z) {
        double r293358 = x;
        double r293359 = y;
        double r293360 = z;
        double r293361 = r293359 + r293360;
        double r293362 = r293358 * r293361;
        double r293363 = r293362 / r293360;
        return r293363;
}

double f(double x, double y, double z) {
        double r293364 = x;
        double r293365 = -6.721102778608699e+76;
        bool r293366 = r293364 <= r293365;
        double r293367 = 4.2219806557969334e-26;
        bool r293368 = r293364 <= r293367;
        double r293369 = !r293368;
        bool r293370 = r293366 || r293369;
        double r293371 = z;
        double r293372 = y;
        double r293373 = r293371 / r293372;
        double r293374 = r293364 / r293373;
        double r293375 = r293374 + r293364;
        double r293376 = r293364 / r293371;
        double r293377 = fma(r293376, r293372, r293364);
        double r293378 = r293370 ? r293375 : r293377;
        return r293378;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

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

Derivation

  1. Split input into 2 regimes
  2. if x < -6.721102778608699e+76 or 4.2219806557969334e-26 < x

    1. Initial program 23.5

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

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

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

      \[\leadsto \color{blue}{\frac{x \cdot y}{z}} + x\]
    6. Using strategy rm
    7. Applied associate-/l*0.1

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

    if -6.721102778608699e+76 < x < 4.2219806557969334e-26

    1. Initial program 5.7

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

      \[\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 -6.7211027786086989 \cdot 10^{76} \lor \neg \left(x \le 4.2219806557969334 \cdot 10^{-26}\right):\\ \;\;\;\;\frac{x}{\frac{z}{y}} + x\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{x}{z}, y, x\right)\\ \end{array}\]

Reproduce

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