New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Should Poly use an algebraic domain by default? #5428

Open
asmeurer opened this Issue Apr 30, 2011 · 4 comments

Comments

Projects
None yet
3 participants
@asmeurer
Copy link
Member

asmeurer commented Apr 30, 2011

In [1]: Poly(t**2 + I, t, domain='ZZ[sqrt(-1)]')
Out[1]: Poly(t**2 + I, t, domain='ZZ[I]')

In [2]: Poly(t**2 + sqrt(2), t)
Out[2]: Poly(t**2 + 2**(1/2), t, domain='EX')

In [3]: Poly(t**2 + I, t)
Out[3]: Poly(t**2 + I, t, domain='EX')

In [4]: Poly(t**2 + I, t, domain='ZZ[sqrt(-1)]')
Out[4]: Poly(t**2 + I, t, domain='ZZ[I]')

In [6]: Poly(t**2 + sqrt(2), t, domain='ZZ[sqrt(2)]')
Out[6]: Poly(t**2 + 2**(1/2), t, domain='ZZ[2**(1/2)]')

I don't know too much about the state of algebraic domains in the polys to know if there is a good reason for this or not, but it seems to me that [2] and [3] should instead return what [4] and [6] return, respectively.  Mateusz, is there a good reason why it uses EX instead of an algebraic domain by default?

Original issue for #5428: http://code.google.com/p/sympy/issues/detail?id=2329
Original author: https://code.google.com/u/asmeurer@gmail.com/
Original owner: https://code.google.com/u/asmeurer@gmail.com/

@mattpap

This comment has been minimized.

Copy link
Member

mattpap commented Apr 29, 2011

There are reasons for this: algebraic number domains are very slow especially for the case when there are many extensions and algorithms for automatic discovery of extensions aren't very smart.

btw. What you show is not a syntax for specifying extensions, this is:

In [1]: Poly(t**2 + I, t, extension=I)
Out[1]: Poly(t**2 + I, t, domain='QQ<I>')

In [2]: Poly(t**2 + I, t, extension=True)
Out[2]: Poly(t**2 + I, t, domain='QQ<I>')

In [3]: Poly(t**2 + I, t, domain='QQ<I>')
Out[3]: Poly(t**2 + I, t, domain='QQ<I>')

In [4]: _.get_domain().is_Algebraic
Out[4]: True

In [5]: Poly(t**2 + I, t, domain='ZZ[I]')
Out[5]: Poly(t**2 + I, t, domain='ZZ[I]')

In [6]: _.get_domain().is_Algebraic
Out[6]: False

ZZ[I] is a polynomial in I, not an algebraic number field (ZZ<I> will give you an error).

Original comment: http://code.google.com/p/sympy/issues/detail?id=2329#c1
Original author: https://code.google.com/u/101069955704897915480/

@asmeurer

This comment has been minimized.

Copy link
Member

asmeurer commented Apr 29, 2011

Oops! It's been too long since I've worked in algebra I guess.  But shouldn't ZZ[I] raise an exception?

How much slower are the algebraic domains?  Are there plans to make them faster?  To me, they are better because you are guaranteed that everything will be simplified to 0 when it can be (there is no such guarantee in EX, and hence it can lead to wrong results when not used carefully).

Original comment: http://code.google.com/p/sympy/issues/detail?id=2329#c2
Original author: https://code.google.com/u/asmeurer@gmail.com/

@mattpap

This comment has been minimized.

Copy link
Member

mattpap commented Apr 30, 2011

> But shouldn't ZZ[I] raise an exception?

It would be nice, but then people would complain that `I` can't be a generator in the context of symbolic manipulation (not algebraic computations). The current state of art is something that is convenient in the former case and allows to do the later when needed.

EX doesn't solve zero equivalence problem in general, whereas algebraic domains do, but for most common cases EX is sufficient and is faster than algebraics (because it doesn't require computing minimal polynomials, field isomorphisms, etc. (which are very expensive -> Groebner bases, PSLQ)). And if you want to do meaningful algebraic computing, then you make have to setup the appropriate domain explicitly anyway, for example factor(x**4 + 1) over I or sqrt(2) or I + sqrt(2).

This is also how Mathematica works more or less.

Original comment: http://code.google.com/p/sympy/issues/detail?id=2329#c3
Original author: https://code.google.com/u/101069955704897915480/

@asmeurer

This comment has been minimized.

Copy link
Member

asmeurer commented Mar 20, 2012

@asmeurer asmeurer self-assigned this Mar 7, 2014

skirpichev added a commit to skirpichev/diofant that referenced this issue Jan 9, 2018

Support extension option for some methods
Probably in future this could be reverted by making
extension=True - default for construct_domain(),
see e.g. diofant#478.

Related issues:
* sympy/sympy#5428
* sympy/sympy#7724
* sympy/sympy#12345

skirpichev added a commit to skirpichev/diofant that referenced this issue Dec 11, 2018

polys: construct_domain() enable algebraic extensions by default
Before:
    In [1]: Poly(x**2 + sqrt(2), x)
    Out[1]: Poly(x**2 + sqrt(2), x, domain='EX')

    In [2]: Poly(x**2 + sqrt(2))
    Out[2]: Poly(x**2 + sqrt(2), x, sqrt(2), domain='ZZ')

After:
    In [1]: Poly(x**2 + sqrt(2), x)
    Out[1]: Poly(x**2 + sqrt(2), x, domain='QQ<sqrt(2)>')

    In [2]: Poly(x**2 + sqrt(2))
    Out[2]: Poly(x**2 + sqrt(2), x, sqrt(2), domain='ZZ')

Closes sympy/sympy#5428
Closes sympy/sympy#542814337

skirpichev added a commit to skirpichev/diofant that referenced this issue Dec 11, 2018

polys: construct_domain() enable algebraic extensions by default
Before:
    In [1]: Poly(x**2 + sqrt(2), x)
    Out[1]: Poly(x**2 + sqrt(2), x, domain='EX')

    In [2]: Poly(x**2 + sqrt(2))
    Out[2]: Poly(x**2 + sqrt(2), x, sqrt(2), domain='ZZ')

After:
    In [1]: Poly(x**2 + sqrt(2), x)
    Out[1]: Poly(x**2 + sqrt(2), x, domain='QQ<sqrt(2)>')

    In [2]: Poly(x**2 + sqrt(2))
    Out[2]: Poly(x**2 + sqrt(2), x, sqrt(2), domain='ZZ')

Closes sympy/sympy#5428
Closes sympy/sympy#542814337
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment