Propositional Calculus: Boolean Functions and Expressions

Slides:



Advertisements
Similar presentations
1 Programming Languages (CS 550) Mini Language Interpreter Jeremy R. Johnson.
Advertisements

Semantics Static semantics Dynamic semantics attribute grammars
Disjunctive Normal Form CS 680: Formal Methods Jeremy Johnson.
Fall Semantics Juan Carlos Guzmán CS 3123 Programming Languages Concepts Southern Polytechnic State University.
Termination Analysis Math Foundations of Computer Science.
Brief Introduction to Logic. Outline Historical View Propositional Logic : Syntax Propositional Logic : Semantics Satisfiability Natural Deduction : Proofs.
From Chapter 4 Formal Specification using Z David Lightfoot
Let remember from the previous lesson what is Knowledge representation
Propositional Calculus Math Foundations of Computer Science.
Propositional Calculus Math Foundations of Computer Science.
Propositional Calculus CS 680: Formal Methods in Verification Computer Systems Jeremy Johnson.
Adapted from Discrete Math
SAT Solver Math Foundations of Computer Science. 2 Boolean Expressions  A Boolean expression is a Boolean function  Any Boolean function can be written.
Predicates and Quantifiers
Intro to Discrete Structures
Syntax & Semantic Introduction Organization of Language Description Abstract Syntax Formal Syntax The Way of Writing Grammars Formal Semantic.
Systems Architecture I1 Propositional Calculus Objective: To provide students with the concepts and techniques from propositional calculus so that they.
1 Inference Rules and Proofs (Z); Program Specification and Verification Inference Rules and Proofs (Z); Program Specification and Verification.
Boolean Algebra and Computer Logic Mathematical Structures for Computer Science Chapter 7.1 – 7.2 Copyright © 2006 W.H. Freeman & Co.MSCS Slides Boolean.
CMPF144 FUNDAMENTALS OF COMPUTING THEORY Module 5: Classical Logic.
CS 363 Comparative Programming Languages Semantics.
Logic Design CS 270: Mathematical Foundations of Computer Science Jeremy Johnson.
Propositional Calculus CS 270: Mathematical Foundations of Computer Science Jeremy Johnson.
Chapter 3 Part II Describing Syntax and Semantics.
Logical Agents Chapter 7. Outline Knowledge-based agents Logic in general Propositional (Boolean) logic Equivalence, validity, satisfiability.
Dr. Muhammed Al-MulhemICS (Denotational Semantics)
CS6133 Software Specification and Verification
Disjunctive Normal Form CS 270: Math Foundation of CS Jeremy Johnson.
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 2 Syntax A language that is simple to parse.
LDK R Logics for Data and Knowledge Representation Propositional Logic Originally by Alessandro Agostini and Fausto Giunchiglia Modified by Fausto Giunchiglia,
Albert Gatt LIN3021 Formal Semantics Lecture 3. Aims This lecture is divided into two parts: 1. We make our first attempts at formalising the notion of.
Copyright © 2006 Addison-Wesley. All rights reserved.1-1 ICS 410: Programming Languages Chapter 3 : Describing Syntax and Semantics Denotational Semantics.
1 Section 6.2 Propositional Calculus Propositional calculus is the language of propositions (statements that are true or false). We represent propositions.
Boolean Expression Evaluation CS 270: Math Foundations of CS Jeremy Johnson.
Section 1.4. Propositional Functions Propositional functions become propositions (and have truth values) when their variables are each replaced by a value.
Logics for Data and Knowledge Representation ClassL (part 1): syntax and semantics.
1 Proving Properties of Recursive Functions and Data Structures CS 270 Math Foundations of CS Jeremy Johnson.
CENG 424-Logic for CS Introduction Based on the Lecture Notes of Konstantin Korovin, Valentin Goranko, Russel and Norvig, and Michael Genesereth.
1 Recursive Data Structures CS 270 Math Foundations of CS Jeremy Johnson.
Describing Syntax and Semantics
Propositional Logic (a.k.a. Sentential Logic)
CS 270: Mathematical Foundations of Computer Science
Propositional Equivalence
Lecture 1 – Formal Logic.
Knowledge Representation and Reasoning
The Propositional Calculus
ARTIFICIAL INTELLIGENCE
September 4, 1997 Programming Languages (CS 550) Lecture 6 Summary Operational Semantics of Scheme using Substitution Jeremy R. Johnson TexPoint fonts.
Disjunctive Normal Form
Syntax versus Semantics
Jeremy R. Johnson Wed. Sept. 29, 1999
Propositional Calculus: Boolean Functions and Expressions
Proving Properties of Recursive Functions and Data Structures
Jeremy R. Johnson Anatole D. Ruslanov William M. Mongan
Propositional Calculus: Boolean Algebra and Simplification
Mini Language Interpreter Programming Languages (CS 550)
Elementary Metamathematics
Chapter 1 The Foundations: Logic and Proof, Sets, and Functions
Logics for Data and Knowledge Representation
Logics for Data and Knowledge Representation
What would be our focus ? Geometry deals with Declarative or “What is” knowledge. Computer Science deals with Imperative or “How to” knowledge 12/25/2018.
CS 270 Math Foundations of CS
Simplification of Boolean Expressions
Disjunctive Normal Form
Back to “Serious” Topics…
Computer Security: Art and Science, 2nd Edition
What would be our focus ? Geometry deals with Declarative or “What is” knowledge. Computer Science deals with Imperative or “How to” knowledge 2/23/2019.
Logics for Data and Knowledge Representation
Chapter 7. Propositional and Predicate Logic
This Lecture Substitution model
Presentation transcript:

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

Propositional Calculus September 4, 1997 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 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

September 4, 1997 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. A Boolean function can be described using a truth table. There are 22n Boolean function of n variables. s x0 x1 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 f x0 x1 s Multiplexor function 6 6

Grammars Recursive description of patterns September 4, 1997 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 7

Boolean Expression Grammar September 4, 1997 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. Also uses & 8 8

Example Derivation    BExpr    BExpr BExpr Variable BExpr p  p  p  BExpr BExpr Constant BExpr T BExpr

Example Derivation       p  p  p    T BExpr T T   BExpr 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 September 4, 1997 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 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 September 4, 1997 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)) [ else nil ] ) ) 14 14

Semantics of Boolean Expressions September 4, 1997 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 15

Evaluating Expression Trees Assume p = T and q = F  p=T  T  q=F  p=T  T  p=T T T

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 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 September 4, 1997 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 x0 x1 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 (s  x0  x1 )  (s  x0  x1 )  (s  x0  x1 )  (s  x0  x1 ) 20 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 x y x  y 0 0 1 0 1 0 1 0 0 1 1 1 x y x  y 0 0 1 0 1 1 1 0 0 1 1 1 x y x  y 0 0 0 0 1 1 1 0 1 1 1 0 implication Equivalence (iff) xor 21