\documentclass[12pt,reqno]{article}
\usepackage[usenames]{color}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{amsfonts}
\usepackage{amscd}
\usepackage{graphicx}
\usepackage[colorlinks=true,
linkcolor=webgreen,
filecolor=webbrown,
citecolor=webgreen]{hyperref}
\definecolor{webgreen}{rgb}{0,.5,0}
\definecolor{webbrown}{rgb}{.6,0,0}
\usepackage{color}
\usepackage{fullpage}
\usepackage{float}
\usepackage{psfig}
\usepackage{graphics}
\usepackage{latexsym}
\usepackage{epsf}
\usepackage{breakurl}
\setlength{\textwidth}{6.5in}
\setlength{\oddsidemargin}{.1in}
\setlength{\evensidemargin}{.1in}
\setlength{\topmargin}{-.1in}
\setlength{\textheight}{8.4in}
\newcommand{\seqnum}[1]{\href{https://oeis.org/#1}{\rm \underline{#1}}}
\begin{document}
\begin{center}
\epsfxsize=4in
\leavevmode\epsffile{logo129.eps}
\end{center}
\theoremstyle{plain}
\newtheorem{theorem}{Theorem}
\newtheorem{corollary}[theorem]{Corollary}
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem{proposition}[theorem]{Proposition}
\theoremstyle{definition}
\newtheorem{definition}[theorem]{Definition}
\newtheorem{example}[theorem]{Example}
\newtheorem{conjecture}[theorem]{Conjecture}
\theoremstyle{remark}
\newtheorem{remark}[theorem]{Remark}
\begin{center}
\vskip 1cm{\LARGE\bf
Sequences of the Stable Matching Problem
}
\vskip 1cm
\large
Matvey Borodin,
Aidan Duncan,
Boyan Litchev,
Jiahe Liu,
Veronika Moroz,
Matthew Qian,
Rohith Raghavan,
Garima Rastogi, and
Michael Voigt\\
PRIMES STEP \\
Department of Mathematics\\
MIT\\
77 Massachusetts Ave.\\
Cambridge, MA 02139 \\
USA\\
\href{mailto:primes.step@gmail.com}{\tt primes.step@gmail.com}\\
\ \\
Tanya Khovanova\\
Department of Mathematics \\
MIT\\
77 Massachusetts Ave.\\
Cambridge, MA 02139 \\
USA\\
\href{mailto:tanya@math.mit.edu}{\tt tanya@math.mit.edu}
\end{center}
\vskip .2 in
\begin{abstract}
We begin this paper by discussing different types of preference profiles related to the stable marriage problem. We then introduce the concept of soulmates, where a man and a woman rank each other first, and hell-pairs, where a man and a woman rank each other last. We generate sequences enumerating preference profiles of different types. We also calculate sequences related to the egalitarian cost, or ``quality'', of a matching. In total, we introduce and discuss 30 new sequences related to the stable marriage problem and discuss 6 sequences that are already in the {\it On-Line Encyclopedia of Integer Sequences}.
\end{abstract}
\section{Introduction}
In the stable marriage problem (SMP) \cite{GS1962}, $n$ men and $n$ women get married depending on their preferences in such a way that the matching is \textit{stable}. A matching is not stable if there exist two people of opposite genders who prefer each other over their assigned partners.
The SMP applies to a variety of settings and has many applications and generalizations. The most famous application is used for matching medical students with residency programs \cite{GS1962}, which is a variation of the stable marriage problem where hospitals are allowed to hire several graduate students.
In this paper, we describe many sequences related to this problem.
In Section~\ref{sec:prel}, we describe our assumptions in accordance with the original setting of the stable marriage problem, where people of two different genders marry each other. We give preliminary definitions, including the egalitarian cost for matching a pair of people of opposite genders.
In Section~\ref{sec:pp}, we introduce sequences related to different types of preference profiles depending on $n$, the number of men, which is the same as the number of women. These sequences describe the total number of preference profiles, as well as the number of preference profiles for each of the following: profiles where all men prefer the same woman, profiles where the first man is more desirable than the second man, profiles where all men rank the women the same way, profiles where all women have distinct men as their first choice, and profiles where the matrix of men's profiles forms a Latin square.
In Section~\ref{sec:soulmates}, we concentrate on sequences that depend on the number of soulmate pairs. Soulmate pairs are important in the SMP as they describe a pair of people who rank each other first. As a result, in a stable matching, any two people in a soulmate pair must be married, and then, they can be removed from consideration. We count the number of profiles with $k$ pairs of soulmates. We also count the number of profiles with $k$ pairs of soulmates in a special case when the men's and women's preferences form Latin squares. We provide formulas for these sequences.
In Section~\ref{sec:distSM}, we calculate the number of profiles that generate a given number of stable matchings. There is no easy formula for these numbers, so they are calculated by a program. Given the computational complexity, we only calculated the values for $n$ up to $n = 4$. For $n=2$, the number of stable matchings could be either 1 or 2. For $n=3$, the number of stable matchings could be 1, 2, or 3. For $n=4$, the number of stable matchings is not more than 10.
In Section~\ref{sec:special}, we consider some interesting sequences. First, we look at hell-pairs. A hell-pair is a pair of people of opposite genders who rank each other last. Intriguingly, they may still end up together in a stable matching, in which case we call them a hell-couple. We count the number of profiles where hell-couples are possible. Then we count the number of profiles containing outcasts---two people of opposite genders whom everyone else ranks last, making them destined for each other in a stable marriage. Finally, we enumerate the profiles where the outcasts form a hell-couple.
Section~\ref{sec:symmetries} is devoted to the symmetries of the SMP. We count the number of preference profiles up to relabeling men.
Given a preference profile, it is possible to have different stable matchings with different egalitarian costs. In Section~\ref{sec:ec}, for values of $n$ up to 4, we investigate which egalitarian costs are possible in a stable matching. In addition, we count the total number of stable matchings for a given egalitarian cost.
\section{Preliminaries}\label{sec:prel}
First, we make several assumptions:
\begin{itemize}
\item We have $n$ men and $n$ women.
\item Each person prefers to be married over being single.
\item A man only marries a woman, and vice versa.
\item Each person ranks people of the opposite gender without ties.
\end{itemize}
Thus, each man numbers the $n$ women in increasing order from $1$ through $n$, with 1 being his favorite and $n$ being his least favorite. Similarly, each woman numbers the $n$ men in increasing order from $1$ through $n$, with 1 being her favorite and $n$ being her least favorite. We call these $2n$ sets of preferences a \textit{preference profile}.
We can look separately at men's profiles and women's profiles. We can arrange men's preferences in a matrix where the $i$-th row corresponds to the $i$-th man's preferences. Thus, each row is a permutation of the numbers 1 through $n$ in such a matrix. Similar arguments work for women's preferences.
Once all the preference profiles are set, people are paired into marriages. We call the set of all these marriages \textit{unstable} if there is a man $m$ and woman $w$ such that they prefer each other to their spouses, and \textit{stable} if no such man/woman pair exists. In an unstable set of marriages, the pair $m$ and $w$ described above is called a \textit{blocking pair} or a \textit{rogue couple}. By definition, a set of marriages without a rogue couple is stable.
We call a set of stable marriages a \textit{stable matching}. We denote the maximum number of stable matchings for $n$ men and $n$ women as $M(n)$. If two people can end up married in a stable matching, they are called \textit{valid partners} of each other.
The Gale-Shapley algorithm \cite{GS1962}, also known as the deferred acceptance algorithm, finds a stable matching given a preference profile. It involves a number of rounds described as follows:
\begin{itemize}
\item In the first round, each man proposes to the woman he prefers most, and then each woman replies ``maybe'' to her most preferable suitor and ``no'' to all other suitors. Each woman is then provisionally ``engaged'' to the suitor she prefers the most out of those who proposed to her in that round. This suitor is, likewise, provisionally engaged to her.
\item In each subsequent round, each unengaged man proposes to the woman he prefers most out of the women to whom he has not yet proposed, regardless of whether the woman is already engaged. Then, each woman becomes provisionally engaged to the suitor she prefers the most out of those who have proposed to her so far. In doing so, she may reject her current provisional partner, who then becomes unengaged.
\item This process is repeated until everyone is engaged.
\end{itemize}
This version of the algorithm is called \textit{men-proposing}. By symmetry, there exists a women-proposing algorithm. The men-proposing Gale-Shapley algorithm is \textit{man-optimal} and \textit{woman-pessimal}. That means every man gets paired with the best possible valid partner, and every woman gets paired with the worst possible one. By symmetry, the women-proposing Gale-Shapley algorithm is \textit{woman-optimal} and \textit{man-pessimal}.
\subsection{The egalitarian cost}
The \textit{pairwise egalitarian cost} of a man and a woman is the sum of the rankings they give each other \cite{GI1989}. If we suppose woman $w$ ranks man $m$ as $i$-th in her preferences, and $m$ ranks $w$ as $j$-th in his preferences, then the egalitarian cost of the pair $(m,w)$ equals $i + j$. The \textit{egalitarian cost} of a stable matching is the sum of all the pairwise egalitarian costs of the married couples in the matching. Any matching with the smallest possible egalitarian cost is called \textit{egalitarian}.
Now, suppose we have a man and a woman with a pairwise egalitarian cost of 2. This means that they both rank each other first. Thus, unless they are married, they will form a blocking pair. That means any stable marriage has to have them as a couple. We call such a pair a \textit{soulmate pair} or \textit{soulmates}.
Soulmates are important as they reduce the matching problem to fewer people. In a stable matching problem with $n$ men, $n$ women, and $k$ pairs of soulmates, the number of stable matchings is the same as the number for the group of people from which the soulmate couples are removed, with the preferences for each person adjusted accordingly. In particular, the maximum number of stable marriages for any set of $2n$ people with $k$ pairs of soulmates cannot exceed $M(n - k)$.
\section{Preference profiles}\label{sec:pp}
\subsection{The total number of profiles}
The total number of different preference profiles is
\[(n!)^{2n},\]
as each person can rank the opposite gender in $n!$ ways.
Here are the first few terms of the sequence for the total number of different preference profiles, with the first term corresponding to $n = 1$:
\[1,\ 16,\ 46656,\ 110075314176,\ 619173642240000000000.\]
% 1, 1, 16, 46656, 110075314176, 619173642240000000000, 19408409961765342806016000000000000, 6823819180249038753817675898369448345600000000000000, 48789725533845219197010193096946682961355723304326670581760000000000000000
This is sequence \seqnum{A185141} in the OEIS \cite{OEIS}. It is defined as ``$a(n)$ is the number of `templates,' or ways of placing a single digit within an $n^2$-by-$n^2$ Sudoku puzzle so that all rows, columns, and $n$-by-$n$ blocks have exactly one copy of the digit.'' This connection between preference profiles and Sudoku puzzles has already been studied in \cite{STEPSudoku}.
\subsection{The homecoming queen}
We consider profiles where all men prefer the same woman. We call this woman a \textit{homecoming queen}. We count the profiles where a homecoming queen exists. Equivalently, we can consider the profiles where all women have the same man, a \textit{homecoming king}, as their first choice.
For $n$ men and $n$ women, there are $n$ ways to pick the woman that all men rank first. Then there are $((n-1)!)^n$ ways to fill in the rest of their preference profiles. There are then $(n!)^n$ ways to fill in the preference profiles for the women. This results in a total of
\[n((n-1)!)^n(n!)^n\]
profiles where all men prefer the same woman. This is the same number of preference profiles as when there exists a woman that all men rank at the $i$-th place, where $i$ can be anywhere from 1 to $n$.
The sequence of the total number of preference profiles where all men prefer the same woman as their first choice is now sequence \seqnum{A340890} and starts as follows:
\[1,\ 8,\ 5184,\ 1719926784,\ 990677827584000000,\ 2495937495082991616000000000000,\ \ldots. \]
%1, 8, 5184, 1719926784, 990677827584000000, 2495937495082991616000000000000, 58001506007267709490243656115814400000000000000, 23264754073069200132851692722771970253637181903994880000000000000000, 276563279384738472441881461150820319515509436842670527461953665124819533824000000000000000000, 156769169465776230081382813324668370616746016283229482126159396667031221100038318089578741760000000000000000000000000000000.
We can ignore women's preferences and divide the sequence by $(n!)^n$. We get the following sequence, which counts the number of different possible men's preferences in the stable marriage problem with the homecoming queen. This is now sequence \seqnum{A342573}:
\[1,\ 2,\ 24,\ 5184,\ 39813120,\ 17915904000000,\ \ldots. \]
%1, 2, 24, 5184, 39813120, 17915904000000, 702142910300160000000, 3330690501757390081228800000000, 2534703826002712645182542460223488000000000, 395940866122425193243875570782668457763038822400000000000
The formula for the $n$-th term is
\[n((n-1)!)^n.\]
This sequence can be viewed as the number of ordered $n$-tuples consisting of $n$ (not necessarily distinct) permutations of order $n$ such that the first element of each of them is the same. Equivalently, we can say that the $i$-th element of each of them is the same.
If we can assume that the homecoming queen is woman number 1, then the number of such men's profiles is sequence $a(n) = ((n-1)!)^n$.
\[1, 1, 8, 1296, 7962624, 2985984000000, 100306130042880000000,\ \ldots. \]
%1, 1, 8, 1296, 7962624, 2985984000000, 100306130042880000000, 416336312719673760153600000000, 281633758444745849464726940024832000000000, 39594086612242519324387557078266845776303882240000000000
This sequence is the same as sequence \seqnum{A091868} shifted by 1.
Another natural sequence is the number of profiles where all men prefer the same woman and all women prefer the same man. To calculate the sequence, we just need to square the corresponding terms in sequence \seqnum{A342573}, which is the number of different possible men's preferences where they all prefer the same woman as their first choice. We get
\[1, 4, 576, 26873856, 1585084524134400, 320979616137216000000000000,\ \ldots. \]
%1, 4, 576, 26873856, 1585084524134400, 320979616137216000000000000, 493004666484778531821296025600000000000000, 11093499218496894899774404870401368262117949440000000000000000
This is now sequence \seqnum{A343474}: the number of preference profiles with a homecoming queen and king. The queen and king rank each other first, meaning they are soulmates. Such profiles have exactly one pair of soulmates.
\subsection{One woman is more preferable than another}
The homecoming queen is a more desirable woman than any other woman. We want to relax this condition and consider a pair of women where woman $w_1$ is always ranked higher than woman $w_2$.
We see that for each man, there are $\frac{n!}{2}$ possible profiles, as only half of all potential profiles meet our conditions. Note that we are assuming that $n>1$. The total number of ways to arrange all the men's profiles is
\[\frac{(n!)^{n}}{2^n}.\]
They form sequence \seqnum{A343692} starting with index 2:
\[1,\ 27,\ 20736,\ 777600000,\ 2176782336000000,\ \ldots.\]
%Table[(n!)^n/2^n, {n, 2, 10}]
%1, 27, 20736, 777600000, 2176782336000000, 645362587921121280000000, 27285016590396539545426329600000000, 213106813311662727500673631554480635904000000000, 386661002072680852777222237092449665784217600000000000000000000
By symmetry, sequence \seqnum{A343692} counts the number of women's preferences where man $m_1$ is always more desired than man $m_2$.
Going back to counting profiles where one woman is more preferable than another, since there are no conditions for the women's preferences, there are $(n!)^n$ ways to arrange them. This gives us a total of
\[\frac{(n!)^{2n}}{2^n}\]
profiles where every man prefers woman $w_1$ over $w_2$. This is now sequence \seqnum{A338665}, and it starts as
\[4,\ 5832,\ 6879707136,\ 19349176320000000000,\ \ldots.\]
%Table[(n!)^(2 n)/2^n, {n, 2, 10}]
%4, 5832, 6879707136, 19349176320000000000, 303256405652583481344000000000000, 53311087345695615264200592956011315200000000000000, 190584865366582887488321066784947980317795794157526056960000000000000000.
Since every man prefers woman $w_1$ to woman $w_2$, he will always propose to woman $w_1$ first. When woman $w_2$ is proposed to, the man proposing to her has already proposed to woman $w_1$. Since a man can only propose once per round, woman $w_1$ is first proposed to by him in an earlier round than woman $w_2$. Once a woman is proposed to, she will remain engaged (not necessarily with the same man) for the rest of the algorithm, so woman $w_1$'s first engagement comes in an earlier round than woman $w_2$'s.
We also consider a symmetric case where both conditions apply: man $m_1$ is more desired than man $m_2$, and woman $w_1$ is more desired than woman $w_2$. The corresponding sequence is the square of sequence \seqnum{A343692}; that is, the number of profiles is
\[\frac{(n!)^{2n}}{4^n}.\]
It is now sequence \seqnum{A343693}: the number of preference profiles for $n$ men and $n$ women, with $n>1$, such that all men prefer woman $w_1$ over woman $w_2$ and all women prefer man $m_1$ over man $m_2$.
\[1,\ 729,\ 429981696,\ 604661760000000000.\]
%Table[(n!)^(2 n)/4^n, {n, 2, 10}]
%1, 729, 429981696, 604661760000000000, 4738381338321616896000000000000, 416492869888246994251567132468838400000000000000, 744472130338214404251254167128703048116389820927836160000000000000000, 45414513879851870274245681660582356320629081347021328317938070440504213897216000000000000000000, 149506730523849706727392972302120562187906280787686807752761265437155934429205244149760000000000000000000000000000000000000000
This sequence is sequence \seqnum{A338665} divided by $2^n$.
\subsection{Same taste}
Suppose the men have exactly the same taste meaning that they rank all the women in the same order. Then, the number of ways to arrange men's preferences is $n!$, since every man ranks all the women in the same order. This is the sequence of factorial numbers, \seqnum{A000142}.
If we also consider the women's preferences, we get a total of $(n!)^{n+1}$ profiles, since the women can rank the men in any order. This sequence of preference profiles corresponds to the OEIS sequence \seqnum{A091868} and starts as
\[1,\ 1,\ 8,\ 1296,\ 7962624,\ 2985984000000,\ \ldots.\]
Performing the Gale-Shapley Algorithm on these profiles always leads to a special result, as we show below.
\begin{proposition}
When the men all rank the women in the same order, the men-proposing Gale-Shapley algorithm ends in exactly $n$ rounds.
\end{proposition}
\begin{proof}
In the first round of the men-proposing algorithm, all men propose to the same woman: the homecoming queen. She gets engaged to the man of her first choice. In the second round, the $n-1$ unengaged men propose to the same woman who is second on their lists, so she gets engaged to her most-preferred man out of the $n-1$ men. This continues for $n$ rounds.
\end{proof}
Interestingly, we get couples with mutual rankings (1,1), (2,2), and so on. The egalitarian cost of the resulting matching is
\[n(n+1).\]
Notice that if both men and women have the same taste, then the number of such profiles is just $(n!)^2$. This corresponds to the sequence of factorial squares, \seqnum{A001044}:
\[1,\ 4,\ 36,\ 576,\ 14400,\ 518400,\ 25401600,\ 1625702400,\ \ldots.\]
\subsection{Tastes differ}
On the opposite side of the spectrum, consider the scenario where each woman is the first choice for exactly one man, which we call the case where men's tastes differ. As compared to the previous case, this one may have a chance to make more people happier.
For $n$ men and $n$ women, there are $n!$ ways for the men to arrange their first choices and $((n-1)!)^n$ ways to rank the rest of the women. We can set the women's preferences in $(n!)^n$ ways, since their preferences are not restricted, giving us a total of
\[(n!)^{n+1}((n-1)!)^n\]
preference profiles where all men prefer different women. In general, this sequence describes the number of profiles where each man ranks a different woman as his $i$-th choice.
The sequence of preference profiles where all men prefer different women as their first choices, which is now \seqnum{A343475}, starts as follows:
\[1, 8, 10368, 10319560704, 23776267862016000000,\ \ldots.\]
%Table[n!^(n + 1) (n - 1)!^n, {n, 10}]
%1, 8, 10368, 10319560704, 23776267862016000000, 299512499409958993920000000000000, 41761084325232750832975432403386368000000000000000, 117254360528268768669572531322770730078331396796134195200000000000000000, 11151031424792655208856660513601075282865340493496475667265971777832723603783680000000000000000000, 56888396215740878371932195299255658329404794388858314473940721862532289512781904868346333809868800000000000000000000000000000000.
\begin{proposition}
The men-proposing Gale-Shapley algorithm terminates in one round if and only if each woman is the first choice for exactly one man.
\end{proposition}
\begin{proof}
If every woman is the first choice for exactly one man, then in the first round of the men-proposing algorithm, every woman is proposed to exactly once. So, all women get engaged, and the algorithm stops.
Similarly, if the men-proposing algorithm stops after the first round, all men get engaged in the first round. It follows that they proposed to different women.
\end{proof}
If we wanted to count only the men's preference profiles where each man has ranked a different woman as their first choice, we just need to ignore women's preferences, which is achieved by dividing sequence \seqnum{A343475} by $(n!)^n$. This gives us the formula
\[n!((n-1)!)^n.\]
We get another sequence, which is now \seqnum{A343694}. It counts the number of men's preference profiles where all men prefer different women as their first choices and starts as follows:
\[1, 2, 48, 31104, 955514880, 2149908480000000.\]
%Table[n! (n - 1)!^n, {n, 10}]
%1, 2, 48, 31104, 955514880, 2149908480000000, 505542895416115200000000, 16786680128857246009393152000000000, 102199258264429373853760111996211036160000000000, 143679021498505654124337567125614729953051527872512000000000000
We can also consider a more specific case where each man ranks a different woman as his first choice and each woman ranks a different man as her first choice. The new sequence counting such profiles, \seqnum{A343695}, is a square of the previous sequence, \seqnum{A343694}:
\[(n!)^2((n-1)!)^{2n},\] and starts as follows:
\[1, 4, 2304, 967458816, 913008685901414400.\]
%Table[n!^2 (n - 1)!^(2 n), {n, 10}]
%1, 4, 2304, 967458816, 913008685901414400, 4622106472375910400000000000000, 255573619105709190896159859671040000000000000000, 281792629748570725486109522755987396047015304495104000000000000000000, 10444688389799535672440661668710965357968392730721066975209656086980827545600000000000000000000, 20643661218768049943606755030193893294574411787828905156303609149475717218398297638625517612925190144000000000000000000000000
We can restrict the profiles some more. Suppose not only men and women have different preferences for their first choices, but also these choices match each other. This is equivalent to saying that we have $n$ pairs of soulmates, and this case is described in Section~\ref{sec:nsoul}.
\subsection{Tastes really differ}
Suppose now, not only does each man rank a different woman first, but also each $k$-th ranking is distinct across all men. In other words, the men's preferences form a Latin square when arranged in a matrix. Thus, the number of such profiles for men is described by sequence \seqnum{A002860} (the number of Latin squares) in the OEIS:
\[1,\ 2,\ 12,\ 576,\ 161280,\ 812851200,\ 61479419904000,\ \ldots.\]
%A002860 Number of Latin squares of order n; or labeled quasigroups.
% 1, 2, 12, 576, 161280, 812851200, 61479419904000, 108776032459082956800, 5524751496156892842531225600, 9982437658213039871725064756920320000, 776966836171770144107444346734230682311065600000
Counting in the women's preferences, too, for every $n$, we need to multiply the number of possibilities for the women's profiles, $(n!)^n$, by the corresponding term of \seqnum{A002860}$(n)$. This gives us a new sequence \seqnum{A343696} of unique profiles for $n$ men and $n$ women where men's profiles form a Latin square:
\[1,\ 8,\ 2592,\ 191102976,\ 4013162496000000,\ 113241608573209804800000000, \ldots.\]
%1, 8, 2592, 191102976, 4013162496000000, 113241608573209804800000000, 5078594244241245901264634511360000000000, 759796697672599288560347581750936194390876487680000000000, 602809439070636186475532789128702956081602819845966698324215778508800000000000, 3952455012405984878655023176872856656419546081589440478151647395030463223431168000000000000000000000000,
As before, the men-proposing Gale-Shapley algorithm for such profiles terminates in one round.
Now, we consider the sequence when both the men's and women's profiles form Latin squares. We call such profiles \textit{mutually-Latin} profiles. The formula for the number of profiles is \seqnum{A002860}$(n)^2$ because both the men and women have \seqnum{A002860}$(n)$ choices for profiles. This sequence, which counts the number of preference profiles when both the men's and women's profiles form Latin squares, is now \seqnum{A343697}:
\[1, 4, 144, 331776, 26011238400, 660727073341440000, 3779719071732351369216000000, \ldots.\]
As before, both the men-proposing and the women-proposing Gale-Shapley algorithms for such profiles terminate in one round.
\subsection{Latin profiles}
The \textit{Latin} marriage problem is a subset of the stable marriage problem where the sum of a man's ranking of a woman and said woman's ranking of the man must equal $n+1$. In other words, the egalitarian cost of any man-woman pair is $n+1$ \cite{T2002}. The corresponding profiles are called \textit{Latin} profiles. The Latin marriage problem is interesting because its profiles tend to produce a lot of stable matchings. Sequence \seqnum{A351413} in the OEIS \cite{OEIS} describes the number of possible stable matchings in a Latin profile, and starts as follows:
\[1,\ 2,\ 3,\ 10,\ 9,\ 48,\ 61,\ \ldots.\]
This sequence counts the number of stable matchings for Latin profiles and thus provides a lower bound of the maximum number of stable matchings for any profile for a given $n$.
In a Latin profile, men's preferences (and, by symmetry, women's preferences) have to form a Latin square \cite{T2002}. The number of Latin profiles is the number of Latin squares of the corresponding order \seqnum{A002860}$(n)$ since a Latin square represents men's preferences. Once the men's preferences are set, women's preferences are uniquely determined.
\subsection{Disjoint profiles}
In this section, we study a special type of profile called a \textit{disjoint} profile. In such profiles, each pair of mutual rankings $(i,j)$ occurs exactly once. In particular, each disjoint profile has exactly one pair of soulmates and one hell-pair. Such profiles correspond to entries in a disjoint-groups Sudoku \cite{STEPSudoku}, where in a particular place in a box, all digits are distinct across all the boxes. For example, the top-left corners of every box have distinct digits. This creates 9 additional groups to add to columns, rows, and boxes that have to contain distinct digits.
As shown in \cite{STEPSudoku}, there are 12 disjoint profiles for $n=2$.
\begin{proposition}
For any $n$, the number of disjoint profiles does not exceed $(n^2)!$ and is divisible by $(n!)^2$.
\end{proposition}
\begin{proof}
There are $n^2$ ways to pair a man and a woman and $n^2$ ways for them to rank each other. Thus, each profile is a permutation of possible rankings distributed among possible pairs of people. The number of permutations is $(n^2)!$. Not all permutations can be used, as we forbid ties in individual rankings.
In such profiles, there is exactly one pair of soulmates, whom we denote $m_1$ and $w_1$. Let $m_1$'s $k$th choice be $w_k$, and $w_1$'s $k$th choice be $m_k$. The possible disjoint profiles in this scenario each correspond to $(n!)^2$ different profiles overall because there are $n^2$ ways to pick the soulmate pair and $(n-1)!^2$ ways to fill in the remainder of the profiles for each person in the soulmate pair. Therefore, the number of disjoint profiles is divisible by $n^2 \cdot (n-1)!^2 = (n!)^2$.
\end{proof}
We wrote a program to calculate the number of disjoint profiles. The argument in the proof above allowed us to slightly speed up the program by assuming that the first man and the first woman rank other people in order and multiplying the resulting count of disjoint profiles by $(n!)^2$. We were able to calculate the number of disjoint profiles up to $n=4$. This is now sequence \seqnum{A345679}, which begins
\[1,\ 12,\ 8784,\ 1031049216,\ \ldots.\]
\subsection{Joint profiles}
In our paper \cite{STEPSudoku}, we introduced a new type of Sudoku called \textit{joint-groups} or \textit{JG Sudoku}. In such a Sudoku, every digit corresponds to a \textit{joint} preference profile. In this new profile type, each possible mutual ranking $(i,j)$ appears exactly $n$ times, and once per $i$. We showed that a joint profile is a mutually-Latin profile; that is, both men's and women's preferences form Latin squares. In addition, for a mutual ranking $(i,j)$, the value $j$ is a function of $i$, thus we can write $j = f(i)$. We call the function $f$ the \textit{key} function.
The number of joint profiles is the number of Latin squares of order $n$ times the number of key functions, or $\text{A}002860(n)n!$. This follows from the fact that a joint profile is uniquely defined by a Latin square of women's preferences and the key function, which is a permutation of $n$ elements.
The number of joint profiles as a function of $n$ is now sequence \seqnum{A344693}:
\[1,\ 4,\ 72,\ 13824,\ 19353600,\ 585252864000,\ 309856276316160000,\ \ldots.\]
%1, 4, 72, 13824, 19353600, 585252864000, 309856276316160000, 4385849628750224818176000, 2004821822925413274697731145728000, 36224269774123479086515914989912457216000000, 31014029806101314488308034499720939299674343342080000000
\section{Soulmates}\label{sec:soulmates}
Recall that soulmates are a pair of people who rank each other first and must, therefore, always be married.
To begin, let's look at the number of profiles with $k$ pairs of soulmates, which we denote by $F(k, n)$. For $n=2$, we can manually check that 2 profiles have no soulmates, 12 profiles have 1 pair of soulmates, and 2 profiles have 2 pairs of soulmates.
We introduce another function that is useful for our calculations. Given our set of $n$ men and $n$ women, consider a subset of $k$ men and $k$ women such that no pair of men and women outside this subset has a soulmate. Then, let us denote the number of profiles for the people not in our subset as $S(k, n)$. We have
\[S(0,n) = F(0,n) \quad \textrm{ and } \quad S(n,n) = 1.\]
\begin{lemma}
The formula for $S(k,n)$ is
\[S(k,n) = \sum_{i=0}^{n-k} (-1)^{i}\cdot \binom{n-k}{i}^2\cdot ((n-1)!)^{2i}\cdot i!\cdot (n!)^{2n-2k-2i}.\]
\end{lemma}
\begin{proof}
First, the total number of possible profiles for people not in the subset is $(n!)^{2n-2k}$ since there are $n!$ ways to fill each person's preference profile and a total of $2n-2k$ people. Next, we calculate the number of profiles with at least one pair of soulmates and subtract it from the total number of profiles for people not in the subset.
There are ${n-k \choose 1}^2$ ways to pick a pair of soulmates out of $n-k$ men and $n-k$ women, and their profiles can be completed in $((n-1)!)^2$ ways. Everyone else's profiles can be completed in $(n!)^{2n-2k-2}$ ways, but in completing these other profiles, we overcount the number of profiles with more than one pair of soulmates. Since the profiles with at least 2 pairs of soulmates are counted twice, we must subtract these ${n-k \choose 2}^2 \cdot 2! \cdot ((n-1)!)^4 \cdot (n!)^{2n-2k-4}$ profiles. But now, we undercount the profiles with three pairs of soulmates, so we add $\binom{n – k}{3}^2 \cdot 3! \cdot ((n – 1)!)^6 \cdot (n!)^{2n-2k-6}$ profiles.
We continue in this fashion using the principle of inclusion-exclusion, and we get the complete formula:
\[S(k,n) = \sum_{i=0}^{n-k} (-1)^{i}\cdot \binom{n-k}{i}^2 \cdot i! \cdot ((n-1)!)^{2i} \cdot (n!)^{2n-2k-2i}.\]
\end{proof}
\begin{example}
When $k = n$, we get $S(n,n)=1$. If $k = n-1$ instead, we get
\[S(n-1,n) = (n!)^2 - ((n-1)!)^2 = ((n-1)!)^2(n^2-1).\]
\end{example}
Now, we are ready to calculate our main function $F(k,n)$.
\begin{theorem}
The formula for $F(k,n)$ is
\[\binom{n}{k}^2\cdot k! \cdot ((n-1)!)^{2k} \cdot \left(\sum_{i=0}^{n-k} (-1)^{i}\cdot \binom{n-k}{i}^2\cdot ((n-1)!)^{2i}\cdot i!\cdot (n!)^{2n-2k-2i}\right).\]
\end{theorem}
\begin{proof}
There are $\binom{n}{k}^2$ ways to choose $k$ pairs of people to be soulmates, and they can be matched to each other in $k!$ ways. These soulmates' profiles can be completed in $((n-1)!)^{2k}$ ways. Now, all that remains is to complete the remaining $2(n-k)$ people's profiles in such a way that there are no pairs of soulmates. We calculated this above as $S(k,n)$.
Thus, the complete formula for the number of profiles with exactly $k$ pairs of soulmates is
\[F(k,n) = \binom{n}{k}^2\cdot k! \cdot ((n-1)!)^{2k} \cdot S(k,n),\]
or, in the expanded form,
\[\binom{n}{k}^2\cdot k! \cdot ((n-1)!)^{2k} \cdot \left(\sum_{i=0}^{n-k} (-1)^{i}\cdot \binom{n-k}{i}^2\cdot ((n-1)!)^{2i}\cdot i!\cdot (n!)^{2n-2k-2i}\right).\]
\end{proof}
We evaluate the function $F(k,n)$ for $k$ and $n$ below 5 in Table~\ref{table:ksoul}. Rows correspond to a fixed $n$, and columns correspond to a fixed $k$.
\begin{table}[ht!]
\begin{center}
\begin{tabular}{|c||c|c|c|c|c|}
\hline
& 0& 1& 2& 3& 4\\
\hline
1& 0& 1& & & \\
\hline
2& 2& 12& 2& & \\
\hline
3& 9984& 27072& 9216& 384& \\
\hline
4& 28419102720& 55736377344& 23460876288& 2418647040& 40310784\\
\hline
\end{tabular}
\end{center}
\caption{$F(k,n)$.}
\label{table:ksoul}
\end{table}
There are several sequences here that deserve our separate attention.
\subsection{Special cases}
\subsubsection{Love is in the air: $n$ pairs of soulmates}\label{sec:nsoul}
Suppose we have exactly $n$ pairs of soulmates. Our formula gives
\[F(n,n) = ((n-1)!)^{2n} n!.\]
The number of preference profiles for $n$ men and $n$ women with $n$ pairs of soulmates is now sequence \seqnum{A343698}. It starts as follows:
\[1,\ 2,\ 384,\ 40310784,\ 7608405715845120, \ldots.\]
%Table[(n - 1)!^(2 n) n!, {n, 10}]
%1, 2, 384, 40310784, 7608405715845120, 6419592322744320000000000000, 50709051409862934701619019776000000000000000, 6988904507653043786857875068352862005134308147200000000000000000
For such profiles, each person has exactly one valid partner: their soulmate. Consequently, the only stable matching is where each soulmate pair is married. For these profiles, the Gale-Shapley algorithm ends in one round, whether it is men-proposing or women-proposing. Also, the resulting stable matching has the best possible egalitarian cost, $2n$.
\subsubsection{$n-1$ pairs of soulmates}
For $n-1$ pairs of soulmates, the formula becomes
\[ ((n-1)!)^{2n+1} \cdot n^2 \cdot (n^2 - 1).\]
The sequence of preference profiles with $n-1$ pairs of soulmates is now sequence \seqnum{A343699}:
\[0,\ 12,\ 9216,\ 2418647040,\ 913008685901414400,\ \ldots.\]
%Table[(n - 1)!^(2 n + 1) n^2 (n^2 - 1), {n, 10}]
%0, 12, 9216, 2418647040, 913008685901414400, 1348114387776307200000000000000, 17038241273713946059743990644736000000000000000, 3522407871857134068576369034449842450587691306188800000000000000000, 20723588074999078715160042993474137615016652243494180506368365251946086400000000000000000000, 5631951225358346958821287334626310174611074644496973132920131464390696661765408581966287047177011200000000000000000000000
\begin{proposition}
Profiles with $n-1$ pairs of soulmates have exactly one stable matching. When used on these preference profiles, the men-proposing Gale-Shapley algorithm ends in $j$ rounds, where the man in the non-soulmate pair ranks his eventual wife $j$.
\end{proposition}
\begin{proof}
Soulmates must be matched with each other; after that, two people are left, and they cannot avoid being together as a couple. As a result, we get a unique stable matching.
In the first round of the men-proposing Gale-Shapley algorithm, each of the $n-1$ men in the $n-1$ soulmate pairs propose to their first choices, and then they stay engaged for all the rounds. So, the only person left proposing is the man in the non-soulmate pair. He gets to his true partner on the $j$-th round, where $j$ corresponds to his ranking of her.
\end{proof}
\subsubsection{No soulmates}
To calculate the number of profiles without any pairs of soulmates, we plug in $k=0$ into the formula for $S(k,n)$. We get
\[\binom{n}{0}^2\cdot 0! \cdot ((n-1)!)^{0} \cdot \left(\sum_{i=0}^{n-0} (-1)^{i}\cdot \binom{n-0}{i}^2\cdot ((n-1)!)^{2i}\cdot i!\cdot (n!)^{2n-20-2i}\right).\]
Simplifying, we have
\[\sum_{i=0}^{n} (-1)^{i}\cdot \binom{n}{i}^2\cdot ((n-1)!)^{2i}\cdot i!\cdot (n!)^{2n-2i}.\]
The number of profiles without soulmates is now sequence \seqnum{A343700}, which starts as follows:
\[0,\ 2,\ 9984,\ 28419102720,\ 175302739963548794880,\ \ldots.\]
%0, 2, 9984, 28419102720, 175302739963548794880, 5801674463718565478400000000000000, 2113937863028052653298578438638220083200000000000000, 15500609395854457241550377325238753195602871153217230602240000000000000000, 3853954130777658041996391488959258416352503300075390514753331535052146995185582080000000000000000000, 51491301881551236595846912233155650312255006810382593559575031295967497982281052869908552079508571276842106880000000000000000000000
Such profiles are useful for calculating $M(n)$, which is the maximum possible number of stable matchings. Indeed, consider a profile for $n$ men and $n$ women with soulmates $m_1$ and $w_1$. The soulmates have to be together. So, the number of different stable matchings for this profile is the same as the number of stable matchings for $n-1$ men and $n-1$ women when we exclude $m_1$ and $w_1$. Because the sequence $M(n)$ is strictly increasing \cite{T2002}, profiles with $M(n)$ possible matchings cannot have soulmates for $n>1$.
\subsection{Tastes really differ}
Let us go back to profiles where men's preferences form a Latin square and see what happens if we require $k$ pairs of soulmates. We denote the number of Latin squares of size $n$ as $L_n$.
\begin{theorem}
The number of preference profiles in a stable matching problem with $n$ men and $n$ women, where there are exactly $k$ pairs of soulmates and the men's preferences form a Latin square, is
\[L_n \cdot \binom{n}{k}\cdot (n-1)^{n-k} \cdot ((n-1)!)^n.\]
\end{theorem}
\begin{proof}
Since the preference profiles for men form a Latin square, every woman will have exactly one man who ranks her first. Therefore, if we want $k$ pairs of soulmates, there are $\binom{n}{k}$ ways to pick the $k$ women for the soulmate pairs. After that, we have $(n-1)!$ ways to complete the profiles for every woman with a soulmate, and $(n-1)(n-1)!$ ways to complete the profiles for every woman that does not have a soulmate. Since we have $L_n$ ways to choose the profiles for men, this gives us a total of
\[L_n \cdot \binom{n}{k}\cdot ((n-1)!)^k \cdot (n-1)^{n-k}((n-1)!)^{n-k} = L_n \cdot \binom{n}{k}\cdot (n-1)^{n-k} \cdot ((n-1)!)^n\] preference profiles that have $k$ pairs of soulmates.
\end{proof}
We summarize the results for small values of $n$ and $k$ in Table~\ref{table:mtrd}. The columns correspond to different $n$, and rows correspond to different $k$. As expected, the total for a given $n$ is sequence \seqnum{A343696}, which counts the number of profiles when men's tastes really differ.
\begin{table}[ht!]
\begin{center}
\begin{tabular}{|c|c|c|c|c|c|}
\hline
&1&2&3&4&5\\
\hline
0&0&2&768&60466176&1315033086689280\\
\hline
1&1&4&1152&80621568&1643791358361600\\
\hline
2&---&2&576&40310784&821895679180800\\
\hline
3&---&---&96&8957952&205473919795200\\
\hline
4&---&---&---&746496&25684239974400\\
\hline
5&---&---&---&---&1284211998720\\
\hline
Total&1&8&2592&191102976&4013162496000000\\
\hline
\end{tabular}
\end{center}
\caption{Distribution of preference profiles by the number of soulmate pairs when men's tastes form a Latin square.}
\label{table:mtrd}
\end{table}
There are two special sequences to consider. The first one is the number of preference profiles where men's tastes really differ and there are $n$ soulmates. It corresponds to the case $k=n$, and the formula for it is
\[L_n \cdot ((n-1)!)^n.\]
The number of preference profiles when men's tastes really differ, and there are $n$ pairs of soulmates is now sequence \seqnum{A344662}:
\[1,\ 2,\ 96,\ 746496,\ 1284211998720,\ 2427160677580800000000,\ \ldots.\]
%1 ,2, 96, 746496, 1284211998720, 2427160677580800000000, 6166762687851449045483520000000000, 45287412266290145430585597857888710164480000000000, 1555956528335898586085189699733983238252540690603399394099200000000000, 395245501240598487865502317687285665641954608158944047815164739503046322343116800000000000000, 1116338347579496830411118207235985750697191044300850538143260547614352958498124401617636687872000000000000000000000000000
The second special sequence is the sequence counting the number of profiles where the men's tastes really differ and there are 0 soulmates. In this case, the formula is
\[L_n \cdot (n-1)^n \cdot ((n-1)!)^n.\]
The sequence which counts the number of profiles where the men's tastes really differ, with 0 soulmate pairs, is now sequence \seqnum{A344663}:
\[0, 2, 768, 60466176, 1315033086689280, 37924385587200000000000000,\ \ldots.\]
%0, 2, 768, 60466176, 1315033086689280, 37924385587200000000000000, 1726298879786383239996474654720000000000, 261072919520121696668385285116754694244904468480000000000, 208836950100011929062766575947297434628338701720339215752571230617600000000000, 1378135848291144955393621267341374054991268978878673434553714544944450408726397427961036800000000000000, 111633834757949683041111820723598575069719104430085053814326054761435295849812440161763668787200000000000000000000000000000000000000
Now we look at the case when both men's and women's preference profiles form Latin squares and where there are $k$ pairs of soulmates.
\begin{theorem}
The number of preference profiles in a stable matching problem with $n$ men and $n$ women where there are exactly $k$ pairs of soulmates, and both the men's and women's preference profiles form Latin squares is
\[\frac{L_n^2}{n!} \cdot \binom{n}{k} \cdot \left( \sum_{i=0}^{n-k} (-1)^i \frac{(n-k)!}{i!} \right).\]
\end{theorem}
\begin{proof}
We have $L_n$ ways to choose men's preference profiles. Now, we calculate the number of ways for women to pick their first choices.
We have $\binom{n}{k}$ ways to pick which women will be married in pairs of soulmates. After that, we need to ensure that there are no other soulmate pairs. Among the $n-k$ women without soulmates, the people that they rank first will be some permutation of the $n-k$ men that are not soulmates. This is because in a Latin preference profile, all of the people who are ranked first must be different, and all of the men in a soulmate pair have already been ranked first by someone, so they cannot be ranked first again. We need these $n-k$ men and women to not have any pairs of soulmates, so we need our permutation to be a derangement. We denote the number of derangements of size $i$ as $D_i$.
This gives us that there are $\binom{n}{k} \cdot D_{n-k}$ possible ways to pick the women's first choices. The women's preference profiles can then be completed in $\frac{L_n}{n!}$ ways. Therefore, we have $\frac{L_n}{n!} \cdot \binom{n}{k} \cdot D_{n-k}$ preference profiles for women, which gives us a total of
\[\frac{L_n^2}{n!} \cdot \binom{n}{k} \cdot D_{n-k} = \frac{L_n^2}{n!} \cdot \binom{n}{k} \cdot \left( \sum_{i=0}^{n-k} (-1)^i \frac{(n-k)!}{i!} \right)\]
preference profiles with $k$ soulmates.
\end{proof}
We summarize the results for small values of $n$ in Table~\ref{table:mwtrd}. The columns correspond to different $n$ and rows to different $k$.
\begin{table}[ht!]
\begin{center}
\begin{tabular}{|c|c|c|c|c|c|}
\hline
&1&2&3&4&5\\
\hline
0&0&2&48&124416&9537454080\\
\hline
1&1&0&72&110592&9754214400\\
\hline
2&*&2&0&82944&4335206400\\
\hline
3&*&*&24&0&2167603200\\
\hline
4&*&*&*&13824&0\\
\hline
5&*&*&*&*&216760320\\
\hline
Total&1&4&144&331776&26011238400\\
\hline
\end{tabular}
\end{center}
\caption{Distribution of the number of soulmates when men's and women's tastes really differ.}
\label{table:mwtrd}
\end{table}
Notice the zeroes on the diagonal. When men's and women's preferences form Latin squares, every man and woman must be ranked first exactly once; thus, there cannot be exactly $n – 1$ pairs of soulmates. This is also reflected in the formula since if we want to have $n-1$ pairs of soulmates, we would be multiplying by the number of derangements of size 1, which is 0.
As expected, the total in each column is sequence \seqnum{A343697}. But we also have two more sequences of note. The first sequence is the number of preference profiles when men's and women's tastes really differ, and there are $n$ pairs of soulmates. It corresponds to the case $k=n$, and the formula simplifies to
\[\frac{L_n^2}{n!}.\]
This is the number of Latin squares multiplied by the number of Latin squares up to relabeling the digits. The sequence counting the number of preference profiles where both men's and women's preferences form Latin squares and there are $n$ pairs of soulmates is now sequence \seqnum{A344664}, and it starts as follows:
\[1,\ 2,\ 24,\ 13824,\ 216760320,\ 917676490752000,\ 749944260264355430400000,\ \ldots.\]
% 1, 2, 24, 13824, 216760320, 917676490752000, 749944260264355430400000, 293457967200879687743551498616832000, 84112872283641495670736269523436185936222748672000, 27460610008848610956892895086773773421767179663217968124264448000000, 15123393270772464396002563799278912390053645826960296649482922447620253611668275200000000
Additionally, in the case with no pairs of soulmates, the formula simplifies to
\[\frac{L_n^2}{n!} \cdot \left( \sum_{i=0}^n (-1)^i \frac{n!}{i!} \right).\]
The sequence counting the number of preference profiles where both men's and women's preferences form Latin squares and there are no soulmates is now \seqnum{A344665}, and it starts as follows:
\[0,\ 2,\ 48,\ 124416,\ 9537454080,\ 243184270049280000,\ \ldots.\]
%0, 2, 48, 124416, 9537454080, 243184270049280000, 1390396658530114967961600000, 4352862027490648408300099378983469056000, 11228731998377005106060609036300637077741992056717312000, 36658843398022550531624696117934603340895735930389121945136191766528000000, 222080527122187207495607368289977138515610065901206363370097438486650947578295603953664000000000
\section{Distribution for the number of stable matchings}\label{sec:distSM}
Given a preference profile, we can calculate the total number of stable matchings.
\begin{example}
For $n = 2$, the following preference profile has two possible matchings, both of which are stable: First man: [1, 2], second man: [2, 1], first woman: [2, 1], second woman: [1, 2].
\end{example}
We wrote a program to calculate the number of stable matchings for every profile for $n \leq 4$. The results are summarized in Table~\ref{table:distribution}, where the columns correspond to different $n$. Row $k$ shows how many different profiles have exactly $k$ stable matchings. For example, there are 144 profiles for $n=4$ that result in 10 distinct stable matchings.
\begin{table}[ht]
\centering
\begin{tabular}{|c|c|c|c|c|}
\hline
& 1 & 2 & 3 & 4 \\
\hline
1 & 1 & 14 & 34080 & 65867261184 \\
\hline
2 & 0 & 2 & 11484 & 35927285472 \\
\hline
3 & 0 & 0 & 1092 & 7303612896 \\
\hline
4 & 0 & 0 & 0 & 861578352\\
\hline
5 & 0 & 0 & 0 &111479616 \\
\hline
6 & 0 & 0 & 0 & 3478608 \\
\hline
7 & 0 & 0 & 0 &581472 \\
\hline
8 & 0 & 0 & 0 & 36432 \\
\hline
9 &0 & 0 & 0 & 0 \\
\hline
10 &0 & 0 & 0 & 144 \\
\hline
Total & 1 & 16 & 46656 & 110075314176 \\
\hline
\end{tabular}
\caption{Distribution for the number of stable matchings.}
\label{table:distribution}
\end{table}
We submitted four sequences to the OEIS related to this table.
The first sequence is the number of preference profiles for 3 men and 3 women that generate $n$ possible stable matchings, which is now sequence \seqnum{A344666}. It is a finite sequence of three terms:
\[34080,\ 11484,\ 1092.\]
The second sequence, now \seqnum{A344667}, is the number of preference profiles for 4 men and 4 women that generate $n$ possible stable matchings. It is a finite sequence with 10 terms:
\[65867261184,\ 35927285472,\ 7303612896,\ 861578352,\ 111479616,\ 3478608,\ 581472,\ 36432, 0,\ 144.\]
We also submitted two infinite sequences. The first sequence, now sequence \seqnum{A344668}, corresponds to the first row. It is the number of profiles for $n$ men and $n$ women that result in one stable matching:
\[1,\ 14,\ 34080,\ 65867261184,\ \ldots.\]
The second sequence, now sequence \seqnum{A344669}, is the number of profiles for $n$ men and $n$ women that result in the maximum number of stable matchings. It is the last non-zero term in each column:
\[1,\ 2,\ 1092,\ 144,\ \ldots.\]
\subsection{Soulmates}
Suppose we have a pair of soulmates. Since they have to be married to each other, we can remove them from consideration and look at the other couples. It follows that the maximum number of stable matchings when there is exactly one pair of soulmates is $M(n-1)$. Similarly, if there are $k$ pairs of soulmates, the maximum possible number of stable matchings is $M(n-k)$.
\begin{example}
We know that for $n=2$, the maximum possible number of stable matchings is 2. This means for $n=3$, the maximum number of stable matchings with at least one couple of soulmates is also 2.
\end{example}
Table~\ref{table:SMVersusGoodness} shows the number of profiles for a given $n$ where there is a soulmate pair and a given number of stable matchings. The leftmost column represents the number of stable matchings, while the top row is $n$.
\begin{table}[ht]
\centering
\begin{tabular}{|c|c|c|c|}
\hline
& 1 & 2 & 3 \\
\hline
1 & 1 & 14 & 30840\\
\hline
2 & 0 & 0 & 5832\\
\hline
Total & 1 & 14 & 36672 \\
\hline
\end{tabular}
\caption{Distribution for the number of stable matchings with at least one pair of soulmates.}
\label{table:SMVersusGoodness}
\end{table}
\section{Special Cases}\label{sec:special}
\subsection{A hell-pair and a hell-couple}
Suppose we have two people that rank each other as $n$. We call such a pair a \textit{hell-pair}, and if they end up getting married, we call them a \textit{hell-couple}. Such a pair has an egalitarian cost of $2n$. Additionally, replacing ranking $i$ with $n+1-i$ is a bijection that swaps soulmates with hell-pairs. Thus, the sequence counting the number of profiles with $k$ hell-pairs is the same as the corresponding sequence with $k$ pairs of soulmates.
Is it possible to have a hell-couple in a stable matching? Yes, it is. For example, two people who are ranked last by everyone else have to be together no matter what mutual ranking they have. This means any mutual ranking of two people in a married couple is possible.
\begin{proposition}
In a stable matching, having more than one hell-couple is impossible.
\end{proposition}
\begin{proof}
Suppose we have two hell-couples $(m_1,w_1)$ and $(m_2,w_2)$. Then $(m_1,w_2)$ and $(m_2,w_1)$ are rogue couples, making the matching unstable.
\end{proof}
Suppose there is a hell-couple in a stable matching. A person in this hell situation is ready to run away with anyone who agrees. This means that in a stable matching, every other person values the member of the hell-couple of the opposite gender less than their partner. In particular, no one can rank a member of a hell-couple first.
\begin{proposition}\label{prop:hellcouple}
If a preference profile has a stable matching with a hell-couple, all possible stable matchings have that hell-couple.
\end{proposition}
\begin{proof}
We have a preference profile with a stable matching in which two people, man $m_1$ and woman $w_1$, form a hell-couple. We know that the men-proposing Gale-Shapley algorithm is woman-pessimal, meaning that women are always matched with the man they prefer least out of all their valid partners. This means that if we were to apply the men-proposing Gale-Shapley algorithm to this preference profile, we must have $w_1$ matched with $m_1$ since $w_1$ prefers $m_1$ least, and we are given that they are valid partners. Additionally, the men-proposing Gale-Shapley algorithm is man-optimal, meaning that men are always matched with the person they prefer most out of their valid partners. This means $w_1$ is the only valid partner for $m_1$. Similarly, $m_1$ is the only valid partner for $w_1$. Thus, they form a couple in any stable matching.
\end{proof}
It follows that if any of a profile's stable matching has a hell-couple, the possible number of matchings for such a profile does not exceed $M(n-1)$.
Consider the sequence describing the number of profiles such that there exists a stable matching with a hell-couple. We calculated this sequence, which is now sequence \seqnum{A344670}, by a program, and it starts as follows:
\[1,\ 4,\ 4536,\ 5113774080,\ \ldots.\]
Consider pairs containing a preference profile and one of its stable matchings. We calculated the sequence of the number of these pairs that generate a hell-couple. That is, each profile that generates a hell-couple in a matching was counted with multiplicity equaling the number of matchings that generate this hell-couple. As per Proposition~\ref{prop:hellcouple}, the multiplicity is the number of possible stable matchings for this profile.
The sequence, which is now sequence \seqnum{A344671}, starts as follows:
\[1,\ 4,\ 4608,\ 5317484544,\ \ldots.\]
\subsection{Outcasts}
It might be that the opposite notion to soulmates is not a hell-pair but rather the outcasts. We call two people the \textit{outcasts} if they are ranked $n$ by every person of the opposite gender who is not in this pair. In a stable matching, two outcasts have to be paired with each other. This is independent of their mutual rankings, so they might be soulmates, or a hell-couple, or anything in between.
We can have at most one pair of outcasts (unless $n = 2$) since everyone except the two outcasts ranks them last. We want to calculate the number of profiles with at least one pair of outcasts.
\begin{proposition}
The number of preference profiles with $n$ men and $n$ women such that there exists at least one pair of outcasts is
\[n^4 \cdot ((n-1)!)^{2n} \textrm{ for } n \neq 2, \textrm{ and } 14 \textrm{ for } n = 2.\]
\end{proposition}
\begin{proof}
The statement is true for $n=1$. Suppose $n>2$. Then we have $\binom{n}{1}^2 = n^2$ ways to pick the two outcasts, then $(n!)^2$ ways to complete the outcasts' preference profiles, and finally $((n-1)!)^{2n-2}$ ways to complete everyone else's profile. Therefore, we have
\[n^2 \cdot (n!)^2 \cdot ((n-1)!)^{2n-2} = n^4 \cdot ((n-1)!)^{2n}\]
ways to have a pair of outcasts for $n>2$.
However, when $n = 2$, the above formula double-counts the cases with two outcast pairs. We can pick the two pairs in $2! = 2$ ways, and from there, we only have 1 way to complete the preference profile, so there are 2 preference profiles that have two pairs of outcasts. Subtracting these from the previous number to avoid double-counting, we get that there are $14$ preference profiles with at least one pair of outcasts for $n=2$.
The formula for the number of outcasts is
\[n^4 \cdot ((n-1)!)^{2n} \textrm{ for } n \neq 2, \textrm{ and } 14 \textrm{ for } n = 2.\]
\end{proof}
The first few terms of this sequence counting the number of preference profiles that have outcasts, which is now sequence \seqnum{A344689}, are as follows:
\[1,\ 14,\ 5184,\ 429981696,\ 39627113103360000,\ \ldots.\]
%Table[n^4 (n-1)!^(2n), {n,2,10}]
%1, 14, 5184, 429981696, 39627113103360000, 11555266180939776000000000000, 24157228657754148059243505254400000000000000, 709983949983801273585561911705687568775548764160000000000000000, 520402602329775972199889472492375107519949414596673059590723457777664000000000000000000, 15676916946577623008138281332466837061674601628322948212615939666703122110003831808957874176000000000000000000000000
\subsection{Outcast-hell pair}
In order for us to have an outcast-hell pair, we need to pick two people and have everyone rank them last. Note that this means there can only be one outcast-hell pair. Moreover, in such a scenario, we can have at most one hell-pair, and the people in it must be outcasts. We can pick two people to be outcasts in $\binom{n}{1}^2 = n^2$ ways, and since everyone ranks them last, we can complete everyone's preference profiles in $((n-1)!)^{2n}$ ways, so for any $n$, we have $n^2 \cdot ((n-1)!)^{2n}$ preference profiles with an outcast-hell pair. Notice that, by symmetry, this is the same as the number of profiles with a pair of people such that everyone ranks them first. This is sequence \seqnum{A343474}:
\[1,\ 4,\ 576,\ 26873856,\ 1585084524134400,\ \ldots.\]
Except for the second term, the number of outcast profiles equals $n^2$ times the number of outcast-hell pair profiles. This makes sense, as the only difference is that the members of the outcast pair can rank each other any way they want.
\section{Symmetries}\label{sec:symmetries}
We can relabel men, relabel women, and swap men with women without changing the number or type of matchings.
We can relabel men in $n!$ ways. This is equivalent to fixing the first woman's preferences to be 1, 2, 3, $\ldots$, $n$. Because of this symmetry, the total number of profiles has to be divisible by $n!$.
In addition, we can relabel the women, excluding the first, in the order of the preferences of the first man. This effectively means we can shuffle the men and all the women but the first. Therefore, profiles come in groups of $n!(n-1)!$ profiles, which result in the same matchings but use different orderings of men and women.
\subsection{Distinct men's profiles up to relabeling}
We calculate the number of different men's profiles up to relabeling men for small values of $n$.
Suppose $n = 1$. Then, there is only one woman and only one man, so there can only be one possible set of preference profiles.
Suppose $n = 2$. If both men prefer the same woman, this woman can be either woman 1 or 2. If they prefer different women, we can shuffle them so that the first man prefers woman 1. So, there are 3 distinct men's profiles in total.
We now present a general formula. There are $n!$ possible profiles and $n$ men, so we are choosing $n$ preference profiles from a list of size $n!$, with repeats allowed, and the order in which the elements are chosen does not matter. Therefore, the total number of ways to do so is
\[\binom{n!+n-1}{n} .\]
The sequence of the number of different men's profiles up to relabeling men is now sequence \seqnum{A344690}, which starts as follows:
\[1,\ 3,\ 56,\ 17550,\ 225150024,\ 197554684517400,\ 16458566311785642529680, \ldots.\]
%Table[Binomial[Factorial[n] + n - 1, n], {n, 10}]
%1, 3, 56, 17550, 225150024, 197554684517400, 16458566311785642529680, 173358539198065045263504881415600, 300709637734376436340098187751948137677075840, 109112041481912234203213339867180762753584908387010487351680, 10269700511764816245466184298959025497491140714627207124564297126391231020800, 304583704689239931535141349877567258840627774290030515060878900976296940869975234642182384620800, 3399098908905414242534564563432259806020481720167335609869030220925302365375205618767107714412348142753805610684185600
We can think of this sequence as the number of $n$-multisets chosen from the set of all permutations of $n$ elements.
\section{The egalitarian cost distribution for small values of $n$}\label{sec:ec}
The egalitarian cost depends on a matching. Given a preference profile, having different stable matchings with different egalitarian costs is possible. Interestingly, if $n=2$ or 3, and there are several stable matchings, the egalitarian cost is the same for all these matchings. This does not hold true for larger $n$.
Suppose $n=2$. If there is one stable matching, there are 2 profiles with an egalitarian cost of 4, 8 profiles with an egalitarian cost of 5, and 4 profiles with an egalitarian cost of 6. If there are two stable matchings, there are two profiles with an egalitarian cost of 6. Thus, we have two sequences. The number of profiles such that the matching has an egalitarian cost $g$: 2, 8, 6. The number of possible matchings for different profiles such that the egalitarian cost is $g$: 2, 8, 8.
Suppose $n = 3$. We know that 34080 profiles have one stable matching, 11484 profiles have two matchings, and 1092 profiles have 3 matchings.
Possible egalitarian costs range from 6 to 12, inclusive. If the profile has a matching with an egalitarian cost of 6, then this matching is unique, and all the couples are soulmates. We already calculated the number of such profiles as 384. If the egalitarian cost is 7 for one of the matchings, then the matching is unique too with two soulmate couples.
We cannot have a total egalitarian cost of 18. If there was a matching of egalitarian cost 18, all couples would have to be hell-couples. In this case, any pair of people not in a couple form a rogue pair, making the matching unstable.
When a profile has multiple matchings, the matchings may have different total egalitarian costs, as seen in the following example.
\begin{example}
Consider a profile where the following matrices describe women's and men's preferences, respectively:
\[
\begin{pmatrix}
3 & 1 & 2 \\
1 & 2 & 3 \\
1 & 2 & 3
\end{pmatrix}
\quad
\begin{pmatrix}
1 & 2 & 3 \\
2 & 3 & 1 \\
3 & 2 & 1
\end{pmatrix}.
\]
The men-proposing Gale-Shapley algorithm ends with a total egalitarian cost of 12. The couples are man 1 and woman 1, man 2 and woman 3, and man 3 and woman 2. The women-proposing algorithm ends with a total egalitarian cost of 11. The couples are the following: woman 1 and man 3, woman 2 and man 1, and woman 3 and man 2.
\end{example}
Using a program, we calculated the number of preference profiles in the stable marriage problem with 3 men and 3 women such that a stable matching with egalitarian cost $n$ exists. The egalitarian cost for stable matchings ranges from 6 to 12 inclusive:
\[384,\ 2304,\ 7416,\ 13860,\ 15912,\ 10836,\ 3564.\]
We did a similar calculation for $n=4$, where the egalitarian cost ranges from 8 to 20: 40310784, 322486272, 1394454528, 4263542784, 9856161792, 17805053952, 25557163776, 29223099648, 26437927680, 18541903680, 9633334320, 3379380192, 626260608.
We combined all these numbers into one sequence \seqnum{A344691}: an irregular table, where $T(n,k)$ is the number of preference profiles in the stable marriage problem with $n$ men and $n$ women such that there exists a stable matching with an egalitarian cost of $k$.
One might notice that the sum of $T(3,k)$ over different $k$ is 54276, larger than the total number of preference profiles, which is 46656. This result implies that there exist profiles generating matchings with different egalitarian costs. This sum is also different from the total number of matchings with different profiles: Since 34080 profiles have one stable matching, 11484 profiles have two matchings, and 1092 profiles have 3 matchings, the total number of matchings with different profiles is
\[1 \cdot 34080 + 2 \cdot 11484 + 3 \cdot 1092 = 60324.\]
This suggests another sequence, which counts different matchings with a given egalitarian cost rather than different profiles. In other words, for a given egalitarian cost and profile that can generate a matching with this egalitarian cost, we count this profile with the weight equaling the number of different matchings with the given egalitarian cost.
The irregular table $T'(n,k)$ is combined in sequence \seqnum{A344692}: the number of different stable matchings for different profiles for $n$ men and $n$ women with an egalitarian cost of $k$. For $n=3$ and egalitarian costs ranging from 6 to 12, we get the following numbers:
\[384,\ 2304,\ 7488,\ 14592,\ 18072,\ 13104,\ 4380.\]
The total, as expected, equals 60324. For $n=4$ the egalitarian cost ranges from 12 to 20 and the values of $T'(n,k)$ are as follows: 40310784, 322486272, 1397440512, 4299816960, 10080681984, 18632540160, 27586068480, 32664453120, 30544625664, 21941452800, 11480334336, 3963617280, 707788800.
It is not surprising that
\[T(n,2n) = T'(n,2n) \quad \textrm{ and } \quad T(n,2n+1) = T'(n,2n+1) .\]
If the egalitarian cost is $2n$ or $2n+1$, there are $n$ or $n-1$ pairs of soulmates, respectively. In both cases, there is only one stable matching per profile.
\section{Acknowledgments}
This project was done as part of MIT PRIMES STEP, a program that allows students in grades 6 through 9 to try research in mathematics. Tanya Khovanova is the mentor of this project. We are grateful to PRIMES STEP for this opportunity. We are grateful to Dan Eilers for pointing out that one of our references to sequences was to a wrong sequence and for providing the correct link.
\begin{thebibliography}{9}
\bibitem{STEPSudoku} M.~Borodin, E.~Chen, A.~Duncan, T.~Khovanova, B.~Litchev, J.~Liu, V.~Moroz, M.~Qian, R.~Raghavan, G.~Rastogi, and M.~Voigt,
The stable matching problem and Sudoku, Arxiv preprint
arXiv:2108.02654 [math.HO]. Available at
\url{https://arxiv.org/abs/2108.02654}, 2021.
\bibitem{GS1962} D.~Gale and L.~S.~Shapley, College admissions and the stability of marriage, \textit{Amer.~Math.~Monthly}, \textbf{69} (1962), 9--15.
\bibitem{GI1989} D.~Gusfield and R.~W.~Irving, \textit{The Stable Marriage
Problem: Structure and Algorithms}, MIT Press, 1989.
\bibitem{OEIS} N. J. A. Sloane et al., The On-Line Encyclopedia of Integer Sequences, published electronically at \url{https://oeis.org}, 2023.
\bibitem{T2002} E.~G.~Thurber, Concerning the maximum number of stable matchings in the stable marriage problem, \textit{Discrete Math.} \textbf{248} (2002) 195--219.
\end{thebibliography}
\bigskip
\hrule
\bigskip
\noindent 2020 {\it Mathematics Subject Classification}:
Primary 05A99.
\noindent \emph{Keywords: } stable matching problem, Gale-Shapley algorithm, preference profile.
\bigskip
\hrule
\bigskip
\noindent (Concerned with sequences
\seqnum{A000142},
\seqnum{A001044},
\seqnum{A002860},
\seqnum{A091868},
\seqnum{A185141},
\seqnum{A338665},
\seqnum{A340890},
\seqnum{A342573},
\seqnum{A343474},
\seqnum{A343475},
\seqnum{A343692},
\seqnum{A343693},
\seqnum{A343694},
\seqnum{A343695},
\seqnum{A343696},
\seqnum{A343697},
\seqnum{A343698},
\seqnum{A343699},
\seqnum{A343700},
\seqnum{A344662},
\seqnum{A344663},
\seqnum{A344664},
\seqnum{A344665},
\seqnum{A344666},
\seqnum{A344667},
\seqnum{A344668},
\seqnum{A344669},
\seqnum{A344670},
\seqnum{A344671},
\seqnum{A344689},
\seqnum{A344690},
\seqnum{A344691},
\seqnum{A344692},
\seqnum{A344693},
\seqnum{A345679}, and
\seqnum{A351413}.)
\bigskip
\hrule
\bigskip
\vspace*{+.1in}
\noindent
Received January 10 2022;
revised versions received September 22 2023; October 29 2023; January 15 2024.
Published in {\it Journal of Integer Sequences}, January 16 2024.
\bigskip
\hrule
\bigskip
\noindent
Return to
\htmladdnormallink{Journal of Integer Sequences home page}{https://cs.uwaterloo.ca/journals/JIS/}.
\vskip .1in
\end{document}