Subscriber OnlyScience

A conversation between Johann Sebastian Bach and Leonhard Euler with the help of ChatGPT

That’s Maths: ‘I have learned much today, and I am grateful for the opportunity to exchange ideas with such a brilliant mind’

Frederick the Great of Prussia, a devoted patron of the arts, had a particular interest in music and admired the music of Johann Sebastian Bach. In 1747, Bach visited Potsdam, where his son Carl Philipp Emanuel was the kapellmeister in Frederick’s court. When Frederick learned of this, he summoned “Old Bach” to the palace and invited him to try out his collection of pianofortes. As they went from room to room, Bach improvised a new piece of music on each instrument.

Bach asked the king to give him a musical theme and, on the spot, developed it into a three-part fugue. The next day he was taken on a tour of all the organs in Potsdam. Upon returning to Leipzig, Bach developed Frederick’s theme into a six-part fugue and sent it to the king with a flattering letter that opened: “In deepest humility I dedicate herewith to Your Majesty a musical offering, the noblest part of which derives from Your Majesty’s own august hand.”

The brilliant Swiss mathematician Leonhard Euler spent 20 years at the Prussian Academy of Sciences in Potsdam. Euler had earlier written a book on the mathematical theory of music. Bach too was fascinated by the relationship between mathematics and music; undoubtedly, the two savants would have had many common interests and much to discuss. A recent authoritative biography of Euler by Ronald Calinger makes no mention of any meeting between them, but it is intriguing to speculate on how they might have interacted.

AI to the Rescue

ChatGPT is in the news (GPT means generative pre-trained transformer). This chatbot, launched recently by OpenAI, can answer questions, write student essays and computer programs, and, it is claimed, write poetry and song lyrics. It can mimic human conversation and its output can be difficult to recognise as artificially produced.


I asked the chatbot to generate a conversation between Euler and Bach. Neither music nor maths were mentioned in the request. In less than a minute, out came a short article that was fluent and coherent if somewhat lacklustre. The content of this “meeting of minds” is distilled below.

After warm greetings, Bach remarked that he had always been fascinated by mathematics and its relationship to music, and the almost magical way in which they are intertwined. He was familiar with Euler’s book, which showed how the principles of harmony and counterpoint are expressed mathematically as ratios and proportions, and musical scales and chord progressions can be analysed using group theory and number theory.

Euler proposed that his mathematical formulas could provide a framework for composing. For example, the structure of a fugue can be analysed mathematically, with each voice and counterpoint having its own unique rhythm and structure. But Bach observed that music must have emotion and expressiveness, otherwise it is just a collection of mathematical patterns. Mathematics and music must work together to produce a beautiful and meaningful composition.

The two men discussed the Pythagorean tuning system, based on whole number ratios. They also discussed the equal temperament system, in which all semitones have the same frequency ratio, allowing for a more uniform distribution of musical intervals. Finally, it was time for Bach to leave, and he concluded, “I have learned much today, and I am grateful for the opportunity to exchange ideas with such a brilliant mind.”

  • Peter Lynch is emeritus professor at the School of Mathematics & Statistics, University College Dublin – He blogs at