Algebraic Laws for Regular Epxressions
Transcript of Algebraic Laws for Regular Epxressions
![Page 1: Algebraic Laws for Regular Epxressions](https://reader038.fdocuments.net/reader038/viewer/2022102823/546f4721b4af9f0a088b45ba/html5/thumbnails/1.jpg)
ALGEBRAIC LAWS FOR REGULAR EXPRESSIONS
Amit Kumar R and Avik Dhupar
III-A-CSEF A F L
![Page 2: Algebraic Laws for Regular Epxressions](https://reader038.fdocuments.net/reader038/viewer/2022102823/546f4721b4af9f0a088b45ba/html5/thumbnails/2.jpg)
April 8, 2023
2
Overview
What is a regular expression? Laws
Associative Commutative Distributive Idempotent Laws involving closures
Identities & Annihilators
![Page 3: Algebraic Laws for Regular Epxressions](https://reader038.fdocuments.net/reader038/viewer/2022102823/546f4721b4af9f0a088b45ba/html5/thumbnails/3.jpg)
April 8, 2023
3
Regular Expressions
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
![Page 4: Algebraic Laws for Regular Epxressions](https://reader038.fdocuments.net/reader038/viewer/2022102823/546f4721b4af9f0a088b45ba/html5/thumbnails/4.jpg)
April 8, 2023
4
Associative Law
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)
![Page 5: Algebraic Laws for Regular Epxressions](https://reader038.fdocuments.net/reader038/viewer/2022102823/546f4721b4af9f0a088b45ba/html5/thumbnails/5.jpg)
April 8, 2023
5
Commutative Law
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
![Page 6: Algebraic Laws for Regular Epxressions](https://reader038.fdocuments.net/reader038/viewer/2022102823/546f4721b4af9f0a088b45ba/html5/thumbnails/6.jpg)
April 8, 2023
6
Distributive Law
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 concatenation over union, which states that L(M+N)=LM+LN
Right distributive law of concatenation over union which states that (M+N)L=ML+NL
![Page 7: Algebraic Laws for Regular Epxressions](https://reader038.fdocuments.net/reader038/viewer/2022102823/546f4721b4af9f0a088b45ba/html5/thumbnails/7.jpg)
April 8, 2023
7
Idempotent law
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 ≠ XAlthough there are some cases for the values of X
when the equality holds true such as 0+0 = 0For an RE, the idempotent law for union is L+L=L
which means if we take two identical copies of an expression, we can replace them by only one copy of the expression
![Page 8: Algebraic Laws for Regular Epxressions](https://reader038.fdocuments.net/reader038/viewer/2022102823/546f4721b4af9f0a088b45ba/html5/thumbnails/8.jpg)
April 8, 2023
8
Laws Involving Closure
(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 as L+ LL + LLL … and L* is defined as + L+ LL+ LLL… by which the above expression holds true
![Page 9: Algebraic Laws for Regular Epxressions](https://reader038.fdocuments.net/reader038/viewer/2022102823/546f4721b4af9f0a088b45ba/html5/thumbnails/9.jpg)
April 8, 2023
9
Identities and Annihilators
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 value ‘v’ such that when the operator is applied to ‘v’ and ‘x’, the output is the annihilator (v) - e.g. is the annihilator for concatenation, L = L =
![Page 10: Algebraic Laws for Regular Epxressions](https://reader038.fdocuments.net/reader038/viewer/2022102823/546f4721b4af9f0a088b45ba/html5/thumbnails/10.jpg)
April 8, 2023
10
Checking a Law
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 equivalent2. We can use the “concretization” test: Think of R and S as if they were single symbols, i.e., R = {0} and S = {1} Test whether the law holds under the concrete symbols.If so, then this is a true law, and if not then the law is
false.
![Page 11: Algebraic Laws for Regular Epxressions](https://reader038.fdocuments.net/reader038/viewer/2022102823/546f4721b4af9f0a088b45ba/html5/thumbnails/11.jpg)
April 8, 2023
11
Concretization Test
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 anystring of 0‘s and 1‘s since 0 and 1 are each
in L(0*1*).
![Page 12: Algebraic Laws for Regular Epxressions](https://reader038.fdocuments.net/reader038/viewer/2022102823/546f4721b4af9f0a088b45ba/html5/thumbnails/12.jpg)
April 8, 2023
12
Concretization Test
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.The test would say this law is true for RE operators,
but not for other operators like intersection, but this is because we are applying the test beyond regular expressions.
![Page 13: Algebraic Laws for Regular Epxressions](https://reader038.fdocuments.net/reader038/viewer/2022102823/546f4721b4af9f0a088b45ba/html5/thumbnails/13.jpg)
April 8, 2023
13
Conclusion
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.
![Page 14: Algebraic Laws for Regular Epxressions](https://reader038.fdocuments.net/reader038/viewer/2022102823/546f4721b4af9f0a088b45ba/html5/thumbnails/14.jpg)
April 8, 2023
14
Questions and Discussion