EECS 2001A : Introduction to the Theory of Computation · Recursively de ned sets of binary...

21
EECS 2001A : Introduction to the Theory of Computation Suprakash Datta Course page: http://www.eecs.yorku.ca/course/2001 Also on Moodle S. Datta (York Univ.) EECS 2001A S 2020 1 / 21

Transcript of EECS 2001A : Introduction to the Theory of Computation · Recursively de ned sets of binary...

Page 1: EECS 2001A : Introduction to the Theory of Computation · Recursively de ned sets of binary strings: Example 1: The set of palindromic strings P 2P 0 2P;1 2P 8x 2P;0x0 2P;1x1 2P No

EECS 2001A : Introduction to the Theory of

Computation

Suprakash Datta

Course page: http://www.eecs.yorku.ca/course/2001Also on Moodle

S. Datta (York Univ.) EECS 2001A S 2020 1 / 21

Page 2: EECS 2001A : Introduction to the Theory of Computation · Recursively de ned sets of binary strings: Example 1: The set of palindromic strings P 2P 0 2P;1 2P 8x 2P;0x0 2P;1x1 2P No

Mathmatical Basics for Review

Review of Some Mathematics

Sets

Functions

Graphs

Recursive definitions

Logic

S. Datta (York Univ.) EECS 2001A S 2020 2 / 21

Page 3: EECS 2001A : Introduction to the Theory of Computation · Recursively de ned sets of binary strings: Example 1: The set of palindromic strings P 2P 0 2P;1 2P 8x 2P;0x0 2P;1x1 2P No

Mathmatical Basics for Review

Next

Review of sets

S. Datta (York Univ.) EECS 2001A S 2020 3 / 21

Page 4: EECS 2001A : Introduction to the Theory of Computation · Recursively de ned sets of binary strings: Example 1: The set of palindromic strings P 2P 0 2P;1 2P 8x 2P;0x0 2P;1x1 2P No

Mathmatical Basics for Review Sets

Sets

Representations

Notation: ∈,⊆,⊂

Common sets: natural numbers (N), integers (Z), real numbers(R), positive real numbers R+ = {x |x ∈ R, x > 0}

Universal set

Custom defined: Lprime = {x |x ∈ N, x is prime}

Operations: Union (A ∪ B), Intersection (A ∩ B), Complement(Ac)

Cardinality: |A|

S. Datta (York Univ.) EECS 2001A S 2020 4 / 21

Page 5: EECS 2001A : Introduction to the Theory of Computation · Recursively de ned sets of binary strings: Example 1: The set of palindromic strings P 2P 0 2P;1 2P 8x 2P;0x0 2P;1x1 2P No

Mathmatical Basics for Review Sets

Sets - Examples and Properties

Cartesian Product: A× B = {(a, b)|a ∈ A, b ∈ B}

If Σ = {0, 1}, then Σ× Σ = {(0, 0), (0, 1), (1, 0), (1, 1)}

Power set: set of all subsets of a set A. P(A) = {S |S ⊆ A}If A = {x , y}, then P(A) = {{}, {x}, {y}, {x , y}}

For any set A, A ∈ P(A) and ∅ ∈ P(A)

For finite sets, |P(A)| = 2|A|, |A× B| = |A| ∗ |B|

S. Datta (York Univ.) EECS 2001A S 2020 5 / 21

Page 6: EECS 2001A : Introduction to the Theory of Computation · Recursively de ned sets of binary strings: Example 1: The set of palindromic strings P 2P 0 2P;1 2P 8x 2P;0x0 2P;1x1 2P No

Mathmatical Basics for Review Sets

Next

Review of functions

S. Datta (York Univ.) EECS 2001A S 2020 6 / 21

Page 7: EECS 2001A : Introduction to the Theory of Computation · Recursively de ned sets of binary strings: Example 1: The set of palindromic strings P 2P 0 2P;1 2P 8x 2P;0x0 2P;1x1 2P No

Mathmatical Basics for Review Functions

Functions

f : A→ C , for all a ∈ A, f (a) ∈ C

f : A× B → C , for all a ∈ A, b ∈ B , f (a, b) ∈ C

Examples:f : N→ N, f (a) = 3a + 1f : N× N→ N, f (a, b) = 3a + 2b + ab + 1

Types: injective (one-one), surjective (onto), bijective (1:1correspondence)

S. Datta (York Univ.) EECS 2001A S 2020 7 / 21

Page 8: EECS 2001A : Introduction to the Theory of Computation · Recursively de ned sets of binary strings: Example 1: The set of palindromic strings P 2P 0 2P;1 2P 8x 2P;0x0 2P;1x1 2P No

Mathmatical Basics for Review Functions

Functions: Representation

Formula: f : N→ N, f (a) = 3a + 1

Table: g : {a, b} × {0, 1} → {a, b}

0 1a a bb b a

List (f ): {(1, 4), (2, 7), (3, 10), (4, 13), . . .}Each pair: first element is the input, second element is theoutput

List (g): {(a, 0, a), (a, 1, b), (b, 0, b), (b, 1, a)}Each triple: first 2 elements are inputs, last element is the output

S. Datta (York Univ.) EECS 2001A S 2020 8 / 21

Page 9: EECS 2001A : Introduction to the Theory of Computation · Recursively de ned sets of binary strings: Example 1: The set of palindromic strings P 2P 0 2P;1 2P 8x 2P;0x0 2P;1x1 2P No

Mathmatical Basics for Review Functions

Next

Review of graphs

S. Datta (York Univ.) EECS 2001A S 2020 9 / 21

Page 10: EECS 2001A : Introduction to the Theory of Computation · Recursively de ned sets of binary strings: Example 1: The set of palindromic strings P 2P 0 2P;1 2P 8x 2P;0x0 2P;1x1 2P No

Mathmatical Basics for Review Graphs

Graphs

Nodes and Edges, weights

Undirected, directed

Cycles, trees

Connected

New: Self-loops

S. Datta (York Univ.) EECS 2001A S 2020 10 / 21

Page 11: EECS 2001A : Introduction to the Theory of Computation · Recursively de ned sets of binary strings: Example 1: The set of palindromic strings P 2P 0 2P;1 2P 8x 2P;0x0 2P;1x1 2P No

Mathmatical Basics for Review Graphs

Examples

S. Datta (York Univ.) EECS 2001A S 2020 11 / 21

Page 12: EECS 2001A : Introduction to the Theory of Computation · Recursively de ned sets of binary strings: Example 1: The set of palindromic strings P 2P 0 2P;1 2P 8x 2P;0x0 2P;1x1 2P No

Mathmatical Basics for Review Graphs

Next

Introduction to recursive definitions

S. Datta (York Univ.) EECS 2001A S 2020 12 / 21

Page 13: EECS 2001A : Introduction to the Theory of Computation · Recursively de ned sets of binary strings: Example 1: The set of palindromic strings P 2P 0 2P;1 2P 8x 2P;0x0 2P;1x1 2P No

Mathmatical Basics for Review Recursive Definitions

Recursive definitions - 1

1 Sequences, E.g., Fibonacci sequence: fi , i ∈ Nf1 = f2 = 1

for n > 2, fn = fn−1 + fn−22 Structures, E.g., Binary trees

an empty tree is a binary tree

a node pointing to two binary trees, one its left child and theother one its right child, is a binary tree

3 Sets, Example: Even natural numbers Ne .

2 ∈ Ne

∀n ∈ Ne , n + 2 ∈ Ne

No other numbers are in Ne

S. Datta (York Univ.) EECS 2001A S 2020 13 / 21

Page 14: EECS 2001A : Introduction to the Theory of Computation · Recursively de ned sets of binary strings: Example 1: The set of palindromic strings P 2P 0 2P;1 2P 8x 2P;0x0 2P;1x1 2P No

Mathmatical Basics for Review Recursive Definitions

Recursive definitions - 2

Recursively defined sets of binary strings:

Example 1: The set of palindromic strings P

ε ∈ P

0 ∈ P, 1 ∈ P

∀x ∈ P, 0x0 ∈ P, 1x1 ∈ P

No other strings are in P

Example 2: The set E of all binary strings with an equal numberof zeroes and ones.

ε ∈ E

for every x , y in E , 0x1y and 1x0y are both in E

nothing else is in E .

S. Datta (York Univ.) EECS 2001A S 2020 14 / 21

Page 15: EECS 2001A : Introduction to the Theory of Computation · Recursively de ned sets of binary strings: Example 1: The set of palindromic strings P 2P 0 2P;1 2P 8x 2P;0x0 2P;1x1 2P No

Mathmatical Basics for Review Recursive Definitions

Recursive definitions - Exercises

Recursively define the following:

The set of odd natural numbers

The sequence of powers of 3 (1, 3, 9, 27, 81, . . .)

The set of all strings over {0, 1} that have exactly one zero

What set L does the following definition produce?a ∈ L; for any x ∈ L, ax , bx , xb are in L. Nothing is in L unlessit can be obtained by the previous statements

Prove that Example 2 on the previous slide is correct

S. Datta (York Univ.) EECS 2001A S 2020 15 / 21

Page 16: EECS 2001A : Introduction to the Theory of Computation · Recursively de ned sets of binary strings: Example 1: The set of palindromic strings P 2P 0 2P;1 2P 8x 2P;0x0 2P;1x1 2P No

Mathmatical Basics for Review Recursive Definitions

Next

Review of Logic

S. Datta (York Univ.) EECS 2001A S 2020 16 / 21

Page 17: EECS 2001A : Introduction to the Theory of Computation · Recursively de ned sets of binary strings: Example 1: The set of palindromic strings P 2P 0 2P;1 2P 8x 2P;0x0 2P;1x1 2P No

Mathmatical Basics for Review Logic Review

Logic Review - 1

Boolean Logic: The only ‘truth values’ are True, False

Operations: ∨,∧,¬

Quantifiers: ∀, ∃

statement: Suppose x ∈ Z, y ∈ Z, then ∀x∃y(y > x)“for any integer, there exists a larger integer”

Logical equivalence: a→ b “is the same as” (is logicallyequivalent to) ¬a ∨ b

Bidirectional Implication: a↔ b is logically equivalent to(a→ b) ∧ (b → a)

S. Datta (York Univ.) EECS 2001A S 2020 17 / 21

Page 18: EECS 2001A : Introduction to the Theory of Computation · Recursively de ned sets of binary strings: Example 1: The set of palindromic strings P 2P 0 2P;1 2P 8x 2P;0x0 2P;1x1 2P No

Mathmatical Basics for Review Logic Review

Logic Review - 2

Contrapositive and converse:

the contrapositive of a→ b is ¬b → ¬a

the converse of a→ b is b → a

Any statement is logically equivalent to its contrapositive, butnot to its converse.

S. Datta (York Univ.) EECS 2001A S 2020 18 / 21

Page 19: EECS 2001A : Introduction to the Theory of Computation · Recursively de ned sets of binary strings: Example 1: The set of palindromic strings P 2P 0 2P;1 2P 8x 2P;0x0 2P;1x1 2P No

Mathmatical Basics for Review Logic Review

Logic Review - 3

Predicate Logic: each variable must be quantified:∀x(x < y) is meaningless(Abuse of notation: ∀x ∈ R...)

Implication or AND/OR?

“All parrots like chilies”∀x(Parrot(x) ∧ LikeChilies(x))vs∀x(Parrot(x)→ LikeChilies(x))

“Some parrots like chilies”∃x(Parrot(x) ∧ LikeChilies(x))vs∃x(Parrot(x)→ LikeChilies(x))

S. Datta (York Univ.) EECS 2001A S 2020 19 / 21

Page 20: EECS 2001A : Introduction to the Theory of Computation · Recursively de ned sets of binary strings: Example 1: The set of palindromic strings P 2P 0 2P;1 2P 8x 2P;0x0 2P;1x1 2P No

Mathmatical Basics for Review Logic Review

Logic Review - 4

Subtleties of quantifiers

Negation of statements: ¬(a→ b) = ?¬(∀x∃y(y > x)) ≡ ∃x∀y(y ≤ x)LHS: negation of “for every integer, there exists a largerinteger”,RHS: “there exists an integer that is larger than every integer”

∀x∃yP(x , y) is not the same as ∃y∀xP(y , x)Consider P(y , x) : x ≤ y .∀x∃y(x ≤ y) is TRUE over Z (set y = x + 1)∃y∀x(x ≤ y) is FALSE over Z (there is no largest number in Z)

S. Datta (York Univ.) EECS 2001A S 2020 20 / 21

Page 21: EECS 2001A : Introduction to the Theory of Computation · Recursively de ned sets of binary strings: Example 1: The set of palindromic strings P 2P 0 2P;1 2P 8x 2P;0x0 2P;1x1 2P No

Mathmatical Basics for Review Logic Review

Understanding which Quantifier to Use

∃ or ∀?

Some people like basketball

People are careless when it comes to social distancing

Humans are mortal

Discrete Math problems are hard

S. Datta (York Univ.) EECS 2001A S 2020 21 / 21