Average Error: 13.1 → 13.6
Time: 1.9m
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)}\]
\[\left(\sqrt[3]{\sqrt{\log \left(e^{\mathsf{fma}\left(\frac{x}{\sqrt{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}}, 0.5, 0.5\right)}\right)}} \cdot \sqrt[3]{\sqrt{\log \left(e^{\mathsf{fma}\left(\frac{x}{\sqrt{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}}, 0.5, 0.5\right)}\right)}}\right) \cdot \sqrt[3]{\sqrt{\log \left(e^{\mathsf{fma}\left(\frac{x}{\sqrt{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}}, 0.5, 0.5\right)}\right)}}\]
\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}
\left(\sqrt[3]{\sqrt{\log \left(e^{\mathsf{fma}\left(\frac{x}{\sqrt{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}}, 0.5, 0.5\right)}\right)}} \cdot \sqrt[3]{\sqrt{\log \left(e^{\mathsf{fma}\left(\frac{x}{\sqrt{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}}, 0.5, 0.5\right)}\right)}}\right) \cdot \sqrt[3]{\sqrt{\log \left(e^{\mathsf{fma}\left(\frac{x}{\sqrt{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}}, 0.5, 0.5\right)}\right)}}
double f(double p, double x) {
        double r7949066 = 0.5;
        double r7949067 = 1.0;
        double r7949068 = x;
        double r7949069 = 4.0;
        double r7949070 = p;
        double r7949071 = r7949069 * r7949070;
        double r7949072 = r7949071 * r7949070;
        double r7949073 = r7949068 * r7949068;
        double r7949074 = r7949072 + r7949073;
        double r7949075 = sqrt(r7949074);
        double r7949076 = r7949068 / r7949075;
        double r7949077 = r7949067 + r7949076;
        double r7949078 = r7949066 * r7949077;
        double r7949079 = sqrt(r7949078);
        return r7949079;
}

double f(double p, double x) {
        double r7949080 = x;
        double r7949081 = p;
        double r7949082 = 4.0;
        double r7949083 = r7949082 * r7949081;
        double r7949084 = r7949080 * r7949080;
        double r7949085 = fma(r7949081, r7949083, r7949084);
        double r7949086 = sqrt(r7949085);
        double r7949087 = r7949080 / r7949086;
        double r7949088 = 0.5;
        double r7949089 = fma(r7949087, r7949088, r7949088);
        double r7949090 = exp(r7949089);
        double r7949091 = log(r7949090);
        double r7949092 = sqrt(r7949091);
        double r7949093 = cbrt(r7949092);
        double r7949094 = r7949093 * r7949093;
        double r7949095 = r7949094 * r7949093;
        return r7949095;
}

Error

Bits error versus p

Bits error versus x

Target

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

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

    \[\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 add-log-exp13.1

    \[\leadsto \sqrt{\color{blue}{\log \left(e^{\mathsf{fma}\left(\frac{x}{\sqrt{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}}, 0.5, 0.5\right)}\right)}}\]
  5. Using strategy rm
  6. Applied add-cube-cbrt13.6

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

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

Reproduce

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