MCS-212 · Block 2 Unit 2

Automata and Languages

Section 4 of 8

Block 2 · Unit 2Automata and Languages12 min · Section 4 of 8

2.4Algebra of regular expressions and regular languages

Covers IGNOU MCS-212 §2.2.4, 2.3, Theorems 2–4, Example 15, Ex.5

Different regular expressions can describe the same language: a∗aa^*a and aa∗aa^* both mean “one or more aa‘s”. Laws of regular expressions let us simplify them and prove that two expressions are equivalent — useful when optimising a search pattern or a lexer.

Correct identities

For regular expressions R,S,TR, S, T:

No.IdentityName / idea
1(R+S)+T=R+(S+T)(R + S) + T = R + (S + T),   R+S=S+R\;R + S = S + R,   R+R=R\;R + R = Runion is associative, commutative, idempotent
2R+∅=RR + \emptyset = R,   R∅=∅R=∅\;R\emptyset = \emptyset R = \emptyset∅\emptyset is the “zero”
3Rλ=λR=RR\lambda = \lambda R = Rλ\lambda is the “one”
4(RS)T=R(ST)(RS)T = R(ST)concatenation is associative
5R(S+T)=RS+RTR(S + T) = RS + RT,   (S+T)R=SR+TR\;(S + T)R = SR + TRdistributive laws
6∅∗=λ∗=λ\emptyset^* = \lambda^* = \lambda
7R∗R∗=R∗=(R∗)∗R^*R^* = R^* = (R^*)^*
8RR∗=R∗R=R+RR^* = R^*R = R^+ and R∗=λ+RR∗R^* = \lambda + RR^*star unfolds
9(R+S)∗=(R∗+S∗)∗=(R∗S∗)∗=(R∗S)∗R∗=R∗(SR∗)∗(R + S)^* = (R^* + S^*)^* = (R^*S^*)^* = (R^*S)^*R^* = R^*(SR^*)^*star of a union

Each law is proved by comparing languages. For example, L(R(S+T))=L(R) (L(S)∪L(T))=L(R)L(S)∪L(R)L(T)=L(RS+RT)L(R(S + T)) = L(R)\,(L(S) \cup L(T)) = L(R)L(S) \cup L(R)L(T) = L(RS + RT).

Regular languages

Proof. If L={w1,…,wn}L = \{w_1, \dots, w_n\}, the regular expression w1+w2+⋯+wnw_1 + w_2 + \dots + w_n describes it (and ∅\emptyset describes the empty language). ■\blacksquare For example, {aa,ab,ba,bb}\{aa, ab, ba, bb\} is described by aa+ab+ba+bbaa + ab + ba + bb and also by (a+b)(a+b)(a + b)(a + b): one regular language can have many regular expressions.

Not every language is regular. {anbn∣n≥0}\{a^nb^n \mid n \geq 0\} and “strings with twice as many aa‘s as bb‘s” are not regular: describing them needs unlimited counting, which neither regular expressions nor finite automata can do.

Key takeaways

  • r=sr = s means L(r)=L(s)L(r) = L(s).
  • RR∗=R∗R=R+RR^* = R^*R = R^+ and R∗=λ+RR∗R^* = \lambda + RR^*.
  • (R+S)∗=R∗(SR∗)∗=(R∗S∗)∗(R + S)^* = R^*(SR^*)^* = (R^*S^*)^*, but (R+S)∗≠R∗S∗(R + S)^* \neq R^*S^*.
  • Regular language = described by a regular expression; all finite languages are regular, but some languages (like anbna^nb^n) are not.

Practice questions

Answer on paper first, then check. The explanation matters more than the letter you chose.

Question 1 · multiple choice

Which identity is correct?

Show answer

Answer: C. a∗=λ+aa∗a^* = \lambda + aa^*

a∗a^* is “zero aa‘s” (λ\lambda) or “one or more aa‘s” (aa∗aa^*). Option 1 is tempting, but λ∈L(a∗)\lambda \in L(a^*) while λ∉L(aa∗)\lambda \notin L(aa^*).

Question 2 · multiple choice

What is R∅R\emptyset for any regular expression RR?

Show answer

Answer: A. ∅\emptyset

There is no string in ∅\emptyset to concatenate with, so the product is empty. Option 2 is the rule for RλR\lambda.

Question 3 · multiple choice

Which string shows that (a+b)∗≠a∗b∗(a + b)^* \neq a^*b^*?

Show answer

Answer: D. baba

baba is in (a+b)∗(a + b)^* but not in a∗b∗a^*b^* (an aa after a bb). The other strings are in both languages.

Question 4 · multiple choice

Why is every finite language regular?

Show answer

Answer: B. Because the union of its words, w1+⋯+wnw_1 + \dots + w_n, is a regular expression for it

Each word is a regular expression (a concatenation of symbols), and a finite union of them is too. Option 3 is false: {anbn}\{a^nb^n\} is not regular.

Question 5 · multiple choice

Which law gives b∗((ab)b∗)∗=(b+ab)∗b^*((ab)b^*)^* = (b + ab)^*?

Show answer

Answer: D. R∗(SR∗)∗=(R+S)∗R^*(SR^*)^* = (R + S)^*

With R=bR = b, S=abS = ab the left side has exactly this form. Option 1 (associativity) only regroups concatenations.

Question 6 · short answer

Prove R+R=RR + R = R and R(S+T)=RS+RTR(S + T) = RS + RT for regular expressions.

Show worked answer

L(R+R)=L(R)∪L(R)=L(R)L(R + R) = L(R) \cup L(R) = L(R) (a set united with itself is unchanged), so R+R=RR + R = R. L(R(S+T))=L(R) L(S+T)=L(R) (L(S)∪L(T))L(R(S + T)) = L(R)\,L(S + T) = L(R)\,(L(S) \cup L(T)). A string xyxy with x∈L(R)x \in L(R) and y∈L(S)∪L(T)y \in L(S) \cup L(T) is in L(R)L(S)L(R)L(S) or in L(R)L(T)L(R)L(T), and conversely; so this equals L(R)L(S)∪L(R)L(T)=L(RS+RT)L(R)L(S) \cup L(R)L(T) = L(RS + RT). Hence R(S+T)=RS+RTR(S + T) = RS + RT.

↑ ↓ move↵ openTab switch type