%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% CS2LAP: Logic and Prolog 2000/2001                         %
% Implementation of a Goal-directed Theorem Prover in Prolog %
% Ulle Endriss, King's College London, endriss@dcs.kcl.ac.uk %
%                                                            %
%           *** Partially Finished Version ***               %
%                                                            %
% File: auxiliary.pl                                         %
% Purpose: implement the auxiliary predicates add/3 and      %
%   conj2list/2                                              %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


% Note: You don't have to make any changes to this file.


% Add an element to a list, if it is not already a member of that
% list. 

add( Element, List, List) :-
  member( Element, List), !.

add( Element, List, [Element | List]).


% Translate a conjunction into a list of formulas. If the first 
% argument of conj2list/2 is instantiated with a term corresponding
% to a conjunction, the variable given in the second argument position
% will be matched with the list of conjuncts of that formula.
%
% Example:
% ?- conj2list( a and b and (c or d), X).
% X = [a, b, c or d]
% Yes 

conj2list( A and B, List) :- !,  % recursion step
  conj2list( A, ListA),
  conj2list( B, ListB),
  append( ListA, ListB, List).

conj2list( A, [A]).              % base case

  




