Comments on: MIU in Haskell https://jeltsch.wordpress.com/2013/04/18/miu-in-haskell/ Mathematics, computer science, and computers Thu, 17 Nov 2016 15:05:58 +0000 hourly 1 http://wordpress.com/ By: MIU in Curry « Wolfgang Jeltsch https://jeltsch.wordpress.com/2013/04/18/miu-in-haskell/#comment-480 Sun, 30 Aug 2015 21:09:20 +0000 http://jeltsch.wordpress.com/?p=582#comment-480 […] language Curry, and the third talk was about a Curry implementation of MIU. The blog articles MIU in Haskell and A taste of Curry are write-ups of the first two talks. However, a write-up of the third talk […]

]]>
By: Wolfgang Jeltsch https://jeltsch.wordpress.com/2013/04/18/miu-in-haskell/#comment-279 Sat, 27 Apr 2013 11:54:16 +0000 http://jeltsch.wordpress.com/?p=582#comment-279 Please enter this on the GHCi prompt:

length $ splits $ replicate 1000000 M

This should give you the result 1000001 quite quickly.

Now try this:

length $ splits' $ replicate 1000000 M

I wasn’t able to get a result within a reasonable amount of time.

The problem with split' lies in the use of inits. The inits function is implemented as follows:

inits :: [a] -> [[a]]
inits xs = [] : case xs of
                    []      -> []
                    x : xs' -> map (x : ) (inits xs')

Note that the recursive application of inits is under a map. So the suffix of an expression inits [x_1,x_2,…,x_n] that starts at an index i is defined by a nested application of map of depth i:

map (x_1 : ) (map (x_2 : ) (…(map (x_i : ) […])…))

To detect that the result of an expression map f xs is non-empty, we have to detect that xs is non-empty. So to detect that the above suffix is non-empty, we need to walk through the i layers of maps, which takes \mathcal O(i) time.

This means that to fetch the k-th element of inits xs, we need

\sum_{i = 0}^k \mathcal O(i) = \mathcal O(k^2)

time.

The implementation of split doesn’t suffer from this problem, since it creates prefixes by a single application of map, and computes every single prefix independently.

]]>
By: rd6137 https://jeltsch.wordpress.com/2013/04/18/miu-in-haskell/#comment-277 Fri, 26 Apr 2013 17:01:22 +0000 http://jeltsch.wordpress.com/?p=582#comment-277 Why is split more efficient than split'?? I was unable to exhibit any difference between the two (Criterion used).

Thank you!

]]>
By: Wolfgang Jeltsch https://jeltsch.wordpress.com/2013/04/18/miu-in-haskell/#comment-274 Thu, 18 Apr 2013 18:58:27 +0000 http://jeltsch.wordpress.com/?p=582#comment-274 By the way, in your Gravatar profile you say, “I like seeing how other languages do things differently.” So I wonder, did you already look at languages that are not indo-european, like Estonian? They are at some points quite different from what we “indo-europeans” are used to.

]]>
By: Wolfgang Jeltsch https://jeltsch.wordpress.com/2013/04/18/miu-in-haskell/#comment-273 Thu, 18 Apr 2013 18:54:47 +0000 http://jeltsch.wordpress.com/?p=582#comment-273 The stripPrefix function returns a Maybe value, since it needs to signal whether the given list starts with the given prefix or not. In the replace function, I have already ensured that it does; so it is simpler to use the solution with drop and length, where I do not have to get rid of the Maybe.

]]>
By: BMeph https://jeltsch.wordpress.com/2013/04/18/miu-in-haskell/#comment-272 Thu, 18 Apr 2013 17:19:24 +0000 http://jeltsch.wordpress.com/?p=582#comment-272 In the “replace” function, I noticed that you didn’t use the “stripPrefix” function – was that for readability concerns?

]]>
By: MIU in Haskell, part 2 | Theory Lunch https://jeltsch.wordpress.com/2013/04/18/miu-in-haskell/#comment-271 Thu, 18 Apr 2013 13:51:23 +0000 http://jeltsch.wordpress.com/?p=582#comment-271 […] Today, I presented a Haskell program that computes derivations in the MIU formal system from Douglas Hofstadter’s MU puzzle. I have posted a write-up of my talk on my personal blog. […]

]]>