Average Error: 13.2 → 13.2
Time: 5.1s
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(\mathsf{expm1}\left(\mathsf{log1p}\left(e^{1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}}\right)\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(\mathsf{expm1}\left(\mathsf{log1p}\left(e^{1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}}\right)\right)\right)}
double f(double p, double x) {
        double r302564 = 0.5;
        double r302565 = 1.0;
        double r302566 = x;
        double r302567 = 4.0;
        double r302568 = p;
        double r302569 = r302567 * r302568;
        double r302570 = r302569 * r302568;
        double r302571 = r302566 * r302566;
        double r302572 = r302570 + r302571;
        double r302573 = sqrt(r302572);
        double r302574 = r302566 / r302573;
        double r302575 = r302565 + r302574;
        double r302576 = r302564 * r302575;
        double r302577 = sqrt(r302576);
        return r302577;
}

double f(double p, double x) {
        double r302578 = 0.5;
        double r302579 = 1.0;
        double r302580 = x;
        double r302581 = 4.0;
        double r302582 = p;
        double r302583 = r302581 * r302582;
        double r302584 = r302583 * r302582;
        double r302585 = r302580 * r302580;
        double r302586 = r302584 + r302585;
        double r302587 = sqrt(r302586);
        double r302588 = r302580 / r302587;
        double r302589 = r302579 + r302588;
        double r302590 = exp(r302589);
        double r302591 = log1p(r302590);
        double r302592 = expm1(r302591);
        double r302593 = log(r302592);
        double r302594 = r302578 * r302593;
        double r302595 = sqrt(r302594);
        return r302595;
}

Error

Bits error versus p

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

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

    \[\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.2

    \[\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.2

    \[\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.2

    \[\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.2

    \[\leadsto \sqrt{0.5 \cdot \log \color{blue}{\left(e^{1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}}\right)}}\]
  7. Using strategy rm
  8. Applied expm1-log1p-u13.2

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

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

Reproduce

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