3-re - CS 476 3 Regular Expressions 1 Regular expressions...

Info icon This preview shows pages 1–4. Sign up to view the full content.

CS 476 – 3. Regular Expressions 1 Regular expressions An alternative way to describe regular languages Common in scripting languages (perl, python, etc.) & UNIX utilities (awk, sed, grep, etc.) Defined by the “regular operations”: Union ( or + ) Concatenation ( · or nothing) Star ( * ). * Note: + is similar to star; except that it cannot include empty set: R + = R * - {∅} . Example 0 * 10 * = { w | w contains exactly one 1 } Σ * * = { w | w contains at least one 1 } Σ * 001Σ * = { w | w contains 001 as a substring } (ΣΣ) * = { w | w contains an even number of characters } ΣΣ * = { w | w 6 = } 01 + 11 = { 01 , 11 } = (0 + 1)1 • ∅ * = { } Precedence of operators 1. Star 2. Concatenation 3. Union Formal Definition: R is a regular expression if R is one of the following: a , a Σ • ∅ R 1 + R 2 R 1 · R 2 R * 1
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

1.1 Equivalence of REs and FAs Theorem 1.1 A language is regular iff it can be generated by some Regular Expression. This will be proven in two parts: Lemma 1.2 Every language generated by a RE can be generated by some DFA/NFA. Lemma 1.3 Every language generated by a DFA/NFA can be generated by some RE. Proof of Lemma 1.2. We will give an NFA for each of the 6 cases that define a RE. R = a for some a Σ q 0 start q 1 a R = q 0 start R = q 0 start The NFA for the remainder can be constructed just in the same way as the NFA constructions we gave for the regular language operators: R 1 + R 2 R 1 · R 2 R * 1 Example 0 : q 00 start q 01 0 1 : q 10 start q 11 1 01 : q 00 start q 01 q 10 q 11 0 1 2
Image of page 2
01 + 0 : q S start q 00 q 01 q 10 q 11 q 0 00 q 0 01 0 1 0 To prove Lemma 1.3, we first define “Generalized NFA” (GNFA) which takes regular expressions for its transitions: e.g: p q (01 + 1) * A GNFA also has the following properties: The start state does not have any incoming transitions. The accepting state (there is only one accepting state) does not have any outgoing transitions. Except for these, there is exactly one transition from every state to every other state. Proof of Lemma 1.3. We will: 1. Convert the DFA into a GNFA (generalized NFA). 2. Reduce the number of states in the GNFS one by one until just 2 states remain. q s start q a R which is equivalent to regular expression R . Definition : A GNFA is a 5-tuple ( Q, Σ , δ, q s , q a ) : Q is a finite set of states.
Image of page 3

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

Image of page 4
This is the end of the preview. Sign up to access the rest of the document.
  • Spring '16
  • Can Alkan
  • Formal language, Regular expression, Regular language, Nondeterministic finite state machine, qs

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern