Congruence and Sets

Congruence and Sets
Dali - β€œThe Persistence of Memory”
Discrete Structures (CS 173) Lecture 5
Gul Agha
University of Illinois at Urbana-Champaign
Based on lecture notes by Derek Hoiem
1
Review of Last Class
β€’ A composite integer π‘˜ can be factored into smaller integers
whose product is equal to π‘˜
β€’ π‘Ž divides 𝑏 means that b= π‘˜π‘Ž for some integer π‘˜
β€’ Two numbers are relatively prime if they have no common
prime factors
β€’ 𝐠𝐜𝐝(π‘Ž, 𝑏) is the largest integer that divides both π‘Ž and 𝑏
β€’ lcm(π‘Ž, 𝑏) is the smallest integer that both π‘Ž and 𝑏 divide
2
Goals of this lecture
β€’ Introduce the concept of congruence mod k
3 ≑ 15 (mod 12)
β€’ Be able to perform modulus arithmetic
β€’ Brief introduction to sets
3
Applications of congruence
β€’
β€’
β€’
β€’
β€’
β€’
bitwise operations
error checking
computing 2D coordinates in images
encryption
telling time
etc.
4
Congruence mod k
β€’ Two integers are congruent mod k if they
differ by an integer multiple of k
β€’ Definition: If π‘˜ is any positive integer, two
integers π‘Ž and 𝑏 are congruent mod k iff π‘˜
divides (π‘Ž βˆ’ 𝑏)
π‘Ž ≑ 𝑏 mod π‘˜ ↔ π‘˜ | (π‘Ž βˆ’ 𝑏)
5
Examples of congruent mod k
overhead
6
Modulus addition proof
Claim: For any integers π‘Ž, 𝑏, 𝑐, 𝑑, π‘˜ with π‘˜ > 0, if π‘Ž ≑ 𝑏 (mod π‘˜)
and 𝑐 ≑ 𝑑 (mod π‘˜) then π‘Ž + 𝑐 ≑ (𝑏 + 𝑑) (mod π‘˜)
Definition: π‘Ž ≑ 𝑏 mod π‘˜ ↔ π‘˜ | (π‘Ž βˆ’ 𝑏)
overhead
7
Modulus multiplication proof
Claim: For any integers π‘Ž, 𝑏, 𝑐, 𝑑, π‘˜ with π‘˜ > 0, if π‘Ž ≑ 𝑏 (mod π‘˜)
and 𝑐 ≑ 𝑑 (mod π‘˜) then π‘Žπ‘ ≑ 𝑏𝑑 (mod π‘˜)
Definition: π‘Ž ≑ 𝑏 mod π‘˜ ↔ π‘˜ | (π‘Ž βˆ’ 𝑏)
overhead
8
Equivalence classes with modulus
The equivalence class of integer π‘₯ (written [π‘₯])
is the set of all integers congruent to π‘₯ (mod π‘˜)
In (mod 7), 3 = {… , βˆ’11, βˆ’4, 3, 10, 17, … }
In (mod 5), 3 = {… , βˆ’7, βˆ’2, 3, 8, 13, … }
In 𝑍5, 3 = 8 = [βˆ’2]
9
Modulus arithmetic
π‘₯ + 𝑦 = [π‘₯ + 𝑦]
π‘₯ βˆ— 𝑦 = [π‘₯ βˆ— 𝑦]
overhead
10
Short Break
(2517 +26)2 ≑ ______ (π‘šπ‘œπ‘‘ 3)
xkcd #183
11
RSA Key Generation
β€’ Creating the public and private keys for encryption/decryption
–
–
–
–
–
Choose two prime numbers 𝑝 and π‘ž
𝑛 = π‘π‘ž
π‘˜ = (𝑝 βˆ’ 1)(π‘ž βˆ’ 1)
Choose an integer 𝑒 such that 𝑒 ≀ π‘˜ and 𝑒 is relatively prime with k
Solve for 𝑑𝑒 ≑ 1 mod π‘˜ (e.g., with extended Euclidean algorithm)
β€’ Using the keys
– Public key: 𝑛, 𝑒
– Private key: 𝑑
– Encryption
β€’ Turn message into an integer π‘š
β€’ Coded message 𝑐 ≑ π‘šπ‘’ (mod 𝑛)
– Decryption
β€’ Original message π‘š ≑ 𝑐 𝑑 (mod 𝑛)
12
Another congruence proof
Claim: If 𝑛 is odd, then 𝑛2 ≑ 1 (mod 8)
Definition: π‘Ž ≑ 𝑏 mod π‘˜ ↔ π‘˜ | (π‘Ž βˆ’ 𝑏)
overhead
13
Sets
Topics: lists, set builders, tuples vs. sets, equivalence, cardinality,
subsets and supersets
overhead
14
Things to remember
β€’ Concept of congruence mod k, it’s definition
in terms of divide, and equivalence classes
– Many applications in CS
β€’ The key to modular arithmetic is keeping
numbers small
β€’ Concept of sets and set equivalence
15
Set Application: analysis of purchasing patterns
β€’ How similar are two
shopper’s purchases? (e.g.,
intersection / union of
purchased items)
β€’ If someone buys x and y,
what might she buy next?
Application: counting
β€’ 1000 people are asked whether they like tea
and/or coffee
– 600 like tea
– 500 like coffee
– 200 like neither
– How many like both?
17
Thinking about sets
overhead
18
Constructing sets
β€’ Miscellaneous elements: extensional definition
β€’ Constructors: multiples of 3, squared numbers, quadrant, line
segment (intentional definition)
overhead
19
The empty set
β€’ βˆ… (in latex: \emptyset)
β€’ All sets are supersets of the empty set
β€’ The empty set contains no elements
20
Subset transitivity proof
Claim: For any sets 𝐴, 𝐡, 𝐢, if 𝐴 βŠ† 𝐡 and 𝐡 βŠ† 𝐢, then 𝐴 βŠ† 𝐢
Definition: 𝐴 is a subset of 𝐡 if every element of 𝐴 is also an
element of 𝐡
21
Set operations
β€’ Intersection, union, difference
β€’ De Morgan’s Laws
overhead
22
Sizes of sets
β€’ For discrete sets: the number of unique
elements in the set
β€’ For continuous sets: measures of cardinality.
β€’ 𝐴 βˆͺ 𝐡 = 𝐴 + 𝐡 βˆ’ |𝐴 ∩ 𝐡|
23
Set size problems
β€’ 1000 people are asked whether they like mint and/or
chamomile:
–
–
–
–
600 like mint
500 like chamomile
200 like neither
How many like both?
β€’ How many numbers from 0 to 99 have a β€œ7” in them?
overhead
24
Short break
xkcd 1180
1. All humanoids eat bananas, except humanoids with unpainted yellow noses (to avoid
confusion).
2. There are 1,000 humanoids on Krog, of which 200 naturally have yellow noses.
3. There have been two recent sprees of nose-paintings. 50 originally yellow-nosed
humanoids were painted in each spree, and 10 unlucky ones were painted twice.
4. How many banana-eating humanoids are left?
25
Cartesian products (cross-products)
β€’ Cartesian product 𝐴 × π΅ consists of pairs
π‘₯, 𝑦 for each π‘₯ ∈ 𝐴 and 𝑦 ∈ 𝐡
β€’ Creates tuples that provide all ordered
combinations of sets
overhead
26
Inclusion proof
Claim: Let 𝐴 = π‘₯, 5 βˆ’ π‘₯ βˆ’ 3 2 : π‘₯ ∈ 1, 5 ,
𝐡 = π‘₯, 𝑦 ∈ 𝑅, π‘₯ β‰₯ 0, 𝑦 β‰₯ 0 .
Show 𝐴 βŠ† 𝐡.
Definition: 𝐴 is a subset of 𝐡 if every element of 𝐴 is also an
element of 𝐡
overhead
27
Contrapositive proof
Claim: For any sets 𝐴 and 𝐡, if 𝐴 βˆ’ 𝐡 βˆͺ 𝐡 βˆ’ 𝐴 = 𝐴 βˆͺ 𝐡, then 𝐴 ∩ 𝐡 = βˆ….
overhead
28
Things to remember
β€’ Sets and set constructors
β€’ How to operate on sets: intersection, union,
difference, not, Cartesian product
β€’ How to count elements of a set or
combination of sets
β€’ Proof strategies for sets
29
Administrative
β€’ First Examlet on Thursday!
β€’ DRES and auditors: let me know who you are
β€’ There will be a new moodle activity due Friday
30