Hi Erisa,
one solution, using your notation, could eg be
* aPowerSeries
^ PowerSeries on:
[ :generator |
|a b|
a:=OrderedCollection new.
b:=OrderedCollection new.
[ a add: self next.
b add: aPowerSeries next.
generator yield:
a asDhbVector * b asDhbVector reverse
] repeat
]
the multiplication of DhbVectors is the same as your ".*". DhbVector is
not in the standard pharo, it is part of the polymath project, i was
just too lazy to program that part by hand, but changing that should be
no problem.
werner
On 05/30/2016 09:47 PM, Erisa wrote:
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.