Is this a bug?

67 views
Skip to first unread message

Martin R

unread,
Sep 21, 2022, 9:22:30 AM9/21/22
to sage-devel
sage: R.<q,t> = QQ[]
sage: F = R.fraction_field()
sage: ~F(-1)
1/(-1)
sage: 1/F(-1)
-1
sage: R.<q> = QQ[]
sage: F = R.fraction_field()
sage: ~F(-1)
-1

Travis Scrimshaw

unread,
Sep 21, 2022, 11:29:41 PM9/21/22
to sage-devel
No, it is not. The generic fraction field can only reduce something up to a unit since the gcd is defined up to a unit. I agree it looks funny, but I don't see a sensible way to code to get a negative sign in the numerator. Compare with

sage: ~F(-q+1)
1/(-q + 1)
sage: ~F(q-1)
1/(q - 1)
sage: -1 / F(-q+1)
(-1)/(-q + 1)
sage: -1 / F(q-1)
(-1)/(q - 1)

Of course, there are two distinct elements here, but which ones are the "correct" way to print stuff? Not to mention if we are doing something in a more general integral domain (or polynomials with a completely different implementation).

Something could be done when the denominator is a unit not equal to one though. Possibly only in the printing however (i.e., not in the reduce() method and its internal representation) in order to reduce the amount of computations when manipulating such elements.

Best,
Travis


Fredrik Johansson

unread,
Sep 22, 2022, 9:56:00 AM9/22/22
to sage-devel
On Thursday, September 22, 2022 at 5:29:41 AM UTC+2 Travis Scrimshaw wrote:
No, it is not. The generic fraction field can only reduce something up to a unit since the gcd is defined up to a unit. I agree it looks funny, but I don't see a sensible way to code to get a negative sign in the numerator.

Rings could define canonical units where that makes sense. This is how Nemo does it, for example: http://nemocas.github.io/Nemo.jl/stable/fraction/

Fredrik
Reply all
Reply to author
Forward
0 new messages