Average Error: 13.5 → 14.8
Time: 16.6s
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 \sqrt[3]{{\left(1 + \frac{x}{\left(\sqrt{\left|\sqrt[3]{\mathsf{fma}\left(4, {p}^{2}, x \cdot x\right)}\right|} \cdot \sqrt{\sqrt{\mathsf{fma}\left(4, {p}^{2}, x \cdot x\right)}}\right) \cdot \sqrt{\sqrt{\sqrt[3]{\mathsf{fma}\left(4, {p}^{2}, x \cdot x\right)}}}}\right)}^{3}}}\]
\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}
\sqrt{0.5 \cdot \sqrt[3]{{\left(1 + \frac{x}{\left(\sqrt{\left|\sqrt[3]{\mathsf{fma}\left(4, {p}^{2}, x \cdot x\right)}\right|} \cdot \sqrt{\sqrt{\mathsf{fma}\left(4, {p}^{2}, x \cdot x\right)}}\right) \cdot \sqrt{\sqrt{\sqrt[3]{\mathsf{fma}\left(4, {p}^{2}, x \cdot x\right)}}}}\right)}^{3}}}
double f(double p, double x) {
        double r229204 = 0.5;
        double r229205 = 1.0;
        double r229206 = x;
        double r229207 = 4.0;
        double r229208 = p;
        double r229209 = r229207 * r229208;
        double r229210 = r229209 * r229208;
        double r229211 = r229206 * r229206;
        double r229212 = r229210 + r229211;
        double r229213 = sqrt(r229212);
        double r229214 = r229206 / r229213;
        double r229215 = r229205 + r229214;
        double r229216 = r229204 * r229215;
        double r229217 = sqrt(r229216);
        return r229217;
}

double f(double p, double x) {
        double r229218 = 0.5;
        double r229219 = 1.0;
        double r229220 = x;
        double r229221 = 4.0;
        double r229222 = p;
        double r229223 = 2.0;
        double r229224 = pow(r229222, r229223);
        double r229225 = r229220 * r229220;
        double r229226 = fma(r229221, r229224, r229225);
        double r229227 = cbrt(r229226);
        double r229228 = fabs(r229227);
        double r229229 = sqrt(r229228);
        double r229230 = sqrt(r229226);
        double r229231 = sqrt(r229230);
        double r229232 = r229229 * r229231;
        double r229233 = sqrt(r229227);
        double r229234 = sqrt(r229233);
        double r229235 = r229232 * r229234;
        double r229236 = r229220 / r229235;
        double r229237 = r229219 + r229236;
        double r229238 = 3.0;
        double r229239 = pow(r229237, r229238);
        double r229240 = cbrt(r229239);
        double r229241 = r229218 * r229240;
        double r229242 = sqrt(r229241);
        return r229242;
}

Error

Bits error versus p

Bits error versus x

Target

Original13.5
Target13.5
Herbie14.8
\[\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.5

    \[\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 add-sqr-sqrt13.5

    \[\leadsto \sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\color{blue}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x} \cdot \sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}}}\right)}\]
  4. Applied sqrt-prod14.5

    \[\leadsto \sqrt{0.5 \cdot \left(1 + \frac{x}{\color{blue}{\sqrt{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}} \cdot \sqrt{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}}}\right)}\]
  5. Simplified14.5

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

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

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

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

    \[\leadsto \sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\sqrt{\mathsf{fma}\left(4, {p}^{2}, x \cdot x\right)}} \cdot \color{blue}{\left(\sqrt{\sqrt{\sqrt[3]{\mathsf{fma}\left(4, {p}^{2}, x \cdot x\right)} \cdot \sqrt[3]{\mathsf{fma}\left(4, {p}^{2}, x \cdot x\right)}}} \cdot \sqrt{\sqrt{\sqrt[3]{\mathsf{fma}\left(4, {p}^{2}, x \cdot x\right)}}}\right)}}\right)}\]
  11. Applied associate-*r*14.8

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

    \[\leadsto \sqrt{0.5 \cdot \left(1 + \frac{x}{\color{blue}{\left(\sqrt{\left|\sqrt[3]{\mathsf{fma}\left(4, {p}^{2}, x \cdot x\right)}\right|} \cdot \sqrt{\sqrt{\mathsf{fma}\left(4, {p}^{2}, x \cdot x\right)}}\right)} \cdot \sqrt{\sqrt{\sqrt[3]{\mathsf{fma}\left(4, {p}^{2}, x \cdot x\right)}}}}\right)}\]
  13. Using strategy rm
  14. Applied add-cbrt-cube14.8

    \[\leadsto \sqrt{0.5 \cdot \color{blue}{\sqrt[3]{\left(\left(1 + \frac{x}{\left(\sqrt{\left|\sqrt[3]{\mathsf{fma}\left(4, {p}^{2}, x \cdot x\right)}\right|} \cdot \sqrt{\sqrt{\mathsf{fma}\left(4, {p}^{2}, x \cdot x\right)}}\right) \cdot \sqrt{\sqrt{\sqrt[3]{\mathsf{fma}\left(4, {p}^{2}, x \cdot x\right)}}}}\right) \cdot \left(1 + \frac{x}{\left(\sqrt{\left|\sqrt[3]{\mathsf{fma}\left(4, {p}^{2}, x \cdot x\right)}\right|} \cdot \sqrt{\sqrt{\mathsf{fma}\left(4, {p}^{2}, x \cdot x\right)}}\right) \cdot \sqrt{\sqrt{\sqrt[3]{\mathsf{fma}\left(4, {p}^{2}, x \cdot x\right)}}}}\right)\right) \cdot \left(1 + \frac{x}{\left(\sqrt{\left|\sqrt[3]{\mathsf{fma}\left(4, {p}^{2}, x \cdot x\right)}\right|} \cdot \sqrt{\sqrt{\mathsf{fma}\left(4, {p}^{2}, x \cdot x\right)}}\right) \cdot \sqrt{\sqrt{\sqrt[3]{\mathsf{fma}\left(4, {p}^{2}, x \cdot x\right)}}}}\right)}}}\]
  15. Simplified14.8

    \[\leadsto \sqrt{0.5 \cdot \sqrt[3]{\color{blue}{{\left(1 + \frac{x}{\left(\sqrt{\left|\sqrt[3]{\mathsf{fma}\left(4, {p}^{2}, x \cdot x\right)}\right|} \cdot \sqrt{\sqrt{\mathsf{fma}\left(4, {p}^{2}, x \cdot x\right)}}\right) \cdot \sqrt{\sqrt{\sqrt[3]{\mathsf{fma}\left(4, {p}^{2}, x \cdot x\right)}}}}\right)}^{3}}}}\]
  16. Final simplification14.8

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

Reproduce

herbie shell --seed 2019325 +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))))))))