Sei sulla pagina 1di 14

Algebraic Laws for regular

expressions
FAFL Amit Kumar R and Avik Dhupar
Overview
22

What is a regular expression?


Laws
Associative
Commutative
Distributive
Idempotent
Laws involving closures
Identities & Annihilators
7/31/11
Regular Expressions
33

Regular expressions can be seen as a


system of notations for denoting  -NFA

They form an “algebraic” representation of


-NFA

Very convenient for representing pattern


in documents

7/31/11
Associative Law
44

It is the property of an operator that allows


us to regroup the operands when operator
is applied twice.
An example for arithmetic associative law
is
(X+Y)+Z = X+(Y+Z)
Similarly, for an RE, the associative law for
union is (L+M)+N=L+(M+N)
The associative law for concatenation
states that (LM)N=L(MN) 7/31/11
Commutative Law
55
It is the property of an operator that allows us to
switch the order of its operand and get the same
result.
An example for arithmetic commutative law is
X+Y=Y+X
Similarly, for an RE, the commutative law for
union is L+M=M+L
But, the commutative law for concatenation does
not hold good, i.e., LM≠ML

7/31/11
Distributive Law
66

It involves two operators and asserts that


one operator can be pushed down to be
applied to each argument of other
operator individually.
An example for arithmetic distributive law
is
X*(Y+Z) = X*Y+X*Z
In the case of RE, the distributive law is
stated in two forms, that are, Left
Distributive law of concatenation7/31/11
over
union, which states that L(M+N)=LM+LN
Idempotent law
77

An operator is said to be idempotent if the


result of applying it to two of the same
values as arguments is that value itself.
This law is not analogous to arithmetic
laws.
As an example, X+X ≠ X or, X*X ≠ X
Although there are some cases for the
values of X when the equality holds true
such as 0+0 = 0
For an RE, the idempotent law for union
7/31/11 is
L+L=L which means if we take two
Laws Involving Closure
88

(L*)*=L* : This law states that closing an


expression that is already closed doesn’t
change the language
* =  : The closure of  contains only
the string 
* =  : The only string that can be
formed by concatenating any number of
copies of the empty string is the empty
string itself
L*= L+ +  : Here, L+ is defined as7/31/11
L+ LL
+ LLL … and L* is defined as  + L+ LL+
Identities and Annihilators
99

The identity for an operator is some value


‘v’ such that when the operator is applied
to ‘v’ and to some other value ‘x’ the
result is ‘x’
The empty language  is the identity
for union, i.e.
+L=L+=L
 is the identity for concatenation :  
L = L = L
The annihilator for an operator is some
7/31/11
Checking a Law
10
10
Suppose we are told that the law (R + S)*
= (R*S*)* holds for regular expressions.
How would we check that this claim is
true?
1. Convert the RE’s to DFA’s and minimize
the DFA’s to see
if they are equivalent
2. We can use the “concretization” test:
q Think of R and S as if they were single
symbols, i.e., 7/31/11
Concretization Test
11
11
For our example
(R + S)* = (R*S*)*
We can substitute 0 for R and 1 for S.
The left side is clearly any sequence of 0‘s.
and 1‘s. The right side also denotes any
string of 0‘s and 1‘s since 0 and 1 are
each in L(0*1*).

7/31/11
Concretization Test
12
12
NOTE: Extensions of the test beyond
regular expressions
may fail.
Consider the “law” L ∩ M ∩ N = L ∩ M.
This is clearly false.
Let L = M = {a} and N = . {a} ≠ .
But if L = {a} and M = {b} and N = {c}
then L∩M does equal L ∩ M ∩ N which is
empty. 7/31/11
Conclusion
13
13
We can now say that regular expressions are very
useful for representing certain sets of strings in
an algebraic fashion. Actually these describe the
languages accepted by finite state automata. And
the operations used in the expressions are the
only tools for doing that without which it is not
possible.
The Algebraic Laws apply to these expressions
and help us in simplifying a complicated regular
expression.

7/31/11
Questions and Discussion
14
14

7/31/11

Potrebbero piacerti anche