SWEN-220 Math Models - Department of Software …swen-220/slides/SWEN-220-Alloy_04... · SWEN-220...
Transcript of SWEN-220 Math Models - Department of Software …swen-220/slides/SWEN-220-Alloy_04... · SWEN-220...
![Page 1: SWEN-220 Math Models - Department of Software …swen-220/slides/SWEN-220-Alloy_04... · SWEN-220 Math Models Fields & Relations ... Join all elements of Course to all elements of](https://reader030.fdocuments.in/reader030/viewer/2022020412/5b01c8077f8b9a6a2e8ec210/html5/thumbnails/1.jpg)
SWEN-220 Math Models
Fields & Relations
Joins
![Page 2: SWEN-220 Math Models - Department of Software …swen-220/slides/SWEN-220-Alloy_04... · SWEN-220 Math Models Fields & Relations ... Join all elements of Course to all elements of](https://reader030.fdocuments.in/reader030/viewer/2022020412/5b01c8077f8b9a6a2e8ec210/html5/thumbnails/2.jpg)
Simplified Course Model
![Page 3: SWEN-220 Math Models - Department of Software …swen-220/slides/SWEN-220-Alloy_04... · SWEN-220 Math Models Fields & Relations ... Join all elements of Course to all elements of](https://reader030.fdocuments.in/reader030/viewer/2022020412/5b01c8077f8b9a6a2e8ec210/html5/thumbnails/3.jpg)
One Solution
![Page 4: SWEN-220 Math Models - Department of Software …swen-220/slides/SWEN-220-Alloy_04... · SWEN-220 Math Models Fields & Relations ... Join all elements of Course to all elements of](https://reader030.fdocuments.in/reader030/viewer/2022020412/5b01c8077f8b9a6a2e8ec210/html5/thumbnails/4.jpg)
One Solution
What is SWEN220.enrolled?
![Page 5: SWEN-220 Math Models - Department of Software …swen-220/slides/SWEN-220-Alloy_04... · SWEN-220 Math Models Fields & Relations ... Join all elements of Course to all elements of](https://reader030.fdocuments.in/reader030/viewer/2022020412/5b01c8077f8b9a6a2e8ec210/html5/thumbnails/5.jpg)
One Solution
What is Course.enrolled?
![Page 6: SWEN-220 Math Models - Department of Software …swen-220/slides/SWEN-220-Alloy_04... · SWEN-220 Math Models Fields & Relations ... Join all elements of Course to all elements of](https://reader030.fdocuments.in/reader030/viewer/2022020412/5b01c8077f8b9a6a2e8ec210/html5/thumbnails/6.jpg)
One Solution
What is enrolled.Tim?
![Page 7: SWEN-220 Math Models - Department of Software …swen-220/slides/SWEN-220-Alloy_04... · SWEN-220 Math Models Fields & Relations ... Join all elements of Course to all elements of](https://reader030.fdocuments.in/reader030/viewer/2022020412/5b01c8077f8b9a6a2e8ec210/html5/thumbnails/7.jpg)
One Solution
What is enrolled.Person?
![Page 8: SWEN-220 Math Models - Department of Software …swen-220/slides/SWEN-220-Alloy_04... · SWEN-220 Math Models Fields & Relations ... Join all elements of Course to all elements of](https://reader030.fdocuments.in/reader030/viewer/2022020412/5b01c8077f8b9a6a2e8ec210/html5/thumbnails/8.jpg)
Join Operator Definition
Assume r1 and r2 are relations.
• Further assume r1 has m columns (m-ary),
• And r2 has n columns (n-ary).
Then• r1.r2 only makes sense if the last (rightmost) column of r1 and the first (leftmost) column of r2 are from the same top-level signature.
• r1.r2 has (m + n - 2) columns
![Page 9: SWEN-220 Math Models - Department of Software …swen-220/slides/SWEN-220-Alloy_04... · SWEN-220 Math Models Fields & Relations ... Join all elements of Course to all elements of](https://reader030.fdocuments.in/reader030/viewer/2022020412/5b01c8077f8b9a6a2e8ec210/html5/thumbnails/9.jpg)
Join Operator Definition
SWEN220.enrolled
r1(unary)
r2(binary)
{ SWEN220$0 } { SWEN220$0->Joe$0, . . . }
last (rightmost) column first (leftmost) column
Course
=
![Page 10: SWEN-220 Math Models - Department of Software …swen-220/slides/SWEN-220-Alloy_04... · SWEN-220 Math Models Fields & Relations ... Join all elements of Course to all elements of](https://reader030.fdocuments.in/reader030/viewer/2022020412/5b01c8077f8b9a6a2e8ec210/html5/thumbnails/10.jpg)
The Magical Join Operator (.)
SWEN220.enrolled
SWEN220 = { SWEN220$0 }
enrolled = { SWEN220$0->Joe$0, SWEN220$0->Tim$0,
SWEN261$0->Tim$0, SWEN261$0->Jane$0 }
Join all elements of SWEN220 to all elements of enrolled (create triplets)
{
SWEN220$0->SWEN220$0->Joe$0, SWEN220$0->SWEN220$0->Tim$0,
SWEN220$0->SWEN261$0->Tim$0, SWEN220$0->SWEN261$0->Jane$0
}
![Page 11: SWEN-220 Math Models - Department of Software …swen-220/slides/SWEN-220-Alloy_04... · SWEN-220 Math Models Fields & Relations ... Join all elements of Course to all elements of](https://reader030.fdocuments.in/reader030/viewer/2022020412/5b01c8077f8b9a6a2e8ec210/html5/thumbnails/11.jpg)
The Magical Join Operator (.)
SWEN220.enrolled
SWEN220 = { SWEN220$0 }
enrolled = { SWEN220$0->Joe$0, SWEN220$0->Tim$0,
SWEN261$0->Tim$0, SWEN261$0->Jane$0 }
Select all triplets where the two courses are the same
{
SWEN220$0->SWEN220$0->Joe$0, SWEN220$0->SWEN220$0->Tim$0,
SWEN220$0->SWEN261$0->Tim$0, SWEN220$0->SWEN261$0->Jane$0
}
![Page 12: SWEN-220 Math Models - Department of Software …swen-220/slides/SWEN-220-Alloy_04... · SWEN-220 Math Models Fields & Relations ... Join all elements of Course to all elements of](https://reader030.fdocuments.in/reader030/viewer/2022020412/5b01c8077f8b9a6a2e8ec210/html5/thumbnails/12.jpg)
The Magical Join Operator (.)
SWEN220.enrolled
SWEN220 = { SWEN220$0 }
enrolled = { SWEN220$0->Joe$0, SWEN220$0->Tim$0,
SWEN261$0->Tim$0, SWEN261$0->Jane$0 }
Project the result by removing the columns used for selection.
{
SWEN220$0->SWEN220$0->Joe$0, SWEN220$0->SWEN220$0->Tim$0,
SWEN220$0->SWEN261$0->Tim$0, SWEN220$0->SWEN261$0->Jane$0
}
![Page 13: SWEN-220 Math Models - Department of Software …swen-220/slides/SWEN-220-Alloy_04... · SWEN-220 Math Models Fields & Relations ... Join all elements of Course to all elements of](https://reader030.fdocuments.in/reader030/viewer/2022020412/5b01c8077f8b9a6a2e8ec210/html5/thumbnails/13.jpg)
The Magical Join Operator (.)
SWEN220.enrolled = { Joe$0, Tim$0 }
![Page 14: SWEN-220 Math Models - Department of Software …swen-220/slides/SWEN-220-Alloy_04... · SWEN-220 Math Models Fields & Relations ... Join all elements of Course to all elements of](https://reader030.fdocuments.in/reader030/viewer/2022020412/5b01c8077f8b9a6a2e8ec210/html5/thumbnails/14.jpg)
The Magical Join Operator (.)
Course.enrolled
Course = { SWEN220$0, SWEN261$0, SWEN262$0 }
enrolled = { SWEN220$0->Joe$0, SWEN220$0->Tim$0,
SWEN261$0->Tim$0, SWEN261$0->Jane$0 }
Join all elements of Course to all elements of enrolled (create triplets){
SWEN220$0->SWEN220$0->Joe$0, SWEN220$0->SWEN220$0->Tim$0,
SWEN220$0->SWEN261$0->Tim$0, SWEN220$0->SWEN261$0->Jane$0
SWEN261$0->SWEN220$0->Joe$0, SWEN261$0->SWEN220$0->Tim$0,
SWEN261$0->SWEN261$0->Tim$0, SWEN261$0->SWEN261$0->Jane$0
SWEN262$0->SWEN220$0->Joe$0, SWEN262$0->SWEN220$0->Tim$0,
SWEN262$0->SWEN261$0->Tim$0, SWEN262$0->SWEN261$0->Jane$0
}
![Page 15: SWEN-220 Math Models - Department of Software …swen-220/slides/SWEN-220-Alloy_04... · SWEN-220 Math Models Fields & Relations ... Join all elements of Course to all elements of](https://reader030.fdocuments.in/reader030/viewer/2022020412/5b01c8077f8b9a6a2e8ec210/html5/thumbnails/15.jpg)
The Magical Join Operator (.)
Course.enrolled
Course = { SWEN220$0, SWEN261$0, SWEN262$0 }
enrolled = { SWEN220$0->Joe$0, SWEN220$0->Tim$0,
SWEN261$0->Tim$0, SWEN261$0->Jane$0 }
Select all triplets where the two courses are the same{
SWEN220$0->SWEN220$0->Joe$0, SWEN220$0->SWEN220$0->Tim$0,
SWEN220$0->SWEN261$0->Tim$0, SWEN220$0->SWEN261$0->Jane$0
SWEN261$0->SWEN220$0->Joe$0, SWEN261$0->SWEN220$0->Tim$0,
SWEN261$0->SWEN261$0->Tim$0, SWEN261$0->SWEN261$0->Jane$0
SWEN262$0->SWEN220$0->Joe$0, SWEN262$0->SWEN220$0->Tim$0,
SWEN262$0->SWEN261$0->Tim$0, SWEN262$0->SWEN261$0->Jane$0
}
![Page 16: SWEN-220 Math Models - Department of Software …swen-220/slides/SWEN-220-Alloy_04... · SWEN-220 Math Models Fields & Relations ... Join all elements of Course to all elements of](https://reader030.fdocuments.in/reader030/viewer/2022020412/5b01c8077f8b9a6a2e8ec210/html5/thumbnails/16.jpg)
Course.enrolled
Course = { SWEN220$0, SWEN261$0, SWEN262$0 }
enrolled = { SWEN220$0->Joe$0, SWEN220$0->Tim$0,
SWEN261$0->Tim$0, SWEN261$0->Jane$0 }
Project the result by removing the columns used for selection.{
SWEN220$0->SWEN220$0->Joe$0, SWEN220$0->SWEN220$0->Tim$0,
SWEN220$0->SWEN261$0->Tim$0, SWEN220$0->SWEN261$0->Jane$0
SWEN261$0->SWEN220$0->Joe$0, SWEN261$0->SWEN220$0->Tim$0,
SWEN261$0->SWEN261$0->Tim$0, SWEN261$0->SWEN261$0->Jane$0
SWEN262$0->SWEN220$0->Joe$0, SWEN262$0->SWEN220$0->Tim$0,
SWEN262$0->SWEN261$0->Tim$0, SWEN262$0->SWEN261$0->Jane$0
}
The Magical Join Operator (.)
![Page 17: SWEN-220 Math Models - Department of Software …swen-220/slides/SWEN-220-Alloy_04... · SWEN-220 Math Models Fields & Relations ... Join all elements of Course to all elements of](https://reader030.fdocuments.in/reader030/viewer/2022020412/5b01c8077f8b9a6a2e8ec210/html5/thumbnails/17.jpg)
Course.enrolled = {Joe$0, Tim$0, Jane$0}
The Magical Join Operator (.)
![Page 18: SWEN-220 Math Models - Department of Software …swen-220/slides/SWEN-220-Alloy_04... · SWEN-220 Math Models Fields & Relations ... Join all elements of Course to all elements of](https://reader030.fdocuments.in/reader030/viewer/2022020412/5b01c8077f8b9a6a2e8ec210/html5/thumbnails/18.jpg)
The Magical Join Operator (.)
enrolled.Tim
Tim = { Tim$0 }
enrolled = { SWEN220$0->Joe$0, SWEN220$0->Tim$0,
SWEN261$0->Tim$0, SWEN261$0->Jane$0 }
Join all elements of enrolled to all elements of Tim (create triplets)
{
SWEN220$0->Joe$0->Tim$0, SWEN220$0->Tim$0->Tim$0,
SWEN261$0->Tim$0->Tim$0, SWEN261$0->Jane$0->Tim$0
}
![Page 19: SWEN-220 Math Models - Department of Software …swen-220/slides/SWEN-220-Alloy_04... · SWEN-220 Math Models Fields & Relations ... Join all elements of Course to all elements of](https://reader030.fdocuments.in/reader030/viewer/2022020412/5b01c8077f8b9a6a2e8ec210/html5/thumbnails/19.jpg)
The Magical Join Operator (.)
enrolled.Tim
Tim = { Tim$0 }
enrolled = { SWEN220$0->Joe$0, SWEN220$0->Tim$0,
SWEN261$0->Tim$0, SWEN261$0->Jane$0 }
Select all triplets where the two Persons are the same
{
SWEN220$0->Joe$0->Tim$0, SWEN220$0->Tim$0->Tim$0,
SWEN261$0->Tim$0->Tim$0, SWEN261$0->Jane$0->Tim$0
}
![Page 20: SWEN-220 Math Models - Department of Software …swen-220/slides/SWEN-220-Alloy_04... · SWEN-220 Math Models Fields & Relations ... Join all elements of Course to all elements of](https://reader030.fdocuments.in/reader030/viewer/2022020412/5b01c8077f8b9a6a2e8ec210/html5/thumbnails/20.jpg)
enrolled.Tim
Tim = { Tim$0 }
enrolled = { SWEN220$0->Joe$0, SWEN220$0->Tim$0,
SWEN261$0->Tim$0, SWEN261$0->Jane$0 }
Project the result by removing the columns used for selection.
{
SWEN220$0->Joe$0->Tim$0, SWEN220$0->Tim$0->Tim$0,
SWEN261$0->Tim$0->Tim$0, SWEN261$0->Jane$0->Tim$0
}
The Magical Join Operator (.)
![Page 21: SWEN-220 Math Models - Department of Software …swen-220/slides/SWEN-220-Alloy_04... · SWEN-220 Math Models Fields & Relations ... Join all elements of Course to all elements of](https://reader030.fdocuments.in/reader030/viewer/2022020412/5b01c8077f8b9a6a2e8ec210/html5/thumbnails/21.jpg)
enrolled.Tim = { SWEN261$0, SWEN220$0 }
The Magical Join Operator (.)
![Page 22: SWEN-220 Math Models - Department of Software …swen-220/slides/SWEN-220-Alloy_04... · SWEN-220 Math Models Fields & Relations ... Join all elements of Course to all elements of](https://reader030.fdocuments.in/reader030/viewer/2022020412/5b01c8077f8b9a6a2e8ec210/html5/thumbnails/22.jpg)
The Magical Join Operator (.)
enrolled.Person
![Page 23: SWEN-220 Math Models - Department of Software …swen-220/slides/SWEN-220-Alloy_04... · SWEN-220 Math Models Fields & Relations ... Join all elements of Course to all elements of](https://reader030.fdocuments.in/reader030/viewer/2022020412/5b01c8077f8b9a6a2e8ec210/html5/thumbnails/23.jpg)
Players – Teams - Cities
![Page 24: SWEN-220 Math Models - Department of Software …swen-220/slides/SWEN-220-Alloy_04... · SWEN-220 Math Models Fields & Relations ... Join all elements of Course to all elements of](https://reader030.fdocuments.in/reader030/viewer/2022020412/5b01c8077f8b9a6a2e8ec210/html5/thumbnails/24.jpg)
Navigation
![Page 25: SWEN-220 Math Models - Department of Software …swen-220/slides/SWEN-220-Alloy_04... · SWEN-220 Math Models Fields & Relations ... Join all elements of Course to all elements of](https://reader030.fdocuments.in/reader030/viewer/2022020412/5b01c8077f8b9a6a2e8ec210/html5/thumbnails/25.jpg)
Navigation
Player$3.playsFor.location?
![Page 26: SWEN-220 Math Models - Department of Software …swen-220/slides/SWEN-220-Alloy_04... · SWEN-220 Math Models Fields & Relations ... Join all elements of Course to all elements of](https://reader030.fdocuments.in/reader030/viewer/2022020412/5b01c8077f8b9a6a2e8ec210/html5/thumbnails/26.jpg)
Navigation
(Player$2 + Player$1 + Player$0).playsFor.location?
![Page 27: SWEN-220 Math Models - Department of Software …swen-220/slides/SWEN-220-Alloy_04... · SWEN-220 Math Models Fields & Relations ... Join all elements of Course to all elements of](https://reader030.fdocuments.in/reader030/viewer/2022020412/5b01c8077f8b9a6a2e8ec210/html5/thumbnails/27.jpg)
Navigation
playsFor.location.City$1?
![Page 28: SWEN-220 Math Models - Department of Software …swen-220/slides/SWEN-220-Alloy_04... · SWEN-220 Math Models Fields & Relations ... Join all elements of Course to all elements of](https://reader030.fdocuments.in/reader030/viewer/2022020412/5b01c8077f8b9a6a2e8ec210/html5/thumbnails/28.jpg)
Navigation
playsFor.location?
![Page 29: SWEN-220 Math Models - Department of Software …swen-220/slides/SWEN-220-Alloy_04... · SWEN-220 Math Models Fields & Relations ... Join all elements of Course to all elements of](https://reader030.fdocuments.in/reader030/viewer/2022020412/5b01c8077f8b9a6a2e8ec210/html5/thumbnails/29.jpg)
Navigation
playsFor.location?
playsFor = { P4->T0, P0->T3, P3->T1, P2->T1, P1->T2 }
location = { T0->C2, T3->C1, T1->C1, T2->C0 }
![Page 30: SWEN-220 Math Models - Department of Software …swen-220/slides/SWEN-220-Alloy_04... · SWEN-220 Math Models Fields & Relations ... Join all elements of Course to all elements of](https://reader030.fdocuments.in/reader030/viewer/2022020412/5b01c8077f8b9a6a2e8ec210/html5/thumbnails/30.jpg)
Navigation
playsFor.location?
playsFor = { P4->T0, P0->T3, P3->T1, P2->T1, P1->T2 }
location = { T0->C2, T3->C1, T1->C1, T2->C0 }
Join to get quadruples{
P4->T0->T0->C2, P4->T0->T3->C1, P4->T0->T1->C1, P4->T0->T2->C0,
P0->T3->T0->C2, P0->T3->T3->C1, P0->T3->T1->C1, P0->T3->T2->C0,
P3->T1->T0->C2, P3->T1->T3->C1, P3->T1->T1->C1, P3->T1->T2->C0,
P2->T1->T0->C2, P2->T1->T3->C1, P2->T1->T1->C1, P2->T1->T2->C0,
P1->T2->T0->C2, P1->T2->T3->C1, P1->T2->T1->C1, P1->T2->T2->C0
}
![Page 31: SWEN-220 Math Models - Department of Software …swen-220/slides/SWEN-220-Alloy_04... · SWEN-220 Math Models Fields & Relations ... Join all elements of Course to all elements of](https://reader030.fdocuments.in/reader030/viewer/2022020412/5b01c8077f8b9a6a2e8ec210/html5/thumbnails/31.jpg)
Navigation
playsFor.location?
playsFor = { P4->T0, P0->T3, P3->T1, P2->T1, P1->T2 }
location = { T0->C2, T3->C1, T1->C1, T2->C0 }
Select quads where the left column from playsFor equals the right column from location.{
P4->T0->T0->C2, P4->T0->T3->C1, P4->T0->T1->C1, P4->T0->T2->C0,
P0->T3->T0->C2, P0->T3->T3->C1, P0->T3->T1->C1, P0->T3->T2->C0,
P3->T1->T0->C2, P3->T1->T3->C1, P3->T1->T1->C1, P3->T1->T2->C0,
P2->T1->T0->C2, P2->T1->T3->C1, P2->T1->T1->C1, P2->T1->T2->C0,
P1->T2->T0->C2, P1->T2->T3->C1, P1->T2->T1->C1, P1->T2->T2->C0
}
![Page 32: SWEN-220 Math Models - Department of Software …swen-220/slides/SWEN-220-Alloy_04... · SWEN-220 Math Models Fields & Relations ... Join all elements of Course to all elements of](https://reader030.fdocuments.in/reader030/viewer/2022020412/5b01c8077f8b9a6a2e8ec210/html5/thumbnails/32.jpg)
Navigation
playsFor.location?
playsFor = { P4->T0, P0->T3, P3->T1, P2->T1, P1->T2 }
location = { T0->C2, T3->C1, T1->C1, T2->C0 }
Project – eliminate the columns used for the match.{
P4->T0->T0->C2, P4->T0->T3->C1, P4->T0->T1->C1, P4->T0->T2->C0,
P0->T3->T0->C2, P0->T3->T3->C1, P0->T3->T1->C1, P0->T3->T2->C0,
P3->T1->T0->C2, P3->T1->T3->C1, P3->T1->T1->C1, P3->T1->T2->C0,
P2->T1->T0->C2, P2->T1->T3->C1, P2->T1->T1->C1, P2->T1->T2->C0,
P1->T2->T0->C2, P1->T2->T3->C1, P1->T2->T1->C1, P1->T2->T2->C0
}
![Page 33: SWEN-220 Math Models - Department of Software …swen-220/slides/SWEN-220-Alloy_04... · SWEN-220 Math Models Fields & Relations ... Join all elements of Course to all elements of](https://reader030.fdocuments.in/reader030/viewer/2022020412/5b01c8077f8b9a6a2e8ec210/html5/thumbnails/33.jpg)
Navigation
playsFor.location =
{P4->C2, P0->C1, P3->C1, P2->C1, P1->C0}
![Page 34: SWEN-220 Math Models - Department of Software …swen-220/slides/SWEN-220-Alloy_04... · SWEN-220 Math Models Fields & Relations ... Join all elements of Course to all elements of](https://reader030.fdocuments.in/reader030/viewer/2022020412/5b01c8077f8b9a6a2e8ec210/html5/thumbnails/34.jpg)
Join Operator Definition
Assume r1 and r2 are relations.
• Further assume r1 has m columns (m-ary),
• And r2 has n columns (n-ary).
Then• r1.r2 only makes sense if the last (rightmost) column of r1 and the first (leftmost) column of r2 are from the same top-level signature.
• r1.r2 has (m + n - 2) columns