\documentclass[11pt]{article}

\usepackage[right=0.8in, top=1in, bottom=1.2in, left=0.8in]{geometry}
\usepackage{amsmath,amsfonts,amssymb,amsthm}
\usepackage{mathtools}
\usepackage{graphicx}
\usepackage[colorlinks,linkcolor=black]{hyperref}
\usepackage{cleveref}
\usepackage{tikz}
\usepackage{url}
\usepackage{fixme}
\usepackage[roman]{complexity}
\usepackage{setspace}
\spacing{1.06}
\usetikzlibrary{arrows.meta}

\newtheorem{theorem}{Theorem}
\newtheorem{example}[theorem]{Example}
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem{question}[theorem]{Question}
\theoremstyle{definition}
\newtheorem{definition}[theorem]{Definition}
\theoremstyle{remark}
\newtheorem{remark}[theorem]{Remark}

\newcommand{\handout}[5]{
    \noindent
    \begin{center}
        \framebox{
            \vbox{\vspace{0.25cm}
                \hbox to 5.78in { {CS Theory (Spring '25)} \hfill #2 }
                \vspace{0.48cm}
                \hbox to 5.78in { {\Large \hfill #5  \hfill} }
                \vspace{0.42cm}
                \hbox to 5.78in { {#3 \hfill #4} }\vspace{0.25cm}
            }
        }
    \end{center}
    \vspace*{4mm}
}

\newcommand{\lecture}[4]{\handout{#1}{#2}{#3}{#4}{#1}}

\begin{document}

\lecture{Lecture Note: Communication Protocols}{February 27, 2025}{Instructor:\hspace{0.08cm}\emph{Josh Alman }}{}

\setcounter{section}{-1}
\section{Logistics}
\begin{itemize}
    \item Next Tuesday (Mar 4) there will be no in-person lecture. Instead, there will be a video lecture.
    \item Next Thursday (Mar 6) homework 3 will be due at noon.
    \item On the thursday after next (Mar 13), there will be the midterm exam. The exam will cover materials until next Tuesday (Mar 4), and it will cover everything from class and homeworks. 
    
    You can use results from class and homeworks, but you cannot use without proof results that have not appeared in class or homework problems. For example, ``closure of regular languages under intersection'' is not proved in class, and has not appeared in homework problems, so you cannot use it without proof, even if you may have used it in your homework solution (and in that case you should already have a good understanding of the proof :).
    
    You can bring 1 piece of letter-size (or A4-size) paper ``cheat sheet'' to the exam. You can prepare it in any way you prefer, including handwriting or printing. You can put anything on it, but we suggest you put statements of results from class on it, such as the pumping lemma. 
    \item After the midterm, it will be the spring break!
\end{itemize}
%Calendar:				Tuesday							Thursday
%this week: 												today
%next week:				no in-person lecture :(			1. HW due
%                        there will be a video lecture	2. Post practice exam
%the week after that:									Exam! 
%then:	spring break!
%
%Exam will cover materials until next Tues. You can bring 1 piece of paper "cheat sheet"
%Suggestions for type of things to put on cheatsheet:
%- Statements of results from class, like pumping lemma
%
%Exam will cover everything from class and homeworks. You can use results from class and homeworks. But you cannot use results that have not appeared in class or homeworks statements. For example, ``closure under intersection'' something something.

\section{Communication protocols}
%Let's start to talk about communication

Once upon a time, there were two persons, Alice and Bob. Suppose Alice and Bob have $x \in \{0, 1\}^*$ and $y \in \{0, 1\}^*$ as inputs respectively, and their goal is to compute $f(x, y)$ for some function $f: \{0, 1\}^* \times \{0, 1\}^* \to \{0, 1\}$ and for both party to learn $f(x, y)$. To achieve this Goal, Alice and Bob communicates. Their communication might be something like the following:\footnote{This is just an arbitrary example.}

\begin{figure}[ht]\centering
\begin{tikzpicture}[x=0.75pt,y=0.75pt,yscale=-1,xscale=1]
    %uncomment if require: \path (0,332); %set diagram left start at 0, and has height of 332
    
    \draw[-{Stealth}]    (247,80) -- (507,80) ;
    %\draw [shift={(407,80)}, rotate = 180] [color={rgb, 255:red, 0; green, 0; blue, 0 }  ][line width=0.75]    (10.93,-3.29) .. controls (6.95,-1.4) and (3.31,-0.3) .. (0,0) .. controls (3.31,0.3) and (6.95,1.4) .. (10.93,3.29)   ;
    %Straight Lines [id:da69167175072284] 
    \draw[{Stealth}-]    (247,105) -- (507,105) ;
    %\draw [shift={(247,105)}, rotate = 0] [color={rgb, 255:red, 0; green, 0; blue, 0 }  ][line width=0.75]    (10.93,-3.29) .. controls (6.95,-1.4) and (3.31,-0.3) .. (0,0) .. controls (3.31,0.3) and (6.95,1.4) .. (10.93,3.29)   ;
    \draw[-{Stealth}]    (247,130) -- (507,130) ;
    %\draw [shift={(407,130)}, rotate = 180] [color={rgb, 255:red, 0; green, 0; blue, 0 }  ][line width=0.75]    (10.93,-3.29) .. controls (6.95,-1.4) and (3.31,-0.3) .. (0,0) .. controls (3.31,0.3) and (6.95,1.4) .. (10.93,3.29)   ;
    %Straight Lines [id:da43865612321965664] 
    \draw[{Stealth}-]    (247,155) -- (507,155) ;
    \draw[-{Stealth}]    (247,180) -- (507,180) ;
    
    % Text Node
    \draw (197,125) node [anchor=north west][inner sep=0.75pt]   [align=left] {Alice};
    % Text Node
    \draw (517,125) node [anchor=north west][inner sep=0.75pt]   [align=left] {Bob};
    
    \draw (355,63) node [anchor=north west][inner sep=0.75pt]    {Hello!};
    % Text Node
    \draw (305,88) node [anchor=north west][inner sep=0.75pt]    {The length of $y$ is odd.};
    % Text Node
    \draw (280,113) node [anchor=north west][inner sep=0.75pt]    {The number of $b$ in $x$ is prime.};
    \draw (325,138) node [anchor=north west][inner sep=0.75pt]    {$y$ is a palindrome.};
    \draw (345,163) node [anchor=north west][inner sep=0.75pt]    {$f(x, y) = 1$.};
    
\end{tikzpicture} 
\caption{An example of communication between Alice and Bob.}\label{fig: 1}
\end{figure}


%Alice: Hello!
%Bob: the length of $y$ is odd
%Alice: the number of $b$ in $x$ is prime
%Bob: $y$ is a palindrome
%Alice: $f(x, y) = 1$
%
%Goal: compute $f(x, y)$.

Below are a few examples of communication problems, that is, functions for which we study communication protocols. The convention is to use all capital letters for communication problems.


\begin{example}
    $\mathrm{EQUALITY}(x, y) = \begin{cases}
        1 & x = y\\
        0 & x \ne y
    \end{cases}$.
\end{example}

\begin{example}
    $\mathrm{MAJORITY}(x, y) = \begin{cases}
        1 & \text{if $xy$ contains more 1's than 0's}\\
        0 & \text{otherwise}
    \end{cases}$.
\end{example}

\begin{example}
    $\mathrm{PARITY}(x, y) = \begin{cases}
        1 & \text{if $xy$ contains an odd number of $1$'s}\\
        0 & \text{otherwise}
    \end{cases}$.
\end{example}

For any communication problems, the following na\"ive protocol always works.
\begin{example}
    Alice first sends her whole input $x$ to Bob. Bob then computes $f(x, y)$ and sends it to Alice. 
    
    This protocol takes $O(|x|) = O(n)$ bits of communication, where $n \coloneq |xy|$. 
\end{example} 

However, for many communication problems $f$, there are much better protocols than the na\"ive one, in terms of total bits of communication. For example, we will see soon that MAJORITY has a protocol with $O(\log n)$ communication, and PARITY has a protocol with $O(1)$ communication.

In this and the next lecture, we will focus on the following question:
\begin{quotation}
    For a given communication problem, what is the least amount of communication any protocol for the problem have to use?
\end{quotation}

\begin{definition}
    We call the number of bits of communication used by a protocol the \emph{communication complexity} of the protocol. We also define the communication complexity of a communication problem to be the minimum communication complexity among all protocols for the problem.
\end{definition}

The rationale that we focus on communication and not the local computation by Alice or Bob themselves is that communication usually takes much longer than local computation. For example, Alice might be in New York while Bob is in Hawaii. As another example, when designing chips, it is common for the bottleneck to be the communication between different parts of the chip, and this is also one of the reasons why people started to study communication complexity.

%Rationale: communication usually takes much longer than local computation

%To prove limits how small a chip you can make to compute these functions


Now we discuss better-than-na\"ive protocols for the MAJORITY and PARITY problems.

\begin{example}[Protocol for MAJORITY]
    Alice first sends the number of $1$'s in $x$ and the number of $0$'s in $x$ to Bob. Bob computes the number of $1$'s in $y$ and the number of $0$'s in $y$, and then computes the total number of $1$'s in $xy$ and the total number of $0$'s in $xy$, using Alice's message. Bob compares the two numbers and sends the answer to Alice.
    
    The protocol takes $O(\log|x|) = O(\log n)$ communication, where $n = |xy|$, since the two numbers Alice sends to Bob can take value as big as $|x|$.
\end{example}

%MAJORITY:
%Alice sends number of 1s in x to Bob
%Alice sends number of 0s in x to Bob
%Bob computes on his own number of 1s in y and number of 0s in y
%Bob computes number of 1s in xy and number of 0s in xy
%Bob compares the two numbers sends the answer to Alice
%
%$O(\log|x|)$ communication
%$n = |x| + |y| = |xy|$. $O(\log n)$.
%``How many communcation is used \emph{in the worst case}''

\begin{example}[Protocol for PARITY]
    Alice sends to Bob whether the number of $1$'s in $x$ is odd. Bob computes whether the number of $1$'s in $y$ is odd, and then computes the answer: $1$ if one of the number of $1$'s in $x$ and the number of $1$'s in $y$ is odd and the other is even, and $0$ is both of these numbers are odd or both are even. Bob then sends the result to Alice.
    
    There are $2$ bits of communication in this protocol. We can prove that this is optimal, as Bob needs $1$ bit of message from Alice to learn about the parity of the number of $1$'s in $x$, and similarly Alice needs $1$ bit of message from Bob. 
\end{example}

\begin{remark}
    Bob already knows the answer before sending it to Alice. However, our requirement is that both Alice and Bob know the solution, so Bob has to send it to Alice. Actually, in most protocols, the last message is one party sending the final answer to the other party.
\end{remark}

%PARITY:
%Alice sends to Bob whether number of 1s in x is odd
%Bob computes whether number of 1s in y is odd
%Bob computes the answer: 1 if one was odd and one was even, 0 if both odd or both even
%Bob tells Alice the answer
%
%2 bits is the lower bound: ``Alice and Bob both needs to have some information about the other party's input''

For EQUALITY, the na\"ive protocol uses $O(n)$ communication, and next time we will see that this is optimal.

%EQUALITY:
%Alice sends x to Bob $O(n)$
%Bob checks if $x = y$ and tells Alice
%Total $O(n)$
%We will see later cannot beat $O(n)$.

%Remark: Any function $f$ has a communication protocol that uses $O(n)$ bits of communication. Alice sends $x$ to Bob. Bob computes $f(x, y)$ and tells Alice. We don't care about local computation of Alice or Bob.

One may notice that PARITY and MAJORITY are all defined in the following form: $f(x, y) = 1$ if the string $xy$ satisfies some property, and $f(x, y) = 0$ otherwise. We can generalize this as follows.

\begin{definition}
    Given a language $L$ over $\{0, 1\}$, define the associated communication problem of $L$ to be \[f_L(x, y) \coloneq \begin{cases}
        1 & xy \in L\\
        0 & xy \notin L
    \end{cases}.\]
\end{definition}


%Communication protocols compute functions:
%$f: \{0, 1\}^* \times \{0, 1\}^* \to \{0, 1\}$.
%Given languages $L$ over $\{0, 1\}$, can consider function
%$f_L(x, y) = \begin{cases}
%    1 & xy \in L\\
%    0 & xy \notin L
%\end{cases}$ You can capture some functions but not all functions in this form.

We can see that $\mathrm{PARITY} = f_{L_P}$ where \[L_P \coloneq \{w \in \{0, 1\}^* \mid \text{the number of $1$'s in $w$ is odd}\},\] and $\mathrm{MAJORITY} = f_{L_M}$ where \[L_M \coloneq \{w \in \{0, 1\}^* \mid \text{the number of $1$'s in $w$ is greater than the number of $0$'s in $w$}\}.\]

However, not all communication problems are associated with a language. For example, for $\mathrm{EQUALITY}$, one may be tempted to define
\[L_E \coloneq \{ww \mid w \in \{0, 1\}^*\}.\]
However, $f_{L_E} \ne \mathrm{EQUALITY}$. As a counterexample, if $x = 000$, $y = 0$, then $f_{L_E}(x, y) = 1$, while $\mathrm{EQUALITY}(x, y) = 0$.
%Parity: $\{w \in \{0, 1\}^* \mid number of 1s in w is odd\}$.

%Majority: $\{w \in \{0, 1\}^* \mid number of 1s in w > number of 0s in w\}$

% Equality: $\{ww \mid w \in \{0, 1\}^*\} = L'$. issue with this.$x = 000$, $y = 0$, then $EQUALITY(x, y) = 0$, but $L'(x, y) = 1$ (with $w = 00$).

We leave a question to think about at the end.  
\begin{question}
    Is it true that $f_L$ has $O(1)$ communication protocol if and only if $L$ is regular?
\end{question}



\end{document}
