Average Error: 13.4 → 13.4
Time: 4.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 \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\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 \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}
double f(double p, double x) {
        double r254292 = 0.5;
        double r254293 = 1.0;
        double r254294 = x;
        double r254295 = 4.0;
        double r254296 = p;
        double r254297 = r254295 * r254296;
        double r254298 = r254297 * r254296;
        double r254299 = r254294 * r254294;
        double r254300 = r254298 + r254299;
        double r254301 = sqrt(r254300);
        double r254302 = r254294 / r254301;
        double r254303 = r254293 + r254302;
        double r254304 = r254292 * r254303;
        double r254305 = sqrt(r254304);
        return r254305;
}

double f(double p, double x) {
        double r254306 = 0.5;
        double r254307 = 1.0;
        double r254308 = x;
        double r254309 = 4.0;
        double r254310 = p;
        double r254311 = r254309 * r254310;
        double r254312 = r254311 * r254310;
        double r254313 = r254308 * r254308;
        double r254314 = r254312 + r254313;
        double r254315 = sqrt(r254314);
        double r254316 = r254308 / r254315;
        double r254317 = r254307 + r254316;
        double r254318 = r254306 * r254317;
        double r254319 = sqrt(r254318);
        return r254319;
}

Error

Bits error versus p

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

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 div-inv13.6

    \[\leadsto \sqrt{0.5 \cdot \left(1 + \color{blue}{x \cdot \frac{1}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}}\right)}\]
  4. Using strategy rm
  5. Applied add-sqr-sqrt14.5

    \[\leadsto \sqrt{0.5 \cdot \left(1 + x \cdot \color{blue}{\left(\sqrt{\frac{1}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}} \cdot \sqrt{\frac{1}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}}\right)}\right)}\]
  6. Applied associate-*r*14.5

    \[\leadsto \sqrt{0.5 \cdot \left(1 + \color{blue}{\left(x \cdot \sqrt{\frac{1}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}}\right) \cdot \sqrt{\frac{1}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}}}\right)}\]
  7. Using strategy rm
  8. Applied sqrt-div14.1

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

    \[\leadsto \sqrt{0.5 \cdot \left(1 + \left(x \cdot \color{blue}{\frac{\sqrt{1}}{\sqrt{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}}}\right) \cdot \frac{\sqrt{1}}{\sqrt{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}}\right)}\]
  10. Applied associate-*r/14.4

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

    \[\leadsto \sqrt{0.5 \cdot \left(1 + \color{blue}{\frac{\left(x \cdot \sqrt{1}\right) \cdot \sqrt{1}}{\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)}\]
  12. Simplified14.4

    \[\leadsto \sqrt{0.5 \cdot \left(1 + \frac{\color{blue}{x}}{\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)}\]
  13. Simplified13.4

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

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

Reproduce

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