<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: Polynomial multiplication</title>
	<atom:link href="http://blog.melding-monads.com/2009/04/07/polynomial-multiplication/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.melding-monads.com/2009/04/07/polynomial-multiplication/</link>
	<description>Math, Computer Science,  and Education</description>
	<lastBuildDate>Wed, 08 May 2013 14:59:04 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
	<item>
		<title>By: lpsmith</title>
		<link>http://blog.melding-monads.com/2009/04/07/polynomial-multiplication/#comment-271</link>
		<dc:creator><![CDATA[lpsmith]]></dc:creator>
		<pubDate>Sat, 04 Aug 2012 13:25:48 +0000</pubDate>
		<guid isPermaLink="false">http://blog.melding-monads.com/?p=43#comment-271</guid>
		<description><![CDATA[Good catch!]]></description>
		<content:encoded><![CDATA[<p>Good catch!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jon Shapcott</title>
		<link>http://blog.melding-monads.com/2009/04/07/polynomial-multiplication/#comment-270</link>
		<dc:creator><![CDATA[Jon Shapcott]]></dc:creator>
		<pubDate>Sat, 04 Aug 2012 02:48:02 +0000</pubDate>
		<guid isPermaLink="false">http://blog.melding-monads.com/?p=43#comment-270</guid>
		<description><![CDATA[This post is a bit old now, but here goes anyway...

The definition for &quot;sub&quot; does not work. The coefficients in the monomials left over at the end of the recursion, and those in the LT and GT branches need to be negated in order to get polynomial subtraction.

You can define sub properly with &quot;sub x = add x . map (\(M c k) -&gt; M (negate c) k)&quot;. But if you do that, you might as well replace make &quot;mergeBy&quot;  be the addition function, using the &quot;+&quot; operator instead of the merging function parameter.]]></description>
		<content:encoded><![CDATA[<p>This post is a bit old now, but here goes anyway&#8230;</p>
<p>The definition for &#8220;sub&#8221; does not work. The coefficients in the monomials left over at the end of the recursion, and those in the LT and GT branches need to be negated in order to get polynomial subtraction.</p>
<p>You can define sub properly with &#8220;sub x = add x . map (\(M c k) -&gt; M (negate c) k)&#8221;. But if you do that, you might as well replace make &#8220;mergeBy&#8221;  be the addition function, using the &#8220;+&#8221; operator instead of the merging function parameter.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: lpsmith</title>
		<link>http://blog.melding-monads.com/2009/04/07/polynomial-multiplication/#comment-60</link>
		<dc:creator><![CDATA[lpsmith]]></dc:creator>
		<pubDate>Tue, 19 Jan 2010 12:57:26 +0000</pubDate>
		<guid isPermaLink="false">http://blog.melding-monads.com/?p=43#comment-60</guid>
		<description><![CDATA[Well,  it&#039;s been a little over a year now since I&#039;ve made this observation,  and I still haven&#039;t taken a serious effort at figuring out why.    On the other hand,  this problem shouldn&#039;t be that difficult,  and your paper might be useful if/when I do.   So by all means,  send me a link or a copy,  though I won&#039;t promise to dig into it anytime soon.

I am curious though,  if you&#039;ve ever heard of or experimented with Haskell.  :-)]]></description>
		<content:encoded><![CDATA[<p>Well,  it&#8217;s been a little over a year now since I&#8217;ve made this observation,  and I still haven&#8217;t taken a serious effort at figuring out why.    On the other hand,  this problem shouldn&#8217;t be that difficult,  and your paper might be useful if/when I do.   So by all means,  send me a link or a copy,  though I won&#8217;t promise to dig into it anytime soon.</p>
<p>I am curious though,  if you&#8217;ve ever heard of or experimented with Haskell.  :-)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Paul Vrbik</title>
		<link>http://blog.melding-monads.com/2009/04/07/polynomial-multiplication/#comment-32</link>
		<dc:creator><![CDATA[Paul Vrbik]]></dc:creator>
		<pubDate>Sun, 05 Jul 2009 04:48:45 +0000</pubDate>
		<guid isPermaLink="false">http://blog.melding-monads.com/?p=43#comment-32</guid>
		<description><![CDATA[Yeah it is an older version. I have a newer (and in my opinion much better) version if you would like.]]></description>
		<content:encoded><![CDATA[<p>Yeah it is an older version. I have a newer (and in my opinion much better) version if you would like.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: lpsmith</title>
		<link>http://blog.melding-monads.com/2009/04/07/polynomial-multiplication/#comment-22</link>
		<dc:creator><![CDATA[lpsmith]]></dc:creator>
		<pubDate>Mon, 04 May 2009 01:21:06 +0000</pubDate>
		<guid isPermaLink="false">http://blog.melding-monads.com/?p=43#comment-22</guid>
		<description><![CDATA[Ran across this paper today,  it looks like it&#039;s rather applicable:

Paul Vrbik and Michael Monagan. &lt;a href=&quot;http://www.cecm.sfu.ca/~mmonagan/papers/delayedMul.pdf&quot; rel=&quot;nofollow&quot;&gt;Lazy and Forgetful Polynomial Arithmetic and Applications.&lt;/a&gt;   (&lt;a href=&quot;http://www.cecm.sfu.ca/CAG/papers/vrbikLazy.pdf&quot; rel=&quot;nofollow&quot;&gt;Older version?&lt;/a&gt;)

I&#039;m not going to have the chance to look at this carefully for a couple of weeks,  and it looks like it&#039;s going to take some effort in determining the exact relationship here,  due to the usage of C to express the algorithms.]]></description>
		<content:encoded><![CDATA[<p>Ran across this paper today,  it looks like it&#8217;s rather applicable:</p>
<p>Paul Vrbik and Michael Monagan. <a href="http://www.cecm.sfu.ca/~mmonagan/papers/delayedMul.pdf" rel="nofollow">Lazy and Forgetful Polynomial Arithmetic and Applications.</a>   (<a href="http://www.cecm.sfu.ca/CAG/papers/vrbikLazy.pdf" rel="nofollow">Older version?</a>)</p>
<p>I&#8217;m not going to have the chance to look at this carefully for a couple of weeks,  and it looks like it&#8217;s going to take some effort in determining the exact relationship here,  due to the usage of C to express the algorithms.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: lpsmith</title>
		<link>http://blog.melding-monads.com/2009/04/07/polynomial-multiplication/#comment-15</link>
		<dc:creator><![CDATA[lpsmith]]></dc:creator>
		<pubDate>Thu, 23 Apr 2009 07:28:38 +0000</pubDate>
		<guid isPermaLink="false">http://blog.melding-monads.com/?p=43#comment-15</guid>
		<description><![CDATA[Hmm... Generatingfunctionology is a good book,  but my recollection was wrong.   It doesn&#039;t have the introduction to using polynomial arithmetic to count things.  I&#039;m not sure of the location of an internet resource that contains a good introduction to what I&#039;m trying to get at.  

This technique is often a good choice because it easily generalizes to problem instances that are tricky to handle with simple applications of the multiplication rule and the principle of inclusion and exclusion,  and it&#039;s efficient because it has a high degree of memoization built in. 

I was being a bit hyperbolic in saying that the first solution is &lt;i&gt;hopelessly&lt;/i&gt; inefficient,  but it decidedly not good.]]></description>
		<content:encoded><![CDATA[<p>Hmm&#8230; Generatingfunctionology is a good book,  but my recollection was wrong.   It doesn&#8217;t have the introduction to using polynomial arithmetic to count things.  I&#8217;m not sure of the location of an internet resource that contains a good introduction to what I&#8217;m trying to get at.  </p>
<p>This technique is often a good choice because it easily generalizes to problem instances that are tricky to handle with simple applications of the multiplication rule and the principle of inclusion and exclusion,  and it&#8217;s efficient because it has a high degree of memoization built in. </p>
<p>I was being a bit hyperbolic in saying that the first solution is <i>hopelessly</i> inefficient,  but it decidedly not good.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: lpsmith</title>
		<link>http://blog.melding-monads.com/2009/04/07/polynomial-multiplication/#comment-14</link>
		<dc:creator><![CDATA[lpsmith]]></dc:creator>
		<pubDate>Thu, 23 Apr 2009 05:16:45 +0000</pubDate>
		<guid isPermaLink="false">http://blog.melding-monads.com/?p=43#comment-14</guid>
		<description><![CDATA[Nothing to forgive,  in my opinion.  :-)   If you find this interesting,  by all means,  keep working at it!

Using &lt;code&gt;pmul&lt;/code&gt; might be somewhat inefficient,  but it should still be much faster than many of the more &quot;obvious&quot; alternatives for solving that particular counting problem.   Of course,  &lt;code&gt;pmul2&lt;/code&gt; is a drop-in replacement,  and is definitely the way to go.

But of course, to the trained mind,  this solution is perfectly obvious.  It&#039;s covered in many books on Combinatorics,  such as my copy of &lt;a href=&quot;http://www.amazon.com/Introductory-Combinatorics-5th-Richard-Brualdi/dp/0136020402/ref=sr_1_1?ie=UTF8&amp;s=books&amp;qid=1240463693&amp;sr=1-1&quot; rel=&quot;nofollow&quot;&gt;Brualdi&lt;/a&gt; (I have a much older edition.)

Take a look at the first chapter or two of &lt;a href=&quot;http://www.math.upenn.edu/~wilf/DownldGF.html&quot; rel=&quot;nofollow&quot;&gt;Generatingfunctionology&lt;/a&gt;.  It&#039;s a good book and available free of charge;  I definitely recommend it.]]></description>
		<content:encoded><![CDATA[<p>Nothing to forgive,  in my opinion.  :-)   If you find this interesting,  by all means,  keep working at it!</p>
<p>Using <code>pmul</code> might be somewhat inefficient,  but it should still be much faster than many of the more &#8220;obvious&#8221; alternatives for solving that particular counting problem.   Of course,  <code>pmul2</code> is a drop-in replacement,  and is definitely the way to go.</p>
<p>But of course, to the trained mind,  this solution is perfectly obvious.  It&#8217;s covered in many books on Combinatorics,  such as my copy of <a href="http://www.amazon.com/Introductory-Combinatorics-5th-Richard-Brualdi/dp/0136020402/ref=sr_1_1?ie=UTF8&amp;s=books&amp;qid=1240463693&amp;sr=1-1" rel="nofollow">Brualdi</a> (I have a much older edition.)</p>
<p>Take a look at the first chapter or two of <a href="http://www.math.upenn.edu/~wilf/DownldGF.html" rel="nofollow">Generatingfunctionology</a>.  It&#8217;s a good book and available free of charge;  I definitely recommend it.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kyle Lahnakoski</title>
		<link>http://blog.melding-monads.com/2009/04/07/polynomial-multiplication/#comment-12</link>
		<dc:creator><![CDATA[Kyle Lahnakoski]]></dc:creator>
		<pubDate>Wed, 22 Apr 2009 23:58:22 +0000</pubDate>
		<guid isPermaLink="false">http://blog.melding-monads.com/?p=43#comment-12</guid>
		<description><![CDATA[Yes, I was wrong: I had forgotten that add() also has a recursive definition.  

I tried to apply your definitions with hope that the inefficiency of pmul would be apparent.  Here is what I got before I gave up.  

pmul (x1x2...xn) (y1y2y3...yn) = 
___cat 
______(mmul x1 y1) 
______(cat
_________(mmul x2 y1) 
_________(add 
____________(cat
_______________(mmul x1 y2)
_______________(map (mmul x1) (y3y4...yn))
____________) 
____________(add 
_______________(cat
__________________(mmul x2 y2)
__________________(map (mmul x2) (y3y4...yn))
_______________) 
_______________(cat 
__________________(mmul x3 y1) 
__________________(add 
_____________________(smul x3 (y2y3...yn)) 
_____________________(pmul (x4x5...xn) (y1y2y3...yn))
__________________)
_______________)
____________)
_________)
______)

I had to assume (once) the add() function expanded using the LT case, just to save myself from three of these things.  Also I used “cat” for concatenation; it was easier to indent without infix operators.    I must conclude Haskell has an expansion/reduction debugger because it is too laborious to do much more by hand.

It could be that the more complex pattern matching required in pmul is causing the slowdown.  But all this is speculation now.  And my comments are no better than Jade NB, who saw the equi-speed consumption of both lists may be the factor.  Assuming Haskell is pattern matching, I must say, this is the most inefficient polynomial multiplier I have ever seen. :)

PS, I do not know what your point was with your solution to “how many ways you can add together 2, 3, and 5 to get say, 1000”.  It seems to me you have found another inefficient way to frame a solution.   And, combined with the most inefficient polynomial multiplier I have ever seen, you have probably made a measurable contribution to the heat-death of the universe.  :)

Please forgive my bad joke.]]></description>
		<content:encoded><![CDATA[<p>Yes, I was wrong: I had forgotten that add() also has a recursive definition.  </p>
<p>I tried to apply your definitions with hope that the inefficiency of pmul would be apparent.  Here is what I got before I gave up.  </p>
<p>pmul (x1x2&#8230;xn) (y1y2y3&#8230;yn) =<br />
___cat<br />
______(mmul x1 y1)<br />
______(cat<br />
_________(mmul x2 y1)<br />
_________(add<br />
____________(cat<br />
_______________(mmul x1 y2)<br />
_______________(map (mmul x1) (y3y4&#8230;yn))<br />
____________)<br />
____________(add<br />
_______________(cat<br />
__________________(mmul x2 y2)<br />
__________________(map (mmul x2) (y3y4&#8230;yn))<br />
_______________)<br />
_______________(cat<br />
__________________(mmul x3 y1)<br />
__________________(add<br />
_____________________(smul x3 (y2y3&#8230;yn))<br />
_____________________(pmul (x4x5&#8230;xn) (y1y2y3&#8230;yn))<br />
__________________)<br />
_______________)<br />
____________)<br />
_________)<br />
______)</p>
<p>I had to assume (once) the add() function expanded using the LT case, just to save myself from three of these things.  Also I used “cat” for concatenation; it was easier to indent without infix operators.    I must conclude Haskell has an expansion/reduction debugger because it is too laborious to do much more by hand.</p>
<p>It could be that the more complex pattern matching required in pmul is causing the slowdown.  But all this is speculation now.  And my comments are no better than Jade NB, who saw the equi-speed consumption of both lists may be the factor.  Assuming Haskell is pattern matching, I must say, this is the most inefficient polynomial multiplier I have ever seen. :)</p>
<p>PS, I do not know what your point was with your solution to “how many ways you can add together 2, 3, and 5 to get say, 1000”.  It seems to me you have found another inefficient way to frame a solution.   And, combined with the most inefficient polynomial multiplier I have ever seen, you have probably made a measurable contribution to the heat-death of the universe.  :)</p>
<p>Please forgive my bad joke.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: lpsmith</title>
		<link>http://blog.melding-monads.com/2009/04/07/polynomial-multiplication/#comment-11</link>
		<dc:creator><![CDATA[lpsmith]]></dc:creator>
		<pubDate>Wed, 22 Apr 2009 18:21:05 +0000</pubDate>
		<guid isPermaLink="false">http://blog.melding-monads.com/?p=43#comment-11</guid>
		<description><![CDATA[&lt;blockquote&gt;In pmul, (y:ys) is passed down the recursive chain until it is multiplied with []. This means (x:xs) must be completely expanded just to get the second term in the resulting polynomial.&lt;/blockquote&gt;

It sounds like you are onto  something,  but you are going to have to clarify.   This part of your reply,  at least,  is wrong.    

The base cases are completely optional,  so long as both polynomials being multiplied are infinite.   So in a sense, these are &quot;optionally corecursive&quot; functions.

For example,  if you want to find out how many ways you can add together 2, 3, and 5 to get say,  1000,  then all you have to do is look at the coefficient of the 1000th power of:

&lt;pre&gt;(pstep 2 `pmul` pstep 3) `pmul` pstep 5&lt;/pre&gt;

where &lt;code&gt;pstep n&lt;/code&gt; represents the polynomial

$latex \displaystyle\sum_{i=0}^{\infty} x^{i n}$]]></description>
		<content:encoded><![CDATA[<blockquote><p>In pmul, (y:ys) is passed down the recursive chain until it is multiplied with []. This means (x:xs) must be completely expanded just to get the second term in the resulting polynomial.</p></blockquote>
<p>It sounds like you are onto  something,  but you are going to have to clarify.   This part of your reply,  at least,  is wrong.    </p>
<p>The base cases are completely optional,  so long as both polynomials being multiplied are infinite.   So in a sense, these are &#8220;optionally corecursive&#8221; functions.</p>
<p>For example,  if you want to find out how many ways you can add together 2, 3, and 5 to get say,  1000,  then all you have to do is look at the coefficient of the 1000th power of:</p>
<pre>(pstep 2 `pmul` pstep 3) `pmul` pstep 5</pre>
<p>where <code>pstep n</code> represents the polynomial</p>
<p><img src='http://s0.wp.com/latex.php?latex=%5Cdisplaystyle%5Csum_%7Bi%3D0%7D%5E%7B%5Cinfty%7D+x%5E%7Bi+n%7D&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='&#92;displaystyle&#92;sum_{i=0}^{&#92;infty} x^{i n}' title='&#92;displaystyle&#92;sum_{i=0}^{&#92;infty} x^{i n}' class='latex' /></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kyle Lahnakoski</title>
		<link>http://blog.melding-monads.com/2009/04/07/polynomial-multiplication/#comment-10</link>
		<dc:creator><![CDATA[Kyle Lahnakoski]]></dc:creator>
		<pubDate>Wed, 22 Apr 2009 13:58:55 +0000</pubDate>
		<guid isPermaLink="false">http://blog.melding-monads.com/?p=43#comment-10</guid>
		<description><![CDATA[I am terrible at Haskell, but pretty good at math:

In pmul, (y:ys) is passed down the recursive chain until it is multiplied with [].  This means (x:xs) must be completely expanded just to get the second term in the resulting polynomial.  

On the other hand, pmul2 does an excellent job of swapping the polynomials: effectively performing the complete expansion in two steps:

(x + xs) * (y + ys) == x*y + x*ys + xs*y + xs*ys.

------------------------------

Looking at the expansion for pmul: There will be many (smul xi ys) for each xi in x, but pmul2 will use smul with decreasing augument size.  It seems the many-term smul and the resulting adds  (and sorting?) consume more resources in the former.]]></description>
		<content:encoded><![CDATA[<p>I am terrible at Haskell, but pretty good at math:</p>
<p>In pmul, (y:ys) is passed down the recursive chain until it is multiplied with [].  This means (x:xs) must be completely expanded just to get the second term in the resulting polynomial.  </p>
<p>On the other hand, pmul2 does an excellent job of swapping the polynomials: effectively performing the complete expansion in two steps:</p>
<p>(x + xs) * (y + ys) == x*y + x*ys + xs*y + xs*ys.</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
<p>Looking at the expansion for pmul: There will be many (smul xi ys) for each xi in x, but pmul2 will use smul with decreasing augument size.  It seems the many-term smul and the resulting adds  (and sorting?) consume more resources in the former.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
