Harvard CS121 and CSCI E-121 Lecture 2: Mathematical Preliminaries

Similar documents
COSE212: Programming Languages. Lecture 1 Inductive Definitions (1)

COSE212: Programming Languages. Lecture 1 Inductive Definitions (1)

CS 133 : Automata Theory and Computability

CS Automata, Computability and Formal Languages

In English, there are at least three different types of entities: letters, words, sentences.

CS 121, Section 2. Week of September 16, 2013

FABER Formal Languages, Automata. Lecture 2. Mälardalen University

CS 455/555: Mathematical preliminaries

Theory of Computation

Automata Theory and Formal Grammars: Lecture 1

Theory of Computer Science

Mathematical Preliminaries. Sipser pages 1-28

Section 1.3 Ordered Structures

Week Some Warm-up Questions

CSE 105 Homework 1 Due: Monday October 9, Instructions. should be on each page of the submission.

Definition: A binary relation R from a set A to a set B is a subset R A B. Example:

Chapter 1. Introduction

Theory of Computation

C1.1 Introduction. Theory of Computer Science. Theory of Computer Science. C1.1 Introduction. C1.2 Alphabets and Formal Languages. C1.

Automata: a short introduction

cse303 ELEMENTS OF THE THEORY OF COMPUTATION Professor Anita Wasilewska

Recap from Last Time

cse303 ELEMENTS OF THE THEORY OF COMPUTATION Professor Anita Wasilewska

Section Summary. Relations and Functions Properties of Relations. Combining Relations

CMSC 330: Organization of Programming Languages. Regular Expressions and Finite Automata

CMPSCI 250: Introduction to Computation. Lecture #23: Finishing Kleene s Theorem David Mix Barrington 25 April 2013

CMSC 330: Organization of Programming Languages

Harvard CS 121 and CSCI E-207 Lecture 10: CFLs: PDAs, Closure Properties, and Non-CFLs

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

Harvard CS 121 and CSCI E-207 Lecture 6: Regular Languages and Countability

Relations. Relations of Sets N-ary Relations Relational Databases Binary Relation Properties Equivalence Relations. Reading (Epp s textbook)

Closure Properties of Regular Languages

2.1 Sets. Definition 1 A set is an unordered collection of objects. Important sets: N, Z, Z +, Q, R.

1 Alphabets and Languages

Nondeterministic Finite Automata and Regular Expressions

What Is a Language? Grammars, Languages, and Machines. Strings: the Building Blocks of Languages

{a, b, c} {a, b} {a, c} {b, c} {a}

Today. Binary relations establish a relationship between elements of two sets

Relations. We have seen several types of abstract, mathematical objects, including propositions, predicates, sets, and ordered pairs and tuples.

Computational Theory

Chapter 9: Relations Relations

Formal Languages, Automata and Models of Computation

Automata and Languages

Set Theory. CSE 215, Foundations of Computer Science Stony Brook University

Today s topics. Introduction to Set Theory ( 1.6) Naïve set theory. Basic notations for sets

CSCI 340: Computational Models. Regular Expressions. Department of Computer Science

Before we show how languages can be proven not regular, first, how would we show a language is regular?

Definition: Let S and T be sets. A binary relation on SxT is any subset of SxT. A binary relation on S is any subset of SxS.

Sets and Functions. MATH 464/506, Real Analysis. J. Robert Buchanan. Summer Department of Mathematics. J. Robert Buchanan Sets and Functions

1. Draw a parse tree for the following derivation: S C A C C A b b b b A b b b b B b b b b a A a a b b b b a b a a b b 2. Show on your parse tree u,

cse303 ELEMENTS OF THE THEORY OF COMPUTATION Professor Anita Wasilewska

Chapter Summary. Sets The Language of Sets Set Operations Set Identities Functions Types of Functions Operations on Functions Computability

CS21 Decidability and Tractability

Comment: The induction is always on some parameter, and the basis case is always an integer or set of integers.

Relationships between elements of sets occur in many contexts. Every day we deal with

Context-free grammars and languages

Equivalence, Order, and Inductive Proof

Foundations of Computer Science Lecture 23 Languages: What is Computation?

CSE 105 THEORY OF COMPUTATION

Chapter 0 Introduction. Fourth Academic Year/ Elective Course Electrical Engineering Department College of Engineering University of Salahaddin

Introduction to Automata

UNIT-I. Strings, Alphabets, Language and Operations

Theoretical Computer Science

Lecture 2: Connecting the Three Models

BASIC MATHEMATICAL TECHNIQUES

1 More finite deterministic automata

Compiler Design. Spring Lexical Analysis. Sample Exercises and Solutions. Prof. Pedro C. Diniz

Foundations of Mathematics MATH 220 FALL 2017 Lecture Notes

Definition: A binary relation R from a set A to a set B is a subset R A B. Example:

Axioms of Kleene Algebra

MA/CSSE 474 Theory of Computation. Your Questions? Previous class days' material Reading Assignments

Computational Models - Lecture 1 1

cse303 ELEMENTS OF THE THEORY OF COMPUTATION Professor Anita Wasilewska

CS 455/555: Finite automata

Languages, regular languages, finite automata

Regular expressions and Kleene s theorem

DRAFT MATERIAL. Induction, Recursion and Programming

Chapter Summary. Sets (2.1) Set Operations (2.2) Functions (2.3) Sequences and Summations (2.4) Cardinality of Sets (2.5) Matrices (2.

COMP9020 Lecture 3 Session 2, 2014 Sets, Functions, and Sequences. Revision: 1.3

Foundations of Mathematics

Lecture 1 09/08/2017

Theory of Computation 1 Sets and Regular Expressions

INF210 Datamaskinteori (Models of Computation)

CDM Closure Properties

TAFL 1 (ECS-403) Unit- III. 3.1 Definition of CFG (Context Free Grammar) and problems. 3.2 Derivation. 3.3 Ambiguity in Grammar

HKN CS/ECE 374 Midterm 1 Review. Nathan Bleier and Mahir Morshed

Dynamic Programming. Shuang Zhao. Microsoft Research Asia September 5, Dynamic Programming. Shuang Zhao. Outline. Introduction.

Sri vidya college of engineering and technology

Finite Automata and Regular Languages

CS 154, Lecture 4: Limitations on DFAs (I), Pumping Lemma, Minimizing DFAs

CS 154. Finite Automata vs Regular Expressions, Non-Regular Languages

Finite Automata Part One

Finite Automata Part One

0 Sets and Induction. Sets

Sets are one of the basic building blocks for the types of objects considered in discrete mathematics.

Binomial Coefficient Identities/Complements

Induction and Recursion

Closure Properties of Regular Languages. Union, Intersection, Difference, Concatenation, Kleene Closure, Reversal, Homomorphism, Inverse Homomorphism

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2017

The integers. Chapter 3

Transcription:

Harvard CS121 and CSCI E-121 Lecture 2: Mathematical Preliminaries Harry Lewis September 5, 2013 Reading: Sipser, Chapter 0

Sets Sets are defined by their members A = B means that for every x, x A iff x B Example: N = {0, 1, 2,...} Cardinality Sets can be finite (e.g. {1, 3, 5}) or infinite (e.g. N ). Q: Is {N } finite? If A is finite (A = {a 1,..., a n } for some n N ), then its cardinality (or size) A is n, the number of elements in A. The empty set has cardinality 0. Cardinality of infinite sets to be discussed later! 1

Set Operations union {a, b} {b, c} = {a, b, c} intersection {a, b} {b, c} = {b} difference {a, b} {b, c} =?? \ another name for 2

Set Operations union {a, b} {b, c} = {a, b, c} intersection {a, b} {b, c} = {b} difference {a, b} {b, c} = {a} \ another name for A and B are disjoint iff A B = The power set of S = P (S) = {X : X S} e.g. P ({a, b}) = {, {a}, {b}, {a, b}} Q: What is P (S)? The Cartesian product of sets A, B A B = {(a, b) : a A, b B} triples,... 3

Set Operations union {a, b} {b, c} = {a, b, c} intersection {a, b} {b, c} = {b} difference {a, b} {b, c} = {a} \ another name for A and B are disjoint iff A B = The power set of S = P (S) = {X : X S} e.g. P ({a, b}) = {, {a}, {b}, {a, b}} The Cartesian product of sets A, B A B = {(a, b) : a A, b B} triples,... 4

Set Operations union {a, b} {b, c} = {a, b, c} intersection {a, b} {b, c} = {b} difference {a, b} {b, c} = {a} \ another name for A and B are disjoint iff A B = The power set of S = P (S) = {X : X S} e.g. P ({a, b}) = {, {a}, {b}, {a, b}} The Cartesian product of sets A, B A B = {(a, b) : a A, b B} triples,... 5

Some little exercises Assume all sets are finite What is the relation between A, B, and A B? A B? A B? P (S)? 6

Functions A function f : S T maps each element s S to (exactly one) element of T, denoted f(s). For example, f(n) = n 2 is a function from Z N (Z = all integers) 7

Special varieties of functions S T S T S T 1-1: s 1 s 2 f(s 1 ) f(s 2 ) Onto: For every t T there is an s S such that f(s) = t Bijection: 1-1 and onto 1-1 Correspondence Formal definition of cardinality: S has (finite) cardinality n N iff there is a bijection f : {1,..., n} S. 8

Special varieties of functions S T S T S T 1-1: s 1 s 2 f(s 1 ) f(s 2 ) Onto: For every t T there is an s S such that f(s) = t Bijection: 1-1 and onto 1-1 Correspondence Formal definition of cardinality: S has (finite) cardinality n N iff there is a bijection f : {1,..., n} S. 9

Relations A k-ary relation on S 1,..., S k is a subset of S 1... S k [A function f : S T corresponds to the relation {(s, f(s)) : s S} S T.] A binary relation on S is a subset of S S For example, (GWB, GHWB) Son, where Son = {(x, y) : x is a son of y} 10

What is a (directed) graph? A binary relation can be pictured as a directed graph : a b c d (Still assuming a finite set of nodes) Every edge has a direction Only one arrow between two nodes in the same direction Self-loops possible 11

What is a (directed) graph? A binary relation can be pictured as a directed graph : a b = {(a, b), (a, c), (b, d), (d, b), (d, d)} c d Formally, a directed graph G consists of a finite set V of vertices (or nodes), and a set of edges E V V. NB: Because a relation (or edge set) is a set (of ordered pairs), there can be only one arrow from one node to another. 12

What is a (directed) graph? A binary relation can be pictured as a directed graph : a b = {(a, b), (a, c), (b, d), (d, b), (d, d)} c d Formally, a directed graph G consists of a finite set V of vertices (or nodes), and a set of edges E V V. NB: Because a relation (or edge set) is a set (of ordered pairs), there can be only one arrow from one node to another. 13

Properties of Binary Relations A relation R S S is: reflexive if a for each a S i.e., (a, a) R for each a S symmetric if a b whenever a b i.e., for any a, b S, if (a, b) R then (b, a) R transitive if a c whenever a b and b c i.e., if (a, b) R and (b, c) R, then (a, c) R 14

Transitive, not symmetric nor reflexive Symmetric, not reflexive, nor transitive Reflexive & symmetric, not transitive Reflexive, transitive, and symmetric 15

Equivalence Relations A relation that satisfies all three properties is called an equivalence relation An equivalence relation decomposes S into equivalence classes any two members of the same equivalence class bear the relation to each other. 16

Which Properties Do These Relations Have? Domain People People People Relation Lives-In-The-Same-City-As Is-An-Ancestor-Of Is-A-Brother-Of 17

Undirected graphs A symmetric relation with no self-loops (that is, for every a, (a, a) / R) can be depicted as an undirected graph Source: http://www.howweknowus.com/2008/07/23/great-work-lousy-title/ 18

Subject: Re: six degrees to harry lewis On Friday, January 23, 2004, at 05:09 AM, Mark Elliot Zuckerberg wrote: Professor, I ve been interested in graph theory and its applications to social networks for a while now, so I did some research (on my own time) that has to do with linking people through articles they appear in from the Crimson. I thought people would find this interesting, so I ve set up a preliminary site that allows people to find the connection (through people and articles) from any person to the most frequently mentioned person in the time frame I looked at. This person is you. 19

Six degrees, continued From: Harry Lewis <lewis@deas.harvard.edu> Date: January 23, 2004 4:25:44 PM EST To: Mark Elliot Zuckerberg <mzuckerb@fas.harvard.edu> Subject: Re: six degrees to harry lewis 20

Six degrees, continued From: Harry Lewis <lewis@deas.harvard.edu> Date: January 23, 2004 4:25:44 PM EST To: Mark Elliot Zuckerberg <mzuckerb@fas.harvard.edu> Subject: Re: six degrees to harry lewis Sure, what the hell. Seems harmless. 21

Strings and Languages Symbol a, b,... Alphabet A finite, nonempty set of symbols usually denoted by Σ String (informal) Finite number of symbols put together e.g. abba, b, bb Empty string denoted by ε Σ = set of all strings over alphabet Σ e.g. {a, b} = {ε, a, b, aa, ab,...} 22

More on Strings Length of a string x is written x abba = 4 a = 1 ε = 0 The set of strings of length n is denoted Σ n. 23

Concatenation Concatenation of strings Written as x y, or just xy Just follow the symbols of x by the symbols of y x = abba, y = b xy = abbab xε = εx = x for any x The reversal x R of a string x is x written backwards. If x = x 1 x 2 x n, and each x i Σ, then x R = x n x n 1 x 1. 24

Formal Inductive Definitions Like recursive data structures and recursive procedures when programming. Strings and their length: ε is a string of length 0. If x is a string of length n and σ Σ, then xσ is a string of length n + 1. (i.e. start with ε and add one symbol at a time, like εaaba, but we don t write the initial ε unless the string is empty) 25

Inductive definitions of string operations The concatenation of x and y, defined by induction on y. [ y = 0 ] x ε = x [ y = n + 1 ] write y = zσ for some z = n, σ Σ define x (zσ) = (x z)σ The reversal of x, defined by induction on x : [ x = 0 ] ε R = ε [ x = n + 1 ] (yσ) R = σ y R, for any y = n, σ Σ 26

Inductive definitions of string operations The concatenation of x and y, defined by induction on y. [ y = 0 ] x ε = x [ y = n + 1 ] write y = zσ for some z = n, σ Σ define x (zσ) = (x z)σ, The reversal of x, defined by induction on x : [ x = 0 ] ε R = ε [ x = n + 1 ] (yσ) R = σ y R, for any y = n, σ Σ 27

An inductive proof Proposition: The n th Fibonacci number is the number of strings over {a, b} of length n 2 with no consecutive b s. First step: make sure you know what everything means What are the Fibonacci numbers? Where does the indexing start? How does the statement of the proposition need to be cleaned up to be precise? Is the proposition true for the smallest value of n? If it is true for small values of n, say for all n k, why would it be true for n = k + 1? 28

So here is what we want to prove: Proposition: For every n 2, F n is the number of strings over {a, b} of length n 2 with no consecutive b s. Proof: Base case: Prove it for n = 2 and n = 3, by a hand check. Induction step: For any n, let X n be the set of strings of length n with no consecutive b s. We have proven that X n = F n+2 for n = 0 and n = 1. Now let k be any number 1 and assume we have proven that X n = F n+2 for all n k. We want to conclude that X k+1 = F k+3. 29

If x X k+1 then x ends with either a or b. So let s split X k+1 into those two subsets, A k+1 and B k+1, and count how many strings are in each. The number of strings in A k+1 is the number of strings in X k since stripping off the final a leaves a string with no consecutive b s, and it could be any string of length k with no consecutive b s. But we already know that X k = F k+2. The number of strings in B k+1 is the number of strings in X k 1, since a string of length k + 1 ending in b must actually end in ab, and the rest of the string, dropping the last two symbols, could be any string of length k 1 with no consecutive b s. We already know that X k 1 = F k+1. So X k+1 = A k+1 + B k+1 = F k+2 + F k+1 = F k+3. 30

Languages A language L over alphabet Σ is a set of strings over Σ (i.e. L Σ ) Computational problem: given x Σ, is x L? Any YES/NO problems can be cast as a language. Examples of simple languages: All words in the American Heritage Dictionary {a, aah, aardvark,..., zyzzva}. Σ Σ {x Σ : x = 3} = {aaa, aab, aba, abb, baa, bab, bba, bbb} 31

More complicated languages The set of strings x {a, b} such that x has more a s than b s. The set of strings x {0, 1} such that x is the binary representation of a prime number. All C programs that do not go into an infinite loop. L 1 L 2, L 1 L 2, L 1 L 2 if L 1 and L 2 are languages.. 32

The highly abstract and metaphorical term language A language can be either finite or infinite A language need not have any internal structure 33

Be careful to distinguish ε The empty string (a string) The empty set (a set, possibly a language) {ε} The set containing one element, which is the empty string (a language) { } The set containing one element, which is the empty set (a set of sets, maybe a set of languages) 34

Operations on Languages Set operations Concatenation of Languages L 1 L 2 = {xy : x L 1, y L 2 } e.g. {a, b}{a, bb} = {aa, ba, abb, bbb} e.g. {ε}l = L e.g. L =? 35

Kleene star L = {w 1 w n : n 0, w 1,..., w n L} e.g. {aa} = {ε, aa, aaaa,...} e.g. {ab, ba, aa, bb} = all even length strings e.g. Σ = Kleene Star of Σ e.g. =? 36