#16137: lazy_list from various input data
-------------------------------------+-------------------------------------
       Reporter:  MatthieuDien       |        Owner:
           Type:  enhancement        |       Status:  needs_review
       Priority:  major              |    Milestone:  sage-7.0
      Component:  misc               |   Resolution:
       Keywords:  LazyPowerSeries,   |    Merged in:
  lazy_list, days57                  |    Reviewers:  Daniel Krenn
        Authors:  Matthieu Dien,     |  Work issues:
  Vincent Delecroix, Daniel Krenn    |       Commit:
Report Upstream:  N/A                |  72a212c34c0f2a172b9d7ac95d11f24d254a86c3
         Branch:  u/dkrenn/16137     |     Stopgaps:
   Dependencies:                     |
-------------------------------------+-------------------------------------

Comment (by vdelecroix):

 It is perfectly fine to use `lazy_list` recursively. With your example one
 option is
 {{{
 from sage.data_structures.lazy_list import lazy_list_generic
 class MySerie(lazy_list_generic):
     def __init__(self):
         lazy_list_generic.__init__(self, cache=[1])
         self._n = 0
     def _new_slice(self):
         n = self._n
         self._n += 1
         return [sum(self.get(i) * self.get(n-i) for i in range(n+1))]
 }}}
 then
 {{{
 sage: f = MySerie()
 sage: f[0]
 1
 sage: f[1]
 1
 sage: f[2]
 2
 sage: f[3]
 5
 sage: f[4]
 14
 sage: f[5]
 42
 }}}

--
Ticket URL: <http://trac.sagemath.org/ticket/16137#comment:100>
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 unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sage-trac.
For more options, visit https://groups.google.com/d/optout.

Reply via email to