Theory of Languages and Automatace.sharif.edu/courses/97-98/2/ce415-1/resources/root... · 2020. 9....

80
Theory of Languages and Automata Chapter 0 - Introduction Sharif University of Technology

Transcript of Theory of Languages and Automatace.sharif.edu/courses/97-98/2/ce415-1/resources/root... · 2020. 9....

Page 1: Theory of Languages and Automatace.sharif.edu/courses/97-98/2/ce415-1/resources/root... · 2020. 9. 7. · OFinal Exam 40-50% Theory of Languages and Automata Prof. Movaghar 3. Teaching

Theory of Languages and Automata

Chapter 0 - Introduction

Sharif University of Technology

Page 2: Theory of Languages and Automatace.sharif.edu/courses/97-98/2/ce415-1/resources/root... · 2020. 9. 7. · OFinal Exam 40-50% Theory of Languages and Automata Prof. Movaghar 3. Teaching

ReferencesO Main Reference

§ M. Sipser, ”Introduction to the Theory of Computation,� 3nd Ed., Cengage Learning , 2013.

O Additional References§ P. Linz, �An Introduction to Formal Languages and Automata,� 3rd

Ed., Jones and Barlett Publishers, Inc., 2001.§ J.E. Hopcroft, R. Motwani and J.D. Ullman, �Introduction to

Automata Theory, Languages, and Computation,� 2nd Ed., Addison-Wesley, 2001.

§ P.J. Denning, J.B. Dennnis, and J.E. Qualitz, �Machines, Languages, and Computation,� Prentice-Hall, Inc., 1978.

§ P.J. Cameron, �Sets, Logic and Categories,� Springer-Verlag, London limited, 1998.

Prof. MovagharTheory of Languages and Automata 2

Page 3: Theory of Languages and Automatace.sharif.edu/courses/97-98/2/ce415-1/resources/root... · 2020. 9. 7. · OFinal Exam 40-50% Theory of Languages and Automata Prof. Movaghar 3. Teaching

Grading Policy

O Assignments 20%O First Quiz 15-20%O Second Quiz 15-20%O Final Exam 40-50%

Prof. MovagharTheory of Languages and Automata 3

Page 4: Theory of Languages and Automatace.sharif.edu/courses/97-98/2/ce415-1/resources/root... · 2020. 9. 7. · OFinal Exam 40-50% Theory of Languages and Automata Prof. Movaghar 3. Teaching

Teaching Assistants

O Teaching Assistants:

O Khashayar GatmiryO E-mail: [email protected]

O Farbod EkbataniO E-mail: [email protected]

Page 5: Theory of Languages and Automatace.sharif.edu/courses/97-98/2/ce415-1/resources/root... · 2020. 9. 7. · OFinal Exam 40-50% Theory of Languages and Automata Prof. Movaghar 3. Teaching

Main Topics

O Complexity TheoryO Computability TheoryO Automata TheoryO Mathematical NotionsO AlphabetO StringsO Languages

Prof. MovagharTheory of Languages and Automata 5

Page 6: Theory of Languages and Automatace.sharif.edu/courses/97-98/2/ce415-1/resources/root... · 2020. 9. 7. · OFinal Exam 40-50% Theory of Languages and Automata Prof. Movaghar 3. Teaching

Complexity Theory

O The scheme for classifying problems according to their computational difficulty

O Options:ü Alter the problem to a more easily solvable one by

understanding the root of difficultyü Approximate the perfect solutionü Use a procedure that occasionally is slow but usually

runs quicklyü Consider alternatives, such as randomized computation

O Applied area:ü Cryptography

Prof. MovagharTheory of Languages and Automata 6

Page 7: Theory of Languages and Automatace.sharif.edu/courses/97-98/2/ce415-1/resources/root... · 2020. 9. 7. · OFinal Exam 40-50% Theory of Languages and Automata Prof. Movaghar 3. Teaching

Computability Theory

O Determining whether a problem is solvable by Computers

O Classification of problems as solvable ones and unsolvable ones

Prof. MovagharTheory of Languages and Automata 7

Page 8: Theory of Languages and Automatace.sharif.edu/courses/97-98/2/ce415-1/resources/root... · 2020. 9. 7. · OFinal Exam 40-50% Theory of Languages and Automata Prof. Movaghar 3. Teaching

Automata Theory

O Definitions and properties of mathematical models of computationü Finite automaton

Usage: Text Processing, Compilers, Hardware Designü Context-free grammar

Usage: Programming Languages, Artificial Intelligence

Prof. MovagharTheory of Languages and Automata 8

Page 9: Theory of Languages and Automatace.sharif.edu/courses/97-98/2/ce415-1/resources/root... · 2020. 9. 7. · OFinal Exam 40-50% Theory of Languages and Automata Prof. Movaghar 3. Teaching

Logic

O The science of the formal principles of reasoning

Prof. MovagharTheory of Languages and Automata 9

Page 10: Theory of Languages and Automatace.sharif.edu/courses/97-98/2/ce415-1/resources/root... · 2020. 9. 7. · OFinal Exam 40-50% Theory of Languages and Automata Prof. Movaghar 3. Teaching

History of Logic

O Logic was known as 'dialectic' or 'analytic' in Ancient Greece. The word 'logic' (from the Greek logos, meaning discourse or sentence) does not appear in the modern sense until the commentaries of Alexander of Aphrodisias, writing in the third century A.D.

O While many cultures have employed intricate systems of reasoning, and logical methods are evident in all human thought, an explicit analysis of the principles of reasoning was developed only in three traditions: those of China, India, and Greece.

Prof. MovagharTheory of Languages and Automata 10

Page 11: Theory of Languages and Automatace.sharif.edu/courses/97-98/2/ce415-1/resources/root... · 2020. 9. 7. · OFinal Exam 40-50% Theory of Languages and Automata Prof. Movaghar 3. Teaching

History of Logic (cont.)O Although exact dates are uncertain, particularly in the case of

India, it is possible that logic emerged in all three societies by the 4th century BC.

O The formally sophisticated treatment of modern logic descends from the Greek tradition, particularly Aristotelian logic, which was further developed by Islamic Logicians and then medieval European logicians.

O The work of Frege in the 19th century marked a radical departure from the Aristotlian leading to the rapid development of symbolic logic, later called mathematical logic.

Prof. MovagharTheory of Languages and Automata 11

Page 12: Theory of Languages and Automatace.sharif.edu/courses/97-98/2/ce415-1/resources/root... · 2020. 9. 7. · OFinal Exam 40-50% Theory of Languages and Automata Prof. Movaghar 3. Teaching

Modern Logic

O Descartes proposed using algebra, especially techniques for solving for unknown quantities in equations, as a vehicle for scientific exploration.

O The idea of a calculus of reasoning was also developed by Leibniz. He was the first to formulate the notion of a broadly applicable system of mathematical logic.

O Frege in his 1879 work extended formal logic beyond propositional logic to include quantificationto represent the "all", "some" propositions of Aristotelian logic.

Prof. MovagharTheory of Languages and Automata 12

Page 13: Theory of Languages and Automatace.sharif.edu/courses/97-98/2/ce415-1/resources/root... · 2020. 9. 7. · OFinal Exam 40-50% Theory of Languages and Automata Prof. Movaghar 3. Teaching

Modern Logic (cont.)

O A logic is a language of formulas.O A formula is a finite sequence of symbols with a

syntax and semantics.O A logic can have a formal system.O A formal system consists of a set of axioms and

rules of inference.

Prof. MovagharTheory of Languages and Automata 13

Page 14: Theory of Languages and Automatace.sharif.edu/courses/97-98/2/ce415-1/resources/root... · 2020. 9. 7. · OFinal Exam 40-50% Theory of Languages and Automata Prof. Movaghar 3. Teaching

Logic Types of Interest

O Propositional LogicO Predicate Logic

Prof. MovagharTheory of Languages and Automata 14

Page 15: Theory of Languages and Automatace.sharif.edu/courses/97-98/2/ce415-1/resources/root... · 2020. 9. 7. · OFinal Exam 40-50% Theory of Languages and Automata Prof. Movaghar 3. Teaching

Syntax of Propositional Logic

O Let {p0, p1, ..} be a countable set of propositional variables,

O {Ù, Ú, ¬, →, ↔} be a finite set of connectives,

O Also, there are left and right brackets,O A propositional variable is a formula,O If φ and ψ are formulas, then so are (¬φ), (φ Ù ψ),

(φ Ú ψ), (φ → ψ), and (φ ↔ ψ).

Prof. MovagharTheory of Languages and Automata 15

Page 16: Theory of Languages and Automatace.sharif.edu/courses/97-98/2/ce415-1/resources/root... · 2020. 9. 7. · OFinal Exam 40-50% Theory of Languages and Automata Prof. Movaghar 3. Teaching

Semantics of Propositional Logic

O Any formula, which involves the propositional variables p0,...,pn , can be used to define a functionof n variables, that is, a function from the set {T, F}n

to {T, F}. This function is often represented as the truth table of the formula and is defined to be the semantics of that formula.

Prof. MovagharTheory of Languages and Automata 16

Page 17: Theory of Languages and Automatace.sharif.edu/courses/97-98/2/ce415-1/resources/root... · 2020. 9. 7. · OFinal Exam 40-50% Theory of Languages and Automata Prof. Movaghar 3. Teaching

Examples

ψ φ (¬φ) (φ Ù ψ) (φ Ú ψ) (φ → ψ) (φ ↔ψ)

T T F T T T T

F T F F T F F

T F T F T T F

F F T F F T T

Prof. MovagharTheory of Languages and Automata 17

Page 18: Theory of Languages and Automatace.sharif.edu/courses/97-98/2/ce415-1/resources/root... · 2020. 9. 7. · OFinal Exam 40-50% Theory of Languages and Automata Prof. Movaghar 3. Teaching

Other Definitions

O A formulae is a tautology if it is always true.§ (P Ú (¬P)) is a tautology.

O A formulae is a contradiction if it is never true.§ (P Ù (¬P)) is a contradiction.

O A formulae is a contingency if it is sometimes true.§ (P → (¬P)) is a contingency.

Prof. MovagharTheory of Languages and Automata 18

Page 19: Theory of Languages and Automatace.sharif.edu/courses/97-98/2/ce415-1/resources/root... · 2020. 9. 7. · OFinal Exam 40-50% Theory of Languages and Automata Prof. Movaghar 3. Teaching

Formal System

A formal system includes the following:O An alphabet A, a set of symbols.O A set of formulae, each of which is a string of

symbols from A.O A set of axioms, each axiom being a formula. O A set of rules of inference, each of which takes as �input� a finite sequence of formulae and produces as output a formula.

Prof. MovagharTheory of Languages and Automata 19

Page 20: Theory of Languages and Automatace.sharif.edu/courses/97-98/2/ce415-1/resources/root... · 2020. 9. 7. · OFinal Exam 40-50% Theory of Languages and Automata Prof. Movaghar 3. Teaching

Proof

O A proof in a formal system is just a finite sequence of formulae such that each formula in the sequence either is an axiom or is obtained from earlier formulae by applying a rule of inference.

Prof. MovagharTheory of Languages and Automata 20

Page 21: Theory of Languages and Automatace.sharif.edu/courses/97-98/2/ce415-1/resources/root... · 2020. 9. 7. · OFinal Exam 40-50% Theory of Languages and Automata Prof. Movaghar 3. Teaching

Theorem

O A theorem of the formal system is just the last formula in a proof.

O Example:For any formula φ, the formula (φ→φ) is a theorem of the propositional logic.

Prof. MovagharTheory of Languages and Automata 21

Page 22: Theory of Languages and Automatace.sharif.edu/courses/97-98/2/ce415-1/resources/root... · 2020. 9. 7. · OFinal Exam 40-50% Theory of Languages and Automata Prof. Movaghar 3. Teaching

A Formal System for Propositional Logic

O There are three �schemes� of axioms, namely:§ (A1) (φ→(ψ → φ))§ (A2) (φ→(ψ → θ))→ ((φ→ ψ)→ (φ → θ))§ (A3) (((¬φ)→(¬ψ))→ (ψ → φ))

O Each of these formulas is an axiom, for all choices of formulae φ, ψ, θ.

O There is only one rule of inference, namely Modus Ponens: From φ and (φ→ ψ), infer ψ.

Prof. MovagharTheory of Languages and Automata 22

Page 23: Theory of Languages and Automatace.sharif.edu/courses/97-98/2/ce415-1/resources/root... · 2020. 9. 7. · OFinal Exam 40-50% Theory of Languages and Automata Prof. Movaghar 3. Teaching

Example of a ProofO Using (A2), taking φ, ψ, θ to be φ, (φ→φ) and φ

respectively ((φ→((φ→φ)→φ))→((φ→(φ→φ))→(φ →φ)))

O Using (A1), taking φ, ψ to be φ and (φ→φ) respectively(φ→((φ→φ)→φ))

O Using Modus Ponens((φ→(φ→φ))→(φ →φ))

O Using (A1), taking φ, ψ to be φ and φ respectively(φ→(φ→φ))

O Using Modus Ponens(φ→φ)

Prof. MovagharTheory of Languages and Automata 23

Page 24: Theory of Languages and Automatace.sharif.edu/courses/97-98/2/ce415-1/resources/root... · 2020. 9. 7. · OFinal Exam 40-50% Theory of Languages and Automata Prof. Movaghar 3. Teaching

Soundness & Completeness

O A formal system is said to be sound if all theorems in that system are tautology.

O A formal system is said to be complete if all tautologies in that system are theorems.

Prof. MovagharTheory of Languages and Automata 24

Page 25: Theory of Languages and Automatace.sharif.edu/courses/97-98/2/ce415-1/resources/root... · 2020. 9. 7. · OFinal Exam 40-50% Theory of Languages and Automata Prof. Movaghar 3. Teaching

Predicate

O A proposition involving some variables, functions and relations

O ExampleP(x) = “x > 3”Q(x,y,z) = “x2 + y2 = z2”

Prof. MovagharTheory of Languages and Automata 25

Page 26: Theory of Languages and Automatace.sharif.edu/courses/97-98/2/ce415-1/resources/root... · 2020. 9. 7. · OFinal Exam 40-50% Theory of Languages and Automata Prof. Movaghar 3. Teaching

Quantifier

O Universal: “for all” �

�x P(x) � P(x1) � P(x2) � P(x3) �…

O Existential: “there exists” ��x P(x) � P(x1) � P(x2) � P(x3) �…

O Combinations:�x �y y > x

Prof. MovagharTheory of Languages and Automata 26

Page 27: Theory of Languages and Automatace.sharif.edu/courses/97-98/2/ce415-1/resources/root... · 2020. 9. 7. · OFinal Exam 40-50% Theory of Languages and Automata Prof. Movaghar 3. Teaching

Quantifiers: Negation

O ¬ (�x P(x)) ��x ¬ P(x)O ¬ (�x P(x)) ��x ¬ P(x)O ¬ �x �y P(x,y) ��x �y ¬ P(x,y)O ¬ �x �y P(x,y) ��x �y ¬ P(x,y)

Prof. MovagharTheory of Languages and Automata 27

Page 28: Theory of Languages and Automatace.sharif.edu/courses/97-98/2/ce415-1/resources/root... · 2020. 9. 7. · OFinal Exam 40-50% Theory of Languages and Automata Prof. Movaghar 3. Teaching

Rules of Inference

1. Direct Proof2. Indirect Proof3. Proof by Contradiction4. Proof by Cases 5. Induction

Prof. MovagharTheory of Languages and Automata 28

Page 29: Theory of Languages and Automatace.sharif.edu/courses/97-98/2/ce415-1/resources/root... · 2020. 9. 7. · OFinal Exam 40-50% Theory of Languages and Automata Prof. Movaghar 3. Teaching

Direct Proof

O If the two propositions (premises) p and p → q are theorems, we may deduce that the proposition q is also a theorem.

O This fundamental rule of inference is called modus ponens by logicians.

p → q p q

Prof. MovagharTheory of Languages and Automata 29

Page 30: Theory of Languages and Automatace.sharif.edu/courses/97-98/2/ce415-1/resources/root... · 2020. 9. 7. · OFinal Exam 40-50% Theory of Languages and Automata Prof. Movaghar 3. Teaching

Indirect Proof

O Proves p→ q by instead proving the contra-positive, ~q→ ~p

p → q~q ~p

Prof. MovagharTheory of Languages and Automata 30

Page 31: Theory of Languages and Automatace.sharif.edu/courses/97-98/2/ce415-1/resources/root... · 2020. 9. 7. · OFinal Exam 40-50% Theory of Languages and Automata Prof. Movaghar 3. Teaching

Proof by Contradiction

O The rule of inference used is that from theorems p and ¬q → ¬p, we may deduce theorem q.

p~q → ~p q

Prof. MovagharTheory of Languages and Automata 31

Page 32: Theory of Languages and Automatace.sharif.edu/courses/97-98/2/ce415-1/resources/root... · 2020. 9. 7. · OFinal Exam 40-50% Theory of Languages and Automata Prof. Movaghar 3. Teaching

Proof by Cases

O You want to prove p→ qO P can be decomposed to some cases:

p ↔ p1 ν p2 ν…ν pn

O Independently prove the n implications given by

pi → q for 1 ≤ i ≤ n.

Prof. MovagharTheory of Languages and Automata 32

Page 33: Theory of Languages and Automatace.sharif.edu/courses/97-98/2/ce415-1/resources/root... · 2020. 9. 7. · OFinal Exam 40-50% Theory of Languages and Automata Prof. Movaghar 3. Teaching

Proof by Induction

O To prove

1. Proof P(0),2. Proof

( )xP x"

[ ( ) ( 1)]x P x P x" ® +

Prof. MovagharTheory of Languages and Automata 33

Page 34: Theory of Languages and Automatace.sharif.edu/courses/97-98/2/ce415-1/resources/root... · 2020. 9. 7. · OFinal Exam 40-50% Theory of Languages and Automata Prof. Movaghar 3. Teaching

Constructive Existence Proof

O Want to prove that

O Find an a and then prove that P(a) is true

)(xPx$

Prof. MovagharTheory of Languages and Automata 34

Page 35: Theory of Languages and Automatace.sharif.edu/courses/97-98/2/ce415-1/resources/root... · 2020. 9. 7. · OFinal Exam 40-50% Theory of Languages and Automata Prof. Movaghar 3. Teaching

Non-Constructive Existence Proof

O Want to prove that

O You cannot find an a that P(a) is trueO Then, you can use proof by contradiction:

)(xPx$

FxPxxPx ®"«$ )(~)(~

Prof. MovagharTheory of Languages and Automata 35

Page 36: Theory of Languages and Automatace.sharif.edu/courses/97-98/2/ce415-1/resources/root... · 2020. 9. 7. · OFinal Exam 40-50% Theory of Languages and Automata Prof. Movaghar 3. Teaching

Intuitive (Naïve) Set Theory

There are three basic concepts in set theory:

O MembershipO ExtensionO Abstraction

Prof. MovagharTheory of Languages and Automata 36

Page 37: Theory of Languages and Automatace.sharif.edu/courses/97-98/2/ce415-1/resources/root... · 2020. 9. 7. · OFinal Exam 40-50% Theory of Languages and Automata Prof. Movaghar 3. Teaching

Membership

O Membership is a relation that holds between a set and an object

O x�A to mean �the object x is a member of the set A�, or �x belongs to A�. The negation of this assertion is written x�A as an abbreviation for the proposition ¬(x�A)

O One way to specify a set is to list its elements. For example, the set A = {a, b, c} consists of three elements. For this set A, it is true that a�A but d�A

Prof. MovagharTheory of Languages and Automata 37

Page 38: Theory of Languages and Automatace.sharif.edu/courses/97-98/2/ce415-1/resources/root... · 2020. 9. 7. · OFinal Exam 40-50% Theory of Languages and Automata Prof. Movaghar 3. Teaching

Extension

O The concept of extension is that two sets are identical if and if only if they contain the same elements. Thus we write A=B to mean

�x [x�A ⟺x�B]

Prof. MovagharTheory of Languages and Automata 38

Page 39: Theory of Languages and Automatace.sharif.edu/courses/97-98/2/ce415-1/resources/root... · 2020. 9. 7. · OFinal Exam 40-50% Theory of Languages and Automata Prof. Movaghar 3. Teaching

Abstraction

Each property defines a set, and each set defines a property

O If p(x) is a property then we can define a set AA = {x � p(x)}

O If A is a set then we can define a predicate p(x) p(x) = x�A

Prof. MovagharTheory of Languages and Automata 39

Page 40: Theory of Languages and Automatace.sharif.edu/courses/97-98/2/ce415-1/resources/root... · 2020. 9. 7. · OFinal Exam 40-50% Theory of Languages and Automata Prof. Movaghar 3. Teaching

Intuitive versus axiomatic set theory

O The theory of set built on the intuitive concept of membership, extension, and abstraction is known as intuitive (naïve) set theory.

O As an axiomatic theory of sets, it is not entirely satisfactory, because the principle of abstraction leads to contradictions when applied to certain simple predicates.

Prof. MovagharTheory of Languages and Automata 40

Page 41: Theory of Languages and Automatace.sharif.edu/courses/97-98/2/ce415-1/resources/root... · 2020. 9. 7. · OFinal Exam 40-50% Theory of Languages and Automata Prof. Movaghar 3. Teaching

Russell’s Paradox

Let p(X) be a predicate defined asP(X) = (XÏX)

Define set R asR={X|P(X)}

O Is P(R) true?O Is P(R) false?

Prof. MovagharTheory of Languages and Automata 41

Page 42: Theory of Languages and Automatace.sharif.edu/courses/97-98/2/ce415-1/resources/root... · 2020. 9. 7. · OFinal Exam 40-50% Theory of Languages and Automata Prof. Movaghar 3. Teaching

Gottlob Frege�s Comments

O The logician Gottlob Frege was the first to develop mathematics on the foundation of set theory. He learned of Russell Paradox while his work was in press, and wrote, �A scientist can hardly meet with anything more undesirable than to have the foundation give way just as the work is finished. In this position I was put by a letter from Mr. Bertrand Russell as the work was nearly through the press.�

Prof. MovagharTheory of Languages and Automata 42

Page 43: Theory of Languages and Automatace.sharif.edu/courses/97-98/2/ce415-1/resources/root... · 2020. 9. 7. · OFinal Exam 40-50% Theory of Languages and Automata Prof. Movaghar 3. Teaching

Power Set

O The set of all subsets of a given set A is known as the power set of A, and is denoted by P(A):

P(A) = {B | B Í A}

Prof. MovagharTheory of Languages and Automata 43

Page 44: Theory of Languages and Automatace.sharif.edu/courses/97-98/2/ce415-1/resources/root... · 2020. 9. 7. · OFinal Exam 40-50% Theory of Languages and Automata Prof. Movaghar 3. Teaching

Set Operation-Union

O The union of two sets A and B isA È B = {x | (x Î A) Ú (x Î B)}

and consists of those elements in at least one of Aand B.

O If A1, …, An constitute a family of sets, their union is

= (A1 È … ÈAn)= {x| x Î Ai for some i, 1≤ i ≤ n}

Aii=1

n

Prof. MovagharTheory of Languages and Automata 44

Page 45: Theory of Languages and Automatace.sharif.edu/courses/97-98/2/ce415-1/resources/root... · 2020. 9. 7. · OFinal Exam 40-50% Theory of Languages and Automata Prof. Movaghar 3. Teaching

Set Operation-Intersection

O The intersection of two sets A and B isA Ç B = {x | (x Î A) � (x Î B)}

and consists of those elements in at least one of Aand B.

O If A1, …, An constitute a family of sets, their intersection is

= (A1 Ç … Ç An) = {x| x Î Ai for all i, 1≤ i ≤ n}

Aii=1

n

Prof. MovagharTheory of Languages and Automata 45

Page 46: Theory of Languages and Automatace.sharif.edu/courses/97-98/2/ce415-1/resources/root... · 2020. 9. 7. · OFinal Exam 40-50% Theory of Languages and Automata Prof. Movaghar 3. Teaching

Set Operation-Complement

O The complement of a set A is a set Ac defined as:Ac = {x | x � A}

O The complement of a set B with respect to A, also denoted as A-B, is defined as:

A-B = {x � A | x � B}

Prof. MovagharTheory of Languages and Automata 46

Page 47: Theory of Languages and Automatace.sharif.edu/courses/97-98/2/ce415-1/resources/root... · 2020. 9. 7. · OFinal Exam 40-50% Theory of Languages and Automata Prof. Movaghar 3. Teaching

Ordered Pairs and n-tuples

O An ordered pair of elements is written (x,y)

where x is known as the first element, and y is known as the second element.

O An n-tuple is an ordered sequence of elements(x1, x2, …, xn)

And is a generalization of an ordered pair.

Prof. MovagharTheory of Languages and Automata 47

Page 48: Theory of Languages and Automatace.sharif.edu/courses/97-98/2/ce415-1/resources/root... · 2020. 9. 7. · OFinal Exam 40-50% Theory of Languages and Automata Prof. Movaghar 3. Teaching

Ordered Sets and Set Products

O By Cartesian product of two sets A and B, we mean the set

A×B = {(x,y) | xÎA , yÎB}

O Similarly,A1×A2×…An = {x1ÎA1, x2ÎA2, …, xnÎAn}

Prof. MovagharTheory of Languages and Automata 48

Page 49: Theory of Languages and Automatace.sharif.edu/courses/97-98/2/ce415-1/resources/root... · 2020. 9. 7. · OFinal Exam 40-50% Theory of Languages and Automata Prof. Movaghar 3. Teaching

Relations

A relation ρ between sets A and B is a subset of A×B:ρ Í A×B

O The domain of ρ is defined asDρ = {x Î A | for some y Î B, (x,y) Î ρ}

O The range of ρ is defined asRρ = {y Î B | for some x Î A, (x,y) Î ρ}

O If ρ Í A×A, then ρ is called a �relation on A�.

Prof. MovagharTheory of Languages and Automata 49

Page 50: Theory of Languages and Automatace.sharif.edu/courses/97-98/2/ce415-1/resources/root... · 2020. 9. 7. · OFinal Exam 40-50% Theory of Languages and Automata Prof. Movaghar 3. Teaching

Types of Relations on Sets

O A relation ρ is reflexive if(x,x) Îρ, for each x ÎA

O A relation ρ is symmetric if, for all x,y ÎA(x,y) Î ρ implies (y,x)Î ρ

O A relation ρ is antisymmetric if, for all x,yÎA(x,y) Î ρ and (y,x) Î ρ implies x=y

O A relation ρ is transitive if, for all x,y,z ÎA(x,y) Î ρ and (y,z) Î ρ implies (x,z) Î ρ

Prof. MovagharTheory of Languages and Automata 50

Page 51: Theory of Languages and Automatace.sharif.edu/courses/97-98/2/ce415-1/resources/root... · 2020. 9. 7. · OFinal Exam 40-50% Theory of Languages and Automata Prof. Movaghar 3. Teaching

Partial Order and Equivalence Relations

O A relation ρ on a set A is called a partial ordering of A if ρ is reflexive, anti-symmetric, and transitive.

O A relation ρ on a set A is called an equivalencerelation if ρ is reflexive, symmetric, and transitive.

Prof. MovagharTheory of Languages and Automata 51

Page 52: Theory of Languages and Automatace.sharif.edu/courses/97-98/2/ce415-1/resources/root... · 2020. 9. 7. · OFinal Exam 40-50% Theory of Languages and Automata Prof. Movaghar 3. Teaching

Total Ordering

O A relation ρ on a set A is a total ordering if ρis a partial ordering and, for each pair of elements (x,y) in A×A at least one of (x,y)Îρor (y,x)Îρ is true.

Prof. MovagharTheory of Languages and Automata 52

Page 53: Theory of Languages and Automatace.sharif.edu/courses/97-98/2/ce415-1/resources/root... · 2020. 9. 7. · OFinal Exam 40-50% Theory of Languages and Automata Prof. Movaghar 3. Teaching

Inverse Relation

O For any relation ρ Í A×B, the inverse of ρ is defined by

ρ-1 = {(y,x) | (x,y) Î ρ}

O If Dρ and Rρ are the domain and range of ρ, thenDρ-1 = Rρ and Rρ-1 = Dρ

Prof. MovagharTheory of Languages and Automata 53

Page 54: Theory of Languages and Automatace.sharif.edu/courses/97-98/2/ce415-1/resources/root... · 2020. 9. 7. · OFinal Exam 40-50% Theory of Languages and Automata Prof. Movaghar 3. Teaching

Equivalence

O Let ρ Í A×A be an equivalence relation on A. The equivalence class of an element x is defined as

[x] = {y Î A | (x,y) Î ρ}

O An equivalence relation on a set partitions the set.

Prof. MovagharTheory of Languages and Automata 54

Page 55: Theory of Languages and Automatace.sharif.edu/courses/97-98/2/ce415-1/resources/root... · 2020. 9. 7. · OFinal Exam 40-50% Theory of Languages and Automata Prof. Movaghar 3. Teaching

Functions

A relation f Í A× B is a function if it has the property:for all x,y,z, (x,y) Î f and (x,z) Î f implies y = z

O If f Í A× B is a function, we write f: A→ B

and say that f maps A into B. We use the common notation

Y = f(x)to mean (x,y) Î f.

Prof. MovagharTheory of Languages and Automata 55

Page 56: Theory of Languages and Automatace.sharif.edu/courses/97-98/2/ce415-1/resources/root... · 2020. 9. 7. · OFinal Exam 40-50% Theory of Languages and Automata Prof. Movaghar 3. Teaching

Functions (cont.)

O As before, the domain of f is the set Df = {xÎ A | for some yÎ B, (x,y) Î f}

and the range of f is the setRf = {yÎ B | for some x Î A, (x,y) Î f}

O If Df Í A, we say the function is a partial function; if Df = A, we say that f is a total function.

Prof. MovagharTheory of Languages and Automata 56

Page 57: Theory of Languages and Automatace.sharif.edu/courses/97-98/2/ce415-1/resources/root... · 2020. 9. 7. · OFinal Exam 40-50% Theory of Languages and Automata Prof. Movaghar 3. Teaching

Functions (cont.)

O If x Î Df, we say that f is defined at x; otherwise f isundefined at x.

O If Rf = B, we say that f maps Df onto B.O If a function f has the property

for all x,y,z, f(x) = z and f(y) = z implies x = ythen f is a one-to-one function. If f: A→ B is a one-to-one function, f gives a one-to

one correspondence between elements of its domain and range.

Prof. MovagharTheory of Languages and Automata 57

Page 58: Theory of Languages and Automatace.sharif.edu/courses/97-98/2/ce415-1/resources/root... · 2020. 9. 7. · OFinal Exam 40-50% Theory of Languages and Automata Prof. Movaghar 3. Teaching

Functions (cont.)

O Let X be a set and suppose A Í X. Define functionCA: X→ {0,1}

such that CA(x) = 1, if xÎ A; CA(x) = 0, otherwise. CA(x) is called the characteristic function of set A with respect to set X.

O If f Í A× B is a function, then the inverse of f is the set

f--1 = {(y,x) | (x,y) Î f} f--1 is a function if and only if f is one-to-one.

Prof. MovagharTheory of Languages and Automata 58

Page 59: Theory of Languages and Automatace.sharif.edu/courses/97-98/2/ce415-1/resources/root... · 2020. 9. 7. · OFinal Exam 40-50% Theory of Languages and Automata Prof. Movaghar 3. Teaching

Functions (cont.)

O Let f: A→ B be a function, and suppose that X Í A. Then the set

Y = f(X) = {y Î B | y = f(x) for some x Î X}is known as the image of X under f.

O Similarly, the inverse image of a set Y included in the range of f is

f -1(Y) = {x Î A | y = f(x) for some y Î Y}

Prof. MovagharTheory of Languages and Automata 59

Page 60: Theory of Languages and Automatace.sharif.edu/courses/97-98/2/ce415-1/resources/root... · 2020. 9. 7. · OFinal Exam 40-50% Theory of Languages and Automata Prof. Movaghar 3. Teaching

CardinalityO Two sets A and B are of equal cardinality, written as

|A| = |B|if and only if there is a one-to-one function f: A→ Bthat maps A onto B.

O We write |A| ≤ |B|

if B includes a subset C such that |A| = |C|.O If |A| ≤ |B| and |A| ≠ |B|, then A has cardinality less

than that of B, and we write|A| < |B|

Prof. MovagharTheory of Languages and Automata 60

Page 61: Theory of Languages and Automatace.sharif.edu/courses/97-98/2/ce415-1/resources/root... · 2020. 9. 7. · OFinal Exam 40-50% Theory of Languages and Automata Prof. Movaghar 3. Teaching

Cardinality (cont.)O Let J = {1, 2, …} and Jn = {1, 2, …, n}.O A sequence on a set X is a function f: J→ X. A sequence

may be written as f(1), f(2), f(3), …

However, we often use the simpler notationx1, x2, x3, …., xi Î X

O A finite sequence of length n on X is a function f: Jn → X, usually written as

x1, x2, x3, …., xn, xi Î XO The sequence of length zero is the function f: → X.

Prof. MovagharTheory of Languages and Automata 61

Page 62: Theory of Languages and Automatace.sharif.edu/courses/97-98/2/ce415-1/resources/root... · 2020. 9. 7. · OFinal Exam 40-50% Theory of Languages and Automata Prof. Movaghar 3. Teaching

Finite and Infinite Sets

O A set A is finite if |A| = |Jn| for some integer n ≥ 0, in which case we say that A has cardinality n.

O A set is infinite if it is not finite.O A set X is denumerable if |X| = |J|. O A set is countable if it is either finite or

denumerable.O A set is uncountable if it is not countable.

Prof. MovagharTheory of Languages and Automata 62

Page 63: Theory of Languages and Automatace.sharif.edu/courses/97-98/2/ce415-1/resources/root... · 2020. 9. 7. · OFinal Exam 40-50% Theory of Languages and Automata Prof. Movaghar 3. Teaching

Some Properties

O Proposition: Every subset of J is countable. Consequently, each subset of any denumerable set is countable.

O Proposition: A function f: J→ Y has a countable range. Hence any function on a countable domain has a countable range.

O Proposition: The set J × J is denumerable. Therefore, A × B is countable for arbitrary countable sets A and B.

Prof. MovagharTheory of Languages and Automata 63

Page 64: Theory of Languages and Automatace.sharif.edu/courses/97-98/2/ce415-1/resources/root... · 2020. 9. 7. · OFinal Exam 40-50% Theory of Languages and Automata Prof. Movaghar 3. Teaching

Some Properties (cont.)

O Proposition: The set A È B is countable whenever Aand B are countable sets.

O Proposition: Every infinite set X is at least denumerable ; that is |X| ≥ |J|.

O Proposition: The set of all infinite sequence on {0, 1} is uncountable.

Prof. MovagharTheory of Languages and Automata 64

Page 65: Theory of Languages and Automatace.sharif.edu/courses/97-98/2/ce415-1/resources/root... · 2020. 9. 7. · OFinal Exam 40-50% Theory of Languages and Automata Prof. Movaghar 3. Teaching

Some Properties (cont.)

O Proposition: (Schröder-Bernestein Theorem) For any set A and B, if |A| ≥ |B| and |B| ≥ |A|, then|A| = |B|.

O Proposition: (Cantor’s Theorem)For any set X,

|X| < |P(X)|.

Prof. MovagharTheory of Languages and Automata 65

Page 66: Theory of Languages and Automatace.sharif.edu/courses/97-98/2/ce415-1/resources/root... · 2020. 9. 7. · OFinal Exam 40-50% Theory of Languages and Automata Prof. Movaghar 3. Teaching

1-1 correspondence Q↔NO Proof (dove-tailing):

Prof. MovagharTheory of Languages and Automata 66

Page 67: Theory of Languages and Automatace.sharif.edu/courses/97-98/2/ce415-1/resources/root... · 2020. 9. 7. · OFinal Exam 40-50% Theory of Languages and Automata Prof. Movaghar 3. Teaching

Countable Sets

O Any subset of a countable setO The set of integers, algebraic/rational numbersO The union of two/finite number of countable setsO Cartesian product of a finite number of countable sets O The set of all finite subsets of NO Set of binary strings

Prof. MovagharTheory of Languages and Automata 67

Page 68: Theory of Languages and Automatace.sharif.edu/courses/97-98/2/ce415-1/resources/root... · 2020. 9. 7. · OFinal Exam 40-50% Theory of Languages and Automata Prof. Movaghar 3. Teaching

Diagonal Argument

Prof. MovagharTheory of Languages and Automata 68

Page 69: Theory of Languages and Automatace.sharif.edu/courses/97-98/2/ce415-1/resources/root... · 2020. 9. 7. · OFinal Exam 40-50% Theory of Languages and Automata Prof. Movaghar 3. Teaching

Uncountable Sets

O R, R2, P(N)O The intervals [0,1), [0, 1], (0, 1)O The set of all real numbersO The set of all functions from N to {0, 1}O The set of functions N→ NO Any set having an uncountable subset

Prof. MovagharTheory of Languages and Automata 69

Page 70: Theory of Languages and Automatace.sharif.edu/courses/97-98/2/ce415-1/resources/root... · 2020. 9. 7. · OFinal Exam 40-50% Theory of Languages and Automata Prof. Movaghar 3. Teaching

Transfinite Cardinal Numbers

O Cardinality of a finite set is simply the number of elements in the set.

O Cardinalities of infinite sets are not natural numbers, but are special objects called transfinite cardinal numbers.

O À0:º|N|, is the first transfinite cardinal number.O continuum hypothesis claims that |R|=À1, the second

transfinite cardinal.

Prof. MovagharTheory of Languages and Automata 70

Page 71: Theory of Languages and Automatace.sharif.edu/courses/97-98/2/ce415-1/resources/root... · 2020. 9. 7. · OFinal Exam 40-50% Theory of Languages and Automata Prof. Movaghar 3. Teaching

Alphabet

O A finite and nonempty set of symbols (usually shown by ∑ or Г).

O Example: ∑ = {$, &, ', … , )}��

Prof. MovagharTheory of Languages and Automata 71

Page 72: Theory of Languages and Automatace.sharif.edu/courses/97-98/2/ce415-1/resources/root... · 2020. 9. 7. · OFinal Exam 40-50% Theory of Languages and Automata Prof. Movaghar 3. Teaching

Strings

O A finite list of symbols from an alphabetO Example: houseO If ω is a string over ∑, the length of ω, written |ω|, is

the number of symbols that it contains. O The empty string (ε or λ) is the string of length zero.

εω = ωε = ωO String z is a substring of ω if z appears consecutively

within ω.

Prof. MovagharTheory of Languages and Automata 72

Page 73: Theory of Languages and Automatace.sharif.edu/courses/97-98/2/ce415-1/resources/root... · 2020. 9. 7. · OFinal Exam 40-50% Theory of Languages and Automata Prof. Movaghar 3. Teaching

Operations on StringsO Reverse of a string:

w = a1a2…an ababaaabbbwR = an…a2a1 bbbaaababa

O Concatenation:w = a1a2…an abbav = b1b2…bm bbbaaawv = a1a2…an b1b2…bm abbabbbaaa |wv| = |w| + |v|

Prof. MovagharTheory of Languages and Automata 73

Page 74: Theory of Languages and Automatace.sharif.edu/courses/97-98/2/ce415-1/resources/root... · 2020. 9. 7. · OFinal Exam 40-50% Theory of Languages and Automata Prof. Movaghar 3. Teaching

Operations on AlphabetO * :

§ The set of all strings that can be produced from ∑.

O + :§ The set of all strings, excluding λ, that can be produced from ∑.§ Suppose that λ={λ}. Then:

Prof. MovagharTheory of Languages and Automata 74

Page 75: Theory of Languages and Automatace.sharif.edu/courses/97-98/2/ce415-1/resources/root... · 2020. 9. 7. · OFinal Exam 40-50% Theory of Languages and Automata Prof. Movaghar 3. Teaching

LanguagesO A set of stringsO Any language on the alphabet ∑ is a subset of ∑*.O Examples:

Prof. MovagharTheory of Languages and Automata 75

Page 76: Theory of Languages and Automatace.sharif.edu/courses/97-98/2/ce415-1/resources/root... · 2020. 9. 7. · OFinal Exam 40-50% Theory of Languages and Automata Prof. Movaghar 3. Teaching

Operations on LanguagesLanguages are a special kind of sets and operations on sets can be defined on them as well.

O Union

O Intersection

O Relative Complement

O Complementλ, b, aa, ab, bb, aaa, …}

Prof. MovagharTheory of Languages and Automata 76

Page 77: Theory of Languages and Automatace.sharif.edu/courses/97-98/2/ce415-1/resources/root... · 2020. 9. 7. · OFinal Exam 40-50% Theory of Languages and Automata Prof. Movaghar 3. Teaching

Operations on Languages (cont.)

O Reverse of a language

O Example:

Prof. MovagharTheory of Languages and Automata 77

Page 78: Theory of Languages and Automatace.sharif.edu/courses/97-98/2/ce415-1/resources/root... · 2020. 9. 7. · OFinal Exam 40-50% Theory of Languages and Automata Prof. Movaghar 3. Teaching

Operations on Languages (cont.)

O Concatenation

O Example:

Prof. MovagharTheory of Languages and Automata 78

Page 79: Theory of Languages and Automatace.sharif.edu/courses/97-98/2/ce415-1/resources/root... · 2020. 9. 7. · OFinal Exam 40-50% Theory of Languages and Automata Prof. Movaghar 3. Teaching

Operations on Languages (cont.)O *: Kleene *

§ The set of all strings that can be produced by concatenation of strings of a language.

§ Example:

O +: § The set of all strings, excluding λ, that can be produced by

concatenation of strings of a language.

Prof. MovagharTheory of Languages and Automata 79

Page 80: Theory of Languages and Automatace.sharif.edu/courses/97-98/2/ce415-1/resources/root... · 2020. 9. 7. · OFinal Exam 40-50% Theory of Languages and Automata Prof. Movaghar 3. Teaching

Gödel Numbering

O Let ∑ be an alphabet containing n objects. Let h: ∑→ Jn be an arbitrary one-to-one correspondence. Define function f as:

f: ∑* → Nsuch that f(ε) =0; f(w.v) = n f(w) + h(v), for wÎ ∑* and vÎ ∑.f is called a Gödel Numbering of ∑*.

O Proposition: ∑* is denumerable.O Proposition: Any language on an alphabet is countable.

Prof. MovagharTheory of Languages and Automata 80