> I was just discussing this with a few people at the sage days at ICERM and
> it seems that LaurentPolynomials are horribly broken.
I don't think much work has been put into Laurent polynomials since the
initial implementation. Improvements are welcome!
> Consider the following in 5.6:
>
> sage: q in R
> True
> sage: q^-1 in R
> True
> sage: 1/q in R
> False
> sage: ~q in R
> False
> sage: 1/q==q^-1
> True
> sage: 1/q is q^-1
> False
> sage: (1/q).parent()
> Fraction Field of Univariate Laurent Polynomial Ring in q over Rational
> Field
> sage: (q^-1).parent()
> Univariate Laurent Polynomial Ring in q over Rational Field
> sage: q^2/q
> q^2/q
> sage: q^2/q in R
> False
>
If R is an integral domain in Sage then division of two elements will
result in an element of the fraction field K, regardless of whether the
result actually lies in the image of the inclusion of R in K. The reason
for this choice is that it allows you to reason about the parent of the
result without having to know what the actual operands are.
The fact that q^-1 is in R is a bit strange, but was presumably a choice
made so that you could easily construct actual elements of R. I would
advocate for the implementation of a shift operator (__lshift__ and
__rshift__) so that the following would work:
sage: f = q^2 + 2*q^4
sage: f >> 3
q^-1 + 2*q
sage: f << 3
q^5 + 2*q^7
The fact that q^2/q prints as q results from elements of R not having a
quo_rem method (which will show up again below).
> If we try and work in Z[q,q^-1], my favourite ring, it gets worse:
>
> sage: R.<q>=LaurentPolynomialRing(ZZ,'q')
> sage: (1/q).parent()
> Fraction Field of Univariate Laurent Polynomial Ring in q over Integer Ring
> sage: (q^-1).parent()
> Univariate Laurent Polynomial Ring in q over Integer Ring
> sage: q^-1 in R
> True
> sage: 1/q in R
> ERROR: An unexpected error occurred while tokenizing input
> ...
> ArithmeticError: unable to reduce because lack of gcd or quo_rem algorithm
>
Z[q,q^-1] is not a PID, so division needs some care. Nobody has put the
time in to make it work properly.
> In general, even basic arithmetic seems hazardous in this ring.
>
True enough.
> At last some of this seems to be addressed in
> http://trac.sagemath.org/sage_trac/ticket/11726. Does anyone know what
> the status of this is?
>
It doesn't look like anyone has looked at it recently. I have no idea of
Tom has time to work on it; I assume he wouldn't object if somebody at
ICERM got it shape to get a positive review.
David
--
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-devel?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.