sympy/sympy — pull request #2111 by smichr (2013-05-16 09:15:03+00:00)
Title: watch for negated base pairs

This addresses the current inability of SymPy to reduce `(x - y)/sqrt(y - x)` to `-sqrt(y - x)`, an expression that arose from the following manipulations (which now work):

```
(-x + y)*sqrt(1/(x - y))
>>> refine(_,Q.positive(x-y))
(-x + y)/sqrt(x - y)
>>> simplify(_)
-sqrt(x - y)
>>> refine((x - y)*sqrt(1/(y - x)), Q.positive(y-x))
(x - y)/sqrt(-x + y)
>>> simplify(_)
-sqrt(-x + y)
```

In theory this problem should be handled by signsimp but
sqrt(-(x - z)) signsimp only looks for things that can have a negative
sign exptracted so (x - z)/sqrt(z - x) becomes (x - z)/sqrt(-(x - z))
and that doesn't simplify unless we look for the negated base in powsimp. (If signsimp worked by replacing `x - z` with `-(z - x)` then it would work.)

Only a minimal attempt is made to find a base and its negated pair. If one desires
other things like x + y*(z - x) to be recognized as the negated expression
of -x + y*(x - z) then sign simplification should be done first.

>>> (x + y*(z - x))==(-(-x + y*(x - z)))
False
>>> signsimp((x + y*(z - x)))==signsimp((-(-x + y*(x - z))))
True

Number that are negated are handled elsewhere so these are sepcifically
excluded from consideration by the added code.