* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Download Modular Arithmetic - svmoore
Survey
Document related concepts
Transcript
Modular Arithmetic Shirley Moore CS4390/5390 Fall 2013 http://svmoore.pbworks.com/ September 3, 2013 Agenda • Complete pre-course survey if you haven’t already • Discuss homework from last class (15 min) • Homework 1 to turn in (due Sept. 12) (5 min) • Introduction to Matlab by Rogelio Long (40 min) • Modular arithmetic (15 min) • Wrap-up and preparation for next class (5 min) Technique of Proving NPCompleteness • Prove: If B is NP-complete, C is in NP, and B is polynomial time reducible to C, then C is NPcomplete. • Definition: A problem L is NP-complete if and only if: – L is in NP – for every problem L’ in NP, there is a polynomialtime reduction from L’ to L • Proof: NP-completeness Proof • HamCyc: Given a graph G=(V,E) with at least three vertices, does G contain a Hamiltonian cycle? • Traveling Salesman Problem (TSP): Given n ≥ 3 cities and distances d(i,j) between each pair of cities, does there exist a tour of length ≤ k that visits each city and returns to the starting point? • Given that HamCyc is NP-complete, prove that TSP is NP-complete. 1. Show that TSP is in NP. 2. Show a polynomial time reduction from HamCyc to TSP. Randomized Algorithm for 3SAT • Schoning, T., "A probabilistic algorithm for k-SAT and constraint satisfaction problems," Symposium on Foundations of Computer Science, 1999. – We present a simple probabilistic algorithm for solving k-SAT and more generally, for solving constraint satisfaction problems (CSP). The algorithm follows a simple local search paradigm: randomly guess an initial assignment and then, guided by those clauses (constraints) that are not satisfied, by successively choosing a random literal from such a clause and flipping the corresponding bit, try to find a satisfying assignment. If no satisfying assignment is found after O(n) steps, start over again. Our analysis shows that for any satisfiable k-CNF-formula with n variables this process has to be repeated only t times, on the average, to find a satisfying assignment, where t is within a polynomial factor of (2(1-1/k))n. Modular Arithmetic • The number X (mod Y) is the remainder when X is divided by Y. – For example: 7 (mod 3) is 1 because 7 = 2 * 3 + 1. That is, when you divide 7 by 3, you get a remainder of 1. – The "modulo Y" terminology can also be used in the following way: Z = X (mod Y), meaning that Z and X have the same remainder when divided by Y. For example: 7 = 25 (mod 3)because 7 = 2 * 3 + 1 and 25 = 8 * 3 + 1 Modular Multiplication • When you take products of many numbers and you want to find their remainder modulo n, you never need to worry about numbers bigger than the square of n. • Pick any two numbers x and y, and look at their remainders (mod 7): – a = x (mod 7) – b = y (mod 7) • Compare the remainder modulo 7 of the products xy and ab: – xy (mod 7) with ab (mod 7) • For example, try x = 26, y = 80 Modular Multiplication of Many Numbers • If we want to multiply many numbers modulo n, we can first reduce all numbers to their remainders. Then, we can take any pair of them, multiply and reduce again. • For example, suppose we want to find X = 36 * 53 * 91 * 17 * 22 (mod 29) • What is the largest number we have to multiply by? Modular Exponentiation • Suppose we would like to calculate 1143 (mod 13). • The straightforward method would be to multiply 11 by 11, then to multiply the result by 11, and so forth. This would require 42 multiplications. • We can save a lot of multiplications if we do the following: – First write 43 as a sum of powers of 2: 43 = 32 + 8 + 2 + 1 – That means that 1143 = 1132 * 118 * 112 * 11 . • How many multiplications are required, and what is the largest number we have to multiply? Preparation for Next Class • Introduction to Modular Arithmetic and Cryptography • Start on Homework 1 (turn in for grade, due September 12)