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
\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}
......
\frametitle{SWHS Uses Hierarchy}
\begin{center}
\includegraphics[scale=0.55]{UsesHierarchy.pdf}
\end{center}
File deleted
......@@ -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}
......
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