[Haskell-cafe] Memoization of functions

briand at aracnet.com briand at aracnet.com
Wed Sep 7 04:28:19 CEST 2011

On Tue, 06 Sep 2011 15:16:09 -0400
Michael Orlitzky <michael at orlitzky.com> wrote:

> I'm working on a program where I need to compute a gajillion (171442176)
> polynomials and evaluate them more than once. This is the definition of
> the polynomial, and it is expensive to compute:
> > polynomial :: Tetrahedron -> (RealFunction Point)
> > polynomial t =
> >     sum [ (c t i j k l) `cmult` (beta t i j k l) | i <- [0..3],
> >                                                    j <- [0..3],
> >                                                    k <- [0..3],
> >                                                    l <- [0..3],
> >                                                    i + j + k + l == 3]
> Currently, I'm storing the polynomials in an array, which is quickly
> devoured by the OOM killer. This makes me wonder: how much memory can I
> expect to use storing a function in an array? Is it possible to save
> some space through strictness? Does that question even make sense?

it's not clear what the relation to your final result is, e.g. can you can computer partial values and then store them ?  or are you having to calculate all 171442176 values and then do further computation with those values ?

if you need to store the results of the polynomials and then use them for further computation, well then it would seem that you're out of luck.

unboxing is likely to be your best friend.

in the event that unboxed arrays would help, I highly recommend repa.


More information about the Haskell-Cafe mailing list