COMP Intro to Logic for Computer Scientists. Lecture 2

Similar documents
Propositional Logic:

Back to the knights and knaves island

Section 1.1 Logic LOGIC

Propositional Calculus: Boolean Algebra and Simplification. CS 270: Mathematical Foundations of Computer Science Jeremy Johnson

L05 - Negating Statements

Propositional Calculus

COMP Primitive and Class Types. Yi Hong May 14, 2015

Definition: A context-free grammar (CFG) is a 4- tuple. variables = nonterminals, terminals, rules = productions,,

Mathematical Logic Part One

Selenium Class 9 - Java Operators

1. Define admissibility and suggest an admissible heuristic functions for the Rubik s cube. (half-twist is counted as a single move).

Program Verification & Testing; Review of Propositional Logic

Notes. Notes. Introduction. Notes. Propositional Functions. Slides by Christopher M. Bourke Instructor: Berthe Y. Choueiry.

1. Logic as a subject matter is the study of logics, understood as models of acceptable inference patterns

CA4003 Compiler Construction Assignment Language Definition

Mathematical Logic Part One

Introduction to Programming in C Department of Computer Science and Engineering. Lecture No. #23 Loops: Precedence of Operators

Mathematical Logic Prof. Arindama Singh Department of Mathematics Indian Institute of Technology, Madras. Lecture - 9 Normal Forms

Propositional Calculus: Boolean Functions and Expressions. CS 270: Mathematical Foundations of Computer Science Jeremy Johnson

Control structures: if

CS 380/480 Foundations of Artificial Intelligence Winter 2007 Assignment 2 Solutions to Selected Problems

COMP Logic for Computer Scientists. Lecture 23

Flow Control. So Far: Writing simple statements that get executed one after another.

npm run pull npm start

Propositional Calculus. Math Foundations of Computer Science

Introduction. The Quine-McCluskey Method Handout 5 January 24, CSEE E6861y Prof. Steven Nowick

1.1 The Fifth Trial pages 18 and 25

Knowledge Representation

VARIABLES & ASSIGNMENTS

Implementation of a Sudoku Solver Using Reduction to SAT

Logical statements and. Lecture 1 ICOM 4075

CS Introduction to Data Structures How to Parse Arithmetic Expressions

MATVEC: MATRIX-VECTOR COMPUTATION LANGUAGE REFERENCE MANUAL. John C. Murphy jcm2105 Programming Languages and Translators Professor Stephen Edwards

Discrete structures - CS Fall 2017 Questions for chapter 2.1 and 2.2

Operators. Java operators are classified into three categories:

To prove something about all Boolean expressions, we will need the following induction principle: Axiom 7.1 (Induction over Boolean expressions):

Warmup Problem. Translate the following sentence from English into Propositional Logic. I want to eat ice cream even though I am on a diet.

Boolean Algebra A B A AND B = A*B A B A OR B = A+B

Le L c e t c ur u e e 2 To T p o i p c i s c t o o b e b e co c v o e v r e ed e Variables Operators

Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Chapter 6 Outline. Unary Relational Operations: SELECT and

CSC 501 Semantics of Programming Languages

LECTURE 3 C++ Basics Part 2

Math Week in Review #5. A proposition, or statement, is a declarative sentence that can be classified as either true or false, but not both.

Recursive definition of sets and structural induction

Homework 1. Due Date: Wednesday 11/26/07 - at the beginning of the lecture

Propositional Logic. Application of Propositional logic

Mixed Integer Linear Programming

Chapter 9 Deductive Arguments II Truth-Functional Logic. Tutorial: Truth Tables

[Ch 6] Set Theory. 1. Basic Concepts and Definitions. 400 lecture note #4. 1) Basics

GO - OPERATORS. This tutorial will explain the arithmetic, relational, logical, bitwise, assignment and other operators one by one.

Boolean algebra, conditional statements, loops.

COP 3402 Systems Software Syntax Analysis (Parser)

Introduction to dependent types in Coq

CITS2211 Discrete Structures Logic

Binary Decision Diagrams

Chapter 3: Propositional Languages

8.3 Common Loop Patterns

Please try all of the TRY THIS problems throughout this document. When done, do the following:

Artificial Intelligence Notes Lecture : Propositional Logic and Inference

Formal Methods of Software Design, Eric Hehner, segment 1 page 1 out of 5

CS Bootcamp Boolean Logic Autumn 2015 A B A B T T T T F F F T F F F F T T T T F T F T T F F F

To prove something about all Boolean expressions, we will need the following induction principle: Axiom 7.1 (Induction over Boolean expressions):

Solutions to Exercises

Logic Informatics 1 Functional Programming: Tutorial 6

CS40-S13: Functional Completeness

Problem Solving through Programming In C Prof. Anupam Basu Department of Computer Science & Engineering Indian Institute of Technology, Kharagpur

1/31/2017. Expressions are Used to Perform Calculations. ECE 120: Introduction to Computing. Five Arithmetic Operators on Numeric Types

9/2/2016. Expressions are Used to Perform Calculations. ECE 120: Introduction to Computing. Five Arithmetic Operators on Numeric Types

Solutions to In-Class Problems Week 1, Fri

Announcements. Homework 0: using cin with 10/3 is NOT the same as (directly)

Propositional logic (Ch. 7)

2SAT Andreas Klappenecker

Module 5 - SUMPRODUCT Theory - 1

Propositional Calculus. CS 270: Mathematical Foundations of Computer Science Jeremy Johnson

Department of Computer Science

Math 55 - Spring 04 - Lecture notes # 1 - Jan 20 (Tuesday)

Lecture 9. Monday, January 31 CS 205 Programming for the Sciences - Lecture 9 1

Logical Connectives. All kittens are cute. ; I like pizza. ; The sky is blue. ; Triangles have three sides.

BITG 1223: Selection Control Structure by: ZARITA (FTMK) LECTURE 4 (Sem 1, 16/17)

CSE 115. Introduction to Computer Science I

Resolution (14A) Young W. Lim 6/14/14

Lecture 3: Constructing the Natural Numbers

Part IIa: Propositional Logic

Fondamenti della Programmazione: Metodi Evoluti. Lezione 5: Invariants and Logic

Bits, Words, and Integers

Simplifying Logical Formulas

Control Structures. March 1, Dr. Mihail. (Dr. Mihail) Control March 1, / 28

Operators. Lecture 3 COP 3014 Spring January 16, 2018

Announcements. HW0 is posted on schedule, due next Friday at 9pm (pretty easy)

CPSC 121: Models of Computation

Information Science 1

Propositional Logic. Andreas Klappenecker

Logic Haskell Exercises

Lecture 4 Advanced Selection. Nested if-else, if-elseif, operators precedence

Assignment 3: Logical Agents: Solutions

Operators DECREASE in strength toward the Bottom

CSE 20 DISCRETE MATH. Fall

CS221 / Autumn 2017 / Liang & Ermon. Lecture 17: Logic II

Chapter 6 Primitive types

Combinatorial Optimization

Transcription:

COMP 1002 Intro to Logic for Computer Scientists Lecture 2 B 5 2 J

Language of logic: building blocks Proposition: A sentence that can be true or false. A: It is raining in St. John s right now. B: 2+2=7 But not Hi! or what is x? Propositional variables: A, B, C ( or p, q, r) It is a shorthand to denote propositions: B is true, for the B above, means 2+2=7 is true.

Language of logic: connectives Pronunciation Notation Meaning Not A (negation) A Opposite of A is true, A is true when A is false A and B (conjunction) A B True if both A and B are true A or B (disjunction) A B True if either A or B are true (or both) If A then B (implication) A B True whenever if A is true, then B is also true Let A be It is sunny and B be it is cold A: It is not sunny A B: It is sunny and cold A B: It is either sunny or cold A B: If it is sunny, then it is cold Can build longer formulas by combining smaller formulas using connectives. And parentheses: will see later when can remove them.

Longer formulas Let A be It is sunny, B be it is cold, C be It s snowing Pronunciation Notation True when A and B A /\ B Both A and B must be true What are the translations of: (B C) ( A) AND THEN If it is cold and snowing, then it is not sunny B C A THEN OR If it is cold, then it is either snowing or sunny A or B A \/ B Either A or B must be true (or both) If A then B A -> B if A is true, then B is also true Not A ~A Opposite of A is true IF ( ) NOT IF ( ) IF ( NOT AND ) (( A) A) C If it is sunny and not sunny, then it is snowing. THEN

The truth We talk about a sentence being true or false when the values of the variables are known. If we didn t know whether it is sunny, or whether it is cold, then we would not know whether A B is true or false. Truth assignment: setting values of all propositional variables to true or false. It is sunny, it is not cold, it is snowing A=true, B=false, C= true Satisfying assignment for a sentence: assignment that makes it true. (Otherwise, falsifying assignment). A=true, B=true satisfies A B A=true, B=false falsifies A B

if... then in logic Last class puzzle has a logical structure: if A then B J 5 What circumstances make this true? A is true and B is true J 5 A is true and B is false J 2 A is false and B is true B 5 A is false and B is false B 2

Truth tables A B not A A and B A or B if A then B True True False True True True True False False False True False False True True False True True False False True False False True A True True False False B True False True False Let A be It is sunny B be it is cold When it is true that it is sunny and true that it is cold, it is true that it is either sunny or cold. When A is true, B is true, then A B is true When it is true that it is sunny, but false that it is cold, then it is both sunny and cold is false. When A is true, B is false, then A B is false.

Order of precedence Combine to make longer formulas In arithmetic: Pronunciation Notation True when Not A A Opposite of A is true A and B A B Both A and B must be true A or B A B Either A or B must be true (or both) 6 + -5 * 7 + 8 = (6+ ((-5)* x)) + 8 First negate 5, then multiply -5 and x, then add this to 6, add result to 8. Order: unary -, then *, then +. In logic formulas 1. Negation ( ) first: like unary minus 2. then AND ( ): like times (*) 3. then OR ( ): like plus (+) 4. Only then "if then" ( ) 5. Parentheses as in arithmetic formulas If A then B A B if A is true, then B is also true A B (C A) A is A B (C A) A Make sure to keep track of parentheses!!! A B C is not the same as A B C, just like 2 + 3 4 2 + 3 4 Check the scenario when A is true, but both B and C are false.

Parse trees Order of precedence in arithmetic: First unary minus (-), then multiplication (*), then addition (+) Parse tree: a way to visualize the order of precedence The last operation on top The numbers/variables on the bottom. Branch points (nodes) marked by arithmetic operations. To compute a value at a branch point (node), compute all values below it. + + 8 6 x 5 6 + -5 * x + 8 = (6+ ((-5)* x)) + 8 + 4 6 + 8 x 5 4* 6 + (-5 + x) * 8 = (4*6)+ (( (-5)+ x)* 8)

Parse trees in logic formulas Precedence: first, then, then, last is like a unary minus, like * and like + Parse tree: a way to visualize the order The last operation on top Variables on the bottom. Branch points marked by connectives. A B C A A B C A Which is A B C A A B C is A B C which is different from A B C A B C A A C B C A B A B C (A B) C

Evaluating logic formulas Precedence: first, then, then, last is like a unary minus, like * and like + Like in arithmetic: evaluate bottom-up, Start with variables, then go up the tree computing the value of each node. Example: Let A be false, B be true and C be false. Evaluate A B C A (which is A B C A) Pronunciation Notation True when Not A A Opposite of A is true A and B A B Both A and B must be true A or B A B Either A or B must be true (or both) If A then B A B if A is true, then B is also true A B 1. B is false Negation of true is false 2. A ( B) is false False and true is false 3. C is true 4. (A ( B)) ( C) is true False or true is true 5. A B C A is false If G then H is false when G is true and H is false C A

Truth tables for longer formulas Longer formulas List all possible combinations of assigning TRUE/FALSE to all variables. For each of them, find the value of the whole formula by evaluating bottom-up like in arithmetic Use the parse tree. B Example: ( A) B Notice: its truth table s last column is the same as for A B So ( A) B and A B are equivalent. A A B Not A (Not A) or B True True False True True False False False False True True True False False True True

Knights and knaves On a mystical island, there are two kinds of people: knights and knaves. Knights always tru tell the truth. Knaves always lie. Raymond Smullyan

Knights and knaves On a mystical island, there are two kinds of people: knights and knaves. Knights always tell the truth. Knaves always lie. Puzzle 1: You meet two people on the island, Arnold and Bob. Arnold says Either I am a knave, or Bob is a knight. Is Arnold a knight or a knave? What about Bob?