http://rosie.projects.telrock.org ]]>

Good catch!

]]>The definition for “sub” 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 “sub x = add x . map (\(M c k) -> M (negate c) k)”. But if you do that, you might as well replace make “mergeBy” be the addition function, using the “+” operator instead of the merging function parameter.

]]>Well, it’s been a little over a year now since I’ve made this observation, and I still haven’t taken a serious effort at figuring out why. On the other hand, this problem shouldn’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’t promise to dig into it anytime soon.

I am curious though, if you’ve ever heard of or experimented with Haskell. :-)

]]>Yeah it is an older version. I have a newer (and in my opinion much better) version if you would like.

]]>Paul Vrbik and Michael Monagan. Lazy and Forgetful Polynomial Arithmetic and Applications. (Older version?)

I’m not going to have the chance to look at this carefully for a couple of weeks, and it looks like it’s going to take some effort in determining the exact relationship here, due to the usage of C to express the algorithms.

]]>Hmm… Generatingfunctionology is a good book, but my recollection was wrong. It doesn’t have the introduction to using polynomial arithmetic to count things. I’m not sure of the location of an internet resource that contains a good introduction to what I’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’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 *hopelessly* inefficient, but it decidedly not good.

Nothing to forgive, in my opinion. :-) If you find this interesting, by all means, keep working at it!

Using `pmul`

might be somewhat inefficient, but it should still be much faster than many of the more “obvious” alternatives for solving that particular counting problem. Of course, `pmul2`

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’s covered in many books on Combinatorics, such as my copy of Brualdi (I have a much older edition.)

Take a look at the first chapter or two of Generatingfunctionology. It’s a good book and available free of charge; I definitely recommend it.

]]>