summary of topics
play

Summary of topics Sets COMP2111 Week 2 Formal languages Term 1, - PowerPoint PPT Presentation

Summary of topics Sets COMP2111 Week 2 Formal languages Term 1, 2020 Discrete Mathematics Recap Relations Functions Propositional Logic 1 2 Summary of topics Sets A set is defined by the collection of its elements. Sets are typically


  1. Summary of topics Sets COMP2111 Week 2 Formal languages Term 1, 2020 Discrete Mathematics Recap Relations Functions Propositional Logic 1 2 Summary of topics Sets A set is defined by the collection of its elements. Sets are typically described by: (a) Explicit enumeration of their elements Sets S 1 = { a , b , c } = { a , a , b , b , b , c } Formal languages = { b , c , a } = . . . three elements Relations S 2 = { a , { a }} two elements Functions S 3 = { a , b , { a , b }} three elements Propositional Logic S 4 = {} zero elements S 5 = {{{}}} one element S 6 = { {} , {{}} } two elements 3 4

  2. (c) Constructions from other sets (already defined) Union, intersection, set difference, symmetric difference, complement (b) Specifying the properties their elements must satisfy; the elements are taken from some ‘universal’ domain, U . A typical Power set Pow( X ) = { A : A ⊆ X } description involves a logical property P ( x ) Cartesian product (below) Empty set ∅ S = { x : x ∈ U and P ( x ) } = { x ∈ U : P ( x ) } ∅ ⊆ X for all sets X . We distinguish between an element and the set comprising this S ⊆ T — S is a subset of T ; includes the case of T ⊆ T single element. Thus always a � = { a } . S ⊂ T — a proper subset: S ⊆ T and S � = T Set {} is empty (no elements); NB set {{}} is nonempty — it has one element. An element of a set and a subset of that set are two different There is only one empty set; only one set consisting of a single a ; concepts only one set of all natural numbers. a ∈ { a , b } , a �⊆ { a , b } ; { a } ⊆ { a , b } , { a } / ∈ { a , b } 5 6 Cardinality Sets of Numbers Number of elements in a set X (various notations): | X | = #( X ) = card( X ) Natural numbers N = { 0 , 1 , 2 , . . . } Positive integers { 1 , 2 , . . . } Common notation N > 0 = Z > 0 = N \ { 0 } Fact Always | Pow ( X ) | = 2 | X | Integers Z = { . . . , − n , − ( n − 1) , . . . , − 1 , 0 , 1 , 2 , . . . } � m � Rational numbers (fractions) Q = n : m , n ∈ Z , n � = 0 |∅| = 0 Pow( ∅ ) = {∅} | Pow( ∅ ) | = 1 Real numbers (decimal or binary expansions) R Pow(Pow( ∅ )) = {∅ , {∅}} | Pow(Pow( ∅ )) | = 2 . . . r = a 1 a 2 . . . a k . b 1 b 2 . . . |{ a }| = 1 Pow( { a } ) = {∅ , { a }} | Pow( { a } ) | = 2 . . . [ m , n ] — interval of integers; it is empty if n < m | [ m , n ] | = n − m + 1, for n ≥ m 7 8

  3. Set Operations Intervals of numbers (applies to any type) [ a , b ] = { x | a ≤ x ≤ b } ; ( a , b ) = { x | a < x < b } Union A ∪ B ; Intersection A ∩ B [ a , b ] ⊇ [ a , b ) , ( a , b ] ⊇ ( a , b ) Note that there is a correspondence between set operations and logical operators (to be discussed later) NB We say that A , B are disjoint if A ∩ B = ∅ ( a , a ) = ( a , a ] = [ a , a ) = ∅ ; however [ a , a ] = { a } . NB Intervals of N , Z are finite: if m ≤ n A ∪ B = B if and only if A ⊆ B A ∩ B = B if and only if A ⊇ B [ m , n ] = { m , m + 1 , . . . , n } | [ m , n ] | = n − m + 1 9 10 Laws of Set Operations Other set operations A \ B — difference , set difference, relative complement Commutativity A ∪ B = B ∪ A It corresponds (logically) to a but not b A ∩ B = B ∩ A A ⊕ B — symmetric difference Associativity ( A ∪ B ) ∪ C = A ∪ ( B ∪ C ) ( A ∩ B ) ∩ C = A ∩ ( B ∩ C ) def A ⊕ B = ( A \ B ) ∪ ( B \ A ) Distribution A ∪ ( B ∩ C ) = ( A ∪ B ) ∩ ( A ∪ C ) A ∩ ( B ∪ C ) = ( A ∩ B ) ∪ ( A ∩ C ) It corresponds to a and not b or b and not a ; also known as Identity A ∪ ∅ = A xor ( exclusive or ) A ∩ U = A A c — set complement w.r.t. the ‘universe’ U A ∪ ( A c ) = U Complementation It corresponds to ‘not a ’ A ∩ ( A c ) = ∅ 11 12

  4. Other useful set laws Example (Idempotence of ∪ ) The following are all derivable from the previous 10 laws. A = A ∪ ∅ (Identity) Idempotence A ∩ A = A = A ∪ ( A ∩ A c ) (Complementation) A ∪ A = A ( A c ) c = A = ( A ∪ A ) ∩ ( A ∪ A c ) (Distributivity) Double complementation = ( A ∪ A ) ∩ U A ∩ ∅ = ∅ (Complementation) Annihilation = ( A ∪ A ) (Identity) A ∪ U = U ( A ∩ B ) c = A c ∪ B c de Morgan’s Laws ( A ∪ B ) c = A c ∩ B c 13 14 Example (Idempotence of ∪ ) Example (Idempotence of ∪ ) A = A ∪ ∅ (Identity) A = A ∪ ∅ (Identity) = A ∪ ( A ∩ A c ) = A ∪ ( A ∩ A c ) (Complementation) (Complementation) = ( A ∪ A ) ∩ ( A ∪ A c ) = ( A ∪ A ) ∩ ( A ∪ A c ) (Distributivity) (Distributivity) = ( A ∪ A ) ∩ U (Complementation) = ( A ∪ A ) ∩ U (Complementation) = ( A ∪ A ) (Identity) = ( A ∪ A ) (Identity) 15 16

  5. Example (Idempotence of ∪ ) Example (Idempotence of ∪ ) A = A ∪ ∅ (Identity) A = A ∪ ∅ (Identity) = A ∪ ( A ∩ A c ) = A ∪ ( A ∩ A c ) (Complementation) (Complementation) = ( A ∪ A ) ∩ ( A ∪ A c ) = ( A ∪ A ) ∩ ( A ∪ A c ) (Distributivity) (Distributivity) = ( A ∪ A ) ∩ U = ( A ∪ A ) ∩ U (Complementation) (Complementation) = ( A ∪ A ) (Identity) = ( A ∪ A ) (Identity) 17 18 A useful result Definition Application (Idempotence of ∩ ) If A is a set defined using ∩ , ∪ , ∅ and U , then dual( A ) is the expression obtained by replacing ∩ with ∪ (and vice-versa) and ∅ Recall Idempotence of ∪ : with U (and vice-versa). = A ∪ ∅ A (Identity) = A ∪ ( A ∩ A c ) (Complementation) Theorem (Principle of Duality) = ( A ∪ A ) ∩ ( A ∪ A c ) (Distributivity) If you can prove A 1 = A 2 using the Laws of Set Operations then = ( A ∪ A ) ∩ U (Complementation) you can prove dual ( A 1 ) = dual ( A 2 ) = ( A ∪ A ) (Identity) Example Absorption law: A ∪ ( A ∩ B ) = A Dual: A ∩ ( A ∪ B ) = A 19 20

  6. Cartesian Product Application (Idempotence of ∩ ) Invoke the dual laws! def S × T = { ( s , t ) : s ∈ S , t ∈ T } where ( s , t ) is an ordered pair A = A ∩ U (Identity) = A ∩ ( A ∪ A c ) × n (Complementation) def i =1 S i = { ( s 1 , . . . , s n ) : s k ∈ S k , for 1 ≤ k ≤ n } = ( A ∩ A ) ∪ ( A ∩ A c ) (Distributivity) = ( A ∩ A ) ∪ ∅ (Complementation) S 2 = S × S , S 3 = S × S × S , . . . , S n = × n 1 S , . . . = ( A ∩ A ) (Identity) ∅ × S = ∅ , for every S i =1 S i | = � n | × n | S × T | = | S | · | T | , i =1 | S i | 21 22 Summary of topics Formal Languages Σ — alphabet , a finite, nonempty set Examples (of various alphabets and their intended uses) Sets Σ = { a , b , . . . , z } for single words (in lower case) Formal languages Σ = { � , − , a , b , . . . , z } for composite terms Relations Σ = { 0 , 1 } for binary integers Functions Σ = { 0 , 1 , . . . , 9 } for decimal integers Propositional Logic The above cases all have a natural ordering; this is not required in general, thus the set of all Chinese characters forms a (formal) alphabet. 23 24

  7. Notation: Σ k — set of all words of length k Definition We often identify Σ 0 = { λ } , Σ 1 = Σ Σ ∗ — set of all words (of all [finite] lengths) word — any finite string of symbols from Σ empty word — λ (sometimes ǫ ) Σ + — set of all nonempty words (of any positive length) n Example Σ ∗ = Σ 0 ∪ Σ 1 ∪ Σ 2 ∪ . . . ; Σ ≤ n = � Σ i w = aba , w = 01101 . . . 1, etc. i =0 length( w ) — # of symbols in w Σ + = Σ 1 ∪ Σ 2 ∪ . . . = Σ ∗ \ { λ } length( aaa ) = 3 , length( λ ) = 0 The only operation on words (discussed here) is concatenation , A language is a subset of Σ ∗ . Typically, only the subsets that can written as juxtaposition vw , wvw , abw , wbv , . . . be formed (or described) according to certain rules are of interest. NB Such a collection of ‘descriptive/formative’ rules is called a λ w = w = w λ grammar . length( vw ) = length( v ) + length( w ) Examples : Programming languages, Database query languages 25 26 Example (HTML documents) Example (Decimal numbers) Take Σ = { “ < html > ”, “ < /html > ”, “ < head > ”, “ < /head > ”, The “language” of all numbers written in decimal to at most two “ < body > ”, . . . } . decimal places can be described as follows: The (language of) valid HTML documents is loosely described Σ = {− , ., 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 } as follows: Consider all words w ∈ Σ ∗ which satisfy the following: Starts with “ < html > ” w contains at most one instance of − , and if it contains an Next symbol is “ < head > ” instance then it is the first symbol. w contains at most one instance of . , and if it contains an Followed by zero or more symbols from the set of HeadItems instance then it is preceeded by a symbol in (defined elsewhere) { 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 } , and followed by either one or two Followed by “ < /head > ” symbols in that set. w contains at least one symbol from { 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 } Followed by “ < body > ” Followed by zero or more symbols from the set of BodyItems NB (defined elsewhere) According to these rules 123 , 123 . 0 and 123 . 00 are all (distinct) Followed by “ < /body > ” words in this language. Followed by “ < /html > ” 27 28

Recommend


More recommend