I am trying to make a predicate in order to validate if a given input represents a formula.
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:
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  
I have made the predicate wff 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.
logical_atom( A ) :-
    atom( A ),     
    atom_codes( A, [AH|_] ),
    AH >= 97,
    AH =< 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),
    !.
When i introduce a test like this one,
wff(and(q, imp(or(p, q), neg(p))))., the call returns both the true and false values. Can you please tell me why it happens like this?