Average Error: 12.6 → 2.6
Time: 1.8s
Precision: 64
\[\frac{x \cdot \left(y + z\right)}{z}\]
\[\begin{array}{l} \mathbf{if}\;y \le -1.653007623578952 \cdot 10^{102}:\\ \;\;\;\;\mathsf{fma}\left(y, \frac{x}{z}, x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{y}{z}, x, x\right)\\ \end{array}\]
\frac{x \cdot \left(y + z\right)}{z}
\begin{array}{l}
\mathbf{if}\;y \le -1.653007623578952 \cdot 10^{102}:\\
\;\;\;\;\mathsf{fma}\left(y, \frac{x}{z}, x\right)\\

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

\end{array}
double f(double x, double y, double z) {
        double r432027 = x;
        double r432028 = y;
        double r432029 = z;
        double r432030 = r432028 + r432029;
        double r432031 = r432027 * r432030;
        double r432032 = r432031 / r432029;
        return r432032;
}

double f(double x, double y, double z) {
        double r432033 = y;
        double r432034 = -1.653007623578952e+102;
        bool r432035 = r432033 <= r432034;
        double r432036 = x;
        double r432037 = z;
        double r432038 = r432036 / r432037;
        double r432039 = fma(r432033, r432038, r432036);
        double r432040 = r432033 / r432037;
        double r432041 = fma(r432040, r432036, r432036);
        double r432042 = r432035 ? r432039 : r432041;
        return r432042;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original12.6
Target3.0
Herbie2.6
\[\frac{x}{\frac{z}{y + z}}\]

Derivation

  1. Split input into 2 regimes
  2. if y < -1.653007623578952e+102

    1. Initial program 11.5

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

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

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

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

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

      \[\leadsto y \cdot \color{blue}{\frac{x}{z}} + x\]
    9. Using strategy rm
    10. Applied fma-def5.7

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

    if -1.653007623578952e+102 < y

    1. Initial program 12.8

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

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

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

Reproduce

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