Well-crafted love songs can be the ticket to fun times and reproductive success, whether you are a member of the Beatles or one of the many animals that woo their mates by singing. Although some troubadours serve up monotonous repetitions of stereotyped songs, most animals, including birds, mammals and insects, like to jazz things up by varying their song patterns. But how the brain generates such variability, and improvisation more generally, remains largely a mystery. On page 233, Coen et al.1 shed light on this issue by showing that much of the variability in the love songs of fruit flies can be predicted from the singers' movements.

Neuroscientists' fascination with the sex life of the fruit fly Drosophila melanogaster began more than 35 years ago with the discovery of fruitless, a gene essential for the male courtship ritual2. This unique handle on a complex social behaviour, in an organism amenable to genetic modification, paved the way for an exceedingly detailed anatomical mapping of the underlying neural circuitry3,4. Deciphering the details of what these circuits do and determining what they can teach us about brain function more broadly are major challenges that would be greatly helped by having a comprehensive description of the computations that the circuits perform and the behaviours they implement.

One thing that we know these circuits do is transform their male owners into mini Casanovas. On encountering a receptive virgin female, a male fly will gently tap her rear end, serenade her with a 'song' by vibrating one of his wings, and lick her genitalia5. Although these behaviours are part of any self-respecting fly's lovemaking repertoire, the duration and ordering of the different courtship elements can be highly unpredictable. What gives rise to such seemingly random behaviour? Is the variability due to stochastic fluctuations in the underlying neural networks (neural noise)6,7, or the result of a dynamic sensory experience?

To address these questions, Coen and colleagues focused on the male fly's song, itself a variable sequence of distinct elements1,8. Just as the Beatles made a career of mixing 'love', 'you', 'me', 'she' and 'baby' in different ways, so male fruit flies switch between 'sine' and 'pulse' songs to impress their audience (Fig. 1). By eavesdropping on more than 100,000 love songs while carefully monitoring the whereabouts of the courting couple, the authors suggest that a logic and order exist in the apparent musical randomness.

Figure 1: The male fruit fly's serenade.
figure 1

a, Male fruit flies attract females by vibrating one of their wings. b, The fly has two distinct song types — the humming sine song and the purring pulse song — and switches between them to generate variable song sequences. Coen et al.1 found that these switches can be predicted by the fly's movements. (Data depicted in b taken from Fig. 6 of ref. 11.)

Coen et al. performed a statistical analysis of their high-resolution behavioural data, and found that transitions between sine and pulse songs can be predicted from the courted female's movements. The authors further discovered that the male's visual experience of the female shapes his song through neural circuits that control locomotion. In fact, the best predictor of song structure is not the female's movements, but the singer's own. Even blind flies, who are induced to sing by the scent of virgin females, show a bias in their song transitions that can be predicted from their movements. The picture that emerges from all of this is one in which the male fly executes a tightly integrated song-and-dance number, inspired by (if he can see her) his partner's movements.

As impressive as that may be, the extent to which the female cares about the details of her lover's intricate performance remains unclear. Does she use information embedded in his song pattern to determine his desirability? Does his ability to couple changes in his song to body movements — his or hers — correlate with other qualities that she would want in a mate? In other words, is song patterning an example of a carefully tuned signalling system, or does it reflect a coupling between leg and wing movements that evolved for unrelated reasons?

Initial experiments to address these questions have failed to provide clear answers. Coen et al. show that song transitions are similar whether or not the singer is ultimately successful in mating. Yet pheromone-insensitive males, who sing for normal durations but have altered song patterning8, tend to be slower and less successful in convincing females to mate1,8. Whether these flies are handicapped in the courting game because of a defect in how they vary their songs, or because of unrelated effects, remains to be seen. But whether song patterning matters to females or not, we now know that its variability, and probably the variability of many other 'fixed' behaviours, is not simply the consequence of noise in nervous-system function6,7. Rather, a sizeable fraction of that variability is likely to reflect computations performed by reliable and predictable brains on an ever-changing sensory environment.

Importantly, this insight was made possible by simultaneously observing, at high temporal resolution, the sensory environment and behavioural output of a genetically tractable organism during a complex social interaction. Such detailed analysis applied to natural behaviours has the power, as Coen et al. aptly demonstrate, to distil seemingly complex and unpredictable behavioural patterns into simple rules and sensorimotor transformations9,10. With such an approach, rather than being the fog that prevents us from understanding nervous-system function, behavioural variability and complexity can be the searchlight that helps us to identify the computational problems that brains evolved to solve.