Brain Teaser You are speaking to twins, Joe and Jim. One always tells the truth and one always lies, but you don’t know which is which. You ask one twin, “Does Joe always lie?”. He answers, “Yes”. Did you speak to Joe or Jim? Which twin is the liar? Some Basics • • • • Number sequences Propositions Truth tables Boolean variables Number Sequences • • • • 5, 1, 1, 2, 7, 9, 4, 4, 9, 11, 13, ?, … 17, 25, 33, 41, ?, … 9, 16, 25, ?, … 8, 16, 32, ?, … Number Sequences • Recursive formula: each term is specified by arithmetic operations on previous term(s). Must initialize. – Recurrence relation • Closed formula: each term specified in terms (arithmetic) of its position in sequence a1 , a2 , a3 , . . . Two sided Nth element an . . . a−2 , a−1 , a0 , a1 , a2 , . . . Number Sequences • Sequence notation a0 , a1 , a2 , . . . Two sided Nth element an . . . a−2 , a−1 , a0 , a1 , a2 , . . . • Notation for sums n ! k=1 ak = a1 + a2 + a3 + . . . + an Practice Problem • Give recursive and closed form expressions for the following: a) b) c) d) 5, 1, 1, 2, 7, 9, 4, 4, 9, 11, 13, … 17, 25, 33, 41, … 9, 16, 25, … 8, 16, 32, … Propositions • A proposition is a statement that can be either true or false. – “Today is Wednesday.” – “I love CS 2100.” – “x = 7” • Not propositions: – “Why am I here?” – “Read the book.” Boolean Variables • We’ll use variables (letters) to represent propositions. – p = “today is Wednesday” – q = “it is raining” • A variable may take one of two values: true (T) or false (F). “Boolean”? In 1854 he published An Investigation into the Laws of Thought, on Which are founded the Mathematical Theories of Logic and Probabilities. Boole approached logic in a new way, reducing it to a simple algebra incorporating logic into mathematics. He pointed out the analogy between algebraic symbols and those that represent logical forms. It began the algebra of logic called Boolean algebra which now finds application in computer construction, switching circuits, etc. Truth Tables • List the possibilities of boolean variables • Game: truth-tellers and liars • Scenario: meet person A and B – A: “Exactly one of us is lying” – B: “At least one of us is telling the truth” • Goal: Identify A and B as truth-tellers or liars Truth Tables • Introduce propositions: – p – q – r – s – – – – A is a truth teller B is a truth teller A’s statement B’s statement Truth Tables Truth Tables Find scenario with no contradictions Paradoxes • “I am telling the truth” • “I am lying” Joe and Jim You are speaking to twins, Joe and Jim. One always tells the truth and one always lies, but you don’t know which is which. You ask one twin, “Does Joe always lie?”. He answers, “Yes”. Did you speak to Joe or Jim? Which twin is the liar? Joe and Jim • Introduce propositions: – p – – q – – Cases – A – – B – Joe is a truth teller Jim is a truth teller We spoke with Jim We spoke with Joe Try to Fill out Truth Tables • Look for inconsistencies/consistencies • Case A: • Case B: Logical Operators • Logical operators operate on Boolean variables, much like algebraic operators (+ , - , * , / ) operate on numerical variables • Just like propositions, operators can be converted into words: “and”, “or”, “not” And (∧) • An “and” operation is true if both arguments are true • In C++ and Java the operator is && • Example: p ∧ q = “Today is Wednesday and it is raining” Or (∨) • An “or” operation is true if at least one argument is true • In C++ and Java the operator is || • Example: p ∨ q = “Today is Wednesday or it is raining (or both)” Not (¬) • A “not” operation negates (flips) its argument • In C++ and Java the operator is ! • Example: ¬p = “Today is not Wednesday” Switching Circuits/Digital Logic Truth Tables for Formal Propositions • Evaluate • Work inside out (hierarchical) – Use precedence rules and parentheses Logical equivalence • Two statements are said to be logically equivalent if they have the same value for every row of a truth table • DeMorgan’s Law Logical Constants • A tautology is always true • A contradiction is always false • Example: prove the following is a tautology Properties of Boolean Operations