Average Error: 13.6 → 13.6
Time: 21.6s
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{\left(\sqrt[3]{\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)} \cdot \sqrt[3]{\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) \cdot \sqrt[3]{\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)}}\]
\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}
\sqrt{\left(\sqrt[3]{\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)} \cdot \sqrt[3]{\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) \cdot \sqrt[3]{\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)}}
double f(double p, double x) {
        double r6607579 = 0.5;
        double r6607580 = 1.0;
        double r6607581 = x;
        double r6607582 = 4.0;
        double r6607583 = p;
        double r6607584 = r6607582 * r6607583;
        double r6607585 = r6607584 * r6607583;
        double r6607586 = r6607581 * r6607581;
        double r6607587 = r6607585 + r6607586;
        double r6607588 = sqrt(r6607587);
        double r6607589 = r6607581 / r6607588;
        double r6607590 = r6607580 + r6607589;
        double r6607591 = r6607579 * r6607590;
        double r6607592 = sqrt(r6607591);
        return r6607592;
}

double f(double p, double x) {
        double r6607593 = x;
        double r6607594 = p;
        double r6607595 = 4.0;
        double r6607596 = r6607595 * r6607594;
        double r6607597 = r6607593 * r6607593;
        double r6607598 = fma(r6607594, r6607596, r6607597);
        double r6607599 = sqrt(r6607598);
        double r6607600 = r6607593 / r6607599;
        double r6607601 = 0.5;
        double r6607602 = fma(r6607600, r6607601, r6607601);
        double r6607603 = exp(r6607602);
        double r6607604 = log(r6607603);
        double r6607605 = cbrt(r6607604);
        double r6607606 = r6607605 * r6607605;
        double r6607607 = r6607606 * r6607605;
        double r6607608 = sqrt(r6607607);
        return r6607608;
}

Error

Bits error versus p

Bits error versus x

Target

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

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

    \[\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-log-exp13.6

    \[\leadsto \sqrt{\color{blue}{\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)}}\]
  5. Using strategy rm
  6. Applied add-cube-cbrt13.6

    \[\leadsto \sqrt{\color{blue}{\left(\sqrt[3]{\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)} \cdot \sqrt[3]{\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) \cdot \sqrt[3]{\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)}}}\]
  7. Final simplification13.6

    \[\leadsto \sqrt{\left(\sqrt[3]{\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)} \cdot \sqrt[3]{\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) \cdot \sqrt[3]{\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)}}\]

Reproduce

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