-
Sepehr Bayat authoredSepehr Bayat authored
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
T4.tex 12.49 KiB
% 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
\item Interface connects two system/modules, like a touch screen between people and phone
\item Implementation and Interface are separated, no matter how the code changes, the output should always be the same
\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, uses mathematical language
\item Implementation details are not included in the MIS
\item MIS uses mathematical language for its preciseness, which means that it is helpful to learn discrete math from the last tutorial
\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
new PointT & 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}
None
\end{frame}
% --------------------------------------------------
\begin{frame}
\frametitle{Point ADT Module}
\textbf{Access Routine Semantics}\\
PointT($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{Except.}\\
%\hline
%init & \multirow{2}{*}{Note 1} & Triangle & \\ \cline{1-3}
\hline
new TriangleT & PointT, PointT, PointT&TriangleADT & ~\\
\hline
sides & & seq[3] of real &~\\
\hline
inequality\char`_theorem & ~ & boolean & LINE~\\
\hline
perimeter\char`_of\char`_triangle & & real & LINE ~\\
\hline
area\char`_of\char`_triangle & & real & LINE ~\\
\hline
\end{tabular}
\end{frame}
% --------------------------------------------------
\begin{frame}
\textbf{Semantics}
State Variables:
$p1$: PointT\\
$p2$: PointT\\
$p3$: PointT\\
~\newline
\textbf{State Invariant}
None
~\newline
\textbf{Assumptions}
None
\end{frame}
% --------------------------------------------------
\begin{frame}
\textbf{Access Routine Semantics}\\
new TriangleT($a, b, c$):
\begin{itemize}
\item transition: $p1, p2, p3 := a, b, c$
\item output: $out := \mathit{self}$
\item exception: none
\end{itemize}
\noindent sides():
\begin{itemize}
\item output: $out := [p1.dist(p2), p1.dist(p3), p2.dist(p3)]$
\item exception: none
\end{itemize}
\end {frame}
% --------------------------------------------------
\begin {frame}
\noindent inequality\_theorem():
\begin{itemize}
\item output:
$out := ((self.sides[0] + self.slide[1]) > self.sides[2]$
$\wedge (self.sides[1] + self.slide[2]) > self.sides[0]$
$\wedge (self.sides[0] + self.slide[2]) > self.sides[1]$)
\item exception:
\\ $ex := ((p1.xcoord()==p2.xcoord() ==p3.xcoord()$ $\vee$
\\ $p1.ycoord()==p2.ycoord() ==p3.ycoord())$ $\Rightarrow \mbox{LINE})$
\end{itemize}
\end{frame}
% --------------------------------------------------
\begin{frame}
\noindent perimeter\_of\_triangle($ $):
\begin{itemize}
\item output: $$out := self.sides[0]+self.sides[1]+self.sides[2]$$
\item exception:
\\ ex := ((p1.xcoord()==p2.xcoord() ==p3.xcoord() $\vee$
\\ p1.ycoord()==p2.ycoord() ==p3.ycoord()) $\Rightarrow \mbox{LINE})$
\end{itemize}
\noindent area of triangle($ $):
\begin{itemize}
\item output : $out :=$
${\sqrt[2]{P/2(P/2-self.sides[0])(P/2-self.sides[1])(P/2-self.sides[2])}}$
\item exception:
\\ ex := ((p1.xcoord()==p2.xcoord() ==p3.xcoord() $\vee$
\\ p1.ycoord()==p2.ycoord() ==p3.ycoord()) $\Rightarrow \mbox{LINE})$
\end{itemize}
\textbf{Local Function}\\
P := perimeter\_of\_triangle( )
\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}