Average Error: 13.0 → 13.0
Time: 16.2s
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{\mathsf{fma}\left(\sqrt[3]{\frac{x}{\sqrt{\mathsf{fma}\left(x, x, \left(4 \cdot p\right) \cdot p\right)}} \cdot \left(\frac{x}{\sqrt{\mathsf{fma}\left(x, x, \left(4 \cdot p\right) \cdot p\right)}} \cdot \frac{x}{\sqrt{\mathsf{fma}\left(x, x, \left(4 \cdot p\right) \cdot p\right)}}\right)}, 0.5, 0.5\right)}\]
\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}
\sqrt{\mathsf{fma}\left(\sqrt[3]{\frac{x}{\sqrt{\mathsf{fma}\left(x, x, \left(4 \cdot p\right) \cdot p\right)}} \cdot \left(\frac{x}{\sqrt{\mathsf{fma}\left(x, x, \left(4 \cdot p\right) \cdot p\right)}} \cdot \frac{x}{\sqrt{\mathsf{fma}\left(x, x, \left(4 \cdot p\right) \cdot p\right)}}\right)}, 0.5, 0.5\right)}
double f(double p, double x) {
        double r7127131 = 0.5;
        double r7127132 = 1.0;
        double r7127133 = x;
        double r7127134 = 4.0;
        double r7127135 = p;
        double r7127136 = r7127134 * r7127135;
        double r7127137 = r7127136 * r7127135;
        double r7127138 = r7127133 * r7127133;
        double r7127139 = r7127137 + r7127138;
        double r7127140 = sqrt(r7127139);
        double r7127141 = r7127133 / r7127140;
        double r7127142 = r7127132 + r7127141;
        double r7127143 = r7127131 * r7127142;
        double r7127144 = sqrt(r7127143);
        return r7127144;
}

double f(double p, double x) {
        double r7127145 = x;
        double r7127146 = 4.0;
        double r7127147 = p;
        double r7127148 = r7127146 * r7127147;
        double r7127149 = r7127148 * r7127147;
        double r7127150 = fma(r7127145, r7127145, r7127149);
        double r7127151 = sqrt(r7127150);
        double r7127152 = r7127145 / r7127151;
        double r7127153 = r7127152 * r7127152;
        double r7127154 = r7127152 * r7127153;
        double r7127155 = cbrt(r7127154);
        double r7127156 = 0.5;
        double r7127157 = fma(r7127155, r7127156, r7127156);
        double r7127158 = sqrt(r7127157);
        return r7127158;
}

Error

Bits error versus p

Bits error versus x

Target

Original13.0
Target13.0
Herbie13.0
\[\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.0

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

    \[\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-cube19.1

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

    \[\leadsto \sqrt{\mathsf{fma}\left(\frac{\color{blue}{\sqrt[3]{\left(x \cdot x\right) \cdot x}}}{\sqrt[3]{\left(\sqrt{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)} \cdot \sqrt{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}\right) \cdot \sqrt{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}}}, 0.5, 0.5\right)}\]
  6. Applied cbrt-undiv22.3

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

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

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

Reproduce

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