- The web page
Prolog Tutorial -- 2.13 contains an example of how to define a particular logical operation using Prolog and generate a truth table.
Using the supplied code as a model, extend the program to handle the following logical operators:
iii.) XOR (exclusive OR - a XOR b is true if the truth values of a and b are different; false otherwise).
iv.) NAND (NOT AND).
v.) NOR (NOT OR)
Your program should be called tables.pl.
- The web page
contains an example of how to represent a tree structure in Prolog and how to navigate the tree.
Using the supplied code as a model, define and test predicates to perform the following actions:
i.) add a child node to an existing node in the tree specified by its value, e.g. the goal add(X, Y) should add the value represented by X as the rightmost child node of the node represented by Y. The goal should only succeed if the node represented by Y exists in the tree.
ii.) remove a specified node from the tree, e.g. the goal remove(X) will remove the node from the tree. The goal should only succeed if the specified node exists and has no children, failing otherwise.
iii.) perform a depth-first traversal of the tree, listing the nodes visited during the traversal in the order they were visited.
iv.) perform a breadth-first traversal of the tree, listing the nodes visited during the traversal in the order they were visited and the level at which each node occurs.
Your program should be called tree.pr.