Average Error: 15.2 → 0.3
Time: 23.9s
Precision: 64
\[1 - \sqrt{\frac{1}{2} \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)}\]
\[\begin{array}{l} \mathbf{if}\;\mathsf{hypot}\left(1, x\right) \le 1.0000000000000007:\\ \;\;\;\;\mathsf{fma}\left(\left(x \cdot x\right) \cdot \left(x \cdot x\right), \frac{-11}{128}, \mathsf{fma}\left(x \cdot x, \frac{1}{8}, \left(\frac{69}{1024} \cdot \left(x \cdot x\right)\right) \cdot \left(\left(x \cdot x\right) \cdot \left(x \cdot x\right)\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\log \left(e^{1 - \left(\frac{1}{2} + \frac{\frac{1}{2}}{\mathsf{hypot}\left(1, x\right)}\right)}\right)}{1 + \frac{\sqrt{\mathsf{fma}\left(\frac{\frac{1}{2}}{\mathsf{hypot}\left(1, x\right)}, \frac{\frac{1}{2}}{\mathsf{hypot}\left(1, x\right)} \cdot \frac{\frac{1}{2}}{\mathsf{hypot}\left(1, x\right)}, \frac{1}{8}\right)}}{\sqrt{\frac{1}{4} - \frac{\frac{1}{2}}{\mathsf{hypot}\left(1, x\right)} \cdot \left(\frac{1}{2} - \frac{\frac{1}{2}}{\mathsf{hypot}\left(1, x\right)}\right)}}}\\ \end{array}\]
1 - \sqrt{\frac{1}{2} \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)}
\begin{array}{l}
\mathbf{if}\;\mathsf{hypot}\left(1, x\right) \le 1.0000000000000007:\\
\;\;\;\;\mathsf{fma}\left(\left(x \cdot x\right) \cdot \left(x \cdot x\right), \frac{-11}{128}, \mathsf{fma}\left(x \cdot x, \frac{1}{8}, \left(\frac{69}{1024} \cdot \left(x \cdot x\right)\right) \cdot \left(\left(x \cdot x\right) \cdot \left(x \cdot x\right)\right)\right)\right)\\

\mathbf{else}:\\
\;\;\;\;\frac{\log \left(e^{1 - \left(\frac{1}{2} + \frac{\frac{1}{2}}{\mathsf{hypot}\left(1, x\right)}\right)}\right)}{1 + \frac{\sqrt{\mathsf{fma}\left(\frac{\frac{1}{2}}{\mathsf{hypot}\left(1, x\right)}, \frac{\frac{1}{2}}{\mathsf{hypot}\left(1, x\right)} \cdot \frac{\frac{1}{2}}{\mathsf{hypot}\left(1, x\right)}, \frac{1}{8}\right)}}{\sqrt{\frac{1}{4} - \frac{\frac{1}{2}}{\mathsf{hypot}\left(1, x\right)} \cdot \left(\frac{1}{2} - \frac{\frac{1}{2}}{\mathsf{hypot}\left(1, x\right)}\right)}}}\\

\end{array}
double f(double x) {
        double r4360405 = 1.0;
        double r4360406 = 0.5;
        double r4360407 = x;
        double r4360408 = hypot(r4360405, r4360407);
        double r4360409 = r4360405 / r4360408;
        double r4360410 = r4360405 + r4360409;
        double r4360411 = r4360406 * r4360410;
        double r4360412 = sqrt(r4360411);
        double r4360413 = r4360405 - r4360412;
        return r4360413;
}

double f(double x) {
        double r4360414 = 1.0;
        double r4360415 = x;
        double r4360416 = hypot(r4360414, r4360415);
        double r4360417 = 1.0000000000000007;
        bool r4360418 = r4360416 <= r4360417;
        double r4360419 = r4360415 * r4360415;
        double r4360420 = r4360419 * r4360419;
        double r4360421 = -0.0859375;
        double r4360422 = 0.125;
        double r4360423 = 0.0673828125;
        double r4360424 = r4360423 * r4360419;
        double r4360425 = r4360424 * r4360420;
        double r4360426 = fma(r4360419, r4360422, r4360425);
        double r4360427 = fma(r4360420, r4360421, r4360426);
        double r4360428 = 0.5;
        double r4360429 = r4360428 / r4360416;
        double r4360430 = r4360428 + r4360429;
        double r4360431 = r4360414 - r4360430;
        double r4360432 = exp(r4360431);
        double r4360433 = log(r4360432);
        double r4360434 = r4360429 * r4360429;
        double r4360435 = fma(r4360429, r4360434, r4360422);
        double r4360436 = sqrt(r4360435);
        double r4360437 = 0.25;
        double r4360438 = r4360428 - r4360429;
        double r4360439 = r4360429 * r4360438;
        double r4360440 = r4360437 - r4360439;
        double r4360441 = sqrt(r4360440);
        double r4360442 = r4360436 / r4360441;
        double r4360443 = r4360414 + r4360442;
        double r4360444 = r4360433 / r4360443;
        double r4360445 = r4360418 ? r4360427 : r4360444;
        return r4360445;
}

Error

Bits error versus x

Derivation

  1. Split input into 2 regimes
  2. if (hypot 1 x) < 1.0000000000000007

    1. Initial program 29.9

      \[1 - \sqrt{\frac{1}{2} \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)}\]
    2. Simplified29.9

      \[\leadsto \color{blue}{1 - \sqrt{\frac{1}{2} + \frac{\frac{1}{2}}{\mathsf{hypot}\left(1, x\right)}}}\]
    3. Taylor expanded around 0 0.0

      \[\leadsto \color{blue}{\left(\frac{1}{8} \cdot {x}^{2} + \frac{69}{1024} \cdot {x}^{6}\right) - \frac{11}{128} \cdot {x}^{4}}\]
    4. Simplified0.0

      \[\leadsto \color{blue}{\mathsf{fma}\left(\left(x \cdot x\right) \cdot \left(x \cdot x\right), \frac{-11}{128}, \mathsf{fma}\left(x \cdot x, \frac{1}{8}, \left(\frac{69}{1024} \cdot \left(x \cdot x\right)\right) \cdot \left(\left(x \cdot x\right) \cdot \left(x \cdot x\right)\right)\right)\right)}\]

    if 1.0000000000000007 < (hypot 1 x)

    1. Initial program 1.5

      \[1 - \sqrt{\frac{1}{2} \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)}\]
    2. Simplified1.5

      \[\leadsto \color{blue}{1 - \sqrt{\frac{1}{2} + \frac{\frac{1}{2}}{\mathsf{hypot}\left(1, x\right)}}}\]
    3. Using strategy rm
    4. Applied flip--1.5

      \[\leadsto \color{blue}{\frac{1 \cdot 1 - \sqrt{\frac{1}{2} + \frac{\frac{1}{2}}{\mathsf{hypot}\left(1, x\right)}} \cdot \sqrt{\frac{1}{2} + \frac{\frac{1}{2}}{\mathsf{hypot}\left(1, x\right)}}}{1 + \sqrt{\frac{1}{2} + \frac{\frac{1}{2}}{\mathsf{hypot}\left(1, x\right)}}}}\]
    5. Simplified0.6

      \[\leadsto \frac{\color{blue}{1 - \left(\frac{\frac{1}{2}}{\mathsf{hypot}\left(1, x\right)} + \frac{1}{2}\right)}}{1 + \sqrt{\frac{1}{2} + \frac{\frac{1}{2}}{\mathsf{hypot}\left(1, x\right)}}}\]
    6. Simplified0.6

      \[\leadsto \frac{1 - \left(\frac{\frac{1}{2}}{\mathsf{hypot}\left(1, x\right)} + \frac{1}{2}\right)}{\color{blue}{1 + \sqrt{\frac{\frac{1}{2}}{\mathsf{hypot}\left(1, x\right)} + \frac{1}{2}}}}\]
    7. Using strategy rm
    8. Applied flip3-+0.6

      \[\leadsto \frac{1 - \left(\frac{\frac{1}{2}}{\mathsf{hypot}\left(1, x\right)} + \frac{1}{2}\right)}{1 + \sqrt{\color{blue}{\frac{{\left(\frac{\frac{1}{2}}{\mathsf{hypot}\left(1, x\right)}\right)}^{3} + {\frac{1}{2}}^{3}}{\frac{\frac{1}{2}}{\mathsf{hypot}\left(1, x\right)} \cdot \frac{\frac{1}{2}}{\mathsf{hypot}\left(1, x\right)} + \left(\frac{1}{2} \cdot \frac{1}{2} - \frac{\frac{1}{2}}{\mathsf{hypot}\left(1, x\right)} \cdot \frac{1}{2}\right)}}}}\]
    9. Applied sqrt-div0.6

      \[\leadsto \frac{1 - \left(\frac{\frac{1}{2}}{\mathsf{hypot}\left(1, x\right)} + \frac{1}{2}\right)}{1 + \color{blue}{\frac{\sqrt{{\left(\frac{\frac{1}{2}}{\mathsf{hypot}\left(1, x\right)}\right)}^{3} + {\frac{1}{2}}^{3}}}{\sqrt{\frac{\frac{1}{2}}{\mathsf{hypot}\left(1, x\right)} \cdot \frac{\frac{1}{2}}{\mathsf{hypot}\left(1, x\right)} + \left(\frac{1}{2} \cdot \frac{1}{2} - \frac{\frac{1}{2}}{\mathsf{hypot}\left(1, x\right)} \cdot \frac{1}{2}\right)}}}}\]
    10. Simplified0.6

      \[\leadsto \frac{1 - \left(\frac{\frac{1}{2}}{\mathsf{hypot}\left(1, x\right)} + \frac{1}{2}\right)}{1 + \frac{\color{blue}{\sqrt{\mathsf{fma}\left(\frac{\frac{1}{2}}{\mathsf{hypot}\left(1, x\right)}, \frac{\frac{1}{2}}{\mathsf{hypot}\left(1, x\right)} \cdot \frac{\frac{1}{2}}{\mathsf{hypot}\left(1, x\right)}, \frac{1}{8}\right)}}}{\sqrt{\frac{\frac{1}{2}}{\mathsf{hypot}\left(1, x\right)} \cdot \frac{\frac{1}{2}}{\mathsf{hypot}\left(1, x\right)} + \left(\frac{1}{2} \cdot \frac{1}{2} - \frac{\frac{1}{2}}{\mathsf{hypot}\left(1, x\right)} \cdot \frac{1}{2}\right)}}}\]
    11. Simplified0.6

      \[\leadsto \frac{1 - \left(\frac{\frac{1}{2}}{\mathsf{hypot}\left(1, x\right)} + \frac{1}{2}\right)}{1 + \frac{\sqrt{\mathsf{fma}\left(\frac{\frac{1}{2}}{\mathsf{hypot}\left(1, x\right)}, \frac{\frac{1}{2}}{\mathsf{hypot}\left(1, x\right)} \cdot \frac{\frac{1}{2}}{\mathsf{hypot}\left(1, x\right)}, \frac{1}{8}\right)}}{\color{blue}{\sqrt{\frac{1}{4} - \frac{\frac{1}{2}}{\mathsf{hypot}\left(1, x\right)} \cdot \left(\frac{1}{2} - \frac{\frac{1}{2}}{\mathsf{hypot}\left(1, x\right)}\right)}}}}\]
    12. Using strategy rm
    13. Applied add-log-exp0.6

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\mathsf{hypot}\left(1, x\right) \le 1.0000000000000007:\\ \;\;\;\;\mathsf{fma}\left(\left(x \cdot x\right) \cdot \left(x \cdot x\right), \frac{-11}{128}, \mathsf{fma}\left(x \cdot x, \frac{1}{8}, \left(\frac{69}{1024} \cdot \left(x \cdot x\right)\right) \cdot \left(\left(x \cdot x\right) \cdot \left(x \cdot x\right)\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\log \left(e^{1 - \left(\frac{1}{2} + \frac{\frac{1}{2}}{\mathsf{hypot}\left(1, x\right)}\right)}\right)}{1 + \frac{\sqrt{\mathsf{fma}\left(\frac{\frac{1}{2}}{\mathsf{hypot}\left(1, x\right)}, \frac{\frac{1}{2}}{\mathsf{hypot}\left(1, x\right)} \cdot \frac{\frac{1}{2}}{\mathsf{hypot}\left(1, x\right)}, \frac{1}{8}\right)}}{\sqrt{\frac{1}{4} - \frac{\frac{1}{2}}{\mathsf{hypot}\left(1, x\right)} \cdot \left(\frac{1}{2} - \frac{\frac{1}{2}}{\mathsf{hypot}\left(1, x\right)}\right)}}}\\ \end{array}\]

Reproduce

herbie shell --seed 2019163 +o rules:numerics
(FPCore (x)
  :name "Given's Rotation SVD example, simplified"
  (- 1 (sqrt (* 1/2 (+ 1 (/ 1 (hypot 1 x)))))))