Formal Methods in Software Engineering 1

Slides:



Advertisements
Similar presentations
Artificial Intelligence
Advertisements

Completeness and Expressiveness
Brief Introduction to Logic. Outline Historical View Propositional Logic : Syntax Propositional Logic : Semantics Satisfiability Natural Deduction : Proofs.
B ϋ CHIS MONADIC SECOND ORDER LOGIC Verification Seminar V.Sowjanya Lakshmi ( Subhasree M.
Rigorous Software Development CSCI-GA Instructor: Thomas Wies Spring 2012 Lecture 11.
Formal Semantics of Programming Languages 虞慧群 Topic 5: Axiomatic Semantics.
Recursive Definitions and Structural Induction
Denotational Semantics Syntax-directed approach, generalization of attribute grammars: –Define context-free abstract syntax –Specify syntactic categories.
Brief Introduction to Logic. Outline Historical View Propositional Logic : Syntax Propositional Logic : Semantics Satisfiability Natural Deduction : Proofs.
Knowledge Representation using First-Order Logic (Part II) Reading: Chapter 8, First lecture slides read: Second lecture slides read:
Search in the semantic domain. Some definitions atomic formula: smallest formula possible (no sub- formulas) literal: atomic formula or negation of an.
Last time Proof-system search ( ` ) Interpretation search ( ² ) Quantifiers Equality Decision procedures Induction Cross-cutting aspectsMain search strategy.
Discrete Mathematics Math 6A Instructor: M. Welling.
CSE115/ENGR160 Discrete Mathematics 01/20/11 Ming-Hsuan Yang UC Merced 1.
Predicates & Quantifiers Goal: Introduce predicate logic, including existential & universal quantification Introduce translation between English sentences.
Relation, function 1 Mathematical logic Lesson 5 Relations, mappings, countable and uncountable sets.
Induction and recursion
ARTIFICIAL INTELLIGENCE [INTELLIGENT AGENTS PARADIGM] Professor Janis Grundspenkis Riga Technical University Faculty of Computer Science and Information.
A Brief Summary for Exam 1 Subject Topics Propositional Logic (sections 1.1, 1.2) –Propositions Statement, Truth value, Proposition, Propositional symbol,
Boolean Algebra and Computer Logic Mathematical Structures for Computer Science Chapter 7.1 – 7.2 Copyright © 2006 W.H. Freeman & Co.MSCS Slides Boolean.
Formal Semantics of Programming Languages 虞慧群 Topic 3: Principles of Induction.
Pattern-directed inference systems
ARTIFICIAL INTELLIGENCE Lecture 3 Predicate Calculus.
LDK R Logics for Data and Knowledge Representation PL of Classes.
© Kenneth C. Louden, Chapter 11 - Functional Programming, Part III: Theory Programming Languages: Principles and Practice, 2nd Ed. Kenneth C. Louden.
Albert Gatt LIN3021 Formal Semantics Lecture 4. In this lecture Compositionality in Natural Langauge revisited: The role of types The typed lambda calculus.
Logics for Data and Knowledge Representation ClassL (part 1): syntax and semantics.
Programming Languages and Design Lecture 3 Semantic Specifications of Programming Languages Instructor: Li Ma Department of Computer Science Texas Southern.
CS6133 Software Specification and Verification
Mathematical Preliminaries
Chapter 2 Logic 2.1 Statements 2.2 The Negation of a Statement 2.3 The Disjunction and Conjunction of Statements 2.4 The Implication 2.5 More on Implications.
LOGIC AND QUANTIFIERS. INTRODUCTION Many algorithms and proofs use logical expressions such as: “IF p THEN q” or “If p1 AND p2, THEN q1 OR q2” Therefore.
CS 285- Discrete Mathematics Lecture 4. Section 1.3 Predicate logic Predicate logic is an extension of propositional logic that permits concisely reasoning.
LDK R Logics for Data and Knowledge Representation First Order Logics (FOL) Originally by Alessandro Agostini and Fausto Giunchiglia Modified by Fausto.
1 CSC384: Intro to Artificial Intelligence Lecture 5.  Knowledge Representation.
Predicates and Quantifiers Dr. Yasir Ali. 1.Predicates 2.Quantifiers a.Universal Quantifiers b.Existential Quantifiers 3.Negation of Quantifiers 4.Universal.
1 First order theories (Chapter 1, Sections 1.4 – 1.5) From the slides for the book “Decision procedures” by D.Kroening and O.Strichman.
Semantics of Predicate Calculus For the propositional calculus, an interpretation was simply an assignment of truth values to the proposition letters of.
Copyright © Peter Cappello 2011 Predicates & Quantifiers.
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.
PREDICATE CALCULS In Propositional Calculus, each atomic symbol denotes a proposition. But there is no way to access the components of an individual assertion.
First-Order Logic Semantics Reading: Chapter 8, , FOL Syntax and Semantics read: FOL Knowledge Engineering read: FOL.
Propositional Logic Rather than jumping right into FOL, we begin with propositional logic A logic involves: §Language (with a syntax) §Semantics §Proof.
Logics for Data and Knowledge Representation ClassL (part 1): syntax and semantics.
1 Chapter 2.1 Chapter 2.2 Chapter 2.3 Chapter 2.4 All images are copyrighted to their respective copyright holders and reproduced here for academic purposes.
Mathematics for Comter I Lecture 3: Logic (2) Propositional Equivalences Predicates and Quantifiers.
Lecture 041 Predicate Calculus Learning outcomes Students are able to: 1. Evaluate predicate 2. Translate predicate into human language and vice versa.
1 Section 7.1 First-Order Predicate Calculus Predicate calculus studies the internal structure of sentences where subjects are applied to predicates existentially.
Logics for Data and Knowledge Representation ClassL (part 1): syntax and semantics.
Chapter 5 With Question/Answer Animations 1. Chapter Summary Mathematical Induction - Sec 5.1 Strong Induction and Well-Ordering - Sec 5.2 Lecture 18.
Propositional Logic (a.k.a. Sentential Logic)
Introduction to Logic for Artificial Intelligence Lecture 2
tautology checking continued
CSE15 Discrete Mathematics 01/23/17
Predicates & Quantifiers
Corky Cartwright January 18, 2017
CS201: Data Structures and Discrete Mathematics I
Logics for Data and Knowledge Representation
Lesson 5 Relations, mappings, countable and uncountable sets
Logics for Data and Knowledge Representation
A Brief Summary for Exam 1
Lesson 5 Relations, mappings, countable and uncountable sets
MA/CSSE 474 More Math Review Theory of Computation
Logics for Data and Knowledge Representation
Discrete Mathematics CMP-200 Propositional Equivalences, Predicates & Quantifiers, Negating Quantified Statements Abdul Hameed
Discrete Mathematics Lecture 4 & 5: Predicate and Quantifier
CS201: Data Structures and Discrete Mathematics I
Representations & Reasoning Systems (RRS) (2.2)
Logics for Data and Knowledge Representation
Presentation transcript:

Formal Methods in Software Engineering 1 Logic Review First Order Logic Propositional Logic Summary Formal Methods in Software Engineering 1

Formal Methods in Software Engineering 2 Logic From Merriam-Webster Online, “Logic is the science of the formal principles of reasoning”. Mathematical logic provides the basis for reasoning the properties and behavior of software systems. First order logic and propositional logic are two logics that are extensively used in software engineering. Formal Methods in Software Engineering 2

Formal Methods in Software Engineering 3 Syntax vs. Semantics The syntax of a logic is the rules that dictate the composition of legal formulas; the semantics of a logic give precise meaning to each formula. Note that without semantics, syntactic elements are meaningless symbols. Formal Methods in Software Engineering 3

Formal Methods in Software Engineering 4 First order logic First order logic uses variables that range over specific domains such as integers or the reals, relations such as ‘’, and functions like ‘’ or ‘+’. It can be used to reason about all the objects in the domain, or to assert that there exists an object satisfying a property. Formal Methods in Software Engineering 4

Formal Methods in Software Engineering 5 Why called first order? An important property of this logic is that it only uses simple variables, i.e., those variables that range directly over the predefined domain. Higher order logics use both simple variables and set variables: Second order logic can use variables that ranger over sets of objects, third order logic can use variables that ranger over sets of sets of objects, … For instance, let x be a simple variable, and Y a set variable. We can express xY in second order logic but not in first order logic. Formal Methods in Software Engineering 5

Formal Methods in Software Engineering 6 Signature The signature of a first order logic defines the syntactic objects, i.e., the building blocks to compose a formula. Formally, G = (V, F, R) includes three sets of disjoint sets: a set of variable symbols V, function symbols F, and relation symbols R. Formal Methods in Software Engineering 6

Formal Methods in Software Engineering 7 Arity The arity of a function or relation symbol refers to the number of arguments the symbol can take. For example, the mathematic function log has arity of 1, the mathematic function add has arity of 2, and so on. Note that a constant symbol is a function symbol of arity 0. Formal Methods in Software Engineering 7

Formal Methods in Software Engineering 8 Term Terms are expressions formed using function symbols and variables. The syntax of a term is formally defined below: term ::= var | const | func (term, term, …, term) add ( add (one, one), v) Formal Methods in Software Engineering 8

Formal Methods in Software Engineering 9 Structure The structure of a first order logic maps syntactic objects in a signature to semantic objects in a domain. Formally, a structure S = (G, D, F, R, f), where G = (V, F, R) is a signature, D is a domain (i.e., a set), F a set of functions, R a set of relations, and a mapping f : F  R  F  R from the function and relation symbols in the signature to actual functions and relations over D. Formal Methods in Software Engineering 9

Formal Methods in Software Engineering 10 Mapping A mapping must preserve the arity of the function and relation symbols, which means that a function (or relation) symbol of arity n is mapped to a domain function (or relation) with n parameters. For instance, the function symbol sub can be mapped to the mathematic function + over integers. Formal Methods in Software Engineering 10

Formal Methods in Software Engineering 11 Assignment An assignment a maps a set V of variables to values in the domain D, denoted as a: V  D. For instance, let V be the set of variables {v1, v2, v3}, and D the set of integers. An example assignment is a = {v1  3, v2  0, v3  -5}. Formal Methods in Software Engineering 11

Term Interpretation Let S = (G, D, F, R, f) be a structure. Let terms(G) be all the terms of a signature G. Let a be an assignment. The term interpretation of S is Ta: terms(G)  D, which maps each term in terms(G) to a value in D. Ta can be recursively defined below: Ta(v) = a(v), for v  V Ta(func(e1, e2, …, en)) = f(func)(Ta(e1), Ta(e2), …, Ta(en)) Formal Methods in Software Engineering 12

Formal Methods in Software Engineering 13 Example Let D be the set of integers. Let a = {v1  2, v2  3, v3  4}. Let f map add to the add function + over the integers. Ta(v1) = a(v1) = 2 Ta(v2) = a(v2) = 3 Ta(v3) = a(v3) = 4 Ta(add(v1, v2)) = f(add)(Ta(v1), Ta(v2)) = 2 + 3 = 5 Ta(add(add(v1, v2), v3)) = f(add)(Ta(add(v1, v2)), Ta(v3)) = 5 + 4 = 9 Formal Methods in Software Engineering 13

Simple formula A simple formula is constructed using relation symbols applied to terms. Formally, simp_form ::= rel(term, term, …, term) | term  term For example, ge (add (one, one), zero) is a simple formula. Important: A term consists of only variables and function symbols, but NOT relation symbols. Formal Methods in Software Engineering 14

First order formula First order formulas include simple formulas, and can also be formed by applying recursively the Boolean operators and the universal and existential quantifiers. Formally, form ::= simp_form | (form  form) | (form  form) | (form  form) | ( form) | (var(form) | var(form) | true | false (ge (one, zero)  ge (add(one, one), v1)) v2 (v1 (ge (v2, v1))) Formal Methods in Software Engineering 15

Formal Methods in Software Engineering 16 Precedence Precedence between Boolean operators can be used to avoid including some of the parentheses. Note that the outermost parentheses can always be ignored. Usually,  has higher precedence over , which in turns has higher precedence over . For example, (a  (b  c)) can be simplified a  b  c. Formal Methods in Software Engineering 16

Formula Interpretation (1) Let S = (G, D, F, R, f) be a structure. Let forms(G) be all the formulas of a signature G. Let a be an assignment. The formula interpretation of S is Ma: forms(G)  {TRUE, FALSE}, which maps each formula in forms(G) to a Boolean value. Formal Methods in Software Engineering 17

Formula Interpretation (2) The interpretation Ma of a formula without quantification can be defined below: Ma(rel(e1, …, en)) = f(rel)(Ta(e1), …, Ta(en)) Ma(e1  e2) = (Ta(e1) = Ta(e2)) Ma(f1  f2) = TRUE iff (Ma(f1) = TRUE and Ma(f2) = TRUE) Ma(f1  f2) = TRUE iff (Ma(f1) = TRUE or Ma(f2) = TRUE) Ma(f1  f2) = TRUE iff (Ma(f1) = FALSE or Ma(f2) = TRUE) Ma( f1) = TRUE iff (Ma(f1) = FALSE) Ma(true) = TRUE Ma(false) = FALSE Formal Methods in Software Engineering 18

Formal Methods in Software Engineering 19 Example Let  = ge(add(add(v1, v2), v3), v2)  ge(v3, v2). Let a be an assignment such that a = { (v1, 2), (v2,3), (v3, 4)}. Let ge is mapped to , and add to +. Ma(ge(add(add(v1, v2), v3), v2)) = f(ge)(Ta(add(add(v1, v2), v3), Ta(v2)) = 9 > 3 = TRUE Ma(ge(v3, v2)) = f(ge)(Ta(v3), Ta(v2)) = 4  3 = TRUE Ma() = TRUE Formal Methods in Software Engineering 19

Formal Methods in Software Engineering 20 Quantified formulas Let a be an assignment, v a variable, and d a value of the chosen domain D. A variant a[d/v] is an assignment that is the same as a except that it assigns d to v. That is, if u  v, a[d/v](u) = a(u); and if u = v, a[d/v](u) = d. The interpretation of quantified formulas is defined as follows: Ma(v()) = TRUE, iff for each d in D, Ma[d/v]() = TRUE Ma(v()) = TRUE, iff there exists d in D so that Ma[d/v]() = TRUE Formal Methods in Software Engineering 20

Model, tautology, contradiction If Ma() = TRUE under structure S, then we say a satisfies  under S, denoted as a s . If a s  for each assignment a, then S is a model of . If s  for every structure S, then  is a tautology. If a s  does not hold for any assignment a and structure s, then  is a contradiction. Formal Methods in Software Engineering 21

Formal Methods in Software Engineering 22 Example a s x  y × 2, where S is the structure that includes the domain of integers, and × is interpreted as multiplication. This holds if a assigns 6 to x and 3 to y. s x × 2  x + x, where S includes the domain of integers, and x and + are interpreted as usual. Thus, S is a model of this formula. (x  y  y  z)  x  z is a tautology. Formal Methods in Software Engineering 22

Syntax vs Semantics Revisited Consider the following formula:  = v1 v2 (v1 < v2  v3 (v1 < v3  v3 < v2)) Is this formula TRUE or FALSE? Now, assume that < does represent less than. Is this formula TRUE or FALSE? Furthermore, assume that the intended domain is integers, is this formula TRUE or FALSE? What if the intended domain is reals? Formal Methods in Software Engineering 23

Formal Methods in Software Engineering 24 Logic Review First Order Logic Propositional Logic Summary Formal Methods in Software Engineering 24

Formal Methods in Software Engineering 25 Syntax In propositional logic, formulas are formed using the following rules: form ::= prop | (form  form) | (form  form) | (form  form) |  form | true | false where prop is a variable over a set of propositional variables AP. Each variable in AP ranges over the Boolean values {TRUE, FALSE}. Formal Methods in Software Engineering 25

Formal Methods in Software Engineering 26 Semantics An assignment a maps a propositional variable in AP to a Boolean value. Formally, a : AP  {TRUE, FALSE}. The interpretation of a formula in propositional logic is defined as in first order logic. That is, Ma(prop) = a(prop), Ma(f1  f2) = Ma(f1)  Ma(f2), and so on. Note that there do not exist the notions of signature and structure. As a result, we can simply write a  when Ma() = TRUE. Formal Methods in Software Engineering 26

Tautology and contradiction A propositional formula is a tautology if it is satisfied by any assignment, and is a contradiction if there is no assignment satisfying it. P V  P P   P  P  (Q  P) Formal Methods in Software Engineering 27

Propositional vs First Order What is the difference between propositional and first order logic? Propositional logic does not have quantification, function and relation symbols. Formal Methods in Software Engineering 28

Formal Methods in Software Engineering 29 Logic Review First Order Logic Propositional Logic Summary Formal Methods in Software Engineering 29

Formal Methods in Software Engineering 30 Summary Logic provides the basis for reasoning software systems. First order logic can only use simple variables. Higher order logics can use set variables. The  quantifier allows to reason properties about all the objects in the domain. The  quantifier allows to assert properties that are satisfied by at least one object. Propositional logic is a simpler formalism than first order logic. Formal Methods in Software Engineering 30