Average Error: 13.6 → 13.8
Time: 5.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 \left(\sqrt{1 + x \cdot \frac{1}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}} \cdot \sqrt{1 + x \cdot \frac{1}{\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(\sqrt{1 + x \cdot \frac{1}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}} \cdot \sqrt{1 + x \cdot \frac{1}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}}\right)}
double f(double p, double x) {
        double r177017 = 0.5;
        double r177018 = 1.0;
        double r177019 = x;
        double r177020 = 4.0;
        double r177021 = p;
        double r177022 = r177020 * r177021;
        double r177023 = r177022 * r177021;
        double r177024 = r177019 * r177019;
        double r177025 = r177023 + r177024;
        double r177026 = sqrt(r177025);
        double r177027 = r177019 / r177026;
        double r177028 = r177018 + r177027;
        double r177029 = r177017 * r177028;
        double r177030 = sqrt(r177029);
        return r177030;
}

double f(double p, double x) {
        double r177031 = 0.5;
        double r177032 = 1.0;
        double r177033 = x;
        double r177034 = 1.0;
        double r177035 = 4.0;
        double r177036 = p;
        double r177037 = r177035 * r177036;
        double r177038 = r177037 * r177036;
        double r177039 = r177033 * r177033;
        double r177040 = r177038 + r177039;
        double r177041 = sqrt(r177040);
        double r177042 = r177034 / r177041;
        double r177043 = r177033 * r177042;
        double r177044 = r177032 + r177043;
        double r177045 = sqrt(r177044);
        double r177046 = r177045 * r177045;
        double r177047 = r177031 * r177046;
        double r177048 = sqrt(r177047);
        return r177048;
}

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.6
Target13.6
Herbie13.8
\[\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.6

    \[\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.8

    \[\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-sqrt13.8

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

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

Reproduce

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