Average Error: 15.4 → 0.2
Time: 8.5s
Precision: 64
\[1 - \sqrt{0.5 \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)}\]
\[\begin{array}{l} \mathbf{if}\;\mathsf{hypot}\left(1, x\right) \le 1.00000072666889728:\\ \;\;\;\;\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 + \log \left(e^{\frac{1}{\mathsf{hypot}\left(1, x\right)}}\right)\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\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 + \log \left(e^{\frac{1}{\mathsf{hypot}\left(1, x\right)}}\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}\;\mathsf{hypot}\left(1, x\right) \le 1.00000072666889728:\\
\;\;\;\;\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 + \log \left(e^{\frac{1}{\mathsf{hypot}\left(1, x\right)}}\right)\right)}}\\

\mathbf{else}:\\
\;\;\;\;\frac{\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 + \log \left(e^{\frac{1}{\mathsf{hypot}\left(1, x\right)}}\right)\right)}}\\

\end{array}
double f(double x) {
        double r201778 = 1.0;
        double r201779 = 0.5;
        double r201780 = x;
        double r201781 = hypot(r201778, r201780);
        double r201782 = r201778 / r201781;
        double r201783 = r201778 + r201782;
        double r201784 = r201779 * r201783;
        double r201785 = sqrt(r201784);
        double r201786 = r201778 - r201785;
        return r201786;
}

double f(double x) {
        double r201787 = 1.0;
        double r201788 = x;
        double r201789 = hypot(r201787, r201788);
        double r201790 = 1.0000007266688973;
        bool r201791 = r201789 <= r201790;
        double r201792 = 0.25;
        double r201793 = 2.0;
        double r201794 = pow(r201788, r201793);
        double r201795 = sqrt(r201787);
        double r201796 = 3.0;
        double r201797 = pow(r201795, r201796);
        double r201798 = r201794 / r201797;
        double r201799 = 0.5;
        double r201800 = 1.0;
        double r201801 = r201800 / r201795;
        double r201802 = 0.1875;
        double r201803 = 4.0;
        double r201804 = pow(r201788, r201803);
        double r201805 = 5.0;
        double r201806 = pow(r201795, r201805);
        double r201807 = r201804 / r201806;
        double r201808 = r201802 * r201807;
        double r201809 = fma(r201799, r201801, r201808);
        double r201810 = r201799 - r201809;
        double r201811 = fma(r201792, r201798, r201810);
        double r201812 = r201787 / r201789;
        double r201813 = exp(r201812);
        double r201814 = log(r201813);
        double r201815 = r201787 + r201814;
        double r201816 = r201799 * r201815;
        double r201817 = sqrt(r201816);
        double r201818 = r201787 + r201817;
        double r201819 = r201811 / r201818;
        double r201820 = -r201799;
        double r201821 = r201787 + r201812;
        double r201822 = r201787 * r201787;
        double r201823 = fma(r201820, r201821, r201822);
        double r201824 = r201823 / r201818;
        double r201825 = r201791 ? r201819 : r201824;
        return r201825;
}

Error

Bits error versus x

Derivation

  1. Split input into 2 regimes
  2. if (hypot 1.0 x) < 1.0000007266688973

    1. Initial program 30.0

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

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

      \[\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 \left(1 + \color{blue}{\log \left(e^{\frac{1}{\mathsf{hypot}\left(1, x\right)}}\right)}\right)}}\]
    7. Taylor expanded around 0 29.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 + \log \left(e^{\frac{1}{\mathsf{hypot}\left(1, x\right)}}\right)\right)}}\]
    8. Simplified0.3

      \[\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 + \log \left(e^{\frac{1}{\mathsf{hypot}\left(1, x\right)}}\right)\right)}}\]

    if 1.0000007266688973 < (hypot 1.0 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.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 add-log-exp0.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 \left(1 + \color{blue}{\log \left(e^{\frac{1}{\mathsf{hypot}\left(1, x\right)}}\right)}\right)}}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.2

    \[\leadsto \begin{array}{l} \mathbf{if}\;\mathsf{hypot}\left(1, x\right) \le 1.00000072666889728:\\ \;\;\;\;\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 + \log \left(e^{\frac{1}{\mathsf{hypot}\left(1, x\right)}}\right)\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\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 + \log \left(e^{\frac{1}{\mathsf{hypot}\left(1, x\right)}}\right)\right)}}\\ \end{array}\]

Reproduce

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