Average Error: 12.9 → 13.0
Time: 17.8s
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{0.5 \cdot \frac{\log \left(e^{{\left(\frac{x}{\sqrt{\mathsf{fma}\left(4, {p}^{2}, {x}^{2}\right)}}\right)}^{3} + {1}^{3}}\right)}{\mathsf{fma}\left(\frac{x}{\mathsf{fma}\left(4, {p}^{2}, {x}^{2}\right)}, x, 1 \cdot \left(1 - \frac{x}{\sqrt{\mathsf{fma}\left(4, {p}^{2}, {x}^{2}\right)}}\right)\right)}}\]
\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}
\sqrt{0.5 \cdot \frac{\log \left(e^{{\left(\frac{x}{\sqrt{\mathsf{fma}\left(4, {p}^{2}, {x}^{2}\right)}}\right)}^{3} + {1}^{3}}\right)}{\mathsf{fma}\left(\frac{x}{\mathsf{fma}\left(4, {p}^{2}, {x}^{2}\right)}, x, 1 \cdot \left(1 - \frac{x}{\sqrt{\mathsf{fma}\left(4, {p}^{2}, {x}^{2}\right)}}\right)\right)}}
double f(double p, double x) {
        double r175996 = 0.5;
        double r175997 = 1.0;
        double r175998 = x;
        double r175999 = 4.0;
        double r176000 = p;
        double r176001 = r175999 * r176000;
        double r176002 = r176001 * r176000;
        double r176003 = r175998 * r175998;
        double r176004 = r176002 + r176003;
        double r176005 = sqrt(r176004);
        double r176006 = r175998 / r176005;
        double r176007 = r175997 + r176006;
        double r176008 = r175996 * r176007;
        double r176009 = sqrt(r176008);
        return r176009;
}

double f(double p, double x) {
        double r176010 = 0.5;
        double r176011 = x;
        double r176012 = 4.0;
        double r176013 = p;
        double r176014 = 2.0;
        double r176015 = pow(r176013, r176014);
        double r176016 = pow(r176011, r176014);
        double r176017 = fma(r176012, r176015, r176016);
        double r176018 = sqrt(r176017);
        double r176019 = r176011 / r176018;
        double r176020 = 3.0;
        double r176021 = pow(r176019, r176020);
        double r176022 = 1.0;
        double r176023 = pow(r176022, r176020);
        double r176024 = r176021 + r176023;
        double r176025 = exp(r176024);
        double r176026 = log(r176025);
        double r176027 = r176011 / r176017;
        double r176028 = r176022 - r176019;
        double r176029 = r176022 * r176028;
        double r176030 = fma(r176027, r176011, r176029);
        double r176031 = r176026 / r176030;
        double r176032 = r176010 * r176031;
        double r176033 = sqrt(r176032);
        return r176033;
}

Error

Bits error versus p

Bits error versus x

Target

Original12.9
Target12.9
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 12.9

    \[\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}\]
  2. Using strategy rm
  3. Applied flip3-+12.9

    \[\leadsto \sqrt{0.5 \cdot \color{blue}{\frac{{1}^{3} + {\left(\frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}^{3}}{1 \cdot 1 + \left(\frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}} \cdot \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}} - 1 \cdot \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}}}\]
  4. Simplified12.9

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

    \[\leadsto \sqrt{0.5 \cdot \frac{{\left(\frac{x}{\sqrt{\mathsf{fma}\left(4, {p}^{2}, {x}^{2}\right)}}\right)}^{3} + {1}^{3}}{\color{blue}{\mathsf{fma}\left(\frac{x}{\mathsf{fma}\left(4, {p}^{2}, {x}^{2}\right)}, x, 1 \cdot \left(1 - \frac{x}{\sqrt{\mathsf{fma}\left(4, {p}^{2}, {x}^{2}\right)}}\right)\right)}}}\]
  6. Using strategy rm
  7. Applied add-log-exp13.0

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

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

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

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

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

Reproduce

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

  :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))))))))