Average Error: 13.3 → 13.3
Time: 12.7s
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 \mathsf{log1p}\left(\log \left(e^{\mathsf{expm1}\left(\frac{x}{\sqrt{\mathsf{fma}\left(4 \cdot p, p, x \cdot x\right)}} + 1\right)}\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 \mathsf{log1p}\left(\log \left(e^{\mathsf{expm1}\left(\frac{x}{\sqrt{\mathsf{fma}\left(4 \cdot p, p, x \cdot x\right)}} + 1\right)}\right)\right)}
double f(double p, double x) {
        double r166999 = 0.5;
        double r167000 = 1.0;
        double r167001 = x;
        double r167002 = 4.0;
        double r167003 = p;
        double r167004 = r167002 * r167003;
        double r167005 = r167004 * r167003;
        double r167006 = r167001 * r167001;
        double r167007 = r167005 + r167006;
        double r167008 = sqrt(r167007);
        double r167009 = r167001 / r167008;
        double r167010 = r167000 + r167009;
        double r167011 = r166999 * r167010;
        double r167012 = sqrt(r167011);
        return r167012;
}

double f(double p, double x) {
        double r167013 = 0.5;
        double r167014 = x;
        double r167015 = 4.0;
        double r167016 = p;
        double r167017 = r167015 * r167016;
        double r167018 = r167014 * r167014;
        double r167019 = fma(r167017, r167016, r167018);
        double r167020 = sqrt(r167019);
        double r167021 = r167014 / r167020;
        double r167022 = 1.0;
        double r167023 = r167021 + r167022;
        double r167024 = expm1(r167023);
        double r167025 = exp(r167024);
        double r167026 = log(r167025);
        double r167027 = log1p(r167026);
        double r167028 = r167013 * r167027;
        double r167029 = sqrt(r167028);
        return r167029;
}

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. Using strategy rm
  3. Applied add-cube-cbrt15.1

    \[\leadsto \sqrt{0.5 \cdot \left(1 + \frac{x}{\color{blue}{\left(\sqrt[3]{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}} \cdot \sqrt[3]{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right) \cdot \sqrt[3]{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}}}\right)}\]
  4. Applied add-cube-cbrt13.3

    \[\leadsto \sqrt{0.5 \cdot \left(1 + \frac{\color{blue}{\left(\sqrt[3]{x} \cdot \sqrt[3]{x}\right) \cdot \sqrt[3]{x}}}{\left(\sqrt[3]{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}} \cdot \sqrt[3]{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right) \cdot \sqrt[3]{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}}\right)}\]
  5. Applied times-frac13.3

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

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

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

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

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

    \[\leadsto \sqrt{0.5 \cdot \mathsf{log1p}\left(\color{blue}{\mathsf{expm1}\left(1 + \frac{x}{\sqrt{\mathsf{fma}\left(4 \cdot p, p, x \cdot x\right)}}\right)}\right)}\]
  13. Using strategy rm
  14. Applied add-log-exp13.3

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

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

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

Reproduce

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