Average Error: 13.2 → 13.2
Time: 24.0s
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{e^{\log \left(\sqrt[3]{\mathsf{fma}\left(\frac{x}{\sqrt{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}}, 0.5, 0.5\right)}\right) + \log \left(\log \left(e^{\sqrt[3]{\mathsf{fma}\left(\frac{x}{\sqrt{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}}, 0.5, 0.5\right)} \cdot \sqrt[3]{\mathsf{fma}\left(\frac{x}{\sqrt{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}}, 0.5, 0.5\right)}}\right)\right)}}\]
\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}
\sqrt{e^{\log \left(\sqrt[3]{\mathsf{fma}\left(\frac{x}{\sqrt{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}}, 0.5, 0.5\right)}\right) + \log \left(\log \left(e^{\sqrt[3]{\mathsf{fma}\left(\frac{x}{\sqrt{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}}, 0.5, 0.5\right)} \cdot \sqrt[3]{\mathsf{fma}\left(\frac{x}{\sqrt{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}}, 0.5, 0.5\right)}}\right)\right)}}
double f(double p, double x) {
        double r6762239 = 0.5;
        double r6762240 = 1.0;
        double r6762241 = x;
        double r6762242 = 4.0;
        double r6762243 = p;
        double r6762244 = r6762242 * r6762243;
        double r6762245 = r6762244 * r6762243;
        double r6762246 = r6762241 * r6762241;
        double r6762247 = r6762245 + r6762246;
        double r6762248 = sqrt(r6762247);
        double r6762249 = r6762241 / r6762248;
        double r6762250 = r6762240 + r6762249;
        double r6762251 = r6762239 * r6762250;
        double r6762252 = sqrt(r6762251);
        return r6762252;
}

double f(double p, double x) {
        double r6762253 = x;
        double r6762254 = p;
        double r6762255 = 4.0;
        double r6762256 = r6762255 * r6762254;
        double r6762257 = r6762253 * r6762253;
        double r6762258 = fma(r6762254, r6762256, r6762257);
        double r6762259 = sqrt(r6762258);
        double r6762260 = r6762253 / r6762259;
        double r6762261 = 0.5;
        double r6762262 = fma(r6762260, r6762261, r6762261);
        double r6762263 = cbrt(r6762262);
        double r6762264 = log(r6762263);
        double r6762265 = r6762263 * r6762263;
        double r6762266 = exp(r6762265);
        double r6762267 = log(r6762266);
        double r6762268 = log(r6762267);
        double r6762269 = r6762264 + r6762268;
        double r6762270 = exp(r6762269);
        double r6762271 = sqrt(r6762270);
        return r6762271;
}

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-exp-log13.2

    \[\leadsto \sqrt{\color{blue}{e^{\log \left(\mathsf{fma}\left(\frac{x}{\sqrt{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}}, 0.5, 0.5\right)\right)}}}\]
  5. Using strategy rm
  6. Applied add-log-exp13.2

    \[\leadsto \sqrt{e^{\log \color{blue}{\left(\log \left(e^{\mathsf{fma}\left(\frac{x}{\sqrt{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}}, 0.5, 0.5\right)}\right)\right)}}}\]
  7. Using strategy rm
  8. Applied add-cube-cbrt13.2

    \[\leadsto \sqrt{e^{\log \left(\log \left(e^{\color{blue}{\left(\sqrt[3]{\mathsf{fma}\left(\frac{x}{\sqrt{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}}, 0.5, 0.5\right)} \cdot \sqrt[3]{\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[3]{\mathsf{fma}\left(\frac{x}{\sqrt{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}}, 0.5, 0.5\right)}}}\right)\right)}}\]
  9. Applied exp-prod13.2

    \[\leadsto \sqrt{e^{\log \left(\log \color{blue}{\left({\left(e^{\sqrt[3]{\mathsf{fma}\left(\frac{x}{\sqrt{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}}, 0.5, 0.5\right)} \cdot \sqrt[3]{\mathsf{fma}\left(\frac{x}{\sqrt{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}}, 0.5, 0.5\right)}}\right)}^{\left(\sqrt[3]{\mathsf{fma}\left(\frac{x}{\sqrt{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}}, 0.5, 0.5\right)}\right)}\right)}\right)}}\]
  10. Applied log-pow13.2

    \[\leadsto \sqrt{e^{\log \color{blue}{\left(\sqrt[3]{\mathsf{fma}\left(\frac{x}{\sqrt{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}}, 0.5, 0.5\right)} \cdot \log \left(e^{\sqrt[3]{\mathsf{fma}\left(\frac{x}{\sqrt{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}}, 0.5, 0.5\right)} \cdot \sqrt[3]{\mathsf{fma}\left(\frac{x}{\sqrt{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}}, 0.5, 0.5\right)}}\right)\right)}}}\]
  11. Applied log-prod13.2

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

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

Reproduce

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