adding xor circuit and tutorial family tree

This commit is contained in:
andy 2021-03-02 17:56:44 +00:00
parent 4a3750c723
commit 43b93918e8
3 changed files with 41 additions and 0 deletions

3
README.md Normal file
View File

@ -0,0 +1,3 @@
# Logic Problems
Working through some logic programming problems using Prolog. Tutorial problems from post-grad AI and AI programming module with some other random problems.

12
familytree.pl Normal file
View File

@ -0,0 +1,12 @@
% tree structure
parent(pam,bob).
parent(tom,bob).
parent(tom,liz).
parent(bob,ann).
parent(bob,pat).
parent(pat,jim).
predecessor(X, Z) :- parent(X, Z).
predecessor(X, Z) :- parent(X, Y), predecessor(Y, Z).
offspring(Y, X) :- parent(X, Y).

26
xor.pl Normal file
View File

@ -0,0 +1,26 @@
% implement logical AND truth table
% and(IN1, IN2, OUT)
and(0,0,0).
and(0,1,0).
and(1,0,0).
and(1,1,1).
% implement logical OR truth table
% or(IN1, IN2, OUT)
or(0,0,0).
or(0,1,1).
or(1,0,1).
or(1,1,1).
% implement logical inverter
% inv(IN, OUT)
inv(0,1).
inv(1,0).
% implement XOR using rule
xor(IN1,IN2,OUT) :- inv(IN1, N1),
inv(IN2, N2),
and(IN1, N2, N3),
and(IN2, N1, N4),
or(N3, N4, OUT).