formalism and languages: sets and languages dr. troy ... · david r. cheriton school of computer...

32
Formalism and Languages: Sets and Languages Dr. Troy Vasiga David R. Cheriton School of Computer Science University of Waterloo WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

Upload: phungnhu

Post on 29-Apr-2018

217 views

Category:

Documents


3 download

TRANSCRIPT

Formalism and Languages: Sets and Languages

Dr. Troy VasigaDavid R. Cheriton School of Computer Science

University of Waterloo

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

Outline

• Short Biography of the Speaker

• MathCircles Ground Rules

• Upcoming Lectures

• Overview

• Sets

• Alphabets, Words and Languages

• Finite Languages

• Regular Languages

• Closure Examples

• Exercises

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

Short biography of the speaker

• Academic background:• B.Math (Computer Science and Combinatorics and

Optimization, Double Degree), UW, 19• M.Math (Combinatorics and Optimization) [thesis topic:

“α-resolvable designs of block size 4”], UW, 19• B.Ed, UBC, 19• Ph.D (Computer Science) “Error detection and correction in

number-theoretic algorithms”, UW, 20

• Current Position:• Lecturer, David R. Cheriton School of Computer Science• Associate Director, Centre for Education in Mathematics and

Computing

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

Short biography of the speaker

• Academic life• teach (mostly) first- and second-year CS courses (CS 115, 116,

135, 241)• coordinate the Canadian Computing Competition (organize

problem creation, publication of results, communication withteachers, select Canadian Computing Olympiad invitees, trainand supervise the Canadian IOI team)

• do lots of school visits (elementary and secondary schools inOntario, Malaysia, Singapore, China, Hong Kong)

• reviewer and grader for other math competitions (Euclid,CIMC/CSMC)

• sit on or chair various CS committees (UndergraduateRecruiting, Outreach, Scholarship committees)

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

Short biography of the speaker

• Non-academic life• bicycle to work every day (yes, every day)• enjoy working out at the gym regularly• enjoy travel (through work and outside of work)• love playing Uno, Sleeping Queens, and Clue and reading with

daughter Natalie• love dinner and movies with lovely wife Krista• enjoy hanging out with neighbourhood friends

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

MathCircles Ground Rules

• Be polite.• listen while presenters are talking• ask questions in a polite manner

• Be punctual.• your instruction will be here from 6:30-8:30• so should you• some material will build on previous material: try to come

weekly

• Be engaged.• listen while presenters are talking• don’t check your phone• don’t do your other homework• work on the problems/exercises given to you

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

Upcoming Lectures

• Oct 28, Nov 4, Nov 11: Carmen Bruni, Number Theory

• Nov 18, Nov 25: Shahla Aliakbari, Real World Applied Math

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

Overview of Lecture

The goal of the next three lectures is to:

• introduce notation as a tool in mathematics

• describe formally what a language is

• classify the descriptive power of various languages

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

Sets

• a set is a collection of objects

• these objects can be anything

• Examples:• {a, b, c}• {troy, michael, john}• {α, {ℵ}, Z}

• a set can be empty: denoted as {} or ∅• a set can be infinite

• N = {0, 1, 2, . . .}• Z = {. . . ,−2,−1, 0, 1, 2, . . .}

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

Subsets

We say that a set A is a subset of B if:

every element of A is alsoin B.

To state this more formally, if x ∈ A, then it follows that x ∈ B.

We denote this as A ⊆ B.

What if A ⊆ B and B ⊆ A?

Then, A = B.

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

Subsets

We say that a set A is a subset of B if: every element of A is alsoin B.

To state this more formally, if x ∈ A, then it follows that x ∈ B.

We denote this as A ⊆ B.

What if A ⊆ B and B ⊆ A?

Then, A = B.

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

Subsets

We say that a set A is a subset of B if: every element of A is alsoin B.

To state this more formally, if x ∈ A, then it follows that x ∈ B.

We denote this as A ⊆ B.

What if A ⊆ B and B ⊆ A?

Then, A = B.

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

Subsets

We say that a set A is a subset of B if: every element of A is alsoin B.

To state this more formally, if x ∈ A, then it follows that x ∈ B.

We denote this as A ⊆ B.

What if A ⊆ B and B ⊆ A?

Then, A = B.

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

Subsets

We say that a set A is a subset of B if: every element of A is alsoin B.

To state this more formally, if x ∈ A, then it follows that x ∈ B.

We denote this as A ⊆ B.

What if A ⊆ B and B ⊆ A?

Then, A = B.

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

Operations

1. Union: A ∪ B = {x : x ∈ A or x ∈ B}

2. Intersection: A ∩ B = {x : x ∈ A and x ∈ B}

3. Difference: A− B = {x : x ∈ A and x 6∈ B}

4. Cartesian Product: A× B = {(x , y) : x ∈ A and y ∈ B}

5. Concatenation: AB = A ◦ B = {xy : x ∈ A and y ∈ B}

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

Set ExamplesSuppose A = {a, b, c} and B = {a, c , d , t}.What are:• A ∪ B:

• A ∩ B:

• A− B:

• B − A:

• A× B:

• AB:

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

Properties of Sets• Idempotentency: A ∪ A = A ∩ A = A

• Commutativity:

A ∪ B = B ∪ A and A ∩ B = B ∩ A

• Associativity:

(A ∪ B) ∪ C = A ∪ (B ∪ C )

(A ∩ B) ∩ C = A ∩ (B ∩ C )

• DeMorgan’s Laws:

A− (B ∪ C ) = (A− B) ∩ (A− C )

A− (B ∩ C ) = (A− B) ∪ (A− C )

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

Properties of Sets• Idempotentency: A ∪ A = A ∩ A = A

• Commutativity:

A ∪ B = B ∪ A and A ∩ B = B ∩ A

• Associativity:

(A ∪ B) ∪ C = A ∪ (B ∪ C )

(A ∩ B) ∩ C = A ∩ (B ∩ C )

• DeMorgan’s Laws:

A− (B ∪ C ) = (A− B) ∩ (A− C )

A− (B ∩ C ) = (A− B) ∪ (A− C )

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

Properties of Sets• Idempotentency: A ∪ A = A ∩ A = A

• Commutativity:

A ∪ B = B ∪ A and A ∩ B = B ∩ A

• Associativity:

(A ∪ B) ∪ C = A ∪ (B ∪ C )

(A ∩ B) ∩ C = A ∩ (B ∩ C )

• DeMorgan’s Laws:

A− (B ∪ C ) = (A− B) ∩ (A− C )

A− (B ∩ C ) = (A− B) ∪ (A− C )

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

Properties of Sets• Idempotentency: A ∪ A = A ∩ A = A

• Commutativity:

A ∪ B = B ∪ A and A ∩ B = B ∩ A

• Associativity:

(A ∪ B) ∪ C = A ∪ (B ∪ C )

(A ∩ B) ∩ C = A ∩ (B ∩ C )

• DeMorgan’s Laws:

A− (B ∪ C ) = (A− B) ∩ (A− C )

A− (B ∩ C ) = (A− B) ∪ (A− C )

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

Proof of DeMorgan’s Law

Let’s prove: A− (B ∪ C ) = (A− B) ∩ (A− C )

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

Alphabets, Words and LanguagesAn alphabet is a finite set of symbols. Usually, we denotealphabets using the symbol Σ.

A word (or string) over an alphabet is a finite sequence of symbolsfrom the alphabet.

We will use the notation ε to denote the empty word: the sequenceof zero symbols from an alphabet.

We will use Σ∗ to denote the set of all words over an alphabet Σ.Thus, any word w over an alphabet Σ must satisfy w ∈ Σ∗.

A language is a set of words over an alphabet. Examples:• ∅• Σ• Σ∗

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

Alphabets, Words and LanguagesAn alphabet is a finite set of symbols. Usually, we denotealphabets using the symbol Σ.

A word (or string) over an alphabet is a finite sequence of symbolsfrom the alphabet.

We will use the notation ε to denote the empty word: the sequenceof zero symbols from an alphabet.

We will use Σ∗ to denote the set of all words over an alphabet Σ.Thus, any word w over an alphabet Σ must satisfy w ∈ Σ∗.

A language is a set of words over an alphabet. Examples:• ∅• Σ• Σ∗

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

Alphabets, Words and LanguagesAn alphabet is a finite set of symbols. Usually, we denotealphabets using the symbol Σ.

A word (or string) over an alphabet is a finite sequence of symbolsfrom the alphabet.

We will use the notation ε to denote the empty word: the sequenceof zero symbols from an alphabet.

We will use Σ∗ to denote the set of all words over an alphabet Σ.Thus, any word w over an alphabet Σ must satisfy w ∈ Σ∗.

A language is a set of words over an alphabet. Examples:

• ∅• Σ• Σ∗

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

Alphabets, Words and LanguagesAn alphabet is a finite set of symbols. Usually, we denotealphabets using the symbol Σ.

A word (or string) over an alphabet is a finite sequence of symbolsfrom the alphabet.

We will use the notation ε to denote the empty word: the sequenceof zero symbols from an alphabet.

We will use Σ∗ to denote the set of all words over an alphabet Σ.Thus, any word w over an alphabet Σ must satisfy w ∈ Σ∗.

A language is a set of words over an alphabet. Examples:• ∅• Σ• Σ∗

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

Finite Languages

Since languages are sets, and sets can be finite, we can have finitelanguages.

For example, if Σ = {a, b, c} then the languages

L1 = {aa, bb, cc}

andL2 = {a, aa, aaa, bbbb, ccccccccc}

are both finite.

Finite languages are not very interesting.

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

Finite Languages

Since languages are sets, and sets can be finite, we can have finitelanguages.

For example, if Σ = {a, b, c} then the languages

L1 = {aa, bb, cc}

andL2 = {a, aa, aaa, bbbb, ccccccccc}

are both finite.Finite languages are not very interesting.

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

Regular Languages

We can construct a certain class of languages called regularlanguages which are defined only using regular expressions.

A regular expression over alphabet Σ is defined as:

• ∅ and each x ∈ Σ are valid regular expressions

• If R1 and R2 are both regular expressions, then so is R1R2.(Concatenation)

• If R1 and R2 are both regular expressions, then so is R1 ∪ R2

(Union).

• If R is a regular expression, then so is R∗ (Repetition).

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

Regular Language notation

Instead of using the “set-notation” (e.g., {, }, ∪, etc.) regularlanguages have their own form of operators:

• If R1 and R2 are regular languages, then so is R1|R2 (Union).

• If R1 and R2 are regular languages, then so is R1R2

(Concatentation).

• If R is a regular language, then R∗ is also regular (Repetition).

• If R is a regular language, then (R) is also regular. (Grouping,for clarity)

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

Regular Expression Examples

1. Σ = {a, b}. Define all words that end in a.

2. What is a(bb∗|a)?

3. Σ = {a, b}. Define all words that have an even length.

4. Σ = {a, b}. Define all words that have an even number of a’s.

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

Closure

We say that regular languages are closed under union,concatenation and repetition. In other words, applying theseoperations to an regular language will produce a regular language.

• The integers are closed under addition.

• The even integers are closed under addition.

• The integers are not closed under division.

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING

Exercises

WWW.CEMC.UWATERLOO.CA | The CENTRE for EDUCATION in MATHEMATICS and COMPUTING