Language, machines and artificial intelligence - PowerPoint PPT Presentation

1 / 31
About This Presentation
Title:

Language, machines and artificial intelligence

Description:

When two trains meet each other at a railroad crossing, each shall come to a ... If L is a language over an alphabet A, then a grammar for L consists of a set of ... – PowerPoint PPT presentation

Number of Views:37
Avg rating:3.0/5.0
Slides: 32
Provided by: jonatha229
Category:

less

Transcript and Presenter's Notes

Title: Language, machines and artificial intelligence


1
  • Language, machines and artificial intelligence

When two trains meet each other at a railroad
crossing, each shall come to a stop, and neither
shall proceed until the other has gone.
TEXAS state law
Source www.dumblaws.com
2
Grammars
  • A grammar is a set of rules used to define the
    structure of the strings in a language.
  • If L is a language over an alphabet A, then a
    grammar for L consists of a set of grammar rules
    of the following form 
  • ? ? ?
  • where ? and ? denote strings of symbols taken
    from A and from a set of grammar symbols
    (non-terminals) that is disjoint from A

3
Productions
  • A grammar rule ? ? ? is often called a
    production, and it can be read in any of several
    ways as follows
  • "replace ? by ?",
  • ? produces ?,"
  • "? rewrites to ? ,
  • "? reduces to ?."

4
Where to begin
  • Every grammar has a special grammar symbol called
    a start symbol, and there must be at least one
    production with left side consisting of only the
    start symbol.
  • For example, if S is the start symbol for a
    grammar, then there must be at least one
    production of the form
  •   S? ?.

5
The Four Parts of a Grammar
  • An alphabet N of grammar symbols called
    non-terminals. (Usually upper case letters.)
  •  2. An alphabet T of symbols called terminals.
    (Identical to the alphabet of the resulting
    language.)
  •  3. A specific non-terminal called the start
    symbol. (Usually S. )
  •  4. A finite set of productions of the form ? ?
    ?, where ? and ? are strings over the alphabet
    N ? T

6
Example
  • Let A a, b, c. Then a grammar for the
    language A can be described by the following
    four productions
  • S ? ?
  • S ? aS
  • S ? bS
  • S ? cS.
  • Or in shorthand
  • S ? ? aS bS cS,
  • "S can be replaced by either ?, or aS, or bS, or
    cS."

7
  • A string made up of grammar symbols and language
    strings is called a sentential form.
  • If x and y are sentential forms and ? ? ? is a
    production, then the replacement of ? by ? in x?y
    is called a derivation, and we denote it by
    writing
  •   x?y ? x?y.

8
Sample derivation.
  • S ? ? aS bS cS,
  • S ? aS
  • S ? aS ? aaS.
  • S ? aS ? aaS ? aacS ? aacbS..
  • S ? aS ? aaS ? aacS ? aacbS ? aacb?
  • aacb
  • A short hand way of showing a derivation exists
  • S ? aacb
  • derives in zero or more steps

9
Other shorthand
  • The following three symbols with their associated
    meanings are used quite often in discussing
    derivations
  •  ? derives in one step,
  •  ? derives in one or more steps,
  •  ? derives in zero or more steps.

10
A more complex grammar
  •   S ? AB
  • A? ? aA
  • B ? ? bB.
  •  
  • We can deduce that the grammar non-terminal
    symbols are S, A, and B, the start symbol is S,
    and the language alphabet includes ?, a, and b.

11
Another derivation
  • Let's consider the string aab.
  • The statement S ? aab means that there exists a
    derivation of aab that takes one or more steps.
  • For example, we have
  •  S ? AB ? aAB ? aaAB ? aaB ? aabB ? aab.

12
Grammar specifies a language
  • If G is a grammar, then the language of G is the
    set of language strings derived from the start
    symbol of G. The language of G is denoted by
  •  
  • L(G)

13
  • If G is a grammar with start symbol S and set of
    language strings T, then the language of G is the
    following set
  •  
  • L(G) s s ? T and S ? s.

14
Finite languages
  • If the language is finite, then a grammar can
    consist of all productions of the form
  • S ? w
  • for each string w in the language.
  • For example, the language a, ba can be
    described by the grammar S ? a ab.

15
Infinite languages
  • If the language is infinite, then some production
    or sequence of productions must be used
    repeatedly to construct the derivations.
  • Notice that there is no bound on the length of
    strings in an infinite language.
  • Therefore there is no bound on the number of
    derivation steps used to derive the strings.
  • If the grammar has n productions, then any
    derivation consisting of n 1 steps must use
    some production twice

16
  • For example, the infinite language anb n ? 0
    can be described by the grammar,
  • S ? b aS.
  • To derive the string anb, use the production
  • S ? aS
  • repeatedly --n times to be exact-- and then stop
    the derivation by using the production S ? b.
  • The production S ? aS allows us to say
  • If S derives w, then it also derives aw,"

17
Recursion
  • A production is called recursive if its left side
    occurs on its right side.
  • For example, the production S ? aS is recursive.
  • A production S ? ? is indirectly recursive if S
    derives (in two or more steps) a sentential form
    that contains S.

18
Indirect recursion
  • For example, suppose we have the following
    grammar
  •   S ? b aA
  • A ? c bS.
  •  The productions S ? aA and A ? bS are both
    indirectly recursive  
  • S ? aA ?abS, 
  • A ?bS ?baA.

19
  • A grammar is recursive if it contains either a
    recursive production or an indirectly recursive
    production.
  • A grammar for an infinite language must be
    recursive!
  • However, a given language can have many grammars
    which could produce it.

20
Combining Grammars
  • Suppose M and N are languages. We can describe
    them with grammars have disjoint sets of
    nonterminals.
  • Assign the start symbols for the grammars of M
    and N to be A and B, respectively
  • M A ? ? N B ? ?
  • Then we have the following rules for creating new
    languages and grammars

21
Union rule
  • The union of the two languages, M ? N, starts
    with the two productions
  • S ? A B
  • followed by the grammars of M and N
  • A ? ?
  • B ? ?

22
Product rule
  • Similarly, the language M ? N starts with the
    production
  • S ? AB
  • followed by, as above,
  • A ? ?
  • B ? ?

23
Closure rule
  • Finally, the grammar for the closure of a
    language, M, starts with the production
  • S ? AS ?
  • followed by the grammar of M
  • A ? ?

24
Example union
  • Suppose we want to write a grammar for the
    following language 
  • L ?, a, b, aa, bb, ..., an, bn, ...
  • L is the union of the two languages
  • M an n ? N
  • N bn n ? N

25
  • Thus we can write a grammar for L as follows
  • S ? A B union rule,
  • A ? ? aA grammar for M,
  • B ? ? bB grammar for N.

26
Example product
  • Suppose we want to write a grammar for the
    following language 
  • L ambn m,n ? N
  • L is the product of the two languages
  • M am m ? N
  • N bn n ? N

27
  • Thus we can write a grammar for L as follows
  •  
  • S ? AB product rule,
  • A ? ? aA grammar for M,
  • B ? ? bB grammar for N.

28
Example closure
  • Suppose we want to construct the language L of
    all possible strings made up from zero or more
    occurrences of aa or bb.
  • L aa, bb M
  • M aa, bb

29
  • So we can write a grammar for L as follows
  •  
  • S ? AS ? closure rule,
  • A ? aa bb grammar for aa, bb.

30
An equivalent grammar
  • We can simplify this grammar
  • Replace the occurrence of A in S ? AS by the
    right side of A ? aa to obtain the production S ?
    aaS.
  • Replace A in S ?AS by the right side of A ? bb to
    obtain the production S ? bbS.
  • This allows us to write the the grammar in
    simplified form as
  •   S ? aaS bbS ?

31
 
Some simple grammars
Write a Comment
User Comments (0)
About PowerShow.com