Average Error: 15.2 → 0.2
Time: 17.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.002150518847943041871040303902873347396962:\\ \;\;\;\;\frac{1 \cdot 1 - \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right) \cdot 0.5}{1 + \sqrt{0.5 \cdot \left(1 + \log \left(e^{\frac{1}{\mathsf{hypot}\left(1, x\right)}}\right)\right)}}\\ \mathbf{elif}\;x \le 0.001774327303338343181371428158854541834444:\\ \;\;\;\;\frac{\mathsf{fma}\left(0.25, \frac{{x}^{2}}{{\left(\sqrt{1}\right)}^{3}}, 0.5 - \mathsf{fma}\left(\frac{{x}^{4}}{{\left(\sqrt{1}\right)}^{5}}, 0.1875, \frac{0.5}{\sqrt{1}}\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{\frac{{1}^{6} - \mathsf{expm1}\left(\mathsf{log1p}\left({\left(\left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right) \cdot 0.5\right)}^{3}\right)\right)}{\mathsf{fma}\left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}, 0.5 \cdot \mathsf{fma}\left(1, 1, \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right) \cdot 0.5\right), {1}^{4}\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}\;x \le -0.002150518847943041871040303902873347396962:\\
\;\;\;\;\frac{1 \cdot 1 - \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right) \cdot 0.5}{1 + \sqrt{0.5 \cdot \left(1 + \log \left(e^{\frac{1}{\mathsf{hypot}\left(1, x\right)}}\right)\right)}}\\

\mathbf{elif}\;x \le 0.001774327303338343181371428158854541834444:\\
\;\;\;\;\frac{\mathsf{fma}\left(0.25, \frac{{x}^{2}}{{\left(\sqrt{1}\right)}^{3}}, 0.5 - \mathsf{fma}\left(\frac{{x}^{4}}{{\left(\sqrt{1}\right)}^{5}}, 0.1875, \frac{0.5}{\sqrt{1}}\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{\frac{{1}^{6} - \mathsf{expm1}\left(\mathsf{log1p}\left({\left(\left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right) \cdot 0.5\right)}^{3}\right)\right)}{\mathsf{fma}\left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}, 0.5 \cdot \mathsf{fma}\left(1, 1, \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right) \cdot 0.5\right), {1}^{4}\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 r125592 = 1.0;
        double r125593 = 0.5;
        double r125594 = x;
        double r125595 = hypot(r125592, r125594);
        double r125596 = r125592 / r125595;
        double r125597 = r125592 + r125596;
        double r125598 = r125593 * r125597;
        double r125599 = sqrt(r125598);
        double r125600 = r125592 - r125599;
        return r125600;
}

double f(double x) {
        double r125601 = x;
        double r125602 = -0.002150518847943042;
        bool r125603 = r125601 <= r125602;
        double r125604 = 1.0;
        double r125605 = r125604 * r125604;
        double r125606 = hypot(r125604, r125601);
        double r125607 = r125604 / r125606;
        double r125608 = r125604 + r125607;
        double r125609 = 0.5;
        double r125610 = r125608 * r125609;
        double r125611 = r125605 - r125610;
        double r125612 = exp(r125607);
        double r125613 = log(r125612);
        double r125614 = r125604 + r125613;
        double r125615 = r125609 * r125614;
        double r125616 = sqrt(r125615);
        double r125617 = r125604 + r125616;
        double r125618 = r125611 / r125617;
        double r125619 = 0.0017743273033383432;
        bool r125620 = r125601 <= r125619;
        double r125621 = 0.25;
        double r125622 = 2.0;
        double r125623 = pow(r125601, r125622);
        double r125624 = sqrt(r125604);
        double r125625 = 3.0;
        double r125626 = pow(r125624, r125625);
        double r125627 = r125623 / r125626;
        double r125628 = 4.0;
        double r125629 = pow(r125601, r125628);
        double r125630 = 5.0;
        double r125631 = pow(r125624, r125630);
        double r125632 = r125629 / r125631;
        double r125633 = 0.1875;
        double r125634 = r125609 / r125624;
        double r125635 = fma(r125632, r125633, r125634);
        double r125636 = r125609 - r125635;
        double r125637 = fma(r125621, r125627, r125636);
        double r125638 = r125637 / r125617;
        double r125639 = 6.0;
        double r125640 = pow(r125604, r125639);
        double r125641 = pow(r125610, r125625);
        double r125642 = log1p(r125641);
        double r125643 = expm1(r125642);
        double r125644 = r125640 - r125643;
        double r125645 = fma(r125604, r125604, r125610);
        double r125646 = r125609 * r125645;
        double r125647 = pow(r125604, r125628);
        double r125648 = fma(r125608, r125646, r125647);
        double r125649 = r125644 / r125648;
        double r125650 = r125649 / r125617;
        double r125651 = r125620 ? r125638 : r125650;
        double r125652 = r125603 ? r125618 : r125651;
        return r125652;
}

Error

Bits error versus x

Derivation

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

    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.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-log-exp0.1

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

    if -0.002150518847943042 < x < 0.0017743273033383432

    1. Initial program 29.9

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

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

      \[\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-log-exp29.9

      \[\leadsto \frac{1 \cdot 1 - \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right) \cdot 0.5}{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.2

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

    if 0.0017743273033383432 < 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.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-log-exp0.1

      \[\leadsto \frac{1 \cdot 1 - \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right) \cdot 0.5}{1 + \sqrt{0.5 \cdot \left(1 + \color{blue}{\log \left(e^{\frac{1}{\mathsf{hypot}\left(1, x\right)}}\right)}\right)}}\]
    7. Using strategy rm
    8. Applied flip3--0.1

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

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

      \[\leadsto \frac{\frac{{1}^{6} - {\left(\left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right) \cdot 0.5\right)}^{3}}{\color{blue}{\mathsf{fma}\left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}, 0.5 \cdot \mathsf{fma}\left(1, 1, \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right) \cdot 0.5\right), {1}^{4}\right)}}}{1 + \sqrt{0.5 \cdot \left(1 + \log \left(e^{\frac{1}{\mathsf{hypot}\left(1, x\right)}}\right)\right)}}\]
    11. Using strategy rm
    12. Applied expm1-log1p-u0.1

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -0.002150518847943041871040303902873347396962:\\ \;\;\;\;\frac{1 \cdot 1 - \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right) \cdot 0.5}{1 + \sqrt{0.5 \cdot \left(1 + \log \left(e^{\frac{1}{\mathsf{hypot}\left(1, x\right)}}\right)\right)}}\\ \mathbf{elif}\;x \le 0.001774327303338343181371428158854541834444:\\ \;\;\;\;\frac{\mathsf{fma}\left(0.25, \frac{{x}^{2}}{{\left(\sqrt{1}\right)}^{3}}, 0.5 - \mathsf{fma}\left(\frac{{x}^{4}}{{\left(\sqrt{1}\right)}^{5}}, 0.1875, \frac{0.5}{\sqrt{1}}\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{\frac{{1}^{6} - \mathsf{expm1}\left(\mathsf{log1p}\left({\left(\left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right) \cdot 0.5\right)}^{3}\right)\right)}{\mathsf{fma}\left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}, 0.5 \cdot \mathsf{fma}\left(1, 1, \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right) \cdot 0.5\right), {1}^{4}\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 2019325 +o rules:numerics
(FPCore (x)
  :name "Given's Rotation SVD example, simplified"
  :precision binary64
  (- 1 (sqrt (* 0.5 (+ 1 (/ 1 (hypot 1 x)))))))