% File:		vec2d.tex
% Author:	See Below
% Date:	        See Below
%
% The authors have placed this file in the public domain;
% they make no warranty and accept no liability for this file.

\documentclass[12pt]{article}
\usepackage{times}
\usepackage{color}
\usepackage[usenames]{xcolor}
\usepackage{scalefnt}
\usepackage{tikz}
\usepackage{wrapfig}
\usetikzlibrary{arrows}
\begin{document}
\newcommand{\header}[1]{\underline{\bf #1}}
\newcommand{\file}[1]{{\bf #1}}
\newcommand{\blankpage}{\newpage\vspace*{3.5in}%
    \centerline{\Large This Page is Intentionally Left Blank}}
\setlength{\parindent}{0.0in}
\setlength{\parskip}{1ex}
\newcommand{\key}[1]{{\bf #1}}
\newcommand{\TT}[1]{{\tt \bfseries #1}}
\newcommand{\EOL}{\penalty \exhyphenpenalty}
\newtheorem{definition}{Definition}[section]
\newtheorem{lemma}[definition]{Lemma}
\newtheorem{corollary}[definition]{Corollary}
\newtheorem{theorem}[definition]{Theorem}
\newtheorem{algorithm}[definition]{Algorithm}
\newenvironment{indpar}[1]%
    {\begin{list}{}{\setlength{\leftmargin}{#1}}\item[]}%
    {\end{list}}

\newcommand{\wh}{\,\widehat{~}\,}
\newcommand{\WH}{$\widehat{~}$}

\begin{center}
{\Large \bf Two Dimensional Geometry Calculator}

\begin{tabular}{ll}
Author:	      & Robert L.~Walton $<$walton@acm.org$>$ \\
Date:         & Wed Aug  4 22:08:37 EDT 2021
\end{tabular}
\\[2ex]
\begin{tabular}{p{5in}}
The author(s) have placed this document and associated problems
in the public domain;
they make no warranty and accept no liability for this document
or associated problems.
\end{tabular}

\end{center}

\medskip

\section{Overview}
This document describes a group of 2-dimensional geometry problems
involving vectors, points, and straight lines
(but \underline{not} polygons).
The problems are embedded in a simple calculator for ease of
testing.

\section{Boolean, Scalars, Vectors, and Transforms}
A \key{boolean} here is either the symbol \key{true} or the symbol \key{false}.

A \key{scalar} here is a double precision floating point number.

A \key{vector} here is a pair $(x,y)$ of double precision floating point
numbers, $x$ denoting an X-coordinate value, and $y$ denoting a
Y-coordinate value.  Such a vector can denote a point $(p_x,p_y)$ in the
XY-plane, or can denote a translation $(v_x,v_y)$ of the plane: \\
\centerline{$(p_x,p_y) \longmapsto (p_x+v_x,p_y+v_y)$}

The product of a scalar $s$ and a vector $v=(v_x,v_y)$ is represented using
$*$ as $s*v = (sv_x,sv_y)$.
The sum of a vector $v=(v_x,v_y)$ and a vector $w=(w_x,w_y)$ is
represented using $+$ as $v+w = (v_x+w_x,v_y+w_y)$.

A \key{linear transformation} here is a pair of vectors, $[\ell_x,\ell_y]$
representing the map:
\centerline{$(v_x,v_y) \longmapsto v_x*\ell_x+v_y*\ell_y$}
Application is represented using
$*$ as $[\ell_x,\ell_y]*v=v_x*\ell_x+v_y*\ell_y$.

A \key{vector list} here is a list of vectors
$(v_1,v_2,\ldots)$.  This can be used to represent the list of vertices
of a polygon or a list of points in the plot of a function.

\newpage

\section{The Calculator Language}
The calculator language of this problem is very simple.
An example is:
\\[1ex]
{\tt
\hspace*{0.2in}\begin{tabular}{l@{\hspace{0.5in}}l}
\rm \bf Input	& \rm \bf Output \\\hline
x=4		& x=4 \\
y = 0.5         & y = 0.5 \\
z = x + y       & z = x + y = 4.5 \\
v=(3,-2)	& v=(3,-2) \\
w=z*v		& w=z*v = (13.5,-9) \\
\# this is a comment & \# this is a comment
\end{tabular}
} % \tt

The syntax is:
\\[1ex]
\hspace*{0.2in}\begin{tabular}{l}
{\em program} ::= {\em statement}$^\star$ \\
{\em statement} ::= \\
\hspace*{0.2in}\begin{tabular}[t]{cl}
                    & {\em comment} {\em eol} \\
                $|$ & {\em variable} \TT{=} {\em value} {\em eol}\\
                $|$ & {\em variable} \TT{=} {\em operator}
		          \{ {\em variable} {\em operator} \}$^\star$
		          {\em variable}$^?$ {\em eol} \\
                $|$ & {\em variable} \TT{=} {\em variable}
		          \{ {\em operator} {\em variable} \}$^\star$
		          {\em operator}$^?$ {\em eol} \\
                $|$ & {\em variable} \TT{=} {\em function}
		          {\em variable}$^\star$ {\em eol} \\
		\end{tabular}
\\[1ex]
{\em eol} ::= end-of-line (line-feed) \\
{\em comment} ::= \TT{\#} {\em character-other-than-line-feed}$^\star$ \\
{\em variable} ::= a single letter (case matters) \\
{\em value} ::= {\em boolean} $|$ {\em scalar} $|$ {\em vector}
	    $|$ {\em linear-transform} $|$ {\em vector-list} \\
{\em boolean} ::= \TT{true} $|$ \TT{false} \\
{\em scalar} ::= double precision floating point number (e.g., 1.4142135) \\
{\em vector} ::= \TT{(} {\em scalar}\TT{,} {\em scalar} \TT{)} \\
{\em linear-transform} ::= \TT{[} {\em vector}\TT{,} {\em vector} \TT{]} \\
{\em vector-list} ::= \TT{()} $|$
                 \TT{(} {\em vector} \{ \TT{,} {\em vector} \}$^\star$ \TT{)} \\
{\em operator} ::= \begin{tabular}[t]{@{}l}
                   one or more non-letter, non-digit graphic characters \\
                   (e.g. {\tt +} or {\tt <=})\\
		   \end{tabular} \\
{\em function} ::= \begin{tabular}[t]{@{}l@{}}
     three or more letters (e.g. {\tt sin} or {\tt area}) \\
     no {\em function} shall be a prefix of another {\em function} \\
     \end{tabular}
\end{tabular}

\newpage

There are multiple versions of the calculator, each an extension
of previous versions:
\begin{center}
\small
\begin{tabular}{ll}
Version & Implements
\\\hline
Scalar	& scalar and boolean types \\
Vector  & the vector type \\
Linear Transform & the linear transformation type \\
Rotations and Reflections & rotation and reflection linear transforms \\
Products & vector scalar and cross products \\
Line and Point & algorithms involving a line and a point \\
Line and Line & algorithms involving two lines \\
\end{tabular}
\end{center}

The Input/Output Rules are:
\begin{indpar}{0.2in}\begin{itemize}

\item Whitespace in {\em statements} is optional and should be deleted
before the {\em statements} are parsed.  There may be whitespace
before the `{\tt \#}' that begins a comment.

\item The output of a {\em statement} is a copy of the {\em statement}
line (including white\-space)
if the {\em statement} is a comment or is of the form
`{\em variable} \TT{=} {\em value} {\em eol}'.
Otherwise the output is one line containing a copy of the {\em statement}
followed by `{\em space} \TT{=} {\em space} {\em value} {\em eol}', where
the {\em value} is that assigned to the {\em variable} beginning the
{\em statement}.

\item Input lines have a maximum of 100,000 characters (long lines
are only needed for inputting vector lists).  Output lines have
no limit (output vector lists can be arbitrarily long).

\item Each calculator version should be able to input and output
values of the types being tested by that version (beginning with
{\em boolean} and {\em scalar} values) and process comments
and statements of the form `{\em variable} \TT{=} {\em variable}'.

\item {\em Scalars} should be output with 6 digits of precision
(which is the default for C/C++).  To pass tests, scalar values
must be accurate to better than 5 digits of precision \underline{or}
to better than $\pm 10^{-10}$.

\item  The total number of vector list elements that need to be
allocated during one program execution will be small enough
that these list elements do not need to be garbage collected
(need not be freed when no longer needed).

\item Input will \underline{not} contain the character `{\tt \$}',
which can then be used as per Coding Hints below.

\end{itemize}\end{indpar}

\newpage

\section{Scalar Calculator}
Implement the calculator with just {\em scalar} and {\em boolean}
value types and the
{\em operators} and {\em functions}:
\begin{center}
\begin{tabular}{l@{~~~~~}l}
Assume:	& {\tt x=}$x$, {\tt y=}$y$ are scalars \\
	& {\tt d=}$d$ is an integer scalar, $-15\le d\le +15$ \\
then: \\[1ex]
\tt x+y & returns $x + y$ \\
\tt x-y & returns $x - y$ \\
\tt x*y & returns $x \times y$ \\
\tt x/y & returns $x / y$ \\
\tt x\%y & returns $x - n*y$ \\
         & where $n = x/y$ rounded to the integer nearest zero \\
\tt -x & returns $-x$ \\
\tt |x| & returns $|x|$, the absolute value of $x$ \\
\tt cos x & returns $\cos ( (\pi/180) * x )$ [{\tt x} is in degrees] \\
\tt sin x & returns $\sin ( (\pi/180) * x )$ [{\tt x} is in degrees] \\
\tt tan x & returns $\tan ( (\pi/180) * x )$ [{\tt x} is in degrees] \\
\tt x<y:d & returns \TT{true} if $x<y-0.5*10^{-d}$, else \TT{false} \\
\tt x<=y:d & returns \TT{true} if $x<y+0.5*10^{-d}$, else \TT{false} \\
\tt x==y:d & returns \TT{true} if $|x-y|<0.5*10^{-d}$, else \TT{false} \\
\tt x:d & returns $x\textrm{~rounded to be an exact multiple of~}10^{-d}$ \\
\end{tabular}
\end{center}

Angles are measured in degrees, with positive angles going counter-clockwise
and negative angles going clockwise.

Comparisons assume the scalars being compared are approximations
to precise numbers that are in units of $10^{-d}$, and therefore to test
for equality the scalars should be (in effect) rounded to the nearest unit.
In addition, the scalars have to be good enough approximations.  As
\label{DOUBLE-SIZE-LIMITS}
double precision floating point numbers are accurate to at most one part
in $10^{16}$, this means that if the units are $10^{-d}$ the scalar
should not have absolute value above $10^{15-d}$.

Division by {\tt 0} will produce results such as
{\tt inf} (plus infinity), {\tt -inf} (minus infinity),
and {\tt nan} (not a number; i.e., result could not be computed).

\begin{center}
\begin{tabular}{rl}
Sample Input Files: & \file{00-XXXX-scalar-vec2d.in} \\
Sample Output Files: & \file{00-XXXX-scalar-vec2d.ftest} \\
Sample Run File: & \file{sample-scalar-vec2d.run} \\
Submit Run File: & \file{submit-scalar-vec2d.run} \\
\end{tabular}
\end{center}

You can test your program using the indicated sample input and
output and you can submit your program using the indicated submit
run file.  Only scalar functionality is tested.

There is also the file:
\begin{center}
\begin{tabular}{rl}
Special Input File: & \file{00-000-special-vec2d.in} \\
\end{tabular}
\end{center}
which may be used to see the results of divide by zero
and other anomalous scalar computations.
The output of your program for this special input file will depend
upon the programming language you use, so the output is
not testable except by human inspection.  Therefore there is
no companion {\tt .ftest} file, and the special input
file is not included in any {\tt .run} files.

\section{Coding Hints}
The calculator memory just maps each variable to a value.
You can map each ASCII character to a value using a
vector of 128 elements, and simply not use the elements
that do not correspond to letters.

To parse a line, remove its whitespace characters.  Then
\begin{itemize}
\item If the line begins with `{\tt \#}', it is a {\em comment}.
\item Else if the line contains a digit, it has the form
`{\em variable} \TT{=} {\em value}', where {\em value} is:
\begin{itemize}
\item A linear-transform if the `\TT{=}' is followed by `\TT{[}'.
\item A vector list if the `\TT{=}' is followed by `\TT{((}'.
\item A vector if the `\TT{=}' is followed by `\TT{(}' but not `\TT{((}'.
\item A scalar otherwise.
\end{itemize}
\item If the line does \underline{not} contain a digit, match the
line to a pattern using the rules:
\begin{itemize}
\item The pattern and the line must be the same length.
\item A pattern character other than `\TT{\$}' must match the line character
exactly.
\item The `\TT{\$}' pattern character must match a letter (which will
be a {\em variable}).
\end{itemize}
\end{itemize}
Examples: \begin{tabular}[t]{l@{~~~}l@{~~~}l}
\underline{The Pattern} & \underline{Matches}
\\[1ex]
\tt \$=\$ & \tt x=y \\
\tt \$=true & \tt t=true \\
\tt \$=() & \tt x=() \\
\tt \$=\$+\$ & \tt b=c+d \\
\tt \$=sin\$ & {\tt x=sinA} & [Normally input as {\tt x=sin A}] \\
\tt \$=\$<=\$:\$ & {\tt x=y<=z:d}  & [Normally input as {\tt x = y<=z:d}] \\
\end{tabular}

Remember that when you output a line, you are outputting the
\underline{original}
line before whitespace characters were removed.

Solutions to the Scalar Calculator problem are available in the files:
\begin{center}
\begin{tabular}{ll}
\TT{c-scalar-vec2d.txt}	&  for C \\
\TT{cc-scalar-vec2d.txt}	&  for C++ \\
\TT{java-scalar-vec2d.txt}	&  for JAVA \\
\TT{py-scalar-vec2d.txt}	&  for PYTHON \\
\end{tabular}
\end{center}

You can build solutions for successive calculator versions
by renaming and extending one of these files, if you like.

The first section of each of these files contains data declarations.
Using these should make it easier
for other people familiar with this problem to read your
code, should that be important.
It is recommended that you use this first section even
if you do not use the rest of the file.

\section{Operations on Vectors}
\begin{minipage}{\textwidth}\raggedright
\begin{wrapfigure}{r}{0.45\textwidth}
\begin{tikzpicture}[x=0.25in,y=0.25in]
\begin{scope}[>=triangle 45,shorten >=0.01in]

    \fill[black] (0,0) circle(0.1) + (+0.0,-0.5) node[black]{$p$};

    \draw[red,->] (0,0) -- (+3,+1);
    \draw[black] (1.3,0.8) node{$v$};
    \fill[black] (+3,+1) circle(0.1) + (+0.2,-0.5) node[black]{$p+v$};
    \draw[blue,->] (+3,+1) -- (-1,+4);
    \draw[black] (+1.6,2.5) node{$w$};
    \fill[black] (-1,+4) circle(0.1) + (+0.5,+0.5) node[black]{$p+v+w$};

    \draw[blue,->] (0,0) -- (-4,+3);
    \draw[black] (-2.8,1.4) node{$w$};
    \fill[black] (-4,+3) circle(0.1) + (-0.2,+0.5) node[black]{$p+w$};
    \draw[red,->] (-4,+3) -- (-1,+4);
    \draw[black] (-2.1,3.3) node{$v$};

    \draw[brown,->] (0,0) -- (-1,+4);
    \draw[black] (-0.2,1.8) node{$v+w$};
\end{scope}
\end{tikzpicture}
\end{wrapfigure}
We will define the \key{vector sum} of vectors $v=(v_x,v_y)$ and
$w=(w_x,w_y)$ to be $v+w=(v_x+w_x,v_y+w_y)$.  If you
think of a point $p=(p_x,p_y)$ in the XY-plane as a vector,
you can associate a translation $\tau_v$ of the XY-plane
with the vector $v$ using the equation $\tau_v(p)=p+v$.  Then\\
\hspace*{0.2in}$\tau_w(\tau_v(p)) = p+v+w = \tau_{v+w}(p)$ \\
See the picture.
\\[1ex]
Vector sums are commutative, i.e.,  $v+w=w+v$, and associative,
i.e., $u+(v+w)=(u+v)+w$.
\end{minipage}

\bigskip

\begin{minipage}{\textwidth}\raggedright
\begin{wrapfigure}{r}{0.55\textwidth}
\begin{tikzpicture}[x=0.20in,y=0.20in]
\begin{scope}[>=triangle 45]

    \draw[black,->] (0,3) -- (4,3) node[black,right]{$2*v$};
    \draw[black,->] (0,2) -- (2,2) node[black,right]{$v$};
    \draw[black,->] (0,1) -- (1,1) node[black,right]{$0.5*v$};
    \fill[black] (0,0) circle(0.1) node[black,right]{$0*v$};
    \draw[red,->] (0,-1) -- (-1,-1) node[black,left]{$-0.5*v$};
    \draw[red,->] (0,-2) -- (-2,-2) node[black,left]{$-1.0*v$};
    \draw[red,->] (0,-3) -- (-4,-3) node[black,left]{$-2.0*v$};
\end{scope}
\end{tikzpicture}
\end{wrapfigure}
We define the \key{scalar product} of a scalar $s$ and a vector
$v=(v_x,v_y)$ as $s*v = (s*v_x,s*v_y)$.  Multiplication
of $v$ by $s>0$ does not change the direction of $v$,
but multiplies the length of $v$ by $s$.  Multiplication of $v$ by
$s<0$ reverses the direction of $v$ and multiplies its length
by $|s|$.  See the picture.
\\[1ex]
Scalar products are associative in that
$s_1*(s_2*v)=(s_1*s_2)*v$ and distributive in that
$s*(v_1+v_2)=s*v_1+s*v_2$ and $(s_1+s_2)*v = s_1*v + s_2*v$.
\end{minipage}

\medskip

The negative of a vector is defined as $-v = (-1)*v = (-v_x,-v_y)$.
Subtraction of vectors is defined as $v-w = v + (-w) = (v_x-w_x,v_y-w_y)$.

\medskip

\begin{minipage}{\textwidth}\raggedright
\begin{wrapfigure}{r}{0.4\textwidth}
\begin{tikzpicture}[x=0.20in,y=0.20in]
\begin{scope}[>=triangle 45,shorten >=0.01in]
    \draw[black] (-1,0) -- (+5,0);
    \draw[black] (0,-1) -- (0,+3);

    \fill[red] (0,0) circle(0.1);
    \draw[black] (2.0,-0.5) node{$||v||*\cos \theta$};

    \draw[brown,>=latex,->] (2.0,0) arc(0:30:2.0);
    \draw[black] (2.4,+0.4) node{$\theta$};

    \fill[red] (3.464101615,2.0) circle(0.1);
    \draw[red,->] (0,0) -- (3.464101615,2.0);
    \draw[black] (1.3,+1.5) node{$||v||$};
    \draw[black] (3.4,+2.5) node[right]{$v$};

    \draw[orange] (3.464101615,0) -- (3.464101615,2.0);
    \draw[black] (3.464101615,1) + (0.1,0)
                 node[right]{$||v||*\sin \theta$};
\end{scope}
\end{tikzpicture}
\end{wrapfigure}
A vector $v=(v_x,v_y)$ has a length and a direction.
The \key{length}, denoted by $||v||$, can be computed using
Pythagoras's Theorem: $||v||=\sqrt{v_x^2+v_y^2}$.  The
direction is given by the counterclockwise angle $\theta$ from
the positive X-axis direction to the vector direction.
This is called the \key{azimuth} of $v$, and in computer
languages may be computed (in radians) by the {\tt atan2} function as
$\theta = \mathrm{atan2}(v_y,v_x)$ (note $v_y$ comes before $v_x$).
\end{minipage}

We measure angles, including azimuths, in degrees.  To convert degrees
to radians, multiply by $\pi/180$, and to convert radians to degrees,
multiply by $180/\pi$.  Positive angles are counter-clockwise, and
negative angles are clockwise.

For a vector {\tt v},~~{\tt azm v} and {\tt ||v||} are said to be
the \key{polar coordinates} of {\tt v}.
The vector with the polar coordinates $\theta$ (azimuth) and $\ell$ (length) is
$(\ell \cos\theta,\ell \sin\theta)$.  For the vector {\tt v}=$(v_x,v_y)$:
\begin{center}
\tt
\begin{tabular}{l}
||v|| = $\sqrt{v_x^2+v_y^2}$ \\
azm v = $(180/\pi)$ * atan2($v_y$,$v_x$)
\end{tabular}
\end{center}
See the picture.

Adding integer multiples of 360 to a vector's
azimuth does \underline{not} change the vector.

\newpage

\section{Vector Calculator}
Implement additions to the scalar calculator for just {\em vector}
value types and the {\em operators} and {\em functions}:
\begin{indpar}{0.05in}
\begin{tabular}{l@{~~~}l@{~~~}l}
Assume: & {\tt s=}$s$, {\tt x=}$x$, {\tt y=$y$},
          {\tt l=$\ell$}, {\tt t=$(180/\pi)*\theta$}
          are scalars \\
	& {\tt d=}$d$ is an integer scalar, $-15\le d\le +15$ \\
	& {\tt v=}$(v_x,v_y)$, {\tt w=}$(w_x,w_y)$ are vectors \\
	& {\tt L} is a list of vectors \\
then: \\[1ex]
\tt (x,y) & returns $(x,y)$ \\
\tt v.x & returns $v_x$ ~~~ ({\tt x} is \underline{not} a variable here) \\
\tt v.y & returns $v_y$ ~~~ ({\tt y} is \underline{not} a variable here) \\
\tt v==w:d & returns $v_x==w_x:d$ AND $v_y==w_y:d$ \\
\tt v:d & returns $(v_x:d,v_y:d)$ \\
\tt s*v & returns $(s v_x, s v_y )$ \\
\tt -v & returns $( -v_x, -v_y )$, {\tt v} with direction reversed \\
\tt v+w & returns $(v_x + w_x, v_y + w_y)$ \\
\tt v-w & returns $(v_x - w_x, v_y - w_y)$ \\
\tt ||v|| & returns $\sqrt{v_x^2 + v_y^2}$ & [length] \\
\tt azm v & returns $(180/\pi)*\mathrm{atan2}(v_y,v_x)$ adjusted & [azimuth] \\
          & to be in the range [0,360).  Calculated values very \\
	  & near 0 or 360 may be unstable. \\
	  & The returned value is undefined if $||v||=0$. \\
\tt l\WH t & returns $(\ell\cos\theta,\ell\sin\theta)$,
	     the vector with length {\tt l} and \\
	   & azimuth {\tt t} degrees,
	     where $\theta = (\pi/180)*{\tt t}$ radians \\
\tt cons v L & returns the list made by prepending {\tt v} to {\tt L} \\
\end{tabular}
\end{indpar}

If {\tt ||v|| = 0} then {\tt azm~v} is undefined (you can do extra
programming to make it defined as {\tt nan} if you like, but this
is not necessary).

\begin{center}
\begin{tabular}{rl}
Sample Input Files: & \file{00-XXXX-vector-vec2d.in} \\
Sample Output Files: & \file{00-XXXX-vector-vec2d.ftest} \\
Sample Run File: & \file{sample-vector-vec2d.run} \\
Submit Run File: & \file{submit-vector-vec2d.run} \\
\end{tabular}
\end{center}

You can test your program using the indicated sample input and
output and you can submit your program using the indicated submit
run file.

\newpage

\section{Display Language}
Points, lines, arrows, etc.~can be displayed
by making a {\tt .pdf} file from an {\tt .in}
file and your solution program.
The display commands are embedded in {\tt .in} file `{\tt \#}' comment
lines, so your program does not have to deal with them.
The {\tt 00-000-vector-vec2d.in} file has examples of all the
display commands.  Most sample {\tt 00-XXXX-YYYY-vec2d.in} files have
have display commands if they compute vectors.

\medskip

\begin{minipage}{\textwidth}
The line/area drawing commands are:
\\[1ex]
\begin{tabular}{@{}l@{~~~~~}l@{}}
\underline{Command} & \underline{Draws}
\\[1ex]
\tt \#!point p [color] [size] & point {\tt p} \\
\tt \#!point L [color] [size] & points in the point list {\tt L} \\
\tt \#!line pq [color] [opt] & line from point {\tt p}
                                 to point {\tt q} \\
\tt \#!line L  [color] [opt] & lines with endpoints that are \\
                             & consecutive points in the \\
		             & list of points {\tt L} \\
\tt \#!infline pA [color] [opt] & infinite line from point {\tt p} \\
                                & in direction {\tt A}
				  (a scalar angle) \\
\tt \#!rectangle pq [color] [opt] & rectangle with opposing corners \\
                                  & point {\tt p} and point {\tt q} \\
\tt \#!circle cr [color] [opt] & circle of center {\tt c}
                                   and radius {\tt r} \\
\tt \#!ellipse cRA [color] [opt] & ellipse with center {\tt c}, radii \\
                                   & {\tt R.x} and {\tt R.y}, rotated \\
                                   & by angle A about its center \\
\end{tabular}
\end{minipage}

In the above {\tt p}, {\tt q}, {\tt c}, {\tt R}, {\tt r}, {\tt A}, {\tt L}
are arbitrary {\em variables}.  Each variable used in a display command
must have been set or computed by a calculator statement output before
the display command.  The last value assigned to the variable by a
calculator statement before the display command will be used by the
display command.

Circle and ellipse radii must be strictly positive.
Spaces are as indicated, and must consist
of at least one horizontal space character.
Coordinates are automatically scaled to fit the logical page.  Angles are
in degrees.

The possible colors
are `{\tt red}', `{\tt blue}', `{\tt brown}', and `{\tt black}'.  Black is
the default.
(Green does not show up when the page is printed in black-and-white, and
so is not provided.)

For points, {\tt size} is an integer in the range [1,18] giving the size
of each point in units of 1/72'nd inch (1pt).  The default is 2pt.

\begin{minipage}{\textwidth}
For non-points {\tt opt} is zero or more of:
\\[1ex]
\hspace*{0.5in}\begin{tabular}{rl}
    \tt . & dotted line \\
    \tt - & dashed line \\
          & ~~ ({\tt .} and {\tt -} conflict; if neither line is solid) \\
    \tt c & close path (for {\tt \#!line L}) \\
          & ~~ (implied by {\tt s}, {\tt d}, {\tt h}, {\tt v}) \\
    \tt m & add arrow head in middle of each line segment (for {\tt \#!line}) \\
    \tt e & add arrow head at end of each line segment (for {\tt \#!line}) \\
    \tt s & fill with solid color \\
    \tt d & fill with dots \\
    \tt h & fill with horizontal bars \\
    \tt v & fill with vertical bars \\
          & ~~ ({\tt s}, {\tt d}, {\tt h}, and {\tt v} conflict) \\
    \tt f & extend infinite line forward from point
            (for {\tt \#!infline}) \\
    \tt b & extend infinite line backward from point
            (for {\tt \#!infline}) \\
          & ~~ ({\tt f}, {\tt b} conflict; if neither
	        line extends in both directions) \\
    \end{tabular}
\end{minipage}

\begin{minipage}{\textwidth}
The text drawing commands are:
\\[1ex]
\begin{tabular}{@{}l@{~~~~~}l@{}}
\underline{Command} & \underline{Draws}
\\[1ex]
\tt \#!text p [color] opt text... &
    the text, place at/near point {\tt p} \\
\tt \#!text pq [color] opt text... &
    ditto but the text is placed at/near \\
    & the midpoint of the line {\tt pq}
\end{tabular}
\end{minipage}

\begin{minipage}{\textwidth}
Here {\tt opt} is `{\tt -}' for no options, or given that the point
of text placement is {\tt ($x$,$y$)}, is one or more of:
\\[1ex]
\hspace*{0.5in}\begin{tabular}{rl}
    \tt t & display about 0.5em above $y$ \\
    \tt b & display about 0.5em below $y$ \\
          & ~~ ({\tt t} and {\tt b} conflict, if neither center on $y$) \\
    \tt l & display about 0.5em left of $x$ \\
    \tt r & display about 0.5em right of $x$ \\
          & ~~ ({\tt l} and {\tt r} conflict, if neither center on $x$) \\
    \tt x & make the bounding rectangle of text white \\
    \tt c & make the bounding circle of text white \\
          & ~~ ({\tt x} and {\tt c} conflict) \\
    \tt o & outline any bounding rectangle or circle with \\
          & a black line of width 1pt \\
    \end{tabular}
\end{minipage}

Here `\key{em}' is the font size; capital letters are typically
0.7em high and lower case letters are typically 0.5em high.

\begin{minipage}{\textwidth}
The page commands are:
\\[1ex]
\begin{tabular}{@{}l@{~~~~~}l@{}}
\underline{Command} & \underline{Action}
\\[1ex]
\tt \#!layout R C [margin]   & Starts new physical page with R rows and \\
                             & C columns of logical pages, each logical \\
			     & page with margins as given in pt (1/72") \\
			     & (margin defaults to 18 or 0.25") \\
\tt \#!newpage [pq] & Starts new logical page with opposite \\
                    & corner coordinates optionally given by \\
		    & points p and q (which are not themselves \\
		    & displayed) \\
\tt \#!header text... & Adds text line to current logical page header \\
\end{tabular}
\end{minipage}

The output from a test case is one or more physical pages
each containing one or more logical pages.  The physical
pages are numbered and labeled with the test case name
(e.g., {\tt 00-000-vec2d}).  Each `{\tt header text...}' adds one
line to the logical page header.  If the first command is
not a `{\tt \#!layout}' command, then `{\tt \#!layout 1 1}'
is assumed.  A `{\tt \#!newpage}' command immediately after a
`{\tt \#!layout}' command may be omitted and will be assumed.

\newpage

\section{Linear Transforms}
If we let $\mathcal{R}$ denote the set of real numbers,
a.k.a., scalars, the set of all vectors is \\
\centerline{
$\mathcal{R}\times\mathcal{R}=\mathcal{R}^2
    =\{(v_x,v_y)|v_x,v_y\in \mathcal{R}\}$}

\begin{definition}\label{LINEAR-TRANSFORMATION}
A \key{linear transformation} $L$ is a continuous map
$L:\mathcal{R}^2\mapsto\mathcal{R}^2$ such that for
all vectors $v$ and $w$, $L(v+w)=L(v)+L(w)$.
\end{definition}

Some examples of linear transformations are (1) the identity map,
(2) rotations, (3) reflections about an axis, (4) scale changes
(i.e., $(v_x,v_y)\longmapsto(s_x v_x,s_y v_y)$ for scalars $s_x$
and $s_y$).

(In vector algebra, linear transformations with domains and/or ranges
that are vector spaces other than $\mathcal{R}^2$ are studied.)

\begin{lemma}
Let $L$ be a linear transformation, $v$ and $w$ be vectors,
and $0=(0,0)$ be the zero vector.  Then $L(0)=0$,  $L(-v)=-L(v)$,
and $L(v-w) = L(v) - L(w)$.
\end{lemma}
\begin{indpar}{0.5in}
Proof: $L(0) = L(0+0)= L(0) + L(0)$ so subtracting $L(0)$
from both sides, $0=L(0)$.  $0 = L(0) = L(v-v) = L(v) + L(-v)$
so subtracting $L(v)$ from both sides, $-L(v)=L(-v)$.
$L(v-w)=L(v+(-w))=L(v)+L(-w)=L(v)+(-L(w))=L(v)-L(w)$.
\end{indpar}

\begin{lemma}
Let $L$ be a linear transformation, $s$ be a scalar, and $v$ be a vector.
Then $L(s*v)=s*L(v)$.
\end{lemma}
\begin{indpar}{0.5in}
Proof: The cases $s=0,1,2,-1,-2$ follow from the previous lemma and
using induction proves the lemma for any integer $s$.  For $s=n/d$
a rational number with integers $n$ and $d$ and $d>0$, \\
\hspace*{0.1in}$n*L(v) = L(n*(d/d)*v) = L(d*(n/d)*v)=d*L((n/d)*v)$ \\
so dividing by $d$
we get $L((n/d)*v)=(n/d)*L(v)$.  For $s$ a non-rational real number,
the result follows from a continuity argument that we will leave
to the mathematicians, since computer scientists only compute
with rational numbers.
\end{indpar}

Let $L$ be a linear transformation; let $v=(v_x,v_y)$ be a vector;
let $u_x=(1,0)$ and $u_y =(0,1)$.  Then \\
\centerline{$L(v) = L(v_x*u_x+v_y*u_y)=v_x*L(u_x)+v_y*L(u_y)$.}

\begin{lemma}
Given vectors $\ell_x$ and $\ell_y$, the map
$L:(v_x,v_y)\longmapsto v_x*\ell_x+v_y*\ell_y$ is a linear
transformation.
\end{lemma}
\begin{indpar}{0.5in}
Proof: $L(v+w) = (v_x+w_x)*\ell_x+(v_y+w_y)*\ell_y
               = v_x*\ell_x+v_y*\ell_y+w_x*\ell_x+w_y*\ell_y
	       = L(v) + L(w)$.
\end{indpar}

So $L$ is determined by $\ell_x = L(u_x)$ and $\ell_y = L(u_y)$,
and there is a 1-1 correspondence between linear transformations
and vector pairs $[\ell_x,\ell_y]$.  Therefore we will represent a linear
transformation $L$ by a pair of vectors {\tt [$\ell_x$,$\ell_y$]}
and represent application of L to the vector {\tt v = ($v_x$,$v_y$)} by \\
\centerline{\tt $L(v)$ = [$\ell_x$,$\ell_y$]*($v_x$,$v_y$) =
             $v_x$*$\ell_x$+$v_y$*$\ell_y$}
Here we use [] instead of () to surround the pair of vectors of a linear
transformation, because our calculator does this to distinguish linear
transformations from lists of vectors.

Examples:
\begin{enumerate}
\item {\tt L=[(1,0),(0,1)]} is the identity map.
$L(v)=v_x*(1,0) + v_y*(0,1) = (v_x,0)+(0,v_y) = (v_x,v_y) = v$.
\item {\tt L=[(0,1),(-1,0)]} rotates vectors $90^\circ$.
Specifically, $L(u_x)=u_y$ and $L(u_y)=-u_x$ and
$L(v)=v_x*(0,1) + v_y*(-1,0) = (0,v_x)+(-v_y,0) = (-v_y,v_x)$.
\item {\tt L=[(-1,0),(0,-1)]} reverses the direction of a vector.
$L(v)=v_x*(-1,0) + v_y*(0,-1) = (-v_x,0)+(0,-v_y) = (-v_x,-v_y) = -v$.
\item {\tt L=[(-1,0),(0,1)]} reflects vectors across the Y-axis.
$L(v)=v_x*(-1,0) + v_y*(0,1) = (-v_x,0)+(0,v_y) = (-v_x,v_y)$.
\item {\tt L=[($s_x$,0),(0,$s_y$)]} scales the X-axis by $s_x$ and
the Y-axis by $s_y$. \\
$L(v)=v_x*(s_x,0) + v_y*(0,s_y)
     = (s_x v_x,0)+(0,s_y v_y)= (s_x v_x, s_y v_y)$.
\end{enumerate}

Now suppose we have a scalar {\tt s}, vector {\tt v},
and two linear transformations
{\tt K = [$\ell^K_x$,$\ell^K_y$]},
{\tt L = [$\ell^L_x$,$\ell^L_y$]}.  Then we can define:
\begin{center}
\tt
\begin{tabular}{l@{~so that~}l}
s*L = [s*$\ell^L_x$,s*$\ell^L_y$]
	 & (s*L)*v = s*(L*v) \\[0.3ex]
K+L = [$\ell^K_x$+$\ell^L_x$,$\ell^K_y$+$\ell^L_y$]
	 & (K+L)*v = K*v + L*v \\[0.3ex]
K-L = [$\ell^K_x$-$\ell^L_x$,$\ell^K_y$-$\ell^L_y$]
	 & (K-L)*v = K*v - L*v \\[0.3ex]
-L = [-$\ell^L_x$,-$\ell^L_y$]
	 & (-L)*v = - L*v \\[0.3ex]
K*L = [K*$\ell^L_x$,K*$\ell^L_y$]
	 & (K*L)*v = K*(L*v)
\end{tabular}
\end{center}

{\tt *} and {\tt +} as defined here are \key{bi-linear}, which means
(supposing {\tt t} to be another scalar and
{\tt J} to be another linear transformation):
\begin{center}
\tt
s*(K+L) = s*K + s*L \\
(s+t)*K = s*K + t*K \\
(J+K)*L = J*L + K*L \\
J*(K+L) = J*K + J*L
\end{center}

Addition of linear transformations commutes,
{\tt K+L = L+K}, but multiplication does not:
in general {\tt K*L} is \underline{not equal} to {\tt L*K}
(as an example, a rotation does not generally commute with
a reflection: see the end of the Rotations and Reflections
section below where $R^\phi*F^\omega = F^\omega*R^{-\phi}$).

Let {\tt I} be the identity transform defined by
{\tt I*v=v} for all vectors {\tt v}  (and therefore {\tt I=[$u_x$,$u_y$]}).
It is easy to check that {\tt K*I = K = I*K} for all linear transforms
{\tt K}.

A linear transform {\tt K} is defined to be the (two-sided) \key{inverse}
of the linear transform {\tt L} if and only if {\tt K*L = I = L*K}.
The inverse of {\tt L} might not exist, but if it does, it is unique
since if there were two, {\tt K$_1$} and {\tt K$_2$}, then \\
\centerline{\tt K$_1$ = K$_1$*I = K$_1$*(L*K$_2$)
                      = (K$_1$*L)*K$_2$ = I*K$_2$ = K$_2$}
The notation {\tt L$^{-1}$} is used for the inverse of {\tt L} if it
exists.  For example, the inverse of a rotation by angle $\phi$ in the
counter-clockwise direction is a rotation by angle $\phi$ in the
clockwise direction.

(One-sided inverses that are not two-sided inverses only exist for
linear transformations whose domain and range are vector spaces of
\underline{different} dimensions, unlike our linear transformations
whose domain and range are both 2-dimensional.)

\newpage

\section{Linear Transform Calculator}
Implement additions to the vector calculator for just {\em linear-transform}
value types and the {\em operators} and {\em functions}:
\begin{center}
\begin{tabular}{l@{~~~~~}l@{~~~~~}l}
Assume: & {\tt s=}$s$ is a scalar \\
	& {\tt d=}$d$ is an integer scalar, $-15\le d\le +15$ \\
	& {\tt v=($v_x$,$v_y$)} and {\tt w=($w_x$,$w_y$)} are vectors \\
	& \multicolumn{2}{@{}l}{{\tt K=[$\ell^K_x$,$\ell^K_y$]} and
	  {\tt L=[$\ell^L_x$,$\ell^L_y$]} are linear transforms} \\
then: \\[1ex]
\tt [v,w] & returns $[v,w]$ \\
\tt K==L:d & returns $\ell^K_x==\ell^L_x:d$ AND $\ell^K_y==\ell^L_y:d$ \\
\tt K:d & returns $[\ell^K_x:d,\ell^K_y:d]$ \\
\tt L.x & returns {\tt $\ell^L_x$}
          ~~~ ({\tt x} is \underline{not} a variable here) \\
\tt L.y & returns {\tt $\ell^L_y$}
          ~~~ ({\tt y} is \underline{not} a variable here) \\
\tt L*v & returns {\tt $v_x$*$\ell^L_x$+$v_y$*$\ell^L_y$} & [application] \\
\tt s*L & returns {\tt [$s\ell^L_x$,$s\ell^L_y$]} \\
\tt K+L & returns {\tt [$\ell^K_x$+$\ell^L_x$,$\ell^K_y$+$\ell^L_y$]} \\
\tt K-L & returns {\tt [$\ell^K_x$-$\ell^L_x$,$\ell^K_y$-$\ell^L_y$]} \\
\tt -L & returns {\tt [-$\ell^L_x$,-$\ell^L_y$]} \\
\tt K*L & returns {\tt [K*$\ell^L_x$,K*$\ell^L_y$]} & [composition] \\
\end{tabular}
\end{center}

\begin{center}
\begin{tabular}{rl}
Sample Input Files: & \file{00-XXXX-linear-vec2d.in} \\
Sample Output Files: & \file{00-XXXX-linear-vec2d.ftest} \\
Sample Run File: & \file{sample-linear-vec2d.run} \\
Submit Run File: & \file{submit-linear-vec2d.run} \\
\end{tabular}
\end{center}

\newpage

\section{Rotations and Reflections}
Rotations and reflections are the two kinds of linear transformations
that preserve vector lengths (i.e., $||L(v)||=||v||$).

\begin{minipage}{\textwidth}\raggedright
\begin{wrapfigure}[5]{r}{0.4\textwidth}
\begin{tikzpicture}[x=0.20in,y=0.20in]
\begin{scope}[>=triangle 45,shorten >=0.01in]
    \draw[black] (-1,0) -- (+5,0);
    \draw[black] (0,-1) -- (0,+3);

    \fill[red] (0,0) circle(0.1);

    \draw[brown,>=latex,->] (2.0,0) arc(0:30:2.0);
    \draw[black] (3.2,+0.4) node{azm~$v$};

    \draw[blue,>=latex,->] (1.7320508,1.0) arc(30:150:2.0);
    \draw[black] (+0.5,+2.3) node{$\phi$};

    \fill[red] (3.464101615,2.0) circle(0.1);
    \draw[red,->] (0,0) -- (3.464101615,2.0);
    \draw[black] (3.6,2.6) node{$v$};

    \fill[red] (-3.464101615,2.0) circle(0.1);
    \draw[red,->] (0,0) -- (-3.464101615,2.0);
    \draw[black] (-3.6,+2.6) node{$R^\phi(v)$};

\end{scope}
\end{tikzpicture}
\end{wrapfigure}
A \key{rotation} $R^\phi$ by $\phi$ degrees (counter-\EOL clockwise)
is defined mathematically by
\hspace*{0.2in}\begin{tabular}[t]{l}
$||R^\phi(v)|| = ||v||$ \\
$\mathrm{azm}~R^\phi(v) = \mathrm{azm}~v + \phi$ if $||v||\neq 0$ \\
\end{tabular} \\
~\\
A rotation preserves angles between vectors; that is: \\
\hspace*{0.2in}$\mathrm{azm}~R^\phi(v)-\mathrm{azm}R^\phi(w)
               = \mathrm{azm}~v-\mathrm{azm}~w$
	       if $||v||\neq 0 \neq ||w||$ \\
Also, adding integer multiples of 360 to $\phi$
does \underline{not} change $R^\phi$.
\end{minipage}

\bigskip

\begin{minipage}{\textwidth}\raggedright
\begin{wrapfigure}[5]{r}{0.5\textwidth}
\begin{tikzpicture}[x=0.20in,y=0.20in]
\begin{scope}[>=triangle 45,shorten >=0.01in]
    \draw[black] (-1,0) -- (+1,0);
    \draw[black] (0,-1) -- (0,+1);

    \fill[red] (0,0) circle(0.1);

    \fill[red] (3.464101615,2.0) circle(0.1);
    \draw[red,->] (0,0) -- (3.464101615,2.0);
    \draw[black] (2.7,0.6) node{$v$};

    \fill[red] (4.0,4.0) circle(0.1);
    \draw[brown,->] (0,0) -- (4.0,4.0);
    \draw[black] (1.4,2.8) node{$v+w$};

    \draw[blue,->] (3.464101615,2.0) -- (4.0,4.0);
    \draw[black] (4.2,3.0) node{$w$};

    \fill[red] (-3.464101615,2.0) circle(0.1);
    \draw[red,->] (0,0) -- (-3.464101615,2.0);
    \draw[black] (-1.4,+2.0) node{$R^\phi(v)$};

    \fill[red] (-5.464101521,1.464101590) circle(0.1);
    \draw[brown,->] (0,0) -- (-5.464101521,1.464101590);
    \draw[black] (-4.2,+0.2) node{$R^\phi(v+w)$};

    \draw[blue,->] (-3.464101615,2.0) -- (-5.464101521,1.464101590);
    \draw[black] (-5.0,2.3) node{$R^\phi(w)$};

\end{scope}
\end{tikzpicture}
\end{wrapfigure}
A rotation preserves side-lengths and angles of a triangle.
Therefore, a rotation preserves vector addition, that is,
$R^\phi(v+w)=R^\phi(v)+R^\phi(w)$, and thus
satisfies Definition~\ref{LINEAR-TRANSFORMATION}
and is a linear transformation.
\end{minipage}

\bigskip

\begin{minipage}{\textwidth}\raggedright
\begin{wrapfigure}[6]{r}{0.4\textwidth}
\begin{tikzpicture}[x=0.20in,y=0.20in]
\begin{scope}[>=triangle 45,shorten >=0.01in]
    \draw[black] (-1,0) -- (+5,0);
    \draw[black] (0,-1) -- (0,+1);

    \fill[red] (0,0) circle(0.1);

    \draw[red] (-0.577350269,-1) -- (2.886751345,5);

    \draw[brown,>=latex,->] (4.0,0) arc(0:60:4.0);
    \draw[black] (3.6,2.6) node{$\phi$};

    \fill[red] (2.897777478,0.776457135) circle(0.1);
    \draw[red,->] (0,0) -- (2.897777478,0.776457135);
    \draw[black] (3.2,0.3) node{$v$};

    \fill[red] (-0.776457135,2.897777478) circle(0.1);
    \draw[red,->] (0,0) -- (-0.776457135,2.897777478);
    \draw[black] (-1.3,+3.6) node{$F^\phi(v)$};

    \draw[blue,>=latex,->] (1.0,1.732050807) arc(60:15:2.0);
    \draw[black] (2.0,1.5) node{$\alpha$};

    \draw[blue] (1.0,1.732050807) circle(0.1);

    \draw[blue,>=latex,->] (1.0,1.732050807) arc(60:105:2.0);
    \draw[black] (0.3,2.3) node{$-\alpha$};

\end{scope}
\end{tikzpicture}
\end{wrapfigure}
A \key{reflection} $F^\phi$ by $\phi$ degrees, which
is a reflection across the line with direction $\phi$
through the origin,
is defined mathematically by
\hspace*{0.2in}\begin{tabular}[t]{l}
$||F^\phi(v)|| = ||v||$ \\
$\mathrm{azm}~F^\phi(v) = \phi - \alpha$ \\
where $\alpha = \mathrm{azm}~v - \phi$ so \\
$\mathrm{azm}~F^\phi(v) = 2*\phi - \mathrm{azm}~v$ if $||v||\neq 0$ \\
\end{tabular} \\
~\\
A reflection negates angles between vectors; that is: \\
\hspace*{0.2in}$\mathrm{azm}~F^\phi(v)-\mathrm{azm}F^\phi(w)
               = -(\mathrm{azm}~v-\mathrm{azm}~w)$
	       if $||v||\neq 0 \neq ||w||$ \\
Also, adding integer multiples of 180 to $\phi$
does \underline{not} change $F^\phi$.
\end{minipage}

\bigskip

\begin{minipage}{\textwidth}\raggedright
\begin{wrapfigure}[7]{r}{0.5\textwidth}
\begin{tikzpicture}[x=0.25in,y=0.25in]
\begin{scope}[>=triangle 45,shorten >=0.01in]
    \draw[black] (-1,0) -- (+1,0);
    \draw[black] (0,-1) -- (0,+1);

    \fill[red] (0,0) circle(0.1);

    \draw[red] (-0.577350269,-1) -- (2.5,4.330127018);

    \fill[red] (2.897777478,0.776457135) circle(0.1);
    \draw[red,->] (0,0) -- (2.897777478,0.776457135);
    \draw[black] (1.5,0.8) node{$v$};

    \draw[blue,->] (2.897777478,0.776457135) -- (3.863703305,-1.035276180);
    \draw[black] (3.8,-0.0) node{$w$};

    \fill[red] (3.863703305,-1.035276180) circle(0.1);
    \draw[brown,->] (0,0) -- (3.863703305,-1.035276180);
    \draw[black] (2.0,-1.2) node{$v+w$};

    \fill[red] (-0.776457135,2.897777478) circle(0.1);
    \draw[red,->] (0,0) -- (-0.776457135,2.897777478);
    \draw[black] (+0.4,+2.6) node{$F^\phi(v)$};

    \draw[blue,->] (-0.776457135,2.897777478) -- (-2.828427124,2.828427124);
    \draw[black] (-1.8,+3.5) node{$F^\phi(w)$};

    \fill[red] (-2.828427124,2.828427124) circle(0.1);
    \draw[brown,->] (0,0) -- (-2.828427124,2.828427124);
    \draw[black] (-3.0,+1.0) node{$F^\phi(v+w)$};

\end{scope}
\end{tikzpicture}
\end{wrapfigure}
A reflection preserves side-lengths and negates angles of a triangle.
Therefore, a reflection preserves vector addition, that is,
$F^\phi(v+w)=F^\phi(v)+F^\phi(w)$, and thus
satisfies Definition~\ref{LINEAR-TRANSFORMATION}
and is a linear transformation.
\end{minipage}

\vspace{0.5in}

A linear map $L$ that preserves vector lengths ($||L(v)||=||v||$)
is said to be \key{unitary}.
A unitary linear map $L$
also preserves the absolute values of angles between vectors,
because $L$ preserves the side-lengths of any triangle made of
vectors, and these determine the absolute values of the angles of
the triangle (but not the direction of these angles).  This means
that {\tt azm L(v)} must be either `{\tt {\rm constant} + azm v}'
or `{\tt {\rm constant} - azm v}'.  These two case are rotations
and reflections, respectively.

Now
$L$, being linear, is determined by $L(u_x)$ and $L(u_y)$, where
$u_x=(1,0)$ and $u_y=(0,1)$, and as $u_y$ is perpendicular to
$u_x$, $L(u_y)$ must be perpendicular to $L(u_x)$ since $L$ is unitary.

Putting all this together we have:
\begin{lemma}
For unitary $L=[\ell_x,\ell_y]$, $\ell_x$ and $\ell_y$ are
vectors of unit length, and $\ell_y$ is perpendicular to $\ell_u$.

If $\ell_y$ is $\ell_x$ rotated counter-clockwise
by 90 degrees, $L$ is a rotation, whereas if
$\ell_y$ is $\ell_x$ rotated clockwise
by 90 degrees, $L$ is a reflection.
\end{lemma}

If $L$ is a rotation, the angle of rotation is: \\
\centerline{$\phi = \mathrm{azm}~L(u_x) - \mathrm{azm}~u_x =
             \mathrm{azm}~L(u_x)$}
and we have: \begin{tabular}[t]{l}
             $L(u_x)=(\cos\phi,\sin\phi)$ \\
             $L(u_y)=(-\sin\phi,\cos\phi)$ \\
	     \end{tabular}

If $L$ is a reflection, the angle of the reflecting line is: \\
\centerline{$\phi = (1/2)*(\mathrm{azm}~L(u_x) + \mathrm{azm}~u_x)
                  = (1/2)*(\mathrm{azm}~L(u_x))$}
and we have: \begin{tabular}[t]{l}
             $L(u_x)=(\cos(2*\phi),\sin(2*\phi))$ \\
             $L(u_y)=(\sin(2*\phi),-\cos(2*\phi))$ \\
	     \end{tabular}

Both rotations and reflections preserve vector lengths
and change vector angles according to a linear formula.
Using the notation $R^\phi$ for rotation by angle $\phi$,
and $F^\phi$ for reflection about the line at angle $\phi$,
we get the following:
\begin{center}
$R^\phi*R^\omega=R^\omega*R^\phi=R^{\phi+\omega}$
~~because~~
    $(\mathrm{azm}~v + \omega) + \phi = \mathrm{azm}~v + (\phi+\omega)$ \\
$F^\phi*F^\omega = R^{2(\phi-\omega)}$
~~because~~
    $2\phi - (2\omega - \mathrm{azm}~v) = \mathrm{azm}~v + 2(\phi-\omega)$ \\
$R^\phi*F^\omega = F^\omega*R^{-\phi}$
~~because~~
    $(2\omega - \mathrm{azm}~v) + \phi =
      2\omega - (\mathrm{azm}~v + (-\phi))$
\end{center}
Note that:
\begin{center}
$R^\phi*R^\omega=R^{\omega+\phi}=R^\omega*R^\phi$ \\
$R^\phi$ and $R^\omega$ commute \\
$R^{-\phi}$ is the inverse of $R^\phi$ \\
$F^\phi*F^\phi= I$ (the identity) so  $F^\phi$ is its own inverse \\
$F^\omega*F^\phi$ is the inverse of $F^\phi*F^\omega$ \\
in general $F^\phi$ and $F^\omega$ do \underline{not} commute\\
\end{center}

\bigskip

\section{Rotations and Reflections Calculator}
Implement additions to the linear calculator for
the {\em operators} and {\em functions}:
\begin{center}
\begin{tabular}{l@{~~~~~}l@{~~~~~}l}
\multicolumn{2}{l}{Assume:} \\
        & {\tt p} is a scalar \\
	& {\tt v} is a vector \\
then: \\[1ex]
\tt v\WH p & returns {\tt w} such that {\tt ||w||=||v||} and
	     {\tt azm w = azm v + p}, \\
	   & {\tt v} rotated by {\tt p} degrees;
	     undefined if {\tt ||v|| = 0} \\
\tt v|p & returns {\tt w} such that {\tt ||w||=||v||} and
	  {\tt azm w = 2*p\,-\,azm v}, \\
	& {\tt v} reflected across the line with direction
	  {\tt p} degrees; \\
	& undefined if {\tt ||v|| = 0} \\
\tt \WH p & returns {\tt [$u_x$\WH p,$u_y$\WH p]}, \\
          & the rotation $R^p$ with angle $p$ degrees \\
\tt |p & returns {\tt [$u_x$|p,$u_y$|p]}, \\
       & the reflection $F^p$ across the line with direction $p$ degrees \\
\end{tabular}
\end{center}

\begin{center}
\begin{tabular}{rl}
Sample Input Files: & \file{00-XXXX-unitary-vec2d.in} \\
Sample Output Files: & \file{00-XXXX-unitary-vec2d.ftest} \\
Sample Run File: & \file{sample-unitary-vec2d.run} \\
Submit Run File: & \file{submit-unitary-vec2d.run} \\
\end{tabular}
\end{center}

\newpage

\section{Products}
There are two products of a pair of vectors that play a
very important role in 2D computational geometry:

\begin{definition}
The \key{scalar product} of two vectors \\
\centerline{{\tt v = ($v_x$,$v_y$)} and {\tt w = ($w_x$,$w_y$)}} \\
is \\
\centerline{\tt v*w = $v_x w_x + v_y w_y$} \\
The \key{cross product} (a.k.a., \key{wedge product}) of the two vectors is \\
\centerline{\tt v\WH w = $(-v_y)w_x + v_x w_y$}
\end{definition}

Note that {\tt ||v||$^2$ = v*v}.

If we denote the rotation counter-clockwise by 90 degrees by {\tt R}$^{90}$,
then \\
\centerline{\tt v\WH w = (-$v_y$,$v_x$)*w = R$^{90}$(v)*w}

Both the scalar and cross product are \key{bi-linear}.  That is,
if {\tt u}, {\tt v}, {\tt w} are vectors and {\tt s} is a scalar:
\begin{center}
\tt
(u+v)*w = u*w + v*w \\
u*(v+w) = u*v + u*w \\
(s*u)*w = s*(u*w) = u*(s*w) \\
(u+v)\WH w = u\WH w + v\WH w \\
u\WH (v+w) = u\WH v + u\WH w \\
(s*u)\WH w = s*(u\WH w) = u\WH (s*w)
\end{center}

The scalar product is symmetric ({\tt v*w = w*v})
while the cross product is anti-symmetric ({\tt v\WH w = -w\WH v}).

\begin{lemma}
For a unitary transform {\tt L}:
\begin{enumerate}
\item {\tt L(v)*L(w) = v*w} for all vectors {\tt v} and {\tt w}.
\item If {\tt L} is a rotation,
         {\tt L(v)\WH L(w) = v\WH w} for all vectors {\tt v} and {\tt w}; \\
      if {\tt L} is a reflection,
         {\tt L(v)\WH L(w) = - v\WH w} for all vectors {\tt v} and {\tt w}.
\end{enumerate}
\end{lemma}

\begin{indpar}{0.3in}
Proof: Since {\tt L} is unitary: \\
{\small \tt
\hspace*{0.05in}
       \begin{tabular}[t]{rcl}
       ||v+w||$^2$ & = & (v+w)*(v+w) = v*v + v*w + w*v + w*w \\
		   & = & ||v||$^2$ + 2*v*w + ||w||$^2${\rm ,} \\
       {\rm so} v*w & = & (1/2) \\
                    & * & ( ||v+w||$^2$ - ||v||$^2$ - ||w||$^2$ ){\rm ,} \\
       {\rm so} L(v)*L(w)
         & = & (1/2) \\
	 & * & (||L(v)+L(w)||$^2$-||L(v)||$^2$-||L(w)||$^2$) \\
         & = & (1/2)*( ||v+w||$^2$ - ||v||$^2$ - ||w||$^2$ ) \\
         & = & v*w
       \end{tabular}
} % \small \tt

If $L$ is a rotation, {\tt R$^{90}$*L=L*R$^{90}$} so \\
{\tt
\hspace*{0.1in}
       \begin{tabular}[t]{rcl}
       L(v)\WH L(w) & = & R$^{90}$(L(v))*L(w) = L(R$^{90}$(v))*L(w) \\
                    & = & R$^{90}$(v)*w = v\WH w \\
       \end{tabular}
} % \tt

If $L$ is a reflection, {\tt R$^{90}$*L=L*R$^{-90}$}
and {\tt R$^{-90}$ = - R$^{90}$} so \\
{\tt
\hspace*{0.1in}
       \begin{tabular}[t]{rcl}
       L(v)\WH L(w) & = & R$^{90}$(L(v))*L(w) = L(R$^{-90}$(v))*L(w) \\
                    & = & R$^{-90}$(v)*w = - R$^{90}$(v)*w = - v\WH w
       \end{tabular}
} % \tt
\end{indpar}

\bigskip

\begin{minipage}{\textwidth}\raggedright
\begin{wrapfigure}{r}{0.5\textwidth}
\begin{tikzpicture}[x=0.30in,y=0.30in]
\begin{scope}[>=triangle 45,shorten >=0.01in]
    \draw[black] (-1,0) -- (+5,0);
    \draw[black] (0,-1) -- (0,+3);
    \fill[red] (0,0) circle(0.1);

    \fill[blue] (4.330127018,2.5) circle(0.1);
    \draw[blue,->] (0,0) -- (4.330127018,2.5);
    \draw[black] (4.5,2.0) node{$v$};

    \fill[red] (2.0,3.464101615) circle(0.1);
    \draw[red,->] (0,0) -- (2.0,3.464101615);
    \draw[black] (0.6,+2.4) node{$||w||$};
    \draw[black] (2.0,+4.0) node{$w$};

    \draw[orange] (3.0,1.732050807) -- (2.0,3.464101615);
    \draw[black] (2.3,3.0) node[right]{$||w||*\sin \theta$};

    \draw[black] (3.4,0.7) node{$||w||*\cos \theta$};

    \draw[brown,>=latex,->] (1.5,0) arc(0:30:1.5);
    \draw[black] (1.0,+0.3) node{$\phi$};

    \draw[brown,>=latex,->] (1.299038105,0.75) arc(30:60:1.5);
    \draw[black] (1.3,+1.3) node{$\theta$};

\end{scope}
\end{tikzpicture}
\end{wrapfigure}
We can use the fact that $*$ and $\wh$ are invariant under
rotations to give a geometric characterization
of these two products.  Let $v$ and $w$ be two vectors, let
$\theta=\mathrm{azm}~w - \mathrm{azm}~v$ be the direction angle of $w$
relative to $v$, and let $\phi = \mathrm{azm}~v$ be the azimuth of $v$
(see the picture).
If we rotate both vectors by $R^{-\phi}$
we line $v$ up with the positive X-axis, while not changing $\theta$,
$||v||$, $||w||$, $v*w$, or $v\wh w$.  So after rotation we have
\hspace*{0.5in}
    \begin{tabular}{l@{~~~~~}l}
    $v=(||v||,0)$ &
    $w=(||w||\cos\theta,||w||\sin\theta)$ \\
    $v*w=||v||\times||w||\times\cos\theta$ &
    $v\wh w=||v||\times||w||\times\sin\theta$ \\
    \end{tabular}
\end{minipage}

From this we deduce two things.  First, \\
\hspace*{0.5in}
    \begin{tabular}{l@{~~~~~}l}
    $v*w=||v||\times||w||\times\cos\theta$ &
    $v\wh w=||v||\times||w||\times\sin\theta$ \\
    \end{tabular} \\
before rotation, as well as after rotation,
which gives a geometric characterization of the products.

Second,\hspace{0.5in}$||v||*R^{-\mathrm{azm}~v}*w=(v*w,v\wh w)$,
\\[1ex]
which gives us a quick way to change coordinate systems
by a rotation times scalar multiplication by $||v||$ so that
$v$ has coordinates $(||v||^2,0)$ in the new coordinate system.
Problems that might be hard to solve in the original
coordinate system can be easily solved in the new coordinate
system.  For example, the end of $w$ is to the left of the infinite directed
line extending $v$ if and only if $v\wh w>0$.  One can also solve
distance problems in the original coordinate system by solving them
in the new coordinate system while remembering that the new system distances
are $||v||$ times the original system distances.  If in addition
$||v||=1$, distances in the new system equal distances in the original
system.

\bigskip

\begin{minipage}{\textwidth}\raggedright
\begin{wrapfigure}{r}{0.37\textwidth}
\begin{tikzpicture}[x=0.30in,y=0.30in]
\begin{scope}[>=triangle 45,shorten >=0.01in]

    \fill[black] (0,0) circle(0.1);
    \draw[black] (0.0,-0.5) node{$p_1$};

    \fill[black] (2.0,3.464101615) circle(0.1);
    \draw[black] (0,0) -- (2.0,3.464101615);
    \draw[black] (2.0,+4.0) node{$p_2$};
    \draw[black] (-0.3,+2.0) node{$||p_2-p_1||$};

    \fill[black] (4.330127018,2.5) circle(0.1);
    \draw[black] (2.0,3.464101615) -- (4.330127018,2.5);
    \draw[black] (4.5,2.0) node{$p_3$};

    \draw[black] (4.330127018,2.5) -- (0,0);

    \draw[orange] (3.0,1.732050807) -- (2.0,3.464101615);
    \draw[black] (4.5,5.5) node[left]{$||p_2-p_1||*\sin \theta$};
    \draw[black,>=latex,->] (3.7,5.3) -- (2.5,2.598076);

    \draw[black] (3.4,0.7) node{$||p_3-p_1||$};

    \draw[brown,>=latex,->] (1.299038105,0.75) arc(30:60:1.5);
    \draw[black] (1.3,+1.3) node{$\theta$};

\end{scope}
\end{tikzpicture}
\end{wrapfigure}
Lastly, looking at the picture at the right, we see that:
\hspace*{0.2in}
    \begin{tabular}{r@{~=~}l}
    \multicolumn{2}{l}{area of triangle $p_1 p_2 p_3$} \\
    & $(1/2)*||p_2-p_1||*\sin\theta*||p_3-p_1||$ \\
    & $(1/2)*(p_3-p_1)\wh (p_2-p_1)$ \\
    & $-~(1/2)*(p_2-p_1)\wh (p_3-p_1)$ \\
    \end{tabular} \\
~\\
So we can use the cross product to compute triangle areas,
but its a bit tricky because what we get is a signed area.
The result is positive if
the angle $\theta$ measured from the first factor of $\wh $ to the
second factor of $\wh $ is in the range $[0,180]$, and negative if
$\theta$ is in the range $[-180,0]$.
\end{minipage}

\newpage

\section{Products Calculator}
Implement additions to the unitary calculator for
the following {\em operators} and {\em functions}:
\begin{center}
\begin{tabular}{l@{~~~~~}l@{~~~~~}l}
Assume: & {\tt v=$v$=}$(v_x,v_y)$ (a vector)
          ~~~ {\tt w=$w$=}$(w_x,w_y)$ (a vector) \\
	& $u_x=(1,0)$ and $u_y=(0,1)$ \\
	& {\tt p=}$p$, {\tt q=}$q$, {\tt r=}$r$ (vectors representing points) \\
then: \\[1ex]
\tt v*w & returns $v_x w_x + w_y w_y$,
          the scalar product of {\tt v} and {\tt w} \\
\tt v\WH w & returns $(-v_y)w_x+v_x w_y$,
           the cross product of {\tt v} and {\tt w} \\
\tt v:w & returns $||v||*R^{-\mathrm{azm}~v}*w = (v*w,v\wh w)$ \\
\tt <v> & returns $(1/||v|)*v$, the unit vector in the same direction as $v$ \\
\tt v!w & returns $R^{-\mathrm{azm}~v}*w = (<v>*w,<v>\wh w)$ \\
\tt v:  & returns {\tt [$v$:$u_x$,$v$:$u_y$]} ~~~ (so {\tt (v:)*w = v:w}) \\
\tt v!  & returns {\tt [$v$!$u_x$,$v$!$u_y$]} ~~~ (so {\tt (v!)*w = v!w}) \\
\tt area~pqr & returns $0.5*(r-p)\wh (q-p)$, the area of triangle $pqr$, \\
             & with positive sign if $pqr$ clockwise, \\
	     & and negative sign if counter-clockwise \\
\end{tabular}
\end{center}

If {\tt ||v|| = 0} then {\tt <v>} and {\tt v!w} will produce coordinates such as
{\tt inf} (plus infinity), {\tt -inf} (minus infinity),
and {\tt nan} (not a number; i.e., result could not be computed).

\begin{center}
\begin{tabular}{rl}
Sample Input Files: & \file{00-XXXX-product-vec2d.in} \\
Sample Output Files: & \file{00-XXXX-product-vec2d.ftest} \\
Sample Run File: & \file{sample-product-vec2d.run} \\
Submit Run File: & \file{submit-product-vec2d.run} \\
\end{tabular}
\end{center}

\newpage

\section{Line and Point}\label{LINE-AND-POINT}
In this section we investigate the following questions:
\begin{enumerate}
\item Is a point on, to the left of, or to the right of
an infinite directed line?  What is the distance from the
point to the line and where is the closest point that is
on the line?
\item What is the general position of a point relative
to a finite line segment?  What is the distance from the
point to the line segment?
\item What is the general position of a direction relative
to two other directions, where all three directions are
defined by directed lines passing through a common point?
\end{enumerate}

We begin with a line {\tt pq} from point {\tt p} to point {\tt q},
{\tt p$\neq$q}.
We may take this line to be either infinite, or to be a finite
line segment with ends {\tt p} and {\tt q}.  We may take the
line to be undirected, or to be directed from {\tt p} to {\tt q}.

We then consider a third point {\tt r} and ask about its relation
to {\tt pq}.

The answers to our questions will not be changed if we perform
a coordinate translation on all the points, so we begin by moving
{\tt p} to the origin {\tt (0,0)} using a translation by {\tt -p}.
Our points become:
\begin{center} \tt
p - p = (0,0) \\
q - p \\
r - p
\end{center}
Next we apply the rotation $R^{\tt -azm(q-p)}$
followed by multiplication by {\tt ||q-p||}.  This was computed
in the last section as the linear transform \\
\centerline{\tt (q-p): = ||q-p||*$R^{\tt -azm(q-p)}$}
This transformation preserves angles and multiplies distances by {\tt ||q-p||}.

If we apply {\tt (q-p):} after the translation {\tt -p}, we get:
\begin{center} \tt
P = (q-p):(p-p) = (0,0) \\
Q = (q-p):(q-p) = ( (q-p)*(q-p), 0 ) \\
R = (q-p):(r-p) = ( (q-p)*(r-p), (q-p)\WH(r-p) )
\end{center}
where we use the facts that {\tt p - p = (0,0)} and
{\tt (q-p)\WH(q-p) = 0}.

Next we define {\tt X} and {\tt Y} to be the coordinates of {\tt R}
so {\tt R = (X,Y)}, and {\tt L} to be the X coordinate of {\tt Q}
so {\tt Q = (L,0)}.

If\label{DISTANCE-OF-LINE-TO-POINT}
we want the distance from {\tt r} to the infinite line {\tt pq},
then this is the same as {\tt 1/||q-p||} times
the distance from {\tt R = (X,Y)} to the infinite
line {\tt PQ}, and the latter is the X-axis.  So the answer is \\
\centerline{\tt |Y|/||q-p|| = |(q-p)\WH(r-p)|/||q-p||}

Next we want to find the point {\tt t} on the infinite line {\tt pq}
that is closest to {\tt r}.  We will represent {\tt t} as {\tt t = p + s*(q-p)}
for the appropriate scalar {\tt s}.  Then {\tt t-p} is the closest point to
{\tt r-p} on the infinite line from {\tt (p-p)} to {\tt (q-p)}
and if we apply the
linear transformation {\tt (q-p):~= ||q-p||*$R^{\tt -azm (q-p)}$},
we get that {\tt T = (q-p):(t-p)} is the closest point to {\tt R} on the
line {\tt PQ}, since rotations preserve distances and multiplication
of all coordinates by {\tt ||q-p||} preserves the notion of `closest'.
But the closest point to {\tt R = (X,Y)} on {\tt PQ = {\rm the X-axis}}
is {\tt (X,0)}, so {\tt T = (X,0)}.
And as {\tt (q-p):} is a linear transformation and {\tt t-p = s*(q-p)},
then {\tt T = s*(Q-P) = s*Q}~~(since {\tt P = (0,0)}).

\hspace*{0.3in}\begin{tabular}{rl}
so	& \tt T = (X,0) = s*Q = (s*L,0) \\
so	& \tt s = X/L \\
therefore     & \tt t = p + (X/L)*(q-p) \\
or	& \tt t = p + ((q-p)*(r-p)/(q-p)*(q-p)) * (q-p) \\
\end{tabular}

Note that if {\tt p}, {\tt q}, and {\tt r} have rational coordinates,
then {\tt t} has rational\label{CLOSEST-IS-RATIONAL},
and \underline{not} irrational,
coordinates.  However the denominator may be large.  If
the input coordinates have at most {\tt d} decimal places,
their denominator is at most $10^d$, and the denominator of {\tt t}
may be as large as \\
\centerline{\tt 10$^{\tt d}$*({\rm numerator of} L)}
where we use the fact that the denominators of {\tt X} and {\tt L}
which are $10^{2d}$ cancel each other out in {\tt X/L} so \\
\centerline{\tt X/L = ({\rm numerator of} X)/({\rm numerator of} L)}

\medskip

\begin{minipage}{\textwidth}\raggedright
\begin{wrapfigure}{r}{0.53\textwidth}
\begin{tikzpicture}[x=0.25in,y=0.25in]
\begin{scope}[>=triangle 45,shorten >=0.01in]

    \draw[black] (-1,0) -- (+9,0);
    \draw[black] (0,-1) -- (0,+3);
    \fill[red] (0,0) circle(0.1);
    \fill[red] (6.0,0) circle(0.1);
    \draw[brown] (6.0,-1) -- (6.0,+3);
    \draw[black] (0.0,-0.5) node[right]{\small \tt P=(0,0)};
    \draw[black] (6.0,-0.5) node[right]{\small \tt Q=(L,0)};
    \draw[black] (0.0,+1.0) node[left]{\small \tt X<0};
    \draw[black] (+6.0,+1.0) node[right]{\small \tt X>L};
    \draw[black] (+3.0,+2.0) node{\small \tt 0<=X<=L};
    \draw[black] (+8.0,+3.0) node{\small \tt R=(X,Y)};

\end{scope}
\end{tikzpicture}
\end{wrapfigure}
If we want the distance from {\tt r} to the \underline{finite} line {\tt pq},
then this is the same as {\tt 1/||q-p||} times
the distance from {\tt R} to the finite
line {\tt PQ}, and there are three cases.
If {\tt X<0}, the answer
is {\small \tt ||R-P||/||q-p||}.  If {\tt X>L},
the answer is {\small \tt ||R-Q||/||q-p||}.
Otherwise the answer is {\small \tt |Y|/||q-p||} as before.
See picture.
\end{minipage}

\medskip

Here we can simplify the above by using: \\
\begin{tabular}{@{~~}l}
\tt ||R-P||/||q-p|| = ||(q-p):(r-p)||/||q-p|| = ||r-p|| \\
\tt ||R-Q||/||q-p|| = ||(q-p):(r-q)||/||q-p|| = ||r-q|| \\
\end{tabular}

Now suppose we want a precise answer to the question: is {\tt r}
on the infinite or finite line {\tt pq}?  This is the same as the question:
is {\tt R} on the infinite or finite line {\tt PQ}?
If the coordinates of {\tt p}, {\tt q}, and {\tt r} have at
most {\tt d} decimal places, they are rational numbers with
denominator {\tt 10$^{\tt d}$}, and the products will be rational
numbers with denominator {\tt 10$^{\tt 2d}$}, so the coordinates of
{\tt R} and {\tt Q} will have denominator {\tt 10$^{\tt 2d}$}.
Or more precisely,
the computed coordinates will be close approximations to such rational numbers.
Therefore
\begin{enumerate}
\item {\tt r} is to the left of the infinite directed line {\tt pq}
if and only if {\tt 0<Y:(2d)}.
\item {\tt r} is to the right of the infinite directed line {\tt pq}
if and only if {\tt Y<0:(2d)}.
\item {\tt r} is on the infinite directed line {\tt pq}
if and only if {\tt Y==0:(2d)}.
\item {\tt r} is on the finite line {\tt pq} if and only if \\
\hspace*{0.3in}{\tt Y==0:(2d)},~~{\tt 0<=X:(2d)},~~and~~{\tt X<=L:(2d)}
\end{enumerate}

There is a difference in the treatment of {\tt X < 0} between
the problem of computing a distance from {\tt r} to the finite
line {\tt pq} and the problem of computing whether {\tt r} is
on the finite line {\tt pq}.  In both problems the line {\tt X = 0} is
a boundary between different cases.  In the distance case, the distance
is continuous across this boundary, so the computed value, the distance,
does not change much when {\tt (X,Y)} moves across the boundary.
In the other case, the computed value may change
from {\tt false} to {\tt true} as {\tt (X,0)} moves from {\tt X < 0}
to {\tt 0 <= X}, and thus the computed value is discontinuous.

In the continuous case we need not concern ourselves with how many
decimal places {\tt X} has, and we can use {\tt X < 0} instead of
{\tt X<0:(2d)}.  In the discontinuous case we cannot get a meaningful
{\tt true/false} answer unless we restrict the number of decimal
places in {\tt X}, though we could get a {\tt true/false/maybe}
answer if we knew more about the potential error in our value for
{\tt X}.

We will say that {\tt X = 0} is a \key{boundary} that is
\key{continuous} in the distance computation and \key{discontinuous}
in the {\tt on/not-on} computation.
For continuous boundaries we can use inequalities to decide which
side of the boundary we are on without worrying about accuracy.
For discontinuous boundaries we must worry about accuracy and
use tests like {\tt X<0:(2d)}.

\medskip

\begin{minipage}{\textwidth}\raggedright
\begin{wrapfigure}{r}{0.48\textwidth}
\begin{tikzpicture}[x=0.25in,y=0.25in]
\begin{scope}[>=triangle 45,shorten >=0.01in]

    \draw[black,->] (-4.5,+1.5) -- (+4.5,-1.5);
    \draw[black,->] (-3.5,-2.5) -- (+3.5,+2.5);
    \draw[red,->] (0,0) -- (+2.5,+1);
    \fill[red] (0,0) circle(0.1) + (0,-0.5) node[black]{\tt p};
    \fill[red] (4.5,-1.5) circle(0.1) + (0.5,0) node[black]{\tt q$_1$};
    \fill[red] (3.5,2.5) circle(0.1) + (0.5,0) node[black]{\tt q$_2$};
    \fill[red] (2.5,1) circle(0.1) + (0.5,0) node[black]{\tt q};
    \draw[black] (4,0) node{LR};
    \draw[black] (-0.5,2.5) node{LL};
    \draw[black] (-4,0) node{RL};
    \draw[black] (+0.5,-2.5) node{RR};

\end{scope}
\end{tikzpicture}
\end{wrapfigure}
Lastly, let us find the general position of a direction {\tt pq} relative
to two other directions, {\tt pq$_1$}  and {\tt pq$_2$}, where
{\tt q$_2$} is to the \underline{left} of the infinite directed line
{\tt pq$_1$} (see picture).
The infinite directed lines {\tt pq$_1$}  and {\tt pq$_2$} divide space into
four regions:
\begin{itemize}
\item[LR]
for points {\tt q} that are to the \underline{left} of {\tt pq$_1$}
and to the \underline{right} of {\tt pq$_2$};
\item[LL] for points {\tt q} that are to the \underline{left} of {\tt pq$_1$}
and to the \underline{left} of {\tt pq$_2$};
\item[RL] for points {\tt q} that are to the \underline{right} of {\tt pq$_1$}
and to the \underline{left} of {\tt pq$_2$};
\item[RR] for points {\tt q} that are to the \underline{right} of {\tt pq$_1$}
and to the \underline{right} of {\tt pq$_2$};
\end{itemize}
\end{minipage}

\medskip

Thus, for example,
if {\tt q} is in region LR, then when {\tt pq$_1$} is rotated
counter-clock\-wise
it will line up with {\tt pq} \underline{before} it lines up with
{\tt pq$_2$}.

Therefore we can use what we already know about finding which side
of an infinite line a point is on
to find the general position of a direction relative to
two other directions.

Note that if
{\tt pq$_2$} and {\tt pq$_1$} have the same direction,
LR and RL are empty, whereas if
{\tt pq$_2$} and {\tt pq$_1$} have opposite directions,
LL and RR are empty.

\newpage

\section{Line and Point Calculator}
Implement additions to the product calculator for
the following {\em operators} and {\em functions}:
\begin{center}
\begin{tabular}{l@{~~~~}l@{~~~~}l}
Assume: & {\tt p}, {\tt q}, {\tt r}, {\tt u}, {\tt v}
          are vectors representing points \\
	& {\tt D=}$D$ is an integer scalar, $-15\le D\le +15$ \\
then: \\[1ex]
\tt disti~pqr  & returns the distance from point {\tt r} to the
		\underline{infinite} line {\tt pq} \\
\tt distf~pqr  & returns the distance from point {\tt r} to the
		\underline{finite} line {\tt pq} \\
\tt closei~pqr  & returns the point {\tt t} on the \underline{infinite}
                  line {\tt pq} \\
		& that is closest to the point {\tt r} \\
\tt closef~pqr  & returns the point {\tt t} on the \underline{finite}
                  line {\tt pq} \\
		& that is closest to the point {\tt r} \\
\tt sidei~pqrD & returns {\tt +1} if {\tt r} is to the left of the
                \underline{infinite directed} line \\
	      & {\tt pq}, zero if it is on the line,
	        and -1 if it is to the right; \\
	      & if all coordinates are exact multiples of $10^{-D}$ \\
	      & and have absolute values $\le 10^{6-D}$ \\
\tt onf~pqrD & returns {\tt true} if and only if {\tt r} is on the
                \underline{finite} line {\tt pq}; \\
	      & if all coordinates are exact multiples of $10^{-D}$ \\
	      & and have absolute values $\le 10^{6-D}$ \\
\tt between~puvwD & returns {\tt true} if and only if the direction
                   {\tt pu} rotated \\
		 & counter-clockwise will line up with the direction \\
		 & {\tt pv} before it lines up with {\tt pw}; but returns
		   {\tt false} \\
		 & if any two of the three directions are identical; \\
	      & if all coordinates are exact multiples of $10^{-D}$ \\
	      & and have absolute values $\le 10^{6-D}$ \\
\end{tabular}
\end{center}

\begin{center}
\begin{tabular}{rl}
Sample Input Files: & \file{00-XXXX-point-vec2d.in} \\
Sample Output Files: & \file{00-XXXX-point-vec2d.ftest} \\
Sample Run File: & \file{sample-point-vec2d.run} \\
Submit Run File: & \file{submit-point-vec2d.run} \\
\end{tabular}
\end{center}

\newpage

\section{Line and Line}
In this section we investigate the following questions:
\begin{enumerate}
\item Do two infinite lines intersect, and if so where?
\item Does a finite line intersect an infinite line?
\item What is the distance between a finite line and an infinite line?
\item Do two finite lines intersect?
\item What is the distance between two finite lines?
\end{enumerate}

Let {\tt p} and {\tt q} be a pair of distinct points so that the set
of points on the infinite line {\tt pq} is: \\
\centerline{{\tt K} = \{ {\tt p + s*(q-p)}: {\tt s} any scalar \}}

Let {\tt m} and {\tt n} be another pair of distinct points so that the set
of points on the infinite line {\tt mn} is: \\
\centerline{{\tt K} = \{ {\tt m + t*(n-m)}: {\tt t} any scalar \}}

If these two infinite lines intersect, there must exist values for
{\tt s} and {\tt t} such that: \\
\centerline{{\tt p + s*(q-p) = m + t*(n-m)}}

The easy way to solve this is to take the cross product of both
sides with {\tt n-m}, because
{\tt (n-m)\WH(t*(n-m)) = t*((n-m)\WH(n-m)) = t*0 = 0}.
So we end up with: \\
\centerline{\tt s*(n-m)\WH(q-p) = (n-m)\WH(m-p)} \\
which we can solve for {\tt s}.  Unless {\tt (n-m)\WH(q-p) = 0}.

If {\tt (n-m)\WH(q-p) $\ne$ 0} then plugging {\tt s} into
{\tt p + s*(q-p)} and using \\
\centerline{\tt (n-m)\WH(q-p) - (n-m)\WH(m-p) = (n-m)\WH(q-m)}
we get that the intersection point is: \\
\centerline{\tt \begin{tabular}{c}
                [(n-m)\WH(q-m)]*p + [(n-m)\WH(m-p)]*q
		\\\hline
		(n-m)\WH(q-p) \\
		\end{tabular} }

What happens if {\tt (n-m)\WH(q-p) = 0}? \\
\hspace*{0.3in}\begin{tabular}{r@{~~}l}
Then    & \tt (n-m)\WH(q-p) = sin $\theta$*||n-m||*||q-p|| = 0 \\
where   & \tt ||n-m|| $\neq$ 0 $\neq$ ||q-p|| \\
and     & \tt $\theta$ = azm (q-p) - azm (n-m) \\
so      & \tt sin $\theta$ = 0 \\
so      & \tt $\theta$ = 0 or $\pm$180 \\
so      & {\tt nm} and {\tt pq} are parallel \\
        \end{tabular}

The converse is also true.  If {\tt mn} and {\tt pq} are parallel, \\
\hspace*{0.3in}\begin{tabular}{r@{~~}l}
then    & {\tt azm (n-m) = azm (q-p)} \\
or      & {\tt azm (n-m) = azm (q-p) $\pm$ 180} \\
and     & \tt ||n-m|| $\neq$ 0 $\neq$ ||q-p|| \\
so      & {\tt n-m = s*(q-p)} for some scalar {\tt s} \\
so      & \tt (n-m)\WH(q-p) = s*((q-p)\WH(q-p)) = 0 \\
        \end{tabular}

Of course, testing a product to see if it is {\tt 0} is subject to
rounding errors.  So we assume that the coordinates of {\tt m},
{\tt n}, {\tt p}, and {\tt q} have at most {\tt d} decimal places,
and therefore {\tt mn} is parallel to {\tt pq} if and only if
{\tt (n-m)\WH(q-p)==0:(2d)}.

If {\tt mn} and {\tt pq} are parallel infinite lines, they
may be disjoint or identical.  To test which, test whether
{\tt m} is on the infinite line {\tt pq}

The question of whether a finite line {\tt mn} intersects an
infinite line {\tt pq} can be answered by applying the translation
by {\tt -p} and then the linear transform {\tt (q-p):} to get:
\begin{center}
\begin{tabular}{rcl}
\tt m & $\longmapsto$ & \tt M = ( (q-p)*(m-p), (q-p)\WH(m-p) ) \\
\tt n & $\longmapsto$ & \tt N = ( (q-p)*(n-p), (q-p)\WH(n-p) ) \\
infinite {\tt pq} & $\longmapsto$ & X-axis \\
\end{tabular}
\end{center}
Then intersection occurs if and only if {\tt M.y} and {\tt N.y}
have opposite signs or one is zero, or more precisely:
\begin{theorem}
If the coordinates of {\tt m},
{\tt n}, {\tt p}, and {\tt q} have at most {\tt d} decimal places,
finite {\tt mn} intersects infinite {\tt pq} if and only if:
\begin{center}
{\tt M.y > 0:(2d)} and {\tt N.y < 0:(2d)} \\
or \\
{\tt M.y < 0:(2d)} and {\tt N.y > 0:(2d)} \\
or \\
{\tt M.y == 0:(2d)} \\
or \\
{\tt N.y == 0:(2d)}
\end{center}
where {\tt M.y == (q-p)\WH(m-p)} and {\tt N.y == (q-p)\WH(n-p)}.
\end{theorem}
The question of intersection has a discontinuous true/false
answer, so the boundaries {\tt M.y == 0} and {\tt N.y == 0}
are discontinuous for this question.  However, for the
question of the distance of finite {\tt mn} from infinite {\tt pq},
the boundaries are continuous, and remembering that distances in
the transformed coordinates are {\tt ||q-p||} times distances
in the original coordinates, we have:
\begin{theorem}
The distance between the finite line {\tt mn} and the infinite
line {\tt pq} is {\tt 0} (due to intersection) unless
\begin{center}
{\tt M.y > 0} and {\tt N.y > 0} \\
or \\
{\tt M.y < 0} and {\tt N.y < 0} \\
\end{center}
in which case it is \\
\centerline{\tt min (|M.y|, |N.y|) / ||q-p||}

where {\tt M.y == (q-p)\WH(m-p)} and {\tt N.y == (q-p)\WH(n-p)}.
\end{theorem}

The question of whether two \underline{finite} lines intersect is made
simpler by the following:
\begin{lemma}
Two finite lines do \underline{not} intersect
if either does not intersect the infinite extension of the other.

Otherwise the two finite lines intersect at a single point unless
the infinite extensions of the two finite lines are identical.
\end{lemma}
\begin{indpar}{0.3in}
Proof: The first statement is clear.

If the infinite extensions of the finite lines are parallel, either
the infinite extensions are identical, or neither finite line
intersects the infinite extension of the other line.
So if both the finite lines intersect the infinite extension of the other,
and if these infinite extensions are not identical, then the
infinite extensions are not parallel, so they must intersect at a
single point.  So each finite line must intersect the infinite extension
of the other line at a single point.

Then let the finite lines be $\ell_1$ and $\ell_2$ and let
$\ell_i$ intersect the infinite extension of the other finite line
at the point $r_i$.  So $r_1=r_2=$ the intersection of the infinite
extensions of both lines, and as $r_i$ is on $\ell_i$, this point is
on both finite lines.
\end{indpar}

We can check whether the infinite extensions of the {\tt mn} and {\tt pq}
are the same by checking whether {\tt m} and {\tt n} are both on
the infinite extension of {\tt pq}, or in other words, whether: \\
\centerline{{\tt (q-p)\WH(m-p)==0:(2d)} and {\tt 0==(q-p)\WH(n-p):(2d)}}

If the two infinite extensions of the two finite lines {\tt pq} and
{\tt mn} are the same
infinite line, we need a new approach.  We need to establish a coordinate
system on this infinite line.

If {\tt r} is a point on this infinite line then we can map
\begin{center}
{\tt r $\mapsto$ R = ( (q-p)*(r-p), (q-p)\WH(r-p) ) = (R.x,0)}
\end{center}
and use the map
\begin{center}
{\tt r $\mapsto$ R.x = (q-p)*(r-p)}
\end{center}
as coordinates on this line.  In this system of coordinates distances
are {\tt ||q-p||} times distances in the original system of coordinates.

In this coordinate system,
\begin{center}
\begin{tabular}{l@{~~~~~}l}
\tt P.x = (q-p)*(p-p) = 0 &
\tt Q.x = (q-p)*(q-p) > 0 \\
\tt M.x = (q-p)*(m-p) &
\tt N.x = (q-p)*(n-p) \\
\end{tabular}
\end{center}
We will switch m and n if necessary so that {\tt M.x < N.x}.
Then the two finite lines are {\tt pq} represented by the
interval {\tt [P.x,Q.x]} and {\tt mn} represented by the
interval {\tt [M.x,N.x]}.  Therefore {\tt pq} and {\tt mn}
\begin{center}
\begin{tabular}{l}
do \underline{not} intersect if {\tt N.x < P.x:(2d)} or {\tt Q.x < M.x:(2d)} \\
\underline{do} intersect
  if {\tt N.x $\ge$ P.x:(2d)} and {\tt Q.x $\ge$ M.x:(2d)} \\
\end{tabular}
\end{center}

Deciding whether or not {\tt pq} and {\tt mn} intersect is a discontinuous
problem.  However finding the length of the intersection under the
assumption that both lines have the same infinite extension is
a continuous problem.  The intersection of {\tt pq} and {\tt mn},
expressed using our line coordinates, is:
\begin{center}
\tt [P.x,Q.x]$\cap$[M.x,N.x] = [max(P.x,M.x),min(Q.x,N.x)]
\end{center}
so the length of the intersection is
\begin{center}
\begin{tabular}{c}
\tt min(Q.x,N.x) - max(P.x,M.x)
\\\hline
\tt ||q-p||
\end{tabular} if this is $\ge$ 0
\\[3ex]
or 0 otherwise
\end{center}

This length is continuous across the boundary
\begin{center}
\tt min(Q.x,N.x) = max(P.x,M.x)
\end{center}

Lastly we consider the problem of finding the distance between
the finite line {\tt mn} and the finite line {\tt pq}.  We assume:

\begin{theorem}
If {\tt mn} and {\tt pq} are finite lines, the function from pairs
of points
{\tt r$_{\tt mn}$} on {\tt mn} and
{\tt r$_{\tt pq}$} on {\tt pq}  to the distance
{\tt ||r$_{\tt mn}$ - r$_{\tt pq}$||} has a minimum.
\end{theorem}

We will \underline{not} give a proof of this,
which involves the mathematics of compact sets.

But we will use this theorem to prove:

\begin{theorem}
\label{FINITE-LINE-DISTANCE-THEOREM}
If either {\tt mn} and {\tt pq} are finite lines that do not intersect, or
{\tt mn} and {\tt pq} are finite lines whose infinite extensions are
identical, then
points {\tt r$_{\tt mn}$} on {\tt mn} and
{\tt r$_{\tt pq}$} on {\tt pq} may be chosen so that
{\tt ||r$_{\tt mn}$ - r$_{\tt pq}$||} is minimal and
one of the chosen points is an end-point of its finite line.

Therefore the distance from {\tt mn} to {\tt pq} is the
minimum of: \\
\hspace*{0.5in}\begin{tabular}{l}
the distance from {\tt m} to {\tt pq} \\
the distance from {\tt n} to {\tt pq} \\
the distance from {\tt p} to {\tt mn} \\
the distance from {\tt q} to {\tt mn} \\
\end{tabular}
\end{theorem}

\begin{indpar}{0.3in}
Proof: By the previous theorem, {\tt r$_{\tt mn}$} in {\tt mn} and
{\tt r$_{\tt pq}$} in {\tt pq} can be chosen so that
{\tt ||r$_{\tt mn}$ - r$_{\tt pq}$||} is minimal.

First assume that the infinite extensions of {\tt mn} and {\tt pq} are
\underline{not} identical, and therefore {\tt mn} and {\tt pq} do not
intersect.  Consider the infinite line $\ell$ through
{\tt r$_{\tt mn}$} and {\tt r$_{\tt pq}$}, and assume that
neither
{\tt r$_{\tt mn}$} or {\tt r$_{\tt pq}$} are endpoints.
Then $\ell$ may be translated to its left or right by
a small enough amount that the translation continues
to intersect both finite lines.  Let the translation
be $\ell'$ and its intersections with the finite lines be
{\tt r'$_{\tt mn}$} and {\tt r'$_{\tt pq}$}.
If {\tt mn} and {\tt pq} are not parallel, then
{\tt ||r'$_{\tt mn}$ - r'$_{\tt pq}$||} will increase
as $\ell$ is translated in one direction and decrease as
it is translated in the other direction, but a decrease
cannot happen by assumption of minimality of
{\tt ||r$_{\tt mn}$ - r$_{\tt pq}$||}, so by contradiction either
{\tt r$_{\tt mn}$} or {\tt r$_{\tt pq}$} must be an endpoint.

If on the other hand {\tt mn} and {\tt pq} are parallel,
{\tt ||r'$_{\tt mn}$ - r'$_{\tt pq}$||} will remain constant
for all translations of $\ell$, and $\ell$ can be translated
in either direction until it encounters an endpoint.

Second, assume that the infinite extensions of {\tt mn} and {\tt pq}
are identical ({\tt mn} and {\tt pq} may or may not intersect).
If {\tt ||r'$_{\tt mn}$ - r'$_{\tt pq}$|| > 0} and
either
{\tt r$_{\tt mn}$} or {\tt r$_{\tt pq}$} is not an endpoint, the one
that is not an endpoint can be translated right or left to decrease
{\tt ||r'$_{\tt mn}$ - r'$_{\tt pq}$||}, contradicting the minimality of
{\tt ||r'$_{\tt mn}$ - r'$_{\tt pq}$||}.  If on the other hand
{\tt ||r'$_{\tt mn}$ - r'$_{\tt pq}$|| = 0} and
{\tt r$_{\tt mn}$ = r$_{\tt pq}$} is not an endpoint, it can be
translated right or left until it becomes an endpoint.
\end{indpar}

The translation argument just given is an example of a
\key{perturbation argument}.  Perturbation arguments are common
in computational geometry.

Of course if the finite lines intersect the distance between
them is zero.

\begin{corollary}
If two finite lines {\tt mn} and {\tt pq} intersect, the distance
between them is {\tt 0}.  Otherwise the distance is the minimum of: \\
\hspace*{0.5in}\begin{tabular}{l}
the distance from {\tt m} to {\tt pq} \\
the distance from {\tt n} to {\tt pq} \\
the distance from {\tt p} to {\tt mn} \\
the distance from {\tt q} to {\tt mn} \\
\end{tabular}
\end{corollary}

This corollary gives an algorithm to compute the distance between
two finite lines as follows.  Let A be the answer to the question:
do the lines intersect?  Let D be the distance computed by the
corollary if A is false.  Then if A is true, return 0, else return D.

But now we have a difficulty: the algorithms we have developed
above for computing A are discontinuous and impose precision
requirements on the data.  What we want is a continuous algorithm
to compute A,
or more specifically, an algorithm that makes errors only if D = 0
to within computational accuracy.  Then if A is erroneously
false, D will be returned, which is the same value that would be
returned if A is true, to within computational accuracy.  And if
A is erroneously true, 0 would be returned, which is the same as
D to within computation accuracy.  Then
our distance algorithm will be continuous and \underline{not} impose
precision requirements on the data.

The following algorithm A has the require continuity property:

\begin{algorithm}\label{INTERSECTION-ALGORITHM}
Algorithm that returns true if finite lines {\tt mn} and {\tt pq}
intersect, and false otherwise.

Make the coordinate change:
\begin{center}
\begin{tabular}{rcl}
\tt m & $\longmapsto$ & \tt M = ( (q-p)*(m-p), (q-p)\WH(m-p) ) \\
\tt n & $\longmapsto$ & \tt N = ( (q-p)*(n-p), (q-p)\WH(n-p) ) \\
\tt p & $\longmapsto$ & \tt P = ( (q-p)*(p-p), (q-p)\WH(p-p) ) = (0,0) \\
\tt q & $\longmapsto$ & \tt Q = ( (q-p)*(q-p), (q-p)\WH(q-p) ) = (L,0) \\
      &               & for {\tt L = (q-p)*(q-p) > 0} \\
\end{tabular}
\end{center}

so infinite {\tt pq} $\longmapsto$ X-axis.

Intersect the finite line {\tt MN} with the region
\begin{center}
$S = [0,L]\times(-\infty,+\infty) =
    \{(x,y):0\leq x\leq L,-\infty < y < +\infty\}$
\end{center}

If the intersection is empty, return false.

Otherwise let {\tt M'} and {\tt N'} be the endpoints of the intersection
({\tt M' = M} and {\tt N' = N} are possible).
\begin{center}
\begin{tabular}{ll}
If & {\tt M'.y > 0} and {\tt N'.y > 0 } \\
or & {\tt M'.y < 0} and {\tt N'.y < 0 } \\
   & return false \\
else & return true \\
\end{tabular}
\end{center}

\end{algorithm}

We want to state the required continuity problem of
Algorithm~\ref{INTERSECTION-ALGORITHM} more precisely.
Let
\begin{center}
$R=\{(m,n,p,q): m\neq n, p\neq q\} \subset {\cal R}^8$ \\
$I=\{(m,n,p,q)\in R: MN \textrm{~intersects~} S\}$ \\
$T=\{(m,n,p,q)\in R:
     \textrm{Algorithm~\ref{INTERSECTION-ALGORITHM} returns true}\}$ \\
$B$ = boundary of $T$ in $R$ \\
$D$ be \begin{tabular}[t]{@{}l}
the minimum of: \\
the distance from {\tt m} to {\tt pq} \\
the distance from {\tt n} to {\tt pq} \\
the distance from {\tt p} to {\tt mn} \\
the distance from {\tt q} to {\tt mn} \\
\end{tabular}
\end{center}

Then we want to prove:
\begin{theorem}
$D = 0$ on $B$.
\end{theorem}

In the proof of this theorem we will use the following:
\begin{lemma}
If $b\in I$ then:
\begin{indpar}{0.5in}
{\tt M'($b$).y = 0} implies $D=0$ at $b$ \\
{\tt N'($b$).y = 0} implies $D=0$ at $b$
\end{indpar}
\end{lemma}

\begin{indpar}{0.3in}
Proof of Lemma:

Let {\tt M'.y = 0}, so {\tt M'} is on the line {\tt PQ}
and also on the line {\tt MN}.
The cases are:
\begin{indpar}{0.5in}
\begin{itemize}
\item[(a)] {\tt M' = M} so {\tt M} is on the line {\tt PQ} and $D=0$.
\item[(b)] {\tt M'.x = P.x} in which case {\tt M' = P}
(as {\tt M'.y = 0 = P.y}), so {\tt P} is on {\tt MN} and $D=0$.
\item[(c)] {\tt M'.x = Q.x} in which case {\tt M' = Q}
(as {\tt M'.y = 0 = Q.y}), so {\tt Q} is on {\tt MN} and $D=0$.
\end{itemize}
\end{indpar}
Similarly for {\tt N'.y = 0}.
\end{indpar}

\begin{indpar}{0.3in}
Proof of Theorem:

First note that since $R\setminus I$ and $R\setminus T$ are open,
$I$ and $T$ are closed.  In addition, {\tt M}, {\tt N}, {\tt P},
and {\tt Q} are continuous functions on $R$, and {\tt M'} and {\tt N'}
are continuous functions on $I$.

Let $b\in B$.  We need to show that $D=0$ at $b$.

Since $T$ is closed and $B$ is the boundary of $T$, $B\subset T$,
and $b\in T\subset I$.  Therefore {\tt M'($b$)} and {\tt N'($b$)}
exist and one of the following is true:
\begin{center}
\begin{tabular}{ll}
(a) & {\tt M'($b$).y = 0} (and therefore by the lemma $D=0$ at $b$) \\
(b) & {\tt N'($b$).y = 0} (and therefore by the lemma $D=0$ at $b$) \\
(c) & {\tt M'($b$).y > 0 > N'($b$).y} \\
(d) & {\tt M'($b$).y < 0 < N'($b$).y} \\
\end{tabular}
\end{center}
Note that {\tt M'($b$).y > 0 < N'($b$).y}
is impossible as $b\in T$,
and similarly {\tt M'($b$).y < 0 > N'($b$).y} is impossible.

So we need only prove that (c) and (d) are impossible or lead
to the conclusion that $D=0$ at $b$.

Since $b$ is on the boundary of $T$ in $R$,
there is an infinite sequence of points in $R\setminus T$
converging to $b$.  Using the fact that $R\setminus T$ is the
disjoint union of $R\setminus I$ and $I\setminus T$,
we divide the argument into two cases:

Case 1: There is a sequence of points in $I\setminus T$ that
converges to $b$.

Then there is a subsequence $s$ of points such that either:
\begin{center}
\begin{tabular}{ll}
(e) & if $b_s\in s$ then {\tt M'($b_s$).y > 0 < N'($b_s$).y}; \\
    & therefore by continuity
            {\tt M'($b$).y $\geq$ 0 $\leq$ N'($b$).y}; \\
(f) & if $b_s\in s$ then {\tt M'($b_s$).y < 0 > N'($b_s$).y}; \\
    & therefore by continuity
            {\tt M'($b$).y $\leq$ 0 $\geq$ N'($b$).y}; \\
\end{tabular}
\end{center}
But (e) is incompatible with both (c) and (d), and similarly (f) is
incompatible with both (c) and (d).

Case 2: There is a sequence of points in $R\setminus I$ that
converges to $b$.

Then there is a subsequence $s$ of points such that either:
\begin{center}
\begin{tabular}{ll}
(g) & if $b_s\in s$ then {\tt M($b_s$).x < P.x > N($b_s$).x}; \\
    & therefore by continuity
            {\tt M($b$).x $\leq$ P.x $\geq$ N($b$).x}; \\
    & therefore since $b\in T\subset I$,
            {\tt M'($b$).x = P.x = N'($b$).x}; \\
(h) & if $b_s\in s$ then {\tt M($b_s$).x > Q.x < N($b_s$).x} \\
    & therefore by continuity
            {\tt M($b$).x $\geq$ Q.x $\leq$ N($b$).x}; \\
    & therefore since $b\in T\subset I$,
            {\tt M'($b$).x = Q.x = N'($b$).x}; \\
\end{tabular}
\end{center}
If {\tt M($b$).x $\neq$ N($b$).x} then either (g) or (h) imply
{\tt M'($b$) = N'($b$)} which is incompatible with both (c) and (d).

Otherwise (g) implies that {\tt M($b$).x = N($b$).x = P($b$).x} and
either (c) or (d) then imply that {\tt P($b$)} is on the line
{\tt MN} at $b$ and hence $D=0$ at $b$.

Similarly (h) implies that {\tt M($b$).x = N($b$).x = Q($b$).x} and
either (c) or (d) then imply that {\tt Q($b$)} is on the line
{\tt MN} at $b$ and hence $D=0$ at $b$.

\end{indpar}

\newpage

\section{Line and Line Calculator}
Implement additions to the point and line calculator for
the following {\em operators} and {\em functions}:
\begin{center}
\begin{tabular}{l@{~~~~~}l}
Assume: & {\tt m}, {\tt n}, {\tt p}, {\tt q} are vectors representing points \\
	& {\tt D=}$D$ is an integer scalar, $-15\le D\le +15$ \\
then: \\[1ex]
\tt intersecti mnpqD & returns {\tt true} if the infinite lines {\tt mn} and
                     {\tt pq} \\
		   & intersect (including the case where the lines are \\
		   & identical) and {\tt false} otherwise; \\
	           & if all coordinates are exact multiples of $10^{-D}$ \\
		   & and have absolute values $\le 10^{6-D}$ \\
\tt intersectf mnpqD & ditto but for finite lines {\tt mn} and {\tt pq} \\
\tt overlapf mnpq & returns the length of the overlap of
                    finite lines {\tt mn} \\
                 & and {\tt pq} assuming the infinite extensions of these \\
		 & lines are identical \\
\tt commoni mnpq & returns the common point of infinite lines {\tt mn} and \\
                 & {\tt pq} assuming these lines are not parallel \\
\tt distf mnpq & returns the distance between finite lines {\tt mn} and
                  {\tt pq} \\
		& (may be zero if lines intersect) \\
\end{tabular}
\end{center}

\begin{center}
\begin{tabular}{rl}
Sample Input Files: & \file{00-XXXX-line-vec2d.in} \\
Sample Output Files: & \file{00-XXXX-line-vec2d.ftest} \\
Sample Run File: & \file{sample-line-vec2d.run} \\
Submit Run File: & \file{submit-line-vec2d.run} \\
\end{tabular}
\end{center}

\end{document}


\section{Grand Unification and Supersymmetry}
As we have seen before, the concept of unification plays a central role in the construction of appropriate phenomenological models of the MSSM. Here, we want to discuss the importance of SUSY in the context of the unification of the Standard Model gauge couplings, which was one of the first proposed examples of  phenomenological implications in the early days of SUSY research \cite{GeorgiGlashow1974}. \\
We define the Standard Model as the most general renormalizable field theory with gauge group
\begin{equation}
	\mathcal{G}_{\mathrm{SM}} = \operatorname{SU}(3) \times \operatorname{SU}(2) \times \operatorname{U}(1),
\end{equation}
with associated gauge couplings $\alpha_3$, $\alpha_2$ and $\alpha_1$, three generations of fermions and a scalar doublet \cite{Hebecker2020}. We know that the respective couplings are larger for the larger component of the gauge group, i.\,e.
\begin{equation}
	\alpha_{3}\left(m_{Z}\right)>\alpha_{2}\left(m_{Z}\right)>\alpha_{1}\left(m_{Z}\right).
\end{equation}
An interesting observation is, that the values of the running couplings come relatively close together at some high energy scale $\Lambda_{\mathrm{GUT}}\sim 10^{16}\ \mathrm{GeV}$ (cf. left plot in Figure \ref{fig:runnings}). To understand how this picture might look like in the MSSM\footnote{For our talk we restrict ourselves to a unification scheme with gauge group  $\mathcal{G}_{\mathrm{MSSM}} = \operatorname{SU}(5) \supset \operatorname{SU}(3)\times\operatorname{SU}(2)\times\operatorname{U}(1)$ as described in \cite{GeorgiGlashow1974}.}, we first  have a look at the value of the Higgs-higgsino mass parameter $\mu$.\\ In order to reproduce the correct values of the $W$ and $Z$ boson masses, in the Georgi-Glashow model \cite{GeorgiGlashow1974} we need values of $\mu^{2} \sim (100\ \mathrm{GeV})^{2}$ \cite{PeskinSchroeder1995}. The large discrepancy in the orders of magnitude of the relevant physical scales is often referred to as the gauge hierarchy problem. At this point SUSY may provide a way around: If SUSY breaking in the MSSM works such that the mass differences of the superpartners are large enough, one can reproduce the correct Higgs mass. These additional superpartners in the particle spectrum lead to interesting cancellations in the computation of the running of the gauge couplings via diagrams such as
\begin{figure}[H]
\centering
\includegraphics[scale = 0.9]{figures/running_diagrams}
\end{figure}
\noindent
where the sfermions are denoted by a tilde (and highlighted in red). For an example calculation of the MSSM effects in the running couplings we refer for example to the respective exercise in \cite{Hebecker2020}.  \newpage The explicit formulas for the beta functions are given by
\begin{equation}
	\beta_{g_i} = \frac{\dd}{\dd t}g_i = \frac{b_i}{16\pi^2} g_i^3 \quad \text{with} \quad (b_1,b_2,b_3) = \left\{\begin{array}{ll}{(\frac{41}{10}, -\frac{19}{6}, 7)} & {\text {in the SM} } \\ {(\frac{33}{5}, 1, -3)} & {\text {in the MSSM}} \end{array}\right.
\end{equation}
where $t = \log\frac{Q}{m_Z}$. For $\alpha_i = g_i^2/4\pi$ this yields
\begin{equation}
	\frac{\dd }{\dd t} \alpha_i^{-1} = -\frac{b_i}{2\pi}.
\end{equation}
As we see in the right plot in Figure \ref{fig:runnings} the unification of the gauge couplings at some high energy scale may be realized in the MSSM. In the end it remains a complicated fine tuning task\footnote{There has been a lot of work considering the qualitative assessment of fine-tuning in theoretical models. Probably the most commonly used measure of fine tuning is the Barbieri-Giudice measure characterized by $\Delta_i \equiv \abs{\frac{\partial \operatorname{ln} m_Z^2}{\partial \operatorname{ln} p_i}}$, where the $p_i$ are the MSSM parameters at the scale $M_X$ which are set by the fundamental SUSY breaking dynamics. The larger the value of $\Delta \equiv \operatorname{max} \Delta_i$ the more fine tuning is needed  \cite{PDG20182019, Hebecker2020}.}. \\
At this point we want to remark that even if this result might look very interesting, and was often referred to as one of the most promising advertisements for the realization of SUSY in nature, it is of course only an approximate result and the picture will already look a lot different at the next loop order.

\begin{figure}[t]
\hfill
	\begin{subfigure}
		\centering
	\includegraphics[scale = 0.55]{figures/dgut-1}
	\end{subfigure}
	\hfill
	\begin{subfigure}
		\centering
	\includegraphics[scale = 0.55]{figures/dgut-2}
	\hfill
	\end{subfigure}
\caption{Running of the (inverse) gauge couplings in the SM and the MSSM, plots inspired by \cite{Kazakov2000}.}
\label{fig:runnings}
\end{figure}