Mathematics for Comter I Lecture 2: Logic (1) Basic definitions Logical operators Translating English sentences
Mathematics for Comter I 2.1. Logic Rules of logic: Give precise meaning to mathematical statements. Distinguish between valid and invalid mathematical arguments. Applications: Design of computer circuits. Construction of computer programs. Verification of correctness of programs.
Mathematics for Comter I 2.1. Logic Logic deals with statements and their truth sets. The statements are called propositions. proposition : true = T (or 1) or false = F (or 0) (binary logic) 1+1 = 2 (Y) ‘the moon is made of green cheese’ (Y) y+1=2 (X) - Uncertain ‘go to town!’ (X) - imperative ‘What time is it?’ (X) - interrogative propositional variables: P, Q, R, S,...
Mathematics for Comter I 2.1. Logic Calculus of propositions: Relate new propositions to old using TRUTH TABLES logical operators (op): Unary: negation Binary: conjunction, disjunction, exclusive or, implication, biconditional
Mathematics for Comter I 2.1. Logic Truth Table Displays the relationships between the truth values of propositions. P1P2P1 op P
Mathematics for Comter I 2.2. Unary Operator Negation ‘not’ Symbol: Example: P : I am going to town P: I am not going to town or It is not the case that I am going to town Truth table: P PP F (0)T (1) F (0)
Mathematics for Comter I 2.3. Binary Operators Binary Conjunction ‘and’ Symbol: Example: P: I am going to town Q: It is going to rain P Q: I am going to town and it is going to rain. Truth Table: Both P and Q must be true !!! PQ PQPQ
Mathematics for Comter I 2.3. Binary Operators Binary Disjunction – Inclusive ‘or’ Symbol: Example: P: I am going to town Q: It is going to rain P Q: I am going to town or it is going to rain. Truth Table: Only one of P, Q need be true. Hence, the inclusive nature. PQ PQPQ
Mathematics for Comter I 2.3. Binary Operators Exclusive ‘or’ Symbol: Example: P: I am going to town Q: It is going to rain P Q: Either I am going to town or it is going to rain. Truth Table: Only one of P and Q must be true. PQ PQPQ
Mathematics for Comter I 2.3. Binary Operators Implication ‘If...then...’ Symbol: Example: P: I am going to town Q: It is going to rain P Q: If I am going to town then it is going to rain. Truth Table: The implication is false only when P is true and Q is false! PQ PQPQ
Mathematics for Comter I 2.3. Binary Operators In C programming language AND && Inclusive OR || Exclusive OR ^ Not !
Mathematics for Comter I 2.3. Binary Operators Implication (continued) Equivalent forms: If P, then Q P implies Q If P, Q P is a sufficient condition for Q Q if P Q whenever P Q is a necessary condition for P Terminology: P = premise, hypothesis, antecedent Q = conclusion, consequence
Mathematics for Comter I 2.3. Binary Operators Implication (continued) A useful way to remember the truth table is to think of a contract or an obligation.
Mathematics for Comter I 2.3. Binary Operators Example: If you make more than $ 25,000, then you must file a tax return. The statement says nothing about someone making less than $ 25,000 – so true every time. You violate the obligation only if you make more than $ 25,000 and do not file a return. If the total marks of a student are more than 55%, then the student will pass this course. A student whose marks less than 55% may still pass. It is wrong if a student has more than 55% and fails.
Mathematics for Comter I 2.3. Binary Operators Implication (continued) There is no causality implied here! If today is Friday, then 2+3 = 5. True, since its conclusion is true. If today is Friday, then 2+3 = 6. True everyday except Friday, even though 2+3 = 6 is false. Compare implications used in normal language: If it is sunny today, then we will go to the beach
Mathematics for Comter I 2.3. Binary Operators Implication (continued) More terminology: Q P is the CONVERSE of P Q Q P is the CONTRAPOSITIVE of P Q Example: Find the converse and contrapositive of the following statement: R: Raining tomorrow is a sufficient condition for my not going to town. Step 1: Assign propositional variables to component propositions P: It will rain tomorrow Q: I will not go to town
Mathematics for Comter I 2.3. Binary Operators Example (continued): Step 2: Symbolize the assertion R: P Q Step 3: Symbolize the converse Q P Step 4: Convert the symbols back into word If I don’t go to town then it will rain tomorrow. or Raining tomorrow is a necessary condition for my not going to town. or My not going to town is a sufficient condition for it raining tomorrow.
Mathematics for Comter I 2.3. Binary Operators Biconditional ‘If and only if’, ‘iff’ Symbol: Example: P: I am going to town Q: It is going to rain P Q: I am going to town if and only if it is going to rain. Truth Table: Both P and Q must have the same truth value. PQ PQPQ
Mathematics for Comter I 2.3. Binary Operators Biconditional (continued) Example: You must file a tax return if and only if you make more than $ 25,000. The statement now says something about someone making less than $ 25,000 – the rule is violated if somebody asks to pay tax but your income is less than $ 25,000. You violate the obligation if you make more than $ 25,000 and do not file a return.
Mathematics for Comter I 2.4. Translating English Sentences Breaking assertions into component propositions - look for the logical operators! Example: If I go to Harry’s or go to the country I will not go shopping. P: I go to Harry’s Q: I go to the country R: I will go shopping If......P......or.....Q.....then....not.....R (P Q) R
Mathematics for Comter I 2.4. Translating English Sentences Constructing a truth table: one column for each propositional variable one for the compound proposition count in binary n propositional variables = 2 n rows You may find it easier to include columns for propositions which themselves are component propositions. e.g. columns for P Q.
Mathematics for Comter I 2.4. Translating English Sentences Truth Table: PQR PQPQ(P Q) R
Mathematics for Comter I 2.4. Translating English Sentences Question: How many different propositions can be constructed from n propositional variables?
Mathematics for Comter I 2.5. Further Readings Basic definitions Rosen: Section 1.1 Logical operators Rosen: Section 1.1 Translating English sentences Rosen: Section 1.1