on IRC right now we have a brief discussion based triggered by:
http://trac.sagemath.org/sage_trac/ticket/3840
I was puzzled by the choice of degree(0) == -1. Since we couldn't agree, I
though posting to [sage-devel] might be a good idea.
On IRC Carl pointed out:
- that this issue was touched on before:
http://groups.google.com/group/sage-devel/browse_thread/thread/f9d7b5016e237b22/7bafcc16315a21bb
- that Modern Computer Algebra defines degree(0) as -Infinity, since it
preserves: degree(ab) == degree(a) + degree(b)
- that -1 allows: cdef int d = p.degree() while -Infinity wouldn't
In any case, Sage's behaviour is inconsistent now:
sage: RR['x,y'](0).degree()
-1
sage: RR['x'](0).degree()
-1
sage: GF(2)['x'](0).degree()
-1
sage: QQ['x,y'](0).degree() # yep, I wrote that
0
I think that the last point isn't important enough to go for -1, so I'd vote
for -Infinity.
So my proposed game plan:
- I fix the libsingular wrapper to return -1
- Gary finishes his patch #3840
- [sage-devel] agrees on -Infinity or -1
Thoughts?
Martin
'
With some reluctance, I vote for -Infinity.
*however*, it might be good to (eventually?) have a general mechanism
for making life easier for a cython caller. Perhaps _degree() is a
cdef where available, returning -1, and degree just a wrapper for
that? I don't like that so much either. Hmmmm.
david
With some reluctance, I vote for -1. I've never been a fan of
testing for, and having to import, Infinity.
Nick
John Cannon votes for -1:
sage: magma.eval('Degree(PolynomialRing(RationalField())!0)')
'-1'
Henri Cohen votes for -2147483647:
sage: gp.eval('poldegree(0)')
'-2147483647'
Stephen Wolfram votes for -Infinity
sage: mathematica.eval('Exponent[x^2,x]')
2
sage: mathematica.eval('Exponent[0,x]')
-Infinity
Michael Monagon votes for -infinity:
> degree(x);
1
> degree(0*x);
-infinity
Joachim Neubuser votes for +infinity!
sage: gap.eval('x := Indeterminate(Rationals);')
'x_1'
sage: gap.eval('Degree(x)')
'1'
sage: gap.eval('Degree(0*x)')
'infinity'
I can't figure out how to get the degree of a poly in maxima.
William
-- William
No one's gotten around to it yet, but degree really should be changed to a
cpdef method, and as such it makes much more sense to return a long (and
hence -1). It also makes it easier to write loops (e.g. 0 <= i <=
f.degree()) and determine the number of coefficients (f.degree() + 1).
I also don't enjoy writing code that has to import and test for infinity.
- Robert
I vote for -1 since... that's what I already voted for by making it -1
in the first place. I like the consistency with Magma.
-- William
--
William Stein
Associate Professor of Mathematics
University of Washington
http://wstein.org
>
> On Aug 13, 2:16 pm, John H Palmieri <jhpalmier...@gmail.com> wrote:
>> I would vote for -Infinity, partly from a mathematical standpoint,
>> and
>> also because this sort of bothers me:
>>
>> sage: F = Frac(CC[['x']]) # or F.<x> = LaurentSeriesRing(CC)
>> sage: F(0).degree() == F(x**(-1)).degree()
>> True
>> sage: F(0).degree() > F(x**(-2)).degree()
>> True
>
> That's a compelling argument. Maybe David Harvey's suggestion of
> separate interfaces for .degree() (mathematical, returns -infinity)
> and for ._degree() (fast, computational, returns -1 or -2147483647) is
> the right way to go?
I'd be happy with this, if it returned -214... -- then the check is
_degree() < 0. The Laurent series argument is convincing.
Nick
Yes, that Laurent series comparison is a bit bothersome. If it can be
avoided, however, I dislike having two ways of doing things, the "fast"
way and the "slow, obvious" way. I'm a big proponent of having the obvious
way be the fast way--that's the whole point of cpdef functions. It also
makes migrating code from Python to Cython more painful and uglier.
- Robert
Here's what magma has to say about laurent series:
> R<x> := PolynomialRing(RationalField());
> Degree(R!0);
-1
> S<y> := LaurentSeriesRing(RationalField());
> Degree(S!0);
>> Degree(S!0);
^
Runtime error in 'Degree': Degree of zero or O(x^n) illegal
But the same error occurs for PowerSeriesRing as well, so there's
some consistency at least.
david
If I may say something...
What is the signature of degree in some domain D?
Is it
degree: D -> (Integer u {-Infinity})
or
degree: (D \ {0}) -> Integer
or
degree: D -> Integer
?
It is all clear (except in the last case) if it is somewhere specified
what the domain and codomain of 'degree' should be. In the last case it
is not so clear what degree(0) should be if D represents Laurent
polynomials.
One might also explicitly say that degree(0) is unspecified, i.e. that
degree is only a partial function.
Note, that -Infinity is not an integer and making
Integer u {-Infinity}
into a ring can be a bit difficult. (What is (-2)*(-Infinity)?)
Just a bit more oil for the fire...
Ralf
I agree (and despite the conflict with Magma). For exactly the same
reason as this:
sage: 0.valuation(2)
+Infinity
The degree *is* a valuation (times minus 1), and must behave
consistently with its extension to the fraction field (rational
functions) and to completions (Laurent polynomials).
So I vote that the 0 polynomial should have degree -Infinity.
John
> Chris.
> >
>