1: Regular languages and FSAs Flashcards
True/false: all finite languages are regular
True.
What is an alphabet?
A finite set of symbols, called letters.
What is a letter?
One item (symbol) within an alphabet.
How do you use the pumping lemma to show a language is regular?
??
If A is an alphabet, what is A*?
A* = the set of all words over (that can be built from) the alphabet A, including the empty word. Words are built from 0 or more letters from the alphabet. Languages from the alphabet A will be subsets of A*.
How do you define a DFA?
You define DFAs as tuples of 5 items as M = (A, S, F, s0, T).
A = alphabet
S = set of states
F = transition function, which takes a non-empty input letter and current state and returns (and goes to) another state
s0 = start state; s0 ∈ S
T = set of accept states, aka terminals. T is a subset of all states: T ⊆ S.
What is a terminal also known as?
A terminal is aka an accept state.
What is a transition function?
Transition functions are used to translate between current states to the next ones according to inputs in FSAs.
What is a regular language?
Languages are regular when there is a DFA whose language is the same as the language in question.
What is an NFA?
A nondeterministic finite state automaton (NFA) is a variant of a FSA which can be modelled as being in more than one state simultaneously. Thinking of the current states of machines as brances of a tree, only one leaf node needs to accept at some point for the NFA to accept the input.
How do you define an NFA?
You define NFAs as a tuple of 5 items such that M = (A,
S, F, s0, T).
A = alphabet
S = set of states
F = transition function, which takes an input letter (which can now also be empty) and current state and returns (and goes to) another state in the power set of S, P(S), which is the set of all subsets of S (since some may become cut off)
s0 = start state; s0 ∈ S
T = set of accept states, aka terminals. T is a subset of all states: T ⊆ S.
What is the language defined by an NFA?
The language will consist of all the words that the NFA accepts.
Prove that if a language is accepted by an NFA if and only if it is accepted by a DFA.
Let N = (A, S, F, s0, T) be an NFA. We construct a DFA M that accepts L(N). We let M = (A,P(S), F’, S0, T’), where:
• The transition function F’ : A x P(S) → P(S) is given by:
F’(a, X) = {y ∈ S : ∃ x ∈ X with a path labelled ϵ ^ i a ϵ ^ j = a from x to y in N, for some i, j ≥ 0}.
• The start state is S0 = {s0} ∪ {s : there exists a path labelled only with ϵs from s0 to s}.
• The new set of accept states is T’ = {Y ⊆ S : Y ∩ T ≠ ∅}, which is all sets of states containing at least one accept state of N.
To finish the proof, we need to show that L(M) = L(N). To do this, we first show that L(N) ⊆ L(M) and then that L(M) ⊆ L(N). To see that L(N) ⊆ L(M), let w = a1 a2 … an ∈ L(N). Then there is a path in N: S0 → a1 S1→ a2 S2 → ··· → an Sn ∈ T’.
Let S1 = F’(a1, S0), S2 = F’(a2, S1), …, Sn = F’(an, Sn-1). Then s1 ∈ S1, s2 ∈ S2, …, sn ∈ Sn ∈ T’. So there is a path in M: S0 → a1 S1 → a2 S2 → ··· → an Sn ∈ T’. So w ∈ L(M). Therefore L(N) ⊆ L(M).
We finish the proof by showing that L(M) ⊆ L(N). Let w = a1 a2 … an ∈ L(M). Then there is a path in N:
S0 → a1 S1 → a2 S2 → ··· → an Sn ∈ T’.
By definition of T’, there exists some sn ∈ Sn ∩ T. Hence there exists some sn-1 ∈ Sn-1 such that sn-1 → an Sn is a transition in N.
Continuing in this fashion, we eventually conclude that s0 ∈ S0 = {s0} and there exists a transition s0 → a1 s1 in
N.
Therefore we can conclude that in N there is the path:
s0 → a1 si1 → ··· → an sin ∈ T and so w ∈ L(N).
How do you convert from a regular expression to an NFA?
- To start, draw a diagram with two states – a start state s and an accept state t, with an arrow from s to t labelled with the whole regular expression. This diagram is not, in general, an NFA, but we will make it into one.
- We slowly break down the labels on the arrows until each label is either a single
letter or Ɛ. To break down an arrow labelled R1 R2, introduce 2 new arrows, R1 and R2, with the same start and end nodes. - To break down an arrow labelled R1R2, introduce a new intermediate state, s’, connected to from the first node with R1 and to the second node with R2.
- To simplify an arrow labelled R*1 introduce a new state s’ with two epsilon connections from the first node and s’ and s’ to the second node, and with R1 being a connection from s’ to itself.
Continue until each arrow is labelled by a single letter (or Ɛ). The resulting diagram will be of an NFA. It can then be turned into a DFA, if necessary, using the NFA to DFA conversion method.
What is a regular expression?
A sequence of letters in a given pattern used to define a language in a compact manner.