Average Error: 12.9 → 13.1
Time: 34.0s
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{\left(\frac{1}{x \cdot x + \left(4 \cdot p\right) \cdot p} \cdot \left(x \cdot x\right)\right) \cdot \frac{x}{\sqrt{x \cdot x + \left(4 \cdot p\right) \cdot p}} + 1 \cdot \left(1 \cdot 1\right)}{\frac{x}{\sqrt{x \cdot x + \left(4 \cdot p\right) \cdot p}} \cdot \left(\frac{x}{\sqrt{x \cdot x + \left(4 \cdot p\right) \cdot p}} - 1\right) + 1 \cdot 1}}\]
\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{1}{x \cdot x + \left(4 \cdot p\right) \cdot p} \cdot \left(x \cdot x\right)\right) \cdot \frac{x}{\sqrt{x \cdot x + \left(4 \cdot p\right) \cdot p}} + 1 \cdot \left(1 \cdot 1\right)}{\frac{x}{\sqrt{x \cdot x + \left(4 \cdot p\right) \cdot p}} \cdot \left(\frac{x}{\sqrt{x \cdot x + \left(4 \cdot p\right) \cdot p}} - 1\right) + 1 \cdot 1}}
double f(double p, double x) {
        double r12891325 = 0.5;
        double r12891326 = 1.0;
        double r12891327 = x;
        double r12891328 = 4.0;
        double r12891329 = p;
        double r12891330 = r12891328 * r12891329;
        double r12891331 = r12891330 * r12891329;
        double r12891332 = r12891327 * r12891327;
        double r12891333 = r12891331 + r12891332;
        double r12891334 = sqrt(r12891333);
        double r12891335 = r12891327 / r12891334;
        double r12891336 = r12891326 + r12891335;
        double r12891337 = r12891325 * r12891336;
        double r12891338 = sqrt(r12891337);
        return r12891338;
}

double f(double p, double x) {
        double r12891339 = 0.5;
        double r12891340 = 1.0;
        double r12891341 = x;
        double r12891342 = r12891341 * r12891341;
        double r12891343 = 4.0;
        double r12891344 = p;
        double r12891345 = r12891343 * r12891344;
        double r12891346 = r12891345 * r12891344;
        double r12891347 = r12891342 + r12891346;
        double r12891348 = r12891340 / r12891347;
        double r12891349 = r12891348 * r12891342;
        double r12891350 = sqrt(r12891347);
        double r12891351 = r12891341 / r12891350;
        double r12891352 = r12891349 * r12891351;
        double r12891353 = 1.0;
        double r12891354 = r12891353 * r12891353;
        double r12891355 = r12891353 * r12891354;
        double r12891356 = r12891352 + r12891355;
        double r12891357 = r12891351 - r12891353;
        double r12891358 = r12891351 * r12891357;
        double r12891359 = r12891358 + r12891354;
        double r12891360 = r12891356 / r12891359;
        double r12891361 = r12891339 * r12891360;
        double r12891362 = sqrt(r12891361);
        return r12891362;
}

Error

Bits error versus p

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original12.9
Target12.9
Herbie13.1
\[\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 clear-num12.9

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

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

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

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

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

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

Reproduce

herbie shell --seed 2019200 
(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))))))))