Average Error: 12.3 → 1.6
Time: 11.1s
Precision: 64
\[\frac{x \cdot \left(y + z\right)}{z}\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.255846650745649725506181831891083788832 \cdot 10^{-5} \lor \neg \left(x \le 1.503173573058023886830252677962462100403 \cdot 10^{-55}\right):\\ \;\;\;\;\mathsf{fma}\left(x, \frac{y}{z}, x\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot y}{z} + x\\ \end{array}\]
\frac{x \cdot \left(y + z\right)}{z}
\begin{array}{l}
\mathbf{if}\;x \le -1.255846650745649725506181831891083788832 \cdot 10^{-5} \lor \neg \left(x \le 1.503173573058023886830252677962462100403 \cdot 10^{-55}\right):\\
\;\;\;\;\mathsf{fma}\left(x, \frac{y}{z}, x\right)\\

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

\end{array}
double f(double x, double y, double z) {
        double r230667 = x;
        double r230668 = y;
        double r230669 = z;
        double r230670 = r230668 + r230669;
        double r230671 = r230667 * r230670;
        double r230672 = r230671 / r230669;
        return r230672;
}

double f(double x, double y, double z) {
        double r230673 = x;
        double r230674 = -1.2558466507456497e-05;
        bool r230675 = r230673 <= r230674;
        double r230676 = 1.5031735730580239e-55;
        bool r230677 = r230673 <= r230676;
        double r230678 = !r230677;
        bool r230679 = r230675 || r230678;
        double r230680 = y;
        double r230681 = z;
        double r230682 = r230680 / r230681;
        double r230683 = fma(r230673, r230682, r230673);
        double r230684 = r230673 * r230680;
        double r230685 = r230684 / r230681;
        double r230686 = r230685 + r230673;
        double r230687 = r230679 ? r230683 : r230686;
        return r230687;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original12.3
Target3.1
Herbie1.6
\[\frac{x}{\frac{z}{y + z}}\]

Derivation

  1. Split input into 2 regimes
  2. if x < -1.2558466507456497e-05 or 1.5031735730580239e-55 < x

    1. Initial program 19.5

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{x}{z}, y, x\right)}\]
    3. Using strategy rm
    4. Applied fma-udef6.5

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

      \[\leadsto \color{blue}{\frac{x \cdot y}{z}} + x\]
    6. Using strategy rm
    7. Applied *-un-lft-identity6.5

      \[\leadsto \color{blue}{1 \cdot \left(\frac{x \cdot y}{z} + x\right)}\]
    8. Using strategy rm
    9. Applied *-un-lft-identity6.5

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

      \[\leadsto 1 \cdot \left(\color{blue}{\frac{x}{1} \cdot \frac{y}{z}} + x\right)\]
    11. Applied fma-def0.3

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

    if -1.2558466507456497e-05 < x < 1.5031735730580239e-55

    1. Initial program 5.7

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{x}{z}, y, x\right)}\]
    3. Using strategy rm
    4. Applied fma-udef2.6

      \[\leadsto \color{blue}{\frac{x}{z} \cdot y + x}\]
    5. Simplified2.9

      \[\leadsto \color{blue}{\frac{x \cdot y}{z}} + x\]
    6. Using strategy rm
    7. Applied *-un-lft-identity2.9

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

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

Reproduce

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