Average Error: 15.2 → 0.0
Time: 31.1s
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.000024004203487:\\ \;\;\;\;\mathsf{fma}\left(\frac{1}{8}, x \cdot x, \left(\frac{69}{1024} \cdot \left(\left(x \cdot x\right) \cdot x\right)\right) \cdot \left(\left(x \cdot x\right) \cdot x\right)\right) - \frac{11}{128} \cdot \left(\left(x \cdot x\right) \cdot \left(x \cdot x\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{1 - \left(\frac{\frac{1}{2}}{\mathsf{hypot}\left(1, x\right)} + \frac{1}{2}\right) \cdot \sqrt{\frac{\frac{1}{2}}{\mathsf{hypot}\left(1, x\right)} + \frac{1}{2}}}{\mathsf{fma}\left(\sqrt{1 + \sqrt{\frac{\frac{1}{2}}{\mathsf{hypot}\left(1, x\right)} + \frac{1}{2}}}, \sqrt{1 + \sqrt{\frac{\frac{1}{2}}{\mathsf{hypot}\left(1, x\right)} + \frac{1}{2}}}, \frac{\frac{1}{2}}{\mathsf{hypot}\left(1, x\right)} + \frac{1}{2}\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.000024004203487:\\
\;\;\;\;\mathsf{fma}\left(\frac{1}{8}, x \cdot x, \left(\frac{69}{1024} \cdot \left(\left(x \cdot x\right) \cdot x\right)\right) \cdot \left(\left(x \cdot x\right) \cdot x\right)\right) - \frac{11}{128} \cdot \left(\left(x \cdot x\right) \cdot \left(x \cdot x\right)\right)\\

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

\end{array}
double f(double x) {
        double r6037927 = 1.0;
        double r6037928 = 0.5;
        double r6037929 = x;
        double r6037930 = hypot(r6037927, r6037929);
        double r6037931 = r6037927 / r6037930;
        double r6037932 = r6037927 + r6037931;
        double r6037933 = r6037928 * r6037932;
        double r6037934 = sqrt(r6037933);
        double r6037935 = r6037927 - r6037934;
        return r6037935;
}

double f(double x) {
        double r6037936 = 1.0;
        double r6037937 = x;
        double r6037938 = hypot(r6037936, r6037937);
        double r6037939 = 1.000024004203487;
        bool r6037940 = r6037938 <= r6037939;
        double r6037941 = 0.125;
        double r6037942 = r6037937 * r6037937;
        double r6037943 = 0.0673828125;
        double r6037944 = r6037942 * r6037937;
        double r6037945 = r6037943 * r6037944;
        double r6037946 = r6037945 * r6037944;
        double r6037947 = fma(r6037941, r6037942, r6037946);
        double r6037948 = 0.0859375;
        double r6037949 = r6037942 * r6037942;
        double r6037950 = r6037948 * r6037949;
        double r6037951 = r6037947 - r6037950;
        double r6037952 = 0.5;
        double r6037953 = r6037952 / r6037938;
        double r6037954 = r6037953 + r6037952;
        double r6037955 = sqrt(r6037954);
        double r6037956 = r6037954 * r6037955;
        double r6037957 = r6037936 - r6037956;
        double r6037958 = r6037936 + r6037955;
        double r6037959 = sqrt(r6037958);
        double r6037960 = fma(r6037959, r6037959, r6037954);
        double r6037961 = r6037957 / r6037960;
        double r6037962 = r6037940 ? r6037951 : r6037961;
        return r6037962;
}

Error

Bits error versus x

Derivation

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

    1. Initial program 29.7

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

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

      \[\leadsto \color{blue}{\frac{{1}^{3} - {\left(\sqrt{\frac{1}{2} + \frac{\frac{1}{2}}{\mathsf{hypot}\left(1, x\right)}}\right)}^{3}}{1 \cdot 1 + \left(\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 \cdot \sqrt{\frac{1}{2} + \frac{\frac{1}{2}}{\mathsf{hypot}\left(1, x\right)}}\right)}}\]
    5. Simplified29.7

      \[\leadsto \frac{\color{blue}{1 - \sqrt{\frac{1}{2} + \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)}}{1 \cdot 1 + \left(\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 \cdot \sqrt{\frac{1}{2} + \frac{\frac{1}{2}}{\mathsf{hypot}\left(1, x\right)}}\right)}\]
    6. Simplified29.7

      \[\leadsto \frac{1 - \sqrt{\frac{1}{2} + \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)}{\color{blue}{\left(\sqrt{\frac{1}{2} + \frac{\frac{1}{2}}{\mathsf{hypot}\left(1, x\right)}} + 1\right) + \left(\frac{1}{2} + \frac{\frac{1}{2}}{\mathsf{hypot}\left(1, x\right)}\right)}}\]
    7. 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}}\]
    8. Simplified0.0

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

    if 1.000024004203487 < (hypot 1 x)

    1. Initial program 1.0

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

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

      \[\leadsto \color{blue}{\frac{{1}^{3} - {\left(\sqrt{\frac{1}{2} + \frac{\frac{1}{2}}{\mathsf{hypot}\left(1, x\right)}}\right)}^{3}}{1 \cdot 1 + \left(\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 \cdot \sqrt{\frac{1}{2} + \frac{\frac{1}{2}}{\mathsf{hypot}\left(1, x\right)}}\right)}}\]
    5. Simplified1.0

      \[\leadsto \frac{\color{blue}{1 - \sqrt{\frac{1}{2} + \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)}}{1 \cdot 1 + \left(\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 \cdot \sqrt{\frac{1}{2} + \frac{\frac{1}{2}}{\mathsf{hypot}\left(1, x\right)}}\right)}\]
    6. Simplified0.1

      \[\leadsto \frac{1 - \sqrt{\frac{1}{2} + \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)}{\color{blue}{\left(\sqrt{\frac{1}{2} + \frac{\frac{1}{2}}{\mathsf{hypot}\left(1, x\right)}} + 1\right) + \left(\frac{1}{2} + \frac{\frac{1}{2}}{\mathsf{hypot}\left(1, x\right)}\right)}}\]
    7. Using strategy rm
    8. Applied add-sqr-sqrt1.0

      \[\leadsto \frac{1 - \sqrt{\frac{1}{2} + \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)}{\color{blue}{\sqrt{\sqrt{\frac{1}{2} + \frac{\frac{1}{2}}{\mathsf{hypot}\left(1, x\right)}} + 1} \cdot \sqrt{\sqrt{\frac{1}{2} + \frac{\frac{1}{2}}{\mathsf{hypot}\left(1, x\right)}} + 1}} + \left(\frac{1}{2} + \frac{\frac{1}{2}}{\mathsf{hypot}\left(1, x\right)}\right)}\]
    9. Applied fma-def0.1

      \[\leadsto \frac{1 - \sqrt{\frac{1}{2} + \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)}{\color{blue}{\mathsf{fma}\left(\sqrt{\sqrt{\frac{1}{2} + \frac{\frac{1}{2}}{\mathsf{hypot}\left(1, x\right)}} + 1}, \sqrt{\sqrt{\frac{1}{2} + \frac{\frac{1}{2}}{\mathsf{hypot}\left(1, x\right)}} + 1}, \frac{1}{2} + \frac{\frac{1}{2}}{\mathsf{hypot}\left(1, x\right)}\right)}}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.0

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

Reproduce

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