In this section we formally define the REDFIN microarchitecture and express the
semantics of the instruction set as an explicit and symbolic state transformer.

\begin{figure}[t]
\begin{minted}[xleftmargin=10pt]{haskell}
data State = State
  { registers           :: RegisterBank
  , memory              :: Memory
  , instructionCounter  :: InstructionAddress
  , instructionRegister :: InstructionCode
  , program             :: Program
  , flags               :: Flags
  , clock               :: Clock }
\end{minted}
\vspace{0mm}
\begin{minted}[xleftmargin=10pt]{haskell}
type Register           = SymbolicValue Word2
type Value              = SymbolicValue Int64
type RegisterBank       = SymbolicArray Word2 Int64
type MemoryAddress      = SymbolicValue Word8
type Memory             = SymbolicArray Word8 Int64
\end{minted}
\vspace{0mm}
\begin{minted}[xleftmargin=10pt]{haskell}
type InstructionAddress = SymbolicValue Word8
type InstructionCode    = SymbolicValue Word16
type Program            = SymbolicArray Word8 Word16
\end{minted}
\vspace{0mm}
\begin{minted}[xleftmargin=10pt]{haskell}
data Flag               = Condition@\,@|@\,@Overflow@\,@|@\,@Halt@\,@...
type Flags              = SymbolicArray Flag Bool
type Clock              = SymbolicValue Word64
\end{minted}
\vspace{-3.5mm}
\caption{Basic types for modelling REDFIN.\label{fig-types}}
\vspace{-5mm}
\end{figure}

\vspace{-1mm}
\subsection{The REDFIN microarchitecture state}
\vspace{-0.5mm}

The main idea of our approach is to use an explicit state transformer
semantics of the REDFIN microarchitecture. The \hs{State} of the entire
processing core is a product of states of every component, see
Fig.~\ref{fig-types}.
% The names and types of the components are self-explanatory.
We define \hs{SymbolicValue} and \hs{SymbolicArray} on top of the SBV
library~\cite{SBV} that we use as the SMT translation and verification frontend.

% \begin{equation*}
% \begin{split}
% S=\{(r, m, ic, ir, p, f, c) : r \in R, m \in M, ic \in A, \\ir \in I,
% p \in P, f \in F, c \in C\},
% \end{split}
% \end{equation*}

% \noindent
% where $R$ is the set of register bank configurations;
% $M$ is the memory state space;
% $A$~is the set of instruction addresses (the instruction counter $ic$ stores the
% address of the current instruction);
% $I$ is the set of instruction codes (the instruction register $ir$ stores the
% code of the current instruction);
% $P$ is the set of programs;
% $F$ is the set of the flag register configurations; and
% $C$ is the set of clock values.

% Fig.~\ref{fig-types} shows the translation of the above into Haskell types. Note
% that the types are not parameterised: recall that REDFIN is parameterised, e.g.
% the data width can be chosen depending on mission requirements, whereas we use fixed
% 64-bit data path for the sake of simplicity. The chosen names are self-explanatory,
% for example, the data type \hs{State} directly corresponds to the set of states~$S$.

% \todo{In principle, any other SMT frontend
% can be used, but to the best of our knowledge, SBV is the most mature SMT library
% available for Haskell. \textbf{No, SBV here is crucial because it does all the actual symbolic execution}} We briefly overview all \hs{State} components below.

% \subsubsection{Data values, registers and memory}

There are~4 registers (addressed by \hs{Word2}) and 256 memory cells (addressed
by \hs{Word8}) that store 64-bit values (\hs{Int64}). The register bank and
memory are represented by symbolic arrays
that can be accessed via SBV's functions \hs{readArray} and \hs{writeArray}.
% \subsubsection{Instructions and programs}
REDFIN uses 16-bit \hs{InstructionCode}s, whose 6 leading bits contain the
opcode, and the remaining 10 bits hold instruction arguments. The \hs{Program}
maps 8-bit instruction addresses to instruction codes.

% \subsubsection{Status flags and clock}
The microarchitecture status \hs{Flags} support conditional branching, track
integer overflow, and terminate the program (we omit a few other flags for
brevity).
% The flag register is a symbolic map from flags to Boolean values.
The \hs{Clock} is a 64-bit counter
incremented on each clock cycle. Status flags and the clock are used for
diagnostic, formal verification and worst-case execution time analysis.

\subsection{Instruction and program semantics}

We can now define the formal semantics of REDFIN instructions and programs as a
\emph{state transformer} $T : S \rightarrow S$, i.e. a function that maps
states to states. We distinguish instructions and programs by using
Haskell's list notation, e.g. $T_{\subhs{nop}}$ is the semantics of the
instruction $\hs{nop} \in I$, whereas $T_{\subhs{[}\subhs{nop}\subhs{]}}$ is the
semantics of the single-instruction program $\hs{[}\hs{nop}\hs{]} \in P$.

% \footnote{REDFIN does not have a dedicated \hs{nop}
% instruction, but one can use the semantically equivalent instruction \hs{jmpi 0}
% instead (i.e. jump to the next instruction).}

\vspace{-3mm}
\noindent\hrulefill~\\
\vspace{-4.5mm}

\noindent
\textbf{Definition (program semantics):} The semantics of a program $p \in P$
is inductively defined as follows:

% \begin{itemize}
% \item
    The semantics of the \emph{empty program} $\hs{[}\hs{]} \in P$ coincides with
    the semantics of the instruction \hs{nop} and is the identity state transformer:
    $T_{\subhs{[}\subhs{]}} = T_{\subhs{nop}} = \hs{id}$.

    % \item
    The semantics of a \emph{single-instruction program} $\hs{[}\hs{i}\hs{]} \in P$
    is a composition of (i) fetching the instruction from
    the program memory~$T_\textit{fetch}$, (ii) incrementing the
    instruction counter~$T_\textit{inc}$, and (iii) the state transformer
    of the instruction itself~$T_{\subhs{i}}$, or, using the order of state
    components from Fig.~\ref{fig-types}:
    \vspace{-1mm}
    \[
    \begin{array}{lcl}
    T_\textit{fetch} & = & (r, m, ic, ir, p, f, c) \mapsto (r, m, ic, p[ic], p, f, c + 1)\\
    T_\textit{inc} & = & (r, m, ic, ir, p, f, c) \mapsto (r, m, ic + 1, ir, p, f, c)\\
    T_{\subhs{[}\subhs{i}\subhs{]}} & = & T_{\subhs{i}} \circ T_\textit{inc} \circ T_\textit{fetch}\\
    \end{array}
    \]

    % \item
    % \vspace{-1mm}
    The semantics of a \emph{composite program} $\hs{i}\hs{:}\hs{p} \in P$,
    where the operator~\hs{:}~prepends an instruction $\hs{i} \in I$ to a program
    $\hs{p} \in P$, is defined as $T_{\subhs{i}\subhs{:}\subhs{p}} = T_{\hs{p}} \circ T_{\subhs{[}\subhs{i}\subhs{]}}$.

% \end{itemize}

\vspace{-2mm}
\noindent\hrulefill~\\
\vspace{-3.5mm}

% \noindent
We represent state transformers in Haskell using the \emph{state monad}, a
classic approach to emulating mutable state in a purely functional programming
language~\cite{wadler1990comprehending}. We call our state monad~\hs{Redfin} and
define it as follows:
% \footnote{A generic version of this monad is available in standard module
% \hs{Control.Monad.State}.}

\begin{minted}[xleftmargin=10pt]{haskell}
data Redfin a = Redfin
  { transform :: State -> (a, State) }
\end{minted}

\noindent
Every computation with the return type~\hs{Redfin}~\hs{a} yields a value of type~\hs{a}
and possibly alters the \hs{State} of the REDFIN microarchitecture. As an example,
below we express the state transformer $T_\textit{inc}$ using the \hs{Redfin} monad.

\begin{minted}[xleftmargin=10pt,fontsize=\small]{haskell}
incrementInstructionCounter :: Redfin ()
incrementInstructionCounter =
    Redfin $ \current -> ((), next)
  where next = current { instructionCounter =
          instructionCounter current + 1 }
\end{minted}

\noindent
In words, the state transformer looks up the value of the \hs{instructionCounter}
in the \hs{current} state and replaces it in the \hs{next} state with the
incremented~value. Such computations directly correspond to REDFIN programs and
can be described using Haskell's powerful \hs{do}-notation:

% The type \hs{Redfin}~\hs{()} indicates that the computation does not
% produce any value as part of the state transformation.

% and can be composed using the operator \hs{>>}.
% For example, \hs{fetchInstruction}\\\hs{>>}~\hs{incrementInstructionCounter} is
% the state transformer $T_\textit{inc} \circ T_\textit{fetch}$ assuming that
% \hs{fetchInstruction} corresponds to $T_\textit{fetch}$. We can also use

\begin{minted}[xleftmargin=10pt,fontsize=\small]{haskell}
readInstructionRegister@\,@::@\,@Redfin@\,@InstructionCode
readInstructionRegister =
  Redfin $ \s -> (instructionRegister s, s)
\end{minted}
\vspace{0.5mm}
\begin{minted}[xleftmargin=10pt,fontsize=\small]{haskell}
executeInstruction :: Redfin ()
executeInstruction = do
  fetchInstruction
  incrementInstructionCounter
  instructionCode <- readInstructionRegister
  decodeAndExecute instructionCode
\end{minted}

\noindent
Here \hs{readInstructionRegister} reads the instruction code from the current
state \emph{without modifying it}. This function is used in \hs{executeInstruction},
which defines the semantics of the REDFIN execution cycle. We omit definitions of
\hs{fetchInstruction} and \hs{decodeAndExecute} for brevity. The latter is a
case analysis of 47 opcodes that returns the matching instruction. We discuss
several instructions below.

% \subsubsection{Halting the processor}
The instruction~\hs{halt} sets the flag~\hs{Halt}, thereby stopping the
execution of the current subroutine until a new one is started by a higher-level
system controller that resets \hs{Halt}.

\begin{minted}[xleftmargin=10pt,fontsize=\small]{haskell}
halt :: Redfin ()
halt = writeFlag Halt true
\end{minted}

\noindent
The auxiliary functions \hs{writeFlag}, \hs{readRegister} etc. are simple
state transformers manipulating parts of the \hs{State}.

% \begin{minted}{haskell}
% writeFlag :: Flag -> SymbolicValue Bool -> Redfin ()
% writeFlag flag value = Redfin $ \s -> ((), s')
%   where s' = s { flags = writeArray (flags s)
%                          (flagId flag) value }
% \end{minted}

% \subsubsection{Arithmetics}
The instruction \hs{abs} is more involved:
it reads a register and writes back the absolute value of its contents.
The semantics accounts for the potential integer overflow that leads to the
\emph{negative resulting value} when the input is $-2^{63}$ (REDFIN uses the
common two's complement signed number representation). The overflow is flagged
by setting~\hs{Overflow}.
% \footnote{We use \hs{Prelude.abs} to distinguish between the instruction
% and the function from the standard library \hs{Prelude}; \hs{fmap} applies
% \hs{Prelude.abs} to the result of \hs{readRegister}.}

\vspace{-0.5mm}
\begin{minted}[xleftmargin=10pt,fontsize=\small]{haskell}
abs :: Register -> Redfin ()
abs rX = do
    state  <- readState
    result <- fmap Prelude.abs (readRegister rX)
    let (_, state') =
      transform (writeFlag Overflow true) state
    writeState $ ite (result .< 0) state' state
    writeRegister rX result
\end{minted}

\noindent
SBV's symbolic \emph{if-then-else} operation~\hs{ite} \emph{merges} two possible
next states, one of which has the \hs{Overflow} flag set.

% The
% auxiliary functions \hs{readRegister}, \hs{writeRegister}, \hs{readState} and
% \hs{writeState} are simple state transformers like
% \hs{readInstructionRegister} and \hs{writeFlag}.

% \subsubsection{Conditional branching}
As an example of a control flow REDFIN instruction consider \hs{jmpi_ct}, which
tests the~\hs{Condition} flag, and adds the provided offset to the instruction
counter if the flag is set.

\vspace{-0.5mm}
\begin{minted}[xleftmargin=10pt,fontsize=\small]{haskell}
jmpi_ct :: SymbolicValue Int8 -> Redfin ()
jmpi_ct offset = do
  ic <- readInstructionCounter
  condition <- readFlag Condition
  let ic' = ite condition (ic + offset) ic
  writeInstructionCounter ic'
\end{minted}

\noindent
% After working through the above examples, it is worth noting that
We use our Haskell encoding of the state transformer as a~\emph{metalanguage}:
we operate the REDFIN core as a puppet master, using external meta-notions of
addition, comparison and let"/binding. From the processor's
point of view, we have infinite memory and act instantly, which gives us unlimited
modelling power. For example, we can simulate the processor environment
in an external tool and feed its result to \hs{writeRegister} as if it was
obtained in one clock cycle.

\vspace{-1mm}
\subsection{Symbolic simulation}
\vspace{-1mm}

Having defined the semantics of REDFIN programs, we can perform \emph{symbolic
processor simulation}. The function \hs{simulate} takes a number of simulation
steps~$N$ and an initial symbolic \hs{State} as input, and executes
\hs{executeInstruction} defined above $N$ times. In each \hs{state} we
merge two possible futures: (i) if the \hs{Halt} flag is set, we continue the
simulation from the \hs{next} state, (ii) otherwise we remain in the current
\hs{state}, since in this case the processor must remain idle.

\begin{minted}[xleftmargin=10pt,fontsize=\small]{haskell}
simulate :: Int -> State -> State
simulate steps s | steps <= 0 = s
                 | otherwise  =
  ite halted s (simulate (steps - 1) next)
 where halted = readArray (flags s) (flagId Halt)
       next   = snd (transform executeInstruction s)
\end{minted}

\noindent
%TODO: What about program synthesis?
Symbolic simulation is very powerful. It allows us to formally verify properties
of REDFIN programs by fixing some parts of the state to constant values (e.g.,
the program), and then making assertions on the resulting values of
the symbolic part of the state, as demonstrated in the next
section~\S\ref{sec-verification}.


\documentclass[12pt]{article}

\include{preamble}
\usepackage{textcomp}
\usepackage{tfrupee}
\pdfmapfile{=tfrupee.map}

\title{Math 241 Fall 2016 \\ Midterm Examination Two}
\author{Professor Adam Kapelner}

\date{November 15, 2016}

\begin{document}
\maketitle

\noindent Full Name \line(1,0){270} ~~~ Section (A or B)~ \line(1,0){30}

\thispagestyle{empty}

\section*{Code of Academic Integrity}

\footnotesize
Since the college is an academic community, its fundamental purpose is the pursuit of knowledge. Essential to the success of this educational mission is a commitment to the principles of academic integrity. Every member of the college community is responsible for upholding the highest standards of honesty at all times. Students, as members of the community, are also responsible for adhering to the principles and spirit of the following Code of Academic Integrity.

Activities that have the effect or intention of interfering with education, pursuit of knowledge, or fair evaluation of a student's performance are prohibited. Examples of such activities include but are not limited to the following definitions:

\paragraph{Cheating} Using or attempting to use unauthorized assistance, material, or study aids in examinations or other academic work or preventing, or attempting to prevent, another from using authorized assistance, material, or study aids. Example: using a cheat sheet in a quiz or exam, altering a graded exam and resubmitting it for a better grade, etc.
\\

\noindent I acknowledge and agree to uphold this Code of Academic Integrity. \\

\begin{center}
\line(1,0){250} ~~~ \line(1,0){100}\\
~~~~~~~~~~~~~~~~~~~~~signature~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ date
\end{center}

\normalsize

\section*{Instructions}

This exam is seventy five minutes and closed-book. You are allowed one page (front and back) of a \qu{cheat sheet.} You may use a graphing calculator of your choice. Please read the questions carefully. If the question reads \qu{compute,} this means the solution will be a number otherwise you can leave the answer in choose, permutation, exponent, factorial or any other notation which could be resolved to a number with a computer. I advise you to skip problems marked \qu{[Extra Credit]} until you have finished the other questions on the exam, then loop back and plug in all the holes. I also advise you to use pencil. The exam is 100 points total plus extra credit. Partial credit will be granted for incomplete answers on most of the questions. \fbox{Box} in your final answers. Good luck!

\pagebreak

\problem Many students take probability and statistics to go on to a career as an actuary. In America, this requires passing many exams. The third exam is called the \qu{models for financial economics} or \qu{MFE} which consists of 30 multiple choice questions with 5 choices each. Each question is separate from other questions (i.e. self-contained).

\begin{figure}[htp]
\centering
\includegraphics[width=3in]{scantron.png}
\end{figure}

In July 2016, the passing rate was $\approx$72\% of questions correct. For the purposes of this problem, assume this means 22 of the questions (or more) would have to be correct in order to pass. \\

We first consider the situation where the test-taker guesses the answer to each question by choosing one of the five equally likely choices.

\benum
\subquestionwithpoints{3} Model the result of \emph{one} question below as a r.v. $X$ which has the value 1 if the answer is correct and 0 if the answer is not correct.  \spc{1}

\subquestionwithpoints{2} When guessing the answers to all 30 questions, are the r.v.'s that represent each question's correctness identically distributed? Yes / no. No explanation necessary.  \spc{0.2}

\subquestionwithpoints{2} When guessing the answers to all 30 questions, are the r.v.'s that represent each question's correctness independent? Yes / no. No explanation necessary.  \spc{0.2}

\subquestionwithpoints{3} Create a r.v. model that represents the total score for all 30 questions.  \spc{1}

\subquestionwithpoints{6} Compute the probability that the guesser gets \textit{exactly} 22 questions correct. Round to three significant digits.  \spc{4}

\subquestionwithpoints{3} If the guesser did the exam over and over again, what would his test average approximately be? \spc{1}

\subquestionwithpoints{6} Write an computable expression for the probability that the guesser passes the exam. Do not compute it explicitly.  \spc{3}

\subquestionwithpoints{5} Regardless of your answer in (g), do you think the guesser has a \textit{realistic} chance of passing? Yes / no and explain your answer. \spc{3}

\subquestionwithpoints{4} In the situtation where the test-taker knows something about some of the topics tested and uses that knowledge to answer some questions but guess on others which he has no knowledge of the topics, would the model built in (d) still be a good model for the test-taker's score on the exam? Yes / no and explain your answer. \spc{5}

\eenum

\problem Powerball is an American lottery game offered by 44 states, the District of Columbia, Puerto Rico and the US Virgin Islands. Since October 7, 2015, the game has used 5 white balls picked from 69 possible balls with replacement and onw \qu{powerball} with 26 possible balls resulting in a matrix from which winning numbers are chosen, resulting in odds of 1 in 292,201,338 of winning a jackpot per play (i.e. about three in a billion). Calculated as a probability, we denote the chance of winning as $p := 3.42 \times 10^{-9}$. \\

\begin{figure}[htp]
\centering
\includegraphics[width=3in]{powerball.png}
\end{figure}

Assume for simplicity that there is a powerball lottery every day, 365 days per year. Also assume when you buy a powerball lottery ticket, you pick a sequence of valid powerball numbers randomly (i.e. equally likely) for each ball.

\benum
\subquestionwithpoints{3} Create a r.v. $X$ for the outcome of one powerball lottery ticket which realizes 1 if you win and 0 if you lose. \spc{1}

\subquestionwithpoints{3} Consider the following strategy: buy a powerball ticket every day until you win. Create a r.v. model $X$ that models the number of days it takes to win. \spc{1}

\subquestionwithpoints{5} How many years would it take to win on average? Round to the nearest year. \spc{4}

\subquestionwithpoints{5} Imagine starting to play when you're 20 years old and stopping when you're 90 years old for a total of 70 years of daily playing. What is the probability of winning (at least once)? Round to two significant digits. \spc{5}

\subquestionwithpoints{5} Assuming you can play everyday \emph{forever}, what is the probability you eventually win? \spc{0.2}

\subquestionwithpoints{3} If you've been playing for 30 years without winning, do you have a higher chance of winning compared to someone who has just started playing? Yes / no. No explanation needed. \spc{0.2}

\subquestionwithpoints{5} Up until this point, we have just been discussing probabilities and modeling the event of winning or losing. Now we will put dollar amounts on these events. The powerball ticket costs \$2 and the average jackpot is \$140 million. Create a r.v. $X$ for the payout of \textit{one} powerball ticket. \spc{4}

\subquestionwithpoints{5} Calculate the expected value of $X$, (the r.v. model for the payout of \emph{one} powerball ticket in dollars). Round to an appropriate number of digits. \spc{5}

\subquestionwithpoints{5} Interpret the expected value you calculated in (i) in the scenario where you don't play for 70 years daily but you \textit{only play once}. \spc{4}

\subquestionwithpoints{6} Calculate the standard error of \emph{one} powerball lottery ticket.  Include units and round to an appropriate number of digits. \spc{8}

\subquestionwithpoints{4} Let's say you are buying the ticket in India where the currency is rupees (\rupee). The exchange rate is \$1 = \rupee66.80 and you have to pay a flat \rupee30 fee to purchase an American ticket from overseas. Create a r.v. $R$ for the lottery ticket bought in India with rupees as a function of the r.v. $X$ created in (h).\spc{2}

\eenum

\problem These are some theoretical questions below.

\benum
\subquestionwithpoints{3} If the r.v. $X \sim $ Deg($c$), prove $\expe{X} = c$ from the definition of expectation for discrete r.v.'s. \spc{5}

%\subquestionwithpoints{3} If $\Xoneton \iid$ with finite $\mu$ and $\sigma$, derive an expression for $\se{\Xbar}$ step-by-step. \spc{3}

\subquestionwithpoints{4} Compute the following expression for $w = 0.24586$:

\beqn
\sum_{\ell=y}^\infty \binom{\ell - 1}{y - 1} w^y (1-w)^{\ell - y}  = \quad\quad\quad\quad
\eeqn\spc{1}

\subquestionwithpoints{4} Assume $\expe{X_i} > 0$ and that $\Xoneton $ are \textit{identically distributed} but not necessarily independent. Resolve: \\

$\displaystyle\limitn \expe{T_n}  = $\spc{0.3}

\subquestionwithpoints{6} In your pocket you have 10 pennies, 2 nickels, 2 dimes and 3 quarters. You reach into your pocket and grab four coins in your hand. What's the probability you have 4\textcent~in your hand? \spc{15}

\subquestionwithpoints{4} [Extra Credit] Resolve the follwing expression for arbitrary r.v. $X$:

\beqn
\bigcup_{x \in \supp{X}} \braces{\omega : X(\omega) = x}  = \quad\quad\quad\quad
\eeqn

\subquestionwithpoints{4} [Extra Credit] Create a r.v. $X$ that has $\abss{\supp{X}} = 2$ but whose $\abss{\Omega} =  \aleph_0$.

\eenum

\end{document}


\chapter{Eclipse OCL}

\section{Invariant - Examples}

\begin{ocl}
context Meeting inv: self.end > self.start

-- "self" always refers to the object identifier from which the constraint is evaluated.
context Meeting inv: end > : end > start

-- Names can be given to the constraint
context Meeting inv startEndConstraint:
self.end > self.start
\end{ocl}

\section{Precondition - Examples}
\begin{ocl}
context Meeting::shift(d:Integer)
pre: self.isConfirmed = false

context Meeting::shift(d:Integer)
pre: d>0 pre: d>0

context Meeting::shift(d:Integer)
pre: self.isConfirmed = false and d>0
\end{ocl}

\section{Postcondition - Examples}
\begin{ocl}

context Meeting::duration():Integer
post: result = self.end – self.start
-- keyword result refers to the result of the operation

context Meeting::confirm()
post: self.isConfirmed = true
\end{ocl}

\section{Examples for Collection Operations}
\begin{ocl}
context Teammeeting
inv: participants->forAll(team=self.for)

context Meeting inv: oclIsTypeOf(Teammeeting)
implies participants->forAll(team=self.for)

context Teammember::numMeeting():Integer
post: result=meetings->size()
context Teammember::numConfMeeting():Integer context Teammember::numConfMeeting():Integer
post: result=meetings->select(isConfirmed)->size()
\end{ocl}


\documentstyle[11pt,reduce]{article}
\title{The Package SPDE for Determining Symmetries of Partial
Differential Equations}
\date{}
\author{Fritz Schwarz \\ GMD, Institut F1 \\
Postfach 1240 \\ 5205 St. Augustin \\
GERMANY \\[0.05in]
Telephone: +49-2241-142782 \\
Email: fritz.schwarz@gmd.de}
\begin{document}
\maketitle

The package SPDE provides a set of functions which may be applied
to determine the symmetry group of Lie- or point-symmetries of a
given system of partial differential equations.  Preferably it is
used interactively on a computer terminal. In many cases the
determining system is solved completely automatically. In some
other cases the user has to provide some additional input
information for the solution algorithm to terminate. The package
should only be used in compiled form.

For all theoretical questions, a description of the algorithm and
numerous examples the following articles should be consulted:
``Automatically Determining Symmetries of Partial Differential
Equations'', Computing vol. 34, page 91-106(1985) and vol. 36, page
279-280(1986), ``Symmetries of Differential Equations: From Sophus
Lie to Computer Algebra'', SIAM Review, to appear, and Chapter 2
of the Lecture Notes ``Computer Algebra and Differential Equations
of Mathematical Physics'', to appear.

\section{Description of the System Functions and Variables}

The symmetry analysis of partial differential equations logically
falls into three parts. Accordingly the most important functions
provided by the package are:

\begin{table}
\begin{center}
\begin{tabular}{| c | c | }\hline
Function name & Operation \\ \hline \hline
\ttindex{CRESYS}
CRESYS(\s{arguments}) & Constructs determining system \\ \hline
\ttindex{SIMPSYS}
SIMPSYS() & Solves determining system \\ \hline
\ttindex{RESULT}
RESULT() & Prints infinitesimal generators \\
&  and commutator table \\ \hline
\end{tabular}
\end{center}
\caption{SPDE Functions}
\end{table}

Some other useful functions for obtaining various kinds of output
are:

\begin{table}
\begin{center}
\begin{tabular}{| c | c |} \hline
Function name & Operation \\ \hline \hline
\ttindex{PRSYS}
PRSYS() & Prints determining system \\ \hline
\ttindex{PRGEN}
PRGEN() & Prints infinitesimal generators \\ \hline
\ttindex{COMM}
COMM(U,V) & Prints commutator of generators U and V \\ \hline
\end{tabular}
\end{center}
\caption{SPDE Useful Output Functions}\label{spde:useful}
\end{table}

There are several global variables defined by the system which should
not be used for any other purpose than that given in
Table~\ref{spde:intt} and~\ref{spde:op}. The three globals of the type
integer are:

\begin{table}
\begin{center}
\begin{tabular}{| c | c |}\hline
Variable name & Meaning \\ \hline \hline
\ttindex{NN}
NN & Number of independent variables \\ \hline
\ttindex{MM}
MM & Number of dependent variables \\ \hline
\ttindex{PCLASS}
PCLASS=0, 1 or 2 & Controls amount of output \\ \hline
\end{tabular}
\end{center}
\caption{SPDE Integer valued globals}\label{spde:intt}
\end{table}

In addition there are the following global variables of type
operator:

\begin{table}
\begin{center}
\begin{tabular}{| c | c |}\hline
Variable name & Meaning \\ \hline \hline
\ttindex{X(I)}
X(I) & Independent variable $x_i$ \\ \hline
\ttindex{U(ALFA)}
U(ALFA) & Dependent variable $u^{alfa}$ \\ \hline
\ttindex{U(ALFA,I)}
U(ALFA,I) & Derivative of $u^{alfa}$ w.r.t. $x_i$ \\ \hline
\ttindex{DEQ(I)}
DEQ(I) & i-th differential equation \\ \hline
\ttindex{SDER(I)}
SDER(I) & Derivative w.r.t. which DEQ(I) is resolved \\ \hline
\ttindex{GL(I)}
GL(I) & i-th equation of determining system \\ \hline
\ttindex{GEN(I)}
GEN(I) & i-th infinitesimal generator \\ \hline
\ttindex{XI(I)} \ttindex{ETA(ALFA)} \ttindex{ZETA(ALFA,I)}
XI(I), ETA(ALFA)  & See definition given in the \\
ZETA(ALFA,I) & references quoted in the introduction. \\ \hline
\ttindex{C(I)}
C(I) & i-th function used for substitution \\ \hline
\end{tabular}
\end{center}
\caption{SPDE Operator type global variables}\label{spde:op}
\end{table}

The differential equations of the system at issue have to be assigned
as values to the operator deq i applying the notation which is defined
in Table~\ref{spde:op}. The entries in the third and the last line of
that Table have obvious extensions to higher derivatives.

The derivative w.r.t. which the i-th differential equation deq i is
resolved has to be assigned to sder i. Exception: If there is a single
differential equation and no assignment has been made by the user, the
highest derivative is taken by default.

When the appropriate assignments are made to the variable deq, the
values of NN and MM (Table~\ref{spde:useful}) are determined
automatically, i.e. they have not to be assigned by the user.

\ttindex{CRESYS}
The function CRESYS may be called with any number of arguments, i.e.

\begin{verbatim}
  CRESYS(); or CRESYS(deq 1,deq 2,... );
\end{verbatim}

 are legal calls. If it is called without any argument, all current
assignments to deq are taken into account. Example: If deq 1, deq 2
and deq 3 have been assigned a differential equation and the symmetry
group of the full system comprising all three equations is desired,
equivalent calls are

\begin{verbatim}
  CRESYS();   or   CRESYS(deq 1,deq 2,deq 3);
\end{verbatim}

The first alternative saves some typing. If later in the session the
symmetry group of deq 1 alone has to be determined, the correct call
is

\begin{verbatim}
  CRESYS deq 1;
\end{verbatim}

\ttindex{SIMPSYS}
After the determining system has bee created, SIMPSYS which has no
arguments may be called for solving it. The amount of intermediate
output produced by SIMPSYS is controlled by the global variable PCLASS
with the default value 0. \ttindex{PCLASS} With PCLASS equal to 0, no
intermediate steps are shown. With PCLASS equal to 1, all intermediate
steps are displayed so that the solution algorithm may be followed
\index{tracing ! SPDE package} through in detail. Each time the algorithm
passes through the top of the main solution loop the message

\begin{verbatim}
  Entering main loop
\end{verbatim}

is written. PCLASS equal 2 produces a lot of LISP output and is of no
interest for the normal user.

If with PCLASS=0 the procedure SIMPSYS terminates without any
response, the determining system is completely solved.  In some cases
SIMPSYS does not solve the determining system completely in a single
run. In general this is true if there are only genuine differential
equations left which the algorithm cannot handle at present. If a case
like this occurs, SIMPSYS returns the remaining equations of the
determining system. To proceed with the solution algorithm,
appropriate assignments have to be transmitted by the user, e.g. the
explicit solution for one of the returned differential equations. Any
new functions which are introduced thereby must be operators of the
form c(k) with the correct dependencies generated by a depend
statement (see the ``REDUCE User's Guide''). Its enumeration has to be
chosen in agreement with the current number of functions which have
alreday been introduced.  This value is returned by SIMPSYS too.

After the determining system has been solved, the procedure RESULT,
which has no arguments, may be called. It displays the infinitesimal
generators and its non-vanishing commutators.

\section{How to Use the Package}

In this Section it is explained by way of several examples how the
package SPDE is used interactively to determine the symmetry group of
partial differential equations. Consider first the diffusion equation
which in the notation given above may be written as

\begin{verbatim}
  deq 1:=u(1,1)+u(1,2,2);
\end{verbatim}

It has been assigned as the value of deq 1 by this statement.  There
is no need to assign a value to sder 1 here because the system
comprises only a single equation.

The determining system is constructed by calling

\begin{verbatim}
  CRESYS(); or CRESYS deq 1;
\end{verbatim}

The latter call is compulsory if there are other assignments to the
operator deq i than for i=1.

The error message

\begin{verbatim}
  ***** Differential equations not defined
\end{verbatim}

appears if there are no differential equations assigned to any deq.

If the user wants the determining system displayed for inspection
before starting the solution algorithm he may call

\ttindex{PRSYS}
\begin{verbatim}
  PRSYS();
\end{verbatim}

and gets the answer

\begin{verbatim}
  GL(1):=2*DF(ETA(1),U(1),X(2)) - DF(XI(2),X(2),2) -
         DF(XI(2),X(1))

  GL(2):=DF(ETA(1),U(1),2) - 2*DF(XI(2),U(1),X(2))

  GL(3):=DF(ETA(1),X(2),2) + DF(ETA(1),X(1))

  GL(4):=DF(XI(2),U(1),2)

  GL(5):=DF(XI(2),U(1)) - DF(XI(1),U(1),X(2))

  GL(6):=2*DF(XI(2),X(2)) - DF(XI(1),X(2),2) - DF(XI(1),X(1))

  GL(7):=DF(XI(1),U(1),2)

  GL(8):=DF(XI(1),U(1))

  GL(9):=DF(XI(1),X(2))

The remaining dependencies

  XI(2) depends on U(1),X(2),X(1)

  XI(1) depends on U(1),X(2),X(1)

  ETA(1) depends on U(1),X(2),X(1)
\end{verbatim}

The last message means that all three functions XI(1), XI(2) and
ETA(1) depend on X(1), X(2) and U(1). Without this information the
nine equations GL(1) to GL(9) forming the determining system are
meaningless. Now the solution algorithm may be activated by calling

\ttindex{SIMPSYS}
\begin{verbatim}
   SIMPSYS();
\end{verbatim}

\ttindex{PCLASS}
If the print flag PCLASS has its default value which is 0 no
intermediate output is produced and the answer is

\begin{verbatim}
  Determining system is not completely solved

  The remaining equations are

  GL(1):=DF(C(1),X(2),2) + DF(C(1),X(1))

  Number of functions is 16

  The remaining dependencies

  C(1) depends on X(2),X(1)
\end{verbatim}

With PCLASS equal to 1 about 6 pages of intermediate output are
obtained. It allows the user to follow through each step of the
solution algorithm.

In this example the algorithm did not solve the determining system
completely as it is shown by the last message. This was to be expected
because the diffusion equation is linear and therefore the symmetry
group contains a generator depending on a function which solves the
original differential equation. In cases like this the user has to
provide some additional information to the system so that the solution
algorithm may continue. In the example under consideration the
appropriate input is

\begin{verbatim}
   DF(C(1),X(1)) := - DF(C(1),X(2),2);
\end{verbatim}

If now the solution algorithm is activated again by

\begin{verbatim}
  SIMPSYS();
\end{verbatim}

the solution algorithm terminates without any further message, i.e.
there are no equations of the determining system left unsolved. To
obtain the symmetry generators one has to say finally

\begin{verbatim}
  RESULT();
\end{verbatim}

and obtains the answer

\begin{verbatim}
  The differential equation

  DEQ(1):=U(1,2,2) + U(1,1)

  The symmetry generators are

  GEN(1):= DX(1)

  GEN(2):= DX(2)

  GEN(3):= 2*DX(2)*X(1) + DU(1)*U(1)*X(2)

  GEN(4):= DU(1)*U(1)

  GEN(5):= 2*DX(1)*X(1) + DX(2)*X(2)

                       2
  GEN(6):= 4*DX(1)*X(1)

         + 4*DX(2)*X(2)*X(1)

                           2
           + DU(1)*U(1)*(X(2)  - 2*X(1))

  GEN(7):= DU(1)*C(1)

  The remaining dependencies

  C(1) depends on X(2),X(1)

  Constraints

  DF(C(1),X(1)):= - DF(C(1),X(2),2)

  The non-vanishing commutators of the finite subgroup

  COMM(1,3):= 2*DX(2)

  COMM(1,5):= 2*DX(1)

  COMM(1,6):= 8*DX(1)*X(1) + 4*DX(2)*X(2) - 2*DU(1)*U(1)

  COMM(2,3):= DU(1)*U(1)

  COMM(2,5):= DX(2)

  COMM(2,6):= 4*DX(2)*X(1) + 2*DU(1)*U(1)*X(2)

  COMM(3,5):=  - (2*DX(2)*X(1) + DU(1)*U(1)*X(2))

                          2
  COMM(5,6):= 8*DX(1)*X(1)

            + 8*DX(2)*X(2)*X(1)

                                2
            + 2*DU(1)*U(1)*(X(2)  - 2*X(1))
\end{verbatim}

The message ``Constraints'' which appears after the symmetry generators
are displayed means that the function c(1) depends on x(1) and x(2)
and satisfies the diffusion equation.

More examples which may used for test runs are given in the final
section.

\index{ansatz of symmetry generator}
If the user wants to test a certain ansatz of a symmetry generator for
given differential equations, the correct proceeding is as follows.
Create the determining system as described above. Make the appropriate
assignments for the generator and call PRSYS() after that.  The
determining system with this ansatz substituted is returned.  Example:
Assume again that the determining system for the diffusion equation
has been created. To check the correctness for example of generator GEN
3 which has been obtained above, the assignments

\begin{verbatim}
  XI(1):=0;  XI(2):=2*X(1);  ETA(1):=X(2)*U(1);
\end{verbatim}

have to be made. If now PRSYS() is called all GL(K) are zero
proving the correctness of this generator.

Sometimes a user only wants to know some of the functions ZETA for for
various values of its possible arguments and given values of MM and
NN. In these cases the user has to assign the desired values of MM and
NN and may call the ZETAs after that. Example:

\begin{verbatim}
  MM:=1;  NN:=2;

  FACTOR U(1,2),U(1,1),U(1,1,2),U(1,1,1);

  ON LIST;

  ZETA(1,1);

  -U(1,2)*U(1,1)*DF(XI(2),U(1))

  -U(1,2)*DF(XI(2),X(1))

         2
  -U(1,1) *DF(XI(1),U(1))

  +U(1,1)*(DF(ETA(1),U(1)) -DF(XI(1),X(1)))

  +DF(ETA(1),X(1))

  ZETA(1,1,1);

  -2*U(1,1,2)*U(1,1)*DF(XI(2),U(1))

  -2*U(1,1,2)*DF(XI(2),X(1))

  -U(1,1,1)*U(1,2)*DF(XI(2),U(1))

  -3*U(1,1,1)*U(1,1)*DF(XI(1),U(1))

  +U(1,1,1)*(DF(ETA(1),U(1)) -2*DF(XI(1),X(1)))

                2
  -U(1,2)*U(1,1) *DF(XI(2),U(1),2)

  -2*U(1,2)*U(1,1)*DF(XI(2),U(1),X(1))

  -U(1,2)*DF(XI(2),X(1),2)

         3
  -U(1,1) *DF(XI(1),U(1),2)

         2
  +U(1,1) *(DF(ETA(1),U(1),2) -2*DF(XI(1),U(1),X(1)))

  +U(1,1)*(2*DF(ETA(1),U(1),X(1)) -DF(XI(1),X(1),2))

  +DF(ETA(1),X(1),2)
\end{verbatim}

If by error no values to MM or NN and have been assigned the message

\begin{verbatim}
  ***** Number of variables not defined
\end{verbatim}

is returned. Often the functions ZETA are desired for special values
of its arguments ETA(ALFA) and XI(K). To this end they have to be
assigned first to some other variable. After that they may be
evaluated for the special arguments. In the previous example this may
be achieved by

\begin{verbatim}
  Z11:=ZETA(1,1)$   Z111:=ZETA(1,1,1)$
\end{verbatim}

Now assign the following values to XI 1, XI 2 and ETA 1:

\begin{verbatim}
  XI 1:=4*X(1)**2; XI 2:=4*X(2)*X(1);

  ETA 1:=U(1)*(X(2)**2  - 2*X(1));
\end{verbatim}

They correspond to the generator GEN 6 of the diffusion equation which
has been obtained above. Now the desired expressions are obtained by
calling

\begin{verbatim}
  Z11;

                               2
 - (4*U(1,2)*X(2) - U(1,1)*X(2)  + 10*U(1,1)*X(1) + 2*U(1))

  Z111;

                                   2
 - (8*U(1,1,2)*X(2) - U(1,1,1)*X(2)  + 18*U(1,1,1)*X(1) +
   12*U(1,1))
\end{verbatim}

\section{Test File}

This appendix is a test file. The symmetry groups for various
equations or systems of equations are determined. The variable PCLASS
has the default value 0 and may be changed by the user before running
it. The output may be compared with the results which are given in the
references.

\begin{verbatim}
%The Burgers equations

deq 1:=u(1,1)+u 1*u(1,2)+u(1,2,2)$

cresys deq 1$ simpsys()$ result()$

%The Kadomtsev-Petviashvili equation

deq 1:=3*u(1,3,3)+u(1,2,2,2,2)+6*u(1,2,2)*u 1

       +6*u(1,2)**2+4*u(1,1,2)$

cresys deq 1$ simpsys()$ result()$

%The modified Kadomtsev-Petviashvili equation

deq 1:=u(1,1,2)-u(1,2,2,2,2)-3*u(1,3,3)

       +6*u(1,2)**2*u(1,2,2)+6*u(1,3)*u(1,2,2)$

cresys deq 1$ simpsys()$ result()$

%The real- and the imaginary part of the nonlinear
%Schroedinger equation

deq 1:= u(1,1)+u(2,2,2)+2*u 1**2*u 2+2*u 2**3$

deq 2:=-u(2,1)+u(1,2,2)+2*u 1*u 2**2+2*u 1**3$

%Because this is not a single equation the two assignments

sder 1:=u(2,2,2)$  sder 2:=u(1,2,2)$

%are necessary.

cresys()$ simpsys()$ result()$

%The symmetries of the system comprising the four equations

deq 1:=u(1,1)+u 1*u(1,2)+u(1,2,2)$

deq 2:=u(2,1)+u(2,2,2)$

deq 3:=u 1*u 2-2*u(2,2)$

deq 4:=4*u(2,1)+u 2*(u 1**2+2*u(1,2))$

sder 1:=u(1,2,2)$ sder 2:=u(2,2,2)$ sder 3:=u(2,2)$
sder 4:=u(2,1)$

%is obtained by calling

cresys()$ simpsys()$

df(c 5,x 1):=-df(c 5,x 2,2)$

df(c 5,x 2,x 1):=-df(c 5,x 2,3)$

simpsys()$  result()$

% The symmetries of the subsystem comprising equation 1
%  and 3 are obtained by

cresys(deq 1,deq 3)$ simpsys()$ result()$

% The result for all possible subsystems is discussed in
% detail in ``Symmetries and Involution Systems: Some
% Experiments in Computer Algebra'', contribution to the
% Proceedings of the Oberwolfach Meeting on Nonlinear
% Evolution Equations, Summer 1986, to appear.
\end{verbatim}
\end{document}


\section{Methodology}

The main estimation strategy is a coach-fixed effect (FE) regression model with team wins as a dependent variable. As control variables, the model includes performance-based metrics that help capture a player's relative skill level. More specifically, it is assumed that a player's Box Plus Minus (BPM) metric from his last season is an overall measure of his ability level. BPM is a

The coaching impact is captured by the fixed effect ($\lambda_{k}$), which is a dummy variable designating head coach identity. The resulting fixed effects are algebraically equivalent to deviations from means, so they would represent the additional wins relative to the average. The model also includes player metrics as a control for player ability, and the number of games missed as a proxy for player fitness.

The model uses Box Plus Minues (BPM) as an overall measure of player ability. More specifically, a player expected level of ability is given by his BPM from the previous season.

Formally, the model can be represented by the following equation:

For team $i$ in season $t$ under coach $k$,

\begin{equation}
\text{Wins}_{itk} = \sum_{p=1}^{5}(\alpha_{p}\text{BPM}_{p,t-1} + \beta_{p}\text{Inj}_{pit}) + \lambda_{k} + \epsilon_{itk}
\end{equation}

where ${BPM}_{p,t-1}$ represents player $p$'s achieved BPM score in season $t-1$, ${Inj}_{p,i,t}$ indicates his number of games missed (presumably due to injury), and $\lambda_{k}$ is the coach fixed effect. $\epsilon_{i,t,k}$ is the error term.

For simplicity, the model assumes a 5-player roster per team. Since players are sorted by minutes played, where Player 1 ($p = 1$) would be the coach's preferred player by the defining characteristic of seeing the most playing time. Player 2 would be the second and Player 5 would be the least in a 5-person rotation. It is important to note that reducing teams to 5 members does not compromise accuracy. Although rosters may extend up to 12 members, coaches mostly rely on a handful of players. Secondary players see significant variation in roles and personnel over the course of a season, so they are excluded from the main estimation. Section 5 considers larger roster sizes and confirms that the results are robust to the inclusion of additional players.

There is enough reason to believe that neither time or team fixed effects play a significant role because no franchise offers strict advantages over another. Although one might argue that big market teams like the Lakers in Los Angeles and the Knicks in New York may have a slight advantage in attracting talent, expectations are also high for those teams and they often experience periods of downturn.  In addition, the institutional setup of the NBA is such that no team has an edge when it comes to offering higher salaries. Unlike European soccer and other professional sports leagues, the NBA adopts a salary cap where teams have a limit on how much they can spend. Moreover, the structure of the league also compensates "losing" teams by granting them priority in selecting players out of college. All of these factors ensure that the league is somewhat balanced out.

can offer more money than others to attract a player. because of a common salary cap. \footnote{There are exceptions like for retaining a player of their own.} In addition, the lottery system ensures that weaker teams have the chance to rebuild through the draft.

\subsection{Solving for Serial Correlation}

The main challenge arises from the use of performance-based metrics as indicators for player ability, which could pick up some of the coaching effect and lead to potentially understating the impact of coaches over the long run. In order to improve unbiasedness, it imposes a cap on the time span over which the coach effect is examined. In other words, only the first \textit{three} seasons from each coach-team tenure are observed, filtering out the rest. For example, Phil Jackson's 9-season tenure with the Chicago Bulls (1990 to 1998) is reduced to the first \textit{three} (1990 to 1992) by eliminating all subsequent seasons. This strategy helps the playing field by assessing all coaches over a fixed time span. The downside is a reduction in sample size, which drops from X to Y observations.

Trimming-off seasons beyond the third has effectively little impact on the accuracy of the estimates. A 3-season tenure is as almost equally informative as a 6-season tenure when it comes to the coach effect. Section 5 helps illustrate this point by showing that results are robust to different time considerations. For simplicity, the main estimation model assumes a 3-season cap because it allows ample time for coaches to leave a footprint without diving into the danger zone of serial correlation.

Somel papers choose to use payroll as a proxy for ability, as opposed to performance-based metrics. However, salaries fail to pick up a great deal of variations, so this paper avoids this alternative. For instance, players may witness a jump in performance from one season to another, yet salaries are sticky over the course of a multi-year contract. Additionally, the NBA is under a salary cap system where pay is not always proportional to on-court value. Many argue that, because of the "maximum" contract, the relative impact of a player like Lebron James outweighs the amount of salary-based income he receives. Moreover, star players frequently accept pay cuts to team up with other stars. All of these points make payroll a weak substitute for ability.