A Binary Relation as a Set of Pairs
A binary relation records which ordered pairs satisfy a relationship. One item can relate to several others or to none.
- Source
- Anbloq
- Language
- English
- Created
- Updated
- Chapters
- 4
- Reading time
- 1 min
In this article4 chapters
Draw a simple table
A course enrollment relation can contain (Ada, algebra), (Ada, systems), and (Bo, algebra). Using a function from person to one course would lose one enrollment. A Cartesian product supplies the universe of possible pairs.
Choose the direction of a lookup
Finding courses for Ada and finding attendees for algebra are queries on the same relation with different fixed coordinates. A reverse index shows how software can store a second view.[1]
Use an adjacency view to make relation pairs visible
A relation over three terminals can contain \((A,B)\), \((A,C)\) and \((C,C)\). It permits two distinct destinations from A and none from B. The absence of \((B,A)\) shows direction matters. Both coordinates belong to the declared carrier set. See graph adjacency lists.
Rows are source, columns are destination
A B C
A 0 1 1
B 0 0 0
C 0 0 1
State when relations need not be functions
A many-to-many assignment such as students to workshops intentionally permits several results per input. Converting to a dictionary with a single destination per source can lose relation pairs. Test a missing row and a row with two destinations.