\documentstyle[12pt]{article}
\begin{document}

\section{Introduction}

The choices available to the flagellated bacterium, {\it E. coli}, are
quite limited.  It can either 1) propel itself in (approximately) a
straight line; or 2) {\it tumble} end over end. The bacterium effects
these behaviors by rotating the whip-like flagella which cover its
body. Clockwise rotation of individual flagella results in a coherent
rotation of the ensemble and propels {\it E. coli} through the water
in approximately a straight line (in a constant heading).
Counter-clockwise rotation of individual flagella produces an
incoherent rotation of the ensemble which causes {\it E. coli} to
tumble end over end (randomizing its heading).

Despite its limited behavioral repertoire, {\it E. coli} manages to
find food. It achieves this by increasing or decreasing its tumbling
rate depending upon the sign of the time derivative of the
concentration of chemical attractants produced by decaying organic
matter. That is, if the concentration of attractants is increasing,
{\it E. coli} tumbles less frequently (because it is moving in the
right direction).  Conversely, if the concentration of attractants is
decreasing, {\it E.  coli} tumbles more frequently (because it is
moving in the wrong direction).  To the chagrin of humans everywhere,
this simple strategy unfailingly guides the bacterium to the source of
the chemical attractant.

\section{Details}

In this project, you are going to write a program which draws the
trajectory of an {\it E. coli} bacterium looking for food.

\begin{itemize}
\item The food is located at position, $(0,300)$.
\item The bacterium starts out at position, $(x_0,y_0) = (0,0)$.
\item The initial heading of the bacterium, $\theta_0$, is {\bf
    random}.
\item When not tumbling, the bacterium moves in a straight line with
  speed one pixel per second.
\item The distance between the bacterium and the food can
be computed using the following formula:

\[
d_t = \sqrt{x_t^2 + (y_t - 300)^2}
\]

\noindent where $d_t$ is the distance of the bacterium from the food,
$x_t$ and $y_t$ are the $x$ and $y$ coordinates of the bacterium's
position (all at time, $t$).

\item The probability that the bacterium will tumble at any given time
can be computed using the following formula:

\[
p_t = \frac{1}{1 + e^{-100 (d_t - d_{t-1})}}
\]

\noindent where $d_{t-1}$ and $d_t$ are the distances of the bacterium
from the food at time, $t-1$ and $t$. Notice that $p_t$ is nearly one
when $(d_t - d_{t-1}) > 0$ (the bacterium is going in the wrong
direction) and nearly zero when $(d_t - d_{t-1}) < 0$ (the
bacterium is going in the right direction).

\item The heading of the bacterium at time $\theta_t$ remains the same
  with probability, $1 - p_t$, and changes by $\breve{\phi}$, a random
number between 0 and 360, with probability, $p_t$:

\[
\theta_t = \left\{
\begin{array}{cll}
\theta_{t-1} & {\rm with\;prob.} & 1 - p_t\\
\theta_{t-1} + \breve{\phi} & {\rm with\;prob.} & p_t
\end{array}\right.
\]

\noindent where $\breve{\phi}$ is a random number between 0 and 360.

\item The position of the bacterium at time $t$ can be computed 
from the position at time $t-1$ and the heading using the
following equations:

\begin{eqnarray*}
x_t & = & x_{t-1} - \sin \theta_{t-1}\\
y_t & = & y_{t-1} + \cos \theta_{t-1}
\end{eqnarray*}

\noindent where $\theta_{t-1}$ is the heading of the bacterium at time, $t-1$.

\item The bacterium stops when it is less than one pixel from the
  food, i.e., $d_{t-1} < 1.0$.

\end{itemize}

\section{Hints}

\begin{itemize}
  
\item The Scheme functions, {\it sin}, and {\it cos}, take arguments
  in radians, but the Plumbing Graphics function, {\it bend}, takes
  its argument in degrees.  Degrees can be converted to radians by
  multiplying by $\frac{2\pi}{360}$.

\item The Scheme function, {\it random}, takes an integer as
argument and returns a random number between $0$ and $n-1$.

\item Write a tail-recursive function, {\it ecoli-it}, which takes
  $x_{t-1}$, $y_{t-1}$, $d_{t-1}$, $\theta_{t-1}$ and a graphics
  object, $g_{t-1}$, representing the trajectory of the bacterium from
  start to $t-1$ and returns a graphics object representing the
  trajectory of the bacterium from start to finish.

\end{itemize}

\end{document}

