The fibonacciSequence example was really helpful.  I made a new class
PowerSeries, a subclass of Generator.  Then I defined a binary operation  +
as follows:

+ aPowerSeries
  ^ PowerSeries on: [ :ps |
    | a b |
    [ a := self next.
      b := aPowerSeries next.
      ps yield: (a + b) ]
    repeat ]

This works perfectly.  But now I am struggling with how to define
multiplication.  When I do PS1 * PS2, the first yield should be a := PS1
next. b := PS2 next. ps yield (a * b).  Thereafter would come the
PowerSeries, call it PSNew,  (PS2 .* a) + (PS1 * PS2'),  where .* is scalar
multiplication (easy to implement) and PS2' is the original PS2 (i.e.,
rewound 1).  I see several problems here.  It looks like I need a way to
clone (fork?) a PowerSeries since in this computation I need both the
current PS2 and the original PS2 and be able to operate with them
independently.  Second, how do I define the generator so that it first
yields the scalar (a*b) and thereafter is represented by the PowerSeries
PSNew?  Finally, will the recursion in the definition of * blow up rapidly? 



--
View this message in context: 
http://forum.world.st/Is-lazy-evaluation-of-infinite-series-possible-tp4897956p4898204.html
Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.

Reply via email to