Seeking More Advice on Library
David Roundy
droundy@abridgegame.org
Wed, 7 May 2003 16:35:30 -0400
On Wed, May 07, 2003 at 11:34:28AM -0400, Matthew Donadio wrote:
> Hi all,
>
> One of the needs for a few of my DSP routines is support for functions
> over polynomials. The attached file is what I threw together.
>
> Since this definetly has a broader scope than just me, I wanted to get
> some opionions on it.
>
> 1. The module is pretty type-free right now. I wanted to get some
> opionions on the best type for polynomials and names for the type and
> constructor(s).
>
> The big question here (in my mind) is how to represent polynomials. The
> most obvious way is as a list of the coefficients. They can also be
> represented as a list of the roots. Should there be a single type with
> two constructors or two types each with one constructor.
You can only represent a polynomial as a list of roots if the roots are
complex, and it looks like you don't require a to be complex, so I think
you are limited to representing them as a list of coefficients (which seems
best to me anyways).
I would use a single constructor and just provide a function to create a
polynomial from a list of roots. Of course, you can also define a
polynomial by a list of (x,y) pairs, which would be convenient for
interpolation (with the list of roots being a special case).
> 2. Are there any functions that are missing? I have a root finder in a
> different module (the one from Numeric Quest; Laguerre's method), but I
> am going to rewrite it in terms of the module that I attached.
> Functions for inflation and deflation by a single root will need to be
> added.
I'm not sure what it would be called, but it would be nice to be able to
rescale x:
P'(x) = P(s*x)
> 3. Should I add infix operators? I'm not sure what to do about this
> because of namespace clutter.
Is there any reason polynomials can't be of Class Num? I can't think of
any, and that would seem like an ideal solution to the issue of namespace
clutter. (and yes, infix operators are cool)
> Any other thoughts?
How about defining a few common functions as polynomials? I'm not sure
what this would be used for, but it sounds fun, and might be useful for
something. e.g. something like
polyexp = map inverse factorials
polycos = skipaltsign True $ map inverse factorials
where skipaltsign True (x:_:xs) = x : skipaltsign False xs
skipaltsign False (x:_:xs) = -x : skipaltsign True xs
--
David Roundy
http://civet.berkeley.edu/droundy/