#10667: Morphisms and Objects of Categories
---------------------------+------------------------------------------------
   Reporter:  SimonKing    |          Owner:  nthiery                      
       Type:  enhancement  |         Status:  needs_review                 
   Priority:  major        |      Milestone:                               
  Component:  categories   |       Keywords:  objects morphisms containment
Work_issues:               |       Upstream:  N/A                          
   Reviewer:               |         Author:  Simon King                   
     Merged:               |   Dependencies:  #9138, #11115                
---------------------------+------------------------------------------------
Changes (by SimonKing):

  * status:  needs_work => needs_review
  * dependencies:  => #9138, #11115


Comment:

 I created a new version of my patch. The aim is to make the performance of
 containment tests even better. I did the following, compared with the old
 patch:

  * I make the patch dependent on #9138 and #11115 (both help to come to
 speed).

  * I've put power series rings into the category and coercion framework.

  * I introduced base() for join categories: If at least one of the
 underlying categories has a base and if there is no conflict with
 different bases, then the join shall have that base as well. That is
 needed because some algebras have a join category by #9138.

  * SimplicialComplex has not been derived from CategoryObject, even though
 its instances are objects of a category! I corrected it.

  * GroupAlgebras should not only be Hopf algebras with basis but also
 group algebras. Hence, I made it a join of the two.

  * I implemented is_supercategory (there has only been is_subcategory),
 and use it to make containment tests even faster. It depends on #11115,
 because I use the Cython class of cached methods.

 I guess the best news is that the containment test via category framework
 can now compete with a pure class check, if that class check is done in
 Python. I take, for example, commutative rings:
 {{{
 sage: from sage.rings.commutative_ring import is_CommutativeRing
 sage: is_CommutativeRing??
 Type:           function
 Base Class:     <type 'function'>
 String Form:    <function is_CommutativeRing at 0x118c488>
 Namespace:      Interactive
 File:
 /mnt/local/king/SAGE/sandbox/sage-4.7.2.alpha2/local/lib/python2.6/site-
 packages/sage/rings/commutative_ring.py
 Definition:     is_CommutativeRing(R)
 Source:
 def is_CommutativeRing(R):
     return isinstance(R, CommutativeRing)
 sage: is_CommutativeRing(QQ)
 True
 sage: s = SymmetricGroup(4)
 sage: is_CommutativeRing(s)
 False
 sage: %timeit is_CommutativeRing(QQ)
 625 loops, best of 3: 1.09 µs per loop
 sage: %timeit is_CommutativeRing(s)
 625 loops, best of 3: 3.51 µs per loop
 }}}

 Since `is_CommutativeRing` just tests the class, it is supposed to be very
 fast. But let us compare with the generic containment test in the category
 of commutative rings and in the class of objects of that category:
 {{{
 sage: C = CommutativeRings()
 sage: O = C.objects()
 sage: QQ in C
 True
 sage: QQ in O
 True
 sage: s in C
 False
 sage: s in O
 False
 sage: %timeit QQ in C
 625 loops, best of 3: 4.62 µs per loop
 # Timing in sage-4.6.2: 12.9 µs per loop
 sage: %timeit QQ in O
 625 loops, best of 3: 1.5 µs per loop
 sage: %timeit s in C
 625 loops, best of 3: 4.69 µs per loop
 # Timing in sage-4.6.2: 10.2 µs per loop
 sage: %timeit s in O
 625 loops, best of 3: 1.46 µs per loop
 }}}

 Hence, `is_CommutativeRing(s)` is slower than `s in O`, where `O =
 CommutativeRings().objects()`.

 The reason for that speedup is Cython. While `is_CommutativeRing` is a
 Python function, the objects of a category are implemented in Cython.
 Moreover, category containment is tested by the cached method
 `is_supercategory`, which also is in Cython by #9138.

 Caveat: I did not run the full tests, yet, and I would like to try and
 remove some custom containment tests in the category framework, that tend
 to be slower than the generic test and might not be needed with #9138.

-- 
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/10667#comment:12>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica, 
and MATLAB

-- 
You received this message because you are subscribed to the Google Groups 
"sage-trac" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sage-trac?hl=en.

Reply via email to