Average Error: 13.0 → 13.0
Time: 19.3s
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)}\]
\[\sqrt{0.5 \cdot \log \left(e^{1 + \frac{x}{\sqrt{\mathsf{fma}\left(4 \cdot p, 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)}
\sqrt{0.5 \cdot \log \left(e^{1 + \frac{x}{\sqrt{\mathsf{fma}\left(4 \cdot p, p, x \cdot x\right)}}}\right)}
double f(double p, double x) {
        double r110132 = 0.5;
        double r110133 = 1.0;
        double r110134 = x;
        double r110135 = 4.0;
        double r110136 = p;
        double r110137 = r110135 * r110136;
        double r110138 = r110137 * r110136;
        double r110139 = r110134 * r110134;
        double r110140 = r110138 + r110139;
        double r110141 = sqrt(r110140);
        double r110142 = r110134 / r110141;
        double r110143 = r110133 + r110142;
        double r110144 = r110132 * r110143;
        double r110145 = sqrt(r110144);
        return r110145;
}

double f(double p, double x) {
        double r110146 = 0.5;
        double r110147 = 1.0;
        double r110148 = x;
        double r110149 = 4.0;
        double r110150 = p;
        double r110151 = r110149 * r110150;
        double r110152 = r110148 * r110148;
        double r110153 = fma(r110151, r110150, r110152);
        double r110154 = sqrt(r110153);
        double r110155 = r110148 / r110154;
        double r110156 = r110147 + r110155;
        double r110157 = exp(r110156);
        double r110158 = log(r110157);
        double r110159 = r110146 * r110158;
        double r110160 = sqrt(r110159);
        return r110160;
}

Error

Bits error versus p

Bits error versus x

Target

Original13.0
Target13.0
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 13.0

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

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

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

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

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

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

Reproduce

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