Average Error: 13.4 → 13.5
Time: 9.9s
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{x}{\sqrt{\mathsf{fma}\left(4, {p}^{2}, {x}^{2}\right)}}\right)}^{3} + {1}^{3}}{\mathsf{fma}\left(1, \mathsf{expm1}\left(\mathsf{log1p}\left(1 - \frac{x}{\sqrt{\mathsf{fma}\left(4, {p}^{2}, {x}^{2}\right)}}\right)\right), \frac{x \cdot x}{\mathsf{fma}\left(4, {p}^{2}, {x}^{2}\right)}\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{{\left(\frac{x}{\sqrt{\mathsf{fma}\left(4, {p}^{2}, {x}^{2}\right)}}\right)}^{3} + {1}^{3}}{\mathsf{fma}\left(1, \mathsf{expm1}\left(\mathsf{log1p}\left(1 - \frac{x}{\sqrt{\mathsf{fma}\left(4, {p}^{2}, {x}^{2}\right)}}\right)\right), \frac{x \cdot x}{\mathsf{fma}\left(4, {p}^{2}, {x}^{2}\right)}\right)}}
double f(double p, double x) {
        double r223931 = 0.5;
        double r223932 = 1.0;
        double r223933 = x;
        double r223934 = 4.0;
        double r223935 = p;
        double r223936 = r223934 * r223935;
        double r223937 = r223936 * r223935;
        double r223938 = r223933 * r223933;
        double r223939 = r223937 + r223938;
        double r223940 = sqrt(r223939);
        double r223941 = r223933 / r223940;
        double r223942 = r223932 + r223941;
        double r223943 = r223931 * r223942;
        double r223944 = sqrt(r223943);
        return r223944;
}

double f(double p, double x) {
        double r223945 = 0.5;
        double r223946 = x;
        double r223947 = 4.0;
        double r223948 = p;
        double r223949 = 2.0;
        double r223950 = pow(r223948, r223949);
        double r223951 = pow(r223946, r223949);
        double r223952 = fma(r223947, r223950, r223951);
        double r223953 = sqrt(r223952);
        double r223954 = r223946 / r223953;
        double r223955 = 3.0;
        double r223956 = pow(r223954, r223955);
        double r223957 = 1.0;
        double r223958 = pow(r223957, r223955);
        double r223959 = r223956 + r223958;
        double r223960 = r223957 - r223954;
        double r223961 = log1p(r223960);
        double r223962 = expm1(r223961);
        double r223963 = r223946 * r223946;
        double r223964 = r223963 / r223952;
        double r223965 = fma(r223957, r223962, r223964);
        double r223966 = r223959 / r223965;
        double r223967 = r223945 * r223966;
        double r223968 = sqrt(r223967);
        return r223968;
}

Error

Bits error versus p

Bits error versus x

Target

Original13.4
Target13.5
Herbie13.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 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 flip3-+13.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. Simplified13.5

    \[\leadsto \sqrt{0.5 \cdot \frac{\color{blue}{{\left(\frac{x}{\sqrt{\mathsf{fma}\left(4, {p}^{2}, {x}^{2}\right)}}\right)}^{3} + {1}^{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)}}\]
  5. Simplified13.5

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

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

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

Reproduce

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