Average Error: 12.7 → 0.6
Time: 4.7m
Precision: 64
\[\frac{x \cdot \left(y + z\right)}{z}\]
\[\begin{array}{l} \mathbf{if}\;\frac{\left(y + z\right) \cdot x}{z} \le -3.0073521019309817 \cdot 10^{+304}:\\ \;\;\;\;\mathsf{fma}\left(y, \frac{x}{z}, x\right)\\ \mathbf{elif}\;\frac{\left(y + z\right) \cdot x}{z} \le -1.3011950233325992 \cdot 10^{-208}:\\ \;\;\;\;\frac{\left(y + z\right) \cdot x}{z}\\ \mathbf{elif}\;\frac{\left(y + z\right) \cdot x}{z} \le 2.3953532986264383 \cdot 10^{-287}:\\ \;\;\;\;\mathsf{fma}\left(y, \frac{x}{z}, x\right)\\ \mathbf{elif}\;\frac{\left(y + z\right) \cdot x}{z} \le 9.523381845879275 \cdot 10^{+302}:\\ \;\;\;\;\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 -3.0073521019309817 \cdot 10^{+304}:\\
\;\;\;\;\mathsf{fma}\left(y, \frac{x}{z}, x\right)\\

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

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

\mathbf{elif}\;\frac{\left(y + z\right) \cdot x}{z} \le 9.523381845879275 \cdot 10^{+302}:\\
\;\;\;\;\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 r16648435 = x;
        double r16648436 = y;
        double r16648437 = z;
        double r16648438 = r16648436 + r16648437;
        double r16648439 = r16648435 * r16648438;
        double r16648440 = r16648439 / r16648437;
        return r16648440;
}

double f(double x, double y, double z) {
        double r16648441 = y;
        double r16648442 = z;
        double r16648443 = r16648441 + r16648442;
        double r16648444 = x;
        double r16648445 = r16648443 * r16648444;
        double r16648446 = r16648445 / r16648442;
        double r16648447 = -3.0073521019309817e+304;
        bool r16648448 = r16648446 <= r16648447;
        double r16648449 = r16648444 / r16648442;
        double r16648450 = fma(r16648441, r16648449, r16648444);
        double r16648451 = -1.3011950233325992e-208;
        bool r16648452 = r16648446 <= r16648451;
        double r16648453 = 2.3953532986264383e-287;
        bool r16648454 = r16648446 <= r16648453;
        double r16648455 = 9.523381845879275e+302;
        bool r16648456 = r16648446 <= r16648455;
        double r16648457 = r16648456 ? r16648446 : r16648450;
        double r16648458 = r16648454 ? r16648450 : r16648457;
        double r16648459 = r16648452 ? r16648446 : r16648458;
        double r16648460 = r16648448 ? r16648450 : r16648459;
        return r16648460;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original12.7
Target3.2
Herbie0.6
\[\frac{x}{\frac{z}{y + z}}\]

Derivation

  1. Split input into 2 regimes
  2. if (/ (* x (+ y z)) z) < -3.0073521019309817e+304 or -1.3011950233325992e-208 < (/ (* x (+ y z)) z) < 2.3953532986264383e-287 or 9.523381845879275e+302 < (/ (* x (+ y z)) z)

    1. Initial program 48.6

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

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

    if -3.0073521019309817e+304 < (/ (* x (+ y z)) z) < -1.3011950233325992e-208 or 2.3953532986264383e-287 < (/ (* x (+ y z)) z) < 9.523381845879275e+302

    1. Initial program 0.4

      \[\frac{x \cdot \left(y + z\right)}{z}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.6

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{\left(y + z\right) \cdot x}{z} \le -3.0073521019309817 \cdot 10^{+304}:\\ \;\;\;\;\mathsf{fma}\left(y, \frac{x}{z}, x\right)\\ \mathbf{elif}\;\frac{\left(y + z\right) \cdot x}{z} \le -1.3011950233325992 \cdot 10^{-208}:\\ \;\;\;\;\frac{\left(y + z\right) \cdot x}{z}\\ \mathbf{elif}\;\frac{\left(y + z\right) \cdot x}{z} \le 2.3953532986264383 \cdot 10^{-287}:\\ \;\;\;\;\mathsf{fma}\left(y, \frac{x}{z}, x\right)\\ \mathbf{elif}\;\frac{\left(y + z\right) \cdot x}{z} \le 9.523381845879275 \cdot 10^{+302}:\\ \;\;\;\;\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 2019165 +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))