<p>This is called &quot;abduction&quot;.</p>
<p>For the view from philosophical logic, <em>Stanford Encyclopedia of Philosophy</em> offers this entry: <a href="https://plato.stanford.edu/entries/abduction/" rel="nofollow noreferrer">Abduction</a>.</p>
<p>For the view from logic programming, <em>Wikipedia</em> offers this entry: <a href="https://en.wikipedia.org/wiki/Abductive_logic_programming" rel="nofollow noreferrer">Abductive Logic Programming</a>.</p>
<p>A paper that uses Prolog and <a href="https://en.wikipedia.org/wiki/Constraint_Handling_Rules" rel="nofollow noreferrer">CHR</a> (Constraint Handling Rules) for Abductive reasoning:</p>
<p><strong><em>Henning Christiansen: <a href="https://vision.unipv.it/IA2/aa2006-2007/Abductive%20Reasoning%20in%20Prolog%20and%20CHR.pdf" rel="nofollow noreferrer">Abductive reasoning in Prolog and CHR</a> (PDF): A short introduction for the KIIS course, Autumn 2005.</em></strong></p>
<p>Christiansen refers to the book</p>
<p><strong>Abduction and Induction: Essays on their Relation and Integration</strong>, edited by Peter A. Flach and Antonis Hadjiantonis (Kluwer Academic Publishers, April 2000), <a href="https://rads.stackoverflow.com/amzn/click/com/0792362500" rel="nofollow noreferrer" rel="nofollow noreferrer">Amazon Link</a>, <a href="https://www.researchgate.net/publication/321596989_Abduction_and_Induction_Essays_on_their_Relation_and_Integration/link/5e419ee3a6fdccd9659a13ae/download" rel="nofollow noreferrer">first chapter at researchgate</a></p>
<p>and provides this introductory explainer:</p>
<blockquote>
<p><strong>Deduction</strong>, reasoning within the knowledge we have already, i.e.,from those
facts we know and those rules and regularities of the world that we are
familiar with. E.g., reasoning from causes to effects: <em>If you make a fire
here, you will burn down the house.</em></p>
</blockquote>
<p>In Prolog, the language is structured so as to most naturally find the premise &quot;make a fire here&quot; if your goal happens to be &quot;burn the house down&quot;.</p>
<blockquote>
<p><strong>Induction</strong>, finding general rules from the regularities that we have
experienced in the facts that we know; these rules can be used later for
prediction: <em>Every time I made a fire in my living room, the house burnt
down ... Aha, the next time I make a fire in my living room, the house
will burn down too</em>.</p>
</blockquote>
<blockquote>
<p><strong>Abduction</strong>, reasoning from observed results to the basic facts from which
they follow, quite often it means from an observed effect to produce a
qualified guess for a possible cause: <em>The house burnt down, perhaps my cousin
has made a fire in the living room again.</em></p>
</blockquote>
<p>&quot;Abductive Logic Programming&quot; (ALP) is (used to be?) an active area of research.</p>
<p>Here is a Sprinker Link with <a href="https://link.springer.com/search?query=abductive+logic+programming" rel="nofollow noreferrer">search result</a>.</p>
<p>ALP is a common problem in commonsense reasoning and planning. Examples that come to mind:</p>
<ul>
<li><a href="https://arxiv.org/abs/0906.1182" rel="nofollow noreferrer">The CIFF Proof Procedure for
Abductive Logic Programming with Constraints: Theory, Implementation and
Experiments</a></li>
<li>Robert Kowalski, Fariba Sadri et al. have worked on &quot;LPS&quot; (<a href="http://lps.doc.ic.ac.uk/" rel="nofollow noreferrer">Logic Production
System</a>), which uses ALP (but not by name?) in the
context of the <a href="https://en.wikipedia.org/wiki/Event_calculus" rel="nofollow noreferrer">event calculus</a>
to decide what actions to take to make facts about the world <code>true</code> (wishing
for more details here, I do hope they are editing a book on this).</li>
<li>Contrariwise, Raymond Reiter does not use Prolog but
<a href="https://en.wikipedia.org/wiki/Answer_set_programming" rel="nofollow noreferrer">Answer Set Programming</a>
(which may be more adapted to ALP than the SLDNF approach of Prolog) for
(among others) abductive reasoning in the
<a href="https://en.wikipedia.org/wiki/Situation_calculus" rel="nofollow noreferrer">Situation Calculus</a>.
More on this in the book <a href="https://mitpress.mit.edu/books/knowledge-action" rel="nofollow noreferrer">Knowledge in Action</a> (MIT Press, July 2001).</li>
</ul>
Look for algorithm/research area that determines facts that would make a Prolog query true given a Prolog program
<p>I'm looking for research, algorithms or even terminology for this area of research that take a Prolog program and a query I <em>want</em> to be true and attempt to find the facts that would need to be asserted to make it true.  For example:</p>
<pre><code>% Program
hasProperty(Object, Property) :-
   property(Object, hasProperty, Property).

property(apple, hasProperty, red).
property(car, hasProperty, drivable).
</code></pre>
<pre><code>% Magic function that determines what Facts would make
% query 'hasProperty(lemon, sour)' true
% in the program above
?- whatFacts(hasProperty(lemon, sour), Facts).
Facts = [property(lemon, sour)]

</code></pre>
<p>I'm sure research has been done on this, and certainly it seems unsolvable in the general case, but I'm curious what has been done but am having trouble finding the right terminology to find the work.</p>
<p>Would love any pointers to actual algorithms or names for the area or problem I'm describing.</p>