%-----------------------
%William Merryman
%Cheston Williams
%
%cs536 Program 1
%Truth table
%  Makes a truth table from a given
%  boolean expression.
%    table([list of varibles], equation, argument).
%
%-----------------------


%-------
%Given a list of variables, a boolean expression,
%   and a parameter(a, t, f, ex) it creates a 
%   truth table for that expression.
%Parameters: A: a --prints the whole truth table
%               t --prints only true combinations
%               f --prints only false combinations
%               ex --prints one true combination
%-------
table(List, Eqn, A) :- N is 1, nl,createtable(List, N), truth(List, Eqn, A).

%-------
%interprets the boolean equation the user gives
%-------
and(A,B) :- A,B.
or(A,B) :- A;B.

%-------
%turns a list of variables into boolean values
%-------
make_boolean_list([A|[]]) :- make_boolean(A).
make_boolean_list([A|List]) :- make_boolean(A), make_boolean_list(List).

%-------
%turns variables into boolean values.
%-------
make_boolean(true).
make_boolean(fail).




%-------
%sets up an equation to be solved for all possible boolean inputs
%-------
truth(List, Eqn, a) :- make_boolean_list(List), solve(List, Eqn), fail.
truth(List, Eqn, t) :- make_boolean_list(List), solve_true(List, Eqn), fail.
truth(List, Eqn, f) :- make_boolean_list(List), solve_false(List, Eqn), fail.
truth(List, Eqn, ex) :- make_boolean_list(List), solve_true(List, Eqn), !,fail.


%-------
%solves an equation
%-------
solve(List, Eqn) :- Eqn, !, print_list(List), write(true), nl.
solve(List,_) :- print_list(List), write(fail), nl.
solve_true(List, Eqn) :- Eqn, !, print_list(List), write(true), nl.
solve_false(List, Eqn) :- not(Eqn),!, print_list(List), write(fail), nl.


%-------
%prints out a the value of the variables one pass through
%-------
print_list([]).
print_list([A|List]) :- write(A), write('   '), print_list(List).

%-------
%initially creates a table with Var1--VarN variable entries.
%-------
createtable([],_) :- write('Ans'),nl,nl.
createtable([_|List], N) :- write('Var'), write(N), write('   '), 
    Temp is N + 1, createtable(List,Temp).


