  Biological organisms have evolved a wide range of immune mechanisms to defend
themselves against pathogens. Beyond molecular details, these mechanisms differ
in how protection is acquired, processed and passed on to subsequent
generations -- differences that may be essential to long-term survival. Here,
we introduce a mathematical framework to compare the long-term adaptation of
populations as a function of the pathogen dynamics that they experience and of
the immune strategy that they adopt. We find that the two key determinants of
an optimal immune strategy are the frequency and the characteristic timescale
of the pathogens. Depending on these two parameters, our framework identifies
distinct modes of immunity, including adaptive, innate, bet-hedging and
CRISPR-like immunities, which recapitulate the diversity of natural immune
systems.
