Average Error: 15.4 → 0.0
Time: 1.6m
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.012235985861856024:\\ \;\;\;\;\frac{\mathsf{expm1}\left(\left(\mathsf{log1p}\left(\left(\frac{1}{2} - \frac{\frac{1}{2}}{\mathsf{hypot}\left(1, x\right)}\right)\right)\right)\right)}{1 + \sqrt{\frac{1}{2} + \frac{\frac{1}{2}}{\mathsf{hypot}\left(1, x\right)}}}\\ \mathbf{elif}\;x \le 0.010791775012852783:\\ \;\;\;\;\left(x \cdot \mathsf{fma}\left(\frac{69}{1024}, \left(\left(x \cdot x\right) \cdot \left(x \cdot x\right)\right), \left(\mathsf{fma}\left(\frac{-11}{128}, \left(x \cdot x\right), \frac{1}{8}\right)\right)\right)\right) \cdot x\\ \mathbf{else}:\\ \;\;\;\;\frac{\mathsf{expm1}\left(\left(\mathsf{log1p}\left(\left(\frac{1}{2} - \frac{\frac{1}{2}}{\mathsf{hypot}\left(1, x\right)}\right)\right)\right)\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}\;x \le -0.012235985861856024:\\
\;\;\;\;\frac{\mathsf{expm1}\left(\left(\mathsf{log1p}\left(\left(\frac{1}{2} - \frac{\frac{1}{2}}{\mathsf{hypot}\left(1, x\right)}\right)\right)\right)\right)}{1 + \sqrt{\frac{1}{2} + \frac{\frac{1}{2}}{\mathsf{hypot}\left(1, x\right)}}}\\

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

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

\end{array}
double f(double x) {
        double r113149683 = 1.0;
        double r113149684 = 0.5;
        double r113149685 = x;
        double r113149686 = hypot(r113149683, r113149685);
        double r113149687 = r113149683 / r113149686;
        double r113149688 = r113149683 + r113149687;
        double r113149689 = r113149684 * r113149688;
        double r113149690 = sqrt(r113149689);
        double r113149691 = r113149683 - r113149690;
        return r113149691;
}

double f(double x) {
        double r113149692 = x;
        double r113149693 = -0.012235985861856024;
        bool r113149694 = r113149692 <= r113149693;
        double r113149695 = 0.5;
        double r113149696 = 1.0;
        double r113149697 = hypot(r113149696, r113149692);
        double r113149698 = r113149695 / r113149697;
        double r113149699 = r113149695 - r113149698;
        double r113149700 = log1p(r113149699);
        double r113149701 = expm1(r113149700);
        double r113149702 = r113149695 + r113149698;
        double r113149703 = sqrt(r113149702);
        double r113149704 = r113149696 + r113149703;
        double r113149705 = r113149701 / r113149704;
        double r113149706 = 0.010791775012852783;
        bool r113149707 = r113149692 <= r113149706;
        double r113149708 = 0.0673828125;
        double r113149709 = r113149692 * r113149692;
        double r113149710 = r113149709 * r113149709;
        double r113149711 = -0.0859375;
        double r113149712 = 0.125;
        double r113149713 = fma(r113149711, r113149709, r113149712);
        double r113149714 = fma(r113149708, r113149710, r113149713);
        double r113149715 = r113149692 * r113149714;
        double r113149716 = r113149715 * r113149692;
        double r113149717 = r113149707 ? r113149716 : r113149705;
        double r113149718 = r113149694 ? r113149705 : r113149717;
        return r113149718;
}

Error

Bits error versus x

Derivation

  1. Split input into 2 regimes
  2. if x < -0.012235985861856024 or 0.010791775012852783 < 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 expm1-log1p-u0.1

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

    if -0.012235985861856024 < x < 0.010791775012852783

    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{\frac{1}{2}}{\mathsf{hypot}\left(1, x\right)} + \frac{1}{2}}}\]
    3. Using strategy rm
    4. Applied flip--29.7

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

      \[\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 expm1-log1p-u29.7

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

      \[\leadsto \color{blue}{\left(x \cdot x\right) \cdot \left(\frac{1}{8} + \left(x \cdot x\right) \cdot \left(\left(x \cdot x\right) \cdot \frac{69}{1024} - \frac{11}{128}\right)\right)}\]
    10. Using strategy rm
    11. Applied associate-*l*0.0

      \[\leadsto \color{blue}{x \cdot \left(x \cdot \left(\frac{1}{8} + \left(x \cdot x\right) \cdot \left(\left(x \cdot x\right) \cdot \frac{69}{1024} - \frac{11}{128}\right)\right)\right)}\]
    12. Simplified0.0

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

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

Reproduce

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