Average Error: 12.5 → 12.5
Time: 3.9s
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 \frac{\frac{{\left({1}^{3}\right)}^{3} + {\left({\left(\frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}^{3}\right)}^{3}}{\mathsf{fma}\left({\left(\frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}^{3}, {\left(\frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}^{3} - {1}^{3}, {1}^{6}\right)}}{\mathsf{fma}\left(\frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}, \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}} - 1, 1 \cdot 1\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 \frac{\frac{{\left({1}^{3}\right)}^{3} + {\left({\left(\frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}^{3}\right)}^{3}}{\mathsf{fma}\left({\left(\frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}^{3}, {\left(\frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}^{3} - {1}^{3}, {1}^{6}\right)}}{\mathsf{fma}\left(\frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}, \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}} - 1, 1 \cdot 1\right)}}
double code(double p, double x) {
	return sqrt((0.5 * (1.0 + (x / sqrt((((4.0 * p) * p) + (x * x)))))));
}
double code(double p, double x) {
	return sqrt((0.5 * (((pow(pow(1.0, 3.0), 3.0) + pow(pow((x / sqrt((((4.0 * p) * p) + (x * x)))), 3.0), 3.0)) / fma(pow((x / sqrt((((4.0 * p) * p) + (x * x)))), 3.0), (pow((x / sqrt((((4.0 * p) * p) + (x * x)))), 3.0) - pow(1.0, 3.0)), pow(1.0, 6.0))) / fma((x / sqrt((((4.0 * p) * p) + (x * x)))), ((x / sqrt((((4.0 * p) * p) + (x * x)))) - 1.0), (1.0 * 1.0)))));
}

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.5
Target12.4
Herbie12.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 12.5

    \[\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 flip3-+12.5

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

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

    \[\leadsto \sqrt{0.5 \cdot \frac{\color{blue}{\frac{{\left({1}^{3}\right)}^{3} + {\left({\left(\frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}^{3}\right)}^{3}}{{1}^{3} \cdot {1}^{3} + \left({\left(\frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}^{3} \cdot {\left(\frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}^{3} - {1}^{3} \cdot {\left(\frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}^{3}\right)}}}{\mathsf{fma}\left(\frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}, \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}} - 1, 1 \cdot 1\right)}}\]
  7. Simplified12.5

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

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

Reproduce

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