Average Error: 12.6 → 2.4
Time: 2.1s
Precision: 64
\[\frac{x \cdot \left(y + z\right)}{z}\]
\[\begin{array}{l} \mathbf{if}\;y \le -2.6033079480859914 \cdot 10^{30}:\\ \;\;\;\;\mathsf{fma}\left(\frac{x}{z}, y, 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 -2.6033079480859914 \cdot 10^{30}:\\
\;\;\;\;\mathsf{fma}\left(\frac{x}{z}, y, x\right)\\

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

\end{array}
double f(double x, double y, double z) {
        double r433567 = x;
        double r433568 = y;
        double r433569 = z;
        double r433570 = r433568 + r433569;
        double r433571 = r433567 * r433570;
        double r433572 = r433571 / r433569;
        return r433572;
}

double f(double x, double y, double z) {
        double r433573 = y;
        double r433574 = -2.6033079480859914e+30;
        bool r433575 = r433573 <= r433574;
        double r433576 = x;
        double r433577 = z;
        double r433578 = r433576 / r433577;
        double r433579 = fma(r433578, r433573, r433576);
        double r433580 = r433573 / r433577;
        double r433581 = fma(r433580, r433576, r433576);
        double r433582 = r433575 ? r433579 : r433581;
        return r433582;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

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

Derivation

  1. Split input into 2 regimes
  2. if y < -2.6033079480859914e+30

    1. Initial program 11.2

      \[\frac{x \cdot \left(y + z\right)}{z}\]
    2. Taylor expanded around 0 8.5

      \[\leadsto \color{blue}{\frac{x \cdot y}{z} + x}\]
    3. Simplified3.6

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

    if -2.6033079480859914e+30 < y

    1. Initial program 13.0

      \[\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.4

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

Reproduce

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