sympy/sympy — pull request #1921 by mattpap (2013-03-22 21:13:28+00:00)
Title: WIP Improved support for reals in polys

This pull request fixes a long standing issue with "can't raise polynomial to a negative power". Now `gcd()` over reals is computed over rationals and converted back to reals. This is what (for example) `factor()` used for very long time. In future, however, it would be good to implement approximate polynomial GCD.

Renamed `RealDomain` to `RealField` and parametrized its constructor with `prec`, `dps` and `tol`. The default precision is 53 bits (prec=53) (or dps=15). If not given explicitly, tolerance is computed from precision. As a side effect, implemented `ComplexField`. All this is based on customized `mpf`, `mpc` and `MPContext` classes from mpmath.

`mpf` and `mpc` were modified so that they can detect and truncate to zero given the specified tolerance. This applies to constructors, arithmetic operators and methods like `sqrt()`. `__eq__` is still structural so you have to use `ae()` method. This behavior is currently enabled by default. I didn't yet add a switch to disable it. Note that even if disabled, `gcd()` will still work properly in the new implementation.

Example:
```
In [1]: RR.from_sympy(sqrt(2))
Out[1]: 1.4142135623731

In [2]: _/1000
Out[2]: 0.0014142135623731

In [3]: _/1000
Out[3]: 1.4142135623731e-6

In [4]: _/1000
Out[4]: 1.4142135623731e-9

In [5]: _/1000
Out[5]: 1.4142135623731e-12

In [6]: _/1000
Out[6]: 0.0

In [7]: R = RealField(100)

In [8]: R.from_sympy(sqrt(2))
Out[8]: 1.4142135623730950488016887242

In [9]: RR.tolerance
Out[9]: 2.22044604925031e-14

In [10]: R.tolerance
Out[10]: 1.5777218104420236108234571306e-28
```