\section{History and motivation}

\qquad Justification logic is one of those few subjects in which a historical introduction is more fruitful than a plain exposition of the syntax and the semantics of the logic.

\qquad In the debate around foundations of mathematics one of the philosophical positions that arose was Brouwer's intuitionism. Briefly, intuitionism says that the truth of a mathematical statement should be identified with the proof of that statement. Summarizing the core idea of this position in a slogan: \textit{truth means provability}. Starting from this core idea an informal semantics was created. Now, this semantics is known as Brouwer–Heyting–Kolmogorov (BHK) semantics. It gives an informal meaning to the logical connectives $\bot, \e, \ou, \impli, \nao$ in the following way:

\begin{itemize}
	\item $\bot$ is a proposition which has no proof (an absurdity, e.g. $0=1$).
	\item A proof of $\varphi \e \psi$ consist of a proof of $\varphi$ and a proof of $\psi$.
	\item A proof of $\varphi \ou \psi$ is given by exhibiting either a proof of $\varphi$ or a proof of $\psi$.
	\item A proof of $\varphi \impli \psi$ is a construction which, given a proof of $\varphi$, returns a proof of $\psi$.
	\item A proof of $\nao \varphi$ is a construction which transforms any proof of $\varphi$ into a proof of a contradiction. \footnote{By this definition, we can clearly treat $\nao \varphi$ as an abbreviation of $\varphi \impli \bot$.}
\end{itemize}

\qquad Using this semantics we can give an informal argument to show that some formulas are intuitionistic validities (formulas like $\varphi \impli \varphi$, $\varphi \impli (\psi \impli \varphi)$ and $\bot \impli \varphi$) and show that some formulas that are classical validities are not validities by this interpretation (formulas like $\varphi \ou \nao \varphi$ and $\nao\nao\varphi \impli \varphi$). More important than to decide whether some formula is a validity or not, this semantics gives us a way to grasp the intended reasoning that \textit{intuitionistic logic} (Int) wants to capture.

\qquad The first step toward a formalization of this semantics was given by Gödel in 1933 \cite{Goedel33}. He added a new unary operator $B$ to classical logic; $B\varphi$ should be read as `$\varphi$ is provable' ($B$ stand for `beweisbar', the German word for `provable'). This new operator was added in order to express the notion of provability in classical mathematics. To describe the behavior of this operator Gödel constructed the following calculus:

\begin{itemize}
 \item[] All tautologies
 \item[] $B\varphi \impli \varphi$
 \item[] $B(\varphi \impli \psi) \impli$ $(B\varphi \impli B\psi)$
 \item[] $B\varphi \impli BB\varphi$
 \item[] (\textit{Modus Ponens}) $\teo \varphi$, $\teo \varphi\impli\psi$ $\Rightarrow$ $\teo \psi$
 \item[] (\textit{Internalization})  $\teo \varphi$ $\Rightarrow$ $\teo B\varphi$
\end{itemize}

\qquad Since this axiom system is equivalent to Lewis's S4 when we translate  $B\varphi$ by  $\Box\varphi$, we will refer to this calculus of provability in classical mathematics simply as S4.

\qquad Based on the intuitionistic notion of truth as provability, it is possible to define the following translation from formulas of intuitionistic logic to formulas of S4:
\pagebreak
\begin{itemize}
	\item $p^{B} = Bp$;
	\item $\bot^{B} = \bot$;
	\item $(\varphi \e \psi)^{B} = (\varphi^{B} \e \psi^{B})$;
	\item $(\varphi \ou \psi)^{B} = (\varphi^{B} \ou \psi^{B})$;
	\item $(\varphi \impli \psi)^{B} = B(\varphi^{B} \impli \psi^{B})$.
\end{itemize}

\qquad It was shown by Gödel, McKinsey and Tarski (for all the references see \cite{Artemov06}) that this translation `makes sense', i.e., that the following theorem holds:

\begin{center}
	For every formula $\varphi$, Int $\teo \varphi$ iff S4 $\teo \varphi^{B}$.
\end{center}

\qquad The next step is to give a formal interpretation of the $B$ operator. One natural interpretation is the following: fix a first-order version of Peano Arithmetic (\textbf{PA}); $B$ should be interpreted as the predicate $\ex y Proof (y,x)$ which asserts that there exits a proof (in \textbf{PA}) with Gödel number $y$ for a formula with Gödel number $x$. This predicate has the following property:

\begin{center}
	For every sentence $\varphi$ in the language of \textbf{PA}, $\textbf{PA} \teo \varphi$ iff $Proof (n,\ulcorner \varphi\urcorner)$ holds for some $n$.
\end{center}

\qquad For simplicity, we will use $Prov(x)$ as an abbreviation of $\ex y Proof (y,x)$. Let $*$ be a bijection between the sentences of \textbf{PA} and the propositional variables. We can extend the mapping $*$ to give an arithmetical interpretation of all S4 formulas as follows:

\begin{itemize}
	\item $\bot^{*} = \bot$;
	\item $(\varphi \e \psi)^{*} = (\varphi^{*} \e \psi^{*})$;
	\item $(\varphi \ou \psi)^{*} = (\varphi^{*} \ou \psi^{*})$;
	\item $(\varphi \impli \psi)^{*} = (\varphi^{*} \impli \psi^{*})$;
	\item $(B\varphi)^{*} = Prov(\ulcorner \varphi^{*}\urcorner)$.
\end{itemize}

\qquad On the one hand, it was straightforward how to interpret the modal formulas in the language of \textbf{PA}; on the other hand it was not clear how to give a formal interpretation of this provability calculus (S4) in \textbf{PA}. In \cite{Goedel33} Gödel pointed out that S4 does not correspond to the calculus of the predicate $Prov(x)$ in \textbf{PA}. Simply because S4 proves the formula $B(B(\bot) \impli \bot)$. Using the above translation this formula correspond to $Prov(\ulcorner Prov(\ulcorner\bot\urcorner) \impli \bot\urcorner)$. And since the following sentences are equivalent in \textbf{PA}:

\begin{center}
	$Prov(\ulcorner\bot\urcorner) \impli \bot$\\
	$\nao Prov(\ulcorner\bot\urcorner)$\\
	$Consist(\textbf{PA})$,
\end{center}
$Prov(\ulcorner Prov(\ulcorner\bot\urcorner) \impli \bot\urcorner)$ means that the consistency of \textbf{PA} is internally provable in \textbf{PA}, which contradicts Gödel's Second Incompleteness Theorem.

\qquad In a lecture in 1938 \cite{Goedel38} Gödel suggested a way to remedy this problem. Instead of using the implicit representation of proofs by the existential quantifier in the formula $\ex y Proof (y,x)$ one can use explicit variables for proofs (like $t$) in the formula $Proof (t,x)$. In these lines, Gödel proposed expanding the language of classical propositional logic with variables for proofs and adding the following ternary operator $tB(\varphi,\psi)$ which should be read as `$t$ is a derivation of $\psi$ from $\varphi$'. Using $tB(\varphi)$ as an abbreviation of $tB(\top,\varphi)$, Gödel formulated the following axiom system:

\begin{itemize}
	\item[] All tautologies
	\item[] $tB(\varphi)\impli \varphi$
	\item[] $tB(\varphi,\psi) \impli (sB(\psi,\theta) \impli f(t,s)B(\varphi,\theta))$\footnote{To understand the motivation behind this function $f$ consider the following. Suppose $t$ is a derivation of $\psi$ from $\varphi$ and $s$ is a derivation of $\theta$ from $\psi$. Then it can be easily seen that the concatenation of $t$ and $s$, $t^{\smallfrown}s$, is a derivation of $\theta$ from $\varphi$. So, if $t$ is a derivation of $\psi$ from $\varphi$ and $s$ is a derivation of $\theta$ from $\psi$, then $f(t,s)= t^{\smallfrown}s$.  }
	\item[] $tB(\varphi) \impli t\p B(tB(\varphi))$
	\item[] (\textit{Modus Ponens}) $\teo \varphi$, $\teo \varphi\impli\psi$ $\Rightarrow$ $\teo \psi$
	\item[] (\textit{Internalization})  $\teo \varphi$ $\Rightarrow$ $\teo tB(\varphi)$ (where $t$ is an derivation of $\varphi$).
\end{itemize}

\qquad Gödel just formulated this system but he did not give a proof of how this system could be used to be a bridge between Int and \textbf{PA}. Independently of Gödel's system presented in \cite{Goedel38} (the lecture was published only in 1998), Sergei Artemov (in \cite{Artemov01}) proposed the use of explicit variables and constants for proofs and some basic operations between proofs (Application `$\cdot$', Sum `$+$' and Verifier `$!$'). Instead of having $B\varphi$ (or the more modern notation of provability logic $\Box \varphi$), the non-classical formulas are of the form $t$$:$$\varphi$ (which should be read as `$t$ is a proof of $\varphi$'); where $t$ is a simple or complex term composed of proof variables or constants. With this new language Artemov stipulated the following axiom system to capture the behavior of this explicit provability:

\begin{itemize}
	\item[] All tautologies
	\item[] $t$$:$$\varphi \impli \varphi$
	\item[] $t$$:$$(\varphi \impli \psi) \impli$ $(s$$:$$\varphi \impli$ $[t\cdot s]$$:$$\psi)$
	\item[] $t$$:$$\varphi \impli$ $!t$$:$$t$$:$$\varphi$
	\item[] $t$$:$$\varphi \impli$ $[t+s]$$:$$\varphi$
	\item[] $s$$:$$\varphi \impli$ $[t+s]$$:$$\varphi$
	\item[] (\textit{Modus Ponens}) $\teo \varphi$, $\teo \varphi\impli\psi$ $\Rightarrow$ $\teo \psi$
	\item[] (\textit{axiom necessitation})  $\teo c$$:$$\varphi$, where $\varphi$ is an axiom and $c$ is a justification constant.
\end{itemize}

\qquad This logic was called \textit{Logic of Proofs} (LP) and it was the first example of justification logic.

\qquad If $\varphi$ is a S4 formula, there is a mapping $r$ (called a \textit{realization}) from the occurrences of $B$'s (or boxes) into terms. The result of this mapping on $\varphi$ is denoted $\varphi^{r}$. The following theorem express the connection between S4 and LP:

\textbf{(Realization Theorem between S4 and LP)} For every $\varphi$ in the language of S4, there is a realization $r$ such that

\begin{center}
S4 $\teo \varphi$ iff LP $\teo \varphi^{r}$
\end{center}

\qquad There is a way to define an interpretation $*$ of the LP formulas into the sentences of \textbf{PA} (for details see \cite{Artemov01}). And with all this machinery Artemov was able to prove the following result:

\textbf{(Provability Completeness of Intuitionistic Logic)} For every $\varphi$, for every interpretation $*$, there is a realization $r$ such that

\begin{center}
Int $\teo \varphi$ iff S4 $\teo \varphi^{B}$ iff LP $\teo (\varphi^{B})^{r}$ iff \textbf{PA} $\teo ((\varphi^{B})^{r})^{*}$
\end{center}

\qquad This result shows that instead of the philosophical attitude of understanding intuitionistic logic as a reasoning different from the reasoning that classical logic wants to capture, we can interpret intuitionistic logic as provability in \textit{classical mathematics}. Thus, the primitive notions that appear in the BHK semantics (`proof' and `construction') can have a formal meaning in a classical setting.

\qquad Going beyond the specific problem of the formalization of BHK semantics, justification logic can be seen as a new tool to introduce the notion of \textit{justifications} in the well-established discussion of epistemic logic (for a more detailed discussion see \cite{Artemov08}). Instead of using modal formulas like $\Box \varphi$ to express:

\begin{center}
For a given agent, $\varphi$ is known,
\end{center}
we use justification formulas like $t$$:$$\varphi$ to express:

\begin{center}
For a given agent, $\varphi$ is known for the reason $t$.
\end{center}

\qquad Informally, we can see the terms $t, s, \dots$ as justifications and the operators $+, \cdot, !$ can be seen as means of epistemic action. In fact, this point of view enables us to see justification logic as something bigger than the logic of the explicit provability; justification logic can be seen as a logic of \textit{explicit knowledge}.

\qquad Our main interest in justification logic lies in this connection with epistemic logic. We are not going to focus on the arithmetical interpretation of this logic, instead we are going to work only with the Kripke-style semantics introduced by Melvin Fitting for this logic. But it is important to have the provability interpretation in mind because some of the choices made to formulate specific aspects of justification logic are directly motivated by the relationship with provability logic and the arithmetical interpretation.

\section{The propositional case: language and axiom system}

\begin{defn} (Basic vocabulary)
	\begin{itemize}
		\item $p, q, p\p, q\p, \dots$ (\textit{propositional variables});
		\item $\impli, \bot$ (\textit{boolean connectives});
		\item $x,y,z, \dots \dots$(\textit{justification variables});
		\item $a, b, \dots$, with indices, $1, 2, \dots$ (\textit{justification constants});
		\item $+$, $\cdot$ (\textit{justification operators});
		\item $),($ (\textit{parentheses}).
	\end{itemize}
\end{defn}

\begin{defn} (Justification terms)
	\begin{center}
		$ t :: = x$   $|$ $c$ $|$  $(t \cdot t)$ $|$ $(t + t)$
	\end{center}
\end{defn}

\begin{defn} (Justification formulas)
	\begin{center}
		$ \varphi :: = p$   $|$ $\bot$ $|$  $(\varphi \impli \varphi)$ $|$ $t$$:$$\varphi$
	\end{center}
\end{defn}

\qquad We define $\nao, \e, \see$ and $\ou$ as usual. Sometimes, to help readability, we use the brackets `$],[$' together with `$),($'.

\qquad The minimal justification logic J$_{0}$ is axiomatized by the following axiom schemes and inference rules:\\

All tautologies\\

(\textit{Application Axiom}) $t$$:$$(\varphi \impli \psi) \impli$ $(s$$:$$\varphi \impli$ $[t\cdot s]$$:$$\psi)$\\

(\textit{Sum Axioms}) $t$$:$$\varphi \impli$ $[t+s]$$:$$\varphi$, $s$$:$$\varphi \impli$ $[t+s]$$:$$\varphi$\\

(\textit{Modus Ponens}) $\teo \varphi$, $\teo \varphi\impli\psi$ $\Rightarrow$ $\teo \psi$ \\

(\textit{axiom necessitation})  $\teo c$$:$$\varphi$, where $\varphi$ is an axiom and $c$ is a justification constant.\\

\qquad The notion of derivation in this system, J$_{0}$ $\teo \varphi$, is defined as usual.

\begin{defn}
Let $\C$ be a non-empty set of formulas. We say that $\C$ is a \textit{constant specification}, if for every $\varphi \in \C$, $\varphi = c$$:$$\psi$ where $c$ is a justification constant and $\psi$ is an axiom. A proof meets constant specification $\C$ provided that whenever the inference rule `axiom necessitation' is used to introduce $c$$:$$\psi$, then $c$$:$$\psi \in \C$.

\qquad We say that a constant specification $\C$ is \textit{axiomatically appropriate} if i) for every axiom $\varphi$ there is a justification constant $c_{1}$ such that $c_{1}$$:$$\varphi\in \C$; and ii) if $c_n, c_{n-1}, \dots , c_{1}$$:$$\varphi\in \C$, then $c_{n+1}, c_{n}, \dots , c_{1}$$:$$\varphi\in \C$, for each $n \geq 1$.
\end{defn}

\qquad For a constant specification $\C$, by J$_{\C}$ we mean J$_{0}$ plus formulas from $\C$ as additional axioms.

\begin{teor}
(Internalization) Suppose $\C$ is an axiomatically appropriate constant specification. In these conditions, J$_{\C}$ satisfies internalization. That is, if J$_{\C}$ $\teo \varphi$ then J$_{\C}$ $\teo  t$$:$$\varphi$, for some justification term $t$.
\end{teor}

\qquad There are some well-know examples of justification logic other than J$_{0}$; in this thesis we are going to mention only two of them. The first one is the already mentioned Logic of Proofs (LP): it extends the language of J$_{0}$ with the unary justification operator $!$ and has the following additional axiom schemes:\\

(\textit{Factivity Axiom}) $t$$:$$\varphi \impli \varphi$\\

(\textit{Positive Introspection Axiom}) $t$$:$$\varphi \impli$ $!t$$:$$t$$:$$\varphi$\\

\qquad The second one is called JT45, it extends the language of LP with the unary justification operator $?$ and has the following additional axiom scheme:\\

(\textit{Negative Introspection Axiom}) $\nao t$$:$$\varphi \impli$ $?t$$:$$\nao t$$:$$\varphi$\\

\qquad We have stated the Internalization Theorem above for J$_{0}$, but this theorem also holds for LP and JT45. Because of the Positive Introspection Axiom we can prove this result for LP and JT45 with a weaker notion of axiomatically appropriate constant specification $\C$. In both of these logics we just say that a constant specification $\C$ is axiomatically appropriate if for every axiom $\varphi$ there is a justification constant $c$ such that $c$$:$$\varphi\in \C$. It should be noted that the Internalization Theorem is just an explicit form of the necessitation rule.

\qquad Informally speaking, the \textit{forgetful projection} of a justification formula $\varphi$, denoted $\varphi^{\circ}$, is the result of replacing every subformula $t$$:$$\psi$ with $\Box\psi$. We also commented on the notion of \textit{realization}. With these two notions we can state more clearly the relationship between modal logic and justification logic.

\begin{defn}
Suppose KL is a normal modal logic and let JL be a justification logic mentioned above. We say that JL is a \textit{counterpart} of KL if the following holds:

\begin{itemize}
\item  If JL $\teo \varphi$, then KL $\teo \varphi^{\circ}$.
\item  If KL $\teo \varphi$, then there is a realization $r$ such that JL $\teo \varphi^{r}$.
\end{itemize}
\end{defn}

\qquad It can be proved that for an axiomatically appropriate constant specification $\C$:

\begin{center}
J$_{\C}$ is a counterpart of K\\

LP is a counterpart of S4\\

JT45 is a counterpart of S5
\end{center}

\section{From propositional logic to first-order}

\qquad Before we start presenting the first-order version of JT45 we need to remember some properties of derivations in classical first-order logic. It is useful to remember these details, because first-order justification logic tries to mirror some aspects of the individual variables in classical first-order derivations.

\qquad Let $\varphi(x)$ be any tautology, and let $t$ be the following derivation:

\begin{enumerate}[1.]
	\item $\varphi(x)$
	\item $\todo x \varphi(x)$                 (generalization)
	\item $\todo x\varphi(x) \impli (Px \impli \todo x\varphi(x))$ (tautology)
	\item $Px \impli \todo x\varphi(x)$ (Modus Ponens)
\end{enumerate}

\qquad Although $x$ is free in the formula $Px \impli \todo x\varphi(x)$, if $c$ is an individual term we cannot substitute $c$ for $x$ in $t$ in order to obtain a derivation $t(c / x)$ of $Pc \impli \todo x\varphi(x)$ (if we do that we ruin the derivation at 2).

\qquad Now, let $s$ be the following derivation:

\begin{enumerate}[1.]
\item $\varphi(x)$
\item $\todo x \varphi(x)$                 (generalization)
\item $\todo x\varphi(x) \impli (Py \impli \todo x\varphi(x))$ (tautology)
\item $Py \impli \todo x\varphi(x)$ (Modus Ponens)
\end{enumerate}

\qquad $y$ is free in the formula $Py \impli \todo x\varphi(x)$ and moreover for every individual term $c$ the result of substituting $c$ for $y$ in $s$, $s(c/y)$, is a  derivation of $Pc \impli \todo x\varphi(x)$.

\qquad These examples show us that there are two different roles of variables in a derivation: a variable can be a \textit{formal symbol} that can be subjected to generalization or a \textit{place-holder} that can be substituted for. In $t$, $x$ is both a formal symbol and a place-holder. And in $s$, $x$ is a formal symbol and $y$ is a place-holder.

\qquad This consideration motivates the following definition:

\begin{center}
$x$ \textit{is free in the derivation} $t$ of the formula $\varphi$ iff for every individual term $c$, $t(c/x)$ is a derivation of $\varphi(c/x)$.
\end{center}

\qquad In propositional justification logic we write $t$$: $$\varphi$ to express that $t$ is a derivation of $\varphi$. In order to represent the distinct roles of variables in first-order justification logic, we are going to write formulas of the form:

\begin{center}
$t$$:$$Px \impli \todo x\varphi(x)$\\
$s$$:_{\{y\}}$$Py \impli \todo x\varphi(x)$
\end{center}

\qquad The role of $\{y\}$ in $s$$:_{\{y\}}$$Py \impli \todo x\varphi(x)$ is to point out that $y$ is free in the derivation $s$ of $Py \impli \todo x\varphi(x)$.


\section{Brief History of Burgers' Equation}

    The simplest fluids (called Newtonian fluids), are described by the well-known Navier-Stokes equations, named after Claude-Louis Navier and George Gabriel Stokes. These are a set of non-linear (PDEs), which are obtained by applying the principles of conservation of mechanics and thermodynamics on a volume of fluid to obtain the so-called integral formulation of the equations. Applying certain considerations, especially those in which the tangential forces have a linear relationship with the velocity gradient (Newton's viscosity law), the differential formulation is obtained which is generally more useful for solving the problems that arise in the mechanics of fluids. For further details about the Navier-Stokes equations see \cite{Acheson2001, Batchelor1967, Landau1987, Currie1974, Temam1984}. \\

    Let $v$ be a vector field, Navier-Stokes equations are given as follows
    \begin{equation}
        \left \lbrace \begin{array}{ll}
    	\nabla \cdot v = 0, \\
    	(\rho v)_t + (\nabla \cdot \rho v) v + \nabla p - \mu \nabla^2 v - \rho G = 0.
    	\end{array}  \right .
    	\label{navierstokes}
    \end{equation}
    It is well known that when $\rho$ is considered the density, $p$ the pressure, $v$ the velocity and $\mu$ the viscosity of a fluid, these equations describe the dynamics of an incompressible fluid (free divergence, and $\rho_t = 0$), where $G$ represents the gravitational effects. \\

    In contrast to equation (\ref{navierstokes}), this can be investigated in one spatial dimension. Simplification in (\ref{navierstokes}) of the $x$ component of the velocity vector, which we will call $v^x$, gives
    \begin{equation*}
        \rho \frac{\partial v^x}{\partial t} + \rho v^x \frac{\partial v^x}{\partial x} + \rho v^y \frac{\partial v^x}{\partial y} + \rho v^z \frac{\partial v^x}{\partial z} + \frac{\partial p}{\partial x} - \mu \left(\frac{\partial^2 v^x}{\partial x^2} + \frac{\partial^2 v^x}{\partial y^2} + \frac{\partial^2 v^x}{\partial z^2} \right) - \rho G^x = 0.
    \end{equation*}

    \noindent Considering a $1D$ problem with no pressure gradient, the above equation reduces to\\
    \begin{equation}
        \rho \frac{\partial v^x}{\partial t} + \rho v^x \frac{\partial v^x}{\partial x} - \mu \frac{\partial^2 v^x}{\partial x^2} - \rho G^x = 0.
        \label{1.2}
    \end{equation}
    If we use now the traditional variable $v$ rather than $v^x$, take $\alpha$ to be the kinematic viscosity, i.e, $\alpha = \frac{\mu}{\rho}$ and $G \equiv 0$, then the equation (\ref{1.2}) becomes just the viscid Burgers' equation
    \begin{equation}
    \label{Burgers_Equation}
        \frac{\partial v(x, t)}{\partial t} +  \underbrace{v(x, t) \frac{\partial v(x, t)}{\partial x}}_{\textbf{Convection}} - \underbrace{\alpha \frac{\partial^2 v(x, t)}{\partial x^2}}_{\textbf{Diffusion}} = 0.
    \end{equation}

    Some assumptions  are  made,  namely: $\rho =$ constant (density), $\mu =$ constant  (viscosity),  $p=$ constant (pressure). \\

    Burgers' equation was introduced in 1915 by Harry Bateman \cite{Bateman1915}, an English mathematician, in his paper along with its corresponding initial condition and boundary values. Later in 1939, Johannes Martinus Burgers \cite{Burgers1939,Burgers1948}, a Dutch physicist, simplified the Navier-Stokes equation (\ref{navierstokes}) by just dropping the pressure term, and in 1948 explained the  mathematical modeling of turbulence with the help of the equation (\ref{Burgers_Equation}). The name of this equation is because Burgers became one of the leading figures in the field of fluid mechanics and, therefore, honors his contributions. \\

    The equation (\ref{Burgers_Equation}) is a partial differential equation nonlinear, where the second term is known as the convective part of the equation and the third as the diffusive part. This equation appears in several areas of applied mathematics, such as fluid mechanics, nonlinear acoustics, gas dynamics, traffic flow, and many others. It is generally considered a toy model, i.e., a tool that is used to understand part of the internal behavior of the general problem.  \\

    The formulation given by the equation (\ref{Burgers_Equation}) is called the strong form, i.e., the partial differential equation requires that it be satisfied for each point $x$ in its domain and for each $t$. This formulation can be written as follows
    \begin{equation}
    	\frac{\partial v}{\partial t} + A(v) + F(v) = 0, \hspace{2mm} t > 0,
    	\label{strong}
    \end{equation}
	where $F$ and $A$ are given by
	\begin{equation*}
		A(v) = - \alpha v_{xx}, \hspace{3mm} F(v) = \frac{1}{2} (v^2)_x , \hspace{3mm} x \in I.
	\end{equation*}
	Multiplying both sides of (\ref{strong}) by $\phi \in X$, for some arbitrary smooth function $\phi$ of compact support, such that the integral of the PDE over the space $I$ is satisfied, we get
    \begin{equation}
    	\displaystyle \int_{I} \frac{\partial v}{\partial t} \phi dx + \int_{I} A(v) \phi dx + \int_{I} F(v) \phi dx = 0, \hspace{2mm} \forall \phi \in X,\hspace{2mm} \forall t > 0.
    	\label{weak}
    \end{equation}
	The formulation (\ref{weak}) is called the weak form of (\ref{Burgers_Equation}) and $\phi$ are known as the test functions.  If we denote $\langle \cdot, \cdot \rangle$ as the inner product in $X$, then (\ref{weak}) can be written in compact form as follows
    \begin{equation}
    	\left \langle \frac{\partial v}{\partial t} + A(v) + F(v), \phi\right\rangle = 0, \hspace{2mm} \forall \phi \in X, \hspace{2mm} \forall t > 0.
    	\label{compact_weak}
    \end{equation}
	Note that the two formulations, (\ref{weak}) and (\ref{strong}), are equivalent if the solution is smooth enough, however the weak formulation can adjust less regular solutions than in the strong form. In fact, the solution to (\ref {weak}) is known as the distribution solution of the original equation (\ref{Burgers_Equation}), since it can be shown to satisfy (\ref{Burgers_Equation}) in the sense of distributions. For more details of the above it is recommended to see Schwartz \cite{Schwartz1966}, Lions and Magenes \cite{Lions1972}, Renardy and Rogers \cite{Renardy1993}. \\

	Proper use of these formulations allows one to recover the strong form from the weak form, therefore, an appropriate way to design a numerical method is to first choose one of the formulations satisfied by the exact solution, then restrict the choice of test functions to a space of finite dimension, to replace $u$ with the discrete solution $u_N$, and possibly to replace the exact integration with quadrature rules. \\

    \subsection{Analytical solutions for Burgers' equation.}

    When we want to know the precision of an approximation, an alternative is through numerical experiments that can be compared with some other solution considered as a good reference. For this type of tests, the better is to have exact solutions to compare with an approximate one, and fortunately the equation (\ref{Burgers_Equation}) can be solved exactly by Hopf-Cole transformation introduced by Eberhard Hopf \cite{Hopf1950} and Julian David Cole \cite{Cole1951} independently to convert the Burgers' equation into a linear parabolic equation and solve it exactly for any initial condition. \\

   	\noindent Now consider the problem of initial value for the equation (\ref{Burgers_Equation}) as follows
    \begin{equation}
        \left \lbrace \begin{array}{ll}
    	u_t + u u_x = \alpha u_{xx} & x \in \mathbb{R}, \hspace{2mm} t > 0, \hspace{2mm} \alpha > 0 \\
    	u (x, 0) = u_0 (x)  & x \in \mathbb{R},
    	\end{array}  \right .
    	\label{IVP}
    \end{equation}
	Hence, the transformation known as the Cole-Hopf transformation is given by
    \begin{equation}
        u = -2 \alpha \frac{\varphi_x}{\varphi}
        \label{Hopf_tranform}
    \end{equation}
    Operating (\ref{Hopf_tranform}) into each term of (\ref{IVP}) we find that
    \begin{equation*}
        u_t = \frac{2 \alpha (\varphi_t \varphi_x - \varphi \varphi_{x t})}{\varphi^2} \hspace{2mm} , \hspace{2mm} u u_x = \frac{4 \alpha^2 \varphi_x (\varphi \varphi_{xx} - \varphi^2_x)}{\varphi^3},
    \end{equation*}
    and
    \begin{equation*}
        \alpha u_{xx} = - \frac{2 \alpha^2 (2 \varphi_x^3 - 3 \varphi \varphi_{xx} \varphi_x + \varphi^2 \varphi_{xxx})}{\varphi^3}.
    \end{equation*}
    Substituting these expressions into (\ref{IVP}),
    \begin{align*}
        \frac{2 \alpha (-\varphi \varphi_{x t} +  \varphi_x ( \varphi_t - \alpha \varphi_{xx}) + \alpha \varphi \varphi_{xxx})}{\varphi^2} = 0,
    \end{align*}
	so we have the following,
	\begin{align*}
        - \varphi \varphi_{x t} + \varphi_x (\varphi_t - \alpha \varphi_{xx}) + \alpha \varphi \varphi_{xxx} = 0 &\Longleftrightarrow \varphi_x (\varphi_t - \alpha \varphi_{xx}) = \varphi (\varphi_{x t} - \alpha \varphi_{xxx}) \\
        &\Longleftrightarrow \varphi_x (\varphi_t - \alpha \varphi_{xx}) =  \varphi (\varphi_t - \alpha \varphi_{xx})_x.
    \end{align*}
    Therefore, if $\varphi$ solves the equation $\varphi_t - \alpha \varphi_{xx} = 0$, $x \in \mathbb{R}$, then $u(x, t)$ given by the transformation (\ref{Hopf_tranform}) solves the Burgers equation.\\

    \noindent To completely transform the problem (\ref{IVP}) we still have to work with the initial condition function. To do this, note that (\ref{Hopf_tranform}) can be written as
    \begin{equation}
        u = -2 \alpha (\log \varphi)_x,
        \label{Hopf2}
    \end{equation}

    \noindent hence, we get
    \begin{equation*}
        \varphi (x, t) = \displaystyle e^{- \int \frac{u(x, t)}{2 \alpha} dx}.
    \end{equation*}
    It is clear from (\ref{Hopf2}) that multiplying $\varphi$ by a constant does not affect $u$, so we can write the last equation as
    \begin{equation}
        \varphi (x, t) = \displaystyle e^{- \int_{0}^{x} \frac{u(y, t)}{2 \alpha} dy}.
        \label{phi}
    \end{equation}
    The initial condition on (\ref{IVP}) must be transformed by using (\ref{Hopf2}) to get
    \begin{equation*}
        \varphi (x, 0) = \varphi_0 (x) = \displaystyle e^{- \int_{0}^{x} \frac{u_0 (y)}{2 \alpha} dy}.
    \end{equation*}
    In summary, we have reduced the problem (\ref{IVP}) to this one
    \begin{equation}
        \left \lbrace \begin{array}{ll}
    	\varphi_t - \alpha \varphi_{xx} = 0,  & x \in \mathbb{R}, \hspace{2mm} t > 0, \hspace{2mm} \alpha > 0, \\
    	\varphi (x, 0) = \varphi_0 (x) = \displaystyle e^{- \int_{0}^{x} \frac{u_0 (y)}{2 \alpha} dy}, & x \in \mathbb{R}.
    	\end{array}  \right .
    \label{heat}
    \end{equation}
    \paragraph{Parabolic Equation.} The general solution of the initial value problem for the equation (\ref{heat}) is well known and can be handled by a variety of methods. An interesting method related to spectral methods is the following: one can take the Fourier transform with respect to $x$ for both the equation and the initial condition $\varphi_0 (x)$ to obtain a first-order (ODE) as follows
    \begin{equation*}
        \left \lbrace \begin{array}{ll}
    	\hat{\varphi}_t = \xi^2 \alpha \hat{\varphi},  & \xi \in \mathbb{R}, \hspace{2mm} t > 0, \hspace{2mm} \alpha > 0, \\
    	\hat{\varphi} (\xi, 0) = \hat{\varphi}_0 (\xi), & \xi \in \mathbb{R},
    	\end{array}  \right .
    \end{equation*}
    where $\hat{\varphi} (\xi, t) = \displaystyle \int_{-\infty}^{\infty} \varphi (x, t) e^{i \xi x} dx $. \\

    \noindent Then the solution for this problem is
    \begin{equation*}
         \hat{\varphi} (\xi, t) =  \hat{\varphi}_0 (\xi) e^{ \xi^2 \alpha t}.
    \end{equation*}

    \noindent To recover $\varphi (x, t)$ we have to use the inverse Fourier transformation $F^{-1}$ , namely,
    \begin{equation*}
        \varphi (x, t) = F^{-1} (\hat{\varphi} (\xi, t)) = F^{-1} (\hat{\varphi}_0 e^{\xi^2 \alpha t}) = \varphi_0 (x) \ast F^{-1} (e^{\xi^2 \alpha t}),
    \end{equation*}
    where $\ast$ denotes the convolution product.\\

    \noindent On the other hand
    \begin{equation*}
        F^{-1} (e^{\xi^2 \alpha t}) = \frac{1}{2 \sqrt{\pi \alpha t}} e^{- \frac{x^2}{4 \alpha t}},
    \end{equation*}
    so the initial value problem (\ref{heat}) has the analytic solution
    \begin{equation*}
        \varphi (x, t) = \frac{1}{2 \sqrt{\pi \alpha t}} \displaystyle \int_{-\infty}^{\infty} \varphi_0 (\xi) e^{- \frac{(x - \xi)^2}{4 \alpha t}} d\xi.
    \end{equation*}
    Finally, from (\ref{Hopf_tranform}), we obtain the analytic solution for the problem (\ref{IVP})
    \begin{equation}
    \label{Exact_Solution}
        u (x, t) =  \displaystyle \frac{\int_{-\infty}^{\infty} \frac{x - \xi}{t} \varphi_0 (\xi) e^{- \frac{(x - \xi)^2}{4 \alpha t}} d\xi}{\int_{-\infty}^{\infty} \varphi_0 (\xi) e^{- \frac{(x - \xi)^2}{4 \alpha t}} d\xi}.
    \end{equation}

    However, the previous solution cannot always be calculated explicitly and we must implement some numerical integration method very efficiently to obtain a good approximation.

    \begin{figure}[H]
    	\centering
    	\includegraphics[width=11cm]{introduction/figures/Exact_Solution_alpha=001.png}
    	\caption{Exact solution for (\ref{IVP}) with initial condition $u_0 (x) = e^{-0.05x^2}$ using the equation (\ref{Exact_Solution}) for $x \in [-60, 60]$, $t \in [0, 100]$, and $\alpha = 0.01$.}
    	\label{Exact_Solution_alpha=0.01}
    \end{figure}


\documentclass[12pt]{article}
\usepackage[usenames]{color} %used for font color
\usepackage{amsmath, amssymb, amsthm}
\usepackage{wasysym}
\usepackage[utf8]{inputenc} %useful to type directly diacritic characters
\usepackage{graphicx}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{float}
\usepackage{mathtools}
\usepackage [english]{babel}
\usepackage [autostyle, english = american]{csquotes}
\MakeOuterQuote{"}
\graphicspath{ {./} }
\newcommand{\Z}{\mathbb{Z}}
\newcommand{\N}{\mathbb{N}}
\newcommand{\R}{\mathbb{R}}
\newcommand{\Q}{\mathbb{Q}}
\newcommand{\prob}{\mathbb{P}}
\newcommand{\degrees}{^{\circ}}
\DeclarePairedDelimiter\ceil{\lceil}{\rceil}
\DeclarePairedDelimiter\floor{\lfloor}{\rfloor}

\author{Tianshuang (Ethan) Qiu}
\begin{document}

\section{Mon Dis, 2c}
Let $a\leq b \leq c \leq d$, we can do this since $\N$ is ordered. We rearrange $a+b+c+d = abcd$ to $a+b+c = d(abc-1)$
\newline
Since we have assumed an order, we have $a+b+c \leq 3d$, so $abc-1 \leq 3$, $abc \leq 4$
\newline
Now in this case $abc$ can only be $1,2,3,4$. We consider each of these cases:
\newline
$abc = 1 \implies a=1, b=1, c=1$, solving for our original equation gives $3 = 0d$, which does not have a solution.
\newline
$abc = 2$, by our assumed order we have $a=1, b=1, c=2$, and we solve $2d=4+d$, $d=4$, this gives a solution.
\newline
$abc = 3$, by our assumed order we have $a=1, b=1, c=3$, and we solve $3d=5+d$, which does not have an integer solution.
\newline
$abc = 4$, by our assumed order we have $a_0=1, b_0=1, c_0=4$, or $a_1=1, b_1 = 2, b_2=2$. Solving the first equation gives $d = 2$, which contradicts our assumption of $c \leq d$, so this is not a solution. Solving the latter gives $4d = 5+d$, which does not have an integer solution.
\newline
So finally we have our solution: rearrangements of $1,1,2,4$ is the only natural solution to this system.

\section{Mon Dis, 4g}
$$(7,29) \to (7+1,29+1) = (8, 30) \to (4, 15)$$
$$(4,15) \to (4+11, 15+11) = (15, 26)$$
$$(7,29) \to (7+19, 29+19) = (26, 48)$$
$$((4, 15), (15,26)) \to (4, 26)$$
$$((4,26), (26,48)) \to (4,48)$$
$$(4, 48) \to (2, 24) \to (1, 12)$$

\end{document}


\ignore{
\documentstyle[11pt]{report}
\textwidth 13.7cm
\textheight 21.5cm
\newcommand{\myimp}{\verb+ :- +}
\newcommand{\ignore}[1]{}
\def\definitionname{Definition}

\makeindex
\begin{document}
}
\chapter{\label{chapter:tabling}Tabling}
The Picat system is a term-rewriting system. For a predicate call, Picat selects a matching rule and rewrites the call into the body of the rule. For a function call $C$, Picat rewrites the equation $C = X$ where $X$ is a variable that holds the return value of $C$. Due to the existence of recursion in programs, the term-rewriting process may never terminate. Consider, for example, the following program:
\begin{verbatim}
    reach(X,Y) ?=> edge(X,Y).
    reach(X,Y) => reach(X,Z),edge(Z,Y).
\end{verbatim}
where the predicate \texttt{edge} defines a relation, and the predicate \texttt{reach} defines the transitive closure of the relation. For a query such as \texttt{reach(a,X)}, the program never terminates due to the existence of left-recursion in the second rule. Even if the rule is converted to right-recursion, the query may still not terminate if the graph that is represented by the relation contains cycles.

Another issue with recursion is redundancy. Consider the following problem: \emph{Starting in the top left corner of a $N\times N$ grid, one can either go rightward or downward. How many routes are there through the grid to the bottom right corner?} The following gives a program in Picat for the problem:
\begin{verbatim}
    route(N,N,_Col) = 1.
    route(N,_Row,N) = 1.
    route(N,Row,Col) = route(N,Row+1,Col)+route(N,Row,Col+1).
\end{verbatim}
The function call \texttt{route(20,1,1)} returns the number of routes through a 20$\times$20 grid. The function call \texttt{route(N,1,1)} takes exponential time in \texttt{N}, because the same function calls are repeatedly spawned during the execution, and are repeatedly resolved each time that they are spawned.

\section{Table Declarations}
Tabling\index{tabling} is a memoization technique that can prevent infinite loops and redundancy. The idea of tabling\index{tabling} is to memorize the answers to subgoals and use the answers to resolve their variant descendants. In Picat, in order to have all of the calls and answers of a predicate or function tabled\index{tabling}, users just need to add the keyword \texttt{table}\index{\texttt{table}} before the first rule.

\subsection*{Example}
\begin{verbatim}
    table
    reach(X,Y) ?=> edge(X,Y).
    reach(X,Y) => reach(X,Z),edge(Z,Y).

    table
    route(N,N,_Col) = 1.
    route(N,_Row,N) = 1.
    route(N,Row,Col) = route(N,Row+1,Col)+route(N,Row,Col+1).
\end{verbatim}
With tabling\index{tabling}, all queries to the \texttt{reach} predicate are guaranteed to terminate, and the function call \texttt{route(N,1,1)} takes only \texttt{N}$^2$ time.

For some problems, such as planning problems, it is infeasible to table\index{tabling} all answers, because there may be an infinite number of answers. For some other problems, such as those that require the computation of aggregates, it is a waste to table\index{tabling} non-contributing answers. Picat allows users to provide table modes\index{mode-directed tabling} to instruct the system about which answers to table\index{tabling}. For a tabled\index{tabling} predicate, users can give a \emph{table mode declaration}\index{mode-directed tabling} in the form ($M_{1},M_{2},\ldots,M_{n}$), where each $M_{i}$ is one of the following: a plus-sign (+) indicates input, a minus-sign (-) indicates output, \texttt{max} indicates that the corresponding variable should be maximized, and \texttt{min} indicates that the corresponding variable should be minimized. The last mode $M_{n}$ can be \texttt{nt}, which indicates that the argument is not tabled. Two types of data can be passed to a tabled predicate as an \texttt{nt} argument: (1) global data that are the same to all the calls of the predicate, and (2) data that are functionally dependent on the input arguments. Input arguments are assumed to be ground.  Output arguments, including \texttt{min} and \texttt{max} arguments, are assumed to be variables. An argument with the mode \texttt{min} or \texttt{max} is called an \emph{objective} argument. Only one argument can be an objective to be optimized. As an objective argument can be a compound value, this limit is not essential, and users can still specify multiple objective variables to be optimized. When a table mode\index{mode-directed tabling} declaration is provided, Picat tables\index{tabling} only one optimal answer for the same input arguments.

\subsection*{Example}
\begin{verbatim}
    table(+,+,-,min)
    sp(X,Y,Path,W) ?=>
        Path = [(X,Y)],
        edge(X,Y,W).
    sp(X,Y,Path,W) =>
        Path = [(X,Z)|Path1],
        edge(X,Z,Wxz),
        sp(Z,Y,Path1,W1),
        W = Wxz+W1.
\end{verbatim}
The predicate \texttt{edge(X,Y,W)} specifies a weighted directed graph, where \texttt{W} is the weight of the edge between node \texttt{X} and node \texttt{Y}. The predicate \texttt{sp(X,Y,Path,W)} states that \texttt{Path} is a path from \texttt{X} to \texttt{Y} with the minimum weight \texttt{W}. Note that whenever the predicate \texttt{ sp/4} is called, the first two arguments must always be instantiated. For each pair, the system stores only one path with the minimum weight.

The following program finds a shortest path among those with the minimum weight for each pair of nodes:
\begin{verbatim}
    table (+,+,-,min).
    sp(X,Y,Path,WL) ?=>
        Path = [(X,Y)],
        WL = (Wxy,1),
        edge(X,Y,Wxy).
    sp(X,Y,Path,WL) =>
        Path = [(X,Z)|Path1],
        edge(X,Z,Wxz),
        sp(Z,Y,Path1,WL1),
        WL1 = (Wzy,Len1),
        WL = (Wxz+Wzy,Len1+1).
\end{verbatim}
For each pair of nodes, the pair of variables \texttt{(W,Len)} is minimized, where \texttt{W} is the weight, and \texttt{Len} is the length of a path. The built-in function \texttt{compare\_terms($T_1$,$T_2$)} is used to compare answers. Note that the order is important. If the term would be \texttt{(Len,W)}, then the program would find a shortest path, breaking a tie by selecting one with the minimum weight.

The tabling system is useful for offering dynamic programming solutions for planning problems. The following shows a tabled program for general planning problems:
\begin{verbatim}
    table (+,-,min)
    plan(S,Plan,Len),final(S) => Plan=[],Len=0.
    plan(S,Plan,Len) =>
        action(Action,S,S1),
        plan(S1,Plan1,Len1),
        Plan = [Action|Plan1],
        Len = Len1+1.
\end{verbatim}
The predicate \texttt{action(Action,S,S1)} selects an action and performs the action on state \texttt{S} to generate another state, \texttt{S1}.

\subsection*{Example}
The program shown in Figure \ref{fig:farmer} solves the Farmer's problem: {\em The farmer wants to get his goat, wolf, and cabbage to the other side of the river. His boat isn't very big, and it can only carry him and either his goat, his wolf, or his cabbage. If he leaves the goat alone with the cabbage, then the goat will gobble up the cabbage. If he leaves the wolf alone with the goat, then the wolf will gobble up the goat. When the farmer is present, the goat and cabbage are safe from being gobbled up by their predators.}

\begin{figure}
\begin{center}
\begin{verbatim}
    go =>
        S0=[s,s,s,s],
        plan(S0,Plan,_),
        writeln(Plan.reverse()).

    table (+,-,min)
    plan([n,n,n,n],Plan,Len) => Plan=[], Len=0.
    plan(S,Plan,Len) =>
        Plan=[Action|Plan1],
        action(S,S1,Action),
        plan(S1,Plan1,Len1),
        Len=Len1+1.

    action([F,F,G,C],S1,Action) ?=>
        Action=farmer_wolf,
        opposite(F,F1),
        S1=[F1,F1,G,C],
        not unsafe(S1).
    action([F,W,F,C],S1,Action) ?=>
        Action=farmer_goat,
        opposite(F,F1),
        S1=[F1,W,F1,C],
        not unsafe(S1).
    action([F,W,G,F],S1,Action) ?=>
        Action=farmer_cabbage,
        opposite(F,F1),
        S1=[F1,W,G,F1],
        not unsafe(S1).
    action([F,W,G,C],S1,Action) ?=>
        Action=farmer_alone,
        opposite(F,F1),
        S1=[F1,W,G,C],
        not unsafe(S1).

    index (+,-) (-,+)
    opposite(n,s).
    opposite(s,n).

    unsafe([F,W,G,_C]),W==G,F!==W => true.
    unsafe([F,_W,G,C]),G==C,F!==G => true.
\end{verbatim}
\end{center}
\caption{\label{fig:farmer}A program for the Farmer's problem.}
\end{figure}

\section{The Tabling Mechanism}
The Picat tabling\index{tabling} system employs the so-called \emph{linear tabling}\index{linear tabling} mechanism, which computes fixpoints by iteratively evaluating looping subgoals. The system uses a data area, called the \emph{table area}\index{tabling}, to store tabled\index{tabling} subgoals and their answers. The tabling area can be initialized with the following built-in predicate:

\begin{itemize}
\item \texttt{initialize\_table}\index{\texttt{initialize\_table/0}}: This predicate initializes the table area.
\end{itemize}
This predicate clears up the table area. It's the user's responsibility to ensure that no data in the table area are referenced by any part of the application.

Linear tabling relies on the following three primitive operations to access and update the table\index{tabling} area.

\begin{description}
\item[Subgoal lookup and registration:] This operation is used when a tabled\index{tabling} subgoal is encountered during execution. It looks up the subgoal table\index{tabling} to see if there is a variant of the subgoal. If not, it inserts the subgoal (termed a \emph{pioneer} or \emph{generator}) into the subgoal table\index{tabling}. It also allocates an answer table\index{tabling} for the subgoal and its variants. Initially, the answer table\index{tabling} is empty. If the lookup finds that there already is a variant of the subgoal in the table\index{tabling}, then the record that is stored in the table\index{tabling} is used for the subgoal (called a \emph{consumer}). Generators and consumers are handled differently. In linear tabling\index{linear tabling}, a generator is resolved using rules, and a consumer is resolved using answers; a generator is iterated until the fixed point is reached, and a consumer fails after it exhausts all of the existing answers.
\item[Answer lookup and registration:] This operation is executed when a rule succeeds in generating an answer for a tabled\index{tabling} subgoal. If a variant of the answer already exists in the table\index{tabling}, then it does nothing; otherwise, it inserts the answer into the answer table\index{tabling} for the subgoal, or it tables\index{tabling} the answer according to the mode declaration. Picat uses the lazy consumption strategy (also called the local strategy). After an answer is processed, the system backtracks to produce the next answer.
\item[Answer return:] When a consumer is encountered, an answer is returned immediately, if an answer exists. On backtracking, the next answer is returned. A generator starts consuming its answers after it has exhausted all of its rules. Under the lazy consumption strategy, a top-most looping generator does not return any answer until it is complete.
\end{description}

\ignore{
\section{Initialization of the Table Area}
\begin{itemize}
\item \texttt{table\_get\_all($Goal$) = $List$}\index{\texttt{table\_get\_all/1}}:  This function returns a list of answers of the subgoals that are subsumed by $Goal$. For example, the \texttt{table\_get\_all(\_)}\index{\texttt{table\_get\_all/1}} fetches all of the answers in the table\index{tabling}, since any subgoal is subsumed by the anonymous variable\index{anonymous variable}.
\item \texttt{table\_get\_one($Goal$)}\index{\texttt{table\_get\_one/1}}: If there is a subgoal in the subgoal table\index{tabling} that is a variant of \texttt{$Goal$}, and that has answers, then \texttt{$Goal$} is unified with the first answer. This predicate fails if there is no variant subgoal in the table\index{tabling}, or if there is no answer available.
\end{itemize}
}

\ignore{
\end{document}
}


\subsection{The value function of a policy}

\subsubsection{Other}

\(P(s_{t+1}|H)=P(s_{t+1}|s_t=s, a_t=a)=P_{s,a}\)

\(E[r_t|H]=E[r_t|s_t=s, a_t=a]=R_{s,a}\)

\subsubsection{Optimal policies}

Expected return is greater or identical to any other policy.


% Copyright 2018-2021 Melvin Eloy Irizarry-Gelpí
\setcounter{chapter}{9}
\chapter{Diffraction}
%
In this experiment you will learn about diffraction of light from a laser due to a single slit.
%
\section{Preliminary}
%
When light passes through a double slit, an interference pattern is produced. The physical mechanism responsible for this is \textbf{diffraction}. The \textbf{interference pattern} arises as the combination of the \textbf{diffraction pattern} from each slit in the double slit.

You looked at interference patterns from a double slit in the previous experiment: A collection of dark and bright fringes. A diffraction pattern is similar, but has less structure (e.g. no ``internal'' fringes). For the interference pattern, you found that the distance between nearby \textbf{peaks} was almost constant and close to the theoretical value
\begin{equation}
    \Delta y \approx \frac{\ell \lambda}{d}
\end{equation}
Here $\ell$ is the longitudinal distance between the slit and the screen where the pattern appears, $\lambda$ is the wavelength of the laser light, and $d$ is the separation between the two slits. If the distance between nearby peaks is the same, then it follows that the distance $y_{n}$ from the central peak to the $n$-th peak is given by
\begin{equation}
    y_{n} \approx \frac{n \ell \lambda}{d}
\end{equation}
There is an analogous result for a diffraction pattern from a single slit. However, for a single slit there is no slit separation $d$, so instead the \textbf{slit width} $a$ plays a role:
\begin{equation}
    x_{n} \approx \frac{n \ell \lambda}{a}
\end{equation}
The interpretation is also different: $x_{n}$ is now the distance from the central peak to the $n$-th dark region (valley). In order to emphasize this subtle difference, I encourage you to use $y$ for distance \textbf{from the center to a bright peak}, and $x$ for distance \textbf{from the center to a dark valley}.
%
\subsection{Intensity}
%
Since the interference and diffraction patterns involve dark and bright regions, it is useful to measure the brightness along the screen. In your experiment this is done with a light intensity sensor. For practical purposes, light intensity is measured in units of percentage (\%). Dark regions have small percentage of intensity, and bright regions have large percentages. One observation about the intensity of the many bright regions in a pattern is that the intensity appears to change from peak to peak. For single slit diffraction there is a particular prediction for the ratio of the intensity of bright peaks. Let $I_{0}$ be the intensity of the central bright peak, $I_{1}$ be the intensity of the first bright peak, and $I_{2}$ be the intensity of the second bright peak. Then you expect that
\begin{align}
    \frac{I_{1}}{I_{0}} = 0.045 && \frac{I_{2}}{I_{0}} = 0.016
\end{align}
That is, the intensity of the first bright peak away from the center should be about 4.5\% the intensity of the central bright peak. Similarly, the intensity of the second bright peak away from the center should be about 1.6\% the intensity of the central bright peak. These relations should hold for bright peaks on both sides.
%
\section{Experiment}
%
The experiment consisted of collecting light intensity data for diffraction patterns from different single slits:
\begin{itemize}
    \item Single slit with $a = 0.08$ mm
    \item Single slit with $a = 0.04$ mm
    \item Single slit with $a = 0.16$ mm
\end{itemize}
For each single slit configuration you should have two runs, for consistency.
%
\section{Analysis}
%
The analysis for this experiment is very similar to the analysis in the previous experiment with the interference pattern. The main difference is that you need to find the position of dark valleys now, instead of bright peaks before.
%
\section{My Data}
%
For my data I used the \textbf{red laser}, so the wavelength value is 6.35{ }\texttimes{ }10\textsuperscript{\textminus 4} mm. I also collected data for the $a = 0.02$ mm slit (runs 7 and 8).
%
\section{Your Data}
%
For your data you used the \textbf{green laser}, so the wavelength value is 5.32{ }\texttimes{ }10\textsuperscript{\textminus 4} mm.
%
% \newpage
% \section{Your Report}
% %
% Your report should include the following:
% \begin{itemize}
%     \item A table like Table \ref{table.11.results.12} with the distance values for the $a = 0.08$ mm slit (either run 1 or run 2).
%     \item A table like Table \ref{table.11.results.34} with the distance values for the $a = 0.04$ mm slit (either run 4 or run 4).
%     \item A table like Table \ref{table.11.results.56} with the distance values for the $a = 0.16$ mm slit (either run 5 or run 6).
%     \item A table like Table \ref{table.11.intensity.8} with the intensity ratios for the $a = 0.08$ mm slit (either run 1 or run 2).
%     \item A table like Table \ref{table.11.intensity.4} with the intensity ratios for the $a = 0.04$ mm slit (either run 3 or run 4).
%     \item A table like Table \ref{table.11.intensity.16} with the intensity ratios for the $a = 0.16$ mm slit (either run 5 or run 6).
%     \item A chart like Figure \ref{figure.11.chart1} with the intensity profile for the $a = 0.08$ mm slit (either run 1 or run 2).
%     \item A chart like Figure \ref{figure.11.chart2} with the intensity profile for the $a = 0.04$ mm slit (either run 3 or run 4).
%     \item A chart like Figure \ref{figure.11.chart3} with the intensity profile for the $a = 0.16$ mm slit (either run 5 or run 6).
%     \item Which diffraction slit yields the dark valleys that are closest to the central bright peak?
%     \item Which diffraction slit yields the dark valleys that are farthest to the central bright peak?
% \end{itemize}
%
\newpage
\section{Tables}
%
\begin{table}[ht!]
    \centering
    \begin{tabular}{l|r}
        \textbf{Feature} & \textbf{Position} (mm) \\
        \hline
        Valley 3L & 50.08 \\
        Valley 2L & 57.32 \\
        Valley 1L & 65.11 \\
        \hline
        Peak 0C & 72.77 \\
        \hline
        Valley 1R & 79.8 \\
        Valley 2R & 87.29 \\
        Valley 3R & 94.61 \\
        \hline
    \end{tabular}
    \caption{Positions for Run 2 ($a = 0.08$ mm)}
    \label{table.11.pos.12}
\end{table}
%
\begin{table}[ht!]
    \centering
    \begin{tabular}{l|r}
        \textbf{Feature} & \textbf{Position} (mm) \\
        \hline
        Valley 2L & 51.73 \\
        Valley 1L & 65.19 \\
        \hline
        Peak 0C & 81.15 \\
        \hline
        Valley 1R & 95.46 \\
        Valley 2R & 109.98 \\
        \hline
    \end{tabular}
    \caption{Positions for Run 4 ($a = 0.04$ mm)}
    \label{table.11.pos.34}
\end{table}
%
\begin{table}[ht!]
    \centering
    \begin{tabular}{l|r}
        \textbf{Feature} & \textbf{Position} (mm) \\
        \hline
        Valley 3L & 66.8 \\
        Valley 2L & 70.57 \\
        Valley 1L & 74.34 \\
        \hline
        Peak 0C & 77.94 \\
        \hline
        Valley 1R & 81.66 \\
        Valley 2R & 85.43 \\
        Valley 3R & 89.24 \\
        \hline
    \end{tabular}
    \caption{Positions for Run 5 ($a = 0.16$ mm)}
    \label{table.11.pos.56}
\end{table}
%
\newpage
\begin{table}[ht!]
    \centering
    \begin{tabular}{l|r}
        \textbf{Difference} & \textbf{Distance} (mm) \\
        \hline
        Valley 3L -- Peak 0C & \textminus 22.69 \\
        Valley 2L -- Peak 0C & \textminus 15.45 \\
        Valley 1L -- Peak 0C & \textminus 7.66 \\
        \hline
        Valley 1R -- Peak 0C & 7.03 \\
        Valley 2R -- Peak 0C & 14.52 \\
        Valley 3R -- Peak 0C & 21.84 \\
        \hline
    \end{tabular}
    \caption{Distances for Run 2 ($a = 0.08$ mm)}
    \label{tablel.11.dis.12}
\end{table}
%
\begin{table}[ht!]
    \centering
    \begin{tabular}{l|r}
        \textbf{Difference} & \textbf{Distance} (mm) \\
        \hline
        Valley 2L -- Peak 0C & \textminus 29.42 \\
        Valley 1L -- Peak 0C & \textminus 15.96 \\
        \hline
        Valley 1R -- Peak 0C & 14.31 \\
        Valley 2R -- Peak 0C & 28.83 \\
        \hline
    \end{tabular}
    \caption{Distances for Run 4 ($a = 0.04$ mm)}
    \label{tablel.11.dis.34}
\end{table}
%
\begin{table}[ht!]
    \centering
    \begin{tabular}{l|r}
        \textbf{Difference} & \textbf{Distance} (mm) \\
        \hline
        Valley 3L -- Peak 0C & \textminus 11.14 \\
        Valley 2L -- Peak 0C & \textminus 7.37 \\
        Valley 1L -- Peak 0C & \textminus 3.6 \\
        \hline
        Valley 1R -- Peak 0C & 3.72 \\
        Valley 2R -- Peak 0C & 7.49 \\
        Valley 3R -- Peak 0C & 11.3 \\
        \hline
    \end{tabular}
    \caption{Distances for Run 5 ($a = 0.16$ mm)}
    \label{tablel.11.dis.56}
\end{table}
%
\newpage
\begin{table}[ht!]
    \centering
    \begin{tabular}{l|r|r|r}
        $n$ & \textbf{Observed} $x_{n}$ (mm) & \textbf{Expected} $x_{n}$ (mm) & \textbf{P.D.} (\%) \\
        \hline
        \textminus 3 & \textminus 22.69 & \textminus 22.38 & 1.37 \\
        \textminus 2 & \textminus 15.45 & \textminus 14.92 & 3.53 \\
        \textminus 1 & \textminus 7.66 & \textminus 7.46 & 2.66 \\
        \hline
        +1 & 7.03 & 7.46 & \textminus 5.78 \\
        +2 & 14.52 & 14.92 & \textminus 2.70 \\
        +3 & 21.84 & 22.38 & \textminus 2.43 \\
        \hline
    \end{tabular}
    \caption{Results for Run 2 ($a = 0.08$ mm)}
    \label{table.11.results.12}
\end{table}
%
\begin{table}[ht!]
    \centering
    \begin{tabular}{l|r|r|r}
        $n$ & \textbf{Observed} $x_{n}$ (mm) & \textbf{Expected} $x_{n}$ (mm) & \textbf{P.D.} (\%) \\
        \hline
        \textminus 2 & \textminus 29.42 & \textminus 29.85 & \textminus 1.42 \\
        \textminus 1 & \textminus 15.96 & \textminus 14.92 & 6.95 \\
        \hline
        +1 & 14.31 & 14.92 & \textminus 4.10 \\
        +2 & 28.83 & 29.85 & \textminus 3.40 \\
        \hline
    \end{tabular}
    \caption{Results for Run 4 ($a = 0.04$ mm)}
    \label{table.11.results.34}
\end{table}
%
\begin{table}[ht!]
    \centering
    \begin{tabular}{l|r|r|r}
        $n$ & \textbf{Observed} $x_{n}$ (mm) & \textbf{Expected} $x_{n}$ (mm) & \textbf{P.D.} (\%) \\
        \hline
        \textminus 3 & \textminus 11.14 & \textminus 11.19 & \textminus 0.46 \\
        \textminus 2 & \textminus 7.37 & \textminus 7.46 & \textminus 1.22 \\
        \textminus 1 & \textminus 3.6 & \textminus 3.73 & \textminus 3.50 \\
        \hline
        +1 & 3.72 & 3.73 & \textminus 0.28 \\
        +2 & 7.49 & 7.46 & 0.39 \\
        +3 & 11.3 & 11.19 & 0.97 \\
        \hline
    \end{tabular}
    \caption{Results for Run 5 ($a = 0.16$ mm)}
    \label{table.11.results.56}
\end{table}
%
\newpage
\begin{table}[ht!]
    \centering
    \begin{tabular}{l|r}
        \textbf{Ratio} & \textbf{Value} \\
        \hline
        $I_{\text{3L}} / I_{\text{0C}}$ & 0.017 \\
        $I_{\text{2L}} / I_{\text{0C}}$ & 0.025 \\
        $I_{\text{1L}} / I_{\text{0C}}$ & 0.055 \\
        \hline
        $I_{\text{1R}} / I_{\text{0C}}$ & 0.065 \\
        $I_{\text{2R}} / I_{\text{0C}}$ & 0.031 \\
        $I_{\text{3R}} / I_{\text{0C}}$ & 0.021 \\
        \hline
    \end{tabular}
    \caption{Intensity ratios for Run 2 ($a = 0.08$ mm)}
    \label{table.11.intensity.8}
\end{table}
%
\begin{table}[ht!]
    \centering
    \begin{tabular}{l|r}
        \textbf{Ratio} & \textbf{Value} \\
        \hline
        $I_{\text{1L}} / I_{\text{0C}}$ & 0.086 \\
        \hline
        $I_{\text{1R}} / I_{\text{0C}}$ & 0.099 \\
        \hline
    \end{tabular}
    \caption{Intensity ratios for Run 4 ($a = 0.04$ mm)}
    \label{table.11.intensity.4}
\end{table}
%
\begin{table}[ht!]
    \centering
    \begin{tabular}{l|r}
        \textbf{Ratio} & \textbf{Value} \\
        \hline
        $I_{\text{3L}} / I_{\text{0C}}$ & 0.010 \\
        $I_{\text{2L}} / I_{\text{0C}}$ & 0.020 \\
        $I_{\text{1L}} / I_{\text{0C}}$ & 0.051 \\
        \hline
        $I_{\text{1R}} / I_{\text{0C}}$ & 0.059 \\
        $I_{\text{2R}} / I_{\text{0C}}$ & 0.025 \\
        $I_{\text{3L}} / I_{\text{0C}}$ & 0.014 \\
        \hline
    \end{tabular}
    \caption{Intensity ratios for Run 5 ($a = 0.16$ mm)}
    \label{table.11.intensity.16}
\end{table}
%
\FloatBarrier
\newpage
\section{Figures}
%
\begin{figure}[ht!]
	\centering
	\includegraphics[scale=0.74]{image/11-diffraction/chart1.pdf}
	\caption{Intensity for diffraction pattern with $a = 0.08$ mm.}
	\label{figure.11.chart1}
\end{figure}
%
\begin{figure}[ht!]
	\centering
	\includegraphics[scale=0.74]{image/11-diffraction/chart2.pdf}
	\caption{Intensity for diffraction pattern with $a = 0.04$ mm.}
	\label{figure.11.chart2}
\end{figure}
%
\begin{figure}[ht!]
	\centering
	\includegraphics[scale=0.74]{image/11-diffraction/chart3.pdf}
	\caption{Intensity for diffraction pattern with $a = 0.16$ mm.}
	\label{figure.11.chart3}
\end{figure}
%


\documentclass{article}
\usepackage{enumerate}
\usepackage{amsmath, amsthm, amssymb}
\usepackage[margin=1in]{geometry}
\usepackage[parfill]{parskip}

\title{Econ C103 Problem Set 2}
\author{Sahil Chinoy}

\begin{document}
\maketitle{}

\subsection*{Exercise 1}

\begin{enumerate}[(a)]

	\item

	In this context, a mechanism consists of

	\begin{itemize}

		\item A set of messages $M$.

		\item A rule that maps from the set of messages to the (real-valued) tax the worker pays $t: M \rightarrow \mathbb{R}$.

		\item A rule that maps from the set of messages to the type of job the worker has $x: M \rightarrow \{l,h\}$.

	\end{itemize}

	\item

	A direct mechanism is one in which the worker reports their ability $\theta$. This implies $M = [\underline{\theta}, \bar{\theta}]$.

	\item

	An incentive compatible direct mechanism is one in which it is always optimal for the worker to tell the truth about their ability, that is, $x(m) = x(\theta)$. This implies

	\begin{equation*}
	w_{x(\theta)} - t(\theta) - \frac{x(\theta)}{
	\theta} \geq \max_m \left \{ w_{x(m)} - t(m) - \frac{x(m)}{\theta} \right \}
	\end{equation*}

	\item

	Incentive compatibility implies that an individual with true ability $\theta$ should prefer to report $\theta \neq \theta'$.

	\begin{equation*}
	w_{x(\theta)} - t(\theta) - \frac{x(\theta)}{
	\theta} \geq w_{x(\theta')} - t(\theta') - \frac{x(\theta')}{
	\theta}
	\end{equation*}
	\begin{equation}
	\frac{1}{\theta} (x(\theta') - x(\theta)) \geq w_{x(\theta')} - t(\theta') - (w_{x(\theta)} - t(\theta))
	\end{equation}

	Likewise, an individual with true ability $\theta'$ should prefer to report $\theta' \neq \theta$.

	\begin{equation*}
	w_{x(\theta')} - t(\theta') - \frac{x(\theta')}{
	\theta'} \geq w_{x(\theta)} - t(\theta) - \frac{x(\theta)}{
	\theta'}
	\end{equation*}
	\begin{equation}
	\frac{1}{\theta'} (x(\theta) - x(\theta')) \geq w_{x(\theta)} - t(\theta) - (w_{x(\theta')} - t(\theta'))
	\end{equation}

	Adding (1) and (2)

	\begin{equation*}
	(\frac{1}{\theta} - \frac{1}{\theta'})(x(\theta') - x(\theta)) \geq 0
	\end{equation*}

	Since $0 \leq \underline{\theta}$, both $\theta$ and $\theta'$ are positive, so we can rearrange to find

	\begin{equation*}
	(\theta'- \theta)(x(\theta') - x(\theta)) \geq 0
	\end{equation*}

	Thus, for $\theta' > \theta$, $x(\theta') > x(\theta)$. This proves $x(\theta)$ is monotonically increasing.

	\item

	Since $x = \{l,h\}$, we define $\theta_0 = \sup \{ \theta: x(\theta) = l \}$. Since a worker will always report the type that leads to the lowest taxes, the tax can only depend on the type of job the worker has, not on their ability.

	\begin{equation*}
	t(\theta) =  \begin{cases}
	      t_1, &\theta > \theta_0 \\
	      t_0, & \theta < \theta_0
	   \end{cases}
	\end{equation*}

	Workers with ability $\theta < \theta_0$ should prefer the low-intensity job and associated tax

	\begin{equation}
		w_l - t_0 - \frac{l}{\theta_0} \geq w_h - t_1 - \frac{h}{\theta_0}
	\end{equation}

	Likewise, workers with ability $\theta > \theta_0$ should prefer the high-intensity job and associated tax

	\begin{equation}
		w_l - t_0 - \frac{l}{\theta_0} \leq w_h - t_1 - \frac{h}{\theta_0}
	\end{equation}

	Combining (3) and (4)

	\begin{equation*}
		w_l - t_0 - \frac{l}{\theta_0} = w_h - t_1 - \frac{h}{\theta_0}
	\end{equation*}
	\begin{equation*}
		t_1 = t_0 + (w_h - w_l) - \frac{h-l}{\theta_0}
	\end{equation*}

	So

	\begin{equation*}
	t(\theta) =  \begin{cases}
	      t_0 + (w_h - w_l) - \frac{h-l}{\theta_0}, &\theta > \theta_0 \\
	      t_0, & \theta < \theta_0
	   \end{cases}
	\end{equation*}

	\item

	Since the outcome of any mechanism can be implemented in an incentive-compatible direct mechanism, the set of outcomes that can be implemented in any mechanism is characterized by the job allocation rule

	\begin{equation*}
	x(\theta) =  \begin{cases}
	      h, &\theta > \theta_0 \\
	      l, & \theta < \theta_0
	   \end{cases}
	\end{equation*}

	And the taxation rule

	\begin{equation*}
	t(\theta) =  \begin{cases}
	      t_0 + (w_h - w_l) - \frac{h-l}{\theta_0}, &\theta > \theta_0 \\
	      t_0, & \theta < \theta_0
	   \end{cases}
	\end{equation*}

	\item

	Consider an indirect mechanism where the worker decides between high and low intensity jobs and reports only their wage $w_x \in \mathbb{R}$. Then $M = \mathbb{R}$. One outcome that can be implemented in this mechanism is a uniform tax $\tau$ on wages

	\begin{equation*}
	t(w_x) = \tau w_x
	\end{equation*}

	The allocation rule is meaningless, since the worker decides their own job.

	\item

	The participation constraint implies the agent has positive utility in all cases

	\begin{equation*}
	\max_m \left \{ w_{x(m)} - t(m) - \frac{x(m)}{\theta} \right \} \geq 0
	\end{equation*}

	In the context of taxation, this means that wages net of taxes and the cost of effort from working must be positive. If we consider a world in which unemployment is an option, i.e. the worker can choose to hold no job, receive no wage, and pay no tax ($x = w_x = t =0$), then the participation constraint is binding in the sense that an agent can opt for unemployment and thereby refuse to participate in the mechanism. If we require that everyone hold a job and pay taxes, then the participation constraint does not apply.

	\item

	For $l = w_l = 0$, we have

	\begin{equation*}
	E[t] = F(\theta_0) t_0 + (1 - F(\theta_0)) (t_0 + w_h - \frac{h}{\theta_0})
	\end{equation*}

	If we restrict ourselves to mechanisms where $t \leq w_{x(\theta)}$, then $t_0 \leq 0$, since $w_l = 0$. Clearly, the expected tax revenue is increasing in $t_0$, so the maximum expected revenue occurs for $t_0 = 0$. This implies a tax structure

	\begin{equation*}
	t(\theta) =  \begin{cases}
	      w_h - \frac{h}{\theta_0}, &\theta > \theta_0 \\
	      0, & \theta < \theta_0
	   \end{cases}
	\end{equation*}

	\item

	When $t=0$, the worker will choose the high intensity job if

	\begin{equation*}
	w_h - \frac{h}{\theta} > 0
	\end{equation*}
	\begin{equation*}
	\theta > \frac{h}{w_h}
	\end{equation*}

	With $w_h = 4$ and $h = 1$, workers with ability $\theta > \frac{1}{4}$ will choose the high intensity job. Given that $\theta$ is uniformly distributed, this implies the worker will choose the high intensity job with probability $\frac{3}{4}$.

	\item

	With $t_0 = 0$, $w_h = 4$, $h=1$, $F(\theta) = \theta$

	\begin{equation*}
	E[t] = (1 - \theta_0) (4 - \frac{1}{\theta_0}) = 5 - 4\theta_0 - \frac{1}{\theta_0}
	\end{equation*}

	The expected revenue is maximized for $\frac{d E[t]}{d \theta_0} = 0$

	\begin{equation*}
	-4 + \frac{1}{\theta_0^2} = 0
	\end{equation*}
	\begin{equation*}
	\theta_0 = \frac{1}{2}
	\end{equation*}

	So, workers with ability $\theta > \frac{1}{2}$ will choose the high intensity job. Given that $\theta$ is uniformly distributed, this implies the worker will choose the high intensity job with probability $\frac{1}{2}$.

\end{enumerate}

\end{document}


\section{NT Functions and Polynomials}

\begin{Remark}
    The main idea for most NT FEs is to take aid from LARGE integers on the
    left side of the divisibility.
\end{Remark}

\prob{https://artofproblemsolving.com/community/c6h597243p3544096}{ISL 2013 N1}{E}{Let $\mathbb{Z} _{>0}$ be the set of positive integers. Find all functions $f: \mathbb{Z} _{>0}\rightarrow \mathbb{Z} _{>0}$ such that
    \[ m^2 + f(n) \mid mf(m) +n \]
for all positive integers $m$ and $n$.}

\solu{Go with the flow.}

\prob{https://artofproblemsolving.com/community/c6h356076p1935854}{ISL 2010 N5}{M}{Find all functions $g:\mathbb{N}\rightarrow\mathbb{N}$ such that \[\left(g(m)+n\right)\left(g(n)+m\right)\] is a perfect square for all $m,n\in\mathbb{N}.$}

\solu{Playig around with some primes give us that for every ``big'' primes, we need to have every residue class present in the range of $ g $. Now with this fact, we can prove the injectivity as well. Now we want to show that $ g(n+1)=g(n)+1 $. How to show that? We can show that by saying that no prime $ p $ exits such that $ p|g(n+1)-g(n) $, in other words, again the residue classes.}

\prob{https://artofproblemsolving.com/community/c6h27188p169519}{ISL 2004 N3}{E}{Find all functions $ f: \N\to\N$ satisfying
    \[ \left. \left(f\left(m\right)^{2}+f\left(n\right)\right) \right|
        \left(m^{2}+n\right)^{2}\]
for any two positive integers $ m$ and $ n$.}

\begin{solution}
    First get $ f(1)=1 $, then using casework, get $ f(p-1)=p-1 $. Then let $
    m=(p-1) $, and use the division algorithm to reduce the dividend.
\end{solution}

\begin{Remark}
    In nt-fe s with ``divisible'' condition, one occurring idea is to get an
    infinite set of integers with the desired output value, and somehow keep
    those numbers only in the divisor, and make them vanish from the dividend.
    Most of the time, using division algorithm to reduce the dividend does the
    trick.
\end{Remark}

\prob{https://artofproblemsolving.com/community/c6h355799p1932945}{ISL 2009 N5}{E}{Let $P(x)$ be a non-constant polynomial with integer coefficients. Prove that there is no function $T$ from the set of integers into the set of integers such that the number of integers $x$ with $T^n(x)=x$ is equal to $P(n)$ for every $n\geq 1$, where $T^n$ denotes the $n$-fold application of $T$.}

\solu{Write down what the problem is actually saying. Integer functions are like cycles, use that.}

\prob{}
{ISL 2019 N4}{M}{
    Find all functions $f:\mathbb{N} \to \mathbb{N}$ such that for all $a, b
    \in \mathbb{N}, a+b < C$ for some constant $C$, we have
    \[a + f(b) | a^2 + bf(a)\]
}

\begin{solution}
    The main idea is to get primes on the left hand side somehow. We want to
    show for primes, $p|f(p)$.
\end{solution}


\section{Formal ledger rules}
\label{sec:model}

\begin{ruledfigure}{t}
  \begin{displaymath}
    \begin{array}{rll}
      \B{} && \mbox{the type of Booleans}\\
      \N{} && \mbox{the type of natural numbers}\\
      \Z{} && \mbox{the type of integers}\\
      \H{} && \mbox{the type of bytestrings: } \bigcup_{n=0}^{\infty}\{0,1\}^{8n}\\
      (\phi_1 : T_1, \ldots, \phi_n : T_n) && \mbox{a record type with fields $\phi_1, \ldots, \phi_n$ of types $T_1, \ldots, T_n$}\\
      t.\phi && \mbox{the value of $\phi$ for $t$, where $t$ has type $T$ and $\phi$ is a field of $T$}\\
      \Set{T} && \mbox{the type of (finite) sets over $T$}\\
      \List{T} && \mbox{the type of lists over $T$, with $\_[\_]$ as indexing and $|\_|$ as length}\\
      h::t && \mbox{the list with head $h$ and tail $t$}\\
      x \mapsto f(x) && \mbox{an anonymous function}\\
      \hash{c} && \mbox{a cryptographic collision-resistant hash of $c$}\\
      \Interval{A} && \mbox{the type of intervals over a totally-ordered set $A$}\\
      \FinSup{K}{M} && \mbox{the type of finitely supported functions from a type $K$ to a monoid $M$}
    \end{array}
  \end{displaymath}
  \caption{Basic types and notation}
  \label{fig:basic-types}
\end{ruledfigure}
%
Our formal ledger model follows the style of the UTXO-with-scripts model from~\cite{Zahnentferner18-UTxO} adopting the notation from~\cite{eutxo-1-paper} with basic types defined as in Figure~\ref{fig:basic-types}.

\paragraph{Finitely-supported functions.}
\label{sec:fsfs}
%
We model token bundles as finitely-supported functions.
If $K$ is any type and $M$ is a monoid with identity element $0$, then a function $f: K \rightarrow M$ is \textit{finitely supported} if $f(k) \ne 0$ for only finitely many $k \in K$.
More precisely, for $f: K \rightarrow M$ we define the \textit{support} of $f$ to be
%%
$\supp(f) = \{k \in K : f(k) \ne 0\}$
%%
and
%%
$\FinSup{K}{M} = \{f : K \rightarrow M : \left|\supp(f)\right| < \infty \}$.
%%

If $(M,+,0)$ is a monoid then $\FinSup{K}{M}$ also becomes a monoid if we define addition pointwise (i.e., $(f+g)(k) = f(k) + g(k)$), with the identity element being the zero map.
Furthermore, if $M$ is an abelian group then $\FinSup{K}{M}$ is also an abelian group under this construction, with $(-f)(k) = -f(k)$.
Similarly, if $M$ is partially ordered, then so is $\FinSup{K}{M}$ with comparison defined pointwise: $f \leq g$ if and only if $f(k) \leq g(k)$ for all $k \in K$.

It follows that if $M$ is a (partially ordered) monoid or abelian group then so is $\FinSup{K}{\FinSup{L}{M}}$ for any two sets of keys $K$ and $L$.
We will make use of this fact in the validation rules presented later in the paper (see Figure~\ref{fig:validity}).
Finitely-supported functions are easily implemented as finite maps, with a failed map lookup corresponding to returning 0.

\subsection{Ledger types}

%
\begin{ruledfigure}{htb}
  \begin{displaymath}
    \begin{array}{rll}
      \multicolumn{3}{l}{\textsc{Ledger primitives}}\\
      \Quantity && \mbox{an amount of currency, forming an abelian group (typically \Z{})}\\
      \Asset && \mbox{a type consisting of identifiers for individual asset classes}\\
      \Tick && \mbox{a tick}\\
      \Address && \mbox{an ``address'' in the blockchain}\\
      \TxId && \mbox{the identifier of a transaction}\\
      \txId : \utxotx \rightarrow \TxId && \mbox{a function computing the identifier of a transaction}\\
      \lookupTx : \Ledger \times \TxId \rightarrow \utxotx && \mbox{retrieve the unique transaction with a given identifier}\\
      \verify : \PublicKey\times\H\times\H \rightarrow \B && \mbox{signature verification}\\
      \FPScript && \mbox{forging policy scripts}\\
      \scriptAddr : \Script \rightarrow \Address && \mbox{the address of a script}\\
      \applyScript{\_} : \Script \to (\Address \times \utxotx \times \Set{\Output}) \to
      \B && \mbox{apply script inside brackets to its arguments}\\
    \\
    \multicolumn{3}{l}{\textsc{Ledger types}} \\
    \Policy &=& \Address \qquad \mbox{(an identifier for a custom currency)}\\
    \Signature &=& \H\\
    \\
    \Quantities   &=& \FinSup{\Policy}{\FinSup{\Asset}{\Quantity}}\\
    \\
    \Output &=& (\addr: \Address, \val: \Quantities)\\
    \\
    \OutputRef &=& (\txrefid: \TxId, \idx: \s{Int})\\
    \\
    \Input &=& ( \outputref : \OutputRef\\
             & &\ \validator: \Script)\\
    \\
    \utxotx &=&(\inputs: \Set{\Input},\\
               & &\ \outputs: \List{\Output},\\
               & &\ \validityInterval: \Interval{\Tick},\\
               & &\ \forge: \Quantities\\
               & &\ \scripts: \Set{\FPScript},\\
               & &\ \sigs: \Set{\Signature})\\
    \\
    \Ledger &=&\!\List{\utxotx}\\
    \end{array}
  \end{displaymath}
  \caption{Ledger primitives and basic types}
  \label{fig:ledger-types}
\end{ruledfigure}
%
Figure~\ref{fig:ledger-types} defines the ledger primitives and types that we need to define the \UTXOma\ model.
All outputs use a pay-to-script-hash scheme, where an output is locked with the hash of a script. We use a single scripting language for forging policies and to define output locking scripts. Just as in Bitcoin, this is a restricted domain-specific language (and not a general-purpose language); the details follow in Section~\ref{sec:fps-language}.
We assume that each transaction has a unique identifier derived from its value by a hash function. This is the basis of the $\lookupTx$ function to look up a transaction, given its unique identifier.

\paragraph{Token bundles.}

We generalise per-output transferred quantities from a plain \Quantity\ to a bundle of \Quantities.
A \Quantities{} represents a token bundle: it is a mapping from a policy and an \emph{asset}, which defines the asset class, to a \Quantity{} of that asset.\footnote{
  We have chosen to represent \Quantities{} as a finitely-supported function whose values are themselves finitely-supported functions (in an implementation, this would be a nested map).
  We did this to make the definition of the rules simpler (in particular Rule~\ref{rule:forging}).
  However, it could equally well be defined as a finitely-supported function from tuples of \Policy{}s and \Asset{}s to \Quantity{}s.
}
Since a \Quantities\ is indexed in this way, it can represent any combination of tokens from any assets (hence why we call it a token \emph{bundle}).

\paragraph{Asset groups and forging policy scripts.}

A key concept is the \emph{asset group}.
An asset group is identified by the hash of special script that controls the creation and destruction of asset tokens of that asset group.
We call this script the \emph{forging policy script}.

\paragraph{Forging.}

Each transaction gets a $\forge$ field, which simply modifies the required balance of the transaction by the $\Quantities$ inside it: thus a positive $\forge$ field indicates the creation of new tokens.
In contrast to outputs, $\Quantities$ in forge fields can
also be negative, which effectively burns existing tokens.\footnote{
The restriction on outputs is enforced by Rule~\ref{rule:all-outputs-are-non-negative}.  We simply do not impose such a restriction on the $\forge$ field: this lets us define rules in a simpler way, with cleaner notation. }

Additionally, transactions get a $\scripts$ field holding a set of forging policy scripts: \(\Set{\FPScript}\).
This provides the forging policy scripts that are required as part of validation when tokens are minted or destroyed (see Rule~\ref{rule:forging} in Figure~\ref{fig:validity}). The forging scripts of the assets being forged are
executed and the transaction is only considered valid if the execution of the script returns $\true$.
A forging policy script is executed in a context that provides access to the main components of the forging transaction, the UTXOs it spends, and the policy ID.
The passing of the context provides a crucial piece of the puzzle regarding self-identification: it includes the script's own $\Policy$, which avoids the problem of trying to include the hash of a script inside itself.

\paragraph{Validity intervals.}
\label{para:validity-intervals}

A transaction's \emph{validity interval} field contains an interval of ticks (monotonically increasing units of ``time'', from~\cite{eutxo-1-paper}).
The validity interval states that the transaction must only be validated if the current tick is within the interval. The validity interval, rather than the actual current chain tick value, must be used
for script validation. In an otherwise valid transaction, passing the current
tick to the evaluator
could result in different script validation outcomes at different ticks, which
would be problematic.

\paragraph{Language clauses.}

In our choice of the set of predicates $\texttt{p1, ..., pn}$ to include in the
scripting language definition, we adhere to the following heuristic: we only
admit predicates with quantification over finite structures
passed to the evaluator in the transaction-specific data, i.e. sets,
maps, and lists. The computations we allow in the predicates themselves are well-known
computable functions, such as hashing, signature checking, arithmetic operations, comparisons,
etc.

The gamut of policies expressible in the model we propose here is
fully determined by the collection of predicates,
assembled into a single script by logical connectives
\texttt{\&\&}, \texttt{||}, and \texttt{Not}.
Despite being made up of only hard-coded predicates and connectives,
the resulting policies can be quite
expressive, as we will demonstrate in the upcoming applications section.
When specifying forging predicates, we use $\texttt{tx.\_}$ notation to access
the fields of a transaction.

\subsection{Transaction validity}
\label{sec:validity}

\begin{ruledfigure}{t}
  \begin{displaymath}
  \begin{array}{lll}
  \multicolumn{3}{l}{\txunspent : \utxotx \rightarrow \Set{\s{OutputRef}}}\\
  \txunspent(t) &=& \{(\txId(t),1), \ldots, (\txId(id),\left|t.outputs\right|)\}\\
  \\
  \multicolumn{3}{l}{\unspent : \s{Ledger} \rightarrow \Set{\s{OutputRef}}}\\
  \unspent([]) &=& \emptymap \\
  \unspent(t::l) &=& (\unspent(l) \setminus t.\inputs) \cup \txunspent(t)\\
  \\
  \multicolumn{3}{l}{\getSpent : \s{Input} \times \s{Ledger} \rightarrow \s{Output}}\\
  \getSpent(i,l) &=& \lookupTx(l, i.\outputref.\id).\outputs[i.\outputref.\idx]
  \end{array}
  \end{displaymath}
  \caption{Auxiliary validation functions}
  \label{fig:validation-functions}
\end{ruledfigure}
%
\begin{ruledfigure}{t}
\begin{enumerate}

\item
  \label{rule:slot-in-range}
  \textbf{The current tick is within the validity interval}
  \begin{displaymath}
    \msf{currentTick} \in t.\i{validityInterval}
  \end{displaymath}

\item
  \label{rule:all-outputs-are-non-negative}
  \textbf{All outputs have non-negative values}
  \begin{displaymath}
    \textrm{For all } o \in t.\outputs,\ o.\val \geq 0
  \end{displaymath}

\item
  \label{rule:all-inputs-refer-to-unspent-outputs}
  \textbf{All inputs refer to unspent outputs}
  \begin{displaymath}
    \{i.\outputref: i \in t.\inputs \} \subseteq \unspent(l).
  \end{displaymath}

\item
  \label{rule:value-is-preserved}
  \textbf{Value is preserved}
  \begin{displaymath}
    t.\forge + \sum_{i \in t.\inputs} \getSpent(i, l) = \sum_{o \in t.\outputs} o.\val
  \end{displaymath}

\item
  \label{rule:no-double-spending}
  \textbf{No output is double spent}
  \begin{displaymath}
    \textrm{If } i_1, i \in t.\inputs \textrm{ and }  i_1.\outputref = i.\outputref
    \textrm{ then } i_1 = i.
  \end{displaymath}

\item
  \label{rule:all-inputs-validate}
  \textbf{All inputs validate}
  \begin{displaymath}
    \textrm{For all } i \in t.\inputs,\
    \applyScript{i.\validator}(\scriptAddr(i.\validator), t,
    \{\getSpent(i, l) ~\vert~ i~\in~ t.\inputs\}) = \true
  \end{displaymath}

\item
  \label{rule:validator-scripts-hash}
  \textbf{Validator scripts match output addresses}
  \begin{displaymath}
    \textrm{For all } i \in t.\inputs,\ \scriptAddr(i.\validator) = \getSpent(i, l).\addr
  \end{displaymath}

\item
  \label{rule:forging}
  \textbf{Forging}\\
  A transaction with a non-zero \forge{} field is only
  valid if either:
  \begin{enumerate}
  \item the ledger $l$ is empty (that is, if it is the initial transaction).
  \item \label{rule:custom-forge}
    for every key $h \in \supp(t.\forge)$, there
    exists $s \in t.\scripts$ with
    $h = \scriptAddr(s)$.
  \end{enumerate}
  \medskip
  % ^ There's no space between these items without this, but all the other items have space due to \displaymath

\item
  \label{rule:all-mps-validate}
  \textbf{All scripts validate}
  \begin{displaymath}
    \textrm{For all } s \in t.\scripts,\ \applyScript{s}(\scriptAddr(s), t,
    \{\getSpent(i, l) ~\vert~ i~\in~ t.\inputs\}) = \true
  \end{displaymath}

\end{enumerate}
\caption{Validity of a transaction $t$ in a ledger $l$}
\label{fig:validity}
\end{ruledfigure}
%
Figure~\ref{fig:validity} defines what it means for a transaction $t$ to be valid for a valid ledger $l$ during the tick \currentTick, using some auxiliary functions from Figure~\ref{fig:validation-functions}. A ledger $l$ is \textit{valid} if either $l$ is empty or $l$ is of the form $t::l^{\prime}$ with $l^{\prime}$ valid and $t$ valid for $l^{\prime}$.

The rules follow the usual structure for an UTXO ledger, with a number of modifications and additions.
The new \textbf{Forging} rule (Rule~\ref{rule:forging}) implements the support for forging policies by requiring that the currency's forging policy is included in the transaction --- along with Rule~\ref{rule:all-mps-validate} which ensures that they are actually run!
The arguments that a script is applied to are the ones discussed earlier.

When forging policy scripts are run, they are provided with the appropriate transaction data, which allows them to enforce conditions on it.
In particular, they can inspect the $\forge$ field on the transaction, and so a forging policy script can identify how much of its own currency was forged, which is typically a key consideration in whether to allow the transaction.

We also need to be careful to ensure that transactions in our new system preserve value correctly.
There are two aspects to consider:
\begin{itemize}
\item
  We generalise the type of value to \Quantities.
  However, since \Quantities\ is a monoid (see Section~\ref{sec:model}), Rule~\ref{rule:value-is-preserved} is (almost) identical to the one in the original UTXO model, simply with a different monoid.
  Concretely, this amounts to preserving the quantities of each of the individual token classes in the transaction.
\item
  We allow forging of new tokens by including the forge field into the balance in Rule~\ref{rule:value-is-preserved}.
\end{itemize}


\documentclass[fleqn,12pt]{article}
\newcommand{\expectation}[1]{\langle #1 \rangle}
\begin{document}
\title{Statistical Function Notes}
\author{Brian Gough}
\date{November 2008}
\maketitle

\section{Weighted mean and variance}
We have $N$ samples $x_i$ drawn from a gaussian distribution
$G(\mu,\sigma)$ (or any distribution with finite first and second
moments).  Each sample has a weight $w_i$ which represents the
relative value we place on it.  Given the estimate of the mean
%
\begin{eqnarray}
\bar{x} &=& {1 \over W} \sum_i w_i x_i \\
W       &=& \sum_i w_i
\end{eqnarray}
%
\noindent
we want an unbiased estimator of the variance of the underlying
distribution $\sigma^2$.

We start with the standard definition of the sample variance $V$ and
compute the bias correction factor.
%
\begin{eqnarray}
V &=& {1\over W} \sum_i w_i (x_i - \bar{x})^2 \\
  &=& {1\over W} \sum_i w_i \left(x_i - {1\over W}\sum_j w_j x_j\right)^2 \\
  &=& {1\over W} \sum_i w_i \left(x_i^2 - {2 \over W} x_i \sum_j w_j x_j
       + {1 \over W^2} (\sum_j w_j x_j)^2\right) \\
  &=& {1\over W} \left( \sum_i w_i x_i^2
       - {2 \over W} \sum_i w_i x_i \sum_j w_j x_j
       + {1 \over W} (\sum_j w_j x_j)^2\right)\\
  &=& {1\over W} \left( \sum_i w_i x_i^2
       - {1 \over W} \sum_i w_i x_i \sum_j w_j x_j\right)\\
  &=& {1\over W} \left( \sum_i w_i x_i^2
       - {1 \over W} \sum_{ij} w_i w_j x_i x_j\right)
\end{eqnarray}
%
We find the expectation value $\expectation{V}$ using the Gaussian
formulas $\expectation{x_i} = \mu$, $\expectation{x_i x_j} = \mu^2 +
\delta_{ij} \sigma^2$.  We assume that any random contribution
dependent on the weights themselves is zero or can be
neglected in comparison to $\sigma$.

%
\begin{eqnarray}
\expectation{V}   &=& {1\over W} \left( \sum_i w_i \expectation{x_i^2}
       - {1 \over W} \sum_{ij} w_i w_j \expectation{x_i x_j}\right)\\
      &=& {1\over W} \left( \sum_i w_i (\mu^2 + \sigma^2)
       - {1 \over W} \sum_{ij} w_i w_j (\mu^2 + \delta_{ij} \sigma^2)\right)\\
      &=& {1\over W} \left( W (\mu^2 + \sigma^2)
       - {1 \over W} ( W^2 \mu^2 +( \sum_i w_i^2) \sigma^2)\right)\\
      &=& {1\over W} \left(W \sigma^2 - {1 \over W} ( \sum_i w_i^2)\sigma^2\right)\\
      &=& \left({{W^2 - \sum_i w_i^2} \over W^2}\right) \sigma^2
\end{eqnarray}
%
Therefore an unbiased estimator $U$ of $\sigma^2$ is
%
\begin{eqnarray}
U &=& {W^2 \over {(W^2 - \sum_i w_i^2)}} \expectation{V}\\
  &=& {W^2 \over {(W^2 - \sum_i w_i^2)}} {1\over W} \sum_i w_i (x_i - \bar{x})^2 \\
  &=& {W \over {(W^2 - \sum_i w_i^2)}} \sum_i w_i (x_i - \bar{x})^2
\end{eqnarray}
%
And this is the formula used in GSL.
\subsection{Notes}
Note the following properties:

\begin{itemize}
\item
The formula is invariant under rescaling of the weights.

\item
For equal weights $w_i = w$ the factor reduces to $N/(N^2-N) =
1/(N-1)$, which is the familiar factor of the unbiased estimator of
the variance for data without weights.

\item
When $\sum_i (w_i/W)^2 \ll 1$ the commonly-used weighted variance
formula $V = (1/W)\sum_i w_i (x_i - \bar{x})^2$ is a good
approximation.
\end{itemize}

If we assume that the ``experimental errors'' arising from the weights
contribute, the underlying variance $\sigma^2$ is overestimated by
this formula (e.g. consider the case $\sigma = 0$---all the variation
will come from the gaussian fluctuations represented by the
$w_i$). The appropriate expectation in this case is $\expectation{x_i
  x_j} = \mu^2 + \delta_{ij} (\sigma^2 + 1/w_i)$
\end{document}


\section{Perceptrons}
\smallskip \hrule height 2pt \smallskip

\begin{itemize}
	\item Decision mechanism: sign of $w \cdot x$.  If + say yes, if - say no.  % week 6 audio
	\item Linear classifier in feature space.
	\item Error driven, not probabilistic. \hfill \\
		\begin{itemize}
			\item Mistake driven rather than model drive. \hfill \\
			\item Parameters from reactions to mistakes  % end of slide set 7
		\end{itemize}
	\item does better with linearly separable data.
	\item Parameters are from a discriminative interpretation % end of slide set 7
	\item To train, you go through the data until the held-out accuracy maxes out. % end of slide set 7
	\item  Just moving the plane to satisfy your labels.
			Then project new sample into this space and see which side it was on.  % week 6 audio
	\item Note you can scale your $w$ (weight) vector(s) by any constant because all you care about is sign($w \cdot x$).
		This rescales your gamma by that constant too! \hfill \\
	\item Bias allows you to have decision boundaries that don't go through the origin.
		You could us any number, but 1 is used by convention.
	\item Go through the data point by point, not feature by feature.
		Feature by feature would assume independence of the features (bad).  % Week 6 audio.
	\item If linearly separable, it will converge.  And we will know how fast it will converge.  % Week 6 audio
\end{itemize}

\subsection{Properties of Perceptron}
\underline{Separability}: some parameters get the training set perfectly correct. \hfill \\
\underline{Convergence}: if the training is separable, the perceptron will eventually converge. \hfill \\
\underline{Mistake Bound}: the maximum number of mistakes (for the binary case) is related to the
margin or degree of separability: $mistakes \leq \frac{R^2}{\gamma^2}$. \hfill \\
\hfill \\  \hfill \\

Sort of inspired by what might happen in a human brain.
Neurons send info.  A module sums them up \& produces a result.

\subsection{Problems with the Perceptron}
\includegraphics[width=2.8in]{figures/perceptron_problems.pdf}
Lines might not be optimal: issues with generalizibility. \hfill \\
Leads into SVMs. \hfill \\

 \subsection{Linear Classifiers}
 Inputs are feature values.  \hfill \\
 Each feature has a weight.  \hfill \\
 Sum is the activation.  activation$_w(x) = \sum_i w_i x_i = w \cdot x$  \hfill \\
 If the activation is positive, chose output class 1.  \hfill \\
 If the activation is negative, chose output class 2.  \hfill \\

 \includegraphics[width=1.5in]{figures/linear_classifier_cartoon.pdf}  \hfill \\

 For a binary decision rule:   \hfill \\
 In the space of feature vectors:
 \begin{itemize}
 	\item examples are points
	\item any weight vector is a hyperplane
	\item one side corresponds to y = +1
	\item the other side corresponds to y = -1
	\item ??? The $w \cdot x = 0$ is the solution to the line.
 \end{itemize}

 \includegraphics[width=1.5in]{figures/binary_decision_rule.pdf} \hfill \\
 The black line is the decision boundary.     \hfill \\
 $w$ is a vector normal to the decision boundary, and points towards the + label points.

 \subsubsection{Binary Perceptron Algorithm}
 \begin{itemize}
 	\item start with zero weights: $w=0$
	\item for $ t = 1 \dots T$ (T passes over the data):
		\begin{itemize}
			\item for $i = 1 \dots n$ (each training example)
			\begin{itemize}
				\item  Classify with current weights: \hfill \\
					$ y = sign(w \cdot x^i)$ \hfill \\
					(sign($z$)  is $+1$ if $z > 0$, else -1) \hfill \\
				\item if correct (i.e. $y = y^i$), don't change weights.
				\item if it was wrong, update with $w = w + y^i x^i$
			\end{itemize}
		\end{itemize}
 \end{itemize}
Figure showing "you got it wrong:"  \hfill \\
 \includegraphics[width=1.0in]{figures/binary_perceptron_rule.pdf}  \hfill \\
 The -1 is the $y^i$ in the equation above.   \hfill \\
   \hfill \\

 \includegraphics[width=3.2in]{figures/perceptron_chugging_example.pdf}

 \underline{$w \cdot x$ and the boundary between positive and negative answers} \hfill \\
If a point has w * x = 1000, a small change in x might change w * x' to 999, or 1001, but it surely won't make w * x a negative value. On the other hand, if w * x = 0.0001, even tiny changes to x might make w * x' negative. And by extension, cases where w * x = 0 where even the tiniest change might make w * x' change sign. So the values where w * x = 0 are those that are on the boundary between positive and negative examples.[1]

So \textbf{the equation w * x = 0 defines the boundary between the positive and negative region}. Now let's unpack that statement. w is a fixed vector, while x is a variable point. So think of w = [w1, w2] as constants, and x = [x1, x2] as variables. The equation w * x = 0 is just another way of writing the equation w1 x1 + w2 x2 = 0. But this is a linear equation in two variables, so it defines a line. You can algebraically solve the equation for x2, and that gives you the "standard form" of the equation of a line, which you can then draw.

[1] The boundary of a region is defined as the set of points where even points very close by can be outside that region.

 \subsection{Multiclass Decision Rule}

 If we have more than two classes:
 \begin{itemize}
 	\item we have a weight vector for \textbf{each} class: $w_y$
	\item we calculate an activation for each class: \hfill \\
		activation$_w(x,y) = w_x \cdot x$
	\item the highest activation wins:  \hfill \\
		$y^* = \argmax_y(activation_w(x,y))$ \hfill \\
		"win the vote"
 \end{itemize}

For each point, look at all 3 classes and see which is farthest from the hyperplane.
You can treat the dot product (+ bias) as a confidence from the hyperplane you are.  % week 6 audio.
\hfill \\
\hfill \\

\includegraphics[width=1.5in]{figures/multiclass_decision_rule_planes.pdf}

\includegraphics[width=2.5in]{figures/perceptron_multiclass--win_the_vote.pdf}

 \subsubsection{Binary Perceptron Algorithm}
 \begin{itemize}
 	\item start with zero weights: $w_y=0$
	\item for $ t = 1 \dots T$ (T passes over the data):
		\begin{itemize}
			\item for $i = 1 \dots n$ (each training example)
			\begin{itemize}
				\item  Classify with current weights: \hfill \\
					(no more $ y = sign(w_y \cdot x^i)$) \hfill \\
					instead:  $y= \argmax_y w_y \cdot x^i$ \hfill \\
				\item if correct (i.e. $y = y^i$), don't change weights.
				\item if it was wrong, update two vectors: \hfill \\
					$w_{y^i} = w_{y^i} + x^i$ \hfill \\
					If class 2 was the right label, add $x_i$ to $w_2$. \hfill \\
					Also want to push down the wrong classification:  \hfill \\
					(Didn't have to push one down for binary because adding to one pushed the other. )
					$w_y = w_y -x^i$ \hfill \\
			\end{itemize}
		\end{itemize}
 \end{itemize}
 \includegraphics[width=1.0in]{figures/multi_perceptron_rule.pdf}

 \subsection{Linear Separability}
 \subsubsection{binary case}
Recall $ \displaystyle  ||x||_2 = \sqrt{\sum_i x_i^2}$

 The data is linearly separable with margin $\gamma$ if:   \hfill \\
$\exists .w \forall t . y^t (w \cdot x^t) \geq \gamma > 0$.  \hfill \\
Plain english: the data is linearly separable if there exists a w that has a margin greater than zero for all points $t$.  \hfill \\
Note: for $y^t = 1$, $w \cdot x^t \geq \gamma$ and for $y^t = -1$, $w \cdot x^t \leq -\gamma$.  \hfill \\
Plain english: points having label = 1 have a dot product that is greater than $\gamma$, and points that have label = -1 have a dot product that is more negative than $-\gamma$.  \hfill \\
 \includegraphics[width=1.0in]{figures/lin_sep_margin.pdf}

 \subsubsection{maximum number of mistakes for training linearly separable binary data}
Here, assume the data is separable with margin $\gamma$ and the weight vector is a unit vector: \hfill \\
In math notation, this is: $\exists w^*$ such that $||w^*||_2 = 1$ and $\forall t. y^t(w^* \cdot x^t) \geq \gamma$.) \hfill \\
Recall that you can scale your $w$ (weight) vector(s) by any constant because all you care about is sign($w \cdot x$),
but that this scales your $\gamma$.  You are just multiplying the equation above by a constant.  \hfill \\

Also assume some maximum radius R for your data points:
$\forall t. ||x^t||_2 \leq R$ \hfill \\
Then the number of mistakes (parameter updates) made by the perceptron is bounded by
$\displaystyle mistakes \leq \frac{R^2}{\gamma^2}$. \hfill \\
For full inductive proof, see slides.
Strategy: let $w^k$ be the weights after the k-th update (mistake).
Then $k^2 \gamma^2 \leq ||w^k||_2^2 \leq k R^2$ \hfill \\
Therefore $k \leq \frac{R^2}{\gamma^2}$.  \hfill \\
\textbf{If there is a linear separator, the Perceptron will find it!} \hfill \\
 \hfill \\

The \# of mistakes you need to make for a perceptron to converge is bounded by a ratio of $R/\gamma^2$. \hfill \\
 \hfill \\

What if gamma is small?
    Starting to violate linearly separability rule.
    Shouldn't trust perceptron under this.

\subsection{Logistic Regression \& Perceptron similarities}
\underline{Logistic regression}:  \hfill \\
In vector notation, y is in the set $\{ 0, 1\}$. \hfill \\
$w = w + \nu \sum_j [y^j - P(y^j | x^j, w))] x^j$ \hfill \\

\underline{Perceptron}:  \hfill \\
When y is in $\{ 0, 1\}$: \hfill \\
$w = w + [y^j - sign^0(w \cdot x^j)] x^j$  \hfill \\
Note: sign$^0(z) =  + 1$ if $z > 0$ and 0 otherwise.  \hfill \\
\hfill \\
Differences:   \hfill \\
1. Online vs. batch learning.  Logistic regression is batch, Perceptron is on-line.  \hfill \\
2. Logistic is probabilistic and Perceptron is error-driven.