1 / 44

Logic

Logic . The essence of rational thinking. Examples. Consider a life insurance contract that states "the sum of $100,000 will be paid to Sue and Sam if either Sue reaches age 65 or Same reaches age 65" What happens if Sue turns 65 6 months before Sam?

brinly
Télécharger la présentation

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. Logic The essence of rational thinking

  2. Examples • Consider a life insurance contract that states "the sum of $100,000 will be paid to Sue and Sam if either Sue reaches age 65 or Same reaches age 65" • What happens if Sue turns 65 6 months before Sam? • What happens if Sam turns 65 6 months before Sue? • What happens if Sue and Same were born on the same day at the same time? • Consider a checking account that requires signatures. You might see something like this: • Valid checking signature (check one): • party 1 or party 2 • party 1 and party 2 • Consider a ticket to a concert. The fine print reads "if the artist cancels, then this ticket is refundable". • What if the artist does not cancel?

  3. Logic • Mathematicians and Philosophers have described human reasoning as logical systems. • George Boole created an algebra for logic. This is known as Boolean logic. • Computer programs rely on logical expressions.

  4. Logic • Any statement that can be either true or false is a proposition. • Which of these are propositions? • My roommate eats pizza • Brush your teeth • I have a job • I have five kids • How tall is Mount Everest? • I have a German Shepherd • I've seen Star Wars 56 times

  5. Propositions • A proposition is a statement that has a value of either true or false. • Mount Everest is the tallest mountain in the world. • The Mississippi is the longest river in the world. • It makes sense to say “it is true” that “Mount Everest is the tallest mountain in the world”. • We conclude that the statement is a proposition. • It makes sense to say “it is false” that “The Mississippi is the longest river in the world” since the Nile is the longest. • We conclude that the statement is a proposition

  6. Logic • Every proposition has one of only two values: • true • false • In logic, there is no ‘probably’ or ‘maybe’. • A proposition is either completely true or it is completely false. • A proposition cannot be probably true or mostly true. • Law of non-contradiction: A proposition be both true and false at the same time. • Law of the excluded middle: The notion that there are only two truth values in a logical system

  7. Simple Propositions • A simple proposition is one that cannot be broken into parts • A compound proposition can be broken into parts. • Simple: I am hungry • Simple: I am cold • Compound: I am hungry and I am cold

  8. Logic • Propositions are often labeled (or named) to make them shorter to read • P = My roommate eats pizza • Q = I am poor • R = I have a job • S = I have five kids • T = I have a German Shepherd • U = I've seen Star Wars 56 times • Propositions can be combined with logical operators • AND as in P AND Q • NOT as in NOT Q • OR as in T OR U • IMPLIES as in R IMPLIES NOT Q • EQUALS as in R EQUALS T

  9. Well Formed Propositions • Propositions must be well-formedin order to have meaning. In other words, they must be grammatically correct. • Consider arithmetic equations. Rules must be followed to write down meaningful equations • X = * 5 - / + 2 ) 9 ( + 1 • X = 5 * ( 2 / 9 ) + 1 • There are rules for writing propositions. If these rules are not followed • You may write something that appears to be a proposition • Actually just a meaningless jumble of labels and operators.

  10. Well Formed Propositions Jabberwocky is a famous poem written by Lewis Carroll. It looks and sounds like an English poem, but is in reality just a series of nonsensical symbols (when written)and melodic sounds (when spoken)

  11. Logical Propositions • Axiom: Any single letter is a logical proposition • Axiom: If we let □ be a placeholder from some proposition, each of the following is also a proposition • □ AND □ • □ OR □ • □ IMPLIES □ • □ EQUALS □ • NOT □ • (□)

  12. Logical Propositions • Axiom: Any single letter is a logical proposition • Axiom: If we let □ be a placeholder from some proposition, each of the following is also a proposition • □ AND □ • □ OR □ • □ IMPLIES □ • □ EQUALS □ • NOT □ • (□) • Identify whether each of the following is a logical proposition. • P • P AND OR Q • P NOT Q • P AND NOT (Q OR R) • P EQUALS Q IMPLIES NOT P

  13. Reasoning • P = My roommate eats pizza • Q = I am poor • R = I have a job • S = I have five kids • T = I have a German Shepherd • U = I've seen Star Wars 56 times • How would you formally say • I am not poor? • I have a job and a German shepherd? • I have either a job or five kids? • If I have a job then I am not poor • If I have a roommate that eats pizza then I am poor.

  14. Evaluating Propositions • Consider the simple propositions • P = “I am hungry” • Q = “I am cold” • What is the truth value of • P AND Q • P OR Q • NOT P OR NOT Q EQUALS P • Determining the truth value of a proposition requires that we follow well-defined evaluation rules.

  15. Operators • Operators take input and produce one output • operands : the input values • arity : number of input values

  16. Conjunction (AND) • Conjunction is a binary operator : there are only two inputs. Each input is two-valued. There are only four cases that we need to define. • What does AND mean? • The logical conjunction of false with false is false • The logical conjunction of false with true is false • The logical conjunction of true with false is false • The logical conjunction of truewith trueis true

  17. Conjunction (Truth Table)

  18. Truth Tables • All propositions can be defined as truth tables • To construct a truth table • List all variables • Make one column for each variable • Make a row for each unique combination of variables • Add a row to the right that corresponds to the propositionand fill in the table

  19. Disjunction (OR) • Logical disjunction is not intuitive. In everyday use we often pose two mutually exclusive possibilities and ask which of those two possibilities actually occurred. • Did you watch television or did you eat dinner? • Expected responses: • I watched television • I ate dinner • Unexpected responses: • I did both • I did neither (I went for a walk) • Logically correct answers • Yes (true) • No (false) http://www.flickr.com/photos/x-ray_delta_one/4347981720/sizes/z/in/photostream/

  20. Disjunction (OR)

  21. Implication • Implication captures an IF-THEN relationship. Implication has properties that precisely express correct human reasoning! • P = “my car battery is dead” • Q = “my car won’t start” • P IMPLIES Q • We might phrase this informally as “whenever my car battery is dead, my car won’t start.”

  22. Implication

  23. Implication • Further thought on implication • P is True and Q is True. • P IMPLIES Q is logically consistent since the car won’t start because the car battery is dead. • P is True and Q is False. • P IMPLIES Q is logically inconsistent since the car is said to start whenever the car batter is not dead. • P is False and Q is True. • P IMPLIES Q is logically consistent since the car may not start for some reason unrelated to the battery. • P is False and Q is False. • P IMPLIES Q is logically consistent since the car will start and the battery is not dead.

  24. Implication • Q IMPLIES P is the converse of P IMPLIES Q. If an implication is true, the converse may not be. • Consider the implication that • “Humphrey is a dog implies Humphrey is a mammal” • The converse is not necessarily true since • “Humphrey is a mammal” does not imply that “Humphrey is a dog”. http://www.flickr.com/photos/joeshlabotnik/2822317000/

  25. Equivalence Two propositions are equivalent if they have the same truth table (the same truth values)

  26. Equivalence • Consider the statement: • It's not the case that I am both unemployed and not poor. • There is a simpler statement that has the same truth table: • I am poor or I have a job • Two different propositions that have the same truth table are said to be equivalent.

  27. Negation

  28. Truth Tables • P = My roommate eats pizza • Q = I am poor • R = I have a job • S = I have five kids • T = I have a German Shepherd • U = I've seen Star Wars 56 times • Truth tables can describe the meaning of compound propositions. • Generate the truth table for these statements • My roommate eats pizza and I'm not poor • I've seen Star Wars 56 times and I have either a job or five kids • It's not the case that I am both unemployed and not poor.

  29. Tautologies • G = I have good grades • M = Mom sends money • Tautology: any proposition that has a value of True regardless of the inputs • A tautology is just a long-winded way of expressing something that is self-evident. • If you elect me to be president then I will serve as the elected president • P IMPLIES P • If mom sends money, then either my grades are good or else my grades stink. • M implies (G or NOT G)

  30. Contradictions • P = My roommate eats pizza • Q = I am poor • R = I have a job • S = I have five kids • T = I have a German Shepherd • U = I've seen Star Wars 56 times • Contradiction: Any proposition that has a value of False for all inputs. • A contradiction is just nonsense • I have a job and I don't have a job. • I am 21 years old and I am not 21 years old. http://www.flickr.com/photos/bouldair/5302915006/sizes/z/in/photostream/

  31. Law of Non-Contradiction • Valid human reasoning requires that a proposition cannot be both true and false. • Matthew says: My new internet connection is blazingly fast. I watched HD movies all night. • Susan: Have you finished your CT homework? • Matthew: No. My new internet connection is so slow that I can’t download the one-page assignment.

  32. Google queries uses logic • Consider using Google to search for web pages. What do the following queries mean? • ram • ram memory • ram AND memory • ram –truck • ram AND NOT truck • (ram or dram) • ram OR dram • ram (pdf or ppt) • ram AND (pdf OR pptx)

  33. Digital Logic Digital circuits are the physical components of a computing system: the hardware. Digital circuits are typically constructed by combining logic gates. A logic gate is an electronic device that implements a Boolean operator.

  34. Illustration

  35. Logic Gates • Logic gates are usually implemented using transistors as switches. • A transistor is a switch and the voltage level can be thought of as either 1 (a value of true) or 0 (value of false). • Logic gates are drawn schematically as shown below.

  36. Logic Gates • Can the following proposition be encoded in hardware? • P AND NOT (Q OR R)

  37. Logic Gates What does this do?

  38. Graphic Art A graphic designer is a professional who works with images and fonts to create graphics. Many important image editing functions are direct applications of formal logic!

  39. Image Operations

  40. Database Queries • Most databases store information in tables • Each row contains a record. • Each column defines a field (part of a record) • Every cell contains a fields value for one record • Much of the worlds info is in a database • No fly list • National Do Not Call registry • National Sex Offender Registry • DNA databases

  41. Example (Political Donors)

  42. How to find data in the table • Databases are designed to efficiently find information. • The primary way of finding is through an SQL query • SQL: Structured Query Language • A standard language used to find data

  43. SQL Select • SELECT general form: • SELECT field1, field2,…,fieldN FROM table WHERE criteria • Find all donors who have contributed at least $500 • SELECT first, last FROM Donor WHERE Amount >= 500 • Filter for young donors (under 40) • SELECT first, last FROM Donor WHERE Amount >= 500 AND Age < 40 • Find all donors from either New York or California • SELECT first, last FROM Donor WHERE State = ‘NY’ or State = ‘CA’

  44. Software Requirements use Logic • Consider a cruise control with the following actions: • Off switch • On switch • Set switch • Requirement 1: • car is started IMPLIES IsOn is set to false • Requirement 2: • Off switch is pressed IMPLIES IsOn is set to false • Requirement 3: • On switch is pressed IMPLIES (IsOnis set to true AND isSet is set to false) • Requirement 4: • (Set switch is pressed AND isOn = true) IMPLIES (isSet is set to true AND SpeedSetting is set to CarSpeed) • Requirement 5: • (SET switch is pressed AND IsOn=true) IMPLIES (IsSet is set to true AND SpeedSetting is set to CarSpeed • Requirement 6: • (IsOn=true AND IsSet=true AND CarSpeed<SpeedSetting) IMPLIES throttle speed is increased

More Related