Average Error: 15.7 → 0.3
Time: 18.1s
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.002439316417548789348024307344076078152284:\\ \;\;\;\;\frac{1 \cdot 1 - \left(1 + \sqrt[3]{{\left(\frac{1}{\mathsf{hypot}\left(1, x\right)}\right)}^{3}}\right) \cdot 0.5}{\mathsf{expm1}\left(\mathsf{log1p}\left(1 + \sqrt{0.5 \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)}\right)\right)}\\ \mathbf{elif}\;x \le 0.957930575927707361749696701735956594348:\\ \;\;\;\;\frac{\mathsf{fma}\left(\frac{{x}^{2}}{{\left(\sqrt{1}\right)}^{3}}, 0.25, 0.5 - \mathsf{fma}\left(0.1875, \frac{{x}^{4}}{{\left(\sqrt{1}\right)}^{5}}, \frac{0.5}{\sqrt{1}}\right)\right)}{1 + \sqrt{0.5 \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{0.25}{{x}^{3}} + \left(0.5 - \frac{0.5}{x}\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.002439316417548789348024307344076078152284:\\
\;\;\;\;\frac{1 \cdot 1 - \left(1 + \sqrt[3]{{\left(\frac{1}{\mathsf{hypot}\left(1, x\right)}\right)}^{3}}\right) \cdot 0.5}{\mathsf{expm1}\left(\mathsf{log1p}\left(1 + \sqrt{0.5 \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)}\right)\right)}\\

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

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

\end{array}
double f(double x) {
        double r196066 = 1.0;
        double r196067 = 0.5;
        double r196068 = x;
        double r196069 = hypot(r196066, r196068);
        double r196070 = r196066 / r196069;
        double r196071 = r196066 + r196070;
        double r196072 = r196067 * r196071;
        double r196073 = sqrt(r196072);
        double r196074 = r196066 - r196073;
        return r196074;
}

double f(double x) {
        double r196075 = x;
        double r196076 = -0.0024393164175487893;
        bool r196077 = r196075 <= r196076;
        double r196078 = 1.0;
        double r196079 = r196078 * r196078;
        double r196080 = hypot(r196078, r196075);
        double r196081 = r196078 / r196080;
        double r196082 = 3.0;
        double r196083 = pow(r196081, r196082);
        double r196084 = cbrt(r196083);
        double r196085 = r196078 + r196084;
        double r196086 = 0.5;
        double r196087 = r196085 * r196086;
        double r196088 = r196079 - r196087;
        double r196089 = r196078 + r196081;
        double r196090 = r196086 * r196089;
        double r196091 = sqrt(r196090);
        double r196092 = r196078 + r196091;
        double r196093 = log1p(r196092);
        double r196094 = expm1(r196093);
        double r196095 = r196088 / r196094;
        double r196096 = 0.9579305759277074;
        bool r196097 = r196075 <= r196096;
        double r196098 = 2.0;
        double r196099 = pow(r196075, r196098);
        double r196100 = sqrt(r196078);
        double r196101 = pow(r196100, r196082);
        double r196102 = r196099 / r196101;
        double r196103 = 0.25;
        double r196104 = 0.1875;
        double r196105 = 4.0;
        double r196106 = pow(r196075, r196105);
        double r196107 = 5.0;
        double r196108 = pow(r196100, r196107);
        double r196109 = r196106 / r196108;
        double r196110 = r196086 / r196100;
        double r196111 = fma(r196104, r196109, r196110);
        double r196112 = r196086 - r196111;
        double r196113 = fma(r196102, r196103, r196112);
        double r196114 = r196113 / r196092;
        double r196115 = pow(r196075, r196082);
        double r196116 = r196103 / r196115;
        double r196117 = r196086 / r196075;
        double r196118 = r196086 - r196117;
        double r196119 = r196116 + r196118;
        double r196120 = r196119 / r196092;
        double r196121 = r196097 ? r196114 : r196120;
        double r196122 = r196077 ? r196095 : r196121;
        return r196122;
}

Error

Bits error versus x

Derivation

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

    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}{1 \cdot 1 - \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right) \cdot 0.5}}{1 + \sqrt{0.5 \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)}}\]
    5. Using strategy rm
    6. Applied add-cbrt-cube0.1

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

      \[\leadsto \frac{1 \cdot 1 - \left(1 + \sqrt[3]{\color{blue}{{\left(\frac{1}{\mathsf{hypot}\left(1, x\right)}\right)}^{3}}}\right) \cdot 0.5}{1 + \sqrt{0.5 \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)}}\]
    8. Using strategy rm
    9. Applied expm1-log1p-u0.1

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

    if -0.0024393164175487893 < x < 0.9579305759277074

    1. Initial program 30.7

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

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

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

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

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

      \[\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)}}\]
    9. Simplified0.4

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

    if 0.9579305759277074 < x

    1. Initial program 1.0

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

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

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

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

      \[\leadsto \frac{1 \cdot 1 - \left(1 + \sqrt[3]{\color{blue}{{\left(\frac{1}{\mathsf{hypot}\left(1, x\right)}\right)}^{3}}}\right) \cdot 0.5}{1 + \sqrt{0.5 \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)}}\]
    8. Taylor expanded around inf 0.2

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

      \[\leadsto \frac{\color{blue}{\frac{0.25}{{x}^{3}} + \left(0.5 - \frac{0.5}{x}\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.3

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

Reproduce

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