Skip to content
Snippets Groups Projects
Commit 4d3a1460 authored by alicj's avatar alicj
Browse files

resolve issue #35

parents ed341150 3b3fe62a
No related branches found
No related tags found
No related merge requests found
No preview for this file type
......@@ -203,6 +203,8 @@ Don't have to doxygen test driver program.
Questions - rewrite isInBounds not assuming ascending
- why isInBounds for Data, not for CurveT?
- question about what is needed for cubic
- what is needed for regression?
- maybe add derivatives? integration?
......@@ -277,34 +279,41 @@ Questions - rewrite isInBounds not assuming ascending
\newpage
\section* {Curve Interpolation ADT Module}
\section* {Curve ADT Module}
\subsection*{Template Module}
CurveInterpADT
CurveADT
\subsection* {Uses}
SeqServicesModule for isAscending, interp1d and index
SeqServicesModule
\subsection* {Syntax}
\subsubsection* {Exported Constants}
MAX\_ORDER = 2
\subsubsection* {Exported Types}
CurveInterpT = ?
CurveT = ?
\subsubsection* {Exported Access Programs}
\begin{tabular}{| l | l | l | l |}
\begin{tabular}{| l | l | l | p{5cm} |}
\hline
\textbf{Routine name} & \textbf{In} & \textbf{Out} & \textbf{Exceptions}\\
\hline
new CurveInterpT & $X: \mathbb{R}^n$, $Y: \mathbb{R}^n$ & CurveInterpT & IndepVarNotAscending\\
new CurveT & $X: \mathbb{R}^n$, $Y: \mathbb{R}^n$, $i: \mathbb{N}$ &
CurveT & IndepVarNotAscending,\newline InvalidInterpOrder\\
\hline
minD & ~ & $\mathbb{R}$ & ~\\
\hline
maxD & ~ & $\mathbb{R}$ & ~\\
\hline
order & ~ & $\mathbb{N}$ & ~\\
\hline
eval & $x: \mathbb{R}$ & $\mathbb{R}$ & OutOfDomain\\
\hline
\end{tabular}
......@@ -315,6 +324,7 @@ eval & $x: \mathbb{R}$ & $\mathbb{R}$ & OutOfDomain\\
minx: $\mathbb{R}$\\
maxx: $\mathbb{R}$\\
o: $\mathbb{N}$\\
f: $\mathbb{R} \rightarrow \mathbb{R}$
\subsubsection* {State Invariant}
......@@ -323,17 +333,19 @@ None
\subsubsection* {Assumptions}
None
The user will not request function evaluations that would cause the
interpolation to select index values outside of where the function is defined.
\subsubsection* {Access Routine Semantics}
\noindent new CurveInterpT($X, Y$):
\noindent new CurveT($X, Y$):
\begin{itemize}
\item transition: $\mbox{minx}, \mbox{maxx}, f := X_0, X_{|X|-1}, (\lambda v:
\mbox{interp}(X, Y, v))$
\item transition: $\mbox{minx}, \mbox{maxx}, o, f := X_0, X_{|X|-1}, i, (\lambda v:
\mbox{interp}(X, Y, o, v))$
\item output: $out := \mbox{self}$
\item exception: $(\neg \mbox{isAscending}(X) \Rightarrow \mbox{IndepVarNotAscending})$
\item exception: $(\neg \mbox{isAscending}(X) \Rightarrow
\mbox{IndepVarNotAscending} | i \notin [1..\mbox{MAX\_ORDER}] \Rightarrow \mbox{InvalidInterpOrder})$
\end{itemize}
\noindent minD():
......@@ -348,6 +360,12 @@ None
\item exception: None
\end{itemize}
\noindent order():
\begin{itemize}
\item output: $out := \mbox{o}$
\item exception: None
\end{itemize}
\noindent eval($x$):
\begin{itemize}
\item output: $out := f(x)$
......@@ -356,9 +374,12 @@ None
\subsection*{Local Functions}
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)$\\
interp: $\mathbb{R}^n \times \mathbb{R}^n \times \mathbb{N} \times \mathbb{R}
\rightarrow \mathbb{R}$\\
\noindent interp($X$, $Y$, $o$, $v$) $$\equiv (o=1 \Rightarrow \mbox{interpLin}(X_i, Y_i,
X_{i+1}, Y_{i+1}, v) | o = 2 \Rightarrow \mbox{interpQuad}(X_{i-1}, Y_{i-1}, X_i, Y_i, X_{i+1},
Y_{i+1}, v) )$$ where $i = \mbox{index}(X, v)$\\
\newpage
......@@ -366,11 +387,11 @@ where $i = \mbox{index}(X, v)$\\
\subsection* {Module}
DataModule
Data
\subsection* {Uses}
CurveInterpT, SeqServicesModule for interp1d and index
CurveADT for CurveT, SeqServices for interpLin and index
\subsection* {Syntax}
......@@ -386,11 +407,11 @@ MAX\_SIZE = 10
\hline
Data\_init & ~ & ~ & ~\\
\hline
Data\_add & c: CurveInterpT, $z: \mathbb{R}$ & ~ & Full, IndepVarNotAscending\\
Data\_add & s: CurveT, $z: \mathbb{R}$ & ~ & Full, IndepVarNotAscending\\
\hline
eval & $x: \mathbb{R}, z: \mathbb{R}$ & ~ & ~\\
Data\_eval & $x: \mathbb{R}, z: \mathbb{R}$ & ~ & ~\\
\hline
slice & $x: \mathbb{R}$ & CurveInterpT & ~\\
Data\_slice & $x: \mathbb{R}$ & CurveT & ~\\
\hline
\end{tabular}
......@@ -399,12 +420,12 @@ slice & $x: \mathbb{R}$ & CurveInterpT & ~\\
\subsubsection* {State Variables}
$s$: sequence of CurveInterpT\\
$S$: sequence of CurveT\\
$Z$: sequence of $\mathbb{R}$
\subsubsection* {State Invariant}
$| s | \leq \mbox{MAX\_SIZE}$\\
$| S | \leq \mbox{MAX\_SIZE}$\\
$| Z | \leq \mbox{MAX\_SIZE}$
\subsubsection* {Assumptions}
......@@ -415,29 +436,29 @@ Data\_init() is called before any other access program.
Data\_init():
\begin{itemize}
\item transition: $s, Z := < >, <>$
\item transition: $S, Z := < >, <>$
\item exception: none
\end{itemize}
\noindent Data\_add($c, z$):
\noindent Data\_add($s, z$):
\begin{itemize}
\item transition: $s, Z := s || <c>, Z || <z>$
\item exception: $exc := (|s| = \mbox{MAX\_SIZE} \Rightarrow \mbox{Full} | z
\item transition: $S, Z := S || <s>, Z || <z>$
\item exception: $exc := (|S| = \mbox{MAX\_SIZE} \Rightarrow \mbox{Full} | z
\leq Z_{|Z|-1} \Rightarrow \mbox{IndepVarNotAscending})$
\end{itemize}
\noindent Data\_eval($x, z$):
\begin{itemize}
\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 output: $out := \mbox{interpLin}(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 Data\_slice($x$):
\begin{itemize}
\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
\item output: $out := \mbox{CurveT}(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}
......@@ -448,7 +469,7 @@ Data\_init():
\subsection* {Module}
SeqServicesModule
SeqServices
\subsection* {Uses}
......@@ -466,11 +487,15 @@ None
\hline
\textbf{Routine name} & \textbf{In} & \textbf{Out} & \textbf{Exceptions}\\
\hline
isAscending & $x: \mathbb{R}^n$ & $\mathbb{B}$ & ~\\
isAscending & $X: \mathbb{R}^n$ & $\mathbb{B}$ & ~\\
\hline
isInBounds & $x: \mathbb{R}^n, \mathbb{R}$ & $\mathbb{B}$ & ~\\
isInBounds & $X: \mathbb{R}^n, x: \mathbb{R}$ & $\mathbb{B}$ & ~\\
\hline
interpLin & $x_1: \mathbb{R}, y_1: \mathbb{R}, x_2: \mathbb{R}, y_2: \mathbb{R},
x: \mathbb{R}$ & $\mathbb{R}$ & ~\\
\hline
interp1d & $x_1: \mathbb{R}, y_1: \mathbb{R}, x_2: \mathbb{R}, y_2: \mathbb{R},
interpQuad & $ x_0: \mathbb{R}, y_0: \mathbb{R},
x_1: \mathbb{R}, y_1: \mathbb{R}, x_2: \mathbb{R}, y_2: \mathbb{R},
x: \mathbb{R}$ & $\mathbb{R}$ & ~\\
\hline
index & $X: \mathbb{R}^n, x: \mathbb{R}$ & $\mathbb{N}$ & ~\\
......@@ -495,9 +520,9 @@ None, unless noted with a particular access program
\subsubsection* {Access Routine Semantics}
\noindent isAscending($x$)
\noindent isAscending($X$)
\begin{itemize}
\item output: $out := \exists(i | i \in [0..|x|-2] : x_{i+1} \leq x_i)$
\item output: $out := \neg \exists(i | i \in [0..|X|-2] : X_{i+1} \leq X_i)$
\item exception: none
\end{itemize}
......@@ -507,12 +532,19 @@ None, unless noted with a particular access program
\item exception: none
\end{itemize}
\noindent interp1d($x_1, y_1, x_2, y_2, x$) \textit{\# assuming isAscending is True}
\noindent interpLin($x_1, y_1, x_2, y_2, x$) \textit{\# assuming isAscending is True}
\begin{itemize}
\item output: $out := \frac{(y_2 - y_1)}{(x_2-x_1)} (x - x_1) + y_1$
\item exception: none
\end{itemize}
\noindent interpQuad($x_0, y_0, x_1, y_1, x_2, y_2, x$) \textit{\# assuming isAscending is True}
\begin{itemize}
\item output: $out := y_1 + \frac{y_2 - y_0}{x_2-x_0} (x - x_1) + \frac{y_2 - 2 y_1 + y_0}{2
(x_2-x_1)^2} (x - x_1)^2$
\item exception: none
\end{itemize}
\noindent index($X, x$) \textit{\# assuming isAscending is True and isInBounds
is True}
\begin{itemize}
......
No preview for this file type
......@@ -386,7 +386,7 @@ Example of raising the exception
\begin{frame}
\frametitle{Quality Criteria}
\frametitle{Quality Criteria (H\&S Section 7.3.2)}
\begin{itemize}
\item Consistent
......
......@@ -25,4 +25,4 @@ class TestCircles:
assert self.circle.xcoord() == 1
def test_xcoord_are_not_equal(self):
assert not(self.circle.xcoord() != 1)
\ No newline at end of file
assert self.circle.xcoord() != 2
\ No newline at end of file
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