The goal of the proposed research is to develop a mathematical theory of the relationship between attention and memory, to explain how attention controls the flow of information into and out of memory, and how memory influences what is attended and how it is attended. The theory is a combination of two previous theories, one addressing attention and one addressing memory retrieval. Both of previous theories focus on the speed of processing. The attention theory argues that different stimuli in the world `race` to become objects of attention. The first one to finish the race captures attention. The retrieval theory is similar, arguing that different traces in memory race to become the one to be retrieved. The first one to finish gets retrieved. The new theory combines these two approaches, interpreting them as different perspectives on the same process. The new theory makes quantitative predictions about the speed of processing and the probability of responding in a number of domains, including attention, memory, and categorization. It is significant because it integrates previous approaches, building on their successes, and providing an integrated theory of a large part of human cognition.