This is not the right fix. You can see this because this will drop the factor if k is None. None is there to indicate that the factor should not be extracted...but if the exponent is right, it *can* be extracted (but in that case None was a bad choice).

I pushed branch 2787 that has the right fix, I believe.

`factor(sqrt(-p*n*x))` should be `sqrt(n)*sqrt(p)*sqrt(-x)`, not `n*sqrt(p)*sqrt(x)` (which is what the current PR gives).. That's a better test than the Piecewise since it generates the None case. And of course Piecewise will work when this routine is working properly.