78
CS 103 Discrete Structures Lecture 02 Logic and Proofs (1)

CS 103 Discrete Structures Lecture 02 Logic and Proofs (1)

Embed Size (px)

Citation preview

The Foundations: Logic and Proofs

CS 103 Discrete Structures Lecture 02Logic and Proofs (1)

1Chapter 1 section 1.1 by Dr. Mosaad HassanThe Foundations: Logic and ProofsChapter 1, Part I: Propositional Logic2Chapter SummaryPropositional LogicThe Language of PropositionsApplicationsLogical EquivalencesPredicate LogicThe Language of QuantifiersLogical EquivalencesNested QuantifiersProofsRules of Inference

3Propositional Logic SummaryThe Language of PropositionsConnectivesTruth ValuesTruth TablesApplicationsTranslating English SentencesLogic Circuits Logical EquivalencesImportant EquivalencesVerifying Equivalence4Propositional LogicSection 1.15Section SummaryPropositionsConnectivesNegationConjunctionDisjunctionImplication; contrapositive, inverse, converseBiconditionalTruth Tables

6Rules and LogicRules of logic specify the meaning of mathematical statementsThey are used to distinguish between valid and invalid mathematical argumentsThey are also used in the design of computer circuits, the construction of computer programs, and the verification of the correctness of programsExample: If you get 100% on the final, then you get an ALogic is the basis of all mathematical and automated reasoningIt has practical applications to the design of computing machines, to the specification of systems, to artificial intelligence, to computer programming, to programming languages, and to other areas of computer science.

Proofs and TheoremsProof is a correct mathematical argument. Proofs play an essential role in the development of new ideas. They are used to:verify that computer programs produce the correct output for all possible input valuesshow that an algorithm always produces the correct resultestablish the security of a systemTheorem is a mathematical statement built using other correct mathematical statements

Propositional LogicBasic building blocks of logic are propositionsA Proposition is a declarative sentence (that is, a sentence that declares a fact) that is either true or false, but not both.The following are propositions.Ar Riyadh is the capital of the KSA.Cairo is the capital of Egypt.1 + 2 = 22 + 2 = 3Propositions 1 and 2 are true, whereas 3 and 4 are falseChapter 1 section 1.1 by Dr. Mosaad Hassan9Propositional LogicThe following are not propositions:What time is it?Read this carefullyx + 1 = 2x + y = z1 and 2 are not propositions because they are not declarative sentences. 3 and 4 are not propositions as they are neither true nor false. They can, however, be turned into propositions if we assign values to the variables.

Propositional VariablesPropositional variables (or statement variables) are letters used to represent propositions, not used to denote numerical variables.Letters commonly used to denote propositional variables are p, q, r, s, . . . . Truth value of a proposition is either T or F

Propositional logic (or propositional calculus) is the area of logic that deals with propositions. It was first developed systematically by the Greek philosopher Aristotle more than 2300 years ago

Compound PropositionsThey are formed or constructed by combining one or more existing propositions using logical operators. The simplest of those logical operators is negation.

Negation of a proposition (negation operator)Let p be a proposition. The negation of p, denoted by p, is the statement "It is not the case that p"The proposition p is read "not p" The truth value of p is the opposite of the truth value of p

pp TFFTNegation (NOT) Operator Example: Find the negation of the proposition Today is Friday and express it in simple English

Solution: The negation is any of the following:It is not the case that today is FridayToday is not FridayIt is not Friday today

Exercise: Find the negation of:At least 10 students attended todays classTaibah University is in Madinah MunawwarahConjunction (AND) Operator Definition: Let p and q be propositions. The conjunction of p and q, denoted by p q, is the compound proposition "p and q" The conjunction p q is True only if both p and q are true, and False otherwise

pqp q TTTTFFFTFFFFConjunction (AND) Operator Example: Find the conjunction of the propositions p and q where:p: Today is Friday q: It is raining todaySolution: The conjunction p q is the proposition Today is Friday and it is raining today This proposition is: True on rainy Fridays False on any day that is not a Friday and on Fridays when it is not raining

Disjunction (OR) Operator Definition: Let p and q be propositions. The disjunction of p and q, denoted by p q, is the compound proposition "p or q" The disjunction p q is: False only if both p and q are False True otherwise

pq p qTTTTFTFTTFFFDisjunction (OR) Operator Example: Find the disjunction of the propositions p and q where:p: Today is Friday q: It is raining todaySolution: The disjunction p v q is the proposition Today is Friday or it is raining todayThis proposition is:True on any day that is either a Friday or a rainy day (including rainy Fridays)False only on days that are not Fridays when it also does not rainDisjunction: Inclusive OR Connective OR is used in two ways:

Inclusive OR (or just OR)A disjunction is True when at least one of the two propositions is true. Example: Students who have taken calculus or computer science can take this classThat is, students who can take the class are:Who have taken both calculus and computer science,Who have taken calculusWho have taken computer scienceDisjunction: Exclusive OR A disjunction is True when only one of the two propositions is true

Example: Students who have taken calculus or computer science, but not both, can enroll in this classThat is, students that can take the class are:Who have taken calculus,Who have taken computer scienceStudents who have taken both calculus and a computer science course cannot take the classenroll : 19Chapter 1 section 1.1 by Dr. Mosaad HassanExclusive OR (XOR) Operator Definition: Let p and q be propositions. The exclusive or of p and q, denoted by p q (p XOR q), is the proposition that is:True when exactly one of p and q is true False otherwise

p qp qTTFTFTFTTFFF20Chapter 1 section 1.1 by Dr. Mosaad HassanConditional Statement: ImplicationDefinition: Let p and q be propositions. The conditional statement p q is the proposition if p then q The conditional statement p q is False when p is true and q is falseTrue otherwisep q is true when:Both p and q are true, or if p is false (no matter what truth value q has)p qp qTTTTFFFTTFFT21Chapter 1 section 1.1 by Dr. Mosaad HassanHypothesis ConclusionIn the conditional statement p q:p is called the hypothesis (antecedent or premise) q is called the conclusion (consequent or consequence)There are many ways of expressing p q:if p then qif p, qp is sufficient for qq if pq when pa necessary condition for p is qq unless pp implies qp only if qa sufficient condition for q is pq whenever pq is necessary for pq follows from p

22Chapter 1 section 1.1 by Dr. Mosaad HassanImplication: ExampleLet p be the statement Ahmed learns discrete structures and q the statement Ahmed will find a good job. Express the statement p q in EnglishSolution: The statement p q can be expressed in English in several ways:If Ahmed learns discrete mathematics, then he will find a good jobAhmed will find a good job when he learns discrete mathematicsFor Ahmed to get a good job, it is sufficient for him to learn discrete mathematicsAhmed will find a good job unless he does not learn discrete mathematicsNote: if-then construction used in many programming languages is different from that used in logic23Chapter 1 section 1.1 by Dr. Mosaad HassanConverse, Contrapositive, & Inverse There are three conditional statements that are related to the statement p q:The inverse of p q is p q The converse of p q is q p The contrapositive of p q is q p

A statement and its contrapositive are equivalentThe converse and the inverse of a conditional statement are also equivalent

24Chapter 1 section 1.1 by Dr. Mosaad HassanContrapositive: ExampleFind contrapositive of the conditional statement: The home team wins whenever it is raining

q whenever p is the implication p q p: it is rainingq: the home team winsThe original statement can be rewritten as:If it is raining, then the home team wins

Contrapositive:If the home team does not win, then it is not raining25Chapter 1 section 1.1 by Dr. Mosaad HassanConverse and Inverse: Example Find the converse and inverse of the conditional statement: The home team wins whenever it is raining

Converse:If the home team wins, then it is raining

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

Note that only the contrapositive is equivalent to the original statement26Chapter 1 section 1.1 by Dr. Mosaad HassanCS 103 Discrete Structures Lecture 03Logic and Proofs (2)27Chapter 1 section 1.1 by Dr. Mosaad HassanBi-conditional or Bi-implicationDefinition: Let p and q be propositions. The bi-conditional statement p q is the proposition p if and only if q The bi-conditional statement p q is:True when p and q have the same truth valuesFalse otherwise

pqp q TTTTFFFTFFFT28Chapter 1 section 1.1 by Dr. Mosaad HassanBi-conditional or Bi-implicationExample: Letp: You can take the flightq: You buy a ticketThen p q is the statement:You can take the flight if and only if you buy a ticketThe same can also be expressed as:p is necessary and sufficient for qif p then q, and converselyp iff qNote that p q has exactly the same truth value as (p q) (q p)29Chapter 1 section 1.1 by Dr. Mosaad HassanLogical Operators: SummaryNegation (true if p is false)NOTConjunction (true if p and q are true)ANDInclusive Disjunction (true if p or q or both are true)ORExclusive Disjunction (true if p and q are different)XORImplication (false if p is true and q is false)Bi-Implication (true if p and q are the same)XNOR30Chapter 1 section 1.1 by Dr. Mosaad HassanTruth Tables for Compound Propositions: ExampleConstruct the truth table of the compound proposition:(p q) (p q)

Solution

31Chapter 1 section 1.1 by Dr. Mosaad HassanTruth Tables For Compound PropositionsRowsNeed a row for every possible combination of values for the atomic propositions.ColumnsNeed a column for the compound proposition (usually at far right)Need a column for the truth value of each expression that occurs in the compound proposition as it is built up.This includes the atomic propositions 32Truth Tables for Compound Propositions: ExercisesConstruct truth tables for each of the following compound propositions:(p q)(q p)(p q) (q p)(p q) (p q)(p q) (p q) (p q) (p q)(p q) (p q) (p q) (p q) (p q) (q r)33Chapter 1 section 1.1 by Dr. Mosaad HassanPrecedence of Logical OperatorsWe will generally use parentheses to specify the order in which logical operators in a compound proposition are to be applied.To reduce the number of parentheses, we specify the precedence shown in this table:

Which two of thefollowing have thesame meaning?p q r(p q) rp (q r)

OperatorPrecedence1 23 4534Chapter 1 section 1.1 by Dr. Mosaad HassanBits and Boolean VariablesComputers represent information using bitsA bit may have one of two values: 0, 1There are two possible truth values: T, F. Therefore, a bit can be used to represent a truth value as shown in this table:

A variable is called a Boolean variable if its value can only be either true or false. A Boolean variable can be represented using a bit.

35Chapter 1 section 1.1 by Dr. Mosaad HassanBit OperationsBit Operations correspond to Logical ConnectivesAfter replacing true by 1 and false by 0 in the truth tables, we can use the bit operators OR, AND, and XOR as follow:

36Chapter 1 section 1.1 by Dr. Mosaad HassanBit Strings and Bitwise OperationsA bit string is a sequence of zero or more bits. The length of this string is the number of bits in the string. 101010011 is a bit string of length nine. We can extend bit operations to bit strings. bitwise OR, bitwise AND, and bitwise XOR Bitwise OR of two strings of the same length is the string that have the OR of the corresponding bits in the two stringsSimilarly for bitwise AND and bitwise XORWe use the symbols , , and to represent the bitwise OR, bitwise AND, and bitwise XOR operations, respectively37Chapter 1 section 1.1 by Dr. Mosaad HassanBitwise Operations: ExampleFind the bitwise OR, bitwise AND, and bitwise XOR of the bit strings: 01 1011 0110 and11 0001 110 1

The bitwise OR, bitwise AND, and bitwise XOR of these strings are obtained by taking the OR, AND, and XOR of the corresponding bits, respectively

38Chapter 1 section 1.1 by Dr. Mosaad HassanApplications of Propositional LogicSection 1.239Examples of Applications of Propositional LogicTranslating English to propositional logic

Electronic logic circuits

40Translating English SentencesStatements/sentences in English (and every other natural language) are often ambiguous. Translating sentences into compound propositions can be used to remove ambiguityTranslation may involve making a set of assumptions based on the intended meaning of the sentence. After translation of sentences from English into logical expressions we can:Analyze these logical expressions to determine their truth valuesManipulate themUse rules of inference41Chapter 1 section 1.1 by Dr. Mosaad HassanTranslate the following sentence into a logical expression? You can access the Internet from campus only if you are a computer science major or you are not a freshmanSolution: Representing this sentence by a single propositional variable, such as p, is not usefulInstead, we will use propositional variables to represent each sentence part and determine the appropriate logical connectives between them. Letp:you can access the internet from campusq:you are a computer science majorr:you are a freshmanThen the required expression is p (q r)Translating English Sentences: Example 142Chapter 1 section 1.1 by Dr. Mosaad HassanTranslate the following sentence into a logical expression: You cannot ride the roller coaster if you are under 4 feet tall unless you are older than 16

Letp: You can ride the roller coasterq: You are under 4 feet tallr: You are older than 16 yearsThen, the sentence can be translated to(q r) pTranslating English Sentences: Example 2roller coaster : 43Chapter 1 section 1.1 by Dr. Mosaad HassanElectronic Logic Circuits

In electronic logic circuits, each input/output signal is viewed as a 0 or 1, where 0 represents False and 1 represents TrueComplex circuits are constructed from three basic circuits called gates

The NOT gate (inverter) takes an input and produces its negationThe OR gate takes two inputs and produces the value equivalent to the disjunction of those two inputsThe AND gate takes two inputs and produces the value equivalent to the conjunction of those two inputsComplex digital circuits are constructed by combining these basic gates to produce the desired outputgiven the input signals

44Sections 1.1 and 1.2 ExercisesWhich of these sentences are propositions? What are the truth values of those that are propositions?2 + 3 = 5x + 2 = 11Answer this questionWhat time is it?2n 100Jeddah is the capital of Saudi ArabiaKaaba exists in Makkah.You are younger than your son.45Chapter 1 section 1.1 by Dr. Mosaad HassanFind the negation of each of these propositions?Today is Thursday.2 + 1 = 3The summer in Egypt is hot and sunny.Let p and q be two propositionsp: I received my UK visa this weekq: Im going to the UK on next FridayExpress the following propositions as English sentences.pp q p qp q p qp qp q p (p q)

46Chapter 1 section 1.1 by Dr. Mosaad HassanLet p and q be the propositionsp : It is below freezingq : It is snowingWrite the following propositions using p and q and logical connectives.It is below freezing and snowing.It is below freezing but not snowing.It is not below freezing and it is not snowing.It is either snowing or below freezing (or both).If it is below freezing, it is also snowing.It is either below freezing or it is snowing, but it is not snowing if it is below freezing.That it is below freezing is necessary and sufficient for it to be snowing.47Chapter 1 section 1.1 by Dr. Mosaad HassanFor each of these sentences, determine whether an Inclusive OR or an Exclusive OR is intended. Explain your answer.Coffee or tea comes with dinner.A password must have at least three digits or be at least eight characters long.The prerequisite for the course is a course in number theory or a course in cryptography.You can pay using U. S. dollars or R.S.Experience with C++ or Java is required.Lunch includes soup or salad.To enter the country you need a passport or a voter registration card.Publish or perish.

48Chapter 1 section 1.1 by Dr. Mosaad HassanWrite each of these statements in the form if p then q in English. I will remember to send you the address only if you send me an e-mail message.To be a citizen of this country, it is sufficient that you were born in the United States.If you keep your textbook, it will be a useful reference in your future courses.The Red Wings will win the Stanley Cup if their goalie plays well.That you get the job implies that you had the best credentials.The beach erodes whenever there is a storm.It is necessary to have a valid password to log on to the server.You will reach the summit unless you begin your climb too late.

49Chapter 1 section 1.1 by Dr. Mosaad HassanState the converse, contrapositive, and inverse of each of these conditional statements.If it snows today, I will ski tomorrow.I come to class whenever there is going to be a quiz.A positive integer is a prime only if it has no divisors other than 1 and itself.If it snows tonight, then I will stay at home.I go to the beach whenever it is a sunny summer day.When I stay up late, it is necessary that I sleep until noon.

50Chapter 1 section 1.1 by Dr. Mosaad HassanConstruct the truth table for each of the following compound propositions:

51Chapter 1 section 1.1 by Dr. Mosaad HassanConstruct a truth table for each of these compound propositions.

52Chapter 1 section 1.1 by Dr. Mosaad HassanConstruct a truth table for each of these compound propositions.

53Chapter 1 section 1.1 by Dr. Mosaad HassanFind the bitwise OR, bitwise AND, and bitwise XOR for each pair of bit strings.101 1110 010 00011111 0000 1010 101000 0111 0001 10 0100 100011 1111 1111 00 0000 0000

Evaluate each of the following expressions.1 1000 (0 1011 1 1011)(0 1111 1 0101) 0 1000(0 1010 1 1011) 0 1000(1 1011 01010) (1 0001 1 1011)54Chapter 1 section 1.1 by Dr. Mosaad HassanCS 103 Discrete Structures Lecture 04Logic and Proofs (3)55Chapter 1 section 1.1 by Dr. Mosaad HassanPropositional EquivalencesSection 1.356Section SummaryTautologies, Contradictions, and Contingencies. Logical EquivalenceImportant Logical EquivalencesShowing Logical Equivalence

57Propositional EquivalencesCompound propositions can be classified according to their possible truth values into three types:Tautology is a compound proposition that is always true, no matter what the truth values of the propositions that occur in itContradiction is a compound proposition that is always falseContingency is a compound proposition that is neither a tautology nor a contradictionTautologies and contradictions are often important in mathematical reasoning.Tautology and Contradiction: ExampleWe can construct examples of tautologies and contradictions using just one propositional variable

p p is a tautology. p p is a contradictionppp p p p TFTFFTTFLogical Equivalence: p q Compound propositions that have the same truth values in all possible cases are called logically equivalent

Definition: The compound propositions p and q are called logically equivalent if p q is a tautology.

The notation p q denotes that p and q are logically equivalent.The symbol is not a logical connective and p q is not a compound proposition but rather is the statement that p q is a tautologypqpq(pq)(pq)pqTTFFTFFTFFTTFFFTTFTFFFFTTFTTLogical Equivalence: Example 1Show that (p q) and p q are logically equivalent

Columns in the truth table giving the truth values of(p q) and p q agree. Thus, (p q) p q

Note that (p q) (p q) is a tautology Logical Equivalence: Example 2Show that p q and p q are logically equivalent.

Note that (p q) (p q) is a tautology pq pp qp qTTFTTTFFFFFTTTTFFTTTLogical Equivalence: Example 3Show that p (q r) and (p q) (p r) are logically equivalent

This is the distributive law of disjunction over conjunction

Number of Rows in a Truth TableHow many rows are there in a truth table with n propositional variables?

Solution: 2n We will see how to do this in Chapter 6.

Note that this means that with n propositional variables, we can construct 2n distinct (i.e., not equivalent) propositions. 64LogicalEquivalenceThis table shows some important equivalences.

T denotes the compound proposition that is always true

F denotes the compound proposition that is always false

Logical Equivalence:De Morgan's Laws De Morgans laws tell us how to negate conjunctions and disjunctions

(p q) p q

(p q) p q

De Morgans Laws: Example 1Determine the negation of Ahmed has a cellphone and he has a laptop computer

Letp: Ahmed has a cellphoneq: Ahmed has a laptop computer

Then Ahmad has a cellphone and he has a laptop computer can be represented by p q

By the first De Morgan's laws, (p q) p q

Therefore, the negation of our original statement is Ahmed does not have a cellphone or he does not have a laptop computerDe Morgans Laws: Example 2Determine the negation of Ali will go to the university or Mohammad will go to the university

Letp: Ali will go to the universityq: Mohammad will go to the university

Then Ali will go to the university or Mohammad will go to the university can be represented by p q

By the first De Morgan's laws, (p q) p q

The negation of our original statement is Ali will not go to the university and Mohammad will not go to the universityVerifying Logical EquivalencesTruth Tables are one way of verifying logical equivalencesWe can show that two expressions are logically equivalent by developing a series of logically equivalent statementsTo prove that A B we produce a series of equivalences beginning with A and ending with B

Example 1: Show that (p q) p q

(p q) (p q)Definition of implication (p) qDe Morgans law p qDouble-negationA A1...An BVerifying Logical Equivalences: Example 2Show that (p r) (q r) and (p q) r are logically equivalent

(p r) (q r) (p r) (q r) Definition of implication p r q rAssociative p q r rCommutative (p q) (r r)Associative (p q) rDe Morgan, Idempotent (p q) r Definition of implicationVerifying Logical Equivalences: Example 3Prove that (p q) (p q) is a Tautology

(p q) (p q) (p q) (p q)Implication (p q) (p q)De Morgans (p p) (q q)Commutative, Associative T TIdentity TUsing a Truth Table to Show Non-Equivalence: ExampleUse a truth table to show that neither the converse nor inverse of an implication are equivalent to the implication

Solution: pq p qp q p qq p TTFFTTTTFFTFTTFTTFTFFFFTTTTT73Notation for Multiple Conjunctions and Disjunctions

74Section 1.3 ExercisesUse truth tables to verify these equivalences:

Use De Morgan's laws to find the negation of each of the following statements:Ahmad is rich and happy.Ali will bicycle or run tomorrow.Mohammad walks or takes the bus to class.Ibrahim is smart and hard working.

Show that each of these conditional statements is a tautology by using truth tables

Show that each of the following compound propositions are logically equivalent:

p q and (p q) (p q) (p q) and p q(p q) and p q (p q) (p r) and p (q r)p (q r) and q (p r)(p q) r and p (q r) (p q) r and (p r) (q r) (p q) (r s)and(p r) (q s)Exercise 4.a: Solutionp q and (p q) (p q)

p q (p q) (q p) Definition of bi-implication (p q) (q p) Definition of implication [(p q) q] [(p q) p]Distributive [(p q) (q q)] [(p p) (q p)] Distributive [(p q) F] [F (q p)]Negation (p q) (q p)Identity (p q) (p q)Commutative (p q) (p q)CommutativeChapter 1 section 1.2 by Dr. Mosaad Hassan78