CS1022 Computer Programming & Principles Lecture 1 Logic and Proof.

Slides:



Advertisements
Similar presentations
TRUTH TABLES Section 1.3.
Advertisements

TRUTH TABLES The general truth tables for each of the connectives tell you the value of any possible statement for each of the connectives. Negation.
Constructing a Truth Table
Logic & Critical Reasoning
Truth Tables Presented by: Tutorial Services The Math Center.
1. Propositions A proposition is a declarative sentence that is either true or false. Examples of propositions: The Moon is made of green cheese. Trenton.
Logic ChAPTER 3 1. Truth Tables and Validity of Arguments
EE1J2 - Slide 1 EE1J2 – Discrete Maths Lecture 3 Syntax of Propositional Logic Parse trees revised Construction of parse trees Semantics of propositional.
Logic Chapter 2. Proposition "Proposition" can be defined as a declarative statement having a specific truth-value, true or false. Examples: 2 is a odd.
2/17/2008Sultan Almuhammadi1 ICS Logic & Sets (An Overview) Week 1.
Boolean Algebra Computer Science AND (today is Monday) AND (it is raining) (today is Monday) AND (it is not raining) (today is Friday) AND (it is.
1 Section 1.2 Propositional Equivalences. 2 Equivalent Propositions Have the same truth table Can be used interchangeably For example, exclusive or and.
1 Math 306 Foundations of Mathematics I Math 306 Foundations of Mathematics I Goals of this class Introduction to important mathematical concepts Development.
Propositional Logic Lecture 1: Sep 2. Content 1.Mathematical proof (what and why) 2.Logic, basic operators 3.Using simple operators to construct any operator.
Propositional Logic Lecture 2: Sep 9. Conditional Statement If p then q p is called the hypothesis; q is called the conclusion “If your GPA is 4.0, then.
Homework 3.
Truth Tables for Negation, Conjunction, and Disjunction.
3.2 – Truth Tables and Equivalent Statements
TRUTH TABLES. Introduction Statements have truth values They are either true or false but not both Statements may be simple or compound Compound statements.
Chapter 3 – Introduction to Logic The initial motivation for the study of logic was to learn to distinguish good arguments from bad arguments. Logic is.
Lecture 8 Introduction to Logic CSCI – 1900 Mathematics for Computer Science Fall 2014 Bill Pine.
The Foundations: Logic and Proofs
Propositional Logic.
Intro to Discrete Structures
Section 1-4 Logic Katelyn Donovan MAT 202 Dr. Marinas January 19, 2006.
Discrete Maths 2. Propositional Logic Objective
Lecture for Week Spring.   Introduction to Propositional Logic  Types of Proposition  Operator and Truth table Agenda.
CSE 20 DISCRETE MATH Prof. Shachar Lovett Clicker frequency: CA.
CS 285- Discrete Mathematics Lecture 2. Section 1.1 Propositional Logic Propositions Conditional Statements Truth Tables of Compound Propositions Translating.
Chapter 1 The Logic of Compound Statements. Section 1.1 Logical Form and Logical Equivalence.
Propositional Logic Dr. Yasir Ali. Formal or propositional logic was first developed by the ancient Greeks, who wanted to be able to reason carefully.
BY: MISS FARAH ADIBAH ADNAN IMK. CHAPTER OUTLINE: PART III 1.3 ELEMENTARY LOGIC INTRODUCTION PROPOSITION COMPOUND STATEMENTS LOGICAL.
Valid and Invalid Arguments
MATH 102 Contemporary Math S. Rook
Chapter 5 – Logic CSNB 143 Discrete Mathematical Structures.
Math 240: Transition to Advanced Math Deductive reasoning: logic is used to draw conclusions based on statements accepted as true. Thus conclusions are.
Logical Form and Logical Equivalence Lecture 2 Section 1.1 Fri, Jan 19, 2007.
Discrete Mathematics Lecture1 Miss.Amal Alshardy.
DISCRETE STRUCTURE Bs (IT).
Of 33 lecture 12: propositional logic – part I. of 33 propositions and connectives … two-valued logic – every sentence is either true or false some sentences.
Logic Review. FORMAT Format Part I 30 questions 2.5 marks each Total 30 x 2.5 = 75 marks Part II 10 questions Answer only 5 of them! Total 5 x 5 marks.
HAWKES LEARNING Students Count. Success Matters. Copyright © 2015 by Hawkes Learning/Quant Systems, Inc. All rights reserved. Section 3.2 Truth Tables.
CSNB143 – Discrete Structure LOGIC. Learning Outcomes Student should be able to know what is it means by statement. Students should be able to identify.
Boolean Algebra. Logical Statements A proposition that may or may not be true:  Today is Monday  Today is Sunday  It is raining.
LOGIC Lesson 2.1. What is an on-the-spot Quiz  This quiz is defined by me.  While I’m having my lectures, you have to be alert.  Because there are.
Chapter 7 Logic, Sets, and Counting
Chapter 3: Semantics PHIL 121: Methods of Reasoning March 13, 2013 Instructor:Karin Howe Binghamton University.
Chapter 3: Introduction to Logic. Logic Main goal: use logic to analyze arguments (claims) to see if they are valid or invalid. This is useful for math.
MLS 570 Critical Thinking Reading Notes for Fogelin: Propositional Logic Fall Term 2006 North Central College.
Warmup Answer the following True/False questions in your head: I have brown hair AND I am wearing glasses I am male OR I am wearing sneakers I am NOT male.
How do I show that two compound propositions are logically equivalent?
Chapter 7 Logic, Sets, and Counting Section 1 Logic.
Logical Form and Logical Equivalence Lecture 1 Section 1.1 Wed, Jan 12, 2005.
Boolean Algebra Monday/Wednesday 7th Week. Logical Statements Today is Friday AND it is sunny. Today is Friday AND it is rainy. Today is Monday OR it.
CS203 Discrete Mathematical Structures
Section 1.1. Section Summary Propositions Connectives Negation Conjunction Disjunction Implication; contrapositive, inverse, converse Biconditional Truth.
Formal Test for Validity. EVALUATIONS Evaluations An evaluation is an assignment of truth-values to sentence letters. For example: A = T B = T C = F.
CSNB143 – Discrete Structure Topic 4 – Logic. Learning Outcomes Students should be able to define statement. Students should be able to identify connectives.
Notes - Truth Tables fun, fun, and more fun!!!!. A compound statement is created by combining two or more statements, p and q.
Metalogic. TWO CONCEPTIONS OF LOGICAL CONSEQUENCE.
Joan Ridgway. If a proposition is not indeterminate then it is either true (T) or false (F). True and False are complementary events. For two propositions,
1 Boolean Logic CS/APMA 202, Spring 2005 Rosen, section 1.1 Aaron Bloomfield.
Outline Logic Propositional Logic Well formed formula Truth table
رياضيات متقطعة لعلوم الحاسب MATH 226. Text books: (Discrete Mathematics and its applications) Kenneth H. Rosen, seventh Edition, 2012, McGraw- Hill.
Mathematics for Computing Lecture 2: Computer Logic and Truth Tables Dr Andrew Purkiss-Trew Cancer Research UK
Propositional and predicate logic
Chapter 1. Chapter Summary  Propositional Logic  The Language of Propositions (1.1)  Logical Equivalences (1.3)  Predicate Logic  The Language of.
Chapter 1 Logic and proofs
Logical Operators (Connectives) We will examine the following logical operators: Negation (NOT,  ) Negation (NOT,  ) Conjunction (AND,  ) Conjunction.
Discrete Structures for Computer Science Presented By: Andrew F. Conn Slides adapted from: Adam J. Lee Lecture #1: Introduction, Propositional Logic August.
Presentation transcript:

CS1022 Computer Programming & Principles Lecture 1 Logic and Proof

Plan of lecture Introduction Propositional logic Truth tables Logical equivalence Conditionals Predicate logic Relation between quantifiers 2 CS1022

Introduction Logic Essential in formal disciplines (science) Consists of rules for drawing inferences Does not depend on any specific topic Provides a suitable tool for reasoning – Propositional logic – simple statements and their truth – Predicate logic – statements with variables Proof Means to convince someone (us!) about something Systematic arguments (template and strategies) 3 CS1022

Why logic is important to Computing Provides a way to precisely and clearly state what is being reasoned about, e.g. propositions in simple and complex forms, properties, relations, quantifiers.... Helps us understand how the meaning of complex expressions can be understood in terms of the meaning of the basic parts and their construction Enables reasoning in a systematic fashion over long chains for inferences Useful for proving general properties of a program specification. Different "logics" for different reasoning issues, e.g. static (no time), dynamic (change), modal (possibilities),.... Important level of abstraction 4 CS1022

Why logic is important to Computing If-then-else constructs: if CONDITION then STATEMENT – CONDITION can be true or false – STATEMENT depends on CONDITION Logic studies when truth/falsity of a statement can be inferred Example: – if (A > 20 and B 20 and B > 50) then STATEMENT If we know how operators and, or, etc. combine basic propositions into larger propositions, and if we know what is the case, then we can determine if the STATEMENT follows. 5 CS1022

Building blocks of formal logic: propositions – Propositions are statements – (later about truth/falsity) – Examples: – “It is sunny now” – “There are 35 students here” – “This slide has a flying pig” – “It is too far to walk to the city centre” To save us writing, we will abbreviate statements: – “It is sunny now” abbreviated as “S” – “There are 35 students here” abbreviated as “L” – “This slide has a flying pig” abbreviated as “P” 6 CS1022 Syntax 1 - Propositions

Syntax 2 - Connectives Building blocks of formal logic: connectives Construct complex statements from simpler ones: – (not S) – it is not sunny now (Language v Logic) – (S or P) – it is sunny now or this slide has a flying pig – (P and L) – this slide has a flying pig and there are 35 students here – (conditional later) We are not concerned (at this point) with the internal content or structure of the propositions. We see and understand a sentence "it is not sunny now", but the logic just sees (not S). 7 CS1022

Syntax 3 – Syntax Definition General (recursive) definition for statements – All proposition letters (P, Q, R, S, etc.) are statements – If α and β are statements then (not α) is a statement (and so is (not β)) (α or β) is a statement (α and β) is a statement (conditional later) 8 CS1022

Suppose we have propositions letters P, Q, R We can create the following statements – (P and Q) – ((Q and P) or R) – (not (Q and (P or R))) These are not propositional statements (why?) – P (not and Q R) – (or P not Q (and R)) We might drop outermost brackets Order doesn't matter for and and or. – (R or (P and Q)) Syntax 4 - Examples 9 CS1022

Suppose – P stands for “logic is fun” – Q stands for “today is Friday” Express in propositional logic – “Logic is not fun and today is Friday” – “Today is not Friday and Logic is not Fun” – “Logic is fun or today is not Friday” not (P or Q) ((not Q) not (and P)) Syntax 5 - Examples 10 CS1022 (not (P and Q)) ((not Q) and (not P)) ((not P) and Q) (P or (not Q))

Suppose – S stands for “Cat videos are silly” – U stands for “You owe me £10” What does each propositional statement mean: – (not (S or U)) – ((not S) and (not U)) Syntax 6 - Examples 11 CS1022 It is not true that cat videos are silly or that you owe me £10 Cat videos are not silly and you don’t owe me £10

Sometimes you will also see – “  ” for “and”; “  ” for “or”; “  ” for “not” – Small letters instead of capital letters for propositions – Strings for propositions (e.g., “catsRcool”) – “Compound proposition” or “formulae” for statements – Propositional “variables” for propositional “letters” They are “variables” because they can vary over the propositional letters Question: are the following statements OK? – (not (not (not (not P)))) – (P and (Q and (R and (S and U)))) – ((((S or P) or R) or Q) or U) Syntax 7 - Examples 12 CS1022

Not concerned with the "meaning" of a proposition other than whether it is true or false. Not about "how" we know it is true or false, but supposing it is, what else do we know. Abstraction. The "truth" of a proposition determined "by inspection" – The book is on the table. The "real" world. The "truth" determined by "stipulation"- suppose The book is on the table is true. Not the "real" world. Mostly we are not concerned with the internal content or the "real" world, and we stipulate truth of a proposition. The truth value of P is true/false. Semantics 1 – Truth of a Proposition 13 CS1022

Given the truth value of the individual propositions, we can systematically compute the truth value of complex statements. This shows us what we "know" about the meaning of the connectives. Truth tables: – Represent the effect of logical operators Next slides show truth tables for operators Each line represents a different circumstance Semantics 2 – Truth of Complex Statements 14 CS1022

The negation of P, (not P), is the opposite of the truth value of P: A conjunction of P and Q, (P and Q), is true only when both P and Q are true (and false otherwise) Semantics 3 - Truth tables not, and 15 CS1022 P(not P) TF FT PQ(P and Q) TTT TFF FTF FFF

A disjunction (P or Q) is false only when both P and Q are false (and true otherwise) – Meaning (P or Q) is true where either P is true, or Q is true, or both are true (inclusive or) – Does not mean (P or Q) is true where either P is true or Q is true, but not both are true (exclusive or) Semantics 4 - Truth tables or 16 CS1022 PQ(P or Q) TTT TFT FTT FFF

How to build truth tables? Given propositions P, Q, R, S,..., we do: 1.Get all possible combinations of T (true) and F (false) for the propositions 2.Break down the formula into smaller sub-formulae 3.Combine truth-values of sub-formulae using the truth tables, and combine until final value is computed General strategy – Analyse a complex statement by breaking it down to fundamental parts (propositions and connectives) and basic meanings (truth values of propositions and connectives) Semantics 5 – Building Truth tables 17 CS1022

Truth table for ((P and Q) or (not R)): Semantics 6 – Filling in Truth tables 18 CS1022 PQR(P and Q)(not R)((P and Q) or (not R)) Left-most columns are single/individual propositions Break-down of formulae to the right of propositions Right-most column is the formula we are dealing with

Truth table for ((P and Q) or (not R)): Semantics 7 – Step 1 19 CS1022 PQR(P and Q)(not R)((P and Q) or (not R)) Assign T (true) or F (false) to propositions Notice: get all possible combinations Easy way: T/F, then TT/FF, then TTTT/FFFF, etc. PQR(P and Q)(not R)((P and Q) or (not R)) T F T F T F T F PQR(P and Q)(not R)((P and Q) or (not R)) TT TF FT FF TT TF FT FF PQR(P and Q)(not R)((P and Q) or (not R)) TTT TTF TFT TFF FTT FTF FFT FFF

Truth table for ((P and Q) or (not R)): Semantics 8 – Step 2 20 CS1022 Compute truth value of next most complex subformulae using the truth values of the parts. PQR(P and Q)(not R)((P and Q) or (not R)) TTT TTF TFT TFF FTT FTF FFT FFF PQR(P and Q)(not R)((P and Q) or (not R)) TTT TTF TFT TFF FTT FTF FFT FFF PQR(P and Q)(not R)((P and Q) or (not R)) TTTT TTF TFT TFF FTT FTF FFT FFF PQR(P and Q)(not R)((P and Q) or (not R)) TTTT TTFT TFT TFF FTT FTF FFT FFF PQR(P and Q)(not R)((P and Q) or (not R)) TTTT TTFT TFTF TFF FTT FTF FFT FFF PQR(P and Q)(not R)((P and Q) or (not R)) TTTT TTFT TFTF TFFF FTT FTF FFT FFF PQR(P and Q)(not R)((P and Q) or (not R)) TTTT TTFT TFTF TFFF FTTF FTFF FFTF FFFF PQR(P and Q)(not R)((P and Q) or (not R)) TTTT TTFT TFTF TFFF FTTF FTFF FFTF FFFF PQR(P and Q)(not R)((P and Q) or (not R)) TTTT TTFT TFTF TFFF FTTF FTFF FFTF FFFF PQR(P and Q)(not R)((P and Q) or (not R)) TTTTF TTFT TFTF TFFF FTTF FTFF FFTF FFFF PQR(P and Q)(not R)((P and Q) or (not R)) TTTTF TTFTT TFTF TFFF FTTF FTFF FFTF FFFF PQR(P and Q)(not R)((P and Q) or (not R)) TTTTF TTFTT TFTFF TFFF FTTF FTFF FFTF FFFF PQR(P and Q)(not R)((P and Q) or (not R)) TTTTF TTFTT TFTFF TFFFT FTTF FTFF FFTF FFFF PQR(P and Q)(not R)((P and Q) or (not R)) TTTTF TTFTT TFTFF TFFFT FTTFF FTFFT FFTFF FFFFT PQR(P and Q)(not R)((P and Q) or (not R)) TTTTF TTFTT TFTFF TFFFT FTTFF FTFFT FFTFF FFFFT PQR(P and Q)(not R)((P and Q) or (not R)) TTTTF TTFTT TFTFF TFFFT FTTFF FTFFT FFTFF FFFFT PQR(P and Q)(not R)((P and Q) or (not R)) TTTTFT TTFTT TFTFF TFFFT FTTFF FTFFT FFTFF FFFFT PQR(P and Q)(not R)((P and Q) or (not R)) TTTTFT TTFTTT TFTFF TFFFT FTTFF FTFFT FFTFF FFFFT PQR(P and Q)(not R)((P and Q) or (not R)) TTTTFT TTFTTT TFTFFF TFFFT FTTFF FTFFT FFTFF FFFFT PQR(P and Q)(not R)((P and Q) or (not R)) TTTTFT TTFTTT TFTFFF TFFFTT FTTFF FTFFT FFTFF FFFFT PQR(P and Q)(not R)((P and Q) or (not R)) TTTTF TTFTT TFTFF TFFFT FTTFF FTFFT FFTFF FFFFT

Truth table for ((P and Q) or (not R)): Semantics 8 – Step 3 21 CS1022 Compute truth value of next most complex subformulae using the truth values of the parts. PQR(P and Q)(not R)((P and Q) or (not R)) TTT TTF TFT TFF FTT FTF FFT FFF PQR(P and Q)(not R)((P and Q) or (not R)) TTT TTF TFT TFF FTT FTF FFT FFF PQR(P and Q)(not R)((P and Q) or (not R)) TTTT TTF TFT TFF FTT FTF FFT FFF PQR(P and Q)(not R)((P and Q) or (not R)) TTTT TTFT TFT TFF FTT FTF FFT FFF PQR(P and Q)(not R)((P and Q) or (not R)) TTTT TTFT TFTF TFF FTT FTF FFT FFF PQR(P and Q)(not R)((P and Q) or (not R)) TTTT TTFT TFTF TFFF FTT FTF FFT FFF PQR(P and Q)(not R)((P and Q) or (not R)) TTTT TTFT TFTF TFFF FTTF FTFF FFTF FFFF PQR(P and Q)(not R)((P and Q) or (not R)) TTTT TTFT TFTF TFFF FTTF FTFF FFTF FFFF PQR(P and Q)(not R)((P and Q) or (not R)) TTTT TTFT TFTF TFFF FTTF FTFF FFTF FFFF PQR(P and Q)(not R)((P and Q) or (not R)) TTTTF TTFT TFTF TFFF FTTF FTFF FFTF FFFF PQR(P and Q)(not R)((P and Q) or (not R)) TTTTF TTFTT TFTF TFFF FTTF FTFF FFTF FFFF PQR(P and Q)(not R)((P and Q) or (not R)) TTTTF TTFTT TFTFF TFFF FTTF FTFF FFTF FFFF PQR(P and Q)(not R)((P and Q) or (not R)) TTTTF TTFTT TFTFF TFFFT FTTF FTFF FFTF FFFF PQR(P and Q)(not R)((P and Q) or (not R)) TTTTF TTFTT TFTFF TFFFT FTTFF FTFFT FFTFF FFFFT PQR(P and Q)(not R)((P and Q) or (not R)) TTTTF TTFTT TFTFF TFFFT FTTFF FTFFT FFTFF FFFFT PQR(P and Q)(not R)((P and Q) or (not R)) TTTTF TTFTT TFTFF TFFFT FTTFF FTFFT FFTFF FFFFT PQR(P and Q)(not R)((P and Q) or (not R)) TTTTFT TTFTT TFTFF TFFFT FTTFF FTFFT FFTFF FFFFT PQR(P and Q)(not R)((P and Q) or (not R)) TTTTFT TTFTTT TFTFF TFFFT FTTFF FTFFT FFTFF FFFFT PQR(P and Q)(not R)((P and Q) or (not R)) TTTTFT TTFTTT TFTFFF TFFFT FTTFF FTFFT FFTFF FFFFT PQR(P and Q)(not R)((P and Q) or (not R)) TTTTFT TTFTTT TFTFFF TFFFTT FTTFF FTFFT FFTFF FFFFT PQR(P and Q)(not R)((P and Q) or (not R)) TTTTFT TTFTTT TFTFFF TFFFTT FTTFFF FTFFTT FFTFFF FFFFTT

A logical operator for conditionals – if today is Friday then I am wearing a green shirt – if P then Q – P  Q Add to the earlier Definition: (α  β) is a statement Factual vs. logical truth – If we accept that the conditional is true P  Q and that P (the premise) is true, then it follows logically that Q (the conclusion) is also true – Accept: if today is Friday then I am wearing a green shirt – Accept: Today is Friday – Infer: I am wearing a green shirt Conditionals 1 22 CS1022

The formula P  Q is false when – The premise P is true and – The conclusion Q is false Truth table We read “P implies Q” or “P is sufficient for Q” Works for most lines of the truth table, but some intuitive oddness. Conditionals 2 23 CS1022 PQ (P  Q) TTT TFF FTT FFT

Two formulae with same propositions may have the same final truth value, for any truth values of the propositions (or can prove each entails the other) – Suppose propositions P and Q – We can build formulae (P or Q) not ((not P) and (not Q)) Such formulae are logically equivalent; they "mean" the same thing. – We represent two logically equivalent formulae  and  as   Logical equivalence 1 24 CS1022

We can prove that two formulae α and β are logically equivalent via truth-tables: – Build a truth table for α and another truth table for β – Compare their final columns; if they are equal then they are equivalent – You must use the truth values of the propositions exactly in the same order, that is, if a proposition is true/false in one formula, it is true/false in the other – Moral is: two formulae may appear different, yet they "mean" the same thing. – Issues about meaning the same thing (morning star and evening star). Logical equivalence 2 25 CS1022

Prove that (P or Q) and not ((not P) and (not Q)) are logically equivalent Logical equivalence 3 26 CS1022 PQnot Pnot Q (not P) and (not Q) not ((not P) and (not Q)) TT TF FT FF PQ(P or Q) TTT TFT FTT FFF PQnot Pnot Q (not P) and (not Q) not ((not P) and (not Q)) TTF TFF FTT FFT PQnot Pnot Q (not P) and (not Q) not ((not P) and (not Q)) TTF TFF FTT FFT PQnot Pnot Q (not P) and (not Q) not ((not P) and (not Q)) TTFF TFFT FTTF FFTT PQnot Pnot Q (not P) and (not Q) not ((not P) and (not Q)) TTFF TFFT FTTF FFTT PQnot Pnot Q (not P) and (not Q) not ((not P) and (not Q)) TTFFF TFFTF FTTFF FFTTT PQnot Pnot Q (not P) and (not Q) not ((not P) and (not Q)) TTFFF TFFTF FTTFF FFTTT PQnot Pnot Q (not P) and (not Q) not ((not P) and (not Q)) TTFFFT TFFTFT FTTFFT FFTTTF PQnot Pnot Q (not P) and (not Q) not ((not P) and (not Q)) TTFFFT TFFTFT FTTFFT FFTTTF PQ(P or Q) TTT TFT FTT FFF

Logical equivalence 4 27 CS1022 From Rosen (2007) T represents *any* true proposition. F represents *any* false proposition.

Logical equivalence 5 28 CS1022 From Rosen (2007)

You should now know: Why logic and proof are important to computing Propositional logic: syntax and meaning How to write truth tables Logical equivalences Summary 29 CS1022

Further reading R. Haggarty. “Discrete Mathematics for Computing”. Pearson Education Ltd (Chapter 2) Wikipedia article ( onal_calculus) onal_calculus Chapter of a book ( /chap3.pdf) /chap3.pdf 30 CS1022