440 likes | 579 Views
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?
E N D
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? • 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?
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.
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
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
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
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
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
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.
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)
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 □ • (□)
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
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.
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.
Operators • Operators take input and produce one output • operands : the input values • arity : number of input values
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
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
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/
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.”
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.
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/
Equivalence Two propositions are equivalent if they have the same truth table (the same truth values)
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.
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.
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)
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/
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.
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)
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.
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.
Logic Gates • Can the following proposition be encoded in hardware? • P AND NOT (Q OR R)
Logic Gates What does this do?
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!
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
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
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’
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