I need to generalize the SeriesData
object for my own purposes. One of the things I need to do is to reimplement code to multiply product of series.
I've made two attempts at this, and both of them are slower than the built-in SeriesData
. Is there an algorithm that has better Timing
than mine?
(*Two of my implementations*)
multSerList1[lists__] :=
Array[Plus @@ Times @@@ (MapThread[Part, {{lists}, #}, 1] & /@
Flatten[Permutations /@ IntegerPartitions[#, {3}], 1]) &, Min[Length /@ {lists}], Length[{lists}]];
multSerList2[listFirst_, listRest__] :=
Fold[Function[{a1, a2}, Array[Inner[Times, Take[a1, #], Reverse[Take[a2, #]], Plus] &, Min[Length /@
{listFirst, listRest}]]], listFirst, {listRest}];
To test this, I try to multiply the following three series together:
realExampleList = {
List @@ Normal[Series[Exp[y x], {x, 0, 4}]],
List @@ Normal[Series[Log[1 + c x], {x, 0, 5}]],
List @@ Normal[Series[PolyLog[2, -n x], {x, 0, 3}]]}
Then multSerList1@@realExampleList
or multSerList2@@ realExampleList
both yield
I can apply AbsoluteTiming
to time my code. It takes 0.0002 s for first one and 0.0001 s for the second one on my machine. But Multiplying the SeriesData
(need to remove the Normal
and List
)
realExampleListSerData = {
Series[Exp[y x], {x, 0, 4}],
Series[Log[1 + c x], {x, 0, 5}],
Series[PolyLog[2, -n x], {x, 0, 3}]};
By simply doing Times@@realExampleListSerData
, it gets the answer in 0.00002 s, which is five times faster.
I need help implementing the multiplication of series that performs approximately as well as the SeriesData
.
Thanks!
SeriesData
object? That way, you can simply use the multiplication implemented forSeriesData
when implementing the multiplication of your wrapper, with negligible overhead $\endgroup$ListConvolve
. $\endgroup$SeriesData
. $\endgroup$ListConvolve
. Can you provide a short example of how I can use it? $\endgroup$