Average Error: 12.5 → 0.7
Time: 2.2s
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} \lor \neg \left(\frac{x \cdot \left(y + z\right)}{z} \le -2.72792898397245706 \cdot 10^{55} \lor \neg \left(\frac{x \cdot \left(y + z\right)}{z} \le 1.6295824888591354 \cdot 10^{-81} \lor \neg \left(\frac{x \cdot \left(y + z\right)}{z} \le 2.06201301805685587 \cdot 10^{265}\right)\right)\right):\\ \;\;\;\;\mathsf{fma}\left(\frac{y}{z}, x, x\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot \left(y + z\right)}{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} \lor \neg \left(\frac{x \cdot \left(y + z\right)}{z} \le -2.72792898397245706 \cdot 10^{55} \lor \neg \left(\frac{x \cdot \left(y + z\right)}{z} \le 1.6295824888591354 \cdot 10^{-81} \lor \neg \left(\frac{x \cdot \left(y + z\right)}{z} \le 2.06201301805685587 \cdot 10^{265}\right)\right)\right):\\
\;\;\;\;\mathsf{fma}\left(\frac{y}{z}, x, x\right)\\

\mathbf{else}:\\
\;\;\;\;\frac{x \cdot \left(y + z\right)}{z}\\

\end{array}
double f(double x, double y, double z) {
        double r379700 = x;
        double r379701 = y;
        double r379702 = z;
        double r379703 = r379701 + r379702;
        double r379704 = r379700 * r379703;
        double r379705 = r379704 / r379702;
        return r379705;
}

double f(double x, double y, double z) {
        double r379706 = x;
        double r379707 = y;
        double r379708 = z;
        double r379709 = r379707 + r379708;
        double r379710 = r379706 * r379709;
        double r379711 = r379710 / r379708;
        double r379712 = -2.8024718099763744e+284;
        bool r379713 = r379711 <= r379712;
        double r379714 = -2.727928983972457e+55;
        bool r379715 = r379711 <= r379714;
        double r379716 = 1.6295824888591354e-81;
        bool r379717 = r379711 <= r379716;
        double r379718 = 2.062013018056856e+265;
        bool r379719 = r379711 <= r379718;
        double r379720 = !r379719;
        bool r379721 = r379717 || r379720;
        double r379722 = !r379721;
        bool r379723 = r379715 || r379722;
        double r379724 = !r379723;
        bool r379725 = r379713 || r379724;
        double r379726 = r379707 / r379708;
        double r379727 = fma(r379726, r379706, r379706);
        double r379728 = r379725 ? r379727 : r379711;
        return r379728;
}

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 2 regimes
  2. if (/ (* x (+ y z)) z) < -2.8024718099763744e+284 or -2.727928983972457e+55 < (/ (* x (+ y z)) z) < 1.6295824888591354e-81 or 2.062013018056856e+265 < (/ (* x (+ y z)) z)

    1. Initial program 21.3

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

      \[\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}\]
  3. Recombined 2 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} \lor \neg \left(\frac{x \cdot \left(y + z\right)}{z} \le -2.72792898397245706 \cdot 10^{55} \lor \neg \left(\frac{x \cdot \left(y + z\right)}{z} \le 1.6295824888591354 \cdot 10^{-81} \lor \neg \left(\frac{x \cdot \left(y + z\right)}{z} \le 2.06201301805685587 \cdot 10^{265}\right)\right)\right):\\ \;\;\;\;\mathsf{fma}\left(\frac{y}{z}, x, x\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot \left(y + z\right)}{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))