Mock theta functions were introduced by Ramanujan in his famous last letter to Hardy in 1920 but were properly understood only recently with the work of Zwegers in 2002. I will describe three manifestations of this apparently exotic mathematics in three important physical contexts of holography, topology and duality where mock modularity has come to play in important role.

In particular, I will derive a holomorphic anomaly equation for the indexed partition function of a two-dimensional CFT2 dual to AdS3 that counts the black hole degeneracies, and for Vafa-Witten partition function for twisted four dimensional N=4 super Yang-Mills theory on CP2 for the gauge group SO(3) that counts instantons. The holomorphic kernel of this equation is not modular but `mock modular’ and one obtains correct modular properties only after including certain `anomalous’ nonholomorphic boundary contributions. This phenomenon can be related to the holomorphic anomaly of the elliptic genus of a two-dimensional noncompact supersymmetric sigma model, and in a simpler context of quantum mechanics to the Atiyah-Patodi-Singer eta invariant.

Mock modularity is thus essential to exhibit modular symmetries expected from the AdS3/CFT2 holographic equivalence in quantum gravity and the S-duality symmetry of four-dimensional quantum gauge theories.