Sudoku as an Expression in Propositional Logic

Similar documents
Binary Adders: Half Adders and Full Adders

Chapter 3. Cartesian Products and Relations. 3.1 Cartesian Products

Sudoku puzzles and how to solve them

COMPUTER SCIENCE. Paper 1 (THEORY)

Row Echelon Form and Reduced Row Echelon Form

1.5 SOLUTION SETS OF LINEAR SYSTEMS

Mathematical Induction

CSL105: Discrete Mathematical Structures. Ragesh Jaiswal, CSE, IIT Delhi

Practical Guide to the Simplex Method of Linear Programming

Handout #1: Mathematical Reasoning

8 Primes and Modular Arithmetic

BOOLEAN ALGEBRA & LOGIC GATES

1 Review of Least Squares Solutions to Overdetermined Systems

Data Structures Fibonacci Heaps, Amortized Analysis

Introduction. The Quine-McCluskey Method Handout 5 January 21, CSEE E6861y Prof. Steven Nowick

Solutions to Math 51 First Exam January 29, 2015

Pigeonhole Principle Solutions

Offline 1-Minesweeper is NP-complete

MTAT Cryptology II. Sigma Protocols. Sven Laur University of Tartu

CHAPTER 2. Logic. 1. Logic Definitions. Notation: Variables are used to represent propositions. The most common variables used are p, q, and r.

6.3 Conditional Probability and Independence

Systems of Linear Equations

Mathematical Induction

CSEE 3827: Fundamentals of Computer Systems. Standard Forms and Simplification with Karnaugh Maps

Logic in Computer Science: Logic Gates

Resolution. Informatics 1 School of Informatics, University of Edinburgh

Sudoku Puzzles Generating: from Easy to Evil

MATH 304 Linear Algebra Lecture 18: Rank and nullity of a matrix.

Testing LTL Formula Translation into Büchi Automata

NP-Completeness and Cook s Theorem

PARALLELIZED SUDOKU SOLVING ALGORITHM USING OpenMP

Invalidity in Predicate Logic

3. Mathematical Induction

Specimen 2015 am/pm Time allowed: 1hr 30mins

1.2 Solving a System of Linear Equations

Matrix Algebra. Some Basic Matrix Laws. Before reading the text or the following notes glance at the following list of basic matrix algebra laws.

Regular Languages and Finite Automata

CSE 135: Introduction to Theory of Computation Decidability and Recognizability

Genetic Algorithms and Sudoku

Sudoku as a SAT Problem

8 Square matrices continued: Determinants

Minimally Infeasible Set Partitioning Problems with Balanced Constraints

Basic Proof Techniques

Enumerating possible Sudoku grids

COMP 250 Fall 2012 lecture 2 binary representations Sept. 11, 2012

Continued Fractions and the Euclidean Algorithm

Set Theory Basic Concepts and Definitions

Lecture 3: Finding integer solutions to systems of linear equations

Full and Complete Binary Trees

Solving Linear Systems, Continued and The Inverse of a Matrix

Relational Databases

So let us begin our quest to find the holy grail of real analysis.

Solution to Exercise 2.2. Both m and n are divisible by d, som = dk and n = dk. Thus m ± n = dk ± dk = d(k ± k ),som + n and m n are divisible by d.

10 th POLISH SUDOKU CHAMPIONSHIP INSTRUCTION BOOKLET. February 22, 2015 IMPORTANT INFORMATION:

Name: Section Registered In:

Chapter 17. Orthogonal Matrices and Symmetries of Space

Boolean Design of Patterns

Basic Logic Gates Richard E. Haskell

1 The Line vs Point Test

a 11 x 1 + a 12 x a 1n x n = b 1 a 21 x 1 + a 22 x a 2n x n = b 2.

4.5 Linear Dependence and Linear Independence

npsolver A SAT Based Solver for Optimization Problems


1. Introduction to image processing

A simple solution to the hardest logic puzzle ever

Solving Systems of Linear Equations

Math 3000 Section 003 Intro to Abstract Math Homework 2

Gates, Circuits, and Boolean Algebra

Mathematics of Sudoku I

Likewise, we have contradictions: formulas that can only be false, e.g. (p p).

CHAPTER 3. Methods of Proofs. 1. Logical Arguments and Formal Proofs

Package sudoku. February 20, 2015

Transportation Polytopes: a Twenty year Update

The Graphical Method: An Example

Ofgem Carbon Savings Community Obligation (CSCO) Eligibility System

Section 8.2 Solving a System of Equations Using Matrices (Guassian Elimination)

5.1 Radical Notation and Rational Exponents

Sensitivity Analysis 3.1 AN EXAMPLE FOR ANALYSIS

Lecture 8: Synchronous Digital Systems

Chapter 9. Systems of Linear Equations

Lecture Notes on Linear Search

8 Divisibility and prime numbers

Chapter 6. Linear Programming: The Simplex Method. Introduction to the Big M Method. Section 4 Maximization and Minimization with Problem Constraints

VISUAL ALGEBRA FOR COLLEGE STUDENTS. Laurie J. Burton Western Oregon University

IB Math Research Problem

Algebra of the 2x2x2 Rubik s Cube

Lecture Notes 2: Matrices as Systems of Linear Equations

Solving Systems of Linear Equations Using Matrices

Manipulability of the Price Mechanism for Data Centers

Section IV.1: Recursive Algorithms and Recursion Trees

Scheduling Shop Scheduling. Tim Nieberg

Logic in general. Inference rules and theorem proving

LINEAR INEQUALITIES. Mathematics is the art of saying many things in many different ways. MAXWELL

Math Content by Strand 1

December 4, 2013 MATH 171 BASIC LINEAR ALGEBRA B. KITCHENS

1 Determinants and the Solvability of Linear Systems

Introduction to Logic in Computer Science: Autumn 2006

Boolean Algebra Part 1

MATH10212 Linear Algebra. Systems of Linear Equations. Definition. An n-dimensional vector is a row or a column of n numbers (or letters): a 1.

Transcription:

Sudoku as an Expression in Propositional Logic Peter Cappello Department of Computer Science University of California, Santa Barbara INTRODUCTION Sudoku is a kind of puzzle that involves a 9 9 array of squares. Please see the Wikipedia entry on Sudoku: http://en.wikipedia.org/wiki/sudoku. The puzzle summarily is to fill in each empty square with a nonzero digit such that each: row contains all the nonzero digits column contains all the nonzero digits region (emboldened sub-array) contains all the nonzero digits. THE PROBLEM Let P be an indexed set of boolean variables, p(i, j, d), for i, j, d, where p(i, j, d) = true means that the square in row i and column j has digit d. We refer to the set of values of these variables as P s truth assignment. Definition: A truth assignment is feasible when, for any fixed [row] i and [column] j, p(i, j, d) = true for exactly one value of d. Definition: The proposed solution corresponding to a feasible truth assignment has digit d in the square associated with row i and column j, where p(i, j, d) = true. THE PROBLEM SPECIFICATION Input: An instance I of a Sudoku puzzle. Output: A propositional expression over the boolean variables in P that is satisfiable if and only if:. P s truth assignment is feasible and. the proposed solution corresponding to P s truth assignment is a solution to Sudoku puzzle I. Describe a correct output expression, or an algorithm for producing it.

A SOLUTION Each instance of a Sudoku puzzle has some nonempty squares. We refer to these constraints as the instance s initial conditions. We refer to the conditions on any solution that are stated in the Introduction as the general conditions. A truth assignment α corresponds to a puzzle solution when α:. is feasible and. satisfies the instance s initial conditions and. satisfies the general conditions. We construct an expression that is the conjunction of sub-expressions, corresponding to the conditions described above. We will construct an expression, β, that corresponds to the initial conditions, and expression, γ, that ensures feasibility, and an expression σ that encodes the general conditions. Our goal: a truth assignment α satisfies β γ σ if and only if the proposed solution corresponding to α is a solution to the puzzle. Before we begin this program, we establish a generic expression that will prove useful in several places. Let p, p,..., p n be boolean variables. We seek an expression over these variables that is satisfiable if and only if exactly of the variables is true. This expression can be written as the conjunction of conditions:. At least one variable is true. At most one variable is true. Clearly, the first condition is satisfied by the disjunction of the variables: p p... p n. One way to express condition is to ensure that no variables are both true: For every i j, (p i p j ) p i p j. Thus, the expression we seek is the conjunction of these expressions. For example, if we want exactly one of p, q, r, and s to be true, an expression that ensures this is (p q r s) (( p q) ( p r) ( p s) ( q r) ( q s) ( r s)). Let S be a set of boolean variables. Let ψ(s) denote the propositional logic expression that is satisfiable if and only if exactly element of S is true. We see from the discussion above that we always can construct such an expression. AN EXPRESSION THAT CORRESPONDS TO THE INITIAL CONDITIONS Again, the initial conditions are the squares that initially have a number. Let us say that there are k such squares. We denote their rows, columns, and numbers as (r, c, n ),..., (r k, c k, n k ). For any given initial condition, such as the square in row r column c has number n, we require that. p(r, c, n) is true, and

. all other variables for this square are false: m n p(r, c, m). We define a parameterized expression, β(r, c, n), for the initial condition that the square in row r and column c has number n: β rcn = p(r, c, n) p(r, c, m). Then, an expression for the initial conditions, β, is just the conjunction of the expressions for the each initialized square: β = β(r, c, n ) β(r k, c k, n k ). m n AN EXPRESSION THAT ENSURES FEASIBILITY Our expression of the initial conditions is satisfiable if and only if exactly one associated propositional variable is assigned true. Regarding feasibility, we thus need only concern ourselves with the empty squares. Let the square in row r and column c be empty. A feasible assignment of truth values to the propositional variables p(r, c, n), for n =,,, requires that exactly one is true. Let P rc denote this set of propositional variables. ψ(p rc ) expresses this requirement. Validity requires the conjunction of ψ(p rc ) over the set of empty squares. Let E = {(r, c) the square in row r and column c is empty }. Define γ = ψ(p rc ). (r, c) E Then, γ is satisfiable if and only if, for each empty square s, exactly of the propositional variables associated with s is true. AN EXPRESSION THAT ENCODES THE GENERAL CONDITIONS To aid in the subsequent discussion, we present the -dimensional set of boolean variables (row, column, number) visually in Figure. General condition General condition states that each row contains all the nonzero digits. Consider row. If this row satisfies general condition, then exactly column in this row has a in it. We focus our attention of the variables that represent the columns in row with number value : p(,, ), p(,, ), p(,, ), and p(,, ). In Figure, these variables are green. Let R be the set that contains these variables. Then ψ(r ) is satisfiable if and only if exactly of the variables associated with row and number value is assigned true. We want similar expressions for row and number values,, and. Indeed, for general condition, we want the conjunction of such expressions, for each row, and for each number value in each row: ψ(r rn ), r,n where r, n. The R rn of interest are shown in Figure??. Let R rn be the set of variables associated with row r and number value n. In Figure, each set of variables connected by a black line represents an R rn, for some particular row r and number value n.

COLUMN ROW NUMBER Figure : The -dimensional array of propositional variables: (i) Variables with a common row and column (i.e., are associated with the same square) are connected by a red line; (ii) variables with a common row and number value are connected by a black line; (iii) variables with a common column and number value are connected by a blue line.

Figure : The -dimensional array of propositional variables, where variables are green if they are associated with row and number value : R. 5

General condition General condition 6