01 Intro
01 Intro
1
Course Introduction
2
Formal Language and Automata Theory
3
Contacts
• Contacts
• In person - Room 331, Mirae Hall, please check w/ me in advance.
• Use e-class messages.
• Do not use e-mails. All enquires through e-class.
• Work - Life Balance
• Please make your enquires before 9 PM during week days.
• Otherwise, I'll answer them in the next day, or on Monday for the late questions
or weekend questions.
4
Lecture Type and Teaching Methods
fl
Lecture Type and Teaching Methods
Textbook
• But you have to use the technical terms in the original textbook, so I
recommend to read the English version.
• You don't need to buy the book, but I strongly recommend you to read it.
6
Lecture Type and Teaching Methods
Lectures
8
Recommended Study Methods
9
ffi
ffi
fi
Recommended Study Methods
• You can more rmly understand Automata and Formal Language by solving
those problems.
10
fi
Evaluation
Attendance + Quizzes + Exams
• Please remind that the quiz and exams will be also counted as attendances.
11
Quiz, Assignment and Exams
• Quiz
• Several problem solving questions.
• Questions will be about contents you've learned so far.
• Assignment
• A programming assignment in Python to simulate some automata we will
discuss during lectures.
• Questions will be given in English, but you can answer them either in English
or Korean.
12
Quizzes and Exams
• Exams
• Mid-term Exam - Weeks 1 ~ 7
• Final Exam - Weeks 1 ~ 14, but mostly from Weeks 9 ~ 14.
• Questions will be from various sources, even from the previous ones.
• Quiz - 10% / Exercises - 40%
• Unknown Mysterious Boxes - 50%
• Sometimes I'll ask simple things I mentioned during the lectures.
• e.g.) Who is this guy?
• Answers for the quiz and exercises will not be given.
13
Q&A
14
Introduction and Preliminaries
15
Topics
16
Introduction to Formal Language
and Automata Theory
17
Why Do We Need to Study FLAT?
18
ff
Key Topics
Syntax Definition for
Programming Languages
Algorithm &
Problem Difficulties
Regular Languages
Turing Machine
String Pattern & Finite Automata
Matching in
Programming
19
What will be discussed in this course?
and what you should know after taking this course.
21
Formal Language and Grammar
• Formal language
• an abstraction of the general characteristics of programming languages.
• consists of a set of sentences, formed from a set of symbols, according to formal
rules.
• Grammar
• a set of rules for generating sentences in a formal language.
• We can learn some essential features of programming languages from formal languages.
• How to read and process strings (or code) written in a certain languages.
22
Mechanical Computation
• Algorithm
• describes how mechanical computation can be done to solve problems.
• We will discuss the kinds of problems, which can be solved by mechanical
means.
23
Mathematical Preliminaries and
Notations
24
Sets
26
ff
Sets
27
𝜙
fi
Sets
• f : S1 → S2
• If the domain of f is all of S1, then domain range
f is a total function on S1;
otherwise it's a partial function.
30
Functions and Relations
Order-of-magnitude Notation
• Let f(n) and g(n) be functions whose domain is a subset of positive integers.
• If there exists a positive constant c, s.t. for all su ciently large n
• f(n) ≤ c|g(n)|, we say that f has order at most g.
• f(n) = O( g(n) )
• Similarly, if |f(n)| ≥ c|g(n)|, then f has order at least g,
• f(n) = ( g(n) )
• if c1|g(n)| ≤ |f(n)| ≤ c2|g(n)|, then f and g have the same order of magnitude,
• f(n) = ( g(n) )
31
𝛩
𝛺
ffi
Functions and Relations
Order-of-magnitude Notation
f(n) ≤ c|g(n)| => 2n2 + 3n ≤ c|n3|
• Let
n = 100?
• f(n) = 2n2 + 3n,
• g(n) = n3, 2*100*100 + 3*100 ≤ c*1,000,000
33
Functions and Relations
Relation
• Example 1.4
• For non-negative integers, we can de ne a relation x ≡ y, i . x mod 3 = y mod 3.
• Is this an equivalence relation?
• Obviously 2 ≡ 2.
• 2 ≡ 5 ⟷ 5 ≡ 2, since 2 mod 3 = 5 mod 3 = 2.
• if 3 ≡ 6 and 6 ≡ 9, then 3 ≡ 9.
• How about for all integers, x ≡ y, i . x2 = y2?
35
ff
fi
ff
Graphs and Trees
Graph
36
fi
Graphs and Trees
e2 e4
37
Graphs and Trees
Trees
• height(T) = max(level(vi)), vi ∈ T
38
Proof Techniques
Proof by Induction
• Suppose we have a sequence of statements P1, P2, ... - may be in nite - and
we want to prove that they are true.
39
fi
Proof Techniques
Proof by Induction
• The key is that we can prove each statement incrementally from the start.
• P1 (basis) is true and inductive assumption holds,
• then "proving inductive step is correct" automatically proves that
• P2 is true, then P3 is true, ...
• For k ≥ 1, P1, P2, …, Pk. (basis)
n
• Prove that a binary tree of height n has at most 2 leaves.
• l(n): the maximum number of leaves of binary tree w/ height n.
n
• Then we need to show that l(n) ≤ 2 .
0
• Basis: l(0) = 1 = 2 .
k
• Inductive Assumption: l(k) ≤ 2 , for k = 0, 1, ..., n.
n n+1
• Inductive Step: Now we need to check if l(n) ≤ 2 is true, then l(n + 1) ≤ 2
is also true.
41
Proof Techniques
Example 1.5
n
• Inductive Step: If l(n) ≤ 2 is true, then
l(n + 1) ≤ 2n+1 is also true.
• We know that it's a binary tree, so every
node (and leaf) has at most 2 child nodes. height n
• Thus, if inductive assumption is true for How many more nodes can be
n, then it is also true for n+1. attached to the current leaves?
n
• This proves l(n) ≤ 2 for all n.
42
Proof Techniques
Proof by Contradiction
43
fi
fi
ffi
fi
Proof Techniques
Example 1.7
44
Proof Techniques
Example 1.7
2 2
• 2m = n (1).
• Then n must be even, so that we can write n = 2k.
2 2
• Substituting this to n from eq. (1), we get m = 2k .
• Now m is also even, which contradicts to the assumption that n and m have
no common factors.
45
Summary
47
Topics
48
Languages
• Natural Languages
• Korean, English, Arabic, Chinese, Vietnamese, Spanish, Russian, German, and
many more.
50
fi
String
51
String
• Length of a string
• | a | = 1, (single character)
• | wa | = | w | + 1, for all a ∈ Σ and w, any string on Σ.
n
• w : a string obtained by repeating w for n times.
0
• w = λ, for all w.
53
Sentence
54
fi
fi
Language
Example 1.9
• We can use set operations (e.g., union, intersection, etc.) w/ languages too.
• Complement of L
c
• L = Σ* − L.
• Reverse of L
R R
• L = {w : w ∈ L}.
• Concatenation
• L1L2 = {xy : x ∈ L1, y ∈ L2}.
56
Language
n
• L : L concatenated n times.
0
• L = {λ} - a language has an empty string as its only sentence.
1
• L = L.
• Star-closure
0 1 2
• L* = L ∪ L ∪ L ⋯.
• Positive closure
+ 1 2
• L = L ∪ L ⋯ = L* − {λ}.
57
Grammar
De nition 1.1
59
Language generated by Grammar
De nition 1.2
60
fi
Language and Grammar
Example 1.12
• G = (V, T, S, P)
61
fi
Language and Grammar
Example 1.12
n n+1
• L = {a b : n ≥ 0}
• G = ({S, A}, {a, b}, S, P) with productions P is the following.
• S → aSb
• S → Ab
• A→λ
• S ⇒* aabbb?
62
Equivalence
• L(G1) = L(G2).
• e.g.) the grammar we've found in the previous slide is equivalent to the
grammar of Example 1.12 in the textbook.
63
Equivalence
Example 1.14
• Consider the grammar G1 = ({S, A}, {a, b}, S, P1), with P1 consisting of productions
• S → aAb | λ
• A → aAb | λ
• This grammar is equivalent to the grammar G = ({S}, {a, b}, S, P) with P is given by
• S → aSb | λ
• Both of them generate
n n
• L(G) = L(G1) = {a b : n ≥ 0}.
64
Automata
65
fi
fi
Automata
67
fi
Summary
• You have to get familiar with the notations for languages and grammars.
• We will use them a lot in future lectures.
• It takes a huge part of what you have to write during quizzes and exams.
• You need to understand the connections between languages and grammars.
• If you see a grammar, you can see a language generated by it.
• If you see a language, you can infer a grammar to derive it.
68