% Template based on:
% https://www.cs.columbia.edu/~djhsu/coms4774-s21/scribe.html

\documentclass[12pt]{article}

\usepackage{amscd}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amstext}
\usepackage{amsthm}
\usepackage{bbold}
\usepackage{bm}
\usepackage{colonequals}
\usepackage[dvips,letterpaper,margin=1in]{geometry}
\usepackage{mathtools}
\usepackage{graphicx}
\usepackage{xcolor}

\usepackage{csquotes}
\MakeOuterQuote{"}

\definecolor{cblack}{rgb}{0,0,0}
\definecolor{cblue}{rgb}{0.121569,0.466667,0.705882}
\definecolor{corange}{rgb}{1.000000,0.498039,0.054902}
\definecolor{cgreen}{rgb}{0.172549,0.627451,0.172549}
\definecolor{cred}{rgb}{0.839216,0.152941,0.156863}
\definecolor{cpurple}{rgb}{0.580392,0.403922,0.741176}
\definecolor{cbrown}{rgb}{0.549020,0.337255,0.294118}
\definecolor{cpink}{rgb}{0.890196,0.466667,0.760784}
\definecolor{cgray}{rgb}{0.498039,0.498039,0.498039}

\usepackage{hyperref}
\hypersetup{
  linkcolor  = cblue,
  citecolor  = cgreen,
  urlcolor   = corange,
  colorlinks = true,
}

% Lecture information
\newcommand\coursename{CPSC 664, Spring 2023}
\newcommand\scribe{Tim Kunisky}
\newcommand\lecturer{Tim Kunisky}
\newcommand\lecturedate{January 19, 2023}
\newcommand\lecturetitle{Lecture 2: Integer partitioning II}

% Define theorem environments here.
\newtheorem{claim}{Claim}
\newtheorem{theorem}{Theorem}[section]
\newtheorem{remark}[theorem]{Remark}
\newtheorem{assumption}[theorem]{Assumption}
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem{question}[theorem]{Question}
\newtheorem{problem}[theorem]{Problem}
\newtheorem{definition}[theorem]{Definition}
\newtheorem{example}[theorem]{Example}
\newtheorem{proposition}[theorem]{Proposition}
\newtheorem{corollary}[theorem]{Corollary}
\newtheorem{conjecture}[theorem]{Conjecture}

% Some of my macros
\renewcommand{\AA}{\mathbb{A}}
\newcommand{\CC}{\mathbb{C}}
\newcommand{\DD}{\mathbb{D}}
\newcommand{\EE}{\mathbb{E}}
\newcommand{\FF}{\mathbb{F}}
\newcommand{\HH}{\mathbb{H}}
\newcommand{\NN}{\mathbb{N}}
\newcommand{\PP}{\mathbb{P}}
\newcommand{\QQ}{\mathbb{Q}}
\newcommand{\RR}{\mathbb{R}}
\renewcommand{\SS}{\mathbb{S}}
\newcommand{\ZZ}{\mathbb{Z}}
\DeclareSymbolFont{bbold}{U}{bbold}{m}{n}
\DeclareSymbolFontAlphabet{\mathbbold}{bbold}
\newcommand{\One}{\mathbbold{1}}

\newcommand{\ba}{\bm a}
\newcommand{\bb}{\bm b}
\newcommand{\bc}{\bm c}
\newcommand{\bd}{\bm d}
\newcommand{\be}{\bm e}
\newcommand{\bg}{\bm g}
\newcommand{\bh}{\bm h}
\newcommand{\bi}{\bm i}
\newcommand{\bj}{\bm j}
\newcommand{\bk}{\bm k}
\newcommand{\bbm}{\bm m}
\newcommand{\bp}{\bm p}
\newcommand{\bq}{\bm q}
\newcommand{\br}{\bm r}
\newcommand{\bs}{\bm s}
\newcommand{\bt}{\bm t}
\newcommand{\bu}{\bm u}
\newcommand{\bv}{\bm v}
\newcommand{\bw}{\bm w}
\newcommand{\bx}{\bm x}
\newcommand{\by}{\bm y}
\newcommand{\bz}{\bm z}

\newcommand{\bA}{\bm A}
\newcommand{\bB}{\bm B}
\newcommand{\bC}{\bm C}
\newcommand{\bD}{\bm D}
\newcommand{\bE}{\bm E}
\newcommand{\bF}{\bm F}
\newcommand{\bG}{\bm G}
\newcommand{\bH}{\bm H}
\newcommand{\bI}{\bm I}
\newcommand{\bL}{\bm L}
\newcommand{\bM}{\bm M}
\newcommand{\bN}{\bm N}
\newcommand{\bP}{\bm P}
\newcommand{\bQ}{\bm Q}
\newcommand{\bR}{\bm R}
\newcommand{\bS}{\bm S}
\newcommand{\bT}{\bm T}
\newcommand{\bU}{\bm U}
\newcommand{\bV}{\bm V}
\newcommand{\bW}{\bm W}
\newcommand{\bX}{\bm X}
\newcommand{\bY}{\bm Y}
\newcommand{\bZ}{\bm Z}

\newcommand{\zero}{\bm{0}}
\newcommand{\one}{\bm{1}}

\newcommand{\sA}{\mathcal{A}}
\newcommand{\sB}{\mathcal{B}}
\newcommand{\sC}{\mathcal{C}}
\newcommand{\sD}{\mathcal{D}}
\newcommand{\sE}{\mathcal{E}}
\newcommand{\sF}{\mathcal{F}}
\newcommand{\sG}{\mathcal{G}}
\newcommand{\sH}{\mathcal{H}}
\newcommand{\sI}{\mathcal{I}}
\newcommand{\sJ}{\mathcal{J}}
\newcommand{\sK}{\mathcal{K}}
\newcommand{\sL}{\mathcal{L}}
\newcommand{\sM}{\mathcal{M}}
\newcommand{\sN}{\mathcal{N}}
\newcommand{\sO}{\mathcal{O}}
\newcommand{\sP}{\mathcal{P}}
\newcommand{\sQ}{\mathcal{Q}}
\newcommand{\sR}{\mathcal{R}}
\newcommand{\sS}{\mathcal{S}}
\newcommand{\sT}{\mathcal{T}}
\newcommand{\sU}{\mathcal{U}}
\newcommand{\sV}{\mathcal{V}}
\newcommand{\sX}{\mathcal{X}}
\newcommand{\sY}{\mathcal{Y}}

\newcommand{\fB}{\mathscr{B}}
\newcommand{\fC}{\mathscr{C}}
\newcommand{\fE}{\mathscr{E}}
\newcommand{\fH}{\mathscr{H}}
\newcommand{\fI}{\mathscr{I}}
\newcommand{\fP}{\mathscr{P}}
\newcommand{\fV}{\mathscr{V}}

\DeclareSymbolFont{sfoperators}{OT1}{cmss}{m}{n}
% don't waste a math group
\DeclareSymbolFontAlphabet{\mathsf}{sfoperators}
% tell LaTeX to use sfoperators for names of operators
\makeatletter
\renewcommand{\operator@font}{\mathgroup\symsfoperators}
\makeatother

\DeclareMathOperator*{\argmax}{arg\,max}
\DeclareMathOperator*{\argmin}{arg\,min}
\DeclareMathOperator{\GOE}{GOE}
\DeclareMathOperator{\sym}{sym}
\DeclareMathOperator{\Part}{Part}
\DeclareMathOperator{\poly}{poly}
\DeclareMathOperator{\Unif}{Unif}
\DeclareMathOperator{\Var}{Var}
\DeclareMathOperator{\Cov}{Cov}
\DeclareMathOperator{\Tr}{Tr}
\DeclareMathOperator{\rank}{rank}
\DeclareMathOperator{\obj}{obj}
\DeclareMathOperator{\diag}{diag}
\DeclareMathOperator{\sgn}{sgn}

\renewcommand\Re{\operatorname{Re}}
\renewcommand\Im{\operatorname{Im}}
% These put symbols below.
\newcommand{\Px}{\mathop{\mathbb{P}}}
\newcommand{\Ex}{\mathop{\mathbb{E}}}
\newcommand{\Varx}{\mathop{\mathsf{Var}}}

\newcommand\numberthis{\addtocounter{equation}{1}\tag{\theequation}}

%
% Put your custom macros here if you want.
%

\begin{filecontents}{2023-01-19.bib}
@book{MM-2011-NatureOfComputation,
  title={The nature of computation},
  author={Moore, Cristopher and Mertens, Stephan},
  year={2011},
  publisher={OUP Oxford}
}
\end{filecontents}

\newcommand{\Mod}[1]{\ (\mathrm{mod}\ #1)}

\begin{document}

% This creates the header for scribe notes.
\noindent \coursename \hfill Scribe: \scribe \\
\lecturedate \hfill Lecturer: \lecturer
\vspace{1em}

\hrule

\vspace{1.5em}
\begin{center}
  {\Large\lecturetitle}
\end{center}

\section{First moment method by integration}

Recall that we left off planning to compute the expectation of the random variable
\begin{equation}
    Z \colonequals \#\bigg\{ \bx \in \{\pm 1\}^n: \langle \bx, \ba \rangle = 0 \bigg\}.
\end{equation}
Normally what we would do, and what we will do later for other problems, is to expand $Z$ into a sum of indicators like in the last lecture and compute from there.
But, in the special case of integer partitioning, it turns out that it is possible to get much more precise information using the following beautiful trick.

Define the function
\begin{equation}
    F(t) \colonequals \prod_{j = 1}^n (e^{ia_j t} + e^{-ia_j t}).
\end{equation}
This is a random function, inheriting its randomness from the $a_j$.
Consider two manipulations of this function: on the one hand, by Euler's formula $e^{ix} = \cos x + i \sin x$,
\begin{equation}
    F(t) = 2^n \prod_{j = 1}^n \cos(a_j t),
\end{equation}
a real-valued function.
On the other hand, expanding the product,
\begin{equation}
    F(t) = \sum_{ \bx \in \{ \pm 1\}^n} \exp\left(it \sum_{j = 1}^n x_j a_j\right) = \sum_{d \in \ZZ} e^{idt} \#\bigg\{\bx \in \{\pm 1\}^n: \langle \bx, \ba \rangle = d\bigg\}.
\end{equation}

Thus, $F(t)$ is a kind of generating function of the numbers of $\bx$ achieving different values of the ``discrepancy'' or ``objective function'' $\langle \bx, \ba\rangle$.
We can extract these counts by using the \emph{Fourier transform}, which amounts to the following observation.
\begin{proposition}[Orthogonality of Fourier modes]
    For any $d \in \ZZ$,
    \begin{equation}
        \frac{1}{2\pi}\int_{-\pi}^{\pi} e^{idt}\, dt = \left\{\begin{array}{ll} 1 & \text{if } d = 0 \\ 0 & \text{if } d \neq 0 \end{array}\right\}.
    \end{equation}
\end{proposition}
\begin{proof}
    Use Euler's formula and calculate the integrals of sine and cosine directly.
\end{proof}

In particular, we may extract $Z$ from $F(t)$ by computing
\begin{equation}
    Z = \frac{1}{2\pi}\int_{-\pi}^{\pi}F(t)\, dt = \frac{2^n}{2\pi}\int_{-\pi}^{\pi} \, \prod_{j = 1}^n \cos(a_jt) \, dt.
\end{equation}
Taking the expectation, we may exchange the integral and expectation, and then use that the $a_j$ are i.i.d., to observe that
\begin{equation}
    \EE Z = \frac{2^n}{2\pi}\int_{-\pi}^{\pi} \, \prod_{j = 1}^n \EE \cos(a_jt) \, dt = \frac{2^n}{2\pi}\int_{-\pi}^{\pi} \, (\EE \cos(a_1t))^n \, dt.
\end{equation}
Let us define
\begin{align*}
  f(t)
  &\colonequals \EE \cos(a_1t) \\
  &= \frac{1}{B} \sum_{a = 0}^{B - 1} \cos(at) \\
  &= \frac{1}{2B} \sum_{a = 0}^{B - 1} (e^{iat} + e^{-iat})
    \intertext{and summing this as two geometric series, you may check that we arrive at}
  &= \frac{1}{2B}\left(1 + \frac{\sin((B - \frac{1}{2})t)}{\sin(\frac{1}{2}t)}\right). \numberthis
\end{align*}
You may check that, extending by continuity, $f(0) = 1$, and this is the maximum of $f(t)$ over $t \in [-\pi, \pi]$; see Figure~\ref{fig:f}.
\begin{figure}
    \label{fig:f}
    \begin{center}
        \includegraphics[scale=0.3]{B10.png}
    \end{center}
    \caption{A plot of $f(t)$ with $B = 10$.}
\end{figure}

\section{Laplace method}

The \emph{Laplace method} is a useful general analysis tool to understand integrals like this.
The idea is that, for large $n$, the dominant contribution to the integral will be from a small neighborhood around $t = 0$.
There, we can approximate $f$ by a Taylor series:
\begin{align}
  f(0) &= 1, \\
  f^{\prime}(0) &= 0,
                  \intertext{and you may check with a slightly more involved calculation that}
                  f^{\prime\prime}(0) &= -\frac{B^2}{3} + O(B).
\end{align}
Thus, near $t = 0$, we have
\begin{equation}
    f(t) \approx f(0) + f^{\prime}(0)t + \frac{f^{\prime\prime}(0)}{2} t^2 \approx 1 - \frac{B^2}{6}t^2.
\end{equation}

Now, starting with our intuition that we may restrict to a small neighborhood around $t = 0$, we approximate
\begin{align*}
  \int_{-\pi}^{\pi}f(t)^n \, dt
  &\approx \int_{-\epsilon}^{\epsilon} f(t)^n \, dt \\
  &\approx \int_{-\epsilon}^{\epsilon} \left(1 - \frac{B^2}{6}t^2\right)^n \, dt \\
  &\approx \int_{-\epsilon}^{\epsilon} \exp\left(-\frac{B^2n}{6}t^2\right) \, dt
    \intertext{Let us view this as a Gaussian integral with ``effective variance'' $\sigma^2 \colonequals 3 / B^2 n \ll 1$. Then, we may rewrite and, since this variance is very small, expand the range of integration without affecting the value very much,}
  &= \int_{-\epsilon}^{\epsilon} \exp\left(-\frac{t^2}{2\sigma^2}\right) \, dt \\
  &\approx \int_{-\infty}^{\infty} \exp\left(-\frac{t^2}{2\sigma^2}\right) \, dt
    \intertext{which is the normalizing constant in the Gaussian distribution,}
  &= \sqrt{2\pi \sigma^2} \\
  &= \frac{\sqrt{6\pi}}{B \sqrt{n}}. \numberthis
\end{align*}
Substituting into the expression we wanted to calculate,
\begin{equation}
    \EE Z = \frac{2^n}{2\pi} \int_{-\pi}^{\pi} f(t)^n \, dt \approx \sqrt{\frac{3}{2\pi}} \cdot \frac{2^n}{B\sqrt{n}}.
\end{equation}
If we do these calculations more carefully keeping track of error terms, we arrive at the following.
\begin{theorem}
    For any $B, n$,
    \begin{equation}
        \EE Z = (1 + O(1 / B) + O(1 / n)) \cdot \sqrt{\frac{3}{2\pi}} \cdot \frac{2^n}{B\sqrt{n}},
    \end{equation}
    with the $O(\cdot)$ hiding absolute constants.
\end{theorem}
\noindent
See Appendix A.6 of \cite{MM-2011-NatureOfComputation} for many more details about how to perform such calculations carefully.

Consequently, we can verify one side of our prediction from last lecture.
\begin{corollary}
    \label{cor:unsat-threshold}
    Suppose that $B = B(n)$ is such that $B / (2^n / \sqrt{n}) = B / B^* \to \infty$.
    Then, with high probability, there exist no perfect partitions of $a_1, \dots, a_n$.
\end{corollary}

\section{Minimum discrepancy in the unsatisfiable regime}

Essentially the same calculation can also clarify some more details of how our problem behaves in the situation described by Corollary~\ref{cor:unsat-threshold}.
In that case, it is interesting to determine the scaling of the minimum achievable discrepancy, the value of the optimization problem
\begin{equation}
    \begin{array}{ll} \text{minimize} & \left|\sum_{j = 1}^n x_ja_j \right| \\
          \text{subject to} & \bx \in \{\pm 1\}^n. \end{array}
\end{equation}

To that end, we calculate expectations of
\begin{equation}
    Z_d \colonequals \#\bigg\{ \bx \in \{\pm 1\}^n: \langle \bx, \ba \rangle = d \bigg\}.
\end{equation}
By the same argument as for $Z = Z_0$,
\begin{equation}
    Z_d = \frac{1}{2\pi}\int_{-\pi}^{\pi}e^{-idt}F(t)\, dt = \frac{2^n}{2\pi}\int_{-\pi}^{\pi} \, \cos(dt) \prod_{j = 1}^n \cos(a_jt) \, dt,
\end{equation}
where we may take the real part since we know $Z_d$ is real, and taking expectations we find
\begin{equation}
    \EE Z_d = \frac{2^n}{2\pi} \int_{-\pi}^{\pi} \cos(dt) f(t)^n dt.
\end{equation}
Near $t = 0$, we have the Taylor approximation $\cos(dt) \approx 1 - \frac{d^2}{2}t^2$.
Since $f(t) \approx 1 - \frac{B^2}{6}t^2$, so long as $d \ll B$, we will have in the Laplace method calculation that $\cos(dt)$ is effectively equal to 1 in the interval $[-\epsilon, \epsilon]$ on which $f(t)^n$ is not negligibly small.
Making this reasoning precise, one may confirm that
\begin{theorem}
    For any $B, n, d$,
    \begin{equation}
        \EE Z_d = (1 + O(d / B) + O(1 / n)) \cdot \sqrt{\frac{3}{2\pi}} \cdot \frac{2^n}{B\sqrt{n}},
    \end{equation}
    with the $O(\cdot)$ hiding absolute constants.
\end{theorem}

What does this tell us about the minimum discrepancy?
We have, for $D \ll B$,
\begin{equation}
    \EE[\#\{\bx \in \{\pm 1\}^n: |\langle \bx, \ba \rangle| \leq D\}] = \EE \sum_{d = -D}^D Z_d \approx 2D \cdot \sqrt{\frac{3}{2\pi}} \cdot \frac{2^n}{B\sqrt{n}}.
\end{equation}
On the other hand, whenever $|\langle \bx, \ba \rangle| = d$ then $|\langle -\bx, \ba \rangle| = d$ as well, so we might intuit that the $D$ for which there typically exists a $\bx$ with $|\langle \bx, \ba \rangle| = D$ makes the above quantity equal to 2.\footnote{This is admittedly a flimsy heuristic argument, but surprisingly gives the right result!}
This gives
\begin{equation}
    D = \sqrt{\frac{2\pi}{3}} \frac{B\sqrt{n}}{2^n}.
\end{equation}
Thus we are led to the following conjecture.
\begin{conjecture}
    Suppose $B = B(n)$ is such that $B / (2^n / \sqrt{n}) = B / B^* \to \infty$.
    Then,
    \begin{equation}
        \left\{\begin{array}{ll} \text{minimize} & \left|\sum_{j = 1}^n x_ja_j \right| \\
          \text{subject to} & \bx \in \{\pm 1\}^n \end{array}\right\} = (1 + o(1)) \sqrt{\frac{2\pi}{3}} \frac{B\sqrt{n}}{2^n}.
    \end{equation}
\end{conjecture}
\noindent
Of course, it would also be reasonable to more conservatively conjecture the above without a specific constant, but we will see in the next lecture that this constant is correct and has an intuitive interpretation in terms of the ``random energy model.''

\section{Second moment method}

Let us now turn to trying to show the converse statement to Corollary~\ref{cor:unsat-threshold}, that if $B / B^* \to 0$ then with high probability there exist perfect partitions of $a_1, \dots, a_n$.

Actually, this attempt would be doomed to fail from the outset: what we wrote above simply is not true.
That is because we always have $\sum_{j = 1}^n x_ja_j \equiv \sum_{j = 1}^n a_j \Mod{2}$, and so a perfect partition can only exist if $\sum_{j = 1}^n a_j$ is even, which will only happen with probability about $\frac{1}{2}$.
We should revise our notion of ``perfect partition'' in light of this observation: in the notation of the previous section, what is reasonable to expect is that $Z_0 + Z_1 \geq 1$ with high probability (i.e., there exists a $\bx$ with $|\langle \bx, \ba \rangle| \in \{0, 1\}$), not $Z = Z_0 \geq 1$ with high probability.

However, let us proceed and see where our argument would break down even if we had not made this observation ``from outside'' of our moment calculations.
In either case, the main tool for proving this kind of result is the following.
\begin{proposition}[Basic second moment method]
    \label{prop:2mm}
    Suppose $Z \geq 0$ is a real-valued random variable.
    Then,
    \begin{equation}
        \PP[Z > 0] \geq \frac{(\EE Z)^2}{\EE Z^2} = 1 - \frac{\Var[Z]}{\EE Z^2}.
    \end{equation}
\end{proposition}
\begin{proof}
    Using the Cauchy-Schwarz inequality,
    \begin{equation}
        \EE Z = \EE Z\One\{Z > 0\} \leq \sqrt{(\EE Z^2) (\EE \One\{Z > 0\}^2)} = \sqrt{(\EE Z^2)(\PP[Z > 0])},
    \end{equation}
    and rearranging gives the result.
\end{proof}

To use this, our main task is to compute $\EE Z^2$.
Let us sketch how to do this; for further details you can see Section 14.5 of \cite{MM-2011-NatureOfComputation}.
Squaring our integral representation of $Z$ and rearranging,
\begin{equation}
    Z^2 = \left(\frac{2^n}{2\pi}\right)^2\int_{-\pi}^{\pi}\int_{-\pi}^{\pi} \prod_{j = 1}^n \cos(a_j s)\cos(a_j t) \, ds \, dt.
\end{equation}
Again by independence of the $a_j$, we have
\begin{equation}
    \EE Z^2 = \left(\frac{2^n}{2\pi}\right)^2\int_{-\pi}^{\pi}\int_{-\pi}^{\pi} (\underbrace{\EE \cos(a_1 s)\cos(a_1 t)}_{g(s, t)})^n  \, ds \, dt.
\end{equation}
Though it is a little more cumbersome, you can still write a closed formula for $g(s, t)$ and verify that its maximum is at $(s, t) = (0, 0)$, where $g(0, 0) = 1$.
We may then use a two-dimensional version of the Laplace method: we have $\nabla g(0, 0) = \bm 0$ since the origin is a maximum, and so the two dimensional Taylor expansion says that, near $(0, 0)$,
\begin{equation}
    g(s, t) \approx 1 + \left[\begin{array}{c} s \\ t \end{array}\right]^{\top} \nabla^2 g(0, 0) \left[\begin{array}{c} s \\ t \end{array}\right],
\end{equation}
where $\nabla^2 g(0, 0)$ is the Hessian matrix, which is negative-definite (again since the origin is a local maximum).
We may then go through the previous derivation again, now working with a two-dimensional Gaussian integral; we omit the details, but ultimately you will find
\begin{equation}
    \EE Z^2 = 2(1 + o(1))(\EE Z)^2.
\end{equation}
(Here, importantly, the $o(1)$ term only satisfies that asymptotic so long as $\EE Z \sim B^* / B \to \infty$; the actual bound we can obtain on it when doing the Laplace method carefully is $O(1 / \EE Z)$.)

It is here that we see the reflection of the parity issue mentioned above in our moment arguments: with this kind of asymptotic, the best that Proposition~\ref{prop:2mm} can tell us is
\begin{equation}
    \PP[Z > 0] \geq \frac{1}{2} + o(1),
\end{equation}
which is exactly what our parity reasoning told us to expect!
To repair the situation, one may do the same calculation with $Z_1$ as with $Z = Z_0$, and note that only one of $Z_0$ and $Z_1$ can be positive.
Combining these results, we would find the following.

\begin{theorem}
    \label{thm:sat-threshold}
    Suppose that $B = B(n)$ is such that $B / (2^n / \sqrt{n}) = B / B^* \to 0$.
    Then, with high probability, there exists $\bx \in \{\pm 1\}^n$ such that $\sum_{j = 1}^n x_ja_j \in \{0, 1\}$.
\end{theorem}

\bibliographystyle{alpha}
\bibliography{2023-01-19}

\end{document}
