Strings and Languages Operations

Slides:



Advertisements
Similar presentations
Pumping Lemma Examples
Advertisements

Regular Grammars Formal definition of a regular expression.
COMMONWEALTH OF AUSTRALIA Copyright Regulations 1969 WARNING This material has been reproduced and communicated to you by or on behalf of Monash University.
COMMONWEALTH OF AUSTRALIA Copyright Regulations 1969 WARNING This material has been reproduced and communicated to you by or on behalf of Monash University.
Fall 2005 CSE 467/567 1 Formal languages regular expressions regular languages finite state machines.
79 Regular Expression Regular expressions over an alphabet  are defined recursively as follows. (1) Ø, which denotes the empty set, is a regular expression.
CS 3240 – Chuck Allison.  A model of computation  A very simple, manual computer (we draw pictures!)  Our machines: automata  1) Finite automata (“finite-state.
1 Regular Expressions/Languages Regular languages –Inductive definitions –Regular expressions syntax semantics Not covered in lecture.
Lecture 1 String and Language. String string is a finite sequence of symbols. For example, string ( s, t, r, i, n, g) CS4384 ( C, S, 4, 3, 8) (1,
Regular Languages A language is regular over  if it can be built from ;, {  }, and { a } for every a 2 , using operators union ( [ ), concatenation.
Chapter 2 Languages.
Language Recognizer Connecting Type 3 languages and Finite State Automata Copyright © – Curt Hill.
Lexical Analysis CSE 340 – Principles of Programming Languages Fall 2015 Adam Doupé Arizona State University
CSC312 Automata Theory Lecture # 2 Languages.
CSC312 Automata Theory Lecture # 2 Languages.
Formal Methods in SE Theory of Automata Qasiar Javaid Assistant Professor Lecture # 06.
Lecture Two: Formal Languages Formal Languages, Lecture 2, slide 1 Amjad Ali.
Two examples English-Words English-Sentences alphabet S ={a,b,c,d,…}
Recap Lecture-2 Kleene Star Closure, Plus operation, recursive definition of languages, INTEGER, EVEN, factorial, PALINDROME, {anbn}, languages of strings.
Automata, Computability, & Complexity by Elaine Rich ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Slides provided by author Slides edited for.
1 Chapter 1 Introduction to the Theory of Computation.
Lecture # 3 Regular Expressions 1. Introduction In computing, a regular expression provides a concise and flexible means to "match" (specify and recognize)
Languages, Grammars, and Regular Expressions Chuck Cusack Based partly on Chapter 11 of “Discrete Mathematics and its Applications,” 5 th edition, by Kenneth.
Module 2 How to design Computer Language Huma Ayub Software Construction Lecture 8.
L ECTURE 3 Chapter 4 Regular Expressions. I MPORTANT T ERMS Regular Expressions Regular Languages Finite Representations.
1 Module 14 Regular languages –Inductive definitions –Regular expressions syntax semantics.
Recursive Definitions & Regular Expressions (RE)
Regular Expressions and Languages A regular expression is a notation to represent languages, i.e. a set of strings, where the set is either finite or contains.
Regular Expressions Chapter 6 1. Regular Languages Regular Language Regular Expression Finite State Machine L Accepts 2.
Strings and Languages CS 130: Theory of Computation HMU textbook, Chapter 1 (Sec 1.5)
1 String v is a prefix of w if w= v y for some string y. String v is a suffix of w if w= x v for some string x. String v is a substring of w if there are.
Lecture 02: Theory of Automata:08 Theory of Automata.
CSC312 Automata Theory Lecture # 3 Languages-II. Formal Language A formal language is a set of words—that is, strings of symbols drawn from a common alphabet.
Regular Expressions Chapter 6. Regular Languages Regular Language Regular Expression Finite State Machine L Accepts.
CS 203: Introduction to Formal Languages and Automata
Recursive Definations Regular Expressions Ch # 4 by Cohen
MA/CSSE 474 Theory of Computation Minimizing DFSMs.
November 2003Computational Morphology III1 CSA405: Advanced Topics in NLP Xerox Notation.
Lecture # Book Introduction to Theory of Computation by Anil Maheshwari Michiel Smid, 2014 “Introduction to computer theory” by Daniel I.A. Cohen.
Strings and Languages Denning, Section 2.7. Alphabet An alphabet V is a finite nonempty set of symbols. Each symbol is a non- divisible or atomic object.
Lecture # 4.
Mathematical Foundations of Computer Science Chapter 3: Regular Languages and Regular Grammars.
Lecture 2 Theory of AUTOMATA
1 Section 11.1 Regular Languages Problem: Suppose the input strings to a program must be strings over the alphabet {a, b} that contain exactly one substring.
1 Chapter Regular Languages. 2 Section 11.1 Regular Languages Problem: Suppose the input strings to a program must be strings over the alphabet.
1 Chapter 3 Regular Languages.  2 3.1: Regular Expressions (1)   Regular Expression (RE):   E is a regular expression over  if E is one of:
Week 13 - Wednesday.  What did we talk about last time?  Exam 3  Before review:  Graphing functions  Rules for manipulating asymptotic bounds  Computing.
1 Strings and Languages Lecture 2-3 Ref. Handout p12-17.
Lecture 02: Theory of Automata:2014 Asif Nawaz Theory of Automata.
Set, Alphabets, Strings, and Languages. The regular languages. Clouser properties of regular sets. Finite State Automata. Types of Finite State Automata.
Lecture 03: Theory of Automata:2014 Asif Nawaz Theory of Automata.
CHAPTER TWO LANGUAGES By Dr Zalmiyah Zakaria.
1 Let S = { π : π is a permutation of {1, 2, 3, …, n} for some integer n ≥ 1 }. (a) List the elements of S for n= 1, 2, and 3. (b) Prove that the set S.
MA/CSSE 474 Theory of Computation Regular Expressions Intro.
Recap Lecture 3 RE, Recursive definition of RE, defining languages by RE, { x}*, { x}+, {a+b}*, Language of strings having exactly one aa, Language of.
Theory of Computation Lecture #
Lecture # 2.
Language Theory Module 03.1 COP4020 – Programming Language Concepts Dr. Manuel E. Bermudez.
Regular Languages, Regular Operations, Closure
Theory of Automata.
Regular Expressions (Examples)
LANGUAGES Prepared by: Paridah Samsuri Dept. of Software Engineering
COP4620 – Programming Language Translators Dr. Manuel E. Bermudez
Recap lecture 29 Example of prefixes of a language, Theorem: pref(Q in R) is regular, proof, example, Decidablity, deciding whether two languages are equivalent.
MA/CSSE 474 Theory of Computation Minimizing DFSMs.
CSE322 Regular Expressions and their Identities
Chapter 1 Introduction to the Theory of Computation
Recap lecture 11 Proof of Kleene’s theorem part II (method with different steps), particular examples of TGs to determine corresponding REs.
Recap Lecture 3 RE, Recursive definition of RE, defining languages by RE, { x}*, { x}+, {a+b}*, Language of strings having exactly one aa, Language of.
Introduction and Chapter One: Fundamentals
Presentation transcript:

Strings and Languages Operations Concatenation Exponentiation Kleene Star Regular Expressions

Strings and Language Operations Concatenation Exponentiation Kleene star Pages 27-30 of the text Regular expressions Pages 71-75 of the text

String Concatenation If x and y are element of S*, the concatenation of x and y is the string xy formed by writing the symbols of x and the symbols of y consecutively. Suppose x = abb and y = ba xy = abbba yx = baabb

Properties of String Concatenation Suppose x,y and z are strings. Concatenation is not commutative. xy is not guaranteed to be equal to yx Concatenation is associative (xy)z = x(yz) = xyz The empty string is the identity for concatenation x/\ = /\x = x

Language Concatenation Suppose L1 and L2 are languages. The concatenation of L1 and L2, denoted L1L2,is defined as L1L2 = { xy | x  L1 and y  L2 } Example, Let L1 = { ab, bba } and L2 = { aa, b, ba } What is L1L2? Solution Let x1= ab, x2= bba, y1= aa, y2= b, y3= ba L1L2 = { x1y1, x1y2, x1y3, x2y1, x2y2, x2y3 } = { abaa, abb, abba, bbaaa, bbab, bbaba}

Language Concatenation is not commutative Let L1 = { aa, bb, ba } and L2 = { /\, aba } Let x1= aa, x2= bb, x3=ba, y1= /\, y2= aba L1L2 = { x1y1, x1y2, x2y1, x2y2, x3y1, x3y2 } = { aa, aaaba, bb, bbaba, ba, baaba } L2L1 = { y1x1, y1x2, y1x3, y2x1, y2x2, y2x3 } = { aa, bb, ba, abaaa, ababb, ababa } L2L2 = { y1y1, y1y2, y2y1, y2y2 } = { /\, aba, aba, abaaba } = { /\, aba, abaaba }

Associativity of Language Concatenation (L1L2)L3 = L1(L2L3) = L1L2L3 Example Let L1={a,b}, L2={c,d}, and L3={e,f} L1L2L3=({a,b}{c,d}){e,f} ={ac, ad, bc, bd}{e,f} ={ ace,acf,ade,aef,bce,bcf,bde,bdf } L1L2L3={a,b}({c,d}{e,f}) ={a,b}{ce, df, ce, df} ={ ace,acf,ade,aef,bce,bcf,bde,bdf }

Special Cases What language is the identity for language concatenation? The set containing only the empty string /\: {/\} Example {aab,ba,abc}{/\} = {/\}{aab,ba,abc} = {aab,ba,abc} What about {}? For any language L, L {} = {} L = {} Thus {} for concatentation is like 0 for multiplication {aab,ba,abc}{} = {}{aab,ba,abc} = {} The intuitive reason is that we must choose a string from both sets that are being concatenated, but there is nothing to choose from {}.

Exponentiation We use exponentiation to indicate the number of items being concatenated Symbols Strings Set of symbols (S for example) Set of strings (languages) a3 = aaa x3 = xxx S3 = SSS = { x  S* | |x|=3 } L3 = LLL

Examples of Exponentiation Let x=abb, S={a,b}, L={ab,b} a4 = aaaa x3 = (abb)(abb)(abb) = abbabbabb S3 = SSS = {a,b}{a,b}{a,b} ={aaa,aab,aba,abb,baa,bab,bba,bbb} L3 = LLL = {ab,b}{ab,b}{ab,b} = {ababab,ababb,abbab,abbb, babab,babb,bbab,bbb}

Results of Exponentiation Exponentiation of a symbol or a string results in a string. Exponentiation of a set of symbols or a set of strings results in a set of strings a symbol  a string a string  a string a set of symbols  a set of strings a set of strings  a set of strings

Special Cases of Exponentiation L0 = { /\ } for any language L {aa,bb}0 = { /\ } { a, aa, aaa, aaaa, …}0 = { /\ } { /\ }0 = { /\ } 0 = { }0 = { /\ }

Kleene Star Kleene * is a unary operation on languages. Kleene * is not an operation on strings However, see the pages on regular expressions. L* represents any finite number of concatenations of L. L* = Uk>0 Lk = L0 U L1 U L2 U … For any L, /\ is always an element of L* because L0 = { /\ } Thus, for any L, L* != 

Example of Kleene Star Let L={aa} L0={ /\ } L1=L={aa } L2={ aaaa } L* = L0  L1  L2  L3 … = { /\, aa, aaaa, aaaaaa, … } = set of all strings that can be obtained by concatenating 0 or more copies of aa

Example of Kleene Star Let L={aa, b} L0={ /\ } L1=L={aa,b} L2= LL={ aaaa, aab, baa, bb} L3= … L* = L0  L1  L2  L3 … = set of all strings that can be obtained by concatenating 0 or more copies of aa and b

Regular Languages Regular languages are languages that can be obtained from the very simple languages over S, using only Union Concatenation Kleene Star See lecture 14 and pages 71-75 of the text

Examples of Regular Languages {aab} (i.e. {a}{a}{b} ) {aa,b} (i.e. {a}{a}  {b} ) {a,b}* language of strings that can be obtained by concatenating any number of a’s and b’s {bb}{a,b}* language of strings that begin with bb (followed by any number of a’s and b’s) {a}*{bb,/\} language of strings that begin with any number of a’s and end with an optional bb. {a}*{b}* language of strings that consist of only a’s or only b’s and /\.

Regular Expressions We can simplify the formula for regular languages slightly by leaving out the set brackets { } and replacing  with + The results are called regular expressions.

Examples of Regular Expressions Set notation Regular Expressions {aab} aab {aa,b} = {aa}{b} aa+b {a,b}* = ({a}{b})* (a+b)* {bb}{a,b}* = {bb}({a}{b})* bb(a+b)* {a}*{bb,/\} = {a}*({bb}{/\}) a*(bb+/\) {a}*{b}* a*+b*

String or Language? Consider the regular expression a*(bb+/\) a*(bb+/\) is a string over alphabet {a, b, *, +, /\, (, ),  } a*(bb+/\) represents a language over alphabet {a, b} It represents the language of strings over {a,b} that begin with any number of a’s and end with an optional bb. Some regular expressions look just like strings over alphabet {a,b} Regular expression aaba represents the language {aaba} Regular expression /\ represents the language {/\} It should be clear from the context whether a sequence of symbols is a regular expression or just a string.