## Summary

Foraging animals have to locate food sources that are usually patchily distributed and subject to competition. Deciding when to leave a food patch is challenging and requires the animal to integrate information about food availability with cues signaling the presence of other individuals (e.g. pheromones). To study how social information transmitted via pheromones can aid foraging decisions, we investigated the behavioral responses of the model nematode *Caenorhabditis elegans* to food depletion and pheromone accumulation in food patches. We experimentally show that animals consuming a food patch leave it at different times and that the leaving time affects the animal preference for its pheromones. In particular, worms leaving early are attracted to their pheromones, while worms leaving later are repelled by them. We further demonstrate that the inversion from attraction to repulsion depends on associative learning and, by implementing a simple model, we highlight that it is an adaptive solution to optimize food intake during foraging.

## Footnotes

Lead contact: Jeff Gore gore{at}mit.edu

↵

^{1}In general, we have*g*(*t*) =*Ca*_{i}(*t*), where*C*is a constant. But we simply amounts to re-scaling the units of time).↵

^{2}2 Proof: If*m*_{i}worms occupy a patch, and each worm feeds at a rat a rate . Assuming that mi remains constant over time, the*a*(*t*) =*A*_{0}*e*^{−mt}, where*A*_{0}is the initial food density.↵

^{3}Proof: . This is always negative as long as*A*>*g*_{D}, because*N*is always positive and all terms inside the sum are squared.↵

^{4}We assume that the population is large enough so that a single mutant does not alter the distributions significantly.↵

^{5}**Proof:**, where Δ*n*_{i}is defined as in Equation (3), and we define . We will show first that Δ*n*_{i}and*α*_{i}are perfectly anticorrelated (i.e. if Δ*n*_{i}> Δ*n*_{j}, then*α*_{i}<*α*_{j}for any*i*,*j*). Then, we will show that this implies that must be negative.**Δ**Both Δ*n*_{i}and*α*_{i}are perfectly anticorrelated:*n*_{i}and*α*_{i}depend on*n*_{i}. Let’s see that their derivatives with respect to it have opposite signs: From Equation (3), , so it’s positive. From Equation (1), , so has the same sign as . Given that and are always positive, this has the same sign as , which is always negative (it’s zero for*m*_{i}= 0, and as long as*t*_{S}≥ 0 and*m*_{i}≥ 0, which is always true. Therefore, is always negative.**is always negative:**Let’s split the sum, separating the terms according to the sign of Δ*n*_{i}: . Now, given that all the Δ*n*_{i}in the first sum are greater than all the Δ*n*_{i}in the second, and that Δ*n*_{i}and*α*_{i}are perfectly anticorrelated, all the*α*_{i}in the first sum must be smaller than all the*α*_{i}in the second. Therefore, we can find a number*α*_{0}which is in the middle of the two groups of*α*_{i}, so that ,