diff --git a/Lectures/L17_MG/MG.pdf b/Lectures/L17_MG/MG.pdf index 9ea4189f7e882e409ba3981fdc712d8b1fd2d1fb..95d29d150220a3c7e774cdb1a4417d1231101b0b 100644 Binary files a/Lectures/L17_MG/MG.pdf and b/Lectures/L17_MG/MG.pdf differ diff --git a/Lectures/L17_MG/MG.tex b/Lectures/L17_MG/MG.tex index e5058487a7b09afcb73e54810fd31c9f4bf09561..52b51b140d0244bad7f1865bf03d60b7f150fb34 100755 --- a/Lectures/L17_MG/MG.tex +++ b/Lectures/L17_MG/MG.tex @@ -69,8 +69,8 @@ TBD \begin{itemize} \item Assignment 2 \begin{itemize} -\item Part 1: February 12, 2018 -\item Partner Files: February 18, 2018 +\item \structure{Part 1: February 20, 2018} +\item \structure{Partner Files: February 26, 2018} \item Part 2: March 2, 2018 \end{itemize} @@ -89,6 +89,72 @@ TBD %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\begin{frame}[fragile] +\frametitle{And Series} + +\structure<1>{Write a function \texttt{forall(A)} that takes a list of boolean values +\texttt{A} and returns $\forall ( i:\mathbb{N} | i \in [0 ..|A|-1] : A_i)$} + +\begin{verbatim} +def forall(A): + return reduce(?, A, ?) + +print(forall([True, True, True, True])) +print(forall([True, True, True, False])) +\end{verbatim} + +\uncover<2->{\texttt{reduce(lambda x, y: x and y, A, True)}} +\end{frame} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\begin{frame}[fragile] +\frametitle{Contains} + +\structure<1>{Write a function \texttt{contains(x, xs)} that takes a value \texttt{x} and a +list of values \texttt{xs} and returns $\exists ( y | y \in xs : y = x)$} + +\begin{verbatim} +def contains(x, xs): + return reduce(func?, seq?, False) + +adjectives = ["lazy", "grouchy", "scheming"] + +print(contains(4, [3, 4, 5, 6, 8])) +print(contains("happy", adjectives)) + +\end{verbatim} + +\uncover<2->{\texttt{reduce(lambda a, b: a or b, [y==x for y in xs], False)}} + +\end{frame} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\begin{frame}[fragile] +\frametitle{Connection Between FP Topics} + +\begin{itemize} +\item List comprehensions can be implemented by maps and filters +\item All list comprehensions can be implemented via for loops +\item Not all for loops can be implemented by a list comprehension +\item Details + \href{http://treyhunner.com/2015/12/python-list-comprehensions-now-in-color/} +{here} +\end{itemize} + +\begin{verbatim} +N = range(10) +dbl = lambda n: n*2 +odd = lambda n: n%2==1 +list(map(dbl, filter(odd, N))) +# versus +[n * 2 for n in N if n % 2 == 1] +\end{verbatim} +\end{frame} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + \begin{frame} \frametitle{Homework: Index Set} @@ -101,6 +167,12 @@ list of values \texttt{B} and returns a list of indices where \texttt{B[i] = \uncover<2->{$$\mbox{indexSet}(x, B) \equiv \{i : \mathbb{N} | i \in [0 .. |B|-1] \wedge B_i = x : i\}$$}\\ +\uncover<3->{\texttt{def indexSet(x, B):}}\\ +\uncover<3->{\structure<3>{\texttt{~~~~~return [i for i in ? if ?]}}}\\ +\uncover<4->{\structure<4->{\texttt{~~~~~return [i for i in range(len(B)) if + B[i]==x]}}}\\ +~\\ +\uncover<4->{See the range function example on 2017 midterm} \end{frame} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -525,12 +597,13 @@ Output design pattern {Hardware-Hiding Module} & ~ \\ \midrule -\multirow{6}{0.3\textwidth}{Behaviour-Hiding Module} & Input Format Module\\ -& Input Parameters Module\\ +\multirow{6}{0.3\textwidth}{Behaviour-Hiding Module} & Input Parameters Module\\ & Output Format Module\\ +& Output Verification Module\\ & Temperature ODEs Module\\ & Energy Equations Module\\ & Control Module\\ +& Specification Parameters Module\\ \midrule \multirow{3}{0.3\textwidth}{Software Decision Module} & {Sequence Data Structure Module}\\ @@ -539,8 +612,8 @@ Output design pattern \bottomrule \end{tabular} -\caption{Module Hierarchy} -\label{TblMH} +%\caption{Module Hierarchy} +%\label{TblMH} \end{table} \end{frame} @@ -567,14 +640,15 @@ Output design pattern \begin{frame} \frametitle{Example Modules from SWHS} -\textbf{Input Verification Module} +\textbf{Input Parameters Module} \begin{description} -\item[Secrets:] The rules for the physical and software constraints. -\item[Services:] Verifies that the input parameters comply with physical and - software constraints. Throws an error if a parameter violates a physical - constraint. Throws a warning if a parameter violates a software constraint. -\item[Implemented By:] SWHS +\item[Secrets:] The data structure for input parameters, how the +values are input and how the values are verified. The load and verify secrets +are isolated to their own access programs (like submodules). This, combined +with the fact that all of the services are invoked together, suggests that the +one module one secret rule can be relaxed here. +\item[Services:] ... \end{description} \end{frame} @@ -602,7 +676,7 @@ Output design pattern \frametitle{SWHS Uses Hierarchy} \begin{center} -\includegraphics[scale=0.55]{UsesHierarchy.pdf} +\includegraphics[scale=0.55]{../Figures/RevisedHierarchy.pdf} \end{center} \end{frame} diff --git a/Lectures/L17_MG/MG.vrb b/Lectures/L17_MG/MG.vrb deleted file mode 100644 index 3fc0a1ca9a54582e16b4a6272a922c3b90c17256..0000000000000000000000000000000000000000 --- a/Lectures/L17_MG/MG.vrb +++ /dev/null @@ -1,7 +0,0 @@ - -\frametitle{SWHS Uses Hierarchy} - -\begin{center} -\includegraphics[scale=0.55]{UsesHierarchy.pdf} -\end{center} - diff --git a/Lectures/L17_MG/UsesHierarchy.pdf b/Lectures/L17_MG/UsesHierarchy.pdf deleted file mode 100644 index a229222f5284ff31b7e96c88ae67d0c2a012bd50..0000000000000000000000000000000000000000 Binary files a/Lectures/L17_MG/UsesHierarchy.pdf and /dev/null differ diff --git a/Tutorials/T05-PyUnit/slides/Unit Testing.tex b/Tutorials/T05-PyUnit/slides/Unit Testing.tex index 86232d9bcf8d138e6b97d3afad09d2c738f1d7a2..997ca72163f5ed5963b0d47d66eae828382fd4fa 100644 --- a/Tutorials/T05-PyUnit/slides/Unit Testing.tex +++ b/Tutorials/T05-PyUnit/slides/Unit Testing.tex @@ -292,7 +292,6 @@ class TestCircles: \end{itemize} \item{By default, \texttt{approx} considers numbers within a relative tolerance of 1e-6 and absolute tolerance of 1e-12 of its expected value to be equal. } - \end{itemize} \begin{lstlisting}[language=Python, escapechar=!] >>> 1.0001 == approx(1) @@ -304,7 +303,6 @@ True \end{lstlisting} \end{frame} - \begin{frame}[fragile] \frametitle{Redundant code in tests} \begin{lstlisting}[language=Python, escapechar=!] @@ -319,7 +317,7 @@ class TestCircles: def test_xcoord_are_not_equal(self): !\colorbox{yellow}{circle = CircleT(1,2,3)}! - assert circle.xcoord() != 1 + assert not circle.xcoord() == 1 \end{lstlisting} \end{frame} @@ -341,7 +339,7 @@ class TestCircles: assert self.circle.xcoord() == 1 def test_xcoord_are_not_equal(self): - assert self.circle.xcoord() != 2 + assert not self.circle.xcoord() == 2 \end{lstlisting} \end{frame} @@ -380,8 +378,8 @@ class TestCircles: import pytest def test_zero_division(): -with pytest.raises(ZeroDivisionError): -1 / 0 + with pytest.raises(ZeroDivisionError): + 1 / 0 \end{lstlisting} \end{frame}