A Logic Primer. Stavros Tripakis University of California, Berkeley. Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 A Logic Primer 1 / 35

Similar documents
A Logic Primer. Stavros Tripakis University of California, Berkeley

Propositional Logic: Models and Proofs

INTRODUCTION TO PREDICATE LOGIC HUTH AND RYAN 2.1, 2.2, 2.4

Temporal Logic. Stavros Tripakis University of California, Berkeley. We have designed a system. We want to check that it is correct.

Learning Goals of CS245 Logic and Computation

THE LANGUAGE OF FIRST-ORDER LOGIC (FOL) Sec2 Sec1(1-16)

Propositional Logic and Semantics

First-Order Logic. 1 Syntax. Domain of Discourse. FO Vocabulary. Terms

Classical First-Order Logic

A brief introduction to Logic. (slides from

First-Order Logic (FOL)

Propositional and Predicate Logic. jean/gbooks/logic.html

Predicate Calculus. Formal Methods in Verification of Computer Systems Jeremy Johnson

Predicate Logic - Introduction

1 First-order logic. 1 Syntax of first-order logic. 2 Semantics of first-order logic. 3 First-order logic queries. 2 First-order query evaluation

CSCE 222 Discrete Structures for Computing. Propositional Logic. Dr. Hyunyoung Lee. !!!!!! Based on slides by Andreas Klappenecker

First-order Logic (Session 1) Anthony W. Lin Yale-nus College, Singapore

3. Only sequences that were formed by using finitely many applications of rules 1 and 2, are propositional formulas.

Predicate Calculus. CS 270 Math Foundations of Computer Science Jeremy Johnson

Tutorial 1: Modern SMT Solvers and Verification

Propositional Logic: Part II - Syntax & Proofs 0-0

Logic for Computer Science Handout Week 8 DERIVED RULE MODUS TOLLENS DERIVED RULE RAA DERIVED RULE TND

if t 1,...,t k Terms and P k is a k-ary predicate, then P k (t 1,...,t k ) Formulas (atomic formulas)

22c:145 Artificial Intelligence. First-Order Logic. Readings: Chapter 8 of Russell & Norvig.

Comp487/587 - Boolean Formulas

Classical First-Order Logic

Part I: Propositional Calculus

Introduction to Logic in Computer Science: Autumn 2007

Syntax of FOL. Introduction to Logic in Computer Science: Autumn Tableaux for First-order Logic. Syntax of FOL (2)

First Order Logic (FOL) 1 znj/dm2017

First-Order Logic First-Order Theories. Roopsha Samanta. Partly based on slides by Aaron Bradley and Isil Dillig

EECS 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization

First Order Logic: Syntax and Semantics

Tecniche di Verifica. Introduction to Propositional Logic

Announcements. CS243: Discrete Structures. Propositional Logic II. Review. Operator Precedence. Operator Precedence, cont. Operator Precedence Example

Predicate Logic: Syntax

GS03/4023: Validation and Verification Predicate Logic Jonathan P. Bowen Anthony Hall

Introduction to Logic in Computer Science: Autumn 2006

MAI0203 Lecture 7: Inference and Predicate Calculus

PROPOSITIONAL LOGIC. VL Logik: WS 2018/19

EECS 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization

Computational Logic. Davide Martinenghi. Spring Free University of Bozen-Bolzano. Computational Logic Davide Martinenghi (1/26)

Propositional Logic: Syntax

06 From Propositional to Predicate Logic

Computational Logic. Recall of First-Order Logic. Damiano Zanardini

Advanced Topics in LP and FP

Predicate Calculus. Lila Kari. University of Waterloo. Predicate Calculus CS245, Logic and Computation 1 / 59

Propositional logic (revision) & semantic entailment. p. 1/34

Propositional Logic: Review


The non-logical symbols determine a specific F OL language and consists of the following sets. Σ = {Σ n } n<ω

Automated Reasoning Lecture 5: First-Order Logic

Propositional Logic: Logical Agents (Part I)


Intelligent Agents. First Order Logic. Ute Schmid. Cognitive Systems, Applied Computer Science, Bamberg University. last change: 19.

State-Space Exploration. Stavros Tripakis University of California, Berkeley

CS1021. Why logic? Logic about inference or argument. Start from assumptions or axioms. Make deductions according to rules of reasoning.

Stanford University CS103: Math for Computer Science Handout LN9 Luca Trevisan April 25, 2014

G52DOA - Derivation of Algorithms Predicate Logic

Methods of Partial Logic for Knowledge Representation and Deductive Reasoning in Incompletely Specified Domains

Logic. Propositional Logic: Syntax

First-Order Predicate Logic. Basics

3. The Logic of Quantified Statements Summary. Aaron Tan August 2017

Propositional logic. First order logic. Alexander Clark. Autumn 2014

Chapter 2. Logical Notation. Bahar Aameri. Department of Computer Science University of Toronto. Jan 16, Mathematical Expression and Reasoning 1

4 Quantifiers and Quantified Arguments 4.1 Quantifiers

Logics - Introduction

An Introduction to Modal Logic III

Section Summary. Section 1.5 9/9/2014

α-formulas β-formulas

Propositional and Predicate Logic - II

Logic. Propositional Logic: Syntax. Wffs

Lecture 3: Semantics of Propositional Logic

Logic: The Big Picture


Logic Propositional logic; First order/predicate logic

Logic and Modelling. Introduction to Predicate Logic. Jörg Endrullis. VU University Amsterdam

Chapter 4: Classical Propositional Semantics

Logic Synthesis and Verification

Announcements. CS311H: Discrete Mathematics. Propositional Logic II. Inverse of an Implication. Converse of a Implication

Web Science & Technologies University of Koblenz Landau, Germany. Models in First Order Logics

INTRODUCTION TO LOGIC. Propositional Logic. Examples of syntactic claims

Semantics and Generative Grammar. Expanding Our Formalism, Part 1 1

Logic Background (1A) Young W. Lim 5/14/18

Satisfiability Modulo Theories

First-Order Theorem Proving and Vampire

CS156: The Calculus of Computation

Predicate Logic. Xinyu Feng 09/26/2011. University of Science and Technology of China (USTC)

CS 2800: Logic and Computation Fall 2010 (Lecture 13)

Herbrand Theorem, Equality, and Compactness

AAA615: Formal Methods. Lecture 2 First-Order Logic

First-Order Predicate Logic. First-Order Logic 153/467

Artificial Intelligence Knowledge Representation I

Lecture 12. Statement Logic as a word algebra on the set of atomic statements. Lindenbaum algebra.

SAT Solvers: Theory and Practice

AI Principles, Semester 2, Week 2, Lecture 5 Propositional Logic and Predicate Logic

Introduction to first-order logic:

Reasoning Under Uncertainty: Introduction to Probability

Knowledge base (KB) = set of sentences in a formal language Declarative approach to building an agent (or other system):

Examples: P: it is not the case that P. P Q: P or Q P Q: P implies Q (if P then Q) Typical formula:

Transcription:

EE 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization Fall 2014 A Logic Primer Stavros Tripakis University of California, Berkeley Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 A Logic Primer 1 / 35 Logic The α and ω in science. Basis of mathematics. Also of engineering. Particularly useful for verification (model-checking = checking a model against a logical formula). But also used in other domains, e.g.: Prolog, Datalog, UML OCL (Object Constraint Language),... A myriad of variants: Propositional logic First-order logic Temporal logic... Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 A Logic Primer 2 / 35

What is logic? Logic = Syntax + Semantics + Proofs Proofs Example: Manual, or Automated: Proofs = Computations Syntax: boolean formulas Semantics: boolean functions Proofs: is a formula satisfiable? valid (a tautology)? E.g., for boolean logic: an NP-complete problem (a representative for many combinatorial problems). Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 A Logic Primer 3 / 35 BOOLEAN LOGIC (a.k.a. Propositional Logic or Propositional Calculus) Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 A Logic Primer 4 / 35

Syntax Symbols: Constants: false and true, or 0, 1, or, Variable symbols (atomic propositions): p, q,..., x, y,... Boolean connectives: (and), (or), (not), (implies), (is equivalent to) Parentheses: ( ) Expressions (formulas): φ ::= 0 1 p q... x y... φ 1 φ 2 φ 1 φ 2 φ φ 1 φ 2 φ 1 φ 2 (φ ) Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 A Logic Primer 5 / 35 Syntax Examples: x x x y z x (y z) (x y) z (p q) (0 p q) Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 A Logic Primer 6 / 35

Syntax Avoiding ambiguity by directly enforcing parantheses in the syntax: φ ::= 0 1 p q... x y... (φ 1 φ 2 ) (φ 1 φ 2 ) ( φ ) (φ 1 φ 2 ) (φ 1 φ 2 ) So x y z is not allowed, but these are OK: x (y z) (x y) z Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 A Logic Primer 7 / 35 Alternative syntax instead of, instead of, + instead of, instead of, x instead of x,... E.g., instead of xy + z (x y) ( z) Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 A Logic Primer 8 / 35

Semantics The meaning of logical formulas. E.g., what is the semantics of a boolean formula such as p q? If p, then q, of course. So, why do we even need to talk about semantics? Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 A Logic Primer 9 / 35 Semantics What is the meaning of a boolean formula? Different views (all equivalent): A truth table. A boolean function. A set containing the solutions ( models ) of the formula. Why not consider the syntax itself to be the semantics? Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 A Logic Primer 10 / 35

Semantics Formula: Truth table: x (y z) x y z result 0 0 0 0 0 0 1 0 0 1 0 0 0 1 1 0 1 0 0 0 1 0 1 1 1 1 0 1 1 1 1 1 An equivalent formula (different syntax, same semantics): (x y) (x z) Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 A Logic Primer 11 / 35 Semantics Boolean function: a function f : B n B m, where B = {0, 1}. Formula: x (y z) defines 1 the boolean function: f : B 3 B such that: f(0, 0, 0) = 0 f(0, 0, 1) = 0... 1 assuming an order on the variables: (1) x, (2) y, (3) z. Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 A Logic Primer 12 / 35

Semantics A formula φ : x (y z) defines 2 a subset [φ] B 3 : [φ] = {(1, 0, 1), (1, 1, 0), (1, 1, 1)} This is the set of solutions : all assignments to x, y, z which make the formula true. To be independent from an implicit order on variables, we can also view [φ] as a set of minterms: [φ] = {xyz, xyz, xyz} We can also view [φ] as a set of sets of atomic propositions: [φ] = {{x, z}, {x, y}, {x, y, z}} What is the type of [φ] in this last case? [φ] B P = 2 P where P is the set of atomic propositions (= formula variables). 2 assuming an order on the variables: (1) x, (2) y, (3) z. Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 A Logic Primer 13 / 35 Semantics: satisfaction relation Satisfaction relation: a = φ means a is a solution (or model) of φ (or a satisfies φ ). So a = φ iff a [φ] Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 A Logic Primer 14 / 35

Semantics: satisfiability, validity A formula φ is satisfiable if [φ] is non-empty, i.e., if there exists a = φ. A formula φ is valid (a tautology) if for all a, a = φ, i.e., if [φ] = 2 P. Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 A Logic Primer 15 / 35 PREDICATE LOGIC Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 A Logic Primer 16 / 35

Limitations of propositional logic All humans are mortal. How to write it in propositional logic? We can associate one proposition p i for every human i, with the meaning human i is mortal, and then state: p 1 p 2 p 7000000000 But even this is not enough, since we also want to talk about future generations. Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 A Logic Primer 17 / 35 Expressing this in (first-order) predicate logic x : H(x) M(x) x: variable H, M: predicates (functions that return true or false ) H(x): x is human. M(x): x is mortal. : for all quantifier. Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 A Logic Primer 18 / 35

First-Order Predicate Logic (FOL) Syntax Terms: t ::= x c f(t 1,..., t n ) where x is any variable symbol, c is any constant symbol, 3 and f is any function symbol of some arity n. Formulas: φ ::= P (t 1,..., t n ) (φ φ) (φ φ) ( φ) ( x : φ) ( x : φ) where P is any predicate symbol of some arity n, and t i are terms. 3 constants can also be seen as functions of arity 0 Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 A Logic Primer 19 / 35 FOL Syntax Example: x : x > 0 x + 1 > 0 or, more pedantically: x : >(x, 0) >(+(x, 1), 0) 0, 1: constants x: variable symbol +: function symbol of arity 2 >: predicate symbol of arity 2 Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 A Logic Primer 20 / 35

FOL Syntax Note: This is also a syntactically well-formed formula: x > 0 x + 1 > 0 so is this: x : x > y or this: x : 2z > f(y) Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 A Logic Primer 21 / 35 Parse Tree of Formula Formula: x : x > 0 x + 1 > 0 Parse tree: x > > x 0 + 0 x 1 Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 A Logic Primer 22 / 35

Free and Bound Variables Formula: x : x > y Parse tree: x > x y y is free in the formula: no ancestor of the leaf node y is a node of the form y or y. x is bound in the formula: has ancestor x. Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 A Logic Primer 23 / 35 Scope of Variables Formula: ( x : x = x x : P (x)) x > 0 Parse tree: x > x 0 = x x x P x Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 A Logic Primer 24 / 35

Renaming Formula: ( x : x = x x : P (x)) x > 0 ( y : y = y z : P (z)) x > 0 Parse tree: y > x 0 = z y y P z Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 A Logic Primer 25 / 35 FOL Semantics In propositional logic, a solution (model) of a formula was simply an assignment of truth values to the propositional variables. E.g., (p := 1, q := 0) }{{} model = p q }{{} formula What are the solutions (models) of predicate logic formulas? }{{}??? = x : P (x) y : Q(x, y) }{{} model formula Cannot give meaning to the formula without first giving meaning to P, Q. Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 A Logic Primer 26 / 35

FOL Semantics Let P and F be the sets of predicate and function symbols (for simplicity F also includes the constants). A model M for the pair (P, F) consists of the following: Note: A non-empty set U, the universe of concrete values. For each 0-arity symbol c F, a concrete value c M U. For each f F with arity n, a function f M : U n U. For each P P with arity n, a set P M U n. c, f, P are just symbols (syntactic objects). c M, f M, P M are semantical objects (values, functions, sets). Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 A Logic Primer 27 / 35 FOL Semantics Example: Let M be such that x : P (x) y : Q(x, y) U = N: the set of naturals. P M = {0, 2,...}: the set of even naturals. Q M = {(0, 1), (1, 2), (2, 3),...}: the set of pairs (n, n + 1), for n N. Then the statement above is true. Of course, it could have been written more clearly (for a human): x : Even(x) y : y = x + 1... but a computer (or a person who does not speak English) is equally clueless as to what P or Even means... Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 A Logic Primer 28 / 35

FOL Semantics Example: x : P (x) y : Q(x, y) Let M be another model such that U = N: the set of naturals. P M = {0, 2,...}: the set of even naturals. Q M = {(1, 0), (3, 1), (5, 2),...}: the set of pairs (2n + 1, n), for n N. Then the statement above is false. Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 A Logic Primer 29 / 35 FOL Semantics What is the meaning of x : x > y? Undefined if we know nothing about the value of y. We need one more thing: environments (or look-up tables for variables). Environment: l : VariableSymbols U assigns a concrete value to every variable symbol. Notation: l[x a] is a new environment l such that l (x) = a and l (y) = l(y) for any other variable y. Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 A Logic Primer 30 / 35

FOL Semantics: Giving concrete values to terms Once we have M and l, every term evaluates to a concrete value in U. Example: M: U = N, 0 = 0, 1 = 1,..., + = addition function,... l: x 2, y 1 term t value M l (t) x + 1 3 x y 2... For a term t, we denote this value by M l (t). Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 A Logic Primer 31 / 35 FOL Semantics Finally we can define the satisfaction relation for first-order predicate logic (M: model, l: environment, φ: formula): M, l = φ M, l = P (t 1,..., t n ) iff ( M l (t 1 ),..., M l (t n ) ) P M M, l = φ 1 φ 2 iff M, l = φ 1 and M, l = φ 2 M, l = φ iff M, l = φ M, l = x : φ iff for all a U : M, l[x a] = φ holds M, l = x : φ iff for some a U : M, l[x a] = φ holds Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 A Logic Primer 32 / 35

FOL Semantics: Satisfiability, Validity A FOL formula φ is satisfiable if there exist M, l such that M, l = φ holds. A formula φ is valid (a tautology) if for all M, l, it holds M, l = φ. Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 A Logic Primer 33 / 35 FOL Semantics: Satisfiability, Validity Examples: 1 x : P (x) P (x) Valid. 2 x 0 f(x) 0 y 0 f(y) 0 x y Satisfiable. Example model: U = N, x 0, y 1, f( ) 0, is the not equal to relation on N: {(0, 1), (0, 2),..., (1, 0), (1, 2),...}. 3 x + 2 = y f(read(write(a, x, 3), y 2)) f(y x + 1) Satisfiable with a non-standard interpretation of +, or read, write. Unsatisfiable with the standard interpretation of those symbols (theories of arithmetic and arrays). Why? Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 A Logic Primer 34 / 35

Bibliography Biere, A., Heule, M., Van Maaren, H., and Walsh, T. (2009). Handbook of Satisfiability. IOS Press. Huth, M. and Ryan, M. (2004). Logic in Computer Science: Modelling and Reasoning about Systems. Cambridge University Press. Tourlakis, G. (2008). Mathematical Logic. Wiley. Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 A Logic Primer 35 / 35