I am aware that languages like Prolog allow you to write things like the following:
mortal(X) :- man(X). % All men are mortal man(socrates). % Socrates is a man ?- mortal(socrates). % Is Socrates mortal? yes
What I want is something like this, but backwards. Suppose I have this:
mortal(X) :- man(X). man(socrates). man(plato). man(aristotle).
I then ask it to give me a random X for which mortal(X) is true (thus it should give me one of 'socrates', 'plato', or 'aristotle' according to some random seed).
My questions are:
- Does this sort of reverse inference have a name?
- Are there any languages or libraries that support it?
EDIT
As somebody below pointed out, you can simply ask mortal(X) and it will return all X, from which you can simply pick a random one from the list. What if, however, that list would be very large, perhaps in the billions? Obviously in that case it wouldn't do to generate every possible result before picking one.
To see how this would be a practical problem, imagine a simple grammar that generated a random sentence of the form "adjective1 noun1 adverb transitive_verb adjective2 noun2". If the lists of adjectives, nouns, verbs, etc. are very large, you can see how the combinatorial explosion is a problem. If each list had 1000 words, you'd have 1000^6 possible sentences.