[Haskell-beginners] simplifying algebraic expression

Jürgen Doser jurgen.doser at gmail.com
Wed Sep 1 07:31:20 EDT 2010


El mié, 01-09-2010 a las 16:36 +0600, Alexander.Vladislav.Popov
escribió:
> It has given me an infinite loop and out-of-memory exception. I tried
> different variations but not found the valid one and don't know what
> to do next.

you have to reduce the inner expressions recursively, then pattern-match
on those results to simplify:

rdc (Add a b) = case (rdc a, rdc b) of
			(Const 0, x) -> x
			(x, Const 0) -> x
			...

You can now be sure that whatever you pattern-match on is already a
fully simplified algebraic expression (i.e., a sum of rational powers of
x with rational coefficients). This should make it easier to think about
the necessary cases you have to handle.

Btw., is there a particular reason why you did not try to write the
recursion explicitely, but used the function s?

	Jürgen



More information about the Beginners mailing list