\chapter{Fusion}
\section {Definitions}
{\bf Definition:}
Let $p$ be a prime, $T \in S_p(G), W \le T$ with $W$ weakly closed in $T$ with respect
to $G$ and $D=C_G (W)$.  Then $N_G(W)$ \emph{controls fusion} in $D$.
\\
\\
{\bf Definition:}
$P \in S_p(G)$.  $X \in p(G)$ is a \emph {tame intersection} of
$Q, R \in S_p (G)$ if $X= Q \cap R$ and $N_Q (X), N_R (X) \in S_p(N(X))$.
\\
\\
{\bf Definition:}
For $R, Q \in S_p(G)$, write $R \rightarrow_x Q$ if $\exists Q_i \in S_p(G), 1 \le i \le n$,
and $x_i \in N_G(P \cap Q_i)$ such that (1) $P \cap Q_i$ is a tame intersection of
$P$ and $Q_i$
for each $1 \le i \le n$,
(2) $P \cap R \le P \cap Q_1$ and $(P \cap R)^{x_1 x_1 \ldots x_i} \le (P \cap Q_i)$
for each $1 \le i \le n$, and
(3) $R^x=Q$ where $x= x_1 x_2 \ldots x_n$.
\section {Alperin's Results}
{\bf Alperin's Fusion Theorem:}
If $P \in S_p(G), g \in G$ and $ \langle A, A^g \rangle \subseteq P$.  Then
for $1 \le i \le n$, $\exists Q_i \in S_p (G)$ and $x_i \in N(P \cap Q_i)$ such
that (1) $g= x_1 x_2 ... x_n$,
(2) $P \cap Q_i$ is a tame intersection of $P$ and $Q_i$ for each $i$,
(3) $A \subseteq P \cap Q_1$ and
$A^{x_1 x_2 ... x_i} \subseteq P \cap Q_{i+1}$.
\\
\\
{\bf Lemma 1:}
$Q \rightarrow P, \forall Q \in S_p(G)$.
\\
\\
{\bf Lemma 2:}
$P \rightarrow P$.
\\
\\
{\bf Lemma 3:}
$\rightarrow$ is transitive.
\begin{quote}
\emph{Proof:}
Let $\{R_i, y_i: 1 \le i \le m \}$ and
$\{Q_i, x_i: 1 \le i \le n \}$ accomplish $S \rightarrow R$ and $R \rightarrow Q$
respectively.  Then $R_1 , R_2 , \ldots , R_m , Q_1, \ldots , Q_n$ and
$y_1 , y_2 , \ldots , y_m , x_1 , \ldots , x_n$ accomplish $A \rightarrow Q$.
\end{quote}
{\bf Lemma 4:}
If $S \rightarrow_x P$, $Q^x \rightarrow P$ and $P \cap Q = P \cap S$
then $Q \rightarrow P$.
\begin{quote}
\emph{Proof:} It suffices to show $Q \rightarrow Q^x$.
Let $\{S_i, x_i: 1 \le i \le n \}$
accomplish $S \rightarrow P$ then
$\{S_i, x_i: 1 \le i \le n \}$ also accomplishes
$Q \rightarrow Q^x$.
\end{quote}
{\bf Lemma 5:}  If
Assume $R, Q \in S_p(G)$ with $R \rightarrow P$ and $P \cap Q < R \cap Q$.  Assume further,
$\forall S \in S_p(G)$ with $|S \cap P| > |Q \cap  P|$ and $S \rightarrow P$.  Then
$Q \rightarrow P$.
\\
\\
{\bf Lemma 6:}
Assume $P \cap Q$ is tame and
$S \rightarrow P, \forall S \in S_p(G)$ with $|S \cap P| > |Q \cap P|$ and $S \rightarrow P$
then $Q \rightarrow P$.
\begin{quote}
\emph{Proof:}
By Lemma 2, we can assume $Q \ne P$ and thus $P \cap Q < P_0 = N_P(P \cap Q)$
By hypothesis $P_0$ and $Q_0= N_Q(P \cap Q)$ are Sylow in $M=N_G(P \cap Q)$ so there is
an $x \in M$ with $Q_0^x=P_0$.  Hence $Q \rightarrow Q_x$ by $Q, x$; further,
$P \cap Q < P_0 \le P \cap Q^x$ so $Q^x \rightarrow P$ and finally by Lemma 3 $Q \rightarrow P$.
\\
\\
\emph{Proof of Lemma 1:}
Pick a counterexample $Q$ with $P \cap Q$ of maximal order.  By Lemma 2, $P \ne Q$ so
$P \cap Q \ne P$ hence $P \cap Q < N_P(P \cap Q)$.  Let $S \in S_p(G)$ with
$N_P(P \cap Q) < N_S(P \cap Q) \le P \cap S$, $S \rightarrow P$ by the maximality of
$P \cap Q$ this there is a $x \in G: S \rightarrow_x P$.  Now $(P \cap Q)^x \le q^x$,
$P \cap Q \le S$ and $S^x=P$ so $(P \cap Q)^x \le P$.  Thus
$(P \cap Q)^x \le P \cap Q^x$.  If $(P \cap Q)^x \ne P \cap Q^x$ then
$|P \cap Q| < |P \cap Q^x|$ so by the maximality of $P \cap Q$, $Q^x \rightarrow P$.  But
then $Q \rightarrow P$ by Lemma 4 contradicting the choice of $Q$.  Now we have
$(P \cap Q)^x = P \cap Q^x$ and let $T \in S_p(G)$ with
$N_{Q^x}(P \cap Q^x) \le
N_{T}(P \cap Q^x) \in S_p(N_G(P \cap Q^x))$.  Again
$P \cap Q^x < N_{Q^x}(P \cap Q^x) \le T$ so $P \cap Q^x < T \cap Q^x$.  Hence if
$T \rightarrow P$, by Lemma 5 $Q^x \rightarrow P$ which was already shown false.  Thus
we do not have $T \rightarrow P$ and by the maximality od $|P \cap Q|$,
$P \cap Q^x = P \cap T$.
By the choice of $T$ and since $P \cap Q^x = P \cap T$, we have
$N_T(P \cap T) \in S_p(N_G(P \cap T)$.
By the choice of $S$,
$N_S(P \cap Q) \in S_p(N_G(P \cap Q)$.  Since
$(P \cap Q)^x = (P \cap Q^x) = P \cap T$ and $S^x=P$, we have
$N_P(P \cap T) \in S_p(N_G(P \cap T)$.  But now, by Lemma 6, $T \rightarrow P$, contrary to the
previous observation.
\\
\\
\emph{Proof of Alperin:}  By Lemma 1, $P^{g^{-1}} \rightarrow P$.  Let
$Q_i, x_i, 1 \le i < n$ accomplish
$P^{g^{-1}} \rightarrow P$. $ \langle A, A^{g{-1}} \rangle \subseteq P \cap P^{g^{-1}}$ so
$A \subseteq P \cap P^{g^{-1}} \le (P \cap Q_1)$ and $A^{x_1 x_2 \ldots x_i}
\le P \cap Q_{i+1}$
for $1 \le i < n$ setting $x=x_1 x_2 \ldots x_{n-1}$.
$P = P^{g^{-1}x}$ so $x_n=x^{-1}g \in N_G(P)$ and
$g= x x_n$.  Finally, let $Q_n=P$ and note that
$A^{x_1 x_2 \ldots x_{n-1}}= A^{g x_n^{-1}} \le P^{x_n^{-1}}=P=P \cap Q_n$ and
the theorem holds.
\end{quote}


% -*- mode: latex; TeX-master: "Vorbis_I_spec"; -*-
%!TEX root = Vorbis_I_spec.tex
\section{Helper equations} \label{vorbis:spec:helper}

\subsection{Overview}

The equations below are used in multiple places by the Vorbis codec
specification.  Rather than cluttering up the main specification
documents, they are defined here and referenced where appropriate.

\subsection{Functions}

\subsubsection{ilog} \label{vorbis:spec:ilog}

The "ilog(x)" function returns the position number (1 through n) of the highest set bit in the two's complement integer value
\varname{[x]}.  Values of \varname{[x]} less than zero are defined to return zero.

\begin{programlisting}
  1) [return\_value] = 0;
  2) if ( [x] is greater than zero ) {

       3) increment [return\_value];
       4) logical shift [x] one bit to the right, padding the MSb with zero
       5) repeat at step 2)

     }

   6) done
\end{programlisting}

Examples:

\begin{itemize}
 \item ilog(0) = 0;
 \item ilog(1) = 1;
 \item ilog(2) = 2;
 \item ilog(3) = 2;
 \item ilog(4) = 3;
 \item ilog(7) = 3;
 \item ilog(negative number) = 0;
\end{itemize}

\subsubsection{float32\_unpack} \label{vorbis:spec:float32:unpack}

"float32\_unpack(x)" is intended to translate the packed binary
representation of a Vorbis codebook float value into the
representation used by the decoder for floating point numbers.  For
purposes of this example, we will unpack a Vorbis float32 into a
host-native floating point number.

\begin{programlisting}
  1) [mantissa] = [x] bitwise AND 0x1fffff (unsigned result)
  2) [sign] = [x] bitwise AND 0x80000000 (unsigned result)
  3) [exponent] = ( [x] bitwise AND 0x7fe00000) shifted right 21 bits (unsigned result)
  4) if ( [sign] is nonzero ) then negate [mantissa]
  5) return [mantissa] * ( 2 ^ ( [exponent] - 788 ) )
\end{programlisting}

\subsubsection{lookup1\_values} \label{vorbis:spec:lookup1:values}

"lookup1\_values(codebook\_entries,codebook\_dimensions)" is used to
compute the correct length of the value index for a codebook VQ lookup
table of lookup type 1.  The values on this list are permuted to
construct the VQ vector lookup table of size
\varname{[codebook\_entries]}.

The return value for this function is defined to be 'the greatest
integer value for which \varname{[return\_value]} to the power of
\varname{[codebook\_dimensions]} is less than or equal to
\varname{[codebook\_entries]}'.

\subsubsection{low\_neighbor} \label{vorbis:spec:low:neighbor}

"low\_neighbor(v,x)" finds the position \varname{n} in vector \varname{[v]} of
the greatest value scalar element for which \varname{n} is less than
\varname{[x]} and vector \varname{[v]} element \varname{n} is less
than vector \varname{[v]} element \varname{[x]}.

\subsubsection{high\_neighbor} \label{vorbis:spec:high:neighbor}

"high\_neighbor(v,x)" finds the position \varname{n} in vector [v] of
the lowest value scalar element for which \varname{n} is less than
\varname{[x]} and vector \varname{[v]} element \varname{n} is greater
than vector \varname{[v]} element \varname{[x]}.

\subsubsection{render\_point} \label{vorbis:spec:render:point}

"render\_point(x0,y0,x1,y1,X)" is used to find the Y value at point X
along the line specified by x0, x1, y0 and y1.  This function uses an
integer algorithm to solve for the point directly without calculating
intervening values along the line.

\begin{programlisting}
  1)  [dy] = [y1] - [y0]
  2) [adx] = [x1] - [x0]
  3) [ady] = absolute value of [dy]
  4) [err] = [ady] * ([X] - [x0])
  5) [off] = [err] / [adx] using integer division
  6) if ( [dy] is less than zero ) {

       7) [Y] = [y0] - [off]

     } else {

       8) [Y] = [y0] + [off]

     }

  9) done
\end{programlisting}

\subsubsection{render\_line} \label{vorbis:spec:render:line}

Floor decode type one uses the integer line drawing algorithm of
"render\_line(x0, y0, x1, y1, v)" to construct an integer floor
curve for contiguous piecewise line segments. Note that it has not
been relevant elsewhere, but here we must define integer division as
rounding division of both positive and negative numbers toward zero.

\begin{programlisting}
  1)   [dy] = [y1] - [y0]
  2)  [adx] = [x1] - [x0]
  3)  [ady] = absolute value of [dy]
  4) [base] = [dy] / [adx] using integer division
  5)    [x] = [x0]
  6)    [y] = [y0]
  7)  [err] = 0

  8) if ( [dy] is less than 0 ) {

        9) [sy] = [base] - 1

     } else {

       10) [sy] = [base] + 1

     }

 11) [ady] = [ady] - (absolute value of [base]) * [adx]
 12) vector [v] element [x] = [y]

 13) iterate [x] over the range [x0]+1 ... [x1]-1 {

       14) [err] = [err] + [ady];
       15) if ( [err] >= [adx] ) {

             16) [err] = [err] - [adx]
             17)   [y] = [y] + [sy]

           } else {

             18) [y] = [y] + [base]

           }

       19) vector [v] element [x] = [y]

     }
\end{programlisting}


\documentclass[jou]{apa6}

\usepackage[american]{babel}

\usepackage{csquotes}
\usepackage[style=apa,sortcites=true,sorting=nyt,backend=biber]{biblatex}
\DeclareLanguageMapping{american}{american-apa}
\addbibresource{bibliography.bib}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Discrete Structures
%% The start of RBS stuff
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Working internal and external links in PDF
\usepackage{hyperref}
% Extra math symbols in LaTeX
\usepackage{amsmath}
\usepackage{gensymb}
\usepackage{amssymb}
% Enumerations with (a), (b), etc.
\usepackage{enumerate}

\let\OLDitemize\itemize
\renewcommand\itemize{\OLDitemize\addtolength{\itemsep}{-6pt}}

\usepackage{etoolbox}
\makeatletter
\preto{\@verbatim}{\topsep=3pt \partopsep=3pt }
\makeatother

% These sizes redefine APA for A4 paper size
\oddsidemargin 0.0in
\evensidemargin 0.0in
\textwidth 6.27in
\headheight 1.0in
\topmargin -24pt
\headheight 12pt
\headsep 12pt
\textheight 9.19in

\title{Discrete Structures (W2): Sets and Predicates}
\author{Kalvis}
\affiliation{RBS}

\leftheader{Discrete Structures (W2)}

\abstract{
You will do more experiments with Boolean expressions and
start to prove propositional tautologies in Coq.
You will also formulate simple "human-oriented" proofs
about integer arithmetic and other topics.
}

\keywords{Coq, Boolean expressions, Syntax trees, tautologies, proofs.}

\begin{document}
\maketitle

{\bf (W2.1)} Try Boolean short-circuit evaluation on Python:
Define two functions: {\tt f(x)} and {\tt g(x)}. Each of them
prints a message and then returns value {\tt False}. For example:
\begin{verbatim}
def f():
    print('Running f(x)')
	return False
\end{verbatim}
After that evaluate this statment:
\begin{verbatim}
if f(x) and g(x):
    print('Unreachable statement')
\end{verbatim}
There should be also eager

%{\bf (W2.3)} Verify identities on set operations.
%
%{\bf (W2.4)} Indexed operations $\vee_{i=1}^{k}$, $\wedge_{i=1}^{k}$,
%$\cup_{i=1}^{k}$, $\cap_{i=1}^{k}$, $\sum_{i=1}^{k}$,
%$\prod_{i=1}^{k}$.

{\bf (W2.2)} Compare Boolean expressions in Coq, using prefix and infix notation.
\begin{verbatim}
Require Import Bool.
Eval compute in orb true false.
Eval compute in true || false.
Eval compute in andb true false.
Eval compute in true && false.
Eval compute in negb false.
Eval compute in if true then 3 else 4.
Definition a := true.
Eval compute in orb a (negb a).

Definition eMiddle (a:bool): bool :=
  orb a (negb a).
Eval compute in eMiddle true.

Definition Nor (a b:bool): bool :=
  negb (orb a b).
Eval compute in Nor true true.
\end{verbatim}

{\bf (W2.3)} Use precedence and associativity to draw abstract syntax trees.
Use boolean commands "orb", "andb", "implb" and "negb" to
compute in prefix notation this function:
$$E(a,b,c) := a \vee \neg(b \wedge (a \rightarrow c)).$$
Draw the syntax tree of this operation. Its leaves
are variables $a,b,c$ (and also constants, if they are present in the expression).
Inner nodes are all the Boolean operations with 1 or 2 variables.
So, in this tree every inner node has 1 or 2 children.

{\bf (W2.4)} Read a definition of a DNF (Disjunctive Normal Form).
Create a DNF for a 3-argument Boolean function.
You can pick the $8$ truth falues at random.

{\bf (W2.5)}
Prove that for any odd integer $k$, the square $k^2$
gives remainder $1$, when divided by $8$.

{\bf (W2.6)}
Prove that a positive integer $n$ has odd number of positive divisors
(including $1$ and $n$ itself) if and only if $n$ is a full square - can be expressed as $k^2$.

{\bf (W2.7)} Prove that for any prime number $p$, the square root
$\sqrt{p}$ is irrational.

{\bf (W2.8)}
Prove that for any real number $x$ its rounded value to the nearest tenth
(rounding to one decimal place) is equal to $\frac{1}{10}\lfloor 10x + 0.5 \rfloor$.

{\bf (W2.9)}
Prove that there is a function  $f:(-\pi;\pi) \rightarrow \mathbb{R}$
mapping interval $(-\pi;\pi)$ to $\mathbb{R}$ such that every real number
$y$ has exactly one $x$ such that $f(x)=y$.

{\bf (W2.10)}
Prove that it is impossible to enumerate all subsets of natural numbers with natural numbers.
(Natural numbers are all integers $\geq 0$).

{\bf (W2.11)}
Try out the examples in \url{https://bit.ly/2sfIrUK}.
Discuss, if you are unsure, how to write proofs.
Visit tutorials \url{https://bit.ly/37Zjso0}, if you need more inspiration.

{\bf (W2.12)}
Try out the Coq assignment on \url{https://bit.ly/37Zjso0}
(the link "Assignment about Coq (1 of 5)").

\newpage

\section{Some Answers}

{\bf (W2.1)}

Full Python program looks like this:
\begin{verbatim}
def f(): print('Runs f()'); return False
def g(): print('Runs g()'); return False
def h(): print('Runs h()'); return True

## Prints 'Runs f()':
if f() and g(): print('Unreachable')
## Prints 'Runs f()', 'Runs g()':
if f() & g(): print('Unreachable')
## Prints 'Runs h()' and 'Hi':
if h() or g(): print('Hi')
## Prints 'Runs h()', 'Runs g()' and 'Hi'
if h() | g(): print('Hi')
\end{verbatim}

{\bf (W2.5)} Assume that $n$ is odd. Represent it as
$n = 2k+1$. Then
$$n^2 = (2k+1)^2 = 4k^2 +4k + 1 = 4k(k+1) + 1.$$
Consider two cases:\\
(1) If $k$ is odd, then $k+1$ is even and
$4\times (k+1)$ is divisible by $8$.\\
(2) If $k$ is even, then $4 \times k$ is divisible by
$8$.\\
In either case $4k(k+1)$ is divisible by $8$.
Therefore $4k(k+1) + 1$ always gives remainder $1$ when
divided by $8$.

{\bf (W2.6)} Biconditional (if-and-only-if) statement contains two
implications:\\
(1) First, assume that $n$ is a full square: $n = k^2$. We need to
prove that it has odd number of positive divisors.
For any divisor of $n$: $d < \sqrt{n}=k$ there exists another divisor
$d' = n/d$ which is bigger than $\sqrt{n}$ \textendash{} you can
divide all divisors in pairs. In addition, $n$ has a divisor $k = \sqrt{n}$
that is paired with itself.\\
Example: The number $36=6^2$ has these divisor pairs:
$$(1;36),\;(2;18),\;(3;12),\;(4;9),\;(6;6).$$
Since the divisor $\sqrt{n}$ is paired with itself, there is
an odd number of positive divisors.\\
(2) Secondly, assume that $n$ has odd number of divisors; we should prove
that it is a full square.\\
In fact, we will prove the counterpositive: If $n$ is {\bf not} a full square,
then it has even number of divisors. To see this, we also arrange divisors
of $n$ in pairs \textendash{} as before, one of them is less than $\sqrt{n}$, another
one is bigger than $\sqrt{n}$. Only this time the number $\sqrt{n}$ itself
does not count as a divisor of $n$, because it is not an integer.\\
Example: The number $12 \approx (3.4641\ldots)^2$ has these divisor pairs:
$$(1;12),\;(2;6),\;(3;4).$$

\end{document}


\documentclass[11 pt]{scrartcl}
\usepackage[header, margin, koma]{tyler}

\newcommand{\hwtitle}{Discussion 3A Recap}

\pagestyle{fancy}
\fancyhf{}
\fancyhead[l]{\hwtitle{}}
\fancyhead[r]{Tyler Zhu}
\cfoot{\thepage}

\begin{document}
\title{\Large \hwtitle{}}
\author{\large Tyler Zhu}
\date{\large\today}

\maketitle

\section{Modular Arithmetic}
\begin{definition}
    We say that $a$ is \emph{congruent} to $b \pmod{m}$ if
    \[ a\equiv b \pmod{m} \iff m | a-b \iff a-b = m\cdot k, \quad k\in\ZZ .\]
\end{definition}

One interpretation is that mod $m$ gets the remainder when we divide by $m$, but the mod operator is more powerful than just that. For example, we have that
\begin{align*}
    \dots \equiv -9 \equiv -4 \equiv \boxed{1} \equiv 6 \equiv 11 \equiv \dots \pmod{5} \\
    \dots \equiv -8 \equiv -3 \equiv \boxed{2} \equiv 7 \equiv 12 \equiv \dots \pmod{5} \\
    \dots \equiv -7 \equiv -2 \equiv \boxed{3} \equiv 8 \equiv 13 \equiv \dots \pmod{5}
\end{align*}

Given that so many numbers are equivalent to each other when working over a certain modulus, it helps us to agree upon a set of \emph{representatives} for each equivalence class of numbers. In the above example, the representatives for each class has been boxed. In general, the representatives are $\{0, 1, \dots, m-1\}$.

To drive this point home, compare to how we say that all of the following fractions are the same, but we use the boxed one as their representative (namely $\frac 13$):
\[ \dots = \dfrac{-3}{-9} = \dfrac{-2}{-6} = \dfrac{-1}{-3} = \boxed{\dfrac{1}{3}} = \dfrac{2}{6} = \dfrac{3}{9} = \dots \]

Doing math over a modulus is similar to normal arithmetic; addition, subtraction, multiplication, and exponentiation all hold.

Division is tricky however. Being able to divide by $a$ is equivalent to having an \emph{inverse}, i.e. a number $x$ which makes $ax \equiv 1 \pmod{m}$. The existence of an inverse is equivalent to having a solution $(x,k)$ over integers to the equation $ax = 1 + m\cdot k$. We saw in the notes (and you can reason why) that this happens only when $\gcd(a,m) = 1$, and is unique mod $m$.

In general, it's a good question to ask when we have solutions to the equation
\[ ax + by = c\]
for $a,b,d \in \ZZ$. If we let $d = \gcd(a,b)$, then solutions exist only when $d | c$ (take this equation mod $d$ if you don't believe me). Additionally, mod $a$ or $b$ these solutions are unique.

We even have an algorithm called the \emph{Extended Euclidean Algorithm} which helps us find solutions to $ax+by = d$, from which we can get solutions to any equation in the above form (the Euclidean Algorithm lets us compute $\gcd(a,b)$ efficiently; you can imagine why extending it lets us recover the above solutons).

One common followup is finding the number of solutions to an equation like $10x \equiv 25 \pmod{30}$. Think about this (you may find the above context helpful).

\section{Tips}
\itemnum
    \ii ``Find the last digit'' $\rar$ Take mod $10$. ``Last two digits'' $\rar$ Take mod $100$, and so on.
    \ii It's useful to write a number $n$ as $n = \sum_{i=0}^k d_i 10^i = \overline{d_kd_{k-1}\dots d_1d_0}$ when taking mods.
    \ii Recall that $a\equiv b \implies a^n \equiv b^n \pmod{n}$; in other words, reduce the bases of your powers.
    \ii It can be helpful to work with different definitions of modular arithmetic. For example, showing that $3x\equiv 10 \pmod{21}$ has no solutions is easiest by demonstrating that $3x = 10 + 21k$ reduces to $0\equiv 1 \pmod{3}$.
    \ii While the EEA is great, finding inverses will often be faster/easier by writing out multiples of $m$. For example, if I'm finding the inverse of $9$ mod $11$, it's easier to look for a multiple of 9 in $1, 12, 23, 34, 45, \dots$ and then divide than to do the EEA.
\itemend

\section{Extra Practice}
\begin{exercise}
    Prove that for any number $n$, the alternating sum of the digits of $n$, i.e. $d_0 - d_1 + d_2 - \dots$, is divisible by 11 if and only if $n$ is divisible by 11.
\end{exercise}

\end{document}


\subsection{Soft constraint specifications: Fizz-Buzz}
We start with an extremely simple example, highlighting how easy our system makes it to encode and check data integrity constraints. The Fizz-Buzz programming exercise is based on a children's game and frequently found in programming interviews. The synthetic dataset we generated obeys the following rules: for each record \(x, y\), $x$ is a number between 0 and 1000, and $y$ is ``Fizz'' if \(x \mod 3 = 0\), ``Buzz'' if \(x \mod 5 = 0\), ``FizzBuzz'' if \(x \mod 15 = 0\), and \(x\) otherwise. In our synthetic dataset we introduced three outliers: \texttt{(25, "Fizz")}, \texttt{(28, "Woof!")}, \texttt{(30, "Buzz")}. Each demonstrates a different error, namely swapping ``Fizz'' and ``Buzz'', producing entirely incorrect output, and failing to recognize that a number is divisible by both $3$ and $5$.

A traditional way of checking that all tuples verify the production rule outlined above is to encode this rule itself as a database integrity constraint. This requires encoding the full complexity of the exercise in the rule, and would require manual adjustments if the rules were to change. Instead, a user might want to specify the bare minimum for the system to infer the rules; in this case, it is sufficient to add one extraction rule, mapping integers to two booleans denoting whether they are divisible by $3$ or $5$. In \dBoost/, this is expressed as:

\begin{minted}{python3}
@rule
def divisibleBy3or5(x: int) -> ("div 3", "div 5"):
  return (x % 3 == 0, x % 5 == 0)
\end{minted}

Running the discrete statistical analyzer on the synthetic datasets suggests that the two columns are correlated, and using the histogram model flags the aforementioned outliers. The output of the program for the \texttt{(30, "Buzz")} line, for example, is similar to:

\begin{lstnobreak}[gobble=2]
   $30$ $Buzz$
   > Values ($30$, '$Buzz$') do not
     match features ('$div 3$', '$strip numbers$')
   • histogram for ('div 3', 'strip numbers'):
     [532] ████████████████████ (False, '<num>')
     [133] █████ (False, 'Buzz')
     [  1] ▌ (False, 'Fizz')
     [  1] ▌ (False, 'Woof!')
     [  1] /▌/ $(True, 'Buzz')$
     [267] ██████████ (True, 'Fizz')
     [ 66] ██ (True, 'FizzBuzz')
\end{lstnobreak}

Using the partitioned histogram model produces similar output:

\begin{lstnobreak}[gobble=2]
   $30$ $Buzz$
   > Values ($30$, '$Buzz$') do not
     match features ('$div 3$', '$strip numbers$')
   • histogram for ('strip numbers',) if 'div 3' = True:
     [  1] /▌/ $('Buzz',)$
     [267] ████████████████████ ('Fizz',)
     [ 66] ████ ('FizzBuzz',)
   ... if 'div 3' = False:
     [532] ████████████████████ ('<num>',)
     [133] █████ ('Buzz',)
     [  1] ▌ ('Fizz',)
     [  1] ▌ ('Woof!',)
\end{lstnobreak}


\documentclass[a4paper,12pt]{article}

\usepackage{amsmath,amssymb,amsthm,tikz}
\usetikzlibrary{calc,arrows.meta}
\usepackage[margin=20mm]{geometry}
\usepackage{hyperref}

\setlength{\parindent}{0pt}
\setlength{\columnsep}{1cm}

\begin{document}

\twocolumn

\thispagestyle{empty}

\begin{center}
{\Large Assignment 12}\\
{\Large Published on 2020-12-06,}\\
{\em Estimated Time: 30 minutes,}\\
{\em Max.grade 10\textperthousand}
\end{center}

\section{Strongly Connected Components}

One of the multiple practical applications of a DFS traversal of a directed graph
is finding strongly connected components (strongly connected graphs are defined
in (Goodrich2011, p.626)), the relevant algorithm is
known as Kosaraju's algorithm.
See \url{https://bit.ly/3lI20ec}, \url{https://bit.ly/3mNU2la}.

{\bf Definition.} A subset of vertices in a directed graph $S \subseteq G.V$ makes a strongly
connected component, iff for any two distinct vertices $u,v$ there is
a path $u \leadsto v$ (one or more  and also another path $v \leadsto u$ that goes
back from $v$ to $u$).

If you can travel only in one direction (say, from $u$ to $v$), but cannot return,
then $u,v$ should be in different strongly connected components.
(Same thing, if $u$ and $v$ are mutually unreachable.) Moreover, every
vertex is strongly connected to itself \textendash{} so even in the worst case
a graph with $n$ vertices would have at most $n$ strongly connected components
(containing one vertex each).

Figure~\ref{fig:strongly-connected-transposed} shows an example of a graph with $n=5$ vertices
having $3$ strongly connected components. Next to that graph is the {\em transposed graph} $G^T$
where all the edges are reversed.

\begin{figure}[!htb]
\center{\includegraphics[width=3in]{assignment12-strongly-connected/strongly-connected-transposed.png}}
\caption{\label{fig:strongly-connected-transposed} Graph $G$ and $G^T$}
\end{figure}

\subsection{Kosaraju's algorithm}

There is a way to find strongly connected components in an
arbitrary graph by
running DFS twice (i.e. it works in linear time $O(n+m)$).

$$\begin{array}{rl}
  & \text{\sc Strongly\textunderscore{}Connected}(G)\\
  & \textcolor{teal}{\text{\em (compute all finishing times $u.f$)}}\\
1 & \text{call}\;\text{\sc DFS}(G)\\
  & \textcolor{teal}{\text{\em ($G^T$ is transposed $G$, all edges reversed)}}\\
2 & \text{compute}\;G^{T}\\
  & \textcolor{teal}{\text{\em (visit vertices in decreasing $u.f$ order)}}\\
3 & \text{call}\;\text{\sc DFS}(G^T)\\
4 & \text{\bf for each}\;\text{tree $T$ in the forest}\;\text{\sc DFS}(G^T)\\
5 & \hspace{0.5cm} \text{Output $T$ as a component}\\
\end{array}$$

To see how this works, we can run it on the example graph shown earlier.
After the DFS on graph $G$ is run, we get the finishing times
for the vertices $0,1,2,3,4$ (all shown in red on the left side
of Figure~\ref{fig:strongly-connected-dfs}.).
After that we replace $G$ by $G^T$ (to the right side of
the same figure), and assign priorities in the decreasing sequence
of $u.f$ (the finishing times when running $\text{\sc DFS}(G)$).

\begin{figure}[!htb]
\center{\includegraphics[width=3in]{assignment12-strongly-connected/strongly-connected-dfs.png}}
\caption{\label{fig:strongly-connected-dfs} DFS on $G$ and $G^T$}
\end{figure}

To make this reverse order obvious, we assign new priorities to
the vertices in $G^T$. The new priorities in $G^T$ are the following:

\begin{itemize}
\item Vertex {\tt "0"} has priority $11 - 10 = 1$.
\item Vertex {\tt "1"} has priority $11 - 4 = 7$.
\item Vertex {\tt "2"} has priority $11 - 5 = 6$.
\item Vertex {\tt "3"} has priority $11 - 9 = 2$.
\item Vertex {\tt "4"} has priority $11 - 8 = 3$.
\end{itemize}

Now run $\text{\sc DFS}(G^T)$. It turns out that the DFS algorithm starts
in the vertex {\tt "0"} once again (since it was finished last in $\text{\sc DFS}(G)$).
But unlike the DFS algorithm in $G$ itself (it produced just one DFS tree),
we get a DFS forest with 3 components (tree/discovery edges shown bold and black in
Figure~\ref{fig:strongly-connected-dfs}).

\begin{itemize}
\item $\{ \mathtt{"0"}, \mathtt{"1"}, \mathtt{"2"} \}$ (DFS tree has root $\mathtt{"0"}$).
\item $\{ \mathtt{"3"} \}$ (DFS tree has root $\mathtt{"3"}$).
\item $\{ \mathtt{"4"} \}$ (DFS tree has root $\mathtt{"4"}$).
\end{itemize}

They represent the strongly connected components in $G$ (they are also
strongly connected in $G^T$).

\section{Problem}

We start with the graph shown in Figure~\ref{fig:problem-graph}.

\begin{figure}[!htb]
\center{\includegraphics[width=3in]{assignment12-strongly-connected/problem-graph.png}}
\caption{\label{fig:problem-graph} Graph diagram}
\end{figure}

\vspace{10pt}
{\bf (A)} Compute the following three numbers from $a,b,c$ (your last
Student ID numbers):
$$\left\{ \begin{array}{l}
U = 2 \cdot ((a+b)\;\text{mod}\;5)\\
V = 2 \cdot ((b+c)\;\text{mod}\;5)+1\\
W = 2 \cdot ((c+a)\;\text{mod}\;5)+1\\
\end{array} \right.$$

By $(x\;\text{mod}\;y)$ we denote the remainder as $x$ is divided by $y$.
Add to the original graph two new directed edges $(U,V)$ and $(U,W)$.
(For example, if $U = 2$, $V = 7$, $W = 1$ then add two outgoing edges from
{\tt "2"} to {\tt "5"} and {\tt "1"} respectively. If an edge exists, do
not add anything.)

Draw the new graph; show the newly added edges in bold or colored differently.

\vspace{10pt}
{\bf (B)} Run the DFS traversal algorithm on the graph $G$.
Mark each vertex
with the pair of numbers {\tt d/f}, where the first number {\tt d} is the
discovery time, and the second number {\tt f} is the finishing time.

\vspace{10pt}
{\bf (C)} Draw the transposed directed graph (same vertices, but each arrow points
in the opposite direction).
Run the DFS traversal algorithm on $G^T$. Make sure that the DFS
outer loop visits the vertices in the reverse order by $u.f$
(the finishing time for the DFS algorithm in step (B)).
In this case you do not produce the discovery/finishing times once again,
just draw the discovery edges used by the DFS on $G^T$ \textendash{}
you can highlight them (show them in bold or use a different color).

\vspace{10pt}
{\bf (D)} List all the strongly connected components (they are
the separate pieces in the forest obtained by running DFS
on $G^T$).

\end{document}


\documentclass[a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath,amssymb}
\usepackage{mathtools}
\usepackage{csquotes}
\usepackage[pdfborder={0 0 0}]{hyperref}

\newcommand\E{\mathbb{E}}
\newcommand\N{\mathcal{N}}
\DeclareMathOperator\cov{cov}
\DeclareMathOperator\var{var}

\newcommand\given{
  \nonscript\:
  \vert
  \nonscript\:
  \mathopen{}
  \allowbreak
}

\title{Mathematical notes on Bishop's book on Pattern Recognition and Machine Learning}
\author{Lukas Prokop}
\date{October 2016 to February 2016}

\begin{document}
\maketitle
\tableofcontents
\clearpage

\section{Preliminaries}

\section{Exercise 1.5}

\begin{description}
  \item[Given] $\var[f] = \E[(f(x) - \E[f(x)])^2]$
  \item[Find] $\var[f] = \E[f(x)^2] - \E[f(x)]^2$
\end{description}

For the expected value $\E$, random variables $a$ and $b$ and constant $c$ it holds that
\begin{align}
  \E[a+b] &= \E[a] + \E[b]       \label{eq:e-add} \\
  \E[c \cdot a] &= c \cdot \E[a] \label{eq:e-multi} \\
  \E[c] &= c                     \label{eq:e-const}
\end{align}

Followingly, we can prove the desired equation:
\begin{align*}
  \var[f] &= \E[(f(x) - \E[f(x)])^2] \\
          &= \E[f(x)^2 - 2f(x) \E[f(x)] + \E[f(x)]^2] \\
          &\overset{\eqref{eq:e-add}}{=} \E[f(x)^2] - \E[2 \cdot f(x) \cdot \E[f(x)]] + \E[f(x)]^2 \\
          &\overset{\eqref{eq:e-multi}}{=} \E[f(x)^2] - \E[2] \cdot \E[f(x)] \cdot \E[\E[f(x)]] + \E[f(x)]^2 \\
          &\overset{\eqref{eq:e-const}}{=} \E[f(x)^2] - 2 \cdot \E[f(x)] \cdot \E[f(x)] + \E[f(x)]^2 \\
          &= \E[f(x)^2] - \E[f(x)]^2
\end{align*}

\section{$\E[ab] = \E[a] \cdot \E[b]$ if $a$ and $b$ are independent}
%
\begin{description}
  \item[Given] two independent random variables $a$ and $b$
  \item[Find] $\E[a \cdot b] = \E[a] \cdot \E[b]$
\end{description}

Let $p(x)$ be the probability density function on $\mathbb{R}$
and $x$ be the $\mathbb{R}$-valued random variable (for $p$).
The expectation $\E[x]$ is defined by
\[ \E[x] = \int_{\mathbb R} p(x) \cdot x \, dx \]
We will prove the formula under this setting.
The case that the probability distribution is defined on ${\mathbb R}^d$
can be discussed analogously. The case that the probability distribution
is given on a finite set $\Omega$ can be discussed by replacing the
integral by the sum over the finite set $\Omega$.
Furthermore for two independent random variables $a$ and $b$, it holds that
\[ p(ab) = p(a) \cdot p(b) \]

\begin{align*}
  \E[x] &= \int p(x) \cdot x \, dx \\
  \E[a \cdot b]
    &= \int \left( p(ab) \cdot ab \right) \: d(ab) \\
    &= \int \int \left( p(a) \cdot p(b) \cdot a \cdot b \right)   \: da \, db \\
    &= \int \int \left( p(a) \cdot a \right)  \cdot \left(p(b) \cdot b\right)  \: da \, db \\
%    &= \int \left( \left( \int p(a) \cdot a \: da\right) \cdot p(b) \cdot b \right)   \: db \\
    &= \left(\int p(a) \cdot a \: da\right) \left(\int p(b) \cdot b  \: db\right) \\
    &= \E[a] \cdot \E[b]
\end{align*}

\section{Exercise 1.6}

\begin{quote}
  \enquote{For two random variables $x$ and $y$, the \emph{covariance} is defined by
  \begin{align*}
    \cov{[x,y]} &= \E_{x,y}[\{x - \E_{x}[x]\}\{y - \E_{y}[y]\}] \\
                &= \E_{x,y}[xy] - \E_{x}[x] \E_{y}[y]
  \end{align*}
  which expresses the extent to which $x$ and $y$ vary together.
  If $x$ and $y$ are independent, then their covariance vanishes.} \\
  ---page 20
\end{quote}

\begin{description}
  \item[Given] two independent random variables $x$ and $y$ with covariance defined by $\cov[x,y] = \E_{x,y}[\{x - \E_{x}[x]\}\{y - \E_{y}[y]\}]$
  \item[Find] $\cov[x,y] = 0$
\end{description}

If two random variables $a$ and $b$ are independent, then it holds that
\begin{align}
  \E[a \cdot b] &= \E[a] \cdot \E[b]       \label{eq:e-2-multi}
\end{align}

\begin{align*}
  \cov{[x,y]}
    &= \E_{x,y}[\{x - \E_{x}[x]\}\{y - \E_{y}[y]\}] \\
    &= \E_{x,y}[xy - y\E_x[x] - x\E_y[y] + \E_x[x] \cdot \E_y[y]] \\
    &\overset{\eqref{eq:e-add}}{=} \E_{x,y}[xy] + \E_{x,y}[-y \cdot \E_x[x]] + \E_{x,y}[-x \cdot \E_y[y]] + \E_{x,y}[\E_x[x] \cdot \E_y[y]] \\
    &\overset{\eqref{eq:e-multi}}{=} \E_{x,y}[xy] - \E_x[x] \cdot \E_{y}[y] - \E_{y}[y] \cdot \E_{x}[x] + \E_{x,y}[\E_x[x] \cdot \E_y[y]] \\
    &\overset{\eqref{eq:e-2-multi}}{=} \E_{x,y}[x] \cdot \E_{x,y}[y] - 2 \cdot \E_x[x] \cdot \E_{y}[y] + \E_{x,y}[\E_x[x] \cdot \E_y[y]] \\
    &\overset{\eqref{eq:e-const}}{=} \E_{x,y}[x] \cdot \E_{x,y}[y] - 2 \cdot \E_x[x] \cdot \E_{y}[y] + \E_x[x] \cdot \E_y[y] \\
    &= 0
\end{align*}

\section{Gaussian interpretation of curve fitting}

\begin{description}
  \item[Given] $p(t \given x,w,\beta) = \N(t \given y(x,w), \beta^{-1})$ and
    \[ \N(x \given \mu, \sigma^2) = (2 \pi \sigma^2)^{-\frac12} \exp\left(-2^{-1} \sigma^{-2} (x - \mu)^2\right) \]
  \item[Find]
    \[ \ln{p(t \given x,w,\beta)} = -\frac{\beta}{2} \cdot \sum_{n=1}^N \left(y(x_n,w) - t_n\right)^2 + \frac{N}{2} \ln\beta - \frac{N}{2} \ln(2\pi) \]
\end{description}

Remember the basic laws for logarithms:
\begin{align}
  \ln(a \cdot b) &= \ln{a} + \ln{b}              \label{eq:ln-multi} \\
  \ln\left(\frac{a}{b}\right) &= \ln{a} - \ln{b} \label{eq:ln-div} \\
  \ln(\exp(a)) &= a                              \label{eq:ln-inv} \\
  \ln(a^b) &= b \cdot \ln(a)                     \label{eq:ln-power}
\end{align}

\begin{align}
  \ln{p(t \given x,w,\beta)} &= (2 \pi \beta^{-1})^{-\frac12} \exp\left(-2^{-1} \beta (t - y(x,w))^2\right) \\
      &\overset{\eqref{eq:ln-multi}}{=} \ln(2 \pi \beta^{-1})^{-\frac12} + \ln\exp\left(-2^{-1} \beta (t - y(x,w))^2\right) \\
      &\overset{\eqref{eq:ln-inv}}{=} \ln\left(\frac{\beta}{2\pi}\right)^{\frac12} - \frac{\beta}{2}\left(t - y(x,w)\right)^2 \\
      &\overset{\eqref{eq:ln-inv}}{=} \frac12 \cdot \ln\left(\frac{\beta}{2\pi}\right) - \frac{\beta}{2}\left(t - y(x,w)\right)^2 \\
      &\overset{\eqref{eq:ln-inv}}{=} \frac12 \cdot \ln \beta - \frac12 \cdot \ln(2\pi) - \frac{\beta}{2}\left(t - y(x,w)\right)^2 \\
  \sum_{n=1}^N \ln{p(t_n \given x_n,w,\beta)} &= \sum_{n=1}^N \left(\frac12 \ln{\beta} - \frac12 \ln{2\pi} - \frac\beta2 (t_n - y(x_n, w))^2\right) \\
      &= \frac{N}{2} \ln\beta - \frac{N}{2} \ln{2\pi} - \frac{\beta}{2} \sum_{n=1}^N \left(y(w_n, w) - t_n\right)^2
\end{align}

\section{Exercise 1.11}

\begin{description}
  \item[Given] $\ln{p(x \given \mu, \sigma^2)} = -\frac1{2\sigma^2} \sum_{n=1}^N (x_n - \mu)^2 - \frac{N}{2} \ln{\sigma^2} - \frac{N}{2} \ln(2\pi)$
  \item[Find] $\mu_{\text{ML}} = \frac{1}{N} \cdot \sum_{n=1}^N x_n$ for maximized $\mu$ and \\
    $\sigma_{\text{ML}} = \frac{1}{N}\cdot \sum_{n=1}^N (x_n - \mu_{\text{ML}})^2$ for maximized $\sigma^2$
\end{description}

So we want to determine the 2 parameters of a Gaussian distribution, namely $\mu$ and $\sigma^2$, in the maximum likelihood case.
We begin with $\mu$:

\begin{enumerate}
  \item Derive $\ln{p(x \given \mu, \sigma^2)}$ for $\mu$
    \begin{align*}
      \frac\partial{\partial \mu} \ln{p(x \given \mu, \sigma^2)}
      &= \frac\partial{\partial \mu} \left(-\frac{1}{2\sigma^2} \cdot \sum_{n=1}^N (x_n - \mu)^2 - \frac{N}{2} \ln{\sigma^2} - \frac{N}{2} \ln(2\pi)\right) \\
      &= \frac\partial{\partial \mu} \left(-\frac{1}{2\sigma^2} \cdot \sum_{n=1}^N (x_n^2 - 2 x_n \mu + \mu^2) - \frac{N}{2} \ln{\sigma^2} - \frac{N}{2} \ln(2\pi)\right) \\
      &= -\frac{1}{2\sigma^2} \cdot \sum_{n=1}^N (-2x_n + 2\mu) \\
      &= -\frac1{\sigma^2} \cdot \sum_{n=1}^N (\mu - x_n)
    \end{align*}
  \item Set result zero
    \[ 0 = -\frac{1}{\sigma^2} \cdot \sum_{n=1}^N (\mu - x_n) = \sum_{n=1}^N (\mu - x_n) = N \cdot \mu - \sum_{n=1}^N x_n \]
    \[ \implies \mu_{\text{ML}} = \frac1N \cdot \sum_{n=1}^N x_n \qquad \text{commonly called \enquote{sample mean}} \]
\end{enumerate}

We continue with $\sigma^2$ and use the same approach:

\begin{enumerate}
  \item Derive $\ln{p(x \given \mu, \sigma^2)}$ for $\sigma^2$
    \begin{align*}
      \frac{\partial}{\partial \sigma^2} \ln{p(x \given \mu, \sigma^2)}
      &= \frac{\partial}{\partial \sigma^2} \left(-\frac{1}{2\sigma^2} \cdot \sum_{n=1}^N (x_n - \mu)^2 - \frac{N}2 \ln{\sigma^2} - \frac{N}2 \ln(2\pi)\right) \\
      &= \frac{1}{2\sigma^4} \cdot \sum_{n=1}^N (x_n - \mu)^2 - \frac{N}{2} \cdot \frac{1}{\sigma^2} \\
      &= \frac{1}{2\sigma^2} \left(\frac{1}{\sigma^2} \cdot \sum_{n=1}^N (x_n - \mu)^2 - N\right)
    \end{align*}
  \item Set result zero
    \begin{align*}
      0 &= \frac{1}{2\sigma^2} \left(\frac{1}{\sigma^2} \cdot \sum_{n=1}^N (x_n - \mu)^2 - N\right) \\
      N \cdot \sigma^2 &= \sum_{n=1}^N (x_n - \mu)^2 \\
      \sigma^2_{\text{ML}} &= \frac{1}{N} \cdot \sum_{n=1}^N (x_n - \mu)^2 \qquad \text{commonly called \enquote{sample variance}}
    \end{align*}
\end{enumerate}

\section{Precision parameter $\beta$ in the maximum likelihood case}

\begin{description}
  \item[Given] $\ln{p(t \given x,w,\beta)} = -\frac{\beta}{2} \cdot \sum_{n-1}^N \left(y(x_n,w) - t_n\right)^2 + \frac{N}2 \ln{\beta} - \frac{N}{2} \ln(2\pi)$
  \item[Find] $\frac{1}{\beta_{\text{ML}}} = \frac{1}{N} \cdot \sum_{n=1}^N (y(x_n, w_{\text{ML}}) - t_n)^2$ by maximizing $\beta$
\end{description}

\begin{enumerate}
  \item Derive $\ln{p(t \given x,w,\beta)}$ with $\beta$
    \begin{align*}
      \frac{\partial}{\partial \beta} \ln{p(t \given x,w,\beta)}
      &= \frac{\partial}{\partial \beta} \left(-\frac{\beta}{2} \sum_{n=1}^N (y(x_n,w) - t_n)^2 + \frac{N}{2} \ln\beta - \frac{N}{2} \ln(2\pi)\right) \\
      &= -\frac12 \cdot \sum_{n=1}^N \left(y(x_n,w) - t_n\right)^2 + \frac{N}{2} \cdot \frac1\beta
    \end{align*}
  \item Set result zero
    \begin{align*}
      0 &= -\frac{1}{2} \cdot \sum_{n=1}^N \left(y(x_n,w) - t_n\right)^2 + \frac{N}{2\beta} \\
      \frac{N}{\beta} &= \sum_{n=1}^N \left(y(x_n,w) - t_n\right)^2 \\
      \frac{1}{\beta_{\text{ML}}} &= \frac{1}{N} \cdot \sum_{n=1}^N (y(x_n,w) - t_n)^2
    \end{align*}
\end{enumerate}

\end{document}


\subsubsection{lag}
We design a lag controller with siso tool box.
$$
C(s) = \dfrac{3.6493(s + 7.347)}{s + 3.694}
$$
\begin{itemize}
	\item all figures from siso toolbox
	\begin{figure}[H]
		\caption{All figures from siso toolbox}
		\centering
		\includegraphics[width=16cm]{../Figure/Q1/Q1_b/lag/siso_all.png}
	\end{figure}
	\newpage
	\item root locus with lag controller
	\begin{figure}[H]
		\caption{root locus}
		\centering
		\includegraphics[width=12cm]{../Figure/Q1/Q1_b/lag/rlocus.png}
	\end{figure}
	\item step response for closeloop system with lag controller
	\begin{figure}[H]
		\caption{step response for closeloop system}
		\centering
		\includegraphics[width=12cm]{../Figure/Q1/Q1_b/lag/feedback_step.png}
	\end{figure}
	\item closeloop bode (magnitude) with lag controller
	\begin{figure}[H]
		\caption{closeloop bode (magnitude)}
		\centering
		\includegraphics[width=12cm]{../Figure/Q1/Q1_b/lag/feedback_bode.png}
	\end{figure}
	\item openloop bode (magnitude) with lag controller
	\begin{figure}[H]
		\caption{openloop bode (magnitude)}
		\centering
		\includegraphics[width=12cm]{../Figure/Q1/Q1_b/lag/openloop_bode.png}
	\end{figure}
	\item sensitivity function with lag controller
	\begin{figure}[H]
		\caption{sensitivity function}
		\centering
		\includegraphics[width=12cm]{../Figure/Q1/Q1_b/lag/s_bode.png}
	\end{figure}
	\item complementary sensitivity function with lag controller
	\begin{figure}[H]
		\caption{complementary sensitivity function}
		\centering
		\includegraphics[width=12cm]{../Figure/Q1/Q1_b/lag/t_bode.png}
	\end{figure}
\end{itemize}
System is stable with controller and have a noise cancelation for frequancy after $100_{rad/{\sec}}$ and it have effect on system about $-20_{dB}$. System have very good disturbance rejection about $1_{rad/{\sec}}$ and have a good disturbance rejection about $10_{rad/{\sec}}$ and disturbance have effect on system about $-5_{dB}$.

In this question we don't know what is plant and actuator and how noise or disturbance effect on system and about what frequancy so we assume that noise is about more than $100_{rad/{\sec}}$ and disturbance is about $10_{rad/{\sec}}$ and$-5_{dB}$ is a low effect and system work well.

No. System have staedy state error. we could increase gain in controller but it needed very high gaib controller and no actuator can do this so we can't make staedy state error zero with this requirements.


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Copyright (c) 2003-2018 by The University of Queensland
% http://www.uq.edu.au
%
% Primary Business: Queensland, Australia
% Licensed under the Apache License, version 2.0
% http://www.apache.org/licenses/LICENSE-2.0
%
% Development until 2012 by Earth Systems Science Computational Center (ESSCC)
% Development 2012-2013 by School of Earth Sciences
% Development from 2014 by Centre for Geoscience Computing (GeoComp)
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\section{The Stokes Problem}
\label{STOKES PROBLEM}
In this section we discuss how to solve the Stokes problem.
We want to calculate the velocity\index{velocity} field $v$ and pressure $p$
of an incompressible fluid\index{incompressible fluid}.
They are given as the solution of the Stokes problem\index{Stokes problem}
\begin{equation}\label{Stokes 1}
-\left(\eta(v_{i,j}+ v_{j,i})\right)_{,j}+p_{,i}=f_{i}-\sigma_{ij,j}
\end{equation}
where  $f_{i}$ defines an internal force\index{force, internal} and
$\sigma_{ij}$ is an initial stress\index{stress, initial}.
The viscosity $\eta$ may weakly depend on pressure and velocity.
If relevant we will use the notation $\eta(v,p)$ to express this dependency.

We assume an incompressible medium:
\begin{equation}\label{Stokes 2}
-v_{i,i}=0
\end{equation}
Natural boundary conditions are taken in the form
\begin{equation}\label{Stokes Boundary}
\left(\eta(v_{i,j}+ v_{j,i})\right)n_{j}-n_{i}p=s_{i} - \alpha \cdot n_{i} n_{j} v_{j}+\sigma_{ij} n_{j}
\end{equation}
which can be overwritten by constraints of the form
\begin{equation}\label{Stokes Boundary0}
v_{i}(x)=v^D_{i}(x)
\end{equation}
at some locations $x$ at the boundary of the domain.
$s_{i}$ defines a normal stress and $\alpha\ge 0$ the spring constant for
restoring normal force.
The index $i$ may depend on the location $x$ on the boundary.
$v^D$ is a given function on the domain.

\subsection{Solution Method \label{STOKES SOLVE}}
If we assume that $\eta$ is independent from the velocity and pressure,
equations~\ref{Stokes 1} and~\ref{Stokes 2} can be written in the block form
\begin{equation}
\left[ \begin{array}{cc}
A     & B^{*} \\
B & 0 \\
\end{array} \right]
\left[ \begin{array}{c}
v \\
p \\
\end{array} \right]
=\left[ \begin{array}{c}
G \\
0 \\
\end{array} \right]
\label{STOKES}
\end{equation}
where $A$ is a coercive, self-adjoint linear operator in a suitable Hilbert
space, $B$ is the $(-1) \cdot$ divergence operator and $B^{*}$ is the adjoint
operator (=gradient operator).
For more details on the mathematics see references \cite{AAMIRBERKYAN2008,MBENZI2005}.

If $v_{0}$ and $p_{0}$ are given initial guesses for velocity and pressure we
calculate a correction $dv$ for the velocity by solving the first equation of
\eqn{STOKES}
 \begin{equation}\label{STOKES ITER STEP 1}
 A dv_{1} = G - A v_{0} - B^{*} p_{0}
\end{equation}
We then insert the new approximation $v_{1}=v_{0}+dv_{1}$ to calculate a
correction $dp_{2}$ for the pressure and an additional correction $dv_{2}$ for
the velocity by solving
 \begin{equation}
 \begin{array}{rcl}
 B A^{-1} B^{*} dp_{2} & = & Bv_{1} \\
 A dv_{2} & = & B^{*} dp_{2}
\end{array}
 \label{STOKES ITER STEP 2}
 \end{equation}
The new velocity and pressure are then given by $v_{2}=v_{1}-dv_{2}$ and
$p_{2}=p_{0}+dp_{2}$ which will fulfill the block system~\ref{STOKES}.
This solution strategy is called the Uzawa scheme\index{Uzawa scheme}.

There is a problem with this scheme: in practice we will use an iterative
scheme to solve any problem for operator $A$.
So we will be unable to calculate the operator $ B A^{-1} B^{*}$ required for
$dp_{2}$ explicitly. In fact, we need to use another iterative scheme to solve
the first equation in~\ref{STOKES ITER STEP 2} where in each iteration step
an iterative solver for $A$ is applied. Another issue is the fact that the
viscosity $\eta$ may depend on velocity or pressure and so we need to iterate
over the three equations~\ref{STOKES ITER STEP 1} and~\ref{STOKES ITER STEP 2}.

In the following we will use the two norms
\begin{equation}
\|v\|_{1}^2 = \int_{\Omega} v_{j,k}v_{j,k} \; dx
\mbox{ and }
\|p\|_{0}^2= \int_{\Omega} p^2 \; dx.
\label{STOKES STOP}
\end{equation}
for velocity $v$ and pressure $p$.
The iteration is terminated if the stopping criterion
 \begin{equation} \label{STOKES STOPPING CRITERIA}
\max(\|Bv_{1}\|_{0},\|v_{2}-v_{0}\|_{1}) \le \tau \cdot \|v_{2}\|_{1}
 \end{equation}
for a given tolerance $0<\tau<1$ is met.
Notice that because of the first equation of~\ref{STOKES ITER STEP 2} we have
that $\|Bv_{1}\|_{0}$ equals the norm of $B A^{-1} B^{*} dp_{2}$ and
consequently provides a norm for the pressure correction.

We want to optimize the tolerance choice for solving~\ref{STOKES ITER STEP 1}
and~\ref{STOKES ITER STEP 2}. To do this we write the iteration scheme as a
fixed point problem. Here we consider the errors produced by the iterative
solvers being used.
From \eqn{STOKES ITER STEP 1} we have
\begin{equation} \label{STOKES total V1}
v_{1} = e_{1} + v_{0} + A^{-1} ( G - Av_{0} - B^{*} p_{0} )
\end{equation}
where $e_{1}$ is the error when solving~\ref{STOKES ITER STEP 1}.
We will use a sparse matrix solver so we have not full control on the norm
$\|.\|_{s}$ used in the stopping criterion for this equation.
In fact we will have a stopping criterion of the form
\begin{equation}
\| A e_{1} \|_{s}  = \| G - A v_{1} - B^{*} p_{0} \|_{s} \le \tau_{1} \| G - A v_{0} - B^{*} p_{0} \|_{s}
\end{equation}
where $\tau_{1}$ is the tolerance which we need to choose.
This translates into the condition
\begin{equation}
\| e_{1} \|_{1} \le K \tau_{1} \| dv_{1} - e_{1} \|_{1}
\end{equation}
The constant $K$ represents some uncertainty combining a variety of unknown
factors such as the norm being used and the condition number of the stiffness matrix.
From the first equation of~\ref{STOKES ITER STEP 2} we have
\begin{equation}\label{STOKES total P2}
p_{2} =  p_{0} + (B A^{-1} B^{*})^{-1} (e_{2} + Bv_{1} )
\end{equation}
where $e_{2}$ represents the error when solving~\ref{STOKES ITER STEP 2}.
We use an iterative preconditioned conjugate gradient method
(PCG)\index{linear solver!PCG}\index{PCG} with iteration operator
$B A^{-1} B^{*}$ using the $\|.\|_{0}$ norm.
As suitable preconditioner\index{preconditioner} for the iteration operator we
use $\frac{1}{\eta}$ \cite{ELMAN}, i.e. the evaluation of the preconditioner
$P$ for a given pressure increment $q$ is the solution of
\begin{equation} \label{STOKES P PREC}
\frac{1}{\eta} (Pq) = q \; .
\end{equation}
Note that in each evaluation of the iteration operator $q=B A^{-1} B^{*} s$
one needs to solve the problem
\begin{equation} \label{STOKES P OPERATOR}
A w = B^{*} s
\end{equation}
with sufficient accuracy to return $q=Bw$. We assume that the desired
tolerance is sufficiently small, for instance one can take $\tau_{2}^2$ where
$\tau_{2}$ is the tolerance for~\ref{STOKES ITER STEP 2}.

In an implementation we use the fact that the residual $r$ is given as
\begin{equation} \label{STOKES RES }
 r= B (v_{1} -  A^{-1} B^{*} dp) =  B (v_{1} - A^{-1} B^{*} dp) = B (v_{1}-dv_{2}) = B v_{2}
\end{equation}
In particular we have $e_{2} = B v_{2}$.
So the residual $r$ is represented by the updated velocity $v_{2}=v_{1}-dv_{2}$.
In practice, if one uses the velocity to represent the residual $r$ there is
no need to recover $dv_{2}$ in~\ref{STOKES ITER STEP 2} after $dp_{2}$ has
been calculated.
In PCG the iteration is terminated if
\begin{equation} \label{STOKES P OPERATOR ERROR}
\| P^{\frac{1}{2}}B v_{2} \|_{0} \le \tau_{2} \| P^{\frac{1}{2}}B v_{1} \|_{0}
\end{equation}
where $\tau_{2}$ is the given tolerance. This translates into
\begin{equation} \label{STOKES P OPERATOR ERROR 2}
\|e_{2}\|_{0} = \| B v_{2} \|_{0} \le M \tau_{2} \| B v_{1} \|_{0}
\end{equation}
where $M$ is taking care of the fact that $P^{\frac{1}{2}}$ is dropped.

As we assume that there is no significant error from solving with the operator
$A$ we have
\begin{equation} \label{STOKES total V2}
v_{2} =  v_{1} - dv_{2}
= v_{1}  - A^{-1} B^{*}dp
\end{equation}
Combining the equations~\ref{STOKES total V1},~\ref{STOKES total P2} and~\ref{STOKES total V2}
and setting the errors to zero we can write the solution process as a fix
point problem
\begin{equation}
v = \Phi(v,p) \mbox{ and } p = \Psi(u,p)
\end{equation}
with suitable functions $\Phi(v,p)$ and $ \Psi(v,p)$ representing the
iteration operator without errors. In fact, for a linear problem, $\Phi$ and
$\Psi$ are constant. With this notation we can write the update step in the
form $p_{2}= \delta p + \Psi(v_{0},p_{0})$ and $v_{2}= \delta v + \Phi(v_{0},p_{0})$
where the total error $\delta p$ and $\delta v$ are given as
\begin{equation}
 \begin{array}{rcl}
\delta p & = &  (B A^{-1} B^{*})^{-1} ( e_{2} + B e_{1} ) \\
\delta v & = &  e_{1} -  A^{-1} B^{*}\delta p  \;.
\end{array}\label{STOKES ERRORS}
\end{equation}
Notice that $B\delta v = - e_{2}=-Bv_{2}$.
Our task is now to choose the tolerances $\tau_{1}$ and $\tau_{2}$ such that
the global errors $\delta p$ and $\delta v$ do not stop the convergence of the
iteration process.

To measure convergence we use
\begin{equation}
\epsilon = \max(\|v_{2}-v\|_{1}, \|B A^{-1} B^{*} (p_{2}-p)\|_{0})
\end{equation}
In practice using the fact that $B A^{-1} B^{*} (p_{2}-p_{0}) = B v_{1}$
and assuming that $v_{2}$ gives a better approximation to the true $v$ than
$v_{0}$ we will use the estimate
\begin{equation}
\epsilon = \max(\|v_{2}-v_{0}\|_{1}, \|B v_{1}\|_{0})
\end{equation}
to estimate the progress of the iteration step after the step is completed.
Note that the estimate of $\epsilon$ is used in the stopping
criterion~\ref{STOKES STOPPING CRITERIA}.
If $\chi^{-}$ is the convergence rate assuming exact calculations, i.e.
$e_{1}=0$ and $e_{2}=0$, we are expecting to maintain $\epsilon \le \chi^{-} \cdot \epsilon^{-}$.
For the pressure increment we get:
\begin{equation} \label{STOKES EST 1}
\begin{array}{rcl}
\|B A^{-1} B^{*} (p_{2}-p)\|_{0}
 & \le & \|B A^{-1} B^{*} (p_{2}-\delta p-p)\|_{0} +
\|B A^{-1} B^{*} \delta p\|_{0} \\
 & = & \chi^{-} \cdot \epsilon^{-} + \|e_{2} + B e_{1}\|_{0}  \\
& \approx & \chi^{-} \cdot \epsilon^{-} + \|e_{2}\|_{0} \\
& \le & \chi^{-} \cdot \epsilon^{-} + M \tau_{2} \|B v_{1}\|_{0} \\
\end{array}
\end{equation}
So we choose the value for $\tau_{2}$ from
\begin{equation} \label{STOKES TOL2}
 M \tau_{2} \|B v_{1}\|_{0}  \le (\chi^{-})^2 \epsilon^{-}
\end{equation}
in order to make the perturbation for the termination of the pressure
iteration a second order effect. We use a similar argument for the velocity:
\begin{equation}\label{STOKES EST 2}
\begin{array}{rcl}
\|v_{2}-v\|_{1} & \le & \|v_{2}-\delta v-v\|_{1} + \| \delta v\|_{1} \\
& \le &  \chi^{-} \cdot \epsilon^{-}  + \| e_{1} -  A^{-1} B^{*}\delta p \|_{1} \\
& \approx &  \chi^{-} \cdot \epsilon^{-}  + \| e_{1} \|_{1} \\
& \le &  \chi^{-} \cdot \epsilon^{-}  +  K \tau_{1} \| dv_{1} - e_{1} \|_{1}
\\
& \le &  ( 1  + K \tau_{1}) \chi^{-} \cdot \epsilon^{-}
\end{array}
\end{equation}
So we choose the value for $\tau_{1}$ from
\begin{equation} \label{STOKES TOL1}
K \tau_{1} \le \chi^{-}
\end{equation}
Assuming we have estimates for $M$ and $K$\footnote{if no estimates are
available, we use the value $1$} we can use~\ref{STOKES TOL1} and
\ref{STOKES TOL2} to get appropriate values for the tolerances.
After the step has been completed we can calculate a new convergence rate
$\chi =\frac{\epsilon}{\epsilon^{-}}$.
For partial reasons we restrict $\chi$ to be less or equal a given maximum
value $\chi_{max}\le 1$.
If we see $\chi \le \chi^{-} (1+\chi^{-})$ our choices for the tolerances were
suitable. Otherwise, we need to adjust the values for $K$ and $M$.
From the estimates~\ref{STOKES EST 1} and~\ref{STOKES EST 2} we establish
\begin{equation}\label{STOKES EST 3}
\chi \le ( 1 + \max(M \frac{\tau_{2} \|B v_{1}\|_{0}}{\chi^{-} \epsilon^{-}},K \tau_{1}  ) ) \cdot \chi^{-}
\end{equation}
If we assume that this inequality would be an equation if we would have chosen
the right values $M^{+}$ and $K^{+}$ then we get
\begin{equation}\label{STOKES EST 3b}
\chi =  ( 1 + \max(M^{+} \frac{\chi^{-}}{M},K^{+} \frac{\chi^{-}}{K}) ) \cdot \chi^{-}
\end{equation}
From this equation we see if our choice for $K$ was not good enough.
In this case we can calculate a new value
 \begin{equation}
K^{+} =  \frac{\chi-\chi^{-}}{(\chi^{-})^2} K
\end{equation}
In practice we will use
 \begin{equation}
K^{+}  = \max(\frac{\chi-\chi^{-}}{(\chi^{-})^2} K,\frac{1}{2}K,1)
\end{equation}
where the second term is used to reduce a potential overestimate of $K$.
The same identity is used for to update $M$. The updated $M^{+}$ and $K^{+}$
are then use in the next iteration step to control the tolerances.

In some cases one can observe that there is a significant change in the
velocity but the new velocity $v_{1}$ has still a small divergence, i.e.
we have $\|Bv_{1}\|_{0} \ll \|v_{1}-v_{0}\|_{1}$.
In this case we will get a small pressure increment and consequently only very
small changes to the velocity as a result of the second update step which
therefore can be skipped and we can directly repeat the first update step
until the increment in velocity becomes significant relative to its divergence.
In practice we will ignore the second half of the iteration step as long as
 \begin{equation}\label{STOKES LARGE BV1}
\|Bv_{1}\|_{0} \le \theta \cdot \|v_{1}-v_{0}\|
\end{equation}
where $0<\theta<1$ is a given factor. In this case we will also check the
stopping criterion with $v_{1}\rightarrow v_{2}$ but we will not correct $M$
in this case.

Starting from an initial guess $v_{0}$ and $p_{0}$ for velocity and pressure
the solution procedure is implemented as follows:
\begin{enumerate}
 \item calculate viscosity $\eta(v_{0},p)_{0}$ and assemble operator $A$ from $\eta$
 \item calculate the tolerance $\tau_{1}$ from \eqn{STOKES TOL1}
 \item solve \eqn{STOKES ITER STEP 1} for $dv_{1}$ with tolerance $\tau_{1}$
 \item update $v_{1}= v_{0}+ dv_{1}$
 \item if $Bv_{1}$ is large (see~\ref{STOKES LARGE BV1}):
 \begin{enumerate}
   \item calculate the tolerance $\tau_{2}$ from~\ref{STOKES TOL2}
   \item solve~\ref{STOKES ITER STEP 2} for $dp_{2}$ and $v_{2}$ with tolerance $\tau_{2}$
   \item update $p_{2}\leftarrow p_{0}+ dp_{2}$
 \end{enumerate}
 \item else:
  \begin{itemize}
    \item update $p_{2}\leftarrow p$ and $v_{2}\leftarrow v_{1}$
  \end{itemize}
 \item calculate convergence measure $\epsilon$ and convergence rate $\chi$
 \item if stopping criterion~\ref{STOKES STOPPING CRITERIA} holds:
 \begin{itemize}
   \item return $v_{2}$ and $p_{2}$
 \end{itemize}
 \item else:
 \begin{enumerate}
   \item update $M$ and $K$
   \item goto step 1 with $v_{0}\leftarrow v_{2}$ and $p_{0}\leftarrow p_{2}$.
 \end{enumerate}
\end{enumerate}

\subsection{Functions}

\begin{classdesc}{StokesProblemCartesian}{domain}
opens the Stokes problem\index{Stokes problem} on the \Domain domain.
The domain needs to support LBB compliant elements for the Stokes problem, see~\cite{LBB} for details\index{LBB condition}.
For instance one can use second order polynomials for velocity and first order
polynomials for the pressure on the same element.
Alternatively, one can use macro elements\index{macro elements} using linear
polynomials for both pressure and velocity with a subdivided element for the
velocity. Typically, the macro element is more cost effective.
The fact that pressure and velocity are represented in different ways is
expressed by
\begin{python}
  velocity=Vector(0.0, Solution(mesh))
  pressure=Scalar(0.0, ReducedSolution(mesh))
\end{python}
\end{classdesc}

\begin{methoddesc}[StokesProblemCartesian]{initialize}{\optional{f=Data(),
    \optional{fixed_u_mask=Data(), \optional{eta=1,%
    \optional{surface_stress=Data(), \optional{stress=Data()},%
    \optional{restoration_factor=0}}}}}}
assigns values to the model parameters. In any call all values must be set.
\var{f} defines the external force $f$, \var{eta} the viscosity $\eta$,
\var{surface_stress} the surface stress $s$ and \var{stress} the initial stress $\sigma$.
The locations and components where the velocity is fixed are set by the values
of \var{fixed_u_mask}.
\var{restoration_factor} defines the restoring force factor $\alpha$.
The method will try to cast the given values to appropriate \Data class objects.
\end{methoddesc}

\begin{methoddesc}[StokesProblemCartesian]{solve}{v,p
\optional{, max_iter=100 \optional{, verbose=False \optional{, usePCG=True }}}}
solves the problem and returns approximations for velocity and pressure.
The arguments \var{v} and \var{p} define initial guesses.
\var{v} must have function space \var{Solution(domain)} and \var{p} must have
function space \var{ReducedSolution(domain)}.
The values of \var{v} marked by \var{fixed_u_mask} remain unchanged.
If \var{usePCG} is set to \True then the preconditioned conjugate gradient
method (PCG)\index{preconditioned conjugate gradient method!PCG} scheme is
used. Otherwise the problem is solved with the generalized minimal residual
method (GMRES)\index{generalized minimal residual method!GMRES}.
In most cases the PCG scheme is more efficient.
\var{max_iter} defines the maximum number of iteration steps.
If \var{verbose} is set to \True information on the progress of of the solver
is printed.
\end{methoddesc}

\begin{methoddesc}[StokesProblemCartesian]{setTolerance}{\optional{tolerance=1.e-4}}
sets the tolerance in an appropriate norm relative to the right hand side.
The tolerance must be non-negative and less than 1.
\end{methoddesc}

\begin{methoddesc}[StokesProblemCartesian]{getTolerance}{}
returns the current relative tolerance.
\end{methoddesc}

\begin{methoddesc}[StokesProblemCartesian]{setAbsoluteTolerance}{\optional{tolerance=0.}}
sets the absolute tolerance for the error in the relevant norm.
The tolerance must be non-negative.
Typically the absolute tolerance is set to 0.
\end{methoddesc}

\begin{methoddesc}[StokesProblemCartesian]{getAbsoluteTolerance}{}
returns the current absolute tolerance.
\end{methoddesc}

\begin{methoddesc}[StokesProblemCartesian]{getSolverOptionsVelocity}{}
returns the solver options used to solve \eqn{STOKES ITER STEP 1} and \eqn{STOKES P OPERATOR}) for velocity.
\end{methoddesc}

\begin{methoddesc}[StokesProblemCartesian]{getSolverOptionsPressure}{}
returns the solver options used to solve the preconditioner \eqn{STOKES P PREC} for pressure.
\end{methoddesc}

\begin{methoddesc}[StokesProblemCartesian]{getSolverOptionsDiv}{}
sets the solver options for solving the equation to project the divergence of
the velocity onto the function space of pressure.
\end{methoddesc}

\begin{methoddesc}[StokesProblemCartesian]{setStokesEquation}{\optional{f=None,
    \optional{fixed_u_mask=None, \optional{eta=None,%
    \optional{surface_stress=None, \optional{stress=None},%
    \optional{restoration_factor=None}}}}}}
assigns new values to the model parameters, see method \function{initialize} for description of the
parameter list. In contrast to \function{initialize} only values given in the argument list are set.
Typically this method is called to update parameters such as viscosity $\eta$ within a time integration scheme
after the problem has been set up by an initial call of method \function{initialize}.
\end{methoddesc}

\begin{methoddesc}[StokesProblemCartesian]{updateStokesEquation}{v, p}
this method is called by the solver to allow for updating the model parameter during the iteration process for
incompressibility. In order to implement a non-linear dependence of model parameters such as viscosity $\eta$
from the current velocity \var{v} or pressure field \var{p} this function can be overwritten in the following way:
\begin{python}
    class MyStokesProblem(StokesProblemCartesian):
       def updateStokesEquation(self, v, p):
           my_eta=<eta derived from v and p>
           self.setStokesEquation(eta=my_eta)
\end{python}
Note that \function{setStokesEquation} to update the model. \warning{It is not guaranteed that the iteration converges if model parameters are altered.}
\end{methoddesc}

\subsection{Example: Lid-driven Cavity}
The following script \file{lid_driven_cavity.py}\index{scripts!\file{lid_driven_cavity.py}}
which is available in the \ExampleDirectory illustrates the usage of the
\class{StokesProblemCartesian} class to solve the lid-driven cavity problem:
\begin{python}
  from esys.escript import *
  from esys.finley import Rectangle
  from esys.weipa import saveVTK
  from esys.escript.models import StokesProblemCartesian
  NE=25
  dom = Rectangle(NE,NE,order=2)
  x = dom.getX()
  sc=StokesProblemCartesian(dom)
  mask= (whereZero(x[0])*[1.,0]+whereZero(x[0]-1))*[1.,0] + \
        (whereZero(x[1])*[0.,1.]+whereZero(x[1]-1))*[1.,1]
  sc.initialize(eta=.1, fixed_u_mask=mask)
  v=Vector(0., Solution(dom))
  v[0]+=whereZero(x[1]-1.)
  p=Scalar(0.,ReducedSolution(dom))
  v,p=sc.solve(v, p, verbose=True)
  saveVTK("u.vtu", velocity=v, pressure=p)
\end{python}


\documentclass[twoside]{MATH77}
\usepackage{multicol}
\usepackage[fleqn,reqno,centertags]{amsmath}
\begin{document}
\begmath 15.3 Cumulative Distribution Function for Chi-Square
\hbox{Probability Distribution}

\silentfootnote{$^\copyright$1997 Calif. Inst. of Technology, \thisyear \ Math \`a la Carte, Inc.}

\subsection{Purpose}

The procedure described in this Section computes the Cumulative Distribution
Function (CDF) of the Chi-Square probability distribution. The CDF is
sometimes called the lower tail. The
lower tail, or CDF, $P(\chi ^2|\nu )$, and the upper tail, $Q(\chi ^2|\nu )$
for the Chi-Square probability distribution with argument $\chi $ and $\nu $
degrees of freedom are defined by%
\begin{gather*}
\hspace{-5pt}P(\chi ^2|\nu )=\frac{2^{-\nu /2}}{\Gamma (\nu /2)}\int_0^{
\chi^2}t^{(\nu / 2)-1}e^{-t/2}dt,\phantom{=1-P(\chi ^2|\nu )}\\
\hspace{-5pt}Q(\chi ^2|\nu )=\frac{2^{-\nu /2}}{\Gamma (\nu /2)}
\int_{\chi ^2}^\infty t^{(\nu / 2)-1}e^{-t/2}dt\phantom{,}=1-P(\chi ^2|\nu )
\end{gather*}
\subsection{Usage}

\subsubsection{Program Prototype, Single Precision}

\begin{description}
\item[REAL]  \ {\bf CHISQ, NU, P, Q}

\item[INTEGER]  \ {\bf IERR}
\end{description}

Assign values to CHISQ and NU, and obtain P $=P(\chi ^2|\nu )$ and Q $%
=Q(\chi ^2|\nu )$ by using
$$
\fbox{{\bf CALL SCDCHI (CHISQ, NU, P, Q, IERR)}}
$$

\subsubsection{Argument Definitions}

\begin{description}
\item[CHISQ]  \ [in] Argument $\chi ^2$ of the functions $P(\chi ^2|\nu )$
and $Q(\chi ^2|\nu ).$  Must be nonnegative.  Must be positive if NU = 0.

\item[NU]  \ [in] Degrees of freedom $\nu $ of the functions $P(\chi ^2|\nu )
$ and $Q(\chi ^2|\nu ).$  Must be nonnegative.  Must be positive if
CHISQ = 0.

\item[P]  \ [out] The value of the function $P(\chi ^2|\nu ).$

\item[Q]  \ [out] The value of the function $Q(\chi ^2|\nu ).$

\item[IERR]  \ [out] A flag that normally is zero to indicate successful
computation. See Section E below for discussion of non-zero values.
\end{description}

\subsubsection{Modifications for Double Precision}

For double precision computation, change the REAL type statement to DOUBLE
PRECISION and change the initial letter of the procedure name to D.

\subsection{Example and Remarks}

See DRDCDCHI and ODDCDCHI for an example of the usage of this subprogram.

The procedures SGAMIK and SGAMIE, described in Chapter~2.19, are used to
control the procedure SGAMI and determine the error estimate it returns.
SGAMI is used as described in Section D below.

\subsection{Functional Description}

\subsubsection{Method}

The identities $P(\chi ^2|\nu ) = P(a,x)$ and $Q(\chi ^2|\nu ) = Q(a,x)$,
with $a = \nu /2$ and $x = \chi ^2/2$, where $P(a,x)$ and $Q(a,x)$ are
incomplete gamma function ratios, are used. The procedure SGAMI described in
Chapter~2.19 is used to evaluate $P(a,x)$ and $Q(a,x).$

\subsubsection{Accuracy Tests}

See Section~2.19.D.

\subsection{Error Procedures and Restrictions}

The procedure SGAMI issues error messages, under several conditions, at
level 2 + MSGOFF, where MSGOFF is zero unless specified by a call to SGAMIK
(see Chapter~2.19) at some time before calling SCDCHI. If error termination
is suppressed by setting MSGOFF $< 0$, or by calling ERMSET (see Chapter
19.2), IERR will be set to a non-zero value.

If the desired tolerance could not be achieved, IERR is set to~2.

If SCDCHI is called with both CHISQ and NU zero, IERR is set to~3 and P is
set to~3.0.

If SCDCHI is called with one or both of CHISQ and NU negative, IERR is set
to~4 and P is set to~4.0.

\subsection{Supporting Information}

\begin{tabular}{@{\bf}l@{\hspace{5pt}}l}
\bf Entry & \hspace{.35in} {\bf Required Files}\vspace{2pt} \\
DCDCHI & \parbox[t]{2.7in}{\hyphenpenalty10000 \raggedright
AMACH, DCDCHI, DCSEVL, DERF, DERM1, DERV1, DGAM1, DGAMMA, DINITS, DRCOMP,
DREXP, DRLOG, DXPARG, ERFIN, ERMSG, IERM1, IERV1\rule[-5pt]{0pt}{8pt}}\\
SCDCHI & \parbox[t]{2.7in}{\hyphenpenalty10000 \raggedright
AMACH, ERFIN, ERMSG, IERM1, IERV1, SCDCHI, SCSEVL, SERF, SERM1, SERV1,
SGAM1, SGAMMA, SINITS, SRCOMP, SREXP, SRLOG, SXPARG}\\
\end{tabular}

Designed and programmed by W. V. Snyder, JPL, 1993.

\begcodenp
\lstset{language=[77]Fortran,showstringspaces=false}
\lstset{xleftmargin=.8in}

\centerline{\bf \large DRDCDCHI}\vspace{10pt}
\lstinputlisting{\codeloc{dcdchi}}

\vspace{30pt}\centerline{\bf \large ODDCDCHI}\vspace{10pt}
\lstset{language={}}
\lstinputlisting{\outputloc{dcdchi}}
\end{document}


%Suggested order of slides
% slides-linsvm-hard-margin
% slides-linsvm-hard-margin-dual
% slides-linsvm-soft-margin
% slides-linsvm-erm
% slides-linsvm-optimization

\subsection{Linear Hard Margin SVM}
\includepdf[pages=-]{../slides-pdf/slides-linsvm-hard-margin.pdf}

\subsection{Hard-Margin SVM Dual}
\includepdf[pages=-]{../slides-pdf/slides-linsvm-hard-margin-dual.pdf}

\subsection{Soft-Margin SVM}
\includepdf[pages=-]{../slides-pdf/slides-linsvm-soft-margin.pdf}

\subsection{SVMs and Empirical Risk Minimization}
\includepdf[pages=-]{../slides-pdf/slides-linsvm-erm.pdf}

\subsection{Support Vector Machine Training}
\includepdf[pages=-]{../slides-pdf/slides-linsvm-optimization.pdf}


\subsection{Two dimensional uniform dataset}

\begin{figure}
  \includegraphics[width=\columnwidth]{experiment-2D-uniform.pdf}
  \vspace{2mm}
  \centering
  \includegraphics[width=.975\columnwidth]{colormap.pdf}
  %
  \caption{%
  %
  {\bfseries \sffamily Two dimensional uniform dataset (results)}
  %
  Randomized SOM made of $1024$ neurons with a $2$-nearest neighbors induced topology. Model has been trained for $25,000$ epochs on two-dimensional points drawn from a uniform distribution on the unit square. \textbf{A} Map topology in neural space. \textbf{B} Map topology in data space. \textbf{C to H} Receptive field of the map for six samples.
  %
  }
  \label{fig:2D-uniform:results}
\end{figure}