#9944: categories for polynomial rings
----------------------------------------------+-----------------------------
   Reporter:  robertwb                        |       Owner:  nthiery   
       Type:  defect                          |      Status:  needs_info
   Priority:  major                           |   Milestone:  sage-4.7  
  Component:  categories                      |    Keywords:            
     Author:  Robert Bradshaw                 |    Upstream:  N/A       
   Reviewer:  Nicolas M. Thiéry, Mike Hansen  |      Merged:            
Work_issues:                                  |  
----------------------------------------------+-----------------------------

Comment(by SimonKing):

 Perhaps it is a conversion map that is slower than necessary?

 If you look at
 `sage.categories.algebras.Algebras.ParentMethods.__init_extra__`, you see
 that it tries to register a certain set morphism as a coercion from the
 base ring into the algebra (that obviously works only if the algebra is
 unital).

 But aparently a different coercion is used -- a slower coercion!

 Namely, together with my patch from #9138:
 {{{
 sage: R.<x> = ZZ[]
 sage: R.category() # the __init_extra__ was supposed to be used.
 Join of Category of unique factorization domains and Category of
 commutative algebras over Integer Ring
 sage: c = R.convert_map_from(R.base_ring())
 sage: c
 Polynomial base injection morphism:
   From: Integer Ring
   To:   Univariate Polynomial Ring in x over Integer Ring
 }}}

 That is not what `__init_extra__` attempted to register!

 Let us compare:
 {{{
 sage: from sage.categories.morphism import SetMorphism
 sage: H = R.base().Hom(R)
 sage: f = SetMorphism(H,R.from_base_ring)
 sage: timeit('c(100)',number=10^5)
 100000 loops, best of 3: 8.13 µs per loop
 sage: timeit('f(100)',number=10^5)
 100000 loops, best of 3: 1.75 µs per loop
 }}}

 So, things could be considerably improved. Obvious questions: Will
 `from_base` always yield a faster approach than the base injection
 morphism? And can we enforce to use the faster coercion?

 Aparently it is not so easy:
 {{{
 sage: AC = Algebras(ZZ).parent_class
 sage: R._unset_coercions_used()
 sage: AC.__init_extra__(R)
 sage: R.convert_map_from(R.base_ring())
 Polynomial base injection morphism:
   From: Integer Ring
   To:   Univariate Polynomial Ring in x over Integer Ring
 sage: R._unset_coercions_used()
 sage: f.register_as_coercion()
 sage: R.convert_map_from(R.base_ring())
 Polynomial base injection morphism:
   From: Integer Ring
   To:   Univariate Polynomial Ring in x over Integer Ring
 }}}

 Can you explain how to force the use of a particular map for coercion of
 the base ring?

-- 
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/9944#comment:19>
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