Average Error: 13.1 → 13.6
Time: 18.2s
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{\frac{\mathsf{fma}\left(1 \cdot 1, 1, \frac{x \cdot \left(x \cdot \frac{x}{\mathsf{fma}\left(p \cdot 4, p, x \cdot x\right)}\right)}{\sqrt{\mathsf{fma}\left(p \cdot 4, p, x \cdot x\right)}}\right)}{\mathsf{fma}\left(1, 1 - \frac{x}{\sqrt{\mathsf{fma}\left(p \cdot 4, p, x \cdot x\right)}}, \frac{x \cdot x}{\mathsf{fma}\left(p \cdot 4, p, x \cdot x\right)}\right)} \cdot 0.5}\]
\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}
\sqrt{\frac{\mathsf{fma}\left(1 \cdot 1, 1, \frac{x \cdot \left(x \cdot \frac{x}{\mathsf{fma}\left(p \cdot 4, p, x \cdot x\right)}\right)}{\sqrt{\mathsf{fma}\left(p \cdot 4, p, x \cdot x\right)}}\right)}{\mathsf{fma}\left(1, 1 - \frac{x}{\sqrt{\mathsf{fma}\left(p \cdot 4, p, x \cdot x\right)}}, \frac{x \cdot x}{\mathsf{fma}\left(p \cdot 4, p, x \cdot x\right)}\right)} \cdot 0.5}
double f(double p, double x) {
        double r10374996 = 0.5;
        double r10374997 = 1.0;
        double r10374998 = x;
        double r10374999 = 4.0;
        double r10375000 = p;
        double r10375001 = r10374999 * r10375000;
        double r10375002 = r10375001 * r10375000;
        double r10375003 = r10374998 * r10374998;
        double r10375004 = r10375002 + r10375003;
        double r10375005 = sqrt(r10375004);
        double r10375006 = r10374998 / r10375005;
        double r10375007 = r10374997 + r10375006;
        double r10375008 = r10374996 * r10375007;
        double r10375009 = sqrt(r10375008);
        return r10375009;
}

double f(double p, double x) {
        double r10375010 = 1.0;
        double r10375011 = r10375010 * r10375010;
        double r10375012 = x;
        double r10375013 = p;
        double r10375014 = 4.0;
        double r10375015 = r10375013 * r10375014;
        double r10375016 = r10375012 * r10375012;
        double r10375017 = fma(r10375015, r10375013, r10375016);
        double r10375018 = r10375012 / r10375017;
        double r10375019 = r10375012 * r10375018;
        double r10375020 = r10375012 * r10375019;
        double r10375021 = sqrt(r10375017);
        double r10375022 = r10375020 / r10375021;
        double r10375023 = fma(r10375011, r10375010, r10375022);
        double r10375024 = r10375012 / r10375021;
        double r10375025 = r10375010 - r10375024;
        double r10375026 = r10375016 / r10375017;
        double r10375027 = fma(r10375010, r10375025, r10375026);
        double r10375028 = r10375023 / r10375027;
        double r10375029 = 0.5;
        double r10375030 = r10375028 * r10375029;
        double r10375031 = sqrt(r10375030);
        return r10375031;
}

Error

Bits error versus p

Bits error versus x

Target

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

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

    \[\leadsto \sqrt{\frac{\color{blue}{\mathsf{fma}\left(1 \cdot 1, 1, \frac{x \cdot \frac{x \cdot x}{\mathsf{fma}\left(p \cdot 4, p, x \cdot x\right)}}{\sqrt{\mathsf{fma}\left(p \cdot 4, p, x \cdot x\right)}}\right)}}{1 \cdot 1 + \left(\frac{x}{\sqrt{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}} \cdot \frac{x}{\sqrt{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}} - 1 \cdot \frac{x}{\sqrt{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}}\right)} \cdot 0.5}\]
  6. Simplified13.1

    \[\leadsto \sqrt{\frac{\mathsf{fma}\left(1 \cdot 1, 1, \frac{x \cdot \frac{x \cdot x}{\mathsf{fma}\left(p \cdot 4, p, x \cdot x\right)}}{\sqrt{\mathsf{fma}\left(p \cdot 4, p, x \cdot x\right)}}\right)}{\color{blue}{\mathsf{fma}\left(1, 1 - \frac{x}{\sqrt{\mathsf{fma}\left(p \cdot 4, p, x \cdot x\right)}}, \frac{x \cdot x}{\mathsf{fma}\left(p \cdot 4, p, x \cdot x\right)}\right)}} \cdot 0.5}\]
  7. Using strategy rm
  8. Applied *-un-lft-identity13.1

    \[\leadsto \sqrt{\frac{\mathsf{fma}\left(1 \cdot 1, 1, \frac{x \cdot \frac{x \cdot x}{\color{blue}{1 \cdot \mathsf{fma}\left(p \cdot 4, p, x \cdot x\right)}}}{\sqrt{\mathsf{fma}\left(p \cdot 4, p, x \cdot x\right)}}\right)}{\mathsf{fma}\left(1, 1 - \frac{x}{\sqrt{\mathsf{fma}\left(p \cdot 4, p, x \cdot x\right)}}, \frac{x \cdot x}{\mathsf{fma}\left(p \cdot 4, p, x \cdot x\right)}\right)} \cdot 0.5}\]
  9. Applied times-frac13.6

    \[\leadsto \sqrt{\frac{\mathsf{fma}\left(1 \cdot 1, 1, \frac{x \cdot \color{blue}{\left(\frac{x}{1} \cdot \frac{x}{\mathsf{fma}\left(p \cdot 4, p, x \cdot x\right)}\right)}}{\sqrt{\mathsf{fma}\left(p \cdot 4, p, x \cdot x\right)}}\right)}{\mathsf{fma}\left(1, 1 - \frac{x}{\sqrt{\mathsf{fma}\left(p \cdot 4, p, x \cdot x\right)}}, \frac{x \cdot x}{\mathsf{fma}\left(p \cdot 4, p, x \cdot x\right)}\right)} \cdot 0.5}\]
  10. Simplified13.6

    \[\leadsto \sqrt{\frac{\mathsf{fma}\left(1 \cdot 1, 1, \frac{x \cdot \left(\color{blue}{x} \cdot \frac{x}{\mathsf{fma}\left(p \cdot 4, p, x \cdot x\right)}\right)}{\sqrt{\mathsf{fma}\left(p \cdot 4, p, x \cdot x\right)}}\right)}{\mathsf{fma}\left(1, 1 - \frac{x}{\sqrt{\mathsf{fma}\left(p \cdot 4, p, x \cdot x\right)}}, \frac{x \cdot x}{\mathsf{fma}\left(p \cdot 4, p, x \cdot x\right)}\right)} \cdot 0.5}\]
  11. Final simplification13.6

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

Reproduce

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