CS:5810 Formal Methods in So7ware Engineering

Similar documents
Mathematics for Computer Science/Software Engineering. Notes for the course MSM1F3 Dr. R. A. Wilson

Automata Theory. Şubat 2006 Tuğrul Yılmaz Ankara Üniversitesi

Lecture 16 : Relations and Functions DRAFT

INTRODUCTORY SET THEORY

Chapter 8 Integers 8.1 Addition and Subtraction

Basic Concepts of Set Theory, Functions and Relations

Lecture 12: Entity Relationship Modelling

Entity Relationship Diagram

CS 4604: Introduc0on to Database Management Systems. B. Aditya Prakash Lecture #5: En-ty/Rela-onal Models- - - Part 1

Cardinality. The set of all finite strings over the alphabet of lowercase letters is countable. The set of real numbers R is an uncountable set.

Chapter 3. Cartesian Products and Relations. 3.1 Cartesian Products

Chapter 7. Permutation Groups

Lecture 1. Basic Concepts of Set Theory, Functions and Relations

Relational Databases

So let us begin our quest to find the holy grail of real analysis.

Automata and Formal Languages

Cartesian Products and Relations

Mathematics Review for MS Finance Students

Abstract Algebra Cheat Sheet

Database Design Overview. Conceptual Design ER Model. Entities and Entity Sets. Entity Set Representation. Keys

This asserts two sets are equal iff they have the same elements, that is, a set is determined by its elements.

a 11 x 1 + a 12 x a 1n x n = b 1 a 21 x 1 + a 22 x a 2n x n = b 2.

THE LANGUAGE OF SETS AND SET NOTATION

Data Analysis 1. SET08104 Database Systems. Napier University

Software Engineering

Discrete Maths. Philippa Gardner. These lecture notes are based on previous notes by Iain Phillips.

Geometric Transformations

Pigeonhole Principle Solutions

ER modelling, Weak Entities, Class Hierarchies, Aggregation

Chapter 4 Lecture Notes

Math 223 Abstract Algebra Lecture Notes

SMALL SKEW FIELDS CÉDRIC MILLIET

Software Model Checking: Theory and Practice

1 if 1 x 0 1 if 0 x 1

Boolean Algebra Part 1

THE PRODUCT SPAN OF A FINITE SUBSET OF A COMPLETELY BOUNDED ARTEX SPACE OVER A BI-MONOID

Foundations of mathematics. 2. Set theory (continued)

Formal Languages and Automata Theory - Regular Expressions and Finite Automata -

Combinatorial Proofs

Chapter 2: Entity-Relationship Model. Entity Sets. " Example: specific person, company, event, plant

Follow links for Class Use and other Permissions. For more information send to:

Basic Concepts of Point Set Topology Notes for OU course Math 4853 Spring 2011

CS 3719 (Theory of Computation and Algorithms) Lecture 4

BANACH AND HILBERT SPACE REVIEW

1. Prove that the empty set is a subset of every set.

Graph Theory Problems and Solutions

Outline. Data Modeling. Conceptual Design. ER Model Basics: Entities. ER Model Basics: Relationships. Ternary Relationships. Yanlei Diao UMass Amherst

You know from calculus that functions play a fundamental role in mathematics.

Lecture 1 Introduction Properties of Probability Methods of Enumeration Asrat Temesgen Stockholm University

6.2 Permutations continued

Homework 3 (due Tuesday, October 13)

MA651 Topology. Lecture 6. Separation Axioms.

2. Conceptual Modeling using the Entity-Relationship Model

Lecture Note 1 Set and Probability Theory. MIT Spring 2006 Herman Bennett

CMPSCI 250: Introduction to Computation. Lecture #19: Regular Expressions and Their Languages David Mix Barrington 11 April 2013

Lecture 17 : Equivalence and Order Relations DRAFT

3. Relational Model and Relational Algebra

Math Review. for the Quantitative Reasoning Measure of the GRE revised General Test

Continued Fractions and the Euclidean Algorithm

COMP 378 Database Systems Notes for Chapter 7 of Database System Concepts Database Design and the Entity-Relationship Model

Monitoring Metric First-order Temporal Properties

Set Theory Basic Concepts and Definitions

So#ware quality assurance - introduc4on. Dr Ana Magazinius

Name: Section Registered In:

SOL 3.21, 3.22 Date:

XV. The Entity-Relationship Model

The Entity-Relationship Model

Georg Cantor ( ):

C H A P T E R Regular Expressions regular expression

A Note on Context Logic

Binary Adders: Half Adders and Full Adders

Unit 2.1. Data Analysis 1 - V Data Analysis 1. Dr Gordon Russell, Napier University

Lights and Darks of the Star-Free Star

S on n elements. A good way to think about permutations is the following. Consider the A = 1,2,3, 4 whose elements we permute with the P =

2. The Language of First-order Logic

The University of British Columbia

1 The Concept of a Mapping

Matrix Algebra. Some Basic Matrix Laws. Before reading the text or the following notes glance at the following list of basic matrix algebra laws.

MASSACHUSETTS INSTITUTE OF TECHNOLOGY 6.436J/15.085J Fall 2008 Lecture 5 9/17/2008 RANDOM VARIABLES

Georg Cantor and Set Theory

On the generation of elliptic curves with 16 rational torsion points by Pythagorean triples

Mathematical Methods of Engineering Analysis

Discrete Mathematics

SOLUTIONS TO ASSIGNMENT 1 MATH 576

Matrix Representations of Linear Transformations and Changes of Coordinates

Database Design and Normal Forms

Algorithmic Mathematics

Online EFFECTIVE AS OF JANUARY 2013

Semantics of UML class diagrams

Lecture Notes on Database Normalization

Database Management Systems

Solutions to TOPICS IN ALGEBRA I.N. HERSTEIN. Part II: Group Theory

SQL Database queries and their equivalence to predicate calculus

How To Understand The Theory Of Computer Science

Entity-Relationship Model

o-minimality and Uniformity in n 1 Graphs

Introduction to Theory of Computation

7 Relations and Functions

DEGREES OF ORDERS ON TORSION-FREE ABELIAN GROUPS

Transcription:

CS:5810 Formal Methods in So7ware Engineering Sets and Rela<ons Copyright 2001-15, Matt Dwyer, John Hatcliff, Rod Howell, Laurence Pilard, and Cesare Tinelli. Created by Cesare Tinelli and Laurence Pilard at the University of Iowa from notes originally developed by Matt Dwyer, John Hatcliff, Rod Howell at Kansas State University. These notes are copyrighted materials and may not be used in other course settings outside of the University of Iowa in their current form or modified form without the express written permission of one of the copyright holders. During this course, students are prohibited from selling notes to or being paid for taking notes by any person or commercial firm without the express written permission of one of the copyright holders. 1

These Notes review the concepts of sets and rela<ons required for working with the Alloy language focus on the kind of set opera<on and defini<ons used in specifica<ons give some small examples of how we will use sets in specifica<ons CS:5810 -- Formal Methods in Software Engineering Fall 15 2

Set Collec<on of dis<nct objects Each set s objects are drawn from a larger domain of objects all of which have the same type - - - sets are homogeneous Examples: {2,4,5,6, } {red, yellow, blue} {true, false} {red, true, 2} set of integers set of colors set of boolean values for us, not a set! domain CS:5810 -- Formal Methods in Software Engineering Fall 15 3

Value of a Set Is the collec<on of its members Two sets A and B are equal iff every member of A is a member of B every member of B is a member of A x є S denotes x is a member of S Ø denotes the empty set CS:5810 -- Formal Methods in Software Engineering Fall 15 4

Defining Sets We can define a set by enumera*on PrimaryColors == {red, yellow, blue} Boolean == {true, false} Evens == {, - 4, - 2, 0, 2, 4, } This works fine for finite sets, but what do we mean by? remember, we want to be precise CS:5810 -- Formal Methods in Software Engineering Fall 15 5

Defining Sets We can define a set by comprehension, that is, by describing a property that its elements must share Nota<on: { x : D P(x) } Form a new set of elements drawn from domain D by including exactly the elements that sa<sfy predicate (i.e., Boolean func<on) P Examples: { x : Ν x < 10} { x : Ζ ( y : Ζ x = 2y) } { x : Ν x > x} Naturals less than 10 Even integers Empty set of natural numbers CS:5810 -- Formal Methods in Software Engineering Fall 15 6

Cardinality The cardinality (#) of a finite set is the number of its elements Examples: # {red, yellow, blue} = 3 # {1, 23} = 2 # Ζ =? Cardinali<es are defined for infinite sets too, but we ll be most concerned with the cardinality of finite sets CS:5810 -- Formal Methods in Software Engineering Fall 15 7

Set Opera<ons Union (X, Y sets over domain D): X Y {e: D e X or e Y} {red} {blue} = {red, blue} Intersec<on X Y {e: D e X and e Y} {red, blue} {blue, yellow} = {blue} Difference X \ Y {e: D e X and e Y} {red, yellow, blue} \ {blue, yellow} = {red} CS:5810 -- Formal Methods in Software Engineering Fall 15 8

Subsets A subset holds elements drawn from another set X Y iff every element of X is in Y {1, 7, 17, 24} Ζ A proper subset is a non- equal subset Another view of set equality A = B iff (A B and B A) CS:5810 -- Formal Methods in Software Engineering Fall 15 9

Power Sets The power set of set S (denoted Pow (S)) is the set of all subsets of S, i.e., Pow (S) {e e S} Example: Pow ({a,b,c}) = {Ø, {a}, {b}, {c}, {a,b}, {a,c}, {b,c}, {a,b,c}} Note: for any S, Ø S and thus Ø Pow (S) CS:5810 -- Formal Methods in Software Engineering Fall 15 10

Exercises These slides include ques<ons that you should be able to solve at this point They may require you to think some You should spend some effort in solving them and may in fact appear on exams CS:5810 -- Formal Methods in Software Engineering Fall 15 11

Exercises Specifying using comprehension nota<on Odd posi<ve integers The squares of integers, i.e. {1,4,9,16, } Express the following logic proper<es on sets without using the # operator Set has at least one element Set has no elements Set has exactly one element Set has at least two elements Set has exactly two elements CS:5810 -- Formal Methods in Software Engineering Fall 15 12

Set Par<<oning Sets are disjoint if they share no elements O7en when modeling, we will take some set S and divide its members into disjoint subsets called blocks or parts We call this division a par**on Each member of S belongs to exactly one block of the par<<on Soup Chips & Salsa Steak Pizza Sweet & Sour Pork Cake Apple pie Ice Cream CS:5810 -- Formal Methods in Software Engineering Fall 15 13

Example Model residential scenarios Basic domains: Person, Residence Par<<ons: Par<<on Person into Child, Student, Adult Par<<on Residence into Home, DormRoom, Apartment CS:5810 -- Formal Methods in Software Engineering Fall 15 14

Exercises Express the following proper<es of pairs of sets Two sets are disjoint Two sets form a par<<oning of a third set CS:5810 -- Formal Methods in Software Engineering Fall 15 15

Expressing Rela<onships It s useful to be able to refer to structured values a group of values that are bound together e.g., struct, record, object fields Alloy is a calculus of rela*ons All of our Alloy models will be built using rela<ons (sets of tuples) but first some basic defini<ons CS:5810 -- Formal Methods in Software Engineering Fall 15 16

Product Given two sets A and B, the product of A and B, usually denoted A x B, is the set of all possible pairs (a, b) where a A and b B A x B {(a, b) a A, b B} Example: PrimaryColor x Boolean: { (red,true), (red, false), } (blue,true), (blue, false), (yellow, true), (yellow, false) CS:5810 -- Formal Methods in Software Engineering Fall 15 17

Rela<on A binary rela<on R between A and B is an element of Pow (A x B), i.e., R A x B Examples: Parent : Person x Person Parent == {(John, Autumn), (John, Sam)} Square : Z x N Square == {(1,1), (- 1,1), (- 2,4)} ClassGrades : Person x {A, B, C, D, F} ClassGrades == {(Todd,A), (Jane,B)} CS:5810 -- Formal Methods in Software Engineering Fall 15 18

Rela<on A ternary rela<on R between A, B and C is an element of Pow (A x B x C) Example: FavoriteBeer : Person x Beer x Price FavoriteBeer == {(John, Miller, $2), (Ted, Heineken, $4), (Steve, Miller, $2)} N- ary rela<ons with n>3 are defined analogously (n is the arity of the rela<on) CS:5810 -- Formal Methods in Software Engineering Fall 15 19

Binary Rela<ons The set of first elements is the defini*on domain of the rela<on domain (Parent) = {John} NOT Person! The set of second elements is the image of the rela<on image (Square) = {1,4} NOT Ν! How about {(1,blue), (2,blue), (1,red)} domain? image? CS:5810 -- Formal Methods in Software Engineering Fall 15 20

Common Rela<on Structures One-to-Many Many (two) Many-to-One One Many One One-to-One Many-to-Many Many Many One One CS:5810 -- Formal Methods in Software Engineering Fall 15 21

Func<ons A func*on is a rela<on F of arity n+1 containing no two dis<nct tuples with the same first n elements, i.e., for n = 1, (a 1, b 1 ) F, (a 2, b 2 ) F, (a 1 = a 2 b 1 = b 2 ) Examples: {(2, red), (3, blue), (5, red)} {(4, 2), (6,3), (8, 4)} Instead of F: A1 x A2 x x An x B we write F: A1 x A2 x An - > B CS:5810 -- Formal Methods in Software Engineering Fall 15 22

Exercises Which of the following are func<ons? Parent == {(John, Autumn), (John, Sam)} Square == {(1, 1), (- 1, 1), (- 2, 4)} ClassGrades == {(Todd, A), (Virg, B)} CS:5810 -- Formal Methods in Software Engineering Fall 15 23

Rela<ons vs. Func<ons John Lorie Parent Autumn Sam Many-to-many -2-1 Todd Virg 1 Square 4 ClassGrades 1 A B Many-to-one One-to-one In other words, a function is a relation that is X-to-one. CS:5810 -- Formal Methods in Software Engineering Fall 15 24

Special Kinds of Func<ons Consider a func<on f from S to T f is total if defined for all values of S f is par*al if undefined for some values of S Examples Squares : Ζ - > Ν, Squares = {, (- 1,1), (0,0), (1, 1), (2,4), } Abs = {(x, y) : Ζ x Ν (x < 0 and y = - x) or (x 0 and y = x)} CS:5810 -- Formal Methods in Software Engineering Fall 15 25

Func<on Structures Total Function Partial Function Undefined for this input Note: the empty relation is a partial function CS:5810 -- Formal Methods in Software Engineering Fall 15 26

Special Kinds of Func<ons A func<on f: S - > T is injec*ve (one- to- one) if no image element is associated with mul<ple domain elements surjec*ve (onto) if its image is T bijec*ve if it is both injec<ve and surjec<ve We ll see that these come up frequently can be used to define proper<es concisely CS:5810 -- Formal Methods in Software Engineering Fall 15 27

Func<on Structures Injective Function Surjective Function CS:5810 -- Formal Methods in Software Engineering Fall 15 28

Exercises What kind of func<on/rela<on is Abs? Abs = {(x, y) : Ζ x Ν (x < 0 and y = - x) or (x 0 and y = x)} How about Squares? Squares : Ζ x Ν, Squares = {(x, y) : Ζ x Ν y = x*x} CS:5810 -- Formal Methods in Software Engineering Fall 15 29

Special Cases Relations Partial Functions Surjective Bijective Total Injective CS:5810 -- Formal Methods in Software Engineering Fall 15 30

Func<ons as Sets Func<ons are rela<ons and hence sets We can apply all of the usual operators ClassGrades == {(Todd, A), (Jane, B)} #(ClassGrades {(Ma{, C)}) = 3 CS:5810 -- Formal Methods in Software Engineering Fall 15 31

Exercises In the following if an operator fails to preserve a property give an example What operators preserve func<on- ness??? \? What operators preserve surjec<vity? What operators preserve injec<vity? CS:5810 -- Formal Methods in Software Engineering Fall 15 32

Rela<on Composi<on Use two rela<ons to produce a new one map domain of first to image of second Given s: A x B and r: B x C then s;r : A x C s;r {(a,c) (a,b) s and (b,c) r} For example s == {(red,1), (blue,2)} r == {(1,2), (2,4), (3,6)} s;r = {(red,2), (blue,4)} CS:5810 -- Formal Methods in Software Engineering Fall 15 33

Rela<on Closure Intui<vely, the closure of a rela<on r: S x S, wri{en r +, is what you get when you keep naviga<ng through r un<l you can t go any farther. r + r (r;r) (r;r;r) For example GrandParent == Parent;Parent Ancestor == Parent + CS:5810 -- Formal Methods in Software Engineering Fall 15 34

Rela<on Transpose Intui<vely, the transpose of a rela<on r: S x T, wri{en ~r, is what you get when you reverse all the pairs in r. ~r {(b,a) (a,b) r} For example ChildOf == ~Parent DescendantOf == (~Parent) + CS:5810 -- Formal Methods in Software Engineering Fall 15 35

Exercises In the following if an operator fails to preserve a property give an example What proper<es, i.e., func<on- ness, onto- ness, 1-1- ness, by the rela<on operators? composi<on (;) closure ( + ) transpose (~) CS:5810 -- Formal Methods in Software Engineering Fall 15 36

Acknowledgements Some of these slides are adapted from David Garlan s slides from Lecture 3 of his course of Software Models entitled Sets, Relations, and Functions (http://www.cs.cmu.edu/afs/cs/academic/class/15671-f97/www/ ) CS:5810 -- Formal Methods in Software Engineering Fall 15 37