COSC 341 Languages - PowerPoint PPT Presentation

1 / 8
About This Presentation
Title:

COSC 341 Languages

Description:

... L, then uaa, uab, uba, and ubb L. Is L = Evenstring? How can we ... Suppose u X. Then so are uaa, uab, uba, ubb. So X=L, and strings in L all have even length. ... – PowerPoint PPT presentation

Number of Views:31
Avg rating:3.0/5.0
Slides: 9
Provided by: MOL52
Category:
Tags: cosc | languages | ubb

less

Transcript and Presenter's Notes

Title: COSC 341 Languages


1
COSC 341Languages
  • We begin our investigation of formal languages.
  • Lets ask some basic questions.
  • Why do we care about formal languages?
  • Answer Programming languages!
  • What is a formal language?
  • Answer A set of strings over some alphabet.
  • What is an alphabet?
  • Answer Any finite set, for example a, b . Or
    the English alphabet of 26 letters. Or 128 ASCII
    characters. Or the digits 0, 1, 2, , 9.
  • What is a string over a, b ?
  • Answer Any function f n ? a, b , where n
    0, 1, 2, , n-1.
  • Example If g 3 ? a, b is given by g(0) b,
    g(1) a, and g(2) a, then g is the string
    usually written baa.

2
Examples of simple formal languages
  • Definition If ? is any alphabet, then ? is the
    set of all strings over ?.
  • Examples Suppose ? a, b .
  • Simplest of all languages is ?, which has no
    strings in it at all.
  • ? is a language with one string, namely the
    empty string (of length 0).
  • a is a language with one string, namely the
    function f 1 ? a, b defined by f(0) a.
    (String of length 1.)
  • ?, a, b is the finite language consisting of
    all strings of length 1.
  • ?, a, b, aa, ab, ba, bb is the finite
    language consisting of all the strings of length
    2.
  • ? ?, a, b, aa, ab, ba, bb, aaa, aab, is
    the infinite language consisting of all strings.
    Notice that ? includes the empty string ?.

3
Recursive definitions of languages
  • We like to define languages by recursion because
    it shows how to generate strings of the language
  • ? is the universal set, the atoms typically
    come from ?, and the operation used to build
    complex strings is usually concatenation
  • Recall that we write the concatenation of two
    strings, e.g. abba and baab, by writing them side
    by side abbabaab
  • L a, aa, aaa, is defined by
  • a ? L
  • if u ? L then ua ? L.
  • L ?, a, aa, aaa,
  • ? ? L
  • if u ? L then ua ? L.
  • L a, aaa, aaaaa, an n is odd
  • ?
  • ?

4
A more interesting language
Let Evenstring u u?? has even length,
where ? a, b . Maybe Evenstring can be
defined recursively ? ? L if u ? L, then uaa,
uab, uba, and ubb ? L. Is L Evenstring? How can
we be sure? We must show that L ? Evenstring and
that Evenstring ? L. That L ? Evenstring can be
proved by induction Let X ? L consist of the
strings of L that belong to Evenstring. Now ? ? X
since 0 is even. Suppose u ? X. Then so are uaa,
uab, uba, ubb. So XL, and strings in L all have
even length. Conversely, we show (again by
induction) that every string of even length
belongs to L. Let E 0, 2, 4, and let Y n
? E every string of length n is in L. Now 0 ?
Y and if n ?Y then n2?Y. Why? So?
5
Another way to define languages
  • Suppose ? a, b .
  • The simplest languages over a, b are
  • ?, the set having no strings in it at all.
  • ?, the set having just one string, namely the
    empty string (of length 0).
  • a , the set having just one string, namely the
    function f 1 ? a, b defined by f(0) a.
    (String of length 1.)
  • b , the set having just one string, namely the
    function g 1?a, b given by g(0) b.
  • Idea
  • Suppose we combine these languages with the help
    of set-theoretic operations like ? and ??
  • Would still have a recursive way to define
    languages, but the basic building blocks are
    languages, not strings, and the operations are
    things we do to languages, not things we do to
    strings.

6
What operations may be used?
Union If L1 a, ab and L2 ba, bb
then L1?L2 a, ab, ba, bb . Concatenation of
languages If L1 a, ab and L2 ba, bb
then L1L2 aba, abb, abba, abbb . Note that
L1L2 ? L1?L2 and L1L2 ? L2L1 baa, baab, bba,
bbab . Kleene star If L1 a then L1 ?,
a, aa, aaa, . If L2 aa then L2 ?, aa,
aaaa, . (Why only these operations? Tradition.
We shall see in Ch 6 that we may also use ? and
relative complement if we choose.)
7
Regular expressions
  • Suppose we want to define a language over
    alphabet ? a, b by giving a recursive
    definition on languages, where
  • we say which of ?, ?, a , b are to be
    used as building blocks, and
  • which of union, concatenation, and Kleene star
    are to be used as operations.
  • Regular expressions are a notation for expressing
    the languages as building blocks option
    concisely.
  • Simplest regular expressions (for ? a, b )
  • ?, ?, a, b.
  • More complex regular expressions are built up as
    follows
  • if u and v are regular expressions, then so are
    u?v, uv, and u.

8
Using regular expressions
Let ? a, b . The regular expression ? defines
the empty language ? ? defines the language ? a
defines the language a a?b defines the
language a ?b a, b a defines the
language ?, a, aa, aaa, (ab) defines ?, ab,
abab, ababab, a?b defines a ?b ?,
a, aa, ??, b, bb, ?, a, b, aa, bb, aaa,
bbb, (a?b) defines a, b ?, a, b, aa,
ab, ba, bb, What regular expression defines
Evenstring?
Write a Comment
User Comments (0)
About PowerShow.com