SmithLogo

CSC 250

Theory of Computation

Smith Computer Science



Lecture Notes 06:
Practice with Regular Expressions


Outline

This class we'll discuss:




Recap: RegExes, how powerful are they?

For the the Machine Abstraction of Regular Expressions, we can ask:

what problems can they solve?

In other words: Which Language sets can they generate/accept?

Regular Languages are more powerful than Finite Languages (can encompass more)
more descriptive power!



Still confused about RExs? Go to Office Hours with Winnie!! (and with me)




Algorithms: Code, RegExes, and Diagrams

As we saw above, an algorithm can be encoded as:

  1. RegEx
  2. (pseudo) Code
But we know that a piece of code can also be drawn using things like a "Flow Diagram"!

In this section, we'll use a special type of diagram called a State Diagram.

State Diagram

A State diagram looks like this:

not a map



Finite Automaton AKA: Finite State Machine (FSM)

  1. Finite number of states
  2. Follows Rules that have been programmed beforehand


phsm

Operation Examples

Example 01: Processing a String



proc 1!

Example 02: Processing a String



proc 2!

Example 03: Processing a String



proc 3!

Activity 1 [2 minutes]:
Try to build your own machine. One that "Accepts" this set:

zero 1 zero 1!

(Wait; then Click)



0 one 0 one!




Alphabets and languages



Alphabeast!




Formal Definition



very formal

Our Last Example:



DEFINE!

Operators in FSMs: OR

How might we handle a language that contains an or?

Example:
{w|w doesn’t contain either 00 or 11 as a substring}


ORRRRRR!

Let's try one basic example:

Yak is a good dog!

Activity 2 [2 minutes]:
Explain the sequence of states for these words:
  • 101010
  • 010110
  • 110011


Activity 3 [2 minutes]:
Answer the following questions:
  • What is the descriptive power of Finite Automata?
  • (Wait; then Click)



    We need to compare it with regular expressions... we'll do that bit by bit.

    Reg Lang descriptive power!


  • Are there languages that Cannot be described by a finite automaton?

  • (try to come up with a counter example)
    (Wait; then Click)



    YES! NON Regular Languages!

    Can't do it!




    Useful Properties

    These are some properties that can help you deduce, generalize, or analyze FSMs with respect to their RegEx and Regular Languages.

    Complement

    IF a Language \(L_1\) is recognizable by an FA \( M_1\),
    is language \( (L_1)^{c} \) also recognizable by some FA?

    Or in other words, \[\exists M_2 \quad | \quad L(M_2) = L(M_1)^{c} \]

    complement!



    Intersection



    interX!

    Activity 4 [2 minutes]:
    How would you prove this (by construction)?
    (Wait; then Click)



    1. run both machines “in parallel”
    2. accept if (and only if) both reach an accepting state


    Example:

    interX Exmpl!



    inX Exmpl!



    Intersection: General Rule



    inX rule!





    Union



    uni | on!

    Activity 5 [2 minutes]:
    How would you prove this (by construction)?
    (Wait; then Click)



    1. run both machines “in parallel”
    2. accept if either reach an accepting state


    Example:

    union Exmpl!



    union Sol



    Union: General Rule



    union rule