If: a computational literary criticism

If, by Rudyard Kipling is an inspirational poem that was voted the UKs favourite poem in the 1990s. It consists of a series of lines that start with If. What If, by Benjamin Zephaniah is a more subversive poem modelled on the original.

If statements, of course, are a really core part of programs so are these poems, given they are all about IF, algorithms? The use of If here isn’t quite the same as a pure computational one as seen in programs. For a start, it doesn’t follow the structure of a computer science IF statement. Here are a few lines:

If you can keep your head when all about you
  Are losing theirs and blaming it on you,
If you can trust yourself when all men doubt you,
  But make allowance for their doubting too;
...

In programs, an IF statement has a specific structure. It consists of a test of something that is true or false but then gives a specific action to take when the statement is true. The lines

you can keep your head when all about you are losing theirs AND blaming it on you,

is more or less such a true or false statement. Either you can keep your head or you can’t. This though ignores the possibility of you sometimes losing your head and sometimes not. The poem presumably means to say that you must ALWAYS keep your head. What exactly does “when” here mean too? The reason we do not use English when writing programs is the lack of clarity of what is actually meant. Programs are mathematically precise in their meaning. They do only have one possible meaning (and that is the point). this is also a potential issue of writing programs by instructing AIs over what you want in English!

This boolean expression (something that evaluates to true or false) also uses a logical connective AND just like in a program – you must both be keeping your head AND people must be blaming it on you for the whole to be true. If they are both true then the action that follows is taken, but if they aren’t both true the poem says nothing about you!

Another issue in If, is that this test / boolean expression is not immediately followed by an action to do when it is true. The action comes right at the very end of the poem

...
Yours is the Earth and everything that's in it,
And - which is more - you'll be a Man, my son!

This comes after a whole series of these partial IF statements. To make it more clearly like a program you would add a more explicitly IF-THEN structure, which is the equivalent of putting ANDs between all the tests. In a program that would be written more like the following:

IF you can keep your head when all about you
Are losing theirs and blaming it on you,
THEN IF you can trust yourself when all men doubt you,
But make allowance for their doubting too;
...
...
THEN Yours is the Earth and everything that's in it,
And - which is more - you'll be a Man, my son!

Only if all the tests are true does the final action get taken. Though it isn’t really an action, it is more an assertion that something else is true – “the Earth is yours”, rather than “we give you the Earth”. (Also that final And is no longer a logical connective!)

Poems like this could be made more explicitly computational though. For example, a slightly more computational version might be:

IF you can keep your head when all about you
Are losing theirs AND blaming it on you
THEN I will thank you, giving you a pay rise too
...

A love poem in this vein might start

IF you are a snail 
    THEN I will become your shell.
IF you are a ...

This leads on to the idea of pseudocode poems, that use other computational constructs. More of that to come.

To do …

  • Write your own poem in this style with true/false questions followed by specific actions, modelled on the computational version of IF. It could be a reworking of If itself or a completely different poem.

More on …

Subscribe to be notified whenever we publish a new post to the CS4FN blog.


This blog is funded by EPSRC on research agreement EP/W033615/1.

QMUL CS4FN EPSRC logos

Leave a comment