Average Error: 13.0 → 13.0
Time: 16.5s
Precision: 64
\[1.000000000000000006295358232172963997211 \cdot 10^{-150} \lt \left|x\right| \lt 9.999999999999999808355961724373745905731 \cdot 10^{149}\]
\[\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}\]
\[\sqrt{\log \left(e^{\frac{x}{\sqrt{\mathsf{fma}\left(4 \cdot p, p, x \cdot x\right)}} + 1}\right) \cdot 0.5}\]
\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}
\sqrt{\log \left(e^{\frac{x}{\sqrt{\mathsf{fma}\left(4 \cdot p, p, x \cdot x\right)}} + 1}\right) \cdot 0.5}
double f(double p, double x) {
        double r297995 = 0.5;
        double r297996 = 1.0;
        double r297997 = x;
        double r297998 = 4.0;
        double r297999 = p;
        double r298000 = r297998 * r297999;
        double r298001 = r298000 * r297999;
        double r298002 = r297997 * r297997;
        double r298003 = r298001 + r298002;
        double r298004 = sqrt(r298003);
        double r298005 = r297997 / r298004;
        double r298006 = r297996 + r298005;
        double r298007 = r297995 * r298006;
        double r298008 = sqrt(r298007);
        return r298008;
}

double f(double p, double x) {
        double r298009 = x;
        double r298010 = 4.0;
        double r298011 = p;
        double r298012 = r298010 * r298011;
        double r298013 = r298009 * r298009;
        double r298014 = fma(r298012, r298011, r298013);
        double r298015 = sqrt(r298014);
        double r298016 = r298009 / r298015;
        double r298017 = 1.0;
        double r298018 = r298016 + r298017;
        double r298019 = exp(r298018);
        double r298020 = log(r298019);
        double r298021 = 0.5;
        double r298022 = r298020 * r298021;
        double r298023 = sqrt(r298022);
        return r298023;
}

Error

Bits error versus p

Bits error versus x

Target

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

Derivation

  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{\left(\frac{x}{\sqrt{\mathsf{fma}\left(4 \cdot p, p, x \cdot x\right)}} + 1\right) \cdot 0.5}}\]
  3. Using strategy rm
  4. Applied add-log-exp13.0

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

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

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

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

    \[\leadsto \sqrt{\log \left(e^{\frac{x}{\sqrt{\mathsf{fma}\left(4 \cdot p, p, x \cdot x\right)}} + 1}\right) \cdot 0.5}\]

Reproduce

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

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

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