Average Error: 12.9 → 13.0
Time: 6.3s
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)}\]
\[\log \left(\sqrt{e^{\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}}}\right) + \log \left(\sqrt{e^{\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}}}\right)\]
\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}
\log \left(\sqrt{e^{\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}}}\right) + \log \left(\sqrt{e^{\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}}}\right)
double f(double p, double x) {
        double r291610 = 0.5;
        double r291611 = 1.0;
        double r291612 = x;
        double r291613 = 4.0;
        double r291614 = p;
        double r291615 = r291613 * r291614;
        double r291616 = r291615 * r291614;
        double r291617 = r291612 * r291612;
        double r291618 = r291616 + r291617;
        double r291619 = sqrt(r291618);
        double r291620 = r291612 / r291619;
        double r291621 = r291611 + r291620;
        double r291622 = r291610 * r291621;
        double r291623 = sqrt(r291622);
        return r291623;
}

double f(double p, double x) {
        double r291624 = 0.5;
        double r291625 = 1.0;
        double r291626 = x;
        double r291627 = 4.0;
        double r291628 = p;
        double r291629 = r291627 * r291628;
        double r291630 = r291629 * r291628;
        double r291631 = r291626 * r291626;
        double r291632 = r291630 + r291631;
        double r291633 = sqrt(r291632);
        double r291634 = r291626 / r291633;
        double r291635 = r291625 + r291634;
        double r291636 = r291624 * r291635;
        double r291637 = sqrt(r291636);
        double r291638 = exp(r291637);
        double r291639 = sqrt(r291638);
        double r291640 = log(r291639);
        double r291641 = r291640 + r291640;
        return r291641;
}

Error

Bits error versus p

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original12.9
Target12.9
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 12.9

    \[\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-exp12.9

    \[\leadsto \color{blue}{\log \left(e^{\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}}\right)}\]
  4. Using strategy rm
  5. Applied add-sqr-sqrt13.0

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

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

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

Reproduce

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