#10496: The default call method of maps does not do as promised by the
documentation
--------------------------+-------------------------------------------------
   Reporter:  SimonKing   |       Owner:  robertwb        
       Type:  defect      |      Status:  needs_review    
   Priority:  major       |   Milestone:  sage-4.6.2      
  Component:  coercion    |    Keywords:  generic call map
     Author:  Simon King  |    Upstream:  N/A             
   Reviewer:  David Roe   |      Merged:                  
Work_issues:              |  
--------------------------+-------------------------------------------------
Changes (by SimonKing):

  * status:  needs_work => needs_review


Comment:

 I updated my patch. Here are some timings for different situations.

 With the patch:
 {{{
 sage: R.<x,y> = QQ[]; phi=R.hom([y,x])
 # Element in domain
 sage: timeit("a=phi(y)")
 625 loops, best of 3: 32.3 µs per loop
 # Element coerces into domain
 sage: timeit("a=phi(5)")
 625 loops, best of 3: 51.3 µs per loop
 # non-Element that converts into domain
 sage: D={(0, 2): -1, (0, 0): -1, (1, 1): 7, (2, 0): 1/3}
 sage: phi(D)
 -x^2 + 7*x*y + 1/3*y^2 - 1
 sage: timeit("a=phi(D)")
 625 loops, best of 3: 119 µs per loop
 # use pushforward
 sage: I = R*[x^2*y^4-2*y^2, 3*x*y-y^3]
 sage: phi(I)
 Ideal (x^4*y^2 - 2*x^2, -x^3 + 3*x*y) of Multivariate Polynomial Ring in
 x, y over Rational Field
 sage: timeit("a=phi(I)")
 625 loops, best of 3: 164 µs per loop
 }}}

 The same examples without my patch:
 {{{
 sage: R.<x,y> = QQ[]; phi=R.hom([y,x])
 sage: timeit("a=phi(y)")
 625 loops, best of 3: 32.3 µs per loop
 sage: timeit("a=phi(5)")
 625 loops, best of 3: 37.1 µs per loop
 sage: D={(0, 2): -1, (0, 0): -1, (1, 1): 7, (2, 0): 1/3}
 sage: phi(D)
 ---------------------------------------------------------------------------
 AttributeError                            Traceback (most recent call
 last)

 /home/king/SAGE/work/modules/<ipython console> in <module>()

 /mnt/local/king/SAGE/sage-4.6/local/lib/python2.6/site-
 packages/sage/categories/map.so in sage.categories.map.Map.__call__
 (sage/categories/map.c:3145)()

 /mnt/local/king/SAGE/sage-4.6/local/lib/python2.6/site-
 packages/sage/rings/morphism.so in
 sage.rings.morphism.RingHomomorphism_im_gens._call_
 (sage/rings/morphism.c:5761)()

 AttributeError: 'dict' object has no attribute '_im_gens_'
 sage: I = R*[x^2*y^4-2*y^2, 3*x*y-y^3]
 sage: phi(I)
 Ideal (x^4*y^2 - 2*x^2, -x^3 + 3*x*y) of Multivariate Polynomial Ring in
 x, y over Rational Field
 sage: timeit("a=phi(I)")
 625 loops, best of 3: 492 µs per loop
 }}}

 Hence:

 * If the argument has the right parent, it is as quick as before.
 * If the argument coerces into the domain, it is slower. That is no
 surprise, because "not doing coercion" is certainly faster than "doing
 coercion", but "not doing coercion" is a bug IMO.
 * If the argument is not an element and is not dealt with by pushforward
 but converts into the domain, my patch fixes a bug (it is now added as
 doctest).
 * Calling pushforward works a lot quicker with my patch.

 So, I do think that overall it is a progress. I am now starting doctests,
 but I think it is ready for review again.

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