Average Error: 12.5 → 0.7
Time: 2.1s
Precision: 64
\[\frac{x \cdot \left(y + z\right)}{z}\]
\[\begin{array}{l} \mathbf{if}\;\frac{x \cdot \left(y + z\right)}{z} \le -2.8024718099763744 \cdot 10^{284}:\\ \;\;\;\;\mathsf{fma}\left(\frac{y}{z}, x, x\right)\\ \mathbf{elif}\;\frac{x \cdot \left(y + z\right)}{z} \le -2.72792898397245706 \cdot 10^{55}:\\ \;\;\;\;\frac{x \cdot \left(y + z\right)}{z}\\ \mathbf{elif}\;\frac{x \cdot \left(y + z\right)}{z} \le 1.6295824888591354 \cdot 10^{-81}:\\ \;\;\;\;\mathsf{fma}\left(\frac{y}{z}, x, x\right)\\ \mathbf{elif}\;\frac{x \cdot \left(y + z\right)}{z} \le 2.06201301805685587 \cdot 10^{265}:\\ \;\;\;\;\frac{x \cdot \left(y + z\right)}{z}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{\frac{z}{y + z}}\\ \end{array}\]
\frac{x \cdot \left(y + z\right)}{z}
\begin{array}{l}
\mathbf{if}\;\frac{x \cdot \left(y + z\right)}{z} \le -2.8024718099763744 \cdot 10^{284}:\\
\;\;\;\;\mathsf{fma}\left(\frac{y}{z}, x, x\right)\\

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

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

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

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

\end{array}
double f(double x, double y, double z) {
        double r465994 = x;
        double r465995 = y;
        double r465996 = z;
        double r465997 = r465995 + r465996;
        double r465998 = r465994 * r465997;
        double r465999 = r465998 / r465996;
        return r465999;
}

double f(double x, double y, double z) {
        double r466000 = x;
        double r466001 = y;
        double r466002 = z;
        double r466003 = r466001 + r466002;
        double r466004 = r466000 * r466003;
        double r466005 = r466004 / r466002;
        double r466006 = -2.8024718099763744e+284;
        bool r466007 = r466005 <= r466006;
        double r466008 = r466001 / r466002;
        double r466009 = fma(r466008, r466000, r466000);
        double r466010 = -2.727928983972457e+55;
        bool r466011 = r466005 <= r466010;
        double r466012 = 1.6295824888591354e-81;
        bool r466013 = r466005 <= r466012;
        double r466014 = 2.062013018056856e+265;
        bool r466015 = r466005 <= r466014;
        double r466016 = r466002 / r466003;
        double r466017 = r466000 / r466016;
        double r466018 = r466015 ? r466005 : r466017;
        double r466019 = r466013 ? r466009 : r466018;
        double r466020 = r466011 ? r466005 : r466019;
        double r466021 = r466007 ? r466009 : r466020;
        return r466021;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

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

Derivation

  1. Split input into 3 regimes
  2. if (/ (* x (+ y z)) z) < -2.8024718099763744e+284 or -2.727928983972457e+55 < (/ (* x (+ y z)) z) < 1.6295824888591354e-81

    1. Initial program 15.6

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

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

    if -2.8024718099763744e+284 < (/ (* x (+ y z)) z) < -2.727928983972457e+55 or 1.6295824888591354e-81 < (/ (* x (+ y z)) z) < 2.062013018056856e+265

    1. Initial program 0.3

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

    if 2.062013018056856e+265 < (/ (* x (+ y z)) z)

    1. Initial program 50.1

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{x \cdot \left(y + z\right)}{z} \le -2.8024718099763744 \cdot 10^{284}:\\ \;\;\;\;\mathsf{fma}\left(\frac{y}{z}, x, x\right)\\ \mathbf{elif}\;\frac{x \cdot \left(y + z\right)}{z} \le -2.72792898397245706 \cdot 10^{55}:\\ \;\;\;\;\frac{x \cdot \left(y + z\right)}{z}\\ \mathbf{elif}\;\frac{x \cdot \left(y + z\right)}{z} \le 1.6295824888591354 \cdot 10^{-81}:\\ \;\;\;\;\mathsf{fma}\left(\frac{y}{z}, x, x\right)\\ \mathbf{elif}\;\frac{x \cdot \left(y + z\right)}{z} \le 2.06201301805685587 \cdot 10^{265}:\\ \;\;\;\;\frac{x \cdot \left(y + z\right)}{z}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{\frac{z}{y + z}}\\ \end{array}\]

Reproduce

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