Magicians have long relied on sleight of hand and deception to thrill their audiences, but they may now have another tool in their box of tricks - a computer.

Scientists have for the first time "taught" a computer to create magic tricks, using artificial intelligence (AI).

They gave a computer program the outline of how a magic jigsaw puzzle and a mind-reading card trick work, and fed into it the results of experiments into how humans understand magic tricks.

The program created completely new variations of those tricks using complex mathematical techniques and algorithms, but which can still be performed by a magician.

The work could make tricks easier for budding magicians, but researchers also believe their work could benefit future medical science.

One trick involves assembling a jigsaw to show a series of shapes, then taking apart and putting it back together again so that certain shapes disappear, caused by a clever principle of geometry.

The trick relies on several factors coming into play simultaneously, such as the size of the puzzle, the number of pieces involved, the number of shapes that appear and disappear and the ways that the puzzle can be arranged.

A second "mind-reading" trick involves identifying a card that has been selected from a deck using a few seemingly innocuous pieces of information from the audience and using a mobile phone application to reveal the card on the phone's screen.

The computer program was used to arrange the decks in such a way that a specific card could be identified with the least amount of information possible.

It identified arrangements for the deck that, on average, required one less question to be asked before the card was identified than using traditional methods, with the app avoiding the magician having to remember the order of the cards.

Howard Williams, a member of the research team at Queen Mary University of London, said the computer program brought together existing mathematical principles to create a new variation on a trick, in much the same way that an author might twist traditional plots and characters to come up with a new story.

He said: "Computer intelligence can process much larger amounts of information and run through all the possible outcomes in a way that is almost impossible for a person to do on their own.

"So while a member of the audience might have seen a variation on this trick before, the AI can now use psychological and mathematical principles to create lots of different versions and keep audiences guessing."

He said that the findings of the research, around people's psychological "deception", could in future inform designs for medical devices to help eradicate any possibilities of deception and make them "foolproof" for those using them.

Professor Peter McOwan, who also worked on the project, added: "Using AI to create magic tricks is a great way to demonstrate the possibilities of computer intelligence and it also forms a part of our research in to the psychology of being a spectator.

"For example, we suspected that audiences would be suspicious of the involvement of technology in the delivery of a trick but we've found out that isn't the case."

The research is published in the journal Frontiers In Psychology.

The card trick is available as an app called Phoney, from the Google Play Store.

Sign up to our free newsletters

Get the best updates straight to your inbox:
Please select at least one mailing list.

You can unsubscribe at any time by clicking the link in the footer of our emails. We use Mailchimp as our marketing platform. By subscribing, you acknowledge that your information will be transferred to Mailchimp for processing.