Created
September 14, 2010 20:58
-
-
Save alloy-d/579763 to your computer and use it in GitHub Desktop.
A section of a database systems homework that uses handy relational algebra commands.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
\documentclass[letterpaper]{article} | |
\usepackage{amsmath} | |
\usepackage{graphicx} | |
\usepackage{inconsolata} | |
%\pagestyle{empty} | |
%% About the assignment... | |
\newcommand{\name}{Adam Lloyd} | |
\newcommand{\class}{CSCI 4380} | |
\newcommand{\subdate}{14 Sep 2010} | |
\newcommand{\assignment}{Relational Algebra Examples} | |
%% The header: | |
\newcommand{\betterheader}{\begin{center}\Large\textbf{\class: | |
\assignment}\normalsize\\\vspace{1mm}\name\\\vspace{0.5mm}\subdate\end{center}\vspace{0.1mm}} | |
%% Question/answer headers: | |
\newcommand{\question}[1]{\vspace{0.6mm}\begin{flushleft}\large{\textbf{Question #1}}\end{flushleft}} | |
\newcommand{\answer}{\textbf{Answer: }} | |
%% Relational algebra helpers: | |
\newcommand{\select}[2]{\ensuremath{\sigma_{\mathrm{#1}}\left(#2\right)}} | |
\newcommand{\project}[2]{\ensuremath{\Pi_{\mathrm{#1}}\left(#2\right)}} | |
\newcommand{\join}[3]{\ensuremath{(#1)\bowtie_{\mathrm{#3}}(#2)}} | |
\newcommand{\naturaljoin}[2]{\ensuremath{(#1)\bowtie(#2)}} | |
\newcommand{\union}[2]{\ensuremath{(#1)\cup(#2)}} | |
\newcommand{\rename}[2]{\ensuremath{\rho_{#1}(#2)}} | |
\newcommand{\difference}[2]{\ensuremath{(#2)-(#1)}} | |
\begin{document} | |
\betterheader | |
%% Make item labels in enumerate look like (a), (b), etc. | |
\renewcommand{\labelenumi}{(\alph{enumi})} | |
\question{X} | |
\begin{enumerate} | |
\item \select{classroom='Low\;3051'}{class} | |
\item | |
\project{facultyRIN}{\select{positionName='Center\;Director'}{appointment}} | |
\item | |
\project{name}{\join{faculty}{\select{name='Computer\;Science'}{department}}{departmentCode=code}} | |
\item There is no clearly defined relationship between a class and a | |
department. If we choose say that a class is offered by a | |
department if the department code matches the subject code, then | |
the query is simply | |
$\project{name}{\join{department}{\select{subjectCode='CSCI'}{class}}{code=subjectCode}}$, | |
and it is rather silly. (This is explanation is consistent with my | |
understanding, but it is not suggested by the database schema.) | |
Alternatively, if we decide that a course is offered by a | |
department if one of that department's faculty teaches it, we get | |
\begin{align*} | |
C &:= \select{subjectCode='CSCI'}{class} \\ | |
F &:= \join{faculty}{C}{rin=instructorRIN} \\ | |
D &:= \join{department}{D}{code=departmentCode} \\ | |
result &:= \project{name}{F} | |
\end{align*} | |
but risk not considering cross-listed courses properly. | |
\item \begin{align*} | |
D &:= \select{departmentCode='ABCD'}{faculty} \\ | |
D\_RIN &:= \project{rin}{D} \\ | |
VP &:= \select{positionName='Vice\;President'}{appointment} \\ | |
VP\_RIN &:= \rename{S(rin)}{\project{facultyRIN}{VP}} \\ | |
result &:= \union{D\_RIN}{VP\_RIN} | |
\end{align*} | |
\item \begin{align*} | |
C &:= \select{semester='spring'\;AND\;year=2010}{class} \\ | |
FT\_RIN &:= \rename{S(rin)}{\project{instructorRIN}{C}} \\ | |
FNT\_RIN &:= \project{rin}{faculty} \\ | |
result &:= \difference{FT\_RIN}{FNT\_RIN} | |
\end{align*} | |
\end{enumerate} | |
\end{document} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment