Answered step by step
Verified Expert Solution
Question
1 Approved Answer
In this assignment, you are to implement the Davis - Putnam algorithm and use it to solve versions of the peg game. The peg game
In this assignment, you are to implement the DavisPutnam algorithm and use it to solve versions of the peg game.
The peg game is a wellknown puzzle. You have a board with holes in a geometric pattern and a collection of pegs. Initially, there are pegs in all but one of the holes. The rule is that if there are three holes, A B C in a row, C is empty, and there are pegs in A and B then you can jump the peg in A over B to C and take out the peg in B The puzzle is to find a way of carrying out jumps so that there is one peg left on the board.
You will write three programs.
An implementation of the DavisPutnam procedure, which takes as input a set of clauses and outputs either a satisfying valuation, or a statement that the clauses cannot be satisfied.
A front end, which takes as input a geometric layout of a board and a starting state and outputs a set of clauses that can be input to
A back end, which takes as input the output of and translates it into a solution to the original problem.
Compiling the peg puzzle to propositional logic
The peg game can be expressed propositionally as follows: There are two kinds of atoms:
PegHI means that hole H has a peg in it at time I. For instance Peg means that hole has a peg at time Note: in propositional logic, a construction like "Peg is considered a single symbol of characters. The parentheses and comma are not punctuation, they are just characters in the symbol, to make it easier for the human reader.
JumpABCI means that at time I, the peg in A is jumped to C over B
The number of time points is necessarily equal to the number of holes minus one, since you start with one hole and end with one peg. Let N be the number of holes. Then for each hole H and IN there should be an atom PegHI and for each triple of holes in a row ABC and IN there should be an atom JumpABCI
Propositional Encoding
There are between seven and nine kinds of propositions, depending on which optional categories are included.
Precondition axioms. If at time I, you jump a peg from A to C over B then A and B must have pegs at time I and C must not have a peg at time I.
For instance, with the above puzzle,
Jump Peg Peg ~Peg
In CNF in the general case this becomes three clauses:
~Jump V Peg
~Jump V Peg
~Jump V ~Peg
Causal axioms. If you jump from A to C over B at time I, then, at time I A and B are empty and C has a peg.
For instance, Jump ~Peg ~Peg Peg
In CNF this becomes three clauses:
~Jump V ~Peg
~Jump V ~Peg
~Jump V Peg
Frame axioms. Frame axioms assert that state can change only if a relevant action occurs.
If PegHI and ~PegHI then either JumpXHYI or JumpHXYI for some holes X and Y
For instance, Peg ~Peg Jump V Jump V Jump V Jump
In CNF that becomes the single clause
~Peg V Peg V Jump V Jump V Jump V Jump
If ~PegHI and PegHI then JumpXYHI for some holes X and Y
For instance ~Peg Peg Jump V Jump
In CNF that becomes the single clause
Peg V ~Peg V Jump V Jump
One action at a time
No two actions can be executed at the same time.
For instance ~Jump Jump
In CNF that becomes the single clause ~Jump V ~Jump
Optional At least one action is executed at each step.
For instance Jump V Jump V V Jumpgoing through all possible jumps
Adding additional constraints that you know are valid never costs much in performance, unless you add an enormous number, and can hugely improve performance, depending on the specifics.
That is already in CNF
Starting state Specify the truth value of PegH for each hole H
Ending state: Exactly one peg remains. This involves two kinds of axioms.
No two holes have a peg. For each pair of holes HJ assert that ~PegHN PegJN
In CNF that becomes ~PegHN V ~PegJN
Optional At least one peg remains at time N PegN V PegN V V PegNN
That is already in CNF
Specifications
Input Output.
All three programs take their input from a text file produce their output to a text file. If you want, you may use standard input and output.
DavisPutnam:
The input to the DavisPutnam procedure has the following form: An atom is denoted by a natural number: The literal P is the same number as atom P; the literal ~P is the negative. A clause is a line of text containing the integers of the corresponding literals. After all the clauses have been given, the next line is the single value ; anything further in the file is ignored in the execution of the procedure and reproduced at the end of the output.
Please write python, thank you
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started