Average Error: 16.0 → 0.1
Time: 21.3s
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 r8641564 = 1.0;
        double r8641565 = 0.5;
        double r8641566 = x;
        double r8641567 = hypot(r8641564, r8641566);
        double r8641568 = r8641564 / r8641567;
        double r8641569 = r8641564 + r8641568;
        double r8641570 = r8641565 * r8641569;
        double r8641571 = sqrt(r8641570);
        double r8641572 = r8641564 - r8641571;
        return r8641572;
}

double f(double x) {
        double r8641573 = 1.0;
        double r8641574 = x;
        double r8641575 = hypot(r8641573, r8641574);
        double r8641576 = 1.0000000015302035;
        bool r8641577 = r8641575 <= r8641576;
        double r8641578 = 0.125;
        double r8641579 = r8641574 * r8641574;
        double r8641580 = 0.0673828125;
        double r8641581 = r8641579 * r8641579;
        double r8641582 = r8641579 * r8641581;
        double r8641583 = -0.0859375;
        double r8641584 = r8641581 * r8641583;
        double r8641585 = fma(r8641580, r8641582, r8641584);
        double r8641586 = fma(r8641578, r8641579, r8641585);
        double r8641587 = 0.5;
        double r8641588 = r8641587 / r8641575;
        double r8641589 = r8641587 - r8641588;
        double r8641590 = r8641587 + r8641588;
        double r8641591 = sqrt(r8641590);
        double r8641592 = r8641591 + r8641573;
        double r8641593 = r8641589 / r8641592;
        double r8641594 = r8641577 ? r8641586 : r8641593;
        return r8641594;
}

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)))))))