Download presentation

Presentation is loading. Please wait.

1
**CS 103 Discrete Structures Lecture 02**

Logic and Proofs (1) Chapter 1 section 1.1 by Dr. Mosaad Hassan

2
**The Foundations: Logic and Proofs**

Chapter 1, Part I: Propositional Logic

3
**Chapter Summary Propositional Logic Predicate Logic Proofs**

The Language of Propositions Applications Logical Equivalences Predicate Logic The Language of Quantifiers Nested Quantifiers Proofs Rules of Inference

4
**Propositional Logic Summary**

The Language of Propositions Connectives Truth Values Truth Tables Applications Translating English Sentences Logic Circuits Logical Equivalences Important Equivalences Verifying Equivalence

5
Propositional Logic Section 1.1

6
**Section Summary Propositions Connectives Truth Tables Negation**

Conjunction Disjunction Implication; contrapositive, inverse, converse Biconditional Truth Tables

7
Rules and Logic Rules of logic specify the meaning of mathematical statements They are used to distinguish between valid and invalid mathematical arguments They are also used in the design of computer circuits, the construction of computer programs, and the verification of the correctness of programs Example: If you get 100% on the final, then you get an A Logic is the basis of all mathematical and automated reasoning It 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.

8
**Proofs and Theorems Proof 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 values show that an algorithm always produces the correct result establish the security of a system Theorem is a mathematical statement built using other correct mathematical statements

9
**Propositional Logic Basic building blocks of logic are propositions**

A 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 = 2 2 + 2 = 3 Propositions 1 and 2 are true, whereas 3 and 4 are false Chapter 1 section 1.1 by Dr. Mosaad Hassan

10
**Propositional Logic The following are not propositions:**

What time is it? Read this carefully x + 1 = 2 x + y = z 1 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.

11
**Propositional Variables**

Propositional 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

12
**Compound Propositions**

They 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 p ¬p T F

13
**Negation (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 Friday Today is not Friday It is not Friday today Exercise: Find the negation of: At least 10 students attended today’s class Taibah University is in Madinah Munawwarah

14
**Conjunction (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 p q p ∧ q T F

15
**Conjunction (AND) Operator **

Example: Find the conjunction of the propositions p and q where: p: Today is Friday q: It is raining today Solution: 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

16
**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 p q p ∨q T F

17
**Disjunction (OR) Operator **

Example: Find the disjunction of the propositions p and q where: p: Today is Friday q: It is raining today Solution: The disjunction p v q is the proposition Today is Friday or it is raining today This 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 rain

18
**Disjunction: 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 class That is, students who can take the class are: Who have taken both calculus and computer science, Who have taken calculus Who have taken computer science

19
**Disjunction: 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 class That is, students that can take the class are: Who have taken calculus, Who have taken computer science Students who have taken both calculus and a computer science course cannot take the class enroll : يسجل Chapter 1 section 1.1 by Dr. Mosaad Hassan

20
**Exclusive 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 q p ⊕q T F Chapter 1 section 1.1 by Dr. Mosaad Hassan

21
**Conditional Statement: Implication**

Definition: 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 false True otherwise p → q is true when: Both p and q are true, or if p is false (no matter what truth value q has) p q p →q T F Chapter 1 section 1.1 by Dr. Mosaad Hassan

22
**Hypothesis → Conclusion**

In 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 q if p, q p is sufficient for q q if p q when p a necessary condition for p is q q unless ¬p p implies q p only if q a sufficient condition for q is p q whenever p q is necessary for p q follows from p Chapter 1 section 1.1 by Dr. Mosaad Hassan

23
Implication: Example Let p be the statement Ahmed learns discrete structures and q the statement Ahmed will find a good job. Express the statement p → q in English Solution: The statement p → q can be expressed in English in several ways: If Ahmed learns discrete mathematics, then he will find a good job Ahmed will find a good job when he learns discrete mathematics For Ahmed to get a good job, it is sufficient for him to learn discrete mathematics Ahmed will find a good job unless he does not learn discrete mathematics Note: if-then construction used in many programming languages is different from that used in logic Chapter 1 section 1.1 by Dr. Mosaad Hassan

24
**Converse, 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 equivalent The converse and the inverse of a conditional statement are also equivalent Chapter 1 section 1.1 by Dr. Mosaad Hassan

25
**Contrapositive: Example**

Find contrapositive of the conditional statement: The home team wins whenever it is raining q whenever p is the implication p → q p: it is raining q: the home team wins The 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 raining Chapter 1 section 1.1 by Dr. Mosaad Hassan

26
**Converse 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 statement Chapter 1 section 1.1 by Dr. Mosaad Hassan

27
**CS 103 Discrete Structures Lecture 03**

Logic and Proofs (2) Chapter 1 section 1.1 by Dr. Mosaad Hassan

28
**Bi-conditional or Bi-implication**

Definition: 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 values False otherwise p q p ↔q T F Chapter 1 section 1.1 by Dr. Mosaad Hassan

29
**Bi-conditional or Bi-implication**

Example: Let p: You can take the flight q: You buy a ticket Then p q is the statement: You can take the flight if and only if you buy a ticket The same can also be expressed as: p is necessary and sufficient for q if p then q, and conversely p iff q Note that p q has exactly the same truth value as (p → q) (q → p) Chapter 1 section 1.1 by Dr. Mosaad Hassan

30
**Logical Operators: Summary**

Negation (true if p is false) NOT Conjunction (true if p and q are true) AND Inclusive Disjunction (true if p or q or both are true) OR Exclusive Disjunction (true if p and q are different) XOR Implication (false if p is true and q is false) → Bi-Implication (true if p and q are the same) XNOR Chapter 1 section 1.1 by Dr. Mosaad Hassan

31
**Truth Tables for Compound Propositions: Example**

Construct the truth table of the compound proposition: (p ¬q) → (p q) Solution Chapter 1 section 1.1 by Dr. Mosaad Hassan

32
**Truth Tables For Compound Propositions**

Rows Need a row for every possible combination of values for the atomic propositions. Columns Need 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

33
**Truth Tables for Compound Propositions: Exercises**

Construct 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) Chapter 1 section 1.1 by Dr. Mosaad Hassan

34
**Precedence of Logical Operators**

We 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 the following have the same meaning? p q → r (p q) → r p (q → r) Operator Precedence 1 2 3 4 5 Chapter 1 section 1.1 by Dr. Mosaad Hassan

35
**Bits and Boolean Variables**

Computers represent information using bits A bit may have one of two values: 0, 1 There 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. Chapter 1 section 1.1 by Dr. Mosaad Hassan

36
**Bit Operations Bit Operations correspond to Logical Connectives**

After replacing true by 1 and false by 0 in the truth tables, we can use the bit operators OR, AND, and XOR as follow: Chapter 1 section 1.1 by Dr. Mosaad Hassan

37
**Bit Strings and Bitwise Operations**

A bit string is a sequence of zero or more bits. The length of this string is the number of bits in the string. 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 strings Similarly for bitwise AND and bitwise XOR We use the symbols , , and to represent the bitwise OR, bitwise AND, and bitwise XOR operations, respectively Chapter 1 section 1.1 by Dr. Mosaad Hassan

38
**Bitwise Operations: Example**

Find the bitwise OR, bitwise AND, and bitwise XOR of the bit strings: and 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 Chapter 1 section 1.1 by Dr. Mosaad Hassan

39
**Applications of Propositional Logic**

Section 1.2

40
**Examples of Applications of Propositional Logic**

Translating English to propositional logic Electronic logic circuits

41
**Translating English Sentences**

Statements/sentences in English (and every other natural language) are often ambiguous. Translating sentences into compound propositions can be used to remove ambiguity Translation 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 values Manipulate them Use rules of inference Chapter 1 section 1.1 by Dr. Mosaad Hassan

42
**Translating English Sentences: Example 1**

Translate 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 freshman Solution: Representing this sentence by a single propositional variable, such as p, is not useful Instead, we will use propositional variables to represent each sentence part and determine the appropriate logical connectives between them. Let p: you can access the internet from campus q: you are a computer science major r: you are a freshman Then the required expression is p → (q ¬r) Chapter 1 section 1.1 by Dr. Mosaad Hassan

43
**Translating English Sentences: Example 2**

Translate 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 Let p: You can ride the roller coaster q: You are under 4 feet tall r: You are older than 16 years Then, the sentence can be translated to (q ¬r) → ¬p roller coaster : السفينة الدوارة Chapter 1 section 1.1 by Dr. Mosaad Hassan

44
**Electronic Logic Circuits**

In electronic logic circuits, each input/output signal is viewed as a 0 or 1, where 0 represents False and 1 represents True Complex circuits are constructed from three basic circuits called gates The NOT gate (inverter) takes an input and produces its negation The OR gate takes two inputs and produces the value equivalent to the disjunction of those two inputs The AND gate takes two inputs and produces the value equivalent to the conjunction of those two inputs Complex digital circuits are constructed by combining these basic gates to produce the desired output given the input signals

45
**Sections 1.1 and 1.2 Exercises**

Which of these sentences are propositions? What are the truth values of those that are propositions? 2 + 3 = 5 x + 2 = 11 Answer this question What time is it? 2n ≤ 100 Jeddah is the capital of Saudi Arabia Kaaba exists in Makkah. You are younger than your son. Chapter 1 section 1.1 by Dr. Mosaad Hassan

46
**Find the negation of each of these propositions?**

Today is Thursday. 2 + 1 = 3 The summer in Egypt is hot and sunny. Let p and q be two propositions p: I received my UK visa this week q: I’m going to the UK on next Friday Express the following propositions as English sentences. ¬p p q p → q p q p q ¬p → ¬q ¬p ¬ q ¬ p (p q) Chapter 1 section 1.1 by Dr. Mosaad Hassan

47
**p : It is below freezing q : It is snowing**

Let p and q be the propositions p : It is below freezing q : It is snowing Write 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. Chapter 1 section 1.1 by Dr. Mosaad Hassan

48
**Coffee or tea comes with dinner. **

For 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. Chapter 1 section 1.1 by Dr. Mosaad Hassan

49
**The Red Wings will win the Stanley Cup if their goalie plays well. **

Write 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 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. Chapter 1 section 1.1 by Dr. Mosaad Hassan

50
**If it snows today, I will ski tomorrow. **

State 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. Chapter 1 section 1.1 by Dr. Mosaad Hassan

51
**Construct the truth table for each of the following compound propositions:**

Chapter 1 section 1.1 by Dr. Mosaad Hassan

52
**Construct a truth table for each of these compound propositions.**

Chapter 1 section 1.1 by Dr. Mosaad Hassan

53
**Construct a truth table for each of these compound propositions.**

Chapter 1 section 1.1 by Dr. Mosaad Hassan

54
**Evaluate each of the following expressions.**

Find the bitwise OR, bitwise AND, and bitwise XOR for each pair of bit strings. Evaluate each of the following expressions. ( ) ( ) ( ) ( 01010) ( ) Chapter 1 section 1.1 by Dr. Mosaad Hassan

55
**CS 103 Discrete Structures Lecture 04**

Logic and Proofs (3) Chapter 1 section 1.1 by Dr. Mosaad Hassan

56
**Propositional Equivalences**

Section 1.3

57
**Section Summary Tautologies, Contradictions, and Contingencies.**

Logical Equivalence Important Logical Equivalences Showing Logical Equivalence

58
**Propositional Equivalences**

Compound 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 it Contradiction is a compound proposition that is always false Contingency is a compound proposition that is neither a tautology nor a contradiction Tautologies and contradictions are often important in mathematical reasoning.

59
**Tautology and Contradiction: Example**

We can construct examples of tautologies and contradictions using just one propositional variable p ¬p is a tautology. p ¬p is a contradiction p ¬p p ∨¬p p ∧¬p T F

60
**Logical 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 tautology

61
**Logical Equivalence: Example 1**

Show 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 p q ¬p ¬q (p∨q) ¬(p∨q) ¬p∧¬q T F

62
**Logical Equivalence: Example 2**

Show that ¬p q and p → q are logically equivalent. Note that (¬p q) (p → q) is a tautology p q ¬p ¬p ∨ q p→ q T F

63
**Logical Equivalence: Example 3**

Show that p (q r) and (p q) (p r) are logically equivalent This is the distributive law of disjunction over conjunction

64
**Number of Rows in a Truth Table**

How 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.

65
Logical Equivalence This table shows some important equivalences. T denotes the compound proposition that is always true F denotes the compound proposition that is always false

67
**Logical Equivalence: De Morgan's Laws**

De Morgan’s laws tell us how to negate conjunctions and disjunctions ¬(p q) ¬p ¬q ¬(p q) ¬p ¬q

68
**De Morgan’s Laws: Example 1**

Determine the negation of Ahmed has a cellphone and he has a laptop computer Let p: Ahmed has a cellphone q: 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 computer

69
**De Morgan’s Laws: Example 2**

Determine the negation of Ali will go to the university or Mohammad will go to the university Let p: Ali will go to the university q: 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 university

70
**Verifying Logical Equivalences**

Truth Tables are one way of verifying logical equivalences We can show that two expressions are logically equivalent by developing a series of logically equivalent statements To 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) ¬q De Morgan’s law p ¬q Double-negation A A1 . An B

71
**Verifying Logical Equivalences: Example 2**

Show 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 r Associative p q r r Commutative (p q) (r r) Associative (p q) r De Morgan, Idempotent (p q) r Definition of implication

72
**Verifying Logical Equivalences: Example 3**

Prove that (p q) (p q) is a Tautology (p q) (p q) (p q) (p q) Implication (p q) (p q) De Morgan’s (p p) (q q) Commutative, Associative T T Identity T

73
**Using a Truth Table to Show Non-Equivalence: Example**

Use a truth table to show that neither the converse nor inverse of an implication are equivalent to the implication Solution: p q ¬ p ¬ q p →q ¬ p →¬ q q → p T F

74
**Notation for Multiple Conjunctions and Disjunctions**

75
**Section 1.3 Exercises Use 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.

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

77
**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)

78
Exercise 4.a: Solution p 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) Commutative Chapter 1 section 1.2 by Dr. Mosaad Hassan

Similar presentations

© 2019 SlidePlayer.com Inc.

All rights reserved.

To make this website work, we log user data and share it with processors. To use this website, you must agree to our Privacy Policy, including cookie policy.

Ads by Google