lecture09

lecture09 - CS 70 Spring 2005 Discrete Mathematics for CS...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
CS 70 Discrete Mathematics for CS Spring 2005 Clancy/Wagner Notes 9 Lecture Notes 8 described methods for logical reasoning based on satisfiability testing and introduced Minesweeper. In this lecture, we show how to construct a complete Minesweeper program. We show that some aspects of Minesweeper are computationally intractable if handled na¨ ıvely. Methods for problem decomposition can help. Minesweeper in CNF Lecture Notes 8 gave a simple example of how to formulate a logical description of a Minesweeper display as a set of clauses. If d is a display, CNF ( d ) denotes the corresponding CNF expression. We will now show how to construct CNF ( d ) systematically for any display. CNF ( d ) consists of propositions arising from each of the known squares, plus the global constraint on the total number of mines left. We begin with the known squares. Consider a known square, such as (2,1) in the following example repeated from Lecture Notes 8: 2 1 1 1 1 1 2 3 (2,1) has 1 mine adjacent to it. There are 5 adjacent squares; 2 of them have been probed and are known to be safe; 0 of them are marked as a mine already. There are n = 5 - 2 - 0 = 3 unknown adjacent squares, of which k = 1 - 0 = 1 are mines. So we need to express in CNF the proposition that k of the n adjacent unknown squares are mines. Call this proposition KN ( k , n ) . Let’s see what we have to work with. CNF requires a conjunction of disjunctions of literals. A disjunction of literals means “at least one ... ,” i.e., an inequality. The literals can be either “(i,j) contains a mine” or “(i,j) doesn’t contain a mine.” Because KN ( k , n ) is entirely symmetric with respect to the unknown squares, we might expect to generate clauses that are symmetric—for example, all positive literals or all negative literals. We begin by writing KN ( k , n ) as two inequalities: KN ( k , n ) ( U ( k , n ) L ( k , n )) where U ( k , n ) means that at most k of the n squares contain a mine. L ( k , n ) means that at least k of the n squares contain a mine. So how do we express “at most k ” using clauses that say “at least one”? Consider any subset of k + 1 squares from the n unknown squares. If at most k are mines, then at least one is not a mine; the converse is also true. So we have the following: CS 70, Spring 2005, Notes 9 1
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
U ( k , n ) for any k + 1 squares out of n , at least one is not a mine. Similarly, consider any subset of n - k + 1 squares: if at least k of all n squares are mines, then at least one of any n - k + 1 squares must be a mine; the converse is also true. Hence L ( k , n ) for any n - k + 1 squares out of n , at least one is a mine. Applying these formulations to the square (2,1) in the above example, where k = 1 and n = 3, we obtain: U ( 1 , 3 ) for any 2 squares out of 3, at least one is not a mine. L
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 8

lecture09 - CS 70 Spring 2005 Discrete Mathematics for CS...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online