Skip to content
Snippets Groups Projects
Commit ca882380 authored by Steven Palmer's avatar Steven Palmer
Browse files
parents 23348ab2 0bd993b3
No related branches found
No related tags found
No related merge requests found
No preview for this file type
......@@ -201,6 +201,13 @@ on the first deadline will be the ones that are graded.
Don't have to doxygen test driver program.
Questions - rewrite isInBounds not assuming ascending
- why isInBounds for Data, not for CurveT?
- maybe add derivatives? integration?
- explain index notation and notation for types
\begin{enumerate}
\item Your git repo will be organizes with the following directories at the
top level: {\tt A1}, {\tt A2}, {\tt A3}, and {\tt A4}.
......@@ -244,7 +251,7 @@ Don't have to doxygen test driver program.
\begin{itemize}
\item The exceptions in the specification should be implemented via Python
exceptions. Your exceptions should have exactly the same name as given in the
specification (FULL, EMPTY). Your exceptions should inherit from the
specification (Full, EMPTY). Your exceptions should inherit from the
Exception class and they should only be used with one argument, a string
explaining what problem has occurred.
\item For the Python implementation of the abstract module, your access programs
......@@ -270,21 +277,21 @@ Don't have to doxygen test driver program.
\newpage
\section* {Point ADT Module}
\section* {Curve Interpolation ADT Module}
\subsection*{Template Module}
pointADT
CurveInterpADT
\subsection* {Uses}
N/A
SeqServicesModule for isAscending, interp1d and index
\subsection* {Syntax}
\subsubsection* {Exported Types}
PointT = ?
CurveInterpT = ?
\subsubsection* {Exported Access Programs}
......@@ -292,204 +299,84 @@ PointT = ?
\hline
\textbf{Routine name} & \textbf{In} & \textbf{Out} & \textbf{Exceptions}\\
\hline
new PointT & real, real & PointT & ~\\
new CurveInterpT & $X: \mathbb{R}^n$, $Y: \mathbb{R}^n$ & CurveInterpT & IndepVarNotAscending\\
\hline
xcrd & ~ & real & ~\\
minD & ~ & $\mathbb{R}$ & ~\\
\hline
ycrd & ~ & real & ~\\
maxD & ~ & $\mathbb{R}$ & ~\\
\hline
dist & PointT & real & ~\\
eval & $x: \mathbb{R}$ & $\mathbb{R}$ & OutOfDomain\\
\hline
rot & real & ~ & ~\\
\hline
\end{tabular}
\subsection* {Semantics}
\subsubsection* {State Variables}
$xc$: real\\
$yc$: real
minx: $\mathbb{R}$\\
maxx: $\mathbb{R}$\\
f: $\mathbb{R} \rightarrow \mathbb{R}$
\subsubsection* {State Invariant}
None
\subsubsection* {Assumptions}
None
\subsubsection* {Access Routine Semantics}
new PointT ($x, y$):
\begin{itemize}
\item transition: $xc, yc := x, y$
\item output: $out := \mathit{self}$
\item exception: none
\end{itemize}
\noindent xcrd:
\begin{itemize}
\item output: $out := xc$
\item exception: none
\end{itemize}
\noindent ycrd:
\begin{itemize}
\item output: $out := yc$
\item exception: none
\end{itemize}
\noindent dist($p$):
\begin{itemize}
\item output:
$out := \sqrt{(xc - p.\mbox{xcrd()})^2 + (yc - p.\mbox{ycrd()})^2}$
\item exception: none
\end{itemize}
\noindent rot($\phi$):
\begin{itemize}
\item $\phi$ is in radians
\item transition:
$$\left [
\begin{array}{c}
xc\\
yc\\
\end{array}
\right ] :=
\left [
\begin{array}{r r}
\cos \phi & - \sin \phi\\
\sin \phi & \cos \phi\\
\end{array}
\right ]
\left [
\begin{array}{c}
xc\\
yc\\
\end{array}
\right ]
$$
\item exception: none
\end{itemize}
\newpage
\section* {Line Module}
\subsection* {Template Module}
lineADT
\subsection* {Uses}
pointADT
\subsection* {Syntax}
\subsubsection* {Exported Types}
LineT = ?
\subsubsection* {Exported Access Programs}
\begin{tabular}{| l | l | l | l |}
\hline
\textbf{Routine name} & \textbf{In} & \textbf{Out} & \textbf{Exceptions}\\
\hline
new LineT & PointT, PointT & LineT & ~\\
\hline
beg & ~ & PointT & ~\\
\hline
end & ~ & PointT & ~\\
\hline
len & ~ & real & ~\\
\hline
mdpt & ~ & PointT & ~\\
\hline
rot & real & ~ & ~\\
\hline
\end{tabular}
\subsection* {Semantics}
\subsubsection* {State Variables}
$b$: PointT\\
$e$: PointT
\subsubsection* {State Invariant}
None
\subsubsection* {Assumptions}
None
\subsubsection* {Access Routine Semantics}
\noindent new LineT ($p_1, p_2$):
\noindent new CurveInterpT($X, Y$):
\begin{itemize}
\item transition: $b, e := p_1, p_2$
\item output: $out := \mathit{self}$
\item exception: none
\end{itemize}
\item transition: $\mbox{minx}, \mbox{maxx}, f := X_0, X_{|X|-1}, (\lambda v:
\mbox{interp}(X, Y, v))$
\noindent beg:
\begin{itemize}
\item output: $out := b$
\item exception: none
\item output: $out := \mbox{self}$
\item exception: $(\neg \mbox{isAscending}(X) \Rightarrow \mbox{IndepVarNotAscending})$
\end{itemize}
\noindent end:
\noindent minD():
\begin{itemize}
\item output: $out := e$
\item exception: none
\item output: $out := \mbox{minx}$
\item exception: None
\end{itemize}
\noindent len:
\noindent maxD():
\begin{itemize}
\item output: $out := b.\mbox{dist}(e)$
\item exception: none
\item output: $out := \mbox{maxx}$
\item exception: None
\end{itemize}
\noindent mdpt:
\noindent eval($x$):
\begin{itemize}
\item output:
$$out := \mbox{new~} \mbox{PointT} (\mbox{avg}(b.\mbox{xcrd()},
e.\mbox{xcrd()}), \mbox{avg}(b.\mbox{ycrd()}, e.\mbox{ycrd()}))$$
\item exception: none
\item output: $out := f(x)$
\item exception: $(\neg(\mbox{minx} \leq x \leq \mbox{maxx}) \Rightarrow \mbox{OutOfDomain}))$
\end{itemize}
\noindent rot ($\phi$):
\begin{itemize}
\item $\phi$ is in radians
\item transition: $b.\mbox{rot}(\phi), e.\mbox{rot}(\phi)$
\item exception: none
\end{itemize}
\subsection*{Local Functions}
\subsubsection*{Local Functions}
avg: real $\times$ real $\rightarrow$ real
\noindent avg($x_1, x_2$) $\equiv \frac{x_1 + x_2}{2}$
interp: $\mathbb{R}^n \times \mathbb{R}^n \rightarrow \mathbb{R}$\\
interp($X$, $Y$, $v$) $\equiv \mbox{interp1d}(X_i, Y_i, X_{i+1}, Y_{i+1}, v)$
where $i = \mbox{index}(X, v)$\\
\newpage
\section* {Circle Module}
\section* {Data Module}
\subsection* {Template Module}
\subsection* {Module}
circleADT
DataModule
\subsection* {Uses}
pointADT, lineADT
CurveInterpT, SeqServicesModule for interp1d and index
\subsection* {Syntax}
\subsubsection* {Exported Types}
\subsubsection* {Exported Constants}
CircleT = ?
MAX\_SIZE = 10
\subsubsection* {Exported Access Programs}
......@@ -497,19 +384,13 @@ CircleT = ?
\hline
\textbf{Routine name} & \textbf{In} & \textbf{Out} & \textbf{Exceptions}\\
\hline
new CircleT & PointT, real & CircleT & ~\\
Data\_init & ~ & ~ & ~\\
\hline
cen & ~ & PointT & ~\\
Data\_add & c: CurveInterpT, $z: \mathbb{R}$ & ~ & Full, IndepVarNotAscending\\
\hline
rad & ~ & real & ~\\
\hline
area & ~ & real & ~\\
\hline
intersect & CircleT & boolean & ~\\
eval & $x: \mathbb{R}, z: \mathbb{R}$ & ~ & ~\\
\hline
connection & CircleT & LineT & ~\\
\hline
force & real $\rightarrow$ real & CircleT $\rightarrow$ real & ~\\
slice & $x: \mathbb{R}$ & CurveInterpT & ~\\
\hline
\end{tabular}
......@@ -518,83 +399,66 @@ force & real $\rightarrow$ real & CircleT $\rightarrow$ real & ~\\
\subsubsection* {State Variables}
$c$: PointT\\
$r$: real
$s$: sequence of CurveInterpT\\
$Z$: sequence of $\mathbb{R}$
\subsubsection* {State Invariant}
None
\subsubsection* {Assumptions}
None
$| s | \leq \mbox{MAX\_SIZE}$\\
$| Z | \leq \mbox{MAX\_SIZE}$
\subsubsection* {Access Routine Semantics}
\subsubsection* {Assumptions}
\noindent new CircleT ($\mathit{cin}, \mathit{rin}$):
\begin{itemize}
\item transition: $c, r := \mathit{cin}, \mathit{rin}$
\item output: $out := \mathit{self}$
\item exception: none
\end{itemize}
Data\_init() is called before any other access program.
\noindent cen:
\begin{itemize}
\item output: $out := c$
\item exception: none
\end{itemize}
\noindent rad:
\begin{itemize}
\item output: $out := r$
\item exception: none
\end{itemize}
\subsubsection* {Access Routine Semantics}
\noindent area:
Data\_init():
\begin{itemize}
\item output: $out := \pi r^2$
\item transition: $s, Z := < >, <>$
\item exception: none
\end{itemize}
\noindent intersect($ci$):
\noindent Data\_add($c, z$):
\begin{itemize}
\item output: $\exists ( p: \mbox{PointT} | \mbox{insideCircle}(p, ci) : \mbox{insideCircle}(p, \mathit{self}))$
\item exception: none
\item transition: $s, Z := s || <c>, Z || <z>$
\item exception: $exc := (|s| = \mbox{MAX\_SIZE} \Rightarrow \mbox{Full} | z
\leq Z_{|Z|-1} \Rightarrow \mbox{IndepVarNotAscending})$
\end{itemize}
\noindent connection($ci$):
\noindent Data\_eval($x, z$):
\begin{itemize}
\item output: $out := \mbox{new~} \mbox{LineT} (c, ci.\mathit{cen()})$
\item exception: none
\item output: $out := \mbox{interp1d}(z_j, s_j.\mbox{eval}(x), z_{j+1},
s_{j+1}.\mbox{eval}(x), z)$, where $j = \mbox{index}(Z, z)$
\item exception: $exc := (\neg \mbox{isInBounds}(Z, z) \Rightarrow \mbox{OutOfDomain})$
\end{itemize}
\noindent force($f$):
\noindent Data\_slice($x$):
\begin{itemize}
\item output: $out := \lambda x \rightarrow \mathit{self}.\mbox{area()} \cdot
x.\mbox{area()} \cdot f(\mathit{self}.\mbox{connection}(x).\mbox{len}())$
\item exception: none
\item output: $out := \mbox{CurveInterpT}(Z, Y)$, where
$Y = ||(i: \mathbb{N}| i \in [0 .. |Z|-1] : \langle s_i.\mbox{eval}(x) \rangle
)$ or $Y = \mbox{ map } \mbox{eval}(x) \mbox{ } s$ \textit{\# in both cases
there is an abuse of notation}
\item exception: None
\end{itemize}
\subsubsection*{Local Functions}
insideCircle: PointT $\times$ CircleT $\rightarrow$ boolean
\noindent insideCircle($p, c$) $\equiv p.\mbox{dist}(c.\mbox{cen()}) \leq c.\mbox{rad()}$
\newpage
%\subsubsection*{Local Functions}
\section* {Deque Of Circles Module}
\section* {Sequence Services Module}
\subsection* {Module}
DequeCircleModule
SeqServicesModule
\subsection* {Uses}
circleADT
None
\subsection* {Syntax}
\subsubsection* {Exported Constants}
MAX\_SIZE = 20
None
\subsubsection* {Exported Access Programs}
......@@ -602,29 +466,15 @@ MAX\_SIZE = 20
\hline
\textbf{Routine name} & \textbf{In} & \textbf{Out} & \textbf{Exceptions}\\
\hline
Deq\_init & ~ & ~ & ~\\
\hline
Deq\_pushBack & CircleT & ~ & FULL\\
\hline
Deq\_pushFront & CircleT & ~ & FULL\\
\hline
Deq\_popBack & ~ & ~ & EMPTY\\
\hline
Deq\_popFront & ~ & ~ & EMPTY\\
\hline
Deq\_back & ~ & CircleT & EMPTY\\
\hline
Deq\_front & ~ & CircleT & EMPTY\\
\hline
Deq\_size & ~ & integer & ~\\
isAscending & $x: \mathbb{R}^n$ & $\mathbb{B}$ & ~\\
\hline
Deq\_disjoint & ~ & boolean & EMPTY\\
isInBounds & $x: \mathbb{R}^n, \mathbb{R}$ & $\mathbb{B}$ & ~\\
\hline
Deq\_sumFx & real $\rightarrow$ real & real & EMPTY\\
interp1d & $x_1: \mathbb{R}, y_1: \mathbb{R}, x_2: \mathbb{R}, y_2: \mathbb{R},
x: \mathbb{R}$ & $\mathbb{R}$ & ~\\
\hline
Deq\_totalArea & ~ & real & EMPTY\\
\hline
Deq\_averageRadius & ~ & real & EMPTY\\
index & $X: \mathbb{R}^n, x: \mathbb{R}$ & $\mathbb{N}$ & ~\\
\hline
\end{tabular}
......@@ -632,107 +482,42 @@ Deq\_averageRadius & ~ & real & EMPTY\\
\subsection* {Semantics}
\subsubsection* {State Variables}
$s$: sequence of CircleT
None
\subsubsection* {State Invariant}
$| s | \leq \mbox{MAX\_SIZE}$
None
\subsubsection* {Assumptions}
Deq\_init() is called before any other access program.
None, unless noted with a particular access program
\subsubsection* {Access Routine Semantics}
Deq\_init():
\noindent isAscending($x$)
\begin{itemize}
\item transition: $s := < >$
\item output: $out := \exists(i | i \in [0..|x|-2] : x_{i+1} \leq x_i)$
\item exception: none
\end{itemize}
\noindent Deq\_pushBack($c$):
\begin{itemize}
\item transition: $s := s || <c>$
\item exception: $exc := (|s| = \mbox{MAX\_SIZE} \Rightarrow \mbox{FULL})$
\end{itemize}
\noindent Deq\_pushFront($c$):
\begin{itemize}
\item transition: $s := <c> || s $
\item exception: $exc := (|s| = \mbox{MAX\_SIZE} \Rightarrow \mbox{FULL})$
\end{itemize}
\noindent Deq\_popBack():
\begin{itemize}
\item transition: $s := s[0..|s| - 2]$
\item exception: $exc := (|s| = 0 \Rightarrow \mbox{EMPTY})$
\end{itemize}
\noindent Deq\_popFront():
\begin{itemize}
\item transition: $s := s[1..|s| - 1]$
\item exception: $exc := (|s| = 0 \Rightarrow \mbox{EMPTY})$
\end{itemize}
\noindent Deq\_back():
\noindent isInBounds($X, x$) \textit{\# assuming isAscending is True}
\begin{itemize}
\item output: $out := s[|s| - 1]$
\item exception: $exc := (|s| = 0 \Rightarrow \mbox{EMPTY})$
\end{itemize}
\noindent Deq\_front():
\begin{itemize}
\item output: $out := s[0]$
\item exception: $exc := (|s| = 0 \Rightarrow \mbox{EMPTY})$
\end{itemize}
\noindent Deq\_size():
\begin{itemize}
\item output: $out := | s |$
\item output: $out := X_0 \leq x \leq X_{|X|-1}$
\item exception: none
\end{itemize}
\noindent Deq\_disjoint():
\begin{itemize}
\item output $$out := \forall(i, j:\mathbb{N} | i \in [0 .. |s| -1] \wedge j \in [0 .. |s| -1] \wedge i \neq j:\neg
s[i].\mbox{intersect}(s[j]))$$
\item exception: $exc := (|s| = 0 \Rightarrow \mbox{EMPTY})$
\end{itemize}
\noindent Deq\_sumFx(f):
\noindent interp1d($x_1, y_1, x_2, y_2, x$) \textit{\# assuming isAscending is True}
\begin{itemize}
\item output $$out := +(i: \mathbb{N} | i \in ([1 .. |s|-1]):
\mbox{Fx}(f, s[i], s[0]))$$
\item exception: $exc := (|s| = 0 \Rightarrow \mbox{EMPTY})$
\end{itemize}
\noindent Deq\_totalArea():
\begin{itemize}
\item output $$out := ?$$ [The total area is the sum of the area of all of the
circles in the deque. You do not need to worry about overlap between
circles. The assignment asks you to provide the missing
equation, but you do not have to implement this access program.]
\item exception: $exc := (|s| = 0 \Rightarrow \mbox{EMPTY})$
\item output: $out := \frac{(y_2 - y_1)}{(x_2-x_1)} (x - x_1) + y_1$
\item exception: none
\end{itemize}
\noindent Deq\_averageRadius():
\noindent index($X, x$) \textit{\# assuming isAscending is True and isInBounds
is True}
\begin{itemize}
\item output $$out := ?$$ [The assignment asks you to provide the missing
equation, but you do not have to implement this access program.]
\item exception: $exc := (|s| = 0 \Rightarrow \mbox{EMPTY})$
\item output: $out := i \mbox{ such that } X_i \leq x \leq X_{i+1}$
\item exception: none
\end{itemize}
\subsubsection*{Local Functions}
Fx: (real $\rightarrow$ real) $\times$ CircleT $\times$ CircleT $\rightarrow$ real
\noindent Fx($f, ci, cj$) $\equiv \mbox{xcomp}(ci.\mbox{force}(f) (cj), ci, cj)$
~\newline
\noindent xcomp: real $\times$ CircleT $\times$ CircleT $\rightarrow$ real
~\newline
\noindent $$\mbox{xcomp}(F, ci, cj)
\equiv F \left [
\frac{ci.\mbox{cen()}.\mbox{xcrd()} -
cj.\mbox{cen()}.\mbox{xcrd()}} {ci.\mbox{connection}(cj).\mbox{len}()}
\right ]$$
\end {document}
No preview for this file type
......@@ -86,7 +86,7 @@ TBD
\item Midterm exam
\begin{itemize}
\item Wednesday, February 29, 7:00 pm
\item Wednesday, February 28, 7:00 pm
\item 90 minute duration
\item Multiple choice - 30--40 questions
\end{itemize}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment