Average Error: 14.7 → 0.0
Time: 3.0s
Precision: 64
\[\frac{x}{x \cdot x + 1}\]
\[\begin{array}{l} \mathbf{if}\;x \le -3787.2690012206258 \lor \neg \left(x \le 19.9196551064145986\right):\\ \;\;\;\;\mathsf{fma}\left(1, \frac{1}{{x}^{9}}, \mathsf{fma}\left(1, \frac{1}{{x}^{5}}, \frac{1}{x}\right)\right) + \frac{x}{\mathsf{fma}\left(-1, 1, {x}^{4}\right)} \cdot \left(-1\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{\mathsf{fma}\left(-1, 1, {x}^{4}\right)} \cdot \left(x \cdot x - 1\right)\\ \end{array}\]
\frac{x}{x \cdot x + 1}
\begin{array}{l}
\mathbf{if}\;x \le -3787.2690012206258 \lor \neg \left(x \le 19.9196551064145986\right):\\
\;\;\;\;\mathsf{fma}\left(1, \frac{1}{{x}^{9}}, \mathsf{fma}\left(1, \frac{1}{{x}^{5}}, \frac{1}{x}\right)\right) + \frac{x}{\mathsf{fma}\left(-1, 1, {x}^{4}\right)} \cdot \left(-1\right)\\

\mathbf{else}:\\
\;\;\;\;\frac{x}{\mathsf{fma}\left(-1, 1, {x}^{4}\right)} \cdot \left(x \cdot x - 1\right)\\

\end{array}
double f(double x) {
        double r61019 = x;
        double r61020 = r61019 * r61019;
        double r61021 = 1.0;
        double r61022 = r61020 + r61021;
        double r61023 = r61019 / r61022;
        return r61023;
}

double f(double x) {
        double r61024 = x;
        double r61025 = -3787.269001220626;
        bool r61026 = r61024 <= r61025;
        double r61027 = 19.9196551064146;
        bool r61028 = r61024 <= r61027;
        double r61029 = !r61028;
        bool r61030 = r61026 || r61029;
        double r61031 = 1.0;
        double r61032 = 1.0;
        double r61033 = 9.0;
        double r61034 = pow(r61024, r61033);
        double r61035 = r61032 / r61034;
        double r61036 = 5.0;
        double r61037 = pow(r61024, r61036);
        double r61038 = r61032 / r61037;
        double r61039 = r61032 / r61024;
        double r61040 = fma(r61031, r61038, r61039);
        double r61041 = fma(r61031, r61035, r61040);
        double r61042 = -r61031;
        double r61043 = 4.0;
        double r61044 = pow(r61024, r61043);
        double r61045 = fma(r61042, r61031, r61044);
        double r61046 = r61024 / r61045;
        double r61047 = r61046 * r61042;
        double r61048 = r61041 + r61047;
        double r61049 = r61024 * r61024;
        double r61050 = r61049 - r61031;
        double r61051 = r61046 * r61050;
        double r61052 = r61030 ? r61048 : r61051;
        return r61052;
}

Error

Bits error versus x

Target

Original14.7
Target0.1
Herbie0.0
\[\frac{1}{x + \frac{1}{x}}\]

Derivation

  1. Split input into 2 regimes
  2. if x < -3787.269001220626 or 19.9196551064146 < x

    1. Initial program 29.7

      \[\frac{x}{x \cdot x + 1}\]
    2. Using strategy rm
    3. Applied flip-+47.0

      \[\leadsto \frac{x}{\color{blue}{\frac{\left(x \cdot x\right) \cdot \left(x \cdot x\right) - 1 \cdot 1}{x \cdot x - 1}}}\]
    4. Applied associate-/r/47.1

      \[\leadsto \color{blue}{\frac{x}{\left(x \cdot x\right) \cdot \left(x \cdot x\right) - 1 \cdot 1} \cdot \left(x \cdot x - 1\right)}\]
    5. Simplified47.1

      \[\leadsto \color{blue}{\frac{x}{\mathsf{fma}\left(-1, 1, {x}^{4}\right)}} \cdot \left(x \cdot x - 1\right)\]
    6. Using strategy rm
    7. Applied sub-neg47.1

      \[\leadsto \frac{x}{\mathsf{fma}\left(-1, 1, {x}^{4}\right)} \cdot \color{blue}{\left(x \cdot x + \left(-1\right)\right)}\]
    8. Applied distribute-lft-in47.1

      \[\leadsto \color{blue}{\frac{x}{\mathsf{fma}\left(-1, 1, {x}^{4}\right)} \cdot \left(x \cdot x\right) + \frac{x}{\mathsf{fma}\left(-1, 1, {x}^{4}\right)} \cdot \left(-1\right)}\]
    9. Simplified47.5

      \[\leadsto \color{blue}{\frac{{x}^{3}}{\mathsf{fma}\left(-1, 1, {x}^{4}\right)}} + \frac{x}{\mathsf{fma}\left(-1, 1, {x}^{4}\right)} \cdot \left(-1\right)\]
    10. Taylor expanded around inf 0.0

      \[\leadsto \color{blue}{\left(1 \cdot \frac{1}{{x}^{9}} + \left(1 \cdot \frac{1}{{x}^{5}} + \frac{1}{x}\right)\right)} + \frac{x}{\mathsf{fma}\left(-1, 1, {x}^{4}\right)} \cdot \left(-1\right)\]
    11. Simplified0.0

      \[\leadsto \color{blue}{\mathsf{fma}\left(1, \frac{1}{{x}^{9}}, \mathsf{fma}\left(1, \frac{1}{{x}^{5}}, \frac{1}{x}\right)\right)} + \frac{x}{\mathsf{fma}\left(-1, 1, {x}^{4}\right)} \cdot \left(-1\right)\]

    if -3787.269001220626 < x < 19.9196551064146

    1. Initial program 0.0

      \[\frac{x}{x \cdot x + 1}\]
    2. Using strategy rm
    3. Applied flip-+0.0

      \[\leadsto \frac{x}{\color{blue}{\frac{\left(x \cdot x\right) \cdot \left(x \cdot x\right) - 1 \cdot 1}{x \cdot x - 1}}}\]
    4. Applied associate-/r/0.0

      \[\leadsto \color{blue}{\frac{x}{\left(x \cdot x\right) \cdot \left(x \cdot x\right) - 1 \cdot 1} \cdot \left(x \cdot x - 1\right)}\]
    5. Simplified0.0

      \[\leadsto \color{blue}{\frac{x}{\mathsf{fma}\left(-1, 1, {x}^{4}\right)}} \cdot \left(x \cdot x - 1\right)\]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.0

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -3787.2690012206258 \lor \neg \left(x \le 19.9196551064145986\right):\\ \;\;\;\;\mathsf{fma}\left(1, \frac{1}{{x}^{9}}, \mathsf{fma}\left(1, \frac{1}{{x}^{5}}, \frac{1}{x}\right)\right) + \frac{x}{\mathsf{fma}\left(-1, 1, {x}^{4}\right)} \cdot \left(-1\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{\mathsf{fma}\left(-1, 1, {x}^{4}\right)} \cdot \left(x \cdot x - 1\right)\\ \end{array}\]

Reproduce

herbie shell --seed 2020027 +o rules:numerics
(FPCore (x)
  :name "x / (x^2 + 1)"
  :precision binary64

  :herbie-target
  (/ 1 (+ x (/ 1 x)))

  (/ x (+ (* x x) 1)))