ozeda.com:8890 regular languagescpennycu/2019/assets/fall/toc/04...a few examples (not limited to):...

18
Regular Languages http://ozeda.com:8890

Upload: others

Post on 25-Jan-2021

0 views

Category:

Documents


0 download

TRANSCRIPT

  • Regular Languages

    http://ozeda.com:8890

  • Definition:

    A language is a Regular Language

    iff some

    Finite State Machine

    recognizes it.

  • Intuition Building:

    What would make a

    language

    NOT Regular?

    Answer: It requires memory.

  • A Few Examples (not limited to):Non-Regular languages

    ● 0n1n

    ● 0m1n, m > n● w = (0|1)*

    where #

    0(w) = #

    1(w)

    ● ww or wwR

    Regular Languages

    ● Contains a substring● 0*1*0+● Any finite language● Binary numbers divisible

    by 3

  • Regular OperationsLet A and B be languages. We define the regular

    operations union, concatenation, and star as

    follows:

    ● Union: A ∪ B = {x | x ∈ A or x ∈ B }.● Concatenation: A ⚬ B = {xy | x ∈ A and y ∈ B }.● Star: A* = {x

    1

    x

    2

    ...x

    k

    | k ≥ 0 and each x

    i

    ∈ A }.

  • Question:Are Regular

    Languages closed

    under Union,

    Concatenation, and

    Star?

  • Theorem: Regular Languages are Closed Under UnionIntuition:

    ● In terms of sets, what does Union mean?● How can this be applied to two FSMs?● Can you build a machine that models this

    behavior?

    Define:

    ● Q3

    = Q

    1

    ⨯ Q2

    or, Q

    3

    = {(p, q) | p ∈ Q1

    and q ∈ Q2

    }

    ● Σ (no change needed)

    ● q3

    = (q

    1

    , q

    2

    )

    ● F3

    = (F

    1

    ⨯ Q2

    ) ∪ (Q1

    ⨯ F2

    )

    Note: NOT (F

    1

    ⨯ F2

    )

    ● δ3

    ((p, q), a) = (δ1

    (p, a), δ2

    (q, a))

    where a ∈ Σ and (p, q) ∈ Q3

    .

    Define:

    ● M1

    = (Q

    1

    , Σ, δ1

    , q

    1

    , F

    1

    )

    ● M2

    = (Q

    2

    , Σ, δ2

    , q

    2

    , F

    2

    )

    ● M3

    = (Q

    3

    , Σ, δ3

    , q

    3

    , F

    3

    )

    Construct M

    3

    = M

    1

    ∪ M2

    What else would this proof need?

  • NFAs and DFAsAnd you thought we

    couldn’t come up with

    any more acronyms….

  • Reminder: Regular OperationsLet A and B be languages. We define the regular

    operations union, concatenation, and star as

    follows:

    ● Union: A ∪ B = {x | x ∈ A or x ∈ B }.● Concatenation: A ⚬ B = {xy | x ∈ A and y ∈ B }.● Star: A* = {x

    1

    x

    2

    ...x

    k

    | k ≥ 0 and each x

    i

    ∈ A }.

  • Proofs that Regular Languages Are Closed Under...● Union: A ∪ B = {x | x ∈ A or x ∈ B}.

    ○ Proof by Construction (last class)

    But…

    ● Concatenation: A ⚬ B = {xy | x ∈ A and y ∈ B}.● Star: A* = {x

    1

    x

    2

    ...x

    k

    | k ≥ 0 and each x

    i

    ∈ A}.

    We Need Better Tools!

  • Deterministicvs.

    NondeterministicFinite Automata

    Everything discussed thus far was

    deterministic, thus a DFA

    Expand this idea to add multiple

    potential paths

    Two types of FSMs

  • What is Determinism?

    Are computers deterministic?

    “If the current state is known, and the

    current inputs are known, then the

    future state is also known.”

    ● No Choices● No Randomness● No Oracles● No Errors/Cheating

    According to our previous definition,

    FSM == DFA

  • What is Nondeterminism?

    “If the current state is known, and the

    current inputs are known, there may be

    multiple possible future states.”

    ● Random choice?● Parallel choice and simultaneous execution?

  • NFAs: Relaxing The Requirements

    Multiple edges with the same label

    ε (optional) edges● ε is not in Σ● Does not consume input character

    Only need one path to an accept state

    What could go wrong?

    How do we know which path to try?

    ● Try them all● Always make the right choice

  • NFA Formal Definition

    A Nondeterministic Finite

    Automaton is a 5-tuple

    N = (Q, Σ, δ, q0

    , F )

    where:

    Q Set of states (finite)

    Σ Alphabet of symbols (finite)δ The transition function

    δ: Q x Σε ➝ 𝓟(Q)q

    0

    The starting (initial) state

    q

    0

    ∈ Q

    F The set of “Accept” states

    F ⊆ Q

  • NFA Formal Definition Example

    N = (Q, Σ, δ, q0

    , F )

    Q {q

    1

    , q

    2

    , q

    3

    , q

    4

    }

    Σ {0, 1}

    δ

    q

    0

    q

    1

    F {q

    4

    }N = ({q

    1

    , q

    2

    , q

    3

    , q

    4

    }, {0, 1}, δ, q1

    , {q

    4

    })

  • NFA Formal Definition Example

    N = (Q, Σ, δ, q0

    , F )

    Q {q

    1

    , q

    2

    , q

    3

    , q

    4

    }

    Σ {0, 1}

    δ

    q

    0

    q

    1

    F {q

    4

    }N = ({q

    1

    , q

    2

    , q

    3

    , q

    4

    }, {0, 1}, δ, q1

    , {q

    4

    })

  • NFA Formal Definition of ComputationLet N = (Q, Σ, δ, q

    0

    , F )

    Let y

    1

    y

    2

    ...y

    m

    be a string w where y

    i

    ∈ Σε

    N accepts w if there is a sequence of

    states r

    0

    , r

    1

    , r

    2

    ...r

    m

    in Q such that:

    1. r

    0

    = q

    0

    ,

    2. r

    i+1

    ∈ δ(ri

    , y

    i+1

    ) for 0 ≤ i < m, and

    3. r

    m

    ∈ F

    N “recognizes”

    language A if

    A = {w | N accepts w}

    We now have a

    NONDETERMINISTIC tool that we

    can use to understand Regular

    Languages!

    Wait… Can we say this?!?