On Fri, 1 Mar 2024 at 10:04, Dima Pasechnik <dimp...@gmail.com> 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 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 treatment.
>
> Exceptions are expensive, performance-wise, and using them as a regular
> means of controlling the flow of the algorithm execution is not a good idea.
> A simple  if/then/else  is much cheaper.
>

Isn't this suggestion to have f.degree() raise an exception when f is zero,
but also then that any code which needs the degree to treat 0 as a special
case (where that makes sense)?   To it would be the caller's responsibility
to do that with a test of f.is_zero() or whatever, rather than by seeing if
an exception is triggered.

John


>
> Dima
> >
> >Martin
> >On Thursday 29 February 2024 at 22:54:20 UTC+1 Nils Bruin wrote:
> >
> >> 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 make
> >> a perfect sense.
> >>
> >> At the moment, I think most degree functions do their best to return
> sage
> >> Integer objects; mainly so that coercion works well with them. So
> whatever
> >> solution we use should probably be based on objects that naturally live
> in
> >> the sage hierarchy. We do have an infinity object in sage and it
> already
> >> gets used for valuations.
> >>
> >> Incidentally:
> >>
> >>  sage: R.<x>=LaurentSeriesRing(QQ)
> >> sage: z=R(0)
> >> sage: z.valuation()
> >> +Infinity
> >> sage: z.degree()
> >> -1
> >>
> >> I don't quite know why laurent series have a degree defined at all, but
> >> they're keeping to the deg(0)=-1 convention.
> >>
> >> Incidentally:
> >>
> >> sage: A.<x>=QQ[]
> >> sage: B.<y>=LaurentPolynomialRing(QQ)
> >> sage: x.valuation(oo)
> >> -1
> >> sage: y.valuation(oo)
> >> 1
> >> so polynomial rings have a valuation (that will return +oo when
> >> appropriate), but on LaurentPolynomialRing this gets silently broken:
> the
> >> argument simply gets ignored and the valuation at 0 is returned. So I
> guess
> >> you can get a well-behaving degree with
> >>
> >> f=0*y
> >> -f(1/y).valuation()
> >>
> >
>
> --
> You received this message because you are subscribed to the Google Groups
> "sage-devel" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to sage-devel+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sage-devel/D20DACD9-8D5A-48F4-81F5-141CF0181BA1%40gmail.com
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sage-devel/CAD0p0K45r2ishqx4kzEwuVF9%3DYDtojjteBn3snKMkGj8ijb72g%40mail.gmail.com.

Reply via email to