Wednesday, January 5, 2011


Yesterday much of Europe, North Africa and central Asia had an opportunity to observe the first solar eclipse of 2011. NASA reports that in Kiev the obscuration (fraction of the Sun’s surface occulted by the Moon) reached the value of 0.731.

What we see during the eclipse is two overlapping circles of nearly equal radius.

Assuming the radius is the same, what is the observable distance between the centers of those circles?

We could compute this using pure geometry, but let’s make it a statistical exercise.

What we know by now is that the intersection of the circles makes a known fraction of each of them (0.73). Let’s drop points into the first circle at random. Then, on average, 73% of them will also fall into the second circle.

Let d be the distance between the centers. For simplicity let the both circle have the radius 1, the first circle have the center (0,0) and the second circle have center (d,0).

The probability of a random point from the first circle to be inside the second circle equals

P{distance((x,y),(d, 0)) ≤ 1} = P{(x-d)2+y2 ≤ 1} = P{d ≤ x + √(1-y2)} = 1-P{x + √(1-y2) ≤ d}.

The last probability is just the cumulative distribution function for the random variable x+√(1-y2). And the value of d we want to find is the 1–0.73=0.27-quantile of that CDF.

Now let’s make an estimate of that quantile using R. To generate uniformly distributed random points inside the circle we just generate random points inside the square [–1;1]2 and then use only those that are inside the circle.

> x  <-  runif(10000, min=-1, max=1)
> y  <-  runif(10000, min=-1, max=1)
> i  <-  x^2 + y^2 <= 1
> length(1[i])
[1] 7861

(Note that the fraction of the points inside the circle, 7861/10000, gives an approximation to the ratio of the areas of the circle and the square, π/4.)

For each of these points, compute the random value we’re interested in

> d  <-  x[i] + sqrt(1 - y[i]^2)

and estimate the quantile, which is basically the largest of the lowest 27% of our observations.

> quantile(d, 1 - 0.73)


For comparison, the true value of d is 0.42737.

Thursday, September 16, 2010

iPad impressions

Recently I got an iPad. Here are my first impressions. (If you're going to find anything positive among them, you won't, sorry.)

  1. To get it working, you need to connect it to iTunes. No idea what for. Before you connect it to iTunes, it won't even show you a wallpaper. And after connecting to iTunes it starts working immediately.
  2. No iTunes (or replacement) for Linux. And I failed to launch it under Wine.
  3. Very little number of preinstalled software.
  4. Appstore has the most complex registration procedure I've seen in the last few years.
  5. Ukraine is absent from the list of countries, from which you should choose during registration in Appstore.
  6. After I chose Russia as my country, my user interface became Russian. Well, half-russian.

    I thought that Apple pays some attention to user interfaces.
  7. iPad cannot synchronise time via NTP. So natural and simple feature that I even didn't care to check — until clock went off by more than one minute.
    There is an app to display time obtained via NTP, but it cannot modify the internal clock (no third-party app can, as far as I understand).
    BTW, the device also has GPS — another source of precise time. Having WiFi, GPS and being unable to sync clock — that's just ridiculous.

Saturday, July 17, 2010

Some Events Worth Mentioning

  1. Mathematical Summer School «Mudramakitra» for high school students (Cherkasy, Ukraine). I will be teaching there.
  2. Conference «Verified Software: Theories, Tools and Experiments» and colocated Summer School on Formal Reasoning & Representation of Complex Systems (Edinburgh, UK). I'm going to attend the summer school.
  3. FOSS Fest 2010 (Odessa, Ukraine). I will be unable to attend.
  4. Kiev Polytechnical University will be hosting Summer School «Achievements and applications of contemporary informatics, mathematics and physics». I'm surprised that there are such events in Ukraine. Again, I'll be unable to attend, but if someone reading this blog is going there, please share your impressions afterwards!
  5. Python conference PyCon Ukraine will be held in Kiev in October.
  6. And finally, while I'm writing this, Australian Haskell hackers are having a great time at the first Australian Hackathon, AusHac2010!

Update. Soon after this post was published, Jasper Van der Jeugt announced that he is preparing the first BelHac — Haskell Hackaton in Ghent, Belgium!

Update2. Hoodlums group (London Haskellers) will have (the first?) meeting on July 29. I'll be in London during that time, so will join them and have some fun!

It is a "Coding Dojo" format where we pick some interesting problem and solve it as a group.

Sunday, March 28, 2010

Shell knowledge contest: report

Shell knowledge contest is over!

At the last minute it turned out that projector for displaying slides was not available. We worked around this by retranslating slides on several participants' personal netbooks (which was a very good idea, worth remembering). I generated two sets of slides, one with an answer slide after each question slide (for displaying on my laptop) and one without answers for displaying on participants' netbooks, so that an answer could not be revealed (intentionally or not) too early.

Slides (questions+answers, 20 of them) are available, so you can try to answer the questions yourself. They are in Russian, but the essential part is the shell code, whose output or effect you need to predict, and the answers. If there is some demand I could translate them to English completely.

There were two leaders, Evgeniy Berkovich and Yuriy Chumak, who gave 7 right answers. To determine the winner I used a set of additional questions about which function definitions are valid, and Yuriy Chumak won.

For me, the funniest question was the following one (#16, translated to English): what is the output of the following shell script?

f () { echo "The ambulance phone number is $13"; }
f `seq 0 12`

Anyone without any knowledge of shell scripting could suppose that the answer is 03 or 103 (103 is used for the calls from mobile phones), but nobody gave the correct answer!

But in general the level of shell knowledge was higher than I expected, for almost all questions (except 1 or 2) there was at least one correct answer.

Some links to other people's impressions (in Russian):

Thanks to all who participated!

Wednesday, March 24, 2010

Announce: Shell knowledge contest

When: This Saturday, March 27. We meet at 15.00 and event starts at 16.00

Where: Ukraine, Odessa, Bazarnaya str. 2. See

What: A contest on Shell scripting knowledge.

In what form: I give you some code, you tell me what it does. Seems easy, huh?

Why: Even if you don't win, you'll definitely find a lot of surprising (and maybe even useful) things about the plain old UNIX Shell.

Registration: yes, please

Note: The contest will be a part of FOSS Fest. I'm not organizing it, so things like time or venue might change — better check the site.

Monday, March 22, 2010

Zurihac: some critique

Zurihac, a Haskell hackathon hosted this time in Zurich by Google, has just ended. This was the biggest Haskell hackathon so far, bringing together over 80 hackers from Europe and nearby continents.

Here are some links:

No doubt organization of such event is a great work, and we all are grateful to organizers for Zurihac becoming reality. But still I'd like to highlight some things which IMO were not thought out enough. Hopefully this list will be useful for future Hackathons organizers.

  • Accomodation Joachim Breitner wrote:
    ok, there seems to be a relatively large number of people staying at the Backpackers. Maybe we can arrange with the hostel that they know about this conference. Then we can register individually and they can just put us together in rooms? Might be more efficient that finding groups of four ourselves. Maybe the local team can talk to them and put information about that on the wiki?
    Unfortunately, this wasn't done.
  • Food There were two issues.

    First, it was too many of us to fit into one restaurant. What could be done: make a wiki page; list some nearby restaurants; make people organize themselves more or less uniformly. What was done: we were just told not to go altogether to the one place.

    Another problem: some (most?) of the restaurants were closed on Sunday. I believe that it might be easier just to call nearby restaurants and find out which are open; then repeat the procedure described above. In contrast, we were told «go there; and if it is closed, well, go somewhere else»

  • Power plugs It was a surprise for most of us that Switzerland has different powerplugs than the rest of Europe. Fortunately, the issue was resolved (personally I thank Simon Meier for lending a cable), but it would nice if we knew about problem in advance. (For instance, organizers of Utrecht hackathon last year kindly reminded us of the possible problems).
  • Duration This hackathon was almost twice as short as the Utrecht one (20 hours against 36 last year).
  • Talks For some reason, talks and demos were postponed to the Sunday evening (they were scheduled for 16.30 and if I recall correctly began around 17.00. As a result, people who had to leave early (due to their flights/trains) missed the talks.
  • Registration This one is not addressed to organizators directly, but rather to attendees. At the moment there are only 57 attendees on the wiki. It's only about 70% of the total number of registered participants. I'd like that coverage to be bigger.

So, once again — Hackathon is held, code is written and talks are given. Only these little things, when done, make a nice feeling that you are cared for. So please, next time, try to do them ;-)

It would be also interesting to hear other opinions from attendees and organizers.

Sunday, March 14, 2010

Sharing the budget with hledger

This time I'd like to tell you how we use hledger in our small family. Here I'll present our experience in question/answer form.

  1. How to make ledger file accessible by different users?

    First, choose a location for the ledger file. According to FHS it probably belongs somewhere in /var. For ourselves I just chose to place it in my home directory.

    Then, for hledger to find your ledger file, just set the environment variable LEDGER to the location chosen. E.g. append

    export LEDGER=~you/.ledger

    to the /etc/profile. If you chose to place ledger file in your home, make sure that other users have permissions to access them. Like:

    chgrp users ~you ~you/.ledger
    chmod g+x ~you
    chmod g+r ~you/.ledger
  2. How to organize accounts?

    The overall account structure won't be much different from what you'd use without sharing. However, for each account you have to decide whether to make it shared or per-user. For example, some expenses are shared (such as house-keeping expenses) and some may be not (differentiating transport expenses may give an evidence about how much everybody spends on that).

    Shared accounts will have the usual form Expenses:Taxes and per-user ones will have the form Expenses:Transport:Leonard, Expenses:Transport:Sheldon etc.

    In our case, we only divide (for obvious reasons) the «wallet» account which tracks the cash one carries with himself.

    In general, some support for shared/differentiated accounts could be built in hledger itself, but we still can solve many problems, see below.

  3. Our transactions interfere when finding similar transactions.

    Ours did too! Until I came up with the patch (now merged into the main repository) which allows filtering relevant transactions by account.

    To demonstrate the problem, suppose my wife has just ended entering her transactions. Among others was:

    2010/02/26 tansport
        Expenses:Transport       20

    Now I'm going to enter my transactions. Among others there is similar transaction for my transportation, but it differs in the second account, it is Assets:Wallet:Roman. Of course, hledger doesn't know about this, so it suggest Maria's transaction for me as a template and I have to enter the correct account manually.

    As a workaround for this with the patch mentioned above you can invoke hledger add with additional parameter -- filter for relevant transaction. For example, I will invoke hledger as hledger add Roman which will result in the correct template transaction.

    To automate this, you can add to your ~/.profile the following code:

    function hledger
        case "$1" in
                $HLEDGER add Roman "$@";;
                $HLEDGER "$@" ;;

    This works for us because almost every transaction involves wallet account. In a different workflow this may work not so well (because some transactions may not involve any of the differentiated accounts). In some sense this is a hack caused by hledger not making distinction between shared and diffirentiated account.

  4. How to achieve consistency in using ledger?

    By the definition of the ledger file format, hledger does not and cannot force you to explicitly create account before using it. Thus nothing prevent you (or other users) from making a typo or just using different account names -- for instance you use Expenses:Transport:Subway but your wife uses Expenses:Subway. If you are aware of this, it can be easily corrected using sed (thanks to simple ledger format), but it is usually difficult to spot.

    That's why I added a new option, --no-new-accounts (now in the main repo), which makes hledger add not to accept new accounts, i.e. accounts which are not yet present in ledger file. This is of course not a guarantee (users already have access to ledger file, so they can do whatever they want) but a good measure.

    Thus, for other users you can add to their ~/.profile the following definition:

    function hledger
        case "$1" in
                $HLEDGER add Maria --no-new-accounts "$@";;
                $HLEDGER "$@" ;;

    You can also use this option by default for yourself, turning it off in the rare cases when you really want to add a new account.

Saturday, February 6, 2010


Since Maria and I moved to Kiev in September 2009 we actively use hledger to track our money.

On average, we record 5 transactions each day — or 35 transactions if you record them at the end of the week. In order for this operation not to consume too much time, transaction entry should be very quick and easy. That's why I made several changes to hledger so that it better fits my workflow.

It took a while before my changes made their way to the main hledger repository. Benefits of some of these patches may be not obvious, so I am going to make a series of blog posts which describe my workflow and show how to efficiently use hledger.

I am going to start with the chart facility. It is useful e.g. when you want to know the structure of your expenses, like: where the most of the money go, where you can save and where saving does not make sense etc.

By the way, I find a lot of criticism of pie charts. But for this purpose I don't see any good alternative.

In order to create ledger charts you have to enable it. E.g. if you use cabal-install, just type "cabal install -fchart" from inside hledger source directory (as of 2010-02-06, hledger with chart facility is not yet released). You will need Chart package installed.

Everything else is trivial. Just type hledger chart ^Expenses to get a fancy pie chart packed in a PNG file. Here's an example:
ledger pie chart

Some tips:

  1. Plotting everything does not make sense since ledger has both positive and negative accounts. Make sure that you plot only accounts with the same sign. «Expenses» accounts are almost always positive.
  2. Usual hledger filtering constructs apply. Some useful examples:
    • hledger chart --depth 2 ^Expenses — plot only top-level subaccounts of Expenses
    • hledger chart -p Dec ^Expenses —make a report for the last December
    • hledger chart ^Expenses not:Rent — ignore Rent account (useful if its balance is too big relative to other expenses)
  3. chart command has some additional options. Use hledger chart -o mychart.png --size 300x500 ^Expenses to specify output file name and dimensions of the image.

Thursday, September 17, 2009


As you could notice, Haskell Weekly News got a new editor, Joe Fredette (greetings, Joe!). But does he know how it really happened?

CCC's authors decided to shed light on this:

(Jokes aside, I'd like to thank Brent for the excellent work he did on HWN.)

About this strip: this is the first our strip prepared entirely in The GIMP, also the first one where I took part in drawing (the main artist is Maria Kovalyova, as always). Drawing comics is almost as funny as programming Haskell!

Tuesday, July 28, 2009

CCC #5: Trial

Finally we came up with a name for our strip — CCC, or Cartesian Closed Comic.

And the new strip is dedicated to the weirdness of Except (aka Either) monad with respect to its Applicative instance, pointed out here. Also inspired by the quote by Daveman.

Tuesday, July 21, 2009

Schrödinger's cat

Idea by lispy.

New magazine: Practice of Functional Programming

Yesterday, the first issue of the new Russian-speaking electronic magazine, Practice of Functional Programming, was presented.

The issue consists of the following articles:

  • editorial, by Lev Walkin;
  • two introductory philosophical articles: «Fear of Laziness» by Sergey Zefirov and «Functions and Functional Approach» by Roman Dushkin;
  • two more practical articles: Eugene Kirpichov tells about pitfalls and workarounds when using mutable state, and Dmitriy Astapov illustrates top-down design approach using checkers game as an example;
  • translation of Dan Piponi's Haskell Monoids and their Uses by Kirill Zaborskiy;
  • extensive literature review by Alex Ott.

I am often sceptical about such localized projects, because they artificially narrow their audience. On the other hand, we hope that this magazine will familiarize our programmers with FP and make it a bit less «alien technology».

So, let's wish a great future to the new magazine!

Wednesday, June 24, 2009

Halting problem

Here's the new strip by Maria. Hope you like it.

It's unlikely that a new strip will appear during the following two weeks, cause we are going to the ecological expedition, where I will teach the basics of statistical reasoning and Maria will investigate some biological phenomena. But we promise to return with the new ideas :)

This strip is inspired by Russell O’Connor.

Tuesday, June 16, 2009


This strip is based on a quote by MyCatVerbs, featuring dons, lambdacat and two suspicious guys sitting in front of a Tupil laptop. Eelco, Chris, is that you?!

(Drawn by Maria Kovalyova)

Tuesday, June 9, 2009

Don't play with your monads

This comic strip is brought to you by Maria Kovalyova, based on a quote by David Leimbach.

How do you like it?

Tuesday, May 26, 2009


Guess, what does this graph show?

Monday, May 25, 2009

The first seminar of LtU-Kiev

LtU-Kiev, a group of Ukrainian programming languages enthusiasts is holding its first seminar, featuring talks about type systems, type inference and dynamic logic. (May 30, Kiev)

Sunday, April 26, 2009

Quantum analogy

Classical physics is an example of pure functional system — when you measure something, the measurement itself has no side effects.

But in quantum mechanics, when you measure something the very action of measurement affects the object of observation. Probably God used unsafePerformIO somewhere?

Thursday, April 23, 2009

Hac5: the rest of the story (almost)

During the third day I tried to develop juicybar. Started by writing new backend class for dock applications (currently it isn't really a class, but eventually you'll be able to have your information bar using bare X, Qt or GTK+ — whatever you want). We did some bughunting with Wolfgang Jeltsch and Duncan Coutts, which showed what evil things can happen if you don't use threaded runtime. Later I hope to make separate post about the future of juicybar, its problems and features.

I had to leave early, about 4.30 pm, to go to Eindhoven (it's also a topic of another post).

I'd like to thank all the organizers — they did really a great (and huge) work. I was glad to meet all those nice people at hackathon (whose names we all know from haskell-cafe). And of course I'm looking forward to the next Hackathon :-)

Hac5: second day

The second day was mostly the day of the demonstrations.
It began with darcs q&a session driven by Eric Kow. Particularly, I found out that no simple solution to my problem is available yet (although I learned about context files which you can exchange with your buddy and use to make "darcs send" happy).
Atze Dijkstra made an announce of the first UHC release. UHC is Utrecht Haskell Compiler, but since UHC grew out of EHC (Essential Haskell Compiler), jokes about UHC being Unessential Haskell Compiler were popular.

Don Stewart showed the way to visualize Haskell data structures using vacuum with cairo backend, and Christophe Poucet made the same in 3d using Ubigraph backend.

David Himmelstrup told about the current status of LHC.
For me, the most interesting during that day was review of Grapefruit made by Wolfgang Jeltsch. The hard thing about Grapefruit is that it extensively uses type extensions and type-level programming, so Wolfgang tried to explain why those are needed. I guess, "ordinary" haskellers passing by were frightened hearing Wolfgang talking about kind polymorphism (at least, I was).

The day ended with collective dinner.