Average Error: 12.4 → 0.5
Time: 2.6s
Precision: 64
\[\frac{x \cdot \left(y + z\right)}{z}\]
\[\begin{array}{l} \mathbf{if}\;\frac{x \cdot \left(y + z\right)}{z} = -\infty \lor \neg \left(\frac{x \cdot \left(y + z\right)}{z} \le -6.319320966689344821973508671251144897854 \cdot 10^{105} \lor \neg \left(\frac{x \cdot \left(y + z\right)}{z} \le 7.175875632447901705638090579257035271353 \cdot 10^{-115} \lor \neg \left(\frac{x \cdot \left(y + z\right)}{z} \le 4.748649064580130719772668610613105641524 \cdot 10^{302}\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} = -\infty \lor \neg \left(\frac{x \cdot \left(y + z\right)}{z} \le -6.319320966689344821973508671251144897854 \cdot 10^{105} \lor \neg \left(\frac{x \cdot \left(y + z\right)}{z} \le 7.175875632447901705638090579257035271353 \cdot 10^{-115} \lor \neg \left(\frac{x \cdot \left(y + z\right)}{z} \le 4.748649064580130719772668610613105641524 \cdot 10^{302}\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 r444105 = x;
        double r444106 = y;
        double r444107 = z;
        double r444108 = r444106 + r444107;
        double r444109 = r444105 * r444108;
        double r444110 = r444109 / r444107;
        return r444110;
}

double f(double x, double y, double z) {
        double r444111 = x;
        double r444112 = y;
        double r444113 = z;
        double r444114 = r444112 + r444113;
        double r444115 = r444111 * r444114;
        double r444116 = r444115 / r444113;
        double r444117 = -inf.0;
        bool r444118 = r444116 <= r444117;
        double r444119 = -6.319320966689345e+105;
        bool r444120 = r444116 <= r444119;
        double r444121 = 7.175875632447902e-115;
        bool r444122 = r444116 <= r444121;
        double r444123 = 4.748649064580131e+302;
        bool r444124 = r444116 <= r444123;
        double r444125 = !r444124;
        bool r444126 = r444122 || r444125;
        double r444127 = !r444126;
        bool r444128 = r444120 || r444127;
        double r444129 = !r444128;
        bool r444130 = r444118 || r444129;
        double r444131 = r444112 / r444113;
        double r444132 = fma(r444131, r444111, r444111);
        double r444133 = r444130 ? r444132 : r444116;
        return r444133;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original12.4
Target3.1
Herbie0.5
\[\frac{x}{\frac{z}{y + z}}\]

Derivation

  1. Split input into 2 regimes
  2. if (/ (* x (+ y z)) z) < -inf.0 or -6.319320966689345e+105 < (/ (* x (+ y z)) z) < 7.175875632447902e-115 or 4.748649064580131e+302 < (/ (* x (+ y z)) z)

    1. Initial program 21.6

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

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

    if -inf.0 < (/ (* x (+ y z)) z) < -6.319320966689345e+105 or 7.175875632447902e-115 < (/ (* x (+ y z)) z) < 4.748649064580131e+302

    1. Initial program 0.3

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{x \cdot \left(y + z\right)}{z} = -\infty \lor \neg \left(\frac{x \cdot \left(y + z\right)}{z} \le -6.319320966689344821973508671251144897854 \cdot 10^{105} \lor \neg \left(\frac{x \cdot \left(y + z\right)}{z} \le 7.175875632447901705638090579257035271353 \cdot 10^{-115} \lor \neg \left(\frac{x \cdot \left(y + z\right)}{z} \le 4.748649064580130719772668610613105641524 \cdot 10^{302}\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 2019354 +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))