Average Error: 13.4 → 13.4
Time: 10.5s
Precision: 64
\[1.00000000000000001 \cdot 10^{-150} \lt \left|x\right| \lt 9.99999999999999981 \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{{\left(\frac{x}{\sqrt{\mathsf{fma}\left(4, {p}^{2}, x \cdot x\right)}}\right)}^{3} + {1}^{3}}{\mathsf{fma}\left(1, 1, \frac{x}{e^{\log \left(\sqrt{\mathsf{fma}\left(4, {p}^{2}, x \cdot x\right)}\right)}} \cdot \left(\frac{x}{\sqrt{\mathsf{fma}\left(4, {p}^{2}, x \cdot x\right)}} - 1\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{{\left(\frac{x}{\sqrt{\mathsf{fma}\left(4, {p}^{2}, x \cdot x\right)}}\right)}^{3} + {1}^{3}}{\mathsf{fma}\left(1, 1, \frac{x}{e^{\log \left(\sqrt{\mathsf{fma}\left(4, {p}^{2}, x \cdot x\right)}\right)}} \cdot \left(\frac{x}{\sqrt{\mathsf{fma}\left(4, {p}^{2}, x \cdot x\right)}} - 1\right)\right)}}
double f(double p, double x) {
        double r317209 = 0.5;
        double r317210 = 1.0;
        double r317211 = x;
        double r317212 = 4.0;
        double r317213 = p;
        double r317214 = r317212 * r317213;
        double r317215 = r317214 * r317213;
        double r317216 = r317211 * r317211;
        double r317217 = r317215 + r317216;
        double r317218 = sqrt(r317217);
        double r317219 = r317211 / r317218;
        double r317220 = r317210 + r317219;
        double r317221 = r317209 * r317220;
        double r317222 = sqrt(r317221);
        return r317222;
}

double f(double p, double x) {
        double r317223 = 0.5;
        double r317224 = x;
        double r317225 = 4.0;
        double r317226 = p;
        double r317227 = 2.0;
        double r317228 = pow(r317226, r317227);
        double r317229 = r317224 * r317224;
        double r317230 = fma(r317225, r317228, r317229);
        double r317231 = sqrt(r317230);
        double r317232 = r317224 / r317231;
        double r317233 = 3.0;
        double r317234 = pow(r317232, r317233);
        double r317235 = 1.0;
        double r317236 = pow(r317235, r317233);
        double r317237 = r317234 + r317236;
        double r317238 = log(r317231);
        double r317239 = exp(r317238);
        double r317240 = r317224 / r317239;
        double r317241 = r317232 - r317235;
        double r317242 = r317240 * r317241;
        double r317243 = fma(r317235, r317235, r317242);
        double r317244 = r317237 / r317243;
        double r317245 = r317223 * r317244;
        double r317246 = sqrt(r317245);
        return r317246;
}

Error

Bits error versus p

Bits error versus x

Target

Original13.4
Target13.4
Herbie13.4
\[\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.4

    \[\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-+13.4

    \[\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. Simplified13.4

    \[\leadsto \sqrt{0.5 \cdot \frac{\color{blue}{{\left(\frac{x}{\sqrt{\mathsf{fma}\left(4, {p}^{2}, x \cdot x\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.4

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

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

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

Reproduce

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