Average Error: 13.5 → 13.5
Time: 2.1m
Precision: 64
\[10^{-150} \lt \left|x\right| \lt 10^{+150}\]
\[\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}\]
\[\sqrt{\mathsf{log1p}\left(\mathsf{expm1}\left(\mathsf{fma}\left(\frac{x}{\sqrt{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}}, 0.5, 0.5\right)\right)\right)}\]
\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}
\sqrt{\mathsf{log1p}\left(\mathsf{expm1}\left(\mathsf{fma}\left(\frac{x}{\sqrt{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}}, 0.5, 0.5\right)\right)\right)}
double f(double p, double x) {
        double r7442954 = 0.5;
        double r7442955 = 1.0;
        double r7442956 = x;
        double r7442957 = 4.0;
        double r7442958 = p;
        double r7442959 = r7442957 * r7442958;
        double r7442960 = r7442959 * r7442958;
        double r7442961 = r7442956 * r7442956;
        double r7442962 = r7442960 + r7442961;
        double r7442963 = sqrt(r7442962);
        double r7442964 = r7442956 / r7442963;
        double r7442965 = r7442955 + r7442964;
        double r7442966 = r7442954 * r7442965;
        double r7442967 = sqrt(r7442966);
        return r7442967;
}

double f(double p, double x) {
        double r7442968 = x;
        double r7442969 = p;
        double r7442970 = 4.0;
        double r7442971 = r7442970 * r7442969;
        double r7442972 = r7442968 * r7442968;
        double r7442973 = fma(r7442969, r7442971, r7442972);
        double r7442974 = sqrt(r7442973);
        double r7442975 = r7442968 / r7442974;
        double r7442976 = 0.5;
        double r7442977 = fma(r7442975, r7442976, r7442976);
        double r7442978 = expm1(r7442977);
        double r7442979 = log1p(r7442978);
        double r7442980 = sqrt(r7442979);
        return r7442980;
}

Error

Bits error versus p

Bits error versus x

Target

Original13.5
Target13.5
Herbie13.5
\[\sqrt{\frac{1}{2} + \frac{\mathsf{copysign}\left(\frac{1}{2}, x\right)}{\mathsf{hypot}\left(1, \frac{2 \cdot p}{x}\right)}}\]

Derivation

  1. Initial program 13.5

    \[\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}\]
  2. Simplified13.5

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

    \[\leadsto \sqrt{\color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\mathsf{fma}\left(\frac{x}{\sqrt{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}}, 0.5, 0.5\right)\right)\right)}}\]
  5. Final simplification13.5

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

Reproduce

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

  :herbie-target
  (sqrt (+ 1/2 (/ (copysign 1/2 x) (hypot 1 (/ (* 2 p) x)))))

  (sqrt (* 0.5 (+ 1 (/ x (sqrt (+ (* (* 4 p) p) (* x x))))))))