sagemath / sage

Main repository of SageMath
https://www.sagemath.org
Other
1.47k stars 487 forks source link

Allow "generic" PolynomialRing implementation #24264

Closed jdemeyer closed 6 years ago

jdemeyer commented 7 years ago

It is possible to specify a specific backend like PolynomialRing(QQ, 'x', implementation="singular") but the opposite (asking for a generic Sage implementation) is not. Fix this by allowing implementation="generic".

This requires various fixes involving the implementation keyword being ignored or breaking caching. In particular, we fix this caching bug:

sage: p = 2^64 + 13
sage: A = GF(p^2)
sage: B = GF(p^3)
sage: R = A.modulus().parent()
sage: S = B.modulus().parent()
sage: R is S
False

We also introduce a new implementation "GF2X" for the GF2X package. This used be called "NTL" which we still allow as alias.

CC: @embray @tscrim

Component: basic arithmetic

Author: Jeroen Demeyer

Branch/Commit: 0efda1b

Reviewer: Travis Scrimshaw

Issue created by migration from https://trac.sagemath.org/ticket/24264

tscrim commented 6 years ago
comment:48

Trivial thing, but can we break this output line since it is so long:

            ValueError: domain (Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in x over Integer Ring)
             and codomain (Univariate Polynomial Ring in t over Univariate Polynomial Ring in x over Integer Ring)
             must have the same functorial construction over their base rings

Otherwise LGTM and you can set a positive review on my behalf.

jdemeyer commented 6 years ago
comment:49

Replying to @tscrim:

Trivial thing, but can we break this output line since it is so long

Shouldn't the output in doctests match the actual output from the terminal? If the actual output is one long line, shouldn't the doctest reflect that?

If you insist, I will change it though.

tscrim commented 6 years ago
comment:50

Replying to @jdemeyer:

Replying to @tscrim:

Trivial thing, but can we break this output line since it is so long

Shouldn't the output in doctests match the actual output from the terminal? If the actual output is one long line, shouldn't the doctest reflect that?

If you insist, I will change it though.

My usually 90 char wide terminal splits it (essentially randomly) and we have the guideline of 80 char/line in documentation. So with that in mind, I was suggesting the most logical places to split that and keep the lines short. If you would rather leave it as one really (really) long line, then I won't insist, but it makes it much more manageable for me and is in the spirit of the rest of Sage's doc. (I would also not oppose a strict 80 char/line cuts as well.)

jdemeyer commented 6 years ago
comment:51

Replying to @tscrim:

and we have the guideline of 80 char/line in documentation.

In my mind, there is a difference between the different parts of the documentation:

  1. textual documentation: word wrap as usual

  2. code in EXAMPLES: follow PEP 8, which means trying to limit the line lengths

  3. output in EXAMPLES: I think it is best to keep the exact formatting of the output and not randomly wrap lines.

tscrim commented 6 years ago
comment:52

The problem is it is so ugly on my screen that I cannot read it at once with my default settings. IMO, there is no benefit in keeping it "exactly" (where I would say that is not completely accurate with how terminals can wrap) in the doc without some breaks (in this case, I think they are logical). Although this is effectively bikeshedding, and I don't care enough to die on this hill.

vbraun commented 6 years ago
comment:53
sage -t --long --warn-long 65.5 src/sage/rings/morphism.pyx
**********************************************************************
File "src/sage/rings/morphism.pyx", line 361, in sage.rings.morphism
Failed example:
    phi3 = RingHomomorphism_from_base(H, R.hom([x])); phi3
Expected:
    Ring endomorphism of Univariate Quotient Polynomial Ring in a over Finite Field of size 2 with modulus x^2 + x + 1
      Defn: Induced from base ring by
            Ring endomorphism of Univariate Polynomial Ring in x over Finite Field of size 2 (using NTL)
              Defn: x |--> x
Got:
    Ring endomorphism of Univariate Quotient Polynomial Ring in a over Finite Field of size 2 with modulus x^2 + x + 1
      Defn: Induced from base ring by
            Ring endomorphism of Univariate Polynomial Ring in x over Finite Field of size 2 (using GF2X)
              Defn: x |--> x
**********************************************************************
tscrim commented 6 years ago
comment:54

Jeroen, will you update the output here, or should I do it?

jdemeyer commented 6 years ago
comment:55

I forgot about this ticket. If you can update it, please do.

tscrim commented 6 years ago

Changed commit from fff5d7e to ad3118f

tscrim commented 6 years ago
comment:56

Updated.


New commits:

ad3118fMerge branch 'u/jdemeyer/allow__generic__polynomialring_implementation' of git://trac.sagemath.org/sage into u/tscrim/generic_polynomialring_implementation-24264
tscrim commented 6 years ago

Changed branch from u/jdemeyer/allowgenericpolynomialring_implementation to u/tscrim/generic_polynomialring_implementation-24264

7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 6 years ago

Branch pushed to git repo; I updated commit sha1 and set ticket back to needs_review. New commits:

0efda1bFixing doctest output in morphism.pyx.
7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 6 years ago

Changed commit from ad3118f to 0efda1b

tscrim commented 6 years ago
comment:58

Commit, then push. :p

vbraun commented 6 years ago

Changed branch from u/tscrim/generic_polynomialring_implementation-24264 to 0efda1b