Average Error: 13.3 → 13.3
Time: 15.5s
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)}\]
\[\log \left(e^{\mathsf{expm1}\left(\mathsf{log1p}\left(\sqrt{0.5 \cdot \left(\frac{x}{\sqrt{\mathsf{fma}\left(p \cdot 4, p, x \cdot x\right)}} + 1\right)}\right)\right)}\right)\]
\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}
\log \left(e^{\mathsf{expm1}\left(\mathsf{log1p}\left(\sqrt{0.5 \cdot \left(\frac{x}{\sqrt{\mathsf{fma}\left(p \cdot 4, p, x \cdot x\right)}} + 1\right)}\right)\right)}\right)
double f(double p, double x) {
        double r216803 = 0.5;
        double r216804 = 1.0;
        double r216805 = x;
        double r216806 = 4.0;
        double r216807 = p;
        double r216808 = r216806 * r216807;
        double r216809 = r216808 * r216807;
        double r216810 = r216805 * r216805;
        double r216811 = r216809 + r216810;
        double r216812 = sqrt(r216811);
        double r216813 = r216805 / r216812;
        double r216814 = r216804 + r216813;
        double r216815 = r216803 * r216814;
        double r216816 = sqrt(r216815);
        return r216816;
}

double f(double p, double x) {
        double r216817 = 0.5;
        double r216818 = x;
        double r216819 = p;
        double r216820 = 4.0;
        double r216821 = r216819 * r216820;
        double r216822 = r216818 * r216818;
        double r216823 = fma(r216821, r216819, r216822);
        double r216824 = sqrt(r216823);
        double r216825 = r216818 / r216824;
        double r216826 = 1.0;
        double r216827 = r216825 + r216826;
        double r216828 = r216817 * r216827;
        double r216829 = sqrt(r216828);
        double r216830 = log1p(r216829);
        double r216831 = expm1(r216830);
        double r216832 = exp(r216831);
        double r216833 = log(r216832);
        return r216833;
}

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(1 + \frac{x}{\sqrt{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}}\right) \cdot 0.5}}\]
  3. Using strategy rm
  4. Applied add-log-exp13.3

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

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

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

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

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

Reproduce

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