Average Error: 13.2 → 13.2
Time: 2.1m
Precision: 64
\[10^{-150} \lt \left|x\right| \lt 10^{+150}\]
\[\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}\]
\[\sqrt[3]{\mathsf{fma}\left(0.5, \frac{x}{\sqrt{\mathsf{fma}\left(p \cdot 4, p, x \cdot x\right)}}, 0.5\right) \cdot \sqrt{\mathsf{fma}\left(0.5, \frac{x}{\sqrt{\mathsf{fma}\left(p \cdot 4, p, x \cdot x\right)}}, 0.5\right)}}\]
\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}
\sqrt[3]{\mathsf{fma}\left(0.5, \frac{x}{\sqrt{\mathsf{fma}\left(p \cdot 4, p, x \cdot x\right)}}, 0.5\right) \cdot \sqrt{\mathsf{fma}\left(0.5, \frac{x}{\sqrt{\mathsf{fma}\left(p \cdot 4, p, x \cdot x\right)}}, 0.5\right)}}
double f(double p, double x) {
        double r10021133 = 0.5;
        double r10021134 = 1.0;
        double r10021135 = x;
        double r10021136 = 4.0;
        double r10021137 = p;
        double r10021138 = r10021136 * r10021137;
        double r10021139 = r10021138 * r10021137;
        double r10021140 = r10021135 * r10021135;
        double r10021141 = r10021139 + r10021140;
        double r10021142 = sqrt(r10021141);
        double r10021143 = r10021135 / r10021142;
        double r10021144 = r10021134 + r10021143;
        double r10021145 = r10021133 * r10021144;
        double r10021146 = sqrt(r10021145);
        return r10021146;
}

double f(double p, double x) {
        double r10021147 = 0.5;
        double r10021148 = x;
        double r10021149 = p;
        double r10021150 = 4.0;
        double r10021151 = r10021149 * r10021150;
        double r10021152 = r10021148 * r10021148;
        double r10021153 = fma(r10021151, r10021149, r10021152);
        double r10021154 = sqrt(r10021153);
        double r10021155 = r10021148 / r10021154;
        double r10021156 = fma(r10021147, r10021155, r10021147);
        double r10021157 = sqrt(r10021156);
        double r10021158 = r10021156 * r10021157;
        double r10021159 = cbrt(r10021158);
        return r10021159;
}

Error

Bits error versus p

Bits error versus x

Target

Original13.2
Target13.2
Herbie13.2
\[\sqrt{\frac{1}{2} + \frac{\mathsf{copysign}\left(\frac{1}{2}, x\right)}{\mathsf{hypot}\left(1, \frac{2 \cdot p}{x}\right)}}\]

Derivation

  1. Initial program 13.2

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

    \[\leadsto \color{blue}{\sqrt{\mathsf{fma}\left(\frac{x}{\sqrt{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}}, 0.5, 0.5\right)}}\]
  3. Using strategy rm
  4. Applied add-cbrt-cube13.2

    \[\leadsto \color{blue}{\sqrt[3]{\left(\sqrt{\mathsf{fma}\left(\frac{x}{\sqrt{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}}, 0.5, 0.5\right)} \cdot \sqrt{\mathsf{fma}\left(\frac{x}{\sqrt{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}}, 0.5, 0.5\right)}\right) \cdot \sqrt{\mathsf{fma}\left(\frac{x}{\sqrt{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}}, 0.5, 0.5\right)}}}\]
  5. Simplified13.2

    \[\leadsto \sqrt[3]{\color{blue}{\mathsf{fma}\left(0.5, \frac{x}{\sqrt{\mathsf{fma}\left(p \cdot 4, p, x \cdot x\right)}}, 0.5\right) \cdot \sqrt{\mathsf{fma}\left(0.5, \frac{x}{\sqrt{\mathsf{fma}\left(p \cdot 4, p, x \cdot x\right)}}, 0.5\right)}}}\]
  6. Final simplification13.2

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

Reproduce

herbie shell --seed 2019162 +o rules:numerics
(FPCore (p x)
  :name "Given's Rotation SVD example"
  :pre (< 1e-150 (fabs x) 1e+150)

  :herbie-target
  (sqrt (+ 1/2 (/ (copysign 1/2 x) (hypot 1 (/ (* 2 p) x)))))

  (sqrt (* 0.5 (+ 1 (/ x (sqrt (+ (* (* 4 p) p) (* x x))))))))