[Haskell-beginners] Simplify (normalize) symbolic polynom-like expression

Daniel Hlynskyi abcz2.uprola at gmail.com
Sun Jun 17 10:30:37 CEST 2012


Thanks, that worked!

> Note that this isn't quite the right way to represent a poly if you
want to get to a canonical representation.

Can you expand a bit more on this? It is not classic poly, but
combination of symbolic vars,sums,products and exponentiation
operations (in fact, auto-random-generated)

2012/6/17 Chaddaï Fouché <chaddai.fouche at gmail.com>:
> On Sun, Jun 17, 2012 at 9:36 AM, Chaddaï Fouché
> <chaddai.fouche at gmail.com> wrote:
>> normalize (Sum xs) = case sort . filter (/= I 0) . map normalize $ xs of
>>  [] -> I 0
>>  [a] -> a
>>  ys -> sumPrefix ys
>>    where
>>      sumPrefix (I n : I m : ys) = sumPrefix $ I (n+m) : ys
>>      sumPrefix ys = ys
>
> Sorry I did this a bit too fast...
>
>> normalize (Sum xs) = case sumPrefix . sort . filter (/= I 0) . map normalize $ xs of
>>  [] -> I 0
>>  [a] -> a
>>  ys -> Sum ys



More information about the Beginners mailing list