680 likes | 1.54k Views
CS 103 Discrete Structures Lecture 01 Introduction Logic and Proofs (1). CS 103 Discrete Structures. Textbook Discrete Mathematics and Its Applications, 7th ed. By K. Rosen Attendance 75% in is mandatory You are not allowed to miss lectures for the exams of other courses
E N D
CS 103Discrete StructuresLecture 01 Introduction Logic and Proofs (1)
CS 103 Discrete Structures Textbook • Discrete Mathematics and Its Applications, 7th ed. By K. Rosen Attendance • 75% in is mandatory • You are not allowed to miss lectures for the exams of other courses Grade Breakup • Homework: 10% • Two Midterm Exams: 25% each (6-7 wk, 11-12 wk) • Comprehensive Final Exam: 40%
Midterm Exam • 75 minute duration • Will cover all lectures delivered before the exam date • Will consist of MCQ’s, fill-in-the-blanks, questions with short answers, writing of proofs, and drawing of diagrams • If you miss any of these exams for any reason, you will have to appear for a makeup exam on the Thursday of the last week of teaching. This exam will cover all lectures delivered in the semester. It will consist of writing proofs, drawing of diagrams and answering questions having 0.5-1 page answers.
How to do well in this course? • BEFORE EVERY LECTURE • Read the relevant portion of the textbook • DURING EVERY LECTURE • Ask questions if anything is not clear • AFTER EVERY LECTURE • Review the lecture slides. IF anything is not clear THEN (discuss it with your fellow students)AND (ask me about it at the beginning of the next lecture OR visit me in my office during office hours OR email me about it) • Solve all exercises assigned after each section • IF unable to solve, THEN ask me for help
Course contents • Logic and proofs • Sets, Functions, and Relations • Mathematical induction • Counting • Discrete probability • Relations • Graph theory • Trees • Boolean algebra
What are Discrete Structures? • Structures that are naturally discrete and not continuous • Integer are discrete. They have distinct values. They are non-continuous. • Real numbers are not discrete but continuous. They can vary smoothly and continuously. • Discrete: Cars, books, students in a class • Continuous: Gasoline in a car, width of a book, weight of a student
What is Discrete Mathematics? • Discrete mathematics is mathematics that deals with discrete structures. • In it we learn the concepts associated with discrete objects, their properties, and relationships. • We can view it as the mathematics that is necessary for decision making in non-continuous situations
Five Themes of Discrete Mathematics • Mathematical Reasoning • Combinatorial Analysis • Discrete Structures • Algorithmic Thinking • Applications and Modeling
Five Themes of Discrete Mathematics • Mathematical Reasoning Understanding mathematical reasoning in order to: • Read, comprehend, and construct mathematical arguments. • Construct proofs by using mathematical induction which is a valid proof technique. • Combinatorial Analysis • Discrete Structures • Algorithmic Thinking • Applications and Modeling
Five Themes of Discrete Mathematics • Mathematical Reasoning • Combinatorial Analysis An important problem-solving skill is the ability to count or enumerate objects. • How student can perform combinatorial analysis to solve counting problems and analyze algorithms, not on applying formulae. • Discrete Structures • Algorithmic Thinking • Applications and Modeling
Five Themes of Discrete Mathematics • Mathematical Reasoning • Combinatorial Analysis • Discrete Structures How to work with discrete structures used to represent discrete objects and relationships between these objects. • These discrete structures include sets, permutations, relations, graphs, trees, and finite-state machines. • Algorithmic Thinking • Applications and Modeling
Five Themes of Discrete Mathematics • Mathematical Reasoning • Combinatorial Analysis • Discrete Structures • Algorithmic Thinking Some problems are solved by designing an algorithm. Afterwards a program can be written to implement the algorithm • All activities that include algorithm specification, verification, and analysis (of memory and time required to perform it) are covered in this course. • Applications and Modeling
Five Themes of Discrete Mathematics • Mathematical Reasoning • Combinatorial Analysis • Discrete Structures • Algorithmic Thinking • Applications and Modeling Discrete mathematics has applications in a large number of areas. • Examples: computer science, data networking, chemistry, business, and the Internet. Modeling with discrete mathematics is an important problem-solving skill.
Chapter 1 The Foundations:Logic and Proofs1.1 Propositional Logic
Rules and Logic Rulesof 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 Logicis 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.
Proofs and Theorems Proofis 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
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
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.
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
Compound Propositions They are formed or constructed by combining one or more existing propositions using logical operators. 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
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 attend today in class • Taibah University is in Madinah Monawwarah
Truth Table Example: Truth Table for ¬p
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 • False otherwise
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 pq 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
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.
Disjunction: Inclusive OR Connective or is used in two ways: • Inclusive Or (normal 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
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
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: • Truewhen exactly one of p and q is true • Falseotherwise
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 • And p is false • (no matter what truth value q has)
Premise → Consequence • In the conditional statement p → q: • p is called the hypothesis (antecedent or premise) • q is called the conclusion (or consequence) • 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
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
Converse, Contrapositive, and Inverse There are three related conditional statements to 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
Contrapositive Example: Find contrapositive of the conditional statement: The home team wins whenever it is raining q whenever pis 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 notwin, then it is notraining
Converse and Inverse Example: Find the converseand 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.
CS 103Discrete StructuresLecture 02 Logic and Proofs (2)
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.
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)
Truth Tables for Compound Propositions Example: Construct the truth table of the compound proposition: (p v ¬q) → (p q) Solution
Truth Tables for Compound Propositions Exercise: 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)
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 followinghave the same meaning? • p q →r • (p q) →r • p (q →r)
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.
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:
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. • 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 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
Bitwise Operations:Example Find 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
Chapter 1 The Foundations:Logic and Proofs1.2 Applications of Propositional Logic
Applications of Propositional Logic Example: 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
Translating English Sentences Example: 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)
Translating English Sentences Example: 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