title: Prolog - formulas in propositional logic
body: <p>I am trying to make a predicate in order to validate if a given input represents a formula.</p>
  
  <p>I am allowed to use only to propositional atoms like p, q, r, s, t, etc.
  The formulas which I have to test are the following:</p>
  
  <pre><code>neg(X) - represents the negation of X  
  and(X, Y) - represents X and Y  
  or(X, Y) - represents X or Y  
  imp(X, Y) - represents X implies Y  
  </code></pre>
  
  <p>I have made the predicate <code>wff</code> which returns true if a given structure is a formula and false the otherwise. Also, I don't have to use variables inside the formula, only propositional atoms as mentioned bellow.</p>
  
  <pre><code>logical_atom( A ) :-
      atom( A ),     
      atom_codes( A, [AH|_] ),
      AH &gt;= 97,
      AH =&lt; 122.
  
  wff(A):-
      \+ ground(A),
      !,
      fail.
  
  wff(and(A, B)):-
      wff(A),
      wff(B).
  
  wff(neg(A)):-
      wff(A).
  
  wff(or(A, B)):-
      wff(A),
      wff(B).
  
  wff(imp(A, B)):-
      wff(A),
      wff(B).
  
  wff(A):-
      ground(A),
      logical_atom(A),
      !.
  </code></pre>
  
  <p>When i introduce a test like this one,
  <code>wff(and(q, imp(or(p, q), neg(p)))).</code>, the call returns both the <code>true</code> and <code>false</code> values. Can you please tell me why it happens like this? </p>