Average Error: 13.0 → 0.6
Time: 14.3s
Precision: 64
\[\frac{x \cdot \left(y + z\right)}{z}\]
\[\begin{array}{l} \mathbf{if}\;\frac{\left(y + z\right) \cdot x}{z} \le -4.073166165574361464408320689937250424044 \cdot 10^{294}:\\ \;\;\;\;\mathsf{fma}\left(y, \frac{x}{z}, x\right)\\ \mathbf{elif}\;\frac{\left(y + z\right) \cdot x}{z} \le -1.074386046725077208279245167890270635099 \cdot 10^{-215}:\\ \;\;\;\;\frac{\left(y + z\right) \cdot x}{z}\\ \mathbf{elif}\;\frac{\left(y + z\right) \cdot x}{z} \le 4.055281378633951231577706418563709391147 \cdot 10^{-95}:\\ \;\;\;\;x \cdot \frac{y + z}{z}\\ \mathbf{elif}\;\frac{\left(y + z\right) \cdot x}{z} \le 1.284288781303400225636776173581348772622 \cdot 10^{300}:\\ \;\;\;\;\frac{\left(y + z\right) \cdot x}{z}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(y, \frac{x}{z}, x\right)\\ \end{array}\]
\frac{x \cdot \left(y + z\right)}{z}
\begin{array}{l}
\mathbf{if}\;\frac{\left(y + z\right) \cdot x}{z} \le -4.073166165574361464408320689937250424044 \cdot 10^{294}:\\
\;\;\;\;\mathsf{fma}\left(y, \frac{x}{z}, x\right)\\

\mathbf{elif}\;\frac{\left(y + z\right) \cdot x}{z} \le -1.074386046725077208279245167890270635099 \cdot 10^{-215}:\\
\;\;\;\;\frac{\left(y + z\right) \cdot x}{z}\\

\mathbf{elif}\;\frac{\left(y + z\right) \cdot x}{z} \le 4.055281378633951231577706418563709391147 \cdot 10^{-95}:\\
\;\;\;\;x \cdot \frac{y + z}{z}\\

\mathbf{elif}\;\frac{\left(y + z\right) \cdot x}{z} \le 1.284288781303400225636776173581348772622 \cdot 10^{300}:\\
\;\;\;\;\frac{\left(y + z\right) \cdot x}{z}\\

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

\end{array}
double f(double x, double y, double z) {
        double r21083142 = x;
        double r21083143 = y;
        double r21083144 = z;
        double r21083145 = r21083143 + r21083144;
        double r21083146 = r21083142 * r21083145;
        double r21083147 = r21083146 / r21083144;
        return r21083147;
}

double f(double x, double y, double z) {
        double r21083148 = y;
        double r21083149 = z;
        double r21083150 = r21083148 + r21083149;
        double r21083151 = x;
        double r21083152 = r21083150 * r21083151;
        double r21083153 = r21083152 / r21083149;
        double r21083154 = -4.0731661655743615e+294;
        bool r21083155 = r21083153 <= r21083154;
        double r21083156 = r21083151 / r21083149;
        double r21083157 = fma(r21083148, r21083156, r21083151);
        double r21083158 = -1.0743860467250772e-215;
        bool r21083159 = r21083153 <= r21083158;
        double r21083160 = 4.055281378633951e-95;
        bool r21083161 = r21083153 <= r21083160;
        double r21083162 = r21083150 / r21083149;
        double r21083163 = r21083151 * r21083162;
        double r21083164 = 1.2842887813034002e+300;
        bool r21083165 = r21083153 <= r21083164;
        double r21083166 = r21083165 ? r21083153 : r21083157;
        double r21083167 = r21083161 ? r21083163 : r21083166;
        double r21083168 = r21083159 ? r21083153 : r21083167;
        double r21083169 = r21083155 ? r21083157 : r21083168;
        return r21083169;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original13.0
Target3.1
Herbie0.6
\[\frac{x}{\frac{z}{y + z}}\]

Derivation

  1. Split input into 3 regimes
  2. if (/ (* x (+ y z)) z) < -4.0731661655743615e+294 or 1.2842887813034002e+300 < (/ (* x (+ y z)) z)

    1. Initial program 59.6

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

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

    if -4.0731661655743615e+294 < (/ (* x (+ y z)) z) < -1.0743860467250772e-215 or 4.055281378633951e-95 < (/ (* x (+ y z)) z) < 1.2842887813034002e+300

    1. Initial program 0.3

      \[\frac{x \cdot \left(y + z\right)}{z}\]

    if -1.0743860467250772e-215 < (/ (* x (+ y z)) z) < 4.055281378633951e-95

    1. Initial program 13.9

      \[\frac{x \cdot \left(y + z\right)}{z}\]
    2. Using strategy rm
    3. Applied *-un-lft-identity13.9

      \[\leadsto \frac{x \cdot \left(y + z\right)}{\color{blue}{1 \cdot z}}\]
    4. Applied times-frac0.1

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{\left(y + z\right) \cdot x}{z} \le -4.073166165574361464408320689937250424044 \cdot 10^{294}:\\ \;\;\;\;\mathsf{fma}\left(y, \frac{x}{z}, x\right)\\ \mathbf{elif}\;\frac{\left(y + z\right) \cdot x}{z} \le -1.074386046725077208279245167890270635099 \cdot 10^{-215}:\\ \;\;\;\;\frac{\left(y + z\right) \cdot x}{z}\\ \mathbf{elif}\;\frac{\left(y + z\right) \cdot x}{z} \le 4.055281378633951231577706418563709391147 \cdot 10^{-95}:\\ \;\;\;\;x \cdot \frac{y + z}{z}\\ \mathbf{elif}\;\frac{\left(y + z\right) \cdot x}{z} \le 1.284288781303400225636776173581348772622 \cdot 10^{300}:\\ \;\;\;\;\frac{\left(y + z\right) \cdot x}{z}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(y, \frac{x}{z}, x\right)\\ \end{array}\]

Reproduce

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