Average Error: 13.0 → 13.0
Time: 16.9s
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{\log \left(e^{\frac{x}{\sqrt{\mathsf{fma}\left(4 \cdot p, p, x \cdot x\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{\log \left(e^{\frac{x}{\sqrt{\mathsf{fma}\left(4 \cdot p, p, x \cdot x\right)}} + 1}\right) \cdot 0.5}
double f(double p, double x) {
        double r203138 = 0.5;
        double r203139 = 1.0;
        double r203140 = x;
        double r203141 = 4.0;
        double r203142 = p;
        double r203143 = r203141 * r203142;
        double r203144 = r203143 * r203142;
        double r203145 = r203140 * r203140;
        double r203146 = r203144 + r203145;
        double r203147 = sqrt(r203146);
        double r203148 = r203140 / r203147;
        double r203149 = r203139 + r203148;
        double r203150 = r203138 * r203149;
        double r203151 = sqrt(r203150);
        return r203151;
}

double f(double p, double x) {
        double r203152 = x;
        double r203153 = 4.0;
        double r203154 = p;
        double r203155 = r203153 * r203154;
        double r203156 = r203152 * r203152;
        double r203157 = fma(r203155, r203154, r203156);
        double r203158 = sqrt(r203157);
        double r203159 = r203152 / r203158;
        double r203160 = 1.0;
        double r203161 = r203159 + r203160;
        double r203162 = exp(r203161);
        double r203163 = log(r203162);
        double r203164 = 0.5;
        double r203165 = r203163 * r203164;
        double r203166 = sqrt(r203165);
        return r203166;
}

Error

Bits error versus p

Bits error versus x

Target

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

    \[\leadsto \sqrt{\left(\frac{x}{\sqrt{\mathsf{fma}\left(4 \cdot p, p, x \cdot x\right)}} + \color{blue}{\log \left(e^{1}\right)}\right) \cdot 0.5}\]
  5. Applied add-log-exp13.0

    \[\leadsto \sqrt{\left(\color{blue}{\log \left(e^{\frac{x}{\sqrt{\mathsf{fma}\left(4 \cdot p, p, x \cdot x\right)}}}\right)} + \log \left(e^{1}\right)\right) \cdot 0.5}\]
  6. Applied sum-log13.0

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

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

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

Reproduce

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