Average Error: 12.4 → 2.2
Time: 2.1s
Precision: 64
\[\frac{x \cdot \left(y + z\right)}{z}\]
\[\begin{array}{l} \mathbf{if}\;x \le -6.32812940840826245 \cdot 10^{-198}:\\ \;\;\;\;\mathsf{fma}\left(\frac{y}{z}, x, x\right)\\ \mathbf{elif}\;x \le 2.0356444854556903 \cdot 10^{-15}:\\ \;\;\;\;\mathsf{fma}\left(\frac{x}{z}, y, x\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{\frac{z}{y + z}}\\ \end{array}\]
\frac{x \cdot \left(y + z\right)}{z}
\begin{array}{l}
\mathbf{if}\;x \le -6.32812940840826245 \cdot 10^{-198}:\\
\;\;\;\;\mathsf{fma}\left(\frac{y}{z}, x, x\right)\\

\mathbf{elif}\;x \le 2.0356444854556903 \cdot 10^{-15}:\\
\;\;\;\;\mathsf{fma}\left(\frac{x}{z}, y, x\right)\\

\mathbf{else}:\\
\;\;\;\;\frac{x}{\frac{z}{y + z}}\\

\end{array}
double f(double x, double y, double z) {
        double r449835 = x;
        double r449836 = y;
        double r449837 = z;
        double r449838 = r449836 + r449837;
        double r449839 = r449835 * r449838;
        double r449840 = r449839 / r449837;
        return r449840;
}

double f(double x, double y, double z) {
        double r449841 = x;
        double r449842 = -6.3281294084082624e-198;
        bool r449843 = r449841 <= r449842;
        double r449844 = y;
        double r449845 = z;
        double r449846 = r449844 / r449845;
        double r449847 = fma(r449846, r449841, r449841);
        double r449848 = 2.0356444854556903e-15;
        bool r449849 = r449841 <= r449848;
        double r449850 = r449841 / r449845;
        double r449851 = fma(r449850, r449844, r449841);
        double r449852 = r449844 + r449845;
        double r449853 = r449845 / r449852;
        double r449854 = r449841 / r449853;
        double r449855 = r449849 ? r449851 : r449854;
        double r449856 = r449843 ? r449847 : r449855;
        return r449856;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original12.4
Target2.9
Herbie2.2
\[\frac{x}{\frac{z}{y + z}}\]

Derivation

  1. Split input into 3 regimes
  2. if x < -6.3281294084082624e-198

    1. Initial program 13.1

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

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

    if -6.3281294084082624e-198 < x < 2.0356444854556903e-15

    1. Initial program 6.8

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

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

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

    if 2.0356444854556903e-15 < x

    1. Initial program 20.8

      \[\frac{x \cdot \left(y + z\right)}{z}\]
    2. Using strategy rm
    3. Applied associate-/l*0.1

      \[\leadsto \color{blue}{\frac{x}{\frac{z}{y + z}}}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification2.2

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -6.32812940840826245 \cdot 10^{-198}:\\ \;\;\;\;\mathsf{fma}\left(\frac{y}{z}, x, x\right)\\ \mathbf{elif}\;x \le 2.0356444854556903 \cdot 10^{-15}:\\ \;\;\;\;\mathsf{fma}\left(\frac{x}{z}, y, x\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{\frac{z}{y + z}}\\ \end{array}\]

Reproduce

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