From 21a9c6c139dbadb6047e4b8f06a14a8e560eb66e Mon Sep 17 00:00:00 2001 From: Sepehr Bayat <bayats1@mcmaster.ca> Date: Sun, 28 Jan 2018 12:38:29 -0500 Subject: [PATCH] Upload New File --- Tutorials/T04-A2Example/slides/T4.tex | 580 ++++++++++++++++++++++++++ 1 file changed, 580 insertions(+) create mode 100644 Tutorials/T04-A2Example/slides/T4.tex diff --git a/Tutorials/T04-A2Example/slides/T4.tex b/Tutorials/T04-A2Example/slides/T4.tex new file mode 100644 index 00000000..8abf50f4 --- /dev/null +++ b/Tutorials/T04-A2Example/slides/T4.tex @@ -0,0 +1,580 @@ +% Define Document Class +% Class Options Include: +% notes, notesonly, handout, trans, +% hidesubsections, shadesubsections, +% inrow, blue, red, grey, brown +%-------------------------------------------------------------------------- +\documentclass[xcolor=dvipsnames, shownotes, colorlinks]{beamer} +%-------------------------------------------------------------------------- + +% Define Package Theme +%-------------------------------------------------------------------------- +\usepackage{color} +\usepackage{multirow} +\usepackage[T1]{fontenc} +%% \usepackage{fix-cm} +\usepackage{hyperref} +\usepackage[utf8]{inputenc} +\usepackage[british]{babel} +\usepackage{tabularx} + +\hypersetup{ + urlcolor=cyan, + linkcolor=white +} +\usepackage{subfigure} +%% \usepackage{xspace} +\usepackage{} +\usepackage{enumerate} +\usetheme{Antibes} +\setbeamertemplate{sidebar}[right] +\usepackage{listings} % Code formatting +%% \usepackage{framed} +%% \usepackage{booktabs} +\usepackage{tabularx} +\usepackage{marvosym} +\usepackage{tikz} + +\usetikzlibrary{shapes} +\usetikzlibrary{arrows} +\usetikzlibrary{calc,positioning} + +\lstset{ + language=Python, + basicstyle=\ttfamily\scriptsize, + tabsize=2, + breaklines=true, + prebreak=\raisebox{0ex}[0ex][0ex]{\ensuremath{\hookleftarrow}}, + frame=single, + showstringspaces=true, + showspaces=false, + keywordstyle=\color{blue}, + stringstyle=\color{magenta}, + commentstyle=\color{ForestGreen}, + literate={\#}{{\textcolor{ForestGreen}{\#}}}1 {@}{{\textcolor{blue}{\MVAt}}}1 {\$}{\vdots}1 +} +%-------------------------------------------------------------------------- + +% Commands +%------------------------------------------------------------------------------ + +\newcommand*\oldmacro{}% +\let\oldmacro\insertshorttitle% +\renewcommand*\insertshorttitle{% + \oldmacro\hfill% + \insertframenumber\,/\,\inserttotalframenumber} + +% Figure Source +\usepackage[absolute,overlay]{textpos} + +\setbeamercolor{framesource}{fg=gray} +\setbeamerfont{framesource}{size=\tiny} + +\newcommand{\source}[1]{\begin{textblock*}{\paperwidth}(-5pt,\textheight) + \begin{beamercolorbox}[ht=0.5cm,right]{framesource} + \usebeamerfont{framesource}\usebeamercolor[fg]{framesource} Source: {#1} + \end{beamercolorbox} +\end{textblock*}} + +%------------------------------------------------------------------------------ + + +% Presentation Title Slide +%-------------------------------------------------------------------------- +\title{MIS Example} +\subtitle{CS 2ME3/SE 2AA4} +\author{Sepehr Bayat} +\institute{Department of Computing and Software\\ +McMaster University\\ } +\date{January 29} +%-------------------------------------------------------------------------- + + +% Document +% To add notes to the slides use: \note{} +% Add \section{} or \subsection{} for use in table of contents +%-------------------------------------------------------------------------- +\begin{document} + +% Create Title Slide +\begin{frame} +\maketitle +\end{frame} + +\section[Outline]{} +% Create Table of Contents Slide - Outline +\begin{frame} +\frametitle{Outline} + {\hypersetup{linkcolor=black} + \tableofcontents + } +\end{frame} + +\section{What is a module?} + +\begin{frame} + \frametitle{What is a module?} + \begin{itemize} \item A file with encapsulated code to implement a specific functionality + \item Ex: For designing a website with a login system, we may have a module that deals with logging out + \item A module comes with an "interface" + \item An interface includes things like functions and arguments of the function + \end{itemize} +\end{frame} + +% -------------------------------------------------- + + +% -------------------------------------------------- + +\begin{frame} + \frametitle{What is a MIS?} + \begin{itemize} \item Module Interface Specification + \item Specifices externally observable behaviour of a module + \item Not in language of implementation, but uses mathematical and application language + \item Internal implementations are not included in a MIS + \end{itemize} + +\end{frame} + +% -------------------------------------------------- + +% -------------------------------------------------- + +\section{MIS Template} +\begin{frame} + \frametitle{MIS Template Structure} + \begin{itemize} + \item Uses + \begin{itemize} + \item Imported constants, data types and access programs + \end{itemize} + \item Syntax + \begin{itemize} + \item Exported constants and types + \item Exported functions (access routine interface syntax) + \end{itemize} + \item Semantics + \begin{itemize} + \item State variables + \item State invariants + \item Assumptions + \item Access routine semantics + \item Local functions + \item Local types + \item Local constants + \item Considerations + \end{itemize} + \end{itemize} + +\end{frame} + +% -------------------------------------------------- + + + +% -------------------------------------------------- + +\section{Example} +\begin{frame} + \frametitle{Example } + Consider implementation of point on two dimensional plane + \begin{itemize} + \item Position P is represented by pair of real numbers (x,y) + \item A triangle is represented by three points + \item Considering we have three points in a 2D surface and we want to know the possibility of having a triangle with the three points and then calculate the perimeter and the area of the triangle. + + \end{itemize} + \end {frame} +% -------------------------------------------------- + +% -------------------------------------------------- +%\section{Example} +\begin{frame} + Consider the following triangle: + \begin{figure}[h] + \centering + \includegraphics[width=0.5\textwidth]{triangle.png} + \end{figure} + We are using the following inequality which is called inequality equation to know the possibility of having triangle with three points A, B and C: + +\end{frame} +% -------------------------------------------------- + +% -------------------------------------------------- +%\section{Example} +\begin{frame} + \begin{itemize} +\item $$ \mathrm{AB + AC < BC, AC + BC < AB, AB + BC < AC}$$ + \end{itemize} +We are calculating the perimeter of the triangle using the following formula: +\begin{itemize} +\item $$\mathrm {P = (AB+AC+BC)}$$ +\end{itemize} +We are using the Heron formula to calculate the area of the triangle: +\begin {itemize} +\item $$ \mathrm {\sqrt[2]{P/2(P/2-AB)(P/2-AC)(P/2-BC)}}$$ +\end{itemize} + + \end {frame} + +\subsection{Point ADT Module} + +\begin{frame} +\frametitle{Point ADT Module } + +\textbf{Template Module}\\ +pointADT +\newline + +\textbf{Uses}\\ +N/A +\newline + +\textbf{Syntax}\\ +Exported Types: +\newline +pointT = ? + +\end{frame} + +% -------------------------------------------------- + +\begin{frame} + +\textbf{Exported Access Programs}\\ +~\newline + +\begin{tabular}{| l | l | l | l |} +\hline +\textbf{Routine name} & \textbf{In} & \textbf{Out} & \textbf{Exceptions}\\ +\hline +init & real, real & pointT & ~\\ +\hline +xcoord & ~ & real & ~\\ +\hline +ycoord & ~ & real & ~\\ +\hline +dist & pointT & real & ~\\ +\hline +\end{tabular} + +\end{frame} + +% -------------------------------------------------- + +\begin{frame} + +\textbf{Semantics} + +State Variables: + +$xc$: real\\ +$yc$: real + +~\newline +\textbf{State Invariant} +None + +~\newline +\textbf{Assumptions} +init() is called for each abstract object before any other access routine is called for that object + + + + +\end{frame} + + +% -------------------------------------------------- + + +\begin{frame} + +\frametitle{Point ADT Module} + +\textbf{Access Routine Semantics}\\ + +init($x, y$): +\begin{itemize} +\item transition: $xc, yc := x, y$ +\item output: $out := \mathit{self}$ +\item exception: none +\end{itemize} + +\noindent xcoord(): +\begin{itemize} +\item output: $out := xc$ +\item exception: none +\end{itemize} + +\noindent ycoord(): +\begin{itemize} +\item output: $out := yc$ +\item exception: none +\end{itemize} + +\noindent dist($p$): +\begin{itemize} +\item output: $out := \sqrt{(\mathit{self}.xc - p.\mbox{xcoord()})^2 + (\mathit{self}.yc - p.\mbox{ycoord()})^2}$ + +\item exception: none +\end{itemize} + + + + +\end{frame} + + + +% -------------------------------------------------- + + +\begin{frame}[fragile] + +\frametitle{MIS Interface} + +From the MIS we can deduce the interface of the code will look like: + + \begin{lstlisting} + # Interface + class pointT: + + # Constructor + def __init__(self, x, y): + + # Selectors + def xcoord(self): + + def ycoord(self): + + def dist(self, p): + + \end{lstlisting} + + +\end{frame} + +% -------------------------------------------------- + +\begin{frame} + \frametitle{MIS Implementation} + \begin{center} + \textbf{See PointADT.py for implementation.}\\ + \end{center} + + + +\end{frame} + +% -------------------------------------------------- + + +% +% +% +% +% +% + +% -------------------------------------------------- + +\subsection{TriangleADT Module } +\begin{frame} + \frametitle{TriangleADT } + +\textbf{Template Module}\\ +TriangleADT +\newline + +\textbf{Uses}\\ +PointADT +\newline + +\textbf{Syntax}\\ +Exported Types: +\newline +TriangleADT = ?\\ +\end{frame} + +% -------------------------------------------------- + +\begin{frame} + +\textbf{Exported Access Programs}\\ +~\newline +\tabcolsep=0.09cm +\begin{tabular}{| l | l | l | l |} +\hline +\textbf{Routine name} & \textbf{In} & \textbf{Out} & \textbf{Exceptions}\\ +%\hline +%init & \multirow{2}{*}{Note 1} & Triangle & \\ \cline{1-3} +\hline +init & pointT,pointT,pointT&TriangleADT & ~\\ +\hline +sides & & &~\\ +\hline +inequality theorem & ~ & boolean & LINE~\\ +\hline +perimeter of triangle & & real & LINE ~\\ +\hline +area of triangle & & real & LINE ~\\ +\hline +\end{tabular} + +\end{frame} + +% -------------------------------------------------- + +\begin{frame} + +\textbf{Semantics} + +State Variables: + +$p1$: pointT\\ +$p2$: pointT\\ +$p3$: pointT\\ +$AB$: real\\ +$AC$ : real\\ +$BC$ : real\\ +~\newline +\textbf{State Invariant} +None + +~\newline +\textbf{Assumptions} +init() is called for each abstract object before any other access routine is called for that object + + + + +\end{frame} + + +% -------------------------------------------------- + +\begin{frame} + + +\textbf{Access Routine Semantics}\\ + +init($p1, p2, p3$): +\begin{itemize} +\item transition: $a, b, c := p1, p2, p3$ +\item output: $out := \mathit{self}$ +\item exception: none +\end{itemize} +\noindent sides(): +\begin{itemize} +\item transition: $AB, AC, BC := pointT.dist(self.a,self.b),$ +\\ $pointT.dist(slef.a,self.c), pointT.dist(self.b,self.c)$ +\item output: $out := \mathit{self}$ +\item exception: none +\end{itemize} +\end {frame} + + + + +\begin {frame} +\noindent inequality theorem(): +\begin{itemize} +\item output: $$out := \mathrm {(self.AB +self.AC > self.BC,and, self.AB+self.BC }$$ + $$ \mathrm {> self.AC, and, self.AC+self.BC >self.AB)}$$ +\item exception: +\\ ex := (self.a.xcoord()==self.b.xcoord() ==self.c.xcoord() or +\\ self.a.ycoord()==self.b.ycoord() ==self.c.ycoord()) $\Rightarrow \mbox{LINE})$ +\end{itemize} + + + +\end{frame} + + +% -------------------------------------------------- + +\begin{frame} +\noindent perimeter of triangle($ $): +\begin{itemize} +\item output: $$out := \mathrm{self.AB+self.AC+self.BC}$$ +\item exception: +\\ ex := (self.a.xcoord()==self.b.xcoord() ==self.c.xcoord() or +\\ self.a.ycoord()==self.b.ycoord() ==self.c.ycoord()) $\Rightarrow \mbox{LINE})$ + +\end{itemize} +\noindent area of triangle($ $): +\begin{itemize} +\item output : $$out :=\mathit {\sqrt[2]{P/2(P/2-self.AB)(P/2-self.AC)(P/2-self.BC)}}$$ +\item exception: +\\ ex := (self.a.xcoord()==self.b.xcoord() ==self.c.xcoord() or +\\ self.a.ycoord()==self.b.ycoord() ==self.c.ycoord()) $\Rightarrow \mbox{LINE})$ +\end{itemize} + +\textbf{Local Constants}\\ +P := self.AB+self.AC+self.BC + + + +\end{frame} + + + +% -------------------------------------------------- + + +\begin{frame}[fragile] + +\frametitle{MIS Interface} + +From the MIS we can deduce the interface of the code will look like: + + \begin{lstlisting} + # Interface + class TriangleADT: + + #Constructor + def __init__(self, p1, p2, p3): + + + #Selectors + def sides(self): + + def inequality theorem(self): + + def perimeter of triangle(self): + + def area of triangle(self): + + \end{lstlisting} + + +\end{frame} + +% -------------------------------------------------- + +\begin{frame} + \frametitle{MIS Implementation} + \begin{center} + \textbf{See TriangleADT for implementation.}\\ + \end{center} + + +\end{frame} + +% -------------------------------------------------- + + + +% ----------------------------------------------------- +\begin{frame} + \frametitle{Implementation files} + \begin{itemize} + \item Implementation files PointADT.py and TriangleADT.py can be found in the repo under Tutorial/T4/src + \end{itemize} + +\end{frame} + + + +\end{document} -- GitLab