I am trying to create a function which takes in two streams of coefficients and will multiply them. For example, the series 1+2x+3x^2 is represented as (1,2,3). If I had the two series 1+2x+3x^2 and 2+6x+9x^2, the output of this function will be 2+10x+27x^2+36x^3+27x^4 or (2,10,27,36,27,...).
My addSeries function goes like this:
function addSeries(s,t){
if(s.toString() === "sempty" && t.toString() === "sempty"){
return sempty;
}
else if(s.toString() === "sempty"){
return snode(t.head(), memo0(() => addSeries(t.tail(),s)));
}
else if(t.toString() === "sempty"){
return snode(s.head(), memo0(() => addSeries(s.tail(),t)));
}
return snode(s.head() + t.head(), memo0(() => addSeries(s.tail(),t.tail())));
}
How can I use this same principle to multiply two streams?