0% found this document useful (0 votes)
59 views26 pages

3 Types of Structures Used in Modeling Computation

The document discusses three main types of structures used in modeling computation: grammars, finite-state machines, and Turing machines. Grammars are used to generate sentences in formal languages and determine if a sentence is part of a language. Finite-state machines recognize certain types of formal languages through a set of states and transitions. Turing machines are an abstract model of a computer used to model computable functions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
59 views26 pages

3 Types of Structures Used in Modeling Computation

The document discusses three main types of structures used in modeling computation: grammars, finite-state machines, and Turing machines. Grammars are used to generate sentences in formal languages and determine if a sentence is part of a language. Finite-state machines recognize certain types of formal languages through a set of states and transitions. Turing machines are an abstract model of a computer used to model computable functions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 26

3 Types of Structures used in Modeling Computation

Grammars
• Used to generate sentences of a language and to determine if a given sentence is in a language
• Formal languages, generated by grammars, provide models for programming languages (Java, C,
etc) as well as natural language --- important for constructing compilers

Finite-State Machines (FSM)


• FSM are characterized by a set of states, an input alphabet, and transitions that assigns a next state
to a pair of state and an input. They are used in language recognition (equivalent to certain
grammar) but also for other tasks such as controlling vending machines

Turing Machine (TM)


• They are an abstraction of a computer used to compute number theoretic functions
Early Models of Computation

• Recursive Function Theory


Kleene, Church, Turing, Post, 1930’s (before computers!!)
• Turing Machines – Turing, 1940’s (defined: computable)
• RAM Machines – von Neumann, 1940’s (“real computer”)
• Cellular Automata – von Neumann, 1950’s
(Wolfram 2005; physics of our world?)
• Finite-state machines, pushdown automata
various people, 1950’s
• VLSI models – 1970s ( integrated circuits made of thousands of transistors form a
single chip)
• Parallel RAMs, etc. – 1980’s
Intro to Languages
• English grammar tells us if a given combination of words is a valid sentence.
• The syntax of a sentence concerns its form, while the semantics concerns its meaning.
e.g. the mouse wrote a poem

• From a syntax point of view this is a valid sentence.

• From a semantics point of view not …perhaps in Disney land

• Natural languages (English, French, Portguese, etc) have very complex rules of syntax and not
necessarily well-defined.
Formal Language
• Formal language – is specified by well-defined set of rules of syntax

• We describe the sentences of a formal language using a grammar.

• Two key questions:


1 - Is a combination of words a valid sentence in a formal language?
2 – How can we generate the valid sentences of a formal language?
• Formal languages provide models for both natural languages and programming languages.
Σ = {a, b},
Grammars
• A formal grammar G is any compact, precise mathematical definition
of a language L.
• As opposed to just a raw listing of all of the language’s legal sentences, or just
examples of them.
• A grammar implies an algorithm that would generate all legal
sentences of the language.
• Often, it takes the form of a set of recursive definitions.
• A popular way to specify a grammar recursively is to specify it as a
phrase-structure grammar.
Grammars
• Example: A grammar that generates a subset of the English language

sentence  noun _ phrase predicate

noun _ phrase  article noun

predicate  verb
article  a
article  the

noun  boy
noun  dog

verb  runs
verb  sleeps
• A derivation of “the boy sleeps”:

sentence  noun _ phrase predicate


 noun _ phrase verb
 article noun verb
 the noun verb
 the boy verb
 the boy sleeps
• A derivation of “a dog runs”:

sentence  noun _ phrase predicate


 noun _ phrase verb
 article noun verb
 a noun verb
 a dog verb
 a dog runs
Language of the grammar:

L = { “a boy runs”,
“a boy sleeps”,
“the boy runs”,
“the boy sleeps”,
“a dog runs”,
“a dog sleeps”,
“the dog runs”,
“the dog sleeps” }
Notation
noun  boy
noun  dog

Variable Terminal
or Production
Symbols of
Non-terminal rule
the vocabulary

Symbols of
the vocabulary
Basic Terminology
► A vocabulary/alphabet, V is a finite nonempty set of elements
called symbols.
• Example: V = {a, b, c, A, B, C, S}

► A word/sentence over V is a string of finite length of elements


of V.
• Example: Aba

► The empty/null string, λ is the string with no symbols.

► V* is the set of all words over V.


• Example: V* = {Aba, BBa, bAA, cab …}

► A language over V is a subset of V*.


Phrase-Structure Grammars
• A phrase-structure grammar
G = (V,T,S,P) is a 4-tuple, in which:
• V is a vocabulary (set of symbols)
• The “template vocabulary” of the language.
• T  V is a set of symbols called terminals
• Actual symbols of the language.
• Also, N :≡ V − T is a set of special “symbols” called nonterminals.
(Representing concepts like “noun”)
• SN is a special nonterminal, the start symbol.
• in our example the start symbol was “sentence”.
• P is a set of productions (to be defined).
• Rules for substituting one sentence fragment for another
• Every production rule must contain at least one nonterminal on its left
side.
Phrase-structure Grammar
► EXAMPLE:

 Let G = (V, T, S, P),

 where V = {a, b, A, B, S}
 T = {a, b},
 S is a start symbol
 P = {S → ABa, A → BB, B → ab, A → Bb}.

G is a Phrase-Structure Grammar.
What sentences can be generated
with this grammar?
Derivation
• Definition

• Let G=(V,T,S,P) be a phrase-structure grammar.

• Let w0=lz0r (the concatenation of l, z0, and r) w1=lz1r be strings over V.

• If z0  z1 is a production of G we say that w1 is directly derivable from w0 and we


write wo => w1.

• If w0, w1, …., wn are strings over V such that w0 =>w1,w1=>w2,…, wn-1 => wn, then
we say that wn is derivable from w0, and write w0=>*wn.

• The sequence of steps used to obtain wn from wo is called a derivation.


Language
• Let G(V,T,S,P) be a phrase-structure grammar. The
• language generated by G (or the language of G)
• denoted by L(G) , is the set of all strings of terminals
• that are derivable from the starting state S.

• L(G)= {w  T* | S =>*w}
Language L(G)
► EXAMPLE:

• Let G = (V, T, S, P), where V = {a, b, A, S}, T = {a, b}, S is a start


symbol and P = {S → aA, S → b, A → aa}.

• The language of this grammar is given by L (G) = {b, aaa};

1. we can derive aA from using S → aA, and then derive aaa using A →
aa.

2. We can also derive b using S → b.


Another example
• Grammar:
G=(V,T,S,P) T={a,b} P=
S  aSb
S 
V={a,b,S}

• Derivation of sentence : ab
S  aSb  ab

S  aSb S 
S  aSb
• Grammar: S 

aabb
• Derivation of sentence :
S  aSb  aaSbb  aabb

S  aSb S 
• Other derivations:
S  aSb  aaSbb  aaaSbbb  aaabbb
S  aSb  aaSbb  aaaSbbb
 aaaaSbbbb  aaaabbbb
So, what’s the language of the
grammar with the productions? S  aSb
S 
• Language of the grammar with the productions:
S  aSb
S 
n n
L  {a b : n  0}
G={(S,A),(a,b),S,P}
Automata
Types of Grammars - Chomsky hierarchy of languages

• Venn Diagram of Grammar Types:

Type 0 – Phrase-structure Grammars


Type 1 –
Context-Sensitive
Type 2 –
Context-Free
Type 3 –
Regular

You might also like