Professional Documents
Culture Documents
LECTURE A 5.regular Languages Expressions
LECTURE A 5.regular Languages Expressions
=
n
n
Example. To create 2/3 take p=3, then take p+q=2
thus p=-1 which is negative integer, OK
Interest in Recursive Definitions
Recursive definition allow us to prove some
Statements About What Is Computable.
Recursive definition leads to Proof by
Induction
Principle of Mathematical
Induction*
Let A Be a Subset of the Natural Numbers
0 e A, and
for each natural number, n,
if { 0, 1, ..., n } e A ,
implies (n + 1) e A
then A = N
* Lewis & Papadimitriou, pg. 24
Mathematical Induction
In practice, mathematical induction is used
to prove assertions of the form
For all natural numbers, n,
property P is true
Mathematical Induction Practice
To prove statements of the form
A = { n : P is true of n }, three steps
1. Basis Step: show that 0 e A,
i.e., P is true of n = 0
2. Induction Hypothesis: assume that for some
arbitrary, but fixed n > 0, P holds for each
natural number 0, 1, ... , n
Mathematical Induction Practice
3. Induction Step: use the induction hypothesis
(that P is true of n) to show that P is true of (n
+ 1)
By the Induction Principle, Then A=N and
Hence, P Is True of Every Natural Number.
Induction Example*
* Lewis & Papadimitriou, pg. 25
1. Basis Step
Show that for any n
n
n n
>
+ + + =
+
|
\
|
.
|
0
1 2
2
2
,
0
0 0
2
0 0
0
2
=
+
|
\
|
.
|
=
= true for n
Induction Example
2. Induction Hypothesis
Assume that for some
when
n
m
m m
m n
>
+ + + =
+
|
\
|
.
|
s
0
1 2
2
2
,
We just assume
that the rule is
true for certain
m smaller than
n
Induction Example
3. Induction Step
( ) ( )
( )
1 2 1 1 2 1
1 2
2
2
1
2 2
2
2
2
2
+ + + + = + + + +
+ +
+
|
\
|
.
|
=
+
|
\
|
.
| + +
=
+ + +
n n n n
n
n n
n n
n
n n n
where is replaced by from the
induction hypothesis
Induction Example
( )
( )
( ) ( )
=
+ + + +
=
+ + +
= +
n n n
n n
n n
2
2
2 1 1
2
1 1
2
0 1
which shows that the hypothesis is true since if it was true
for then it must be true for any ,
Another Induction Example
Define set EVEN as
1. 0 is in EVEN
2. if x e EVEN then so is x + 2
3. The only elements of EVEN are those
produced by 1 & 2 above.
Prove by induction that all of elements of
EVEN end in either 0, 2, 4, 6, or 8.
Induction Example (cont)
Proof
1. Basis Step
0 e EVEN by definition, therefore the property is
true of the zeroth step since 0 e { 0, 2, 4, 6, 8
}
2. Induction Hypothesis
Assume that the last digit of
(m+2) e { 0, 2, 4, 6, 8 } for 0 < m < n
Induction Example
3. Induction Step
n e EVEN n e EVEN
0 2 ...
1 4 n 2n + 2
2 6 n+1 (2n+2)+2
3 8 n+1 2(n+1) +2
4 10
ends in {0,2,4,6,8}
by step 2
0+2=2, 2+2=4,4+2=6
6+2=8, 8+2=0 e {0,2,4,6,8}
Prove by induction that all of elements of EVEN end in
either 0, 2, 4, 6, or 8.
2n+2
Thus if for n it ends wih 0,2,4,6,8 then for
n+1 it also ends with 0,2,4,6,8
Regular Expressions
Shorthand Notation for Concisely
Expressing Languages
Defined Recursively
Lead to a Definition of Regular Languages
Provide Finite Representation of Possibly
Infinite Languages
Lead to Lexical Analyzers
Regular Expressions Notation
{ }
{ }
{ }
{ }
Language
with operator precedence being
highest lowest
or +
Kleene Star Concatenation Set Union
a a
a b a b
a a
a a
-
+
+
,
* *
*
Regular Expressions Over I
u and A are regular expressions
a is a regular expression for each a e I
If r and s are regular expressions, then so
are r s, r - s, and r*
No other sequences of symbols are regular
expressions
Regular Expressions Alternative
1. L( A ) = {A }
L( a ) = { a }
If p and q are regular expressions, then
2. L( pq ) = L( p ) L( q )
3. L( p q ) = L( p ) L( q )
4. L( p* ) = L( p )*
Regular expressions
Regular Expressions Example
What is L
3
( ( a b )* a ) ?
( ) ( ) ( ) ( )
( ) ( ){ } ( )
( ) { } ( )
( ) ( ) ( ) { } ( )
{ } { } ( ) { } ( )
{ } { } ( )
{ } { }
L L L
L
L
L L
3
=
=
=
=
=
=
= e
a b a
a b a
a b a
a b a
a b a
a b a
w a b w a
*
*
*
*
*
, *
, *:
2
1
4
3
1, 1
definition
ends with
Observe that we do everything by completely formal transformations
between expressions representing languages and sets (languages)
Regular Expressions
Boolean OR Distributes over Concatenation
which is the language of all strings beginning
with a, ending with b, and having none or more
cs in the middle, and,
all strings beginning and ending with b and
having at least one c in the middle
( ) ( )
( )
L
L
= +
= +
language
language
a bc c b
ac b bcc b
*
* *
Regular Expressions
The Boolean OR Operator Can Distribute
When It Is Inside a Kleene Starred
Expression, but Only in Certain Ways
( ) ( )
( )( )( )
( )
( )
L = +
= + + +
= +
= +
language a bc b
a bc a bc a bc b
a b bc b
ab bcb
*
* *
*