Average Error: 15.7 → 0.0
Time: 20.0s
Precision: 64
\[1 - \sqrt{\frac{1}{2} \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)}\]
\[\begin{array}{l} \mathbf{if}\;x \le -0.010462939647205145:\\ \;\;\;\;\frac{\frac{1}{2} - \frac{\frac{1}{2}}{\mathsf{hypot}\left(1, x\right)}}{\mathsf{hypot}\left(\left(\sqrt{\frac{\frac{1}{2}}{\mathsf{hypot}\left(1, x\right)}}\right), \left(\sqrt{\frac{1}{2}}\right)\right) + 1}\\ \mathbf{elif}\;x \le 0.008896625846513824:\\ \;\;\;\;\mathsf{fma}\left(\frac{1}{8}, \left(x \cdot x\right), \left(\mathsf{fma}\left(\left(\left(x \cdot x\right) \cdot \left(\left(x \cdot x\right) \cdot \left(x \cdot x\right)\right)\right), \frac{69}{1024}, \left(\frac{-11}{128} \cdot \left(\left(x \cdot x\right) \cdot \left(x \cdot x\right)\right)\right)\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1}{2} - \frac{\frac{1}{2}}{\mathsf{hypot}\left(1, x\right)}}{\mathsf{hypot}\left(\left(\sqrt{\frac{\frac{1}{2}}{\mathsf{hypot}\left(1, x\right)}}\right), \left(\sqrt{\frac{1}{2}}\right)\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}\;x \le -0.010462939647205145:\\
\;\;\;\;\frac{\frac{1}{2} - \frac{\frac{1}{2}}{\mathsf{hypot}\left(1, x\right)}}{\mathsf{hypot}\left(\left(\sqrt{\frac{\frac{1}{2}}{\mathsf{hypot}\left(1, x\right)}}\right), \left(\sqrt{\frac{1}{2}}\right)\right) + 1}\\

\mathbf{elif}\;x \le 0.008896625846513824:\\
\;\;\;\;\mathsf{fma}\left(\frac{1}{8}, \left(x \cdot x\right), \left(\mathsf{fma}\left(\left(\left(x \cdot x\right) \cdot \left(\left(x \cdot x\right) \cdot \left(x \cdot x\right)\right)\right), \frac{69}{1024}, \left(\frac{-11}{128} \cdot \left(\left(x \cdot x\right) \cdot \left(x \cdot x\right)\right)\right)\right)\right)\right)\\

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

\end{array}
double f(double x) {
        double r4036577 = 1.0;
        double r4036578 = 0.5;
        double r4036579 = x;
        double r4036580 = hypot(r4036577, r4036579);
        double r4036581 = r4036577 / r4036580;
        double r4036582 = r4036577 + r4036581;
        double r4036583 = r4036578 * r4036582;
        double r4036584 = sqrt(r4036583);
        double r4036585 = r4036577 - r4036584;
        return r4036585;
}

double f(double x) {
        double r4036586 = x;
        double r4036587 = -0.010462939647205145;
        bool r4036588 = r4036586 <= r4036587;
        double r4036589 = 0.5;
        double r4036590 = 1.0;
        double r4036591 = hypot(r4036590, r4036586);
        double r4036592 = r4036589 / r4036591;
        double r4036593 = r4036589 - r4036592;
        double r4036594 = sqrt(r4036592);
        double r4036595 = sqrt(r4036589);
        double r4036596 = hypot(r4036594, r4036595);
        double r4036597 = r4036596 + r4036590;
        double r4036598 = r4036593 / r4036597;
        double r4036599 = 0.008896625846513824;
        bool r4036600 = r4036586 <= r4036599;
        double r4036601 = 0.125;
        double r4036602 = r4036586 * r4036586;
        double r4036603 = r4036602 * r4036602;
        double r4036604 = r4036602 * r4036603;
        double r4036605 = 0.0673828125;
        double r4036606 = -0.0859375;
        double r4036607 = r4036606 * r4036603;
        double r4036608 = fma(r4036604, r4036605, r4036607);
        double r4036609 = fma(r4036601, r4036602, r4036608);
        double r4036610 = r4036600 ? r4036609 : r4036598;
        double r4036611 = r4036588 ? r4036598 : r4036610;
        return r4036611;
}

Error

Bits error versus x

Derivation

  1. Split input into 2 regimes
  2. if x < -0.010462939647205145 or 0.008896625846513824 < 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{\frac{1}{2}}{\mathsf{hypot}\left(1, x\right)} + \frac{1}{2}}}\]
    3. Using strategy rm
    4. Applied flip--1.0

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

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

      \[\leadsto \frac{\frac{1}{2} - \frac{\frac{1}{2}}{\mathsf{hypot}\left(1, x\right)}}{1 + \sqrt{\frac{\frac{1}{2}}{\mathsf{hypot}\left(1, x\right)} + \color{blue}{\sqrt{\frac{1}{2}} \cdot \sqrt{\frac{1}{2}}}}}\]
    8. Applied add-sqr-sqrt0.1

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

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

    if -0.010462939647205145 < x < 0.008896625846513824

    1. Initial program 30.5

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

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

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{1}{8}, \left(x \cdot x\right), \left(\mathsf{fma}\left(\left(\left(\left(x \cdot x\right) \cdot \left(x \cdot x\right)\right) \cdot \left(x \cdot x\right)\right), \frac{69}{1024}, \left(\frac{-11}{128} \cdot \left(\left(x \cdot x\right) \cdot \left(x \cdot x\right)\right)\right)\right)\right)\right)}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.0

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

Reproduce

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