title: How to interpret moreover and a series like Y1,. . . ,Yn in prolog program
body: <p>For my exercise I have this program. Consider the following Prolog program, which realizes simple terms built from variables and the function symbol <code>plus</code>.</p>
  
  <pre><code>variable(x).
  variable(y).
  term(X) :- variable(X).
  term(plus(X,Y)):- term(X), term(Y).
  </code></pre>
  
  <p>a) Implement a predicate <code>uses(TERM, A)</code> in Prolog which is true iff <code>TERM</code> is a term built with <code>plus</code> and <code>A</code> is an argument of the outermost <code>plus</code> symbol of <code>TERM</code>, i.e., <code>term(TERM)</code> is true and, moreover, <code>TERM = plus(A,_)</code> or <code>TERM = plus(_,A).</code></p>
  
  <p>b) Implement a predicate <code>contains(TERM, X)</code> in Prolog which is true iff <code>TERM</code> is a term built with <code>plus</code> and <code>X</code> is a subterm of <code>TERM</code>. In other words, <code>contains(TERM, X)</code> is true iff <code>uses(TERM, X)</code> is true or if
  there are <code>n &gt; 0</code> elements <code>Y1,. . . ,Yn</code> such that the following statements are true:</p>
  
  <pre><code>• uses(TERM,Y1)
  • uses(Yn,X)
  • uses(Yi−1,Yi) for all i ∈ {2, . . . , n}.
  </code></pre>
  
  <p>Make sure that the evaluation of all queries <code>?- contains(t1,t2)</code> terminates if <code>t1</code> and <code>t2</code> are ground terms.</p>
  
  <p>So far I have come up with the following solutions:</p>
  
  <p>a) <code>uses(TERM, A) :- term(TERM), (TERM=plus(A,_); TERM=plus(_,A)).</code></p>
  
  <p>I am confused here whether this solution is correct. In the question they used "moreover" and for this I kept <code>TERM</code> in first bracket like this <code>(TERM=plus(A,_); TERM=plus(_,A))</code>. Is this correct?</p>
  
  <p>b) </p>
  
  <pre><code>contains(TERM, X) :- uses(TERM, X).
  contains(TERM, X) :- uses(TERM, I), contains(I,X).
  </code></pre>
  
  <p>well I am confused here whether my answer is correct or not. I don't know how to interpret a series like <code>Y1,. . . ,Yn</code> in Prolog. </p>