\documentclass{article}
\usepackage{amsmath,amssymb}
\usepackage[margin=3cm]{geometry}
\usepackage{graphicx}
\usepackage{syntax}
\usepackage{dirtree}
\usepackage{longtable}
\usepackage{pgfplots}

\begin{document}

\title{\texttt{randexam}: Randomized Exam Generation and Grading\\[1em] Developer Manual\\[1em] \Large Version 1.13.0}
\date{\vspace*{-2em}2015-10-07}
\maketitle

\section{Concepts}

The exam \emph{library} contains $N_{\rm Q}$ \emph{questions}, each
with up to $N_{\rm V}$ \emph{variants}. Each question variant contains
up to $N_{\rm A}$ \emph{answers}, exactly one of which must be the
\emph{correct answer}. The correct answer for variant $V$ of question
$Q$ is denoted $C(Q,V)$. The questions within the library are grouped
into \emph{zones}.

We randomly generate $N_{\rm e}$ \emph{exams}. Each exam contains
exactly one randomly chosen variant of each library question, with the
question order randomly permuted within each zone. The order of the
zones is not permuted. Questions are numbered globally with the
library and exams, not per-zone. Question $q$ on exam $e$ thus
corresponds to variant $V(e,q)$ of question $Q(e,q)$ in the
library. The answer order for each exam question is also a random
permutation of the original answer order, so $A(e,q,a)$ is the library
answer corresponding to exam answer $a$.

We use capital-letter variables for quantities within the library
and small letters for quantities within the randomly generated exams
and students. Exams, questions, variants, and students are all
numbered with Arabic numerals starting from 1. Answers are numbered
with roman letters starting from A.

Each randomly generated exam is identified by a \emph{key} $K(e)$ of
length $N_{\rm K}$, which is a sequence of answers
$K_1,\ldots,K_{N_K}$. The keys are encoded on the Scantron forms as
the answers to the final set of questions. For example, on a
96-question Scantron form, the 4-digit key ``ECEA'' is encoded as the
answers (93) E, (94) C, (95) E, and (96) A.

During the exam each student completes a single Scantron form,
resulting in $N_{\rm s}$ Scantron forms for an equal number of
students. These forms are scanned and the raw data can be processed to
derive the points for each student.

In summary, the size variables used are:
\begin{center}
  \begin{tabular}{ll}
    $N_{\rm Q}$ & number of questions (in the library and on each exam) \\
    $N_{\rm e}$ & number of exams \\
    $N_{\rm A}$ & maximum number of answers per question \\
    $N_{\rm V}$ & maximum number of variants per question \\
    $N_{\rm s}$ & number of students (equal to the number of Scantron forms) \\
    $N_{\rm g}$ & number of ranked groups of students for statistics generation \\
    $N_{\rm D}$ & number of answer-digits required to encode the exam number \\
    $N_{\rm K}$ & number of answer-digits in the exam key
  \end{tabular}
\end{center}

\section{Processing pipeline}

The full processing pipeline for making, using, and grading a
randomized exam is shown in Figure~\ref{fig:pipeline}. The purple
output files can be inspected and hand-edited before processing runs
to control the processing pipeline.

\begin{figure}
  \centering
  \includegraphics{pipeline}
  \caption{The pipeline for making and grading the randomized
    exams. The green pentagons are input files that require human
    effort to generate, the purple boxes are output files, the yellow
    ellipses are program runs, and the pink hexagon is the students
    sitting the exam and the scanning of the Scantron forms.}
  \label{fig:pipeline}
\end{figure}

\section{File formats}

All library and exam question are formatted in single TeX files. All
data is stored in CSV (comma-separated values) files for easy editing
by hand in a spreadsheet or text editor.

\subsection{\texttt{library.tex}}

The \verb+library_template.tex+ file should be copied to
\verb+library.tex+ and edited to fill in the questions. Non-comment
text may only go into the locations indicated in the file. This file
should be a valid \LaTeX{} file that can be typeset and edited to
prepare the questions. To generate the randomized exams with the
\texttt{randexam} script, the format of \texttt{library.tex} must
conform to the grammar shown in Figure~\ref{fig:library-grammar}. The
basic structure of \texttt{library.tex} is thus a tree, as shown in
Figure~\ref{fig:library-tree}. An outline of the \LaTeX{} in the
\texttt{library.tex} is given in Figure~\ref{fig:library-outline}. The
\texttt{randexam} script processes \texttt{library.tex} using a state
machine. The state transition graph is shown in
Figure~\ref{fig:statemachine}.

\begin{figure}
  \centering
\begin{minipage}{\textwidth}
\setlength{\grammarindent}{9em}
\begin{grammar}
<library> ::= <preamble text> `\verb+\begin{document}+' <body> `\verb+\end{document}+'

<body> ::= <coverpage text> <zone-list>

<zone-list> ::= <zone> <zone-list> | <zone>

<zone> ::= `\verb+\zone+' <zone text>
\alt `\verb+\zone+' <zone text> <question-list>

<question-list> ::= <question> <question-list> | <question>

<question> ::= `\verb+\question{+' <points> `\verb+}+' <variant-list>

<variant-list> ::= <variant> <variant-list> | <variant>

<variant> ::= `\verb+\variant+' <variant text> `\verb+\begin{answers}+' <answer-list> `\verb+\end{answers}+'

<answer-list> ::= <answer> <answer-list> | <answer>

<answer> ::= `\verb+\answer+' <answer text>
\alt `\verb+\correctanswer+' <answer text>
\end{grammar}
\end{minipage}
\caption{Grammer for the \texttt{library.tex} input file expressed in
  partial Backus-Naur Form. The \textit{text} entries refer to any
  valid \LaTeX{} text, and \textit{points} is a numeric value.}
  \label{fig:library-grammar}
\end{figure}

\begin{figure}
  \centering
\begin{minipage}{14em}
\dirtree{%
.1 library.
.2 preamble text.
.2 coverpage text.
.2 zone 1.
.3 zone text.
.3 question 1.
.4 variant 1.
.5 variant text.
.5 answers.
.6 answer 1.
.6 answer 2.
.6 ....
.4 variant 2.
.4 ....
.3 question 2.
.3 ....
.2 zone 2.
.2 ....
}
\end{minipage}
  \caption{Tree structure of the \texttt{library.tex} input file.}
  \label{fig:library-tree}
\end{figure}

\begin{figure}
  \centering
\begin{minipage}{40em}
\begin{verbatim}
<preamble text>
\begin{document}
    <coverpage text>
    \zone
        <zone text>
        \question{<points>}
            \variant
                <variant text>
                \begin{answers}
                    \answer <answer text>
                    \correctanswer <answer text>
                    <more answers...>
                \end{answers}
            <more variants...>
        <more questions...>
    <more zones...>
\end{document}
\end{verbatim}
\end{minipage}
\caption{Outline of the \texttt{library.tex} input file.}
  \label{fig:library-outline}
\end{figure}

\begin{figure}
  \centering
  \includegraphics{statemachine}
  \caption{The state machine used by the \texttt{randexam} script to
    read the \texttt{library.tex} input file.}
  \label{fig:statemachine}
\end{figure}

\subsection{\texttt{exams.tex}}

This is the generated file containing all of the randomized
exams. Each coverpage ends with the exam key that needs to be filled
in by the student.

\subsection{\texttt{specs.csv}}

This file encodes the arrays:
\begin{center}
  \begin{tabular}{lll}
    array & dimensions & description \\
    \hline
    $K(e)$ & $N_{\rm e}$ & key for exam $e$ \\
    $Q(e,q)$ & $N_{\rm e} \times N_{\rm Q}$
    & library question for question $q$ on exam $e$ \\
    $V(e,q)$ & $N_{\rm e} \times N_{\rm Q}$
    & library question variant for question $q$ on exam $e$ \\
    $A(e,q,a)$ & $N_{\rm e} \times N_{\rm Q} \times N_{\rm A}$
    & library answer corresponding to answer $a$ for question $q$ on exam $e$
  \end{tabular}
\end{center}
The first column is the exam number, the second column is the exam
key, and then triples of columns identify the library question $Q$,
variant $V$, and library answer order. As an example:
\begin{verbatim}
e,K(e),"Q(e,q=1)","V(e,q=1)","A(e,q=1,:)","Q(e,q=2)","V(e,q=2)","A(e,q=2,:)"
1,ADC,2,2,DEBCA,3,2,DCEBA
2,BED,1,2,BDCAE,2,1,DECBA
\end{verbatim}
Here the key of the first exam is $K(1) = {\rm ADC}$ and the second
question on this exam is variant $V(1,2) = 2$ of library question
$Q(1,2) = 3$. The first answer for this question on the exam paper is
answer $A(1,2,1) = \rm D$ from the library question, while the second
answer on the exam paper is answer $A(1,2,2) = \rm C$ from the library
question.

\subsection{\texttt{points.csv}}

The points file encodes the array:
\begin{center}
  \begin{tabular}{lll}
    array & dimensions & description \\
    \hline
    $P(Q,V,A)$ & $N_{\rm Q} \times N_{\rm V} \times N_{\rm A}$
    & points awarded for giving answer $A$ to variant $V$ of question $Q$
  \end{tabular}
\end{center}
This is stored as a four-column file with entries like:
\begin{verbatim}
Q,V,A,"P(Q,V,A)"
...
2,1,A,0.0
2,1,B,0.0
2,1,C,0.0
2,1,D,1.0
2,1,E,0.0
\end{verbatim}
Here some lines have been removed, as indicated by the ellipsis. This
shows that for variant 1 of question 2, answer D is worth 1
point and all other answers are not worth any points, so
$P(2,1,4) = 1.0$ and $P(2,1,A) = 0$ for $A \ne 4$.

\subsection{\texttt{override.csv}}

The override file encodes the array:
\begin{center}
  \begin{tabular}{llp{10.5cm}}
    array & dimensions & description \\
    \hline
    $P^{\rm over}_{\rm sQ}$ & $N_{\rm s} \times N_{\rm Q}$
    & override points awarded to student $s$ for library question $Q$
    (or -1 to not override)
  \end{tabular}
\end{center}
This is stored as a CSV file with the first column being the student
NetID and subsequent columns specifying questions. The column header
indicates the question number. It is not necessary to include all
students or all questions, and any students or questions not specified
will have entries of $-1$ in $P^{\rm over}_{\rm sQ}$, indicating that
they should not be overridden. For example:
\begin{verbatim}
NetID,8,13
RDEVILLE,0.4,7
MWEST,0,-1
\end{verbatim}
Here two students have override scores specified for two
questions. Student \texttt{RDEVILLE} will have a score of 0.4 for
library question $Q = 8$ and $7$ for $Q = 13$. Student \texttt{MWEST}
will have a score of zero for question $Q = 8$, but for question $Q =
13$ his score will not be overridden, meaning it will be computed from
the answer and points data as usual.

\subsection{\texttt{solutions.csv}}

This file gives the correct solutions for each exam in case grading by
hand is necessary. This thus encodes the array:
\begin{center}
  \begin{tabular}{lll}
    array & dimensions & description \\
    \hline
    $c(e,q)$ & $N_{\rm e} \times N_{\rm Q}$
    & the correct answer for question $q$ on exam $e$
  \end{tabular}
\end{center}
The first two columns give the exam number and key for reference, and
then subsequent columns give the correct answers. For example:
\begin{verbatim}
e,K(e),"C(e,q=1)","C(e,q=2)","C(e,q=3)"
1,ADC,A,A,D
2,BED,D,A,A
3,CAE,A,E,D
4,DBA,A,A,D
5,ECB,B,E,A
\end{verbatim}
Here the third exam has key $K(3) = \rm CAE$ and the correct answer
for the first question on this exam is $c(3,1) = \rm A$, while the
correct answer for the second question is $c(3,2) = E$, etc.

The correct answers for each exam are derived from the correct answers
in the library file, given for each library question and each variant
in the array:
\begin{center}
  \begin{tabular}{lll}
    array & dimensions & description \\
    \hline
    $C(Q,V)$ & $N_{\rm Q} \times N_{\rm V}$
    & the correct answer for variant $V$ of library question $Q$
  \end{tabular}
\end{center}
The derivation of $c(e,q)$ is then:
\begin{equation}
  A(e,q,c(e,q)) = C\big( Q(e,q), V(e,q) \big).
\end{equation}

\subsection{\texttt{scantron.dat}}

This is the raw data file from the Scantron machine. There are two
possible formats for the Scantron data, depending on whether students
are allowed to bubble in more than one answer. Selecting multiple
answers is a possible approach for partial credit (where a student may
get half or third credit if they select two or three answers, for
example). The difference in the data file is how the answers are
encoded. If only a single answer is allowed, then it contains lines
like:
\begin{verbatim}
721000001001120412001Y  5380     1    N DEVILLE   R993502067   RDEVILLE 434
721000002001120412001Y  5380     1    N WEST      M795969582   MWEST    252
\end{verbatim}
Here each answer is represented by a single digit, with 1 = A, 2 = B,
etc., so student \verb+RDEVILLE+ answered D for question 1, C for
question 2, and D for question 3.

If, instead, multiple answers are allowed, the question information is
encoded in a two-digit decimal value that represents a little-endian
``binary'' encoding of the bubbled answers. That is, each answer has a
numeric value ($2^0$ = A, $2^1$ = B, \ldots, $2^4$ = E) and the
question value is the sum of all selected answer values. The data file
then contains lines like:
\begin{verbatim}
721000001001120412001Y  5380     1    N DEVILLE   R993502067   RDEVILLE 080412
721000002001120412001Y  5380     1    N WEST      M795969582   MWEST    021601
\end{verbatim}
Here student \verb+RDEVILLE+ answered D for question 1 (08 = $2^3$ =
D), C for question 2 (04 = $2^2$ = C), and both C and D for question 3
(12 = $2^2 + 2^3$ = C + D).

The actual file sent from the scanning office should be renamed to
\verb+scantron.dat+. The particular parsing is controlled by the
variable \verb+MULTIPLE_ANSWERS_PER_QUESTION+; this variable only
controls the parsing of \verb+scantron.dat+.

\subsection{\texttt{answers.csv}}

This file is essentially just a CSV version of the data in
\verb+scantron.dat+. It encodes the arrays:
\begin{center}
  \begin{tabular}{lll}
    array & dimensions & description \\
    \hline
    $u(s,i)$ & $N_{\rm s} \times 4$
    & student last name, first initial, student ID number, and NetID \\
    $b(s,q,a)$ & $N_{\rm s} \times N_{\rm Q} \times N_{\rm A}$
    & bubble selection of answer $a$ given to question $q$ by student $s$;\\
    & & 0 = empty, 1 = filled \\
    $k(s)$ & $N_{\rm s}$
    & key filled in by student $s$
  \end{tabular}
\end{center}
The first column in the data file is the student number, then the next
four columns store the student information, the sixth column stores
the exam key, and then columns 7 and up store the bubbled-in answers
to the questions in exam order. As an example:
\begin{verbatim}
s,Name,Initial,Number,NetID,k(s),"b(s,q=1,:)","b(s,q=2,:)","b(s,q=3,:)"
1,DEVILLE,R,993502067,RDEVILLE,CAE,D,C,CD
2,WEST,M,795969582,MWEST,ECB,B,E,AB
\end{verbatim}
Here we see the second student has information giving the last name
$u(2,1) = \mathtt{WEST}$, the first initial $u(2,2) = \mathtt{M}$, the
student number $u(2,3) = 795969582$, and the NetID $u(2,4) =
\texttt{MWEST}$. The exam key for this student is $k(2) = \rm ECB$ and
the student bubbled answers $b(2,1,:) = [0,1,0,0,0]$ (selecting just
B) for question 1 on this exam paper, bubbled answers $b(2,2,:) =
[0,0,0,0,1]$ (selecting just E) for question 2, and bubbled answers
$b(2,3,:) = [1,1,0,0,0]$ (selecting both A and B) for question 3.

\subsection{\texttt{scores.csv}}

This file encodes the array $P_{\rm se}(s)$ described in
Section~\ref{sec:grading}. For reference, the student number and
information in array $u(s,i)$ is also included in the first
columns. As an example:
\begin{verbatim}
s,Name,Initial,Number,NetID,P_s(s)
1,DEVILLE,R,993502067,RDEVILLE,2.0
2,WEST,M,795969582,MWEST,2.0
\end{verbatim}
Here we see that both students have total points $P_{\rm s}(1) =
P_{\rm s}(2) = 2.0$.

\subsection{\texttt{stats.tex}}

This file presents various summary statistics relating to the student
and question performance in the exam. It should be processed with
\texttt{pdflatex} to produce the output \texttt{stats.pdf} file.

\subsection{\texttt{stats\underline{ }*.csv}}

Multiple files are written to encode the statistics arrays described
in Section~\ref{sec:statistics}. These are named after the variables
they contain, so $n^{\rm a}_{\rm QV}$ is be stored in
\verb+stats_n_a_QV.csv+, for example. The format is broadly similar to
those files described in detail above, with column headings that
specify the contents.

\section{Grading}
\label{sec:grading}

The map from student number $s$ to exam number $e$ is given by the
array
\begin{center}
  \begin{tabular}{lll}
    array & dimensions & description \\
    \hline
    $e(s)$ & $N_{\rm s}$ & exam number corresponding to student number $s$
  \end{tabular}
\end{center}
This array is determined so that
\begin{equation}
  K(e(s)) = k(s).
\end{equation}

The points awarded to each student can be determined using the grading
key for any exam, not just the particular exam that the student
actually took. To make this clear, we consider the arrays:
\begin{center}
  \begin{tabular}{lll}
    array & dimensions & description \\
    \hline
    $P_{\rm seq}(s,e,q)$ & $N_{\rm s} \times N_{\rm e} \times N_{\rm Q}$
    & points awarded to student $s$ on question $q$ scored for exam $e$ \\
    $P_{\rm se}(s,e)$ & $N_{\rm s} \times N_{\rm e}$
    & total points awarded to student $s$ scored for exam $e$ \\
    $P_{\rm sq}(s,q)$ & $N_{\rm s} \times N_{\rm Q}$
    & points award to student $s$ on question $q$ using the correct exam \\
    $P_{\rm s}(s)$ & $N_{\rm s}$
    & total points awarded to student $s$ scored using the correct exam \\
    $P_{\rm sQ}(s,Q)$ & $N_{\rm s} \times N_{\rm Q}$
    & points awarded to student $s$ for library question $Q$
  \end{tabular}
\end{center}
We define an array for partial credit $\sigma(n)$ (the variable
\verb+SCORE_PER_ANSWERS+ in \verb+randexam+) which is the score value
multiplier when $n$ answers are selected (e.g., $\sigma(1)=1$ always,
but $\sigma(n)=1/n$ can be used to award partial credit, or
$\sigma(n)=0$ for $n>1$ will allow no partial credit). The first array
in the table above is computed by:
\begin{equation}
  P_{\rm seq}(s,e,q) = \begin{cases}
    \displaystyle \sum_{a=1}^{N_{\rm A}} P\Big(Q(e,q), V(e,q), A(e,q,a)\Big)
    b(s,q,a) \sigma\Bigg(\sum_{a'=1}^{N_{\rm A}} b(s,q,a')\Bigg)
    & \text{if } P^{\rm over}_{\rm sQ}\big(s,Q(e,q)\big) < 0 \\
    P^{\rm over}_{\rm sQ}\big(s,Q(e,q)\big) & \text{otherwise}
  \end{cases}
\end{equation}
The subsequent arrays in the table above are then computed by:
\begin{align}
  P_{\rm se}(s,e) &= \sum_{q = 1}^{N_{\rm Q}} P_{\rm seq}(s,e,q) \displaybreak[0] \\
  P_{\rm sq}(s,q) &= P_{\rm seq}\big(s,e(s),q\big) \displaybreak[0] \\
  P_{\rm s}(s) &= P_{\rm se}\big(s,e(s)\big) \displaybreak[0] \\
  P_{\rm sQ}\Big(s,Q\big(e(s),q\big)\Big) &= P_{\rm seq}\big(s,e(s),q\big).
\end{align}
We expect that $e(s)$ maximizes $P_{\rm se}(s,e)$ for each $s$, as
grading with the ``wrong'' exam key should give random choices for
each answer. Indeed, for $\hat{e} \ne e(s)$, $P_{\rm se}(s,\hat{e})$
should be approximately $N_{\rm Q} / N_{\rm A}$, assuming that each
question is worth one point if correct. Some significant deviations
are likely, however, when the number of students $N_{\rm s}$ is much
larger than the number of questions $N_{\rm Q}$.

\section{Curving}
\label{sec:curving}

Curved score values are stored in the array:
\begin{center}
  \begin{tabular}{lll}
    array & dimensions & description \\
    \hline
    $P^{\rm curve}_{\rm s}(s)$ & $N_{\rm s}$
    & total curved points awarded to student $s$
  \end{tabular}
\end{center}

The default is for no curving, in which case $P^{\rm curve}_{\rm s}$
is equal to $P_{\rm s}$. If score curving is enabled (by the
\texttt{curve_scores} configuration parameter) then
$P^{\rm curve}_{\rm s}$ is computed using the piecewise linear
function shown in Figure~\ref{fig:curve} with the following
parameters:
\begin{center}
  \begin{tabular}{cll}
    quantity & config option & description \\
    \hline
    $M_0$ & --- & median of old (uncurved) scores \\
    $M_1$ & \texttt{curve_new_median} & desired median of new (curved) scores \\
    $Z_1$ & \texttt{curve_new_zero} & desired new (curved) score for old zero score
  \end{tabular}
\end{center}

\begin{figure}
  \centering
  \begin{tikzpicture}
    \begin{axis}[
      width=10cm,
      xlabel={old score $P_{\rm s}$},
      ylabel={new score $P^{\rm curve}_{\rm s}$},
      grid=both,
      axis equal image,
      xmin=0,
      xmax=100,
      ymin=0,
      ymax=100,
      ]
      \node[above right] at (axis cs:60,0) {$M_0$};
      \node[above right] at (axis cs:0,80) {$M_1$};
      \node[below right] at (axis cs:0,20) {$Z_1$};
      \addplot coordinates {
        (0,20)
        (60,80)
        (100,100)
      };
      \addplot[dashed,blue,mark=*] coordinates {
        (0,80)
        (60,80)
        (60,0)
      };
    \end{axis}
  \end{tikzpicture}
  \caption{Curving function that transforms old scores to new scores.}
  \label{fig:curve}
\end{figure}

\section{Statistics}
\label{sec:statistics}

As well as computing the scores for each student, we can assess how
the students as a group performed on the different questions and
variants. Basic statistics for this assessment are listed below.
  \begin{longtable}[c]{llp{9cm}}
    array & dimensions & description \\
    \hline
    \endhead
    $n^{\rm s}_{\rm e}(e)$ & $N_{\rm e}$
    & number of students taking exam $e$ \\
    $n^{\rm s}_{\rm QV}(Q,V)$ & $N_{\rm Q} \times N_{\rm V}$
    & number of students given variant $V$ of question $Q$ \\
    $n^{\rm a}_{\rm QVA}(Q,V,A)$ & $N_{\rm Q} \times N_{\rm V} \times N_{\rm A}$
    & number of students giving answer $A$ for variant $V$ of question $Q$ \\
    $n^{\rm a}_{\rm QV}(Q,V)$ & $N_{\rm Q} \times N_{\rm V}$
    & number of students giving an answer for variant $V$ of question $Q$ \\
    $n^{\rm na}_{\rm QV}(Q,V)$ & $N_{\rm Q} \times N_{\rm V}$
    & number of students not giving an answer for variant $V$ of question $Q$ \\
    $n^{\rm a}_{\rm Q}(Q)$ & $N_{\rm Q}$
    & number of students giving an answer for question $Q$ \\
    $r^{\rm a}_{\rm QVA}(Q,V,A)$ & $N_{\rm Q} \times N_{\rm V} \times N_{\rm A}$
    & fraction of students giving answer $A$ for variant $V$ of question $Q$ \\
    $r^{\rm na}_{\rm QV}(Q,V)$ & $N_{\rm Q} \times N_{\rm V}$
    & fraction of students not giving an answer for variant $V$ of question $Q$ \\
    $P_{\rm QV}(Q,V)$ & $N_{\rm Q} \times N_{\rm V}$
    & total points awarded for variant $V$ of question $Q$ \\
    $P_{\rm Q}(Q)$ & $N_{\rm Q}$
    & total points awarded for question $Q$ \\
    $\bar{P}_{\rm QV}(Q,V)$ & $N_{\rm Q} \times N_{\rm V}$
    & average points per student for variant $V$ of question $Q$ \\
    $\bar{P}_{\rm Q}(Q)$ & $N_{\rm Q}$
    & average points per student for question $Q$ \\
    $\bar{P}$ & 1
    & average points per student for entire exam \\
    $P^{\rm max}_{\rm QV}(QV)$ & $N_{\rm Q} \times N_{\rm V}$
    & maximum points available for variant $V$ of question $Q$ \\
    $P^{\rm max}_{\rm Q}(Q)$ & $N_{\rm Q}$
    & maximum points available for question $Q$ \\
    $P^{\rm max}$ & $1$
    & maximum points available for the entire exam \\
    $\hat{P}_{\rm Q}(Q)$ & $N_{\rm Q}$
    & normalized average points per student for question $Q$ \\
    $R_{\rm QV}(Q,V)$ & $N_{\rm Q} \times N_{\rm V}$
    & ratio of average points for variant $V$ to average for question $Q$ \\
    $n_{\rm QVC}(Q,V,C)$ & $N_{\rm Q} \times N_{\rm V} \times N_{\rm A}$
    & number of students who bubbled in $C$ answers for variant $V$ of question $Q$ \\
    $r^{\rm s}_{QQ}(Q,\hat{Q})$ & $N_{\rm Q} \times N_{\rm Q}$
    & correlation between student scores on questions $Q$ and $\hat{Q}$ \\
    $r^{\rm Q}_{\rm ss}(s,\hat{s})$ & $N_{\rm s} \times N_{\rm s}$
    & correlation between question points for students $s$ and $\hat{s}$ \\
    $n^{\rm ai}_{\rm ss}(s,\hat{s})$ & $N_{\rm s} \times N_{\rm s}$
    & number of mutually incorrect exam answers for students $s$ and $\hat{s}$ \\
    $r^{\rm ai}_{\rm ss}(s,\hat{s})$ & $N_{\rm s} \times N_{\rm s}$
    & proportion of identical incorrect answers for students $s$ and $\hat{s}$ \\
    $D_{\rm Q}(Q)$ & $N_{\rm Q}$
    & ``difficulty'' of question $Q$: one minus normalized averaged points $\hat{P}_{\rm Q}(Q)$ \\
    $r^{\rm P}_{\rm Q}(Q)$ & $N_{\rm Q}$
    & ``discrimination'' of question $Q$: correlation coefficient of $P_{\rm sQ}(s,Q)$ and $\big(P_{\rm s}(s) - P_{\rm sQ}(s,Q)\big)$ \\
    $q_{\rm sQ}(s,Q)$ & $N_{\rm s} \times N_{\rm Q}$
    & exam question number $q$ in which library question $Q$ appears for student $s$ \\
    $V_{\rm sQ}(s,Q)$ & $N_{\rm s} \times N_{\rm Q}$
    & variant number of library question $Q$ given to student $s$ \\
    $c_{\rm sQ}(s,Q)$ & $N_{\rm s} \times N_{\rm Q}$
    & correct answer position for library question $Q$ given to student $s$
  \end{longtable}
These quantities are computed by:
\begin{align}
  n^{\rm s}_{\rm e}(e) &= \sum_{s = 1}^{N_{\rm s}} \delta\big(K(e), k(s)\big) \displaybreak[0] \\
  n^{\rm s}_{\rm QV}(\hat{Q},\hat{V}) &= \sum_{s = 1}^{N_{\rm s}} \sum_{q = 1}^{\rm N_{\rm Q}}
  \delta\Big(\hat{Q}, Q\big(e(s),q\big)\Big)
  \ \delta\Big(\hat{V}, V\big(e(s),q\big)\Big) \displaybreak[0] \\
  n^{\rm a}_{\rm QVA}(\hat{Q},\hat{V},\hat{A}) &= \sum_{s = 1}^{N_{\rm s}} \sum_{q = 1}^{N_{\rm Q}} \sum_{a = 1}^{N_{\rm A}}
  \delta\Big( \hat{Q}, Q\big(e(s),q\big) \Big) \ \delta\Big(\hat{V}, V\big(e(s),q\big) \Big)
  \ \delta\Big( \hat{A}, A\big(e(s),q,a\big) \Big) \nonumber \\
  &\qquad \cdot b(s,q,a)\sigma\Big(\sum_{a'}b(s,q,a')\Big) \displaybreak[0] \\
  n^{\rm a}_{\rm QV}(Q,V) &= \sum_{A = 1}^{N_{\rm A}} n^{\rm a}_{\rm QVA}(Q,V,A) \displaybreak[0] \\
  n^{\rm na}_{\rm QV}(Q,V) &= n^{\rm s}_{\rm QV}(Q,V) - n^{\rm a}_{\rm QV}(Q,V) \displaybreak[0] \\
  n^{\rm a}_{\rm Q}(Q) &= \sum_{V = 1}^{N_{\rm V}} n^{\rm a}_{\rm QV}(Q,V) \displaybreak[0] \\
  r^{\rm a}_{\rm QVA}(Q,V,A) &= \frac{n^{\rm a}_{\rm QVA}(Q,V,A)}{n^{\rm s}_{\rm QV}(Q,V)} \displaybreak[0] \\
  r^{\rm na}_{\rm QV}(Q,V) &= \frac{n^{\rm na}_{\rm QV}(Q,V)}{n^{\rm s}_{\rm QV}(Q,V)} \displaybreak[0] \\
  P_{\rm QV}(\hat{Q},\hat{V}) &= \sum_{s = 1}^{N_{\rm s}} \sum_{q = 1}^{N_{\rm Q}} P_{\rm sq}(s,q)
  \ \delta\Big(\hat{Q}, Q\big(e(s),q\big)\Big)
  \ \delta\Big(\hat{V}, V\big(e(s),q\big)\Big) \displaybreak[0] \\
  P_{\rm Q}(Q) &= \sum_{V = 1}^{N_{\rm V}} P_{\rm QV}(Q,V) \displaybreak[0] \\
  \bar{P}_{\rm QV}(Q,V) &= \frac{P_{\rm QV}(Q,V)}{n^{\rm s}_{\rm QV}(Q,V)} \displaybreak[0] \\
  \bar{P}_{\rm Q}(Q) &= \frac{P_{\rm Q}(Q)}{N_{\rm s}} \displaybreak[0] \\
  \bar{P} &= \sum_{Q=1}^{N_{\rm Q}} \bar{P}_{\rm Q}(Q)
  = \frac{1}{N_{\rm s}} \sum_{s=1}^{N_{\rm s}} P_{\rm s}(s) \displaybreak[0] \\
  P^{\rm max}_{\rm QV}(Q,V) &= \max_{A \in \{1,\ldots,N_{\rm A}\}} P(Q,V,A) \displaybreak[0] \\
  P^{\rm max}_{\rm Q}(Q) &= \max_{V \in \{1,\ldots,N_{\rm V}\}} P^{\rm max}_{\rm QV}(Q,V) \displaybreak[0] \\
  P^{\rm max} &= \sum_{Q=1}^{N_{\rm Q}} P^{\rm max}_{\rm Q}(Q) \displaybreak[0] \\
  \hat{P}_{\rm Q}(Q) &= \frac{\bar{P}_{\rm Q}(Q)}{P^{\rm max}_{Q}(Q)} \displaybreak[0] \\
  R_{\rm QV}(Q,V) &= \frac{\bar{P}_{\rm QV}(Q,V)}{\bar{P}_{\rm Q}(Q)} \displaybreak[0] \\
  n_{\rm QVC}(Q,V,C) &= \sum_{s=1}^{N_{\rm s}} \delta\left(C - \sum_{a=1}^{N_{\rm A}} b\big(s,q_{\rm sQ}(s,Q),a\big)\right)
  \delta\big(V-V_{\rm sQ}(s,Q)\big) \displaybreak[0]\\
  r^{\rm s}_{\rm QQ}(Q, \hat{Q}) &= \frac{\sum_{s=1}^{N_{\rm s}}
    (P_{sQ}(s,Q) - \bar{P}_Q(Q)) (P_{sQ}(s,\hat{Q}) - \bar{P}_Q(\hat{Q}))
  }{
    \sqrt{\sum_{s=1}^{N_{\rm s}} (P_{sQ}(s,Q) - \bar{P}_Q(Q))^2}
    \sqrt{\sum_{s=1}^{N_{\rm s}} (P_{sQ}(s,\hat{Q}) - \bar{P}_Q(\hat{Q}))^2}} \displaybreak[0] \\
  r^{\rm Q}_{\rm s}(s, \hat{s}) &= \frac{\sum_{Q=1}^{N_{\rm Q}}
    (P_{sQ}(s,Q) - \bar{P}_Q(Q)) (P_{sQ}(s,\hat{Q}) - \bar{P}_Q(\hat{Q}))
  }{
    \sqrt{\sum_{Q=1}^{N_{\rm Q}} (P_{sQ}(s,Q) - \bar{P}_Q(Q))^2}
    \sqrt{\sum_{Q=1}^{N_{\rm Q}} (P_{sQ}(s,\hat{Q}) - \bar{P}_Q(\hat{Q}))^2}} \displaybreak[0] \\
  n^{\rm ai}_{\rm ss}(s,\hat{s}) &= \sum_{q = 1}^{N_{\rm Q}} \delta\big(0, P_{\rm sq}(s,q)\big)
  \ \delta\big(0, P_{\rm sq}(\hat{s},q)\big) \displaybreak[0] \\
  r^{\rm ai}_{\rm ss}(s,\hat{s}) &= \frac{1}{n^{\rm ai}_{\rm ss}(s,\hat{s})} \sum_{q = 1}^{N_{\rm Q}}
  \delta\big(a(s,q), a(\hat{s},q)\big)
  \ \delta\big(0, P_{\rm sq}(s,q)\big) \ \delta\big(0, P_{\rm sq}(\hat{s},q)\big) \displaybreak[0] \\
  D_{\rm Q}(Q) &= 1 - \hat{P}_{\rm Q}(Q) \displaybreak[0] \\
  r^{\rm P}_{\rm Q}(Q) &= \frac{\displaystyle \sum_{s=1}^{N_{\rm s}}
    \Big(P_{sQ}(s,Q) - \bar{P}_Q(Q)\Big) \Big(\big(P_{s}(s) - P_{sQ}(s,Q)\big) - \big(\bar{P} - \bar{P}_Q(Q)\big)\Big)
  }{
    \sqrt{\displaystyle \sum_{s=1}^{N_{\rm s}} \Big(P_{sQ}(s,Q) - \bar{P}_Q(Q)\Big)^2}
    \sqrt{\displaystyle \sum_{s=1}^{N_{\rm s}} \Big(\big(P_{s}(s) - P_{sQ}(s,Q)\big) - \big(\bar{P} - \bar{P}_Q(Q)\big)\Big)^2}} \displaybreak[0] \\
  q_{\rm sQ}(s,\hat{Q}) &= \sum_{q = 1}^{N_{\rm Q}} \delta\Big(\hat{Q},Q\big(e(s),q\big)\Big) q
  \hspace{2em} \Longrightarrow \hspace{2em} Q\big(e(s), q_{\rm sQ}(s,\hat{Q})\big) = \hat{Q} \displaybreak[0] \\
  V_{\rm sQ}(s,Q) &= V\big(e(s), q_{\rm sQ}(s,Q)\big) \\
  c_{\rm sQ}(s,Q) &= c\big(e(s), q_{\rm sQ}(s,Q)\big)
\end{align}
where $\delta(x,y)$ is the Kronecker delta function, equal to one with
equal arguments and zero otherwise.

We expect that $R_{\rm QV}(Q,V) \approx 1$, indicating that all
variants were equally difficult for question $Q$. We also expect that
$r^{\rm ai}_{\rm ss}(s,\hat{s}) \approx 1/N_{\rm A}$ for $e(s) =
e(\hat{s})$, indicating only random association between incorrect
answers given by students with identical exams, although this may be
legitimately higher due to correlations between student mistakes.

To understand how students of different ability levels perform it is
helpful to group students by their exam scores. We consider $N_{\rm
  g}$ almost-equal-sized \emph{groups} of students, where all students
in group $g$ perform worse than all students in group $g + 1$, etc. We
can then compute the following per-group quantities:
\begin{center}
  \begin{tabular}{llp{9cm}}
    array & dimensions & description \\
    \hline
    $s(r)$ & $N_{\rm s}$
    & student number at rank $r$ \\
    $g(s)$ & $N_{\rm g}$
    & group number of student $s$ \\
    $n^{\rm s}_{\rm g}(g)$ & $N_{\rm g}$
    & number of students in group $g$ \\
    $P_{\rm gQV}(g,Q,V)$ & $N_{\rm g} \times N_{\rm Q} \times N_{\rm V}$
    & total points awarded for variant $V$ of question $Q$ to students in group $g$ \\
    $P_{\rm gQ}(g,Q)$ & $N_{\rm g} \times N_{\rm Q}$
    & total points awarded for question $Q$ to students in group $g$ \\
    $\bar{P}_{\rm gQ}(g,Q)$ & $N_{\rm g} \times N_{\rm Q}$
    & average points awarded for question $Q$ to students in group $g$ \\
    $\hat{P}_{\rm gQ}(g,Q)$ & $N_{\rm g} \times N_{\rm Q}$
    & normalized average points awarded for question $Q$ to students in group $g$
  \end{tabular}
\end{center}
The definitions for the above quantities are:
\begin{align}
  P_{\rm s}\big(s(r)\big) &\le P_{\rm s}\big(s(r + 1)\big) \displaybreak[0] \\
  g\big(s(r)\big) &= \left\lfloor \frac{(r - 1) \, N_{\rm g}}{N_{\rm s}}
  \right\rfloor + 1 \displaybreak[0] \\
  n^{\rm s}_{\rm g}(\hat{g}) &= \sum_{s=1}^{N_{\rm s}}
  \delta\big(\hat{g}, g(s)\big) \displaybreak[0] \\
  P_{\rm gQV}(\hat{g},\hat{Q},\hat{V}) &= \sum_{s=1}^{N_{\rm s}} \sum_{q=1}^{N_{\rm Q}}
  P_{\rm sq}(s,q) \ \delta\big(\hat{g}, g(s)\big)
  \ \delta\Big(\hat{Q}, Q\big(e(s),q\big)\Big)
  \ \delta\Big(\hat{V}, V\big(e(s),q\big)\Big) \displaybreak[0] \\
  P_{\rm gQ}(g,Q) &= \sum_{V=1}^{N_{\rm V}} P_{\rm gQV}(g,Q,V) \displaybreak[0] \\
  \bar{P}_{\rm gQ}(g,Q) &= \frac{P_{\rm gQ}(g,Q)}{n^{\rm s}_{\rm g}(g)} \displaybreak[0] \\
  \hat{P}_{\rm gQ}(g,Q) &= \frac{\bar{P}_{\rm gQ}(g,Q)}{P^{\rm max}_{\rm Q}(Q)}
\end{align}

\section{Implementation notes}

The randomized exam procedure described in this document is
implemented in the \texttt{randexam} Python script. The configuration
section at the top of the file should be edited as appropriate.

The internal variables in the script follow the notation in this
document and use \texttt{numpy} for array handling. The only
significant departure is that all variables are numbered from zero
rather than from one, as Python uses zero-indexed arrays. The
conversion between one-based and zero-based quantities occurs during
reading and writing. All internal variables and computations are
zero-based.

In this document overloaded notation is used for index variables and
arrays, so that we write both $Q(e,q)$ and $C(Q,V)$, where $Q$ is
understood to be a dummy variable in the latter expression. In the
code, plain variable names like \texttt{Q} refer to the array and
names like \texttt{Qi} and \texttt{Qj} are used for dummy index
variables.

All variables that represent answers are string-valued and store
values A, B, etc, rather than an integer. These correspond to indexes
$\rm A \leftrightarrow 0$, $\rm B \leftrightarrow 1$, etc. To convert
between zero-based integer indexes and string representations, the
functions \texttt{chr2ind()} and \texttt{ind2chr()} can be used. For
example, to access a value in the $A(e,q,a)$ array we can write:
\begin{verbatim}
e = 7
q = 0
a = "D"
print(A(e, q, chr2ind(a)))
\end{verbatim}

The bubbled-in answers of students are stored in a ``bubble'' array
$b$, which uses 0 for unselected answers and 1 for selections. There
are a three conversion routines that deal with the bubble list format:
\verb+binary2bubble()+, \verb+string2bubble()+, and
\verb+bubble2string()+, which do exactly what they say. The
conversions to and from strings make use of the \verb+ch2ind()+ and
\verb+ind2chr()+ routines. The controlling of the parsing is through
the \verb+MULTIPLE_ANSWERS_PER_QUESTION+ variable, and the partial
credit scoring (the $\sigma(n)$ array) is stored as
\verb+SCORE_PER_ANSWERS+.

\section{Key generation}

The exam keys are generated by encoding the exam number $e$ in
base-$N_{\rm A}$ using $N_{\rm D}$ digits and then appending two or
three checksum digits. The exam-number digits are in little-endian
order, with least significant digit first, so for zero-based digits
$K_i$ and zero-based indexes $i$ they are
\begin{equation}
  K_i = \left\lfloor \frac{e}{(N_{\rm A})^i} \right\rfloor
  \mod N_{\rm A}, \text{ for } i = 0,\ldots,(N_{\rm D} - 1).
\end{equation}
The $N_{\rm C}$ checksum digits are the \emph{parity digit} $K_{\rm
  P}$, a \emph{Fletcher-type} checksum $K_{\rm F}$, and possibly a
modified Fletcher-type checksum $K_{\rm M}$, defined for zero-based
digits $K_i$ and zero-based indexes $i$ by
\begin{align}
  K_{\rm P} &= \sum_{i=0}^{N_{\rm D} - 1} K_i \mod N_{\rm A}
  \displaybreak[0] \\
  K_{\rm F} &= \sum_{i=0}^{N_{\rm D} - 1} w_{{\rm F},i} K_i \mod N_{\rm A}
  & w_{{\rm F},i} &= \Big(i\ \operatorname{mod}\ (N_A - 1)\Big) + 1
  \displaybreak[0] \\
  K_{\rm M} &= \sum_{i=0}^{N_{\rm D} - 1} w_{{\rm M},i} K_i \mod N_{\rm A}
  & w_{{\rm M},i} &= \left(\left\lfloor \frac{i}{N_{\rm A} - 1}
  \right\rfloor\, \operatorname{mod}\ (N_{\rm A} - 1)\right) + 1.
\end{align}
Using the first two checksum digits ensures a minimum Hamming distance
of 3 for at most $(N_{\rm A} - 1)$ non-checksum digits (up to $N_{\rm
  A}^{(N_{\rm A} - 1)}$ different random exams).  If more digits are
required to encode the exam numbers then the third checksum digit is
appended to the key, ensuring a Hamming distance of at least 3 for up
to $(N_{\rm A} - 1)^2$ non-checksum digits, allowing up to $N_{\rm
  A}^{(N_{\rm A} - 1)^2}$ different random exams. In the case of
$N_{\rm A} = 5$ the key lengths are:
\begin{center}
  \begin{tabular}{cccc}
    number of exams & exam-number digits $N_{\rm D}$
    & checksum digits & key length $N_{\rm K} = N_{\rm D} + N_{\rm C}$ \\
    \hline
    5 & 1 & 2 & 3 \\
    25 & 2 & 2 & 4 \\
    125 & 3 & 2 & 5 \\
    625 & 4 & 2 & 6 \\
    3125 & 5 & 3 & 8 \\
    15625 & 6 & 3 & 9
  \end{tabular}
\end{center}

\section{Contributors}

The following people have contributed to the development of
\verb+randexam+:
\begin{description}
\item[Matt West:] Primary developer.
\item[Lee DeVille:] Concept development, testing, individualized
  student feedback code.
\item[Dallas Trinkle:] Support for multiple answers and partial
  credit.
\end{description}

\end{document}


\documentclass[aspectratio=169]{beamer}
\usetheme[
    section page = progressbar,
    progressbar = foot,
    background = light
]{metropolis}

\newcounter{notes}
\setcounter{notes}{0}

\input{macro}

\title{Equivalence Between Systems Stronger than Resolution \\
{\small M.L. Bonet, Jordi Levy}}
\author{Sankalp Gambhir}

\begin{document}
    \frame{\titlepage}
    %
    \section{Resolution...?}
    \begin{frame}
        \frametitle{Resolution}
        It is an inference rule. \pause

            \[\begin{prooftree}
                \hypo{x \lor A}
                \hypo{\lnot x \lor B}
                \infer2{\pause A \lor B}
            \end{prooftree}
            \quad \textit{CUT}
            \]

        \pause This is the Resolution inference rule, done! \pause However this
        is not quite the form we need it in. This rule is incomplete in the case
        we try to apply it to MaxSAT instead\pause, so we would like to modify
        it to fit our needs.
    \end{frame}
    \begin{frame}
        \frametitle{MaxSAT Resolution}
        The goal is to find a maximal set of simultaneously satisfiable clauses
        by cardinality, or alternately, the minimum number of unsatisfiable
        clauses for any assignment. \pause The main issue with MaxSAT is that we
        cannot have our inference rules changing the number of unsatisfiable
        clauses. This is how we define a \emph{sound} inference rule in MaxSAT.
        \notes{Unfortunately, solving the Max-SATproblem forφis, in general,
        notequivalentto solving it forφ′; i.e., the number of unsatisfiedclauses
        inφandφ′is not the same for every truth assignment. Therefore, if we
        want to compute anoptimal solution, we cannot apply unit propagation as
        in SATsolvers.}

        As for Resolution --

        \begin{multicols}{2}
            \[\begin{prooftree}[center, separation=2.5em]
                \hypo{x \lor A}
                \hypo{\lnot x \lor B}
                \infer2{A \lor B}
            \end{prooftree}\]

            \pause
            \columnbreak

            \[\begin{prooftree}[center, separation=2.5em]
                \hypo{x \lor A & \lnot x \lor B}
                \infer1{\pause A \lor B \pause \quad x \lor A \lor \overline{B} \pause \quad \lnot x \lor \overline{A} \lor B}
            \end{prooftree}\]

        \end{multicols}

        \notes{The exact form of this is not too important for our purposes here.}
    \end{frame}
    %
    \section{What's stronger? \\ {\tiny I hope not more than 5 minutes have passed}}
    \begin{frame}
        \frametitle{Circular Proofs}

        \notes{Consider for a second, a water tank. If we draw 5 lines of water from
        it, it's gonna empty out real quick. Some of the pipes go around the
        place, then back into the tank. Starting with an empty tank, you get...
        nothing. However, if overall, the number of pipes leaving the tank was
        smaller than the number of pipes coming in, we might just have a full
        tank on our hands. }

        % insert image!!
        \centering
        \scalebox{1}{\includegraphics[width=\textwidth]{fig/water.png}}
    \end{frame}
    \begin{frame}
        \frametitle{Circular Proofs}

        \begin{multicols}{2}
            \centering
            \begin{tikzpicture}[
            roundnode/.style={circle, draw=red!60, fill=red!15, very thick, minimum size=7mm},
            squarednode/.style={rectangle, draw=blue!60, fill=blue!5, very thick, minimum size=5mm},
            ]
            %Nodes
            \node[roundnode]      (ax)                              {$x \lor A$};
            \node[squarednode]    (split)         [below=of ax] {SPLIT};
            \node[roundnode]      (x)           [below=of split] {$x$};
            \node[roundnode]      (xx)          [right=of split] {$x \lor \lnot x$};
            \node[squarednode]    (cut)         [below=of xx] {CUT};
            \node[roundnode]      (ax2)         [right=of cut] {$x \lor A$};

            %Lines
            \draw[->] (ax) -- (cut);
            \draw[->] (x)  to [out=150,in=210]  (split);
            \draw[->] (split) -- (x);
            \draw[->] (split) -- (xx);
            \draw[->] (xx) -- (cut);
            \draw[->] (cut) -- (ax2);
            \end{tikzpicture}

            \notes{Rather blood tanks now that I've written the colors the wrong way around}

            \pause
            \columnbreak
            \justify

            SPLIT and CUT have \emph{flows}. These flows allow us to calculate
            the balance on each formula node. \pause For each formula in the
            system, we must have a non-negative balance\pause, and for our goal
            in particular, we would like the tank to be filled and not just
            passing water, per the analogy, so we want a positive balance.
            \cite{atserias2019circular}

        \end{multicols}

    \end{frame}
    %
    \begin{frame}
        \frametitle{Weighted Proofs}

        \notes{In MaxSAT, replace instances of a clause $A$ by a pair $(A, n)$ with n
        being the number of times it occurs. Negative weights can be used to
        signify clauses that haven't been proved.}

        \[A, A, \ldots , A \rightarrow (A, n)\]

        \pause Weighted MaxSAT in particular is equivalent to the normal MaxSAT.
        \notes{Because you can just interchange the occurences and numbers.}
        \pause \\Where does n lie? \notes{What is the domain of n? Positive? Non
        Negative? All integers?} \pause What could $n = -2$ mean? \notes{You
        might see this is suspiciously similar to our analogy earlier. So we try
        to look at them together.}

    \end{frame}
    \section{Equivalence and Dual Rail Proofs\\
    {\tiny As much as I'd like to think I have 5 more minutes...}}
    \begin{frame}
        \frametitle{Equivalence}
        \notes{I hope I have convinced you by way of analogy that the two
        discussed systems are indeed equivalent. Resolution seems somewhat
        foreign to this discussion, but the rest of the focus is on equivalence
        of these systems under arbitrary inference rules and what it means for
        the restriction to resolution and MaxSAT in particular.}

        \notes{I will give an outline of the proof.}

        So take the balance we discussed for circular proofs, and start with
        those as weights for your weighted proof. \notes{We can freely sever
        certain edges and create a total ordering of the nodes.} Traversing the
        nodes, each of the inference rules, having a \emph{flow} associated to
        it, can be seen as combining and modifying the weights.
        \cite{bonet2020equivalence} \notes{Proof seems quite intuitive, it's
        just hard to show that it does indeed satisfy all the conditions for a
        weighted proof.}
    \end{frame}
    \begin{frame}
        \frametitle{Equivalence}
        \notes{The other direction is simpler, especially now that we have
        explicitly established a correspondence between the two ideas.}
        \pause

        For the other direction, start with nodes corresponding to the
        hypothesis, and for each step of the weighted proof, introduce nodes for
        the inference rules, with appropriate flow values inferred from the
        weights used. The main issue is proving, again, that the final weights
        satisfy our conditions.
    \end{frame}
    \begin{frame}
        \frametitle{Equivalence}
        \notes{So why would you care? Circular proofs are annoying enough,
        analogies and everything. Everything is equivalent anyway. Circular
        proofs give us intuitive representations of proof ideas, and provide
        intuition for extensions of weighted proofs by being able to access the
        more general ideas of flow networks in graph theory.} Why do I care?
        \pause Graphs!

        \pause Infact, the actual proof of equivalence relies on introducing
        terms of the form $(A, n), (A, -n)$. \pause This inherently circular ideology
        allows us to simplify our proofs by introducing clauses before they're
        available, making promises for their arrival. \pause All's fine, \emph{as long
        as we keep our promises.}
    \end{frame}

    \begin{frame}
        \frametitle{Dual Rail Disbelief of Making it this Far}

        The basic idea behind Dual Rail Proofs is simple, treat literals $x$ and
        $\lnot x$ as different variables. \pause This creates several issues in
        the case of SAT as we know, unless your clauses are in certain forms.
        \pause Here, manipulating the weights allows us to (somewhat) simplify
        that issue, while helping our cause too. \notes{We would need to
        explicitly derive empty clauses to obtain unsat.}

    \end{frame}

    \begin{frame}
        \frametitle{Dual-Rail Equivalent systems }

        No general version of this proof is given. The discussion is limited to
        Dual Rail MaxSAT (with resolution) and what we need to add to
        circular/weighted proofs to obtain equivalence. \pause Turns out, not
        too bad. \pause Allowing 0-SPLITs, i.e. +n, -n clauses from nothing,
        instead of the usual SPLIT, makes it equivalent.

    \end{frame}

    \begin{frame}{References}
        \bibliographystyle{amsalpha}
        \bibliography{ref.bib}
    \end{frame}
\end{document}


\documentclass{article}

\author{Saif Ul Islam}
\date{Sep 7th, 2020}
\title{Algorithms, Week 2, Lec 1}

\begin{document}

    \maketitle

    \tableofcontents

    \section{General Analysis Strategy}

    \begin{enumerate}
        \item T(n): Maximum line taken by algorithm to solve any input of size n
        \item T(n): Measure of goodness, how good or bad inidicated by function
        \item The function will indicate how good is a algorithm
        \item Conservative Definition - \textit{Worst Case}.
    \end{enumerate}

    What is \textit{T(n)}? It indicates the maximum time it would take for a machine to run that algorithm - the worst case scenario?

    \begin{enumerate}
        \item Form of T(n) (independent from machine)
        \item "Linear", "Cubic", "Quadratic" etc
        \item Bounds of T(n), upper bound, lower bound
        \item Large n is important, as n becomes larger and larger which algorithm is better
    \end{enumerate}

    \section{Running Time Analysis}

    \begin{enumerate}
        \item The running time depends upon the input size, e.g., n
        \item Different inputs of the same size may rsult in different running time
        \item Criteria for measuring running time
        \item Worst-Case Time (Maximum running time over legal inpout of size \textit{n})
        \item Criteria Worst-case time
        \item Let I denote an input instance
        \item Let |I| denote its length
        \item Let T(I) denote the running time of algorihtm on input I
    \end{enumerate}

    Some measurements are as follows,

    \begin{enumerate}
        \item Average Case Time - the average running time over all inputs of size n
        \item Let P(I) denote the probability of seeing this input
        \item Average case time is the weighted sum of running times with weights being the probabilities
    \end{enumerate}

    \subsection{Example: 2-Dimension Maxima}

    The car selection problem can be modelled this way: For each car we assocaite (x, y) pair where,

    \begin{enumerate}
        \item x is the speed of the car
        \item y is the negation of the price
    \end{enumerate}

    \subsubsection{Algorithm}

    MAXIMA(int n, Point P[1 ... n])
        for i <- 1 to n
        do maximal <- true:
            for j <- 1 to n
            do
                if(i != j) and  (P[i].x <= P[j].x) and (P[i].y <= P[j].y)
                    then maximal <- false;
                    break;
                if maximal == true
                    continue;

    \subsubsection{Analysis}

    To do \textit{Analysis}, just count the steps,

\end{document}

Semester V/Algorithms/Sir Muhammad Waqas/Recorded Notes/Sep 7, 2020.tex


\documentclass{article}
\usepackage{amsmath} % aligned env

\usepackage{relsize} % make some math large
\usepackage{bm} % make some math bold

\usepackage{caption}
\usepackage{geometry}
\geometry{
	a4paper,
	noheadfoot=true,
	left=1.0in,
	right=1.0in,
	top=1.0in,
	bottom=1.0in,
}

\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing}

\definecolor{myLightGray}{RGB}{191,191,191}
\definecolor{myGray}{RGB}{160,160,160}
\definecolor{myDarkGray}{RGB}{144,144,144}
\definecolor{myDarkRed}{RGB}{167,114,115}
\definecolor{myRed}{RGB}{255,58,70}
\definecolor{myGreen}{RGB}{0,255,71}

\begin{document}

\title{Latex Tikz Examples, Timeline Charts}
\author{\href{https://fanwangecon.github.io/}{Fan Wang}\thanks{https://fanwangecon.github.io, repository: \href{https://fanwangecon.github.io/Tex4Econ/}{Tex4Econ}}}
\date{\today}

\section{Tikz Example 1}

\begin{tikzpicture}[scale=1]
\node[align=center] at (1,0.5) {Susceptible\\stage};
\node[align=center] at (2.25,1.85) {Time of\\infection};
\draw [thick,->] (2.25,1.4) -- (2.25,0.15);
\node[align=center] at (3.15,0.85) {Latent\\period};
\draw [thick,decorate,decoration={brace,amplitude=6pt,raise=0pt}] (2.5,0.15) -- (3.75,0.15);
\draw [thick,->] (4,0.85) -- (4,0.15);
\node[align=center] at (6.25,0.6) {Infectious period};
\draw [thick,->] (8.25,0.85) -- (8.25,0.15);
\node[align=center] at (9.15,0.5) {Immune\\stage};
\draw [thick,decorate,decoration={brace,amplitude=6pt,raise=0pt}] (4.25,0.15) -- (8,0.15);
\draw [thick,->] (0,0) -- (10,0);
\draw [thick,->] (4.6,-0.85) -- (4.6,-0.15);
\draw [thick,->] (7.65,-0.4) -- (7.65,-0.15);
\draw [thick,decorate,decoration={brace,amplitude=6pt,raise=0pt,mirror}] (4.75,-0.15) -- (7.5,-0.15);
\node[align=center] at (6.25,-0.85) {Symptomatic\\period};
\node[align=center] at (4.6,-1.3) {Onset of\\symptoms};
\end{tikzpicture}

\section{Tikz Example 2}

\begin{tikzpicture}[%
    every node/.style={
        font=\footnotesize,
        text height=1ex,
        text depth=.25ex,
    },
]
% draw horizontal line
\draw[->] (0,0) -- (8.5,0);

% draw vertical lines
\foreach \x in {0,1,...,8}{
    \draw (\x cm,3pt) -- (\x cm,0pt);
}

% place axis labels
\node[anchor=north] at (1,0) {$t-1$};
\node[anchor=north] at (4,0) {$t$};
\node[anchor=north] at (5,0) {$t$};
\node[anchor=north] at (7,0) {$t+2$};

% draw scale above
\fill[myLightGray] (1,0.25) rectangle (2,0.4);
\fill[myDarkGray] (2,0.25) rectangle (3,0.4);
\fill[myDarkRed] (3,0.25) rectangle (4,0.4);
\fill[myRed] (4,0.25) rectangle (5,0.4);
\draw[myRed,dashed,thick,-latex] (5.05,0.325) -- (6.05,0.325);

% draw scale below
\fill[myLightGray] (3,-0.4) rectangle (4,-0.55);
\fill[myGray] (4,-0.4) rectangle (5,-0.55);
\fill[myGreen] (5,-0.4) rectangle (6,-0.55);
\draw[myGreen,dashed,thick,-latex] (6.05,-0.475) -- (7.05,-0.475);

% draw curly braces and add their labels
\draw[decorate,decoration={brace,amplitude=5pt}] (3,0.45) -- (5,0.45)
    node[anchor=south,midway,above=4pt] {Training period};
\draw[decorate,decoration={brace,amplitude=5pt}] (6,-0.6) -- (5,-0.6)
    node[anchor=north,midway,below=4pt] {Testing period};

% Add Lines
\node[align=center] at (2.25,1.85) {Realization of Shocks};
\draw [thick,->] (2,1.4) -- (2,0.15);

\end{tikzpicture}

\section{Tikz Example 3}

\begin{tikzpicture}
\draw (0,0) -- (13,0);
\foreach \x in {0,2,4,6,8,12,13}
  \draw (\x cm,3pt) -- (\x cm,-3pt);
\draw (0,0) node[below=3pt] (a) {$(i)$} node[above=3pt] {};
\draw (2,0) node[below=3pt] (b) {} node[above=3pt] {$(ii)$};
\draw (4,0)  node[below=3pt]  {$(iii)$} node[above=3pt] (c) {};
\draw (6,0) node[below=3pt](d) {} node[above=3pt] {$(iv)$};
\draw (8,0) node[below=3pt](e) {$(v)$} node[above=3pt] {};
\draw (12,0) node[above=3pt] (f) {$(vi)$} node[below=3pt] {};
\draw[latex-latex]
  (e.north) -- (f.north);
\draw[latex-latex,blue]
  (e.north) to[bend left] (f.north);
\draw[latex-latex,red]
  (e.north) to[out=60,in=150] (f.north);
\end{tikzpicture}\qquad

\section{Tikz Example 4}

\begin{tikzpicture}
\draw (0,0) -- (13,0);
\foreach \x in {0,2,4,6,8,12,13}
  \draw (\x cm,3pt) -- (\x cm,-3pt);
\draw (0,0) node[below=3pt] (a) {$(i)$} node[above=3pt] {};
\draw (2,0) node[below=3pt] (b) {} node[above=3pt] {$(ii)$};
\draw (4,0)  node[below=3pt]  {$(iii)$} node[above=3pt] (c) {};
\draw (6,0) node[below=3pt](d) {} node[above=3pt] {$(iv)$};
\draw (8,0) node[below=3pt](e) {$(v)$} node[above=3pt] {};
\draw (12,0) node[above=3pt] (f) {$(vi)$} node[below=3pt] {};
\draw[latex-latex]
  (e.north|-f.north) -- (f.north);
\draw[latex-latex,blue]
  (e.north|-f.north) to[bend left] (f.north);
\draw[latex-latex,red]
  (e.north|-f.north) to[out=60,in=120] (f.north);
\end{tikzpicture}

\section{Tikz With Caption}

\begin{figure}[!ht]
\centering
\begin{tikzpicture}[object/.style={thin,double,<->}]
  \draw[object] (7cm,-1cm) -- (6cm,-2cm) node[midway,above] {a label};
\end{tikzpicture}
\caption{A caption.}
\end{figure}

\section{Tikz Timeline}

\subsection{Tikz Timeline Plain}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Model Timeline
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{figure}[h]
  \begin{minipage}{1\linewidth}
  \caption{Model Timeline}
  \begin{tikzpicture}
  \draw (0,0) -- (12,0);
  \foreach \x in {0,3,6,9,12}
    \draw (\x cm,2pt) -- (\x cm,-2pt);
  % Last Period
  \node[align=center] at (1.5, 0.7) {choose \\ $k, b$ };
  % Current Period
  \node[align=center] at (3, 2.1)  (a) {$ \epsilon$ \\ realized};
  \draw [thin, -] (3, 1.6) -- (3, 0);
  \node[align=center] at (4.5, 0.7) (b) {wealth  \\ $\Lambda(k,b, \epsilon)$ };
  \node[align=center] at (6, 1.6)  (a) {$ r^I$ \\ realized};
  \draw [thin, dashed] (6, 1.0) -- (6, 0);
  \node[align=center] at (7.5, 0.7) {choose \\ $k^{\prime}, b^{\prime}(r^I)$ };
  % Next Period
  \node[align=center] at (9, 2.1) {$ \epsilon^{\prime}$ \\ realized};
  \draw [thin, -] (9, 1.6) -- (9, 0);
  \node[align=center] at (10.5, 0.7) {wealth  \\ $\Lambda(k^{\prime}, b^{\prime}, \epsilon^{\prime})$ };
  \node[align=center] at (12, 1.6)  (a) {$ r^{I\prime}$ \\ realized};
  \draw [thin, dashed] (12, 1.0) -- (12, 0);
  % Text Below
  \draw (1,0) node[below=7pt] {\textbf{last} period};
  % \draw [thick,decorate,decoration={brace,amplitude=6pt,raise=0pt,mirror}] (2.8,-0.30) -- (8.8,-0.30);
  \draw (6,0)  node[below=7pt]  {\textbf{current} period};
  \draw (11,0) node[below=7pt] {\textbf{next} period};
  % % Arrows
  % \draw[latex-latex,blue]
  %   (a.north|-b.north) to[out=60,in=120] (b.north);
  % \draw[latex-latex,red]
  %   (e.north|-f.north) to[out=60,in=120] (f.north);
  \end{tikzpicture}
  {\footnotesize
  \emph{Notes:} (1) $k$, the risky capital choice, is determined before productivity shock $\epsilon$ realization. (2) $b^{\prime}$, the net financial choice including principle and interests owed, is determined given $r^I$, which is the interest rate cost of informal loan taken out this period.}
  \end{minipage}
  \end{figure}

  \subsection{Tikz Timeline with Skeleton Tree}
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  %%% Model Timeline With Tree Inside
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

  \tikzset{
      % Two node styles for game trees: solid and hollow
      solid node/.style={circle,draw,inner sep=1.5,fill=black},
      hollow node/.style={circle,draw,inner sep=1.5,fill=white}
  }

  \def\famm{15mm}
  \def\height{2}
  \tikzstyle{level 1}=[level distance=\famm,sibling distance=\famm]
  \tikzstyle{level 2}=[level distance=\famm,sibling distance=\famm]

  \begin{figure}[h]
    \begin{minipage}{1\linewidth}
    \caption{Model Timeline With Tree Inside}
    \begin{tikzpicture}
    \draw (0,0) -- (12,0);
    \foreach \x in {0,2,4,12}
      \draw (\x cm,2pt) -- (\x cm,-2pt);
    % Last Period
    \node[align=center] at (1, 0.7) {choose \\ $k, b$ };
    % Current Period
    \node[align=center] at (2, 2.1)  (a) {$ \epsilon$ \\ realized};
    \draw [thin, -] (2, 1.6) -- (2, 0);
    \node[align=center] at (3, 0.7) (b) {wealth  \\ $\Lambda(k,b, \epsilon)$ };
    \node[align=center] at (4, 1.6)  (a) {$ r^I$ \\ realized};
    \draw [thin, dashed] (4, 1.0) -- (4, 0);
    \node[solid node, align=center, label=left:{$P1$}]  at (6, 1.5) {}
    [grow=right]
    child
    child{
        [grow=right]
        child
        child{
            [grow=right]
            child
            child
            child
            child
            }
        child
        }
    child;
    % Next Period
    \node[align=center] at (12, 2.1) {$ \epsilon^{\prime}$ \\ realized};
    \draw [thin, -] (12, 1.6) -- (12, 0);
    % Text Below
    \draw (1,0) node[below=7pt] {\textbf{last} period};
    \draw (6,0) node[below=7pt]  {\textbf{current} period};
    % % Arrows
    % \draw[latex-latex,blue]
    %   (a.north|-b.north) to[out=60,in=120] (b.north);
    % \draw[latex-latex,red]
    %   (e.north|-f.north) to[out=60,in=120] (f.north);
    \end{tikzpicture}
    {\footnotesize
    \emph{Notes:} (1) $k$, the risky capital choice, is determined before productivity shock $\epsilon$ realization. (2) $b^{\prime}$, the net financial choice including principle and interests owed, is determined given $r^I$, which is the interest rate cost of informal loan taken out this period.}
    \end{minipage}
    \end{figure}

\subsection{Tikz Timeline with Spanning and Annotated Tree}
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  %%% Model Timeline With Fancy Tree Inside
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

  \def\famm{20mm}
  \def\height{2}
  \tikzstyle{level 1}=[level distance=\famm,sibling distance=\famm]
  \tikzstyle{level 2}=[level distance=\famm,sibling distance=\famm]

  \begin{figure}[h]
    \begin{minipage}{1\linewidth}
    \caption{Model Timeline with Fancy Tree Inside}
    \begin{tikzpicture}
    \draw (0,0) -- (12,0);
    \foreach \x in {0,2,4,12}
      \draw (\x cm,2pt) -- (\x cm,-2pt);
    % Last Period
    \node[align=center] at (1, 0.7) {choose \\ $k, b$ };
    % Current Period
    \node[align=center] at (2, 2.1)  (a) {$ \epsilon$ \\ realized};
    \draw [thin, -] (2, 1.6) -- (2, 0);
    \node[align=center] at (3, 0.7) (b) {wealth  \\ $\Lambda(k,b, \epsilon)$ };
    \node[align=center] at (4, 1.6)  (a) {$ r^I$ \\ realized};
    \draw [thin, dashed] (4, 1.0) -- (4, 0);

    \node(0)[solid node, align=center, % solid node gives fist (left to right) black dot
    label=left:{
       $\textcolor{black}{\mathlarger{\mathlarger{\mathlarger{\bm{\phi}}}}}$
        }] at (5.75, 1.5) {}
    [grow=right]
    child{
    [black] node(11)[]{}
    edge from parent
          node[sloped, below, black]{$\phi=0$}
    }
    child{
    [grow=right]
    % The starting node for theta
    node(12)[solid node, xshift=16, yshift=0, % solid node gives second (left to right) black dot
                    label=left:{
                      $\textcolor{black}{\mathlarger{\mathlarger{\mathlarger{\bm{\theta}}}}}$
                    }]{}
    % Draw the theta branches
      child{
          [red] node(21)[]{}
          edge from parent
              node[sloped, below, black]{$\theta=0$}
      }
      child{
          [white] node(22)[xshift=16, yshift=0]{}
          edge from parent
              [draw=none] % prevents a line to be drawn from phi to phi
              node[above, black, xshift=7]{$k' = \theta \cdot \Lambda$}
              node[below, black, xshift=10]{$b' = \Lambda - k'$}
      }
      child{
          [black] node(23)[]{}
          edge from parent
              node[sloped, above, black]{$\theta=1$}
      }
    edge from parent
      [draw=none] % prevents a line to be drawn from phi to phi
      % node[above, black, yshift=-55]{$c = \phi \cdot \Gamma$}
      % node[below, black, yshift=-55]{$\Lambda = \left(1-\phi\right) \cdot \Gamma$}
      node[above, black, xshift=4]{$c = \phi \cdot \Gamma$}
      node[below, black, xshift=4]{$\Lambda = \Gamma - c$}
      }
    child{
    [red] node(13)[]{}
    edge from parent
          node[sloped, above, black]{$\phi=1$}
    };
    \draw[dashed, bend right]
    (11) to (13);
    \draw[dashed, bend right]
    (21) to (23);
    % Next Period
    \node[align=center] at (12, 2.1) {$ \epsilon^{\prime}$ \\ realized};
    \draw [thin, -] (12, 1.6) -- (12, 0);
    % Text Below
    \draw (1,0) node[below=7pt] {\textbf{last} period};
    \draw (6.5,0) node[below=7pt]  {\textbf{current} period, $\Lambda$ realized, choose $k'$ and $b'$};
    % % Arrows
    % \draw[latex-latex,blue]
    %   (a.north|-b.north) to[out=60,in=120] (b.north);
    % \draw[latex-latex,red]
    %   (e.north|-f.north) to[out=60,in=120] (f.north);
    \end{tikzpicture}
    {\footnotesize
    \emph{Notes:} (1) $k$, the risky capital choice, is determined before productivity shock $\epsilon$ realization. (2) $b^{\prime}$, the net financial choice including principle and interests owed, is determined given $r^I$, which is the interest rate cost of informal loan taken out this period.}
    \end{minipage}
    \end{figure}

\section{Tikz Timeline Frame}

\subsection{Empty Frame}

\def\fgw{1.0*\textwidth}
\def\fgh{0.20*\textheight}

\newcommand{\tikzframe}{
	\draw (0,     \fgh) -- (\fgw,     \fgh);
	\draw[loosely dotted] (0, 0.5*\fgh) -- (\fgw, 0.5*\fgh);
	\draw (0, 0       ) -- (\fgw, 0       );
	% Three Straight Lines
	\draw[dashed] (0.125*\fgw, 0  ) -- (0.125*\fgw,   \fgh);
	\draw[dotted] (0.500*\fgw, 0.2*\fgh ) -- (0.500*\fgw,   0.8*\fgh);
	\draw[dashed] (0.875*\fgw, 0  ) -- (0.875*\fgw,   \fgh);

	\node[align=center] at (0.065*\fgw, 0.900*\fgh) {last\\period};
	\node[align=center] at (0.500*\fgw, 0.900*\fgh) {current period};
	\node[align=center] at (0.935*\fgw, 0.900*\fgh) {next\\period};

	\node[align=center] at (0.325*\fgw, 0.100*\fgh) {shocks and \\ income realization};
	\node[align=center] at (0.675*\fgw, 0.100*\fgh) {asset choices};
}
\newcommand{\tikzframebelowtext}[4]{
  \def\fgiw{#1*\textwidth}
  \def\fgih{#2*\textheight}
  \def\fgiwm{#3*\fgiw}
  \def\fgihm{#4*\fgih}

  % left pane middle point, align horizontally middle pane
  \def\fgiwlm{0.125*\textwidth + \fgiwm*0.5 - 0.5*0.125*\textwidth}
  % right pane middle point, align horizontally middle in pane
  \def\fgiwrm{\fgiwm + \fgiw*0.5 - 0.125*\textwidth*0.5 - \fgiwm*0.5}

  % fgihtb: figure internal height top pane bottom
  % bottom 10 percent space of top pane space
  \def\fgihtb{\fgihm + \fgih*0.085 - \fgihm*0.085}

  % There is a flow line on top, limited text
  % three parts, left prior, right after, middle current.
  % current in two parts, shock realization and choices.
  % In top part, span charts, simple text
  % in bottom part, sufficient height to allow for detailed text
  % descriptions.

  % Bottom and top lines
  \draw [solid] (0, \fgih) -- (\fgiw, \fgih);
  \draw [solid] (0, 0    ) -- (\fgiw, 0    );

  % Left and right lines
  \draw [solid] (0,     0) -- (0,     \fgih);
  \draw [solid] (\fgiw, 0) -- (\fgiw, \fgih);

  % verticle middle line
  \draw [solid] (\fgiwm, 0) -- (\fgiwm,   \fgih);
  % horizontal middle line (divide text and flow)
  \draw [solid] (0, \fgihm) -- (\fgiw,   \fgihm);

  % left border last period
  \draw[dashed] (0.125*\fgiw, 0  ) -- (0.125*\fgiw,   \fgih);
  % right border next period
  \draw[dashed] (0.875*\fgiw, 0  ) -- (0.875*\fgiw,   \fgih);

  % %
  % \draw[loosely dotted] (0, 0.575*\fgih) -- (\fgiw, 0.575*\fgih);
  % \draw[loosely dotted] (0, 0.350*\fgih) -- (\fgiw, 0.350*\fgih);

  \node[align=center] at (0.065*\fgiw, 0.900*\fgih) {last\\period};
  \node[align=center] at (0.500*\fgiw, 0.900*\fgih) {current period};
  \node[align=center] at (0.935*\fgiw, 0.900*\fgih) {next\\period};

  \node[align=center] at (\fgiwlm, \fgihtb) {shocks};
  \node[align=center] at (\fgiwrm, \fgihtb) {asset choices};
}

100 percent frame with 20 percent page height and 100 percent page width:

\begin{center}
\begin{tikzpicture}[scale=1.0]
\tikzframe
\end{tikzpicture}
\end{center}

50 percent rescaled center-aligned frame with 20 percent page height and 100 percent page width:

\begin{center}
\begin{tikzpicture}[scale=0.5, every node/.style={scale=0.5}]]
\tikzframe
\end{tikzpicture}
\end{center}

\subsection{Frame Filled Choice}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Define Common Blocks
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Define text block
\newcommand{\textblock}{
\node[align=center] (A) at (0.065*\fgw, 0.5*\fgh)
    {choose \\ $k, b$ };
\node[align=center] (B) at (0.370*\fgw, 0.5*\fgh)
    {$\Gamma\left(k,b,\epsilon\right)$ };
\node[align=center] (C) at (0.790*\fgw, 0.5*\fgh)
    {$\begin{aligned}
      c &= \Gamma\cdot\phi\\
      k &= \Gamma\cdot\phi\cdot\theta\\
      b &= \Gamma\cdot\phi\cdot\left(1-\theta\right)
      \end{aligned}$};
\node[align=center] (D) at (0.935*\fgw, 0.5*\fgh)
    {draw \\$\epsilon^{\prime}$ shock};
}

% Define continuous choices
\def\famm{10mm}
\tikzstyle{level 1}=[level distance=\famm,sibling distance=\famm]
\tikzstyle{level 2}=[level distance=\famm,sibling distance=\famm]
\newcommand{\shkspan}[2]{
\node(0)[solid node, align=center, % solid node gives fist (left to right) black dot
label=left:{
   $\textcolor{black}{\epsilon}$
    }] at (#1, #2) {}
[grow=right]
child{
    [black] node(31)[]{}
    edge from parent
          node[sloped, below, black]{}
}
child{
    edge from parent
      [draw=none]
  }
child{
    [red] node(33)[]{}
    edge from parent
          node[sloped, above, black]{}
};
\draw[dashed, bend right]
(31) to (33);
}
\newcommand{\ctsspans}[2]{
\node[solid node, align=center, % solid node gives fist (left to right) black dot
label=left:{
   $\textcolor{black}{\phi}$
    }] at (#1, #2) {}
[grow=right]
child{
[black] node(11)[]{}
edge from parent
      node[sloped, below, black]{$\phi=0$}
}
child{
[grow=right]
% The starting node for theta
node(12)[solid node, xshift=9, yshift=0, % solid node gives second (left to right) black dot
                label=left:{
                  $\theta$
                }]{}
% Draw the theta branches
    child{
        [red] node(21)[]{}
        edge from parent
            node[sloped, below, black]{$\theta=0$}
    }
    child{
        [white] node(22)[xshift=16, yshift=0]{}
        edge from parent
          [draw=none]
    }
    child{
        [black] node(23)[]{}
        edge from parent
            node[sloped, above, black]{$\theta=1$}
    }
    edge from parent
      [draw=none]
  }
child{
[red] node(13)[]{}
edge from parent
      node[sloped, above, black]{$\phi=1$}
};
\draw[dashed, bend right]
(11) to (13);
\draw[dashed, bend right]
(21) to (23);
}

\subsubsection{Spans to Left of Descriptions, 100 percent}
% A. Frame
\begin{center}
\begin{tikzpicture}[scale=1.0]
\tikzframe
% B. Text
\textblock
% C. Arrows
\draw [->, line width=0.25mm] (0.115*\fgw, 0.5*\fgh) -- (0.195*\fgw, 0.5*\fgh);
\draw [->, line width=0.25mm] (0.410*\fgw, 0.5*\fgh) -- (0.480*\fgw, 0.5*\fgh);
\draw [->, line width=0.25mm] (0.835*\fgw, 0.5*\fgh) -- (0.890*\fgw, 0.5*\fgh);
% D. Span Children
\ctsspans{0.530*\fgw}{0.500*\fgh}
\shkspan{0.235*\fgw}{0.500*\fgh}
% \draw  -- (10,0);
\end{tikzpicture}
\end{center}

\subsubsection{Spans to Left of Descriptions, 50 percent}
% A. Frame
\begin{center}
\begin{tikzpicture}[scale=0.5, every node/.style={scale=0.5}]
\tikzframe
% B. Text
\textblock
% C. Arrows
\draw [->, line width=0.25mm] (0.115*\fgw, 0.5*\fgh) -- (0.195*\fgw, 0.5*\fgh);
\draw [->, line width=0.25mm] (0.410*\fgw, 0.5*\fgh) -- (0.480*\fgw, 0.5*\fgh);
\draw [->, line width=0.25mm] (0.835*\fgw, 0.5*\fgh) -- (0.890*\fgw, 0.5*\fgh);
% D. Span Children
\ctsspans{0.530*\fgw}{0.500*\fgh}
\shkspan{0.235*\fgw}{0.500*\fgh}
% \draw  -- (10,0);
\end{tikzpicture}
\end{center}

\subsubsection{Frame Filled Choice Spans Above Descriptions}
% A. Frame
\begin{center}
\begin{tikzpicture}[scale=1.0, every node/.style={scale=1.0}]
\tikzframebelowtext{1}{0.25}{0.4}{0.35}
% \draw  -- (10,0);
\end{tikzpicture}
\end{center}

\begin{center}
\begin{tikzpicture}[scale=1.0, every node/.style={scale=1.0}]
\tikzframebelowtext{0.6}{0.20}{0.4}{0.35}
% \draw  -- (10,0);
\end{tikzpicture}
\end{center}

\begin{center}
\begin{tikzpicture}[scale=1.0, every node/.style={scale=1.0}]
\tikzframebelowtext{1}{0.15}{0.5}{0.5}
% \draw  -- (10,0);
\end{tikzpicture}
\end{center}

\subsubsection{Frame Filled Choice Spans Above Descriptions}
% A. Frame
\begin{center}
\begin{tikzpicture}[scale=1.0, every node/.style={scale=1.0}]
\tikzframebelowtext{1}{0.25}{0.4}{0.4}
% B. Text
\node[align=center] (A) at (0.065*\fgw, 0.65*\fgh)
    {choose \\ $k, b$ };
\node[align=center] (B) at (0.320*\fgw, 0.350*\fgh)
    {$\Gamma\left(k,b,\epsilon\right)$ };
\node[align=center] (C) at (0.675*\fgw, 0.350*\fgh)
    {$\begin{aligned}
      c &= \Gamma\cdot\phi\\
      k &= \Gamma\cdot\phi\cdot\theta\\
      b &= \Gamma\cdot\phi\cdot\left(1-\theta\right)
      \end{aligned}$};
\node[align=center] (D) at (0.935*\fgw, 0.65*\fgh)
    {draw \\$\epsilon^{\prime}$ shock};
% C. Arrows
\draw [->, line width=0.25mm] (0.115*\fgw, 0.65*\fgh) -- (0.250*\fgw, 0.65*\fgh);
\draw [->, line width=0.25mm] (0.410*\fgw, 0.65*\fgh) -- (0.550*\fgw, 0.65*\fgh);
\draw [->, line width=0.25mm] (0.790*\fgw, 0.65*\fgh) -- (0.890*\fgw, 0.65*\fgh);
% D. Span Children
\ctsspans{0.600*\fgw}{0.650*\fgh}
\shkspan{0.300*\fgw}{0.650*\fgh}
% \draw  -- (10,0);
\end{tikzpicture}
\end{center}

\end{document}


\documentclass{article}

\usepackage{fancyhdr}
\usepackage{extramarks}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{amsfonts}
\usepackage{tikz}
\usepackage{physics}
\usepackage[plain]{algorithm}
\usepackage{algpseudocode}

\usetikzlibrary{automata,positioning}

%
% Basic Document Settings
%

\topmargin=-0.45in
\evensidemargin=0in
\oddsidemargin=0in
\textwidth=6.5in
\textheight=9.0in
\headsep=0.25in

\linespread{1.1}

\pagestyle{fancy}
\lhead{\hmwkAuthorName}
\chead{\hmwkClass\ (\hmwkClassInstructor\ \hmwkClassTime): \hmwkTitle}
\rhead{\firstxmark}
\lfoot{\lastxmark}
\cfoot{\thepage}

\renewcommand\headrulewidth{0.4pt}
\renewcommand\footrulewidth{0.4pt}

\setlength\parindent{0pt}

%
% Create Problem Sections
%

\newcommand{\enterProblemHeader}[1]{
    \nobreak\extramarks{}{Problem \arabic{#1} continued on next page\ldots}\nobreak{}
    \nobreak\extramarks{Problem \arabic{#1} (continued)}{Problem \arabic{#1} continued on next page\ldots}\nobreak{}
}

\newcommand{\exitProblemHeader}[1]{
    \nobreak\extramarks{Problem \arabic{#1} (continued)}{Problem \arabic{#1} continued on next page\ldots}\nobreak{}
    \stepcounter{#1}
    \nobreak\extramarks{Problem \arabic{#1}}{}\nobreak{}
}

\setcounter{secnumdepth}{0}
\newcounter{partCounter}
\newcounter{homeworkProblemCounter}
\setcounter{homeworkProblemCounter}{1}
\nobreak\extramarks{Problem \arabic{homeworkProblemCounter}}{}\nobreak{}

\newcommand{\be}{\begin{equation}}
\newcommand{\ee}{\end{equation}}
\newcommand{\bes}{\begin{equation*}}
\newcommand{\ees}{\end{equation*}}
\newcommand{\bea}{\begin{flalign*}}
\newcommand{\eea}{\end{flalign*}}
%
% Homework Problem Environment
%
% This environment takes an optional argument. When given, it will adjust the
% problem counter. This is useful for when the problems given for your
% assignment aren't sequential. See the last 3 problems of this template for an
% example.
%
\newenvironment{homeworkProblem}[1][-1]{
    \ifnum#1>0
        \setcounter{homeworkProblemCounter}{#1}
    \fi
    \section{Problem \arabic{homeworkProblemCounter}}
    \setcounter{partCounter}{1}
    \enterProblemHeader{homeworkProblemCounter}
}{
    \exitProblemHeader{homeworkProblemCounter}
}

%
% Homework Details
%   - Title
%   - Due date
%   - Class
%   - Section/Time
%   - Instructor
%   - Author
%

\newcommand{\hmwkTitle}{Lecture \#1}
\newcommand{\hmwkDueDate}{\today}
\newcommand{\hmwkClass}{Trefethen and Bau}
\newcommand{\hmwkClassTime}{}
\newcommand{\hmwkClassInstructor}{Professor Isaac Newton}
\newcommand{\hmwkAuthorName}{\textbf{Aditya Vijaykumar}}

%
% Title Page
%

\title{
    %\vspace{2in}
    \textmd{\textbf{\hmwkClass:\ \hmwkTitle}}\\
    \normalsize\vspace{0.1in}\small{\hmwkDueDate\ }\\
%    \vspace{3in}
}

\author{\hmwkAuthorName}
\date{}

\renewcommand{\part}[1]{\textbf{\large Part \Alph{partCounter}}\stepcounter{partCounter}\\}

%
% Various Helper Commands
%

% Useful for algorithms
\newcommand{\alg}[1]{\textsc{\bfseries \footnotesize #1}}

% For derivatives
\newcommand{\deriv}[1]{\frac{\mathrm{d}}{\mathrm{d}x} (#1)}

% For partial derivatives
\newcommand{\pderiv}[2]{\frac{\partial}{\partial #1} (#2)}

% Integral dx
\newcommand{\dx}{\mathrm{d}x}

% Alias for the Solution section header
\newcommand{\solution}{\textbf{\large Solution}}

% Probability commands: Expectation, Variance, Covariance, Bias
\newcommand{\E}{\mathrm{E}}
\newcommand{\Var}{\mathrm{Var}}
\newcommand{\Cov}{\mathrm{Cov}}
\newcommand{\Bias}{\mathrm{Bias}}

\begin{document}

\maketitle

%\pagebreak
\begin{homeworkProblem}\small
$\left[\begin{array}{cccc}
1 & -1 & 0 & 0	\\
0 & 1 & 0 & 0	\\
0 & -1 & 1 & 0	\\
0 & -1 & 0 & 1
\end{array}\right]
\left[\begin{array}{cccc}
1 & 0 & 1 & 0	\\
0 & 1 & 0 & 0	\\
0 & 0 & 1 & 0	\\
0 & 0 & 0 & 1
\end{array}\right]
\left[\begin{array}{cccc}
1 & 0 & 0 & 0	\\
0 & 1 & 0 & 0	\\
0 & 0 & \frac{1}{2} & 1	\\
0 & 0 & 0 & 0
\end{array}\right]$B
$\left[\begin{array}{cccc}
2 & 0 & 0 & 0	\\
0 & 1 & 0 & 0	\\
0 & 0 & 1 & 0	\\
0 & 0 & 0 & 1
\end{array}\right]
\left[\begin{array}{cccc}
0 & 0 & 0 & 1	\\
0 & 1 & 0 & 0	\\
0 & 0 & 1 & 0	\\
1 & 0 & 0 & 0
\end{array}\right]
\left[\begin{array}{cccc}
1 & 0 & 0 & 0	\\
0 & 1 & 0 & 0	\\
0 & 0 & 1 & 1	\\
0 & 0 & 0 & 0
\end{array}\right]
\left[\begin{array}{cccc}
0 & 0 & 0	\\
1 & 0 & 0	\\
0 & 1 & 0	\\
0 & 0 & 1
\end{array}\right]
$\\

A is just the product of all matrices to the left of B and C is just the product of all matrices to the right of B.

\end{homeworkProblem}

\begin{homeworkProblem}
\textbf{Part (a)}
\begin{flalign*}
	f_1&=k_{12} \left(-l_{12}-x_1+x_2\right)\\
	f_2&=k_{23} \left(-l_{32}-x_2+x_3\right)-k_{12} \left(-l_{12}-x_1+x_2\right)\\
	f_3&=k_{34} \left(-l_{34}-x_3+x_4\right)-k_{23} \left(-l_{32}-x_2+x_3\right)\\
	f_4&=-k_{34} \left(-l_{34}-x_3+x_4\right)
\end{flalign*}
$$\left[\begin{array}{cccc}
f_1 \\
f_2 \\
f_3\\
f_4
\end{array}\right] = \left[\begin{array}{cccc}
-k_{12} & k_{12} & 0 & 0	\\
k_{12} & -(k_{12}+k_{23}) & k_{23} & 0	\\
0 & k_{23} & -(k_{23}+k_{34}) & k_{34}	\\
0 & 0 & k_{34} & -k_{34}
\end{array}\right] \left[\begin{array}{cccc}
x_1 \\
x_2 \\
x_3\\
x_4
\end{array}\right] + (constant \ matrix)$$

\textbf{Part (b)}
The dimensions of K will be that of $\frac{f}{x}$, ie. $\frac{kg}{s^2}$.\\

\textbf{Part (c)}
The dimensions of $\det(K)$ will be ${(\frac{kg}{s^2})}^4$.\\

\textbf{Part (d)}
$$1 \frac{kg}{s^2} = 1000\frac{g}{s^2}$$
$$1 (\frac{kg}{s^2})^4 = 10^{12}\frac{g}{s^2}$$
$$\det(K)=10^{12}\det(K')$$
\end{homeworkProblem}

\begin{homeworkProblem}
Let the identity $I=[e_1,e_2,\ldots,e_m]$, $R^{-1}=[a_1,a_2,\ldots,a_n]$. Let us write the expression $I = R^{-1}R$ as follows,
$$[e_1,e_2,\ldots,e_m]=[a_1,a_2,\ldots,a_n] \left[ \begin{array}{cccc}
r_{11} & r_{12} & \ldots & r_{1m}\\
r_{21} & r_{22} & \ldots & r_{2m}\\
\vdots & \vdots & \vdots & \vdots \\
r_{1m} & r_{2m} & \ldots & r_{mm}\\
\end{array}\right]$$
\end{homeworkProblem}
\end{document}


\documentclass[12pt]{article}

\usepackage{fullpage}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{algorithm}
\usepackage{algpseudocode}
\usepackage{amsthm}
\usepackage{verbatim}% To print as typed ignoring the LaTeX commands
\begin{document}

\title{Algorithm Sample}
%\author{Mamta Dahiya}

\maketitle

\section*{How to write Algorithm in LaTeX}

{\bf Use packages 'algorithm' and 'algpseudocode'}. AN example is given below:

\begin{algorithm}
  \caption{Recursive edit-distance}
  \begin{algorithmic}
    \Procedure{Edit-Distance}{$str1, str2, m, n$}\\
    \Comment number of operations to convert str1 into str2
      \If{$m = 0$}
        \State \Return $n$  \Comment Insert all n characters of str2
      \EndIf
      \If{$n = 0$}
        \State \Return $m$  \Comment Delete all m character of str1
      \EndIf
      \If{$str1[m] = str2[m]$}
        \State \Return \textsc{Edit-Distance}$(str1, str2, m-1, n-1)$ \Comment copy
      \EndIf
      \State \Return $1 + min\{\textsc{Edit-Distance}(str1, str2, m-1, n-1),$ \Comment replace\\
        \hspace{1.25in}\textsc{Edit-Distance}$(str1, str2, m-1, n),$ \Comment delete $str1[m]$\\
        \hspace{1.25in}\textsc{Edit-Distance}$(str1, str2, m, n-1)$\} \Comment insert $str2[n]$
    \EndProcedure
  \end{algorithmic}
\end{algorithm}

See the TeX file to know how the above algorithm is produced.
Read the documentation of the package 'algorithm' for more details.
\end{document}

Lotka_Volterra/Report and ppt/Guidelines for Project-20211027/algo_sample.tex


\section{Dataflow Analysis Algorithm (DFA)}

(Prepared by Aditya Senthilnathan)

In this section, we will now try to answer the question "How do we identify what the DFA value should be at every program point?"

We will only analyse one particular variable x for now. This can easily be generalised for arbitrary number of variables and this is left to the reader.

\subsection{Insight}

DFA of a complex and large program can be expressed as a combination of simple rules relating the change in information between adjacent statements.

\vspace{0.3cm}

We're just going to see
\begin{itemize}
    \item What the value of x is just before this statement
    \item What is the current statement
    \item Based on the current statement, we then use rules (to be discussed) to compute what should be the value after the statement
\end{itemize}

One way to think about this is that we are "pushing" or "transferring" information from one statement to the next. It's almost just like program execution with the caveat that we are not dealing with concrete values anymore but rather abstract DFA values.

\subsection{Function for "Constant Information"}

We now define a function $C(x, s, in/out)$ where,

\begin{itemize}
    \item $x$ - variable for which we want to compute abstract values
    \item $s$ - statement s in the program
    \item $in/out$ - whether it is input to the statement or output to the statement i.e just before the statement or just after the statement.
    \begin{itemize}
        \item $C(x, s, in)$ = Value of x just before s
        \item $C(x, s, out)$ = Value of x just after s i.e just after statement s is executed
    \end{itemize}
\end{itemize}

The idea is to calculate the value of this function $C(x, s, in/out)$ for every x and every s (both in and out)

\subsection{Transfer Function}

We need to define how information is transferred from one statement to another i.e how are we pushing information. For this we need to define a transfer function.

\begin{center}
    \underline{Transfer Function:} transfers information from one statement to another
\end{center}

We are going to define rules for the following two cases:

\begin{itemize}
    \item \textbf{Case 1:} There are one or more predecessor points with edges to the current program point. In this case, we will see how to combine information/values flowing in from the predecessor points to assign a value for the $C()$ function in the current program point
    \item \textbf{Case 2:} For a given statement s, we see how the information/value is modified as it flows through the statement
\end{itemize}

\subsubsection{Transfer function for Global Constant Propagation}

We will define the function by doing an exhaustive case analysis. We can do this kind of finite description of the function with an exhaustive case analysis because there are only a limited number of values and cases to consider.

\vspace{0.3cm}

$C(x, s, p)$ can take only one of 3 different unique values during and after execution of the DFA algorithm i.e $\top, \bot, C$. Also once the algorithm picks a constant value for x at a particular program point, the constant value is fixed and it cannot vary after that. Eg. If the DFA algorithm picks 3, it cannot assign 4 later on. It can only change to either $\top$ or $\bot$ later on in the execution.

\vspace{0.3cm}

\textbf{Rules for the Transfer function:}

\begin{enumerate}
    \item If $C(p_i, x, out) = \bot$ for any i, then $C(x, s, in) = \bot$
    % Insert image
    \item If $C(p_i, x, out) = c$ and $C(p_j, x, out) = d$ and $c \neq d, i \neq j$ for some $i, j$ then, $C(s,x,in) = \bot$
    % Insert image
    \item If $C(p_i, x, out) = c$ or $C(p_i, x, out) = \top$ for all i, then $C(s, x, in) = c$
    \item If $C(p, x_i, out) = \top$ for all i, then $C(s, x, in) = \top$
    \item If $C(s, x, in) = \top$, then $C(s, x, out) = \top$
    \item If rule 5 does not apply i.e $C(s,x,in) \neq \top$, then $C(x := c, x, out) = c$ [where c is a constant]
    \item If rule 5 does not apply i.e $C(s,x,in) \neq \top$, then $C(x := f(...), x, out) = \bot$
    \item $C(y := ..., x, out) = C(y:=..., x, in)$ where $y \neq x$
\end{enumerate}

We now have 8 rules relating $C(s, x, in/out)$ to the value of this function at a predecessor point. These rules are exhaustive.

\vspace{0.3cm}

\underline{But so far we have just stated the rules. How do we get the actual values?}

\vspace{0.3cm}

Think of this as a system of equations. We are interested in solving and identifying values for this $C$ function such that all 10 rules are satisfied.

\vspace{0.3cm}

\underline{How do we solve this system of equations?}

\vspace{0.3cm}

Note that there is a trivial solution,

\begin{center}
    $C(s, x, in/out) = \bot$, for all statements s
\end{center}

All 8 rules are satisfied by this solution but this solution is useless to us because it doesn't allow us to perform any transformations/optimizations. We're not interested in just any solution. We are interested in the "most precise" solution (for some notion of precision). For eg. Saying that $x=4$ at some program point is more precise than just saying $x=\bot$. Similarly, saying that $x=\top$ is more precise than saying $x=\bot$ because the fact that this program point is unreachable is still useful information because now we can consider doing dead code elimination in this part of the program.

\vspace{0.3cm}

To solve this system of equations in a more precise way, we use a Fixed Point Iteration Algorithm.

\vspace{0.3cm}

\underline{Algorithm:}

\vspace{0.3cm}

\begin{itemize}
    \item At every entry point s to the program, set $C(s, x, in) = \bot$
    \item At every other statement s (which is non-entry), set $C(s,x,in) = \top$
    \item For every statement s, $C(s,x,out) = \top$
    \item Repeat the following until all program points satisfy rules 1-8:
    \begin{itemize}
        \item Pick a statement s not satisfying one or more rules in rules 1-8 and update the corresponding $C()$ function value using the appropriate rule
    \end{itemize}
\end{itemize}

There is a guarantee that this algorithm will converge. It will also give us the most precise answer. In the worst case, the solution it gives will be $\bot$ at all program points.


\documentclass[12pt]{article}
\usepackage[pdftex]{graphicx}
\newcommand{\dd}{\mathrm{d}}
\newcommand{\kg}{\mathrm{kg}}
\newcommand{\m}{\mathrm{m}}
\newcommand{\cm}{\mathrm{cm}}
\newcommand{\mm}{\mathrm{mm}}
\newcommand{\km}{\mathrm{km}}
\newcommand{\mi}{\mathrm{mi}}
\newcommand{\s}{\mathrm{s}}
\newcommand{\ms}{\mathrm{ms}}
\newcommand{\h}{\mathrm{h}}
\newcommand{\N}{\mathrm{N}}
\newcommand{\W}{\mathrm{W}}
\newcommand{\hp}{\mathrm{hp}}
\newcommand{\rad}{\mathrm{rad}}
\newcounter{problem}
\stepcounter{problem}
\newcounter{answer}[problem]
\newenvironment{problem}{\noindent\begin{minipage}{\textwidth}\sloppy\sloppypar\raggedright\textbf{\theproblem.}\refstepcounter{problem}\stepcounter{answer}---}{\end{minipage}\\[2ex]}
\newcommand{\source}[1]{[{#1}]}
\newenvironment{answers}{\\[0.5ex]}{}
\newcommand{\answer}[1]{\textbf{\Alph{answer}:}\refstepcounter{answer}~\mbox{#1\hspace{3ex}}}
\newcommand{\longanswer}[1]{\textbf{\Alph{answer}:}\refstepcounter{answer}~{#1}\\}
\begin{document}

\section*{NYU General Physics 1---Term Exam 3}

\begin{problem}
  \source{from lecture 2013-10-24} You analyzed a mass $M$ sitting on
  a table-top of mass $m$ held up on two fulcra (points of contact),
  separated by a distance $L$.  If the mass $M$ is put directly over
  the \emph{left} fulcrum, what is the magnitude of the contact force
  at the \emph{right} fulcrum?  By ``contact force'' we mean the force
  of the fulcrum on the table top.
  \begin{answers}
    \answer{$\displaystyle \frac{m\,g}{2}$}
    \answer{$\displaystyle \frac{M\,g}{2}+\frac{m\,g}{2}$}
    \answer{$\displaystyle M\,g+\frac{mg}{2}$}
    \answer{$\displaystyle M\,g-\frac{mg}{2}$}
    \answer{$\displaystyle \frac{Mg}{2}$}
  \end{answers}
\end{problem}

\begin{problem}
  \source{from lecture 2013-10-29} We considered a hanging sign, with
  the cable at an angle of $\theta$ to the horizontal, as shown.
  \\\includegraphics{../mp/hanging_sign2.pdf}\\ If we choose the
  pin (black dot) connecting the beam and the wall as the axis (reference point), what is the magnitude of
  the torque on the beam coming from the cable marked ``$T_1$''?
  \begin{answers}
    \answer{$T_1\,\cos\theta$}
    \answer{$T_1\,\sin\theta$}
    \answer{$T_1\,L\,\cos\theta$}
    \answer{$T_1\,L\,\sin\theta$}
  \end{answers}
\end{problem}

\begin{problem}
  \source{from lecture 2013-10-31} Just like we did in lecture,
  consider a harmonic oscillator consisting of a mass $m$ attached to
  a spring of spring constant $k$ (force per unit length) on a
  frictionless table.  It oscillates with amplitude $A$.  The period
  of the oscillator:
  \begin{answers}
    \answer{does not depend on the amplitude}
    \answer{does not depend on the mass}
    \answer{does not depend on the spring constant}
    \answer{changes with time}
  \end{answers}
\end{problem}

\begin{problem}
  \source{from lecture 2013-11-05} We considered a stretched brass
  string of density $\rho$ and diameter $D$, fixed at both ends,
  tightened to tension $T$. Assuming $\rho$, $D$, and $T$ remain
  fixed, how does the fundamental frequency of the string depend on
  length $L$?  (Hint: As you change the length, you also change the
  total mass $M$ of the string.)
  \begin{answers}
    \answer{$f\propto 1/L$}
    \answer{$f\propto 1/\sqrt{L}$}
    \answer{$f$ is independent of $L$}
    \answer{$f\propto \sqrt{L}$}
    \answer{$f\propto L$}
  \end{answers}
\end{problem}

\begin{problem}
  \source{from lecture 2013-11-07} We discussed a traveling sinusoidal
  wave on a stretched string.  The wave moved in the $x$ direction,
  and the the bits of string oscillated in the $y$ direction.  What
  statement is \emph{false?}
  \begin{answers}
    \answer{The wave was transverse.}
    \answer{Each bit of string moves in both the $x$ and $y$ directions.}
    \answer{Every bit of string oscillates at precisely the same frequency.}
    \answer{The plots of $y$ vs time and $y$ vs $x$ were both sinusoidal in form.}
  \end{answers}
\end{problem}

\begin{problem}
  \source{from lecture 2013-11-12} The amplitude of the standing wave
  in a piano string, fixed at both ends, declines with time.  What is
  one possible reason?
  \begin{answers}
    \answer{It is subject to static friction.}
    \answer{It is under tension.}
    \answer{It is emitting a sound into the air.}
    \answer{The oscillation frequency is changing with time.}
  \end{answers}
\end{problem}

\begin{problem}
  \source{from problem set 8, problem 1} Where is the center of mass
  of this object, which you considered in the problem set?
  \\\includegraphics{../py/com_shape.pdf}
  \begin{answers}
    \answer{$x=2.5\,\cm$, $y=3.0\,\cm$}
    \answer{$x=3.0\,\cm$, $y=3.0\,\cm$}
    \answer{$x=2.5\,\cm$, $y=3.5\,\cm$}
    \answer{$x=3.0\,\cm$, $y=3.5\,\cm$}
    \answer{None of the above}
  \end{answers}
\end{problem}

\begin{problem}
  \source{from problem set 8, problem 2} Consider the topmost,
  horizontal beam in this bridge, which you considered in the problem
  set.
  \\\includegraphics{../py/bridge.pdf}\\
  Is that top beam under tension or compression?  Assume that the
  joints are bearings, free to rotate!
  \begin{answers}
    \answer{tension}
    \answer{compression}
    \answer{the beam is not under stress}
    \answer{could be either, depending on other details}
  \end{answers}
\end{problem}

\begin{problem}
  \source{from problem set 8, problem 3} If you hold your right arm
  such that your upper arm is vertical and your forearm is horizontal,
  and you have a $10\,\kg$ grocery bag hanging from your right hand,
  \emph{very roughly} what is the contact force between the bones at
  your elbow joint?
  \begin{answers}
    \answer{$0.25\,\N$}
    \answer{$5\,\N$}
    \answer{$100\,\N$}
    \answer{$2000\,\N$}
  \end{answers}
\end{problem}

\begin{problem}
  \source{from problem set 9, problem 1} You solved this problem
  (ladder leaning against the wall) with two choices of ``axis of
  rotation'' or reference point.  There were some differences between
  the two calculations.  In each case you had some forces and some
  torques.  What is true about the corresponding forces and torques
  across the two calculations?
  \begin{answers}
    \longanswer{the corresponding torques and corresponding forces were all the same across the two calculations}
    \longanswer{the corresponding torques were different in the two calculations, but forces were the same}
    \longanswer{the corresponding forces were different in the two calculations, but torques were the same}
    \longanswer{the corresponding torques and forces were all different across the two calculations}
  \end{answers}
\end{problem}

\begin{problem}
  \source{from problem set 9, problem 2} A long, thin rod of length
  $L$ and cross-sectional area $A$ and elastic (Young's) modulus $E$
  has mass $M$.  Think of the rod as being like a Hooke's Law spring;
  it can be stretched by applying a force.  What is the spring
  constant $k$ for this spring?
  \begin{answers}
    \answer{$\displaystyle{E\,L}$}
    \answer{$\displaystyle\frac{E\,A}{L}$}
    \answer{$\displaystyle\frac{E}{A\,L}$}
    \answer{$\displaystyle\frac{L}{E\,A}$}
    \answer{none of these}
  \end{answers}
\end{problem}

\begin{problem}
  \source{from problem set 9, problem 2} You compared the vibration
  frequency $f_1$ of a bone supporting your mass with the pendulum
  frequency $f_2$ of the bone swinging freely under the influence of
  gravity.  What did you find?
  \begin{answers}
    \answer{$f_1 > f_2$}
    \answer{$f_1 = f_2$}
    \answer{$f_1 < f_2$}
  \end{answers}
\end{problem}

\begin{problem}
  \source{from problem set 9, problem 3} You plotted the kinetic
  energy of a simple harmonic oscillator as a function of time.  The
  plot of the kinetic energy $K$ as a function of time has what
  property?
  \begin{answers}
    \longanswer{the average kinetic energy is zero}
    \longanswer{kinetic energy increases and decreases repeatedly with time}
    \longanswer{the plot looks quadratic (like a parabola) everywhere}
    \longanswer{the kinetic energy is at a maximum when the position is at a maximum}
  \end{answers}
\end{problem}

\begin{problem}
  \source{from problem set 10, problem 1} I asked you to differentiate
  the expression
  $$ x(t) = A\,\sin(\omega\,t+\phi) $$ twice with respect to time.
  The second derivative with respect to time of this function is
  \begin{answers}
    \answer{$\displaystyle \frac{\dd^2 x}{\dd t^2} = A\,\cos(\omega\,t+\phi)$}
    \answer{$\displaystyle \frac{\dd^2 x}{\dd t^2} = -\omega^2\,A\,\sin(\omega\,t+\phi)$}
    \answer{$\displaystyle \frac{\dd^2 x}{\dd t^2} = \omega\,A\,\cos(\omega\,t+\phi)$}
    \answer{$\displaystyle \frac{\dd^2 x}{\dd t^2} = \omega^2\,A\,\sin(\omega\,t+\phi)$}
    \answer{$\displaystyle \frac{\dd^2 x}{\dd t^2} = -A\,\sin(\omega\,t+\phi)$}
  \end{answers}
\end{problem}

\begin{problem}
  \source{from problem set 10, problem 2} You made plots of the expression
  $$ y(x,t) = A\,\cos(\frac{2\pi\,x}{\lambda} - \frac{2\pi\,t}{T}) $$
  at various different times.  All these plots were sinusoidal, but
  differed from one another in what respect?
  \begin{answers}
    \answer{the amplitude was different in each plot}
    \answer{the wavelength was different in each plot}
    \answer{each plot was shifted in the $x$-direction relative to the others}
    \answer{each plot was shifted in the $y$-direction relative to the others}
  \end{answers}
\end{problem}

\begin{problem}
  \source{from problem set 10, problem 2} I gave you the expression
  $$ y(x,t) = A\,\cos(\frac{2\pi\,x}{\lambda} - \frac{2\pi\,t}{T}) $$
  where $A$, $\lambda$, and $T$ are constants. This represents a
  traveling wave. At what speed (magnitude of velocity) is it
  traveling?
  \begin{answers}
    \answer{$\displaystyle \lambda\,T$}
    \answer{$\displaystyle \frac{\lambda}{T}$}
    \answer{$\displaystyle \frac{T}{\lambda}$}
    \answer{$\displaystyle 2\,\pi\,\frac{\lambda}{T}$}
    \answer{$\displaystyle 2\,\pi\,\frac{T}{\lambda}$}
  \end{answers}
\end{problem}

\begin{problem}
  \source{from problem set 10, problem 3} The speed of sound in air is
  about
  \begin{answers}
    \answer{$0.3\,\m\,s^{-1}$}
    \answer{$3\,\m\,s^{-1}$}
    \answer{$30\,\m\,s^{-1}$}
    \answer{$300\,\m\,s^{-1}$}
  \end{answers}
\end{problem}

\begin{problem}
  \source{from \textit{Conservation of Energy} lab} You used a
  pendulum consisting of a mass on a light string.  Why does the
  tension force in the string not do any work on the mass?  That is,
  why do you not have to consider the tension force when you
  calculate the potential or kinetic energies?
  \begin{answers}
    \longanswer{The tension force is always perpendicular to the direction of motion.}
    \longanswer{The tension force is zero.}
    \longanswer{The tension force does not act on the mass.}
    \longanswer{The force of the mass on the string is opposite to the force of the string on the mass.}
  \end{answers}
\end{problem}

\begin{problem}
  \source{from \textit{Collisions in One Dimension} lab} In the lab
  you did some collision in which the lab write-up said that ``energy
  is not conserved.'' What was the more \emph{precise} meaning of this
  in the context of the lab?
  \begin{answers}
    \longanswer{The laws of physics don't hold in Meyer Hall.}
    \longanswer{Kinetic energy is not always conserved.}
    \longanswer{Momentum is not always conserved.}
    \longanswer{It is impossible to calculate the kinetic energy in these kinds of collision problems.}
  \end{answers}
\end{problem}

\begin{problem}
  \source{from \textit{Ballistic Pendulum} lab} You inferred the speed
  of the ball out of the gun by using an equation that looked like
  $$ v = D \left(\frac{g}{2\,d}\right)^{\frac{1}{2}} $$ This equation
  depends on some premises or assumptions.  Which of the following is
  \emph{not} one of those premises?
  \begin{answers}
    \longanswer{Air resistance is negligible.}
    \longanswer{The gun fires the ball horizontally.}
    \longanswer{The ball is not spinning when it is launched by the gun.}
    \longanswer{The gravitational force affects only the vertical component of velocity.}
  \end{answers}
\end{problem}

\end{document}