Lecture01 Intro
Lecture01 Intro
Text Book:
“Theory of Computation an Introduction" by James L. Hein, Jones & Bartlett
Publishers 1996; ISBN: 0-86720-497-4.
1
Course details
2
The course content
4
Formal Languages and Automata
What and why?
◼ What is formal language?
A formal language is a set of words, i.e. finite strings of letters, symbols,
or tokens. The set from which these letters are taken is called the
alphabet over which the language is defined. A formal language is often
defined by means of a formal grammar (also called its formation rules);
accordingly, words that belong to a formal language are sometimes
called well-formed words (or well-formed formulas).
5
Formal Languages and Automata
What and why?
◼ What is Automata?
• Automata : the plural of automaton: self operating machine.
the automata can be used to test whether a particular expression is in fact
part of the language.
• Languages in turn, can be described by regular expressions and
grammars. Regular expressions denote the structure of data, especially text
strings. For example, as part of a calculator, you might want to have a rule
like S → S | S + S, which states that an expression can be formed by taking
any two expressions and connecting them by a plus sign.
6
Mathematical background
7
Basic Concepts (language, grammar, automata)
◼ Language: is a set of strings.
- If A is an alphabet, then a language over A is a collection of all
strings over A.
◼ Example
If A={a} then the following are simple examples of languages
over an alphabet A:
{Ф}, {}, {a}, and A* ={, a, aa, aaa, ………}.
8
Example
Let the alphabet be = {a, b } then,
- * = {, a, b, aa, ab, ba, bb, aaa, bbb, …} - + = * - {}
- L1 = { a, aa, bbb} finite
- L2 = {anbn : n>= 0} infinite
- L1 = *- L1
- LR = {wR: w L}
- L0={}
- L1 L2 = {xy: x L1, y L2}
if L = {anbn : n>= 0}
L2 = {anbnambm : n>= 0, m>= 0} → (L.L)
LR = {bnan : n>= 0}
L* = Lo L1 L2 …
L+ = L1 L2 L3 …
9
Basic Concepts
◼ Grammar: is a set of production rules used to define the structure of the
strings in a language.
◼ If L is a language over the alphabet A, then a grammar for L consists of a
set of grammar rules of the form:
∝→ß,
Where ∝ and ß denotes strings of symbols taken from A and from a set of
grammar symbols denoted as the non-terminals set N.
◼ Every grammar has a special grammar symbol called a start symbol S, and
at least one production with the left side consisting of only the start symbol.
◼ For example if the start symbol is S, then the production rule will be:
S→ß,
10
Basic Concepts
◼ Example
Let A={a,b,c}, then the grammar for the A* language can be described by
the following production rules:
S→
S→aS
S→bS
S→cS.
◼ How do we know that this grammar describes the
language A*?
We must be able to describe each string of the language in terms of the
grammar rules.
◼ Prove that the string aacb is in A*???
11
Basic Concepts
The grammar consists of the following four parts:
◼ An alphabet N of grammar symbols called nonterminals.
12
Basic Concepts
◼ Example
If A={a,b,c}, and the production rules is the set P the
grammar G=<N,T,S,P> ≡ <{S,A,B}, {a,b,c}, S, P>,
where P ≡ S→AB A→ |aA B→ |bB.
◼ Let us derive the string aab:
S⇒AB⇒aAB⇒aaAB⇒aaB⇒aabB⇒aab.
◼ Note: that the language can have more than one grammar.
So we should not be surprised when two people come up
with two different grammars for the same language.
13
Basic Concepts
◼ {,a,aa,…,an,…} …?
◼ {b,abc,aabcc,….,anbcn,…}…?
◼ {ac,abc,abbc,…,abnc,….}…?
14
Combining grammars
Suppose M and N are languages whose grammars have disjoint sets of
non-terminals. Suppose also that the start symbols for the grammars M
and N are A and B respectively. We can obtain the following new
languages and grammars:
15
Combining grammars
Examples
Describe the combined grammars in each L of the following
1- If L = {,a,b,aa,bb,……, an,bn,……}????
2- If L = {ambn | m,n ∊ ℕ}????
3- If L={aa,bb}*, write the grammar for L?????
16
Thank You!
17