\chapter{The Coq Proof Assistant}
\label{ch:coq}

The \TMmodelName{} verification is formalized using the Coq proof assistant.
This chapter begins by motivating Coq as a good candidate for a verification system.
It then presents a brief overview of the term language of Coq with a focus on some the features used in \TMmodelName{}.

\section{Why Coq}

This section discusses the reasons Coq was chosen as the mechanized verifier for \TMmodelName{}.
It describes how higher-order logics can simplify first-order problems by permitting developers to generalize proofs.
It argues that intuitionistic logics are natural choices for automated verification, as truth values are represented as programs inhabiting a type.
It discusses how Coq implements both of these features and articulates the useful features of the Coq standard library for the \TMmodelName{} verification.

The high degree of automation available in first-order systems makes them appear very desirable.
However, the ability to generalize theorems in higher-order proof systems makes them more practical than first-order systems.
Any finite problem can be expressed in a first-order logic.
However, without the ability to generalize theorems, developers quickly become burdened with a multitude of specialized proof obligations.
Many first-order proof systems offer the ability to write functions to generalize these proofs.
However, these functions cannot be verified, increasing the unverified surface of the proof and consequently undermining confidence.
Although the safety problem and confinement policy for capability-based systems can be expressed as first-order problems, this verification effort uses Coq because it is a higher-order proof assistant.

Most higher-order logics available fit into two categories: classical higher-order predicate logic and intuitionistic type theory.
For proofs that can be automatically verified, intuitionistic and classical logics have the same expressive power.
They differ in how they view the concept of truth.
Classical logics reason about truth and falsehood directly, relying upon meta-analysis like term rewriting to prove a theorem.
Intuitionistic logic reasons about construction and refutation directly, requiring a witness for every truth.
These witnesses make statements in intuitionistic logic stronger than classical logic.

The concept of how truth is constructed directly informs computational verification.
Proofs as constructions and proofs as meta-inferences necessarily operate in different ways.
Constructions and theorems have a direct relationship with software terms and types according to the Curry-Howard isomorphism. \msdnote{Not citing}
In Coq, proofs as programs can be directly written by the developer and can be directly manipulated by other programs without resorting to meta-theory, simple type checking may suffice.
This reduces the amount of meta-logic necessary to express properties and forms very natural proofs.

Verifying a theorem in Coq is the act of constructing a program satisfying a type representing the theorem.
To any developer acquainted with parametric polymorphism and (co)inductive data types, reading and manipulating these programs will be familiar.
Base definitions and functions are executable programs that can be readily understood by developers unfamiliar with proofs, reducing mental overhead.
While specifying a program precisely can give the developer a great deal of power, Coq also includes a wide array of tools to help construct programs automatically.
Coq includes a tactic meta-language and pattern-matching system to assist the developer when searching for a program.
These are combined into a hint system that can be combined to produce a high degree of automation for domains that are highly syntactically driven.

The \TMmodelName{} verification utilizes a number of features of the Coq standard library.
Boolean decidability is used to place most propositions into Boolean logic, making them computationally decidable.
Decidability is a critical problem because undecidability hides the unknowable; a theorem with an unknowable assumption can still be verified.
By ensuring that all propositional hypotheses are isomorphic to Boolean functions, \TMmodelName{} ensures that the results are always known.

The Coq standard library also provides meta-theory support for equivalence relations.
The rewrite tactic in Coq can perform automated rewriting of any equivalence relation, not just built-in equality.
It requires only that relevant terms respect the equivalence relation for relevant types.
This permits the model to reasoning about potentially different, but semantically identical, types and terms.

The last major features of the Coq standard library utilized by \TMmodelName{} are the axiom-free finite set and map libraries. \cite{CoqFSet}
These are very large productions modeled after the OCaml Set and Map libraries.
They include a collection of supplemental libraries containing useful theorems pertinent to their interface as well as implementations including a fully concrete definition using lists.

\section{The Coq Term Language}

\Cref{ch:embed,ch:access,ch:safety,ch:flow,ch:confinement} contain a detailed theorem walk-through of the confinement verification in Coq.
As previously stated in \Cref{sect:intro:confidence}, one goal of this dissertation is to produce confidence in the confinement verfification result.
This dissertation presumes that reviewers have confidence in the proof assistant and it therefore does not discuss the mechanics of the proof construction.
As such, this section focuses exclusively on the useful portions of the Gallina term language of Coq.

Gallina is a higher-order functional language and constructive dependent type system that implements higher-order intuitionistic logic.
The syntax and semantics of Gallina are based on OCaml functions and data-types, but with dependently typed parametric polymorphism.
It contains the usual functions, anonymous functions, and fixpoints along with cofixpoints (sometimes called lazy fixpoints).
(Co)Inductive types are a generalized notion of (co)data-type with (co)constructor definitions.
Gallina also includes a highly type-generalized pattern matching system for (co)constructors.

All terms in Coq belong to one of three sorts: \coqkw{Set}, \coqkw{Prop}, and \coqkw{Type}.
\coqkw{Set} is the sort of ``specifications'' or programs, and \coqkw{Prop} is the sort of ``propositions'' or theorems.
The difference between the two is how they handle the type \mbox{\coqvar{*} \(\rightarrow\) \coqvar{*}}.
The type \mbox{\coqkw{Set} \(\rightarrow\) \coqkw{Set}} is not in the sort \coqkw{Set}, but the type \coqkw{Prop} \(\rightarrow\) \coqkw{Prop} is in the sort \coqkw{Prop}.
This makes \coqkw{Prop} impredicative, in that its terms may be self-defining, and \coqkw{Set} predicative, in that it is not.
The sort \coqkw{Type} is stratified and somewhat complex.
\coqkw{Type} is used very little in this effort and may be considered parametric for either \coqkw{Prop} or \coqkw{Set}.

Unlike general programming languages, all functions in Coq are obliged to terminate.
Definitions and anonymous functions do not permit recursion and simply terminate.
Fixpoints permit structural recursion that can be automatically inferred.
General functions permit the developer to specify both the function and the termination measure, though it may be possible for Coq to infer this as well.
Because all functions must terminate, (co)inductive data types are often used to express general propositions as dependent type families.

The connection between programs and proofs can be summarized in relationships with functions and inductive types.
Implication and universal quantification are expressed by dependent function types, respectively with or without a named parameter.
\coqvar{A} \(\rightarrow\) \coqvar{B} is syntactically the same as \(\forall\) (\coqkw{\_}:\coqvar{A}), \coqvar{B} where \coqkw{\_} is any free variable.
\coqvar{True} is the universally inhabited type and \coqvar{False} is the universally uninhabited type.
Negation, written \(\neg\) \coqvar{A} is syntactically \coqvar{A} \(\rightarrow\) \coqvar{False}.

Most other constructions are inductive types or involve pattern matching.
Conjunction, disjunction, and existential quantification are all inductive types.
The type (\coqvar{and} \coqvar{A} \coqvar{B}), written \coqvar{A} \(\wedge\) \coqvar{B}, has one constructor \coqvar{conj} requiring terms of types \coqvar{A} and \coqvar{B}.
The type (\coqvar{or} \coqvar{A} \coqvar{B}), written \coqvar{A} \(\vee\) \coqvar{B}, has two constructors \coqvar{proj1} and \coqvar{proj2} requiring only one term of type \coqvar{A} or \coqvar{B}, respectively.
Existential quantification over a predicate has one introduction constructor, \coqvar{ex\_intro}, that can only be constructed by a witness satisfying the quantified proposition.

\section{Model Abstraction}
\label{sect:coq:modelAbstraction}

\TMmodelName{} is constructed as an abstract implementation to allow it to be used as a framework for future system verifications.
Operating systems are not the only capability-based system; capability-based systems also include virtual machines, language runtimes, and distributed systems.
As an abstract model, \TMmodelName{} focus on the heart of the confinement problem, producing a result applicable across all domains.

\TMmodelName{} utilizes the Coq module type system as an abstraction mechanism.
This decision was motivated by the use of module type abstraction in the axiom-free finite set library.
Because abstractions and axioms are the same structure in Coq, \TMmodelName{} also provides a trivial implementation to produce an axiom-free result.
It is often the case that the abstract module types are verbatim software from implementation modules.
However, it is not possible to produce them by type inference in Coq version 8.3pl2.
As a work-around, the project includes simple tool to syntactically create a module type based on each trivial implementation through very simple annotations.

This verification includes the very primitive Perl script ``typeify.pl'' to automatically produce precise module types from module functors.
It does not process the full language of Coq, but processes the commands line-by-line using a very small state transition routine over a very strict module format.
The module must contain only one internal module functor, declared on a single line, and the functor parameter list must match the module type parameter list.
Theorems are abstracted by replacing the keyword ``Theorem'' with ``Parameter'' and removing all lines between commands ``Proof.'' and ``Qed.''
Although Coq allows theorems to nest and elide the ``Proof'' command, we do not handle these cases.
Two commands are supported as comments to provide better abstraction in the generated types.
The ``(* ABSTRACT *)'' command processes a ``Definition'' into an appropriate ``Parameter'' allowing other modules to override these definitions with other implementations.
The ``(* TYPE\_REMOVE *)'' command eliminates the subsequent line in the generated type altogether and is often used to eliminate helper theorems and lemmas.
Any potential errors introduced by this transformation will be caught when the original module against the generated signature.

It is necessary that each module functor and signature be pure, in that all dependencies are completely captured by parametricity.
The use of existentially declaring a module type loses type information in Coq 8.3 in ways that would be available in Coq 8.2.
Therefore, updated versions of the \COQFMap{} finite map libraries have been constructed to produce appropriate types.
The pattern of constructing pure functors from the trivial implementation is prevalent throughout \TMmodelName{} and produces an axiom-free proof with a type signature that can be satisfied in future efforts,
While this syntactic type construction is used wherever possible, there are certain portions of the proof which are encoded manually.

The following conventions regarding module names are used throughout this dissertation.
Modules that are also files have the \coqfilemodule{FileModule} font face where as inner modules have the \coqvar{InnerModule} font face.
The locations of each inner module should be clear from the surrounding context.
File modules containing functor implementations are suffixed with -\coqfilemodule{Impl}, while modules constructing a fully complete implementation by functor application are suffixed with -\coqfilemodule{Appl}.
File modules containing type signatures, or those which have no abstraction, are given no suffix.
Convenience file modules with supplemental libraries are suffixed with -\coqfilemodule{\_Conv} and are further suffixed as above.
All abstract module types passed as parameters and convenience modules share the same naming convention throughout the proof, which is summarized in \cref{table:coq:moduleConvention}.

\begin{table}
  \centering
  \begin{tabular}{| l | l |}
    \hline
    Instance & Declaration and location \\
    \hline \hline
    \COQARSet{} & \COQFSet{} of \COQAccessRight{} \\
    \COQRef{} & \COQReferenceType{} module of \COQReferences{}.v\\
    \COQRefS{} &  \COQRefSetType{} module of \COQRefSets{}.v\\
    \COQRefSet{} & \COQReference{} \COQFSet{} of \COQRefS{} \\
    \COQEdges{} &  \COQAccessEdgeType{} module of \COQAccessEdges{}.v \\
    \COQAccessGraph{} & \COQAccessGraphType{} module of \COQAccessGraphs{}.v\\
    \COQAG{} & \COQFSet{} of \COQAccessGraphType{} \\
    \COQSeq{} & \COQSeqAccType{} module of \COQSequentialAccess{}.v\\
    \COQCap{} & \COQCapabilityType{} of \COQCapabilities{}.v\\
    \COQCC{} & \COQCapabilityConv{} of \COQCapabilitiesUConv{}.v \\
    \COQCapS{} &  \COQCapSetType{} \\
    \COQCapSet{} & \COQCapability{} \COQFSet{} of \COQCapS{} \\
    \COQInd{} & \COQIndexType{} of \COQIndicies{}.v\\
    \COQObj{} & \COQObjectType{} of \COQObjects{}.v \\
    \COQOC{} & \COQObjectConv{} of \COQObjectsUConv{}.v \\
    \COQSys{} & \COQSystemStateType{} of \COQSystemState{}.v \\
    \COQSC{} & \COQSystemStateConv{} of \COQSystemStateUConv{}.v \\
    \COQSemDefns{} &  \COQSemanticsDefinitionsType{} of \COQSemanticsDefinitions{}.v \\
    \COQSem{} &  \COQSemanticsType{} of \COQSemantics{}.v \\
    \COQSemConv{} & \COQSemanticsConv{} of \COQSemanticsUConv{}.v \\
    \COQExe{} &  \COQExecutionType{} of \COQExecution{}.v\\
    \COQMut{} &  \COQMutationType{} of \COQMutation{}.v \\
    \COQSub{} &  \COQSubsystemType{} of \COQSubsystem{}.v \\
    \hline
  \end{tabular}
  \caption{Declaration and location of common module names.\label{table:coq:moduleConvention}}
\end{table}


\subsection{Frequency domain processing}
At the end of the structure there are some frequency domain processing blocks, as seen in \ref{fig:struct}. For this, first a short-time Fourier transform is taken and after the processing steps the signal is resynthesised via the inverse short time Fourier transform. Before resynthesis, two processing steps are applied to the signal.

First, the phases of the signal are locked by summing phases from adjacent bins.\cite{Puckette} This is done to suppress the so called phasiness of the signal.

Second, the amplitudes of the original signal's frequency bins are used to weigh the effected signal's bin amplitudes. This is not done uniformly, but instead the lower end of the spectrum is weighed more heavily. The weighing is done to get rid of amplitude modulation which is particularly prominent in the low frequency range \cite{dudas}. This is why the lower end of the spectrum is weighed more heavily, too.

Both of the frequency domain processing steps are just ways to polish the sound and get rid of some artifacts; the steps are not meant to add anything new to the signal. As such, they also don't have any physical counterpart.


\chapter{Chapter 2. A Math Primer for Aspiring Logicians}

\section*{2.7 Exercises}

	\begin{enumerate}

		\item[2.7.1] This depends on the answers you've given. The following correspond to my answers:

			\begin{enumerate}[(a)]

				\item We did not need to use any of the proof principles we discussed, we simply produced a counterexample.

				\item We used indirect proof. The argument form was as follows:
				\begin{itemize}

					\item Suppose that there is a possible situation in which the premises are true and the conclusion is false.

					\item We get a contradiction.

					\item Therefore there is no situation in which the premises are true and the conclusion false.

					\item So, in every situation where the premises are true, so must be the conclusion, meaning the inference is valid.

				\end{itemize}

				\item Same as (b)

				\item Same as (a)

				\item Same as (a)

				\item Same as (a)

			\end{enumerate}

		\item[2.7.2] Here are proofs for the facts. Note that this are not the only possible proofs, but they can function as examples. It's a bit tricky to illustrate the procedure that leads to these proofs, so I will present you with the finished end-product. For advice on how to find the proofs, see the slides.

			\begin{enumerate}[(a)]

			\item  The sum of two even numbers is even.

				\emph{Precise statement}. For all integers $n$ and $m$, if $n$ and $m$ are both even, then $n+m$ is even.

				\begin{proof}
				Let $n,m$ be two arbitrary integers (for universal generalization). Assume (for conditional proof) that $n$ and $m$ are both even. This means, by definition, that there exists an integer $k$ such that $n=2k$ and there exists an integer $l$ such that $m=2l$. Now consider $n+m$. Since $n=2k$ and $m=2l$, we have that $n+m=2k+2l$. But $2k+2l=2(k+l)$. So, there exists a natural number, namely $k+l$, such that twice that number is $n+m$. But by definition this just means that $n+m$ is even, which is what we needed to show. By conditional proof and universal generalization, the claim is proven.
				\end{proof}

			\item If the product of two numbers is odd, then at least one of the two numbers is odd.

			\emph{Precise statement}. Let $n$ and $m$ be integers. If $n\cdot m$ is odd, then either $n$ is odd or $m$ is odd.

				\begin{proof}
				We prove this claim by contrapositive proof. So, suppose that neither $n$ nor $m$ is odd. Note that since a number is odd iff it's not even, this just means that both $n$ and $m$ are even. For our contrapositive proof, we need to derive that $n\cdot m$ is also not odd. Since a number is odd iff it's not even, this means we have to show that $n\cdot m$ is even.  But we've already proven that if a number is even, then its product with any other number is even (2.3.9, example for conditional proof). So surely, if \emph{both} $n$ and $m$ are even, then $n\cdot m$ is even, which is what we needed to show.
				\end{proof}

			How could you have seen that contrapositive proof is a good strategy here? Well, whenever you have a conditional with a disjunction in the then-part, it's a good idea to try contrapositive proof.

			\item Every number is either even or odd.

				\emph{Precise statement}. Let $n$ be a natural number. Then $n$ is even or $n$ is odd (and, in fact, not both).

				\begin{proof}
				We prove this fact indirectly. So, let $n$ be an arbitrary number and suppose that $n$ is neither even nor odd, meaning $n$ is both not even and not odd. Since a number is odd iff it's not even, this means that $n$ is both even and not even. But that's a contradiction. So, by indirect proof, it's not the case that $n$ is neither even nor odd, meaning that $n$ is either even or odd, as desired.
				\end{proof}

			How could you see that you should use indirect proof to show this? Well, whenever you try to prove that one of two cases must obtain and you can't prove them from something you already know, indirect proof is a good idea.

			\item If you add one to an even number, you get an odd number.

				\emph{Precise statement}. Let $n$ be an integer. If $n$ is even, then $n+1$ is odd.

				\begin{proof}
				Let $n$ be an arbitrary integer and suppose that $n$ is even (for conditional proof). By definition, this means that there exists an integer $k$ such that $n=2k$. We now need to derive that $n+1$ must be odd. We do this via indirect proof. So, suppose that $n+1$ is also even, meaning that there exists an integer $l$ such that $n+1=2l$. Since $n=2k$ and $n+1=2l$, we can infer that $2k+1=2l$. From this we can infer that $1=2l-2k$. So, $1=2(l-k)$. But since $l-k$ is an integer, this would mean that 1 is an even number. And we know that $1$ isn't even, so we arrived at a contradiction. We can therefore conclude that $n+1$ is not even, i.e. odd, which is what we needed to show.
				\end{proof}

			Why can we assume that $1$ isn't even? Well, that's something that can itself be proven using the methods of the next chapter. But for the present purpose it's fine to assume it. Remember that our aim is to convince the reader that a purely axiomatic proof exists and not to provide one ourselves.

			\item The product of two prime numbers is not a prime number.

			\emph{Precise statement}: Let $n$ and $m$ be natural numbers. Then, if $n$ and $m$ are prime, then $n\cdot m$ is not prime.

			\begin{proof}
			Let $n$ and $m$ be two natural numbers and assume that both $n$ and $m$ are prime (for conditional proof). This means, by definition, that $n>1$ and $m>1$ and there exists no number $k,l<n$ such that $n=k\cdot l$ and there exist no numbers $i,j$ such that $m=i\cdot j$. We need to show that $n\cdot m$ is not a prime number. We do this indirectly. For suppose that $n\cdot m$ would be prime. This would mean $1<n\cdot m$ and there exist no numbers $a,b<n\cdot m$ such that $n\cdot m=a\cdot b$. But since $n>1$ and $m>1$, $n\cdot m>n$ and $n\cdot m>m$. So, there would be two numbers $a$ and $b$ with $a,b<n\cdot m$ and $n\cdot m=a\cdot b$, after all---just let $a=n$ and $b=m$. Contradiction. Hence $n\cdot m$ is not prime, as desired.
			\end{proof}

			\item No prime number \emph{bigger than two} is the product of an even and an odd number.

			\emph{Precise statement}. Let $n$ be a natural number. Then if $n>2$ and $n$ is prime, there do not exist numbers $k$ and $l$ such that $k$ is even, $l$ is odd and $n=k\cdot l$.

			\begin{proof}
			Suppose that $n$ is a natural number, that $n>2$ and that $n$ is prime. We need to derive that there are no numbers $k$ and $l$ such that $k$ is even, $l$ is odd and $n=k\cdot l$. We again, do this indirectly. So suppose that $k$ is even, $l$ is odd, and $n=k\cdot l$. Now, since $k$ is even, we know by our earlier observation that $n=k\cdot l$ is even, too. But we've also proved that if $n$ is prime and $n>2$, then $n$ is odd. And since $n$ is prime and $n>2$ by assumption, we get that $n$ is odd. So $n$ has to be both even and odd, which is a contradiction. Hence there are not numbers $k$ and $l$ such that $k$ is even, $l$ is odd and $n=k\cdot l$, which is what we needed to show.
			\end{proof}

		\end{enumerate}

		\item[2.7.3]

			\begin{enumerate}[(a)]

				\item A necessary but not sufficient condition for $n$ to be even is that $n$ is divisible by at least two numbers $k,l$ (not necessarily different). If $n$ is even, then there are two such numbers, in fact one of them is two. But there are numbers which are divisible by two distinct numbers and not even. E.g. $15=3\cdot 5$. Hence the condition is not sufficient.

				\item A sufficient condition but not necessary for $n$ to be even is that it's divisible by four. If $n$ is divisible by four, then it's divisible by two and thus even. But there are even numbers which are not divisible by four, for example, 14.

				\item A necessary and sufficient condition for $n$ to be even is that $n$ is divisible by two---that's the definition of being even. A perhaps more interesting example is the condition that $n$ be divisible by an even number. If $n$ is divisible by an even number, then it's even since an even number is divisible by two and a divisor of a divisor is a divisor. And if $n$ is even, then by definition $n$'s divisible by two, which is an even number. Hence the condition is both necessary and sufficient for $n$ to be even.

			\end{enumerate}

		\item[2.7.4]

			\begin{enumerate}

				\item The sum of two even natural numbers is even.

				\item Every natural number is either even or odd.

				\item The sum of the square of a number and that number itself is always even.

				\item There is no biggest negative real number.

			\end{enumerate}

		\item[2.7.5]

		\begin{proposition}
		Every prime number bigger than two is odd.
		\end{proposition}
		\begin{proof}[Proof (Informal sketch)]
		We prove this fact indirectly. Suppose that there exists a prime number which is bigger than two and even. Since the number is is even, it must be divisible by two. But by definition, a prime number cannot be divisible by any number smaller than it. Since our prime was supposed to be bigger than two but at the same time needs to be divisible by two, we arrive at a contradiction: our prime is both divisible by a number smaller than it and not. Hence a prime like this, which is bigger than two and even, cannot exist. So, we can conclude that every prime bigger than two is even.
				\end{proof}

	\end{enumerate}

%%% Local Variables:
%%% mode: latex
%%% TeX-master: "../../logic.tex"
%%% End:


\chapter{Particle Filter}
\label{chp:partFilter}
A particle filter is a method of estimating and describing the state of a system, as a set of samples of a posterior belief.
In the context of a particle filter, each sample is called a particle, which is a concrete instance of the system state, i.e. a hypothesis as to how the real world state might be.
Since the filter represents a distribution by a set of particles, instead of a parametric form such as a Gaussian, we can consider a particle filter to be non parametric.

\input{figure/ParticleFilter/particleDemo}

The state estimations of particle filters are in practice applied to robotics in form of global localization.
Global localization means that a robot with an unknown position, in an otherwise known map, can identify its approximate position through a series of sensor measurements and controlled movements.

The principle of using a particle filter for global localization is best explained through an illustrative example.
Figure \ref{fig:particleDemo} shows 4 stages og the state estimation, where figure \ref{subfig:demo1} show the initial state, where we know nothing about the robots actual position and therefore spread particles all over the map.
As the robot measures e.g. distances to different objects and moves around, we learn more about the position and can eliminate all the particles that doesn't fit our new beliefs, which in figure \ref{subfig:demo3} leads to two clusters of particles.
The two clusters are our best estimates due to the symmetry of the corridor, and the robot therefore has to move into one of the distinguishable rooms to identify the correct cluster, as shown in figure \ref{subfig:demo4}.

The filter actually builds on the \emph{survival of the fittest} thought, where the particles that best fit into the context of the robots measurements and movements are kept and copied, while particles that fits poorly are eliminated.
How well each particle fits the measured pose is expressed through importance weights, $w$, which are used in the algorithm of a particle filter to chose which particles to keep and which to eliminate.

The algorithm is recursive, i.e. the belief $bel(x_t)$ is constructed from the previous belief $bel(x_{t-1})$, that existed one time step earlier.
Therefor the set of particles $X_{t-1}$ is one of the inputs to the algorithms.
The other inputs are the new measurement $z_t$ and the most recent set of movements controls $u_t$.
The basic form of the particle filter algorithm is listed in table \ref{tab:partAlgo}.
Line 4-5 moves a particle $x_{t-1}^{[n]}$ to $x_t^{[n]}$ based on the control sequence $u_t$ and assigns a new importance weight, $w_t^{[n]}$ according to the measurement $z_t$.\\
This new importance weight is then used in line 8-11 to determine which particles to keep and which to eliminate in order to generate the new belief, represented be a set of particles, $X_t$.
A process also known as resampling.

\begin{table}[!b]
    \caption[Short Caption]{The basic particle filter algorithm.}
    \label{tab:partAlgo}
\begin{tabular}{|l p{12cm}|}

    \hline
    1: \qquad  & \textbf{Algorithm Particle\_ filter}($X_{t-1}, u_t, z_t$)\textbf{:} \\
    2: \qquad  & \qquad $\bar{X_t} = X_t = Ø$ \\
    3: \qquad  & \qquad for $n = 1$ to $N$ do\\
    4: \qquad  & \qquad \qquad sample $x_t^{[n]} \sim p(x_t | u_t, x_{t-1}^{[n]})$\\
    5: \qquad  & \qquad \qquad $w_t^{[n]}=p(z_t|x_t^{[n]}$\\
    6: \qquad  & \qquad \qquad $\bar{X_t} = \bar{X_t} + \langle x_t^{[n]}, w_t^{[n]} \rangle $  \\
    7: \qquad  & \qquad endfor \\
    8: \qquad  & \qquad  for $n = 1$ to $N$ do\\
    9: \qquad  & \qquad \qquad draw $i$ with probability $\propto w_t^{[i]}$\\
    10: \qquad & \qquad \qquad add $x_t^{[i]}$ to $X_t$\\
    11: \qquad & \qquad endfor\\
    12: \qquad & \qquad return $X_t$\\
    \hline
\end{tabular}
\end{table}

\noindent The resampling process is the part of the algorithm where the particles should converges towards the robots true position.
But the process of choosing which particles to keep and which to kill is not trivial and can be approached in multiple ways, one of which is called \emph{Low Variance Resampling} algorithm.

The Low Variance Resampling algorithm is a probabilistic approach, where the particles to survive is chosen from a probability distribution based on each particles weight.
%This probability is introduced by the use of a random variable called $\beta$.
%\begin{align*}
%    \beta = 2 \cdot w_{max} \cdot U(0, 1)
%\end{align*}
%The $\beta$-value is a step size in a cyclic environment of the particle weights as shown i figure \ref{fig:RePart}.
%Each particle is scaled by its weights and if you step twice in a row in the same particle, this particle is kept for the next iteration of the particle filter.
The steps of the Low Variance Resampling algorithm is as follows:
\begin{enumerate}
    \item Chose an initial index, $i$ from a uniform distribution of all particles in the set to be resampled, $i=U(1,N_{particles})$
    \item Generate a new random $\beta$-value, $\beta = 2 \cdot w_{max} \cdot U(0, 1)$
    \item if $\beta > w_t^{[i]}$
    \begin{enumerate}
        \item Subtract the weight from $\beta$.
        \item Increment the index $i$.
    \end{enumerate}
    \item if $\beta < w_t^{[i]}$
    \begin{enumerate}
        \item Add the particle to the new set of particles, $X_{t+1}$
    \end{enumerate}
    \item Repeat from step 2, until $sizeof \left( X_{t+1} \right) = sizeof \left( X_{t} \right)$
\end{enumerate}


\documentclass[12pt]{article}
\newcommand{\kg}{\mathrm{kg}}
\newcommand{\m}{\mathrm{m}}
\newcommand{\s}{\mathrm{s}}
\newcommand{\J}{\mathrm{J}}
\newcommand{\mps}{\m\,\s^{-1}}
\newcommand{\kcal}{\mathrm{kcal}}
\begin{document}
\newcounter{problem}
\thispagestyle{empty}

\section*{NYU General Physics 1---Problem set 6}

\paragraph{Problem~\theproblem:}\refstepcounter{problem}%
\textsl{(a)} What combination of mass $m$ and speed $v$ have units of energy?

\textsl{(b)} What combination of pressure $P$ and length $L$ have units of energy?

\textsl{(c)} What combination of acceleration $g$, mass $m$, and length $L$ have units of energy?

\textsl{(c)} What combination of density $\rho$, length $L$, and speed $v$ have units of energy?

\textsl{(d)} What is an eV in J?  This is the typical energies of what kinds of energetic events?

\textsl{(e)} What is a ``ton of TNT equivalent'' in J?  What is it's cultural significance?

\textsl{(f)} What is a ``barrel of oil equivalent'' in J?  What is it's economic significance?

\paragraph{Problem~\theproblem:}\refstepcounter{problem}%
A standard-sized and typically able college-age human  walks into a building for an appointment on the 10th story.  The
elevator is broken.  She walks up the 9 stories.  Roughly speaking:

\textsl{(a)} How much mechanical energy does she need to expend to climb
those 9 stories?

\textsl{(b)} How much time do you think it takes her to climb those
stairs?  Assume she is at least somewhat motivated to get to her
appointment.  If you are having trouble estimating this, hire a friend
to time themselves climbing stairs.  Use that time and the total
energy from part \textsl{(a)} to get a power, and express the power in
horsepower.  Are you surprised?  Why is horsepower defined as it is?

\textsl{(c)} Now convert the energy you got in part \textsl{(a)} to
what dieticians call ``Calories'', which are really SI kcal units.
What fraction of a standard human $2000\,\kcal$ diet was this stair
climbing exercise?  Does this make sense given what you know about
programs of ``exercise''?

\textsl{(d)} How many flights of stairs could our subject climb in a day if
all her body did was convert a $2000\,\kcal$ input of food into
stair-climbing energy?  Why is that not at all a realistic description
of the body?  On what bodily processes is energy spent in forms
\emph{other} than mechanical forms?

\paragraph{Problem~\theproblem:}\refstepcounter{problem}%
A student of mass $m_\mathrm{student}=80\,\kg$ stands at rest next to
a block of ice of mass $m_\mathrm{ice}=320\,\kg$, also at rest, on a
frictionless frozen lake.  The student pushes on the block until the
block is moving away from the student at $1.5\,\mps$ (that is, until
$\left|\vec{v}_\mathrm{ice}-\vec{v}_\mathrm{student}\right|=1.5\,\mps$).
How much work did the student do?  Give your answer in $\J$.  Don't
forget to conserve linear momentum!  \emph{Hint:} All that work went into
kinetic energy.  \emph{Another hint:} One of the hard things about
this problem is that I am giving you the \emph{relative} velocity and
not the absolute velocity.  How are you going to deal with that?
Spend some time visualizing the problem before writing equations.

\end{document}


\section{Secured AES: Affine masking}
\label{sec:secured_aes}
The version of the AES is an affine implementation according to the paper \emph{Affine masking against high-order side channel analysis}~\cite{FMPR10a}.
Each byte state of the AES state, denoted $\statea[i]$ for the $i$-th byte, is manipulated under the form $\rmult \times \statea[i] \oplus \stateb[i]$: $\rmult$ is a non zero random byte, $\stateb[i]$ is initialized with 16-random bytes denoted $\maes[0]\dots \maes[15]$, and $\times$ denotes the multiplication over the AES finite field~\cite{FIPS197}.
For each round, the AES operations are applied to both $\statea$ and $\stateb$.

Similarly, the key schedule operation is also protected by manipulating each byte of the key state, denoted  $\stateK[i]$, under an affine form $\rmult' \times \stateK[i] \oplus \keym[i]$ where $\keym$ is initialize with 16-random bytes denoted $ \mkey[0] \dots \mkey[15]$ independent from the aes random bytes $\maes[0]\dots \maes[15]$. As the key schedule is performed independently from encryption and decryption operations, before using each masked key byte,
it has to be changed into $\rmult \times \stateK[i] \oplus \keym[i]$ (same multiplicative byte $\rmult$) to have a consistent computation.

To sum up, the AES encryption/decryption and the key schedule each use 19 random bytes as input:
\begin{itemize}
\item 16 bytes for Boolean masking $\maes[0]\dots \maes[15]$/$\mkey[0]\dots \mkey[15]$ that initialized the masking state $\stateb$/$\stateK$;
\item 1 multiplicative byte $\rmult$/$\rmult'$;
\item 2 bytes $\rin $, $\rout$ / $\rin'$, $\rout'$ (two boolean masking bytes used for SubByte operation).
\end{itemize}

To make this report more readable, we provide the correspondance Table ~\ref{tab:notations} between the notations  in this report (``Here'') and in the ``assembly code''.

\begin{center}

\begin{tabular}{lll}
	  Assembly code & Here & size \\ \hline
%	 raw key  & \texttt{t} & $\key$ & 16\\
\texttt{key\_rin[0]} 		& $\rin'$ 		& 1\\
 \texttt{key\_rout[0]} 		& $\rout '$ 	&1\\
\texttt{key\_rmult[0]} 		& $\rmult ' $	&1\\
 \texttt{key\_maskedState[i]} 	& $ \rmult \times \stateK[i] \oplus \keym[i] $ & 1\\
 \texttt{key\_masksState[i]} 	& $ \keym[i]$ & 1\\
\texttt{key\_gtab} 			& $\gtab$  	&$ 16 \times 16$ \\
\texttt{key\_permIndicesMC} &$\perMC$ & 4\\
\hline
 \texttt{aes\_state[i]} & $\rmult \times \statea[i] \oplus \stateb[i] $ & 1\\
 \texttt{aes\_state2[i]} & $\stateb[i]$  & 1\\
\texttt{aes\_rin[0]} & $\rin$ &1\\
\texttt{aes\_rout[0]} & $\rout$ &1\\
\texttt{aes\_rmult[0]} & $\rmult$ &1\\
 \texttt{aes\_gtab} &  $\gtab$  &$ 16 \times 16$\\
 \texttt{aes\_permIndices} & $\permIndices$& 16\\
\texttt{aes\_permIndicesBis} & $\permIndicesbis$ & 16\\
\texttt{aes\_permIndicesMC} & $\perMC$  & 4 \\
 \texttt{aes\_permIndicesBisMC} & $\perMCbis$  &4 \\
 \texttt{aes\_sboxMasked} & $\sboxm$ & $16 \times 16$ \\
\hline
\end{tabular}
\captionof{table}{Notations correspondance between this report and the assembly code. Sizes are in number of bytes.}
\label{tab:notations}
\end{center}

\noindent We can distinguish three main steps:
\begin{itemize}

	\item[1] Pre-processing: before the AES rounds, the following operations in this order are performed : loading of inputs, computation of the table $\gtab$ (multiplication by $\rmult$), computation of the affine sbox denoted $\sboxm$, key schedule with affine masking.

	\item[2] AES rounds: 10 AES rounds with affine masking of the state and subkeys.

	\item[3] Post-processing: after AES rounds, the state $\statea$ is unmasked by removing the Boolean mask $\stateb$ and by removing the multiplicative factor $\rmult$ (multiplying by $\rmult^{-1}$).
\end{itemize}

\noindent \underline{Shuffling:} Many sub-operations on the AES state are performed in a random order: each byte is processed in a random order with pre-computed permutation based on the input random values.
For AES rounds:
$\perMC$ is used to shuffle MixColumns of $\statea$ and $\perMCbis$ to shuffle MixColumns of $\stateb$. Permutation $\perMC$ (resp. $\perMCbis$) is computed from the initial value $\stateb[0]=\maes[0]$ (resp. $\stateb[1]=\maes[1]$).
The permutation $\permIndices$ is used to shuffle SubBytes and ShiftRows of $\statea $ and the permutation $\permIndicesbis$ is used to shuffle SubBytes and ShiftRows of $\stateb$. These permutations are computed from $\maes[0], \maes[1], \maes[2], \maes[3]$.
%the initial value of $\stateb[0],$ $ \stateb[1], \stateb[2]$ and $\stateb[3]$.

For key schedule: the four permutations are similar.
The permutation $\perMC$ is used to shuffle the manipulation of the words' coordinates of the masked key state (the term word referring here to $4$-bytes vector) and $\perMCbis$ is used to shuffle the manipulation of the words' coordinates of $\keym$. The former permutation is computed from $\mkey[0]$, while the latter one is computed from $\mkey[1]$.
%the initial $\keym[0]$ value.
The permutation $\permIndices$ is used to shuffle SubBytes and ShiftRows of the masked key state and $\permIndicesbis$ is used to shuffle SubBytes and ShiftRows of the key mask state $\keym$. These permutations are computed from $\mkey[0], \mkey[1], \mkey[2], \mkey[3]$.
%the initial values of $\keym[0], \keym[1], \keym[2]$ and $\keym[3]$.


\begin{document}

\chapter{Objectives}

\label{chapter:objectives}

\section{Primary}

The main objective of this work is to develop an algorithm that generates a
quantitatively safe trajectory for a robot through an uncertain dynamic
environment by utilizing information about how dynamic obstacles are going to
move in the future and to develop a formal probabilistic representation of
stochastic dynamic obstacles. This can be simply stated as determining the
curvature that minimizes the line integral over the dynamic cost distribution
for a given set of dynamic obstacles.

\begin{equation}
    J(C, A) = \int \limits_{C} \exp{\Big(P(x, y, t_0, t_m, A) + 1\Big)} \,
    \mathrm{d}s
    \label{eq:objective}
\end{equation}

Eq.~\ref{eq:objective} describes the objective function, $J$, that needs to be
minimized with respect to the curvature in order to determine the safest path
through the environment. In Eq.~\ref{eq:objective}, the function $P$ is the
cost surface for a given time interval and set of obstacles and represents the
cost of coming in collision with or moving towards the trajectory of any
obstacle in the environment. More description about $P$ is given in
Sec.~\ref{sec:cost} and is formally defined in Eq.~\ref{eq:prob}.  More
precisely, the objective of this work to develop an algorithm that will provide
an approximate solution to Eq.~\ref{eq:argminobjective} which will return a
significantly low cost path through a environment for a given set of obstacles.
The solution is described in Sec.~\ref{sec:design_planner}

\begin{equation}
    \Gamma(A) = \argmin{C} \, J(C, A)
    \label{eq:argminobjective}
\end{equation}

\section{Secondary}

The main secondary objective for this work is to show that the proposed
solution can provide safer paths than standard planners such as potential
fields by leveraging information about how the obstacles move through the
environment. Quantitative and qualitative experiments have been conducted that
provide evidence that the proposed solution does indeed produce safer paths
based on the safety metrics that have been devised for this work. These results
are shown in Ch.~\ref{chapter:results}.

\end{document}


\chapter{Flow of a uniform incompressible viscous fluid}\label{c4}
\section{Introduction}\label{c4s1}
\begin{itemize}
\item A fluid is considered to be incompressible if
\begin{equation}\label{c4s1e1}
\md{\rho} = 0,
\end{equation}
in which case, the equation of mass conservation \eqref{c3s6e1} reduces to
\begin{equation}\label{c4s1e2}
\Delta = \dive\vec{u} = 0
\end{equation}
Equation \eqref{c4s1e2} when used in the momentum balance equation \eqref{c3s6e2} gives
\[
\rho\md{u_i} = \rho F_i - \pdt{p}{x_i} + 2\mu\frac{\partial e_{ij}}{\partial x_j} =
\rho F_i - \pdt{p}{x_i} + \mu\frac{\partial u_i}{\partial x_j \partial x_j} + \frac{\partial}{\partial x_i}\pdt{u_j}{x_j}
\]
The last term on the right hand side is zero so that
\begin{equation}\label{c4s1e3}
\rho\md{\vec{u}} = \rho\vec{F} - \grad p + \mu\nabla^2\vec{u}
\end{equation}
is the equation of motion. Further, since $\rho$ is a constant, there are only four unknowns, $\vec{u}$ and $p$. If $\rho$ and $T$ are fixed, then by the equation of state, the thermodyamic
pressure is fixed. For an incompressible fluid, the thermodynamic and mechanical pressures are identical so that $p$ in \eqref{c4s1e3} is a fixed quantity. Therefore, equation \eqref{c4s1e3}
suffices for finding the unknowns.

\item We make an assumption, stronger than incompressibility, that the density of the fluid is uniform. That is, $\rho$ is independent of $\vec{x}$. Such an assumption is valid if there
is no motion driven by buoyancy forces. Thus, we do not consider \enquote*{free convection} in this chapter.

\item Writing \eqref{c4s1e3} so that the left hand side is accelaration,
\[
\md{\vec{u}} = \vec{F} - \frac{1}{\rho}\grad p + \nu\nabla^2\vec{u},
\]
where $\nu = \mu/\rho$ is the kinematic viscosity of the fluid. It is the \enquote*{diffusivity} of fluid velocity and like all such quantities has dimensions $[L^2 T^{-1}]$.

\item It is difficult to tell when the effects of viscosity can be ignored or when they matter, despite the small value of $\mu$ for common fluids. Therefore, we take the conservative stand
and study its effect.

\item If $\rho$ is uniform and if we write $p = p_0 + \rho\vec{g}\cdot\vec{x} + P$, where $p_0$ is a constant and $P$ is a function of $\vec{x}$ and $t$, then
\[
\grad p = 0 + \rho\vec{g} + \grad{P}
\]
or $\rho\vec{g} - \grad{p} = -\grad{P}$ and hence the equation of motion \eqref{c4s1e3} becomes
\[
\rho\md{\vec{u}} = -\grad P + \mu\nabla^2\vec{u}
\]
The effect of gravity is then folded in the new variable $P$. Thus, we can use the quantity $P$ instead of mechanical pressure $p$ if it does not show up in the boundary conditions. For $P$
is a mathematical artefact while boundary conditions are always in terms of a physical quantity. If $\rho$ is constant then $P = p - \rho\vec{g}\cdot\vec{x}$ is indeed a known quantity.
\end{itemize}
\subsection{Exercises}
\begin{enumerate}
\item Consider a fluid moving through a cylinder and a cylindrical polar coordinate system with its $z$ axis
coinciding with the axis of the cylinder. Then the normal component of the deviatoric stress is
\[
\mu e_{\sigma\sigma} = \mu\pdt{u_\sigma}{\sigma}.
\]
Since the fluid does not penetrate the cylinder, $u_\sigma = 0$ and the result follows immediately.

\item The expression for the stress tensor is
\[
\sigma_{ij} = -p\delta_{ij} + 2\mu e_{ij},
\]
where the rate of strain tensor
\[
e_{ij} = \frac{1}{2}\left(\pdt{u_i}{x_j} + \pdt{u_j}{x_i}\right).
\]
We know that
\[
\pdt{u_i}{x_j} = e_{ij} + \xi_{ij}
\]
so that
\[
\sigma_{ij} = -p\delta_{ij} + \mu(2\pdt{u_i}{x_j} - 2\xi_{ij}).
\]
Using equation (2.3.9) from the book,
\[
\sigma_{ij} = -p\delta_{ij} + \mu\left(2\pdt{u_i}{x_j} + \epsilon_{ijk}\omega_k\right)
\]
so that
\[
\sigma_{ij}n_j = -p\delta_{ij}n_j + \mu\left(2n_j\pdt{u_i}{x_j} + \epsilon_{ijk}n_j\omega_k\right).
\]
The left hand side is the force per unit area exerted across a surface element with normal $\un$. The right
hand side, written in Gibbs' notation is
\[
-p\un + \mu(2\un\cdot\grad\vec{u} + \un \times \vec{\omega}).
\]
Now consider the stress at a rigid boundary. If $n_j$ is a normal to the right surface then there is no velocity
along that direction. That is $u_j = 0$. Therefore, in this situation $e_{ij} = \xi_{ij}$ and hence
\[
\sigma_{ij} = -p\delta_{ij} + 2\mu \xi_{ij}.
\]
Once again using equation (2.3.9) from the book, we get
\[
\sigma_{ij} = -p\delta_{ij} - \mu \epsilon_{ijk}\omega_k,
\]
so that the force per unit area on the surface normal to $n_j$ is
\[
\sigma_{ij}n_j = -p\delta_{ij}n_j - \mu \epsilon_{ijk}n_j\omega_k,
\]
In Gibbs' notation, the right hand side is
\[
-p\un - \mu\un\times\vec{\omega}.
\]
\end{enumerate}

\section{Steady unidirectional flow}\label{c4s2}
\begin{itemize}
\item The equation of a steady flow along the $x$ axis is
\begin{equation}\label{c4s2e1}
\frac{\partial^2 u_x}{\partial y^2} + \frac{\partial^2 u_x}{\partial z^2} = -\frac{G}{\rho},
\end{equation}
where $G$ is the pressure gradient. $u_y$ and $u_z$ are both zero and $u_x = u_x(y, z)$.

\item In the case of flow through a long pipe of a circular cross section, we transform equation \eqref{c4s2e1}
in cylindrical polar coordinates so that it becomes
\begin{equation}\label{c4s2e2}
\frac{1}{r}\frac{\partial}{\partial r}\left(r\pdt{u}{r}\right) = -\frac{G}{\rho}.
\end{equation}
Its solution subject to the boundary conditions $u(r) = 0$ and $u$ is finite is
\begin{equation}\label{c4s2e3}
u(r) = \frac{G}{4\mu}(a^2 - r^2).
\end{equation}
The volume flux is calculated as follows. Consider two cylinders coaxial with the pipe having radii $r$ and $r +
dr$. If their ``height" is $dx$ then the volume between them is $dV = 2\pi (r + dr) dx - 2\pi rdx = 2\pi rdrdx$.
Since $dx = udt$, $dV = 2\pi r dr u dt$ or
\[
\td{V}{t} = 2\pi r u dr.
\]
This is the rate of flow of volume between the two cylinders. Therefore, the total flux is
\begin{equation}\label{c4s2e4}
Q = \int_0^a \td{V}{t} = \frac{\pi G a^4}{8\mu}.
\end{equation}
The only non-zero components of the rate of strain tensor are
\[
e_{rx} = e_{xr} = \frac{1}{2}\pdt{u}{r}
\]
so that the tangential stress at the wall is
\[
\mu\left[e_{rx} + e_{xr}\right]_{r=a} = -\frac{1}{2}Ga
\]
The rate of dissipation is
\[
\Phi = \frac{2\mu}{\rho}e_{ij}e_{ij} = \frac{G^2\rho^2}{4\rho\mu}.
\]

\item We will now solve the Navier-Stokes equation for a steady, laminar flow through an elliptical pipe. But
before we do that, we note that curves of equal velocity in a pipe of circular cross section are circles. For
equation \eqref{c4s2e3} can be written in the form $r^2 = $constant for a fixed value of $u$. We expect that the
flow through an elliptical pipe too will have the same property.

Let the equation of the cross section be
\[
\frac{y^2}{b^2} + \frac{z^2}{c^2} = 1
\]
or $c^2y^2 + b^2z^2 = b^2c^2$ and let the velocity profile be of the form $u(y, z) =\alpha y^2 + \beta z^2 +
\gamma$. Substituting it in
\eqref{c4s2e1}, we get
\begin{equation}\label{c4s2e5}
\alpha + \beta = -\frac{G}{2\mu}.
\end{equation}
The velocity profile will coincide with the ellipse of $\alpha = kc^2, \beta = kb^2, \gamma = -kb^2c^2$ for some
constant $k$. Substituting these in equation \eqref{c4s2e5} we get
\begin{equation}\label{c4s2e6}
k = -\frac{G}{2(b^2 + c^2)\mu}
\end{equation}
Now that we have got $k$ in terms of the physical parameters of the problem, we immediately have
\begin{eqnarray*}
\alpha &=& -\frac{Gc^2}{2(b^2 + c^2)\mu} \\
\beta  &=& -\frac{Gb^2}{2(b^2 + c^2)\mu} \\
\gamma &=& -\frac{Gb^2c^2}{2(b^2 + c^2)\mu}
\end{eqnarray*}
so that the velocity profile is
\begin{equation}\label{c4s2e7}
u(y, z) = \frac{G}{2\mu(b^{-2} + c^{-2})}\left(\frac{y^2}{b^2} + \frac{z^2}{c^2} - 1\right)
\end{equation}

\item Navier-Stokes equation for a steady, laminar flow through a rectangular pipe is
\begin{equation}\label{c4s2e8}
\nabla^2 u = -\frac{G}{\mu}.
\end{equation}
Supposing $u^\prime$ is a solution of the Laplace's equation then it is easy to check
that
\[
u^\prime - \frac{G}{2\mu}(b^2 - y^2)
\]
is a solution of \eqref{c4s2e8}. The goal then is to find $u^\prime$. $u(\pm b, z) = 0$ and
$u(y, \pm c) = 0$ implies that $u^\prime(\pm b, z) = 0$ and $u^\prime(y, \pm c) = G(b^2 - y^2)/(2\mu)$.
Let us assume that $u^\prime(y, z) = Y(y)Z(z)$, so that
\begin{eqnarray*}
Y^\tp &=& -k^2 Y \\
Z^\tp &=& k^2 Z
\end{eqnarray*}
where $k^2$ is a constant. The choice of sign of $k^2$ is determined by the need to satisfy the
boundary conditions on $u^\prime$. The other choice of sign will make $Y$ a hyperbolic function,
for which we cannot satisfy the boundary conditions. The solutions of the above ordinary differential
equations are
\begin{eqnarray*}
Y &=& A\cos(ky) + B\sin(ky) \\
Z &=& C\cosh(kz) + D\sinh(kz)
\end{eqnarray*}
$Y(\pm b) = 0$ gives $k = (2n+1)\pi/(2b)$ and $B = 0$. $Z$ being an even function of $z$ requires that
$D = 0$. Thus,
\[
u^\prime = A_n\cos\left(\frac{(2n+1)\pi y}{2b}\right)\cosh\left(\frac{(2n+1)\pi z}{2b}\right)
\]
or that the general solution of the Laplace's equation is
\begin{equation}\label{c4s2e9}
u^\prime = \sum_{n \ge 0}A_n\cos\left(\frac{(2n+1)\pi y}{2b}\right)\cosh\left(\frac{(2n+1)\pi z}{2b}\right).
\end{equation}
Finally, the solution of \eqref{c4s2e8} is
\begin{equation}\label{c4s2e10}
u(y,z)=\sum_{n \ge 0}A_n\cos\left(\frac{(2n+1)\pi y}{2b}\right)\cosh\left(\frac{(2n+1)\pi z}{2b}\right) - \frac{G}{2\mu}(b^2 - y^2).
\end{equation}
Equivalently,
\begin{equation}\label{c4s2e11}
u(y,z)=\sum_{n \text{ odd}}A_n\cos\left(\frac{n\pi y}{2b}\right)\cosh\left(\frac{n\pi z}{2b}\right) - \frac{G}{2\mu}(b^2 - y^2).
\end{equation}

\item The remark above equation (4.3.13) is a bit confusing. When the flow is steady there is no
net force on it and the acceleration is zero. The force of gravity balances the viscous drag.

\item The governing equation for paint brush flow is
\begin{equation}\label{c4s2e12}
\nabla^2 u = 0,
\end{equation}
where $u$ is a function of $y$ and $z$ coordinates. The boundary conditions are
\begin{eqnarray}
u(0, z) &=& 0 \label{c4s2e13} \\
u(b, z) &=& 0 \label{c4s2e14} \\
u(y, 0) &=& U,\; 0 < y < b \label{c4s2e15} \\
\lim_{z \rightarrow \infty}u(y, z) &=& 0 \label{c4s2e16}
\end{eqnarray}
Once again, we use the method of separation of variables to write $u(y, z) = Y(y)Z(z)$ and hence
\begin{eqnarray*}
Y^\tp &=& -k^2 Y \\
Z^\tp &=& k^2 Z
\end{eqnarray*}
The choice of sign of the constant of separation is dictated by the boundary conditions. If
\[
Y(y) = A\cos(ky) + B\sin(ky)
\]
then $Y(0) = 0$ and $Y(b) = 0$ require us to have $A = 0$ and $kb = n\pi$ or
\begin{equation}\label{c4s2e17}
Y(y) = B\sin\left(\frac{n\pi y}{b}\right).
\end{equation}
The solution of the $z$-equation is
\[
Z(z) = Ce^{kz} + De^{-kz}.
\]
Equation \eqref{c4s2e16} requires $C = 0$. The solution $u$ can thus be written as
\begin{equation}\label{c4s2e18}
u(y, z) = \sum_{n=1}^\infty A_n \exp\left(-\frac{n\pi z}{b}\right)\sin\left(\frac{n\pi y}{b}\right).
\end{equation}
We still have not used the boundary condition \eqref{c4s2e15}. Putting it in the
previous equation gives
\begin{equation}\label{c4s2e19}
U = \sum_{n=1}^\infty A_n \sin\left(\frac{n\pi y}{b}\right).
\end{equation}
We now use the relation
\begin{equation}\label{c4s2e20}
\int_0^\pi\sin(mx)\sin(nx)dx = \frac{\pi}{2}\delta_{mn}
\end{equation}
or,
\begin{equation}\label{c4s2e21}
\int_0^b \sin\left(\frac{m\pi y}{b}\right)\sin\left(\frac{n\pi y}{b}\right)dy = \frac{b}{2}\delta_{mn}.
\end{equation}
Using it in equation \eqref{c4s2e22} we get
\begin{equation}\label{c4s2e22}
A_n = \begin{cases}
0 & \text{ if } n \text{ is even.} \\
\frac{4U}{n\pi} & \text{ if } n \text{ is odd.}
\end{cases}
\end{equation}
Thus, the solution of the boundary value problem is
\begin{equation}\label{c4s2e23}
u(y, z) = \frac{4U}{\pi}\sum_{n\text{ odd}} \frac{1}{n}\exp\left(-\frac{n\pi z}{b}\right)\sin\left(\frac{n\pi y}{b}\right).
\end{equation}

\item Before leaving this section, we revisit the opening remarks in the book. If the flow is uni-directional and
if the flow velocity is independent of the coordinate in the flow direction then the convective term $\vec{u}\cdot
\grad{\vec{u}}$ is zero. The equation of motion becomes
\[
\pdt{\vec{u}}{t} = -\grad{p} + \mu\nabla^2\vec{u}.
\]
Without loss of generality assume that the flow is in the $x$ direction. Since $\vec{u}$ is independent of $x$, it is
evident that so is $\grad{p}$, or $p$. The flow wise motion is thus independent of the span wise motion. The motion in
the $yz$-plane is independent of the flow.

\item Let us now confine ourselves to the motion of a fluid in a long cylindrical pipe whose generators are parallel
to the $x$-axis. There is no pressure gradient in the $y$ or $z$ axes and hence
\begin{eqnarray*}
\pdt{v}{t} &=& -\mu\nabla^2 v \\
\pdt{w}{t} &=& -\mu\nabla^2 w
\end{eqnarray*}
Such a motion cannot be sustained against the viscous dissipation unless sustained by continual energy supply from
the tangential stresses at the boundary. The tangential stress is $\tau_{ij} = \mu e_{ij}$ so that the force per unit
area is $f_j = n_i\tau_{ij} = \mu n_i e_{ij}$ and the power supplied by it is $f_j u_j = \mu n_i e_{ij} u_j$. In the
span-wise plane, $n_1 = 0, u_1 = 0$ and this expression becomes
\[
\mu\left\{n_2 (e_{22}u_2 + e_{23}u_3) + n_3(e_{32}u_2 + e_{33}u_3)\right\}.
\]
Integrating this expression along a curve in the span-wise plane gives
\[
\mu\oint\left\{n_2 (e_{22}u_2 + e_{23}u_3) + n_3(e_{32}u_2 + e_{33}u_3)\right\}dl
\]
This expression is the power supplied by the boundary via tangential stresses. In the motion of a fluid through a
pipe, there are no tangential stresses and therefore there is no motion in the span-wise plane.
\end{itemize}

\section{Unsteady unidirectional flow}\label{c4s3}
\begin{itemize}
\item In this section we consider motion triggered by an unsteady movement of a boundary keeping the pressures
far upstream and far downstream equal. We can control only the pressures far upstream and far downstream in an
experiment. When we describe the problem statement we restrict ourselves in keeping them equal and we make no
statement about the pressure midway.

\item Navier-Stokes equation when $\grad{p} = 0$ and when the motion is in a single direction, say $x$, is
\begin{equation}\label{c4s3e1}
\pdt{u}{t} = \nu\left(\frac{\partial^2 u}{\partial y^2} + \frac{\partial^2 u}{\partial z^2}\right),
\end{equation}
where we wrote $\vec{u} = (u, v, w)$. We solve this equation using Fourier transforms. We define them as
\begin{eqnarray}
\hat{u}(k_y, k_z, t) &=&  \iint_{\mathbb{R}^2}u(y, z, t)e^{-i\vec{k}\cdot\vec{x}}dydz \\
u(y, z, t) &=& \frac{1}{4\pi^2}\iint_{\mathbb{R}^2} \hat{u}(k_y, k_z, t)e^{i\vec{k}\cdot\vec{x}}dk_ydk_z,
\end{eqnarray}
where $\vec{k} = k_y\uvec{y} + k_z\uvec{z}$ and $\vec{x} = y\uvec{y} + z\uvec{z}$. If we take the Fourier
transform of \eqref{c4s3e1} we get
\[
\pdt{\hat{u}}{t} = -\nu k^2 \hat{u}.
\]
Its solution is
\begin{equation}\label{c4s3e4}
\hat{u}(k_y, k_z, t) = \phi(k_y, k_z)e^{-\nu k^2 t}.
\end{equation}
From the above equation it is immediately clear that $\phi(\vec{k}) = \hat{u}(\vec{k}, 0)$, the initial value of
the Fourier transform of $u$, that is,
\[
\phi(\vec{k}) = \iint_{\mathbb{R}^2} u(y, z, 0)e^{-i\vec{k}\cdot\vec{x}}dydz.
\]
Substituting this in equation \eqref{c4s3e4} we get
\[
\hat{u}(\vec{k}, t) = \iint_{\mathbb{R}^2} u(y, z, 0)e^{-i\vec{k}\cdot\vec{x} - \nu k^2t}dydz.
\]
Therefore,
\[
u(\vec{x},t)=\frac{1}{4\pi^2}\iint_{\mathbb{R}^2} dk_ydk_z e^{i\vec{k}\cdot\vec{x}}\iint_{\mathbb{R}^2} dy^\op dz^\op u(y, z, 0) e^{-i\vec{k}\cdot\vec{x}^\op - k^2\nu t}
\]
Interchanging the order of integration,
\begin{equation}\label{c4s3e5}
u(\vec{x},t)=\frac{1}{4\pi^2}\iint_{\mathbb{R}^2} dy^\op dz^\op \iint_{\mathbb{R}^2} dk_ydk_z u(y, z, 0) e^{i\vec{k}\cdot(\vec{x}-\vec{x}^\op) - k^2\nu t}.
\end{equation}
Let us write the $\vec{k}-$integral as
\begin{equation}\label{c4s3e6}
K(\vec{x}, \vec{x}^\op) = \iint_{\mathbb{R}^2} dk_ydk_z u(y, z, 0) e^{i\vec{k}\cdot(\vec{x}-\vec{x}^\op) - k^2\nu t}.
\end{equation}
The integral readily factorizes as
\begin{equation}\label{c4s3e7}
K(\vec{x}, \vec{x}^\op) = u(y, z, 0) \int_{\mathbb{R}} dk_y e^{ik_y(y-y^\op)-k_y^2\nu t}\int_{\mathbb{R}} dk_z e^{ik_z(y-y^\op)-k_z^2\nu t}
\end{equation}
The two integrals are identical and we can as well focus only on one of them
\[
I(y, y^\op) = \int_{\mathbb{R}} dk_y e^{ik_y(y-y^\op)-k_y^2\nu t}
\]
After `completing the square' of the arguments of the exponential,
\[
I(y, y^\op) = \exp\left(-\frac{(y - y^\op)^2}{4\nu t}\right)\int_{\mathbb{R}}\exp\left(-\left(k_y\sqrt{\nu t} + i\frac{y^\op - y}{2\sqrt{\nu t}}\right)\right)dk_y
\]
or,
\[
I(y, y^\op) = \exp\left(-\frac{(y - y^\op)^2}{4\nu t}\right)\frac{1}{\sqrt{\nu t}}\int_{\mathbb{R}}\exp\left(-\left(k_y\sqrt{\nu t} + i\frac{y^\op - y}{2\sqrt{\nu t}}\right)\right)d(k_y\sqrt{\nu t}).
\]
The integral is of the form
\[
\int_{\mathbb{R}} e^{-(x + ia)^2}dx,
\]
where $a$ is a constant. It can be shown that
\begin{equation}\label{c4s3e8}
\int_{\mathbb{R}} e^{-(x + ia)^2}dx = \int_{\mathbb{R}}e^{-x^2}dx = \sqrt{\pi}
\end{equation}
so that
\begin{equation}\label{c4s3e9}
I(y, y^\op) = \exp\left(-\frac{(y - y^\op)^2}{4\nu t}\right)\sqrt{\frac{\pi}{\nu t}}
\end{equation}
and hence
\begin{equation}\label{c4s3e10}
K(\vec{x}, \vec{x}^\op) = \frac{\pi}{\nu t}u(y, z, 0) \exp\left(-\frac{(y - y^\op)^2 + (z - z^\op)^2}{4\nu t}\right).
\end{equation}
From equations \eqref{c4s3e5}, \eqref{c4s3e6} and \eqref{c4s3e10} we get
\begin{equation}\label{c4s3e11}
u(\vec{x}, t) = \frac{1}{4\pi\nu t}\iint_{\mathbb{R}^2}dy^\op dz^\op u(y^\op, z^\op, 0)\exp\left(-\frac{(y - y^\op)^2 + (z - z^\op)^2}{4\nu t}\right).
\end{equation}

\item Equation \eqref{c4s3e11} is a solution of the partial differential equation \eqref{c4s3e1} whose exact form
depends on the initial value $u(y, z, 0)$. We will now apply it to various cases of the initial values.

\item Supposing there are two streams of fluid moving with different velocities and suppose that there is
initially a sharp boundary between them. If we choose our reference frame as the one moving with a speed
equal to the mean of the two streams then with respect to it, one field moves with velocity, say, $U$ and
the other one with velocity $-U$. Further, let the initial boundary between the streams coincide with
the $xz$ plane so that
\begin{eqnarray*}
u(y^\op, z^\op, 0) &=& U \text{ if } y^\op > 0 \\
u(y^\op, z^\op, 0) &=& -U \text{ if } y^\op < 0.
\end{eqnarray*}
Putting these values in equation \eqref{c4s3e11} we get
\[
u(\vec{x},t) = \frac{1}{4\pi\nu t}\int_{\mathbb{R}}e^{-(z-z^\op)^2/(4\nu t)}dz^\op\left[\int_0^\infty U e^{-(y-y^\op)^2/(4\nu t)}dy^\op - \int_{-\infty}^0 U e^{-(y-y^\op)^2/(4\nu t)}dy^\op\right].
\]
The $z^\op$ integral can be readily evaluated so that
\[
u(\vec{x},t) = \frac{1}{\sqrt{4\pi\nu t}}\left[\int_0^\infty U e^{-(y-y^\op)^2/(4\nu t)}dy^\op - \int_{-\infty}^0 U e^{-(y-y^\op)^2/(4\nu t)}dy^\op\right].
\]
In the second integral, make the substitution $y^\op \mapsto -y^\op$ so that
\begin{equation}\label{c4s3e12}
u(\vec{x},t) = \frac{U}{\sqrt{4\pi\nu t}}\left[\int_0^\infty e^{-(y-y^\op)^2/(4\nu t)}dy^\op - \int_0^\infty e^{-(y+y^\op)^2/(4\nu t)}dy^\op\right].
\end{equation}
In the first integral, put $\xi = y - y^\op$ so that it becomes
\[
-\int_y^{-\infty}\exp\left(-\frac{\xi^2}{4\nu t}\right)d\xi = \int_{-y}^\infty\exp\left(-\frac{\xi^2}{4\nu t}\right)d\xi.
\]
Similarly, in the second integral put $\xi = y + y^\op$ so that it becomes
\[
\int_y^\infty\exp\left(-\frac{\xi^2}{4\nu t}\right)d\xi.
\]
Equation \eqref{c4s3e12} thus becomes,
\[
u(\vec{x}, t) = \frac{U}{\sqrt{4\pi\nu t}}\int_{-y}^y\exp\left(-\frac{\xi^2}{4\nu t}\right)d\xi = \frac{U}{\sqrt{\pi\nu t}}\int_0^y\exp\left(-\frac{\xi^2}{4\nu t}\right)d\xi.
\]
Finally, make the substitution $\chi = \xi/\sqrt{4\nu t}$ to
\[
u(\vec{x}, t) = \frac{2U}{\sqrt{\pi}}\int_0^{y/\sqrt{4\nu t}} e^{-\chi^2}d\chi.
\]
We now use the definition of the error function,
\begin{equation}\label{c4s3e13}
\text{erf}(x) = \frac{2}{\sqrt{\pi}}\int_0^x e^{-t^2}dt.
\end{equation}
Therefore,
\begin{equation}\label{c4s3e14}
u(\vec{x}, t) = U\text{erf}\left(\frac{y}{\sqrt{4\nu t}}\right).
\end{equation}
The velocity profile is shown in figure \ref{c4f1}
\begin{figure}
\centering
\includegraphics[scale=0.6]{c4f1}
\caption{Transition layer between two parallel streams}\label{c4f1}
\end{figure}
This figure was produced using the following code.
\begin{verbatim}
x <- seq(from = 0, to = 3, len = 100)
y <- pnorm(x) - pnorm(0)
X <- c(-rev(x), x)
# Recall that we are in the frame of reference such that upper
# fluid moves with velocity U and the lower one with velocity -U.
Y <- c(-rev(y), y)
plot(
  Y,
  X,
  type = 'l',
  main = 'Transition layer',
  xlab = 'u/U',
  ylab = expression(y / sqrt(4 * nu * t))
)
abline(h = 0, lty = 2)
abline(v = 0, lty = 2)
\end{verbatim}

The distance between the points where $u/U = \pm 0.99$ is computed using the following code.
\begin{verbatim}
d1 <- qnorm(0.99)
d2 <- qnorm(0.1)
delta_u_by_U <- d1 - d2
\end{verbatim}
It is $4.652696$ so that
\[
\delta y = \sqrt{\nu t} \times 2 \times 4.652696 = 9.3053.
\]
The coefficient will be $8$ if we use $u/U = \pm 0.9772499$.

\item We next show that the asymptotic behaviour of the solution will remain unchanged if instead of the
sharp discontinuity that we assumed previously we have
\begin{equation}\label{c4s3e15}
u(y) = \frac{y}{|y|}U + F(y),
\end{equation}
where the function $F$ goes to zero rapidly as $y \rightarrow \pm\infty$ and
\begin{equation}\label{c4s3e16}
\int_\mathbb{R} F(y)dy = 0.
\end{equation}
Note that the first term in equation \eqref{c4s3e15} is just $\pm U$. When the $u$ of \eqref{c4s3e15}
is used in equation \eqref{c4s3e11}, the first term will give the right hand side of equation
\eqref{c4s3e14} and the second term will give
\[
I = \frac{1}{4\pi\nu t}\iint_{\mathbb{R}^2}F(y^\op)\exp\left(-\frac{(y - y^\op)^2 + (z - z^\op)^2}{4\nu t}\right)dy^\op dz^\op.
\]
The $z^\op$ integral readily evaluates to $\sqrt{4\pi\nu t}$ so that
\begin{eqnarray*}
I &=& \frac{1}{\sqrt{4\pi\nu t}}\int_\mathbb{R}F(y^\op)\exp\left(-\frac{(y - y^\op)^2}{4\nu t}\right)dy^\op \\
&=& \frac{e^{-y^2/(4\nu t)}}{\sqrt{4\pi\nu t}}\int_\mathbb{R}F(y^\op)\exp\left[\frac{2yy^\op - {y^\op}^2}{4\nu t}\right]dy^\op
\end{eqnarray*}
Let us approximate the exponential as $e^x \approx 1 + x$ for small values of $x$ so that
\[
I = \frac{e^{-y^2/(4\nu t)}}{\sqrt{4\pi\nu t}}\left\{\int_\mathbb{R}F(y^\op)dy^\op + \frac{y}{2\nu t}\int_\mathbb{R}F(y^\op)y^\op dy^\op - \int_\mathbb{R}F(y^\op)\frac{{y^\op}^2}{4\nu t}dy^\op\right\}.
\]
From \eqref{c4s3e16} it is clear that $F$ is an odd function so that the first and the third integrals
are zero and
\[
I = \frac{1}{4}\frac{1}{\nu t}\frac{y}{\sqrt{\pi\nu t}}\exp\left(-\frac{y^2}{4\nu t}\right)\int_\mathbb{R}F(y^\op)y^\op dy^\op
\]
For a fixed $y/\sqrt{\nu t}$, $I = O(t^{-1})$.

\item Before proceeding we show that the condition on $F$ in equation \eqref{c4s3e15} can be
relaxed. If $F(y) = \exp(iay)$ for a real constant $a$ then
\[
I = \frac{1}{\sqrt{4\pi\nu t}}\int_{\mathbb{R}}e^{iay^\op}\exp\left(-\frac{(y - y^\op)^2}{4\nu t}\right)dy^\op.
\]
It can be simplified as
\[
I = \frac{e^{iay}}{\sqrt{4\pi\nu t}}\int_{\mathbb{R}}\exp\left(-ia(y - y^\op) - \frac{(y - y^\op)^2}{4\nu t}\right)dy^\op.
\]
Under the transformation $y^\op \mapsto y - y^\op$, the integral becomes
\begin{eqnarray*}
I &=& \frac{e^{iay}}{\sqrt{4\pi\nu t}}\int_{\mathbb{R}}\exp\left(-iay^\op - \frac{{y^\op}^2}{4\nu t}\right)dy^\op \\
 &=& \frac{e^{iay - a^2\nu t}}{\sqrt{4\pi\nu t}}\int_{\mathbb{R}}\exp\left(-\left(\frac{y^\op}{\sqrt{4\pi\nu t}} + ia\sqrt{\nu t}\right)^2\right) dy^\op.
\end{eqnarray*}
Under yet another transformation $y^\op/\sqrt{4\pi\nu t} \mapsto y^\op$, we have
\[
I = e^{iay - a^2\nu t}\int_{\mathbb{R}}e^{-({y^\op} + ia\nu t)^2}dy^\op = \sqrt{\pi}e^{iay - a^2\nu t}.
\]
As $t \rightarrow \infty$, $I \rightarrow 0$. Thus any function that can be written as a sum of normal modes $e^{iay}$
will decay to zero as time goes by.

This analysis demonstrates that an instability at the interface of fluids moving with differing velocities
should decay rapidly with time. It seems to contradict the standard analysis of Kelvin-Helmholtz instability.
However, one must remember that the standard analysis assumes that the fluids are ideal while we work
with real fluids.

\item In the case of a plane boundary moved suddenly in a fluid initially at rest, the boundary value
problem is $u_t = \nu u_{yy}$, subject to
\begin{eqnarray*}
u(y, 0) &=& 0, \text{ for } y > 0 \\
u(0, t) &=& U, \text{ for } t > 0.
\end{eqnarray*}
If we move the to the frame of reference of the moving plane, the initial and boundary conditions become
\begin{eqnarray*}
u(y, 0) &=& -U, \text{ for } y > 0 \\
u(0, t) &=& 0, \text{ for } t > 0.
\end{eqnarray*}
In this form the problem is identical to the upper half-space of the previous item. The solution is, following
\eqref{c4s3e14},
\begin{equation}
u(y, t) = -U\text{erf}\left(\frac{y}{4\nu t}\right)
\end{equation}\label{c4s3e17}
which in the laboratory frame of reference becomes
\begin{equation}\label{c4s3e18}
u(y, t) = U - U\text{erf}\left(\frac{y}{4\nu t}\right)
\end{equation}
We cannot use equation \eqref{c4s3e11} in this case because we do not know that $u$ is in the lower half-space.
We cannot put it zero because it is not the case that there is fluid at rest in the lower half-space.

\item We now consider the motion of a fluid between two parallel plates of which one is at rest and the other
moves with a uniform velocity $U$ in its own plane. The boundary value problem for this case is $u_t = \nu u_{yy}$
subject to
\begin{eqnarray*}
u(0, t) &=& U, t > 0 \\
u(d, t) &=& 0, t > 0 \\
u(y, 0) &=& 0, 0 \le y \le d.
\end{eqnarray*}
The boundary conditions for this problem are inhomogeneous so that we cannot use the separation of variables to
solve the problem. We introduce a new variable,
\begin{equation}\label{c4s3e19}
w(y, t) = U\left(1 - \frac{y}{d}\right) - u(y, t).
\end{equation}
It is easy to verify that $w_t = \nu w_{yy}$ and
\begin{eqnarray*}
w(0, t) &=& 0, t > 0 \\
w(d, t) &=& 0, t > 0 \\
w(y, 0) &=& U\left(1 - \frac{y}{d}\right).
\end{eqnarray*}
If $w(y, t) = Y(y)T(t)$ then
\[
\frac{1}{T}\td{T}{t} = \frac{\nu}{Y}\frac{d^2Y}{dy^2} = -k^2,
\]
where $-k^2$ is a constant of separation. We chose its sign keeping in mind that the solution cannot blow up
as time goes by. Thus,
\begin{equation}\label{c4s3e20}
T(t) = \alpha e^{-k^2 t}
\end{equation}
and
\begin{equation}\label{c4s3e21}
Y(y) = A\exp\left(\frac{ik}{\sqrt{\nu}}y\right) + B\exp\left(-\frac{ik}{\sqrt{\nu}}y\right).
\end{equation}
The solution $w$ is
\begin{equation}\label{c4s3e22}
w(y, t) = Ae^{-k^2 t}\exp\left(\frac{ik}{\sqrt{\nu}}y\right) + Be^{-k^2 t}\exp\left(-\frac{ik}{\sqrt{\nu}}y\right)
\end{equation}
where the constant $\alpha$ has been `absorbed' in $A$ and $B$. The condition $w(0, t) = 0$ gives $B = -A$ so that
\begin{equation}\label{c4s3e23}
w(y, t) = 2Aie^{-k^2 t}\sin\left(\frac{ky}{\sqrt{\nu}}\right).
\end{equation}
The condition $w(d, t) = 0$ restricts $k$ to
\begin{equation}\label{c4s3e24}
k = \frac{n\pi\sqrt{\nu}}{d}, n \in \mathbb{Z}.
\end{equation}
Thus,
\begin{equation}\label{c4s3e25}
w(y, t) = A_n\exp\left(-n^2\pi^2\frac{\nu t}{d^2}\right)\sin\left(\frac{n\pi y}{d}\right).
\end{equation}
The constant is now denoted as $A_n$ to indicate the possibility that it will depend on $n$, They are determined by
the initial condition. Thus, we have
\[
\sum_{n=1}^\infty A_n\sin\left(\frac{n\pi y}{d}\right) = U\left(1 - \frac{y}{d}\right)
\]
so that
\[
\sum_{n=1}^\infty A_n\int_0^d\sin\left(\frac{m\pi y}{d}\right)\sin\left(\frac{n\pi y}{d}\right)dy = U\int_0^d\left(1 - \frac{y}{d}\right)\sin\left(\frac{m\pi y}{d}\right)dy
\]
or
\[
\sum_{n=1}^\infty A_n \frac{d}{2}\delta_{mn} = \frac{Ud}{\pi m}
\]
or
\begin{equation}\label{c4s3e26}
A_m = \frac{2U}{\pi m}.
\end{equation}
The solution to the initial, boundary value problem is thus,
\begin{equation}\label{c4s3e27}
u(y, t) = U\left(1 - \frac{y}{d}\right) - \frac{2U}{\pi}\sum_{n=1}^\infty \frac{1}{n}\exp\left(-n^2\pi^2\frac{\nu t}{d^2}\right)\sin\left(\frac{n\pi y}{d}\right).
\end{equation}

\item We next consider the motion of a fluid due to an oscillating plate. Suppose that the upper half of the
$xy$-plane is filled with a fluid and is bounded by a plate lying in the $xy$-plane. If the plate oscillates
with a velocity $U\cos(nt)$ then we can assume that in the steady state the velocity of the fluid too will
have a harmonic component of frequency $n$. Thus, we can assume that
\[
u(y, t) = \Re(e^{int}F(y)),
\]
for a function $F$. Substituting this form in the differential equation of the fluid we get $\nu F^{\tp} =
inF$. If we write $in/\nu = \alpha^2$ then the solution to this equation is
\[
F(y) = A e^{-\alpha y} + Be^{\alpha y}.
\]
From the definition of $\alpha^2$ it follows that
\[
\alpha = (1 + i)\sqrt{\frac{n}{2\nu}}
\]
so that the requirement that $F$ stays finite as $y \rightarrow \infty$ needs $B = 0$. Note that the fluid
is confined to the upper half of the $xy$-plane so that the condition $y \rightarrow -\infty$ is irrelevant.
Thus,
\[
u(y, t) = A\exp\left(-\sqrt{\frac{n}{2\nu}}y\right)\cos\left(nt - \frac{n}{2\nu}y\right).
\]
Since $u(0, t) = U\cos(nt)$, we have $A = U$ and the solution of the problem is
\begin{equation}\label{c4s3e28}
u(y, t) = U\exp\left(-\sqrt{\frac{n}{2\nu}}y\right)\cos\left(nt - \frac{n}{2\nu}y\right).
\end{equation}

\item The differential equation for starting flow is
\begin{equation}\label{c4s3e29}
\pdt{u}{t} = \frac{G}{\rho} + \nu\left(\frac{\partial^2 u}{\partial r^2} + \frac{1}{r}\pdt{u}{r}\right),
\end{equation}
where $G$ the constant pressure gradient. The boundary and initial conditions on $u$ are
\begin{eqnarray}
u(a, t) &=& 0, \text{ for } t \ge 0 \label{c4s3e30} \\
u(r, 0) &=& 0, \text{ for } 0 \le r \le a.\label{c4s3e31}
\end{eqnarray}
In this problem the equation is inhomogeneous but the boundary condition is homogeneous. We can make the
equation homogeneous by writing $u$ as a sum of the steady state solution plus the transient solution. Let
\begin{equation}\label{c4s3e32}
u(r, t) = \frac{G}{4\nu}(a^2 - r^2) + w(r, t).
\end{equation}
It is easy to confirm that $w$ satisfies the equation
\begin{equation}\label{c4s3e33}
\pdt{w}{t} = \nu\left(\frac{\partial^2 w}{\partial r^2} + \frac{1}{r}\pdt{w}{r}\right),
\end{equation}
subject to
\begin{eqnarray}
w(a, t) &=& 0, \text{ for } t \ge 0 \label{c4s3e34} \\
w(r, 0) &=& \frac{G}{4\mu}(a^2 - r^2), \text{ for } 0 \le r \le a.\label{c4s3e35}
\end{eqnarray}
This is a homogenous partial differential equation with homogeneous boundary conditions. We can solve it
using the `separation of variables' method. If we write $w(r, t) = R(r)T(t)$ then
\[
\frac{1}{T}\td{T}{t} = \frac{\nu}{R}\left(\frac{d^2R}{dr^2} + \frac{1}{r}\td{R}{r}\right) = -k^2\nu,
\]
where $-k^2\nu$ is the constant of separation. Its sign is chosen to ensure that the solution does not
diverge as $t \rightarrow \infty$. We thus get two ordinary differential equations
\begin{eqnarray}
T^\op + k^2\nu T &=& 0 \label{c4s3e36} \\
r^2R^\tp + rR^\op + k^2r^2R &=& 0 \label{c4s3e37}
\end{eqnarray}
Introduce a new variable $x = kr$ in equation \eqref{c4s3e37} to get
\begin{equation}\label{c4s3e38}
x^2R^\tp + xR^\op + x^2R = 0.
\end{equation}
Bessel equation of order $n$ is $z^2w^\tp + zw^\op + (z^2 - n^2)w = 0$, where $w$ is a function of $z$.
Comparing it with equation \eqref{c4s3e38} suggests that it is Bessel equation of order $0$ and its
solution is
\begin{equation}\label{c4s3e39}
R(x) = \alpha J_0(x) + \beta Y_0(x),
\end{equation}
where $J_0$ is the Bessel function of first kind order $0$ and $Y_0$ is Bessel function of second kind
of order $0$. Since $Y_0 \rightarrow \infty$ as $x = kr \rightarrow 0$ we must have $\beta = 0$ and
\begin{equation}\label{c4s3e40}
R(x) = \alpha J_0(x).
\end{equation}
Using the boundary condition $R(r = a) = 0$ or $R(x = ka) = 0$ in the above equation gives
\[
\alpha J_0(ra) = 0.
\]
If we want a non-trivial solution then $ra$ should be a zero of the function $J_0$, say $\lambda_n$.
Thus,
\[
R(kr) = \alpha J_0\left(\lambda_n\frac{r}{a}\right).
\]
Since $ka = \lambda_n$, $k = \lambda_n/a$ so that the solution to \eqref{c4s3e36} is
\[
T(t) = \alpha^\op\exp\left(-\lambda_n^2\frac{\nu t}{a^2}\right)
\]
so that
\begin{equation}\label{c4s3e41}
w(r, t) = \frac{G}{4\mu}\sum_{n=1}^\infty A_n J_0\left(\lambda_n\frac{r}{a}\right)\exp\left(-\lambda_n^2\frac{\nu t}{a^2}\right),
\end{equation}
where we pulled out $G/(4\mu)$ outside the sum for convenience. Using the initial condition in
\eqref{c4s3e35} we get
\begin{equation}\label{c4s3e42}
a^2 - r^2 = \sum_{n=1}^\infty A_n J_0\left(\lambda_n\frac{r}{a}\right)
\end{equation}

\end{itemize}


% This is part of the TFTB Reference Manual.
% Copyright (C) 1996 CNRS (France) and Rice University (US).
% See the file refguide.tex for copying conditions.

\markright{tfrgrd}
\section*{\hspace*{-1.6cm} tfrgrd}

\vspace*{-.4cm}
\hspace*{-1.6cm}\rule[0in]{16.5cm}{.02cm}
\vspace*{.2cm}

{\bf \large \sf Purpose}\\
\hspace*{1.5cm}
\begin{minipage}[t]{13.5cm}
Generalized rectangular time-frequency distribution.
\end{minipage}
\vspace*{.5cm}

{\bf \large \sf Synopsis}\\
\hspace*{1.5cm}
\begin{minipage}[t]{13.5cm}
\begin{verbatim}
[tfr,t,f] = tfrgrd(x)
[tfr,t,f] = tfrgrd(x,t)
[tfr,t,f] = tfrgrd(x,t,N)
[tfr,t,f] = tfrgrd(x,t,N,g)
[tfr,t,f] = tfrgrd(x,t,N,g,h)
[tfr,t,f] = tfrgrd(x,t,N,g,h,rs)
[tfr,t,f] = tfrgrd(x,t,N,g,h,rs,alpha)
[tfr,t,f] = tfrgrd(x,t,N,g,h,rs,alpha,trace)
\end{verbatim}
\end{minipage}
\vspace*{.5cm}

{\bf \large \sf Description}\\
\hspace*{1.5cm}
\begin{minipage}[t]{13.5cm}
        {\ty tfrgrd} computes the Generalized Rectangular Distribution of a
        discrete-time signal {\ty x}, or the cross GRD representation
        between two signals. Its expression is :
\[GRD_x(t,\nu)=
\iint_{-\infty}^{+\infty} \dfrac{2 r_s}{|\tau|^{\alpha}}\
\mbox{sinc}\left(\frac{2\pi r_s v}{|\tau|^{\alpha}}\right)\
x(t+v+\frac{\tau}{2})\ x^*(t+v-\frac{\tau}{2})\ e^{-j2\pi \nu \tau}\ dv\
d\tau\] where $r_s$ is a scaling factor which determines the spread of the
low-pass filter, and $\alpha$ is the dissymetry ratio.\\

\hspace*{-.5cm}\begin{tabular*}{14cm}{p{1.5cm} p{8cm} c}
Name & Description & Default value\\
\hline
        {\ty x}      & signal if auto-GRD, or {\ty [x1,x2]} if cross-GRD {\ty
			(Nx=length(x))} \\
        {\ty t}      & time instant(s)         & {\ty (1:Nx})\\
        {\ty N}      & number of frequency bins & {\ty Nx}\\
        {\ty g}      & time smoothing window, {\ty G(0)} being forced to
		{\ty 1}, where {\ty G(f)} is the Fourier transform of {\ty g(t)}.
                                         & {\ty window(odd(N/10))}\\
        {\ty h}      & frequency smoothing window, {\ty h(0)} being forced to {\ty 1}.
                                         & {\ty window(odd(N/4))}\\
        {\ty rs}     & kernel width            & {\ty 1}\\
        {\ty alpha} & dissymmetry ratio       & {\ty 1}\\
        {\ty trace}  & if nonzero, the progression of the algorithm is shown
                                         & {\ty 0}\\

\hline\end{tabular*}\end{minipage} \newpage
\hspace*{1.5cm}\begin{minipage}[t]{13.5cm}
\hspace*{-.5cm}\begin{tabular*}{14cm}{p{1.5cm} p{8.5cm} c}
Name & Description & Default value\\\hline

        {\ty tfr}    & time-frequency representation\\
        {\ty f}      & vector of normalized frequencies\\

\hline
\end{tabular*}
\vspace*{.2cm}

When called without output arguments, {\ty tfrgrd} runs {\ty tfrqview}.
\end{minipage}
\vspace*{1cm}

{\bf \large \sf Example}
\begin{verbatim}
         sig=fmlin(128,0.05,0.3)+fmlin(128,0.15,0.4);
         g=window(9,'Kaiser'); h=window(27,'Kaiser');
         t=1:128; tfrgrd(sig,t,128,g,h,36,1/5,1);
\end{verbatim}
\vspace*{.5cm}

{\bf \large \sf See Also}\\
\hspace*{1.5cm}
\begin{minipage}[t]{13.5cm}
all the {\ty tfr*} functions.
\end{minipage}
\vspace*{.5cm}

{\bf \large \sf Reference}\\
\hspace*{1.5cm}
\begin{minipage}[t]{13.5cm}
[1] F. Auger ``Some Simple Parameter Determination Rules for the
Generalized Choi-Williams and Butterworth Distributions'' IEEE Signal
processing letters, Vol 1, No 1, pp. 9-11, Jan. 1994.

\end{minipage}