Skip to content
Snippets Groups Projects
Commit d3072fe1 authored by alicj's avatar alicj
Browse files
parents 88bd50bf 177f17c1
No related branches found
No related tags found
No related merge requests found
No preview for this file type
...@@ -69,8 +69,8 @@ TBD ...@@ -69,8 +69,8 @@ TBD
\begin{itemize} \begin{itemize}
\item Assignment 2 \item Assignment 2
\begin{itemize} \begin{itemize}
\item Part 1: February 12, 2018 \item \structure{Part 1: February 20, 2018}
\item Partner Files: February 18, 2018 \item \structure{Partner Files: February 26, 2018}
\item Part 2: March 2, 2018 \item Part 2: March 2, 2018
\end{itemize} \end{itemize}
...@@ -89,6 +89,72 @@ TBD ...@@ -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} \begin{frame}
\frametitle{Homework: Index Set} \frametitle{Homework: Index Set}
...@@ -101,6 +167,12 @@ list of values \texttt{B} and returns a list of indices where \texttt{B[i] = ...@@ -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 = \uncover<2->{$$\mbox{indexSet}(x, B) \equiv \{i : \mathbb{N} | i \in [0 .. |B|-1] \wedge B_i =
x : 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} \end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
...@@ -525,12 +597,13 @@ Output design pattern ...@@ -525,12 +597,13 @@ Output design pattern
{Hardware-Hiding Module} & ~ \\ {Hardware-Hiding Module} & ~ \\
\midrule \midrule
\multirow{6}{0.3\textwidth}{Behaviour-Hiding Module} & Input Format Module\\ \multirow{6}{0.3\textwidth}{Behaviour-Hiding Module} & Input Parameters Module\\
& Input Parameters Module\\
& Output Format Module\\ & Output Format Module\\
& Output Verification Module\\
& Temperature ODEs Module\\ & Temperature ODEs Module\\
& Energy Equations Module\\ & Energy Equations Module\\
& Control Module\\ & Control Module\\
& Specification Parameters Module\\
\midrule \midrule
\multirow{3}{0.3\textwidth}{Software Decision Module} & {Sequence Data Structure Module}\\ \multirow{3}{0.3\textwidth}{Software Decision Module} & {Sequence Data Structure Module}\\
...@@ -539,8 +612,8 @@ Output design pattern ...@@ -539,8 +612,8 @@ Output design pattern
\bottomrule \bottomrule
\end{tabular} \end{tabular}
\caption{Module Hierarchy} %\caption{Module Hierarchy}
\label{TblMH} %\label{TblMH}
\end{table} \end{table}
\end{frame} \end{frame}
...@@ -567,14 +640,15 @@ Output design pattern ...@@ -567,14 +640,15 @@ Output design pattern
\begin{frame} \begin{frame}
\frametitle{Example Modules from SWHS} \frametitle{Example Modules from SWHS}
\textbf{Input Verification Module} \textbf{Input Parameters Module}
\begin{description} \begin{description}
\item[Secrets:] The rules for the physical and software constraints. \item[Secrets:] The data structure for input parameters, how the
\item[Services:] Verifies that the input parameters comply with physical and values are input and how the values are verified. The load and verify secrets
software constraints. Throws an error if a parameter violates a physical are isolated to their own access programs (like submodules). This, combined
constraint. Throws a warning if a parameter violates a software constraint. with the fact that all of the services are invoked together, suggests that the
\item[Implemented By:] SWHS one module one secret rule can be relaxed here.
\item[Services:] ...
\end{description} \end{description}
\end{frame} \end{frame}
...@@ -602,7 +676,7 @@ Output design pattern ...@@ -602,7 +676,7 @@ Output design pattern
\frametitle{SWHS Uses Hierarchy} \frametitle{SWHS Uses Hierarchy}
\begin{center} \begin{center}
\includegraphics[scale=0.55]{UsesHierarchy.pdf} \includegraphics[scale=0.55]{../Figures/RevisedHierarchy.pdf}
\end{center} \end{center}
\end{frame} \end{frame}
......
\frametitle{SWHS Uses Hierarchy}
\begin{center}
\includegraphics[scale=0.55]{UsesHierarchy.pdf}
\end{center}
File deleted
...@@ -292,7 +292,6 @@ class TestCircles: ...@@ -292,7 +292,6 @@ class TestCircles:
\end{itemize} \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. } \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} \end{itemize}
\begin{lstlisting}[language=Python, escapechar=!] \begin{lstlisting}[language=Python, escapechar=!]
>>> 1.0001 == approx(1) >>> 1.0001 == approx(1)
...@@ -304,7 +303,6 @@ True ...@@ -304,7 +303,6 @@ True
\end{lstlisting} \end{lstlisting}
\end{frame} \end{frame}
\begin{frame}[fragile] \begin{frame}[fragile]
\frametitle{Redundant code in tests} \frametitle{Redundant code in tests}
\begin{lstlisting}[language=Python, escapechar=!] \begin{lstlisting}[language=Python, escapechar=!]
...@@ -319,7 +317,7 @@ class TestCircles: ...@@ -319,7 +317,7 @@ class TestCircles:
def test_xcoord_are_not_equal(self): def test_xcoord_are_not_equal(self):
!\colorbox{yellow}{circle = CircleT(1,2,3)}! !\colorbox{yellow}{circle = CircleT(1,2,3)}!
assert circle.xcoord() != 1 assert not circle.xcoord() == 1
\end{lstlisting} \end{lstlisting}
\end{frame} \end{frame}
...@@ -341,7 +339,7 @@ class TestCircles: ...@@ -341,7 +339,7 @@ class TestCircles:
assert self.circle.xcoord() == 1 assert self.circle.xcoord() == 1
def test_xcoord_are_not_equal(self): def test_xcoord_are_not_equal(self):
assert self.circle.xcoord() != 2 assert not self.circle.xcoord() == 2
\end{lstlisting} \end{lstlisting}
\end{frame} \end{frame}
...@@ -380,8 +378,8 @@ class TestCircles: ...@@ -380,8 +378,8 @@ class TestCircles:
import pytest import pytest
def test_zero_division(): def test_zero_division():
with pytest.raises(ZeroDivisionError): with pytest.raises(ZeroDivisionError):
1 / 0 1 / 0
\end{lstlisting} \end{lstlisting}
\end{frame} \end{frame}
......
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