Average Error: 13.1 → 13.5
Time: 13.4s
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{\left(\left(\sqrt[3]{x} \cdot \sqrt[3]{x}\right) \cdot \frac{\sqrt[3]{x}}{\sqrt[3]{\sqrt{\mathsf{fma}\left(p \cdot 4, p, x \cdot x\right)}} \cdot \left(\sqrt[3]{\sqrt{\mathsf{fma}\left(p \cdot 4, p, x \cdot x\right)}} \cdot \sqrt[3]{\sqrt{\mathsf{fma}\left(p \cdot 4, p, x \cdot x\right)}}\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{\left(\left(\sqrt[3]{x} \cdot \sqrt[3]{x}\right) \cdot \frac{\sqrt[3]{x}}{\sqrt[3]{\sqrt{\mathsf{fma}\left(p \cdot 4, p, x \cdot x\right)}} \cdot \left(\sqrt[3]{\sqrt{\mathsf{fma}\left(p \cdot 4, p, x \cdot x\right)}} \cdot \sqrt[3]{\sqrt{\mathsf{fma}\left(p \cdot 4, p, x \cdot x\right)}}\right)} + 1\right) \cdot 0.5}
double f(double p, double x) {
        double r10031214 = 0.5;
        double r10031215 = 1.0;
        double r10031216 = x;
        double r10031217 = 4.0;
        double r10031218 = p;
        double r10031219 = r10031217 * r10031218;
        double r10031220 = r10031219 * r10031218;
        double r10031221 = r10031216 * r10031216;
        double r10031222 = r10031220 + r10031221;
        double r10031223 = sqrt(r10031222);
        double r10031224 = r10031216 / r10031223;
        double r10031225 = r10031215 + r10031224;
        double r10031226 = r10031214 * r10031225;
        double r10031227 = sqrt(r10031226);
        return r10031227;
}

double f(double p, double x) {
        double r10031228 = x;
        double r10031229 = cbrt(r10031228);
        double r10031230 = r10031229 * r10031229;
        double r10031231 = p;
        double r10031232 = 4.0;
        double r10031233 = r10031231 * r10031232;
        double r10031234 = r10031228 * r10031228;
        double r10031235 = fma(r10031233, r10031231, r10031234);
        double r10031236 = sqrt(r10031235);
        double r10031237 = cbrt(r10031236);
        double r10031238 = r10031237 * r10031237;
        double r10031239 = r10031237 * r10031238;
        double r10031240 = r10031229 / r10031239;
        double r10031241 = r10031230 * r10031240;
        double r10031242 = 1.0;
        double r10031243 = r10031241 + r10031242;
        double r10031244 = 0.5;
        double r10031245 = r10031243 * r10031244;
        double r10031246 = sqrt(r10031245);
        return r10031246;
}

Error

Bits error versus p

Bits error versus x

Target

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

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

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

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

    \[\leadsto \sqrt{\left(1 + \color{blue}{\left(\left(\sqrt[3]{x} \cdot \sqrt[3]{x}\right) \cdot \sqrt[3]{x}\right)} \cdot \frac{1}{\sqrt{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}}\right) \cdot 0.5}\]
  7. Applied associate-*l*14.9

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

    \[\leadsto \sqrt{\left(1 + \left(\sqrt[3]{x} \cdot \sqrt[3]{x}\right) \cdot \color{blue}{\frac{\sqrt[3]{x}}{\sqrt{\mathsf{fma}\left(p \cdot 4, p, x \cdot x\right)}}}\right) \cdot 0.5}\]
  9. Using strategy rm
  10. Applied add-cube-cbrt13.5

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

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

Reproduce

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

  :herbie-target
  (sqrt (+ 0.5 (/ (copysign 0.5 x) (hypot 1.0 (/ (* 2.0 p) x)))))

  (sqrt (* 0.5 (+ 1.0 (/ x (sqrt (+ (* (* 4.0 p) p) (* x x))))))))