title: How to find facts that do not have contribution in goal
body: <p>I'm trying to write a program that can check if the student program can fulfill a certain goal or not. I can do that part. Now, I want to check if the student program actually contains unnecessary code or not. For solving this case, I think I need to know if the student program contains facts that do not contribute to the specified goal. However, I cannot figure it out, how to find facts that do not contribute to the goal. </p>
  
  <p>To make it easier to understand, let's consider a simpler example. In this example, the specified goal is: is john the grandfather of tomy?</p>
  
  <pre><code>father(john, jim).
  father(jim, tomy).
  father(john, david).
  father(bruce, anne).
  mother(mary, jim).
  
  grandfather(A,B) :- father(A, X), father(X,B).
  
  goal:- grandfather(john, tomy).
  </code></pre>
  
  <p>Actually the goal can be satisfied by the following facts only:</p>
  
  <pre><code>father(john, jim).
  father(jim, tomy).
  </code></pre>
  
  <p>And the things that I want to know is which facts that actually do not contribute to the goal. The answer would be all the following facts:</p>
  
  <pre><code>father(john, david).
  father(bruce, anne).
  mother(mary, jim).
  </code></pre>
  
  <p>Any help is really appreciated.
  Thanks</p>