I know that languages ββlike Prolog let you write things like:
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 back. Suppose I have this:
mortal (X): - man (X).
man (socrates).
man (plato).
man (aristotle).
Then I ask him to give me a random X for which mortal (X) is true (thus, he should give me one of "socrates", "plato" or "aristotle" according to some random seed).
My questions:
- Does this kind of inverse output have a name?
- Are there any languages ββor libraries that support it?
EDIT
As pointed out below, you can just ask the mortal (X), and he will return all X from which you can simply select a random one from the list. What if, however, this list is very large, possibly in billions? Obviously, in this case, he would not do to generate every possible result before choosing it.
To understand 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 lists of adjectives, nouns, verbs, etc. Very large, you can see how a combinatorial explosion is a problem. If there were 1000 words in each list, you would have 1000 ^ 6 possible sentences.
source share