Average Error: 12.9 → 12.9
Time: 41.6s
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{\frac{\mathsf{fma}\left(\left(\left(1 \cdot 1\right) \cdot 1\right) \cdot \left(\left(1 \cdot 1\right) \cdot 1\right), \left(1 \cdot 1\right) \cdot 1, \left(\frac{x \cdot x}{\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)}}\right) \cdot \left(\left(\frac{x \cdot x}{\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)}}\right) \cdot \left(\frac{x \cdot x}{\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)}}\right)\right)\right)}{\mathsf{fma}\left(\left(1 \cdot 1\right) \cdot 1 - \frac{x \cdot x}{\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)}}, \left(1 \cdot 1\right) \cdot 1, \left(\frac{x \cdot x}{\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)}}\right) \cdot \left(\frac{x \cdot x}{\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)}}\right)\right)}}{\mathsf{fma}\left(1, 1 - \frac{x}{\sqrt{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}}, \frac{x \cdot x}{\mathsf{fma}\left(p, 4 \cdot 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{\frac{\mathsf{fma}\left(\left(\left(1 \cdot 1\right) \cdot 1\right) \cdot \left(\left(1 \cdot 1\right) \cdot 1\right), \left(1 \cdot 1\right) \cdot 1, \left(\frac{x \cdot x}{\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)}}\right) \cdot \left(\left(\frac{x \cdot x}{\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)}}\right) \cdot \left(\frac{x \cdot x}{\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)}}\right)\right)\right)}{\mathsf{fma}\left(\left(1 \cdot 1\right) \cdot 1 - \frac{x \cdot x}{\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)}}, \left(1 \cdot 1\right) \cdot 1, \left(\frac{x \cdot x}{\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)}}\right) \cdot \left(\frac{x \cdot x}{\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)}}\right)\right)}}{\mathsf{fma}\left(1, 1 - \frac{x}{\sqrt{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}}, \frac{x \cdot x}{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}\right)} \cdot 0.5}
double f(double p, double x) {
        double r10833146 = 0.5;
        double r10833147 = 1.0;
        double r10833148 = x;
        double r10833149 = 4.0;
        double r10833150 = p;
        double r10833151 = r10833149 * r10833150;
        double r10833152 = r10833151 * r10833150;
        double r10833153 = r10833148 * r10833148;
        double r10833154 = r10833152 + r10833153;
        double r10833155 = sqrt(r10833154);
        double r10833156 = r10833148 / r10833155;
        double r10833157 = r10833147 + r10833156;
        double r10833158 = r10833146 * r10833157;
        double r10833159 = sqrt(r10833158);
        return r10833159;
}

double f(double p, double x) {
        double r10833160 = 1.0;
        double r10833161 = r10833160 * r10833160;
        double r10833162 = r10833161 * r10833160;
        double r10833163 = r10833162 * r10833162;
        double r10833164 = x;
        double r10833165 = r10833164 * r10833164;
        double r10833166 = p;
        double r10833167 = 4.0;
        double r10833168 = r10833167 * r10833166;
        double r10833169 = fma(r10833166, r10833168, r10833165);
        double r10833170 = r10833165 / r10833169;
        double r10833171 = sqrt(r10833169);
        double r10833172 = r10833164 / r10833171;
        double r10833173 = r10833170 * r10833172;
        double r10833174 = r10833173 * r10833173;
        double r10833175 = r10833173 * r10833174;
        double r10833176 = fma(r10833163, r10833162, r10833175);
        double r10833177 = r10833162 - r10833173;
        double r10833178 = fma(r10833177, r10833162, r10833174);
        double r10833179 = r10833176 / r10833178;
        double r10833180 = r10833160 - r10833172;
        double r10833181 = fma(r10833160, r10833180, r10833170);
        double r10833182 = r10833179 / r10833181;
        double r10833183 = 0.5;
        double r10833184 = r10833182 * r10833183;
        double r10833185 = sqrt(r10833184);
        return r10833185;
}

Error

Bits error versus p

Bits error versus x

Target

Original12.9
Target12.9
Herbie12.9
\[\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 12.9

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

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

    \[\leadsto \sqrt{\color{blue}{\frac{{\left(\frac{x}{\sqrt{\mathsf{fma}\left(p \cdot 4, p, x \cdot x\right)}}\right)}^{3} + {1}^{3}}{\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)}} + \left(1 \cdot 1 - \frac{x}{\sqrt{\mathsf{fma}\left(p \cdot 4, p, x \cdot x\right)}} \cdot 1\right)}} \cdot 0.5}\]
  5. Simplified12.9

    \[\leadsto \sqrt{\frac{\color{blue}{\mathsf{fma}\left(\frac{x}{\sqrt{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}}, \frac{x \cdot x}{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}, \left(1 \cdot 1\right) \cdot 1\right)}}{\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)}} + \left(1 \cdot 1 - \frac{x}{\sqrt{\mathsf{fma}\left(p \cdot 4, p, x \cdot x\right)}} \cdot 1\right)} \cdot 0.5}\]
  6. Simplified12.9

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

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

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

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

    \[\leadsto \sqrt{\frac{\frac{\color{blue}{\mathsf{fma}\left(\left(\left(1 \cdot 1\right) \cdot 1\right) \cdot \left(\left(1 \cdot 1\right) \cdot 1\right), \left(1 \cdot 1\right) \cdot 1, \left(\frac{x \cdot x}{\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)}}\right) \cdot \left(\left(\frac{x \cdot x}{\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)}}\right) \cdot \left(\frac{x \cdot x}{\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)}}\right)\right)\right)}}{\left(\frac{x}{\sqrt{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}} \cdot \mathsf{expm1}\left(\mathsf{log1p}\left(\frac{x \cdot x}{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}\right)\right)\right) \cdot \left(\frac{x}{\sqrt{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}} \cdot \mathsf{expm1}\left(\mathsf{log1p}\left(\frac{x \cdot x}{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}\right)\right)\right) + \left(\left(\left(1 \cdot 1\right) \cdot 1\right) \cdot \left(\left(1 \cdot 1\right) \cdot 1\right) - \left(\frac{x}{\sqrt{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}} \cdot \mathsf{expm1}\left(\mathsf{log1p}\left(\frac{x \cdot x}{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}\right)\right)\right) \cdot \left(\left(1 \cdot 1\right) \cdot 1\right)\right)}}{\mathsf{fma}\left(1, 1 - \frac{x}{\sqrt{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}}, \frac{x \cdot x}{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}\right)} \cdot 0.5}\]
  14. Simplified12.9

    \[\leadsto \sqrt{\frac{\frac{\mathsf{fma}\left(\left(\left(1 \cdot 1\right) \cdot 1\right) \cdot \left(\left(1 \cdot 1\right) \cdot 1\right), \left(1 \cdot 1\right) \cdot 1, \left(\frac{x \cdot x}{\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)}}\right) \cdot \left(\left(\frac{x \cdot x}{\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)}}\right) \cdot \left(\frac{x \cdot x}{\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)}}\right)\right)\right)}{\color{blue}{\mathsf{fma}\left(\left(1 \cdot 1\right) \cdot 1 - \frac{x \cdot x}{\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)}}, \left(1 \cdot 1\right) \cdot 1, \left(\frac{x \cdot x}{\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)}}\right) \cdot \left(\frac{x \cdot x}{\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)}}\right)\right)}}}{\mathsf{fma}\left(1, 1 - \frac{x}{\sqrt{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}}, \frac{x \cdot x}{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}\right)} \cdot 0.5}\]
  15. Final simplification12.9

    \[\leadsto \sqrt{\frac{\frac{\mathsf{fma}\left(\left(\left(1 \cdot 1\right) \cdot 1\right) \cdot \left(\left(1 \cdot 1\right) \cdot 1\right), \left(1 \cdot 1\right) \cdot 1, \left(\frac{x \cdot x}{\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)}}\right) \cdot \left(\left(\frac{x \cdot x}{\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)}}\right) \cdot \left(\frac{x \cdot x}{\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)}}\right)\right)\right)}{\mathsf{fma}\left(\left(1 \cdot 1\right) \cdot 1 - \frac{x \cdot x}{\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)}}, \left(1 \cdot 1\right) \cdot 1, \left(\frac{x \cdot x}{\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)}}\right) \cdot \left(\frac{x \cdot x}{\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)}}\right)\right)}}{\mathsf{fma}\left(1, 1 - \frac{x}{\sqrt{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}}, \frac{x \cdot x}{\mathsf{fma}\left(p, 4 \cdot p, x \cdot x\right)}\right)} \cdot 0.5}\]

Reproduce

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