Average Error: 12.6 → 1.9
Time: 10.4s
Precision: 64
\[\frac{x \cdot \left(y + z\right)}{z}\]
\[\begin{array}{l} \mathbf{if}\;x \le -8.016360700427365170842384714795056454403 \cdot 10^{-25} \lor \neg \left(x \le 4.552799791601321906213708917293087187758 \cdot 10^{-64}\right):\\ \;\;\;\;x \cdot \frac{y + z}{z}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{x}{z}, y, x\right)\\ \end{array}\]
\frac{x \cdot \left(y + z\right)}{z}
\begin{array}{l}
\mathbf{if}\;x \le -8.016360700427365170842384714795056454403 \cdot 10^{-25} \lor \neg \left(x \le 4.552799791601321906213708917293087187758 \cdot 10^{-64}\right):\\
\;\;\;\;x \cdot \frac{y + z}{z}\\

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

\end{array}
double f(double x, double y, double z) {
        double r326072 = x;
        double r326073 = y;
        double r326074 = z;
        double r326075 = r326073 + r326074;
        double r326076 = r326072 * r326075;
        double r326077 = r326076 / r326074;
        return r326077;
}

double f(double x, double y, double z) {
        double r326078 = x;
        double r326079 = -8.016360700427365e-25;
        bool r326080 = r326078 <= r326079;
        double r326081 = 4.552799791601322e-64;
        bool r326082 = r326078 <= r326081;
        double r326083 = !r326082;
        bool r326084 = r326080 || r326083;
        double r326085 = y;
        double r326086 = z;
        double r326087 = r326085 + r326086;
        double r326088 = r326087 / r326086;
        double r326089 = r326078 * r326088;
        double r326090 = r326078 / r326086;
        double r326091 = fma(r326090, r326085, r326078);
        double r326092 = r326084 ? r326089 : r326091;
        return r326092;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original12.6
Target3.0
Herbie1.9
\[\frac{x}{\frac{z}{y + z}}\]

Derivation

  1. Split input into 2 regimes
  2. if x < -8.016360700427365e-25 or 4.552799791601322e-64 < x

    1. Initial program 19.7

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

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

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

      \[\leadsto \color{blue}{x} \cdot \frac{y + z}{z}\]

    if -8.016360700427365e-25 < x < 4.552799791601322e-64

    1. Initial program 5.7

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{y}{z}, x, x\right)}\]
    3. Taylor expanded around 0 2.9

      \[\leadsto \color{blue}{\frac{x \cdot y}{z} + x}\]
    4. Simplified3.4

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{x}{z}, y, x\right)}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification1.9

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -8.016360700427365170842384714795056454403 \cdot 10^{-25} \lor \neg \left(x \le 4.552799791601321906213708917293087187758 \cdot 10^{-64}\right):\\ \;\;\;\;x \cdot \frac{y + z}{z}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{x}{z}, y, x\right)\\ \end{array}\]

Reproduce

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