lesson 6 28

Upload: manuel-albert-cunanan

Post on 07-Apr-2018

215 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/6/2019 Lesson 6 28

    1/42

    DISCRETE Mathematics withAUTOMATA

    The Foundations:Logic and Proof and Sets

    Integers And DivisionIntegers And Algorithm

    Representing Graphs andGraph Isomorphism

    ConnectivityPaths and Circuits

    Euler And Hamilton Paths

    Shortest Path Problems

    RecursiveDefinitions & Algorithms

  • 8/6/2019 Lesson 6 28

    2/42

  • 8/6/2019 Lesson 6 28

    3/42

    The Foundations: Logic and Proof andSets

    Example 1

    All the following declarative sentences are propositions.

    1. Washington, D.C., is the capital of the United Statesof America.

    2. Toronto is the capital of Canada

    3. 1 + 1 = 2.

    4. 2 + 2 = 3.

    Propositions 1 and 3 are true, whereas 2 and 4 are false.

  • 8/6/2019 Lesson 6 28

    4/42

    The Foundations: Logic and Proof andSets

    Example 2

    Consider the following sentences.1.What time is it?2.Read this carefully.3.x + 1 = 2.4.x + y = z.

    Sentences 1 and 2 are not propositions because

    they are not declarative sentences. Sentences 3and 4 are not propositions because they are neithertrue nor false, since the variables in these sentenceshave not been assigned values.

  • 8/6/2019 Lesson 6 28

    5/42

    The Foundations: Logic and Proof andSets

    The truth vales of a proposition is true, denoted byT, if it is a true proposition and false, denotedby F, if it is a false proposition.

    The area of logic that deals with propositions iscalled the propositional calculus orpropositional logic.

    Compound propositions are formed from existingpropositions using logic operators.

  • 8/6/2019 Lesson 6 28

    6/42

    The Foundations: Logic and Proof andSets

    Definition 1

    Let p be a proposition. The statement

    Its is no the case thatp

    is another proposition, called the negation ofp.The negation of p is denoted by p. Theproposition p is readnotp.

  • 8/6/2019 Lesson 6 28

    7/42

    The Foundations: Logic and Proof andSets

    Example 2Find the negation of the propositionToday is Friday.And express this in simple English.

    SolutionThe negation is

    It is not the case that today is Friday.

    Or simply Today is not Friday.Or It is not Friday today.

  • 8/6/2019 Lesson 6 28

    8/42

  • 8/6/2019 Lesson 6 28

    9/42

    The Foundations: Logic and Proof andSets

    Definition 2Letp and q be propositions. The propositions p and qdenotedp q is the proposition that is true when bothpand q are true and is false otherwise.The proposition p q is called the conjunction ofp and q.

    TABLE 2 The Truth table for theConjunction of Two Proposition

    p q p q

    T T T

    T F F

    F T F

    F F F

  • 8/6/2019 Lesson 6 28

    10/42

    The Foundations: Logic and Proof andSets

    Example 4

    Find the conjunction of the propositionsp and q wherep is the propositionToday is Fridayand q is thepropositionIt is raining today.

    Solution:

    The conjunction of these propositions,p ^ q, is the

    propositionToday is Friday and it is raining today.This proposition is true on rainy Fridays and is false onany day that is not a Friday and on Fridays when itdoes not rain.

  • 8/6/2019 Lesson 6 28

    11/42

    The Foundations: Logic and Proof andSets

    Definition 3Letp and q be propositions. The proposition p or q,denotedp V q, is the proposition that is false whenp andq are both false or true otherwise. The propositionp V qis called the disjunction ofp and q.

    TABLE 3 The Truth table for theDisjunction of Two Proposition

    p q p V q

    T T T

    T F T

    F T T

    F F F

  • 8/6/2019 Lesson 6 28

    12/42

    The Foundations: Logic and Proof andSets

    The use of the connective or in a disjunctioncorresponds to one of the two ways the word oris usedin English, namely, in an inclusive way. A disjunction istrue when at least one of the two propositions is true.

    For instance, the inclusive or is being used in thestatement

    Students who have taken calculus or computerscience can take this class.

    Here, we mean that students who have taken bothcalculus and computer science can take the class, aswell as the students who have taken only one of the twosubjects.

  • 8/6/2019 Lesson 6 28

    13/42

    The Foundations: Logic and Proof andSets

    On the other hand, we are using the exclusive way orwhen we say

    Students who have taken calculus or computerscience, but not both, can enroll in this class.

    Here, we mean that students who have taken bothcalculus and a computer science course cannot take

    the class. Only those who have taken exactly one ofthe two courses can take the class.

  • 8/6/2019 Lesson 6 28

    14/42

    The Foundations: Logic and Proof andSets

    Example 5

    What is the disjunction of the propositionsp and q wherep and q are the same propositions as in Example 4?

    Solution:

    The disjunction ofp and q,p V q, is the propositionToday is Friday or it is raining today.

    This proposition is true on any day that is either a Fridayor a rainy day (including rainy Fridays). It is only falseon days that are not Fridays when it also does not rain.

  • 8/6/2019 Lesson 6 28

    15/42

    The Foundations: Logic and Proof andSets

    Definition 4Letp and q be propositions. The exclusive or ofp and q,denoted by p q, is the proposition that is true whenexactly one ofp and q is true and is false otherwise.

    TABLE 4 The Truth table for theExclusive Or of Two Proposition

    p q p q

    T T F

    T F T

    F T T

    F F F

  • 8/6/2019 Lesson 6 28

    16/42

    The Foundations: Logic and Proof andSets

    IMPLICATIONS

    Definition 5

    Letp and q be propositions. The implicationp q is theproposition that is false whenp is true and q is false, andtrue otherwise. In this implicationp is called thehypothesis (or antecedentorpremise) and q is called theconclusion (or consequence).

    An implication is sometimes called a conditionalstatement.

  • 8/6/2019 Lesson 6 28

    17/42

    The Foundations: Logic and Proof andSets

    Because implications play such an essential role inmathematical reasoning, a variety of terminology is usedto expressp q. You will encounter most if not all ofthe following ways to express this implication:

    ifp, then q p implies qifp, q p only ifqp is sufficient for q a sufficient condition for q ispq ifp q wheneverp

    q whenp q is necessary forp a necessary condition q follows frompforp is q

  • 8/6/2019 Lesson 6 28

    18/42

    The Foundations: Logic and Proof andSets

    The implicationp q is false only in the case thatp istrue, but q is false. It is true when bothp and q aretrue, and whenp is false (no matter what truth value qhas).

    TABLE 5 The Truth table for theImplicationp q

    p q p q

    T T T

    T F FF T T

    F F T

  • 8/6/2019 Lesson 6 28

    19/42

    The Foundations: Logic and Proof andSets

    A useful way to understand the truth value of animplication is to think of an obligation or a contract. Forexample, the pledge many politicians make when runningfor office is:

    IfI am elected, then I will lower taxes.

    If the politician is elected, voters would expect thispolitician to lower taxes. Furthermore, if the politician isnot elected, then voters will not have any expectation thatthis person will lower taxes, although the person may havesufficient influence to cause those in power to lower taxes.

    It is only when the politician is elected but does not lowertax those voters can say that the politician has broken thecampaign pledge. This last scenario corresponds to the casewhenp is true, but q is false inp q.

  • 8/6/2019 Lesson 6 28

    20/42

    The Foundations: Logic and Proof andSets

    Example 6What is the value of the variable x after the statement

    if 2+2=4 then x := x+1

    if x=0 before this statement is encountered? (Thesymbol := stands for assignment. The statement x :=x+1 means the assignment of the value of x +1 to x.)

    Solution:

    Since 2+2=4 is true, the assignment statement x := x+1is executed. Hence, x has the value 0+1 = 1 after thisstatement is encountered.

  • 8/6/2019 Lesson 6 28

    21/42

    The Foundations: Logic and Proof andSets

    CONVERSE, CONTRAPOSITIVE, AND INVERSE

    There are some related implications that can be formedfromp q. The proposition q p is called the converseofp q. The contrapositive ofp q is the proposition q p. The proposition p q is called the inverse of

    p q.

    The contrapositive, q p, of an implicationp qhas the same truth value asp q. To see this, notethat the contrapositive is false only when p is false and

    q is true, that is, only whenp is true and q is false. Onthe other hand, neither the converse, q p, nor theinverse, p q, has the same truth value as p q forall possible truth values ofp and q.

  • 8/6/2019 Lesson 6 28

    22/42

  • 8/6/2019 Lesson 6 28

    23/42

    The Foundations: Logic and Proof andSets

    Consequently, the contrapositive of this implication is

    If the home team does not win, then it is not raining.

    The converse is

    If the home team wins, then it is raining.

    The inverse is

    If it is not raining, then the home team does not win.

    Only the contrapositive is equivalent to the originalstatement.

  • 8/6/2019 Lesson 6 28

    24/42

  • 8/6/2019 Lesson 6 28

    25/42

    The Foundations: Logic and Proof andSets

    The terminology

    p if and only ifq

    is used for this biconditional and it is symbolically writtenby combining the symbols and . There are someother common ways to expresspq:

    p is necessary and sufficient for qifp then q, and conversely

    p ifq

    The last way of expressing the biconditional uses theabbreviation iff for if and only if.

  • 8/6/2019 Lesson 6 28

    26/42

    The Foundations: Logic and Proof andSets

    Example 8Let p be the statementYou can take the flightand let qbe the statementYou buy a ticket. Thenp q is thestatement

    You can take the flight if and only if you buy a ticket.

    This statement is true ifp and q are either both true orboth false, that is, if you buy a ticket and can take theflight or if you do not buy a ticket and you cannot takethe flight. It is false when p and q have opposite truthvalues, that is, when you do not buy a ticket, but youcan take the flight (such as when you get a free trip) andwhen you buy a ticket and cannot take the flight (such aswhen the airline bumps you).

  • 8/6/2019 Lesson 6 28

    27/42

  • 8/6/2019 Lesson 6 28

    28/42

    The Foundations: Logic and Proof andSets

    TRANSLATING ENGLISH SENTENCES

    Example 9

    How can this English sentence be translated into alogical expression?

    You can access the Internet from campus only ifyou are a computer science major or you are not a

    freshman.

  • 8/6/2019 Lesson 6 28

    29/42

    The Foundations: Logic and Proof andSets

    Solution:There are many ways to translate this sentence into a

    logical expression. Although it is possible to representthe sentence by a single propositional variable, such as

    p, this would not be useful when analyzing its meaningor reasoning with it. Instead, we will use propositionalvariables to represent each sentence part and determinethe appropriate logical connectives between them, inparticular, we let a, c, and frepresent You can accessthe Internet from campus, You are a computer sciencemajor,and You are a freshman, respectively. Noting

    thatonly ifis one way an implication can be expressed,this sentence can be represented asa (c V f).

  • 8/6/2019 Lesson 6 28

    30/42

    The Foundations: Logic and Proof andSets

    Example 10How can this English sentence be translated into a logicalexpression?

    You cannot ride the roller coaster if you are under 4 feettall unless you are older than 16 years old.

    Solution:

    There are many ways to translate this sentence into alogical expression. The simplest but least useful way issimply to represent the sentence by a singlepropositional variable, say,p.

  • 8/6/2019 Lesson 6 28

    31/42

    The Foundations: Logic and Proof andSets

    Although this is not wrong, doing this would not assist uswhen we try to analyze the sentence or reason using it.More appropriately, what we can do is to usepropositional variables to represent each of the sentenceparts and to decide on the appropriate logicalconnectives between them.

    In particular, we let q, rand s representYou can ride the roller coaster, You are under 4 feet

    tall,andYou are older than 16 years old, respectively.Then the sentence can be translated to(r s ) q.

  • 8/6/2019 Lesson 6 28

    32/42

    The Foundations: Logic and Proof andSets

    SYSTEM SPECIFICATIONS

    Example 11Express the specification The automated reply cannot besent when the file system is full sing logical connectives

    Solution:One way to translate this is to letp denoteTheautomated reply can be sentand q denote The filesystem is full. Then p represents It is not the casethat the automated reply can be sent, which can also beexpressed as The automated reply cannot be sent.Consequently, our specification can be represented bythe implication qp.

  • 8/6/2019 Lesson 6 28

    33/42

    The Foundations: Logic and Proof andSets

    Example 12Determine whether these system specifications areconsistent:

    The diagnostic message is stored in the buffer or it isretransmitted.

    The diagnostic message is not stored in the buffer.If the diagnostic message is stored in the buffer, then itis retransmitted.

    Solution:To determine whether these specifications are consistent,we first express them using logical expressions. Letpdenote The diagnostic message id stored in the bufferand let q denote The diagnostic message isretransmitted.

  • 8/6/2019 Lesson 6 28

    34/42

    The Foundations: Logic and Proof andSets

    The specification can then be written asp V q, p, andp q. an assignment of truth values that makes all threespecifications true must havep false to make p true.

    Since we wantp V q to be true butp must be false, q

    must be true. Becausep q is true whenp is false andq is true, we conclude that these specifications areconsistent since they are all true whenp is false and q istrue.

    We could come with the same conclusion by use of atruth table to examine the four possible assignments oftruth values top and q.

  • 8/6/2019 Lesson 6 28

    35/42

    The Foundations: Logic and Proof andSets

    LOGIC PUZZLES

    Puzzles that can be solved using logical reasoning areknown as logical puzzles.

    Example 15In Smullyan posed many puzzles about an island thathas two kinds of inhabitants, knights, who always tell thetruth, and their opposites, knaves, who always lie. Youencounter two peopleA and B. What areA and B ifAsays B is a knight and B says The two of us areopposite types?

  • 8/6/2019 Lesson 6 28

    36/42

    The Foundations: Logic and Proof andSets

    Solution:

    Letp and q be the statements that A is a knight and B is a knight,respectively, so that p and q are the statements that A is aknave that B is a knave, respectively.

    We first consider the possibility that A is a knight; this is thestatement thatp is true. If A is a knight, then he is telling the

    truth when he says that be is a knight, so that q is true, and Aand B are the same types, the statement (p q) V (p q),would have to be true, which it is not, becauseA and B are bothknights. Consequently, we can conclude that A is not a knight,that is, thatp is false.

    IfA is a knave, then because everything a knave says is false,As

    statement that B is a knight, that is, that q is true, is a lie, whichmeans that q is false and B is also a knave. Furthermore, ifB is aknave, then Bs statement thatA and B are opposite types is a lie,which is consistent with both A and B being knaves. We canconclude that bothA and B are knaves.

  • 8/6/2019 Lesson 6 28

    37/42

  • 8/6/2019 Lesson 6 28

    38/42

    The Foundations: Logic and Proof andSets

    Solution:

    Let s be the statement that the son has a muddyforehead and let dbe the statement that the daughterhas a muddy forehead. When the father says that at

    least one of the two children has a muddy forehead hestating that the disjunctions s V dis true. Both childrenwill answer Nothe first time the question is askbecause each sees mud on the other childs forehead.That is the son knows that dis true, but does not knowwhether s is true, and the daughter knows that s is true,but does not know whether dis true.

  • 8/6/2019 Lesson 6 28

    39/42

  • 8/6/2019 Lesson 6 28

    40/42

    The Foundations: Logic and Proof andSets

    Truth Value Bit

    TF

    10

    TABLE 8 Table for the BitOperators OR, AND, andXOR.

    x y x V y x y x y

    0 0 0 0 0

    0 1 1 0 1

    1 0 1 0 1

    1 1 1 1 0

    A Bit has two possible values, namely, 0 (zero) and 1 (one). Thismeaning of the word bit comes from binarydigit, since zeros andones are the digit used in binary representations of numbers. Avariable Boolean variable if its value is either true or false.Computer bit operations correspond to the logical connectives.

  • 8/6/2019 Lesson 6 28

    41/42

    The Foundations: Logic and Proof andSets,

    Definition 7A bit string is a sequence of zero and more bits. Thelength of this string is the number of bits in the string.

    Example 17Find the bitwise OR, bitwise AND, and bitwise XOR of thebit strings 01 1011 0110 and 11 0001 1101.

  • 8/6/2019 Lesson 6 28

    42/42

    The Foundations: Logic and Proof andSets

    Example 17Find the bitwise OR, bitwise AND, and bitwise XOR of thebit strings 01 1011 0110 and 11 0001 1101.

    Solution:The bitwise OR, bitwise AND, and bitwise XOR of thesestrings are obtained by taking the OR,AND, andXOR ofthe corresponding bits, respectively. This gives us

    01 1011 0110

    11 0001 110111 1011 1111 bitwise OR01 0001 0100 bitwise AND10 1010 1011 bitwise XOR