Re: [Haskell-cafe] Question about memory usage

2010-08-18 Thread Daniel Fischer
On Tuesday 17 August 2010 17:33:15, Sebastian Fischer wrote: > > BTW, what sort of memory usage are we talking about here? > ./calcfib 1 +RTS -s > 451,876,020 bytes allocated in the heap >10,376 bytes copied during GC >19,530,184 bytes maximum res

Re: [Haskell-cafe] Question about memory usage

2010-08-18 Thread John van Groningen
Sebastian Fischer wrote: >.. >Interesting. It uses the same amount of memory but is faster probably because >it allocates less. > >But I prefer programs for people to read over programs for computers to >execute and I have a hard time to verify that your algorithm computes According to:

Re: [Haskell-cafe] Question about memory usage

2010-08-18 Thread Sebastian Fischer
Hi John, You could try: [...] It allocates less and has a smaller maximum residency: (ghc 6.12.2,windows 7 64) 292,381,520 bytes allocated in the heap 13,020,308 bytes maximum residency (8 sample(s)) 99 MB total memory in use (9 MB lost due to fragmentation) MUT

Re: [Haskell-cafe] Question about memory usage

2010-08-18 Thread John van Groningen
Sebastian Fischer wrote: >>BTW, what sort of memory usage are we talking about here? > >I was referring to the memory usage of this program > >import System.Environment >import Data.Numbers.Fibonacci > >main :: IO () >main = do n <- (read . head) `fmap` getArgs > (fib

Re: [Haskell-cafe] Question about memory usage

2010-08-17 Thread Richard O'Keefe
On Aug 17, 2010, at 6:39 PM, Roel van Dijk wrote: >> Using x**n = exp(n*log(x)) and floating point arithmetic, >> the whole thing can be done in O(1) time, and the price of >> some inaccuracy. > It will calculate a subset of the Fibonacci numbers in O(1) time. > Thinking about it I think you can e

Re: [Haskell-cafe] Question about memory usage

2010-08-17 Thread Jacques Carette
Daniel Fischer wrote: On Aug 16, 2010, at 6:03 PM, Jacques Carette wrote: Any sequence of numbers given by a linear recurrence equation with constant coefficients can be computed quickly using asymptotically efficient matrix operations. In fact, the code to do this can be derived automatic

Re: [Haskell-cafe] Question about memory usage

2010-08-17 Thread Sebastian Fischer
BTW, what sort of memory usage are we talking about here? I was referring to the memory usage of this program import System.Environment import Data.Numbers.Fibonacci main :: IO () main = do n <- (read . head) `fmap` getArgs (fib n :: Integer) `seq` return () comp

Re: [Haskell-cafe] Question about memory usage

2010-08-17 Thread Daniel Fischer
On Tuesday 17 August 2010 08:59:29, Sebastian Fischer wrote: > > I wonder whether the numbers in a single step of the computation > occupy all the memory or whether old numbers are retained although > they shouldn't be. BTW, what sort of memory usage are we talking about here? I have now tried you

Re: [Haskell-cafe] Question about memory usage

2010-08-17 Thread Ivan Lazar Miljenovic
Sebastian Fischer writes: > On Aug 17, 2010, at 8:39 AM, Roel van Dijk wrote: > >> That is an interesting trick. So there exists an algorithm that >> calculates Fibonacci numbers in O(log n) time. > > This is what my program does. But it's only O(long n) [snip] Are you getting Haskell mixed up w

Re: [Haskell-cafe] Question about memory usage

2010-08-17 Thread Sebastian Fischer
On Aug 17, 2010, at 8:39 AM, Roel van Dijk wrote: That is an interesting trick. So there exists an algorithm that calculates Fibonacci numbers in O(log n) time. This is what my program does. But it's only O(long n) if you assume multiplication is constant time (which it is not for large num

Re: [Haskell-cafe] Question about memory usage

2010-08-16 Thread Sebastian Fischer
On Aug 17, 2010, at 12:33 AM, Jason Dagit wrote: So next I would use heap profiling to find out where and what type of data the calculation is using. I did. I would do heap profiling and look at the types. All retained data is of type ARR_WORDS. Retainer profiling shows that the majorit

Re: [Haskell-cafe] Question about memory usage

2010-08-16 Thread Roel van Dijk
On Tue, Aug 17, 2010 at 3:53 AM, Richard O'Keefe wrote: > On Aug 17, 2010, at 12:37 AM, Roel van Dijk wrote: >> >> phi = (1 + sqrt 5) / 2 >> fib n = ((phi ** n) - (1 - phi) ** n) / sqrt 5 >> >> The use of (**) should make the complexity at least O(n). Please >> correct me if I'm wrong (or sloppy).

Re: [Haskell-cafe] Question about memory usage

2010-08-16 Thread Richard O'Keefe
On Aug 17, 2010, at 12:37 AM, Roel van Dijk wrote: > > phi = (1 + sqrt 5) / 2 > fib n = ((phi ** n) - (1 - phi) ** n) / sqrt 5 > > The use of (**) should make the complexity at least O(n). Please > correct me if I'm wrong (or sloppy). Using the classic x**0 = 1 x**1 = x

Re: [Haskell-cafe] Question about memory usage

2010-08-16 Thread Daniel Peebles
There's a Fibonacci Heap: http://en.wikipedia.org/wiki/Fibonacci_heap Not sure what else though :) On Mon, Aug 16, 2010 at 11:14 PM, Antoine Latter wrote: > On Mon, Aug 16, 2010 at 1:37 PM, Andrew Coppin > wrote: > > > > This neatly leads us back to my second assertion: In all my years of > >

Re: [Haskell-cafe] Question about memory usage

2010-08-16 Thread Jason Dagit
On Mon, Aug 16, 2010 at 9:00 AM, Sebastian Fischer < s...@informatik.uni-kiel.de> wrote: > [CC-ing café again] > > > On Aug 16, 2010, at 5:52 PM, Daniel Fischer wrote: > > I am a bit concerned about the memory usage. >>> >> >> Of your implementation of the matrix power algorithm? >> > > Yes. > >

Re: [Haskell-cafe] Question about memory usage

2010-08-16 Thread Antoine Latter
On Mon, Aug 16, 2010 at 1:37 PM, Andrew Coppin wrote: > > This neatly leads us back to my second assertion: In all my years of > computer programming, I've never seen one single program that actually > *needs* the Fibonacci numbers in the first place (let alone in > arbitrary-precision). > I thin

Re: [Haskell-cafe] Question about memory usage

2010-08-16 Thread Andrew Coppin
Roel van Dijk wrote: On Sat, Aug 14, 2010 at 5:41 PM, Andrew Coppin wrote: (Then again, the Fibonacci numbers can be computed in O(1) time, and nobody ever needs Fibonacci numbers in the first place, so this is obviously example code.) A bit off-topic, but I don't think there exists

Re: [Haskell-cafe] Question about memory usage

2010-08-16 Thread Jacques Carette
Since we're off-topic... Any sequence of numbers given by a linear recurrence equation with constant coefficients can be computed quickly using asymptotically efficient matrix operations. In fact, the code to do this can be derived automatically from the recurrence itself. Here is what you

Re: [Haskell-cafe] Question about memory usage

2010-08-16 Thread Sebastian Fischer
[CC-ing café again] On Aug 16, 2010, at 5:52 PM, Daniel Fischer wrote: I am a bit concerned about the memory usage. Of your implementation of the matrix power algorithm? Yes. Making the fields of Matrix strict should help: data Matrix a = Matrix !a !a !a Making all fields strict makes

Re: [Haskell-cafe] Question about memory usage

2010-08-16 Thread Sebastian Fischer
[continuing off topic] On Aug 16, 2010, at 3:13 PM, Daniel Fischer wrote: You can calculate the n-th Fibonacci number in O(log n) steps using Integer arithmetic to get correct results. Yes, I was delighted when I saw this for the frist time. It works be computing /1 1\^n \1 0/

Re: [Haskell-cafe] Question about memory usage

2010-08-16 Thread Daniel Fischer
On Monday 16 August 2010 14:37:34, Roel van Dijk wrote: > On Sat, Aug 14, 2010 at 5:41 PM, Andrew Coppin > > wrote: > > (Then again, the Fibonacci numbers can be computed > > in O(1) time, and nobody ever needs Fibonacci numbers in the first > > place, so this is obviously example code.) > > A bi

Re: [Haskell-cafe] Question about memory usage

2010-08-16 Thread Roel van Dijk
On Sat, Aug 14, 2010 at 5:41 PM, Andrew Coppin wrote: > (Then again, the Fibonacci numbers can be computed > in O(1) time, and nobody ever needs Fibonacci numbers in the first place, so > this is obviously example code.) A bit off-topic, but I don't think there exists a function that computes fi

Re: [Haskell-cafe] Question about memory usage

2010-08-14 Thread Tako Schotanus
First of all, thanks to the people who responded :) On Sat, Aug 14, 2010 at 17:49, Christopher Lane Hinson < l...@downstairspeople.org> wrote: > > On Sat, 14 Aug 2010, Tako Schotanus wrote: > > I was reading this article: >> >> >> http://scienceblogs.com/goodmath/2009/11/writing_basic_functions_

Re: [Haskell-cafe] Question about memory usage

2010-08-14 Thread Daniel Peebles
> > In the example above, fiblist is a global variable, so the answer to "when > does it get freed?" would be "never". (I believe it's called a CAF leak.) > Is that actually true? I've heard lots of references to this, but I'm not sure it is true. Sure, it's harder for it to get collected when eve

Re: [Haskell-cafe] Question about memory usage

2010-08-14 Thread Christopher Lane Hinson
On Sat, 14 Aug 2010, Tako Schotanus wrote: I was reading this article: http://scienceblogs.com/goodmath/2009/11/writing_basic_functions_in_has.php And came to the part where it shows: > fiblist = 0 : 1 : (zipWith (+) fiblist (tail fiblist)) But then I read that "Once it's been referenced,

Re: [Haskell-cafe] Question about memory usage

2010-08-14 Thread Andrew Coppin
Tako Schotanus wrote: > fiblist = 0 : 1 : (zipWith (+) fiblist (tail fiblist)) Very interesting stuff for somebody who comes from an imperative world of course. Oh yes, that old chestnut. There's a page on the wiki somewhere with a whole collection of these cryptic one-liners - Pascal's t

[Haskell-cafe] Question about memory usage

2010-08-14 Thread Tako Schotanus
I was reading this article: http://scienceblogs.com/goodmath/2009/11/writing_basic_functions_in_has.php And came to the part where it shows: > fiblist = 0 : 1 : (zipWith (+) fiblist (tail fiblist)) Very interesting stuff for somebody who comes from an imperative world of course. But then I re