Formal languages - PowerPoint PPT Presentation

1 / 8
About This Presentation
Title:

Formal languages

Description:

COSC341 Lecture 4. 1. Formal languages. We begin by asking some basic ... Recursive step: if u L, then uaa, uab, uba, and ubb L. We prove that L = Evenstring. ... – PowerPoint PPT presentation

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

less

Transcript and Presenter's Notes

Title: Formal languages


1
Formal languages
  • We begin by asking some basic questions.
  • 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 .
  • What is a string over a, b ?
  • Answer Any finite sequence of alphabet elements.
  • More precisely, for alphabet a, b Any
    function f n ? a, b , where n 0, 1, 2,
    , n-1.
  • If g 3 ? a, b is given by g(0) b, g(1)
    a, and g(2) a, then string g is written baa.

2
Examples of 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 definitionsof languages
  • It is natural to define languages by recursion
    ? is the universal set, the atoms are from ?,
    and the operation to build complex strings is
    concatenation
  • If f n ? ? and g m ? ? then fg nm ? ? has
    fg(j) f(j) for jltn and fg(j) g(j-n) for
    n?jltnm.
  • L a, aa, aaa, is defined by
  • Basis a ? L
  • Recursive step if u ? L then ua ? L.
  • L ?, a, aa, aaa,
  • Basis ? ? L
  • Recursive step if u ? L then ua ? L.
  • L a, aaa, aaaaa, an n is odd
  • Basis a ? L
  • Recursive step if u ? L then uaa ? L

4
A more interesting language
Let ? a, b . Consider the language Evenstring
u u?? has even length. Evenstring can be
defined recursively Basis ? ? L Recursive step
if u ? L, then uaa, uab, uba, and ubb ? L. We
prove that L Evenstring. (?) First we show
inductively that L ? Evenstring. Let u ? L be
arbitrary.Then u must be either ? or formed by
the recursive step. Since length of ? is 0, and 0
is even, ? ? Evenstring. Otherwise u must have
one of the forms vaa, vab, vba, vbb, where v ? L.
By induction, v ? Evenstring. So the length of v
is even. Therefore the length of u vaa, vab,
... is also even. So u ? Evenstring. (?)
Conversely, we show that L ? Evenstring . The
unique string of length 0 is ? and ? ? L. A
string of length n2 has form u vaa, vab, vba,
vbb. By induction v ? L, and by the definition of
L, u ? L.
5
Regular Sets
Operations on sets of strings XY xy x ? X
and y ? Y X ? Y z z ? X or z ?
Y X ?i0? Xi X ?i1? Xi Note that X
XX Regular sets (regular languages) Let S be
an alphabet. ?, l and a, for every a ? S,
are regular. If X and Y are regular sets over S,
then also XY, X ? Y, and X.
6
Examples
Union If L1 a, ab and L2 ba, bb
then L1?L2 a, ab, ba, bb . Concatenation 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, .
7
Regular Expressions
We now introduce shorthand for regular
sets. Write b for the language b, etc. We
define Regular expressions Let S be an
alphabet. ?, l and a, for every a ? X, are
regular If u and v are regular, then also (uv),
(u ? v), and (u). Delete parentheses whenever
possible... Again, u stands for uu.
8
Examples of 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,
Write a Comment
User Comments (0)
About PowerShow.com