Re: [sage-devel] Re: Degree of the zero polynomial ring for `LaurentPolynomialRing`

2024-03-01 Thread John Cremona
Mathematically, the degree of a nonzero polynomial is the negative of its valuation at infinity, i.e. the valuation for which 1/x is a uniformiser. On Fri, 1 Mar 2024, 19:29 Travis Scrimshaw, wrote: > Some quick data points: > > - The general graded modules (and hence algebras) code raises an

Re: [sage-devel] Re: Degree of the zero polynomial ring for `LaurentPolynomialRing`

2024-03-01 Thread Travis Scrimshaw
Some quick data points: - The general graded modules (and hence algebras) code raises an error for `0` since it is defined there by the direct summand the element belongs to (and `0` belongs to all of them. - For polynomials, it is very useful to have a single check `f.degree() > k` for some

Re: [sage-devel] Re: Degree of the zero polynomial ring for `LaurentPolynomialRing`

2024-03-01 Thread 'Martin R' via sage-devel
I don't get it - are my previous messages invisible? 1st Message: I don't understand - `degree` doesn't make much sense for Laurent series - there is no way to determine the degree of a LaurentSeries and no way to determine the degree of a LazyLaurentSeries with one minor exception - which is

Re: [sage-devel] Re: Degree of the zero polynomial ring for `LaurentPolynomialRing`

2024-03-01 Thread Giacomo Pope
As an aside, the univariate LaurentPolynomialRing had a notion of `valuation` but the multivariate one didn't... In the PR: https://github.com/sagemath/sage/pull/37490 I added random elements but also a notion of valuation() for the multivariate case and just made it act similarly to the

Re: [sage-devel] Re: Degree of the zero polynomial ring for `LaurentPolynomialRing`

2024-03-01 Thread Nils Bruin
On Friday 1 March 2024 at 09:49:15 UTC-8 Giacomo Pope wrote: Following this discussion, I have made a draft PR to change the degree for *only* the LaurentPolynomialRing and I will see if the CI detects anything. https://github.com/sagemath/sage/pull/37513 I agree that if we change the

Re: [sage-devel] Re: Degree of the zero polynomial ring for `LaurentPolynomialRing`

2024-03-01 Thread 'Martin R' via sage-devel
On Friday 1 March 2024 at 19:03:35 UTC+1 Dima Pasechnik wrote: On Fri, Mar 1, 2024 at 5:58 PM 'Martin R' via sage-devel < sage-...@googlegroups.com> wrote: I don't understand - `degree` doesn't make much sense for Laurent series - there is no way to determine the degree of a LaurentSeries and

Re: [sage-devel] Re: Degree of the zero polynomial ring for `LaurentPolynomialRing`

2024-03-01 Thread Dima Pasechnik
On Fri, Mar 1, 2024 at 5:58 PM 'Martin R' via sage-devel < sage-devel@googlegroups.com> wrote: > I don't understand - `degree` doesn't make much sense for Laurent series - > there is no way to determine the degree of a LaurentSeries and no way to > determine the degree of a LazyLaurentSeries with

Re: [sage-devel] Re: Degree of the zero polynomial ring for `LaurentPolynomialRing`

2024-03-01 Thread Dima Pasechnik
On Fri, Mar 1, 2024 at 5:11 PM Nils Bruin wrote: > On Friday 1 March 2024 at 04:26:43 UTC-8 Dima Pasechnik wrote: > > > It seems that exactly the same algorithm will work (I didn't check this!) > for Laurent polynomials (they still form a Euclidean domain), and there you > better set

Re: [sage-devel] Re: Degree of the zero polynomial ring for `LaurentPolynomialRing`

2024-03-01 Thread 'Martin R' via sage-devel
I don't understand - `degree` doesn't make much sense for Laurent series - there is no way to determine the degree of a LaurentSeries and no way to determine the degree of a LazyLaurentSeries with one minor exception - which is when it is known that the series terminates, but that's rare. On

Re: [sage-devel] Re: Degree of the zero polynomial ring for `LaurentPolynomialRing`

2024-03-01 Thread Giacomo Pope
Following this discussion, I have made a draft PR to change the degree for *only* the LaurentPolynomialRing and I will see if the CI detects anything. https://github.com/sagemath/sage/pull/37513 I agree that if we change the LaurentPolynomialRing we should also change the `LaurentSeriesRing`,

Re: [sage-devel] Re: Degree of the zero polynomial ring for `LaurentPolynomialRing`

2024-03-01 Thread 'Martin R' via sage-devel
Could you expand on 'the whole valuation interpretation of "degree" goes out of the window'? What do you mean with "valuation interpretation"? Is raising an exception out of the question? On Friday 1 March 2024 at 18:11:40 UTC+1 Nils Bruin wrote: > On Friday 1 March 2024 at 04:26:43 UTC-8

Re: [sage-devel] Re: Degree of the zero polynomial ring for `LaurentPolynomialRing`

2024-03-01 Thread Nils Bruin
On Friday 1 March 2024 at 04:26:43 UTC-8 Dima Pasechnik wrote: It seems that exactly the same algorithm will work (I didn't check this!) for Laurent polynomials (they still form a Euclidean domain), and there you better set degree(0)=-oo, otherwise it's going to be a problem. I think it's

Re: [sage-devel] Re: Degree of the zero polynomial ring for `LaurentPolynomialRing`

2024-03-01 Thread Dima Pasechnik
On Fri, Mar 1, 2024 at 11:41 AM Oscar Benjamin wrote: > On Fri, 1 Mar 2024 at 11:15, John Cremona wrote: > > > > On Fri, 1 Mar 2024 at 11:03, Dima Pasechnik wrote: > >> > >> On Fri, Mar 1, 2024 at 10:24 AM John Cremona > wrote: > >>> > >>> On Fri, 1 Mar 2024 at 10:04, Dima Pasechnik wrote: >

Re: [sage-devel] Re: Degree of the zero polynomial ring for `LaurentPolynomialRing`

2024-03-01 Thread Oscar Benjamin
On Fri, 1 Mar 2024 at 11:51, 'Martin R' via sage-devel wrote: > On Friday 1 March 2024 at 12:15:36 UTC+1 John Cremona wrote: > On Fri, 1 Mar 2024 at 11:03, Dima Pasechnik wrote: > > OTOH, setting the degree of 0 to be -oo has an obvious advantage: it > automaticlly gives mathematically correct

Re: [sage-devel] Re: Degree of the zero polynomial ring for `LaurentPolynomialRing`

2024-03-01 Thread 'Martin R' via sage-devel
On Friday 1 March 2024 at 12:15:36 UTC+1 John Cremona wrote: On Fri, 1 Mar 2024 at 11:03, Dima Pasechnik wrote: On Fri, Mar 1, 2024 at 10:24 AM John Cremona wrote: On Fri, 1 Mar 2024 at 10:04, Dima Pasechnik wrote: On 1 March 2024 09:07:26 GMT, 'Martin R' via sage-devel <

Re: [sage-devel] Re: Degree of the zero polynomial ring for `LaurentPolynomialRing`

2024-03-01 Thread Oscar Benjamin
On Fri, 1 Mar 2024 at 11:15, John Cremona wrote: > > On Fri, 1 Mar 2024 at 11:03, Dima Pasechnik wrote: >> >> On Fri, Mar 1, 2024 at 10:24 AM John Cremona wrote: >>> >>> On Fri, 1 Mar 2024 at 10:04, Dima Pasechnik wrote: On 1 March 2024 09:07:26 GMT, 'Martin R' via

Re: [sage-devel] Re: Degree of the zero polynomial ring for `LaurentPolynomialRing`

2024-03-01 Thread John Cremona
On Fri, 1 Mar 2024 at 11:03, Dima Pasechnik wrote: > > > On Fri, Mar 1, 2024 at 10:24 AM John Cremona > wrote: > >> >> >> On Fri, 1 Mar 2024 at 10:04, Dima Pasechnik wrote: >> >>> >>> >>> On 1 March 2024 09:07:26 GMT, 'Martin R' via sage-devel < >>> sage-devel@googlegroups.com> wrote: >>> >I'd

Re: [sage-devel] Re: Degree of the zero polynomial ring for `LaurentPolynomialRing`

2024-03-01 Thread Dima Pasechnik
On Fri, Mar 1, 2024 at 10:24 AM John Cremona wrote: > > > On Fri, 1 Mar 2024 at 10:04, Dima Pasechnik wrote: > >> >> >> On 1 March 2024 09:07:26 GMT, 'Martin R' via sage-devel < >> sage-devel@googlegroups.com> wrote: >> >I'd be OK with raising an exception or with -oo, but it should be >>

Re: [sage-devel] Re: Degree of the zero polynomial ring for `LaurentPolynomialRing`

2024-03-01 Thread John Cremona
On Fri, 1 Mar 2024 at 10:04, Dima Pasechnik wrote: > > > On 1 March 2024 09:07:26 GMT, 'Martin R' via sage-devel < > sage-devel@googlegroups.com> wrote: > >I'd be OK with raising an exception or with -oo, but it should be > uniform, > >and I think it should be the same for polynomials, Laurent

Re: [sage-devel] Re: Degree of the zero polynomial ring for `LaurentPolynomialRing`

2024-03-01 Thread Dima Pasechnik
On 1 March 2024 09:07:26 GMT, 'Martin R' via sage-devel wrote: >I'd be OK with raising an exception or with -oo, but it should be uniform, >and I think it should be the same for polynomials, Laurent polynomials and >in the same spirit for degree and valuation. > >It might be best to raise

Re: [sage-devel] Re: Degree of the zero polynomial ring for `LaurentPolynomialRing`

2024-03-01 Thread Gareth Ma
And that will be a problem when `R` is a laurent polynomial ring. On 01/03/2024 09:12, Gareth Ma wrote: I lean towards setting it to -∞. While we are at this, how should `R.random_element` be called? The method currently takes a `degree` argument, which is a tuple of lower and upper bound,

Re: [sage-devel] Re: Degree of the zero polynomial ring for `LaurentPolynomialRing`

2024-03-01 Thread Gareth Ma
I lean towards setting it to -∞. While we are at this, how should `R.random_element` be called? The method currently takes a `degree` argument, which is a tuple of lower and upper bound, and if the user sets the lower bound to -1, then `0` is a possible outcome. Would the user call it with

Re: [sage-devel] Re: Degree of the zero polynomial ring for `LaurentPolynomialRing`

2024-03-01 Thread 'Martin R' via sage-devel
I'd be OK with raising an exception or with -oo, but it should be uniform, and I think it should be the same for polynomials, Laurent polynomials and in the same spirit for degree and valuation. It might be best to raise an exception, because this ensures that the zero polynomial gets special

Re: [sage-devel] Re: Degree of the zero polynomial ring for `LaurentPolynomialRing`

2024-02-29 Thread Nils Bruin
On Thursday 29 February 2024 at 11:15:21 UTC-8 Dima Pasechnik wrote: How about using something like https://github.com/NeilGirdhar/extended_int ? (Even better, do a PEP to have such a thing in Python proper...) In old, totally duck-typed, Python this didn't really matter, but nowadays it does

Re: [sage-devel] Re: Degree of the zero polynomial ring for `LaurentPolynomialRing`

2024-02-29 Thread Dima Pasechnik
On Thu, Feb 29, 2024 at 4:34 PM Oscar Benjamin wrote: > I recently reviewed cases in the sympy polys code that handle the > degree of a zero polynomial: > https://github.com/sympy/sympy/pull/25784 > > My conclusion is that it is sometimes useful that deg(0) < deg(p) for > p != 0 but otherwise it

Re: [sage-devel] Re: Degree of the zero polynomial ring for `LaurentPolynomialRing`

2024-02-29 Thread John Cremona
There may be case for leaving deg(0) undefined both for polynomials and Laurent polynomials (and power series and Laurent series): it's at best a shorthand (pace Nils' comment about dimensions) and needs to be handled separately in code. So calling deg(0) could raise a ValueError or

Re: [sage-devel] Re: Degree of the zero polynomial ring for `LaurentPolynomialRing`

2024-02-29 Thread Oscar Benjamin
I recently reviewed cases in the sympy polys code that handle the degree of a zero polynomial: https://github.com/sympy/sympy/pull/25784 My conclusion is that it is sometimes useful that deg(0) < deg(p) for p != 0 but otherwise it is not really possible to use the value of deg(0) for anything

Re: [sage-devel] Re: Degree of the zero polynomial ring for `LaurentPolynomialRing`

2024-02-29 Thread Giacomo Pope
There seem to be two things we could do here: 1. Have some form of vote / discussion on whether the degree of the zero polynomial should *ever* be -1 2. Modify the degree calls for the LaurentSeries and LaurentPolynomialRing (maybe other Laurent* which I am unfamiliar with) to have the zero

Re: [sage-devel] Re: Degree of the zero polynomial ring for `LaurentPolynomialRing`

2024-02-28 Thread Dima Pasechnik
On Wed, Feb 28, 2024 at 5:00 PM Nils Bruin wrote: > On Wednesday 28 February 2024 at 08:03:45 UTC-8 Giacomo Pope wrote: > > > I don't know the history of this choice or what we should be doing > generally. -1 for polynomials with only positive degree seems like a > computer science workaround,

Re: [sage-devel] Re: Degree of the zero polynomial ring for `LaurentPolynomialRing`

2024-02-28 Thread Nils Bruin
On Wednesday 28 February 2024 at 08:03:45 UTC-8 Giacomo Pope wrote: I don't know the history of this choice or what we should be doing generally. -1 for polynomials with only positive degree seems like a computer science workaround, but for the LaurentPolynomialRing it just seems wrong? I

Re: [sage-devel] Re: Degree of the zero polynomial ring for `LaurentPolynomialRing`

2024-02-28 Thread Giacomo Pope
Not a "maths" why, but I know anything which uses singular currently returns -1 because of the following snippet cdef long singular_polynomial_deg(poly *p, poly *x, ring *r) noexcept: cdef long _deg, deg cdef int dummy deg = -1 _deg = -1 if p == NULL: return -1

Re: [sage-devel] Re: Degree of the zero polynomial ring for `LaurentPolynomialRing`

2024-02-28 Thread Dima Pasechnik
in the polynomial case, the usual convention is deg(0)=-infinity I don't know why Sage uses -1 instead: R.=QQ[] f=0*x*y f.degree() gives -1. On Wed, Feb 28, 2024 at 1:50 PM 'Martin R' via sage-devel < sage-devel@googlegroups.com> wrote: > Sorry, I confused it with valuation, but I guess it is

[sage-devel] Re: Degree of the zero polynomial ring for `LaurentPolynomialRing`

2024-02-28 Thread 'Martin R' via sage-devel
Yes, I'd say so. On Wednesday 28 February 2024 at 14:57:26 UTC+1 Giacomo Pope wrote: > Ahh ok, thank you. Considering the following output I think a PR to make > the degree of zero for these Laurent classes -Infinity is reasonable? > > ``` > sage: R. = LaurentSeriesRing(QQ) > sage:

[sage-devel] Re: Degree of the zero polynomial ring for `LaurentPolynomialRing`

2024-02-28 Thread Giacomo Pope
Ahh ok, thank you. Considering the following output I think a PR to make the degree of zero for these Laurent classes -Infinity is reasonable? ``` sage: R. = LaurentSeriesRing(QQ) sage: R.zero().valuation() +Infinity sage: R.zero().degree() -1 sage: sage: R. = LaurentPolynomialRing(QQ) sage:

[sage-devel] Re: Degree of the zero polynomial ring for `LaurentPolynomialRing`

2024-02-28 Thread 'Martin R' via sage-devel
Sorry, I confused it with valuation, but I guess it is still a related question. On Wednesday 28 February 2024 at 14:36:35 UTC+1 Giacomo Pope wrote: > This is not what I see on the current beta: > > sage: R. = LaurentSeriesRing(QQ) > sage: R.zero().degree() > -1 > sage: R. =

[sage-devel] Re: Degree of the zero polynomial ring for `LaurentPolynomialRing`

2024-02-28 Thread Giacomo Pope
This is not what I see on the current beta: sage: R. = LaurentSeriesRing(QQ) sage: R.zero().degree() -1 sage: R. = LazyLaurentSeriesRing(QQ) sage: R.zero().degree() --- AttributeErrorTraceback

[sage-devel] Re: Degree of the zero polynomial ring for `LaurentPolynomialRing`

2024-02-28 Thread 'Martin R' via sage-devel
LazyLaurentSeriesRing(QQ) currently gives +Infinity. On Wednesday 28 February 2024 at 12:50:45 UTC+1 Giacomo Pope wrote: > While chasing various bugs which appeared in the CI, I ended up adding a > small method for computing random elements for the LaurentPolynomialRing > class. > > When