%
% This is the LaTeX template file for lecture notes for CS294-8,
% Computational Biology for Computer Scientists.  When preparing 
% LaTeX notes for this class, please use this template.
%
% To familiarize yourself with this template, the body contains
% some examples of its use.  Look them over.  Then you can
% run LaTeX on this file.  After you have LaTeXed this file then
% you can look over the result either by printing it out with
% dvips or using xdvi.
%
% This template is based on the template for Prof. Sinclair's CS 270.

%\documentclass{article}
\documentclass[]{article}
%\usepackage[a4paper, total={7in, 8in}]{geometry}
\usepackage{layout}
\usepackage{tcolorbox}
%\usepackage[usenames,dvipsnames,svgnames,table]{xcolor}
\definecolor{darkgreen}{rgb}{0.0,0,0.9}
\usepackage[colorlinks=true,pdfpagemode=UseNone,citecolor=OliveGreen,linkcolor=red,urlcolor=red,
%pagebackref,
pdfstartview=FitW]{hyperref}

\usepackage{graphics,amsmath,amsthm,thmtools,amssymb,tikz,mathtools, algorithm, algpseudocode}

\usepackage[capitalize]{cleveref}
%\usepackage[backref=true, backend=biber, isbn=false, url=true, firstinits=true, maxnames=20, style=alphabetic,]{biblatex}
\usepackage{paralist}
%\usepackage{pgfplots}
%\usepackage{xspace}
\usepackage{natbib}
\usetikzlibrary{calc}

\setlength{\oddsidemargin}{0 in}
\setlength{\evensidemargin}{0 in}
\setlength{\topmargin}{-0.6 in}
\setlength{\textwidth}{6.5 in}
\setlength{\textheight}{8.5 in}
\setlength{\headsep}{0.75 in}
\setlength{\parindent}{0 in}
\setlength{\parskip}{0.1 in}

%\advance\hoffset by -3mm  % A4 is narrower.
%\advance\voffset by  8mm  % A4 is taller.
%\setlength{\footskip}{1cm}

\def\X{b}
\def\tX{\tilde{b}}
\def\mX{B}
\def\tmX{\tilde{B}}
%\def\bone{{\bf 1}}
%\def\N{\mathbb{N}}
%\def\R{\mathbb{R}}
\def\mP{\mathbb{P}}
\def\mE{\mathbb{E}}
\def\mI{\mathbb{I}}
%\def\cT{{\cal T}}
%\def\cB{{\cal B}}
\def\reff{\textup{Reff}}
%
% The following commands set up the lecnum (lecture number)
% counter and make various numbering schemes work relative
% to the lecture number.
%
\newcounter{lecnum}
\renewcommand{\thepage}{\thelecnum-\arabic{page}}
%\renewcommand{\thesection}{\thelecnum.\arabic{section}}
\renewcommand{\thesection}{\arabic{section}}
%\renewcommand{\theequation}{\thelecnum.\arabic{equation}}
\renewcommand{\theequation}{\thesection.\arabic{equation}}
\renewcommand{\thefigure}{\thesection.\arabic{figure}}
\renewcommand{\thetable}{\thesection.\arabic{table}}
\newcommand{\PP}[2]{\mP_{#1}\left[#2\right]}
\newcommand{\weight}[1]{w(#1)}
\renewcommand{\P}[1]{\mP\left[#1\right]}
\newcommand{\I}[1]{\mI\left[#1\right]}
\newcommand{\E}[1]{\mE\left[#1\right]}
\newcommand{\EE}[2]{\mE_{#1}\left[#2\right]}
\newcommand{\norm}[1]{\|#1\|}
\newcommand{\therank}{{\mathsf{rank}_{1-\eps}}}
\newcommand{\cutcone}{{\textsf{CutCone}}}
\newcommand{\mincut}{{\textsf{Min-Cut}}}
\newcommand{\sparcut}{{\textsf{SparsestCut}}}
\newcommand{\scut}{{\textsf{SC}}}
\newcommand{\LR}{{\textsf{LR}}}
%\DeclareMathOperator{\trace}{Tr}
\DeclareMathOperator{\vol}{vol}
\DeclareMathOperator{\sspan}{span}

\newcommand{\algorithmautorefname}{Algorithm}
\newcommand{\xmod}[1]{\ (\mathrm{mod}\ #1)}

\newcommand{\np}{\textsf{NP}}
%\newcommand{\nph}{\ensuremath{\mathsf{NP}}-\ensuremath{\mathsf{Hard}}\xspace}
%\newcommand{\npc}{\ensuremath{\mathsf{NP-Complete}}\xspace}

\newcommand{\ds}{\displaystyle}
\newcommand{\den}{\texttt{den}}
\newcommand{\dash}[1]{{#1}'}
\renewcommand{\qedsymbol}{\ensuremath{\blacksquare}}

%
% The following macro is used to generate the header.
%
\newcommand{\handout}[5]{
   \renewcommand{\thepage}{#1-\arabic{page}}
   \noindent
   \begin{center}
   \framebox{
      \vbox{
    \hbox to 6.35in { {\bf CS-760 Topics in Computational Complexity}
     	 \hfill #2 }
       \vspace{4mm}
       \hbox to 6.35in { {\Large #5  \hfill} }
       \vspace{2mm}
       \hbox to 6.35in { {\it #3 \hfill #4} }
      }
   }
   \end{center}
   \vspace*{4mm}
}

\newcommand{\lecture}[5]{\handout{#1}{#2}{Lecturer:
#3}{Scribe: #4}{Lecture #1: #5}}


\makeatletter
\def\fnum@figure{{\bf Figure \thefigure}}
\def\fnum@table{{\bf Table \thetable}}
\long\def\@mycaption#1[#2]#3{\addcontentsline{\csname
  ext@#1\endcsname}{#1}{\protect\numberline{\csname
  the#1\endcsname}{\ignorespaces #2}}\par
  \begingroup
    \@parboxrestore
    \small
    \@makecaption{\csname fnum@#1\endcsname}{\ignorespaces #3}\par
  \endgroup}
\def\mycaption{\refstepcounter\@captype \@dblarg{\@mycaption\@captype}}
\makeatother



%Use this command for a figure; it puts a figure in wherever you want it.
%usage: \fig{NUMBER}{SPACE-IN-INCHES}{CAPTION}
\newcommand{\fig}[3]{
			\vspace{#2}
			\begin{center}
			Figure \thelecnum.#1:~#3
			\end{center}
	}
% Use these for theorems, lemmas, proofs, etc.
%\newtheorem{theorem}{Theorem}[lecnum]
\newtheorem{theorem}{Theorem}[section]
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem{fact}[theorem]{Fact}
\newtheorem{problem}[theorem]{Problem}
\newtheorem{notation}[theorem]{Notation}
\newtheorem{proposition}[theorem]{Proposition}
\newtheorem{claim}[theorem]{Claim}
\newtheorem{corollary}[theorem]{Corollary}
\newtheorem{example}[theorem]{Example}
\newtheorem{definition}[theorem]{Definition}
\newtheorem{remark}[theorem]{Remark}
%\newtheorem{item}[theorem]{Item}
%\newtheorem{equation}[theorem]{Equation}
\newenvironment{proofof}[1]{\textcolor{red}{\em Proof of #1.}}{\hfill%\rule{2mm}{2mm}
\qed}
\newenvironment{proofsk}[1]{\textcolor{red}{\em Proof Sketch for #1.}}{\hfill%\rule{2mm}{2mm}
%\newenvironment{proofof}[1]{{\em Proof of #1.}}{\hfill%\rule{2mm}{2mm}
\qed}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{circuitikz}
%\input{preamble}
% **** IF YOU WANT TO DEFINE ADDITIONAL MACROS FOR YOURSELF, PUT THEM HERE:

\begin{document}
%FILL IN THE RIGHT INFO.
%\lecture{**LECTURE-NUMBER**}{**DATE**}{**LECTURER**}{**SCRIBE**}{**TOPIC**}
%TODO Add Lecture Number
\lecture{12}{10 September 2024}{Rohit Gurjar}{Aditya (210050006), Akshat (210050009)}{Boolean Circuits}
%\footnotetext{These notes are partially based on those of Nigel Mansell.}

% **** YOUR NOTES GO HERE:

% Some general latex examples and examples making use of the
% macros follow.  
%**** IN GENERAL, BE BRIEF. LONG SCRIBE NOTES, NO MATTER HOW WELL WRITTEN,
%**** ARE NEVER READ BY ANYBODY.

\section{Boolean Circuits}
A \textbf{Boolean circuit} is directed acyclic graph that represents a Boolean function $f: \{0,1\}^n \to \{0,1\}$. Each node in the DAG represents a logical gate performing one of the operations AND/OR/NOT on the bits coming from the incoming edges to it. There are $n$ input gates which do not have any incoming edges and one (or more) output gate which does not have any outgoing edge. 

The \textbf{size} of the circuit is the number of gates, and the \textbf{depth} is the length of the longest path in the DAG.

The \textbf{fan-in} of a circuit is the max number of inputs to any gate. Circuits with fan-in greater than 2 can be simulated by circuits with fan-in 2, with a polynomial increase in size and  depth increasing by a logarithmic factor. 
Fan-out is the maximum outdegree of any gate, i.e., number of times the output of any gate is getting used (the same output getting used multiple times).

A \textbf{Boolean formula} is similar to a Boolean circuit, but with the restriction that the \textbf{fan-out} is 1. In other words, the output of each gate can only be used once.
\begin{figure}[H]

\begin{center}
\begin{tikzpicture}
    % Define inputs
    \node[circle, draw, inner sep=1pt] (a) at (0,3) {$a$};
    \node[circle, draw, inner sep=1pt] (b) at (0,1) {$b$};
    \node[circle, draw, inner sep=1pt] (c) at (0,-1) {$c$};
    \node[circle, draw, inner sep=1pt] (d) at (0,-3) {$d$};
    
    % Define gates
    \node[circle, draw, inner sep=1pt] (and1) at (2,2) {$\land$};
    \node[circle, draw, inner sep=1pt] (and2) at (2,0) {$\land$};
    \node[circle, draw, inner sep=1pt] (or1) at (4,1) {$\lor$};
    
    % Connect inputs to gates
    \draw [->] (a) -- (and1);
    \draw [->] (b) -- (and1);
    \draw [->] (c) -- (and2);
    \draw [->] (d) -- (and2);
    
    % Connect gates to each other
    \draw [->] (and1) -- (or1);
    \draw [->] (and2) -- (or1);
    
    % Output
    \draw (or1) -- (6,1) node[right] {$f(a,b,c,d)$};
\end{tikzpicture}
\caption{An example boolean circuit (also a boolean formula) computing the function $(a \wedge b) \vee (c \wedge d ).$}
\end{center}
\end{figure}
Boolean circuits are equivalent to \textbf{straight-line programs}, which are programs with no loops or jumps. The number of gates in a circuit is equal to  the number of lines in the program.

% \subsection{Example: Straight-Line Program}
Example:
\[
\begin{aligned}
    x_1 &= a \land b \\
    x_2 &= c \land x_1 \\
    x_3 &= d \land x_1 \\
    x_4 &= x_2 \lor x_3
\end{aligned}
\]
The corresponding Boolean circuit is:

\begin{figure}[H]
\begin{center}
\begin{tikzpicture}
    % Define inputs
    \node[circle, draw, inner sep=1pt] (a) at (0,3) {$a$};
    \node[circle, draw, inner sep=1pt] (b) at (0,1) {$b$};
    \node[circle, draw, inner sep=1pt] (c) at (0,-1) {$c$};
    \node[circle, draw, inner sep=1pt] (d) at (0,-3) {$d$};

    
    % Define gates
    \node[circle, draw, inner sep=1pt] (and1) at (2,2) {$\land$};
    \node[circle, draw, inner sep=1pt] (and2) at (4,2) {$\land$};
    \node[circle, draw, inner sep=1pt] (and3) at (4,0) {$\land$};
    \node[circle, draw, inner sep=1pt] (or1) at (6,1) {$\lor$};
    
    % Connect inputs to gates
    \draw [->] (a) -- (and1);
    \draw [->] (b) -- (and1);
    \draw [->] (and1) -- (and2);
    \draw [->] (c) -- (and2);
    \draw [->] (and1) -- (and3);
    \draw [->] (d) -- (and3);
    
    % Connect gates to each other
    \draw [->] (and2) -- (or1);
    \draw [->] (and3) -- (or1);
    
    % Output
    \draw (or1) -- (8,1) node[right] {$x_4$};
    
\end{tikzpicture}
\caption{Boolean circuit for the above straight line program}
\end{center}
\end{figure}

\section{Circuit Families}
Since a Boolean circuit only accepts inputs of a fixed size, we define a \textbf{circuit family} $\{C_n\}_{n=1}^{\infty}$, where $C_n$ is a circuit for inputs of size $n$. 

A language $L$ is said to be in the class \textbf{size}($T(n)$) if there exists a circuit family $\{C_n\}$ such that $|C_n| = O(T(n))$, and $C_{|x|}(x) = 1$ if and only if $x \in L$.

\section{P/poly}
The class P/poly is the class of languages computed by circuit families of polynomial size:
\[
\text{P/poly} = \bigcup_{c \geq 1} \text{size}(n^c).
\]


\section{Computational power of boolean circuits}
We claim that $\mathbf{P} \subset \mathbf{P{/poly}}$. We will prove this in two parts
\begin{enumerate}
    \item $\mathbf{P} \subseteq \mathbf{P{/poly}}$
    \item There exists a language $L \in \mathbf{P{/poly}}$ which does not belong to $\mathbf{P}$
\end{enumerate}

\begin{proof}
    Given a Turing machine $M$ which runs in polynomial time $T(n)$, we will simulate $M$ by a polynomial-sized circuit family. Let's introduce a gate for each cell of the tape that may be accessed, each state and head position at every time step. Since $M$ runs in polynomial time, it can access at most polynomial number of cells, hence for all $n \in N$ there are $cT(n)$ gates for some constant $c$. The next state, head position and tape contents are a function of the current configuration and thus can be calculated in polynomial size. At the end, the final state can be determined to be accepting using polynomial number of gates. Therefore, we have a polynomial size circuit family which accepts iff $M$ accepts.
    
    To prove the second part we will show something stronger, we will show that an undecidable problem
lies in P/poly.
%     $HALT = \{(M, x)\;|\;M\;halts\;on\;x\} \in \mathbf{P{/poly}}$.
    
    Consider the unary version of the halting problem $UHALT = \{1^n\;|\;n\;encodes\;(M, x)\;and\;M\;halts\;on\;x\}$. 
    Consider a circuit family $\{C_n\}$ such that  for all $n \in N$, 
    if $1^n \in UHALT$ then the circuit $C_n$ is simply $AND$ of $n$ input gates, and if $1^n \not\in UHALT$ then the circuit $C_n$ will always return $0$ (for example, $\neg x_1 \wedge x_1$). 
    Therefore, $UHALT \in \mathbf{P{/poly}}$.
    The main point here is that if the language is sparse (very few `yes' inputs of any size) then it can be hardcoded 
    in the circuit, no matter how hard it is to decide the language for a TM. 
\end{proof}

It is unknown whether $\mathbf{NP} \subseteq \mathbf{P{/poly}}$. However, it is believed to be false because of the Karp-Lipton theorem, which implies the collapse of the polynomial hierarchy to the second level.

\section{Karp Lipton Theorem}
In 1980, Karp and Lipton proved the following theorem
\begin{theorem}\label{thm:karp_lipton_theorem}
    If $\mathbf{NP} \subseteq \mathbf{P{/poly}}$ then $\mathbf{PH} = \mathbf{\Sigma_2^p}$
\end{theorem}

\begin{proof}
    In order to show $\mathbf{PH} = \mathbf{\Sigma_2^p}$, it is sufficient to show that $\mathbf{\Pi_2^p \subseteq \mathbf{\Sigma_2^p}}$
    
    Suppose $L \in \mathbf{\Pi_2^p}$, then there exists a Turing machine $M$ such that
    \[
        L = \{ x : \forall y \in \{0, 1\}^{q(|x|)} \exists z \in \{0, 1\}^{q(|x|)} M(x, y, z) = 1 \}
    \]

    Let $L'$ be the language defined as follows
    \[
        L' = \{ (x, y) : \exists z M(x, y, z) = 1 \}
    \]
    Since $L' \in \mathbf{NP}$, there exists polynomial size circuit family $\{C_m(x, y)\}$ for $L'$ such that $C_m(x, y) = 1$ if and only if $\exists z M(x, y, z) = 1$. Using $C_n$ we can construct a polynomial size circuit family $\{C_m^{'}(x, y)\}$ which outputs $z$ such that $M(x, y, z) = 1$. This is left as homework. 
    We know that if there is an algorithm to decide satisfiability then we can use that algorithm to design another one
    that find a satisfying assignment. A similar argument can be made using circuits, and for all NP languages. 

    Therefore, if $x \in L$ then $\exists C^{'} \forall y M(x, y, C^{'}(x, y)) = 1$, 
    
    and if $x \not\in L$ then we know that $\exists y \forall z M(x,y,z) \neq 1$.
    Hence we can say $\forall C^{'} \exists y M(x, y, C^{'}(x, y)) \not= 1$ (this is because if $x \not\in L$ then no matter what $C'$ outputs it will not be accepted by $M(x,y, \cdot)$.)

    We get $ x \in L$ if and only if $ \exists C^{'} \forall y M(x, y, C^{'}(x, y)) = 1$. This means $L$ is in $\Sigma^p_2$.
\end{proof}

Proving $\text{NP} \not\subseteq \text{P/poly} \implies \text{NP} \not\subseteq \text{P}$, since $\text{P} \subseteq \text{P/poly}$. 
So, proving circuit lower bounds is an approach towards proving P $\neq $ NP. However, the best known circuit lower bound for an NP problem is $5n$.

\end{document}