Docsity

Functions-Formal Specification Methods in Software Development-Lecture Slides, Slides of Software Development Methodologies

Partial preview of the text

Download Functions-Formal Specification Methods in Software Development-Lecture Slides and more Slides Software Development Methodologies in PDF only on Docsity!

Chapter No. 8

Functions

Introduction

  • If each object of one set is related to at most one object of another, then relation between two sets is said to be a function:
  • In this chapter, we introduce a notation for functions and their application
  • We show how this notation can be used to produce concise definitions for many of the basic operators in our language.
  • We examine properties, considering cases in which domain of a function is finite

Partial Functions

Example 8.1 An organization has a system for keeping track of its employees while they are on the premises. Each employee is issued with an active badge which reports their current position to a central database.

  • If set of all people is Person , and set of all locations is Location , then information may be described by a relation where_is of type Person  Locations
  • This relation is a partial function, i.e., where_is  Person  Location

Total Functions

Definition: if each element of X is related to unique element of Y then partial function is a total function denoted by X  Y.

X  Y == { f : XY | dom f = X • f }

b c

d

1

2 3

X f Y

Example : Total Functions

Example 8.3 If Rachel is an employee,

then we may write where_is rachel to

denote her current location. This makes

sense only if the database has a unique

record of Rachel’s whereabouts. If

where_is is the function

{otto  lobby, peter  meeting,

quentin  meeting, rachel  meeting}

Then we may observe that

where_is rachel = meeting

Lambda Functions

  • Suppose that f is a function whose domain is precisely those elements of X that satisfy a constraint p. If the result of applying f to an arbitrary element x can be written as the expression e, then f can be described as

f = {x :X | p  x  e}

  • Lambda notation offers more conciseness ( declaration | constraint  result)
  • Using lambda notation, our function f is f = ( x: X | p  e)

Functions on Relations

We introduced the operators that form the basis of a calculus of relations, i.e., domain, range, inverse, composition, and closure, are examples of functions upon relations

[X, Y] dom : (X  Y) X ran : (X  Y)  Y

 R : (X  Y)  dom R = { x : X | ( y : Y  x  y  R)  x} ran R = {y : Y | ( x : X  x  y  R)  y}

Formalism of Restriction Operators

  • If a function takes more than one argument, then it may be defined as an infix symbol,
  • We use underscores to indicate its position

[X, Y]

_  _ :  X  (X  Y)  (X  Y)

_  _ : (X  Y)   Y  (X  Y)

 R : (X  Y); A :  X; B :  Y 

A  R = { x : X; y : Y | x  A  x  y  R  x  y} R  B = { x : X; y : Y | y  B  x  y  R  xdocsity.com 

Relational Composition Operator

The relational composition operator may be defined as

[X, Y]

_  _ : (X  Y)  (Y  Z)  (X  Z)

 R : (X  Y);  S : (Y  Z)  R  S = { x : X; y : Y, z : Z | x  y  R  y  z  S  x  z}

Relational Inverse Operator

The relational inverse operator may be defined as

[X, Y]

~ : (X  Y)  (Y  X)

 R : (X  Y 

R~^ = { x : X; y : Y | x  y  R  y  x}

Overriding

  • To combine the information contained in functions f and g, we could simply write f  g.
  • However, there may be objects that are mapped to one value under f, and to another under g
  • If this is the case, then f  g is not a function.
  • To ensure that the combination of two functions is also functional, we must resolve any conflicts that arise docsity.com

Overriding

  • If f and g are functions of same type, then f  g denotes relational overriding of f with g.
  • This relation agrees with f everywhere outside the domain of g, but agrees otherwise with g

[X, Y] _  _ : (X  Y)  (X  Y)

 f, g : X  Y  f  g = (dom g  f)  g

Example: Injectivity

Example 8.15 The location function, where_is, is not injective

where_is = {otto  lobby, peter  meeting, quentin  meeting, rachel  meeting}

According to where_is, there are at least two different people in the meeting room, i.e.,

where_is quentin = meeting

where_is peter = meeting

where, quentin, peter

Example: Partial Injection

Example 8.18 : If s and t are the two sets {1, 2} and {a, b, c} respectively, then the set of all partial injective functions from s to t is given by

X  Y = {,? }