23.04.2013 Views

Composición de relaciones

Composición de relaciones

Composición de relaciones

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

RELACIONES<br />

1. Introducción<br />

2. Relaciones Binarias<br />

3. Dominio y Rango<br />

4. Propieda<strong>de</strong>s <strong>de</strong> <strong>relaciones</strong> homogéneas<br />

5. Inversa <strong>de</strong> una relación<br />

6. <strong>Composición</strong> <strong>de</strong> <strong>relaciones</strong><br />

7. Cierres<br />

Introducción<br />

• En una especificación formal se necesita po<strong>de</strong>r<br />

establecer <strong>relaciones</strong> entre objetos.<br />

• En este tema se verá:<br />

– Cómo <strong>de</strong>finir <strong>relaciones</strong><br />

– Cómo obtener información <strong>de</strong> estas <strong>relaciones</strong><br />

– Cómo se pue<strong>de</strong>n clasificar y qué propieda<strong>de</strong>s tienen las<br />

<strong>relaciones</strong><br />

– Qué operaciones se pue<strong>de</strong>n realizar sobre <strong>relaciones</strong>


Relaciones Binarias<br />

• El caso más simple <strong>de</strong> relación es el que se establece entre<br />

pares <strong>de</strong> objetos.<br />

• Definición: una relación es un conjunto <strong>de</strong> pares or<strong>de</strong>nados,<br />

esto es, un subconjunto <strong>de</strong>l producto cartesiano.<br />

• Sintaxis: X ↔ Y. Siendo X e Y dos conjuntos cualesquiera.<br />

• Se tiene que X ↔ Y = = P(X xY)<br />

• Para indicar uno <strong>de</strong> los elementos <strong>de</strong> la relación podremos<br />

escribir (x,y) o bien x ├→y<br />

Dominio y Rango<br />

• Se <strong>de</strong>finen una serie <strong>de</strong> funciones para po<strong>de</strong>r obtener la<br />

información que necesitamos <strong>de</strong> las <strong>relaciones</strong><br />

• Dada una relación R <strong>de</strong> tipo X ↔ Y, se <strong>de</strong>fine:<br />

– dom R = {x:X, y:Y | x ├→y ∈ R • x}<br />

– ran R = {x:X, y:Y | x ├→y ∈ R • y}<br />

– Restricción <strong>de</strong> dominio, dado un conjunto A ⊆ X<br />

A R = {x:X, y:Y | x ├→y ∈ R ∧ x∈ A• x ├→y }<br />

– Restricción <strong>de</strong> rango, dado un conjunto B ⊆ Y<br />

R B = {x:X, y:Y | x ├→y ∈ R ∧ y∈ B• x ├→y }<br />

– Substracción <strong>de</strong> dominio, equivalente a (X \ A) R<br />

A R = {x:X, y:Y | x ├→y ∈ R ∧ x∉A• x ├→y }<br />

– Substracción <strong>de</strong> rango<br />

R B = {x:X, y:Y | x ├→y ∈ R ∧ y∉ B• x ├→y }<br />

– Imagen relacional<br />

R (| A |) = ran (A R )


Inversa <strong>de</strong> una relación<br />

• Dada una relación R <strong>de</strong> tipo X ↔ Y, el conjunto X se<br />

<strong>de</strong>nomina origen e Y <strong>de</strong>stino.<br />

• La operación <strong>de</strong> inversa intercambia dichos conjuntos,<br />

invirtiendo la relación <strong>de</strong> los elementos. Es <strong>de</strong>cir:<br />

∀ x:X, y:Y • x ├→y ∈ R y├→x ∈ R ∼<br />

• Relación homogénea: el conjunto origen y <strong>de</strong>stino tienen el<br />

mismo tipo.<br />

• Relación heterogénea: el conjunto origen y <strong>de</strong>stino son <strong>de</strong><br />

distinto tipo.<br />

• Una relación homogénea importante es la I<strong>de</strong>ntidad<br />

Id X = = {x: X • x ├→x }<br />

• Reflexiva<br />

Propieda<strong>de</strong>s <strong>de</strong> <strong>relaciones</strong><br />

homogéneas<br />

Reflexive [X] == {R: X ↔ X | Id X ⊆ R}<br />

• Simétrica<br />

Symmetric [X] == {R: X ↔ X |∀ x:,y:X • x ├→y∈ R y├→x ∈ R }<br />

• Antisimétrica<br />

Antisymmetric[X] == {R: X ↔ X |(∀ x,y:X • x ├→y∈ R ∧ y├→x ∈ R x = y)}<br />

• Asimétrica<br />

Asymmetric [X] == {R: X ↔ X |∀ x, y:X •( x ├→y∈ R) y├→x ∉ R }<br />

• Estas tres últimas no son exhaustivas, es <strong>de</strong>cir, es posible que una relación<br />

no sea <strong>de</strong> ninguno <strong>de</strong> los 3 tipos.


<strong>Composición</strong> <strong>de</strong> <strong>relaciones</strong><br />

• Se pue<strong>de</strong> construir una relación a partir <strong>de</strong> otras dos.<br />

• Sintaxis: R;S , dadas R relación <strong>de</strong> tipo X ↔ Y y S <strong>de</strong> Y ↔ Z<br />

x├→z ∈ R;S ⇔ ∃ y: Y • x ├→y∈ R ∧ y├→z ∈ S<br />

• Transitividad. La relación R <strong>de</strong>be ser homogénea<br />

Transitive[X] == {R: X ↔ X |∀ x,y,z:X • x ├→y∈ R ∧ y├→z ∈ R x├→z ∈ R}<br />

• Relación <strong>de</strong> equivalencia<br />

Equivalence [X] = = Reflexive [X] ∩Symmetric [X] ∩Transitive[X]<br />

• Clase <strong>de</strong> equivalencia. Sea una relación <strong>de</strong> equivalencia E<br />

sobre el conjunto X, para cada elemento a la clase <strong>de</strong><br />

equivalencia <strong>de</strong> a es el conjunto:{x: X • x ├→a ∈ E}<br />

Cierres<br />

• Un cierre se obtiene añadiendo a una relación nuevos<br />

elementos <strong>de</strong> forma bien <strong>de</strong>finida.<br />

• Cierre reflexivo: R r = R ∪ Id X<br />

• Cierre simétrico: R s = R ∪ R ∼<br />

• Cierre enésimo. R n , composición <strong>de</strong> n copias <strong>de</strong> R. Siendo<br />

R 0 la relación i<strong>de</strong>ntidad.<br />

• Cierre transitivo. Resultado <strong>de</strong> la composición iterativa<br />

finita <strong>de</strong> R<br />

R + = ∪ {n : N | n ≥ 1 • R n}<br />

• Cierre transitivo y reflexivo:R* = R + ∪ Id X

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!