Ticket #3927 (closed enhancement: fixed)

Opened 2 years ago

Last modified 2 years ago

[with new patch, positive review] Several enhancements and bug fixes for Factorization class

Reported by: cremona Owned by: somebody
Priority: minor Milestone: sage-3.1.2
Component: basic arithmetic Keywords: factorization
Cc: Author(s):
Report Upstream: Reviewer(s):
Merged in: Work issues:

Description

This works:

sage: factor(10)*factor(15)^(-1)             
2 * 3^-1

and so does this:

sage: factor(10/15)        
2 * 3^-1

but not this:

sage: factor(10)/factor(15)     
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)

/home/john/sage-3.1.test/spkg/build/python-2.5.2.p3/tmp/<ipython console> in <module>()

TypeError: unsupported operand type(s) for /: 'Factorization' and 'Factorization'

So: Factorizations can be multiplied and inverted but not divided, which is a bit silly. I suggest adding a __div___() method.

Attachments

sage-trac3927.patch Download (2.4 KB) - added by cremona 2 years ago.
sage-trac3927a.patch Download (2.6 KB) - added by cremona 2 years ago.
sage-trac3927b.patch Download (11.3 KB) - added by cremona 2 years ago.
trac3927-fix-gcd-lcm.patch Download (1.5 KB) - added by cwitty 2 years ago.

Change History

Changed 2 years ago by cremona

Changed 2 years ago by cremona

Changed 2 years ago by cremona

  • summary changed from Factorization class has no division implemented to [with patches, needs review] Factorization class has no division implemented

Two patches: the first implements division, the second implements gcd() and lcm() for Factorizations. The first also fixes a small gap discovered while testing those, namely that for FreeAlgebras?, the element 1 could not be inverted. Now, in any ring, for an element a for which a.is_unit() is true, a.invert() returns self. (For many rings, 1 is the only element for which .is_unit() does not return a NotImplementedError?).

Theses patches are essentially orthogonal to the other one #2460 concerning factorization.py. They are based on 3.1.1.

John

Changed 2 years ago by cremona

  • milestone set to sage-3.1.2

Changed 2 years ago by cremona

Changed 2 years ago by cremona

  • summary changed from [with patches, needs review] Factorization class has no division implemented to [with new patch, needs review] Several enhancements and bug fixes for Factorization class

The third patch deals with the issues left from trac #2460. Each Factorization now has a universe (cached as attribute self.__universe) computed using the Sequence idea proposed in trac #2460. The base_ring() function has been changed to universe() and returns the universe. If no universe is found it just sets it to None (for example, this is the case for Factorizations of modular symbol spaces).

I also added a new function is_integral and changed the docstrings to reflect the fact that the exponents needs not be positive (for example, factor(2/3) has always worked and returned a prime factorization with a negative exponent).

Since Factorization is used in a lot of different places I did -testall before posting this, and dealt with a few minor things which arose (no-one minded base_ring() being renamed universe(), but in 2 or 3 places unit_part() was changed to unit()).

All three patches should be applied in order; based on 3.1.1.

I think the add and sub methods are totally pointless but have left them in for now.

Changed 2 years ago by cwitty

  • summary changed from [with new patch, needs review] Several enhancements and bug fixes for Factorization class to [with new patch, positive review] Several enhancements and bug fixes for Factorization class

I fixed a few issues with gcd and lcm, but everything else looks good.

Positive review. (Apply all four patches.)

Changed 2 years ago by cwitty

Changed 2 years ago by cremona

Last patch is fine -- thanks.

Changed 2 years ago by mabshoff

  • status changed from new to closed
  • resolution set to fixed

Merged sage-trac3927.patch, sage-trac3927a.patch, sage-trac3927b.patch and trac3927-fix-gcd-lcm.patch in Sage 3.1.2.alpha1

Note: See TracTickets for help on using tickets.