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

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

Propositional Calculus. Math Foundations of Computer Science

Propositional Calculus. Math Foundations of Computer Science

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

SAT Solver. CS 680 Formal Methods Jeremy Johnson

Programming Languages Third Edition

Propositional Logic Formal Syntax and Semantics. Computability and Logic

Proving Properties of Recursive Functions and Data Structures. CS 270 Math Foundations of CS Jeremy Johnson

Chapter 3 (part 3) Describing Syntax and Semantics

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

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

Binary Decision Diagrams

These notes are intended exclusively for the personal usage of the students of CS352 at Cal Poly Pomona. Any other usage is prohibited without

COSC252: Programming Languages: Semantic Specification. Jeremy Bolton, PhD Adjunct Professor

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

Defining Languages GMU

CSC 501 Semantics of Programming Languages

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

CMSC 330: Organization of Programming Languages. Operational Semantics

Streams, Delayed Evaluation and a Normal Order Interpreter. CS 550 Programming Languages Jeremy Johnson

The Eval/Apply Cycle Eval. Evaluation and universal machines. Examining the role of Eval. Eval from perspective of language designer

Functional Programming. Pure Functional Programming

Chapter 3. Describing Syntax and Semantics ISBN

Chapter 3. Describing Syntax and Semantics

Mixed Integer Linear Programming

Chapter 3: Propositional Languages

Chapter 3. Describing Syntax and Semantics

Finite Model Generation for Isabelle/HOL Using a SAT Solver

HOL DEFINING HIGHER ORDER LOGIC LAST TIME ON HOL CONTENT. Slide 3. Slide 1. Slide 4. Slide 2 WHAT IS HIGHER ORDER LOGIC? 2 LAST TIME ON HOL 1

Control Structures. Lecture 4 COP 3014 Fall September 18, 2017

Introduction to Automata Theory. BİL405 - Automata Theory and Formal Languages 1

Goals: Define the syntax of a simple imperative language Define a semantics using natural deduction 1

(a) (4 pts) Prove that if a and b are rational, then ab is rational. Since a and b are rational they can be written as the ratio of integers a 1

CS131 Typed Lambda Calculus Worksheet Due Thursday, April 19th

Boolean expressions. Elements of Programming Languages. Conditionals. What use is this?

Lecture 5. Logic I. Statement Logic

Logic Informatics 1 Functional Programming: Tutorial 6

Software Verification : Introduction

Chapter 3: Syntax and Semantics. Syntax and Semantics. Syntax Definitions. Matt Evett Dept. Computer Science Eastern Michigan University 1999

CS2104 Prog. Lang. Concepts

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

Propositional Logic. Part I

7/25/2016. Example: Addition of Unsigned Bit Patterns. ECE 120: Introduction to Computing. Adding Two Non-Negative Patterns Can Overflow

Chapter 3. Semantics. Topics. Introduction. Introduction. Introduction. Introduction

CS40-S13: Functional Completeness

Semantics. There is no single widely acceptable notation or formalism for describing semantics Operational Semantics

Summer 2017 Discussion 10: July 25, Introduction. 2 Primitives and Define

Principles of Programming Languages 2017W, Functional Programming

CSCE 531 Spring 2009 Final Exam

8.1 Polynomial-Time Reductions

CITS2211 Discrete Structures Logic

CSCI.6962/4962 Software Verification Fundamental Proof Methods in Computer Science (Arkoudas and Musser) Chapter p. 1/27

Implementation of a Sudoku Solver Using Reduction to SAT

Computer-Aided Program Design

Chapter 3. Syntax - the form or structure of the expressions, statements, and program units

Logic and Computation

Lexical and Syntax Analysis. Top-Down Parsing

Semantics via Syntax. f (4) = if define f (x) =2 x + 55.

Denotational Semantics. Domain Theory

Automated Reasoning. Natural Deduction in First-Order Logic

7. Introduction to Denotational Semantics. Oscar Nierstrasz

Computing Fundamentals 2 Introduction to CafeOBJ

Fall 2018 Discussion 8: October 24, 2018 Solutions. 1 Introduction. 2 Primitives

Overview. CS389L: Automated Logical Reasoning. Lecture 6: First Order Logic Syntax and Semantics. Constants in First-Order Logic.

Modules, Structs, Hashes, and Operational Semantics

CS115 - Module 10 - General Trees

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

Reasoning About Programs Panagiotis Manolios

Chapter 10 Part 1: Reduction

Chapter 3. Describing Syntax and Semantics ISBN

Principles of Programming Languages COMP251: Syntax and Grammars

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

CMSC 330: Organization of Programming Languages. Formal Semantics of a Prog. Lang. Specifying Syntax, Semantics

SC/MATH Boolean Formulae. Ref: G. Tourlakis, Mathematical Logic, John Wiley & Sons, York University

CMSC 330: Organization of Programming Languages

Practice Final. Read all the problems first before start working on any of them, so you can manage your time wisely

COMS 1003 Fall Introduction to Computer Programming in C. Bits, Boolean Logic & Discrete Math. September 13 th

Propositional Logic. Andreas Klappenecker

Type Checking. Outline. General properties of type systems. Types in programming languages. Notation for type rules.

University of Illinois at Chicago Department of Computer Science. Final Examination. CS 151 Mathematical Foundations of Computer Science Fall 2012

Lexical and Syntax Analysis

The Arithmetic Operators. Unary Operators. Relational Operators. Examples of use of ++ and

The Arithmetic Operators

Notes for Chapter 12 Logic Programming. The AI War Basic Concepts of Logic Programming Prolog Review questions

Module 9: Trees. If you have not already, make sure you. Read How to Design Programs Sections 14, 15, CS 115 Module 9: Trees

Outline. General properties of type systems. Types in programming languages. Notation for type rules. Common type rules. Logical rules of inference

SMURF Language Reference Manual Serial MUsic Represented as Functions

CMPSCI 250: Introduction to Computation. Lecture #1: Things, Sets and Strings David Mix Barrington 22 January 2014

Compilers. Compiler Construction Tutorial The Front-end

Parsing III. CS434 Lecture 8 Spring 2005 Department of Computer Science University of Alabama Joel Jones

Contents. Chapter 1 SPECIFYING SYNTAX 1

CS 4110 Programming Languages & Logics. Lecture 17 Programming in the λ-calculus

Theorem proving. PVS theorem prover. Hoare style verification PVS. More on embeddings. What if. Abhik Roychoudhury CS 6214

Semantics and Pragmatics of NLP Propositional Logic, Predicates and Functions

An Evolution of Mathematical Tools

A Survey of Mathematics with Applications 8 th Edition, 2009

Introduction. Following are the types of operators: Unary requires a single operand Binary requires two operands Ternary requires three operands

Introductory logic and sets for Computer scientists

Z Notation. June 21, 2018

Lecture 5: Formation Tree and Parsing Algorithm

Transcription:

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

Propositional Calculus Objective: To provide students with the concepts and techniques from propositional calculus so that they can use it to codify logical statements and to reason about these statements. To illustrate how a computer can be used to carry out formal proofs and to provide a framework for logical deduction. 2

Propositional Calculus Topics Motivation: Logical Reasoning Boolean Functions Syntax and Semantics of Boolean Expressions Equivalence of Boolean Functions and Boolean Expressons Evaluating Boolean Expressions Truth tables and Disjunctive Normal Form (DNF)

Word Problem Tom likes Jane if and only if Jane likes Tom. Jane likes Bill. Therefore, Tom does not like Jane. Let p denote Tom likes Jane Let q denote Jane likes Tom Let r denote Jane likes Bill ((p q) r) p encodes the above claim The claim is not valid as the assignment p = true, q = true, and r = true evaluates to false

Limitations of Propositional Calculus Propositions hide the information in the predicates they abstract. Sometimes properties of the hidden information is required to make further deductions. E.G. for integers a,b, and c, (a < b) && (b < c) implies that a < c; however, this can not be deduced without using the order properties of the integers. The predicate calculus allows the use of predicates to encode this additional information. E.G. we can introduce a parameterized predicate lt(a,b) to encode the predicate a < b. Properties such as lt(a,b) && lt(b,c) lt(a,c) can be asserted. This type of notation and deduction is called predicate calculus and will be discussed later. 5

Boolean Functions A Boolean variable has two possible values (true/false) (1/0). A Boolean function has a number of Boolean input variables and has a Boolean valued output. x 0 x 1 f s x 0 x 1 f 0 0 0 0 0 0 1 0 0 1 0 1 0 1 1 1 1 0 0 0 1 0 1 1 A Boolean function can be described using a truth table. There are 2 2n Boolean function of n variables. s Multiplexor function 1 1 0 0 1 1 1 1 6

Grammars Recursive description of patterns Non-terminals (place holders) Terminals Production rules: Non-terminal string of terminals and non-terminals Start symbol Derivation: Apply rules, starting with start symbol until there are no non-terminals All strings derived this way comprise the language generated by the grammar 7

Boolean Expression Grammar BExpr := Constant T F Variable symbol Not BExpr And BExpr BExpr Or BExpr Bexpr OLI Book uses different grammar with paranetheses around Not, And, and Or. 8

Example Derivation BExpr BExpr BExpr Variable BExpr p BExpr p p p BExpr BExpr Constant BExpr T BExpr

Example Derivation p p p T BExpr T BExpr T Variable p T p (T q) q

Parse Tree A valid derivation can be represented by a tree whose nodes are labeled by the subexpression that is generated and whose children correspond to the rhs of the rule p (T q) p (T q) T q q

OLI Boolean Expression Grammar BExpr := Variable sentential letters Not BExpr And (BExpr & Bexpr) Or (BExpr Bexpr) Imply (BExpr Bexpr) Language defined by this grammar called well formed formulas (WFF) 12

Expression Trees Boolean expressions can be represented by a binary tree Internal nodes are operators Leaf nodes are operands Consider p (T q): p T q

Predicate for Boolean Expressions ; return true if the input expr is a Boolean expression (define (booleanexpr? expr) (cond [ (constant? expr) t ] [ (variable? expr) t ] [ (not? expr) (booleanexpr? (op1 expr)) ] [ (or? expr) (and (booleanexpr? (op1 expr)) (booleanexpr? (op2 expr))) ] [ (and? expr) (and (booleanexpr? (op1 expr)) (booleanexpr? (op2 expr))) ] [ else nil ] ) ) 14

Semantics of Boolean Expressions An expression built up from variables, and, or, and not. x y x y 0 0 0 0 1 0 1 0 0 1 1 1 x y x y 0 0 0 0 1 1 1 0 1 1 1 1 x x 0 1 1 0 and or not 15

Evaluating Expression Trees Assume p = T and q = F T p=t p=t p=t T T T T q=f

Evaluation ;Input: expr is a Boolean Expression, env is an environment of variable ; assignments to T or F. Assume all variables in expr are defined in env ;Output: true if expr evaluates to true and false if expr evaluates to false (define (bool-eval expr env) (cond )) [ (constant? expr) expr ) [ (variable? expr) (lookup expr env) ) [ (not? expr) (not (bool-eval (op expr) env)) ) [ (or? expr) (or (bool-eval (op1 expr) env) (bool-eval (op2 expr) env)) ) [ (and? expr) (and (bool-eval (op1 expr) env) (bool-eval (op2 expr) env)) ]

Short Circuit Evaluation define booleaneval(expr, env) Input: expr is a Boolean Expression, env is an environment of variable assignments to T or F. Assume all variables in expr are defined in env Output: true if expr evaluates to true and false if expr evaluates to false if isconstant(expr) return expr if isvariable(expr) return lookup(expr,env) if isnegation(expr) return not booleaneval(operand(expr)) if isdisjunction(expr) if booleaneval(firstoperand(expr)) return true else return booleaneval(secondoperand(expr)) if isdisjunction(expr) if not booleaneval(firstoperand(expr)) return false else return booleaneval(secondoperand(expr))

Short Circuit Evaluation ; Input: expr is a Boolean Expression, env is an environment of variable ; assignments to T or F. Assume all variables in expr are defined in env ; Output: true if expr evaluates to true and false if expr evaluates to false (define (sc-eval expr env) (cond [ (constant? expr) expr ] [ (variable? expr) (lookup expr env) ] [ (not? expr) (not (sc-eval (op expr) env)) ] [ (or? expr) (if (sc-eval (op1 expr) env) #t (sc-eval (op2 expr) env) ) ] [ (and? expr) (if (sc-eval (op1 expr) env) (sc-eval (op2 expr) env) #f ) ] ))

Disjunctive Normal Form A Boolean expression is a Boolean function Any Boolean function can be written as a Boolean expression Write a Boolean expression that evaluates to true for each row in the truth table that is true and false for other rows. The Boolean expression for a given row is the conjunction of the variables that are true and the negation of variables that are false. Take the disjunction of all such rows. E.G. (multiplexor function) ( s x 0 x 1 ) ( s x 0 x 1 ) (s x 0 x 1 ) (s x 0 x 1 ) s x 0 x 1 f 0 0 0 0 0 0 1 0 0 1 0 1 0 1 1 1 1 0 0 0 1 0 1 1 1 1 0 0 1 1 1 1 20

Additional Notation Several additional Boolean functions of two variables have special meaning and are given special notation. By our previous results we know that all boolean functions can be expressed with not, and, and or; so the additional notation is simply a convenience. x y x y 0 0 1 0 1 1 1 0 0 1 1 1 implication x y x y x y x y 0 0 1 0 1 0 1 0 0 1 1 1 Equivalence (iff) x y x y 0 0 0 0 1 1 1 0 1 1 1 0 xor 21