\documentclass[]{jocg}

\usepackage{amsmath,amsfonts}
\usepackage{amsthm}

\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{booktabs}
\usepackage{mathtools}
\usepackage[mathlines]{lineno}
\usepackage[]{graphicx}
\usepackage{algorithm}
\usepackage[noend]{algpseudocode}
\linenumbers

\setcounter{tocdepth}{1} % -- part,chapters,sections

\usepackage[
  backend=biber,
  style=nature,
  sorting=ynt
]{biblatex}
\addbibresource{main.bib}

\newcommand{\RR}{\mathbb{R}}
\newcommand{\PP}{\mathcal{P}}
\newcommand{\EE}{\mathcal{E}}
\newcommand{\set}[1]{\{#1\}}
\newcommand{\norm}[1]{\|#1\|}
\newcommand{\abs}[1]{|#1|}
\newcommand{\chordarc}{{s_{\textrm{arc}}}}
\DeclareMathOperator{\diam}{\mathrm{diam}}
\DeclareMathOperator{\conv}{\mathcal{CH}}

\newtheorem{proposition}{Proposition}[section]

\theoremstyle{definition}
\newtheorem{definition}[proposition]{Definition}

\theoremstyle{remark}
\newtheorem{remark}[proposition]{Remark}

\title{%
  \MakeUppercase{Measuring polygonal niceness}%
  \thanks{%
    This paper constitutes the completion of the final project for AMS 545
    ``Computational Geometry''.
  }
}

\author{%
  Sharmila~Duppala%
  \thanks{%
    \affil{Department of Computer Science},
    \email{sduppala@cs.stonybrook.edu}%
  }\, and
  David~Kraemer.%
  \thanks{%
    \affil{Department of Applied Mathematics},
    \email{david.kraemer@stonybrook.edu}%
  }
}

\begin{document}

\maketitle

\begin{abstract}
  The $\alpha$-fatness and chord-arc scores as measures of the ``niceness'' of
  polygons are developed and explored, with initial theoretical and empirical
  results.
\end{abstract}

\tableofcontents

\section{Introduction}

Convexity is from many perspectives the ``gold standard'' of niceness for planar
subsets, because it excludes at once large classes of pathological sets
altogether. Yet for establishing a quantitative measure of niceness that matches
with intuitive or legal understandings, convexity is both too restrictive and too
general. The relevant consideration at present revolves around drawing electoral
districts. The immense political consequences of favorable (or unfavorable)
maps has resulted in the development of creative classes of polygonal regions
utilized for this purpose. There exists a strong civic prerogative for providing
quantitative measures of niceness. In a concurrent opinion in the 2004 suit
\textit{Vieth v. Jubelirer} decided by the U.S. Supreme Court, Justice Anthony
Kennedy writes
\begin{quote}
  Because, in the case before us, we have no standard by which to measure the
  burden appellants claim has been imposed on their representational rights,
  appellants cannot establish that the alleged political classifications burden
  those same rights.  Failing to show that the alleged classifications are
  unrelated to the aims of apportionment, appellants’ evidence at best
  demonstrates only that the legislature adopted political classifications. That
  describes no constitutional flaw, at least under the governing Fourteenth
  Amendment standard. \cite{2004vieth}
\end{quote}
Ought convexity be considered as such a standard? In practice, convexity is too
restrictive (e.g., for coastal or river borders) and too general (e.g., a tiny
vertical strip) for this purpose.

The aim of this paper is to propose several alternative measures to determine
the niceness of polygonal regions in a quantitatively rigorous way. We introduce
two classes of measures, the $\alpha$-score and the chord-$f$ scores, develop
some of their basic properties, and show how they perform on simulated data. The
$\alpha$-fatness quantifies how much a given polygon resembles a ball (with
respect to some norm). When $f$ measures the perimeter of a polygon, the
chord-$f$ score quantifies the extent to which ``local nonconvexity'' affects
the distribution of the total boundary. Both measures generally reward convex
polygons, but punish certain convex ``offenders.'' Of course, there exist
nonconvex polygons who score well on both measures as well.

This paper proceeds as follows. Section 2 provides a theoretical overview for
the $\alpha$-fatness and chord-$f$ scores and gives preliminary results on
simple examples. Section 3 outlines the algorithms used to perform
discretizations and compute the $\alpha$-fatness and chord-$f$ scores. Section 4
gives the results of numerical simulations for these measures on randomly
generated ``typical'' polygons and provides data about the success of
discretization. Section 5 includes a discussion of the main results of the paper
and its implications for the electoral districting process.

Source code for this project can be found at
\url{https://github.com/DavidNKraemer/polygonal-niceness}. Documentation, cruft
removal, and user interface improvements are presently evolving.

\section{Theoretical background}

The area of a subset $S \subseteq \RR^2$ of the plane is denoted by
$\lambda(S)$. We will denote the boundary of $S$ by $\partial S$. For two points
$x,y \in \RR^2$, the closed line segment with endpoints in $x$ and $y$ is
denoted $[x,y]$. For $p \in [1, \infty]$, we define the $p$-ball as $B_{p}(x,
\varepsilon) = \set{y \in \RR^2 : \norm{x-y}_p \leq \varepsilon}$ and we will
only be interested in the closed case. Unless otherwise stated, we shall operate
in the Euclidean world with $p = 2$. Throughout we shall assume that $P
\subseteq \RR^2$ is a simple bounded closed polygon. The class of such polygons
is given by $\PP$. Its perimeter is denoted by $\abs{\partial P}$.

\subsection{The $\alpha$-fatness score}

One approach to measuring the relative ``fatness'' of a polygon seeks to
identify regions of the shape which behave highly unlike balls.

\begin{definition}
  The $\alpha$-fatness score of a polygon $P$ is given by
  \begin{equation*}
    \alpha(P) = \inf\set{\frac{\lambda[P \cap B(x,
    \varepsilon)]}{\lambda[B(x,\varepsilon)]} : \varepsilon > 0, x \in P}
  \end{equation*}
  where we impose that the ball $B(x,\varepsilon)$
  does not contain $P$.
  \label{def:alpha}
\end{definition}

The constraint that $P \not\subseteq B(x,\varepsilon)$ ensures definiteness:
otherwise, let $\varepsilon \to \infty$ and the ratio $\frac{\lambda[P \cap B(x,
\varepsilon)]}{\lambda[B(x, \varepsilon)]}$ always approaches $0$. An intuition
for $\alpha(P)$ emerges from considering how it behaves on balls.

\begin{proposition}
  For any $P$, $\alpha(P) \leq \frac{1}{4}$, and if $P = B(x_0, r)$
  then we have equality.
  \label{prop:alpha}
\end{proposition}

\begin{proof}
  To show that $\alpha(P) \leq \frac{1}{4}$, it suffices to show only for convex
  $P$, because $P \subseteq \conv(P)$ implies $\lambda[P \cap B(x, \varepsilon)]
  \leq \lambda[\conv(P) \cap B(x, \varepsilon)]$. Let $d = \diam (P)$ and fix
  $x,y \in \partial P$ such that $\abs{[x,y]} = d$. Assume without loss of
  generality that $x$ lies above $y$, and consider the ball $B(x, d)$. Then $P$
  does not meet the upper disk of $B(x,d)$, for otherwise we could choose $z \in
  P$ in the upper disk of $B(x,d)$ which forms a chord of $P$ longer than $d$.
  A similar argument shows that $P$ cannot occupy more than half of the lower
  disk of $B(x,d)$. Hence
  \begin{equation*}
    \alpha(P) \leq \frac{\lambda[P \cap B(x,d)]}{\lambda[B(x,d)]} \leq
    \frac{1}{4},
  \end{equation*}
  as needed.

  The fact that $\alpha(B(x_0, r)) = \frac{1}{4}$ relies on a neat
  result \cite{10.2307/30044198} that shows that the $L_p$
  ellipsoid $\EE$ with radii $a, b$ has area
  \begin{equation*}
    \lambda(\EE) = a b \cdot 4
    \frac{\Gamma(1+\frac{1}{p})^2}{\Gamma(1+\frac{n}{p})}.
  \end{equation*}
  In our case, $\alpha(B(x_0, r))$ is achieved at a ball on a ``corner'' point
  with radius $2r$.
\end{proof}

Hence, the $\alpha$-score is greater for polygons which exhibit ``niceness''
characteristics. It is not affected tremendously by local nonconvexity in $P$ so
long as $P$ ``snugly fits'' into a ball shape, which is a global property.

\subsection{The chord-$f$ score}

A different class of ``fatness'' measures arises through partitioning $P$ into
two (interior disjoint) polygons $P = P' \cup P''$ via chords. A chord is a pair
$x,y \in \partial P$ such that the segment $[x,y]$ is contained in the interior
of $P$ except at the endpoints $x$ and $y$. Such a chord defines a partition of
$P = P' \cup P''$ by orientation, so that $\partial P'$ is the arc from $x$ to
$y$ together with $[x,y]$ and that $\partial P''$ is the arc from $y$ to $x$
together with $[x,y]$.

\begin{definition}
  Let $f : \mathcal{P} \to \RR$. For a given $P \in \mathcal{P}$, its
  \emph{chord-$f$ score} is given by
  \begin{equation*}
    s_f (P) = \inf \set{\max(f(P'), f(P'')) : x, y \in \partial P}
  \end{equation*}
  where the chord $[x,y]$ partitions $P = P' \cup P''$.
  \label{def:chord-f}
\end{definition}

The intuition for $f$ is some global measure of ``cost'' associated with respect
to $P$. For example, if $f(P) = \abs{\partial P}$, then $s_f$ identifies the
partition (or limiting sequence of partitions) which minimizes the maximum
subpolygon perimeter. Indeed, measures such as perimeter or area are the typical
choices of $f$, but any suitable property of $P$  may be employed.

The chord-$f$ score can be understood relatively simply in the context of a
minimax game. Max, given a polygon with a chord partitioning it, always chooses
the subpolygon associated with a greater $f$ (i.e., the worst cost of the
partition). Min, who plays first, tries to find a chord with the least-bad worst
cost with respect to $f$.

The member of this class of scores under this present investigation is
$\chordarc$, the so-called \emph{chord-arc} score. It is important to note that
the length of the chord $[x,y]$ which partitions $P$ is included in the
estimation of $\chordarc$. One implication of this is that the chord-arc score
need not be bounded above by $\frac{\abs{\partial P}}{2}$.  We have several
facts about $\chordarc$ which develop further intuition for the score.
\begin{proposition}
  \begin{enumerate}
    \item Let $R$ be a rectangle with height $h$ and length $\ell$. Assume that
      $h \leq \ell$. Then $\chordarc(R) = 2h + \ell$.
    \item Let $P$ be convex with perimeter $\abs{\partial P} = w$. Then
      $\chordarc(P) \leq \frac{w}{2} + \diam (P)$.
    \item Let $C$ be a circle with ``perimeter'' $2\pi r$. Then $\chordarc(C) =
      (\pi + 2)r$.
  \end{enumerate}
  \label{rem:chordarc}
\end{proposition}

\begin{proof}
  \begin{enumerate}
    \item That the optimal partition bisects $R$ is readily apparent,
      for this minimizes the maximum perimeter length of either sub-rectangle.
      A case analysis confirms that the preferred strategy for Min is to choose
      a chord along the smaller dimension (i.e., $h$) to bisect $R$, and in this
      case the maximum arc length is $2h + 2\left( \frac{\ell}{2} \right) = 2h +
      \ell$, as needed.
    \item For $P$ convex, a perimeter-bisecting chord, whose length is at most
      $\diam(P)$, always exists.
    \item This follows from part 2 by noticing that the length of \emph{any}
      perimeter-bisecting chord is $\diam(C) = 2r$. \qedhere
  \end{enumerate}
\end{proof}

\section{Overview of empirical design}

In principal computing the $\alpha$-fatness and chord-$f$ scores relies on sweeping
the continuum of points of $P$ and evaluating the aforementioned measurements.
To estimate this process in practice, we employ the following discretizing
scheme. Let $P$ be determined by the vertices $[v_1, \dots, v_n]$ given in
counterclockwise order. Then, given $\delta > 0$, loop through the vertices of
$P$, checking if $\norm{v_{i+1} - v_i} > \delta$. In the case where this holds,
we insert $v_i' = \frac{v_i + v_{i+1}}{2}$ after $v_i$ into the polygon and
resume the loop. This ensures that for any two adjacent vertices $v_{i}$ and
$v_{i+1}$ in the representation of $P$ we have $\norm{v_{i+1} - v_i} \leq
\delta$. As $\delta \to 0$ this estimates $\partial P$ more exactly. All
computations are done with respect to the $L_{\infty}$ norm. The implementation
of this procedure is given in Algorithm \ref{alg:delta}.

Depending on the relative coordinates of the vertex set compared to $\delta$,
the worst-case runtime of refinement varies. In the case where the maximum
distance is $\delta K$, the refinement adds $O(\lg^2 K)$ vertices between the
two coordinates. The overall runtime is $O(n \lg^2 K)$ and the total quantity of
vertices after refinement is $O(n + n\lg^2 K)$.

%% Pseudocode for the delta refinement

\begin{algorithm}[h]
  \begin{algorithmic}[1]
    \Procedure{RefineBy}{$P,\delta$}
    \State{$P = [v_1, v_2, v_3, \dots, v_n]$};
    \State{$v = v_1$}
    \While {$\textit{next}(v) \ne v_1$}
    \If {$\norm{\textit{next}(v) - v}_2 > \delta$}
      \State{\textrm{Insert $\textit{midpoint}(v, \textit{next}(v))$ into $P$ after $v$}}
      \Comment{Now $\textit{next}(v)$ is the midpoint}
    \EndIf
    \EndWhile
    \EndProcedure
  \end{algorithmic}
  \caption{%
    The procedure used to refine a given polygon $P$ by a specified $\delta >
    0$. This modifies the existing $P$ to satisfy the regularity condition
    that $\norm{v_{i+1} - v_i} \leq \delta$ for each adjacent vertex pair
    $v_{i+1}, v_i$ on the discretized boundary $\partial P$.  }
  \label{alg:delta}
\end{algorithm}

Given a $\delta$-refined polygon $P$, the computation of $\alpha(P)$ is
relatively straightforward, with the simplification that points $x$ on which the
ratio is computed lie on $\partial P$. The computation steps through $[v_1,
\dots, v_n]$ and for each $v_i$ the radius $\varepsilon$ of the
minimum-enclosing $\infty$-ball centered at $v_i$ is computed. Then for
$\varepsilon_k = \frac{k}{100} \varepsilon$, $k = 1, \dots, 100$, the ratio
\begin{equation*}
  \frac{\lambda[P \cap B_{\infty}(v_i, \varepsilon_k)]}{B_{\infty}(v_i,
  \varepsilon_k)}
\end{equation*}
is computed and the smallest such ratio is kept. The minimum over all $v_i$ is
given as $\alpha(P)$. The implementation of the $\alpha$ score is given in
Algorithm \ref{alg:alpha}. Though we use a sweep from $k = 1, \dots, 100$, any
suitable range may be selected as an alternative. Unfortunately, there is no
analogous ``bisection'' technique for determining the minimizing $k$ because
this ratio need not be monotonic. Since $P$ need not be convex, the intersection
$P \cap B_{\infty}(v, \varepsilon_k)$ requires $O(n \log n)$ steps. For $n$
vertices, the runtime performance is $O(n^2 \log n)$.

%% Pseudocode for the alpha score

\begin{algorithm}[h]
  \begin{algorithmic}[1]
    \Function{$\alpha$Score}{$P$}
    \State{$P = [v_1, v_2, v_3, \dots, v_n]$};
    \State{$\textrm{min} = \infty$}
    \For {$v \in P$}
    \State{$\varepsilon = \textrm{radius of minimum enclosing ball of $P$ at
    $v$}$}
    \For {$k = 1, 2, \dots, 100$} \Comment{$100$ is arbitrary}
    \State{$\varepsilon_k = \frac{k}{100} \varepsilon$}
    \State{$\textrm{area} = \frac{\lambda[P \cap B_{\infty}(v, \varepsilon_k)]}{B_{\infty}(v, \varepsilon_k)}$}
    \If {$\textrm{min} > \textrm{area}$}
    \State{$\textrm{min} = \textrm{area}$}
    \EndIf
    \EndFor
    \EndFor
    \State{\Return{\textrm{min}}}
    \EndFunction
  \end{algorithmic}
  \caption{%
    The $\alpha$-fatness function.  }
  \label{alg:alpha}
\end{algorithm}

Similarly, given a $\delta$-refined polygon $P$, the chord-$f$ score is computed
by sweeping all possible chords of $P$. For each point $v_i, v_j \in \partial P$
with $i < j$, if $[v_i, v_j]$ is indeed a valid chord of $P$, the partition $P =
P' \cup P''$ is computed and the maximum of $f(P')$ and $f(P'')$ is kept. The
minimum such value is given as $s_f(P)$. The implementation of the chord-$f$
score is given in Algorithm \ref{alg:chordf}. For $n$ vertices, $O(n^2)$
potential chords are computed. To determine if a pair of vertices is a chord
takes $O(n)$ time, which leads to an overall runtime performance of $O(n^3)$.

%% Pseudocode for the chord f score

\begin{algorithm}[h]
  \begin{algorithmic}[1]
    \Function{ChordScore}{P,f}
    \State{$P = [v_1, v_2, v_3, \dots, v_n]$};
    \For {$v \in P$}
    \For {$w \in [\textit{next}(v), \dots, v_n]$}
    \If {$[v,w]$ is a chord of $P$}
      \State{Partition $P = P' \cup P''$ by $[v,w]$}
      \State{$\textrm{submax} = \textit{max}(f(P'), f(P''))$}
      \If {$\textrm{min} > \textrm{submax}$}
        \State{$\textrm{min} = \textrm{submax}$}
      \EndIf
    \EndIf
    \EndFor
    \EndFor
    \State{\Return{\textrm{min}}}
    \EndFunction
  \end{algorithmic}
  \caption{%
    The chord-$f$ function.   }
  \label{alg:chordf}
\end{algorithm}

All of these algorithms are implemented in CGAL \cite{cgal:eb-18a} with the
extensive use of the 2D Polygon library \cite{cgal:gw-p2-18a}. For our data
generation, we make the minor modification that measured ${\chordarc}$ is the
ratio of the actual $\chordarc$ score with the perimeter of the overall polygon.
This changes the interpretation of some of the theoretical results from the
previous section but allows for easier interpretation of the data.

\section{Empirical results}

We evaluate our measurements on randomly generated polygons with vertices in the
unit square $[0,1] \times [0,1]$. We consider collections of such polygons of
10, 50, and 100 vertices. In Figure \ref{fig:delta-alpha} and Figure
\ref{fig:delta-arc}, we measure the effect on
polygons of 10 vertices of sweeping $\delta$ between $0.05$ and $1$ on the
resulting measurements. Figure \ref{fig:alph-inft-10} shows a comparison of
$\alpha$-fatness and relative ${\chordarc}_{\infty}$ scores for polygons on 10
vertices.  Figure \ref{fig:alph-one-50} shows a comparison of $\alpha$-fatness
and relative ${\chordarc}_1$ scores for polygons on 50 vertices. Figure
\ref{fig:alph-inft-100} shows a comparison of $\alpha$-fatness and relative
${\chordarc}_{\infty}$ scores for polygons on 100 vertices.

Our theoretical results seem to be confirmed in that ``ball''-like polygons get
the highest $\alpha$-scores, and it seems that polygons with fewer
``nonconvexities'' score better on the relative ${\chordarc}_{\infty}$ measure. We
observe an overall decline in the relative $\chordarc$ scores as the number of
vertices of the polygons increases. This is attributed to the corresponding
increase in the size of the underlying perimeters of each $P$. The observation
is not shared with the $\alpha$ score, but this can be understood as a sort of
``coastline'' phenomenon, in which polygonal perimeters increase without limit
while the areas converge.

\begin{figure}[t]
  \centering
  \begin{tabular}{lrrrrrrrrrr}
    \toprule
    $\delta$ & $P_1$ & $P_2$ & $P_3$ & $P_4$ & $P_5$ & $P_6$ & $P_7$ & $P_8$ & $P_9$ & $P_{10}$ \\
    \midrule
    0.05 &  0.23 &  0.21 &  0.11 &  0.039 &  0.15 &  0.038 & 0.12 &  0.10 &  0.12 &  0.13 \\
    0.15 &  0.23 &  0.21 &  0.11 &  0.039 &  0.15 &  0.038 & 0.12 &  0.10 &  0.12 &  0.13 \\
    0.26 &  0.23 &  0.21 &  0.11 &  0.039 &  0.15 &  0.038 & 0.12 &  0.10 &  0.12 &  0.13 \\
    0.36 &  0.23 &  0.21 &  0.11 &  0.039 &  0.15 &  0.038 & 0.12 &  0.10 &  0.12 &  0.13 \\
    0.47 &  0.23 &  0.21 &  0.11 &  0.039 &  0.15 &  0.038 & 0.12 &  0.10 &  0.12 &  0.13 \\
    0.57 &  0.23 &  0.21 &  0.11 &  0.039 &  0.15 &  0.038 & 0.12 &  0.10 &  0.12 &  0.13 \\
    0.68 &  0.23 &  0.21 &  0.11 &  0.039 &  0.15 &  0.038 & 0.12 &  0.10 &  0.12 &  0.13 \\
    0.78 &  0.23 &  0.21 &  0.11 &  0.039 &  0.15 &  0.038 & 0.12 &  0.10 &  0.12 &  0.13 \\
    0.89 &  0.23 &  0.21 &  0.11 &  0.039 &  0.15 &  0.038 & 0.12 &  0.10 &  0.12 &  0.13 \\
    1    &  0.23 &  0.21 &  0.11 &  0.039 &  0.15 &  0.038 & 0.12 &  0.10 &  0.12 &  0.13 \\
    \bottomrule
  \end{tabular}
  \caption{%
    Effect of sweeping $\delta$ on measurements of $\alpha$-score on
    10 randomly generated polygons with 10 vertices in $[0,1]^2$.
    Unsurprisingly, the refinement of the different polygons has no effect on
    the $\alpha$-fatness score, since it introduces no additional area to the
    polygon and since the ``corners'' are already present.
  }
  \label{fig:delta-alpha}
\end{figure}

\begin{figure}[t]
  \centering
  \begin{tabular}{lrrrrrrrrrr}
    \toprule
    $\delta$ & $P_1$ & $P_2$ & $P_3$ & $P_4$ & $P_5$ & $P_6$ & $P_7$ & $P_8$ & $P_9$ & $P_{10}$ \\
    \midrule
    0.05  &  0.83 &  0.46 &  0.83 &  0.89 &  0.54 &  0.67 &  0.62 &  1.00 &  0.86 &  0.55 \\
    0.15  &  0.79 &  0.90 &  0.72 &  0.60 &  0.90 &  0.67 &  0.99 &  0.83 &  0.66 &  0.90 \\
    0.26  &  1.00 &  0.75 &  0.50 &  0.60 &  0.90 &  0.49 &  0.77 &  0.52 &  0.72 &  0.69 \\
    0.36  &  0.89 &  1.00 &  0.50 &  0.60 &  0.52 &  0.49 &  1.00 &  0.92 &  0.74 &  0.51 \\
    0.47  &  0.61 &  1.00 &  0.50 &  0.75 &  0.52 &  0.24 &  1.00 &  0.62 &  1.00 &  0.51 \\
    0.57  &  0.61 &  1.00 &  0.25 &  0.75 &  0.52 &  0.24 &  1.00 &  0.62 &  1.00 &  0.51 \\
    0.68  &  0.61 &  1.00 &  0.25 &  0.75 &  0.52 &  0.24 &  1.00 &  0.62 &  1.00 &  0.51 \\
    0.78  &  0.61 &  1.00 &  0.25 &  0.75 &  0.52 &  0.24 &  1.00 &  0.62 &  1.00 &  0.51 \\
    0.89  &  0.61 &  1.00 &  0.25 &  0.75 &  0.52 &  0.24 &  1.00 &  0.62 &  1.00 &  0.51 \\
    1     &  0.61 &  1.00 &  0.25 &  0.75 &  0.52 &  1.00 &  1.00 &  0.62 &  1.00 &  0.51 \\
    \bottomrule
  \end{tabular}
  \caption{%
    Effect of sweeping $\delta$ on measurements of ${\chordarc}_\infty$ on
    10 randomly generated polygons with 10 vertices in $[0,1]^2$. The overall behavior is
    difficult to summarize.  Though one might hope that as $\delta \to 0$ we see
    a stabilization in the chard arc score, this does not appear to occur.
    Moreover, there does not seem to be even a monotonic evolution in the score
    as $\delta \to 0$. This is likely due to the fact that smaller values of
    $\delta$ permit stranger nonconvexities to emerge as viable chords.
  }
  \label{fig:delta-arc}
\end{figure}

\begin{figure}[t]
  \centering
  \includegraphics[height=0.8\textheight]{../plots/u_10_alpha_score_chord_arc_infinity_vertices_0-05_delta_ranking.jpg}
  \caption{$\alpha$ scores and ${\chordarc}_{\infty}$ scores for randomly
  generated polygons on 10 vertices.}
  \label{fig:alph-inft-10}
\end{figure}

\begin{figure}[t]
  \centering
  \includegraphics[height=0.8\textheight]{../plots/u_50_alpha_score_chord_arc_one_vertices_0-05_delta_ranking.jpg}
  \caption{$\alpha$ scores and ${\chordarc}_{1}$ scores for randomly
  generated polygons on 50 vertices.}
  \label{fig:alph-one-50}
\end{figure}

\begin{figure}[t]
  \centering
  \includegraphics[height=0.8\textheight]{../plots/u_100_alpha_score_chord_arc_infinity_vertices_0-05_delta_ranking.jpg}
  \caption{$\alpha$ scores and ${\chordarc}_{\infty}$ scores for randomly
  generated polygons on 100 vertices.}
  \label{fig:alph-inft-100}
\end{figure}

\section{Discussion}

We have developed two classes of measurements for determining the niceness of
polygonal regions in the plane and established initial results, both theoretical
and empirical, for evaluating their effectiveness. The $\alpha$-fatness measures
the extent to which the underlying polygon resembles a ball. It rewards
polygons which fill squarely compact regions and punishes oblong and spread out
polygons. The chord-arc score measures the extent to which the underlying
polygon contains significant ``local nonconvexities'' that are not well
distributed throughout the entire polygon. Interestingly, both measures perform
well (even optimally) on specific types of convex polygons but severely punishes
others. We generally find that these measures conform in some sense to an
intuitive understanding of niceness.

Extensions on these measures can be examined. The connected $\alpha$-fatness
score, for example, computes the intersection of $B(x,\varepsilon)$ with the
connected component of $P$ containing $x$. This might prove a more reliable
estimate of intuitive niceness than the conventional $\alpha$-fatness score,
because it excludes components of $P$ from consideration which are close in a
coarse sense, but not necessarily close in a topological sense. The myriad of
possible choices from which to choose $f$ leaves open a wide space for
exploration. A more suitable measure than simply the perimeter may emerge as a
consequence.

The next extension of this work is to apply these measures to electoral
districts and evaluate their success at distinguishing between offending and
``nice'' districts. Given an increasing corpus of election districts ruled out
or struck down by constitutional grounds, it may be possible to learn a
classification model using these measures. Alternatively, it may be discovered
that these measures are sufficient to distinguish between offending and nice
districts in an unsupervised fashion.

Whether quantitative measures that conform to intuitive understandings of
niceness is relevant to crafting electoral districts at all remains an open
question. General compactness and contiguity are only part of the requirements
which an electoral district must satisfy under the present regime, whereas
others, such as those given in the 1965 Voting Rights Act, bear less consequence
from the pure shape of the district. Doubtless these quantitative measures could
form part of the evaluation process for determining new districts, but the
actual policy will almost surely involve ensembles of measures, both
quantitative and otherwise, in idealized future redistricting.

\printbibliography[heading=bibintoc]

\end{document}


\section{Communication}
\subsection{Random Access}
Best sending rate is $p = \frac{1}{n}$ (using maximization of
$p \left(1 - p\right)^{n-1}$) leads to utilization of $\frac{1}{\emath}$.

\subsection{TDMA}
Statically allocated slots, synchronization done by master.

\subsection{CSMA/CD}
Detect collitions, do exponential backoff of $\set{0, \dots 2^n - 1}$ for $n$th
collision (possibly with upper bound on n). The wait time is twice the round
trip time.

\subsection{Token Ring}
Pass token around, attach to token.

\subsection{CSMA/CA}
IMAGE HERE

\subsection{CSMA/CR}
Before message is sent, arbitration happens. During arbitration every client can
detect which one is allowed to send. During arbitration, every node sends its
unique id and checks whether the result on the bus matches the id. Low bits
override high bits, hence the one with the lowest id wins.

\subsection{FlexRay}
FlexRay uses a combination of TDMA and something close to CSMA/CA alternating,
first a static segment using TDMA, then a dynamic segment

\subsection{Bluetooth}
Frequency hopping in range $2402 + k$ MHz, $0 \leq k \leq 78$, 1600hops per
second. Organized in piconets with 1 master and at most 7 slaves, which can be
combined into scatternets. A node is a master in at most one piconet and can be
a slave in multiple piconets.

The master can only send in even time slots. After each slot, the frequency is
changed using a pseudorandom sequence based on the master's device address
(unique) and the phase of the master's system clock. Packets are either 1, 3, or
5 slots long, the frequency is only changed after the full packet is sent,
however it changes 1, 3, or 5 steps, depending on the packet length.

The initial setup between master and slave is done by the inquiry step, where
the master sends it s ID using a special channel sequence, the slave listens and
replies with its ID, clock and other information.

Then the connection is started with in the page mode. The master sends its and
the slaves address using a special channel sequence, the slave listens whether
it hears its address and answers with its own address. The master then sends a
frequency hop synchronization packet (FHS) to the slave which allows them to
synchronize and connnect.

A slave can be in multiple states, active, hold (not processing date packtes),
sniff (awaken in regular time intervals), and park (no connection but still
synchronized).

\subsection{Packet Details}
Total packet length is either 366 bits, 1626 bits or 2870 bits for 1, 3, and 5
slot packets respectively. Packet length in bits corresponds to $\mu$s send
time. For unprotected data, the payload is 216 bits, 1464 bits and 2712 bits.


% Part: model-theory
% Chapter: models-of-arithmetic
% Section: introduction

\documentclass[../../../include/open-logic-section]{subfiles}

\begin{document}

\olfileid{mod}{mar}{int}
\section{Introduction}

The \emph{standard model} of arithmetic is the
!!{structure}~$\Struct{N}$ with $\Domain{N} = \Nat$ in which
$\Obj{0}$, $\prime$, $+$, $\times$, and $<$ are interpreted as you
would expect. That is, $\Obj{0}$ is $0$, $\prime$ is the successor
function, $+$ is interpeted as addition and $\times$ as multiplication
of the numbers in~$\Nat$. Specifically,
\begin{align*}
  \Assign{\Obj{0}}{N} & = 0\\
  \Assign{\prime}{N}(n) & = n + 1\\
  \Assign{+}{N}(n, m) & = n + m\\
  \Assign{\times}{N}(n, m) & = nm
\end{align*}
Of course, there are structures for $\Lang{L_A}$ that have domains
other than~$\Nat$. For instance, we can take $\Struct{M}$ with domain
$\Domain{M} = \{a\}^*$ (the finite sequences of the single
symbol~$a$, i.e., $\emptyset$, $a$, $aa$, $aaa$, \dots), and
interpretations
\begin{align*}
  \Assign{\Obj{0}}{M} & = \emptyset\\
  \Assign{\prime}{M}(s) & = s \concat a\\
  \Assign{+}{M}(n, m) & = a^{n + m}\\
  \Assign{\times}{M}(n, m) & = a^{nm}
\end{align*}
These two structures are ``essentially the same'' in the sense that
the only difference is the !!{element}s of the !!{domain}s but not how
the !!{element}s of the !!{domain}s are related among each other by
the interpretation functions. We say that the two !!{structure}s are
\emph{isomorphic}.

It is an easy consequence of the compactness theorem that any theory
true in~$\Struct{N}$ also has models that are not isomorphic
to~$\Struct{N}$.  Such structures are called \emph{non-standard}.  The
interesting thing about them is that while the !!{element}s of a
standard model (i.e., $\Struct{N}$, but also all !!{structure}s
isomorphic to it) are exhausted by the values of the standard
numerals~$\num{n}$, i.e.,
\[
\Domain{N} = \Setabs{\Value{\num{n}}{N}}{n \in \Nat}
\]
that isn't the case in non-standard models: if $\Struct{M}$ is
non-standard, then there is at least one $x \in \Domain{M}$ such that
$x \neq \Value{\num{n}}{M}$ for all~$n$.

These non-standard elements are pretty neat: they are ``infinite
natural numbers.'' But their existence also explains, in a sense, the
incompleteness phenomena.  Consider an example, e.g., the consistency
statement for Peano arithmetic, $\OCon[\Th{PA}]$, i.e., $\lnot
\lexists[x][\OPrf[\Th{PA}](x, \gn{\lfalse})]$. Since $\Th{PA}$ neither
proves $\OCon[\Th{PA}]$ nor $\lnot \OCon[\Th{PA}]$, either can be
consistently added to $\Th{PA}$. Since $\Th{PA}$ is consistent,
$\Sat{N}{\OCon[\Th{PA}]}$, and consequently $\Sat/{N}{\lnot
  \OCon[\Th{PA}]}$.  So $\Struct{N}$ is \emph{not} a model of $\Th{PA}
\cup \{\lnot \OCon[\Th{PA}]\}$, and all its models must be
nonstandard. Models of $\Th{PA} \cup \{\lnot \OCon[\Th{PA}]\}$ must
contain some !!{element} that serves as the witness that makes
$\lexists[x][\OPrf[\Th{PA}](\gn{\lfalse})]$ true, i.e., a G\"odel
number of a !!{derivation} of a contradiction from~$\Th{PA}$.  Such
!!a{element} can't be standard---since $\Th{PA} \Proves \lnot
\OPrf[\Th{PA}](\num{n}, \gn{\lfalse})$ for every~$n$.

\end{document}


%!TEX root = fastZKP.tex

\section{Zero Knowledge Argument Protocols}\label{sec:zkp}

In this section, we present the construction of our new zero-knowledge argument system. In~\cite{zhang2017vsql}, Zhang et al. proposed to combine the GKR protocol with a verifiable polynomial delegation protocol, resulting in an argument system. Later, in~\cite{zkvpd,hyrax}, the construction was extended to zero-knowledge, by sending all the messages in the GKR protocol in homomorphic commitments and performing all the checks by zero-knowledge equality and product testing. This incurs a high overhead for the verifier compared to the plain version without zero-knowledge, as each multiplication becomes an exponentiation and each equality check becomes a $\Sigma$-protocol, which is around $100\times$ slower in practice.

In this paper, we follow the same blueprint of combining GKR and VPD to obtain an argument system, but instead show how to extend it to be zero-knowledge efficiently. In particular, the prover masks the GKR protocol with special random polynomials so that the verifier runs a "randomized" GKR that leaks no extra information and her overhead is small. A similar approach was used by Chiesa et.al in~\cite{zksumcheck}. In the following, we present the zero-knowledge version of each building block, followed by the whole zero-knowledge argument.

\subsection{Zero Knowledge Sumcheck}\label{subsec:zksumcheck}
As a core step of the GKR protocol, $\P$ and $\V$ execute a sumcheck protocol on Equation~\ref{eq:GKR}, during which $\P$ sends $\V$ evaluations of the polynomial at several random points chosen by $\V$. These evaluations leak information about the values in the circuit, as they can be viewed as weighted sums of these values

To make the sumcheck protocol zero-knowledge, we take the approach proposed by Chiesa et al. in \cite{zksumcheck}, which is masking the polynomial in the sumcheck protocol by a random polynomial. In this approach, to prove
$$H = \sum\nolimits_{x_1, x_2, \ldots, x_\ell \in \binary}f(x_1, x_2, \ldots, x_\ell)$$
, the prover generates a random polynomial $g$ with the same variables and individual degrees of $f$. She commits to the polynomial $g$, and sends the verifier a claim $G = \sum\limits_{x_1, x_2, \ldots, x_\ell \in \binary}g(x_1, x_2, \ldots, x_\ell)$. The verifier picks a random number $\rho$, and execute a sumcheck protocol with the prover on $$H + \rho G = \sum\nolimits_{x_1, x_2, \ldots, x_\ell \in \{0, 1\}}(f(x_1, x_2, \ldots, x_\ell) + \rho g(x_1, x_2, \ldots, x_\ell)).$$ At the last round of this sumcheck, the prover opens the commitment of $g$ at $g(r_1, \ldots, r_\ell)$, and the verifier computes $f(r_1, \ldots, r_l)$ by subtracting $\rho g(r_1, \ldots, r_\ell)$ from the last message, and compares it with the oracle access of $f$. It is shown that as long as the commitment and opening of $f$ are zero-knowledge, the protocol is zero-knowledge. Intuitively, this is because all the coefficients of $f$ are masked by those of $g$. The soundness still holds because of the random linear combination of $f$ and $g$.

Unfortunately, the masking polynomial $g$ is as big as $f$, and opening it to a random point later is expensive. In~\cite{zksumcheck}, the prover sends a PCP oracle of $g$, and executes a zero-knowledge sumcheck to open it to a random point, which incurs an exponential complexity for the prover. Even replacing it with the zkVPD protocol in~\cite{zkvpd}, the prover time is slow in practice.

In this paper, we show that it suffices to mask $f$ with a small polynomial to achieve zero-knowledge. In particular, we set $g(x_1, \ldots, x_\ell) = a_{0} + g_1(x_1) + g_2(x_2) + \ldots + g_\ell(x_\ell)$, where $g_{i}(x_i) = a_{i,1}x_i + a_{i,2}x_i^2 + \ldots + a_{i,d}x_i^d$ is a random univariate polynomial of degree $d$ ($d$ is the variable degree of $f$). Note here that the size of $g$ is only $O(d\ell)$, while the size of $f$ is $O(2^\ell)$.

The intuition of our improvement is that the prover sends $O(d\ell)$ messages in total to the verifier during the sumcheck protocol, thus a polynomial $g$ with $O(d\ell)$ random coefficients is sufficient to mask all the messages and achieve zero-knowledge. We present the full protocol in Construction~\ref{construction::zksumcheck}.

\begin{figure}[t!]
\small{
\centering{\centering
\framebox{\parbox{.99\linewidth}{
\begin{construction}
\label{construction::zksumcheck}
We assume the existence of a zkVPD protocol defined in Section~\ref{subsec::zkvpd}. For simplicity, we omit the randomness $r_f$ and public parameters $\pp,\vp$ without any ambiguity. To prove the claim $H = \sum\limits_{x_1, x_2, \ldots, x_\ell \in \binary} f(x_1, x_2, \ldots, x_\ell)$:
\begin{enumerate}

\item $\P$ selects a polynomial $g(x_1,\ldots, x_\ell) = a_{0} + g_1(x_1) + g_2(x_2) + \ldots + g_l(x_\ell)$, where $g_{i}(x_i) = a_{i,1}x_i + a_{i,2}x_i^2 + \ldots + a_{i,d}x_i^d$ and all $a_{i,j}$s are uniformly random. $\P$ sends $H = \sum\limits_{x_1, x_2, \ldots, x_\ell \in \binary} f(x_1, x_2, \ldots, x_\ell)$, $G = \sum\limits_{x_1, x_2, \ldots, x_\ell \in \binary} g(x_1, x_2, \ldots, x_\ell)$ and $\comm_g = \Commit(g)$ to $\V$.
\item $\V$ uniformly selects $\rho \in \mathbb{F}^*$, computes $H+\rho G$ and sends $\rho$ to $\P$.
\item $\P$ and $\V$ run the sumcheck protocol on
$$H + \rho G = \sum\limits_{x_1, x_2, \ldots, x_\ell \in \binary}(f(x_1, x_2, \ldots, x_\ell) + \rho g(x_1, x_2, \ldots, x_\ell))$$
\item At the last round of the sumcheck protocol, $\V$ obtains a claim $h_\ell(r_\ell) = f(r_1, r_2, \ldots, r_\ell)+\rho g(r_1, r_2, \ldots, r_\ell)$. $\P$ and $\V$ opens the commitment of $g$ at $r = (r_1,\ldots, r_\ell)$ by $(g(r), \pi)\leftarrow\Open(g,r), \Verify(\comm_g,g(r),r,\pi)$. If $\Verify$ outputs $\reject$, $\V$ aborts.
\item $\V$ computes $h_\ell(r_\ell)-\rho g(r_1,\ldots,r_\ell)$ and compares it with the oracle access of $f(r_1,\ldots, r_\ell)$.

\end{enumerate}
\end{construction}}}}}
\vspace{-.2in}
\end{figure}
The completeness of the protocol holds obviously. The soundness follows the soundness of the sumcheck protocol and the random linear combination in step 2 and 3, as proven in~\cite{zksumcheck}. We give a proof of zero knowledge in Appendix~\ref{app:proofsc}.

\begin{theorem}[Zero knowledge]\label{thm:zksc}
	For every verifier $\V^*$ and every $\ell$-variate polynomial $f:\F^\ell\rightarrow\F$ with variable degree $d$, there exists a simulator $\S$ such that given access to $H = \sum\nolimits_{x_1, x_2, \ldots, x_\ell \in \binary} f(x_1, x_2, \ldots, x_\ell)$, $\S$ is able to simulate the partial view of $\V^*$ in step 1-4 of Construction~\ref{construction::zksumcheck}.
\end{theorem}

\subsection{Zero knowledge GKR}\label{subsec::zkgkr}

To achieve zero-knowledge, we replace the sumcheck protocol in GKR with the zero-knowledge version described in the previous section. However, the protocol still leaks additional information. In particular, at the end of the zero-knowledge sumcheck, $\V$ queries the oracle to evaluate the polynomial on a random point. When executed on Equation~\ref{eq:GKR}, this reveals two evaluations of the polynomial $\tV_i$ defined by the values in the $i$-th layer of the circuit: $\tV_i(u)$ and $\tV_i(v)$.

To prevent this leakage, Chiesa et al.\cite{zksumcheck} proposed to replace the multi-linear extension $\tV_i$ with a low degree extension, such that learning $\tV_i(u)$ and $\tV_i(v)$ does not leak any information about $V_i$. Define a low degree extension of $V_i$ as

\begin{equation}\label{eq:lde}
\dot{V}_{i}(z) \overset{def}{=} \tV_i(z)+Z_i(z)\sum\nolimits_{w \in \{0, 1\}^\lambda}R_i(z, w),
\end{equation}
where $Z(z) = \prod_{i=1}^{s_i} z_i(1-z_i)$, i.e., $Z(z)=0$ for all $z\in\{0, 1\}^{s_i}$. $R_i(z,w)$ is a random low-degree polynomial and $\lambda$ is the security parameter. With this low degree extension, Equation~\ref{eq:GKR} becomes

\begin{align}\label{eq:zkGKR}
\dot{V}_{i}(g)&=\sum\nolimits_{x, y\in \binary^{s_{i+1}}}\tilde{mult}_{i+1}(g, x, y)(\dot{V}_{i+1}(x)\dot{V}_{i+1}(y))\\
&+\tilde{add}_{i+1}(g,x,y)(\dot{V}_{i+1}(x)+\dot{V}_{i+1}(y))\nonumber + Z_i(g)\sum\nolimits_{w \in \binary^\lambda}R_i(g, w)\nonumber\\
&=\sum\nolimits_{x, y\in \binary^{s_{i+1}},w \in \binary^\lambda}(I(\vec{0},w) \cdot \tilde{mult}_{i+1}(g, x, y)(\dot{V}_{i+1}(x)\dot{V}_{i+1}(y))\\
&+\tilde{add}_{i+1}(g,x,y)(\dot{V}_{i+1}(x)+\dot{V}_{i+1}(y))\nonumber + I((x, y), \vec{0})Z_i(g)R_i(g, w))
\end{align}
where $I(\vec{a},\vec{b})$ is an identity polynomial $I(\vec{a},\vec{b}) = 0$ iff $\vec{a}=\vec{b}$. The first equation holds because $\dot{V}_i$ agrees with $\tV_i$ on the Boolean hyper-cube $\binary^{s_i}$, as $Z_i(z) = 0$ for binary inputs. The second equation holds because the mask in $\dot{V}_i$ is in the form of a "sum" and can be moved into the sumcheck equation.

When executing the zero-knowledge sumcheck protocol on Equation~\ref{eq:zkGKR}, at the end of the protocol, $\V$ receives $\dot{V}_{i+1}(u)$ and $\dot{V}_{i+1}(v)$ for random points $u,v\in\F^{s_{i+1}}$ chosen by $\V$. They no longer leak information about $V_{i+1}$, as they are masked by $Z_{i+1}(z)\sum\nolimits_{w \in \{0, 1\}^\lambda}R_{i+1}(z, w)$ for $z=u$ and $z=v$. $\V$ computes $\tilde{mult}_{i+1}(g,u,v)$ and $\tilde{add}_{i+1}(g,u,v)$ as before, computes $Z_i(g), I(\vec{0},c), I((u,v),\vec{0})$ where $c\in\F^\lambda$ is a random point chosen by $\V$ for variable $w$, opens $R_i(g,w)$ at $c$  with $\P$ through a polynomial commitment, and checks that together with $\dot{V}_{i+1}(u), \dot{V}_{i+1}(v)$ received from $\P$ they are consistent with the last message of the sumcheck.$\V$ then uses $\dot{V}_{i+1}(u), \dot{V}_{i+1}(v)$ to proceed to the next round.

Unfortunately, similar to the zero-knowledge sumcheck, the masking polynomial $R_i$ is very large in~\cite{zksumcheck}. Opening $R_i$ at a random point takes exponential time for $\P$ either using a PCP oracle as in~\cite{zksumcheck} or potentially using a zkVPD, as $R$ has $s_i+2s_{i+1}+\lambda$ variables.

In this section, we show that we can set $R_i$ to be a small polynomial to achieve zero-knowledge. In particular, $R_i$ has only two variables with variable degree 2. This is because in the $(i-1)$-th round, $\V$ receives two evaluations of $V_i$, $\dot{V}_i(u)$ and $\dot{V}_i(v)$,  which are masked by $\sum_{w}R_i(u,w)$ and $\sum_{w}R_i(v,w)$; in the $i$-th sumcheck, $\V$ opens $R_i$ at $R_i(u,c)$ and $R_i(v,c)$. It suffices to make these four evaluations linearly independent, assuming the commitment and opening of $R_i$ are using a zkVPD. Therefore, we set the low-degree term in Equation~\ref{eq:lde} as $Z_i(z)\sum\nolimits_{w \in\binary} R_i(z_1, w)$, i.e. $R_i$ only takes two variables, the first variable $z_1$ of $z$ and an extra variable $w\in\binary$ instead of $\binary^\lambda$, with variable degree 2.

The full protocol is presented in Construction~\ref{construction:zkgkr}. Here we use superscriptions (e.g., $u^{(i)}$) to denote random numbers or vectors for the $i$-th layer of the circuit.

%\begin{figure}[H]

%{\small
%\centering{\centering
%\framebox{\parbox{.99\linewidth}{
\begin{mdframed}[nobreak=false]
	\begin{construction}\label{construction:zkgkr}
		\begin{enumerate}
			\item On a layered arithmetic circuit $C$ with $d$ layers and input $\mathsf{in}$, the prover $\P$ sends the output of the circuit $\mathsf{out}$ to the verifier $\V$.

			\item $\P$ randomly selects polynomials $R_1(z_1, w), \ldots, R_d(z_1, w): \F^2\rightarrow \F$ with variable degree 2. $\P$ commits to these polynomials by sending $\comm_i\leftarrow\Commit(R_i)$ to $\V$ for $i\in[1,d]$.

			\item $\V$ defines $\dot{V}_0(z)= \tV_0(z)$, where $\tV_0(z)$ is the multilinear extension of $\mathsf{out}$. $\dot{V}_0(z)$ can be viewed as a special case with $R_0(z_1,w)$ being the 0 polynomial. $\V$ evaluates it at a random point $\dot{V}_0(g^{(0)})$ and sends $g^{(0)}$ to $\P$.

			\item $\P$ and $\V$ execute the zero knowledge sumcheck protocol presented in Construction~\ref{construction::zksumcheck} on
			\[
			\begin{aligned}
			\dot{V}_{0}(g^{(0)})=\sum_{x, y\in \binary^{s_{1}}}&\tilde{mult}_{1}(g^{(0)}, x, y)(\dot{V}_{1}(x)\dot{V}_{1}(y))\\
			&+\tilde{add}_{1}(g^{(0)},x,y)(\dot{V}_{1}(x)+\dot{V}_{1}(y))
		    \end{aligned}
			\]
			If $u_1^{(1)} = v_1^{(1)}$, $\P$ aborts. At the end of the protocol, $\V$ receives $\dot{V}_1(u^{(1)})$ and $\dot{V}_1(v^{(1)})$. $\V$ computes $\tmult_1(g^{(0)},u^{(1)},v^{(1)})$, $\tadd_1(g^{(0)},u^{(1)},v^{(1)})$ and checks that $\tmult_1(g^{(0)},u^{(1)},v^{(1)})\dot{V}_1(u^{(1)})\dot{V}_1(v^{(1)})+\tadd_1(g^{(0)},u^{(1)},v^{(1)})$ $(\dot{V}_1(u^{(1)})+\dot{V}_1(v^{(1)}))$ equals to the last message of the sumcheck (evaluation oracle).

			\item For layer $i=1,\ldots, d-1$:
			\begin{enumerate}
				\item $\V$ randomly selects $\alpha^{(i)}, \beta^{(i)}\in\F$ and sends them to $\mathcal{P}$.
				\item  Let $Mult_{i + 1}(x, y) = \alpha^{(i)}\tilde{mult}_{i+1}(u^{(i)}, x, y)+\beta^{(i)}\tilde{mult}_{i+1}(v^{(i)}, x, y)$ and $Add_{i + 1}(x, y) = \alpha^{(i)}\tilde{add}_{i+1}(u^{(i)}, x, y)+\beta^{(i)}\tilde{add}_{i+1}(v^{(i)}, x, y)$. $\P$ and $\V$ run the zero knowledge sumcheck on the equation\\

				$\alpha^{(i)}\dot{V}_i(u^{(i)})+\beta^{(i)}\dot{V}_i(v^{(i)})=$
				\begin{align*}
				&\sum_{\substack{x, y\in \binary^{s_{i+1}}\\w \in \binary}}(I(\vec{0},w) \cdot Mult_{i+1}(x, y)(\dot{V}_{i+1}(x)\dot{V}_{i+1}(y))\\
				&+Add_{i+1}(x, y)(\dot{V}_{i+1}(x)+\dot{V}_{i+1}(y))\nonumber\\
				&+ I((x, y), \vec{0})(\alpha^{(i)}Z_i(u^{(i)})R_i(u_1^{(i)}, w)+\beta^{(i)}Z_i(v^{(i)})R_i(v_1^{(i)}, w)))
				\end{align*}
				If $u_1^{(i+1)} = v_1^{(i+1)}$, $\P$ aborts.

				\item At the end of the zero-knowledge sumcheck protocol, $\P$ sends $\V$ $\dot{V}_{i+1}(u^{(i+1)})$ and $\dot{V}_{i+1}(v^{(i+1)})$.

				\item $\V$ computes $a_{i+1} = $\\$\alpha^{(i)}\tilde{mult}_{i+1}(u^{(i)}, u^{(i+1)}, v^{(i+1)})+\beta^{(i)}\tilde{mult}_{i+1}(v^{(i)}, u^{(i+1)}, v^{(i+1)})$ and $b_{i+1} = \alpha^{(i)}\tilde{add}_{i+1}(u^{(i)}, u^{(i+1)}, v^{(i+1)})+\beta^{(i)}\tilde{add}_{i+1}(v^{(i)}, u^{(i+1)}, v^{(i+1)})$ locally. $\V$ computes $Z_i(u^{(i)}),Z_i(v^{(i)}),I(\vec{0},c^{(i)}), I((u^{(i+1)},v^{(i+1)}),\vec{0})$ locally.
				\item $\P$ and $\V$ open $R_i$ at two points $R_i(u_1^{(i)},c^{(i)})$ and $R_i(v_1^{(i)},c^{(i)})$ using $\Open$ and $\Verify$.
				\item $\V$ computes the following as the evaluation oracle and uses it to complete the last step of the zero-knowledge sumcheck.
				{\footnotesize
				\begin{align*}
				&I(\vec{0},c^{(i)})(a_{i+1}(\dot{V}_{i+1}(u^{(i+1)})\dot{V}_{i+1}(v^{(i+1)}))+\\
				&b_{i+1}(\dot{V}_{i+1}(u^{(i+1)})+\dot{V}_{i+1}(v^{(i+1)})))+\\
				&I((u^{(i+1)},v^{(i+1)}),\vec{0})(\alpha^{(i)}Z_i(u^{(i)})R_i(u_1^{(i)}, c^{(i)})+\beta^{(i)}Z_i(v^{(i)})R_i(v_1^{(i)}, c^{(i)}))
				\end{align*}
				}
				If all checks in the zero knowledge sumcheck and $\Verify$ passes, $\V$ uses $\dot{V}_{i+1}(u^{(i+1)})$ and $\dot{V}_{i+1}(v^{(i+1)})$ to proceed to the $(i+1)$-th layer. Otherwise, $\V$ outputs $\reject$ and aborts.

			\end{enumerate}

			\item At the input layer $d$, $\V$ has two claims $\dot{V}_{d}(u^{(d)})$ and $\dot{V}_{d}(v^{(d)})$. $\V$ opens $R_d$ at 4 points $R_d(u_1^{(d)},0),R_d(u_1^{(d)},1),R_d(v_1^{(d)},0),R_d(v_1^{(d)},1)$ and checks that $\dot{V}_{d}(u^{(d)}) = \tV_d(u^{(d)})+Z_d(u^{(d)})\sum\limits_{w \in \binary}R_d(u_1^{(d)},w)$ and $\dot{V}_{d}(v^{(d)}) = \tV_d(v^{(d)})+Z_d(v^{(d)})\sum\limits_{w \in \binary}R_d(v_1^{(d)},w)$, given oracle access to two evaluates of $\tV_d$ at $u^{(d)}$ and $v^{(d)}$. If the check passes, output $\accept$; otherwise, output $\reject$.

		\end{enumerate}
	\end{construction}
\end{mdframed}

%}}}}
%\end{figure}

\begin{theorem}\label{thm:zkgkr}
	Construction~\ref{construction:zkgkr} is an interactive proof protocol per Definition~\ref{def:ip}, for a function $f$ defined by a layered arithmetic circuit $C$ such that $f(\mathsf{in},\mathsf{out}) = 1$ iff $C(\mathsf{in}) = \mathsf{out}$. In addition, for every verifier $\V^*$ and every layered circuit $C$, there exists a simulator $\S$ such that given oracle access to $\mathsf{out}$, $\S$ is able to simulate the partial view of $\V^*$ in step 1-5 of Construction~\ref{construction:zkgkr}.
\end{theorem}

The completeness follows from the construction explained above and the completeness of the zero knowledge sumcheck. The soundness follows the soundness of the GKR protocol with low degree extensions, as proven in~\cite{GKR} and~\cite{zksumcheck}. We give the proof of zero knowledge in Appendix~\ref{app:proofgkr}.

\subsection{Zero knowledge VPD}\label{subsec::our_zkvpd}
In this section, we present the instantiations of the zkVPD protocol, as defined in Definition~\ref{def::zkvpd}. For every intermediate layer $i$, we use the same zkVPD protocol as proposed by Zhang et al. in~\cite{zkvpd} to commit and open the masking polynomials $g_i(x), R_i(z_1, w)$. In fact, as we show in the previous sections, these polynomials are very small ($g_i$ is the sum of univariate polynomials and $R_i$ has 2 variables with variable degree 2), the zkVPD protocols become very simple. The complexity of $\KeyGen, \Commit, \Open, \Verify$ and proof size are all $O(s_i)$ for $g_i$ and are all $O(1)$ for $R_i$. We omit the full protocols due to space limit.

For the zkVPD used for the input layer, we design a customized protocol based on the zkVPD protocol in~\cite{zkvpd}. Recall that at the end of the GKR protocol, $\V$ receives two evaluations of the polynomial $\dot{V}_d(z)=\tV_d(z)+Z_d(z)\sum\nolimits_{w \in\binary} R_d(z_1,w)$ at $z=u^{(d)}$ and $z=v^{(d)}$. In our zero knowledge proof protocol, which will be presented in Section~\ref{subsec::zkall}, $\P$ commits to $\dot{V}_d(z)$ using the zkVPD at the beginning, and opens it to the two points selected by $\V$.

The protocol in~\cite{zkvpd} works for any polynomial with $\ell$ variables and any variable degree, and is particularly efficient for multilinear polynomials. We modify the protocol for our zero-knowledge proof scheme and preserves the efficiency. Note that though $\dot{V}_d(z)$ is a low degree extension of the input, it can be decomposed to the sum of $\tV_d(z)$, a multilinear polynomial, and $Z_d(z)\sum\nolimits_{w \in\binary} R_d(z_1,w)$. Moreover, $Z_d(u^{(d)})$ and $Z_d(v^{(d)})$ can be computed directly by $\V$. Therefore, in our construction, $\P$ commits to $\tV_d(z)$ and $\sum\nolimits_{w \in\binary} R_d(z_1,w)$ separately, and later opens the sum together given $Z_d(u^{(d)})$ and $Z_d(v^{(d)})$, which is naturally supported because of the homomorphic property of the commitment. Another optimization is that unlike other layers of the circuit, $R_d(z_1,w)$ itself is not opened at two points ($\V$ does not receive $R_d(u^{(d)},c^{(d)})$ and $R_d(v^{(d)},c^{(d)})$ in Construction~\ref{construction:zkgkr}). Therefore, it suffices to set $\dot{V}_d(z)=\tV_d(z)+Z_d(z)R_d(z_1)$, where $R_d$ is a univariate linear polynomial. The full protocol is presented in Appendix~\ref{app:zkvpdconstruction}.

\begin{theorem}\label{thm:zkvpd}
	Construction~\ref{construction::zkVPD} is a zero-knowledge verifiable polynomial delegation scheme as defined by Definition~\ref{def::zkvpd}, under Assumption~\ref{asp::qSDH} and~\ref{asp::dlEPKE}.
\end{theorem}

The proof of completeness, soundness and zero knowledge is similar to that of the zkVPD protocol in~\cite{zkvpd}. We only add an extra univariate linear polynomial $R(x_1)$, which does not affect the proof. We omit the proof due to space limit. Using the same algorithms proposed in in~\cite{vram,zkvpd}, the running time of $\KeyGen$, $\Commit$ and $\Open$ is $O(2^\ell)$, $\Verify$ takes $O(\ell)$ time and the proof size is $O(\ell)$.

\subsection{Putting Everything Together}\label{subsec::zkall}

In this section, we present our zero knowledge argument scheme. At a high level, similar to~\cite{zhang2017vsql,hyrax,zkvpd}, $\V$ can use the GKR protocol to verify the correct evaluation of a circuit $C$ on input $x$ and a witness $w$, given an oracle access to the evaluation of a polynomial defined by $x,w$ on a random point. We instantiate the oracle using the zkVPD protocol. Formally, we present the construction in Construction~\ref{construction::all}, which combines our zero knowledge GKR and zkVPD protocols. Similar to the protocols in~\cite{zkvpd,hyrax}, Step 6 and 7 are to check that $\P$ indeed uses $x$ as the input to the circuit.
\begin{figure}[t!]
\small{
\centering{\centering
\framebox{\parbox{.99\linewidth}{
\begin{construction}
%\begin{protocol}
\label{construction::all}
	Let $\lambda$ be the security parameter, $\F$ be a prime field, $n$ be an upper bound on input size, and $S$ be an upper bound on circuit size. We use $\VPD_1, \VPD_2, \VPD_3$ to denote the zkVPD protocols for input layer, masking polynomials $g_i$ and $R_i$ described in Construction~\ref{construction:zkgkr}.
	\begin{itemize}
		\item $\mathcal{G}(1^\lambda, n, S)$: run $(\pp_1,\vp_1)\leftarrow\VPD_1.\KeyGen(1^\lambda, \log n)$, $(\pp_2,\vp_2)\leftarrow\VPD_2.\KeyGen(1^\lambda, \log S)$, $(\pp_3,\vp_3)\leftarrow\VPD_3.\KeyGen(1^\lambda)$. Output $\pk = (\pp_1, \pp_2, \pp_3)$ and $\vk = (\vp_1, \vp_2, \vp_3)$.

		\item $\langle\P(\pk,w), \V(\vk)\rangle(x)$: Let $C$ be a layered arithmetic circuit over $\F$ with $d$ layers, input $x$ and witness $w$ such that $|x|+|w|\le n$, $|C|\le S$ and $C(x;w) =1$. Without loss of generality, assume $|w|/|x| = 2^m -1$ for some $m\in\N$.
		\begin{enumerate}
			\item $\P$ selects a random bivariate polynomial $R_d$ with variable degree 2 and commits to the input of $C$ by sending $\comm_d\leftarrow\VPD_1.\Commit(\dot{V}_d, r_V, r_R, \pp_1)$ to $\V$, where $\tV_d$ is the multilinear extension of array $(x;w)$ and $\dot{V}_d=\tV_d+R_d$
			\item $\V$ runs $\VPD_1.\CheckComm(\comm_d,\vp_1)$. If it outputs $\reject$, $\V$ aborts and outputs $\reject$.
			\item $\P$ and $\V$ execute Step 1-5 of the zero knowledge GKR protocol in Construction~\ref{construction:zkgkr}, with the zkVPDs instantiated with $\VPD_2$ and $\VPD_3$. If Construction~\ref{construction:zkgkr} rejects, $\V$ outputs $\reject$ and aborts. Otherwise, by the end of this step, $\V$ receives two claims of $\dot{V}_d$ at $u^{(d)}$ and $v^{(d)}$.
			\item $\P$ runs $(y_1,\pi_1)\leftarrow\VPD_1.\Open(\dot{V}, r_V, r_R,u^{(d)},\pp_1)$,  $(y_2,\pi_2)\leftarrow\VPD_1.\Open(\dot{V}, r_V, r_R, v^{(d)},\pp_1)$ and sends $y_1,\pi_1,y_2,\pi_2$ to $\V$.
			\item $\V$ runs $\Verify(\comm_d,u^{(d)},y_1,\pi_1,\vp_1)$ and $\Verify(\comm_d,v^{(d)},y_2,\pi_2,\vp_1)$ and output $\reject$ if either check fails. Otherwise, $\V$ checks $\dot{V}_d(u^{(d)}) = y_1$ and $\dot{V}_d(v^{(d)}) = y_2$, and rejects if either fails.
			\item $\V$ computes the multilinear extension of input $x$ at a random point $r_x\in\F^{\log |x|}$ and sends $r_x$ to $\P$.
			\item $\P$ pads $r_x$ to $r'_x\in\F^{\log |x|}\times 0^{\log |w|}$ with $\log |w|$ 0s and sends $\V$ $(y_x,\pi_x)\leftarrow\VPD_1.\Open(\tV_d, r_V, r_R, r'_x,\pp_1)$. $\V$ checks $\Verify(\comm_d,r'_x,y_x,\pi_x,\vp_1)$ and $y_x$ equals the evaluation of the multilinear extension on $x$. $\V$ outputs $\reject$ if the checks fail. Otherwise, $\V$ outputs $\accept$.
		\end{enumerate}

	\end{itemize}
%\end{protocol}
\end{construction}}}}}
\vspace{-0.2in}
\end{figure}
\begin{theorem}\label{theorem:main}
	For an input size $n$ and a finite field $\F$, Construction~\ref{construction::all} is a zero knowledge argument for the relation
	\[
	\mathcal{R} = \{(C,x;w): C\in\mathcal{C}_\F\wedge|x|+|w|\le n\wedge C(x;w) = 1\},
	\]
	as defined in Definition~\ref{def::zkp}, under Assumption~\ref{asp::qSDH} and~\ref{asp::dlEPKE}. Moreover, for every $(C,x;w)\in\mathcal{R}$, the running time of $\P$ is $O(|C|)$ field operations and $O(n)$ multiplications in the base group of the bilinear map. The running time of $\V$ is $O(|x|+d\cdot\log |C|)$ if $C$ is log-space uniform with $d$ layers. $\P$ and $\V$ interact $O(d\log |C|)$ rounds and the total communication (proof size) is $O(d\log |C|)$. In case $d$ is $\mathsf{polylog}(|C|)$, the protocol is a succinct argument.
\end{theorem}

\paragraph{Proof Sketch.} The correctness and the soundness follow from those of the two building blocks, zero knowledge GKR and zkVPD, by Theorem~\ref{thm:zkgkr} and~\ref{thm:zkvpd}.

To prove zero knowledge, consider a simulator $\S$ that calls the simulator $\S_{GKR}$ of zero knowledge GKR given in Section~\ref{subsec::zkgkr} as a subroutine, which simulates the partial view up to the input layer. At the input layer, the major challenge is that $\S$ committed to (a randomly chosen) $\dot{V}^*_d$ at the beginning of the protocol, before knowing the points $u^{(d)}, v^{(d)}$ to evaluate on. If $\S$ opens the commitment honestly, with high probability the evaluations are not consistent with the last message of the GKR (sumcheck in layer $d-1$) and a malicious $\V^*$ can distinguish the ideal world from the real world. In our proof, we resolve this issue by using the simulator $\S_{VPD}$ of our zkVPD protocol. Given the trapdoor $\mathsf{trap}$ used in $\KeyGen$, $\S_{VPD}$ is able to open the commitment to any value in zero knowledge, and in particular it opens to those messages that are consistent with the GKR protocol in our scheme, which completes the construction of $\S$. We defer the formal proof to the full version of the paper.

The complexity of our zero knowledge argument scheme follows from our new GKR protocol with linear prover time, and the complexity of the zkVPD protocol for the input layer analyzed in Section~\ref{subsec::our_zkvpd}. The masking polynomials $g_i, R_i$ and their commitments and openings introduce no asymptotic overhead and are efficient in practice.


\section{Work}{}{}\label{sec:Work}
A fundamental concept in classical physics is
\dfont{work}: If an object is moved in a straight line against
a force $F$ for a distance $d$ the work done is $W=Fd$.

\begin{example}{Constant Force}{Constant Force}\label{Constant Force}
How much work is done in lifting a 10 pound weight vertically a
distance of 5 feet?
\end{example}

\begin{solution}
The force due to gravity on a 10 pound weight is
10 pounds at the surface of the earth, and it does not change
appreciably over 5 feet. The work done is $W=10\cdot 5=50$ foot-pounds.
\end{solution}

In reality few situations are so simple. The force might not be
constant over the range of motion, as in the next example.

\begin{example}{Lifting a Weight}{Lifting a Weight}\label{Lifting a Weight}
How much work is done in lifting a 10 pound weight from the
surface of the earth to an orbit 100 miles above the surface?
\end{example}

\begin{solution}
Over 100 miles the force due to gravity does change significantly, so we need
to take this into account. The force exerted on a 10 pound weight at a
distance $r$ from the center of the earth is $\ds F=k/r^2$ and by
definition it is 10 when $r$ is the radius of the earth (we assume the
earth is a sphere). How can we approximate the work done? We divide
the path from the surface to orbit into $n$ small subpaths. On each
subpath the force due to gravity is roughly constant, with value
$\ds k/r_i^2$ at distance $\ds r_i$. The work to raise the object from
$\ds r_i$ to $\ds r_{i+1}$ is thus approximately $\ds k/r_i^2\Delta r$ and the
total work is approximately
$$\sum_{i=0}^{n-1} {k\over r_i^2}\Delta r,$$
or in the limit
$$W=\int_{r_0}^{r_1} {k\over r^2}\,dr,$$
where $\ds r_0$ is the radius of the earth and $\ds r_1$ is $\ds r_0$ plus 100
miles. The work is
$$W=\int_{r_0}^{r_1} {k\over r^2}\,dr=
-\left.{k\over r}\right|_{r_0}^{r_1}=-{k\over r_1}+{k\over r_0}.$$
Using $\ds r_0=20925525$ feet we have $\ds r_1=21453525$. The force on the 10
pound weight at the surface of the earth is 10 pounds, so
$\ds 10=k/20925525^2$, giving $k=4378775965256250$. Then
$$-{k\over r_1}+{k\over r_0}={491052320000\over 95349}\approx 5150052
\quad\hbox{foot-pounds}.$$
Note that if we assume the force due to gravity is 10 pounds over the
whole distance we would calculate the work as $\ds 10(r_1-r_0)=10\cdot100\cdot
5280=5280000$, somewhat higher since we don't account for the
weakening of the gravitational force.
\end{solution}

\begin{example}{Lifting an Object}{Lifting an Object}\label{Lifting an Object}
How much work is done in lifting a 10 kilogram object from the
surface of the earth to a distance $D$ from the center of the earth?
\end{example}

\begin{solution}
This is the same problem as before in different units, and we are not
specifying a value for $D$. As before
$$W=\int_{r_0}^{D} {k\over r^2}\,dr= -\left.{k\over
  r}\right|_{r_0}^{D}=-{k\over D}+{k\over r_0}.$$
While ``weight in pounds'' is a measure of force, ``weight in
kilograms'' is a measure of mass. To convert to force we need to use
Newton's law $F=ma$. At the surface of the earth the acceleration due
to gravity is approximately 9.8 meters per second squared, so the
force is $F=10\cdot 9.8=98$. The units here are ``kilogram-meters per
second squared'' or ``kg m/s$^2$'', also known as a
Newton (N), so $F=98$~N.  The radius of the earth is
approximately 6378.1 kilometers or 6378100 meters.
Now the problem proceeds as before. From
$\ds F=k/r^2$ we compute $k$:
$\ds 98=k/6378100^2$, $\ds k= 3.986655642\cdot 10^{15}$. Then the work is:
$$W=-{k\over D}+6.250538000\cdot 10^8\quad\hbox{Newton-meters.}$$
As $D$ increases $W$ of course gets larger, since the quantity being
subtracted, $-k/D$, gets smaller. But note that the work $W$ will
never exceed $\ds 6.250538000\cdot 10^8$, and in fact will approach this
value as $D$ gets larger. In short, with a finite amount of work, namely
$\ds 6.250538000\cdot 10^8$ N-m, we can lift the 10 kilogram object as far
as we wish from earth.
%\thmrdef{example:object to infinity}
\end{solution}

Next is an example in which the force is constant, but there are many
objects moving different distances.

\begin{example}{Multiple Objects Moving}{Multiple Objects Moving}\label{Multiple Objects Moving}
Suppose that a water tank is shaped like a right circular
cone with the tip at the bottom, and has height 10 meters and radius 2
meters at the top. If the tank is full, how much work is required
to pump all the water out over the top?
\end{example}

\begin{solution}
Here we have a large number of
atoms of water that must be lifted different distances to get to the
top of the tank. Fortunately, we don't really have to deal with
individual atoms---we can consider all the atoms at a given depth
together.

To approximate the work, we can divide the water in the tank into
horizontal sections, approximate the volume of water in a section by a
thin disk, and compute the amount of work required to lift each disk
to the top of the tank. As usual, we take the limit as the sections
get thinner and thinner to get the total work.

\figure[H]
%\texonly
\centerline{\vbox{\beginpicture
\normalgraphs
%\ninepoint
\setcoordinatesystem units <0.5truecm,0.5truecm>
\setplotarea x from -2 to 2, y from 0 to 10
\axis left shiftedto x=0 /
\plot -2 10 0 0 2 10 -2 10 /
\setdashes
\putrule from -1.2 6 to 1.2 6
\betweenarrows {$h$} from -0.4 6 to -0.4 10
\betweenarrows {10} from 2.3 0 to 2.3 10
\setplotsymbol ({\small.})
\plotsymbolspacing=.2pt
\put {2} [b] <0pt,2pt> at 1 10
\arrow <2pt> [0.7, 2] from 0.5 10.4 to 0 10.4
\arrow <2pt> [0.7, 2] from 1.5 10.4 to 2 10.4
\endpicture}}
%\endtexonly
%\figrdef{fig:conical water tank}
%\htmlfigure{Integration_applications-Pump_out_water.html}
\caption{\label{fig:conical water tank}
Cross-section of a conical water tank.}
%\endcaption
\endfigure

At depth $h$ the circular cross-section through the tank has radius
$r=(10-h)/5$, by similar triangles,
 and area $\ds \pi(10-h)^2/25$. A section of the tank at depth
$h$ thus has volume approximately $\ds \pi(10-h)^2/25\Delta h$ and so
contains $\ds \sigma\pi(10-h)^2/25\Delta h$ kilograms of water, where
$\sigma$ is the density of water in kilograms per cubic meter;
$\sigma\approx 1000$. The force due to gravity on this much water is
$\ds 9.8\sigma\pi(10-h)^2/25\Delta h$, and finally, this section of water
must be lifted a distance $h$, which requires
$\ds h9.8\sigma\pi(10-h)^2/25\Delta h$ Newton-meters of work. The total
work is therefore
$$W={9.8\sigma\pi\over 25} \int_0^{10} h(10-h)^2\,dh={980000\over3}\pi\approx
1026254\quad\hbox{Newton-meters.}$$
\end{solution}

A spring has a ``natural length,'' its length if nothing is stretching
or compressing it. If the spring is either stretched or compressed the
spring provides an opposing force; according to \dfont{Hooke's Law}
the magnitude of this force is proportional to the
distance the spring has been stretched or compressed: $F=kx$.
The constant of proportionality, $k$, of course depends on the
spring. Note that $x$ here represents the {\em change} in length from the
natural length.

\begin{example}{Compressing a Spring}{Compressing a Spring}\label{Compressing a Spring}
Suppose $k=5$ for a given spring that has a natural length of
$0.1$ meters. Suppose a force is applied that compresses the spring to
length $0.08$. What is the magnitude of the force?
\end{example}

\begin{solution}
Assuming that the
constant $k$ has appropriate dimensions (namely, kg/s$^2$), the force is
$5(0.1-0.08)=5(0.02)=0.1$ Newtons.
\end{solution}

\begin{example}{Compressing a Spring (continued)}{Compressing a Spring (continued)}\label{Compressing a Spring (continued)}
How much work is done in compressing the spring in the
previous example from its natural length to $0.08$ meters?
From $0.08$ meters to $0.05$ meters?
How much work is done to stretch the spring
from $0.1$ meters to $0.15$ meters?
\end{example}

\begin{solution}
We can approximate the work by
dividing the distance that the spring is compressed (or stretched)
into small subintervals. Then the force exerted by the spring is
approximately constant over the subinterval, so the work required to
compress the spring from $\ds x_i$ to $\ds x_{i+1}$ is approximately
$\ds 5(x_i-0.1)\Delta x$.  The total work is approximately
$$\sum_{i=0}^{n-1} 5(x_i-0.1)\Delta x$$
and in the limit
$$W=\int_{0.1}^{0.08} 5(x-0.1)\,dx=\left.{5(x-0.1)^2\over2}\right|_{0.1}^{0.08}=
{5(0.08-0.1)^2\over2}-{5(0.1-0.1)^2\over2}={1\over1000}\,\hbox{N-m}.$$
The other values we seek simply use different limits. To compress the
spring from $0.08$
meters to $0.05$ meters takes
$$W=\int_{0.08}^{0.05} 5(x-0.1)\,dx=\left.{5(x-0.1)^2\over2}\right|_{0.08}^{0.05}=
{5(0.05-0.1)^2\over2}-{5(0.08-0.1)^2\over2}={21\over4000}\quad\hbox{N-m}$$
and to stretch the spring
from $0.1$ meters to $0.15$ meters requires
$$W=\int_{0.1}^{0.15} 5(x-0.1)\,dx=\left.{5(x-0.1)^2\over2}\right|_{0.1}^{0.15}=
{5(0.15-0.1)^2\over2}-{5(0.1-0.1)^2\over2}={1\over160}\quad\hbox{N-m}.$$
\end{solution}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\Opensolutionfile{solutions}[ex]
\section*{Exercises for \ref{sec:Work}}

\begin{enumialphparenastyle}

%%%%%%%%%%
\begin{ex}
 How much work is done in lifting a 100 kilogram weight from
the surface of the earth to an orbit 35,786 kilometers above the
surface of the earth?
\begin{sol}
 $\approx 5,305,028,516$ N-m
\end{sol}
\end{ex}

%%%%%%%%%%
\begin{ex}
 How much work is done in lifting a 100 kilogram weight from
an orbit 1000 kilometers above the surface of the earth to an orbit
35,786 kilometers above the surface of the earth?
\begin{sol}
 $\approx 4,457,854,041$ N-m
\end{sol}
\end{ex}

%%%%%%%%%%
\begin{ex}
 A water tank has the shape of an upright cylinder with radius $r=1$
meter and height 10 meters. If the depth of the water is 5 meters, how
much work is required to pump all the water out the top of the tank?
\begin{sol}
 $367,500 \pi$ N-m
\end{sol}
\end{ex}

%%%%%%%%%%
\begin{ex}
 Suppose the tank of the previous problem is lying on its
side, so that the circular ends are vertical, and that it has the same
amount of water as before. How much work is required to pump the water
out the top of the tank (which is now 2 meters above the bottom of the
tank)?
\begin{sol}
 $49000\pi + 196000/3$ N-m
\end{sol}
\end{ex}

%%%%%%%%%%
\begin{ex}
 A water tank has the shape of the bottom half of a sphere
with radius $r=1$ meter. If the tank is full,
how much work is required to pump all the water out
the top of the tank?
\begin{sol}
 $2450\pi$ N-m
\end{sol}
\end{ex}

%%%%%%%%%%
\begin{ex}
 A spring has constant $k=10$ kg/s$^2$. How much work is done
in compressing it $1/10$ meter from its natural length?
\begin{sol}
 $0.05$ N-m
\end{sol}
\end{ex}

%%%%%%%%%%
\begin{ex}
 A force of 2 Newtons will compress a spring from 1 meter
(its natural length) to
0.8 meters. How much work is required to stretch the spring from
1.1 meters to 1.5 meters?
\begin{sol}
 $6/5$ N-m
\end{sol}
\end{ex}

%%%%%%%%%%
\begin{ex}
 A 20 meter long steel cable has density 2 kilograms per
meter, and is hanging straight down. How much work is required to lift
the entire cable to the height of its top end?
\begin{sol}
 $3920$ N-m
\end{sol}
\end{ex}

%%%%%%%%%%
\begin{ex}
 The cable in the previous problem has a 100 kilogram bucket
of concrete attached to its lower end. How much work is required to lift
the entire cable and bucket to the height of its top end?
\begin{sol}
 $23520$ N-m
\end{sol}
\end{ex}

%%%%%%%%%%
\begin{ex}
 Consider again the cable and bucket of the previous problem.
How much work is required to lift the bucket 10 meters by raising the
cable 10 meters? (The top half of the cable ends up at the height of
the top end of the cable, while the bottom half of the cable is lifted
10 meters.)
\begin{sol}
 $12740$ N-m
\end{sol}
\end{ex}

\end{enumialphparenastyle}


\subsection{Classifying with probabilistic decision trees}

Previously our decision tree classifier was binary.

We can instead adapt the mixed tree model and using a probit model at each leaf.


\subsection{Probabilistic Roadmap Planner}

Generate random configuration of robot in space.

Find n positions which are legal

Link them using k nearest neighbours

Risk: graph not fully connected.

If so, can add extra nodes between breaks


\chapter{Basic Notations}
		\begin{itemize}
			\item $\R^+ = \R_{\geq 0} = [0, +\infty[$
			\item $\N = \{0, 1, 2, ...\}$
			\item WLOG = Without Loss Of Generality
			\item PID = Principal Ideal Domain
			\item $\delta_{i, j} = \delta_i^j$ is the Kronecker symbol (it's $1$ if $i=j$ and $0$ otherwise)
			\item If $(X, d)$ is a metric space, $B_{<r}(a) := \{x \in X \mid d(a, x) < r \}$ and $B_{\leq r}(a) := \{x \in X \mid d(a, x) \leq r \}$
			\item If $A$ is a set, $\#A = |A| = \text{card}(A)$
		\end{itemize}


\subsection{Local Extrema}\label{subsec:LocalExtremaSubsection}
A \dfont{local maximum} point on a function is a
point $(x,y)$ on the graph of the function whose $y$ coordinate is
larger than all other $y$ coordinates on the graph at points ``close
to'' $(x,y)$. More precisely, $(x,f(x))$ is a local maximum if there
is an interval $(a,b)$ with $a<x<b$ and $f(x)\ge f(z)$ for every $z$
in $(a,b)$. Similarly, $(x,y)$ is a \dfont{local minimum} point
if it has locally the smallest $y$ coordinate. Again
being more precise: $(x,f(x))$ is a local minimum if there
is an interval $(a,b)$ with $a<x<b$ and $f(x)\le f(z)$ for every $z$
in $(a,b)$. A \dfont{local extremum} is either a local minimum or a local maximum.

\begin{definition}{Local Maxima and Minima}{LocalMaxMinDef}
A real-valued function $f$ has a \deffont{local maximum} at $x_0$ if $f(x_0)$
is the largest value of $f$ near $x_0$; in other words, $f(x_0\geq f(x)$
when $x$ is near $x_0$.

\medskip
A real-valued function $f$ has a \deffont{local minimum} at $x_0$ if $f(x_0)$
is the smallest value of $f$ near $x_0$; in other words, $f(x_0)\leq f(x)$
when $x$ is near $x_0$.
\end{definition}

Local maximum and minimum points are quite distinctive on the graph of
a function, and are therefore useful in understanding the shape of the
graph. In many applied problems we want to find the largest or
smallest value that a function achieves (for example, we might want
to find the minimum cost at which some task can be performed) and so
identifying maximum and minimum points will be useful for applied
problems as well. Some examples of local maximum and minimum points
are shown in Figure~\ref{fig:max and min points}.

\begin{figure}[H]
	\centerline{\vbox{\beginpicture
			\normalgraphs
			%\ninepoint
			\setcoordinatesystem units <1.5truecm,1.5truecm>
			\setplotarea x from -1.5 to 1.5, y from -1.5 to 1.5
			\axis left shiftedto x=0 /
			\axis bottom shiftedto y=0 /
			\setquadratic
			\plot -1.400 -1.344 -1.330 -1.023 -1.260 -0.740 -1.190 -0.495 -1.120 -0.285
			-1.050 -0.108 -0.980 0.039 -0.910 0.156 -0.840 0.247 -0.770 0.313
			-0.700 0.357 -0.630 0.380 -0.560 0.384 -0.490 0.372 -0.420 0.346
			-0.350 0.307 -0.280 0.258 -0.210 0.201 -0.140 0.137 -0.070 0.070
			0.000 0.000 0.070 -0.070 0.140 -0.137 0.210 -0.201 0.280 -0.258
			0.350 -0.307 0.420 -0.346 0.490 -0.372 0.560 -0.384 0.630 -0.380
			0.700 -0.357 0.770 -0.313 0.840 -0.247 0.910 -0.156 0.980 -0.039
			1.050 0.108 1.120 0.285 1.190 0.495 1.260 0.740 1.330 1.023
			1.400 1.344 /
			\put {$\bullet$} at -0.5512 0.3752
			\put {$\bullet$} at 0.5512 -0.3752
			\put {$A$} [b] <0pt,4pt> at -0.5512 0.3752
			\put {$B$} [t] <0pt,-4pt> at 0.5512 -0.3752
			\setcoordinatesystem units <1.5truecm,1.5truecm> point at -4 0
			\setplotarea x from -1.5 to 1.5, y from -1.5 to 1.5
			\axis left shiftedto x=0 /
			\axis bottom shiftedto y=0 /
			\setlinear
			\plot -1.5 -1 -1 0.5 -0.25 -0.25 0.5 1.4 1.5 -0.5 /
			\multiput {$\bullet$} at -1 0.5 -0.25 -0.25 0.5 1.4 /
			\multiput {$A$} [b] <0pt,4pt> at -1 0.5 0.5 1.4 /
			\put {$B$} [t] <0pt,-4pt> at -0.25 -0.25
			\endpicture}}
	\caption{Some local maximum points ($A$) and minimum points ($B$). \label{fig:max and min points}}
\end{figure}

If $(x,f(x))$ is a point where $f(x)$ reaches a local maximum or minimum,
and if the derivative of $f$ exists at $x$, then the graph has a
tangent line and the tangent line \emph{must} be horizontal. This is
important enough to state as a theorem.

The proof is simple enough and we include it here, but you may accept Fermat's
Theorem based on its strong intuitive appeal and come back to its proof at a
later time.

\begin{theorem}{Fermat's Theorem}{FT}
	If $f(x)$ has a local extremum at $x=a$ and $f$ is differentiable at $a$, then $f'(a)=0$.
\end{theorem}
\begin{proof}
	We shall give the proof for the case where $f\left( x\right) $ has a
	local maximum at $x=a.$ The proof for the local minimum case is similar.

	Since $f\left( x\right) $ has a local maximum at $x=a,$ there is an open
	interval $\left( c,d\right) $ with $c<a<d$ and $f\left( x\right) \leq
	f\left( a\right) $ for every $x$ in $\left( c,d\right) .$ So, $f\left(
	x\right) -f\left( a\right) \leq 0$ for all such $x.$ Let us now look at the
	sign of the difference quotient $\dfrac{f\left( x\right) -f\left( a\right) }{%
		x-a}.$ We consider two cases according as $x>a\,\ $or $x<a.$

	If $x>a,$ then $x-a>0$ and so, $\dfrac{f\left( x\right) -f\left( a\right) }{%
		x-a}\leq 0.$ Taking limit as $x$ approach $a$ from the right, we get%
	\begin{equation*}
		\lim_{x\rightarrow a^{+}}\frac{f\left( x\right) -f\left( a\right) }{x-a}\leq
		0.
	\end{equation*}
	On the other hand, if $x<a,$ then $x-a<0$ and so,$\dfrac{f\left( x\right)
		-f\left( a\right) }{x-a}\geq 0.$ Taking limit as $x$ approach $a$ from the
	left, we get%
	\begin{equation*}
		\lim_{x\rightarrow a^{-}}\frac{f\left( x\right) -f\left( a\right) }{x-a}\geq
		0.
	\end{equation*}
	Since $f$ is differentiable at $a,$ $f^{\prime }\left( a\right)
	=\lim\limits_{x\rightarrow a^{+}}\dfrac{f\left( x\right) -f\left( a\right) }{%
		x-a}=\lim\limits_{x\rightarrow a^{-}}\dfrac{f\left( x\right) -f\left(
		a\right) }{x-a}.$ Therefore, we have both $f^{\prime }\left( a\right) \leq 0$
	and $f^{\prime }\left( a\right) \geq 0.$ So, $f^{\prime }\left( a\right) =0.$
\end{proof}

Thus, the only points at which a function can have a local maximum or minimum are
points at which the derivative is zero, as in the left hand graph in
Figure~\ref{fig:max and min points},
or the derivative is undefined, as in the right hand graph. Any value
of $x$ in the domain of $f$ for which $f'(x)$ is zero or undefined is called a
\dfont{critical point} for $f$. When looking for local maximum
and minimum points, you are likely to
make two sorts of mistakes: You may forget that a maximum or minimum
can occur where the derivative does not exist, and so forget to check
whether the derivative exists everywhere. You might also assume that
any place that the derivative is zero is a local maximum or minimum
point, but this is not true. A portion of the graph of $\ds f(x)=x^3$ is
shown in Figure~\ref{fig:non extremum}. The derivative of $f$ is
$f'(x)=3x^2$, and $f'(0)=0$, but there is neither a maximum nor
minimum at $(0,0)$.

\begin{figure}[H]
	\centerline{\vbox{\beginpicture
			\normalgraphs
			%\ninepoint
			\setcoordinatesystem units <1.5truecm,0.75truecm>
			\setplotarea x from -1.5 to 1.5, y from -3.4 to 3.4
			\axis left shiftedto x=0 /
			\axis bottom shiftedto y=0 /
			\setquadratic
			\plot -1.500 -3.375 -1.425 -2.894 -1.350 -2.460 -1.275 -2.073 -1.200 -1.728
			-1.125 -1.424 -1.050 -1.158 -0.975 -0.927 -0.900 -0.729 -0.825 -0.562
			-0.750 -0.422 -0.675 -0.308 -0.600 -0.216 -0.525 -0.145 -0.450 -0.091
			-0.375 -0.053 -0.300 -0.027 -0.225 -0.011 -0.150 -0.003 -0.075 -0.000
			0.000 0.000 0.075 0.000 0.150 0.003 0.225 0.011 0.300 0.027
			0.375 0.053 0.450 0.091 0.525 0.145 0.600 0.216 0.675 0.308
			0.750 0.422 0.825 0.562 0.900 0.729 0.975 0.927 1.050 1.158
			1.125 1.424 1.200 1.728 1.275 2.073 1.350 2.460 1.425 2.894
			1.500 3.375 /
			\endpicture}}
	\caption{No maximum or minimum even though the derivative is zero. \label{fig:non extremum}}
\end{figure}

Since the derivative is zero or undefined at both local maximum and
local minimum points, we need a way to determine which, if either,
actually occurs. The most
elementary approach, but one that is often tedious or difficult, is to
test directly whether the $y$ coordinates ``near'' the potential
maximum or minimum are above or below the $y$ coordinate at the point
of interest. Of course, there are too many points ``near'' the point
to test, but a little thought shows we need only test two provided we
know that $f$ is continuous (recall that this means that the graph of
$f$ has no jumps or gaps).

Suppose, for example, that we have identified three points at which
$f'$ is zero or nonexistent: $\ds (x_1,y_1)$, $\ds (x_2,y_2)$, $\ds (x_3,y_3)$,
and $\ds x_1<x_2<x_3$ (see Figure~\ref{fig:testing for max and
	min}). Suppose that we compute the value of $f(a)$ for $\ds x_1<a<x_2$, and
that $\ds f(a)<f(x_2)$. What can we say about the graph between $a$ and
$\ds x_2$? Could there be a point $\ds (b,f(b))$, $\ds a<b<x_2$ with
$\ds f(b)>f(x_2)$? No: if there were, the graph would go up from
$(a,f(a))$ to $(b,f(b))$ then down to $\ds (x_2,f(x_2))$ and somewhere in
between would have a local maximum point. (This is not obvious; it is
a result of the Extreme Value Theorem.)
But at that local maximum
point the derivative of $f$ would be zero or nonexistent, yet we
already know that the derivative is zero or nonexistent only at $\ds x_1$,
$\ds x_2$, and $\ds x_3$. The upshot is that one computation tells us that
$\ds (x_2,f(x_2))$ has the largest $y$ coordinate of any point on the
graph near $\ds x_2$ and to the left of $\ds x_2$. We can perform the same
test on the right. If we find that on both sides of $\ds x_2$ the values
are smaller, then there must be a local maximum at $\ds (x_2,f(x_2))$; if
we find that on both sides of $\ds x_2$ the values are larger, then there
must be a local minimum at $\ds (x_2,f(x_2))$; if we find one of each,
then there is neither a local maximum or minimum at $\ds x_2$.

\begin{figure}[H]
	\centerline{\vbox{\beginpicture
			\normalgraphs
			%\ninepoint
			\setcoordinatesystem units <1.5truecm,1truecm>
			\setplotarea x from -1.5 to 1.5, y from -1.5 to 1.5
			\axis left shiftedto x=0 /
			\axis bottom shiftedto y=0 ticks withvalues
			{$x_1$} {$a$} {$b$} {$x_2$} {$x_3$} / at
			-1.3 -1 -0.5 0.5 1 / /
			\multiput {$\bullet$} at -1.3 0.5 -1 0.8 0.5 1.3 1 0.2 /
			\setquadratic
			\endpicture}}
	\caption{Testing for a maximum or minimum. \label{fig:testing for max and min}}
\end{figure}

It is not always easy to compute the value of a function at a
particular point. The task is made easier by the availability of
calculators and computers, but they have their own drawbacks---they do
not always allow us to distinguish between values that are very close
together. Nevertheless, because this method is conceptually simple and
sometimes easy to perform, you should always consider it.

\begin{example}{Simple Cubic}{simple cubic}
	Find all local maximum and minimum points for the function
	$\ds f(x)=x^3-x$.
\end{example}

\begin{solution}
	The derivative is $\ds f'(x)=3x^2-1$. This is defined
	everywhere and is zero at $\ds x=\pm \sqrt{3}/3$. Looking first at
	$\ds x=\sqrt{3}/3$, we see that $\ds f(\sqrt{3}/3)=-2\sqrt{3}/9$. Now we test
	two points on either side of
	$\ds x=\sqrt{3}/3$, choosing one point in the interval $(-\sqrt{3}/3,\sqrt{3}/3)$ and one point in the interval $(\sqrt{3}/3,\infty)$. Since
	$\ds f(0)=0>-2\sqrt{3}/9$
	and $\ds f(1)=0>-2\sqrt{3}/9$, there must be a local minimum at
	$\ds x=\sqrt{3}/3$. For $\ds x=-\sqrt{3}/3$, we see that
	$\ds f(-\sqrt{3}/3)=2\sqrt{3}/9$. This time we can use $x=0$ and $x=-1$,
	and we find that $\ds f(-1)=f(0)=0< 2\sqrt{3}/9$, so there must be a local
	maximum at $\ds x=-\sqrt{3}/3$.
\end{solution}

Of course this example is made very simple by our choice of points to
test, namely $x=-1$, $0$, $1$. We could have used other values, say
$-5/4$, $1/3$, and $3/4$, but this would have made the calculations
considerably more tedious, and we should always choose very simple points
to test if we can.

\begin{example}{Max and Min}{max and min}\label{max and min}
	Find all local maximum and minimum points for
	$f(x)=\sin x+\cos x$.
\end{example}

\begin{solution}
	The derivative is $f'(x)=\cos x-\sin x$. This is
	always defined and is zero whenever $\cos x=\sin x$. Recalling that
	the $\cos x$ and $\sin x$ are the $x$ and $y$ coordinates of points on
	a unit circle, we see that $\cos x=\sin x$ when $x$ is $\pi/4$,
	$\pi/4\pm\pi$, $\pi/4\pm2\pi$, $\pi/4\pm3\pi$, etc. Since both sine
	and cosine have a period of $2\pi$, we need only determine the status
	of $x=\pi/4$ and $x=5\pi/4$. We can use $0$ and $\pi/2$ to test the
	critical value $x= \pi/4$.
	We find that $\ds f(\pi/4)=\sqrt{2}$, $\ds f(0)=1<\sqrt{2}$ and $\ds f(\pi/2)=1$,
	so there is a local maximum when $x=\pi/4$ and also when
	$x=\pi/4\pm2\pi$, $\pi/4\pm4\pi$, etc. We can summarize this more
	neatly by saying that there are local maxima at $\pi/4\pm 2k\pi$ for
	every integer $k$.

	We use $\pi$ and $2\pi$ to test the critical value $x=5\pi/4$. The
	relevant values are $\ds f(5\pi/4)=-\sqrt2$, $\ds f(\pi)=-1>-\sqrt2$,
	$\ds f(2\pi)=1>-\sqrt2$, so there is a local minimum at $x=5\pi/4$,
	$5\pi/4\pm2\pi$, $5\pi/4\pm4\pi$, etc. More succinctly, there are
	local minima at $5\pi/4\pm 2k\pi$ for
	every integer $k$.
\end{solution}

\begin{example}{Max and Min}{maxminexampletwo}
	Find all local maximum and minimum points for $g\left( x\right) =x^{2/3}$.
\end{example}
\begin{solution}
	The derivative is $g^{\prime }\left( x\right) =\frac{2}{3}%
	x^{-1/3}. $ This is undefined when $x=0$ and is not equal to zero for any $x$
	in the domain of $g^{\prime }.$ Now we test two points on either side of $%
	x=0.$ We use $x=-1$ and $x=1.$ Since $g\left( 0\right) =0,$ $g\left(
	-1\right) =1>0$ and $g\left( 1\right) =1>0,$ there must be a local minimum
	at $x=0$.
\end{solution}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\Opensolutionfile{solutions}[ex]
\section*{Exercises for \ref{subsec:LocalExtremaSubsection}}

\begin{enumialphparenastyle}

Find all local maximum and minimum points $(x,y)$ by the method of this section.

%%%%%%%%%%
\begin{ex}
	$\ds y=x^2-x$
	\begin{sol}
		min at $x=1/2$
	\end{sol}
\end{ex}

%%%%%%%%%%
\begin{ex}
	$\ds y=2+3x-x^3$
	\begin{sol}
		min at $x=-1$, max at $x=1$
	\end{sol}
\end{ex}

%%%%%%%%%%
\begin{ex}
	$\ds y=x^3-9x^2+24x$
	\begin{sol}
		max at $x=2$, min at $x=4$
	\end{sol}
\end{ex}

%%%%%%%%%%
\begin{ex}
	$\ds y=x^4-2x^2+3$
	\begin{sol}
		min at $x=\pm 1$, max at $x=0$.
	\end{sol}
\end{ex}

%%%%%%%%%%
\begin{ex}
	$\ds y=3x^4-4x^3$
	\begin{sol}
		min at $x=1$
	\end{sol}
\end{ex}

%%%%%%%%%%
\begin{ex}
	$\ds y=(x^2-1)/x$
	\begin{sol}
		none
	\end{sol}
\end{ex}

%%%%%%%%%%
\begin{ex}
	$\ds y=3x^2-(1/x^2)$
	\begin{sol}
		none
	\end{sol}
\end{ex}

%%%%%%%%%%
\begin{ex}
	$y=\cos(2x)-x$
	\begin{sol}
		min at $x=7\pi/12+k\pi$, max at $x=-\pi/12+k\pi$, for integer $k$.
	\end{sol}
\end{ex}

%%%%%%%%%%%
%\begin{ex}
% $\ds f(x) =\cases{ x-1 & $x < 2$ \cr
%x^2 & $x\geq 2$\cr}$
%\begin{sol}
% none
%\end{sol}
%\end{ex}
%
% %%%%%%%%%%
%\begin{ex}
% $\ds f(x) =\cases{x-3 & $x < 3$ \cr
%x^3  & $3\leq x \leq 5$\cr
%1/x  &$x>5$\cr}$
%\begin{sol}
% local max at $x=5$
%\end{sol}
%\end{ex}

%%%%%%%%%%
\begin{ex}
	$\ds f(x) = x^2 - 98x + 4$
	%(Hint: Complete the square.)
	\begin{sol}
		local min at $x=49$
	\end{sol}
\end{ex}

%%%%%%%%%%%
%\begin{ex}
% $\ds f(x) =\cases{ -2 & $x = 0$ \cr
%1/x^2 &$x \neq 0$\cr}$
%\begin{sol}
% local min at $x=0$
%\end{sol}
%\end{ex}

%%%%%%%%%%
\begin{ex}
	For any real number $x$ there is a unique
	integer $n$ such that $n \leq x < n +1$, and the greatest
	integer\index{greatest integer} function is defined as $\ds\lfloor
	x\rfloor = n$. Where
	are the critical values of the greatest integer function?  Which are
	local maxima and which are local minima?
\end{ex}

%%%%%%%%%%
\begin{ex}
	Explain why the function $f(x) =1/x$ has no local
	maxima or minima.
\end{ex}

%%%%%%%%%%
\begin{ex}
	How many critical points can a quadratic polynomial function have?
	\begin{sol}
		one
	\end{sol}
\end{ex}

%%%%%%%%%%
\begin{ex}
	Show that a cubic polynomial can have at most two critical
	points. Give examples to show that a cubic polynomial can have zero,
	one, or two critical points.
\end{ex}

%%%%%%%%%%
\begin{ex}
	Explore the family of functions $\ds f(x) = x^3 + cx +1$ where $c$
	is a constant.  How many and what types of local extremes are there?
	Your answer should depend on the value of $c$, that is, different
	values of $c$ will give different answers.
\end{ex}

%%%%%%%%%%
\begin{ex}
	We generalize the preceding two questions. Let $n$ be a
	positive integer and let $f$ be a polynomial of degree $n$. How many
	critical points can $f$ have? (Hint: Recall the \dfont{Fundamental
		Theorem of Algebra},
	which says that a polynomial of degree $n$ has
	at most $n$ roots.)
\end{ex}

\end{enumialphparenastyle}


\documentclass[letterpaper]{article}

\usepackage{fullpage}
\usepackage{nopageno}
\usepackage{amsmath}
\usepackage{amssymb}
\allowdisplaybreaks

\newcommand{\abs}[1]{\left\lvert #1 \right\rvert}

\begin{document}
\title{Notes}
\date{September 12, 2014}
\maketitle
\section*{assignment}
\subsection*{1.4 \#16}
$[a]\in\mathbb{Z}_n$. $[a]$ is nilpotent if $[a]^k=0$ for some $k\ge 1$. zero is always nilpotent. show that $\mathbb{Z}_n$ has no nonzero nilpotents iff n has no factor that is a square. if n has no square factors then the prime factorization consists of distinct primes to the power of one only.
\subsubsection*{proof}
$\Rightarrow$

Assume that $\mathbb{Z}_n$ has no nonzero nilpotents. by contradiction assume that there exists some prime p such that $p^2|n$. write $n=p_1^{\alpha_1}p_2^{\alpha_2}\dots p_t^{\alpha_t}$ at least one $\alpha_i\ge1$. choose $a=p_1p_2\dots p_t$. then $[a]^{\max\alpha}=[0]$. and $[a]\ne0$, contradiction because $n|a$ so n is square free.

$\Leftarrow$
assume $n=p_1p_2\dots p_t$ $\forall p_i$ are distinct.
take $[a]\in\mathbb{Z}_n$ andd assume $[a]^k=[0]$.
then $n|a^k$ and $p_1p_2\dots p_t|a^k$. $\forall p_i, p_i|a^k$.
For every $i$ $p_i|a$ therefore $p_1p_2\dots p_t|a$ and $n|a$ so $[a]=[0]$.
\section*{last time}
$[a]_n$ is invertible iff $(a,n)=1$
a non-zero element of $\mathbb{Z}_n$ is either invertible or a zero-divisor

\subsubsection*{proof}
let $[a]_n\in\mathbb{Z}_n, n\not\vert a$. if $(n,a)=1$ thne $[a]_n$ is invertible. if $(n,a)=d>1$ then $[a]_n[\frac{n}{d}]=[0]_n$ because $a\frac{n}{d}=\frac{a}{d}n$ so $a\frac{n}{d}$ is a multiple of n. $d>1\to d\ne0$.
\subsection*{consequence}
the following are equivalent:
\begin{enumerate}
\item
n  is prime
\item
$[0]$ is the only zero divisor of $\mathbb{Z}_n$.
\item
every  nonzero element of $\mathbb{Z}_n$ is invertible.
\end{enumerate}
\subsubsection*{proof}
if $n$ prime, $(n,a)=1$ for $0<a<n$
\section*{euler function}
if $n\in\mathbb{Z}^+$ $\mathcal{P}(n)=$ the number of positive integers in $\{1,2,\dots,n\}$ that are relatively prime to $n$.
\subsection*{example}
$\mathcal{P}(6)=2$ (because 1 and 5).

observe $\mathcal{P}(n)$ is the number of invertible elements in $\mathbb{Z}_n$.
\subsubsection*{notation}
$\mathbb{Z}_n^*=\{[a]_n:[a]_n\text{ is invertible}\}$. so $\mathcal{P}(n)=|\mathbb{Z}_n^*|$
\subsection*{proposition}
$\mathbb{Z}_n^*$ is closed under multiplication.
\subsubsection*{proof}
let $[a]_n,[b]_n\in\mathbb{Z}_n^*$ then $[a]_n[a']_n=[1]$ and similarly $[b]_n[b']_n=[1]$

then $[a]_n[b]_n[a']_n[b']_n=[1]_n\quad\Box$
\section*{exercise}
if $n=p_1^{\alpha1}\dots p_t^{\alpha t},\alpha i\ge1$ distinct primes

\section*{eulers thm}
if $(a,n)=1$ then $a^{\mathcal{P}(n)}\equiv 1\mod n$.
\subsection*{proof}
$\mathbb{Z}_n^*=\{[a_1],[a_2],\dots,[a_{\mathcal{P}(n)}\}$. now consider $\{[aa_1],[aa_2],\dots,[aa_{\mathcal{P}(n)}\}\in\mathbb{Z}_n^*$. These are distinct elements.
\begin{align*}
  [aa_i]&=[aa_j]\text{ multiply by the inverse of a}\\
  [a]^{-1}[aa_i]&=[a]^{-1}[aa_j]\\
  [a_i]&=[a_j]
\end{align*}
so $\{[aa_1],[aa_2],\dots,[aa_{\mathcal{P}(n)}\}=\mathbb{Z}_n^*$

note that the two lists are permutations of eachother.

then $[a_1][a_2]\dots[a_n]=[aa_1][aa_2]\dots[aa_{\mathcal{P}(n)}]$
\end{document}


\section{Series}\label{sec:series}

While much more can be said about sequences, we now turn to our
principal interest, series. Recall that a series, roughly speaking, is
the sum of a sequence: If $\ds\{a_n\}_{n=0}^\infty$ is a sequence then the
associated series is
\[\sum_{i=0}^\infty a_n=a_0+a_1+a_2+\cdots\]
Associated with a series is a second sequence, called the {\dfont sequence of
  partial sums} $\ds\{s_n\}_{n=0}^\infty$:
\[s_n=\sum_{i=0}^n a_i.\]
So
\[s_0=a_0,\quad s_1=a_0+a_1,\quad s_2=a_0+a_1+a_2,\quad \ldots\]
A series converges\index{series!convergent}\index{convergent series}
if the sequence of partial sums converges, and otherwise the series
diverges\index{series!divergent}\index{divergent series}.

If $\{kx^n\}_{n=0}^{\infty}$ is a geometric sequence, then the associated series $\sum_{i=0}^{\infty}kx^i$ is called a geometric series.

\begin{theorem}{Geometric Series Convergence}{GeoSeriesConvergence}
If $|x|<1$, the geometric series $\ds\sum_i kx^i$ converges to $\ds\frac{k}{1-x}$, otherwise the series diverges (unless $k=0$).
\end{theorem}
\begin{proof}
If $\ds a_n=kx^n$, $\ds\sum_{n=0}^\infty a_n$ is called a
\dfont{geometric series}. A typical partial sum is
\[s_n=k+kx+kx^2+kx^3+\cdots+kx^n=k(1+x+x^2+x^3+\cdots+x^n).\]
We note that
\begin{align*}
  s_n(1-x)&=k(1+x+x^2+x^3+\cdots+x^n)(1-x) \\
  &=k(1+x+x^2+x^3+\cdots+x^n)1-k(1+x+x^2+x^3+\cdots+x^{n-1}+x^n)x \\
  &=k(1+x+x^2+x^3+\cdots+x^n-x-x^2-x^3-\cdots-x^n-x^{n+1}) \\
  &=k(1-x^{n+1}) \\
\end{align*}
so
\begin{align*}
  s_n(1-x)&=k(1-x^{n+1}) \\
  s_n&=k{1-x^{n+1}\over 1-x}. \\
\end{align*}
If $|x|<1$, $\ds\lim_{n\to\infty}x^n=0$ so
\[
  \lim_{n\to\infty}s_n=\lim_{n\to\infty}k{1-x^{n+1}\over 1-x}=
  k{1\over 1-x}.
\]
Thus, when $|x|<1$ the geometric series converges to $k/(1-x)$.
\end{proof}

When, for example, $k=1$ and $x=1/2$:
\[
  s_n={1-(1/2)^{n+1}\over 1-1/2}={2^{n+1}-1\over 2^n}=2-{1\over 2^n}
  \quad\hbox{and}\quad \sum_{n=0}^\infty {1\over 2^n} =
  {1\over 1-1/2} = 2.
\]
We began the chapter with the series
\[\sum_{n=1}^\infty {1\over 2^n},\]
namely, the geometric series without the first term $1$. Each partial
sum of this series is 1 less than the corresponding partial sum for
the geometric series, so of course the limit is also one less than the
value of the geometric series, that is,
\[\sum_{n=1}^\infty {1\over 2^n}=1.\]

It is not hard to see that the following theorem follows from
Theorem~\ref{thm:SequenceProperties}.

\begin{theorem}{Series are Linear}{SeriesLinear}
Suppose that $\ds\sum a_n$ and $\ds\sum b_n$ are convergent series,
and $c$ is a constant. Then

\begin{enumerate}
\item $\ds\sum ca_n$ is convergent and $\ds\sum ca_n=c\sum a_n$
\item $\ds\sum (a_n+b_n)$ is convergent and $\ds\sum (a_n+b_n)=\sum a_n+\sum b_n$.
\end{enumerate}
\end{theorem}

Note that when $c$ is non-zero, the converse of the first part of this theorem is also true. That is, if $\sum ca_n$ is convergent, then $\sum a_n$ is also convergent; if $\sum ca_n$ converges then $\frac{1}{c}\sum ca_n$ must converge.

On the other hand, the converse of the second part of the theorem is not true. For example, if $a_n=1$ and $b_n=-1$, then $\sum a_n+\sum b_n=\sum 0=0$ converges, but each of $\sum a_n$ and $\sum b_n$ diverges.

%The two parts of this theorem are subtly different. Suppose that $\sum
%a_n$ diverges; does $\sum ca_n$ also diverge if $c$ is non-zero? Yes:
%suppose instead that $\sum ca_n$ converges; then by the theorem, $\sum
%(1/c)ca_n$ converges, but this is the same as $\sum a_n$, which by
%assumption diverges. Hence $\sum ca_n$ also diverges. Note that we are
%applying the theorem with $a_n$ replaced by $ca_n$ and $c$ replaced by
%$(1/c)$.
%
%Now suppose that $\sum a_n$ and $\sum b_n$ diverge; does
%$\sum (a_n+b_n)$ also diverge? Now the answer is no: Let $a_n=1$ and
%$b_n=-1$, so certainly $\sum a_n$ and $\sum b_n$ diverge. But
%$\sum (a_n+b_n)=\sum(1+-1)=\sum 0 = 0$. Of course, sometimes
%$\sum (a_n+b_n)$ will also diverge, for example, if $a_n=b_n=1$, then
%$\sum (a_n+b_n)=\sum(1+1)=\sum 2$ diverges.

In general, the sequence of partial sums $\ds s_n$ is harder to understand
and analyze than the sequence of terms $\ds a_n$, and it is difficult
to determine whether series converge and if so to what. The following result
will let us deal with some simple cases easily.

\begin{theorem}{Divergence Test}{thm:DivergenceTest}
If $\ds\sum a_n$ converges then $\ds\lim_{n\to\infty}a_n=0$.
\end{theorem}
\begin{proof}
Since $\sum a_n$ converges, $\ds\lim_{n\to\infty}s_n=L$ and
$\ds\lim_{n\to\infty}s_{n-1}=L$, because this really says the same
thing but ``renumbers'' the terms. By Theorem~\ref{thm:SequenceProperties},
\[
  \lim_{n\to\infty} (s_{n}-s_{n-1})=
  \lim_{n\to\infty} s_{n}-\lim_{n\to\infty}s_{n-1}=L-L=0.
\]
But
\[
  s_{n}-s_{n-1}=(a_0+a_1+a_2+\cdots+a_n)-(a_0+a_1+a_2+\cdots+a_{n-1})
  =a_n,
\]
so as desired $\ds\lim_{n\to\infty}a_n=0$.
\end{proof}

This theorem presents an easy divergence test: Given a series $\sum
a_n$, if the limit $\ds\lim_{n\to\infty}a_n$ does not exist or has a value
other than zero, the series diverges. Note well that the converse is
\emph{not} true: If $\ds\lim_{n\to\infty}a_n=0$ then the series does
not necessarily converge.

\begin{theorem}{The $n$-th Term Test}{nthTermTestTheorem}
If $\ds\lim_{n\to\infty}a_n\neq 0$ or if the limit does not exist, then $\ds\sum a_n$ diverges.
\end{theorem}
\begin{proof}
Consider the statement of the theorem in contrapositive form:
\[\textbf{If }\ds\sum_{n=1}^{\infty}a_n\text{ converges, then }\lim_{n\to\infty}a_n=0.\]
If $s_n$ are the partial sums of the series, then the assumption that the series converges gives us
\[\ds\lim_{n\to\infty}s_n=s\]
for some number $s$. Then
\[\ds\lim_{n\to\infty}a_n=\lim_{n\to\infty}(s_n-s_{n-1})=\lim_{n\to\infty}s_n-\lim_{n\to\infty}s_{n-1}=s-s=0.\]
\end{proof}

\begin{example}{}{}
Show that $\ds\sum_{n=1}^\infty {n\over n+1}$ diverges.
\end{example}\
\begin{solution}
We compute the limit:
$$\lim _{n\to\infty}{n\over n+1}=1\not=0.$$
Looking at the first few terms perhaps makes it clear that the series
has no chance of converging:
$${1\over2}+{2\over3}+{3\over4}+{4\over5}+\cdots$$
will just get larger and larger; indeed, after a bit longer the series
starts to look very much like $\cdots+1+1+1+1+\cdots$, and of course
if we add up enough 1's we can make the sum as large as we desire.
\end{solution}

\begin{example}{Harmonic Series}{HarmonicSeries}
Show that $\ds\sum_{n=1}^\infty {1\over n}$ diverges.
\end{example}
\begin{solution}
Here the theorem does not apply: $\ds\lim _{n\to\infty} 1/n=0$, so it
looks like perhaps the series converges. Indeed, if you have the
fortitude (or the software) to add up the first 1000 terms you will find that
$$\sum_{n=1}^{1000} {1\over n}\approx 7.49,$$
so it might be reasonable to speculate that the series converges to
something in the neighborhood of 10. But in fact the partial sums do go
to infinity; they just get big very, very slowly. Consider the
following:

\hbox to \hsize{$\ds 1+{1\over 2}+{1\over 3}+{1\over 4} >
1+{1\over 2}+{1\over 4}+{1\over
  4} = 1+{1\over 2}+{1\over 2}$\hfill}

\hbox to \hsize{$\ds 1+{1\over 2}+{1\over 3}+{1\over 4}+
{1\over 5}+{1\over 6}+{1\over
    7}+{1\over 8} >
1+{1\over 2}+{1\over 4}+{1\over 4}+{1\over 8}+{1\over 8}+{1\over
    8}+{1\over 8} = 1+{1\over 2}+{1\over 2}+{1\over 2}$\hfill}

\hbox to \hsize{$\ds 1+{1\over 2}+{1\over 3}+\cdots+{1\over16}>
1+{1\over 2}+{1\over 4}+{1\over 4}+{1\over 8}+\cdots+{1\over
  8}+{1\over16}+\cdots +{1\over16} =1+{1\over 2}+{1\over 2}+{1\over
  2}+{1\over 2}$\hfill}
and so on. By swallowing up more and more terms we can always manage
to add at least another $1/2$ to the sum, and by adding enough of
these we can make the partial sums as big as we like. In fact, it's
not hard to see from this pattern that
$$1+{1\over 2}+{1\over 3}+\cdots+{1\over 2^n} > 1+{n\over 2},$$
so to make sure the sum is over 100, for example, we'd add
up terms until we get to around $\ds 1/2^{198}$, that is,
about $\ds 4\cdot 10^{59}$ terms. This series, $\sum (1/n)$, is called the
\dfont{harmonic series}.
\end{solution}

We will often make use of the fact that the first few (e.g. any finite number of) terms in a series are irrelevant when determining whether it will converge. In other words, $\sum_{n=0}^{\infty}a_n$ converges if and only if $\sum_{n=N}^{\infty}a_n$ converges for some $N\geq 1$.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\Opensolutionfile{solutions}[ex]
\section*{Exercises for \ref{sec:series}}

\begin{enumialphparenastyle}

\begin{ex}
Explain why $\ds\sum_{n=1}^\infty {n^2\over 2n^2+1}$
diverges.
\begin{sol}
$\ds\lim_{n\to\infty} n^2/(2n^2+1)=1/2$
\end{sol}
\end{ex}

\begin{ex}
Explain why $\ds\sum_{n=1}^\infty {5\over 2^{1/n}+14}$
diverges.
\begin{sol}
$\ds\lim_{n\to\infty} 5/(2^{1/n}+14)=1/3$
\end{sol}
\end{ex}

\begin{ex}
Explain why $\ds\sum_{n=1}^\infty {3\over n}$
diverges.
\begin{sol}
$\sum_{n=1}^\infty {1\over n}$ diverges, so $\ds\sum_{n=1}^\infty 3{1\over n}$ diverges
\end{sol}
\end{ex}

\begin{ex}
Compute $\ds\sum_{n=0}^\infty {4\over (-3)^n}- {3\over 3^n}$.
\begin{sol}
$-3/2$
\end{sol}
\end{ex}

\begin{ex}
Compute $\ds\sum_{n=0}^\infty {3\over 2^n}+ {4\over 5^n}$.
\begin{sol}
$11$
\end{sol}
\end{ex}

\begin{ex}
Compute $\ds\sum_{n=0}^\infty {4^{n+1}\over 5^n}$.
\begin{sol}
$20$
\end{sol}
\end{ex}

\begin{ex}
Compute $\ds\sum_{n=0}^\infty {3^{n+1}\over 7^{n+1}}$.
\begin{sol}
$3/4$
\end{sol}
\end{ex}

\begin{ex}
Compute $\ds\sum_{n=1}^\infty \left({3\over 5}\right)^n$.
\begin{sol}
$3/2$
\end{sol}
\end{ex}

\begin{ex}
Compute $\ds\sum_{n=1}^\infty {3^n\over 5^{n+1}}$.
\begin{sol}
$3/10$
\end{sol}
\end{ex}

\end{enumialphparenastyle}