Average Error: 13.4 → 13.4
Time: 18.2s
Precision: 64
\[1.00000000000000001 \cdot 10^{-150} \lt \left|x\right| \lt 9.99999999999999981 \cdot 10^{149}\]
\[\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}\]
\[\sqrt{0.5 \cdot \log \left(e^{1 + \frac{x}{\sqrt{\mathsf{fma}\left(4 \cdot p, p, {x}^{2}\right)}}}\right)}\]
\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}
\sqrt{0.5 \cdot \log \left(e^{1 + \frac{x}{\sqrt{\mathsf{fma}\left(4 \cdot p, p, {x}^{2}\right)}}}\right)}
double f(double p, double x) {
        double r340329 = 0.5;
        double r340330 = 1.0;
        double r340331 = x;
        double r340332 = 4.0;
        double r340333 = p;
        double r340334 = r340332 * r340333;
        double r340335 = r340334 * r340333;
        double r340336 = r340331 * r340331;
        double r340337 = r340335 + r340336;
        double r340338 = sqrt(r340337);
        double r340339 = r340331 / r340338;
        double r340340 = r340330 + r340339;
        double r340341 = r340329 * r340340;
        double r340342 = sqrt(r340341);
        return r340342;
}

double f(double p, double x) {
        double r340343 = 0.5;
        double r340344 = 1.0;
        double r340345 = x;
        double r340346 = 4.0;
        double r340347 = p;
        double r340348 = r340346 * r340347;
        double r340349 = 2.0;
        double r340350 = pow(r340345, r340349);
        double r340351 = fma(r340348, r340347, r340350);
        double r340352 = sqrt(r340351);
        double r340353 = r340345 / r340352;
        double r340354 = r340344 + r340353;
        double r340355 = exp(r340354);
        double r340356 = log(r340355);
        double r340357 = r340343 * r340356;
        double r340358 = sqrt(r340357);
        return r340358;
}

Error

Bits error versus p

Bits error versus x

Target

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

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

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

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

    \[\leadsto \sqrt{0.5 \cdot \color{blue}{\log \left(e^{1} \cdot e^{\frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}}\right)}}\]
  6. Simplified13.4

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

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

Reproduce

herbie shell --seed 2019199 +o rules:numerics
(FPCore (p x)
  :name "Given's Rotation SVD example"
  :pre (< 1e-150 (fabs x) 1e+150)

  :herbie-target
  (sqrt (+ 0.5 (/ (copysign 0.5 x) (hypot 1.0 (/ (* 2.0 p) x)))))

  (sqrt (* 0.5 (+ 1.0 (/ x (sqrt (+ (* (* 4.0 p) p) (* x x))))))))