Average Error: 12.9 → 13.1
Time: 34.3s
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 r12891001 = 0.5;
        double r12891002 = 1.0;
        double r12891003 = x;
        double r12891004 = 4.0;
        double r12891005 = p;
        double r12891006 = r12891004 * r12891005;
        double r12891007 = r12891006 * r12891005;
        double r12891008 = r12891003 * r12891003;
        double r12891009 = r12891007 + r12891008;
        double r12891010 = sqrt(r12891009);
        double r12891011 = r12891003 / r12891010;
        double r12891012 = r12891002 + r12891011;
        double r12891013 = r12891001 * r12891012;
        double r12891014 = sqrt(r12891013);
        return r12891014;
}

double f(double p, double x) {
        double r12891015 = 0.5;
        double r12891016 = 1.0;
        double r12891017 = x;
        double r12891018 = r12891017 * r12891017;
        double r12891019 = 4.0;
        double r12891020 = p;
        double r12891021 = r12891019 * r12891020;
        double r12891022 = r12891021 * r12891020;
        double r12891023 = r12891018 + r12891022;
        double r12891024 = r12891016 / r12891023;
        double r12891025 = r12891024 * r12891018;
        double r12891026 = sqrt(r12891023);
        double r12891027 = r12891017 / r12891026;
        double r12891028 = r12891025 * r12891027;
        double r12891029 = 1.0;
        double r12891030 = r12891029 * r12891029;
        double r12891031 = r12891029 * r12891030;
        double r12891032 = r12891028 + r12891031;
        double r12891033 = r12891027 - r12891029;
        double r12891034 = r12891027 * r12891033;
        double r12891035 = r12891034 + r12891030;
        double r12891036 = r12891032 / r12891035;
        double r12891037 = r12891015 * r12891036;
        double r12891038 = sqrt(r12891037);
        return r12891038;
}

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))))))))