Chapter Overview

Conjuring with Computation

Paul Curzon and Peter W McOwan

Chapter 0 :

Introduction

This is a book that will teach you some magic, but also explains the many links between computing and magic, with the result that you will learn about both magic and computation.

Interlude: Jean-Eugène Robert-Houdin

PAUSE:  Alan Turing

Section 1 :

Algorithmic Thinking

Algorithmic thinking is about thinking of the solutions to problems as algorithms. We explain what an algorithm is, why notation matters, and describes the three control structures that all algorithms can be built from.

Chapter 1 :

Invisible Palming /

What is an algorithm?

You invisibly move a card from one pile to another. 

A self-working magic trick consists of a series of steps that if followed guarantee to achieve a magical effect. An algorithm is also a series of steps that if followed blindly guarantee to achieve a result.

PAUSE: Muhammad ibn Musa al-Khwarizmi

Chapter 2 :

The Möbius Rings /

Sequences

You cut a ring in half but magically get two interlocked rings. 

Tricks involve following a sequence of instructions. Sequences in algorithms (and so programs) are a fundamental part of computation. Sequencing is the first key control structure and so a building block for describing computation.

 Interlude: Felicien Trewey and Harry Blackstone Sr.

Chapter 3 :

Six Magical Objects /

Selection

Given the choice of six magical objects, a volunteer picks the one that you, the magician, predicted.

Branching, or selection, where something different is done depending on the situation, is the second key control structure that algorithms are built from.

PAUSE: George Boole

Chapter 4 :

Turning the Key /

Repetition

A volunteer chooses a card from a pack then places it back. You, the magician, see neither it being chosen nor replaced, but still can find the card.

Repetition is the final kind of control structure needed. With sequencing, selection and repetition you have all the building blocks needed to describe the flow of control of any algorithm. All computation (so tricks) can be described with just these three control structures.

Interlude: Penn and Teller

Chapter 5 :

Calculator Conjuring /

Notation 

A volunteer types a long number into a calculator based on a shorter number they freely choose. You demonstrate your ability to do lightening calculation by immediately predicting three numbers that divide exactly into it. Even more surprisingly, when the divisions are done the answer is the original number.

A key step in programming, and a part of computational thinking, is in turning a possibly imprecise version of an algorithm in to very precise steps with no room for doubt. That requires a precise language with a very precise mathematically-defined meaning. This is a difference to magic where informal descriptions are used.

PAUSE: Grace Hopper

Section 2 :

Evaluation &

Logical Thinking I

We explore the need for evaluation of both programs and tricks, and how thinking logically is at the core of computational thinking.

Chapter 6 :

Wizardly Book Magic /

Testing and logical reasoning

Books about witches and wizards are suffused with magic. A volunteer chooses a word apparently freely and the book then controls them, leading them to the word you predicted in advance with the help of the book.

How can we be sure  a program (or trick) always works? We need to evaluate it for correctness. One way is exhaustive testing but with some simple logical thinking we can reduce the number of tests needed.

PAUSE: Margaret Hamilton

Chapter 7 :

The 21 Card Trick /

Logical reasoning

A volunteer freely choses a card from 21 laid out on the table. No one is told which card was chosen, but you, the magician, read the volunteer’s mind to find out which it is.

We can use logical thinking to prove a program (or trick) will always work when the steps are followed correctly.

PAUSE: Edsger W. Dijkstra

Chapter 8 :

Mental Monte & the Trains of Thought /

Reasoning by cases

You turn your back. A volunteer picks a card from three. They move them around. You turn back and the three cards  are mixed some more. Despite not seeing the card being chosen nor all the mixing, you name the card chosen. 

One way mathematicians prove theorems is ‘by cases’. This is really common when proving algorithms correct. Each use of selection turns in to another case to check.

Interlude: Bob Hummer

Section 3 :

Making it work for people

We now look at the presentation side of tricks and the importance of understanding people (ie cognitive psychology). In computing terms this is about usability and user experience.

Chapter 9 :

The Cyclops’ Eye /

You cannot trust your eyes

In this eye-shaped optical illusion, the centre of the eye appears to float off the page.

Optical illusions show that you cannot believe your eyes. Just because you see it does not mean that it is there. When designing interfaces you cannot assume people see what is there.

Interlude: Hajime Ōuchi and Bridget Louise Riley

Chapter 10 :

The Magically Weighted Boxes /

Your brain cannot be trusted at all 

Members of the audience take it in turns to pick up a pile of three boxes, but when, after a click of your fingers, they only pick up two of the boxes, the pile is clearly heavier.

You cannot trust your other senses either. This illusion shows you cannot even judge what is heavy and what is light.

Interlude: Lulu Hurst

Chapter 11 :

The Teleporting Robot /

Keep it simple stupid

With this magic jigsaw, you make a whole robot appear and disappear just by muddling the jigsaw up and putting it back together again.

Some systems are so complicated we can’t take it all in. When designing tricks we aim to add complexity so the audience do not see what is really happening. When designing usable systems we need to avoid overloading the senses. Keep it simple stupid!

Interlude: Sam Lloyd and William Hooper

Section 4 :

Decomposition & Abstraction

When inventing new tricks we can build them out of a collection of basic parts. Such parts can be reused across other tricks.  Likewise we can solve the problem of writing a program by breaking it into parts to write separately, or just reuse bits previously written.

Chapter 12 :

Pre-booked Picture Magic /

Abstraction

An audience member randomly picks a picture from a book of images. You are then able to correctly draw the picture chosen despite not seeing them choose. 

This trick relies on the abstraction of images. Abstraction is about simplifying things down to their essence. Variations arise in many disciplines. Computer scientists have a many versions including simplified images. Most versions though are both more technical and more precise than that.

PAUSE: Susan Kare

Chapter 13 :

Trained Rice /

Decomposing into parts

You train a bottle of rice to grip a chopstick so that the bottle can be lifted with the chopstick, whilst the identical bottle of a member of the audience repeatedly falls.

Even simple tricks can be described as a series of parts, making them easier to invent and describe. This is called decomposition. Decomposition of a problem in to parts in this way is a fundamental part of computational thinking.

PAUSE: Michael Faraday

Chapter 14 :

The Top Hat Teleporter /

Hiding detail and swapping parts

This is a new version of Invisible Palming, but where a teleporting top hat is used to move a card from one pile to another.

Abstraction and decomposition allows us to think about different parts of a program or trick at different levels of detail at different times. This is a key use of those ideas. It also allows us to swap in and out different parts of a trick /program to give variations, and perhaps even better tricks / programs.

PAUSE: Jeanette Wing

Section 5 :

Procedures & Procedural Abstraction

There are many different kinds of false shuffles. Just by saying the name of a shuffle, as a step in a trick, a magician would know what was meant, and be able to incorporate it into the trick. This is procedural abstraction: a key kind of abstraction used by computer scientists, where named, clear and self-contained pieces of code are created for use elsewhere. Once created, they are incorporated in to the program (or ‘called’) by giving their name.

Chapter 15 :

Overhand Shuffle /

Procedures

The overhand shuffle is the standard shuffle used by card players and magicians alike to quickly shuffle a pack of cards. Use it any time you do really want to mix up the cards in a pack.

The core tool for doing decomposition is the procedure. Here we give a sub-trick and specifically a shuffle a name. That allows us to just refer to the name in any trick we wish to use it. Likewise by naming program code that does a well-defined task we can then use the name whenever we want to refer to that code. This is called procedure call and it uses abstraction. We hide the details of how the step is done, just giving the code a name. In this and subsequent chapters we look at shuffles as sub-tricks.

Interlude: Persi Diaconis

Chapter 16 :

Swapped Ends Overhand Shuffle /

Specifying procedures

This false shuffle swaps the cards at the top and bottom of the pack while shuffling the cards in the middle of the pack.

By giving a clear description of the effect of a trick (or program) we do not have to worry about how it works (its implementation) when designing other tricks or (programs) that use it.

PAUSE:  Nikola Tesla

Chapter 17 :

End Overhand Shuffle /

New procedures from old and layers of abstraction

You shuffle the pack but secretly leave the top and bottom cards of the pack alone while mixing up those in the middle of the pack.

Once we have sub-tricks or procedures, doing well defined things, we can chain them together to get new ones that do something different overall.

Interlude: Howard Thurston

Chapter 18 :

False Top Overhand Shuffle /

Parameters and generalisation

This false shuffle leaves the top cards of the pack unchanged.

Often the same sub-trick can be used in different situations, but does something slightly different. For example, it might do the same thing, but moving a different number of cards depending on what the trick needs. This leads to the idea of parameters: specifying the values needed to fit the procedure to the situation.

PAUSE: Ada Lovelace

Chapter 19 :

Side Jogging /

Swapping one procedure for another

You shuffle the cards, but unknown to the audience, the top quarter or so of the pack are un-shuffled.

If we have decomposed a trick into well-defined parts then we can swap in equivalent parts to make variations of the same trick, perhaps to improve the presentation of the trick. With programs, having broken them into clear parts that do a well-defined task, we can substitute different implementations (e.g. that are faster) without affecting the rest of the program. That means we do not need to think about the rest of the program when making such a change.

Interlude: John Nevil Maskelyne

Chapter 20 :

Cyclic False Cut /

Building libraries of useful procedures

You repeatedly cut the cards, but in doing so leave the cyclic order alone.

By making collections of related techniques, like cuts and shuffles, or in programming, procedures about a single topic, we can organise programs so the instructions for the really useful ones are written out once and then just called on whenever needed.

PAUSE:  Maurice Wilkes and David Wheeler

Section 6 :

Building Bigger

We have now seen most of the basic techniques that allow us to build large programs a little at a time. In this section we go a step further, using results from one subroutine in the next.

Chapter 21 :

The False Choice /

Programming interfaces 

You give a member of the audience a choice of several things, but it is actually no choice at all.

To mix and match sub-tricks it helps to be clear about what they do. Procedures need to have clear interfaces i.e., precise descriptions of exactly what they do and when they can be used.  Interfaces help avoid mistakes being introduced when using procedures in large programs.

PAUSE: Tommy Flowers

Chapter 22 :

Creating a Forcing Matrix /

Functions

Spectators choose numbers at random from a grid of numbers. They add up to a number predicted by you, the magician.

Sometimes the aim of a particular part of a program is to return a value – a number perhaps. That is what a Forcing Matrix does. Its job is to come up with a number. This could be the aim in its own right, with the magician magically having predicted the number. It can also be used as a component of other tricks.

PAUSE: John McCarthy

Chapter 23 :

Forced Wizardly Book magic /

Calling functions

You first get the audience to pick a random number by choosing numbers from a grid. Then that page in a book is taken and a volunteer chooses a word from it at random. The book then leads the volunteer on to to a new word in the book no one could have known, except that you did predict it.

We can make more new tricks from simpler ones by chaining trick elements together in sequences where they pass information from one to the next. The resulting trick can be much more powerful. The same applies to programs.

Interlude: David Devant

Chapter 24 :

Invisible Palming (again) /

Sequencing procedures together

We return to the trick where you magically move a card from one pile to another.

Procedures with parameters allow us to create generalised programs. We can decompose them in to parameterised parts and sequence them one after the other, using the same parameters. By matching preconditions and postconditions we can give an outline argument as to why the whole algorithm works.

PAUSE: Robert W. Floyd and Tony Hoare

Section 7 :

Abstraction & Data Representation

We’ve seen abstraction applied to control structures in the form of procedures. Now we explore similar ideas with data: data can have different representations with that representation hidden.

Chapter 25 :

Drawn to You /

Codes and representing data

Several volunteers each draw a picture of their choice. Just by looking at the drawings you are able to work out who drew which.

Tricks often rely on representing information in some particular way. Choosing an appropriate data representation is core to computational thinking and programming.

Interlude: Joseph Jastrow

Chapter 26 :

A Roman Maths Challenge /

Roman numerals

This is a challenge rather than a magic trick: can anyone make a roman sum add up correctly?

Roman numerals as used here are an early example of a number representation different to the one we use. Computers use a different one again. There are many ways to represent the same data.

Interlude: Nevil Maskelyne

Chapter 27 :

The Lottery Trick /

Place-value representation of numbers

You turn the room into a gigantic lottery machine, bouncing lottery balls made of screwed up paper around the room. When a series of balls are chosen, they give a number that does not match anyone’s lottery number … except yours.

We use the Hindu–Arabic numeral system. The really amazing idea is to give digits a position in a number and have their value change depending on the position, so 2 can stand for 2, 20 or 200 depending on its position. This makes large numbers more concise but also makes operations like addition and multiplication easy: they make for simple algorithms.

PAUSE: Charles Babbage

Chapter 28 :

Cards on your Mind /

Binary: How computers represent numbers

Four members of the audience jointly pick a number and concentrate on it helped by a magic set of cards. You can immediately read their collective mind and tell them the number instantly.

This trick uses the same representation of numbers as the one computers actually use: binary.

PAUSE: Gottfried Leibniz

Chapter 29 :

On the Powers of Numbers /

Representing other things by numbers

A volunteer picks a postcard from a selection. Your partner magician, who is out of the room at the time, can immediately say which card was touched.

All sorts of things can be represented by numbers and once they are we can bring them in to the digital world, as those numbers in turn can be represented by binary.

Interlude: Luca Pacioli 

Chapter 30 :

The Out-of-Body Experience /

Error correcting codes

A grid of face up and face down cards is set up at the front of the room by a volunteer. Blindfolded at the back the whole time, you can still later say which card was turned over.

A more advanced data representation is that of the error correcting code. This kind of data representation allow mistakes to be detected and even corrected automatically.

Interlude: Tim Bell

Section 8 :

Human Computer Interaction

We turn to the presentation side of tricks and the importance of understanding people (i.e., cognitive psychology) in more depth. In computing terms this is about usability and user experience.

Chapter 31 :

Four Aces /

Usability and attention

You deal out hands of cards containing Aces. From the way they have landed, one in each pile, everyone can see that on the next deal they will all end up in the volunteer’s hand. Somehow you manage to steal them without anyone seeing to get the perfect hand yourself.

Magicians control your attention, making you miss things that would give the trick away. When designing the interface of an interactive computer system, you need to control their attention too, but making sure the user looks in the right place and so sees everything that is important.

Interlude: Gustav Kuhn

Chapter 32 :

Supernatural Suggestion /

Visual salience

You show the audience five cards on the screen, asking everyone to focus their attention on just one of their choice. You, however, have controlled them all, and when you remove a card, it turns out everyone was focussing on that same card.

What you see depends on where you focus your attention and where you focus your attention depends partly on how salient the things in the scene are. If you want important things to be seen on a screen then you have to make them visually salient.

PAUSE: Peter W McOwan

Chapter 33 :

The Numbers Game /

Visibility of system state

A member of the audience calls out ten random numbers that you write on different pieces of paper. A volunteer picks one at random. Amazingly, you tell them the number on the piece of paper they picked.

A key to a good trick is that the audience lose track of actually what is happening. They think the state of the magical system is one thing, when actually it is something else. Visibility of the system state is an important interaction design principle in software. Users need sufficient feedback to track the internal state of the system. Planes have crashed when this has been done badly and software has behaved like a trick! 

PAUSE:  Don Norman and Jakob Nielsen

Chapter 34 :

The Three Way False Cut /

Conceptual models and metaphors

You cut the cards twice then reform the pack. Unknown to the audience the pack is completely unchanged from before the cuts.

A good design needs a clear conceptual model that leaves the user in no doubt what is happening. A good magic trick does the opposite obfuscating what is happening so the audience thinks the wrong thing is happening.

Interlude: Jay Ose

Chapter 35 :

Joker in the Pack /

Memory

A volunteer thinks of a number and deals out that number of cards. In doing so they have brought the only joker in the pack to the top of the deck.

Our working memory is very limited. Give it too much to remember and we start to forget things. Magicians rely on this. Interaction Designers must avoid it.

PAUSE:  The Xerox Parc Team

Chapter 36 :

Are You Psychic /

User experience and engineering delight 

You test a member of the audience for super powers. Can they, without seeing any of the values on the cards end up with a matching pair?

Usability is about whether a system is easy to use. Just as a magician wants more than a trick just working, appearing magical, interaction designers also go further than just ease of use. Magicians show how User Experience can be designed into a system.

Interlude: Fay Presto

Section 9 :

Evaluation & Logical Thinking II 

In this section, we look at more advanced logical thinking including real-world (and magical-world) uses of algebra.

Chapter 37 :

Are You Psychic (continued) /

Inductive proof and loop invariants

How can we be sure that our volunteer will have the apparent superpowers so that the previous trick definitely will work?

The idea of a loop invariant provides the basis of the logical reasoning about repetition.

Interlude:  Adelaide Herrmann

Chapter 38 :

The Red-Black Mind Meld /

Algebra and proof

You are able to meld your mind with that of a volunteer, controlling their choice of cards to make sure a property you predict holds once all the cards are dealt.

Rigorous argument is one way to convince ourselves that an algorithm (or trick) works, but we can go a step further and use algebra. We describe the algorithm with maths, do some algebra on the result and so prove desirable properties hold. This is a vital way to check safety-critical software is correct.

PAUSE: Shafi Goldwasser

Section 10 :

More Advanced Computational Thinking

We now look at some more advanced forms and uses of computational thinking: of generalisation, decomposition and data representation.

Chapter 39 :

The Doomsday Clock /

Generalisation

The doomsday clock predicts the most important hour in a person’s life. A volunteer has a free choice of a starting number but still the clock stops at the hour predicted for them. 

Having worked out a principle (the mathematics underlying a trick) we can use it to make a more general principle that can then be used to design apparently different tricks that underneath rely on the same maths. We can generalise code in a similar way, allowing it to be used in wider situations.

PAUSE:  John von Neumann

Chapter 40 :

Free My Three /

Divide and conquer

Three cards of a kind, chosen by a volunteer, are lost in the pack. You discard cards repeatedly with no sign of them, until eventually they turn up … the very last cards to be revealed.

Decomposition involves breaking a problem into one or more smaller problems that are easier to solve. Divide and conquer is a powerful version of this where these smaller problems are the same problem as the original (just smaller). Those smaller problems are solved in the same way. This gives a way to create very fast algorithms.

Interlude: Alex Elmsley

Chapter 41 :

The Double Destination Deception /

Data representation: graphs and cycles

A volunteer takes a series of tickets to plan a trip of a lifetime kris-crossing the world. Despite their free choice of route, once done you reveal the you bought in advance precisely the ticket they need to get back from their final destination to their start point.

An important data structure is the graph, and one of the most important problems in computer science involves creating a cycle (i.e., a round trip) through a graph. A famous puzzle about the bridges of Königsberg kick-started the whole idea of graph representations.

Interlude: Dynamo

Section 11 :

Cyber Security and Privacy

There are overlaps between magic tricks and concepts from cybersecurity. Many magic tricks are about the magician having information the audience think they cannot possibly have obtained. Cybersecurity and privacy are concerned with how to prevent such information leakage.

Chapter 42 :

Sniff Out That Card /

Steganography

A volunteer chooses a card and holds it to their chest. They hide it back in the pack, but you can sniff it out from the faint trace of their scent left on it because they held it close.

Steganography is a way of hiding secret messages in apparently innocuous things. What looks like a normal message or image disguises the real thing being communicated. The same idea can be used as the basis of tricks to allow a magician to know information he or she could apparently not possibly know.

PAUSE: Sir Francis Bacon

Chapter 43 :

Classic Mentalism /

Codes and ciphers

Your partner magician leaves the room while a card is chosen. Despite not being there at the time, when they return they can say exactly which card was chosen.

Classic mentalism tricks involve secret codes between participants. Similar codes based on code books have been the basis of algorithms for sharing secret messages for as long as people have wanted to share secrets.

Interlude: Reginald Scot

Chapter 44 :

Call the Clairvoyant /

Legitimate channels

A card is chosen from a pack. You phone your friend, the mysterious ‘Clairvoyant’, and when you ask them to do so, they tell the volunteer which card was chosen. 

Computer systems are kept secure by having separate areas with different security levels. Nothing from a high security area should be able to leak to a lower security area. Hiding information in a legitimate channel (an allowed way to communicate), is one way information might be leaked. Hackers exploit legitimate channels in computer systems. Magicians build tricks around leaking information via legitimate channels too.

Interlude: Sydney and Lesley Piddington

Chapter 45 :

Call the Clairvoyant a Second Time /

Covert channels

An object from a table of objects is chosen and the mysterious ‘Clairvoyant’ is called. They are put straight on to speaker phone so everything can be heard by all. They can name the object chosen.

Sometimes information is leaked via a legitimate channel. Another way is to set up a covert channel: a way of communicating that is not supposed to be there. Hackers exploit covert channels in computer systems. Magicians also build tricks around them.

PAUSE: Hedy Lamarr

Chapter 46 :

Reading a Personality with Hot Chocolate /

Big data and privacy

After stirring it three times, a volunteer drinks a small cup of hot chocolate you make them. You read their personality in the sludge left in the bottom of the cup.

Horoscopes and some personality tests rely on a kind of fakery. Big Tech companies rely on a different kind of fake personality test, gathering as much data as they can about those who use their services. They then make judgements about what kind of person they are and sell the information to advertisers or political parties who exploit this intimate ‘knowledge’ of you to sway opinions.

Interlude: Barnum

Chapter 47 :

The Chevreul Pendulum /

Ethics

A volunteer holds a pendulum made from an old magical key. You ask them questions and the pendulum, controlled by the spirit world, swings to give the answers.

People mainly use magic for entertainment but some use it unethically to con people. Likewise computing skills can be used ethically or unethically. Many magicians debunk frauds exposing the tricks they are using. Some hackers, called white hat hackers do a similar thing. They are employed by companies to attack the company’s own systems, to protect them against black hat hackers, who can, intentionally or otherwise, cause lots of damage. All professional computer scientists are required to study ethics.

Interlude: Randi

Section 12 :

Advanced Technology

Many magic tricks rely on technology to provide the effects. Here are just a few ways such computing-linked technology has formed the basis of tricks.

Chapter 48 :

The Faerie Cage /

Augmented reality

You reveal to the audience that faeries are not only real but you have trapped one in your special rowan-lined box. 

A Victorian invention for theatre, Pepper’s Ghost, forms the basis of both illusions and early versions of augmented reality where the real and virtual worlds mix.

Interlude: John Henry Pepper and Henry Dircks

Chapter 49 :

The Down-Under Deal and Robotic Reveal /

Robots

You do the special down-under deal, ending with a card on the table that no one could have predicted. Despite that, as the card is shown to the audience your helper, a robot, appears from down under the table to reveal that it knew what the card would be.

The final reveal can make a trick extra-special. Automata, the precursors of robots, have long been used as props for tricks. Here a robot is revealed to have magically forced the card that was finally selected. Robots are now being used in workplaces and homes, in dangerous environments to make them safe and as killers.

PAUSE:  Ismail al-Jazari

Chapter 50 :

The One True Sovereign /

Curtain call & creativity

Who is the one true King or Queen of Britain? You have found a long lost magical artefact that can reveal the answer.

We finish with a summary of the main links between conjuring and computing, and reveal one last trick (about authentication).

Interlude: Richard Garriott

Home

Design a site like this with WordPress.com
Get started