\documentclass[12pt]{article}
\usepackage{stmaryrd}
\usepackage{amsfonts, amssymb, amsmath, comment}
\usepackage{times}
\usepackage{listings}
\usepackage{fancyhdr}
\usepackage{hyperref}
\usepackage{url}
%\usepackage{xypic}
%\usepackage{epsf}
%\usepackage{epsfig}
\usepackage{enumitem}
\usepackage{comment}

\usepackage{tikz}
\usetikzlibrary{arrows,automata,shapes.geometric}

\setlist[itemize]{nosep}
\setlist[enumerate]{nosep}

\setlength{\oddsidemargin}{0in}
\setlength{\evensidemargin}{0in}
\setlength{\textwidth}{6.5in}
\setlength{\textheight}{9.0in}
\setlength{\topmargin}{-0.5in}
\setlength{\headheight}{0in}
\parskip12pt
\parindent0pt
\pagestyle{fancy}
\lhead{CS 430 - Fall 2023}
\chead{CM A04}
\rhead{Due Friday, November 10, 11:59 PM EDT}
\cfoot{\normalfont\medskip Copyright \copyright 2023}

\newtheorem{DefinitionPlaceHolder}{Definition}
\newtheorem{DefinitionHoareTriple}[DefinitionPlaceHolder]{Definition}
\newtheorem{DefinitionSpecification}[DefinitionPlaceHolder]{Definition}
\newtheorem{DefinitionState}[DefinitionPlaceHolder]{Definition}
\newtheorem{DefinitionSatisfiedUnderPartialCorrectness}[DefinitionPlaceHolder]{Definition}

\newcommand{\rmp}{\reversemarginpar\marginpar}

\providecommand{\SolutionQuestionHoarePartA}{}
\providecommand{\SolutionQuestionHoarePartB}{}
\providecommand{\SolutionQuestionCorrectnessProvingCostBenefitPartA}{\vspace{9cm}}
\providecommand{\SolutionQuestionCorrectnessProvingCostBenefitPartB}{}
\providecommand{\SolutionQuestionCohesionAndCouplingPartA}{}
\providecommand{\SolutionQuestionCohesionAndCouplingPartB}{}
\providecommand{\SolutionQuestionCohesionAndCouplingExample}{}

%\newcommand\Fontviii{\fontsize{8}{7.2}\selectfont}
\newcommand\Fontix{\fontsize{9}{7.2}\selectfont}
%\newcommand\Fontxii{\fontsize{12}{7.2}\selectfont}
%\newcommand\Fontxv{\fontsize{15}{7.2}\selectfont}
\newcommand\Fontxii{\fontsize{12}{7.2}\selectfont}

\input xy
\xyoption{all}

\begin{document}

\begin{itemize}
\item{
Assignments should be completed individually.
}
\item{
No late assignments will be accepted.
}
\item{
Provide \textbf{concise} answers to the following questions.
Use \textbf{point form} whenever possible.
}
\item{
Submit your completed solutions to \textbf{Crowdmark}.
}
\end{itemize}

\begin{enumerate}

\item \label{QuestionHoare}
\begin{DefinitionHoareTriple} \label{DefinitionHoareTriple}
a \index{Hoare triple}\textbf{Hoare triple} is a triple $\llparenthesis P \rrparenthesis \ C \ \llparenthesis Q \rrparenthesis$ composed of
\begin{itemize}
\item{
$P$, a \textbf{precondition} (an assertion),
}
\item{
$C$, some code, and
}
\item{
$Q$, a \textbf{postcondition} (another assertion).
}
\end{itemize}
\end{DefinitionHoareTriple}

\begin{DefinitionSpecification} \label{DefinitionSpecification}
A \index{specification}\textbf{specification} of a program $C$ is a Hoare triple with $C$ as the middle element of the triple.
\end{DefinitionSpecification}

\begin{DefinitionSatisfiedUnderPartialCorrectness} \label{DefinitionSatisfiedUnderPartialCorrectness}
A Hoare triple is \index{satisfied under partial correctness}\textbf{satisfied under partial correctness} if, whenever execution starts in a \textbf{state} satisfying precondition $P$, and terminates, it follows that the \textbf{state} after execution satisfies postcondition $Q$.
\end{DefinitionSatisfiedUnderPartialCorrectness}

\begin{DefinitionState} \label{DefinitionState}
The \index{state}\textbf{state} of a program at a given moment is the list of the values of each of its variables at that moment.
\end{DefinitionState}

For each specification below, either
\begin{itemize}
\item{
Give an informal argument for why the specification is satisfied under partial correctness, or
}
\item{
Give an example of a starting state which demonstrates that the specification is \textbf{not} satisfied under partial correctness, and briefly explain why your choice is correct.
}
\end{itemize}
\begin{enumerate}
\item \label{QuestionHoarePartA}
$\llparenthesis 2+y \geq 4 \rrparenthesis$ \rmp{[4]}\\
\texttt{x = 2;}\\
$\llparenthesis x+y \geq 4 \rrparenthesis$
\SolutionQuestionHoarePartA

\newpage

\item \label{QuestionHoarePartB}
$\llparenthesis x+y \geq 4 \rrparenthesis$ \rmp{[4]}\\
\texttt{x = 2;}\\
$\llparenthesis 2+y \geq 4 \rrparenthesis$
\SolutionQuestionHoarePartB
\end{enumerate}

\newpage

\item{ \label{QuestionCorrectnessProvingCostBenefit}
It is mentioned in the Lecture Notes that \textbf{cost-benefit analysis} can be used to justify proving a software product is correct when human lives depend on correctness.
One ethically problematic point about this practice is that it requires assigning a dollar value to a human life.
In each of the following cases, assume that human lives depend on the correctness of the software product, and that your software professionals earn \$2000 / week.
\begin{enumerate}
\item \label{QuestionCorrectnessProvingCostBenefitPartA}
It \rmp{[2]}is estimated that a new software product will require $12$ person-weeks from a software professional for proving its correctness.
The IT team manager authorizes spending the time to prove this software product is correct.
What is the minimum dollar value of a human life in this cost-benefit analysis?
Show your work.
\SolutionQuestionCorrectnessProvingCostBenefitPartA

\item \label{QuestionCorrectnessProvingCostBenefitPartB}
It \rmp{[2]}is estimated that another new software product will require $15$ person-weeks from a software professional for proving its correctness.
The IT team manager does not authorize spending the time to prove this software product is correct.
What is the maximum dollar value of a human life in this cost-benefit analysis?
Show your work.
\SolutionQuestionCorrectnessProvingCostBenefitPartB
\end{enumerate}
}

\newpage

\item{ \label{QuestionCohesionAndCoupling}
In each part of this question, you will evaluate a software product, to assess the \textbf{cohesion} and \textbf{coupling} of its modules.
The software product computes the \textbf{mean}, \textbf{median} and \textbf{mode} of a set of examination scores.
Each software product is composed of two modules.
In each part of the question,
\begin{enumerate}[label=\roman*.]
\item{
state whether the modules described have \textbf{high} or \textbf{low} cohesion, and briefly justify your answer, and
}
\item{
state whether the pair of modules described have \textbf{loose} or \textbf{tight} coupling, and briefly justify your answer.
}
\end{enumerate}
\begin{enumerate}
\item
This \rmp{[4]}solution uses two classes, with the given properties/methods.
\begin{enumerate}
\item{
\texttt{list}
\begin{enumerate}
\item{
\texttt{property: mean}
}
\item{
\texttt{property: median}
}
\item{
\texttt{property: mode}
}
\end{enumerate}
}
\item{
\texttt{average-calculator(my-list)} \\
\begin{enumerate}
\item{
\begin{tabbing}
\texttt{method: compute}\=\texttt{-averages} \\
\> \texttt{/* return the triple } \\
\> \texttt{* (my-list.mean,my-list.median,my-list.mode)} \\
\> \texttt{*/}
\end{tabbing}
}
\end{enumerate}
}
\end{enumerate}
\Fontix
\begin{tikzpicture}
    \draw (0.5cm,0.5cm) -- (6cm,0.5cm) -- (6cm,3cm) -- (0.5cm,3cm) -- (0.5cm,0.5cm);
		\node[anchor=west] at (0.5cm,2.75cm) {\texttt{list}};
    \draw (6.5cm,0.5cm) -- (12cm,0.5cm) -- (12cm,3cm) -- (6.5cm,3cm) -- (6.5cm,0.5cm);
		\node[anchor=west] at (6.5cm,2.75cm) {\texttt{average-calculator}};
		\draw (6.75cm,1cm) -- (11.75cm,1cm) -- (11.75cm,2cm) -- (6.75cm,2cm) -- (6.75cm,1cm);
			\node[anchor=west] at (6.75cm,1.75cm) {\texttt{compute-averages}};
	\draw [- triangle 60, thick] (6.75cm,2cm) -- (1.5cm,2.75cm);
\end{tikzpicture}
\Fontxii
\SolutionQuestionCohesionAndCouplingPartA

\newpage

\item
This \rmp{[4]}solution uses two modules, with the given functions and descriptive comments.
\begin{enumerate}
\item{
\texttt{average-calculator-1}
\begin{enumerate}
\item{
\begin{tabbing}
\texttt{total-}\=\texttt{entries(alist)} \\
\> \texttt{/* sum all entries in alist by calling} \\
\> \texttt{* average-calculator-2.count-by-value(alist).} \\
\> \texttt{*/}
\end{tabbing}
}
\item{
\begin{tabbing}
\texttt{sort-}\=\texttt{entries(alist)} \\
\> \texttt{/* return the entries of alist sorted non-descending.} \\
\> \texttt{*/}
\end{tabbing}
}
\item{
\begin{tabbing}
\texttt{mode}\=\texttt{(alist)} \\
\> \texttt{/* return the mode of alist by calling} \\
\> \texttt{* average-calculator-2.count-by-value(alist),} \\
\> \texttt{* and returning a value with the highest count.} \\
\> \texttt{*/}
\end{tabbing}
}
\end{enumerate}
}
\item{
\texttt{average-calculator-2}
\begin{enumerate}
\item{
\begin{tabbing}
\texttt{count-}\=\texttt{items(alist)} \\
\> \texttt{/* return the number of items in alist.} \\
\> \texttt{*/}
\end{tabbing}
}
\item{
\begin{tabbing}
\texttt{count-}\=\texttt{by-value(alist)} \\
\> \texttt{/* return a list of pairs (value, count)} \\
\> \texttt{*/}
\end{tabbing}
}
\item{
\begin{tabbing}
\texttt{mean}\=\texttt{(alist)} \\
\> \texttt{/* compute the mean as the quotient} \\
\> \texttt{* average-calculator-1.total-entries(alist)} \\
\> \texttt{* over average-calculator-2.count-items(alist)} \\
\> \texttt{*/}
\end{tabbing}
}
\item{
\begin{tabbing}
\texttt{median}\=\texttt{(alist)} \\
\> \texttt{/* compute the median as the middle element} \\
\> \texttt{* or mean of the the middle two elements of} \\
\> \texttt{* average-calculator-1.sort-entries(alist)} \\
\> \texttt{*/}
\end{tabbing}
}
\end{enumerate}
}
\end{enumerate}
\Fontix
\begin{tikzpicture}
    \draw (0.5cm,0.5cm) -- (6cm,0.5cm) -- (6cm,7cm) -- (0.5cm,7cm) -- (0.5cm,0.5cm);
		\node[anchor=west] at (0.5cm,6.75cm) {\texttt{average-calculator-1}};
		\draw (0.75cm,1cm) -- (5.75cm,1cm) -- (5.75cm,2cm) -- (0.75cm,2cm) -- (0.75cm,1cm);
			\node[anchor=west] at (0.75cm,1.75cm) {\texttt{mode}};
		\draw (0.75cm,2.5cm) -- (5.75cm,2.5cm) -- (5.75cm,3.5cm) -- (0.75cm,3.5cm) -- (0.75cm,2.5cm);
			\node[anchor=west] at (0.75cm,3.25cm) {\texttt{sort-entries}};
		\draw (0.75cm,4cm) -- (5.75cm,4cm) -- (5.75cm,5cm) -- (0.75cm,5cm) -- (0.75cm,4cm);
			\node[anchor=west] at (0.75cm,4.75cm) {\texttt{total-entries}};
    \draw (6.5cm,0.5cm) -- (12cm,0.5cm) -- (12cm,7cm) -- (6.5cm,7cm) -- (6.5cm,0.5cm);
		\node[anchor=west] at (6.5cm,6.75cm) {\texttt{average-calculator-2}};
		\draw (6.75cm,1cm) -- (11.75cm,1cm) -- (11.75cm,2cm) -- (6.75cm,2cm) -- (6.75cm,1cm);
			\node[anchor=west] at (6.75cm,1.75cm) {\texttt{median}};
		\draw (6.75cm,2.5cm) -- (11.75cm,2.5cm) -- (11.75cm,3.5cm) -- (6.75cm,3.5cm) -- (6.75cm,2.5cm);
			\node[anchor=west] at (6.75cm,3.25cm) {\texttt{mean}};
		\draw (6.75cm,4cm) -- (11.75cm,4cm) -- (11.75cm,5cm) -- (6.75cm,5cm) -- (6.75cm,4cm);
			\node[anchor=west] at (6.75cm,4.75cm) {\texttt{count-by-value}};
		\draw (6.75cm,5.5cm) -- (11.75cm,5.5cm) -- (11.75cm,6.5cm) -- (6.75cm,6.5cm) -- (6.75cm,5.5cm);
			\node[anchor=west] at (6.75cm,6.25cm) {\texttt{count-items}};
	\draw [- triangle 60, thick] (5.75cm,4.5cm) -- (6.75cm,4.5cm);
	\draw [- triangle 60, thick] (5.75cm,1.5cm) -- (6.75cm,4cm);
	\draw [- triangle 60, thick] (6.75cm,3.5cm) -- (5.75cm,4cm);
	\draw [- triangle 60, thick] (11.75cm,3cm) -- (12.25cm,3cm) -- (12.25cm,6cm) -- (11.75cm,6cm);
	\draw [- triangle 60, thick] (6.75cm,2cm) -- (5.75cm,2.5cm);
\end{tikzpicture}
\Fontxii
\SolutionQuestionCohesionAndCouplingPartB
\end{enumerate}
}

\newpage

\item \label{QuestionCohesionAndCouplingExample}
Give \rmp{[4]}an example of a pair of modules, \texttt{module-a} and \texttt{module-b}, such that
\begin{enumerate}[label=\roman*.]
\item{
each of \texttt{module-a} and \texttt{module-b} has \textbf{low} cohesion, and
}
\item{
the pair \texttt{module-a} and \texttt{module-b} has \textbf{loose} coupling.
}
\end{enumerate}
Briefly explain why your example is correct.
Note, your description does not need to be highly detailed; describing the functionalities of \texttt{module-a} and \texttt{module-b} in broad strokes will suffice.
\SolutionQuestionCohesionAndCouplingExample
\end{enumerate}

\end{document}