ICS 241 - PowerPoint PPT Presentation

About This Presentation
Title:

ICS 241

Description:

William Albritton, Information and Computer Sciences Department at ... Let a language L be any set of some arbitrary objects s which will be dubbed 'sentences. ... – PowerPoint PPT presentation

Number of Views:36
Avg rating:3.0/5.0
Slides: 32
Provided by: williama3
Learn more at: http://www2.hawaii.edu
Category:
Tags: ics | dubbed

less

Transcript and Presenter's Notes

Title: ICS 241


1
ICS 241
  • Discrete Mathematics II
  • William Albritton, Information and Computer
    Sciences Department at University of Hawaii at
    Manoa
  • For use with Kenneth H. Rosens Discrete
    Mathematics Its Applications (5th Edition)
  • Based on slides originally created by
  • Dr. Michael P. Frank, Department of Computer
    Information Science Engineering at University
    of Florida

2
Modeling Computation
  • We learned earlier the concept of an algorithm.
  • A description of a computational procedure.
  • Now, how can we model the computer itself, and
    what it is doing when it carries out an
    algorithm?
  • For this, we want to model the abstract process
    of computation itself.

3
Real-World Computer Modeling
Modeling areas needed for real Computer Systems
Engineering
  1. Logic Devices
  2. Technology Scaling
  3. Interconnections
  4. Synchronization
  5. Processor Architecture
  6. Capacity Scaling
  1. Energy Transfer
  2. Programming
  3. Error Handling
  4. Performance
  5. Cost

An efficient and physically realistic model of
computing must accurately address all of these
areas!
4
Section 11.1 Languages Grammars
  • Phrase-Structure Grammars
  • Types of Phrase-Structure Grammars
  • Derivation Trees
  • Backus-Naur Form

5
Computers as Transition Functions
  • A computer (or really any physical system) can be
    modeled as having, at any given time, a specific
    state s?S from some (finite or infinite) state
    space S
  • Also, at any time, the computer receives an input
    symbol i?I and produces an output symbol o?O
  • Where I and O are sets of symbols.
  • Each symbol can encode an arbitrary amount of
    data.
  • A computer can then be modeled as simply being a
    transition function TSI ? SO
  • Given the old state, and the input, this tells us
    what the computers new state and its output will
    be a moment later.
  • Every model of computing well discuss can be
    viewed as just being some special case of this
    general picture.

6
Language Recognition Problem
  • Let a language L be any set of some arbitrary
    objects s which will be dubbed sentences.
  • That is, the legal or grammatically correct
    sentences of the language.
  • Let the language recognition problem for L be
  • Given a sentence s, is it a legal sentence of the
    language L?
  • That is, is s?L?

7
Vocabularies and Sentences
  • Vocabulary V
  • Finite, nonempty set of elements called symbols
  • Sentences w (words, strings) over V
  • String of finite length of elements of V
  • Empty sentence (or string) ? (length 0)
  • Set of all sentences over V Denoted V
  • A language over V a subset of V

8
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
    languages 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.

9
Phrase-Structure Grammars
  • A phrase-structure grammar (abbr. PSG) G
    (V,T,S,P) is a 4-tuple, in which
  • V is a vocabulary (set of words)
  • The template vocabulary of the language.
  • T ? V is a set of words called terminals
  • Actual words of the language.
  • Also, N V - T is a set of special words
    called nonterminals. (Representing concepts like
    noun)
  • S?N is a special nonterminal, the start symbol.
  • P is a set of productions (to be defined).
  • Rules for substituting one sentence fragment for
    another.

10
Productions
  • A production p?P is a pair p(b,a) of sentence
    fragments l, r, which may generally contain a mix
    of both terminals and nonterminals.
  • We often denote the production as b ? a.
  • Read b goes to a (like a directed graph edge)
  • Call b the before string, a the after string.
  • It is a kind of recursive definition meaning that
    If lbr ? LT, then lar ? LT. (LT sentence
    templates)
  • That is, if lbr is a legal sentence template,
    then so is lar.
  • That is, we can substitute a in place of b in any
    sentence template.
  • Sentence templates can have a mix of terminals
    nonterminals

11
Languages from PSGs
  • The recursive definition of the language L
    defined by the PSG G (V, T, S, P)
  • Rule 1 S ? LT (LT is Ls template language)
  • The start symbol is a sentence template (member
    of LT).
  • Rule 2 ?(b?a)?P ?l,r?V lbr ? LT ? lar ? LT
  • Any production, after substituting in any
    fragment of any sentence template, yields another
    sentence template.
  • Rule 3 (?w? LT ?n?N n?w) ? w?L
  • All sentence (string, word) templates that
    contain no nonterminal symbols are sentences
    (strings, words) in L.

Abbreviatethis usinglbr ? lar.(read, lar is
directly derivable from lbr).
12
PSG Example English Fragment
  • We have G (V, T, S, P), where
  • V (sentence), (noun phrase), (verb
    phrase), (article), (adjective), (noun),
    (verb), (adverb), a, the, large, hungry,
    rabbit, mathematician, eats, hops,
    quickly, wildly
  • T a, the, large, hungry, rabbit,
    mathematician, eats, hops, quickly, wildly
  • S (sentence)
  • P (see next slide)

13
Productions for our Language
  • P (sentence) ? (noun phrase) (verb
    phrase),(noun phrase) ? (article) (adjective)
    (noun),(noun phrase) ? (article) (noun),(verb
    phrase) ? (verb) (adverb),(verb phrase) ?
    (verb), (article) ? a, (article) ?
    the,(adjective) ? large, (adjective) ?
    hungry,(noun) ? rabbit, (noun) ?
    mathematician,(verb) ? eats, (verb) ?
    hops,(adverb) ? quickly, (adverb) ? wildly

14
Backus-Naur Form (BNF)
  • Notation used to specify a Type 2 Grammar
  • Used to describe the syntax of many computer
    languages
  • ?sentence? ?noun phrase? ?verb phrase?
  • ?noun phrase? ?article? ?adjective? ?noun?
  • ?verb phrase? ?verb? ?adverb?
  • ?article? a the
  • ?adjective? large hungry
  • ?noun? rabbit mathematician
  • ?verb? eats hops
  • ?adverb? quickly wildly

Square brackets mean optional
Vertical barsmean alternatives
15
A Sample Sentence Derivation
On each step,we apply a production to a fragment
of the previous sentence template to get a new
sentence template. Finally, we end up with a
sequence of terminals (real words), that is, a
sentence of our language L.
  • (sentence) (noun phrase) (verb
    phrase)
  • (article) (adj.) (noun) (verb phrase)
  • (art.) (adj.) (noun) (verb) (adverb)
  • the (adj.) (noun) (verb) (adverb)
    the large (noun) (verb) (adverb)
    the large rabbit (verb) (adverb)
  • the large rabbit hops
    (adverb)
  • the large rabbit hops
    quickly

16
Another Example
T
V
  • Let G (a, b, A, B, S, a, b, S, S
    ? ABa, A ? BB, B ? ab, AB ? b).
  • One possible derivation in this grammar is S ?
    ABa ? Aaba ? BBaba ? Bababa ? abababa.

P
17
Derivability
  • Recall that the notation w0 ? w1 means that
    ?(b?a)?P ?l,r?V w0 lbr ? w1 lar
  • The template w1 is directly derivable from w0.
  • If ?w2,wn-1 w0 ? w1 ? w2 ? ? wn, then we
    write w0 ? wn, and say that wn is derivable from
    w0
  • The sequence of steps wi ? wi1 is called a
    derivation of wn from w0

18
A Simple Definition of L(G)
  • The language L(G) (or just L) that is generated
    by a given phrase-structure grammar G(V,T,S,P)
    can be defined by L(G) w ? T S ? w
  • That is, L is simply the set of strings of
    terminals that are derivable from the start
    symbol.

19
Language Generated by a Grammar
  • Example Let G (S,A,a,b,a,b, S,S ? aA, S
    ? b, A ? aa). What is L(G)?
  • Easy We can just draw a treeof all possible
    derivations.
  • We have S ? aA ? aaa.
  • and S ? b.
  • Answer L aaa, b

S
aA
b
Example of aderivation treeor parse tree or
sentence diagram.
aaa
20
Generating Infinite Languages
  • A simple PSG can easily generate an infinite
    language.
  • Example S ? 11S, S ? 0 (T 0,1).
  • The derivations are
  • S ? 0
  • S ? 11S ? 110
  • S ? 11S ? 1111S ? 11110
  • id est, (11)0
  • Symbol means 0 or more

L (11)0 theset of all strings consisting
of somenumber of concaten-ations of 11 with
itself,followed by 0.
21
Class Exercise
  • Exercise 4.a.e. (p. 749)
  • Each pair of students should use only one sheet
    of paper while solving the class exercises

22
Another example
  • Construct a PSG that generates the language L
    0n1n n?N.
  • 0 and 1 here represent symbols being concatenated
    n times, not integers being raised to the nth
    power.
  • Solution strategy Each step of the derivation
    should preserve the invariant that the number of
    0s the number of 1s in the template so far,
    and all 0s come before all 1s.
  • Solution S ? 0S1, S ? ?.

23
Another example
  • Construct a PSG that generates the language L
    anb3n ngt1
  • In grammar notation, b3 means bbb
  • The language L(G) defined by a grammar G is its
    set of sentences
  • L(G) includes abbb, aabbbbbb, etc.
  • Does not include abb, bbba, or bubba
  • Solution S ? A, A ? aAbbb, A ? ?.

24
Chomsky Hierarchy
  • Venn Diagram of Grammar Types

Type 0 Phrase-structure Grammars
Type 1 Context-Sensitive
Type 2 Context-Free
Type 3 Regular
25
Chomsky Hierarchy
  • Type 0 Phase-Structure Grammar
  • No restrictions on its productions
  • Example grammar for the set aa S ? ABa, AB ? a
  • Type 1 Context-Sensitive PSG
  • All right-hand side fragments are either longer
    than the corresponding left-hand side fragments,
    or empty b lt a ? a ? (lbr ?
    lar)
  • Example grammar for the set 0n1n2n n?N S ?
    0SAB, BA ? AB, 0A ? 01, 1A ? 11, B ? 12, 2B ? 22,
    S ? ?

26
Chomsky Hierarchy
  • Type 2 Context-Free PSG (Backus-Naur Form)
  • All left-hand side fragments have length 1
    b 1 (b ? N)
  • Example 0n1n n?N S ? 0S1, S ? ?
  • Type 3 Regular PSG
  • All after fragments are either single terminals,
    or a pair of a terminal followed by a
    nonterminal a ? T ? a ? TN
  • Ex 0m1n m,n?N S ? 0S, S ? 1A, S ? 1, A ? 1A,
    A ? 1, S ? ?

27
Surf Quotables
  • In your book, you list the 10 people who have
    had the biggest influence on your life, and Noam
    Chomsky is No. 9. Why?
  • Well, when I was a kid I had no interest in
    politics. I thought it was a big waste of time.
    And in the last couple of years, I've found
    myself much more interested in world affairs. The
    thing about Noam is, he just says it in black and
    white. He says, "Well, look, there were 3,000
    people killed in New York, since then there have
    been maybe 10,000 killed in Afghanistan and
    Iraq." It gets me thinking, do we actually honor
    and respect human life the way we think we do?
    Because if we do, then why are other lives less
    important than ours?
  • Amy Barrett, "Dude, Where's My Wave? Questions
    for Kelly Slater," New York Times Magazine, July
    13, 2003

28
Grammar Example
  • Productions (rules) of a grammar
  • 1. SENTENCE -gt NOUNPHRASE VERB NOUNPHRASE
  • 2.  NOUNPHRASE -gt the ADJECTIVE NOUN
  • 3.  NOUNPHRASE -gt the NOUN
  • 4.  VERB -gt pushed
  • 5.  VERB -gt helped
  • 6.  ADJECTIVE -gt pretty
  • 7.  ADJECTIVE -gt poor
  • 8.  NOUN -gt man
  • 9.  NOUN -gt boy
  • 10. NOUN -gt cat

29
Grammar Example
  • Derivation (parse) tree of the sentence
  • the man helped the poor boy

30
Parsing
  • Top-down parsing
  • Begin at the start symbol
  • Proceed by applying productions to create string
  • Bottom-up parsing
  • Work backwards
  • Begin at the string
  • Proceed by applying productions
  • End at the start symbol

31
Class Exercise
  • Exercise 11.a.b. (p. 749)
  • Each pair of students should use only one sheet
    of paper while solving the class exercises
Write a Comment
User Comments (0)
About PowerShow.com