\documentclass{article}
\usepackage[margin=1in]{geometry}
\usepackage{amsmath,amsthm,amssymb}
\usepackage{relsize}
\newcounter{lecnum}
\usepackage{tikz}
\usepackage{float}
\usepackage{graphicx}
\graphicspath{./}
\usepackage{caption}
\usepackage{subcaption}
\newcommand{\abs}[1]{\lvert #1 \rvert}
\newcommand{\lecture}[4]{
   \newpage
   \setcounter{lecnum}{#1}
   \noindent

   \begin{center}
   \framebox{
      \vbox{\vspace{2mm}
    \hbox to 16cm { {\bf CS760 Topics in Computational Complexity
                        \hfill 2024-25 Sem I} }
       \vspace{4mm}
       \hbox to 16cm { {\Large \hfill Lecture #1: #2  \hfill} }
       \vspace{2mm}
       \hbox to 16cm { {\it Scribe: #4  \hfill  Lecturer: #3} }
      \vspace{2mm}}
   }
   \end{center}
   \vspace*{4mm}
}

\newtheorem{theorem}{Theorem}[lecnum]
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem{proposition}[theorem]{Proposition}
\newtheorem{claim}[theorem]{Claim}
\newtheorem{corollary}[theorem]{Corollary}
\newtheorem{definition}[theorem]{Definition}

% custom
\usepackage{enumitem}
\usepackage{hyperref}
\usepackage{cleveref}
\usepackage{commath}
\newcommand{\N}{\mathbb{N}}
\newcommand{\R}{\mathbb{R}}
\newcommand{\F}{\mathbb{F}}
\newcommand{\E}{\mathbb{E}}
\newcommand{\restr}[2]{\ensuremath{\left.#1\right|_{#2}}}
\newcommand{\aw}{\operatorname{aw}}
\newcommand{\NP}{\text{NP}}

\begin{document}

\lecture{1}{02-08-2024}{Rohit Gurjar}{22B0923, 22B0912}

\section{NP-complete/NP-hard}
A language $L$ is said to be NP-hard if $\forall  Q\in \text{NP}$, $Q \leq_p L$.
$L$ is NP-complete if $L\in \NP$ and $L$ is NP-hard.
\begin{center}
\begin{tikzpicture}
    % NP circle
    \draw[thick] (0,0) circle (2.3);
    \node at (-1.2, 1.3) {NP};

    % NP-hard circle
    \draw[thick] (2.5,0) circle (2.3);
    \node at (3.4, 1.3) {NP-hard};

    % NP-complete intersection area
    \begin{scope}
        \clip (0,0) circle (2.3);
        \fill[gray, opacity=0.5] (2.5,0) circle (2.3);
    \end{scope}
    \node at (1.25, 0) {NP-complete};
\end{tikzpicture}
\end{center}
Example:

Input : $M,x$,$1^n$,$1^t$ \\
Output : Yes iff $\exists  u\in\{0,1\}^n$ such that $M$ outputs $1$ on input $ \langle x,u \rangle$ within $t$ steps.

\textbf{HW :} Prove that the above is in NP and is NP-hard
\subsection{SAT}
% SAT is NP-complete.\\
% To prove this we show a polynomial time conversion of any non deterministic turing machine to a SAT instance. If we can solve the SAT instance then we can solve any problem in NP as NP is defined by the problems solvable in polynomial time be a non deterministic turing machine.\\
% Let $p(n)$ be the max time required(polynomial) for an input of size n.\\
% For $i=0 to n$(time stamp) we define variables encoding the state of the system. The max portion of the tape required is $-p(n)$ to $+p(n)$ (so polynomial). For each time stamp we have a variable encoding the value of the tape($2p(n)$ variables), we also create $2p(n)$ variables stating whether the head is at this position or not. We also create variables for the state the machine is currently in. The total number of such variables is polynomial.\\
SAT or Boolean satisfiability problem is the problem of determining whether a given boolean formula has a satisfying assignment.
Its easy to see that SAT is in NP as any correct satisfying assignment serves as a certificate for true instance of the problem, and the certificate  can be verified in polynomial time.\\\\
\textbf{Cook-Levin Theorem- }SAT is NP complete.\\
\textbf{Proof:}\\
\textbf{Reduction:}
We already showed that SAT is in NP.  To prove that it is also NP-hard we show a polynomial time conversion of any non-deterministic Turing machine $M$ with an input $x$ to a SAT instance $\phi_{M,x}$. That means if we can solve   SAT   then we can solve any problem in NP, as NP is defined by the problems solvable in polynomial time by a non deterministic Turing machine. 

Let $p(n)$ be the max time required (polynomial) for an input of size n (as the problem is in NP there must exist a $p(n)$ such that any valid input can be solved in at most $p(n)$ time on an NTM).
For $i=0$ to $p(n)$ (time step) we define variables encoding the state of the system. Note 
that since the machine runs for time $p(n)$, it can only use  the tape cells between $-p(n)$ to $+p(n)$ (so polynomial).
 For each time step we have a variable encoding the value of the tape ($2p(n)$ variables), we also create $2p(n)$ variables stating whether the head is at this position or not. We also create variables for the state the machine is currently in.  The total number of such variables is polynomial.
 
    \begin{figure}[H]
        \centering
        \includegraphics[width=0.65\textwidth]{variable.png}  
        \caption{Encoding of variables. Image source: \url{https://en.wikipedia.org/wiki/Cook-Levin_theorem}}
    \end{figure}
    \begin{figure}[H]
        \centering
        \includegraphics[width=0.65\textwidth]{constraint.png} 
        \caption{Encoding of clauses(rules). Image source: \url{https://en.wikipedia.org/wiki/Cook-Levin_theorem}}
    \end{figure}
\noindent\textbf{intuition:} In the above reduction we basically have stored all tapes values, state and head position at all times $< p(n)$. We can get a satisfying assignment of the above SAT formula for an input of NTM by simply running the NTM for $p(n)$ time steps on an accepting computation path and putting in the corresponding symbols on the NTM tape, head and state for every step in $p(n)$ as the assignment of the variables $T_{i,j,k}, H_{i,k}$ and $Q_{q,k}$, respectively according to the encoding. Due to how we have made our clauses this has to be a satisfying assignment of the SAT formula. 
Also a satisfying assignment of SAT is a valid run of the NTM that accepts in at most $p(n)$ steps. 
%
Therefore, we conclude that the NTM has an accepting path on input $x$
if and only if 
the formula  $\phi_{M,x}$ is satisfiable. 
Moreover,  if we can find the solution of SAT efficiently then we can find a polynomial time accepting run of any NTM 
with just polynomial time overhead.
%
 This,  combined with the fact that SAT is in NP, completes the proof of Cook-levin theorem that says that SAT is NP-complete.
\newpage
Reductions are transitive.
\begin{center}
    \begin{tikzpicture}[
  edge from parent/.style={draw, -latex, thick},
  sibling distance=10em, level distance=6em,
  every node/.style={fill=gray!20, rounded corners, align=center}]

  % Root node
  \node {SAT}
    % Left subtree
    child {node {HAM}}
    % Right subtree
    child {node {IND-SET}
        % Left child of IND-SET
        child {node {TSP}}
        % Right child of IND-SET
        child {node {MAX CUT}}
    };

\end{tikzpicture}
\end{center}


% need to complete
\section{co-NP complete}
A decision problem $C$ is co-NP-complete if it is in co-NP and if every problem in co-NP is polynomial-time many-one reducible to it. Each co-NP problem is the complement of some NP problem.\\
\textbf{Example : } Given a CNF formula, is it a tautology?\\
Examples which are in $co-NP\cap NP$ but not known to be in P:
\begin{itemize}
    \item Integer factoring
    \item Discrete log: Given \(a\), \(b\), and \(p\), find \(r\) such that
    \[
    a^r \equiv b \pmod{p}.
    \]
\end{itemize}

Next, we are going to show another problem to be NP-complete. 

\textbf{Hamiltonian Path :} Given a directed graph, does there exists a path  from $v_1$ to $v_n$ that covers all vertices.

\textbf{Reduction of SAT to Hamiltonian path ($SAT \leq_p HAM$)}\\
 We'd like to create a graph where there is a path corresponding to each of the $2^n$ possible assignments to variables $x_1, \dots, x_n$. And if the assignment satisfies the given Boolean formula then the corresponding path covers all vertices. 
    How we do this is as follows, we make a path for each $x_i$, which can be traversed forwards and backwards. If moving from left to right, it's
    like assuming $x_i$ is 1, and right to left denotes assigning $x_i$ as 0. We will have connecting edges to move from 1 variable to the next,
    and one source and sink vertex. The length of each path is going to be twice the number of clauses (we'll see why we need this length later,
    just assume we choose some random length for now). 

    \begin{figure}[H]
        \centering
        \includegraphics[width=0.65\textwidth]{Hamiltonian1.png}  
        \caption{Image source: Kleinberg and Tardos, Algorithm Design, Chapter 8}
        \label{fig:variables}
    \end{figure}

For example, if wehave 3 variables, $x_1, x_2, x_3$ then the graph looks like the one in Figure~\ref{fig:variables}.  
In this graph, there will be $2^3$ Hamiltonian paths from $s$ to $t$, because for each row, we can either go left to right, or right to left. We can't 
    backtrack on any path because each vertex has to be visited exactly once, and each can correspond to some assignment.

    Now we have to bring in the clauses. We add a node for each clause, and need to make sure it is visited only if the clause is satisfied.
    Let's say our first clause $C_1$ is $x_1 \lor x_2 \lor \lnot x_3$. So whenever $x_1$ is true i.e we move left to right in row 1, we should 
    be able to visit $C_1$. So what we do is add an edge from vertex 1 in row1 to $C_1$, and an edge from $C_1$ to vertex 2 in row 1. So instead of going straight
    from 1 to 2, we can divert to $C_1$ and come back. Since we have $\lnot x_3$, we need to be able to visit $C_1$ while going from right to left.
    So we add an edge from vertex 2 in row 3 to $C_1$, and an edge from $C_1$ to vertex 1 in row 3. We're only going to use the first and second nodes in each row 
    for $C_1$, these are allocated for $C_1$. Similarly third and fourth nodes are for $C_2$, fifth and sixth nodes are for $C_3$. Why are we keeping
    different nodes for each clause? This is because the same variable can make multiple clauses true, maybe even all clauses so we want to have
    the option of allowing a variable path to visit any number of clauses while moving along the row. Below is how the graph will look after filling
    everything for $C_1$, and also we have the full graph if $C_2$ is $\lnot x_2 \lor x_3 \lor x_4$, and $C_3$ is $x_1 \lor \lnot x_2 \lor x_4$.

    \begin{figure}[H]
            \centering
            \includegraphics[width=0.65\textwidth]{FinalHamiltonian.png}
            \caption*{Graph showing one clause node $c_1$. Image source: Kleinberg and Tardos, Algorithm Design, Chapter 8}
            
    \end{figure}

    Now if we find a Hamiltonian path in the graph, we can easily find out the assignment which works. Just see in which direction we move in 
    each row, and correspondingly assign each variable. This will satisfy the assignment as the Hamiltonian path visits every clause, meaning 
    at least one variable assignment is there to make every clause true. Similarly, if we have a satisfying assignment we'll definitely have a
    Hamiltonian path. We can find out in which direction to move through each row from the assignment. Since the assignment is satisfying, there 
    will be at least 1 variable assignment making each clause true, and whatever that is, we can take a detour there and visit that clause. Since
    we allocated different sections for each variable connecting to each clause, this is feasible.
    % \section{Cook-Levin's Theorem}
\end{document}