mathematical foundations - computer sciencerlc/courses/theory/classnotes/... · 2015. 8. 20. ·...

60
Mathematical Foundations Foundations of Computer Science Theory

Upload: others

Post on 05-Feb-2021

7 views

Category:

Documents


0 download

TRANSCRIPT

  • Mathematical Foundations

    Foundations of Computer Science Theory

  • Math Review

    • Sets • Relations • Functions • Closures • Proof techniques • Alphabets, Strings and Languages

  • Sets

    • S1 = {13, 11, 8, 23} • S2 = {8, 23, 11, 13} • S3 = {8, 8, 23, 23, 11, 11, 13, 13} • S4 = {apple, pear, banana, grape} • S5 = {January, February, March, April, May, June, July, August, September, October, November, December} • S6 = {x : x ∈ S5 and x has 31 days} • S7 = {January, March, May, July, August, October, December}

  • Sets

    • ℕ = the positive integers (also called the natural numbers)

    • ℤ = the integers ( … -3, -2, -1, 0, 1, 2, 3, …) • S8 = {i : ∃x ∈ ℕ (i = 2x)} • S9 = {2, 4, 6, 8, …} • S10 = the even natural numbers

  • Sets

    • S11 = the syntactically valid C programs • S12 = {x : x ∈ S11 and x never gets into an

    infinite loop} • S13 = {finite length strings of a’s and b’s} • S14 = { a, b, …, k } • S15 = { 2, 4, 6, … } • S16 = { j : j > 0, and j = 2k for some k > 0 } • S17 = { j : j is a positive integer and even }

    finite set infinite set

  • Programs Can Define Sets

    • We could write a program that enumerates the elements of some set S

    • Or we could write a program that decides S by implementing the characteristic function of S – Such a program returns True if run on some

    element that is in S and False if run on an element that is not in S

    – Example of a characteristic function: { j : j ≥ 0, and j = 2k for some k ≥ 0 }

    • If input j = 6 return true, if input j = 7 return false

  • Cardinality

    • The cardinality of a set S, denoted |S|, is how many elements it contains

    • The cardinality of every set we will consider in this course is either: – a natural number (if S is finite) – countably infinite (if S has the same number of

    elements as there are integers) – uncountably infinite (if S has more elements than

    there are integers)

  • Set Representations

    • ∅ = { } • S ∪ ∅ = S • S ∩ ∅ = ∅ • S - ∅ = S • ∅ - S = ∅ • ¬∅ = U (the Universal Set)

  • Power Set

    • A power set is a set of sets • For example, if S = {a, b, c}, then the power set

    of S is the set of all subsets of S, denoted 2S or P(S)

    • 2S = { ∅, {a}, {b}, {c}, {a,b}, {a,c}, {b,c}, {a,b,c} } • |2S| = 2|S| • For this example, |2S| = 23 = 8

  • Partition of a Set

    • Let S = {1, 2, 3} • Then Π ⊆ P(S) is a partition of a set S iff:

    • no element of Π is empty • all pairs of elements of Π are disjoint • the union of all the elements of Π equals S

    • Three example partitions of S: {{1}, {2, 3}} {{1, 3}, {2}} {{1, 2, 3}}

  • Set Representations Let U = {1, …, 10}

    Let S = { 1, 2, 3, 4, 5 }

    1 2 3 4 5

    S

    U

    6

    7 8

    9 10

  • Set Representations • Complement of a set:

    Let U = {1, …, 7}

    Let S = { 1, 2, 3 } , then ¬S = { 4, 5, 6, 7 }

    Note that ¬¬S = S

    ¬S 1

    2 3

    4

    5

    6

    7

    S

  • Set Operations

    A = { 1, 2, 3 } B = { 2, 3, 4, 5 } • Union

    • Intersection • Difference

    A ∪ B = { 1, 2, 3, 4, 5 }

    A ∩ B = { 2, 3 }

    A - B (or A\B) = { 1 } B - A (or B\A) = { 4, 5 }

    A B 2 3

    1 4

    5

    2 3

    1 4

    5

    2 3

    1 4

    5

  • Disjoint Sets and Set Cardinality

    A = { 1, 2, 3 } B = { 5, 6 } A and B are disjoint: A ∩ B = ∅ • Cardinality is defined for finite sets: A = { 2, 5, 7 } |A| = 3 (the size of the set)

    A B

    5 6 3

    2

    1

  • Cartesian Product

    • The Cartesian product of two sets A and B is the set of all ordered pairs (a, b) such that a ∈ A and b ∈ B

    • We write it as: A × B • If A and B are finite, the cardinality of their

    Cartesian product is |A × B| = |A|⋅|B|

  • Cartesian Product

    A = {2, 4} B = {2, 3, 5} A × B = { (2, 2), (2, 3), (2, 5), (4, 2), (4, 3), (4, 5) } |A × B| = |A|⋅|B| Can apply to more than two sets: A × B × C … × Z

  • Cartesian Product

    Let A be: {Dave, Sara, Billy} Let B be: {cake, pie, ice cream} A × B = { (Dave, cake), (Dave, pie), (Dave, ice cream), (Sara, cake), (Sara, pie), (Sara, ice cream), (Billy, cake), (Billy, pie), (Billy, ice cream) } B × A = { (cake, Dave), (cake, Sara), (cake, Billy), (pie, Dave), (pie, Sara), (pie, Billy), (ice cream, Dave), (ice cream, Sara), (ice cream, Billy) }

  • Relations

    • A relation R is a set of ordered elements (a sequence of two or more objects)

    • If the number of elements is two, then we write a R b or { (a1, b1), (a2, b2), (a3, b3), …}

    • Order matters in a relation, so unless a and b are equal, (a, b) is not the same as (b, a)

  • Relations

    • Relation R = { (a1, b1), (a2, b2), (a3, b3), …} • This is equivalent to: a R b • Example: Let R be the relation on the set of

    integers such that a R b iff a < b – Then R = { …, (1, 2), (2, 3), (3, 4), … }

    • Example: Let R be the relation on the set of integers such that a R b iff a = −b – Then R = { …, (1, -1), (2, -2), (3, -3), … }

  • Binary Relations

    • A binary relation over two sets A and B is a subset of the Cartesian product A × B

    – Example: Let R = Likes = { (Dave, cake), (Dave, ice cream), (Sara, pie), (Sara, ice cream)}

    • An n-ary relation over sets A1, A2, … An is a subset of A1 × A2 × … × An

  • Binary Relations

    • The inverse of a binary relation R, written R-1, is the set of ordered pairs in R with the elements of each pair reversed – Example: Likes -1 = { (cake, Dave), (ice cream,

    Dave), (pie, Sara), (ice cream, Sara)}

  • Composing Relations

    • The composition of R1 ⊆ A × B and R2 ⊆ B × C, written R2 ° R1 , is {(a, c) : ∃b ((a, b) ∈ R1 ∧ ((b, c) ∈ R2)}

    • Example: – Likes = {(Dave, cake), (Dave, ice cream), (Sara, pie),

    (Sara, ice cream)} – Fatgrams = {(cake, 30), (pie, 25), (ice cream, 15)} – Fatgrams ° Likes = {(Dave, 30), (Dave, 15), (Sara,

    25), (Sara, 15)}

  • • How can we represent a binary relation R? • We have several choices:

    – We could list the elements of R – We could write a procedure that defines R either by:

    • Enumerating it • Deciding it

    – We could encode R as an adjacency matrix – We could encode R as a directed graph

    Representing Relations

  • Doreen Ann Catherine Allison

    Doreen true

    Ann true

    Catherine true

    Allison

    Representing a Binary Relation as an Adjacency Matrix

    Consider the Mother-of relation in a family in which Doreen is the mother of Ann, Ann is the mother of Catherine, and Catherine is the mother of Allison. Mother-of = { (Doreen, Ann), (Ann, Catherine), (Catherine, Allison) }

  • Representing a Binary Relation as a Graph

    Mother-of = { (Doreen, Ann), (Ann, Catherine), (Catherine, Allison) }

  • Properties of Relations

    • R ⊆ A × A is reflexive iff, ∀x ∈ A ((x, x) ∈ R)

    • Examples of reflexive relations: • Address defined as “lives at same address as”

    • ≤ defined on the integers (for every integer x, x ≤ x)

  • • R ⊆ A × A is symmetric iff ∀x, y ((x, y) ∈ R → (y, x) ∈ R)

    • Examples of symmetric relations: • Address is symmetric • ≤ is not symmetric

    • A relation is anti-symmetric iff ∀x, y (((x, y)∈R ∧ x ≠ y) → (y, x) ∉ R

    Properties of Relations

    1 1

    1 1

    1

    1

  • • R ⊆ A × A is transitive iff ∀x, y, z (((x, y) ∈ R ∧ (y, z) ∈ R) → (x, z) ∈ R)

    • Examples of transitive relations: • Address is transitive • < is transitive • Mother-of is not transitive

    Properties of Relations

    1 1

    1

  • Equivalence Relations

    • A relation R ⊆ A × A is an equivalence relation iff it is:

    • reflexive

    • symmetric

    • transitive

    • Examples:

    • Equality

    • Address

    • Same-Length-As

  • Equivalence Relations

    • Question 1: Let R be a relation on the set of real numbers such that a R b if and only if a − b is an integer. Is R an equivalence relation?

  • Equivalence Relations

    • Question 1: Let R be a relation on the set of real numbers such that a R b if and only if a − b is an integer. Is R an equivalence relation?

    • Answer: Yes, because – R is reflexive: Since a − a = 0 is an integer for all real

    numbers a, so a R a is true – R is symmetric: Suppose that a R b, then a − b is an

    integer and b − a is also an integer, so b R a is true – R is transitive: If a R b and b R c, then a − b and b − c

    are also integers, therefore a − c = (a − b) + (b − c) is also an integer, so a R c is true

  • Equivalence Relations

    • Question 2: Is the “divides” relation on the set of positive integers an equivalence relation?

  • Equivalence Relations

    • Question 2: Is the “divides” relation on the set of positive integers an equivalence relation?

    • Answer: No. The “divides” relation is reflexive and transitive. However, “divides” is not symmetric (for example, 2|4 but 4|2). Thus, the “divides” relation on the set of positive integers is not an equivalence relation.

  • Equivalence Relations

    • Question 3: Let R be a relation on the set of real numbers such that x R y if and only if x and y are real numbers that differ by less than 1, that is |x−y|< 1. Is R is an equivalence relation?

  • Equivalence Relations

    • Question 3: Let R be a relation on the set of real numbers such that x R y if and only if x and y are real numbers that differ by less than 1, that is |x−y|< 1. Is R is an equivalence relation?

    • Answer: R is reflexive because |x − x| = 0 < 1. R is symmetric, |y − x| = |x − y| < 1. However, R is not an equivalence relation because it is not transitive. – For example, let x = 2.8, y = 1.9, and z = 1.1, so that |x − y|

    = |2.8 − 1.9| = 0.9 < 1, |y − z| = |1.9 − 1.1| = 0.8 < 1, but |x − z| = |2.8 − 1.1| = 1.7 > 1

  • Equivalence Classes

    • For an equivalence relation R, an equivalence class of a is {b: a R b}

    • For example, let R = { (1, f), (2, g), (1, h), (2, i), (3, j), (4, k), (3, l), (4, m) } – The equivalence class [1] = {f, h} – The equivalence class [2] = {g, i} – The equivalence class [3] = {j, l} – The equivalence class [4] = {k, m}

  • Equivalence Classes • An equivalence relation R on a set S carves S up into a

    set of clusters or islands, which we’ll call equivalence classes

    • This set of equivalence classes has the following key property:

    ∀a, b ∈ S ((a ∈ classi ∧ (a, b) ∈ R) → b ∈ classi) • If R is an equivalence relation on a nonempty set S,

    then the set of equivalence classes of R is a partition Π of S. Because Π is a partition: a) no element of Π is empty, b) all members of Π are disjoint, and c) the union of all the elements of Π equals S

  • Equivalence Classes

    • For example, the Address relation “carves up” a set of people into subsets of people who live together

    • Let S be the set of all strings of letters, and let Samelength ⊆ S x S relate strings whose lengths are the same – Samelength is an equivalence relation that carves

    up S, the universe of all strings, into a collection of subsets, one subset for each natural number (i.e., strings of length 0, strings of length 1, etc.)

  • Equivalence Classes

    • Let ℤ be the set of integers, and let ≡3 ⊆ ℤ x ℤ relate integers that are equivalent modulo 3 – In other words, they have the same remainder

    when divided by 3 – ≡3 is an equivalence relation with three

    equivalence classes: [0], [1], and [2] – [0] includes 0, 3, 6, … – [1] includes 1, 4, 7, … – [2] includes 2, 5, 8, …

  • Partial Order

    • A partial order is a relation that is: • reflexive • anti-symmetric • transitive

    • Let R be a partial order defined on a set S. Then the pair (S, R) is a partially ordered set

  • Partial Order A partial order can define a Subset-of relationship:

    Question: Is Proper-subset-of a partial order?

  • Partial Order A partial order can define a Subsumption (Concept-of) relationship:

  • Total Order

    • A total order R ⊆ S × S is a partial order that has the additional property that: ∀a, b ∈ S, ((a, b) ∈ R ∨ (b, a) ∈ R)

    • For example, the ≤ operator on the set of integers is a total order

    • If R is a total order defined on a set S, then the pair (S, R) is a totally ordered set

    3

    6

    5

    4

  • Well-Founded and Well-Ordered Sets

    • Given a partially ordered set (S, R), an infinitely descending chain is a totally ordered (with respect to R) subset B of S that has no minimal element

    • If (S, R) contains no infinitely descending chains then it is called a well-founded set

    – Used in halting proofs

    • If (S, R) is a well-founded set and R is a total order, then (S, R) is called a well-ordered set

    – Used in induction proofs

  • (S, R) Well-founded? Well-ordered?

    The set of sets with respect to the subset-of relation

    Yes No

    The set of concepts with respect to subsumption

    Yes No

    The set of first-order sentences with respect to subsumption

    Yes No

    The set of natural numbers ℕ under ≤ Yes Yes

    The set of integers ℤ under ≤ No No

    Well-Founded and Well-Ordered Sets

  • Functions

    • A unary function maps from a single element (a number) to another element – For example, the successor function takes a single element

    as input and outputs the next element in a sequence • A binary function maps from ordered pairs of elements

    to another element – For example, integer addition takes two integers as input

    • An n-ary function maps from an ordered n-tuple of elements to another element – For example, the quadratric equation function quad takes

    three elements as input: quad(a, b, c) = ax2 + bx + c

  • Functions

    • A binary function f from a set A to a set B is a binary relation (a subset of A × B) such that:

    ∀x∈A ((((x, y) ∈ f ∧ (x, z) ∈ f) → y = z) ∧ ∃y∈B ((x, y) ∈ f ))

    • For example, Likes = {(Dave, cake), (Dave, ice

    cream), (Sara, pie), (Sara, ice cream)} is a relation but not a function

    • However, successor(n) = n + 1 is a relation and a function

  • Functions domain

    1 2 3

    a

    b c

    range

    A B f(1) = a

    4

    5

    f : A → B

    f(2) = b f(3) = c

    We can define the successor function on the integers ℤ using the notation successor: ℤ → ℤ, and successor(n) = n + 1.

  • Properties of Functions

    • f : A → B is a total function on A iff it is a function that is defined on all elements of A

    • f : A → B is a partial function on A iff f is a subset of A × B and every element of A is related to no more than one element of B Total function Partial function

    A B

    A B

  • Properties of Functions

    • f : A → B is one-to-one iff no two elements of A map to the same element of B

    • f : A → B is onto iff every element of B is the value of some element of A

    Not one-to-one, Not onto

    B A A B

    Yes one-to-one, Not onto

  • Properties of Functions Question: for each of the following relations, indicate if it is a function, and, if so, indicate if the function is total, partial, one-to-one, onto, or any combination of these.

  • Properties of Functions

    • The inverse of a binary function f is the relation that contains exactly the ordered pairs in f with the elements of each pair reversed – We write the inverse of f as f -1

    – If f ⊆ A x B, then f -1 ⊆ B x A = {(b, a): (a, b)∈ f} – If a function f is both one-to-one and onto, then f -1 is called

    a bijection

  • • An isomorphism is a homomorphism (a function that maps the elements of its domain to the elements of its range in such a way that some structure of the original set is preserved) that is also a bijection (one-to-one and onto)

    • If two objects are isomorphic to each other, then they are indistinguishable with respect to the defining structure

    • Example: Let G be an arbitrary undirected graph, and let f(G) be exactly G except that the symbol # is appended to the name of every vertex. Then f is an isomorphism.

    Isomorphism

    G f(G)

  • Commutativity: A ∪ B = B ∪ A A ∩ B = B ∩ A Associativity: (A ∪ B) ∪ C = A ∪ (B ∪ C) (A ∩ B) ∩ C = A ∩ (B ∩ C) Idempotency: A ∪ A = A A ∩ A = A Distributivity: A ∪ (B ∩ C) = (A ∪ B) ∩ (A ∪ C) A ∩ (B ∪ C) = (A ∩ B) ∪ (A ∩ C) Absorption: (A ∪ B) ∩ A = A (A ∩ B) ∪ A = A Identity: A ∪ ∅ = A Zero: A ∩ ∅ = ∅ Self Inverse: ¬¬A = A DeMorgan’s Laws ¬(A ∪ B) = ¬A ∩ ¬B ¬(A ∩ B) = ¬A ∪ ¬B

    Properties of Functions on Sets

  • Closures

    • A binary relation R on a set S is closed under property P iff R possesses P – For example, the relation ≤ on the set of integers

    is closed under the property of transitivity • 1 ≤ 2 and 2 ≤ 3, therefore 1 ≤ 3

  • Closures

    • The closure of R under P is a smallest set that includes R and that is closed under P – The closure of ≤ on the set S = {(1,2), (2,3)} under

    transitivity is {(1,2), (2, 3), (1, 3)} – Alternately, we can say “the transitive closure of

    {(1,2), (2,3)} is {(1,2), (2,3), (1,3)}”

    • Question: Let R = {(1, 2), (2, 3), (3, 4)}. What is the reflexive closure of R? What is the transitive closure of R?

  • Closures Under Functions

    • A set S is closed under a function f iff, whenever any of f ‘s arguments are elements of S, the result is also in S – For example, the positive integers are closed

    under addition because adding two positive integers together yields another positive integer

    – But the positive integers are not closed under subtraction because subtracting a positive integer from another positive integer may not be positive

  • Closures Under Functions

    • Examples: – {0} is not closed under the successor function

    since successor(0) = 1 • The closure of {0} under successor is ℕ, the natural

    numbers – ℕ is closed under addition, since the sum of any

    two natural numbers is a natural number – ℕ is not closed under subtraction

    • The closure of ℕ under subtraction is ℤ, the integers – ℤ is not closed under division

    • The closure of ℤ under division is ℚ (the rational numbers) plus a special element that is the result of dividing by 0

  • Closures Under Functions

    • Examples: – ℚ is not closed under limits

    • The closure of ℚ under limits is ℝ (the real numbers) – ℝ is not closed under square root

    • The closure of ℝ under square root is ℂ (the complex numbers)

  • Closures Under Functions

    • Examples: – The set of even length strings of a’s and b’s is

    closed under concatenation – The set of odd length strings of a’s and b’s is not

    closed under concatenation • For example, the string aaa concatenated with the

    string aaa is aaaaaa, whose length is not odd • The closure of the odd length strings of a’s and b’s

    under concatenation is the set of all strings of a’s and b’s

    Mathematical FoundationsMath ReviewSetsSetsSetsPrograms Can Define SetsCardinalitySet RepresentationsPower SetPartition of a SetSet RepresentationsSet RepresentationsSet OperationsDisjoint Sets and Set CardinalityCartesian ProductCartesian ProductCartesian ProductRelationsRelationsBinary RelationsBinary RelationsComposing RelationsRepresenting RelationsRepresenting a Binary Relation as an Adjacency MatrixRepresenting a Binary Relation as a GraphProperties of RelationsProperties of RelationsProperties of RelationsEquivalence RelationsEquivalence RelationsEquivalence RelationsEquivalence RelationsEquivalence RelationsEquivalence RelationsEquivalence RelationsEquivalence ClassesEquivalence ClassesEquivalence ClassesEquivalence ClassesPartial OrderPartial OrderPartial OrderTotal OrderWell-Founded and Well-Ordered SetsWell-Founded and Well-Ordered SetsFunctionsFunctionsFunctionsProperties of FunctionsProperties of FunctionsProperties of FunctionsProperties of FunctionsIsomorphismProperties of Functions on SetsClosuresClosuresClosures Under FunctionsClosures Under FunctionsClosures Under FunctionsClosures Under Functions