Re: Is lazy evaluation of infinite series possible?
Posted by
HilaireFernandes on
May 31, 2016; 12:25pm
URL: https://forum.world.st/Is-lazy-evaluation-of-infinite-series-possible-tp4897956p4898347.html
Multiplication of power series looks tricky as for the term k of the
resulting power series you need to access terms where sum index value to
k. (ps1 next: i) and (ps2 next: k - i). Somehow the bloc of code
defining the multiplicated serie needs to know about its current rank k.
You should not need a dedicated .* operator, you can handle it with only
* operator with appropriate object testing.
No real answer
Le 30/05/2016 21:47, Erisa a écrit :
> 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?
--
Dr. Geo
http://drgeo.eu