@Harpo - I love the working out the statistics of carrots vs courgettes by giraffes to get the best outcomes.
I've been reading on Animal Behaviour and Intelligence for years and am convinced of considerably more abilities, and feelings, than most people would attribute to them.
I'd recommend the following books, written by professional animal behaviour academics, which are still readable to non academics.
Alex and Me - Irene Pepperberg. A thirty year study of the intelligence and learning ability of a grey parrot. It is considerably more than I expected, even with my expectations. (Griffin, the parrot mentioned in
@Harpo article was another parrot in the same study as Alex)
Echo of the Elephants: The Story of an Elephant Family (1993) - Cynthia Moss. Who is the founder of the Amboseli Trust for Elephants and the longest continuous running study of a group of elephants.
ATE. Deeply fascinating study that is still ongoing.
There are considerable examples in both those books of not just learned behaviour, but reasoned learned behaviour. (Not monkey see, monkey do, but monkey see, monkey plot, monkey do something effective - except talking parrots and elephants.)
Regarding farm animals, I have some pet sheep. From my own observations, and from talking to friends with sheep, there is a considerable range of intelligence, and feistiness, by breed and by individual. Many of them are not dim at all - but they can be covert. Some are really bright and are working to thwart you - which may cause shouts of "you stupid ****" - but they are not stupid, they are just refusing to do what you want them to, which is not a sign of stupidity.
Some are dim, and some are selected to be dim by the farmer - a friend knows a farmer in their area that deliberately culls any animal that shows signs of intelligence and independence as they cause more work. Keep doing that to a breed and it is a self-fulfilling prophecy.
I think if the world went vegetarian or vegan there would still be farm animals, though far fewer, as there are people who keep farm animals as pets, keep them for conservation grazing including needing chunky hoofs turning over your marsh, and for wool. I would hope there would be a decrease in the number of animals bred as the demand decreased and there would be a gradual and kind transition. However, little though I like the idea, there would also be mass culls as that is common practice. In the last few years there have been mass culls of pigs on farms, due to the lack of Carbon Dioxide for the abattoirs. (One method of killing is immersion and suffocation in a bath of carbon dioxide.) By the time the supply chain problem was sorted, the pigs were too large to fit in the killing baths and the meat processing machines, so they were shot and binned.
I'd also recommend Isabella Tree - Wilding - which has some passing bits of information on the free ranging animals on their farm, especially the chunks on the pigs and some of their behaviours.
Final observation - the British used to be known as a nation of mutton eaters, because we were major wool exporters. Keep flocks of sheep for longish and happy, healthy lives, to produce the best quality wool (if an animal is not being well kept, the wool is far poorer quality). Then when they reach an age where they need more care, where the wool quality might start to drop off, then they start to be eaten. However this is often at least 8 years old, and some tougher individuals will keep going longer. So the sheep gets most of his or her life before being eaten as mutton. But with the advent of artificial fibre, we are using far less wool. Commercial meat sheep are tending to be slaughtered at 6 months to a year, depending on breed, prices, size etc. Lamb used to be a luxury item as you'd be paying for killing an animal before it could produce 8 years worth of wool. There was also a change in consumer preferences as well. More recently there has been a campaign to put mutton back in the shops and on the table, so that there is value in the carcasses of older animals. They do need to be hung for longer than lamb, but they have a far richer flavour, you need two weeks hanging to make sure they aren't tough.