\documentclass[revision-guide.tex]{subfiles}
%% Current Author: PS
\setcounter{chapter}{13}
\begin{document}
\chapter{Electromagnetism}

\section*{Candidates should be able to:}
\spec{understand and use the terms magnetic flux density, flux and flux linkage}

Electromagnetic induction depends crucially on the concept of \emph{flux}. This is the product of the magnetic field strength $B$ and the area of a loop perpendicular to the field, $A$.
\[ \Phi = BA \]
The unit of flux is the weber, Wb. Given its relation to flux, the field strength $B$ can also be referred to as the magnetic flux density. It also follows that the tesla is equivalent to one weber per metre-squared.

When a coil of wire encloses an area of flux we can calculate the \emph{flux-linkage} which is the product of the flux through the coil and the number of turns on the coil, $N\Phi$.

Magnetic flux density can be defined as the force per unit of current in a wire of unit length in a magnetic field.

\spec{understand that magnetic fields are created by electric current}

An electric current in a wire creates a magnetic field. The field strength depends on the size of the current and the distance from the wire. In the case of a solenoid or electromagnet the field strength is also proportional to the number of turns on the coil.

\spec{recognise and use  $F = BIl\sin\theta$}

This is the equation for the force on a current-carrying wire of length $l$ with a current of $I$ at an angle $\theta$ to a magnetic field of strength $B$.

\spec{recognise and use $F = BQv\sin\theta$}

This is the equation for a particle of charge $Q$ moving at a velocity $v$ at an angle $\theta$ to a magnetic field of strength $B$. Note that this is sometimes called the Lorentz force.

\spec{use Fleming's left-hand rule to solve problems}

Fleming's left-hand rule allows the calculation of the direction of the force on either a charged particle or a current-carrying wire. The geometry is shown below.

\begin{figure}[ht]
  \begin{center}
  \begin{tikzpicture}
      \draw [->, gray,very thick] (0,0) -- (4,0) node[anchor=west,text width=5cm, ] {second finger:\\current, $I$};
      \draw [->, red,very thick] (0,0) -- (0,3) node[anchor=south,text width=2cm, ] {thumb:\\force};
      \draw [->, black,very thick] (0,0) -- (2,2) node[text width=5cm, anchor=west] {first finger:\\field, $B$};
    \end{tikzpicture}
  \end{center}
  \caption{Fleming's left-hand rule}
  \label{flemminglh}
\end{figure}

It is important to note that if you are using the left-hand rule to predict the direction of force on a moving negatively charged particle then the \emph{current} is flowing in the opposite direction to the velocity of the particle.

\emph{Note that vector form of the equations explains the left-hand rule and sine terms as follows:}
$$\mathbf{F} = q\mathbf{v}\times\mathbf{B}$$
$$\mathbf{F} = \mathbf{I}L\times\mathbf{B}$$
\newpage
\spec{explain qualitatively the factors affecting the emf induced across a coil when there is relative motion between the coil and a permanent magnet or when there is a change of current in a primary coil linked with it}

\begin{framed}
\textbf{Faraday's Law}: The induced emf is proportional to the rate of change of flux linked.
\end{framed}

Since the emf depends on the rate of change of flux linkage the size of the emf is proportional to the number of turns on a coil. The rate of change of flux is determined by strength of the magnet and how quickly it is moving through the coil.

\spec{recognise and use $E=-\frac{d(N\Phi)}{dt}$ and explain how it is an expression of Faraday’s and Lenz’s laws}

Since $N\Phi$ is the flux linkage then $\frac{d(N\Phi)}{dt}$ is the rate of change of flux linkage. Thus Faraday's law is expressed in this equation.

\begin{framed}
\textbf{Lenz's Law}: The direction of the induced emf is such that the current it causes to flow opposes the change which is producing it.
\end{framed}

 The negative sign indicates that the induced emf acts to oppose the change in flux linkage which created it. This may occur by the magnetic field opposing the motion of a magnet of coil or by the magnetic field opposing a stationary change in field.

 Note that Lenz's law is a result of conservation of energy and applying it to a specific situation often requires a discussion of work and energy transfers.

\spec{derive, recall and use $r = \frac{mv}{BQ}$ for the radius of curvature of a deflected charged particle}

When a charged particle moves through a uniform magnetic field at a constant speed it experiences a constant force at right-angles to its velocity. This results in it moving in circular motion with the Lorentz force providing the centripetal force.
\[ BQv = \frac{mv^2}{r} \]
\[\implies r = \frac{mv}{BQ} \]

This allows the calculation of the mass to charge ratio of the particle providing its velocity can be determined (e.g. from an accelerating potential).

\newpage
\spec{explain the Hall effect, and derive and use $V = Bvd$}

When an electron moves through a magnetic field it will experience a force at right-angles to its motion. If a current flows through a thin film of material then a negative charge will accumulate on one edge of the film. Figure \ref{halleffect} shows this force acting and charge building up.

\begin{figure}[h]
  \begin{center}
  \begin{tikzpicture}
    \filldraw [fill=yellow!20!white,draw=black] (0,0) rectangle (10,10);
    \draw (10,0)  node[anchor=north east] {Magnetic field into page};
    \filldraw[fill=green] (4,6) circle (0.1) node[anchor=south] {e$^-$};
    \draw[->] (4.2,6) -- (5.5,6) node[midway,above]{$v$};
    \draw[->, thick, red] (4,5.8) -- (4,4) node[anchor=north] {$F$};
    \foreach \x in {1,2,...,9}
        {\draw (\x,.25) node{--};\draw[color=red] (\x,9.75) node{+};}
    \draw[<->] (10.5,0) -- (10.5,10) node[midway, right] {$d$};
  \end{tikzpicture}
  \end{center}
  \caption{The Hall Effect}
  \label{halleffect}
\end{figure}

Over time the charges build up on either side of the wager until equilibrium is reached. At this point the the force due to the electric field on the charge equals the force due to the Lorentz force on the charge.
$$ q\frac{V}{d} = Bqv $$
$$ V_\text{hall} = Bvd $$

This relationship is the basis of a Hall Probe which is used to measure magnetic fields. In these circumstances the velocity $v$ is the drift velocity of the electrons.

\end{document}

%sagemathcloud={"latex_command":"latexmk -xelatex -f -g -bibtex -synctex=1 -interaction=nonstopmode '14-electromagnetism.tex'"}


\chapter{SOFTWARE IMPLEMENTATION}
\section{Introduction}
A software implementation method is a systematically structured approach to effectively integrate software based service or component into the workflow of an organizational structure or an individual end-user. A product software implementation method is a blueprint to get users and/or organizations running with a specific software product. The method is a set of rules and views to cope with the most common issues that occur when implementing a software product: business alignment from the organizational view and acceptance from the human view. The implementation of product software, as the final link in the deployment chain of software production, is in a financial perspective of a major issue. It is stated that the implementation of (product) software consumes up to 1/3 of the budget of a software purchase (more than hardware and software requirements together).We intend to build an application of neural network for text line recognition using Java language and Netbeans 6.0 as our tool. Our application will take image containing text as input and provide OCR generated output by pattern matching technique.The following are our project modules and we implemented the system step by step as per the modules.
\section{ Modules}
\begin{enumerate}
\item Text region detection
\item Text line normalization
\item Features extraction
\item Neural network training
\item Text line scanning
\item Hidden Markov Models decoding
\end{enumerate}
\section{The Algorithm strategy of project}
\begin{enumerate}
\item  Input the image file containing text.
\item  Normalize the text line by line.
\item  Extract the features from the text line.
\item  Train the neural network using AutoMLP training for extracted features.
\item The complete text line using the window from left to right and generate time series signals for character positions.
\item  Decode the time series signal by HMM decoder.
\item The output of HMM decoder is the machine printed document.
 \end{enumerate}


\chapter{Introduction}
\label{chap:introduction}

% Establish a precedence
Personal computers have been developed to a point where those unfamiliar with computer science theory might conclude there is nothing computers cannot do.
While this is an understandable conclusion, it has been proven that there is a limit to the types of computation our ``classical computers", what we today consider general purpose computers, can perform \cite{linz}.
In the last few decades however, the field of quantum mechanics and quantum computing have advanced to the point where primitive operations are now possible in the quantum sphere.
Just this year Google claimed to achieve ``quantum supremacy" in an experiment in which they performed a computation, using a quantum computer, in under five minutes.
Google estimated that the same computation would take a state-of-the-art super computer 10,000 years to complete \cite{quantum_supremacy}.
While quantum computers are not general purpose, they can solve NP-Hard and exponentially complex problems in polynomial time or better \cite{MikeAndIke}.
This breakthrough in computability will change the way information is stored, secured, and created.

% State the problem
Currently, encryption protocols ensure the integrity of data and identities.
One such protocol is the the widely adopted Diffe-Hellman protocol, which is an asymmetric encryption protocol that relies on the historic difficulty of factoring large prime numbers for security \cite{qc:agi}.
The protocol works by using a public and private key pair for each participating party.
Data encrypted using one of the keys (usually a public key) can then only be decrypted using the private key.
A person's public and private keys are mathematically related, but it requires factoring large prime numbers to derive the private key from the public key, which is computationally infeasible with a classical computer.
Quantum computers however, are able to do this in only polynomial time complexity \cite{doi:10.1137/S0036144598347011}.
This development, combined with the growing power of quantum computers, gives rise to security concerns to the Diffe-Hellman protocol in the future.

% Mention the solution
The BB84 is a quantum key distribution protocol which uses properties of quantum bits to address the growing security concerns of current key exchange protocols (KEP).
The BB84 protocol allows two parties to co-generate a disposable, randomly generated, encryption key which can be used to encrypt and decrypt data, and then be discarded after use.
This type of a use and throw encryption key is known as a one-time-pad, and it gets its security from being disposable.
Common patterns for breaking encryption keys cannot be used due to the disposable nature of the one-time-pad.
This technique is only susceptible to a brute force attack, which is always possible in principal but often infeasible \cite{cryptography}.
The BB84 protocol allows for detection of an eavesdropper during the key generation process, allowing them to abort key generation before any encrypted messages are transmitted \cite{qcftgu}.

% Describe the thesis' contribution to the problem
This thesis presents a peer to peer simulation of the BB84 quantum KEP, and serves as an introduction to programming in the quantum computing paradigm using simulaqron and cqc, a quantum network simulator and messaging interface \cite{simulaqron}.
We show that the BB84s security guarantees hold true in the simulated environment.
The simulation allows two parties to co-generate an encryption key and begin exchanging encrypted information using that key.
Both parties can simultaneously detect if a third party tried to eavesdrop on the key generation, allowing the users to abort the communication.

% Describe the thesis content
The rest of the thesis is organized as follows.
Chapter~\ref{chap:background} provides background information on encryption protocols, the quantum computation paradigm, and other background information related to the BB84 protocol.
Chapter~\ref{chap:bb84} details the BB84 protocol algorithm, as well as discusses its theoretical guarantees.
Chapter~\ref{chap:implementation} describes the simulaqron and cqc libraries, as well as the BB84 simulator.
This chapter also serves as introductory material for someone getting into quantum simulation or programming in the quantum paradigm.
Chapter~\ref{chap:conclusion} summarizes this simulator and its potential applications, as well as discusses possible future work.


%
% CMPT 379: Principles of Compiler Design - A Course Overview
% Section: Semantic Analysis and Static Single Assignment
%
% Author: Jeffrey Leung
%

\section{Semantic Analysis and Static Single Assignment}
	\label{sec:semantic-analysis-ssa}
\begin{easylist}

& \textbf{Semantic analysis:} Validating a program's basic requirements and type compatibilities, processing static semantic checks, and adding run-time semantic checks
	&& E.g. Checking that a \textit{main} function exists, that variables are declared, whether operand types are compatible

& \textbf{Static Single Assignment (SSA):} Property of an intermediate representation where each variable is only assigned once
	&& Used to distinguish and merge values from multiple possible paths of computation to create a single resulting value

& \textbf{Dominance:} Characteristic of a node which is a mandatory predecessor of another node (i.e. any path from the root to the lower node must pass through the upper node)
	&& Any node dominates itself
	&& Definitions of a variable dominate its later usages
	&& \textbf{Strict dominance:} Characteristic of a node which dominates a different node

& \textbf{Dominance Frontier (DF):} Set of nodes which, given a target node, are the convergence of two nodes - one which is dominated by the target node and one which is not (i.e. all nodes such that the target node dominates a predecessor but not the node itself)
	&& Notation: $DF(X)$
	&& Can include the node itself
	&& E.g. See figure~\ref{fig:dominance-frontier-example} which calculates the dominance frontier of node 5

\begin{figure}[!htb]
	\caption{Dominance Frontier Example}
	\label{fig:dominance-frontier-example}
	\begin{center}
		\includegraphics[width=\textwidth]{dominance-frontier}
	\end{center}
\end{figure}

	&& Every node in $DF(X)$ requires a $\phi$ (phi) function for each variable defined in $X$

& \textbf{Dominator tree:} Acyclical hierarchical structure of a set of nodes, where a node dominates all of its children

\end{easylist}
\clearpage


\documentclass{sig-alternate}

\input{defines}

\title{Can Quantum Search Accelerate Evolutionary Algorithms?}

\author{Daniel Johannsen\\
Max Planck Institute for Informatics\\
Department of Algorithms and Complexity\\
  Saarbr{\"u}cken, Germany\\
  \email{daniel.johannsen@mpi-inf.mpg.de}\\
\and Piyush P Kurur\thanks{Work done on a visit to the Max Planck Institute for Informatics (MPII) funded by MPII and Research I project (NRNM/CS/20030163)}
\\
Dept of Comp. Sci. and Engg\\
Indian Institute of Technology Kanpur\\
Kanpur UP, India 208016\\
\email{ppk@cse.iitk.ac.in}
 \and Johannes Lengler\\
  Department of Mathematics\\
  Saarland University\\
  Saarbr{\"u}cken, Germany\\
  \email{johannes.lengler@math.uni-sb.de}}

\begin{document}
\maketitle%
\begin{abstract}
\input{abstract}
\end{abstract}
\category{F.2}{Theory of Computation}{Analysis of Algorithms and Problem Complexity}
\terms{Theory, Algorithms}
\keywords{Running time analysis, Quantum Algorithm, Theory}
\begin{table*}
\begin{center}
\begin{tabular}{l|c|c|c}
& \rls\,/\,\rls{}$^*$\,/\,\ooea\,/\,\ooea{}$^*$ & \qrls\,/\,\qooea & \qrls{}$^*$\,/\,\qooea{}$^*$ \\
\hline
\onemax & $\Theta(n\log n)$ & $\Theta(n)$ & $\Theta(n)$ \\
\leadingones & $\Theta(n^2)$ & $\Theta(n^{\nicefrac{3}{2}})$ & $\Theta(n^2)$ \\
\discrepancy & $\Theta(\sqrt{n})$  & $\Theta(\sqrt{n})$ & $\Theta(\sqrt{n})$ \\
\end{tabular}
\caption{\label{tabA}A comparison of the expected optimization times (query complexities) between \rsh{}s and \qrsh{}s on the pseudo-Boolean objective functions \onemax, \leadingones, and \discrepancy.}
\end{center}
\end{table*}

%
%%% - Introduction -
%
\section{Introduction}
\label{sec:introduction}%
\input{introduction}
\splitpages

%
%%% - Quantum Algorithms
%
\section{Probability Amplification}
\label{sec:quantum}%
\input{quantum}
\splitpages

%
%%% - Randiomized Search Heuristics}
%
\section{The Quantum Search Heuristic}%
\label{sec:rsh}%
\input{rsh}
\splitpages

%
%%% - Results
%
\section{OneMax}
\label{sec:onemax}%
\input{onemax}

\section{ Leadingones}
\label{sec:leadingones}%
\input{leadingones}

\ignore{
\begin{table*}[btp]
\begin{center}
\begin{tabular}{l|cc}
& \rls{}$^*$/\ooea{}$^*$ & \qrls{}$^*$/\qooea{}$^*$ \\
\hline
\onemax & $\Theta(n\log n)$ & $\Theta(n)$ \\
\leadingones & $\Theta(n^2)$ & $\Theta(n^2)$ \\
\discrepancy & $\Theta(\sqrt{n})$ & $\Theta(\sqrt{n})$ \\
\end{tabular}
\caption{\label{tabB}A comparison of the expected optimization times  (query complexities) between \rls{}$^*$\,/\,\ooea{}$^*$ and \qrls{}$^*$\,/\,\qooea{}$^*$ on
  the pseudo-Boolean objective functions \onemax, \leadingones, and
  \discrepancy.}
\end{center}
\end{table*}
}
\section{Discrepancy}
\label{sec:discrepancy}%
\input{discrepancy}

\newpage

\section{Conclusion}
\label{sec:conclusion}%
\input{conclusion}
\splitpages

{
%\footnotesize
\bibliographystyle{abbrv}
\bibliography{paper}
}

\end{document}


\documentclass [a4paper,11pt]{article}
\title{Packing static tables for compactness and rapid access}
\author{Arthur C Norman}
\begin{document}
\maketitle
\section{Synopsis}
\section{Introduction}
This is a message to record some of the fun I have been having recently,
in case anybody else ends up interested.

I want to be able to display mathematical formulae nicely. To that end I
need access to character metrics. In my most recent investigation I am
expecting you use seven fonts
   Computer Modern Unicode Typewriter Text  (fixed pitch)
   "Odokai" [AR PL New Kai]                 (a range of CJK characters)
   STIX in Regular, Bold, Italic and BoldItalic (a serif face)
   STIX-Math                                (mathematical symbol support)
Between these I am faced with just over 33000 characters. I want tables
that give character sizes, kern and ligature information and various extra
stuff relating to the typesetting of mathematics. I would like the tables
to be compact but fast to access. I am prepared to take the view that I
will only use these particular fonts - so a user is not entitles to bring
in another without needing to do substantial revision and rebuilding of
everything.

By far the biggest table is one one giving character sizes and providing
indirections into ligature and kern tables. To support fast access I make
this a hash table. If I hashed each character individually then I would
have 33000 entries in my table each using space to hold the hash key. For
the data concerned most characters are arrange in blocks, so I use one
hash table entry for every run of four characters. This wastes some space
where the fonts have isolated characters in them, but saves repetition of
hash keys. I end up with just over 10000 lines active in the hash table,
so on average each line has three of the four positions in it ii use. It
happens that using this arrangement also gives me a neat number of bits to
be used for each hash table entry - 40 bytes which I store as five 64-bit
words.

\section{Approach}
When establishing a hash table there are typically messy compromises to
make. One would like a hash function that is cheap and simple to compute
to save time there, but something too simple may compromise the efficiency
of the table. One would like as small a table as possible to save space,
but that will tend to lead to the need for a large number of probes to
retrieve information. I use a variant of cuckoo hashing, and the main
point of this note is to record what I view as the amazing way in which
this lets me meet all my objectives simultaneously.

I introduce three separate hash functions and for any character I insist
that it end up at one of the locations that these propose for it. Of
course in unlucky cases two or even all of the functions will yield the
same value and then the character concerned does not have as much
flexibility about where it goes. Accepting that as a fact of life, I go
further. Characters in the typewriter and the mathematical font whose
codes are in the range U+0000 to U+007f (ie the basic latin alphabet in
the two fonts I expect to be most heavily used) are treated so that only a
single hash value is used. Then in the typewriter font I make it such that
all characters at codepoints up to U+0600 (this covers a serious range of
European alphabets) and the main range from the Maths font that cover
European letters and mathematical sumbols only have two distinct hash
values. Characters expected to arise less commonly - bold, italic, CJK and
a whole raft of Unicode oddities - are allowed the full three
possibilities.

The one, two or three locations in the hash table that each character is
allowed to reside can be thought of as a bipartite graph, and standard
algorithms (eg Hopcroft-Karp) can seek a maximum matching. If the one that
is found manages to allocate a location for every single character one has
a hash table where the most important latin characters can be found in one
probe, essentially all symbols used in mathematics in two (and hance in an
average of around 1.5), while every character can be looked up in at worst
three probes (and so in an average of around 2). An unsuccessful search
for a character not present in any of the fonts only needs three probes. I
feel that this allows one to believe that performance is good.

The remaining challenge is to ensure that the hash functions used are
cheap to compute and the table is acceptably compact. I will start with
the first of these, assuming that the hash table is of size N. The three
hash functions I use are
    h1(k) = k mod N
    h2(k) = k mod N2 + O2  [for some constants N2 and O2]
    h3(k) = (h1(k) + h2(k)) mod N
and if I arrange that N2+O2<=N I can be confident that h2(k) yields a
value that will lie within table bounds. Especially given that faily often
only the first one or two of these will need to be computed, and in the
light of the fact that modern machines compute remainders reasonably fast
these seem good and simple to implement and not unduly expensive. Observe
that there is a lot of flexibility in the choice of the constants N2 and
O2 as well as in choosing the table size N.

Because the font data is static and not expected to change at all often I
can afford a potentially expensive search to pick N, N2 and O2 so as to
find a small table. Existing known results about cuckoo hashing indicate
that for variants like this with three probes one should expect that with
good has functions it will usually be possible to have a table occupancy
of around 91%. Here one can worry that the blocky allocation of codes in
the fonts and the really naive hash functions might make things worst than
that.

In its most direct form I start with a small table size N and try running
the maximum matching process for all plausible values of N2 and O2,
gradually increasing N until I am first able to create a complete table.
When doing this I judge that a tiny value of the secondary modulus N2 is
not at all liable to be useful since it would not lead to data being
spread out, so I scan for N2 from 2N/3 up to N-1. I then try all legal
values of the offset O2 that will avoid h2(k) ever ending up too large.
This is quite a painfully large search space. To speed it up my code has
two tricks, both of which introduce risks. The first is that I create 8
sub-processes and each investigate part of the search space in parallel. I
avoid heavy duty synchronisation and an effect is that hypothetically one
part of the search could run ahead and find a packing in a slightly larger
size hash table before another had complete analysis of a smaller table
size. Even though that might happen it would probably at worst lead to
issue of a hash table just one larger than perfection. My other speed-up
is to use binary search between a tiny table size that is clearly
impossible to use and a large one where it is easy to fit everything in.
This obviously speeds things up very usefully, but the binary search
process really relies on having a monotonic function to investigate if it
is to guarantee to find the smallest feasible table. Again I have not
found this to be a big problem in practise. My code is such that a
complile time option can be used to disable use of parallel search, and an
alternative entrypoint into the code performs the original naive search
and so can be used to check solutions found using the optimisations.

\section{Initial results}

With this strategy - and let me remind you that it allows the most
important characters to be looked up in one probe and almost all the
relevant rest in only 2 - I find that to store the 10019 keys for my
characters I end up with a table size of 10057. This is a 99.62%
occupancy! My metrics table still ends up consuming around 400 Kbytes, but
I am amazed by how little waste there is.

I have other hash tables to record information about variant and extended
characters and to help position accents. So for instance a left
parenthesis need to be associated with four of five characters
representing gradually larger versions of itself, and then with individual
characters that can be places adjacent to build up truly huge versions.
A typical result here is that I have 141 characters for which "extended
forms" are available, and the hash table set up much as described above
ends up being of size 143. Again cuckoo hashing with an exhaustive search
through a range of trivial hash functions has allowed an almost perfect
hashing scheme to be created.

On a reasonably fast desktop machine running a complete sequential search
for a good hash table for the 10000 entries I am working with takes of the
order of a day. The binary search reduces this to a bit under an hour and
for greater convenience I then seed in and merely verify the best solution
- and the code that creates the tables then runs in seconds.

A further refinement could be to use not just a simple maximum matching
algorithm, but one based on weighted graphs so that matchings that
correspond to placing kets in their first choics position was
systematically preferred. At present my expectation is that at the high
table occupancies I am working with the fact that everything fits is
essentially a fluke based on the exact particular hash parameters in use,
and that this would not improve things much, but if one backed off to
lower hash occupancy regimes it might be useful.

My code for all this is in a file "charmetrics.c" and when compiled with a
"CREATE" flag it can be run to create "charmetrics.h" which contains the
tables for use with C or C++ and also "charmetrics.red" so that metrics
could be used directly from Reduce. All these in the csl/cslbase directory
of the Reduce source tree at sourceforge.

\section{Refinements}

Parallel search using work-farm model

Tokzylowski observes\cite{tokzlyowski} that if you decompose a bipartite
graph into its strong components then each component can be analysed
independently. The special value of this is that when you are seeking a
perfect matching then if one is not available for some strong component then
it can not be for the whole graph. Decomposing a graph into strong components
can be done in linear time and for sparse graphs ... ... ...

Use linear strong component decomposition before Hopcroft Karp

Strong component with more in A then B must fail

Strong component with only 1 or 2 in B must succeed

If at any stage more items remain in A than in B then failure is certain.

Keep largest component until end in case an earlier one proves impossibility.

Adapt Hungarian code to use spare data representation

\section{Final results}
\section{Conclusions}

\section{References}
\bibliographystyle{plain}
\bibliography{cuckoo}

\end{document}


\documentclass[a4paper]{scrartcl}
\usepackage{amssymb, amsmath} % needed for math
\usepackage[utf8]{inputenc} % this is needed for umlauts
\usepackage[ngerman]{babel} % this is needed for umlauts
\usepackage[T1]{fontenc}    % this is needed for correct output of umlauts in pdf
\usepackage[margin=2.5cm]{geometry} %layout
\usepackage{hyperref}   % links im text
\usepackage{parskip}

\title{Minimal distance to a cubic function}
\author{Martin Thoma}

\hypersetup{
  pdfauthor   = {Martin Thoma},
  pdfkeywords = {},
  pdftitle    = {}
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Begin document                                                    %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
\maketitle
\begin{abstract}
In this paper I want to discuss how to find the minimal distance of a
point $P = (x_p, y_p)$ to a cubic function $f: \mathbb{R} \rightarrow \mathbb{R}$,
$f(x) = a \cdot x^3 + b \cdot x^2 + c \cdot x + d$.

So I search for $x \in \mathbb{R}$ such that \dots
\end{abstract}

\section{Minimal distance constant function}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla
quam elit, vestibulum nec facilisis at, condimentum id enim. Sed
iaculis lacinia quam, vel accumsan eros tempor in. Integer ipsum
metus, accumsan sit amet commodo a, egestas vitae sem. Mauris ut
orci ut dolor viverra convallis nec a erat. Aenean consequat elit
vel eros fermentum vestibulum id at ipsum. In vitae orci mauris, et
rhoncus odio. Pellentesque habitant morbi tristique senectus et netus
et malesuada fames ac turpis egestas.
\end{document}


\documentstyle[12pt]{article}
\setlength{\textheight}{23cm}
\setlength{\textwidth}{16cm}
\setlength{\oddsidemargin}{0.25in}
\setlength{\topmargin}{-0.5in}
%\setlength{\parskip}{.5in}
\title{Errors Bars for Transfer Function Elements in Z--files}
\author{Gary D. Egbert\thanks{College of Oceanic and Atmospheric Sciences, Oregon State University, Corvallis; egbert@oce.orst.edu}}

\begin{document}

\maketitle

\section{File Format}

The Z--files contain all information needed to compute standard
transfer functions (e.g., impedances), with error bars in any coordinate
system.  Here is an overview of the format, followed by an
artificial example, with some annotation off to the side.
The basic idea is that there are {\it NCH} channels, with the first
two used as the ``local reference''i.e., these are the input
or predictor channels (classically the local horizontal  magnetics), and
the remaining {\it NCH-2} are the output or predicted channels (the electrics,
and/or vertical magnetics).  Note that there might also have been
another pair of channels (or a whole array) used as a remote reference.
These possible other channels are not referred to explicitly in this
file (but they were used to compute the contents of the file).  A
file of this same format can in principle be produced from single
station, standard remote reference, or the multiple station program.
This effects how the contents of this file was created, but not
any subsequent calculations using this file.

In overview, the file is ASCII, with a short header block
which identifies the {\it NCH} channels.
There are then a series of {\it NBANDS} blocks,
one for each period for which an estimate has been computed.
Each period block contains three complex arrays:

1) {\bf Z} : the transfer function (TF) array.  This array is {\it NCH-2} rows
by 2 columns.  For {\it NCH = 4},
with two reference channels $H_x$ and $H_y$,
and two predicted channels $E_x$ and $E_y$, {\bf Z} is just the impedance
tensor.

2) {\bf S} : the ``inverse signal covariance'' array.  This is a $2 \times 2$
Hermitian matrix.  Only the 3 elements corresponding to the part
on and below the diagonal are actually in the file.  These elements
are given in the order $S_{11}$, $S_{21}$, $S_{22}$.  The missing element
satisfies $S_{12}$ = ${S_{21}}^*$, where the superscript asterisk denotes
the complex conjugate.  Note that in the case of a single station
impedance estimate {\bf S} is just the inverse of the ${\bf H}$ cross power
matrix.  The exact form is slightly different for the case of remote reference
or array results.  This matrix is needed for the error calculation.
(Actually only the diagonal elements, which are real,
are needed unless you rotate the coordinate systems).

3) {\bf N} the residual covariance matrix.
This is an $(NCH-2) \times (NCH-2)$ Hermitian matrix,
output in the same symmetric form as {\bf S}.  This
gives the covariance of the residuals
for all predicted channels.  Again,
only the diagonals (also real) of this matrix are needed for
error calculations in the ``default'' coordinate system, but
other parts of the matrix will be used for a correct treatment of
coordinate changes/rotations.

(Mike: Actually there might be a slight difference
in the header block format in the version you have; this is
for the most recent version, and I'm not sure exactly what Clark is
using).

\small
\begin{verbatim}
 TRANSFER FUNCTIONS IN MEASUREMENT COORDINATES    <====  line 1 of file
 ********** WITH FULL ERROR COVARAINCE*********

S2                                             <===== some sort of "station" id
coordinate    49.28   102.91 declination    0.00    <=== station coordinates
number of channels   5   number of frequencies  26  <===  NCH, NBANDS
 orientations and tilts of each channel
    5     0.00     0.00 S2H  Hx     <===  for each channel in this "station":
    6    90.00     0.00 S2H  Hy     (1) channel number (this came from multmtrn
    7     0.00     0.00 S2H  Hz         and so the #s aren't 1,2 ... ;
    8     0.00     0.00 S2E  Ex      (2) orientation (deg. E of N);  (3) tilt ;
    9    90.00     0.00 S2E  Ey      (4) Data loger ID  (5) channel type

period :      4.65455    decimation level   1    freq. band from   25 to   30
number of data point   2496 sampling freq.   1.000 Hz   <=== info about 1 band
 Transfer Functions
  0.2498E+00 -0.2049E-03 -0.9341E-04  0.2517E+00
 -0.6246E-02 -0.5245E-01 -0.7291E+01 -0.7318E+01       <=== Z
  0.7292E+01  0.7346E+01 -0.3806E-01  0.5754E-02
 Inverse Coherent Signal Power Matrix
  0.2947E-07  0.5753E-16                               <=== S
 -0.1575E-09  0.1391E-09  0.2895E-07  0.2386E-15
 Residual Covariance
  0.3198E+02  0.0000E+00
  0.2252E+03 -0.2185E+03  0.2660E+05  0.0000E+00        <=== N
  0.2424E+03  0.2418E+03  0.4577E+03  0.3710E+03  0.2781E+05  0.0000E+00
\end{verbatim}
\normalsize

The block given above for one period should be pretty much self explanatory.
Note that the last two rows of the TF matrix are the
local impedance tensor.

\section{Error Calculation}

First I just give the formula for calculating errors in the
TF given in the files (i.e., in the ``default''
measurement coordinate system).  Next, I'll give formulas for
transforming the matrices {\bf Z, S, N} into a different
coordinate system (not necessarily by rotation).  The initial formulas
for TF error in the measurement coordinate system
can then be applied to the transformed
matrices.  Finally, linear error propagation is applied to give
the standard error estimates for $\rho_a$ and $\phi$ computed
from the off-diagonal elements of the impedance.

\subsection{Errors In Transfer Functions}

The error covariance for the elements of the transfer
function matrix {\bf Z} is given by:
\begin{equation}
{\bf Cov} [ Z_{ij} Z_{i'j'} ] = N_{ii'} S_{jj'} \,\,\,\,\,\,\, j, j' = 1,2
\,\,\,\,\,\,,\  i, i' = 1,NCH-2   .
\label{eq1}
\end{equation}
You will normally only care about the variances (i.e., the case where
$i = i'$ and $j = j'$).  In this case you would use only the
diagonal elements of {\bf S} and {\bf N}.  In the following I
refer to these variances as
\begin{equation}
{\sigma_{ij}}^2 =
{\bf Var} [ Z_{ij} ] = {\bf Cov} [ Z_{ij} Z_{ij} ] =
N_{ii} S_{jj} .
\label{eq2}
\end{equation}
For example, the impedance element $Z_{xy} ( = E_x / H_y )$
in the above example is element (2,2) (row = i = 2, column = j = 2)
in the TF matrix {\bf Z}.  The error variance is obtained from the product
of the second diagonal element of the inverse coherent signal
power matrix $S_{22}$, and the second diagonal element of the residual
covariance $N_{22}$.  The other off-diagonal impedance element $Z_{yx}$
corresponds to $i = 3$ and $j = 1$, and the variance
is $\sigma_{31} = N_{33} S_{11}$.
Note that this gives the variances of the complex transfer
functions; variances of real and
imaginary parts separately are each one half of the complex variance
given by (\ref{eq1}).

\subsection{Transformation Of Transfer Functions and Errors}

The transformation of error covariance can be computed for
any linear transformation of the predicted and predictor
channels.  Here I just give expressions
for the most standard rotations.  Denote by $\theta_1 , \theta_2 , ...
\theta_{NCH}$ the channel orientations (these are given in the header
block of the Z\_ file).
Let $\theta$ be the desired rotation of the $x-$axis, relative to
the same reference direction used to define the channel orientations
(e.g., geographic or geomagnetic north).  Note that the sort of coordinate
changes we focus on here implicitly involve pairs of channels (the two
reference magnetics; a pair of electric channels).  Vertical magnetics
are not rotated (well ... we {\it could} get into allowing for tilt ...),
and when there are multiple electrics, it will be necessary to identify
pairs of channels to transform together.  I thus describe transformation
of one pair of channels at a time, say channels $l, m$.  Form the matrix
\begin{equation}
{\bf U_{lm}}  =
\left [
\matrix { \cos ( \theta_l - \theta ) & \sin ( \theta_l - \theta ) \cr
          \cos ( \theta_l - \theta ) & \sin ( \theta_m - \theta ) \cr}
\right ] ^{-1}
\label{rotmat}
\end{equation}

Note that if you form the 2-vector ${\bf x }$ from the $(l, m)$
pair of measured data channels, then ${\bf U_{lm}} { \bf x}$ gives the
vector expressed in the new right-handed orthogonal coordinate system
(with $x-$axis pointing
in the direction $\theta$ degrees E of the reference direction).
Note that in the ``usual'' MT case where
there is one pair of reference channels $H_x$, $H_y$ and one pair
of predicted channels $E_x$, $E_y$, and both are expressed in
the same orthogonal coordinate system, then the same matrix ${\bf U_{lm}}$
would be used for coordinate transformation of
both pairs, and we would also have
$\theta_m = \theta_l + 90$.  In this case ${\bf U_{lm}}$ would
reduce to the more familiar form for the impedance tensor
rotation matrix.  The formulas given here work for any orientations,
including the case of non-orthogonal measurment component pairs.

First consider transformation of the predicting channels $l = 1$,
$m = 2$ (normally these would be $H_x$, $H_y$).
${\bf Z}$ and ${\bf S}$ are effected
by this part of the transformation.  In the new coordinate system the
matrices are:
\begin{equation}
{\bf Z'} = {\bf Z U_{12}}^T    \,\,\,\,\,\,\,\,\,\,\,\,
{\bf S'} = {\bf U_{12} S U_{12}}^T
\label{hxf}
\end{equation}
The output residual covariance ${\bf N}$ of course remains unchanged
by a transformation of only the input channels.

Next consider transformation of two
of the output channels, $3 \le l, m \le NCH$.
(Note the numbering convention: output channels start with 3, and go to $NCH$,
for a total of $NCH-2$).  The simplest way to express the result in
general is to define an $(NCH-2) \times (NCH-2)$
transformation matrix ${\bf V_{lm}}$ which rotates only channels $l$ and $m$.
For the example file above, where $NCH = 5$,
the matrix for
rotating the coordinate system for the pair of electric field channels
(i.e., $l = 4, m = 5$), ${\bf V_{45}}$ would take the form
\begin{equation}
{\bf V_{45}}  =
\left [
\matrix {   1 & 0 & 0 \cr
         0 & \cos ( \theta_4 - \theta ) & \cos ( \theta_5 - \theta ) \cr
         0 & \sin ( \theta_4 - \theta ) & \sin ( \theta_5 - \theta ) \cr}
\right]  .
\label{vdef}
\end{equation}
More generally the following pseudo-code defines ${\bf V_{lm}}$,
assuming $l < m$:

\begin{list} {} {\leftmargin=2em}
\item ${\bf V_{lm}} = (NCH-2) \times (NCH-2)$ identity  matrix
\item ${\bf V_{lm}}(l-2,l-2) =  \cos ( \theta_l - \theta )$
\item ${\bf V_{lm}}(m-2,l-2) =  \sin ( \theta_l - \theta )$
\item ${\bf V_{lm}}(l-2,m-2) =  \cos ( \theta_m - \theta )$
\item ${\bf V_{lm}}(m-2,m-2) =  \sin ( \theta_m - \theta )$
\end{list}
With ${\bf V_{lm}}$ thus defined the transformations of {\bf Z} and {\bf N} are:
\begin{equation}
{\bf Z'} = {\bf V_{lm} Z }   \,\,\,\,\,\,\,\,\,\,\,\,
{\bf N'} = {\bf V_{lm} N V_{lm} }^T
\label{rxf}
\end{equation}
In general both input and output channels will be rotated, so
both (\ref{hxf}) and (\ref{rxf}) will be used.  In the 5 channel
example given above the full transfromation of all arrays is thus:
\begin{equation}
{\bf Z'} = {\bf V_{45} Z U_{12} } \sp {T}   \,\,\,\,\,\,\,\,\,\,\,\,
{\bf S'} = {\bf U_{12} S U_{12} } \sp {T}   \,\,\,\,\,\,\,\,\,\,\,\,
{\bf N'} = {\bf V_{45} N V_{45} }^T .
\label{hexf}
\end{equation}
More generally
there may be a series of electric field pairs, requiring that
(\ref{rxf}) be applied for each pair.  Note that in this case
a single matrix {\bf V} can be derived which transforms all
channel pairs, by starting with the $(NCH-2) \times (NCH-2)$
identity matrix and modifying the
appropriate four elements of {\bf V} for each pair $l, m$.
Error (co)variances for the transformed impedance elements are then as
given in (\ref{eq2}) and (\ref{eq1}), with ${\bf N'}$ and ${\bf S'}$
replacing {\bf N} and {\bf S}.

\section{Apparent Resistivities and Phases}

After transforming all three arrays,
apparent resistivities ($\rho_a$), phases ($\phi$) and error
bars ($\sigma_{\rho}; \sigma_{\phi}$) can be computed from
the appropriate off-diagonal impedance
elements (say $Z_{ij}$), the period $T$,
and the associated error variance $\sigma_{ij}$ given above.
For completness here are the expressions derived from linear
propogation of errors, under the assumption that errors are small
compared to the impedance.

$$
\rho_a = { { T | Z_{ij} |^2 } \over {5} }
$$

$$
\sigma_{\rho} = \left [ {{ ( 2T \rho {\sigma_{ij}}^2 } \over 5 } \right ]
\sp {1/2}
$$

$$
\phi = { 180 \over \pi }  \arctan [ \Im ( Z_{ij} ) / \Re ( Z_{ij} ) ]
$$

$$
\sigma_{\phi}  = { 180 \over { \pi | Z_{ij} | } }
\left [ { {\sigma_{ij}}^2 \over 2 }
\right ] \sp {1/2}
$$

\end{document}