Are there any links between poetry and computing? Seems unlikely. But …
Here’s one of my favourite poems for you to contemplate, about recursion.
Great fleas Have Lesser Fleas,
upon Their backs To Bite’em,
And Lesser Fleas Have Lesser fleas,
And So, Ad infinitum.
and Those great Fleas, Themselves, In turn
Have Greater Fleas To go On;
while Those Again have Greater still,
And greater Still, And So on.
This poem is by Victorian logician Augustus De Morgan famous for his laws of boolean logic also Maths tutor of Victorian computer scientist Ada Lovelace. He also made the idea of mathematical induction rigorous. It is the basis of how you prove recursive programs (and iterative ones) are correct.
An Ode to technology
The island of Rhodes in Ancient Greece was a centre for mechanical engineering at the time, and the Greeks were great inventors. According to an Ode by Pindar the island was covered with automata:
The animated figures stand
Adorning every public street
And seem to breathe in stone, or
move their marble feet
Can you write an ode to some aspect of modern computing technology, a lament to a famous computer scientist or a poem about the effect of computing on society?
Write poems about emotions that include emoticons.
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.
The use of If isn’t quite a pure computational one though and it doesn’t follow the structure of a computer science IF statement:
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 consists of a test of something that is true or false but then gives a specific action to take when the statement is true.
For example, a 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 ...
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.
Counting rhymes make a really good introduction to counter-controlled loops ie “for loops” too, so why not write programs that automatically generate rhymes like 10 green bottles, or for your favourite counting book.
You can then make variations like: “100 green bottles sitting on a wall…and if 5 green bottles should accidentally fall…”
Infinite Families of Poems
Take the above idea further, adding parameters to your poems, and suddenly poems as programs makes it possible to write infinite families of poems rather than just old-fashioned single poems.
Non-termination is an important concept in programming, though one you often try to avoid. Never-ending poems (eg The Song That Never Ends) are the poetic equivalent (See also our compressed one below which is my favourite).
Can you write a non-terminating poem of your own?
As poems are often repetitive you can play at compressing and uncompressing them and learn about compression algorithms while contemplating poetry as here.
18 4 18 4 18 4 …
Uncompress it using the code book:
1 [a] 2 [and] 3 [are] 4 [because] 5 [do] 6 [fun] 7 [have] 8 [lot] 9 [of] 10 [rabbits] 11 [them] 12 [there] 13 [why] 14 [1 8 9] 15 [10 7] 16 [14 11] 17 [15 14 6] 18 [17 13 5 17 4 12 3 16 2 13 3 12 16 ]
More compression code puzzles here
Poems and Ciphers
You can use your favourite poem as the basis of a cipher to use to make secret messages (ciphers are just algorithms for creating secret messages). In Robert Graves’ book I, Claudius he has Claudius explain a cipher supposedly used by his predecessor Augustus*. The cipher described is a form of substitution cipher where you swap each letter in the message for a different one, but where the new letter depends both on the letter in the message and its position (this kind of cipher is called a polyalphabetic cipher). Augustus’ cipher was based on Homer’s, The Iliad.
Here is a variation. Convert the letters in the poem to numbers and use these numbers to tell you how far to jump on in the alphabet (A means jump one place forward, B means jump two places and so on, wrapping round to A if you get to the end of the alphabet) to do the encryption. Starting on the letter in the message, jump forward in the alphabet the number of places indicated by the letter in the same position in the poem, and that is the letter to use in the secret message. You can use any poem (or other writing)
So to encrypt the letter HELLO using the poem by Pam Ayres that starts
I am very fond of hedgehogs…
I from the poem is the 9th letter in the alphabet so jump on 9 from H in the message to give Q
A from the poem is the 1st letter in the alphabet so jump on 1 from E in the message to give F
M from the poem is the 13th letter in the alphabet so jump on 13 from L in the message to give Y
V from the poem is the 22nd letter in the alphabet so jump on 22 from L in the message to give H
E from the poem is the 5th letter in the alphabet so jump on 5 from O in the message to give T
The encrypted version of HELLO is therefore QFYHT.
Pick a favourite poem and use it to encrypt a secret message in this way.
[*Sadly, there is no evidence Augustus actually used this cipher. It was probably an invention of Robert Graves for the book.]
Magical Poem Magic
You can turn your favourite poem into a magic trick (as long as it is long enough) that illustrates what an algorithm is, exhaustive testing and the idea of rigorous logical reasoning to do proof. See how here
Pseudocode poems are poems that also work as programs eg
My love for you is endless my love is true while my love is true I love you
Here it is implemented as a Python program.
def myloveforyouisendless(): """My love for you is endless""" my_love = True while my_love == True: print('I love you') myloveforyouisendless()
What does it do when executed? There are more on our Pseudocode poems page. Can you write your own?
Programming shapely poems
Inspired by the poems of the wonderful poet @brian_bilston you could write a program (a python poem) that shapes poetry such as twitter.com/brian_bilston/
Give your program a poem and it should format it in a shape following a number sequence.
See how here
Write a poem writing program
Of course any self-respecting computer scientist, nervous of writing their own poems would just write a program to write them for her/him. Start with Strachey’s 1950s love letter program ideas teachinglondoncomputing.org/writing-love-c You need to include rhyming word lists for the program to choose from if your poems are to rhyme.
Rockstar David Bowie cowrote one of the first creative computing programs and used it to help write lyrics, automating the “cut-up” technique he used. It involves taking random sentences (eg from a newspaper) splitting them in half and then recombining them with different halves. His program helped generate lines for some of his most famous songs (its partly why they are often so surreal).
Over several years cs4fn challenged our readers to write limericks on computing topics. We gave the first lines. They came up with the limericks. Here are some we liked best. cs4fn.org/limericks/ Other limericks are scattered around the cs4fn web pages. You have to find them.
Ada Lovelace and Lord Byron
A last poem-computing link: Victorian Countess, Ada Lovelace worked on the first computer. Her father was the poet Lord Byron.
Programs change the world by changing the way we do things, though not always for the best. Poems and especially protest songs change the world too, by making people think.
Can you name some programs/algorithms and poems/songs that you think helped change the world?
The algorithms and so programs behind the web and public key encryption are examples of the former. Hearing Free Nelson Mandela, by The Special A.K.A certainly led to me finding out more about apartheid. The songs of Bruce Springsteen supposedly helped bring down the Berlin Wall as a result of his concert in East Berlin. Big Yellow Taxi by Joni Mitchell with its line about paving paradise helped make me environmentally aware.