A Logic Primer. Stavros Tripakis University of California, Berkeley

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

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

Propositional Logic: Models and Proofs

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)

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

Propositional Logic and Semantics

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

Classical First-Order Logic

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

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

MAI0203 Lecture 7: Inference and Predicate Calculus

Predicate Logic - Introduction

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

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

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

Tutorial 1: Modern SMT Solvers and Verification

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

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

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

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

A brief introduction to Logic. (slides from

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

First Order Logic (FOL) 1 znj/dm2017

First-Order Logic (FOL)

First Order Logic: Syntax and Semantics

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)

Comp487/587 - Boolean Formulas

Propositional Logic: Review

Classical First-Order Logic

Part I: Propositional Calculus

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

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)

06 From Propositional to Predicate Logic

Propositional and Predicate Logic - II

PROPOSITIONAL LOGIC. VL Logik: WS 2018/19

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

Propositional Logic: Logical Agents (Part I)

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

Tecniche di Verifica. Introduction to Propositional Logic

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

Predicate Logic: Syntax

Introduction to Logic in Computer Science: Autumn 2006

G52DOA - Derivation of Algorithms Predicate Logic

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

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

Propositional Logic: Syntax

Advanced Topics in LP and FP

Automated Reasoning Lecture 5: First-Order Logic

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



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

Logics - Introduction


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.

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

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

CS156: The Calculus of Computation

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

Logic. Propositional Logic: Syntax

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

First-Order Predicate Logic. Basics

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

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

Artificial Intelligence

Reasoning Under Uncertainty: Introduction to Probability

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

An Introduction to Modal Logic III

Section Summary. Section 1.5 9/9/2014

Logic. Propositional Logic: Syntax. Wffs

Lecture 3: Semantics of Propositional Logic

Satisfiability Modulo Theories

First-Order Theorem Proving and Vampire

Introduction to Sets and Logic (MATH 1190)

Propositional Logic. Testing, Quality Assurance, and Maintenance Winter Prof. Arie Gurfinkel

Outline. Formale Methoden der Informatik First-Order Logic for Forgetters. Why PL1? Why PL1? Cont d. Motivation

22c:145 Artificial Intelligence

Logic: The Big Picture

Logic Propositional logic; First order/predicate logic

Automated Reasoning Lecture 2: Propositional Logic and Natural Deduction

Syntax. Notation Throughout, and when not otherwise said, we assume a vocabulary V = C F P.

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

Logic Background (1A) Young W. Lim 12/14/15

Reasoning. Inference. Knowledge Representation 4/6/2018. User

SAT Solvers: Theory and Practice

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

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

Chapter 4: Classical Propositional Semantics

It is not the case that ϕ. p = It is not the case that it is snowing = It is not. r = It is not the case that Mary will go to the party =

Relations to first order logic

Overview. CS389L: Automated Logical Reasoning. Lecture 7: Validity Proofs and Properties of FOL. Motivation for semantic argument method

Logic Synthesis and Verification

Computer-Aided Verification

Classical Propositional Logic

Transcription:

EE 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization Fall 2015 A Logic Primer Stavros Tripakis University of California, Berkeley Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2015 Basic Concepts of Logic 1 / 34 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 logics: Propositional logic First-order logic Temporal logic... Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2015 Basic Concepts of Logic 2 / 34

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 2015 Basic Concepts of Logic 3 / 34 BOOLEAN LOGIC (a.k.a. Propositional Logic or Propositional Calculus) Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2015 Basic Concepts of Logic 4 / 34

Syntax Symbols: Constants: false and true, or 0, 1, or, Variable symbols (atomic propositions): p, q,..., x, y,... Boolean connectives: (and), (or), (not), (implies), or (is equivalent to) Parentheses ( ): used to make syntax unambiguous Expressions (formulas): φ ::= 0 1 p q... x y... φ 1 φ 2 φ 1 φ 2 φ φ 1 φ 2 φ 1 φ 2 Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2015 Basic Concepts of Logic 5 / 34 Syntax Examples: x x x y z (ambiguous) x (y z) (x y) z (p q) (0 p q) usually bings stronger, so p q means ( p) q. Similarly, p q r usually means (p q) r, p q a b usually means (q q) (a b), etc. When unsure, better use parentheses! Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2015 Basic Concepts of Logic 6 / 34

Alternative syntax E.g., instead of, but in modern logic notation, is used for semantical entailment, as in formula φ entails formula φ, or φ φ, meaning that φ is true when φ is true instead of + instead of instead of (often omitted altogether) x instead of x instead of xy + z (x y) ( z) Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2015 Basic Concepts of Logic 7 / 34 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 2015 Basic Concepts of Logic 8 / 34

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 2015 Basic Concepts of Logic 9 / 34 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 2015 Basic Concepts of Logic 10 / 34

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 2015 Basic Concepts of Logic 11 / 34 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 2015 Basic Concepts of Logic 12 / 34

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 2015 Basic Concepts of Logic 13 / 34 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 2015 Basic Concepts of Logic 14 / 34

PREDICATE LOGIC Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2015 Basic Concepts of Logic 15 / 34 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 2015 Basic Concepts of Logic 16 / 34

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 2015 Basic Concepts of Logic 17 / 34 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 2015 Basic Concepts of Logic 18 / 34

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 2015 Basic Concepts of Logic 19 / 34 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 2015 Basic Concepts of Logic 20 / 34

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 2015 Basic Concepts of Logic 21 / 34 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 2015 Basic Concepts of Logic 22 / 34

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 2015 Basic Concepts of Logic 23 / 34 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 2015 Basic Concepts of Logic 24 / 34

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 2015 Basic Concepts of Logic 25 / 34 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 2015 Basic Concepts of Logic 26 / 34

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 2015 Basic Concepts of Logic 27 / 34 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 2015 Basic Concepts of Logic 28 / 34

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 2015 Basic Concepts of Logic 29 / 34 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 2015 Basic Concepts of Logic 30 / 34

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 2015 Basic Concepts of Logic 31 / 34 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 2015 Basic Concepts of Logic 32 / 34

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 2015 Basic Concepts of Logic 33 / 34 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 2015 Basic Concepts of Logic 34 / 34