\chapter{Non Inertial frames and Fictitious force}
\section{Non- inertial frame}
By now we were  discussing  inertial frames ,  in which Newton's second law of motion `$\boldsymbol{F}=\mathrm{ma}$'  holds true .
There are other frames of references in which Newton's law of  inertia does not hold and  are called non- inertial frames. All the accelerated and rotating frames are the non-inertial frames of reference.\\
In an accelerated frame ,  a force-free particle will seem to have an acceleration. If we do not consider the acceleration of the frame but apply Newton's laws to the motion of the force free-particle, then it will appear that a force is acting on it.
\section{Fictitious or Pseudo force (Translational.)}
\begin{figure}[H]
	\centering
	\includegraphics[height=3.5cm,width=7.5cm]{fictitious}
	\caption{}
	\label{}
\end{figure}
Let us consdier two frames $S$ and $S^{\prime}$ where, $S$ is an inertial frame and  frame $S^{\prime}$ is moving with an acceleration  $\mathrm{a}_{0}$ relative to $S$. The acceleration of a particle $P$, on which no external force is acting, will be zero in the frame $S$. But in frame $S^{\prime}$ the observer will find that an acceleration - $\mathrm{a}_{0}$ is acting on it. Thus, in frame $S^{\prime}$ the observed force on the particle is $-\mathrm{m a}_{0}$, where $m$ is the mass of the particle.  \textbf{Such a force, which does not really act on the particle but appears due to the acceleration of the frame, is called a Fictitious or pseudo force}. The fictitious force on the particle $P$ is
\begin{equation}
\mathrm{F}_{0}=- \mathrm{m a}_{0}
\label{Ficititious 1}
\end{equation}
Hence the accelerated frame is non inertial.
If a force $\mathrm{F}_{i}$ is applied on the particle and $\mathrm{a}_{i}$ is the observed acceleration in the inertial frame $S$, then according to Newton's law
\begin{equation}
\mathrm{F}_{i}= \mathrm{ma}_{i}
\label{Ficititious 2}
\end{equation}
Since the non inertial frame $S^{\prime}$ is moving with an acceleration  $\mathrm{a}_{0}$, We can connect the  position vectors of the two frames as,
 \begin{align}
 \mathrm{r}_{i}&=\mathrm{r}_{n}+\frac{1}{2} \mathrm{a}_{0} t^{2}
 \intertext{ Differentiating twice we get,}
 \frac{d^{2} \mathrm{r}_{i}}{d t^{2}}&=\frac{d^{2} \mathrm{r}_{n}}{d t^{2}}+\mathrm{a}_{0}\\
  \frac{d^{2} \mathrm{r}_{i}}{d t^{2}}&=\mathrm{a}_{i}\quad  (\text { The acceleration in the inertial frame.}) \notag\\ \frac{d^{2} \mathrm{r}_{n}}{d t^{2}}&=\mathrm{a}_{n} \quad (\text { The acceleration observed in the non-inertial frame.}) \notag \\
  a_{i}&=a_{n}+a_{0}\notag  \\
  a_{i}-a_{0}&=a_{n} \\
  m a_{i}-m a_{0}&=m a_{n}\\
\intertext{And using equations \ref{Ficititious 1} and \ref{Ficititious 2} we get}
  \mathrm{F}_{n}&=\mathrm{F}_{i}+\mathrm{F}_{0}
  \intertext{Thus the observer in the accelerated frame will measure the resultant (total) force which is the sum of real and fictitious forces on the particle i.e.,}
  \text{Total force}&=\text{True force} +\text{Fictitious force}
 \end{align}
 \subsection{ Free fall of a body inside a box}
 Suppose that a box is falling in the gravitational field of the earth with an acceleration $\mathrm{a}_{0}=-\mathrm{g} \hat{\mathrm{n}}$, where $g$ is the acceleration due to gravity and $\hat{n}$ is a unit vector in the upward direction. Now, if we consider a particle, falling freely inside the box, the fictitious force on the particle is $\mathrm{F}_{0}=-m \mathrm{a}_{0}=m g \hat{n}$. As the real force on the particle due to the attraction of the earth is $-m g \hat{\mathrm{n}}$, the force observed by the observer inside the box is
 \begin{equation}
 \mathrm{F}_{n}=\mathrm{F}_{i}+\mathrm{F}_{0}=-m g \hat{\mathrm{n}}+m g \hat{\mathrm{n}}=0
 \end{equation}
\textbf{ Case-1:}$\quad$ If the particle has no initial velocity relative to the box, it will seem to remain suspended in mid-air at the same place inside the box.\\\\
\textbf{ Case-2:}$\quad$ Suppose that the box is moved with an acceleration $a_{0}=g \hat{\mathrm{n}}$ in the upward direction relative to the ground. In such a case, the real force $\left(F_{i}\right)$ and fictitious force $\left(F_{0}\right)$ on the particle are given by,
\begin{equation}
 \mathrm{F}_{i}=-m g \hat{\mathrm{n}}\quad ; \quad \mathrm{F}_{0}=-m {\mathrm{a}}_{0}=-m g \hat{\mathrm{n}}
\end{equation}
Then, the total force in the accelerated frame (box) is
\begin{equation}
 \mathrm{F}_{n}=\mathrm{F}_{i}+\mathrm{F}_{0}=-m g \hat{\mathrm{n}}-m g \hat{\mathrm{n}}=-2 m g \hat{\mathrm{n}}
\end{equation}
 This means that the observer, stationed in the box having an acceleration $g$ upward, will measure a force $2 m g$ downward on the particle.
\begin{exercise}
\textbf{The Apparent Force of Gravity:}\\
	A small weight of mass $m$ hangs from a string in an automobile which accelerates at rate $A .$ What is the static angle of the string from the vertical, and what is its tension?
\end{exercise}
\begin{figure}[H]
	\centering
	\includegraphics[height=2cm,width=7cm]{Car}
\end{figure}
\begin{answer}
	We shall analyze the problem both in an inertial frame and in a frame accelerating with the car.\\
	\begin{minipage}{0.45\textwidth}
		$\left. \right. $\\
	$\left. \right. $ \hspace{2cm}\textbf{Inertial System}
\begin{figure}[H]
	\centering
	\includegraphics[height=3.5cm,width=4cm]{car 1}
\end{figure}
	\begin{align*}
	T \cos \theta-W &=0 \\
	T \sin \theta &=m A \\
	\tan \theta &=\frac{m A}{W}\\&=\frac{A}{g} \\
	T &=m\left(g^{2}+A^{2}\right)^{1 / 2}
	\end{align*}
	\end{minipage} \hfill
\begin{minipage}{0.45\textwidth}
		$\left. \right. $\\
\textbf{System accelerating with auto.}
\begin{figure}[H]
	\centering
	\includegraphics[height=3.5cm,width=4cm]{car2}
\end{figure}
	\begin{align*}
	T \cos \theta-W &=0 \\
	T \sin \theta-F_{\text {fict }} &=0 \\
	F_{\text {fict }} &=-m A \\
	\tan \theta &=\frac{A}{g} \\
	T &=m\left(g^{2}+A^{2}\right)^{1 / 2}
	\end{align*}
\end{minipage}\\
From the point of view of a passenger in the accelerating car, the fictitious force acts like a horizontal gravitational force. The effective gravitational force is the vector sum of the real and fictitious forces.
\end{answer}

\section{Centrifugal force}
Let us consider a mass $m$ rest in  a non -inertial frame of reference, so that in this frame, the observed acceleration or the acceleration of the particle is zero. Now suppose that a frame is rotating with an angular velocity $\vec{\omega}$ relative to an inertial frame . In this noninertial (rotating) frame, the observed acceleration $\left(\mathrm{a}_{n}\right)$ of the mass $m$ is zero.\\

\begin{minipage}{0.65\textwidth}
\begin{align*}
i.e.,\  a_{n}&=0\\
\text{ Then the total force,}\ \mathrm{F}_{n}=m \mathrm{a}_{n}&=0 \\
\mathrm{F}_{i}+\mathrm{F}_{0}&=\mathrm{F}_{n} \\
-m \vec{\omega}^{2} \mathrm{r}+\mathrm{F}_{0}&=0\\
\text{Then,}\ \mathrm{F}_{0}&=m \vec{\omega}^{2} \mathrm{r}
\intertext{This fictitious force $F_{0}$ is directed away from the centre , along $r$,   and is called the centrifugal force.}
\end{align*}
\end{minipage}\hfil
\begin{minipage}{0.25\textwidth}
	\begin{figure}[H]
		\centering
		\includegraphics[height=3.5cm,width=4.2cm]{Centrifugal1}
		\caption{}
		\label{}
	\end{figure}
\end{minipage}\\
We know that the centrifugal force is a pseudo force and appears in the rotating frame due to its rotation . Here in the noninertial frame the centrifugal force is balanced by the inward tension in the string. In general, in the rotating frame, the centrifugal force is equal and opposite to the actual force and both are acting on the same particle.
\section{ Uniformely Rotating Frames }
\begin{figure}[H]
	\centering
	\includegraphics[height=4.2cm,width=4.2cm]{Centrifugal2}
	\caption{}
	\label{}
\end{figure}
Suppose that a frame $S^{\prime}\left(X_{r}, Y_{r}, Z_{r}\right)$ is rotating with an angular velocity $\vec{\omega}$ relative to an inertial frame $S\left(X_{i}\right.$, $\left.Y_{i}, Z_{i}\right) .$ For simplicity, we assume that both of the frames have common origin $O$ and common $Z$-axis.\\
The position vector of a particle $P$ in both frames will be the same $^{+}$, i.e., $\mathrm{R}_{i}=\mathrm{R}_{r}=\mathrm{R}$, because the origins are coincident. Now, if the particle $P$ is stationary in the frame $S$, the observer in the rotating frame $S^{\prime}$ will see that the particle is moving oppositely with linear velocity $-\vec{\omega} \times \mathrm{R}$.
\begin{align}
\intertext { If the velocity of the particle in the frame $S$,}v_{i} &=\left(\frac{d \mathrm{R}}{d t}\right)_{i}\\ \intertext {Then it's velocity in the rotating frame, $S^{\prime}$ ,} v_{r}&=\left(\frac{d \mathrm{R}}{d t}\right)_{r}\\
\text{It can be written as,}\left(\frac{d \mathrm{R}}{d t}\right)_{r}&=\left(\frac{d \mathrm{R}}{d t}\right)_{i}-\vec{\omega} \times \mathrm{R} \\
\left(\frac{d \mathrm{R}}{d t}\right)_{i}&=\left(\frac{d \mathrm{R}}{d t}\right)_{r}+\vec{\omega} \times \mathrm{R} \label{centrifugal 1}
\intertext{In fact this equation holds for all vectors and relates the time derivatives of a vector in the frames Therefore, equation.\ref{centrifugal 1}  may be written in the form of operator equation,}
\left(\frac{d}{d t}\right)_{i}&=\left(\frac{d}{d t}\right)_{r}+\vec{\omega} \times \mathrm{R} \label{centrifugal 2}
\intertext{ Equation.\ref{centrifugal 1} can be written in terms of velocity as, }
\mathrm{v}_{i}&=\mathrm{v}_{r}+\vec{\omega} \times \mathrm{R} \qquad \text{Since, }\frac{d \mathrm{R}}{d t}=\mathrm{v}
\intertext{Now, if we operate equation.\ref{centrifugal 2}  on velocity vector $\mathrm{v}_{i}$, we have}
\left(\frac{d \mathrm{v}_{i}}{d t}\right)_{i}&=\left(\frac{d \mathrm{v}_{i}}{d t}\right)_{r}+\vec{\omega} \times \mathrm{v}_{i}\label{centrifugal 3}
\intertext{Substituting the value of $\mathrm{v}_{i}$ in the right hand side of the equation.\ref{centrifugal 3} . We obtain,}
\left(\frac{d \mathrm{v}_{i}}{d t}\right)_{i} &=\left[\frac{d}{d t}\left(\mathrm{v}_{r}+\vec{\omega} \times \mathrm{R}\right)\right]_{r}+\vec{\omega} \times\left(\mathrm{v}_{r}+\vec{\omega} \times \mathrm{R}\right) \\
&=\left(\frac{d \mathrm{v}_{r}}{d t}\right)_{r}+\frac{d \vec{\omega}}{d t} \times \mathrm{R}+\vec{\omega} \times\left(\frac{d \mathrm{R}}{d t}\right)_{r}+\vec{\omega} \times \mathrm{v}_{r}+\vec{\omega} \times(\vec{\omega} \times \mathrm{R})
\intertext{If we write the acceleration ,} \frac{d \mathrm{v_{r}}}{d t}&=\mathrm{a}_{r} \quad ; \quad  \frac{d \mathrm{v_{i}}}{d t}=\mathrm{a}_{i}\quad  \text{And}\quad \left(\frac{d \mathrm{R}}{d t}\right)_{r}=\mathrm{v}_{r}\\ \text{Then,}\
\mathrm{a}_{i}&=\mathrm{a}_{r}+2 \vec{\omega} \times \mathrm{v}_{r}+\vec{\omega} \times(\vec{\omega} \times \mathrm{R})+\frac{d \vec{\omega}}{d t} \times \mathrm{R}\\
m \mathrm{a_{i}} &=m \mathrm{a_{r}} +2m (\vec{\omega} \times \mathrm{v}_{r})+ m \vec{\omega} \times(\vec{\omega} \times \mathrm{R})+m \frac{d \vec{\omega}}{d t} \times \mathrm{R}\\
\mathrm{F_{i}} &=\mathrm{F_{r}}+m \frac{d^{2} \mathrm{R}}{d t^{2}}+m \boldsymbol{\vec{\omega}} \times(\boldsymbol{\vec{\omega}} \times \mathrm{r})+2 m \boldsymbol{\vec{\omega}} \times \mathrm{v}+m \frac{d \vec{\omega}}{d t} \times \mathrm{r} \\
\mathrm{F_{r}} &=\mathrm{F_{i}}-m \frac{d^{2} \mathrm{R}}{d t^{2}}-m \boldsymbol{\vec{\omega}} \times(\boldsymbol{\vec{\omega}} \times \mathrm{r})-2 m \boldsymbol{\vec{\omega}} \times \mathrm{v}-m \frac{d \vec{\omega}}{d t} \times \mathrm{r} \\
\mathrm{F_{r}} &=\mathrm{F_{i}} +\mathrm{F}_{\text {translation }}+\mathrm{F}_{\text {centrifugal }}+\mathrm{F}_{\text {Coriolis }}+\mathrm{F}_{\text {azimuthal }}
\end{align}
\subsubsection{Rotation of Earth}
In the case of earth, the common origin $O$ may be considered as the centre of the earth, $Z$-axes as coinciding with its rotational axis and the frame $S^{\prime}$ as rotating with earth relative to the non-rotating frame $S$.
\begin{figure}[H]
	\centering
	\includegraphics[height=4.5cm,width=4cm]{Centrifugal3}
	\caption{Rotation of earth}
	\label{Rotation of earth}
\end{figure}
\begin{align*}
\intertext{For earth, $\vec{\omega}$ is constant, so,} \frac{d \vec{\omega}}{d t}&=0 \\
\text{Then,}\ \mathrm{a}_{i}&=\mathrm{a}_{r}+2 \vec{\omega} \times \mathrm{v}_{r}+\vec{\omega} \times(\vec{\omega} \times \mathrm{R})
\intertext{If $m$ is the mass of the particle, then force in the rotating frame is,}
m \mathrm{a}_{r}&=m \mathrm{a}_{i}-2 m \vec{\omega} \times \mathrm{v}_{r}-m \vec{\omega} \times(\vec{\omega} \times \mathrm{R})\\
\text{But,}\ m \mathrm{a}_{r}&=\mathrm{F}_{i}+\mathrm{F}_{0}
\intertext{Therefore fictitious force $\mathrm{F}_{0}$ is given by,}
\mathrm{F}_{0}&=-2 m \vec{\omega} \times \mathrm{v}_{r}-\vec{\omega} \times(\vec{\omega} \times \mathrm{R})
\intertext{Here $-2 m \vec{\omega} \times \mathrm{v}_{r}$ is the Coriolis force and\  $-m \vec{\omega} \times(\vec{\omega} \times \mathrm{R})$, the centrifugal force.}
\end{align*}
\subsection{Azimuthal Force}
Azimuthal Force  appears to act on the particles which are being observed from a rotating frame which has non-uniform angular velocity i.e. $\frac{d \vec{\omega}}{d t} \neq 0$.
It's direction is tangential to the rotation of frame.
\begin{figure}[H]
	\centering
	\includegraphics[height=3.8cm,width=4cm]{Azimuthal}
	\caption{Azimuthal force.}
	\label{Azimuthal force}
\end{figure}
\begin{equation}
\text{Azimuthal Force}=-m \frac{d{\vec{\omega}}}{d t} \times r=\vec{F}_{a z}
\end{equation}
The direction of azimuthal force on a particle lying on a non-uniformly rotating disc is shown in the figure .\ref{Azimuthal force}
\subsection{Centrifugal force}
 The centrifugal force is the only fictitious force, acting on a particle which is at rest $\left(\mathrm{v}_{r}=0\right.$ ) in the rotating frame.  This force goes hand in hand with the ,$ \frac{mv^{2}}{r}=mr\vec{\omega}^{2}$, centripetal acceleration as viewed by someone in an inertial frame. The centrifugal force may be written as,
\begin{align*}
-m \vec{\omega} \times(\vec{\omega} \times \mathrm{R})&=m \vec{\omega}^{2} \mathrm{r}
\intertext{Where, $r$ is the vector from the axis of the earth to the particle and normal to it, because,}
\boldsymbol{\vec{\omega}} \times(\boldsymbol{\vec{\omega}} \times \mathrm{R})&=(\boldsymbol{\vec{\omega}} \cdot \mathrm{R}) \vec{\omega}-(\boldsymbol{\vec{\omega}} \cdot \boldsymbol{\vec{\omega}}) \mathrm{R}\\&=\vec{\omega}^{2} R \sin \phi \hat{\mathrm{k}}-\vec{\omega}^{2} R(\hat{\mathrm{i}} \cos \phi+\hat{\mathrm{k}} \sin \phi) \qquad[\because \vec{\omega}=\vec{\omega} \hat{\mathrm{k}} \text { and } \mathrm{R}=R(\hat{\mathrm{i}} \cos \phi+\hat{\mathrm{k}} \sin \phi)]\\
&=-\vec{\omega}^{2} R \cos \phi \hat{\mathrm{i}}\\
&=-\vec{\omega}^{2} \mathrm{r}
\end{align*}
\subsubsection{Effective gravity force ($\mathrm{mg}_{\mathrm{eff}}$).}
 Consider a person standing motionless on the earth, at a polar angle $\theta$. In the rotating frame of the earth, the person feels a centrifugal force (directed away from the axis) in addition to the gravitational force, $m \mathrm{g}$.   Note that we're using $\mathrm{g}$ to denote the acceleration due solely to the gravitational force.
The sum of the gravitational and centrifugal forces doesn't point radially, unless the person is at the equator or at a pole. Let us denote the sum by $m \mathrm{~g}_{\text {eff }}$. To calculate $m \mathrm{~g}_{\mathrm{eff}}$, we must calculate $\mathrm{F}_{\text {cent }}=$ $-m \vec{\omega} \times(\vec{\omega} \times \mathrm{r})$. The $\vec{\omega} \times \mathrm{r}$ part has magnitude $R \vec{\omega} \sin \theta$, where $R$ is the radius of the earth, and it is directed tangentially along the latitude circle of radius $R \sin \theta$. So $-m \vec{\omega} \times(\vec{\omega} \times \mathrm{r})$ points outward from the axis, with magnitude $m R \vec{\omega}^{2} \sin \theta$, which is just what we expect for something traveling at frequency $\vec{\omega}$ in a circle of radius $R \sin \theta$. Therefore, the effective gravitational force,
$$
m {g}_{\mathrm{eff}} \equiv m({g}-\vec{\omega} \times(\boldsymbol{\vec{\omega}} \times \mathrm{r}))
$$
\begin{center}
\begin{figure}[H]
\begin{minipage}{0.45\textwidth}
	\includegraphics[height=3cm,width=3cm]{g-effective 1}
\end{minipage}	\hfil
\begin{minipage}{0.45\textwidth}
	\includegraphics[height=3cm,width=3cm]{g-effective 2}
\end{minipage}
	\caption{Effective Gravity force}
	\label{Effective Gravity force}
\end{figure}
\end{center}
\subsection{Coriolis force: $-2 m \vec{\omega} \times {v_{r}}$}
Coriolis force is a fictitious force which acts on a particle only  if it is in motion with respect to the rotating frame. In the rotating frame, if a particle moves with velocity $v_{r}$ , then it's always experience a force, ($-2 m \vec{\omega} \times {v_{r}}$) , perpendicular to it's path opposite to the direction of vector product, $\vec{\omega} \times {v_{r}}$.
\begin{figure}[H]
	\centering
	\includegraphics[height=3.5cm,width=7cm]{coriolis}
	\caption{Coriolis force}
	\label{Coriolis force}
\end{figure}
\begin{equation}
\begin{split}
\text{Coriolis force,}\ \vec{F}_{\text {cor }}&=-2 m \vec{\omega} \times \vec{v}_{r}\\  \text{Or}\quad \vec{F}_{c o r}&=2 m \vec{v}_{r} \times \vec{\omega}
\end{split}
\end{equation}\\ The classic Coriolis example is to imagine you are sitting on the north pole and just happen to have a Howizter handy. You fire the thing off and because the earth is turning under the projectile to you the shell is turning to the right. From the point of view of an observer in an inertial frame, the projectile follows a straight path. The angular deflection of the projectile must be $\omega t$, the earth's rotation in time $t$. The effect of coriolis force is appreciable in the condition if it acts horizontal or has a horizontal componet because in the vertical direction it's effect is masked by the large gravitational force.

\begin{abox}
	Practise set-3
\end{abox}
\begin{enumerate} [label=\color{ocre}\textbf{\arabic*.}]
	\item \textbf{(a)} Given that earth rotates once every $23 \mathrm{~h} 56 \mathrm{~min}$ around the axis from the North to South Pole, calculate the angular velocity, $\omega$, of the earth. When viewed from above the North Pole, the earth rotates counterclockwise (west to east). Which way does $\omega$ point?\\\\
	\textbf{(b)} Foucault's pendulum is a simple pendulum suspended by a long string from a high ceiling. The effect of Coriolis force on the motion of the pendulum is to produce a precession or rotation of the plane of oscillation with time. Find the time for one rotation for the plane of oscillation of the Foucault pendulum at $30^{\circ}$ latitude.
	\begin{answer}
		$ \left. \right.$\\\\
\textbf{(a)}  $\omega$ points in the south to north direction along the rotational axis of the earth.
	\begin{equation*}
\omega=\frac{2 \pi}{T}=\frac{2 \pi}{86,160}=7.292 \times 10^{-5} \mathrm{rad} / \mathrm{s}
	\end{equation*}
\textbf{(b)}The period of rotation of the plane of oscillation is given by
	\begin{equation*}
	T^{\prime}=\frac{2 \pi}{\omega^{\prime}}=\frac{2 \pi}{\omega \sin \lambda}=\frac{T_{0}}{\sin \lambda}=\frac{24}{\sin 30^{\circ}}=48 \mathrm{~h}
	\end{equation*}
\end{answer}

\item An iceberg of mass $5 \times 10^{5}$ tons near the North Pole moves west at the rate of $8 \mathrm{~km} /$ day. Neglecting the curvature of the earth, find the magnitude and direction of the Coriolis force.
\begin{answer}
	\begin{align*}
F_{\text {coriolis }}&=-2 m \omega \times v_{\mathrm{R}} \\
F_{\text {cor }}&=2 m \omega v_{\mathrm{R}} \sin \theta\\&=2 \times 5 \times 10^{8} \times 7.27 \times 10^{-5} \times \frac{8000}{86,400} \quad\left(\because \theta=90^{\circ}\right) \\
&=6730 \mathrm{~N} \text { due north }
	\end{align*}
\end{answer}
\item A train of mass 1000 tons moves in the latitude $60^{\circ}$ north. Find the magnitude and direction of the lateral force that the train exerts on the rails if it moves with a velocity of $15 \mathrm{~m} / \mathrm{s}$.
\begin{answer}
	\begin{align*}
	F_{\text {cor }} &=2 m v \omega \sin \theta \\
	&=2 \times 10^{6} \times 15 \times 7.27 \times 10^{-5} \sin 60^{\circ} \\
	&=1889 \mathrm{~N} \text { on the right rail. }
	\end{align*}
\end{answer}
\item A train of mass $m$ is travelling with a uniform velocity $v$ along a parallel latitude. Show that the difference between the lateral force on the rails when it travels towards east and when it travels towards west is $4 m v \omega \cos \lambda$, where $\lambda$ is latitude and $\omega$ is the angular velocity of the earth.
\begin{answer}
	The difference between the lateral forces on the rails arises because when the train reverses its direction of motion Coriolis force also changes its sign, the magnitude remaining the same. Therefore, the difference between the lateral force on the rails will be equal to $2 m v \omega \cos \lambda-(-2 m v \omega \cos \lambda)$ or $4 m v \omega \cos \lambda$.
\end{answer}
\item  A small block of mass ' $m$ ' lies on a wedge of mass $M$ as shown in figure. All the contact surfaces are smooth. When a horizontal force $\mathrm{F}$ is applied to the wedge, the block does not slide on the wedge. What must be value of $\mathrm{F}$.
\begin{figure}[H]
	\centering
	\includegraphics[height=2.2cm,width=5cm]{pset-3- fict}
\end{figure}
\begin{answer}
\begin{align*}
\text { Horizontal acceleration of the system is } a_{0}&=\frac{F}{M+m}
\intertext{According to question, the block does not slide on the wedge, therefore if block is seen from the reference frame of the wedge it will appear stationary. The wedge has a linear acceleration $a_{0}$ therefore if observation is made from the wedge frame a pseudo force $-m a_{0}$ must be applied on the block as shown in figure. Block is stationary on the wedge so component of forces parallel to the inclined plane must cancel.}
\text{Therefore,} \ m g \sin \theta&=m a_{0} \cos \theta\\  \text{or}\ \tan \theta&=\frac{a_{0}}{g}\\&=\frac{F}{(M+m) g}\\ \text{or}\ F&=(M+m) g \tan \theta
\end{align*}
\end{answer}
\item Assuming earth to be a sphere, calculate the linear speed of an object lying on the earth's surface at an altitude of $\lambda=60^{\circ}$ and also calculate the centrifugal force experienced by an object of mass $50 \mathrm{~kg}$. Compare this force with gravitational force.
fictitious pset-3
\begin{answer}
	\begin{align*}
	\intertext { Angular velocity of earth about its axis due to its spinning motion is ,}
	\omega&=\frac{2 \pi}{T}=\frac{2 \pi}{(24 \times 60 \times 60)} \mathrm{rad} / \mathrm{sec}\\
	\intertext{At latitude $\lambda=60^{\circ}$ objects move in circle of radius $r=R \cos \lambda$}
	\therefore \text {Linear speed }&=\omega r\\
	&=\frac{2 \pi}{24 \times 60 \times 60} \times 6400 \times 10^{3} \cos 60^{\circ} \mathrm{m} / \mathrm{s} \\
	&=\frac{2 \pi \times 10^{3}}{27} \mathrm{~m} / \mathrm{s} \quad 233 \mathrm{~m} / \mathrm{s}\\
	\text { Centrifugal force }&=m \omega^{2} r \\
	&=50 \times\left(\frac{2 \pi}{24 \times 60 \times 60}\right)^{2} \times 6400 \times 10^{3} \\
	&\simeq 1.70 \mathrm{~N} \\
	\text { Gravitational force }&=m g=50 \times 9.8\\&=490 \mathrm{~N}
	\intertext{Since centrifugal force due to spinning of earth is very small compared to the gravitational force due to this reason we do not feel the rotation of earth.}
	\end{align*}
\end{answer}
\item A person is standing at the edge of a disc of radius $\mathrm{R}$. The dise is rotating about its axis with uniform angular velocity $\omega .$ The person throws a stone in radially outward direction with speed $\frac{\omega R}{2}$ relative for the disc. Calculate acceleration of stone as seen by the person soon after throwing. (neglect gravity).
\begin{answer} $\left. \right. $\\
	\begin{figure}[H]
		\centering
		\includegraphics[height=3cm,width=4cm]{fictitious pset-3 1}
	\end{figure}
	\begin{align*}
	\intertext{As seen by the person the stone is acted upon by centrifugal and coriolis forces. The direction of the two forces soon after throwing is shown in the figure. Net force on the stone is}
	F^{\prime}&=\sqrt{F_{c o r}^{2}+F_{c f}^{2}} \\
	&=\sqrt{\left|2 m \vec{v}^{\prime} \times \vec{\omega}\right|^{2}+\left(m \omega^{2} r_{\perp}\right)^{2}}\\&=\sqrt{\left(2 m \frac{\omega R}{2} \omega \sin 90^{\circ}\right)^{2}+ (m \omega^{2}R )^{2}} \\
	F^{\prime}&=\sqrt{2} m \omega^{2}
	\intertext{Then the acceleration,}
	a^{\prime}&=\frac{F^{\prime}}{m}=\sqrt{2} \omega^{2} R
	\end{align*}
\end{answer}
\end{enumerate}

Classical Mechanics  -CSIR/chapter/Non Inertial frames and Fictitious force.tex


\chapter{Random Number Generation}
It is obvious that the aspect of randomness is a crucial factor in procedural content generation. Random numbers are required for countless reasons. They can be used to pick a random element in a set or to assign a random value to a variable. Generating random numbers is a concept that has been in the field of research for many years and, although solutions exist, it remains a delicate task.

In most cases a pseudo-random number generator (PRNG) can be used to generate numbers, although these do not provide a true random result. The term ``pseudo-random" is used to define a sequence of deterministic generated numbers with a distribution that closely resembles that of random variable. Because of the fact that random numbers generated by a PRNG are defined by a mathematical formula, poor PRNG algorithms suffer from several issues such as predictability and dependent distributions \citep{frieze_lcg}.

\section{Linear Congruential Generators}
Linear congruential generators (LCG), proposed several decades ago by D. H. Lehmer, are amongst the oldest and most common PRNG \citep{park_miller}. Requiring nothing but a single variable and a simple formula for generating numbers, they are considered very memory and time-efficient. Their space and time complexity are of order $\bigo{1}$ \citep{Knuth_art2}.

As direct result of their simplicity and efficiency, LCGs are often used in certain applications such as simulations where a satisfactory result that ``looks good" is required. However they present the disadvantage of producing predictable and dependent variables \citep{frieze_lcg}.

\subsection{Recurrence relation}
Linear congruential generators are mathematically described by the following recurrence relation:

\[ X_{n+1} = (a X_{n} + c) \modulo M \]

This recursive formula is used to generate a sequence of numbers $\{X_0, X_1, X_2,...\}$ with a seemingly random uniform distribution \citep{Knuth_art2} where each variable represents the following (as explained by \citep{hamid_lcgSecurity}):
\begin{itemize}
\item $X_{n+1}$ is the next ``random" number in the sequence $\{X_0, X_1, X_2,...\}$. It is referred to as \texttt{next()} in some implementations such as .NET's \texttt{System.Random} class \citep{System.Random} or Java's \texttt{java.util.Random} class \citep{java.util.Random}.
\item $M$ is called the {\em modulus}, generally a large prime number \citep{park_miller}
\item $a$ is called the {\em multiplier}. $0<a<M$
\item $c$ is called the {\em increment}. $0 \leq c<M$
\item The operation $ \modulo $ is called the modulo and defines the remainder of an integer-division.
\end{itemize}

\subsubsection{Seed}
As with all recurrence relations, the formula requires a starting point. In other words the formula should be defined as the following:

\begin{align}
 X_{0} &= k \nonumber \\
 X_{n+1} &= (a X_{n} + c) \modulo M \nonumber
\end{align}

Where $k$ is a constant. The initial value $X_0$ is called the {\em seed} of the generator \citep{hamid_lcgSecurity}. In some implementations such as the  \texttt{java.util.Random} class the variable $X_n$ is also called the seed \citep{java.util.Random}, although generally speaking the term {\em seed} refers to $X_0$.

It is trivial yet important to note that LCGs are ironically deterministic. Two identical LCGs (meaning the values for $a$, $c$ and $M$ are the same) will give exactly the same sequence of numbers if the seed is the same for both LCGs. This is a key concept in PRNG algorithms. Any program that utilises a pseudo-random number generator will provide exactly the same result if all given inputs (including the seed) are the same \citep{Knuth_art2}.

This is an obvious problem since the aim of any PRNG is to mimic the aspect of non-determinism. In order to obtain a different result we require a different seed. Typically, whenever a random seed is needed the computer's time can be used as the seed because this is guaranteed to be unique. The clock time is a feature related to time, which breaks the determinism of the LCG and provides a more unpredictable result \citep{Knuth_art2}.

\subsubsection{Period}
Another problem with LCGs is that the sequence produced is essentially always the same even when using a different seed. This issue is easiest to explain with the use of an example.

\begin{itemize}
\item Let us consider two generators $L_X$ and $L_Y$ that differ only by their seeds.
\item Let $X_0$ and $Y_0$ be the seeds of $L_X$ and $L_Y$ respectively.
\item Let $a = 3,\;c = 1,\;M = 7$. These values for $a$, $c$ and $M$ are most certainly non-ideal but are used only for the purpose of demonstration.
\end{itemize}

We can calculate the numbers generated by the first LCG $L_X$ when its seed is $X_0 = 1$ for instance:

$$ \{X_0, X_1, X_2, ...\} = \{1,\,4,\,6,\,5,\,2,\,0,\,1,\,4,\,6,\,5,\,2,\,0,\,1,\,4,\,...\} $$

We can do the same for the second LCG $L_Y$ with a different seed $Y_0 = 5$:

$$ \{Y_0, Y_1, Y_2, ...\} = \{5,\,2,\,0,\,1,\,4,\,6,\,5,\,2,\,0,\,1,\,4,\,6,\,5,\,2,\,...\} $$

Here we notice two things:
\begin{itemize}
\item The infinite sequence produced by $L_Y$ is nothing more than the sequence from $L_X$ with an offset. In mathematically terms:
\\ $ \{X_0, X_1, X_2, ...\} = \{Y_3, Y_4, Y_5, ...\} $
\item The infinite sequence produced by both $L_X$ and $L_Y$ is simply an infinite repetition of a finite sequence
\end{itemize}
Both of these observations are due to the mathematical determinism of the method. In other words, given a certain input to the LCG, say $X=1$, the result will always be 4.

\subsection{Advantages and Disadvantages}
\paragraph{Advantage} LCGs are famous for their efficiency and simplicity. They are easy to understand and implement. Requiring nothing more than a few simple operations such as bit-shifts and additions, they are computationally cheap \citep{wang_review} and only require a single 16-bit word of storage at-least \citep{yu_random}. Pierre L'Ecuyer has shown that larger word sizes can be used to provide more decent results \citep{lecuyer_tables}. Regardless of word-size used a single word is negligible on modern machines.

\paragraph{Disadvantages}
As demonstrated by Pierre L'Ecuyer, LCGs can give satisfying results in certain applications such as simulations \citep{lecuyer_lcg_k1}. However, the quality of the pseudo-random numbers is very sensitive to the values assigned to its parameters $a$, $c$ and $M$. Bad choices for these parameters have historically lead to LCGs with inadequate results \citep{li_ooRandom}. Finding good coefficients for a LCG is very difficult and has been in the field of research for many years \citep{park_miller}. Generally in most applications, a known and reputable LCG will be used instead of innovating a new one. For instance, the LCG used in Java's \texttt{java.util.Random} class is based on the algorithm discussed by Donald E. Knuth in the {\em The Art of Programming: Volume 2} \citep{Knuth_art2}.

Aside from the concern for the quality of the result, LCGs also has a major concern regarding security. LCGs are notorious for their predictability even if the coefficients provide decent results \citep{hamid_lcgSecurity}. Plumstead has shown that the multiplier $a$ and multiplier $M$ can be inferred when a certain number of pseudo-random bits are revealed \citep{plumstead_predicting}. Therefore, using merely a fragment of a LCG's output, it is possible to predict the sequence of pseudo-random bits without knowing the coefficients $a$ and $M$ \citep{frieze_lcg}. Even worse, once the modulus becomes known we can predict the output with almost perfect certainty as demonstrated by Jacques Stern \citep{Stern_lcgInsecure}. Needless to say, this is a big concern for security because a high degree of unpredictability is required. Therefore LCGs are un-recommended for the use of cryptography. Some suitable alternatives derived from LCGs can be used for cryptography. An example is the Blum Blum Shub algorithm \citep{BlumBlumShub-1}.

\subsection{Constraints for good LCGs}
The aim of a number generator is to provide a sequence of numbers with good statistical properties and randomness \citep{hamid_lcgSecurity}. Naturally good randomness is required for simulation, but it has been shown by \citep{Knuth_decipher} and \citep{plumstead_predicting} that a LCG is more difficult to decipher if its output possesses good statistical randomness. This  makes statistical randomness the key element when designing a number generator.

Another essential feature for LCGs is the concept of full-period. A full period means that all values $0\leq X<M$ are generated once before the LCG returns to its initial state (i.e. it re-generates the initial seed) \citep{Knuth_art2}. Our previous example with the coefficients $a = 3$, $c = 1$, $M = 7$, $X_0=1$ is not a full-period LCG because the period generated does not include $3$:
\[\{1,\,4,\,6,\,5,\,2,\,0,\,1,...\}\]
A full-period LCG with a modulus $M=7$ would generate a period that includes all the numbers $\{0,\,1,\,...,\,6\}$. Donald Knuth has stated that a LCG has a full-period if and only if \citep{Knuth_art2}:
\begin{itemize}
\item The coefficients $c$ and $M$ are {\em relatively prime}, meaning they have no common dividers other than 1.
\item $a-1$ is divisible by all the prime factors of $M$.
\item If $M$ is a multiple of 4 then $a-1$ is so too.
\end{itemize}
However, full-period LCGs are not guaranteed to provide good results. In an example shown by Park and Miller they demonstrated this by using two similar number generators, both provided full-period sequences. These generators were given by formulas \((6 X \modulo 13)\) and \((7 X \modulo 13)\). However the former provided better statistical randomness, making it superior to the latter \citep{park_miller}.

\subsection{Examples of good and bad LCG}
Park and Miller suggested a good example of a LCG that provides adequate results. They refer to this LCG as the {\em minimal standard generator} \citep{park_miller}. This LCG uses the coefficients $M = 2^{31}-1$, $a = 7^5$ and $c = 0$. They claim that this LCG possesses both the full-period and statistical randomness properties. Additionally they also state that this LCG is easy to implement on nearly every computer system \citep{park_miller}.

\begin{quotation}
``We present the rationale for our choice of a minimal standard generator. We believe that this is the generator that should always be used -- unless one has access to a random number generator known to be better." \citep{park_miller}
\end{quotation}

Unfortunately good LCGs are difficult to find and hence there are many LCGs that suffer from certain defects \citep{park_miller}. Notably any number generator with a modulus of the form $M=2^n$ will suffer from an effect where lower bit are less significant and causes problems. For instance, the full-period mixed generator on UNIX platforms called \texttt{rand()} suffers from an issue where  the distribution of the lower bits is non-random \citep{park_miller}. The generator \texttt{rand()} used the parameters $a=1103515245$, c=$12345$ and $M=2^{31}$ \citep{park_miller}.

Another poor example of a LCG which suffers from the same effect that causes a defect in \texttt{rand()} is the random number generator in Turbo Pascal. The parameters used are $a=129$, $c=907633385$ and $M=2^{32}$, which is claimed to be even worse than the function \texttt{rand()} because the multiplier is simply too small \citep{park_miller}.

The worst example of any LCG must probably be the random generator known as RANDU. The coefficients are given by $a=2^{16}+ 3$, $c=0$ and $M=2^{31}$. These coefficients were chosen because they made the implementation of the algorithm very simple and it quickly became widespread \citep{park_miller}. However RANDU does not have a full period and the numbers generated have a distribution which is clearly non-random \citep{park_miller}.

\begin{quotation}
``...its very name RANDU is enough to bring dismay into the eyes and stomachs of many computer scientists!" \citep{Knuth_art2}
\end{quotation}

\section{Alternatives}
\subsection{Coupled Linear Congruential Generators}
In the attempt to make a PRNG that is efficient and cryptographically secure, Katti et al. suggested the use of Coupled Linear Congruential Generator (CLCG). This consists of using two LCGs with slightly different arguments to generate a sequence of bits. They show that breaking a CLCG is of complexity $\bigo{2^{2n}}$ where $n$ is the number of bits in the modulus $M$, which they consider as ``moderate security". However the authors confess that not all CLCGs pass the statistical tests of randomness, but they propose a modified version of CLCGs called dual-coupled LCG designed to provide statistically satisfying results. \citep{katti_coupledCG2}

\subsection{Mersenne twister}
Although LCGs generally provide adequate results they present major flaws in certain applications. One typical example is the Monte Carlo simulation that consists of repeatedly sampling data and testing them. Good statistical randomness is required in order for this simulation to work properly, LCGs simply don't have a level of randomness that is sufficient for a Monte Carlo simulation \citep{Itan-MonteCarlo}. In 1997, Makoto Matsumoto and Takuji Nishimura conceived a pseudo-random number generator known as the Mersenne twister. This method is optimised to provide statistical randomness and passes most statical tests \citep{DBLP:journals/tomacs/MatsumotoN98}. However this number generator on its own remains cryptographically insecure and shouldn't be used for this purpose, although it is possible to modify the algorithm to make it safe \citep{DBLP:journals/iacr/MatsumotoNHS05}.

\subsection{Blum Blum Shub}
PRNG algorithms such as LCG and Mersenne twister are fast and provide decent results. However, they are not cryptographically secure and are predictable. When considering randomness for security proposes, one must consider a different algorithm such as the {\em Blum Blum Shub} algorithm.

The name of the Blum Blum Shub algorithm is derived from its three creators Lenore Blum, Manuel Blum, and Michael Shub. \citep{BlumBlumShub-1} The formula used to generate pseudo-random bits is given as:

\[x_{n+1} = x^2_n \modulo M \]

Where $M$ is the product of two large prime numbers $p$ and $q$. The seed \(x_0 \notin \{0,1\} \) should be co-prime to $M = pq$ \citep{BlumBlumShub-2}.

This number generator is particularly useful in the field of cryptography because of its unpredictability. Predicting the output of the algorithm is possible, but it is a problem that is {\em computationally difficult} to solve. The problem is at-least as difficult as factorising $M$, which is an {\em NP-complete} problem \citep{BlumBlumShub-1}.

\pagebreak


\documentclass[acmsmall,nonacm]{acmart}
\acmConference[]{}{}{}

\usepackage{minted}
\newmintinline[agda]{agda}{escapeinside=<>,mathescape=true}

\newcommand{\α}{\alpha}
\newcommand{\β}{\beta}
\newcommand{\γ}{\gamma}
\newcommand{\σ}{\sigma}
\newcommand{\Γ}{\Gamma}
\newcommand{\Λ}{\Lambda}
\newcommand{\∀}{\forall}
\newcommand{\↑}{\uparrow}
\newcommand{\⊢}{\vdash}
\newcommand{\↦}{\mapsto}
\newcommand{\⊳}{\rhd}
\newcommand{\fix}{\textrm{fix}}

% Each submission (referred to as “abstract” below) should include the student author’s name and e-mail address;
% institutional affiliation; research advisor’s name; ACM student member number; category (undergraduate or graduate)
\author{Jonathan Chan}
\title{A Syntactic Model of Sized Dependent Types}

\begin{document}
\maketitle

\section{???}

The types-as-propositions paradigm associates certain type theories with formal logical systems,
and consequently types in those theories with propositions in those logics.
Furthermore, well-typed programs are associated with proofs of the corresponding proposition.
Many dependent type theories, for instance, correspond to higher-order logics,
and having an automated type checker means having the ability to automatically verify proofs.
One must be careful, however, not to allow nonterminating programs,
because they correspond to logical inconsistencies, i.e. proofs of falsehood;
additionally, in dependent type checkers where programs may be evaluated during type checking,
failure to rule out nonterminating programs leads to nonterminating type checking.
Contemporary proof assistants based on dependent type theories, such as Coq, Agda, Lean, Idris,
and more, typically restrict recursive functions to \emph{structurally-recursive} ones,
where the argument of recursive calls must be \emph{syntactically} smaller.
As an example, consider the following function \agda{minus n m} that computes $\min(n - m, 0)$.

\begin{minted}{agda}
minus : Nat → Nat → Nat
minus Zero m = Zero
minus n Zero = n
minus (Succ n) (Succ m) = minus n m
\end{minted}

Inuitively, any well-typed call to \agda{minus} is guaranteed to terminate because the recursive call
only occurs on constructor arguments, and the base cases must be reached eventually.
However, we often wish to write terminating functions that aren't necessarily syntactically recursive.
Consider now the following function \agda{div n m} that computes $\big\lceil\frac{n}{m+1}\big\rceil$ using \agda{minus}.

\begin{minted}{agda}
div : Nat → Nat → Nat
div Zero m = Zero
div (Succ n) m = Succ (div (minus n m) m)
\end{minted}

Despite the fact that \agda{minus} returns a natural no greater than its first argument,
meaning that the first argument of the recursive call to \agda{div} has a smaller magnitude
than the original argument,
the type checker is unable to conclude that this is a terminating function,
because the first argument isn't \emph{syntactically} smaller (i.e. \agda{n}).
The programmer would have to alter the definition of \agda{minus} to prove this property,
as well as the definition of \agda{div} to use this proof, making writing otherwise simple code burdensome.
Sometimes it would be possible to make the type checker a little more clever by selectively inlining
certain functions that allow the syntactic termination check to pass,
but this is not always possible, and requiring inlining just to pass termination checking is anti-modular.
If inlining \agda{minus} in the body of \agda{div} helped, then we are forced to import its entire definition,
rather than merely its name and type, as is only required for type checking alone.

%\paragraph*{}
A \emph{type-based} rather than syntactic method of termination checking uses \emph{sized types} (Hughes 1996),
where a function is guaranteed to terminate simply if it type checks.
To use sized types, we first alter our definition of naturals to take a size expression as a parameter.

\begin{minted}[escapeinside=<>,mathescape=true]{agda}
data Nat [<$\α$>] : Type where
  Zero : <$\∀ \β < \α$>. Nat [<$\α$>]
  Succ : <$\∀ \β < \α$>. Nat [<$\β$>] → Nat [<$\β$>]
\end{minted}

The bounded size quantification \agda{<$\∀\β < \α$>} asks for some size $\β$ strictly smaller than $\α$.
So to construct the successor of some natural \agda{n : Nat [s]}, we need a size larger than \agda{s}.
Let \agda{<$\↑$>s} denote the next size up from \agda{s}.
Then the successor is simply \agda{Succ {<$\↑$>s} [s] n} (using curly braces for the implicit size parameter).
Now, let us express the fact that \agda{minus} returns a natural no larger than its first argument using sizes,
i.e. that \agda{minus} is in fact \emph{size-preserving}.

\begin{minted}[escapeinside=<>,mathescape=true]{agda}
minus : <$\∀\α$>, <$\β$>. Nat [<$\α$>] → Nat [<$\β$>] → Nat [<$\α$>]
\end{minted}

Then we are able to write a \agda{div} function that the type checker will accept to be terminating
with just a few more annotations.

\begin{minted}[escapeinside=<>,mathescape=true]{agda}
div : <$\∀\α$>, <$\β$>. Nat [<$\α$>] → Nat [<$\β$>] → Nat [<$\α$>]
div [<$\α$>] [<$\β$>] (Zero {<$\α$>} [<$\γ$>])   m = Zero {<$\α$>} [<$\γ$>]
div [<$\α$>] [<$\β$>] (Succ {<$\α$>} [<$\γ$>] n) m = Succ {<$\α$>} [<$\γ$>] (div [<$\γ$>] [<$\β$>] (minus [<$\γ$>] [<$\β$>] n m) m)
\end{minted}

In the second branch, when matching on the first argument of size $\α$, we have the successor of \agda{n},
which itself has size $\γ < \α$.
Then the call to \agda{minus} returns a natural of size $\γ$, which is then passed to the recursive call of \agda{div}.
Type checking passes without problem because the size $\γ$ of the recursive call is strictly smaller
than the size $\α$ of the original call to \agda{div}.
More precisely, when expressing recursive functions as fixpoints,
their typing rule and reduction behaviour is the following
(using $e[x \↦ e']$ to denote substitution of $x$ by $e'$ in $e$):
\begin{align*}
&\Γ, \α, f : \∀\β < \α \mathpunct{.} \σ[\α \↦ \β] \⊢ e : \σ \\[-2\jot]
&\cline{1-2}
&\Γ \⊢ \fix \, f \, [\α] : \σ \coloneqq e : \∀\α \mathpunct{.} \σ
\end{align*}
\begin{align*}
(\fix \, f \, [\α] : \σ \coloneqq e) \: [s] \: e' &\⊳ e[\α \↦ s, f \↦ \Λ\β < s \mathpunct{.} (\fix \, f \, [\α] : \σ \coloneqq e) [\β]] \: e'
\end{align*}

A fixpoint is well-typed if the body has the same type under the environment where
the recursive reference to the fixpoint quantifies over a \emph{smaller} size.
When reducing the fixpoint applied to some size, we substitute in the body the fixpoint bounded by that size.

\section{???}

Once we have a program and correctness proofs about the program, we may wish to compile and run our program.
In Coq and Agda, programs get \emph{extracted} to OCaml and Haskell code, respectively, which are then compiled.
However, the process of extraction necessarily discards some type information,
since the extraction targets are not dependently typed.
This makes it possible to link our proven-safe program after extraction with unsafe code,
which might cause runtime errors, making all of the work proving it correct in vain.
To ensure that our proofs are preserved and verified even during linking,
we want to compile our code in a \emph{type-preserving} manner (Bowman, 2018).
The type-based nature of sized types makes it more amenable than syntactic termination checking
to type-preserving compilation of recursive functions.

Traditionally in dependent type theories, there are two mutually-dependent judgements:
the typing judgement, and the (typed) equality judgement.
Equality is used in the following typing rule:
\end{document}


\chapter{Deriving other gates from universal gates}
%\ref{sec:background}.

\section{Aim}
%\label{sec:objectives}
	To implement the logic functions i.e. AND, OR, NOT, Ex-OR, Ex- NOR and a logical expression with the help of NAND and NOR universal gates respectively.

\section{Apparatus}
%\label{sec:objectives}
	\begin{itemize}
		\tightlist
		\item Kit for realization of NAND and NOR gates
		\item Connecting Leads
	\end{itemize}

\section{Theory}
	Logic gates are electronic circuits which perform logical functions on one or more inputs to produce one output. There are seven logic gates. When all the input combinations of a logic gate are written in a series and their corrresponding outputs written along them, then this input/ output combination is called Truth Table.

	AND, OR, NOT, XOR and XNOR gates can be derived from NAND and NOR gates by converting their respective equations to NAND or NOR form, using he following 3 laws of Boolean Algebra (and their duals according to Duality Principle):
	\begin{enumerate}
		\tightlist
		\item Involution Law: $\overline{(\overline{X})} = X$
		\item Idempotent Law: $X + X = X$
		\item De-Morgan's Law: $\overline{X+Y} = \overline{X} . \overline{Y}$
	\end{enumerate}

	\subsection{NAND gate}
		NAND gate is actually a combination of two logic gates i.e. AND gate followed by NOT gate. So its output is complement of the output of an AND gate.This gate can have minimum two inputs. By using only NAND gates, we can realize all logic functions: AND, OR, NOT, Ex-OR, Ex-NOR, NOR. So this gate is also called as universal gate.
		The expression for NAND gate is:
		$$Y = \overline{A.B}$$
	\subsection{NOR gate}
		NOR gate is actually a combination of two logic gates: OR gate followed by NOT gate. So its output is complement of the output of an OR gate.This gate can have minimum two inputs, output is always one. By using only NOR gates, we can realize all logic functions: AND, OR, NOT, Ex-OR, Ex-NOR, NAND. So this gate is also called universal gate.
		The expression for NOR gate is:
		$$Y = \overline{A+B}$$

\section{Circuits}
	\subsection{NAND gate as Universal gate}
		\subsubsection{NAND gates as OR gate}
			From DeMorgan’s theorems:
			\begin{align*}
				(A.B)^\prime &= A^\prime + B^\prime \\
				(A^\prime .B^\prime)^\prime &= A^{\prime\prime} + B^{\prime\prime} \\
				&= A + B
			\end{align*}
			So, give the inverted inputs to a NAND gate, obtain OR operation at output.
			\begin{figure}[ht]
				\centering
				\subfloat[OR gate using NAND gates]{
					\includegraphics[width=0.6\textwidth,valign=c]{img/exp4/fig1}
					\label{fig:nand_to_or:1}
				}
				\hfill
				\subfloat[Truth Table for OR]
				{
					\begin{tabular}{|c|c|c|}
						\hline
						\multicolumn{2}{|c|}{Input} & Output \\
						\hline
						$A$ & $B$ & $Y=A + B$ \\
						\hline
						0 & 0 & 0 \\
						\hline
						0 & 1 & 1 \\
						\hline
						1 & 0 & 1 \\
						\hline
						1 & 1 & 1 \\
						\hline
					\end{tabular}
					\label{fig:nand_to_or:2}
				}
				\caption{\textit{OR Gate}}
			\end{figure}

		\subsubsection{NAND gates as AND gate}
			From DeMorgan’s theorems:
			\begin{align*}
				Y &= ((A.B)^\prime)^\prime \\
				Y &= (A.B)
			\end{align*}
			A NAND produces complement of AND gate. So, if the output of a NAND gate is inverted, overall output will be that of an AND gate.
			\begin{figure}[ht]
				\centering
				\subfloat[AND gate using NAND gates]{
					\includegraphics[width=0.6\textwidth,valign=c]{img/exp4/fig2}
					\label{fig:nand_to_and:1}
				}
				\hfill
				\subfloat[Truth Table for AND]
				{
					\begin{tabular}{|c|c|c|}
						\hline
						\multicolumn{2}{|c|}{Input} & Output \\
						\hline
						$A$ & $B$ & $Y=A . B$ \\
						\hline
						0 & 0 & 0 \\
						\hline
						0 & 1 & 0 \\
						\hline
						1 & 0 & 0 \\
						\hline
						1 & 1 & 1 \\
						\hline
					\end{tabular}
					\label{fig:nand_to_and:2}
				}
				\caption{\textit{AND Gate}}
			\end{figure}

		\subsubsection{NAND gates as XOR gate}
			From DeMorgan’s theorems:
			\begin{align*}
				Y &= A \oplus B \\
				  &= \overline{A}B + A\overline{B} \\
				  &= \overline{(\overline{\overline{A}B + A\overline{B}})} \\
				  &= \overline{(\overline{(\overline{A}B)} . \overline{(A\overline{B})})} \\
				  &= \overline{(A+\overline{B}) . (\overline{A} + B)}
			\end{align*}
			This can be achieved with the logic diagram shown in Figure \ref{fig:nand_to_xor:1}.
			\begin{figure}[ht]
				\centering
				\subfloat[XOR gate using NAND gates]{
					\includegraphics[width=0.6\textwidth,valign=c]{img/exp4/fig3}
					\label{fig:nand_to_xor:1}
				}
				\hfill
				\subfloat[Truth Table for XOR]
				{
					\begin{tabular}{|c|c|c|}
						\hline
						\multicolumn{2}{|c|}{Input} & Output \\
						\hline
						$A$ & $B$ & $Y=A \oplus B$ \\
						\hline
						0 & 0 & 0 \\
						\hline
						0 & 1 & 1 \\
						\hline
						1 & 0 & 1 \\
						\hline
						1 & 1 & 0 \\
						\hline
					\end{tabular}
					\label{fig:nand_to_xor:2}
				}
				\caption{\textit{XOR Gate}}
			\end{figure}

		\subsubsection{NAND gates as XNOR gate}
			From DeMorgan’s theorems:
			\begin{align*}
				Y &= \overline{A \oplus B} \\
				&= \overline{(\overline{A}B + A\overline{B})} \\
				&= \overline{(\overline{(\overline{\overline{A}B + A\overline{B}})})} \\
				&= \overline{(\overline{(\overline{(\overline{A}B)} . \overline{(A\overline{B})})})} \\
				&= \overline{(\overline{(A+\overline{B}) . (\overline{A} + B)})} \\
				&= \overline{(XOR-gate-implemented-using-NAND-Gates)}
			\end{align*}
			The output of a two input XNOR gate is shown by: $Y = \overline{\overline{A}B + A\overline{B}}$. This can be achieved with the logic diagram shown in Figure \ref{fig:nand_to_xnor:1}.
			\begin{figure}[ht]
				\centering
				\subfloat[XNOR gate using NAND gates]{
					\includegraphics[width=0.6\textwidth,valign=c]{img/exp4/fig4}
					\label{fig:nand_to_xnor:1}
				}
				\hfill
				\subfloat[Truth Table for XNOR]
				{
					\begin{tabular}{|c|c|c|}
						\hline
						\multicolumn{2}{|c|}{Input} & Output \\
						\hline
						$A$ & $B$ & $Y=\overline{A \oplus B}$ \\
						\hline
						0 & 0 & 1 \\
						\hline
						0 & 1 & 0 \\
						\hline
						1 & 0 & 0 \\
						\hline
						1 & 1 & 1 \\
						\hline
					\end{tabular}
					\label{fig:nand_to_xnor:2}
				}
				\caption{\textit{XNOR Gate}}
			\end{figure}

	\subsection{NOR gate as Universal gate}
		\subsubsection{NOR gates as OR gate}
		From DeMorgan’s theorems:
		\begin{align*}
			Y &= \overline{(\overline{(A+B)})} \\
			  &= (A + B)
		\end{align*}
		A NOR produces complement of OR gate. So, if the output of a NOR gate is inverted, overall output will be that of an OR gate.
		\begin{figure}[ht]
			\centering
			\subfloat[OR gate using NOR gates]{
				\includegraphics[width=0.6\textwidth,valign=c]{img/exp4/fig5}
				\label{fig:nor_to_or:1}
			}
			\hfill
			\subfloat[Truth Table for OR]
			{
				\begin{tabular}{|c|c|c|}
					\hline
					\multicolumn{2}{|c|}{Input} & Output \\
					\hline
					$A$ & $B$ & $Y=A + B$ \\
					\hline
					0 & 0 & 0 \\
					\hline
					0 & 1 & 1 \\
					\hline
					1 & 0 & 1 \\
					\hline
					1 & 1 & 1 \\
					\hline
				\end{tabular}
				\label{fig:nor_to_or:2}
			}
			\caption{\textit{OR Gate}}
		\end{figure}

		\subsubsection{NOR gates as AND gate}
		From DeMorgan’s theorems:
		\begin{align*}
			Y &= A.B \\
			  &= \overline{(\overline{A.B})} \\
			  &= \overline{(\overline{A} + \overline{B})}
		\end{align*}
		So, give the inverted inputs to a NOR gate, obtain AND operation at output.
		\begin{figure}[ht]
			\centering
			\subfloat[AND gate using NAND gates]{
				\includegraphics[width=0.6\textwidth,valign=c]{img/exp4/fig6}
				\label{fig:nor_to_and:1}
			}
			\hfill
			\subfloat[Truth Table for AND]
			{
				\begin{tabular}{|c|c|c|}
					\hline
					\multicolumn{2}{|c|}{Input} & Output \\
					\hline
					$A$ & $B$ & $Y=A . B$ \\
					\hline
					0 & 0 & 0 \\
					\hline
					0 & 1 & 0 \\
					\hline
					1 & 0 & 0 \\
					\hline
					1 & 1 & 1 \\
					\hline
				\end{tabular}
				\label{fig:nor_to_and:2}
			}
			\caption{\textit{AND Gate}}
		\end{figure}

		\subsubsection{NOR gates as XOR gate}
		From DeMorgan’s theorems:
		\begin{align*}
			Y &= A \oplus B \\
			&= \overline{A}B + A\overline{B} \\
			&= \overline{(\overline{\overline{A}B + A\overline{B}})} \\
			&= \overline{(\overline{(\overline{A}B)} . \overline{(A\overline{B})})} \\
			&= \overline{(A+\overline{B}) . (\overline{A} + B)} \\
			&= \overline{(A+\overline{B})} + \overline{(\overline{A} + B)} \\
			&= M + N \\
			&= \overline{(\overline{M+N})} \\
			\\
			M = \overline{(A+\overline{B})} &, N = \overline{(\overline{A} + B)}
		\end{align*}
		The output of a two input Ex-OR gate is shown by: $Y = \overline{A}B + A\overline{B}$. This can be achieved with the logic diagram shown in Figure \ref{fig:nor_to_xor:1}.
		\begin{figure}[ht]
			\centering
			\subfloat[XOR gate using NOR gates]{
				\includegraphics[width=0.6\textwidth,valign=c]{img/exp4/fig7}
				\label{fig:nor_to_xor:1}
			}
			\hfill
			\subfloat[Truth Table for XOR]
			{
				\begin{tabular}{|c|c|c|}
					\hline
					\multicolumn{2}{|c|}{Input} & Output \\
					\hline
					$A$ & $B$ & $Y=A \oplus B$ \\
					\hline
					0 & 0 & 0 \\
					\hline
					0 & 1 & 1 \\
					\hline
					1 & 0 & 1 \\
					\hline
					1 & 1 & 0 \\
					\hline
				\end{tabular}
				\label{fig:nor_to_xor:2}
			}
			\caption{\textit{XOR Gate}}
		\end{figure}

		\subsubsection{NOR gates as XNOR gate}
		From DeMorgan’s theorems:
		\begin{align*}
			Y &= \overline{A \oplus B} \\
			&= \overline{\overline{A}B + A\overline{B}} \\
			&= \overline{\overline{(\overline{\overline{A}B + A\overline{B}})}} \\
			&= \overline{\overline{(\overline{(\overline{A}B)} . \overline{(A\overline{B})})}} \\
			&= \overline{\overline{(A+\overline{B}) . (\overline{A} + B)}} \\
			&= \overline{\overline{(A+\overline{B})} + \overline{(\overline{A} + B)}} \\
			&= \overline{M + N} \\
			\\
			M = \overline{(A+\overline{B})} &, N = \overline{(\overline{A} + B)}
		\end{align*}
		The output of a two input Ex-NOR gate is shown by: $Y = \overline{\overline{A}B + A\overline{B}}$. This can be achieved with the logic diagram shown in Figure \ref{fig:nor_to_xnor:1}.
		\begin{figure}[ht]
			\centering
			\subfloat[XNOR gate using NOR gates]{
				\includegraphics[width=0.6\textwidth,valign=c]{img/exp4/fig8}
				\label{fig:nor_to_xnor:1}
			}
			\hfill
			\subfloat[Truth Table for XNOR]
			{
				\begin{tabular}{|c|c|c|}
					\hline
					\multicolumn{2}{|c|}{Input} & Output \\
					\hline
					$A$ & $B$ & $Y=\overline{A \oplus B}$ \\
					\hline
					0 & 0 & 1 \\
					\hline
					0 & 1 & 0 \\
					\hline
					1 & 0 & 0 \\
					\hline
					1 & 1 & 1 \\
					\hline
				\end{tabular}
				\label{fig:nor_to_xnor:2}
			}
			\caption{\textit{XOR Gate}}
		\end{figure}

\section{Procedure}
	\begin{enumerate}
		\tightlist
		\item Check the components for their working (NAND or NOR kit).
		\item Insert the wire-leads into the appropriate places on the kit as per the cicuits shown.
		\item For output, use the LED on the provided kit.
		\item Provide the input data in the input switches and observe the output on the LED.
		\item Verify the truth tables of various gates.
	\end{enumerate}

\section{Precautions}
	\begin{enumerate}
		\tightlist
		\item The leads must be connected properly.
		\item Wires must be connected during power supply being off only.
		\item Change the input switches only when supply is off.
	\end{enumerate}

\section{Result}
	NOT, AND, OR, XOR, XNOR gates can be realized using NAND and NOR gates.


\documentclass{article}

\usepackage{amsmath}
\usepackage{amssymb}

\usepackage{graphicx}
\usepackage{tabularx}
\usepackage{multicol}
\usepackage{enumitem}

\usepackage[english]{babel}
\newtheorem{theorem}{Theorem}

% Geometry
\usepackage{geometry}
\geometry{letterpaper, left=15mm, top=20mm, right=15mm, bottom=20mm}

% Fancy Header
\usepackage{fancyhdr}
\renewcommand{\footrulewidth}{0.4pt}
\pagestyle{fancy}
\fancyhf{}
\chead{MAT 341 - Linear Algebra}
\lfoot{CALU Fall 2021}
\rfoot{RDK}

% Add vertical spacing to tables
\renewcommand{\arraystretch}{1.4}

% Macros
\newcommand{\definition}[1]{\underline{\textbf{#1}}}

\newenvironment{rcases}
  {\left.\begin{aligned}}
  {\end{aligned}\right\rbrace}

% Begin Document
\begin{document}

\section*{Section 1.4: The Matrix Equation}

\begin{itemize}

  \item If $A$ is an $m \times n$, with columns $a_1, \ldots, a_n$, and if $x$ is in $\mathbb{R}^n$, then the product of $A$ and $x$, denoted by $Ax$, is the linear combination
  of the columns of $A$ using the corresponding entries in $x$ as weights; that is:
  \begin{equation*}
    Ax =
    \begin{bmatrix}
      a_1 & a_2 & \cdots & a_n
    \end{bmatrix}
    \begin{bmatrix}
      x_1 \\ x_2 \\ \cdots \\ x_n
    \end{bmatrix}
    = x_1a_1 + x_2a_2 + \cdots + x_na_n
  \end{equation*}

  \item $Ax$ is defined only if the number of columns of $A$ equals the number of entries in $x$.

\end{itemize}

\noindent\fbox{
  \parbox{\textwidth}{
    \begin{theorem}
      If $A$ is an $m \times n$ matrix, with columns $a_1, \ldots, a_n$, and if $b$ is in $\mathbb{R}^m$, then the matrix equation $Ax = b$ has the same solution set as the vector equation
      \begin{equation*}
        x_1a_1 + x_2a_2 + \cdots + x_na_n
      \end{equation*}
      which, in turn, has the same solution set as the system of linear equations whose augmented matrix is
      \begin{equation*}
        Ax = \begin{bmatrix}
          a_1 & a_2 & \ldots & a_n & b
        \end{bmatrix}
      \end{equation*}
    \end{theorem}
  }
}

\begin{itemize}

  \item The equation $Ax = b$ has a solution if and only if $b$ is a linear combination of the columns of $A$.

\end{itemize}

\noindent\fbox{
  \parbox{\textwidth}{
    \begin{theorem}
      Let $A$ be an $m \times n$ matrix. Then the following statements are logically equivalent. That is, for a particular $A$, either they are all true statements or they are all false.
      \begin{enumerate}[label=\alph*.)]
        \item For each $b$ in $\mathbb{R}^m$, the equation $Ax = b$ has a solution.
        \item Each $b$ in $\mathbb{R}^m$ is a linear combination of the columns of $A$.
        \item The columns of $A$ span $\mathbb{R}^m$.
        \item $A$ has a pivot position in every row.
      \end{enumerate}
    \end{theorem}
  }
}

\begin{itemize}

  \item The matrix with $1$s on the diagonal and $0$s elsewhere is called the \definition{identity matrix} and is denoted by $I$:
  \begin{equation*}
    \begin{bmatrix}
      1 & 0 & 0 \\
      0 & 1 & 0 \\
      0 & 0 & 1
    \end{bmatrix}
  \end{equation*}

\end{itemize}

\noindent\fbox{
  \parbox{\textwidth}{
    \begin{theorem}
      If $A$ is an $m \times n$ matrix, $u$ and $v$ are vectors in $\mathbb{R}^n$, and $c$ is a scalar, then
      \begin{enumerate}[label=\alph*.)]
        \item $A(u + v) = Au + Av$
        \item $A(cu) = c(Au)$
      \end{enumerate}
    \end{theorem}
  }
}

\end{document}


\subsection{Hopfield Network}

\subsubsection{Implementation Example: Optical Information Processing}
In paper from D. Psaltis and N. Farhat(1985) \cite{optical_processing}, threshold and feedback properties from Hopfield model was used in implementation of an optical system that processes optical information.

Enhanced error-correcting capability is one important outcome which is benefited from Non-linearity of Hopfield model. With $M$ words of each binary vector $v_i$ with length of N bits, matrix $T_{ij}$ represents a storage of information. Matrix $T_{ij}$ gets multiplied by a stored binary vector $v'_i$ results in a \texttt{pseudoeigensystem} if $N$ is sufficiently larger than $M$. This indicated that the output vector $v''_i$ equals the input.

Supposed non-linear iterative procedural experiments of certain number of known bits $N_1$ and the rest bits set to zero inside total of $N$ bits long vector were addressed to discover under what conditions the number of correct bits $N_2$ in output will be higher than $N_1$. A SNR(signal-to-noise ratio) equation which consists ratio of the expected value to the standard deviation on the same output vector, was used. As the Hopfield model has studied on the convergence property with respect to asynchronous operations, insensitivity to imperfections(non-uniformities, exact form of the threshold operation and errors in $T_{ij}$ matrix) and correct convergence obtained with threshold $T_{ij}$. These all become most desired properties in optical implementation. Detailed optical implementation with 2D inputs was presented which was based on spatial-frequency multiplexing. Methods using Fourier transform, transmitting amplitude(weighted sum) and integral of the product of the input images were introduced in such an implementation. The robustness of a such system with non-linear feedback becomes the most important feature.
As a conclusion, the implementation with the capabilities and limitations of optical techniques matches excellently with the Hopfield model that requires global, linear operations and local, point non-linearities in a fully interconnected optical system.

\subsubsection{Memory Capacity with Modification: \\ replacing sigmoid neuron with a non-monotonic neuron}
In paper from S. Yoshizawa, M. Morita and S. Amari(1992) \cite{capacity_of_nonmonotonic_model} it started with introduction of a new method by replacing sigmoid neuron with a non-monotonic neuron and discussed theoretically on potential of absolute capacity(the maximum number of randomly generated patterns which are memorized as the equilibria of the network with the correlation-type connection weights) to be of order $n$ (nearly equal to $0.4n$).

Previous memory capacities were briefly introduced that Hopfield(1982) model's associative memory capacity is $0.15n$, the proven result of absolute capacity is asymptotically $ \frac{n}{2\log{n}} $ (from McEliece, Posner, Rodemich, \& Venkatesh, 1987; Weisbuch, 1985), and relative capacity(recalling process) is about 0.14n(with admission of small percent of errors) with replica method, but about $0.16n$ with a simply approximation method from respectively two different research work.

Various research suggestions were mentioned though all failed to deal completely with flaws of the conventional model, that both absolute and relative capacities are too small as well as the existence of large number of spurious memories. With a non-monotonic neuron the result turned to be $0.4n$ for the absolute capacity which is even greater than relative capacity while the spurious memory disappeared.

With conventional neuron, memorized pattern is unstable, whereas a basin of attraction around memorized pattern was shown with non-monotonic neuron by replacing sigmoid function with a non-monotonic output function \textit{figure \ref{fig:nonmonotonic}} to neuron elements from the recalling process of an autocorrelation associative memory. This was named as Morita Model in the paper though it is essentially an extension from Hopfield Model.
By then the existence of equilibrium solutions and local stability, the authors did not further investigate on problems as the following: the size of the basin of attraction, the full sketch of spurious memories and the behaviour for clustered memorized patterns, which leaves more research work for future researchers to understand better associative memory with non-monotonic neurons.

\begin{figure}[htbp]
	\centering
	\includegraphics[scale = 0.8]{inc/nonmonotonic.jpg}
	\caption{The non-monotonic output function, S. Yoshizawa, M. Morita and S.Amari(1992)}
	\label{fig:nonmonotonic}
\end{figure}

%THIS IS STH EXTRA OUTSIDE HOPFIELD
\subsection{Experiment on Implicit Memory for Novel Associations between pictures: \\ Effects of Stimulus Unitization and Aging}

From various previous research, concepts such as associative priming, unitization, difference between conceptual and perceptual associative priming, verbal versus pictorial material/stimuli and roll of spatial proximity were briefly summarized \cite{stimulus_unitization_and_aging}.

Experiments with pictorial stimuli(paired pictures) were done in 3 consecutive stages, where the result from first stage showed no evidence on requirement of spatial contiguity, though associative priming was enhanced compared to with spatially separated stimuli, which proved ``implicit memory for novel associations still can occur in the absence of an emergent conceptual representation''. The second experiment was an extension from the first experiment, with focus on the effects of aging and spatial contiguity of the same topic of stimuli on novel association priming between pictures, where stunning result was shown that ``associative priming is age invariant''(exposure of pictures was longer with older group to yield a matched performance in the baseline). The last experiment was based on both first and second experiments that ``associative priming with pictorial stimuli is modulated by spatial contiguity but not by aging'', and the study proved further evidence for the notion that novel association priming for picture pairs is mediated by the PRS(Perceptual Representation System).

%Wenting.

%1982, $0.15n$ (capacity of associative memory)
%
%% Above 0.15n releases the constraint on symmetries according to Olle.
%
%1985, proven $ \frac{n}{2\log{n}} $ (absolute capacity)
%
%1985, $0.14n$ (relative capacity of recalling process)
%
%1993, $ n ~= 0.4n $ (new result, absolute capacity)


\chapter{Bonus: B\'ezout's theorem}
In this chapter we discuss B\'ezout's theorem.
It makes precise the idea that two degree $d$ and $e$
curves in $\CP^2$ should intersect at ``exactly'' $de$ points.
(We work in projective space so e.g.\ any two lines intersect.)

\section{Non-radical ideals}
\prototype{Tangent to the parabola.}
We need to account for multiplicities.
So we will whenever possible work with homogeneous ideals $I$,
rather than varieties $V$,
because we want to allow the possibility that $I$ is not radical.
Let's see how we might do so.

For a first example, suppose we intersect $y=x^2$ with the line $y=1$;
or more accurately, in projective coordinates of $\CP^2$,
the parabola $zy=x^2$ and $y=z$.
The intersection of the ideals is
\[ (zy-x^2, y-z) = (x^2-z^2, y-z) \subseteq \CC[x,y,z]. \]
So this corresponds to having two points;
this gives two intersection points: $(1:1:1)$ and $(-1:1:1)$.
Here is a picture of the two varieties in the affine $z=1$ chart:
\begin{center}
	\begin{asy}
		import graph;
		size(4cm);
		real f(real x) { return x*x-1; }
		graph.xaxis("$\mathcal V(y-z)$", red);
		draw(graph(f,-2,2,operator ..), blue, Arrows);
		label("$\mathcal V(zy-x^2)$", (1.4, f(1.4)), dir(15), blue);
		label("$\mathbb{CP}^2$", (2,3), dir(45));
		dotfactor *= 1.5;
		dot(dir(0), heavygreen);
		dot(dir(180), heavygreen);
	\end{asy}
\end{center}
That's fine, but now suppose we intersect $zy=x^2$ with the line $x=0$ instead.
Then we instead get a ``double point'':
\begin{center}
	\begin{asy}
		import graph;
		size(4cm);
		real f(real x) { return x*x; }
		graph.xaxis("$\mathcal V(y)$", red);
		draw(graph(f,-2,2,operator ..), blue, Arrows);
		label("$\mathcal V(zy-x^2)$", (1.4, f(1.4)), dir(15), blue);
		label("$\mathbb{CP}^2$", (2,3), dir(45));
		dotfactor *= 1.5;
		dot(origin, heavygreen);
	\end{asy}
\end{center}
The corresponding ideal is this time
\[ (zy-x^2, y) = (x^2,y) \subseteq \CC[x,y,z]. \]
This ideal is \emph{not} radical,
and when we take $\sqrt{(x^2,y)} = (x,y)$ we get the ideal
which corresponds to a single projective point $(0:0:1)$ of $\CP^2$.
This is why we work with ideals rather than varieties:
we need to tell the difference between $(x^2,y)$ and $(x,y)$.

\section{Hilbert functions of finitely many points}
\prototype{The Hilbert function attached to the double point $(x^2,y)$
	is eventually the constant $2$.}
\begin{definition}
	Given a nonempty projective variety $V$, there is a unique
	radical ideal $I$ such that $V = \Vp(I)$.
	In this chapter we denote it by $\II(V)$.
	For an empty variety we set $\II(\varnothing) = (1)$,
	rather than choosing the irrelevant ideal.
\end{definition}
\begin{definition}
	Let $I \subseteq \CC[x_0, \dots, x_n]$ be homogeneous.
	We define the \vocab{Hilbert function} of $I$,
	denoted $h_I : \ZZ_{\ge 0} \to \ZZ_{\ge 0}$ by
	\[ h_I(d) = \dim_{\CC} \left( \CC[x_0, \dots, x_n]/I \right)^d \]
	i.e.\ $h_I(d)$ is the dimension of the $d$th graded part of
	$\CC[x_0, \dots, x_n] / I$.
\end{definition}
\begin{definition}
	If $V$ is a projective variety, we set $h_V = h_{\II(V)}$,
	where $I$ is the \emph{radical} ideal satisfying $V = \Vp(I)$.
	If $V = \varnothing$, we choose $I = (1)$.
\end{definition}
\begin{example}[Examples of Hilbert functions in zero dimensions]
	\label{ex:hilbert_zero}
	For concreteness, let us use $\CP^2$.
	\begin{enumerate}[(a)]
		\ii If $V$ is the single point $(0:0:1)$,
		with ideal $\II(V) = (x,y)$,
		then
		\[ \CC[x,y,z] / (x,y) \cong \CC[z]
		\cong \CC \oplus z\CC \oplus z^2\CC \oplus z^3\CC \dots \]
		which has dimension $1$ in all degrees.
		Consequently, we have \[ h_I(d) \equiv 1. \]
		\ii Now suppose we use the ``double point'' ideal $I = (x^2,y)$.
		This time, we have
		\begin{align*}
			\CC[x,y,z] / (x^2,y)
			&\cong \CC[z] \oplus x\CC[z] \\
			&\cong \CC \oplus (x\CC \oplus z\CC) \oplus (xz\CC \oplus z^2\CC)
			\oplus (xz^2\CC \oplus z^3\CC) \oplus\dots.
		\end{align*}
		From this we deduce that
		\[
			h_I(d) =
			\begin{cases}
				2 & d = 1, 2, 3, \dots \\
				1 & d = 0.
			\end{cases}
		\]
		\ii Let's now take the variety $V = \{(1:1:1), (-1:1:1)\}$
		consisting of two points, with $\II(V) = (x^2-z^2, y-z)$. Then
		\begin{align*}
			\CC[x,y,z] / (x^2-z^2,y-z)
			&\cong \CC[x,z] / (x^2-z^2) \\
			&\cong \CC[z] \oplus x\CC[z].
		\end{align*}
		So this example has the same Hilbert function as the previous one.
	\end{enumerate}
\end{example}
\begin{abuse}
	I'm abusing the isomorphism symbol
	$\CC[z] \cong \CC \oplus z\CC \oplus z^2\CC$ and similarly
	in other examples.
	This is an isomorphism only on the level of $\CC$-vector spaces.
	However, in computing Hilbert functions of other examples
	I will continue using this abuse of notation.
\end{abuse}
\begin{example}
	[Hilbert functions for empty varieties]
	Suppose $I \subsetneq \CC[x_0, \dots, x_n]$
	is an ideal, possibly not radical
	but such that \[ \Vp(I) = \varnothing \]
	hence $\sqrt I = (x_0, \dots, x_n)$ is the irrelevant ideal.
	Thus there are integers $d_i$ for $i=0,\dots,n$ such that
	$x_i^{d_i} \in I$ for every $i$; consequently, $h_I(d) = 0$
	for any $d > d_0 + \dots + d_n$.
	We summarize this by saying that
	\[ h_I(d) = 0 \text{ for all $d \gg 0$}. \]
\end{example}
Here the notation $d\gg 0$ means ``all sufficiently large $d$''.

From these examples we see that if $I$ is an ideal,
then the Hilbert function appears to eventually be constant,
with the desired constant equal to the size of $\Vp(I)$,
``with multiplicity'' in the case that $I$ is not radical.

Let's prove this.
Before proceeding we briefly remind the reader of short exact sequences:
a sequence of maps of $0 \to V \injto W \surjto X \to 0$
is one such that the $\img(V \injto W) = \ker(W \surjto X)$
(and of course the maps $V \injto W$ and $W \surjto X$ are
injective and surjective).
If $V$, $W$, $X$ are finite-dimensional vector spaces over $\CC$
this implies that $\dim W = \dim V + \dim X$.

\begin{proposition}
	[Hilbert functions of $I \cap J$ and $I+J$]
	Let $I$ and $J$ be homogeneous ideals in $\CC[x_0, \dots, x_n]$.
	Then \[ h_{I \cap J} + h_{I+J} = h_I + h_J. \]
\end{proposition}
\begin{proof}
	Consider any $d \ge 0$.
	Let $S = \CC[x_0, \dots, x_n]$ for brevity.
	Then
	\begin{diagram}
		0 & \rTo & \left[ S / (I \cap J) \right]^d
			& \rInj & \left[ S / I \right]^d \oplus \left[ S / J \right]^d
			& \rSurj & \left[ S / (I+J) \right]^d
			& \rTo & 0 \\
		&& f & \rMapsto & (f,f) &&&& \\
		&&&& (f,g) & \rMapsto & f-g &&
	\end{diagram}
	is a short exact sequence of vector spaces.
	Therefore, for every $d \ge 0$ we have that
	\[
		\dim \left[ S / I \right]^d \oplus \left[ S / J \right]^d
		= \dim \left[ S / (I \cap J) \right]^d
		+ \dim \left[ S / (I+J) \right]^d
	\]
	which gives the conclusion.
\end{proof}
\begin{example}
	[Hilbert function of two points in $\CP^1$]
	In $\CP^1$ with coordinate ring $\CC[s,t]$,
	consider $I = (s)$ the ideal corresponding to the point $(0:1)$
	and $J = (t)$ the ideal corresponding to the point $(1:0)$.
	Then $I \cap J = (st)$ is the ideal corresponding
	to the disjoint union of these two points,
	while $I+J = (s,t)$ is the irrelevant ideal.
	Consequently $h_{I+J}(d) = 0$ for $d \gg 0$.
	Therefore, we get
	\[ h_{I \cap J}(d) = h_I(d) + h_J(d) \text{ for $d \gg 0$} \]
	so the Hilbert function of a two-point projective variety
	is the constant $2$ for $d \gg 0$.
\end{example}

This example illustrates the content of the main result:
\begin{theorem}
	[Hilbert functions of zero-dimensional varieties]
	Let $V$ be a projective variety consisting of $m$ points
	(where $m \ge 0$ is an integer).
	Then \[ h_V(d) = m \text{ for $d \gg 0$}. \]
\end{theorem}
\begin{proof}
	We already did $m = 0$, so assume $m \ge 1$.
	Let $I = \II(V)$ and for $k=1,\dots,m$
	let $I_k = \II(\text{$k$th point of $V$})$.
	\begin{exercise}
		Show that $h_{I_k} (d) = 1$ for every $d$.
		(Modify \Cref{ex:hilbert_zero}(a).)
		\label{ques:hilbert_always_one}
	\end{exercise}

	Hence we can proceed by induction on $m \ge 2$,
	with the base case $m=1$ already done above.
	For the inductive step,
	we use the projective analogues of \Cref{thm:many_aff_variety}.
	We know that $h_{I_1 \cap \dots \cap I_{m-1}}(d) = m-1$ for $d \gg 0$
	(this is the first $m-1$ points;
	note that $I_1 \cap \dots \cap I_{m-1}$ is radical).
	To add in the $m$th point we note that
	\[
		h_{I_1 \cap \dots \cap I_m}(d)
		= h_{I_1 \cap \dots I_{m-1}}(d) + h_{I_m}(d)
		- h_J(d)
	\]
	where $J = (I_1 \cap \dots \cap I_{m-1}) + I_m$.
	The ideal $J$ may not be radical, but satisfies $\Vp(J) = \varnothing$
	by an earlier example, hence $h_J = 0$ for $d \gg 0$.
	This completes the proof.
\end{proof}
In exactly the same way we can prove that:
\begin{corollary}[$h_I$ eventually constant when $\dim \Vp(I) = 0$]
	Let $I$ be an ideal, not necessarily radical,
	such that $\Vp(I)$ consists of finitely many points.
	Then the Hilbert $h_I$ is eventually constant.
\end{corollary}
\begin{proof}
	Induction on the number of points, $m \ge 1$.
	The base case $m = 1$ was essentially done in \Cref{ex:hilbert_zero}(b)
	and \Cref{ques:hilbert_always_one}.
	The inductive step is literally the same as in the proof above,
	except no fuss about radical ideals.
\end{proof}

\section{Hilbert polynomials}
So far we have only talked about Hilbert functions
of zero-dimensional varieties, and showed that
they are eventually constant.
Let's look at some more examples.
\begin{example}
	[Hilbert function of $\CP^n$]
	The Hilbert function of $\CP^n$ is
	\[ h_{\CP^n}(d) = \binom{d+n}{n}
	= \frac{1}{n!} (d+n)(d+n-1) \dots (d+1) \]
	by a ``balls and urns'' argument.
	This is a polynomial of degree $n$.
\end{example}
\begin{example}
	[Hilbert function of the parabola]
	Consider the parabola $zy-x^2$ in $\CP^2$
	with coordinates $\CC[x,y,z]$.
	Then
	\[ \CC[x,y,z] / (zy-x^2) \cong \CC[y,z] \oplus x\CC[y,z]. \]
	A combinatorial computation gives that
	\begin{align*}
		h_{(zy-x^2)}(0) &= 1 & \text{Basis $1$} \\
		h_{(zy-x^2)}(1) &= 3 & \text{Basis $x,y,z$} \\
		h_{(zy-x^2)}(2) &= 5 & \text{Basis $xy$, $xz$, $y^2$, $yz$, $z^2$}.
	\end{align*}
	We thus in fact see that $h_{(zy-x^2)}(d) = 2d-1$.
\end{example}

In fact, this behavior of ``eventually polynomial'' always works.
\begin{theorem}
	[Hilbert polynomial]
	Let $I \subseteq \CC[x_0, \dots, x_n]$ be a homogeneous ideal,
	not necessarily radical. Then
	\begin{enumerate}[(a)]
		\ii There exists a polynomial $\chi_I$ such that
		$h_I(d) = \chi_I(d)$ for all $d \gg 0$.
		\ii $\deg \chi_I = \dim\Vp(I)$ (if $\Vp(I) = \varnothing$
		then $\chi_I = 0$).
		\ii The polynomial $m! \cdot \chi_I$ has integer coefficients.
	\end{enumerate}
\end{theorem}
\begin{proof}
	The base case was addressed in the previous section.

	For the inductive step, consider $\Vp(I)$ with dimension $m$.
	Consider a hyperplane $H$ such that no irreducible
	component of $\Vp(I)$ is contained inside $H$
	(we quote this fact without proof, as it is geometrically obvious,
	but the last time I tried to write the proof I messed up).
	For simplicity, assume WLOG that $H = \Vp(x_0)$.

	Let $S = \CC[x_0, \dots, x_n]$ again.
	Now, consider the short exact sequence
	\begin{diagram}
		0 & \rTo & [S/I]^{d-1} & \rInj^{\times x_0} & [S/I]^d & \rSurj &
			[S/(I+(x_0))]^d & \rTo & 0 \\
		&& f & \rMapsto & fx_0 &&&& \\
		&&&& f & \rMapsto & f. &&
	\end{diagram}
	(The injectivity of the first map follows from the assumption
	about irreducible components of $\Vp(I)$.)
	Now exactness implies that
	\[ h_I(d) - h_I(d-1) = h_{I + (x_0)}(d). \]
	The last term geometrically corresponds to $\Vp(I) \cap H$;
	it has dimension $m-1$, so by the inductive hypothesis
	we know that
	\[ h_I(d) - h_I(d-1)
		= \frac{c_0 d^{m-1} + c_1 d^{m-2} + \dots + c_{m-1}}{(m-1)!}
		\qquad d \gg 0 \]
	for some integers $c_0$, \dots, $c_{m-1}$.
	Then we are done by the theory of
	\textbf{finite differences} of polynomials.
\end{proof}

\section{B\'ezout's theorem}

\begin{definition}
	We call $\chi_I$ the \vocab{Hilbert polynomial} of $I$.
	If $\chi_I$ is nonzero, we call the leading coefficient of
	$m! \chi_I$ the \vocab{degree} of $I$, which is an integer,
	denoted $\deg I$.

	Of course for projective varieties $V$ we let $h_V = h_{\II(V)}$.
\end{definition}

\begin{example}[Examples of degrees]
	\listhack
	\begin{enumerate}[(a)]
		\ii If $V$ is a finite set of $n \ge 1$ points, it has degree $n$.
		\ii If $I$ corresponds to a double point, it has degree $2$.
		\ii $\CP^n$ has degree $1$.
		\ii The parabola has degree $2$.
	\end{enumerate}
\end{example}

Now, you might guess that if $f$ is a homogeneous quadratic polynomial
then the degree of the principal ideal $(f)$ is $2$, and so on.
(Thus for example we expect a circle to have degree $2$.)
This is true:

\begin{theorem}
	[B\'ezout's theorem]
	Let $I$ be a homogeneous ideal of $\CC[x_0, \dots, x_n]$,
	such that $\dim \Vp(I) \ge 1$.
	Let $f \in \CC[x_0, \dots, x_n]$ be a homogeneous polynomial of degree $k$
	which does not vanish on any irreducible component of $\Vp(I)$.
	Then
	\[ \deg\left( I + (f) \right) = k \deg I. \]
\end{theorem}
\begin{proof}
	Let $S = \CC[x_0, \dots, x_n]$ again.
	This time the exact sequence is
	\begin{diagram}
		0 & \rTo & [S/I]^{d-k} & \rInj^{\times f} & [S/I]^d & \rSurj &
			[S/(I+(f))]^d & \rTo & 0
	\end{diagram}
	We leave this olympiad-esque exercise as \Cref{prob:bezout}.
\end{proof}

\section{Applications}
First, we show that the notion of degree is what we expect.
\begin{corollary}
	[Hypersurfaces: the degree deserves its name]
	Let $V$ be a hypersurface, i.e. $\II(V) = (f)$
	for $f$ a homogeneous polynomial of degree $k$.
	Then $\deg V = k$.
\end{corollary}
\begin{proof}
	Recall $\deg(0) = \deg \CP^n = 1$.
	Take $I = (0)$ in B\'ezout's theorem.
\end{proof}

The common special case in $\CP^2$ is:
\begin{corollary}[B\'ezout's theorem for curves]
	For any two curves $X$ and $Y$ in $\CP^2$ without
	a common irreducible component,
	\[ \left\lvert X \cap Y \right\rvert
		\le \deg X \cdot \deg Y. \]
\end{corollary}

Now, we use this to prove Pascal's theorem.
\begin{theorem}
	[Pascal's theorem]
	Let $A$, $B$, $C$, $D$, $E$, $F$ be six
	distinct points which lie on a conic $\mathscr C$ in $\CP^2$.
	Then the points $AB \cap DE$, $BC \cap EF$, $CD \cap FA$ are collinear.
\end{theorem}
\begin{proof}
	Let $X$ be the variety equal to the union of the
	three lines $AB$, $CD$, $EF$, hence $X = \Vp(f)$
	for some cubic polynomial $f$ (which is the product of three linear ones).
	Similarly, let $Y = \Vp(g)$ be the variety
	equal to the union of the three lines $BC$, $DE$, $FA$.

	\begin{center}
		\begin{asy}
			filldraw(unitcircle, opacity(0.2)+lightcyan, blue);
			pair A = dir(110);
			pair B = dir(210);
			pair C = dir(40);
			pair D = dir(270);
			pair E = dir(130);
			pair F = dir(-30);

			pair P = extension(A, B, D, E);
			pair X = extension(B, C, E, F);
			pair Q = extension(C, D, F, A);

			draw(A--B--C--D--E--F--cycle);
			draw(P--Q, red+dashed);

			dot("$A$", A, dir(A));
			dot("$B$", B, dir(B));
			dot("$C$", C, dir(C));
			dot("$D$", D, dir(D));
			dot("$E$", E, dir(E));
			dot("$F$", F, dir(F));
			dot(P);
			dot(X);
			dot(Q);

			/* Source generated by TSQ */
		\end{asy}
	\end{center}

	Now let $P$ be an arbitrary point on the conic on $\mathscr C$,
	distinct from the six points $A$, $B$, $C$, $D$, $E$, $F$.
	Consider the projective variety
	\[ V = \Vp(\alpha f + \beta g) \]
	where the constants $\alpha$ and $\beta$ are chosen such that $P \in V$.
	\begin{ques}
		Show that $V$ also contains the six points $A$, $B$, $C$, $D$, $E$, $F$
		as well as the three points $AB \cap DE$, $BC \cap EF$, $CD \cap FA$
		regardless of which $\alpha$ and $\beta$ are chosen.
	\end{ques}

	Now, note that $|V \cap \mathscr C| \ge 7$.
	But $\dim V = 3$ and $\dim \mathscr C = 2$.
	This contradicts B\'ezout's theorem unless $V$ and $\mathscr C$
	share an irreducible component.
	This can only happen if $V$ is the union of a line and conic,
	for degree reasons; i.e.\ we must have that
	\[ V = \mathscr C \cup \text{line}. \]
	Finally note that the three intersection points $AB \cap DE$,
	$BC \cap EF$ and $CD \cap FA$ do not lie on $\mathscr C$,
	so they must lie on this line.
\end{proof}

\section\problemhead
\begin{problem}
	\label{prob:bezout}
	Complete the proof of B\'ezout's theorem from before.
	\begin{sol}
		From the exactness,
		$h_I(d) = h_I(d-k) + h_{I+(f)}(d)$,
		and it follows that
		\[ \chi_{I+(f)}(d) = \chi_I(d) - \chi_I(d-k). \]
		Let $m = \dim \Vp(I) \ge 1$.
		Now $\dim \Vp(I+(f)) = m-1$, so
		and $c_{\text{new}} = \deg I+(f)$ then we have
		\[
			\frac{\deg (I+(f)) d^{m-1} + \dots}{(m-1)!}
			=
			\frac{1}{m!}
			\left( \deg I (d^m - (d-k)^m)
			+ \text{lower order terms} \right)
		\]
		from which we read off
		\[ \deg (I+(f)) = \frac{(m-1)!}{m!} \cdot k \binom m1 \deg I
			= k \deg I \]
		as needed.
	\end{sol}
\end{problem}

\begin{problem}
	[USA TST 2016/6]
	\yod
	Let $ABC$ be an acute scalene triangle
	and let $P$ be a point in its interior.
	Let $A_1$, $B_1$, $C_1$ be projections of $P$ onto
	triangle sides $BC$, $CA$, $AB$, respectively.
	Find the locus of points $P$ such that $AA_1$, $BB_1$, $CC_1$
	are concurrent and $\angle PAB + \angle PBC + \angle PCA = 90^{\circ}$.
	\begin{hint}
		You will need to know about complex numbers
		in Euclidean geometry to solve this problem.
	\end{hint}
	\begin{sol}
	In complex numbers with $ABC$ the unit circle,
	it is equivalent to solving the two cubic equations
	\begin{align*}
		(p-a)(p-b)(p-c) &= (abc)^2 (q -1/a)(q - 1/b)(q - 1/c) \\
		0 &= \prod_{\text{cyc}} (p+c-b-bcq) + \prod_{\text{cyc}} (p+b-c-bcq)
	\end{align*}
	in $p$ and $q = \overline p$.
	Viewing this as two cubic curves in $(p,q) \in \mathbb C^2$,
	by Bezout's theorem it follows there are at most nine solutions
	(unless both curves are not irreducible,
	but one can check the first one cannot be factored).
	Moreover it is easy to name nine solutions (for $ABC$ scalene):
	the three vertices, the three excenters, and $I$, $O$, $H$.
	Hence the answer is just those three triangle centers $I$, $O$ and $H$.
	\end{sol}
\end{problem}