The thought experiment is known as Chrysippus’s Dog and goes back to the named ancient Stoic. It was discussed by many modern philosophers, including Dennett, see Chrysippus’s Dog as a Case Study in Non-Linguistic Cognition by Rescorla for a survey. Here is the description of Chrysippus's dog given by Sextus Empiricus:
"[Chrysippus] declares that the dog makes use of the fifth complex indemonstrable syllogism when, on arriving at a spot where three ways meet…, after smelling at the two roads by which the quarry did not pass, he rushes off at once by the third without stopping to smell. For, says the old writer, the dog implicitly reasons thus: “The animal went either by this road, or by that, or by the other: but it did not go by this or that, therefore he went the other way.”"
There is a controversy as to what Chrysippus meant by "implicitly reasons", as well as to what actually happens in real dogs. The two extreme positions are Cartesian and Humean. According to the former, the "implicit reasoning" is an instrumental metaphor, something reflexive that looks as if it was reasoned, for actual reasoning requires language. Dennett and Davidson are in this category, Sorabji even argued that Chrysippus himself advocated the same. According to the latter, the difference between non-linguistic and linguistic reasoning is a matter of degree, not principle. Dennett considers the scenario in Kinds of Minds, and attributes the "inference" to our antropomorphic "intentional stance":
"So we find that when we interpret his
behavior from the intentional stance, we do well to attribute beliefs to Argos that
distinguish Ulysses from other people, strong rival dogs from weaker rival dogs,
lambs from other animals, Ithaca from other places, and so forth. But we must
be prepared to discover that this apparent understanding of his has shocking
gaps in it--gaps inconceivable in a human being with our conceptual scheme,
and hence utterly inexpressible in the terms of a human language.
Tales of intelligence in pets have been commonplace for millennia. The ancient
Stoic philosopher Chrysippus reported a dog that could perform the following
feat of reason... People are less fond of telling tales
of jawdropping stupidity in their pets, and often resist the implications of the
gaps they discover in their pets' competences. Such a smart doggie, but can he
figure out how to unwind his leash when he runs around a tree or a lamppost? ...As researchers regularly discover, the more
ingeniously you investigate the competence of nonhuman animals, the more
likely you are to discover abrupt gaps in competence. The ability of animals to
generalize from their particular exploitations of wisdom is severely limited."
He then gives a reference to an "eye-opening" ethological study of velvet monkeys, Cheney and Seyfarth, How Monkeys See the World. Rescorla, for his part, uses Tolman's theory of cognitive maps (see Kitchin, Cognitive maps: what are they and why study them? for a modern review) to chart a middle path: dogs have non-linguistic cognitive structures that do not carry logical form, not even "implicitly", but can support rudimentary Bayesian inference. Other empirical studies include Allen, Transitive inference in animals, Blaisdell et al., Causal Reasoning in Rats, Penn and Povinelli, Causal cognition in humans and non-human animals, etc. More can be found in Beck's survey Do Animals Engage in Conceptual Thought?
But part of the problem is that it is set up in a way not amenable to empirical studies, how do we distinguish a bona fides inference from an as-if that looks like it for all intents and purposes? It turns on one's favored interpretation and is not really empirical. A recent Cambridge volume The Philosophy of Animal Minds is a comprehensive source on related issues.