1 Boolean Logic CS 202, Spring 2007 Epp, sections 1.1 and 1.2 Aaron Bloomfield.

Slides:



Advertisements
Similar presentations
TRUTH TABLES The general truth tables for each of the connectives tell you the value of any possible statement for each of the connectives. Negation.
Advertisements

1. Propositions A proposition is a declarative sentence that is either true or false. Examples of propositions: The Moon is made of green cheese. Trenton.
Logic Chapter 2. Proposition "Proposition" can be defined as a declarative statement having a specific truth-value, true or false. Examples: 2 is a odd.
Syllabus Every Week: 2 Hourly Exams +Final - as noted on Syllabus
Boolean Algebra Computer Science AND (today is Monday) AND (it is raining) (today is Monday) AND (it is not raining) (today is Friday) AND (it is.
1 Section 1.2 Propositional Equivalences. 2 Equivalent Propositions Have the same truth table Can be used interchangeably For example, exclusive or and.
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.
22C:19 Discrete Math Introduction and Scope Propositions Fall 2011 Sukumar Ghosh.
Logic Truth Tables, Propositions, Implications. Statements Logic is the tool for reasoning about the truth or falsity of statements. –Propositional logic.
TRUTH TABLES. Introduction Statements have truth values They are either true or false but not both Statements may be simple or compound Compound statements.
Logic ChAPTER 3.
Chapter 1, Part I: Propositional Logic With Question/Answer Animations.
The Foundations: Logic and Proofs
CSci 2011 Discrete Mathematics Lecture 3 CSci 2011.
Chapter 1 Section 1.4 More on Conditionals. There are three statements that are related to a conditional statement. They are called the converse, inverse.
The Foundations: Logic and Proofs
Discrete Maths 2. Propositional Logic Objective
CSE 20 DISCRETE MATH Prof. Shachar Lovett Clicker frequency: CA.
CS 285- Discrete Mathematics Lecture 2. Section 1.1 Propositional Logic Propositions Conditional Statements Truth Tables of Compound Propositions Translating.
Chapter 1 The Logic of Compound Statements. Section 1.1 Logical Form and Logical Equivalence.
CS 103 Discrete Structures Lecture 02
BY: MISS FARAH ADIBAH ADNAN IMK. CHAPTER OUTLINE: PART III 1.3 ELEMENTARY LOGIC INTRODUCTION PROPOSITION COMPOUND STATEMENTS LOGICAL.
CSci 2011 Textbook ^Discrete Mathematics and Its Applications,  Rosen  6th Edition  McGraw Hill  2006.
Review I Rosen , 3.1 Know your definitions!
Normal Forms, Tautology and Satisfiability 2/3/121.
Chapter 5 – Logic CSNB 143 Discrete Mathematical Structures.
(CSC 102) Lecture 3 Discrete Structures. Previous Lecture Summary Logical Equivalences. De Morgan’s laws. Tautologies and Contradictions. Laws of Logic.
Logical Form and Logical Equivalence Lecture 2 Section 1.1 Fri, Jan 19, 2007.
CS 2210 (22C:019) Discrete Structures Introduction and Scope: Propositions Spring 2015 Sukumar Ghosh.
Discrete Mathematics Lecture1 Miss.Amal Alshardy.
CSNB143 – Discrete Structure LOGIC. Learning Outcomes Student should be able to know what is it means by statement. Students should be able to identify.
LOGIC Lesson 2.1. What is an on-the-spot Quiz  This quiz is defined by me.  While I’m having my lectures, you have to be alert.  Because there are.
Chapter 7 Logic, Sets, and Counting
Conditional Statements
Propositional Logic. Propositions Any statement that is either True (T) or False (F) is a proposition Propositional variables: a variable that can assume.
Lecture 9 Conditional Statements CSCI – 1900 Mathematics for Computer Science Fall 2014 Bill Pine.
How do I show that two compound propositions are logically equivalent?
Chapter 7 Logic, Sets, and Counting Section 1 Logic.
Propositional Logic ITCS 2175 (Rosen Section 1.1, 1.2)
Logical Form and Logical Equivalence Lecture 1 Section 1.1 Wed, Jan 12, 2005.
Logical Form and Logical Equivalence M Logical Form Example 1 If the syntax is faulty or execution results in division by zero, then the program.
CS203 Discrete Mathematical Structures
Chapter 1: The Foundations: Logic and Proofs
The Foundations: Logic and Proof, Sets, and Foundations PROPOSITIONS A proposition is a declarative sentence that is either True or False, but not the.
Section 1.1. Section Summary Propositions Connectives Negation Conjunction Disjunction Implication; contrapositive, inverse, converse Biconditional Truth.
CSNB143 – Discrete Structure Topic 4 – Logic. Learning Outcomes Students should be able to define statement. Students should be able to identify connectives.
1 Boolean Logic CS/APMA 202, Spring 2005 Rosen, section 1.1 Aaron Bloomfield.
CSci 2011 Recap ^Propositional operation summary not andorconditionalBi-conditional pq ppqqpqpqpqpqpqpqpqpq TTFFTTTT TFFTFTFF FTTFFTTF FFTTFFTT.
Mathematics for Comter I Lecture 2: Logic (1) Basic definitions Logical operators Translating English sentences.
رياضيات متقطعة لعلوم الحاسب MATH 226. Text books: (Discrete Mathematics and its applications) Kenneth H. Rosen, seventh Edition, 2012, McGraw- Hill.
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.
Conditional Statements Lecture 2 Section 1.2 Fri, Jan 20, 2006.
Mathematics for Computing Lecture 2: Computer Logic and Truth Tables Dr Andrew Purkiss-Trew Cancer Research UK
Spring 2003CMSC Discrete Structures1 Let’s get started with... Logic !
3/6/20161 Let’s get started with... Logic !. 3/6/20162 Logic Crucial for mathematical reasoningCrucial for mathematical reasoning Used for designing electronic.
Conditional statement or implication IF p then q is denoted p ⇒ q p is the antecedent or hypothesis q is the consequent or conclusion ⇒ means IF…THEN.
Section 1.3 Implications. Vocabulary Words conditional operation ( ⇒ or →) conditional proposition conditional statement (implication statement) hypothesis.
1 Georgia Tech, IIC, GVU, 2006 MAGIC Lab Rossignac Lecture 01: Boolean Logic Sections 1.1 and 1.2 Jarek Rossignac.
Logic and Truth Tables Winter 2012 COMP 1380 Discrete Structures I Computing Science Thompson Rivers University.
Chapter 1. Chapter Summary  Propositional Logic  The Language of Propositions (1.1)  Logical Equivalences (1.3)  Predicate Logic  The Language of.
Chapter 1 Logic and proofs
Logical Operators (Connectives) We will examine the following logical operators: Negation (NOT,  ) Negation (NOT,  ) Conjunction (AND,  ) Conjunction.
Discrete Structures for Computer Science Presented By: Andrew F. Conn Slides adapted from: Adam J. Lee Lecture #1: Introduction, Propositional Logic August.
Propositional Equivalences
22C:19 Discrete Structures Introduction and Scope: Propositions
CS 2210:0001 Discrete Structures Introduction and Scope: Propositions
CS 202, Spring 2008 Epp, sections 1.1 and 1.2
COT 3100, Spr Applications of Discrete Structures
Information Technology Department
LOGICAL EQUIVALENCES - DISCRETE MATHEMATICS.
Presentation transcript:

1 Boolean Logic CS 202, Spring 2007 Epp, sections 1.1 and 1.2 Aaron Bloomfield

2 Administratrivia HW 1: due next Friday –Section 1.1 # 49, 52 –Section 1.2 # 34, 44, 46 Today’s lecture will be somewhat of a review Next week we will see applications of logic

3 Applications of Boolean logic Computer programs And computer addition Logic problems Sudoku

4 A proposition is a statement that can be either true or false –“The sky is blue” –“I is a Engineering major” –“x == y” Not propositions: –“Are you Bob?” –“x := 7” Boolean propositions

5 We use Boolean variables to refer to propositions –Usually are lower case letters starting with p (i.e. p, q, r, s, etc.) –A Boolean variable can have one of two values true (T) or false (F) A proposition can be… –A single variable: p –An operation of multiple variables: p  (q  r) Boolean variables

6 Introduction to Logical Operators About a dozen logical operators –Similar to algebraic operators + * - / In the following examples, –p = “Today is Friday” –q = “Today is my birthday”

7 Logical operators: Not A not operation switches (negates) the truth value Symbol:  or ~ In C++ and Java, the operand is !  p = “Today is not Friday” p pp TF FT

8 Logical operators: And An and operation is true if both operands are true Symbol:  –It’s like the ‘A’ in And In C++ and Java, the operand is && p  q = “Today is Friday and today is my birthday” pq pqpq TTT TFF FTF FFF

9 Logical operators: Or An or operation is true if either operands are true Symbol:  In C++ and Java, the operand is || p  q = “Today is Friday or today is my birthday (or possibly both)” pq pqpq TTT TFT FTT FFF

10 Logical operators: Exclusive Or An exclusive or operation is true if one of the operands are true, but false if both are true Symbol:  Often called XOR p  q  (p  q)  ¬(p  q) In Java, the operand is ^ (but not in C++) p  q = “Today is Friday or today is my birthday, but not both” pq pqpq TTF TFT FTT FFF

11 Inclusive Or versus Exclusive Or Do these sentences mean inclusive or exclusive or? –Experience with C++ or Java is required –Lunch includes soup or salad –To enter the country, you need a passport or a driver’s license –Publish or perish

12 Logical operators: Nand and Nor The negation of And and Or, respectively Symbols: | and ↓, respectively –Nand: p|q  ¬(p  q) –Nor: p↓q  ¬(p  q) pq pqpqpqpq p|qp|q pqpq TTTTFF TFFTTF FTFTTF FFFFTT

13 Logical operators: Conditional 1 A conditional means “if p then q” Symbol:  p  q = “If today is Friday, then today is my birthday” p→q  ¬p  q pq pqpq¬p  q TTTT TFFF FTTT FFTT the antecedent the consequence

14 Logical operators: Conditional 2 Let p = “I am elected” and q = “I will lower taxes” I state: p  q = “If I am elected, then I will lower taxes” Consider all possibilities Note that if p is false, then the conditional is true regardless of whether q is true or false pq pqpq TTT TFF FTT FFT

15 Logical operators: Conditional 3 ConditionalInverseConverseContra- positive pq pp qqpqpq  p  qqpqp  q  p TTFFTTTT TFFTFTTF FTTFTFFT FFTTTTTT

16 Logical operators: Conditional 4 Alternate ways of stating a conditional: –p implies q –If p, q –p is sufficient for q –q if p –q whenever p –q is necessary for p –p only if q I don’t like this one

17 Logical operators: Bi-conditional 1 A bi-conditional means “p if and only if q” Symbol:  Alternatively, it means “(if p then q) and (if q then p)” p  q  p  q  q  p Note that a bi-conditional has the opposite truth values of the exclusive or pq pqpq TTT TFF FTF FFT

18 Logical operators: Bi-conditional 2 Let p = “You take this class” and q = “You get a grade” Then p  q means “You take this class if and only if you get a grade” Alternatively, it means “If you take this class, then you get a grade and if you get a grade then you take (took) this class” pq pqpq TTT TFF FTF FFT

19 Boolean operators summary Learn what they mean, don’t just memorize the table! not andorxornandnorconditionalbi- conditional pq pp qqpqpqpqpqpqpq p|qp|q pqpqpqpqpqpq TTFFTTFFFTT TFFTFTTTFFF FTTFFTTTFTF FFTTFFFTTTT

20 Precedence of operators Just as in algebra, operators have precedence –4+3*2 = 4+(3*2), not (4+3)*2 Precedence order (from highest to lowest): ¬   → ↔ –The first three are the most important This means that p  q  ¬r → s ↔ t yields: (p  (q  (¬r))) ↔ (s → t) Not is always performed before any other operation

21 Translating English Sentences Problem: –p = “It is below freezing” –q = “It is snowing” It is below freezing and it is 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 pqpq p¬qp¬q ¬p¬q¬p¬q pqpq p→qp→q (pq)(p→¬q)(pq)(p→¬q) p↔qp↔q

22 Translation Example 1 Heard on the radio: –A study showed that there was a correlation between the more children ate dinners with their families and lower rate of substance abuse by those children –Announcer conclusions: If children eat more meals with their family, they will have lower substance abuse If they have a higher substance abuse rate, then they did not eat more meals with their family

23 Translation Example 1 Let p = “Child eats more meals with family” Let q = “Child has less substance abuse Announcer conclusions: –If children eat more meals with their family, they will have lower substance abuse p  q –If they have a higher substance abuse rate, then they did not eat more meals with their family  q   p Note that p  q and  q   p are logically equivalent

24 Translation Example 1 Let p = “Child eats more meals with family” Let q = “Child has less substance abuse” Remember that the study showed a correlation, not a causation pqresultconclusion TTTT TF?F FT?T FFTT

25 Translation Example 2 “I have neither given nor received help on this exam” –Rephrased: “I have not given nor received …” –Let p = “I have given help on this exam” –Let q = “I have received help on this exam” Translation is:  p  q pq pp pqpq TTFF TFFT FTTF FFTF

26 Translation Example 2 What they mean is “I have not given and I have not received help on this exam” –Or “I have not (given nor received) help on this exam” The problem:  has a higher precedence than  in Boolean logic, but not always in English Also, “neither” is vague pq  p  q (pq)(pq) TTFF TFFF FTFF FFTT

27 End of lecture on 19 January 2007

28 Boolean Searches (101 OR 202) AND bloomfield AND “computer science” Note that Google requires you to capitalize Boolean operators Google defaults to AND; many others do not –So the AND’s were optional XOR doesn’t work…

29 Bit Operations 1 Boolean values can be represented as 1 (true) and 0 (false) A bit string is a series of Boolean values – is eight Boolean values in one string We can then do operations on these Boolean strings –Each column is its own Boolean operation 

30 Bit Operations 2 Evaluate the following  (01011  11011) =  (11011) =  

31 && vs. & in C/C++ int p = 11; int q = 20; if ( p && q ) { } if ( p & q ) { } In C/C++, any value other than 0 is true Notice the double ampersand – this is a Boolean operation The binary for the integer 11 is The binary for the integer 20 is As p and q are both true, this is true Notice the single ampersand – this is a bitwise operation  This evaluates to zero (false)! Consider the following: Bitwise Boolean And operation:

32 && vs. & in C/C++ Note that Java does not have this “feature” –If p and q are int: p & q is bitwise p && q will not compile –If p and q are boolean: Both p & q and p && q will be a Boolean operation The same holds true for the or operators ( | and || ) in both Java and C/C++

33 Tautology and Contradiction A tautology is a statement that is always true –p  ¬p will always be true(Negation Law) A contradiction is a statement that is always false –p  ¬p will always be false(Negation Law) p p  ¬pp  ¬p TTF FTF

34 Logical Equivalence A logical equivalence means that the two sides always have the same truth values –Symbol is ≡  or  We’ll use ≡, so as not to confuse it with the bi- conditional

35 p  T ≡ pIdentity law p  F ≡ FDomination law Logical Equivalences of And pT pTpT TTT FTF pF pFpF TFF FFF

36 p  p ≡ pIdempotent law p  q ≡ q  pCommutative law Logical Equivalences of And pp pppp TTT FFF pq pqpqqpqp TTTT TFFF FTFF FFFF

37 (p  q)  r ≡ p  (q  r)Associative law Logical Equivalences of And pqr pqpq(p  q)  rqrqrp  (q  r) TTTTTTT TTFTFFF TFTFFFF TFFFFFF FTTFFTF FTFFFFF FFTFFFF FFFFFFF

38 p  T ≡ TIdentity law p  F ≡ pDomination law p  p ≡ pIdempotent law p  q ≡ q  pCommutative law (p  q)  r ≡ p  (q  r)Associative law Logical Equivalences of Or

39 Corollary of the Associative Law (p  q)  r ≡ p  q  r (p  q)  r ≡ p  q  r Similar to (3+4)+5 = Only works if ALL the operators are the same!

40 ¬(¬p) ≡ pDouble negation law p  ¬p ≡ TNegation law p  ¬p ≡ FNegation law Logical Equivalences of Not

41 DeMorgan’s Law Probably the most important logical equivalence To negate p  q (or p  q), you “flip” the sign, and negate BOTH p and q –Thus, ¬(p  q) ≡ ¬p  ¬q –Thus, ¬(p  q) ≡ ¬p  ¬q pq pp qqpqpq  (p  q)  p  qpqpq  (p  q)  p  q TTFFTFFTFF TFFTFTTTFF FTTFFTTTFF FFTTFTTFTT

42 Yet more equivalences Distributive: p  (q  r) ≡ (p  q)  (p  r) p  (q  r) ≡ (p  q)  (p  r) Absorption p  (p  q) ≡ p p  (p  q) ≡ p

43 How to prove two propositions are equivalent? Two methods: –Using truth tables Not good for long formulae In this course, only allowed if specifically stated! –Using the logical equivalences The preferred method Example: show that:

44 Using Truth Tables pqrp→rq →r (p→r)  (q →r)pqpq(p  q) →r TTTTTTTT TTFFFFTF TFTTTTFT TFFFTTFT FTTTTTFT FTFTFTFT FFTTTTFT FFFTTTFT pqpq(p→r)  (q →r) q →rp→rrqp

45 Idempotent Law Associativity of Or Definition of implication Using Logical Equivalences Re-arranging Original statement DeMorgan’s Law

46 Logical Thinking At a trial: –Bill says: “Sue is guilty and Fred is innocent.” –Sue says: “If Bill is guilty, then so is Fred.” –Fred says: “I am innocent, but at least one of the others is guilty.” Let b = Bill is innocent, f = Fred is innocent, and s = Sue is innocent Statements are: –¬s  f –¬b → ¬f –f  (¬b  ¬s)

47 Can all of their statements be true? Show: (¬s  f)  (¬b → ¬f)  (f  (¬b  ¬s)) bfs¬b¬f¬s ¬s  f ¬b→¬f ¬b  ¬sf  (¬b  ¬s) TTTFFFFTFF TTFFFTTTTT TFTFTFFTFF TFFFTTFTTF FTTTFFFFTT FTFTFTTFTT FFTTTFFTTF FFFTTTFTTF ¬b¬f¬s¬b→¬f f  (¬b  ¬s)¬b  ¬s¬s  f sfb

48 Are all of their statements true? Show values for s, b, and f such that the equation is true Original statement Definition of implication Associativity of AND Re-arranging Idempotent law Re-arranging Absorption law Re-arranging Distributive law Negation law Domination law Associativity of AND

49 What if it weren’t possible to assign such values to s, b, and f? Original statement Definition of implication... (same as previous slide) Domination law Re-arranging Negation law Domination law Contradiction!

50 Functional completeness All the “extended” operators have equivalences using only the 3 basic operators (and, or, not) –The extended operators: nand, nor, xor, conditional, bi-conditional Given a limited set of operators, can you write an equivalence of the 3 basic operators? –If so, then that group of operators is functionally complete

51 Functional completeness of NAND Show that | (NAND) is functionally complete Equivalence of NOT: –p | p ≡  p –  (p  p) ≡  pEquivalence of NAND –  (p) ≡  pIdempotent law

52 Functional completeness of NAND Equivalence of AND: –p  q ≡  (p | q)Definition of nand –p | pHow to do a not using nands –(p | q) | (p | q)Negation of (p | q) Equivalence of OR: –p  q ≡  (  p   q)DeMorgan’s equivalence of OR –As we can do AND and OR with NANDs, we can thus do ORs with NANDs Thus, NAND is functionally complete

53 End of lecture on 22 January 2007