Univ. of Illinois Due Wednesday, Sept 13, 2017 Prof. Allen

Similar documents
UCT Algorithm Circle: Number Theory

Know the Well-ordering principle: Any set of positive integers which has at least one element contains a smallest element.

Odd-Numbered Answers to Exercise Set 1.1: Numbers

Math Introduction to Advanced Mathematics

1 Elementary number theory

COP 4516: Math for Programming Contest Notes

UNIT-II NUMBER THEORY

Lesson 1: Arithmetic Review

Section A Arithmetic ( 5) Exercise A

CS 97SI: INTRODUCTION TO PROGRAMMING CONTESTS. Jaehyun Park

Notes for Unit 1 Part A: Rational vs. Irrational

1. Find f(1), f(2), f(3), and f(4) if f(n) is defined recursively by f(0) = 1 and for n = 0, 1, 2,

Number System. Introduction. Natural Numbers (N) Whole Numbers (W) Integers (Z) Prime Numbers (P) Face Value. Place Value

Rational numbers as decimals and as integer fractions

Chapter 1: Number and Operations

MATH 2221 A Mathematics Laboratory II

Errors in Computation

Integers and Mathematical Induction

Hexadecimal Numbers. Journal: If you were to extend our numbering system to more digits, what digits would you use? Why those?

Lecture Notes, CSE 232, Fall 2014 Semester

Lecture Objectives. Structured Programming & an Introduction to Error. Review the basic good habits of programming

Euclid's Algorithm. MA/CSSE 473 Day 06. Student Questions Odd Pie Fight Euclid's algorithm (if there is time) extended Euclid's algorithm

Lesson 13: Exploring Factored Form

Data Dependences and Parallelization

MAT 003 Brian Killough s Instructor Notes Saint Leo University

COMPETENCY 1.0 UNDERSTAND THE STRUCTURE OF THE BASE TEN NUMERATION SYSTEM AND NUMBER THEORY

SCHOOL OF ENGINEERING & BUILT ENVIRONMENT. Mathematics. Numbers & Number Systems

Introduction to Modular Arithmetic

Integers are whole numbers; they include negative whole numbers and zero. For example -7, 0, 18 are integers, 1.5 is not.

Course Learning Outcomes for Unit I. Reading Assignment. Unit Lesson. UNIT I STUDY GUIDE Number Theory and the Real Number System

Algebraically Speaking Chalkdust Algebra 1 Fall Semester

Algorithms (7A) Young Won Lim 4/10/17

Mathematics. Jaehyun Park. CS 97SI Stanford University. June 29, 2015

MAT 090 Brian Killough s Instructor Notes Strayer University

Lecture 8 Mathematics

GREENWOOD PUBLIC SCHOOL DISTRICT Algebra III Pacing Guide FIRST NINE WEEKS

1 Elementary number theory

Prepared by Sa diyya Hendrickson. Package Summary

Lesson 1: Arithmetic Review

8/27/2016. ECE 120: Introduction to Computing. Graphical Illustration of Modular Arithmetic. Representations Must be Unambiguous

Unit 7 Number System and Bases. 7.1 Number System. 7.2 Binary Numbers. 7.3 Adding and Subtracting Binary Numbers. 7.4 Multiplying Binary Numbers

Topic 10 Part 2 [474 marks]

Math 302 Introduction to Proofs via Number Theory. Robert Jewett (with small modifications by B. Ćurgus)

Logic Design: Part 2

Section 1.2 Fractions

College Prep Algebra II Summer Packet

Module 2: Classical Algorithm Design Techniques

( ) ( ) Completing the Square. Alg 3 1 Rational Roots Solving Polynomial Equations. A Perfect Square Trinomials

Matrices. A Matrix (This one has 2 Rows and 3 Columns) To add two matrices: add the numbers in the matching positions:

Math Glossary Numbers and Arithmetic

Programming Techniques in Computer Algebra

Course Number 432/433 Title Algebra II (A & B) H Grade # of Days 120

A.1 Numbers, Sets and Arithmetic

Math 340 Fall 2014, Victor Matveev. Binary system, round-off errors, loss of significance, and double precision accuracy.

Lecture 7 Number Theory Euiseong Seo

Chapter 1 An Introduction to Computer Science. INVITATION TO Computer Science 1

Loop Invariant Examples

Lemma (x, y, z) is a Pythagorean triple iff (y, x, z) is a Pythagorean triple.

Grade 7 Math Curriculum Map Erin Murphy

SUMMER REVIEW PACKET 2 FOR STUDENTS ENTERING ALGEBRA 1

The Chinese remainder theorem

Creating a new data type

Lab 1: Cipher Fundamentals

Chapter 0: Algebra II Review

or 5.00 or 5.000, and so on You can expand the decimal places of a number that already has digits to the right of the decimal point.

Introduction to Programming in C Department of Computer Science and Engineering\ Lecture No. #02 Introduction: GCD

Section 1.8. Simplifying Expressions

Floating-point representation

Algebra 1 Review. Properties of Real Numbers. Algebraic Expressions

ALGEBRA I Summer Packet

Curriculum Map: Mathematics

Programming & Data Structure Laboratory. Day 2, July 24, 2014

correlated to the Michigan High School Mathematics Content Expectations

Introduction to Matlab

CHAPTER 1B: : Foundations for Algebra

CIS 194: Homework 6. Due Monday, February 25. Fibonacci numbers

Grades 7 & 8 Pre-Algebra/Course 3,

To begin this textbook, we need to start with a refresher of the topics of numbers and numbering systems.

Integer Operations. Summer Packet 7 th into 8 th grade 1. Name = = = = = 6.

Objective A Identify the numerator and the denominator of a fraction. When the numerator is less than the denominator, it is a(n) fraction.

Lab 1: Cipher Fundamentals

Algorithms 4. Odd or even Algorithm 5. Greatest among three numbers Algorithm 6. Simple Calculator Algorithm

BEng (Hons) Telecommunications. Examinations for / Semester 2

Is the statement sufficient? If both x and y are odd, is xy odd? 1) xy 2 < 0. Odds & Evens. Positives & Negatives. Answer: Yes, xy is odd

Exercise Set Decide whether each matrix below is an elementary matrix. (a) (b) (c) (d) Answer:

36 Modular Arithmetic

Chapter 4. Number Theory. 4.1 Factors and multiples

If a b or a c, then a bc If a b and b c, then a c Every positive integer n > 1 can be written uniquely as n = p 1 k1 p 2 k2 p 3 k3 p 4 k4 p s

1.1 calculator viewing window find roots in your calculator 1.2 functions find domain and range (from a graph) may need to review interval notation

n = 1 What problems are interesting when n is just 1?

Montana City School GRADE 5

Discrete Mathematics SECOND EDITION OXFORD UNIVERSITY PRESS. Norman L. Biggs. Professor of Mathematics London School of Economics University of London

CS321 Introduction To Numerical Methods

Conditionals !

Lecture 2: Variables, Vectors and Matrices in MATLAB

Structured programming

Number- Algebra. Problem solving Statistics Investigations

Grade 7 Math (Master) Essential Questions Content Skills

TABLE OF CONTENTS CHAPTER 1 LIMIT AND CONTINUITY... 26

Algebra Homework: Chapter 1 (Homework is listed by date assigned; homework is due the following class period) Day Date In-Class Homework

Transcription:

ECE 298JA NS #2 Version.28 April 22, 208 Fall 207 Univ. of Illinois Due Wednesday, Sept 3, 207 Prof. Allen Topic of this homework: Prime numbers, greatest common divisors, the continued fraction algorithm Corrections from orginal posting in blue. Deliverable: Answers to questions. Prime numbers. According to the fundamental theorem of arithmetic, every integer may be written as a product of primes. (a) Put the numbers,000,000,,000,004 and 999,999 in the form N k use Matlab to find the prime factors). π β k k (you may (b) Give a generalized formula for the natural logarithm of a number, ln(n), in terms of its primes π k and their multiplicities β k. Express your answer as a sum of terms. 2. Explain why the following 2-line Matlab/Octave program returns the prime numbers π k between and 00? n2:00; k isprime(n); n(k) 3. Prime numbers may be identified using sieves (a) By hand, perform the sieve of Eratosthenes for n...49. Circle each prime p then cross out each number which is a multiple of p. (b) In part (a), what is the highest number you need to consider before only the primes remain? (c) Generalize: for n...n, what is the highest number you need to consider before only the primes remain? (d) Write each of these numbers as a product of primes: 22 30 34 43 44 48 49. 4. Find the largest prime π k 00? Hint: Do not use matlab other than to check your answer. Hint: Write out the numbers starting with 00 and counting backwards: 00, 99, 98, 97,. Cross off the even numbers, leaving 99,97,95,. Pull out a factor (only is necessary to show that it is not prime). 5. Find the largest prime π k 000? Hint: Do not use matlab other than to check your answer.

2 Greatest common divisors Consider the Euclidean algorithm to find the greatest common divisor (GCD; the largest common prime factor) of two numbers. Note this algorithm may be performed using one of two methods: Method Division Subtraction On each iteration... a i+ a i+ max(a i, ) min(a i, ) + a i floor(a i / ) + min(a i, ) Terminates when... b 0 (gcd a) b 0 (gcd a) We recommend the division method (Eq. 2., Sect. 2..2, Lec 5, Ch. 2), given in the course notes.. Understand the Euclidean (GCD) algorithm (a) Use the Matlab command factor to find the prime factors of a 85 and b 5. What is the greatest common prime factor of these two numbers? (b) By hand, perform the Euclidean algorithm for a 85 and b 5. (c) By hand, perform the Euclidean algorithm for a 75 and b 25. Is the result a prime number? (d) Consider the first step of the GCD division algorithm when a < b (e.g. a 25 and b 75). What happens to a and n the first step? Does it matter if you begin the algorithm with a < b vs. b < a? (e) Describe in your own words how the GCD algorithm works. Try the algorithm using numbers which have already been separated into factors (e.g. a 5 3 and b 7 3). 2. Coprimes (a) Define the term coprime. (b) How can the Euclidean algorithm be used to identify coprimes? (c) Give at least one application of the Euclidean algorithm. 3. Write a Matlab function, function x my_gcd(a,b), which uses the Euclidean algorithm to find the GCD of any two inputs a and b. Test your function on the (a,b) combinations from parts (a) and (b). Include a printout (or handwrite) your algorithm to turn in. Hints and advice: Don t give your variables the same names as Matlab functions! Since gcd is an existing Matlab/Octave function, if you use it as a variable or function name, you won t be able to use gcd to check your gcd() function. Try clear all to recover from this problem. Try using a while loop for this exercise (see Matlab documentation for help). You may need to make some temporary variables for a and n order to perform the algorithm. 2

3 Alegbraic generalization of the GCD (Euclidean) algorithm Inthisproblemwearelookingforintegersolutions(m,n) Ztotheequationsma+nb gcd(a,b) and ma+nb 0 given positive integers (a,b) Z +. Note that this requires that either m or n be negative. These solutions may be found using the Euclidean algorithm only if (a, b) are coprime (a b). Note that integer (whole number) polynomial relations such as these are known as Diophantine equations. The above equations are linear Diophantine equations, possibly the simplest form of such relations. Matrix approach: It can be difficult to keep track of the a s and b s when the algorithm has many steps. Here is an alternative way to run the Euclidean algorithm, using matrix algebra. Matrix methods provide a more transparent approach to the operations on (a, b). Thus the Euclidean algorithm can be classified in terms of standard matrix operations (discussed in Lec. 5 pp. 73-75): Division method: Define [ a0 b 0 ] [ a b ] [ ] ai+ + [ 0 a i / ][ ai ] Example: gcd(2,3)): For (a, b) (2, 3), the result is as follows: [ ] [ ][ ][ ][ ] [ ][ ] 0 0 0 2 2 0 2 0 3 3 2 3 m n Thus from the above equation we find the solution (m,n) to the integer equation 2m+3n gcd(2,3), namely (m,n) (,) (i.e., 2+3 ). There is also a second solution (3, 2), (i.e., 3 2 2 3 0), which represents the terminating condition. Thus these two solutions are a pair and the solution only exists if (a,b) are coprime (a b). Subtraction method: This method is more complicated than the division algorithm, because at each stage we must check if a < b. Define ] [ a0 b 0 [ ] a b Q [ ] 0 S [ ] 0 0 where Q sets a i+ a i and + assuming a i >, and S is a swap-matrix which swaps a i and if a i <. Using these matrices, the algorithm is implemented by assigning [ ] [ ] [ ] [ ] ai+ ai ai+ ai Q for a i >, QS for a i <. + The result of this method is a cascade of Q and S matrices. For (a,b) (2,3), the result is as follows: [ ] [ ][ ][ ][ ][ ] [ ][ ] 0 0 2 2 2. 0 0 0 0 3 3 Q S Q + S m n Thus we find two solutions (m,n) to the integer equation 2m+3n gcd(2,3).. By inspection, find at least one integer pair (m,n) that satisfies 2m+5n 3. 3

2. Using matrix methods for the Euclidean algorithm, find integer pairs (m,n) that satisfy 2m+5n 3 and 2m+5n 0. Show your work!!! 3. Does the equation 2m+5n have integer solutions for n and m? Why, or why not? 4

4 Continued fractions Here we explore the continued fraction algorithm (CFA), as discussed in Lec. 6 (Chapters and 2). In its simplest form the CFA starts with a real number, which we denote as α R. Let us work with an irrational real number, π I, as an example, because its CFA representation will be infinitely long. We can represent the CFA coefficents α as a vector of integers n k, k,2... α [n.,n 2,n 3,n 4,...] n + n 2 + n 3 + n 4 +... As discussed in Section.2.5, the CFA is recursive, with three steps per iteration: For α π, n 3, r π 3 and α 2 /r. In Matlab (Octave) script alpha0 pi; K0; nzeros(,k); alphazeros(,k); alpha()alpha0; α 2 /0.46 7.0625... α n + n + α 2 n 2 +... α 3 for k2:k %k to K n(k)round(alpha(k-)); %n(k)fix(alpha(k-)); alpha(k) /(alpha(k-)-n(k)); %disp([fix(k), round(n(k)), alpha(k)]); pause() end disp([n; alpha]); %Now compair this to matlab s rat() function rat(alpha0,e-20). By hand (you may use Matlab as a calculator), find the first 3 values of n k for α e π. 2. For part (), what is the error (remainder) when you truncate the continued fraction after n,...,n 3? Give the absolute value of the error, and the percentage error relative to the original α. 3. Use the Matlab program provided to find the first 0 values of n k for α e π, and verify your result using the Matlab command rat(). 4. Discuss the similarities and differences between the Euclidean algorithm (EA) and CFA. 5