We propose and test two possible explanations of envy and its opposite, gloating. One explanation views them as a learning process, just as regret and rejoice are in the private domain: envy is the social correspondent of regret. The other explanation traces envy back to the natural tendency of individuals to seek higher positions in the social ranking, that is a dominant position, a tendency with very strong evolutionary motives. We show experimentally that these two functional reasons for envy coexist. Competition is the product of the desire for dominance, rather than the artificial output of social arrangements.