Average Error: 13.3 → 13.6
Time: 2.0m
Precision: 64
\[10^{-150} \lt \left|x\right| \lt 10^{+150}\]
\[\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}\]
\[\begin{array}{l} \mathbf{if}\;x \le -811.998650832227:\\ \;\;\;\;{e}^{\left(\frac{\log \left(\mathsf{fma}\left(\frac{x}{\mathsf{hypot}\left(x, p \cdot 2\right)}, 0.5, 0.5\right)\right)}{2}\right)}\\ \mathbf{elif}\;x \le -6.093571820386453 \cdot 10^{-07}:\\ \;\;\;\;{e}^{\left(\frac{\mathsf{fma}\left(2, \log \left(\frac{-1}{x}\right) - \log \left(\frac{-1}{p}\right), \log 1.0\right)}{2}\right)}\\ \mathbf{else}:\\ \;\;\;\;{e}^{\left(\frac{\log \left(\mathsf{fma}\left(\frac{x}{\mathsf{hypot}\left(x, p \cdot 2\right)}, 0.5, 0.5\right)\right)}{2}\right)}\\ \end{array}\]
\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}
\begin{array}{l}
\mathbf{if}\;x \le -811.998650832227:\\
\;\;\;\;{e}^{\left(\frac{\log \left(\mathsf{fma}\left(\frac{x}{\mathsf{hypot}\left(x, p \cdot 2\right)}, 0.5, 0.5\right)\right)}{2}\right)}\\

\mathbf{elif}\;x \le -6.093571820386453 \cdot 10^{-07}:\\
\;\;\;\;{e}^{\left(\frac{\mathsf{fma}\left(2, \log \left(\frac{-1}{x}\right) - \log \left(\frac{-1}{p}\right), \log 1.0\right)}{2}\right)}\\

\mathbf{else}:\\
\;\;\;\;{e}^{\left(\frac{\log \left(\mathsf{fma}\left(\frac{x}{\mathsf{hypot}\left(x, p \cdot 2\right)}, 0.5, 0.5\right)\right)}{2}\right)}\\

\end{array}
double f(double p, double x) {
        double r10427983 = 0.5;
        double r10427984 = 1.0;
        double r10427985 = x;
        double r10427986 = 4.0;
        double r10427987 = p;
        double r10427988 = r10427986 * r10427987;
        double r10427989 = r10427988 * r10427987;
        double r10427990 = r10427985 * r10427985;
        double r10427991 = r10427989 + r10427990;
        double r10427992 = sqrt(r10427991);
        double r10427993 = r10427985 / r10427992;
        double r10427994 = r10427984 + r10427993;
        double r10427995 = r10427983 * r10427994;
        double r10427996 = sqrt(r10427995);
        return r10427996;
}

double f(double p, double x) {
        double r10427997 = x;
        double r10427998 = -811.998650832227;
        bool r10427999 = r10427997 <= r10427998;
        double r10428000 = exp(1.0);
        double r10428001 = p;
        double r10428002 = 2.0;
        double r10428003 = r10428001 * r10428002;
        double r10428004 = hypot(r10427997, r10428003);
        double r10428005 = r10427997 / r10428004;
        double r10428006 = 0.5;
        double r10428007 = fma(r10428005, r10428006, r10428006);
        double r10428008 = log(r10428007);
        double r10428009 = r10428008 / r10428002;
        double r10428010 = pow(r10428000, r10428009);
        double r10428011 = -6.093571820386453e-07;
        bool r10428012 = r10427997 <= r10428011;
        double r10428013 = -1.0;
        double r10428014 = r10428013 / r10427997;
        double r10428015 = log(r10428014);
        double r10428016 = r10428013 / r10428001;
        double r10428017 = log(r10428016);
        double r10428018 = r10428015 - r10428017;
        double r10428019 = 1.0;
        double r10428020 = log(r10428019);
        double r10428021 = fma(r10428002, r10428018, r10428020);
        double r10428022 = r10428021 / r10428002;
        double r10428023 = pow(r10428000, r10428022);
        double r10428024 = r10428012 ? r10428023 : r10428010;
        double r10428025 = r10427999 ? r10428010 : r10428024;
        return r10428025;
}

Error

Bits error versus p

Bits error versus x

Target

Original13.3
Target13.3
Herbie13.6
\[\sqrt{\frac{1}{2} + \frac{\mathsf{copysign}\left(\frac{1}{2}, x\right)}{\mathsf{hypot}\left(1, \frac{2 \cdot p}{x}\right)}}\]

Derivation

  1. Split input into 2 regimes
  2. if x < -811.998650832227 or -6.093571820386453e-07 < x

    1. Initial program 13.0

      \[\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}\]
    2. Simplified13.0

      \[\leadsto \color{blue}{\sqrt{\mathsf{fma}\left(\frac{x}{\sqrt{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}}, 0.5, 0.5\right)}}\]
    3. Using strategy rm
    4. Applied add-exp-log13.0

      \[\leadsto \color{blue}{e^{\log \left(\sqrt{\mathsf{fma}\left(\frac{x}{\sqrt{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}}, 0.5, 0.5\right)}\right)}}\]
    5. Using strategy rm
    6. Applied pow1/213.0

      \[\leadsto e^{\log \color{blue}{\left({\left(\mathsf{fma}\left(\frac{x}{\sqrt{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}}, 0.5, 0.5\right)\right)}^{\frac{1}{2}}\right)}}\]
    7. Applied log-pow13.0

      \[\leadsto e^{\color{blue}{\frac{1}{2} \cdot \log \left(\mathsf{fma}\left(\frac{x}{\sqrt{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}}, 0.5, 0.5\right)\right)}}\]
    8. Applied exp-prod13.0

      \[\leadsto \color{blue}{{\left(e^{\frac{1}{2}}\right)}^{\left(\log \left(\mathsf{fma}\left(\frac{x}{\sqrt{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}}, 0.5, 0.5\right)\right)\right)}}\]
    9. Simplified13.0

      \[\leadsto {\color{blue}{\left(\sqrt{e}\right)}}^{\left(\log \left(\mathsf{fma}\left(\frac{x}{\sqrt{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}}, 0.5, 0.5\right)\right)\right)}\]
    10. Using strategy rm
    11. Applied pow1/213.0

      \[\leadsto {\color{blue}{\left({e}^{\frac{1}{2}}\right)}}^{\left(\log \left(\mathsf{fma}\left(\frac{x}{\sqrt{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}}, 0.5, 0.5\right)\right)\right)}\]
    12. Applied pow-pow13.0

      \[\leadsto \color{blue}{{e}^{\left(\frac{1}{2} \cdot \log \left(\mathsf{fma}\left(\frac{x}{\sqrt{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}}, 0.5, 0.5\right)\right)\right)}}\]
    13. Simplified13.0

      \[\leadsto {e}^{\color{blue}{\left(\frac{\log \left(\mathsf{fma}\left(\frac{x}{\mathsf{hypot}\left(x, p \cdot 2\right)}, 0.5, 0.5\right)\right)}{2}\right)}}\]

    if -811.998650832227 < x < -6.093571820386453e-07

    1. Initial program 31.3

      \[\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}\]
    2. Simplified31.3

      \[\leadsto \color{blue}{\sqrt{\mathsf{fma}\left(\frac{x}{\sqrt{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}}, 0.5, 0.5\right)}}\]
    3. Using strategy rm
    4. Applied add-exp-log31.3

      \[\leadsto \color{blue}{e^{\log \left(\sqrt{\mathsf{fma}\left(\frac{x}{\sqrt{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}}, 0.5, 0.5\right)}\right)}}\]
    5. Using strategy rm
    6. Applied pow1/231.3

      \[\leadsto e^{\log \color{blue}{\left({\left(\mathsf{fma}\left(\frac{x}{\sqrt{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}}, 0.5, 0.5\right)\right)}^{\frac{1}{2}}\right)}}\]
    7. Applied log-pow31.3

      \[\leadsto e^{\color{blue}{\frac{1}{2} \cdot \log \left(\mathsf{fma}\left(\frac{x}{\sqrt{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}}, 0.5, 0.5\right)\right)}}\]
    8. Applied exp-prod31.3

      \[\leadsto \color{blue}{{\left(e^{\frac{1}{2}}\right)}^{\left(\log \left(\mathsf{fma}\left(\frac{x}{\sqrt{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}}, 0.5, 0.5\right)\right)\right)}}\]
    9. Simplified31.3

      \[\leadsto {\color{blue}{\left(\sqrt{e}\right)}}^{\left(\log \left(\mathsf{fma}\left(\frac{x}{\sqrt{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}}, 0.5, 0.5\right)\right)\right)}\]
    10. Using strategy rm
    11. Applied pow1/231.3

      \[\leadsto {\color{blue}{\left({e}^{\frac{1}{2}}\right)}}^{\left(\log \left(\mathsf{fma}\left(\frac{x}{\sqrt{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}}, 0.5, 0.5\right)\right)\right)}\]
    12. Applied pow-pow31.3

      \[\leadsto \color{blue}{{e}^{\left(\frac{1}{2} \cdot \log \left(\mathsf{fma}\left(\frac{x}{\sqrt{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}}, 0.5, 0.5\right)\right)\right)}}\]
    13. Simplified31.3

      \[\leadsto {e}^{\color{blue}{\left(\frac{\log \left(\mathsf{fma}\left(\frac{x}{\mathsf{hypot}\left(x, p \cdot 2\right)}, 0.5, 0.5\right)\right)}{2}\right)}}\]
    14. Taylor expanded around -inf 47.0

      \[\leadsto {e}^{\left(\frac{\color{blue}{\left(\log 1.0 + 2 \cdot \log \left(\frac{-1}{x}\right)\right) - 2 \cdot \log \left(\frac{-1}{p}\right)}}{2}\right)}\]
    15. Simplified47.0

      \[\leadsto {e}^{\left(\frac{\color{blue}{\mathsf{fma}\left(2, \log \left(\frac{-1}{x}\right) - \log \left(\frac{-1}{p}\right), \log 1.0\right)}}{2}\right)}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification13.6

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -811.998650832227:\\ \;\;\;\;{e}^{\left(\frac{\log \left(\mathsf{fma}\left(\frac{x}{\mathsf{hypot}\left(x, p \cdot 2\right)}, 0.5, 0.5\right)\right)}{2}\right)}\\ \mathbf{elif}\;x \le -6.093571820386453 \cdot 10^{-07}:\\ \;\;\;\;{e}^{\left(\frac{\mathsf{fma}\left(2, \log \left(\frac{-1}{x}\right) - \log \left(\frac{-1}{p}\right), \log 1.0\right)}{2}\right)}\\ \mathbf{else}:\\ \;\;\;\;{e}^{\left(\frac{\log \left(\mathsf{fma}\left(\frac{x}{\mathsf{hypot}\left(x, p \cdot 2\right)}, 0.5, 0.5\right)\right)}{2}\right)}\\ \end{array}\]

Reproduce

herbie shell --seed 2019168 +o rules:numerics
(FPCore (p x)
  :name "Given's Rotation SVD example"
  :pre (< 1e-150 (fabs x) 1e+150)

  :herbie-target
  (sqrt (+ 1/2 (/ (copysign 1/2 x) (hypot 1 (/ (* 2 p) x)))))

  (sqrt (* 0.5 (+ 1 (/ x (sqrt (+ (* (* 4 p) p) (* x x))))))))