#7742: add a compose function to sage
------------------------------------------------+---------------------------
   Reporter:  was                               |       Owner:  AlexGhitza
       Type:  defect                            |      Status:  needs_work
   Priority:  major                             |   Milestone:  sage-4.6.1
  Component:  basic arithmetic                  |    Keywords:            
     Author:  Christopher Olah, Felix Lawrence  |    Upstream:  N/A       
   Reviewer:  Paul Zimmermann                   |      Merged:            
Work_issues:                                    |  
------------------------------------------------+---------------------------

Comment(by jrp):

 Replying to [comment:19 flawrence]:

 > With normal python functions (such as those in the doctest), the powers-
 of-two provides a major speedup for large n over the other techniques I
 tried, both for the function composition and for the evaluation of the
 resulting function (benchmarked using "timeit").  In fact, without a
 powers-of-two-type algorithm, the self_compose function regularly hit the
 recursion limit and crashed for large n (above 500 or 1000).

 I ran the following:
 {{{
 sage: def f(x):
 ....:     return x + 1
 ....:
 sage: g = self_compose(f,10000)
 sage: g
 <function <lambda> at 0xb0aa80c>
 sage: timeit('g(0)')
 25 loops, best of 3: 9.41 ms per loop
 sage: timeit('nest(f,10000,0)')
 125 loops, best of 3: 6.35 ms per loop
 }}}
 Since nest just loops through xrange and doesn't use powers of two, maybe
 the slowdown before was due to the recursion.  But in any case, it
 definitely helps with the symbolic ones.

 > The compose functions in the patch use lambda functions, which may or
 may not break symbolic functions.

 I'm attaching a patch to check for symbolic functions and (hopefully) do
 the right thing.  I also make self_compose(f,0) return the identity.

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