Average Error: 13.3 → 13.3
Time: 24.8s
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{\left(\log \left(e^{\frac{x}{\sqrt{\mathsf{fma}\left(4 \cdot p, p, x \cdot x\right)}}}\right) + 1\right) \cdot 0.5}\]
\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}
\sqrt{\left(\log \left(e^{\frac{x}{\sqrt{\mathsf{fma}\left(4 \cdot p, p, x \cdot x\right)}}}\right) + 1\right) \cdot 0.5}
double f(double p, double x) {
        double r230793 = 0.5;
        double r230794 = 1.0;
        double r230795 = x;
        double r230796 = 4.0;
        double r230797 = p;
        double r230798 = r230796 * r230797;
        double r230799 = r230798 * r230797;
        double r230800 = r230795 * r230795;
        double r230801 = r230799 + r230800;
        double r230802 = sqrt(r230801);
        double r230803 = r230795 / r230802;
        double r230804 = r230794 + r230803;
        double r230805 = r230793 * r230804;
        double r230806 = sqrt(r230805);
        return r230806;
}

double f(double p, double x) {
        double r230807 = x;
        double r230808 = 4.0;
        double r230809 = p;
        double r230810 = r230808 * r230809;
        double r230811 = r230807 * r230807;
        double r230812 = fma(r230810, r230809, r230811);
        double r230813 = sqrt(r230812);
        double r230814 = r230807 / r230813;
        double r230815 = exp(r230814);
        double r230816 = log(r230815);
        double r230817 = 1.0;
        double r230818 = r230816 + r230817;
        double r230819 = 0.5;
        double r230820 = r230818 * r230819;
        double r230821 = sqrt(r230820);
        return r230821;
}

Error

Bits error versus p

Bits error versus x

Target

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

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

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

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

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

Reproduce

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