csc331 week 1 topic a

Upload: frankjamison

Post on 04-Jun-2018

225 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/13/2019 CSC331 Week 1 Topic A

    1/54

  • 8/13/2019 CSC331 Week 1 Topic A

    2/54

    Topic ASets and Logic

    Section 1.1Sets

    Section 1.2Proposition

    Section 1.3Conditional Propositions andLogical Equivalence

    Section 1.4Arguments and Rules of

    Inference

    Section 1.5Quantifiers

    Section 1.6Nested Quantifiers

  • 8/13/2019 CSC331 Week 1 Topic A

    3/54

    Section 1.1 Sets

    Set = a collection of distinct unordered

    objects

    Members of a set are called elements How to determine a set

    Listing:

    Example: A = {1,3,5,7}

    Description

    Example: B = {x | x = 2k + 1, 0 < k < 3}

  • 8/13/2019 CSC331 Week 1 Topic A

    4/54

    Finite and infinite sets

    Finitesets

    Examples:

    A = {1, 2, 3, 4}

    B = {x | x is an integer, 1 < x < 4}

    Infinitesets

    Examples:

    Z = {integers} = {, -3, -2, -1, 0, 1, 2, 3,} S={x| x is a real number and 1 < x < 4} = [0, 4]

  • 8/13/2019 CSC331 Week 1 Topic A

    5/54

    Some important sets

    The emptyset has no elements.

    Also called null setor void set.

    Universalset: the set of all elements about

    which we make assertions.

    Examples:

    U = {all natural numbers}

    U = {all real numbers} U = {x| x is a natural number and 1< x

  • 8/13/2019 CSC331 Week 1 Topic A

    6/54

    Some important sets

    Two sets X and Y are equal and we write X = Y

    if X and Y have the same elements.

    X = Y if the following two conditions holds:

    For every x, if x X, then x Y,

    and

    For every x, if x Y, then x X.

    This is a great way to prove two sets are equal.

  • 8/13/2019 CSC331 Week 1 Topic A

    7/54

    Cardinality

    Cardinality of a set A (in symbols |A|) is the

    number of elements in A

    Examples:

    If A = {1, 2, 3} then |A| = 3

    If B = {x | x is a natural number and 1< x< 9}

    then |B| = 9

    Infinite cardinality Countable (e.g., natural numbers, integers)

    Uncountable (e.g., real numbers)

  • 8/13/2019 CSC331 Week 1 Topic A

    8/54

    Subsets

    X is a subsetof Y if every element of

    X is also contained in Y

    (in symbols X

    Y) Equality: X = Y if X Y and Y X

    X is aproper subsetof Y if X Y but

    Y X Observation:is a subset of every set

  • 8/13/2019 CSC331 Week 1 Topic A

    9/54

  • 8/13/2019 CSC331 Week 1 Topic A

    10/54

    Set operations:

    Union and Intersection

    Given two sets X and Y

    The unionof X and Y is defined as the set

    X Y = { x | x X or x Y}

    The intersectionof X and Y is defined as the set

    X Y = { x | x X and x Y}

    Two sets X and Y are disjointif X Y =

  • 8/13/2019 CSC331 Week 1 Topic A

    11/54

    Complement and Difference

    The differenceof two sets

    XY = { x | x X and x Y}

    The difference is also called the relative complement

    of Y in X

    Symmetric difference

    XY = (XY) (YX)

    The complement of a set A contained in auniversal set U is the set Ac= UA

    In symbols Ac = U - A

  • 8/13/2019 CSC331 Week 1 Topic A

    12/54

    Venn diagrams

    A Venn diagram provides a graphic view ofsets

    Set union, intersection, difference,

    symmetric difference and complements canbe identified

  • 8/13/2019 CSC331 Week 1 Topic A

    13/54

    Properties of set operations (1)

    Theorem 2.1.10: Let U be a universal set, and

    A, B and C subsets of U. The followingproperties hold:

    a) Associativity: (A B) C = A (B C)

    (A B) C = A (B C)

    b) Commutativity: A B = B A

    A B = B A

  • 8/13/2019 CSC331 Week 1 Topic A

    14/54

    Properties of set operations (2)

    c) Distributive laws:

    A(BC) = (AB)(AC)A(BC) = (AB)(AC)

    d) Identity laws:

    AU=A A= A

    e) Complement laws:

    AAc= U AAc=

    Correction!!!!!It was incorrectly reversed in

    previous version

  • 8/13/2019 CSC331 Week 1 Topic A

    15/54

    Properties of set operations (3)

    f) Idempotent laws:

    AA = A AA = Ag) Bound laws:

    AU = U A=

    h) Absorption laws:A(AB) = A A(AB) = A

  • 8/13/2019 CSC331 Week 1 Topic A

    16/54

    Properties of set operations (4)

    i) Involution law: (Ac)c= A

    j) 0/1 laws: c= U Uc=

    k) De Morgans laws for sets:

    (AB)c

    = Ac

    Bc

    (AB)c= AcBc

  • 8/13/2019 CSC331 Week 1 Topic A

    17/54

    Union and intersection of

    a family Sof sets

    The unionof an arbitrary family Sof sets is

    defined to be those elements x belonging to

    at least one set X in S.

    S = {x | x X for some X S}

    The intersectionof an arbitrary family Sof

    sets is defined to be those elements x

    belonging to every set X in SS = {x | x X for all X S}

  • 8/13/2019 CSC331 Week 1 Topic A

    18/54

    Union and intersection of

    a family Sof sets (2)

  • 8/13/2019 CSC331 Week 1 Topic A

    19/54

    Partition

    Thepartitionof a set X divides X into non-

    overlapping subsets.

    More formally, a collection S of nonempty

    subsets of X is said to be apartition of set X ifevery element in X belongs to exactly one

    member of S

    If S is a partition of X S is pair-wise disjoint and

    S= X

  • 8/13/2019 CSC331 Week 1 Topic A

    20/54

    Logic

    Logic = the study of correct reasoning

    Use of logic In mathematics:

    to prove theorems

    In computer science:

    to prove that programs do what they are

    supposed to do

  • 8/13/2019 CSC331 Week 1 Topic A

    21/54

    Section 1.2 Propositions

    Apropositionis a statement or sentence

    that can be determined to be either true orfalse.

    Examples:

    John is a programmer" is a proposition I wish I were wise is not a proposition

  • 8/13/2019 CSC331 Week 1 Topic A

    22/54

    Truth table of conjunction

    The truth values of compound propositionscan be described by truth tables.

    Truth table of conjunction

    p ^ q is true only when both p and q are true.

    p q p ^ q

    T T T

    T F F

    F T F

    F F F

  • 8/13/2019 CSC331 Week 1 Topic A

    23/54

    Example

    Let p = Tigers are wild animals

    Let q = Chicago is the capital of Illinois p ^q = "Tigers are wild animals and

    Chicago is the capital of Illinois"

    p ^q is false. Why?

  • 8/13/2019 CSC331 Week 1 Topic A

    24/54

    Truth table of disjunction

    The truth table of (inclusive) disjunctionis

    p q is false only when both p and q are false Example: p = "John is a programmer", q = "Mary is a lawyer"

    p v q = "John is a programmer or Mary is a lawyer"

    p q p v q

    T T T

    T F T

    F T T

    F F F

  • 8/13/2019 CSC331 Week 1 Topic A

    25/54

    Negation

    Negation of p: in symbols ~p

    ~p is false when p is true, ~p is true when p isfalse Example: p = "John is a programmer"

    ~p = "It is not true that John is a programmer"

    p ~p

    T F

    F T

  • 8/13/2019 CSC331 Week 1 Topic A

    26/54

    More compound statements

    Let p, q, r be simple statements

    We can form other compound statements,

    such as (pq)^r

    p(q^r)

    (~p)(~q)

    (pq)^(~r)

    and many others

  • 8/13/2019 CSC331 Week 1 Topic A

    27/54

    Example: truth table of (pq)^r

    p q r (p q)^rT T T

    T T F

    T F T

    T F F

    F T T

    F T FF F T

    F F F

  • 8/13/2019 CSC331 Week 1 Topic A

    28/54

    Section 1.3 Conditional propositions

    and logical equivalence

    A conditionalproposition is of the form

    If p then q

    In symbols: p q Example:

    p = " John is a programmer"

    q = " Mary is a lawyer "

    p q = If John is a programmer then Mary is

    a lawyer"

  • 8/13/2019 CSC331 Week 1 Topic A

    29/54

    Truth table of p q

    p q is true when both p and q are true

    or when p is false (true by default or vacuously true)

    p q p q

    T T T

    T F F

    F T T

    F F T

  • 8/13/2019 CSC331 Week 1 Topic A

    30/54

    Hypothesis and conclusion

    In a conditional proposition p q,

    p is called the antecedentor hypothesis

    q is called the consequentor conclusion

    If "p then q" is considered logically the

    same as "p only if q"

  • 8/13/2019 CSC331 Week 1 Topic A

    31/54

    Necessary and sufficient

    A necessarycondition is expressed by the

    conclusion.

    A sufficientcondition is expressed by the

    hypothesis. Example:

    If John is a programmerthen Mary is a lawyer"

    Necessary condition: Mary is a lawyer Sufficient condition: John is a programmer

  • 8/13/2019 CSC331 Week 1 Topic A

    32/54

    Logical equivalence

    Two propositions are said to be logically

    equivalentif their truth tables are identical.

    Example: ~p q is logically equivalentto p q

    p q ~p

    q p q

    T T T T

    T F F F

    F T T T

    F F T T

  • 8/13/2019 CSC331 Week 1 Topic A

    33/54

    Converse

    The converseof p q is q p

    These two propositions

    are not logically equivalent

    p q p q q p

    T T T T

    T F F T

    F T T F

    F F T T

  • 8/13/2019 CSC331 Week 1 Topic A

    34/54

    Contrapositive

    The contrapositive(or transposition) of the

    proposition p q is ~q ~p.

    They are logically equivalent.

    p q p q ~q ~p

    T T T T

    T F F F

    F T T T

    F F T T

  • 8/13/2019 CSC331 Week 1 Topic A

    35/54

    Biconditional proposition

    The biconditional propersitionp if and only if qis defined in symbols as p q

    p q is logically equivalent to (p q)^(q p)

    p q p q (p q) ^ (q p)

    T T T T

    T F F F

    F T F F

    F F T T

  • 8/13/2019 CSC331 Week 1 Topic A

    36/54

    De Morgans laws for logic

    The following pairs of propositions are

    logically equivalent:

    ~ (p q) and (~p)^(~q)

    ~ (p ^ q) and (~p) (~q)

    S ti 1 4 A t d R l

  • 8/13/2019 CSC331 Week 1 Topic A

    37/54

    Section 1.4 Arguments and Rules

    of Inference

    Deductive reasoning: the process of reaching a

    conclusion q from a sequence of propositions p1,

    p2, , pn.

    A (deductive) argument is a sequence ofpropositions written as

    The symbol is read therefore.

    The propositions p1, p2, , pnare calledpremisesor hypothesis.

    The proposition q that is logically obtained

    through the process is called the conclusion.

  • 8/13/2019 CSC331 Week 1 Topic A

    38/54

    Rules of inference (1)

    1. Law ofdetachmentor

    modus ponens p q

    p

    Therefore, q

    2. Modus tollens

    p q ~q

    Therefore, ~p

  • 8/13/2019 CSC331 Week 1 Topic A

    39/54

    Rules of inference (2)

    3. Rule ofAddition

    p

    Therefore, p q

    4. Rule ofsimplification

    p ^ q

    Therefore, p

    5. Rule of conjunction

    p

    q

    Therefore, p ^ q

  • 8/13/2019 CSC331 Week 1 Topic A

    40/54

    Rules of inference (3)

    6. Rule of hypothetical syllogism

    p q

    q r

    Therefore, p r

    7. Rule of disjunctive syllogism

    p q

    ~p

    Therefore, q

  • 8/13/2019 CSC331 Week 1 Topic A

    41/54

    Section 1.5 Quantifiers

    Apropositional functionP(x) is a statement

    involving a variable x

    For example: P(x): 2x is an even integer

    x is an element of a set D

    For example, x is an element of the set of integers

    D is called the domainof P(x)

  • 8/13/2019 CSC331 Week 1 Topic A

    42/54

    Domain of a propositional function

    In the propositional function

    P(x): 2x is an even integer,

    the domain D of P(x) must be defined, for

    instance D = {integers}.

    D is the set where the x's come from.

  • 8/13/2019 CSC331 Week 1 Topic A

    43/54

    For everyand for some

    Most statements in mathematics and

    computer science use terms such as for

    everyand for some.

    For example:

    For everytriangle T, the sum of the angles of T

    is 180 degrees.

    For everyinteger n, n is less than p, for someprime number p.

  • 8/13/2019 CSC331 Week 1 Topic A

    44/54

    Universal quantifier

    One can write P(x) for everyx in a domain D

    In symbols: x P(x)

    is called the universal quantifier

  • 8/13/2019 CSC331 Week 1 Topic A

    45/54

    Truth of as propositional function

    The statement x P(x) is

    True if P(x) is true for every x D

    False if P(x) is not true for some x

    D Example: Let P(n) be the propositional

    function n2+ 2n is an odd integer

    n D = {all integers}

    P(n) is true only when n is an odd integer,

    false if n is an even integer.

  • 8/13/2019 CSC331 Week 1 Topic A

    46/54

    Existential quantifier

    For somex D, P(x) is true if there exists

    an element x in the domain D for which P(x) is

    true. In symbols: x, P(x)

    The symbol is called the existential

    quantifier.

  • 8/13/2019 CSC331 Week 1 Topic A

    47/54

    Counterexample

    The universal statement x P(x) is false ifx D such that P(x) is false.

    The value x that makes P(x) false is called acounterexampleto the statement x P(x). Example: P(x) = "every x is a prime number", for

    every integer x.

    But if x = 4 (an integer) this x is not a primernumber. Then 4 is a counterexample to P(x)being true.

  • 8/13/2019 CSC331 Week 1 Topic A

    48/54

    Generalized De Morgans

    laws for Logic If P(x) is a propositional function, then each

    pair of propositions in a) and b) below have

    the same truth values:a) ~(x P(x)) and x: ~P(x)

    "It is not true that for every x, P(x) holds" is equivalentto "There exists an x for which P(x) is not true"

    b) ~(x P(x)) and x: ~P(x)"It is not true that there exists an x for which P(x) istrue" is equivalent to "For all x, P(x) is not true"

  • 8/13/2019 CSC331 Week 1 Topic A

    49/54

    Summary of propositional logic

    In order to prove the

    universally quantified

    statement x P(x) is

    true It is not enough to

    show P(x) true for

    some x D

    You must show P(x) istrue for every x D

    In order to prove the

    universally quantified

    statement x P(x) is

    false It is enough to exhibit

    some x D for which

    P(x) is false

    This x is called thecounterexampleto

    the statement x P(x)

    is true

  • 8/13/2019 CSC331 Week 1 Topic A

    50/54

    Rules of inference for

    quantified statements

    1. Universal instantiation

    xD, P(x) d D

    Therefore P(d)

    2. Universal generalization

    P(d) for any d D Therefore x, P(x)

    3. Existential instantiation

    x D, P(x) Therefore P(d) for some

    d D

    4. Existential generalization

    P(d) for some d D Therefore x, P(x)

  • 8/13/2019 CSC331 Week 1 Topic A

    51/54

    Section 1.6 Nested Quantifiers

    By definition, the statement xyP(x, y),

    with domain of discourse XY, is true if, for

    everyxX and everyyY, P(x, y)is true.The statement xyP(x, y)is false if there is

    at least onexX and at least oneyY

    such that P(x, y)is false.

  • 8/13/2019 CSC331 Week 1 Topic A

    52/54

    xyP(x, y)

    By definition, the statement xyP(x, y),with

    domain of discourse XY, is true if, for every

    xX, there is at least one yY for whichP(x, y)is true. The statement xyP(x, y)is

    false if there is at least onexX such that

    P(x, y)is falseforevery yY.

  • 8/13/2019 CSC331 Week 1 Topic A

    53/54

    xyP(x, y)

    By definition, the statement xyP(x, y),with

    domain of discourse XY, is true if there is at

    least onexX such that P(x, y)is true forevery oneyY. The statement xyP(x, y)

    is false if, for every xX, there is at least

    oneyY such thatP(x, y)is false.

  • 8/13/2019 CSC331 Week 1 Topic A

    54/54

    xyP(x, y)

    By definition, the statement xyP(x, y),with

    domain of discourse XY, is true if there is at

    least onexX and at least oneyY suchthat P(x, y)is true. The statement xyP(x,

    y) is false if, for every xX and for every y

    Y, P(x, y)is false.