Has anyone implemented or knows of an implementation of arithmetic
operations on multivariate polynomials in Haskell? I would prefer a
solution that uses type classes in an essential way to overload + and
*, so that I can freely add and multiply polynomials in *different*
variables. For example, it should be possible to write (the equivalent
of)
(X + 2*Y) + Z^3
I'm *not* looking for the obvious solution:
============================================================
class Ring a where
+, * :: a -> a -> a
negate :: a -> a
data Poly r = Null | Poly r (Poly r) -- least coeff first
instance Ring a => Ring (Poly a) where
Null + p = p
p + Null = p
Poly c1 p1 + Poly c2 p2 = Poly (c1 + c2) (p1 + p2)
-- etc
============================================================
Here (+) requires that both arguments have the same type. If
X is represented by Poly 0 (Poly 1 Null) :: Poly Int
and 2*Y by Poly (Poly 0 (Poly 2 Null)) Null :: Poly (Poly Int)
then they cannot be added.
I'd appreciate any references.
Regards
Peter Thiemann
Peter Thiemann, Wilhelm-Schickard-Institut, | Phone: x49 7071 2975467
Sand 13, D-72076 Tuebingen, Germany | Fax: x49 7071 29 5958
Email: [EMAIL PROTECTED] |