Average Error: 13.3 → 13.3
Time: 25.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{\log \left(e^{\frac{\mathsf{fma}\left(1, 1 \cdot 1, \frac{x \cdot \frac{x \cdot x}{\sqrt{\mathsf{fma}\left(p \cdot 4, p, x \cdot x\right)}}}{\mathsf{fma}\left(p \cdot 4, p, x \cdot x\right)}\right)}{\mathsf{fma}\left(1, 1, \left(\frac{x}{\sqrt{\mathsf{fma}\left(p \cdot 4, p, x \cdot x\right)}} - 1\right) \cdot \frac{x}{\sqrt{\mathsf{fma}\left(p \cdot 4, p, x \cdot x\right)}}\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{\log \left(e^{\frac{\mathsf{fma}\left(1, 1 \cdot 1, \frac{x \cdot \frac{x \cdot x}{\sqrt{\mathsf{fma}\left(p \cdot 4, p, x \cdot x\right)}}}{\mathsf{fma}\left(p \cdot 4, p, x \cdot x\right)}\right)}{\mathsf{fma}\left(1, 1, \left(\frac{x}{\sqrt{\mathsf{fma}\left(p \cdot 4, p, x \cdot x\right)}} - 1\right) \cdot \frac{x}{\sqrt{\mathsf{fma}\left(p \cdot 4, p, x \cdot x\right)}}\right)}}\right) \cdot 0.5}
double f(double p, double x) {
        double r8505897 = 0.5;
        double r8505898 = 1.0;
        double r8505899 = x;
        double r8505900 = 4.0;
        double r8505901 = p;
        double r8505902 = r8505900 * r8505901;
        double r8505903 = r8505902 * r8505901;
        double r8505904 = r8505899 * r8505899;
        double r8505905 = r8505903 + r8505904;
        double r8505906 = sqrt(r8505905);
        double r8505907 = r8505899 / r8505906;
        double r8505908 = r8505898 + r8505907;
        double r8505909 = r8505897 * r8505908;
        double r8505910 = sqrt(r8505909);
        return r8505910;
}

double f(double p, double x) {
        double r8505911 = 1.0;
        double r8505912 = r8505911 * r8505911;
        double r8505913 = x;
        double r8505914 = r8505913 * r8505913;
        double r8505915 = p;
        double r8505916 = 4.0;
        double r8505917 = r8505915 * r8505916;
        double r8505918 = fma(r8505917, r8505915, r8505914);
        double r8505919 = sqrt(r8505918);
        double r8505920 = r8505914 / r8505919;
        double r8505921 = r8505913 * r8505920;
        double r8505922 = r8505921 / r8505918;
        double r8505923 = fma(r8505911, r8505912, r8505922);
        double r8505924 = r8505913 / r8505919;
        double r8505925 = r8505924 - r8505911;
        double r8505926 = r8505925 * r8505924;
        double r8505927 = fma(r8505911, r8505911, r8505926);
        double r8505928 = r8505923 / r8505927;
        double r8505929 = exp(r8505928);
        double r8505930 = log(r8505929);
        double r8505931 = 0.5;
        double r8505932 = r8505930 * r8505931;
        double r8505933 = sqrt(r8505932);
        return r8505933;
}

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

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

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

    \[\leadsto \sqrt{\log \color{blue}{\left(e^{1 + \frac{x}{\sqrt{\mathsf{fma}\left(p \cdot 4, p, x \cdot x\right)}}}\right)} \cdot 0.5}\]
  8. Using strategy rm
  9. Applied flip3-+13.3

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

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

    \[\leadsto \sqrt{\log \left(e^{\frac{\mathsf{fma}\left(1, 1 \cdot 1, \frac{x \cdot \frac{x \cdot x}{\sqrt{\mathsf{fma}\left(p \cdot 4, p, x \cdot x\right)}}}{\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)}} \cdot \left(\frac{x}{\sqrt{\mathsf{fma}\left(p \cdot 4, p, x \cdot x\right)}} - 1\right)\right)}}}\right) \cdot 0.5}\]
  12. Final simplification13.3

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

Reproduce

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