Average Error: 15.6 → 0.3
Time: 21.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.0000000000000193:\\ \;\;\;\;\mathsf{fma}\left(\frac{69}{1024}, \left(\left(x \cdot x\right) \cdot x\right) \cdot \left(\left(x \cdot x\right) \cdot x\right), \left(\frac{1}{8} - \frac{11}{128} \cdot \left(x \cdot x\right)\right) \cdot \left(x \cdot x\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1}{2} - \sqrt{\frac{\frac{1}{2}}{\mathsf{hypot}\left(1, x\right)}} \cdot \sqrt{\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)}}}\\ \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.0000000000000193:\\
\;\;\;\;\mathsf{fma}\left(\frac{69}{1024}, \left(\left(x \cdot x\right) \cdot x\right) \cdot \left(\left(x \cdot x\right) \cdot x\right), \left(\frac{1}{8} - \frac{11}{128} \cdot \left(x \cdot x\right)\right) \cdot \left(x \cdot x\right)\right)\\

\mathbf{else}:\\
\;\;\;\;\frac{\frac{1}{2} - \sqrt{\frac{\frac{1}{2}}{\mathsf{hypot}\left(1, x\right)}} \cdot \sqrt{\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)}}}\\

\end{array}
double f(double x) {
        double r4306639 = 1.0;
        double r4306640 = 0.5;
        double r4306641 = x;
        double r4306642 = hypot(r4306639, r4306641);
        double r4306643 = r4306639 / r4306642;
        double r4306644 = r4306639 + r4306643;
        double r4306645 = r4306640 * r4306644;
        double r4306646 = sqrt(r4306645);
        double r4306647 = r4306639 - r4306646;
        return r4306647;
}

double f(double x) {
        double r4306648 = 1.0;
        double r4306649 = x;
        double r4306650 = hypot(r4306648, r4306649);
        double r4306651 = 1.0000000000000193;
        bool r4306652 = r4306650 <= r4306651;
        double r4306653 = 0.0673828125;
        double r4306654 = r4306649 * r4306649;
        double r4306655 = r4306654 * r4306649;
        double r4306656 = r4306655 * r4306655;
        double r4306657 = 0.125;
        double r4306658 = 0.0859375;
        double r4306659 = r4306658 * r4306654;
        double r4306660 = r4306657 - r4306659;
        double r4306661 = r4306660 * r4306654;
        double r4306662 = fma(r4306653, r4306656, r4306661);
        double r4306663 = 0.5;
        double r4306664 = r4306663 / r4306650;
        double r4306665 = sqrt(r4306664);
        double r4306666 = r4306665 * r4306665;
        double r4306667 = r4306663 - r4306666;
        double r4306668 = r4306663 + r4306664;
        double r4306669 = sqrt(r4306668);
        double r4306670 = r4306648 + r4306669;
        double r4306671 = r4306667 / r4306670;
        double r4306672 = r4306652 ? r4306662 : r4306671;
        return r4306672;
}

Error

Bits error versus x

Derivation

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

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

    if 1.0000000000000193 < (hypot 1 x)

    1. Initial program 1.4

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

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

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

      \[\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)}}}\]
    6. Using strategy rm
    7. Applied add-sqr-sqrt0.5

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\mathsf{hypot}\left(1, x\right) \le 1.0000000000000193:\\ \;\;\;\;\mathsf{fma}\left(\frac{69}{1024}, \left(\left(x \cdot x\right) \cdot x\right) \cdot \left(\left(x \cdot x\right) \cdot x\right), \left(\frac{1}{8} - \frac{11}{128} \cdot \left(x \cdot x\right)\right) \cdot \left(x \cdot x\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1}{2} - \sqrt{\frac{\frac{1}{2}}{\mathsf{hypot}\left(1, x\right)}} \cdot \sqrt{\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)}}}\\ \end{array}\]

Reproduce

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