Download presentation
Presentation is loading. Please wait.
Published byEileen Patrick Modified over 9 years ago
1
12 April 2009Instructor: Tasneem Darwish1 University of Palestine Faculty of Applied Engineering and Urban Planning Software Engineering Department Formal Methods Functions
2
12 April 2009Instructor: Tasneem Darwish2 Outlines Partial functions Lambda notation Functions on relations
3
12 April 2009Instructor: Tasneem Darwish3 Partial Functions A partial function from X to Y is a relation that maps element of X to at most one element of Y ; we write to denote the set of all such relations Example 8.1 An organisation 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 the set of all people is Person, and the set of all locations is Location, then the information provided by the system may be described by a relation where_is of type Person↔Location. It is impossible for an employee to be in two places at once, so this relation will be a partial function:
4
12 April 2009Instructor: Tasneem Darwish4 Partial Functions These relations are called partial functions because there may be elements of X that are not related to any element of Y. If each element of X is related to some element of Y, then the function is said to be total; we write X →Y to denote the set of all total functions from X to Y Example 8.2 We may define a relation double on the set of natural numbers N as follows: This relation is a total function: for every natural number m there is a unique number n such that
5
12 April 2009Instructor: Tasneem Darwish5 Partial Functions If a lies within the domain of a function f, we write f (a) to denote the unique object that is related to x We say that f (a) is the result of applying function f to argument a There are two inference rules associated with function application:
6
12 April 2009Instructor: Tasneem Darwish6 Partial Functions Example 8.3 If Rachel is an employee, then we may write where_is rachel to denote her current location. Where_is = =
7
12 April 2009Instructor: Tasneem Darwish7 Lambda notation 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 The lambda notation offers a more concise alternative; Example 8.4 The function double could also be defined by
8
12 April 2009Instructor: Tasneem Darwish8 Lambda notation Example 8.5 The function min maps a set of natural numbers to the least number present in that set: the minimum value If the declaration part of a lambda expression introduces more than one variable, then the source type of the function is given by the resulting characteristic tuple The source is the Cartesian product set
9
12 April 2009Instructor: Tasneem Darwish9 Lambda notation Example 8.6 The function pair takes two functions f and g as arguments, each of which must be a homogeneous relation on N. The result is a function that takes a natural number n and returns the pair formed by applying each of f and g to n: Example 8.7 Let triple be the function
10
12 April 2009Instructor: Tasneem Darwish10 Functions on Relations Example 8.8 The domain and range operators may be defined by
11
12 April 2009Instructor: Tasneem Darwish11 Functions on Relations Example 8.9 The restriction operators may be defined by
12
12 April 2009Instructor: Tasneem Darwish12 Functions on Relations Example 8.10 The relational composition operator may be defined by
13
12 April 2009Instructor: Tasneem Darwish13 Functions on Relations Example 8.11 The relational inverse operator may be defined by
14
12 April 2009Instructor: Tasneem Darwish14 Functions on Relations Example 8.12 The transitive closure operator may be defined by
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.