\documentclass[10pt]{article}
\newtheorem{define}{Definition}
%\newcommand{\Z}{{\mathbb{Z}}}
%\usepackage{psfig}

\usepackage{amsmath}        % comment out \newcommand{\binom} in preamble!
\usepackage{amsfonts}
\usepackage{stackrel}  		% needed to define big XOR expressions!
\usepackage{algpseudocode}	% needed for pseudocode parts!

\oddsidemargin=0.15in
\evensidemargin=0.15in
\topmargin=-.5in
\textheight=9in
\textwidth=6.25in

% This is a customized modulo which eats less space!
\makeatletter
 \def\imod#1{\allowbreak\mkern8mu({\operator@font mod}\,\,#1)}
 \makeatother

\begin{document}
\input{preamble.tex}

%{lecture number}{lecture date}{Ronitt Rubinfeld}{Your name}
\lecture{10}{March 12, 2012}{Ronitt Rubinfeld}{Hamidreza Jahanjou}

%%%% body goes in here %%%%

Today, we are going to discuss the following
\begin{itemize}
	\item{Linearity Testing,}
	\item{Fourier Analysis.}
\end{itemize}

\section{Linearity Testing}

\begin{define}
A function $f : \{0,1\}^n \rightarrow \{0,1\}$ is called linear if
\begin{equation} \forall x, y \in \{0,1\}^n : f(x)+f(y) = f(x+y) \pmod 2 \end{equation}\label{eq:homo}
where the plus sign represents mod 2 addition in vector space; specifically,
\[(x_1, ..., x_n) + (y_1, ..., y_n) = (x_1+y_1 \imod 2,\;
									   x_2+y_2 \imod 2,
									   ...,\;
									   x_n+y_n \imod 2).\]
\end{define}

The property defined by equation (\ref{eq:homo}) is also known as the homomorphism property.\\
Some examples of linear functions are
\begin{itemize}
	\item{$f(x)=0$,}
	\item{$f(x)=x_i$, (projection functions),}
	\item{$f(x)= \stackrel[i=1]{n}{\bigoplus} x_i$.}
\end{itemize}

A useful relation is the following for which we give an informal proof.

\begin{claim}
A function $f : \{0,1\}^n \rightarrow \{0,1\}$ is linear iff $\forall x : \;f(x)= \stackrel[i\in S]{}{\bigoplus} x_i$ for some $S\subseteq [n]$.
\end{claim}

\begin{proof-sketch} 
A linear function $f$ is uniquely determined by all $f(u_i)$ where $u_i=(0, ..., 0, 1, 0, ..., 0)$ is the $i$th unit vector. Clearly, $2^n$ possible settings of $f(u_i)$'s means $2^n$ possible linear functions. On the other hand, there are only $2^n$ sets $S \subseteq [n]$. Consequently, we're accounting for all linear functions.
\end{proof-sketch}

How can we tell if a function $f$ is linear? Querying can be very inefficient since points of non-linearity may be very sparse in the whole space. This motivates the following definition.

\begin{define}
A function $f$ is $\epsilon$-close to linear if there exists a linear function $g$ such that
\[
\Pr[f(x)=g(x)]=\frac{|\{x|f(x)=g(x)\}|}{2^n} \geq 1- \epsilon.
\]
Otherwise $f$ is $\epsilon$-far to linear.
\end{define}

Base on this idea, we propose a linearity test.

\begin{algorithmic}
\Function{Test}{}
\Repeat $\;\;r\gets 1$
	\State pick $x,y \in_R \{0,1\}$
	\If {[$f(x)+f(y) \neq f(x+y) \imod 2]$}
   		\State Fail and Halt.
	\EndIf
\Until $r= O(\frac{1}{\epsilon})$
\State Output Pass.
\EndFunction
\end{algorithmic}

Regarding the behavior of our test, we observe the following.
\begin{itemize}
	\item if $f$ is linear, then $\Pr [\mathrm{Pass}] = 1$,
	\item if $f$ is $\epsilon$-far from linear, then $\Pr [\mathrm{Fail}] \geq \frac{3}{4}$.
\end{itemize}

\subsection*{A Notational Switch}
From now on, the following changes are in effect:

\begin{center}
     \begin{tabular}{ | l | l |}
     \hline
     Previously & Now\\ \hline
     &\\
     $f_s :\; \{0,1\}^n \rightarrow \{0,1\}$ & $f_s :\; \{\pm 1\}^n \rightarrow \{\pm 1\}$ \\
     &\\
     $f_s(x)= \stackrel[i\in S]{}{\bigoplus} x_i = \sum_{i\in S} x_i \imod 2 $ & $f_s(x)=\prod_{i\in S} x_i$\\
     &\\ \hline
     \end{tabular}
\end{center}

We note that, with this notational change, $f(x)f(y) \neq f(x,y) \iff f(x)f(y)f(xy) = -1$. Therefore, it's possible to define the following indicator random variables
\[
\frac{1-f(x)f(y)f(xy)}{2} = \begin{cases} 0 & \text{if the test passes,}\\
										  1 & \text{if the test fails.}
							\end{cases}
\]

We also define their expected value:
\[
\delta = \mathbb{E}_{x,y} \bigg[ \frac{1-f(x)f(y)f(xy)}{2}\bigg].
\]

The expected value of the indicator random variable is the probability of rejection in one pass. The probability of being accepted is similarly define as

\[
1- \delta = \mathbb{E}_{x,y} \bigg[ \frac{1+f(x)f(y)f(xy)}{2}\bigg].
\]

But, how can we calculate the value of these expressions? This is where Fourier Analysis comes in.

\section{Fourier Analysis}

Let's begin by considering the set $\mathbf{G} = \{g\; |\; g : \{\pm 1\}^n \rightarrow \mathrm{R} \}$. Note that $\mathbf{G}$ is a vector space of dimension $2^n$. In other words, all functions can be written as linear combinations of $2^n$ basis functions. For $f, g \in \mathbf{G}$, their inner product is defined as 

\[
	\langle f,g \rangle = \frac{1}{2^n} \sum_{x\in \{\pm 1\}^n} f(x)g(x).
\]

Next comes the choice of a basis for our vector space. Here we consider two possibilities. First, let's consider indicator functions

\[
  e_a(x) = \begin{cases}
    	 	1 & \text{if }\, x = a, \\
    	 	0 & \text{if }\, x \neq a.
   \end{cases}
\]

In this case an arbitrary function $f\in\mathbf{G}$ may be written as $f(x) = \sum_a f(x)e_a(x)$.
Even though indicator functions constitute an orthonormal basis, they're not very useful. Instead, we'll use character functions

\[
	\chi_{\raisebox{-2pt}{\scriptsize {S}}} (x) = \prod_{i\in S} x_i.
\]

Some examples of functions that can be written in terms of character functions:

\begin{itemize}
	\item $f(x)=1$ can be written as $1$ which is $\chi_{\raisebox{-2pt}{\scriptsize {$\emptyset$}}}$.
	\item $f(x)=x_i$ can be written as $x_i$ which is $\chi_{\raisebox{-2pt}{\scriptsize {$\{i\}$}}}$.
	\item $\text{And}(x_1, x_2)$ can be written as $\frac{1}{2} + \frac{1}{2}x_1 + \frac{1}{2}x_2 - \frac{1}{2}x_1x_2$.
	\item $\text{Maj}(x_1, x_2, x_3)$ can be written as $\frac{1}{2}x_1 + \frac{1}{2}x_2 + \frac{1}{2}x_3 - \frac{1}{2}x_1x_2x_3$.
\end{itemize}

We haven't shown that character functions form an orthonormal basis yet. This is done in two steps. First we prove their orthonormality. Next, we show that they are indeed a basis.

\begin{lemma}
The set $\{\chi_{\raisebox{-2pt}{\scriptsize {S}}}\; |\; S\subseteq [n]\}$ forms an orthonormal basis.
\end{lemma}

\begin{proof}
Normality:
\[ \langle \chi_{\raisebox{-2pt}{\scriptsize {S}}}, \chi_{\raisebox{-2pt}{\scriptsize {S}}} \rangle = \frac{1}{2^n} \sum_x \underbrace{(\chi_{\raisebox{-2pt}{\scriptsize {S}}}(x))^2}_{\text{1's}} = 1 \]
where the second equality follows from the observation that the LHS expression is an average of 1's.
Orthogonality: suppose $S\neq T$,
\begin{align*} 
\langle \chi_{\raisebox{-2pt}{\scriptsize {S}}}, \chi_{\raisebox{-2pt}{\scriptsize {T}}} \rangle & = \frac{1}{2^n}\sum_{x\in \{\pm 1\}} \chi_{\raisebox{-2pt}{\scriptsize {S}}}(x)\chi_{\raisebox{-2pt}{\scriptsize {T}}}(x) \\
				  & = \frac{1}{2^n}\sum_x \big(\prod_{i\in S} x_i \prod_{j\in T} x_j \big)\\
				  & = \frac{1}{2^n}\sum_x \big(\prod_{x\in S\backslash T} x_i \prod_{j\in T\backslash S} x_j \overbrace{\prod_{k\in S\cap T} x_k^2}^{1} \big) \\
				  & = \frac{1}{2^n}\sum_x \big(\prod_{i\in S\Delta T} x_i\big) \\
				  & = \frac{1}{2^n}\sum_{x, x^{\oplus j}} \big(\prod_{i \in S \Delta T} x_i + \prod_{i \in S \Delta T} x^{\oplus j}_i\big) \\
				  & = \frac{1}{2^n}\sum_{x, x^{\oplus j}} \prod_{i \in S \Delta T \backslash \{j\}} [x_j + \overline{x_j}] \\
				  & = 0
\end{align*}

where $x^{\oplus j}$ is $x$ with the $j$-th entry flipped and the last equality holds because $x_j + \overline{x_j} = 0$.
\end{proof}

Now, we need to show that any $f\in \mathbf{G}$, has a unique representation as a linear combination of $\chi_{\raisebox{-2pt}{\scriptsize {S}}}$'s. The proof of the following theorem is left as an exercise.

\begin{theorem}
Suppose $f\in \mathbf{G}$, then
\[ f = \sum_{S \subseteq [n]} \hat{f}(S) \chi_{\raisebox{-2pt}{\scriptsize {S}}} \]
where 
\[ \hat{f}(S) = \langle f, \chi_{\raisebox{-2pt}{\scriptsize {S}}} \rangle = \frac{1}{2^n} \sum_x f(x) \chi_{\raisebox{-2pt}{\scriptsize {S}}}(x). \]
\end{theorem}

Some nice properties:
\begin{enumerate}
	\item $\chi_{\raisebox{-2pt}{\scriptsize {S}}} \chi_{\raisebox{-2pt}{\scriptsize {T}}} = \chi_{\raisebox{-2pt}{\scriptsize {$S \Delta T$}}}$.
	\item (parity functions:) if $f=\chi_{\raisebox{-2pt}{\scriptsize {S}}}$, then
	\[ \hat{f}(Z) = \begin{cases}
    	 			1 & \text{if }\, Z = S, \\
    	 			0 & \text{if }\, Z \neq S.
   \end{cases}
	\]
    \item 
    \[
    \hat{f}(S) = 1 - 2 \Pr [\underbrace{f(x) \neq \chi_{\raisebox{-2pt}{\scriptsize {S}}}(x)}_{\text{dist}(f, \chi_{\raisebox{-2pt}{\scriptsize {S}}})}].
    \]
	\begin{proof}

	\begin{align*}
	\hat{f}(S) & = \frac{1}{2^n} \sum_x f(x)\chi_{\raisebox{-2pt}{\scriptsize {S}}}(x) \\
			   & = \frac{1}{2^n} \Big[ \sum_{x: f(x) = \chi_{\raisebox{-2pt}{\scriptsize {S}}}(x)} \underbrace{f(x)\chi_{\raisebox{-2pt}{\scriptsize {S}}}(x)}_{1}\;\; + \sum_{x: f(x) 		\neq \chi_{\raisebox{-2pt}{\scriptsize {S}}}(x)} \underbrace{f(x)\chi_{\raisebox{-2pt}{\scriptsize {S}}}(x)}_{-1} \Big] \\
			   & = \frac{1}{2^n} \big[ (2^n - |\{x\;|\; f(x)\neq \chi_{\raisebox{-2pt}{\scriptsize {S}}}(x)\}|) \times 1 + (|\{x\;|\; f(x)\neq 				\chi_{\raisebox{-2pt}{\scriptsize {S}}}(x)\}|) \times (-1) \big] \\
			   & = 1 - 2\Pr [f(x) \neq \chi_{\raisebox{-2pt}{\scriptsize {S}}}(x)].
	\end{align*}

	\end{proof}

	\item if $S\neq T$, then $\text{dist}(\chi_{\raisebox{-2pt}{\scriptsize {S}}}, \chi_{\raisebox{-2pt}{\scriptsize {T}}}) = \frac{1}{2}$.
		
	\begin{proof-sketch}
	For $S \neq T$, consider the Fourier representation of $\chi_{\raisebox{-2pt}{\scriptsize {S}}}$, and in particular the $T$th Fourier coefficient. It is equal to $0$ by the orthonormality of $\chi_{\raisebox{-2pt}{\scriptsize {S}}}$ and $\chi_{\raisebox{-2pt}{\scriptsize {T}}}$. Furthermore, by property 3, we have $0 = 1-2\Pr[\chi_{\raisebox{-2pt}{\scriptsize {S}}} \neq \chi_{\raisebox{-2pt}{\scriptsize {T}}}]$. Solving it gives us property 4.
	\end{proof-sketch}
		
\end{enumerate}
\noindent
{\em Comment:} 
{\em Hadamard codes} 
encode $a\in \{\pm 1\}^n$ by bit strings of length $2^n$ by 
writing the value of $\chi_a$ for all $n$-bit inputs.
Now, for all $a\neq b$ we observe that $\text{Had}(a)$ and $\text{Had}(b)$ differ on $\frac{1}{2}$ of the bits.
		

\end{document}
