Average Error: 14.9 → 0.2
Time: 7.2s
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.002313696967980117136925999332675019104499:\\ \;\;\;\;\frac{\mathsf{fma}\left(-0.5, 1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}, 1 \cdot 1\right)}{1 + \sqrt{0.5 \cdot \frac{1 \cdot 1 - \frac{1}{\mathsf{hypot}\left(1, x\right)} \cdot \frac{1}{\mathsf{hypot}\left(1, x\right)}}{1 - \frac{1}{\mathsf{hypot}\left(1, x\right)}}}}\\ \mathbf{elif}\;x \le 0.00136657127452878318814299962724589931895:\\ \;\;\;\;\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{e^{\log \left(\mathsf{fma}\left(-0.5, 1 + \mathsf{expm1}\left(\mathsf{log1p}\left(\frac{1}{\mathsf{hypot}\left(1, x\right)}\right)\right), 1 \cdot 1\right)\right)}}{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.002313696967980117136925999332675019104499:\\
\;\;\;\;\frac{\mathsf{fma}\left(-0.5, 1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}, 1 \cdot 1\right)}{1 + \sqrt{0.5 \cdot \frac{1 \cdot 1 - \frac{1}{\mathsf{hypot}\left(1, x\right)} \cdot \frac{1}{\mathsf{hypot}\left(1, x\right)}}{1 - \frac{1}{\mathsf{hypot}\left(1, x\right)}}}}\\

\mathbf{elif}\;x \le 0.00136657127452878318814299962724589931895:\\
\;\;\;\;\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{e^{\log \left(\mathsf{fma}\left(-0.5, 1 + \mathsf{expm1}\left(\mathsf{log1p}\left(\frac{1}{\mathsf{hypot}\left(1, x\right)}\right)\right), 1 \cdot 1\right)\right)}}{1 + \sqrt{0.5 \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)}}\\

\end{array}
double f(double x) {
        double r306968 = 1.0;
        double r306969 = 0.5;
        double r306970 = x;
        double r306971 = hypot(r306968, r306970);
        double r306972 = r306968 / r306971;
        double r306973 = r306968 + r306972;
        double r306974 = r306969 * r306973;
        double r306975 = sqrt(r306974);
        double r306976 = r306968 - r306975;
        return r306976;
}

double f(double x) {
        double r306977 = x;
        double r306978 = -0.002313696967980117;
        bool r306979 = r306977 <= r306978;
        double r306980 = 0.5;
        double r306981 = -r306980;
        double r306982 = 1.0;
        double r306983 = hypot(r306982, r306977);
        double r306984 = r306982 / r306983;
        double r306985 = r306982 + r306984;
        double r306986 = r306982 * r306982;
        double r306987 = fma(r306981, r306985, r306986);
        double r306988 = r306984 * r306984;
        double r306989 = r306986 - r306988;
        double r306990 = r306982 - r306984;
        double r306991 = r306989 / r306990;
        double r306992 = r306980 * r306991;
        double r306993 = sqrt(r306992);
        double r306994 = r306982 + r306993;
        double r306995 = r306987 / r306994;
        double r306996 = 0.0013665712745287832;
        bool r306997 = r306977 <= r306996;
        double r306998 = 0.25;
        double r306999 = 2.0;
        double r307000 = pow(r306977, r306999);
        double r307001 = sqrt(r306982);
        double r307002 = 3.0;
        double r307003 = pow(r307001, r307002);
        double r307004 = r307000 / r307003;
        double r307005 = 1.0;
        double r307006 = r307005 / r307001;
        double r307007 = 0.1875;
        double r307008 = 4.0;
        double r307009 = pow(r306977, r307008);
        double r307010 = 5.0;
        double r307011 = pow(r307001, r307010);
        double r307012 = r307009 / r307011;
        double r307013 = r307007 * r307012;
        double r307014 = fma(r306980, r307006, r307013);
        double r307015 = r306980 - r307014;
        double r307016 = fma(r306998, r307004, r307015);
        double r307017 = r306980 * r306985;
        double r307018 = sqrt(r307017);
        double r307019 = r306982 + r307018;
        double r307020 = r307016 / r307019;
        double r307021 = log1p(r306984);
        double r307022 = expm1(r307021);
        double r307023 = r306982 + r307022;
        double r307024 = fma(r306981, r307023, r306986);
        double r307025 = log(r307024);
        double r307026 = exp(r307025);
        double r307027 = r307026 / r307019;
        double r307028 = r306997 ? r307020 : r307027;
        double r307029 = r306979 ? r306995 : r307028;
        return r307029;
}

Error

Bits error versus x

Derivation

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

    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 flip-+0.1

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

    if -0.002313696967980117 < x < 0.0013665712745287832

    1. Initial program 29.1

      \[1 - \sqrt{0.5 \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)}\]
    2. Using strategy rm
    3. Applied flip--29.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. Simplified29.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. Taylor expanded around 0 29.1

      \[\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 0.0013665712745287832 < x

    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.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 expm1-log1p-u0.2

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

      \[\leadsto \frac{\color{blue}{e^{\log \left(\mathsf{fma}\left(-0.5, 1 + \mathsf{expm1}\left(\mathsf{log1p}\left(\frac{1}{\mathsf{hypot}\left(1, x\right)}\right)\right), 1 \cdot 1\right)\right)}}}{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.002313696967980117136925999332675019104499:\\ \;\;\;\;\frac{\mathsf{fma}\left(-0.5, 1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}, 1 \cdot 1\right)}{1 + \sqrt{0.5 \cdot \frac{1 \cdot 1 - \frac{1}{\mathsf{hypot}\left(1, x\right)} \cdot \frac{1}{\mathsf{hypot}\left(1, x\right)}}{1 - \frac{1}{\mathsf{hypot}\left(1, x\right)}}}}\\ \mathbf{elif}\;x \le 0.00136657127452878318814299962724589931895:\\ \;\;\;\;\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{e^{\log \left(\mathsf{fma}\left(-0.5, 1 + \mathsf{expm1}\left(\mathsf{log1p}\left(\frac{1}{\mathsf{hypot}\left(1, x\right)}\right)\right), 1 \cdot 1\right)\right)}}{1 + \sqrt{0.5 \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)}}\\ \end{array}\]

Reproduce

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