Basic Definitions Logical Connectives Connective Examples Truth Tables

Basic Definitions Logical Connectives Connective Examples Truth Tables

An Introduction to Logic Logic: Basic Definitions By • Definition: A proposition is a statement that is either true or false, but not both. Chuck Cusack • Defintion: The value of a proposition is called its truth value. Denoted by T if it is true, F if it is false Example 1: The statement “John Cusack is the president of the U.S.A.” is a proposition with truth value false. Example 2: The statement “Do your homework” is not a proposition because it is not a statement that can be true or false. 1 2 Logical Connectives Connective Examples • Connectives are used to create a proposition from several other propositions. • Let p be the proposition “The sky is clear.” • Such propositions are called compound • Let q be the proposition “It is raining.” propositions • Some examples that combine these are: • The most common connectives are: ∧ – NEGATION (¬ or !) – The sky is clear and it is raining. (p q) – AND (∧) – The sky is clear and it is not raining. (p∧¬q) –OR (∨) – It is raining if and only if the sky is not clear. ⊕ –XOR ( ) ↔¬ – IMPLICATION (→) (q p) – BICONDITIONAL or IF AND ONLY IF (↔) 3 4 Truth Tables NEGATION •If p is a proposition, the negation of p, denoted ¬p, is “it • Truth Tables are used to show the is not the case that p.” relationship between the truth values of • Example: Let p be the statement “this class has 30 students.” Then ¬p is the statement “this class does not individual propositions and the compound have 30 students.” propositions based on them. • It should be obvious that the negation of a proposition has • Example: the opposite truth value. In other words, if p is true, then p q p ∧q ¬p is false. T T T ¬ • The truth table for p is p ¬p T F F T F F T F F F F F T 5 6 1 AND OR •Let p and q be propositions. The proposition “p •Let p and q be propositions. The proposition “p or and q,” denoted by p∧q, is true if and only if both q,” denoted by p∨q, is false if and only if both p p and q are true. and q are false. In other words, it is true if either p • p∧q is called the conjunction of p and q. or q is true, and false otherwise. • p∨q is called the disjunction of p and q. ∨ • The truth table for p∧q is p q p ∧q • The truth table for p q is p q p∨q T T T T T T T F F T F T F T F F T T F F F F F F 7 8 XOR IMPLICATION •Let p and q be propositions. The proposition “p •Let p and q be propositions. The proposition “p exclusive or q,” denoted by p⊕q, is true if and implies q,” denoted by p→q, is false if and only if only if either p or q is true, but not both. p is true and q is false. • When the term OR is used in conversation, often • p→q is called an implication. the correct interpretation is XOR. • The truth table for p→q is p q p→q • The truth table for p⊕q is p q p⊕q T T T T T F T F F T F T F T T F T T F F T F F F 9 10 BICONDITIONAL Constructing Truth Tables •Let p and q be propositions. The proposition “p if and only if q,” denoted by p↔q, is true if and only • Construct the truth table for the proposition if p and q have the same truth value. ((p∧q)∨¬q) • p↔q is called a biconditional. • We do this step by step as follows: • The truth table for p↔q is p q p↔q p q p ∧q ¬q ((p∧q)∨¬q) T T T T T T F T T F F T F F T T F T F F T F F F F F T F F F T T 11 12 2 Everyday Logic Logic in Searching I • Logic is used in many places: –Writing • Situation: You want to find out all you can about – Speaking disc golf. – Search engines • Problem: When you search for “disc golf,” you –Mathematics get many hits about golf and some about discs, but – Computer Programs can’t find those about “disc golf.” • A proper understanding of logic is useful, as the following examples will demonstrate. • Solution: You need to find sites which mention both disc and golf, not either word. Search for disc AND golf 13 14 Logic in Searching II Logic at Home • Situation: You just bought some fresh corn, and you need a cornhusker to husk it, so you search for • Situation: Your mom said “If you are good, you “cornhusker” on the Internet can have some ice cream or some cake.” • Problem: Most of the results you get are about • Problem: You were good, so you ate some ice UNL’s football team. cream and some cake. Your mom got mad because you had both. • Solution: You need to find sites which mention cornhusker, but not UNL or football. Search for • Solution: A simple miscommunication. By having ice cream and cake, you had ice cream or cornhusker AND NOT (UNL OR football) cake. But as is often the case in conversation, she really meant XOR, not OR. 15 16 Logic in School Logic in Programming I • Situation: You have 3 tests for a class. If you get • Situation: If x is greater than 0 and is less than or an A on any two of them, or get an A on at least equal to 10, you need to increment it. one but do not fail any of them, you will get an A • Problem: You tried the following, but it seems for the course. too complicated, and doesn’t compile. • Problem: You are lazy, but want an A. if(0<x<10 OR x=10) x++; • Solution: Because of the OR condition, the • Solution: Try: minimal you can do is get an A on two exams and if(x>0 AND x<=10) x++; fail the third, or get an A on one exam and Ds on the other two. I’ll pick one A and 2 Ds. 17 18 3 Logic and e-Mail Filtering I Logic in Programming II • Situation: You are tired of getting spam about • Situation: Consider the following loop: losing weight and making money on eBay. while(NOT(A[i]!= 0 AND NOT(A[i]>= 10))) • Problem: You tried the following filter: • Problem: You are convinced this is way too If(subject contains weight and subject complicated. contains eBay) Delete message • Solution: Well, it’s hard to say at this point… • Solution: You meant: If(subject contains weight or subject contains eBay) Delete message 19 20 Logic in Programming III Logic and e-mail Filtering II • Situation: You get so much spam, you decide to delete • Situation: Consider the following loop: any message not sent (or copied) to you (blah), or a group while( (i<size AND A[i]>10) OR (i<size to which you belong (foo). You try: AND A[i]<0) OR NOT (A[i]!= 0 AND NOT (A[i]>= 10) ) ) if( TO or CC does not contain blah OR • Problem: You are convinced this is way too TO or CC does not contain foo) complicated. Delete message • Solution: Yet another example we can’t solve. • Problem: It seems like all of your e-mail is being deleted. • Solution: This one is confusing, and we will solve it later. 21 22 Logic and Medication Why Logic? • Situation: Your new medication has the following label: Take 1 or 2 pills every 4-6 hours until condition improves. Do not exceed 6 pills per day, or take for longer than 7 days unless directed by a doctor. Do not take this drug during the last 3 months of • Hopefully the last several examples have pregnancy, unless directed by a doctor. If you are taking XYZs and PDQs or have taken either an XYZ or a PDQ within the last 90 days, and the other within the last 30 days, or are taking an ABC or convinced you that knowing more logic is have taken an ABC within the last 60 days, you should not take this drug. Do not drink alcohol or smoke while on this drug. If you have a heart condition, asthma, diabetes, or have an IQ below 25, important for computer science, and life in do not take this drug. Do not take this drug if you have a high fever, cold sweats, runny nose, headache, or sore throat, and discontinue use if you develop any of these symptoms, and dizziness, general. nervousness, or sleeplessness occur. • Problem: Under what conditions can you take it? • If you are still not convinced, tough. You are going to learn it anyway. • Solution: Well, this one may take more than simple logic. 23 24 4 Propositional Equivalences Some Terminology • Many problems, included the last several • Definition: A tautology is a proposition that examples, can be solved by understanding the is always true. concept of propositional equivalences. • Definition: A contradiction is a proposition • Example: The statement “I am not a student and I am not living in the dorm” is equivalent to “I am not a student or that is always false. living in the dorm.” • Definition: A proposition that is not a • Example: “You will pass this class or you will not be in the J.D.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    8 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us