Partial order on matchings The lattice of stable matchings is based on the following weaker structure, a
partially ordered set whose elements are the stable matchings. Define a comparison operation \le on the stable matchings, where P\le Q
if and only if all doctors prefer matching Q to matching P: either they have the same assigned hospital in both matchings, or they are assigned a better hospital in Q than they are in P. If the doctors disagree on which matching they prefer, then P and Q are incomparable: neither one is \le the other. The same comparison operation can be defined in the same way for any two sets of participants to be matched, not just doctors and hospitals. The choice of which of the two sets of participants to use in the role of the doctors is arbitrary. Swapping the roles of the doctors and hospitals reverses the ordering of every pair of stable matchings, but does not otherwise change the structure of the partial order. This ordering gives the matchings the structure of a partially ordered set. A partially ordered set is defined as an ordering that obeys the following three properties: • For every matching P, P\le P • For every two different matchings P and Q, it cannot be the case that both P\le Q and Q\le P are true. • For every three different matchings P, Q, and R, if P\le Q and Q\le R, then P\le R. For stable matchings, all three properties follow directly from the definition of the comparison operation.
Top and bottom elements Define the best match of a participant x of a stable matching instance to be the participant y that x most prefers, among all the participants for which there exists a stable matching that pairs x with y, and define the worst match analogously. Then no two participants can have the same best match. For, suppose to the contrary that doctors x and x' both have y as their best match, and that y prefers x to x'. Then, in the stable matching that matches x' to y (which must exist by the definition of the best match of x'), x and y would be an unstable pair, because y prefers x to x' and x prefers y to any other partner in any stable matching. However, a stable matching cannot have an unstable pair. This contradiction shows that best matches are distinct, and therefore that assigning all doctors to their best matches gives a matching. It is a stable matching, because any unstable pair would also be unstable for one of the matchings used to define best matches. This matching, assigning all doctor to their best matches, also assigns all hospitals to their worst matches. In the partial ordering on stable matchings, it is greater than all other stable matchings. Symmetrically, assigning all doctors to their worst matches and assigning all hospitals to their best matches gives another stable matching. In the partial order on the matchings, it is less than all other stable matchings. The
Gale–Shapley algorithm gives a process for constructing stable matchings, that can be described as follows: until a matching is reached, the algorithm chooses an arbitrary hospital with an unfilled position, and that hospital makes a job offer to the doctor it most prefers among the ones it has not already made offers to. If the doctor is unemployed or has a less-preferred assignment, the doctor accepts the offer (and resigns from their other assignment if it exists). The process always terminates, because each doctor and hospital interact only once. When it terminates, the result is a stable matching, the one that assigns each hospital to its best match and that assigns all doctors to their worst matches. An algorithm that swaps the roles of the doctors and hospitals (in which unemployed doctors send a job applications to their next preference among the hospitals, and hospitals accept applications either when they have an unfilled position or they prefer the new applicant, firing the doctor they had previously accepted) instead produces the stable matching that assigns all doctors to their best matches and each hospital to its worst match.
Join and meet Given any two stable matchings P and Q for the same input, one can form two more matchings P\vee Q and P\wedge Q in the following way: • In P\vee Q, each doctor gets their best choice among the two hospitals they are matched to in P and Q (if these differ) and each hospital gets its worst choice among the two doctors it is matched to. • In P\wedge Q, each doctor gets their worst choice among the two hospitals they are matched to in P and Q (if these differ) and each hospital gets its best choice. (The same operations can be defined in the same way for any two sets of elements to be matched, not just doctors and hospitals.) Then both P\vee Q and P\wedge Q are matchings. It is not possible, for instance, for two doctors to have the same best choice and be matched to the same hospital in P\vee Q, for regardless of which of the two doctors is preferred by the hospital, that doctor and hospital would form an unstable pair in whichever of P and Q they are not already matched in. Because the doctors are matched in P\vee Q, the hospitals must also be matched. The same reasoning applies symmetrically to P\wedge Q. Additionally, both P\vee Q and P\wedge Q are stable. There cannot be a pair of a doctor and hospital who prefer each other to their match, because the same pair would necessarily also be an unstable pair for at least one of P and Q.
Distributive lattice The two operations P\vee Q and P\wedge Q form the
join and meet operations of a finite
distributive lattice. In this context, a finite
lattice is defined as a partially ordered
finite set (here, the set of stable matchings) in which there is a unique minimum element and a unique maximum element, in which every two elements have a unique
least element greater than or equal to both of them (their join) and every two elements have a unique greatest element less than or equal to both of them (their meet). In the case of the operations P\vee Q and P\wedge Q defined above, the join P\vee Q is greater than or equal to both P and Q because it was defined to give each doctor their preferred choice, and because these preferences of the doctors are how the ordering on matchings is defined. It is below any other matching that is also above both P and Q, because any such matching would have to give each doctor an assigned match that is at least as good. Therefore, it fits the requirements for the join operation of a lattice. Symmetrically, the operation P\wedge Q fits the requirements for the meet operation. Because they are defined using an element-wise minimum or element-wise maximum in the preference ordering, these two operations obey the same
distributive laws obeyed by the minimum and maximum operations on linear orderings: for every three different matchings P, Q, and R, :P\wedge(Q\vee R)=(P\wedge Q)\vee (P\wedge R) and :P\vee(Q\wedge R)=(P\vee Q)\wedge (P\vee R) Therefore, the lattice of stable matchings is a
distributive lattice. ==Representation by rotations==