csc 361preliminaries1 language: set of strings. csc 361preliminaries2 specification and recognition...

25
CSC 361 Preliminaries 1 Preliminaries Language: Set of Strings

Upload: benjamin-french

Post on 14-Jan-2016

216 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: CSC 361Preliminaries1 Language: Set of Strings. CSC 361Preliminaries2 Specification and recognition of languages Sets Operations Defining sets (inductively)

CSC 361 Preliminaries 1

Preliminaries

Language: Set of Strings

Page 2: CSC 361Preliminaries1 Language: Set of Strings. CSC 361Preliminaries2 Specification and recognition of languages Sets Operations Defining sets (inductively)

CSC 361 Preliminaries 2

Specification and recognition of languages

Sets Operations Defining sets (inductively) Proving properties about sets (using induction) Defining functions on sets (using recursion) Proving properties about functions (using

induction)

Strings Operations

Languages : set of strings Operations

Page 3: CSC 361Preliminaries1 Language: Set of Strings. CSC 361Preliminaries2 Specification and recognition of languages Sets Operations Defining sets (inductively)

CSC 361 Preliminaries 3

Representation of Sets

Set: collection of objects Finite : can use enumeration

E.g., {a,b,c} Infinite : requires describing an

infinite characteristic of members using finite terms

E.g., { n N | even(n) /\ square(n) }

Page 4: CSC 361Preliminaries1 Language: Set of Strings. CSC 361Preliminaries2 Specification and recognition of languages Sets Operations Defining sets (inductively)

CSC 361 Preliminaries 4

Sets: Examples• Sets are denoted by { <collection of elements> }

•Examples:

{}{a,b}{{}}{1, 2, …, 100}

{0, 1, 2, …}

{0,2,4, …}{2n | n }

“the empty set”“the set consisting of the elements a and b”“the set consisting of the empty set”“the set consisting of the first 100 natural numbers”

“the set of all natural pair numbers”“the set of all natural pair numbers”

“the set consisting of all natural numbers”

Page 5: CSC 361Preliminaries1 Language: Set of Strings. CSC 361Preliminaries2 Specification and recognition of languages Sets Operations Defining sets (inductively)

CSC 361 Preliminaries 5

Operations on Sets

Set Inclusion and Set EqualityDefinition: •Given 2 sets, A and B, A is contained in B, denoted by A B, if every element in A is also an element in B

True or false:{e,i,t,c} {a, b, …, z}

for any set A, A A

for any set A, A {A}

true

true

false

Definition: •Given 2 sets A and B, A is equal to B, denoted by A = B, if A B and B A

Page 6: CSC 361Preliminaries1 Language: Set of Strings. CSC 361Preliminaries2 Specification and recognition of languages Sets Operations Defining sets (inductively)

CSC 361 Preliminaries 6

Review: Member Union Intersection Subset Powerset Cartesian product

Operations on Sets

BA x

},...}{,{

,

a

Page 7: CSC 361Preliminaries1 Language: Set of Strings. CSC 361Preliminaries2 Specification and recognition of languages Sets Operations Defining sets (inductively)

CSC 361 Preliminaries 7

Set Difference

DeMorgan’s Laws

Operations on Sets

X Y Y X

Y} z X { z | z Y X

YXYX

YXYX

Page 8: CSC 361Preliminaries1 Language: Set of Strings. CSC 361Preliminaries2 Specification and recognition of languages Sets Operations Defining sets (inductively)

CSC 361 Preliminaries 8

Operations on Sets

Cartesian Product• Definition: Given two sets, A and B, the Cartesian product of A and

B, denoted by A B, is the following set:

{(a,b) | a A and b B}

Examples:

•What is: {1, 2 , 3} {a,b} =•True or false: {(1,a), (3,b)} {1, 2 , 3} {a,b} •True or false: {1,2,3} {1, 2 , 3} {a,b}

truefalse

pair or 2-tuple

{(1,a), (1,b), (2,a), (2,b), (3,a), (3,b)}

Page 9: CSC 361Preliminaries1 Language: Set of Strings. CSC 361Preliminaries2 Specification and recognition of languages Sets Operations Defining sets (inductively)

CSC 361 Preliminaries 9

Operations on SetsCartesian Product of More Than 2 SetsDefinition: Given three sets, A, B and C, the Cartesian product of A, B, and C denoted by A B C, is the following set: {(a,b,c) | a A, b B, c C}

Definition. (x,y,z) = (x’,y’, z’) only if x = x’, y = y’ and z = z’

These definitions can be extended to define the Cartesian product: A1 A2 … An

and equality between n-tuples

Triple or 3-tuple

Page 10: CSC 361Preliminaries1 Language: Set of Strings. CSC 361Preliminaries2 Specification and recognition of languages Sets Operations Defining sets (inductively)

CSC 361 Preliminaries 10

Operations on Sets

• Some Cartesian product problems to try out:

• What is: {1, 2 , 3} {a,b} {,} =

• What is the form of the set A B C D

• What is the form of the set A B (C D)

• What is the form of the set (A B ) (C D)

Page 11: CSC 361Preliminaries1 Language: Set of Strings. CSC 361Preliminaries2 Specification and recognition of languages Sets Operations Defining sets (inductively)

CSC 361 Preliminaries 11

Partition of a Set X The set of subsets of X is a partitionpartition of X

iff(1) “covers all subsets”

(2) “pair-wise disjoint”

Collectively Exhaustive / Mutually Exclusive

},...,,{ 21 nXXX

XXXX n ...21

)()( ji XXji

Page 12: CSC 361Preliminaries1 Language: Set of Strings. CSC 361Preliminaries2 Specification and recognition of languages Sets Operations Defining sets (inductively)

CSC 361 Preliminaries 12

Examples Set of Natural numbers is

partitioned by “mod 5” relation into five “equivalence classes”:{ {0,5,10,…}, {1,6,11,…}, {2,7,12,…},

{3,8,13,…}, {4,9,14,…} } “String length” can be used to

partition the set of all bit strings.{ {},{0,1},{00,01,10,11},{000,

…,111},… }

Page 13: CSC 361Preliminaries1 Language: Set of Strings. CSC 361Preliminaries2 Specification and recognition of languages Sets Operations Defining sets (inductively)

CSC 361 Preliminaries 13

RelationsDefinition: Given two sets, A and B, A relation R is any subset of A B. In other words, R A B

• Relations are used to describe how elements of different sets interactQuestion: What does the relation A B indicate?

Examples of relations

Simple:•{(c,s) | c is a class at KU, s is a student at KU, AND s is in C }

Page 14: CSC 361Preliminaries1 Language: Set of Strings. CSC 361Preliminaries2 Specification and recognition of languages Sets Operations Defining sets (inductively)

CSC 361 Preliminaries 14

Relations

Example: Let I be the set of all classroom instructors at Kutztown Let S be the set of all students at Kutztown Then, we can define the relation Students of an Instructor,

over I x S, as follows:Students of an Instructor=

{(i,s) | i I, s S, s is in a course of instructor i}Questions:1. Does this relation represent an equivalence relation?2. Suppose this instructor teaches courses c1, c2, and c3.

Would the sets Students in instructor i’s course, for courses c1, c2, and c3, be disjoint?

Page 15: CSC 361Preliminaries1 Language: Set of Strings. CSC 361Preliminaries2 Specification and recognition of languages Sets Operations Defining sets (inductively)

CSC 361 Preliminaries 15

Equivalence RelationsA relation R is an equivalence relation if R is reflexive, symmetric, and transitive

Relation R is:• reflexive if (a,a) R for each a in the language• symmetric if when (a,b) R then (b,a) R • transitive if (a,b) R and (b,c) R, then (a,c) R

Equivalence relations are generalizations of the equality relation

{(1,2),(1,3),…, (2,3),(2,4),…}

{(a,b) | a and b are males between 35 and 40 years old}

“the relation x < y”x

Page 16: CSC 361Preliminaries1 Language: Set of Strings. CSC 361Preliminaries2 Specification and recognition of languages Sets Operations Defining sets (inductively)

CSC 361 Preliminaries 16

FunctionsDefinition: A function f from a set A to a set B, denoted by f: A B , is rule of correspondence between A and B such that there is a unique element in B assigned to each element in A i.e. for each a A there is one and only one b B such that (a,b) f

Note: •A is the domain of f•B is the range of f

{(c,s) | c is a class at KU, s is a student at KU, AND s is in C }

Question: Is the following relation also a function from the set of KU classes to the set of KU students?

Page 17: CSC 361Preliminaries1 Language: Set of Strings. CSC 361Preliminaries2 Specification and recognition of languages Sets Operations Defining sets (inductively)

CSC 361 Preliminaries 17

Functions

Kinds of Functions Total

All domain elements map to an element in the range

One to one (injection) Total, and each mapping from domain to

range is unique Onto (surjection)

All elements of the range are mapped to from a domain element

1-1 & Onto (bijection)

Page 18: CSC 361Preliminaries1 Language: Set of Strings. CSC 361Preliminaries2 Specification and recognition of languages Sets Operations Defining sets (inductively)

CSC 361 Preliminaries 18

(Total) Function

BAf :

A B

f

Domain Co-domain ( Range)

Page 19: CSC 361Preliminaries1 Language: Set of Strings. CSC 361Preliminaries2 Specification and recognition of languages Sets Operations Defining sets (inductively)

CSC 361 Preliminaries 19

One to One Function (injection)

BAf :

A B

f

Domain Co-domain ( Range)

Page 20: CSC 361Preliminaries1 Language: Set of Strings. CSC 361Preliminaries2 Specification and recognition of languages Sets Operations Defining sets (inductively)

CSC 361 Preliminaries 20

Onto Function (surjection)

BAf :

A B

f

Domain Co-domain ( Range)

Page 21: CSC 361Preliminaries1 Language: Set of Strings. CSC 361Preliminaries2 Specification and recognition of languages Sets Operations Defining sets (inductively)

CSC 361 Preliminaries 21

1-1 Onto Function (bijection)

BAf :

A B

f

Domain Co-domain ( Range)

Page 22: CSC 361Preliminaries1 Language: Set of Strings. CSC 361Preliminaries2 Specification and recognition of languages Sets Operations Defining sets (inductively)

CSC 361 Preliminaries 22

Inductive Definitions Constructive Example

Set of natural numbers N = {0,1,2,3,…}

Finite representation in terms of Seed element: zero Closure Operation: successor function {0,s(0),s(s(0)),s(s(s(0))),…}

Imposes additional structure on the domain.

Page 23: CSC 361Preliminaries1 Language: Set of Strings. CSC 361Preliminaries2 Specification and recognition of languages Sets Operations Defining sets (inductively)

CSC 361 Preliminaries 23

Basis case: Recursive step:

Closure: only if it can be obtained from 0 by a finite number of applications of the operation s.

(* Minimality condition to uniquely determine N *)

0

)(nsn

n

Page 24: CSC 361Preliminaries1 Language: Set of Strings. CSC 361Preliminaries2 Specification and recognition of languages Sets Operations Defining sets (inductively)

CSC 361 Preliminaries 24

Languages

A language can be specified as a set of strings.

Languages are classified by how they can be formed Regular languages are the most

constrained Others

Context-free Context-sensitive Recursively enumerable

Page 25: CSC 361Preliminaries1 Language: Set of Strings. CSC 361Preliminaries2 Specification and recognition of languages Sets Operations Defining sets (inductively)

CSC 361 Preliminaries 25

Language Semantics - Syntax

Regular sets/languages Generator

Regular Expressions, Regular Grammars Recognizer

Finite State Automata Context-free languages

Generator Context-free Grammar

Recognizer Push-down Automata