CS 220: Discrete Structures and their Applications

Slides:



Advertisements
Similar presentations
Artificial Intelligence
Advertisements

Discrete Mathematics Lecture 1 Logic of Compound Statements Harper Langston New York University.
1 Section 1.1 Logic. 2 Proposition Statement that is either true or false –can’t be both –in English, must contain a form of “to be” Examples: –Cate Sheller.
Discrete Mathematics Math 6A Instructor: M. Welling.
Logic Gates Circuits to manipulate 0’s and 1’s. 0’s and 1’s used for numbers Also to make decisions within the computer. In that context, 1 corresponds.
Adapted from Discrete Math
Predicates and Quantifiers
Chapter 1 -- The Foundations: Logic and Proof, Sets and Functions
The Foundations: Logic and Proofs
Discrete Mathematics Goals of a Discrete Mathematics Learn how to think mathematically 1. Mathematical Reasoning Foundation for discussions of methods.
2009/9 1 Logic and Proofs §1.1 Introduction §1.2 Propositional Equivalences §1.3 Predicates and Quantifiers §1.4 Nested Quantifiers §1.5~7 Methods of Proofs.
MATH 213 A – Discrete Mathematics for Computer Science Dr. (Mr.) Bancroft.
Discrete Mathematics and Its Applications
Computer Science 101 The Boolean System. George Boole British mathematician ( ) Boolean algebra –Logic –Set theory –Circuits –Conditions in if.
CS 285- Discrete Mathematics Lecture 2. Section 1.1 Propositional Logic Propositions Conditional Statements Truth Tables of Compound Propositions Translating.
Chapter 1: The Foundations: Logic and Proofs
Copyright © Curt Hill Using Propositional Logic Several applications.
Applications of Propositional Logic
Computer Science 210 Computer Organization Introduction to Boolean Algebra.
MATH 224 – Discrete Mathematics
Propositional Calculus CS 270: Mathematical Foundations of Computer Science Jeremy Johnson.
1 Introduction to Abstract Mathematics Expressions (Propositional formulas or forms) Instructor: Hayk Melikya
Thinking Mathematically
Chapter 1: The Foundations: Logic and Proofs
LECTURE 1. Disrete mathematics and its application by rosen 7 th edition THE FOUNDATIONS: LOGIC AND PROOFS 1.1 PROPOSITIONAL LOGIC.
Section 1.1. Propositions A proposition is a declarative sentence that is either true or false. Examples of propositions: a) The Moon is made of green.
Chapter 1. Chapter Summary  Propositional Logic  The Language of Propositions (1.1)  Logical Equivalences (1.3)  Predicate Logic  The Language of.
Discrete Structures for Computer Science Presented By: Andrew F. Conn Slides adapted from: Adam J. Lee Lecture #1: Introduction, Propositional Logic August.
Chapter 1 Propositional Logic
Logic.
Digital Logic.
Morgan Kaufmann Publishers
Conditional Statements
Computer Science 210 Computer Organization
DISCRETE MATHEMATICS CHAPTER I.
Discrete Mathematics Lecture 1 Logic of Compound Statements
Lecture 1 – Formal Logic.
Discrete Mathematics Logic of Compound Statements
CS 202, Spring 2008 Epp, sections 1.1 and 1.2
Niu Kun Discrete Mathematics Chapter 1 The Foundations: Logic and Proof, Sets, and Functions Niu Kun 离散数学.
CPCS222 Discrete Structures I
Logics for Data and Knowledge Representation
CMSC Discrete Structures
Propositional Calculus: Boolean Functions and Expressions
The Foundations: Logic and Proofs
Principles of Computing – UFCFA3-30-1
Propositional Calculus: Boolean Algebra and Simplification
Information Technology Department
Applications of Propositional Logic
Chapter 1 The Foundations: Logic and Proof, Sets, and Functions
CHAPTER 1: LOGICS AND PROOF
Computer Science 210 Computer Organization
CSRU 1400 Discrete Structure: Logic
Propositional Equivalences
TRUTH TABLES.
Applied Discrete Mathematics Week 1: Logic
Discrete Mathematics and Its Applications Kenneth H
Discrete Mathematics Lecture 2: Propositional Logic
MAT 3100 Introduction to Proof
Discrete Mathematics Lecture 2: Propositional Logic
Section 3.7 Switching Circuits
Predicates and Quantifiers
This Lecture Substitution model
The Foundations: Logic and Proofs
Copyright © Cengage Learning. All rights reserved.
Discrete Structures Prepositional Logic 2
Logical and Rule-Based Reasoning Part I
The Foundations: Logic and Proofs
Propositional Logic Computational Logic Lecture 2
Truth tables.
Presentation transcript:

CS 220: Discrete Structures and their Applications Propositional Logic Sections 1.1-1.2 in zybooks

Logic in computer science Used in many areas of computer science: Booleans and Boolean expressions in programs Reasoning about programs, proving program correctness Artificial intelligence (AI) Hardware design

Propositional Logic A proposition is a statement that is either true or false. Examples of propositions: Two plus two is four. Toronto is the capital of Canada. There is an infinite number of primes. Not propositions: What time is it? Have a nice day! A proposition's truth value is a value indicating whether the proposition is true or false. proposition: statement of fact

Propositional variables We can use propositional variables to represent propositions. Examples: p: January has 31 days. q: February has 33 days.

Conjunction Example: p: January has 31 days. q: February has 33 days. p ∧ q: January has 31 days and February has 33 days.

There are many ways of saying that in English! Define the propositional variables p and h as: p: Sam is poor. h: Sam is happy. There are many ways to express the proposition p ∧ h in English: Sam is poor and he is happy. Sam is poor, but he is happy. Despite the fact that he is poor, Sam is happy. Although Sam is poor, he is happy.

Compound propositions: the conjunction In Java and Python propositions are logical expressions, that can form compound propositions using logical operators such as and, or, and not. For example in Python you can write something like: >>> (5 >= 0) and (5 <= 10) We do the same in propositional logic, except we have different notations for the operators. Don’t be intimidated by notation! Let p and q be propositions. The conjunction of p and q is denoted by p ∧ q. p ∧ q is true if both p and q are true. In English, this is the statement “p and q”

Formal definition of the conjunction operator We can define an operator using its truth table. A truth table shows the truth value of a compound proposition for every possible combination of truth values for the variables contained in it. p q p  q T F

The disjunction operator The disjunction operation is denoted by . The proposition p  q is read "p or q” . p  q is true if either one of p or q is true, or if both are true, and is false otherwise. Notice that T  T = T. We call  the “inclusive or” operator. p q p  q T F

Exclusive OR (XOR) p q p  q T F When a parent tells their child – “you can have chocolate or a lollypop”, they likely mean that the child can have one of the two but NOT both. This corresponds to the exclusive or logical operator. p q p  q T F The exclusive or of logical statements p and q is denoted by p  q

Negation Let p be a proposition. The negation of p is denoted by ¬p In English, this is the statement “not p” p ¬p T F

Summary of operator truth tables q p  q p  q p  q p T F

Truth Tables in Python a b a and b a or b a^b not a True False Notice the different notation for the operators. Here a and b are Boolean (bool) variables.

Compound propositions Let’s evaluate a proposition composed of multiple operations such as: (p  (¬q))  r where the variables have the values: p:F, q:F, r:F (F  (¬F))  F (F  T)  F (T)  F F

Compound propositions In the absence of parentheses how do we evaluate this proposition? p  ¬q  r Possible choices: (p  ¬q)  r p  (¬q  r) p  ¬(q  r)

Compound propositions In the absence of parentheses how do we evaluate this proposition? p  ¬q  r Possible choices: (p  ¬q)  r p  (¬q  r) p  ¬(q  r) Like in arithmetic, operators have precedence: Negation (¬) Conjunction () Disjunction ()

Exclusive or Question: What does abc mean? 1. (ab) c 2. a(bc) 3. 1 and 2 are the same Build truth table

Arithmetic and Logic The operator precedence in logic mirrors that of arithmetic: Negation (¬) Minus sign (-) Conjunction () Multiplication (*) Disjunction () Addition (+) In fact, when you do arithmetic over the bits 0 and1, there is a correspondence between conjunction and multiplication, and disjunction and addition (but 1+1=1). Not exactly identical (bits, not numbers) You will explore this correspondence more in CS270, when you discuss logical circuits.

Compound propositions When constructing the truth table for a compound proposition such as ¬q  ( p  r ) it is helpful to use intermediate columns. Do it: p q r ¬q ( p  r ) ¬q  ( p  r ) T F

Compound propositions When constructing the truth table for a compound proposition such as ¬q  ( p  r ) it is helpful to use intermediate columns: p q r ¬q ( p  r ) ¬q  ( p  r ) T F

Compound propositions q q p q p  q (p q)  (p  q) T F

Compound propositions q q p q p  q (p q)  (p  q) T F

From English to propositional logic Consider the following pieces of identification a person might have in order to apply for a credit card: B: Applicant presents a birth certificate. D: Applicant presents a driver's license. M: Applicant presents a marriage license. Write a logical expression for the requirements under the following conditions: The applicant must present either a birth certificate, or a driver's license, or a marriage license.

From English to propositional logic Consider the following pieces of identification a person might have in order to apply for a credit card: B: Applicant presents a birth certificate. D: Applicant presents a driver's license. M: Applicant presents a marriage license. Write a logical expression for the requirements under the following conditions: The applicant must present at least two of the following forms of identification: birth certificate, driver's license, marriage license.

From English to propositional logic Consider the following pieces of identification a person might have in order to apply for a credit card: B: Applicant presents a birth certificate. D: Applicant presents a driver's license. M: Applicant presents a marriage license. Write a logical expression for the requirements under the following conditions: Applicant must present either a birth certificate or both a driver's license and a marriage license.

How many rows in that truth table? p q r ( p  r )  ¬q T F How many rows are there in a truth table with 3 variables? With 4 variables, 5? n?

Exercises Describe in words when the expression p  q  r  s  t is true and when it is false. Describe in words when the expression p  q  r  s  t is true and when it is false.

A puzzle Knights and knaves. An island has two types of inhabitants: knights, who always tell the truth, and knaves, who always lie. You encounter two people, A and B. A says: “B is a knight” B says: “The two of us are opposite types” Can you figure out what A and B are? Assume knight(A) then knight(B) but then contradiction so not(knight(A)) So knave(A) therefore knave(B), therefore B lies (OK)

A puzzle Knights and knaves. An island has two types of inhabitants: knights, who always tell the truth, and knaves, who always lie. You encounter two people, A and B. A says: “We are both knaves” Can you figure out what A and B are? What “proof rule” did you (implicitly?) use? we’ll come back to proof rules Assume knight(A), then knave(a) contradiction, therefore knave(a) therefore knight(b)