A Mathematician's Apology is a 1940 essay by British mathematician G. H. Hardy. It concerns the aesthetics of mathematics with some personal content, and gives the layman an insight into the mind of a working mathematician.
In the book's title, Hardy uses the word "apology" in the sense of a formal justification or defence (as in Plato's Apology of Socrates), not in the sense of a plea for forgiveness.
Hardy felt the need to justify his life's work in mathematics at this time mainly for two reasons. Firstly, at age 62, Hardy felt the approach of old age (he had survived a heart attack in 1939) and the decline of his mathematical creativity and skills. By devoting time to writing the Apology, Hardy was admitting that his own time as a creative mathematician was finished. In his foreword to the 1967 edition of the book, C. P. Snow describes the Apology as "a passionate lament for creative powers that used to be and that will never come again". In Hardy's words, "Exposition, criticism, appreciation, is work for second-rate minds. [...] It is a melancholy experience for a professional mathematician to find himself writing about mathematics. The function of a mathematician is to do something, to prove new theorems, to add to mathematics, and not to talk about what he or other mathematicians have done."
Secondly, at the start of the World War II, Hardy, a committed pacifist, wanted to justify his belief that mathematics should be pursued for its own sake rather than for the sake of its applications. He wanted to write a book in which he would explain his mathematical philosophy to the next generation of mathematicians; that would defend mathematics by elaborating on the merits of pure mathematics solely, without having to resort to the attainments of applied mathematics in order to justify the overall importance of mathematics; and that would inspire the upcoming generations of pure mathematicians. Hardy was an atheist, and makes his justification not to God but to his fellow man.
One of the main themes of the book is the beauty that mathematics possesses, which Hardy compares to painting and poetry. For Hardy, the most beautiful mathematics was that which had no practical applications in the outside world (pure mathematics) and, in particular, his own special field of number theory. Hardy contends that if useful knowledge is defined as knowledge which is likely to contribute to the material comfort of mankind in the near future (if not right now), so that mere intellectual satisfaction is irrelevant, then the great bulk of higher mathematics is useless. He justifies the pursuit of pure mathematics with the argument that its very "uselessness" on the whole meant that it could not be misused to cause harm. On the other hand, Hardy denigrates much of the applied mathematics as either being "trivial", "ugly", or "dull", and contrasts it with "real mathematics", which is how he ranks the higher, pure mathematics.