An oft-repeated goal in many contexts is the "preservation of diversity." But what is the diversity function to be optimized? This paper shows how a reasonable measure of the "value of diversity" of a collection of objects can be recursively generated from more fundamental information about the dissimilarity-distance between any pair of objects in the set. The diversity function is shown to satisfy a basic dynamic programming equation, which in a well-defined sense generates an optimal classification scheme. A surprisingly rich theory of diversity emerges, having ramifications for several disciplines. Implications and applications are discussed.