<<

 Machines can be required to maintain information about relationships on the information contained within them.  between sets  If S and T are two sets, then their Cartesian product SxT is the of all pairs (s, t) of elements from S and T respectively. This is defined as follows:

 s↦t pronounced s maps to t  It exactly means the same as (s,t).  it is a pair whose first element is s and whose second element is t.  A relation R between sets S and T expresses a relationship between elements in S and elements in T.  It is captured as a set of pairs (s, t) with s∈ S and t ∈ T representing those elements which are related.  PHOTOGRAPHER={anna, bob, chris, dave, elizabeth, francis}  and  CAMERA={canon, kodak ,hasselblad ,minolta, olympus ,pentax}  The relation owns detailing the ownership relation between photographers and their cameras can be defined as follows  Owns={(anna, canon), (bob, canon), (bob, kodak), (chris, hasselblad), (chris, kodak), (chris, pentax), (dave, pentax), (elizabeth, pentax),(elizabeth, minolta)}  Or using the notation  Owns={(anna ↦ canon), (bob ↦ canon), (bob ↦ kodak), (chris ↦ hasselblad), (chris ↦ kodak), (chris ↦ pentax), (dave ↦ pentax), (elizabeth ↦ pentax),(elizabeth ↦ minolta)}

 A relation between S and T is a of SxT or an element of P(SxT).  The notation S⟷T denotes the set of relations between S and T.  Hence S↦T is an abbreviation for the set of all substes of SxT  S⟷T=P(SxT)  To specify that R is a relation between S and T we write R∈S⟷T.  In this case set S is said to be the source of R and the set T is said to be the target.  For example owns ∈ PHOTOGRAPHER⟷CAMERA  The statement that (dave, pentax) ∈ owns states that dave is related to pentax in the relation owns.  dave↦pentax also states that dave is related to pentax.  If owns records the cameras that are owned by the photographers, then this corresponds to the information that dave owns a pentax camera.  When producing specifications, we are generally interested in extracting information from the relations our machines maintain,  To answer particular questions such as:

 Does Bob own a camera?  How many cameras does Elizabeth own?  Who owns a Hasselblad camera?  Which cameras are used by both Chris and Dave?  How many cameras does Anna own?  Is there anyone that does not have a camera?  There are constructs for extracting the information required for questions to be expressed in relations.  Extracting the domain and range of a relation  Domain restriction: restricting the relation to a particular domain of interest  Range restriction: restricting the relation to a particular range of interest  Identifying the elements related to some item in a given set.  Relational inverse the relation the opposite way round  The domain of a relation R∈ S ↔T is the set of elements of S that R relates to something in T.  Items in the source set that are related to something, it is written dom(R)

 Dom(owns)= {anna,bob, chris, dave, elizabeth}

 The range is the set of elements of T that are related to some element of S. it is written ran(R)

 For example  Ran(owns)={canon, kodak, hasselblad, minolta, pentax}

 A relation R∈ S↔ T can be projected onto a particular domain U⊆S.  Only the relationship for items in U is of interest.  The result is those pairs in R whose first element is in U.  It is written U⊲ R.  This is domain restriction.  U⊲ R={S ↦ t | s ↦ t ∈ R ∧ S ∈ U}  For example  To consider only the cameras that chris owns, the relation owns can be restricted to the set {chris}.

 A complementary restriction removes all pairs whose first element is in U.  This is written U ⩤ R  Domain anti restriction  U ⩤ R= { S↦ t | t ∈R ∧ s ∉ U}

 The target set can also be restricted.  The range restriction R⊳ V gives all pairs in R whose second element is in V⊆ T.

 For example, to consider only those photographers who have a kodak camera the relation owns can be range restricted to {kodak}

 Range anti restriction R⩥V gives all pairs apart from those whose second element is in V

 To identify all the elements in the target T that are related to some elements U of the source.  If 푈 ⊆ 푆, then the set of elements in T related to U is called the relational image of U.  It is written as R[U].  It is same as R[U]=ran(U⊲ R)  R[U]={t | s↦t∈ 푅 ∧ 푠 ∈ 푈}  The relational image of {chris, elizabeth} through owns;  This is written owns{chris, elizabeth}

 R-1 it is the type T⟷S  R-1={t↦s | s↦t ∈ 푅}  The inverse of the owns relation could be called by ownedby

 It is concerned with the conjunction of relations.  If s is related to t, and t is related to u, then it is often useful to put these two relations together and observe that s is related to u.  If s↦t ∈ 푅0 푎푛푑 푡 ↦ 푢 ∈ 푅1 , 푡ℎ푒푛 푠 ↦u ∈ R0;R1  A relation might have a same set S and T  Identity relation  Written as id(S) and is of type S⟷ S  A pair (s,t) will be in the identity relation if and only if s=t. thus  Id(S)={(s,t)| s∈ 푆 ∧ 푡 ∈ 푆 ∧ 푠 = 푡}

 The identity relation is reflexive.  Furthermore, it is the smallest reflexive relation on S:  a relation is reflexive if and only if id(S)⊆R  A relation R∈ 푆 ⟷ 푆 is symmetric, if it relates s1 to s0 and s0 to s1.  The order of two elements does not matter.  Example  Relation id(S) is symmetric  Relation R is symmetric if R=R-1  A relation R∈ 푆 ⟷ 푆 is anti-symmetric, if it relates two distinct elements in at most one way.  For s0≠ 푠1. 𝑖푓 푠0 ↦ 푠1 ∈ 푅, 푡ℎ푒푛푠1 ↦ 푠0 ∉ 푅  It happens when R⋂R-1-id(S)={}

 If a relation relates two elements at most one way.  This is equivalent to the property R⋂R-1={}.  It follows that R cannot intersect at all with id(S): that  R⋂id(S)={}

 Whenever s0↦s1 ∈ 푅 and s1 ↦s2 ∈ 푅 then s0 ↦s2 ∈ 푅  reflexive: For every element a in A, (a,a) is in R.  symmetric: If an (a,b) in R, (b,a) is in R.  transitive: If ordered pairs (a,b) and (b,c) in R, (a,c) is in R.  My name is …………………..

 I remember ………………………  If a relation R: S⟷ S is reflexive, symmetric, and transitive, then it is called as equivalence relation.  It means set S can be considered as the union of a collection of pairwise disjoint equivalence classes.  Example  If X is the set of all cars, and the equivalence relation is“ has the same color as", then one particular equivalence class consists of all green cars.  For example, if A = {1, 2, 3}, we can define a relation R = {(1,2), (2,3), (3,1), (3,2)}.  R = {(1,2), (2,3), (3,1), (3,2)}.  For R to be reflexive it must contain (1,1), (2,2), and (3,3).  Since R doesn't even contain (1,1), it is not reflexive. Here is an equivalence relation R2 on A:  R2 = {(1,1), (1,3), (2,2), (3,1), (3,3)}.  If a relation R: S⟷ S on elements of a set S can be composed with itself.  The relation R;R is well defined.  For example  If parent∈ 푃퐸푅푆푂푁 ⟷ 푃퐸푅푆푂푁 then grandeparent= parent;parent  grandgrandparent-=parent3

 Using mathematical induction

 A transitive relation with itself can be written as  If s0↦s1∈ 푅 and s1↦s2∈ R and s0 ↦ 푠2 ∈R.  This is equivalent to the property  R;R⊆R.  For example the subset relation is transitive

 A reflexive relation R relates two elements of S, when there is some iterate of R including R0 which relates them. This is written as R* and it is defined as follows

 If R is symmetric then R* is an equivalence relation

 It excludes the 0th iteration of R and relates two elements of S, when there is iterate of R which relates them.

 Example  succeeds∈ 푃퐸푅푆푂푁 ⟷ 푃퐸푅푆푂푁  The relation follows =succeeds+ holds between a person and any person anywhere behind him in the queue.  in this example, a person is considered not to follow himself

 A relation R0 ∈ 푆 ⟷ 푇 푎푛푑 A relation 1R ∈ 푆 ⟷ 푇  Then the relational override R0 R1

 Example  Chris disposes off his camera collection and then buys an Olympus, the resulting relationship between photographers and their cameras will be given by

 This relation will be given by

 Functions are a particular kind of relations.  For a relation to be a , it must have one further property that it relates elements of S to no more than one element of T.  If s is related to some element by the function f, then f(s) denotes the value of the function on s.(unique element that is related to s)  It is defined only for those elements which are related to some value in T.

 Function from S to T is a relation which relates each element in S to at most one element in T.  Some elements of S might not be related to anything, if they are related to some element then that element is unique.  It generalizes the concept of a function ƒ: X → Y by not forcing f to map every element of X to an element of Y (only some subset X' of X  The set of partial function is defined by S ⇸ T. it is defined as follows

 It states that if any s is related to two elements t1 and t2 of T, then t1 and t2 must be the same.  It is a relation between S and T with the additional property that every element in S maps to no more than one element of T.  For example the relation favourite_colour between PERSON and COLOUR is a partial function. Some people do not have a favorite colour.

 Function from S to T is a relation which relates each element in S to exactly one element in T.  A function is a total function if it is a partial function whose domain is the whole of S.

 A particular relation f is a total function is written as f€ S⟶T.  Example  Favourite_colour € PERSON ⟶ COLOUR claims that every person has a favorite color.

 Total function age ԑ PERSON ⟶ ℕ.

 This corresponds to the fact that everybody has exactly one age associated with them.

 A function is injective if it never maps two different elements to the same thing.  Each element of the target type can be related to at most one element of the source.  Injective functions can be partial or total.  The set of partial is written as S ⤔T.

 This condition is the reverse partial function  It corresponds to f-1.

 A total injective function is a simply a partial injective function which is also a total function and it is written as S↣T

 Or

 Example  Consider a system which manages access to a computer. the function username ԑ PERSON ⤔ Id associates people with the user identities that they have been given.  Injectiveness requires that no ID corresponds to two members of PERSON .  The username is a partial injection allows that not all people appearing in PERSON need to have a user ID.

 A function from S to T is surjective if every element of T is reached from some element of S  The range of f is the whole of T.  The set of partial surjective functions is written as S↠T  And the set of total is written as S↠T

 Example  Birthday ԑ PERSON↠ DATE states that every date is the birthday of at least one person.  Birthday is a total function that states every body has a birthday date.  A function records the school attended by pupils might be declared as attends ԑ PERSON ↠ SCHOOL.  States that every school is attended by at least one pupil.  The function is a partial that some people are not registered at any school

 A function which is total, injective and surjective is called bijective function.  Every element in S is mapped to exactly one element in T. the notation for the set bijective functions from S to T is S ⤖ T

 If A={2, ,4, 8} and B={0, 3, 5} then state the type of function  f1={(2 ,0), (4, 3), (2, 5)}  f2={(4,0),(2,3), (8,0)}  f3={(8,3), (4,5), (2,0)}  Lambda notation can be used specifically for defining functions.  F(x)  Square(x)= 푥2  The general form of a function is

 For any predicate P, and any list of variables z, provided that P defines a type for each of the variables in the list z.  Functions can be combined with the usual set operators such as union, since they are also set of pairs.  The function

 Can be defined as