A Mathematical Model of Complexity and Its Application to Chemotaxis