13
Domain Restriction on Relation Domain Restriction on Relation domain restriction domain restriction operator , , operator , , restricts a relation to only those members restricts a relation to only those members whose domain is in a specified set. whose domain is in a specified set. Let R: M x P be { (m1, p1), (m2, p2), (m3, Let R: M x P be { (m1, p1), (m2, p2), (m3, p1), (m3, p3), (m4, p3) } and S = p1), (m3, p3), (m4, p3) } and S = { m1,m3}, then : { m1,m3}, then : S R = { (m1, p1), (m3,p1), (m3, p3) } S R = { (m1, p1), (m3,p1), (m3, p3) } this can be an example of restricting to only those this can be an example of restricting to only those packages that contain module 1 and module 3. packages that contain module 1 and module 3. Note that S must be a subset of M in order for this to be sensible.

Domain Restriction on Relation domain restriction operator,, restricts a relation to only those members whose domain is in a specified set. domain restriction

Embed Size (px)

Citation preview

Domain Restriction on RelationDomain Restriction on Relation

domain restrictiondomain restriction operator , , restricts a relation to operator , , restricts a relation to only those members whose domain is in a specified set. only those members whose domain is in a specified set.

Let R: M x P be { (m1, p1), (m2, p2), (m3, p1), (m3, p3), Let R: M x P be { (m1, p1), (m2, p2), (m3, p1), (m3, p3), (m4, p3) } and S = { m1,m3}, then :(m4, p3) } and S = { m1,m3}, then :

– S R = { (m1, p1), (m3,p1), (m3, p3) }S R = { (m1, p1), (m3,p1), (m3, p3) }

– this can be an example of restricting to only those packages that contain this can be an example of restricting to only those packages that contain module 1 and module 3. module 1 and module 3.

Note that S must be a subset of M in order for this to be sensible.

Domain RestrictionDomain Restriction

Given a set S and a relation R, domain restriction operation Given a set S and a relation R, domain restriction operation may also be expressed as id(S) ; Rmay also be expressed as id(S) ; R

– S R = id(S) ; RS R = id(S) ; R

Consider the previous example of S and R in matrix form:Consider the previous example of S and R in matrix form:

1

10

1

0

0

0 0 0

0

00 0

0

000 0

0

0

1

0

1

0 1

0

10

0

1

0

0

0

0 00

1

0

10

id (S) : M x M R: M x P S R : M x P

=;

Note that id(S) is a bit of a stretch here; it is really - - id(DOM R)\id(DOM R - S) ??

- - - - - - this is still not quite right ?!

Range Restriction on RelationRange Restriction on Relation

range restrictionrange restriction operator , , restricts a relation to only operator , , restricts a relation to only those members whose range is in a specified set. those members whose range is in a specified set.

Let R: M x P be { (m1, p1), (m2, p3), (m3, p2), (m3, p3), Let R: M x P be { (m1, p1), (m2, p3), (m3, p2), (m3, p3), (m4, p3) } and S = { p1,p2}, then :(m4, p3) } and S = { p1,p2}, then :

– R S = { (m1, p1), (m3,p2) }R S = { (m1, p1), (m3,p2) }

– this can be an example of restricting to only those modules that are this can be an example of restricting to only those modules that are packaged in package 1 and package 2. packaged in package 1 and package 2.

This time, S needs to be a subset of P to make sense.

Range RestrictionRange Restriction

Given a set S and a relation R, range restriction operation may Given a set S and a relation R, range restriction operation may also be expressed as R ; id(S)also be expressed as R ; id(S)

– R S = R ; id(S)R S = R ; id(S)

Consider the previous example of S and R in matrix form:Consider the previous example of S and R in matrix form:

1

10

1

0

0

0 0

00

0

0

0

0

0

0

0

1

0

1

11

1

0

0

0

0 00

0

0

01

id (S) : P x PR: M x P R S : M x P

=;

Note that id(S) is a stretch; it is really - - - id(RAN R)\ id (RAN R- S)?

Additional Domain and Range restrictions Additional Domain and Range restrictions

Domain restriction may be modified to restrict Domain restriction may be modified to restrict the relation, R, to only those members whose the relation, R, to only those members whose domain is domain is NOTNOT in the specified set S. in the specified set S.– S RS R

Similarly, range restriction may be modified to Similarly, range restriction may be modified to restrict the relation, R, to only those members restrict the relation, R, to only those members whose range is whose range is NOTNOT in the specified set S. in the specified set S.

– R SR S

NOT restrictions on domain and rangeNOT restrictions on domain and range

Let R: A x B , S be a proper subset of A, and T Let R: A x B , S be a proper subset of A, and T be a proper subset of B. Thenbe a proper subset of B. Then

– S R = ( A \ S ) RS R = ( A \ S ) R

– R T = R (B \ T )R T = R (B \ T )

Override OperatorOverride Operator

The override operator over two relations R The override operator over two relations R and S, where both relations are defined and S, where both relations are defined over the same sets A x B, is defined as over the same sets A x B, is defined as follows:follows:

R S = (domS R) U SR S = (domS R) U S

Override Operator Example Override Operator Example

Let R = { (J, m1), (T,m3), (K, m4), (S,m5) } and S = { (T,m2), (K,m3), Let R = { (J, m1), (T,m3), (K, m4), (S,m5) } and S = { (T,m2), (K,m3), (Q,m3) } defined over the same sets A x B where A = {J,T,K,S,Q} and B = (Q,m3) } defined over the same sets A x B where A = {J,T,K,S,Q} and B = { m1,m2,m3,m4,m5}{ m1,m2,m3,m4,m5}

– then R S = { (J,m1), (T,m2), (K,m3), (Q,m3), (S,m5) }then R S = { (J,m1), (T,m2), (K,m3), (Q,m3), (S,m5) }

Note that the original relation R is “modified” with the members in S via:Note that the original relation R is “modified” with the members in S via:

– Looking at the domain of S = T, K, QLooking at the domain of S = T, K, Q– Consider only those members in R whose domain is NOT T,K, or QConsider only those members in R whose domain is NOT T,K, or Q– That leaves (J,m1) and (S,m5) in R.That leaves (J,m1) and (S,m5) in R.– Union of { (j,m1), (S,m5) } and S gives us the above result. Union of { (j,m1), (S,m5) } and S gives us the above result.

The override operator is very much like the The override operator is very much like the file file updateupdate capability that is capability that is often encountered in a software File System.often encountered in a software File System.

Relational IMAGERelational IMAGE operator operator

ImageImage operator applied to a relation, R, is the operator applied to a relation, R, is the same as asking for the range of Rsame as asking for the range of R..

If the Image operator is further restricted to a If the Image operator is further restricted to a set S to be applied to the domain of R, then we set S to be applied to the domain of R, then we have the have the Relational Image OperatorRelational Image Operator, R( S ), R( S )– Relational Image Operator applied to a relation R as Relational Image Operator applied to a relation R as

restricted by a set S returns the restricted by a set S returns the rangerange of those of those members of R whose domain is in the set S. members of R whose domain is in the set S.

– Let Let RR = {(a,2), (b,23), (c,11), (d,45)}, = {(a,2), (b,23), (c,11), (d,45)}, SS= {b,c}= {b,c}Then Then R (|S |)R (|S |) = { 23, 11 } = { 23, 11 }

Imagine the above R was a “table” of name and address. Then R( S ) wouldbe the equivalent to a “query” look-up for the addresses of people specified in S.

Transitive ClosureTransitive Closure

Recall that earlier we defined an n-fold relation to be RRecall that earlier we defined an n-fold relation to be Rn.n.

– Let R be a Homogeneous relation R: A x A , and A is some set.Let R be a Homogeneous relation R: A x A , and A is some set.– RR0 0 = id (A) = id (A)– RRnn = R ; R = R ; R n-1 n-1

Consider an example : A= {m1, m2, m3} and R is defined : AxA Consider an example : A= {m1, m2, m3} and R is defined : AxA as R = {(m1,m2), (m1,m3), (m3, m2)}, then:as R = {(m1,m2), (m1,m3), (m3, m2)}, then:– RR0 0 = {(m1,m1), (m2,m2), (m3,m3)}= {(m1,m1), (m2,m2), (m3,m3)}– RR11 = R; R = R; R00 = {(m1,m2), (m1,m3), (m3,m2)} = {(m1,m2), (m1,m3), (m3,m2)}– RR22 = R ; R = R ; R11 = { (m1,m2) } = { (m1,m2) }– RR33 = R ; R = R ; R22 = { } = { }

Transitive Closure may be defined as:Transitive Closure may be defined as:– Reflexive Transitive Closure of RReflexive Transitive Closure of R, R* = R, R* = R00 U R U R11 U R U R22 U - - - U R U - - - U Rnn

– Non-Reflexive Transitive Closure of RNon-Reflexive Transitive Closure of R, R, R++ = R = R1 1 U RU R22 U - - - U R U - - - U Rnn

– Non-Reflexive Transitive Closure of R = Reflexive Transitive Closure of Non-Reflexive Transitive Closure of R = Reflexive Transitive Closure of R \ RR \ R0 0 or or RR++ = R*\R = R*\R00

Check the definition on page 132 – is it correct?

Non-Reflexive Transitive Closure Non-Reflexive Transitive Closure

From the From the example on previous slideexample on previous slide, , – Non-Reflexive Transitive Closure = RNon-Reflexive Transitive Closure = R11 U R U R22

– Since RSince R22 is a subset of R is a subset of R11 in this case R in this case R11 becomes the becomes the non-reflexive transitive closure. non-reflexive transitive closure.

Depending on the interpretation one puts on the Depending on the interpretation one puts on the relation, different answers may be obtained. relation, different answers may be obtained. – If R, in this case, means module calling other If R, in this case, means module calling other

modules, then the “modules, then the “max levels of callsmax levels of calls” is the same as ” is the same as the largest n where Rthe largest n where Rnn is non-empty. is non-empty.

A Theorem Involving RelationA Theorem Involving Relation

Let: R1 be T1 x T2 and R2 be T2 x T3Let: R1 be T1 x T2 and R2 be T2 x T3

├ ├ (R1;R2)(R1;R2)-1-1 = R2 = R2-1-1 ; R1 ; R1-1-1

– (R1;R2)(R1;R2)-1 -1 means x (R1; R2)means x (R1; R2)-1-1 y y– x (R1; R2)x (R1; R2)-1-1 y implies that y (R1; R2) x y implies that y (R1; R2) x– y (R1; R2) x means there is a z in T2 such thaty (R1; R2) x means there is a z in T2 such that

y R1 z and z R2 xy R1 z and z R2 x– y R1 z implies z R1y R1 z implies z R1-1-1 y and y and– z R2 x implies x R2z R2 x implies x R2-1-1 z z– z R1z R1-1-1 y “and” x R2 y “and” x R2-1-1 z is the same as x R2 z is the same as x R2-1-1 z “and” z R1 z “and” z R1-1-1 y y

x R2x R2-1 -1 z and z R1z and z R1-1-1 y means y means R2R2-1-1; R1; R1-1-1

Theorems involving RelationsTheorems involving Relations

See page 134 of your text.See page 134 of your text.

You will You will not not be held accountable of these be held accountable of these theorems, theorems, but at least read thembut at least read them..

They will be given to you if ever needed.They will be given to you if ever needed.