1 / 18

True-False Logic

True-False Logic. What do AND , OR , and NOT do? What is True and what is False?. Preview Questions:. Boolean Logic . Computers don't know anything about True and False They only know 1 and 0 . How do we "encode" True and False?

selia
Download Presentation

True-False Logic

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. True-FalseLogic What do AND, OR, and NOT do? What is True and what is False? Preview Questions: CS 105 Spring 2010

  2. Boolean Logic • Computers don't know anything about True and False • They only know 1 and 0. • How do we "encode" True and False? • We choose 1 as True and 0 as False. CS 105 Spring 2010

  3. Using Boolean Logic with a circuit Door Open Keys in Ignition AND BUZZ!!! CS 105 Spring 2010

  4. Using “And” in Real Life Hemingway wrote “For Whom the Bell Tolls” Note: the “AND” is not used in Google. It is assumed. CS 105 Spring 2010

  5. Using NOT Hemingway wrote many other books CS 105 Spring 2010

  6. Using Boolean Logic with a circuit If buckled the put signal is 1, and if unbuckled it is 0 Seat Belt Buckled Car in Gear NOT Yes, it is in gear Oops—not buckled! AND If seatbelt is NOT buckled it registers 0 (False), then NOT changes it to 1 (True) BUZZ!!! CS 105 Spring 2010

  7. What about “OR” CS 105 Spring 2010

  8. Putting it all together Seat Belt Buckled (0) Car in Gear Door Open Keys in Ignition NOT If seatbelt buckled returns 0, then NOT changes it to True (1) AND AND OR BUZZ!!! CS 105 Spring 2010

  9. What does an OR do? • OR is not fussy. • OR will send a TRUE result if any of its input is TRUE. CS 105 Spring 2010

  10. What does AND do? • AND will only give a TRUE result (that is, a binary 1) if all input is TRUE. CS 105 Spring 2010

  11. What does NOT do? • NOT returns the opposite of the input. It only needs one item, not 2, to examine. • If the data is True, NOT returns False, and if the data is False, NOT returns True. “The Inverter” CS 105 Spring 2010

  12. Symbolic Logic Let the sentence, “The door is open.” be represented by the symbol A and the sentence “The keys are in the ignition.” be represented by the symbol B. Then the expression, “The door is open.” AND “The keys are in the ignition.” can be compactly represented by the logical formula, A AND B Since either of A or B can be TRUE or FALSE we can express all possible combinations by means of a truth table… CS 105 Spring 2010

  13. Truth Tables The above table trivially expresses the fact that the formula A AND B is TRUE only when exactly both A and B are TRUE.As a second example, let C represent the sentence “The car is in gear.” and D represent the sentence “The seat belt is buckled.”. How would we write a truth table for the problem described on slide #8 ? CS 105 Spring 2010

  14. Example: Symbolic Formula D Seat Belt Buckled (0) C A B Car in Gear Door Open Keys in Ignition NOT If seatbelt buckled returns 0, then NOT changes it to True (1) AND AND OR (A AND B) OR (C AND (NOT D)) CS 105 Spring 2010

  15. Truth Tables The above table shows exactly seven cases where the buzzer will sound. CS 105 Spring 2010

  16. Equivalent Formulas Another use of truth tables is to prove that two formulas are equivalent. For example, consider the truth tables for the two formulas below. formula 1 NOT ( A OR B) formula 2 (NOT A) AND (NOT B) CS 105 Spring 2010

  17. Equivalent Formulas We see that formula1 and formula2 are equivalent, since for the same values of A and B the formulas produce exactly the same results. We can denote that two formulas are equivalent by using =, NOT ( A OR B) = (NOT A) AND (NOT B) If two formulas are equivalent we are free to choose either formula. We will make use of this feature when in writing computer programs. There are many pairs of equivalent formulas, two well known pairs make up what is called DeMorgan’s Laws: NOT ( A OR B) = (NOT A) AND (NOT B) NOT ( A AND B) = (NOT A) OR (NOT B) CS 105 Spring 2010

  18. To summarize: • What do AND, OR, and NOT do? • What is True and what is False? CS 105 Spring 2010

More Related