Average Error: 15.2 → 0.2
Time: 12.8s
Precision: 64
\[1 - \sqrt{0.5 \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)}\]
\[\begin{array}{l} \mathbf{if}\;x \le -0.0014344305208084957:\\ \;\;\;\;\frac{1}{\frac{1 + \sqrt{0.5 \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)}}{\mathsf{fma}\left(-0.5, 1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}, 1 \cdot 1\right)}}\\ \mathbf{elif}\;x \le 7.9648613263331997 \cdot 10^{-5}:\\ \;\;\;\;\frac{\mathsf{fma}\left(0.25, \frac{{x}^{2}}{{\left(\sqrt{1}\right)}^{3}}, 0.5 - \mathsf{fma}\left(0.5, \frac{1}{\sqrt{1}}, 0.1875 \cdot \frac{{x}^{4}}{{\left(\sqrt{1}\right)}^{5}}\right)\right)}{1 + \sqrt{0.5 \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\frac{\sqrt{1 + \sqrt{0.5 \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)}}}{\frac{\mathsf{fma}\left(-0.5, 1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}, 1 \cdot 1\right)}{\sqrt{1 + \sqrt{0.5 \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)}}}}}\\ \end{array}\]
1 - \sqrt{0.5 \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)}
\begin{array}{l}
\mathbf{if}\;x \le -0.0014344305208084957:\\
\;\;\;\;\frac{1}{\frac{1 + \sqrt{0.5 \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)}}{\mathsf{fma}\left(-0.5, 1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}, 1 \cdot 1\right)}}\\

\mathbf{elif}\;x \le 7.9648613263331997 \cdot 10^{-5}:\\
\;\;\;\;\frac{\mathsf{fma}\left(0.25, \frac{{x}^{2}}{{\left(\sqrt{1}\right)}^{3}}, 0.5 - \mathsf{fma}\left(0.5, \frac{1}{\sqrt{1}}, 0.1875 \cdot \frac{{x}^{4}}{{\left(\sqrt{1}\right)}^{5}}\right)\right)}{1 + \sqrt{0.5 \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)}}\\

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

\end{array}
double f(double x) {
        double r363009 = 1.0;
        double r363010 = 0.5;
        double r363011 = x;
        double r363012 = hypot(r363009, r363011);
        double r363013 = r363009 / r363012;
        double r363014 = r363009 + r363013;
        double r363015 = r363010 * r363014;
        double r363016 = sqrt(r363015);
        double r363017 = r363009 - r363016;
        return r363017;
}

double f(double x) {
        double r363018 = x;
        double r363019 = -0.0014344305208084957;
        bool r363020 = r363018 <= r363019;
        double r363021 = 1.0;
        double r363022 = 1.0;
        double r363023 = 0.5;
        double r363024 = hypot(r363022, r363018);
        double r363025 = r363022 / r363024;
        double r363026 = r363022 + r363025;
        double r363027 = r363023 * r363026;
        double r363028 = sqrt(r363027);
        double r363029 = r363022 + r363028;
        double r363030 = -r363023;
        double r363031 = r363022 * r363022;
        double r363032 = fma(r363030, r363026, r363031);
        double r363033 = r363029 / r363032;
        double r363034 = r363021 / r363033;
        double r363035 = 7.9648613263332e-05;
        bool r363036 = r363018 <= r363035;
        double r363037 = 0.25;
        double r363038 = 2.0;
        double r363039 = pow(r363018, r363038);
        double r363040 = sqrt(r363022);
        double r363041 = 3.0;
        double r363042 = pow(r363040, r363041);
        double r363043 = r363039 / r363042;
        double r363044 = r363021 / r363040;
        double r363045 = 0.1875;
        double r363046 = 4.0;
        double r363047 = pow(r363018, r363046);
        double r363048 = 5.0;
        double r363049 = pow(r363040, r363048);
        double r363050 = r363047 / r363049;
        double r363051 = r363045 * r363050;
        double r363052 = fma(r363023, r363044, r363051);
        double r363053 = r363023 - r363052;
        double r363054 = fma(r363037, r363043, r363053);
        double r363055 = r363054 / r363029;
        double r363056 = sqrt(r363029);
        double r363057 = r363032 / r363056;
        double r363058 = r363056 / r363057;
        double r363059 = r363021 / r363058;
        double r363060 = r363036 ? r363055 : r363059;
        double r363061 = r363020 ? r363034 : r363060;
        return r363061;
}

Error

Bits error versus x

Derivation

  1. Split input into 3 regimes
  2. if x < -0.0014344305208084957

    1. Initial program 1.1

      \[1 - \sqrt{0.5 \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)}\]
    2. Using strategy rm
    3. Applied flip--1.1

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

      \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(-0.5, 1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}, 1 \cdot 1\right)}}{1 + \sqrt{0.5 \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)}}\]
    5. Using strategy rm
    6. Applied clear-num0.1

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

    if -0.0014344305208084957 < x < 7.9648613263332e-05

    1. Initial program 29.4

      \[1 - \sqrt{0.5 \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)}\]
    2. Using strategy rm
    3. Applied flip--29.4

      \[\leadsto \color{blue}{\frac{1 \cdot 1 - \sqrt{0.5 \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)} \cdot \sqrt{0.5 \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)}}{1 + \sqrt{0.5 \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)}}}\]
    4. Simplified29.4

      \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(-0.5, 1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}, 1 \cdot 1\right)}}{1 + \sqrt{0.5 \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)}}\]
    5. Taylor expanded around 0 29.4

      \[\leadsto \frac{\color{blue}{\left(0.25 \cdot \frac{{x}^{2}}{{\left(\sqrt{1}\right)}^{3}} + 0.5\right) - \left(0.5 \cdot \frac{1}{\sqrt{1}} + 0.1875 \cdot \frac{{x}^{4}}{{\left(\sqrt{1}\right)}^{5}}\right)}}{1 + \sqrt{0.5 \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)}}\]
    6. Simplified0.2

      \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(0.25, \frac{{x}^{2}}{{\left(\sqrt{1}\right)}^{3}}, 0.5 - \mathsf{fma}\left(0.5, \frac{1}{\sqrt{1}}, 0.1875 \cdot \frac{{x}^{4}}{{\left(\sqrt{1}\right)}^{5}}\right)\right)}}{1 + \sqrt{0.5 \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)}}\]

    if 7.9648613263332e-05 < x

    1. Initial program 1.2

      \[1 - \sqrt{0.5 \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)}\]
    2. Using strategy rm
    3. Applied flip--1.2

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

      \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(-0.5, 1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}, 1 \cdot 1\right)}}{1 + \sqrt{0.5 \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)}}\]
    5. Using strategy rm
    6. Applied clear-num0.2

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

      \[\leadsto \frac{1}{\frac{\color{blue}{\sqrt{1 + \sqrt{0.5 \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)}} \cdot \sqrt{1 + \sqrt{0.5 \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)}}}}{\mathsf{fma}\left(-0.5, 1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}, 1 \cdot 1\right)}}\]
    9. Applied associate-/l*0.2

      \[\leadsto \frac{1}{\color{blue}{\frac{\sqrt{1 + \sqrt{0.5 \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)}}}{\frac{\mathsf{fma}\left(-0.5, 1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}, 1 \cdot 1\right)}{\sqrt{1 + \sqrt{0.5 \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)}}}}}}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification0.2

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -0.0014344305208084957:\\ \;\;\;\;\frac{1}{\frac{1 + \sqrt{0.5 \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)}}{\mathsf{fma}\left(-0.5, 1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}, 1 \cdot 1\right)}}\\ \mathbf{elif}\;x \le 7.9648613263331997 \cdot 10^{-5}:\\ \;\;\;\;\frac{\mathsf{fma}\left(0.25, \frac{{x}^{2}}{{\left(\sqrt{1}\right)}^{3}}, 0.5 - \mathsf{fma}\left(0.5, \frac{1}{\sqrt{1}}, 0.1875 \cdot \frac{{x}^{4}}{{\left(\sqrt{1}\right)}^{5}}\right)\right)}{1 + \sqrt{0.5 \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\frac{\sqrt{1 + \sqrt{0.5 \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)}}}{\frac{\mathsf{fma}\left(-0.5, 1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}, 1 \cdot 1\right)}{\sqrt{1 + \sqrt{0.5 \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)}}}}}\\ \end{array}\]

Reproduce

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