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

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

\end{array}
double f(double x) {
        double r4240905 = 1.0;
        double r4240906 = 0.5;
        double r4240907 = x;
        double r4240908 = hypot(r4240905, r4240907);
        double r4240909 = r4240905 / r4240908;
        double r4240910 = r4240905 + r4240909;
        double r4240911 = r4240906 * r4240910;
        double r4240912 = sqrt(r4240911);
        double r4240913 = r4240905 - r4240912;
        return r4240913;
}

double f(double x) {
        double r4240914 = 1.0;
        double r4240915 = x;
        double r4240916 = hypot(r4240914, r4240915);
        double r4240917 = 1.0000000015302035;
        bool r4240918 = r4240916 <= r4240917;
        double r4240919 = 0.125;
        double r4240920 = r4240915 * r4240915;
        double r4240921 = 0.0673828125;
        double r4240922 = r4240920 * r4240920;
        double r4240923 = r4240920 * r4240922;
        double r4240924 = -0.0859375;
        double r4240925 = r4240922 * r4240924;
        double r4240926 = fma(r4240921, r4240923, r4240925);
        double r4240927 = fma(r4240919, r4240920, r4240926);
        double r4240928 = 0.5;
        double r4240929 = r4240928 / r4240916;
        double r4240930 = r4240928 - r4240929;
        double r4240931 = r4240928 + r4240929;
        double r4240932 = sqrt(r4240931);
        double r4240933 = r4240932 + r4240914;
        double r4240934 = r4240930 / r4240933;
        double r4240935 = r4240918 ? r4240927 : r4240934;
        return r4240935;
}

Error

Bits error versus x

Derivation

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

    1. Initial program 30.7

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

      \[\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(\frac{1}{8}, x \cdot x, \mathsf{fma}\left(\frac{69}{1024}, \left(\left(x \cdot x\right) \cdot \left(x \cdot x\right)\right) \cdot \left(x \cdot x\right), \frac{-11}{128} \cdot \left(\left(x \cdot x\right) \cdot \left(x \cdot x\right)\right)\right)\right)}\]

    if 1.0000000015302035 < (hypot 1 x)

    1. Initial program 1.2

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

      \[\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.2

      \[\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.2

      \[\leadsto \frac{\color{blue}{\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)}}}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.1

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

Reproduce

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