CSC 501 Semantics of Programming Languages

Similar documents
Propositional Logic. Part I

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

CSC Discrete Math I, Spring Sets

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

LOGIC AND DISCRETE MATHEMATICS

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

Discrete Mathematics Lecture 4. Harper Langston New York University

Module 6. Knowledge Representation and Logic (First Order Logic) Version 2 CSE IIT, Kharagpur

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

[Ch 6] Set Theory. 1. Basic Concepts and Definitions. 400 lecture note #4. 1) Basics

Programming Languages Third Edition

Chapter 3 (part 3) Describing Syntax and Semantics

An Annotated Language


This is already grossly inconvenient in present formalisms. Why do we want to make this convenient? GENERAL GOALS

Chapter 3. Describing Syntax and Semantics

Lecture 5. Logic I. Statement Logic

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

Propositional Logic. Andreas Klappenecker

CS 512, Spring 2017: Take-Home End-of-Term Examination

Knowledge Representation

LECTURE 8: SETS. Software Engineering Mike Wooldridge

An Evolution of Mathematical Tools

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

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

FUZZY BOOLEAN ALGEBRAS AND LUKASIEWICZ LOGIC. Angel Garrido

3.7 Denotational Semantics

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

Introductory logic and sets for Computer scientists

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

3.4 Deduction and Evaluation: Tools Conditional-Equational Logic

Chapter 2 & 3: Representations & Reasoning Systems (2.2)

This book is licensed under a Creative Commons Attribution 3.0 License

Foundations of AI. 9. Predicate Logic. Syntax and Semantics, Normal Forms, Herbrand Expansion, Resolution

9/19/12. Why Study Discrete Math? What is discrete? Sets (Rosen, Chapter 2) can be described by discrete math TOPICS

CSE 20 DISCRETE MATH. Fall

Program Verification & Testing; Review of Propositional Logic

Formal Verification. Lecture 10

Proseminar on Semantic Theory Fall 2013 Ling 720 An Algebraic Perspective on the Syntax of First Order Logic (Without Quantification) 1

Computation Club: Gödel s theorem

Summary of Course Coverage

Review of Sets. Review. Philippe B. Laval. Current Semester. Kennesaw State University. Philippe B. Laval (KSU) Sets Current Semester 1 / 16

MA651 Topology. Lecture 4. Topological spaces 2

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

A set with only one member is called a SINGLETON. A set with no members is called the EMPTY SET or 2 N

Note that in this definition, n + m denotes the syntactic expression with three symbols n, +, and m, not to the number that is the sum of n and m.

Part I Logic programming paradigm

SOFTWARE ENGINEERING DESIGN I

Towards a Logical Reconstruction of Relational Database Theory

THREE LECTURES ON BASIC TOPOLOGY. 1. Basic notions.

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

THEORY OF COMPUTATION

CSE 20 DISCRETE MATH. Winter

1 The Axiom of Extensionality

DISCRETE MATHEMATICS

Mathematical Logic Prof. Arindama Singh Department of Mathematics Indian Institute of Technology, Madras. Lecture - 37 Resolution Rules

Alloy: A Lightweight Object Modelling Notation

Chapter 3. Describing Syntax and Semantics ISBN

Chapter 3. Describing Syntax and Semantics

Software Engineering Lecture Notes

The Inverse of a Schema Mapping

AXIOMS FOR THE INTEGERS

CS243, Logic and Computation Sets, functions, and languages

Propositional Logic Formal Syntax and Semantics. Computability and Logic

Axioms: Semantics Aspects of C++ Concepts

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

9.5 Equivalence Relations

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

Introduction to Sets and Logic (MATH 1190)

DATABASE THEORY. Lecture 11: Introduction to Datalog. TU Dresden, 12th June Markus Krötzsch Knowledge-Based Systems

Harvard School of Engineering and Applied Sciences CS 152: Programming Languages

Publication Data. Reading Options. Licence and permissions ISBN Mark Jago, 2007

Handout 9: Imperative Programs and State

Basic Verification Strategy

Logic as a framework for NL semantics. Outline. Syntax of FOL [1] Semantic Theory Type Theory

Lecture 1: Conjunctive Queries

Section 2.2: Introduction to the Logic of Quantified Statements

The three faces of homotopy type theory. Type theory and category theory. Minicourse plan. Typing judgments. Michael Shulman.

Lecture Notes on Real-world SMT

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

Meeting13:Denotations

Contents. Chapter 1 SPECIFYING SYNTAX 1

Taibah University College of Computer Science & Engineering Course Title: Discrete Mathematics Code: CS 103. Chapter 2. Sets

Antisymmetric Relations. Definition A relation R on A is said to be antisymmetric

Appendix 1. Description Logic Terminology

Chapter 3: Propositional Languages

1.3. Conditional expressions To express case distinctions like

1 Introduction CHAPTER ONE: SETS

Propositional Logic:

Appendix 1. Description Logic Terminology

2.2 Set Operations. Introduction DEFINITION 1. EXAMPLE 1 The union of the sets {1, 3, 5} and {1, 2, 3} is the set {1, 2, 3, 5}; that is, EXAMPLE 2

Formal Methods in Software Engineering 1

ELEMENTARY NUMBER THEORY AND METHODS OF PROOF

H1 Spring B. Programmers need to learn the SOAP schema so as to offer and use Web services.

Chapter 3. Set Theory. 3.1 What is a Set?

Meeting14:Denotations

ELEMENTARY NUMBER THEORY AND METHODS OF PROOF

Today s Topics. What is a set?

Mathematically Rigorous Software Design Review of mathematical prerequisites

Logic and Discrete Mathematics. Section 2.5 Equivalence relations and partitions

Transcription:

CSC 501 Semantics of Programming Languages Subtitle: An Introduction to Formal Methods. Instructor: Dr. Lutz Hamel Email: hamel@cs.uri.edu Office: Tyler, Rm 251

Books There are no required books in this course; however, occasionally I will assign readings based on material available on the web.

Course Objectives The aim of this course is to Familiarize you with the basic techniques of applying formal methods to programming languages. This includes constructing models for programming languages and using these models to prove properties such as correctness and equivalence of programs. Look at all major programming language constructs including assignments, loops, type systems, and procedure calls together with their models. Introduce mechanical theorem provers so that we can test and prove properties of non-trivial programs.

Some Definitions Definition: In programming language semantics we are concerned with the rigorous mathematical study of the meaning of programming languages. The meaning of a language is given by a formal system that describes the possible computations expressible within that language.

Some Definitions Definition: In computer science and software engineering, formal methods are techniques for the specification, development and verification of software and hardware systems based on formal systems.

Formal Systems Definition: A formal system consists of a formal language and a set of inference rules. The formal language is composed of primitive symbols that make up well formed formulas and the inference rules are used to derive expressions from other expressions within the formal system. A formal system may be formulated and studied for its intrinsic properties, or it may be intended as a description (i.e. a model) of external phenomena. 1 In order to be truly useful in computer science, we require our formal systems to be machine executable. 1 Wikipedia

Uses of Formal Methods Implementation Issues Formally specified models can be considered machine-independent specifications of program behavior. They can act as yard sticks for the correctness of program implementations, transformations, and optimizations. Verification Basis of methods for reasoning about program properties (e.g. equivalence) and program specifications (program correctness). Language Design Can bring to light ambiguities and unforeseen subtleties in programming language constructs.

Observations When programming we can observe two mental activities: We construct correct looking programs - syntactically correct programs. We construct models of the intended computation in our minds. Consider, x := 1 while (x <= 10) do writeln(x) x := x + 1 end whiledo Any person with some familiarity of programming immediately has a mental picture that this program will generate a list of integers from 1 through 10.

Programming Language Definitions Mirroring our intuition, language definitions consist of two parts: Syntax The formal description of the structure of well-formed expressions, phrases, programs, etc. Semantics The formal description of the meaning of the syntactic features of a programming language usually understood in terms of the runtime behavior each syntactic construct evokes. The formal description of the behavior of all the syntactic features of a language is considered a model of the language.

Evaluation/Interpretation Syntax and semantics of a programming language are usually related via an evaluation relation or interpretation, say h. Then we say that the interpretation h takes each syntactic element and maps it into the appropriate semantic construct. We often represent this with the diagram Semantics h Syntax Note: In order for the interpretation h to make any sense we will have to define the syntax and semantics in terms of sets.

Formal Systems and Programs The formal systems we will be using in this course are: A variant of string rewriting systems called a grammar to model the syntax of programming languages. The first order predicate calculus (often also called first order logic) to construct semantics of programming languages.

Readings Read Chapter 0 in Denotational Semantics by David Schmidt (available from the course website). Read Sections 2.1 and 2.2 in Denotational Semantics by David Schmidt.

Mathematical Preliminaries: Logical Notation We 2 will use first order logic as the basis for our reasoning. Without going into the formal details of first order logic terminology and sentence construction we have the following statements: A B denotes the conjunction A and B, A B denotes the disjunction A or B, A denotes the negation not A, A B denotes the implication, if A then B, A B denotes the logical equivalence, A if and only if B (often written as A iff B), where A and B are statements or assertions. 2 The material presented here is based on Naive Set Theory by P. Halmos and The Formal Semantics of Programming Languages by G. Winskel.

Mathematical Preliminaries: Logical Notation Observe the precedences of the logical operators, ordered from high to low:,,

A Word or Two about Implication The truth table for the implication operator can be given as A B A B (1) 1 0 0 (2) 1 1 1 (3) 0 0 1 (4) 0 1 1 Entries (1) and (2) are intuitive: When the antecedent A is true but the consequent B is false then the implication itself is false. If both the antecedent and the consequent are true then the implication is true. However, entries (3) and (4) are somewhat counter intuitive. They state that if the antecedent A is false then the implication is true regardless of the value of the consequent. In other words, we can conclude anything from an antecedent that is false. In mathematical jargon we say that (3) and (4) hold trivially.

A Word or Two about Implication An Example If Bob is a bachelor, then he is single. Bob is a bachelor. Bob is single. Now consider an antecedent that is not true, If Bob is a bachelor, then he is single. Bob is not a bachelor. Bob is not single (by rule (3)). Since the antecedent is not true rule (3) allows us to conclude the opposite of what the implication dictates. However, the following is also valid reasoning, If Bob is a bachelor, then he is single. Bob is not a bachelor. Bob is single (by rule (4)). Not being a bachelor does not necessarily imply that Bob is not single. For example, Bob could be a widower or a divorcee.

A Word or Two about Implication Given the truth table for implication, A B A B (1) 1 0 0 (2) 1 1 1 (3) 0 0 1 (4) 0 1 1 this means that in order to show that an implication holds we only have to show that rule (2) holds. Rule (1) states that the implication is false and rules (3) and (4) are trivially true and therefore not interesting.

Closely Related: Equivalence We write A B if A and B are equivalent. Given the truth table for the equivalence operator is given as, A B A B (1) 1 0 0 (2) 1 1 1 (3) 0 0 1 (4) 0 1 0 That is, the operator only produces a true value if A and B have the same truth assignment. Another, and very useful, way to look at the equivalence operator is as follows: A B A B B A Exercise: Construct the above truth table using this definition of the equivalence operator.

Mathematical Preliminaries: Logical Notation We also allow predicates (properties) as part of our notation, P(x) where the predicate P is true if it holds for x otherwise it is false. We view our standard relational operators as binary predicates. For example, the predicate P(x) that expresses the fact that x is less or equal to 3 is written as, P(x) x 3. Note: Predicates can have arities larger than 1, e.g. P(x, y) with P(x, y) x y.

Mathematical Preliminaries: Logical Notation We also allow for the quantifiers (there exists) and (for all) in our logical statements, x. P(x) there exists an x such that P(x) x. P(x) for all x such that P(x) Some examples, x, y. y = x 2 x, y. female(x) child(x, y) mother(x, y)

Mathematical Preliminaries: Sets Sets 3 are unordered collections of objects and are usually denoted by capital letters. For example, let a, b, c denote some objects then the set A of these objects is written as, A = {a, b, c}. There are a number of standard sets which come in handy, denotes the empty set, i. e. = {}, N denotes the set of all natural numbers including 0, e. g. N = {0, 1, 2, 3, }, I denotes the set of all integers, I = {, 2, 1, 0, 1, 2, }, R denotes the set of all reals, B denotes the set of boolean values, B = {true, false}. 3 Read Sections 2.1 and 2.2 in the book by David Schmidt.

Mathematical Preliminaries: Sets The most fundamental property in set theory is the notion of belonging, a A iff a is an element of the set A. The notion of belonging allows us to define subsets, We define set equivalence as, Z A iff e Z. e A. A = B iff A B B A

Mathematical Preliminaries: Sets We can construct new sets from given sets using union, and intersection, A B = {e e A e B}, A B = {e e A e B}. There is another important set construction called the cross product, A B = {(a, b) a A b B}, A B is the set of all ordered pairs where the first component of the pair is drawn from the set A and the second component of the pair is drawn from B. ( Exercise: Let A = {a, b} and B = {c, d}, construct the set A B.

Mathematical Preliminaries: Sets A construction using subsets is the powerset of some set X, P(X ), The powerset of set X is set of all subsets of X. For example, let X = {a, b}, then Note: X P(X ) = {, {a}, {b}, {a, b}}. Exercise: What would P(X X ) look like?

Mathematical Preliminaries: Sets The fact that X for any set X is interesting in its own right. Let s see if we can prove it. Proof: Proof by contradiction. Assume X is any set. Assume that is not a subset of X. Then the definition of subsets, A B e A.e B, implies that there exist at least one element in that is not also in X. But that is not possible because has no elements a contradiction. Therefore, our assumption the that is not a subset of X must be wrong and we can conclude that X.

Mathematical Preliminaries: Relations A (binary) relation is a set of ordered pairs. If R is a relation that relates the elements of set A to the elements B, then R A B. This means if a A is related to b B via the relation R, then (a, b) R. We often write a R b. Consider the relational operator applied to the set N N. This induces a relation, call it N N, with (a, b) (or a b in our relational notation) if a N is less or equal to b N.

Mathematical Preliminaries: Relations The first and second components of each pair in some relation R are drawn from different sets called the projections of R onto the first and second coordinate, respectively. We introduce the operators domain and range to accomplish these projections. Let R A B, then, dom(r) = A, and ran(r) = B. In this case we talk about a relation from A to B. The range is often called the co-domain. If R X X, then dom(r) = ran(r) = X. Here we talk about a relation in X.

Mathematical Preliminaries: Relations Let R X X such that (a, b) R iff a = b. That is, R is the equality relation in X. (What do the elements of the equality relation look like for N N?) A relation R X X is an equivalence relation if the following conditions hold, R is reflexive 4 x R x, R is symmetric x R y y R x, R is transitive x R y y R z x R z, where x, y, z X. The smallest equivalence relation in some set X is the equality relation defined above. The largest equivalence relation is some set is the cross product X X. (Consider the smallest/largest equiv. relation in I) 4 Recall that x R x (x, x) R

Mathematical Preliminaries: Functions A function f from X to Y is a relation f X Y such that x X, y, z Y. (x, y) f (x, z) f y = z. In other words, each x X has a unique value y Y with (x, y) f or functions are constrained relations. We let X Y denote the set of all functions from X to Y (i. e. X Y P(X Y ), why is the subset strict? Hint: it is not a relation), then the customary notation for specifying functions can be defined as follows, f : X Y iff f X Y.

Mathematical Preliminaries: Functions For function application it is customary to write f (x) = y for (x, y) f. In this case we say that the function is defined at point x. Otherwise we say that the function is undefined at point x and we write f (x) =. Note that f ( ) = and we say the f is strict. We say that f : X Y is a total function if f is defined for all x X. Otherwise we say that f is a partial function.

Mathematical Preliminaries: Functions We can now make the notion of a predicate formal a predicate is a function whose range (co-domain) is restricted to the boolean values: P : X B where P is a predicate that returns true or false for the objects in set X. Example: Let U be the set of all possible objects a universe if you like, and let, human : U B be the predicate that returns true if the object is a human and will return false otherwise, then human(socrates) = true human(car) = false

Mathematical Preliminaries: Exercises 1 In your own words explain what the function m : X Y Z does. 2 How would you describe the function c : X (Y Z)? 3 In your own words explain what the relation R (X Y ) (Z W ) does.